Skip to content

Commit

Permalink
Upgrade fs-extra (#431)
Browse files Browse the repository at this point in the history
* Upgrade `fs-extra`

* Change the value of _codeDirectory

I got the following error.
```
Error: Cannot copy '.' to a subdirectory of itself, 'DIR/node-lambda/.lambda'.
```

* Fix to use relative path when copying files

It seems that `src` of the filter function has changed to relative path.
  • Loading branch information
abetomo authored and DeviaVir committed May 21, 2018
1 parent df9bdf3 commit cb9b930
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 59 deletions.
15 changes: 4 additions & 11 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ so you can easily test run multiple events.
}

_fileCopy (program, src, dest, excludeNodeModules) {
const srcAbsolutePath = path.resolve(src)
const excludes = (() => {
return [
'.git*',
Expand All @@ -275,10 +274,10 @@ so you can easily test run multiple events.
'.lambda',
'deploy.env',
'*.log',
path.join(path.sep, 'build', path.sep)
path.join('build', path.sep)
]
.concat(program.excludeGlobs ? program.excludeGlobs.split(' ') : [])
.concat(excludeNodeModules ? [path.join(path.sep, 'node_modules')] : [])
.concat(excludeNodeModules ? [path.join('node_modules')] : [])
})()

// Formatting for `filter` of `fs.copy`
Expand All @@ -288,12 +287,6 @@ so you can easily test run multiple events.
str = str.substr(0, str.length - 1)
dirBlobs.push(str)
}
if (str.charAt(0) === path.sep) {
return path.join(srcAbsolutePath, str)
}
if (str.indexOf(path.sep) >= 0) {
return path.join(path.resolve('/**'), str)
}
return str
}).join(',') + '}'
const dirPatternRegExp = new RegExp(`(${dirBlobs.join('|')})$`)
Expand All @@ -304,7 +297,7 @@ so you can easily test run multiple events.
const options = {
dereference: true, // same meaning as `-L` of `rsync` command
filter: (src, dest) => {
if (!program.prebuiltDirectory && src === path.join(srcAbsolutePath, 'package.json')) {
if (!program.prebuiltDirectory && src === 'package.json') {
// include package.json unless prebuiltDirectory is set
return true
}
Expand Down Expand Up @@ -445,7 +438,7 @@ so you can easily test run multiple events.
}

_codeDirectory () {
return path.resolve('.', '.lambda')
return path.join(os.tmpdir(), `${path.basename(path.resolve('.'))}-lambda`)
}

_cleanDirectory (codeDirectory) {
Expand Down
142 changes: 113 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"commander": "^2.14.1",
"continuation-local-storage": "^3.2.1",
"dotenv": "^0.4.0",
"fs-extra": "^0.30.0",
"fs-extra": "^6.0.1",
"klaw": "^2.1.1",
"minimatch": "^3.0.3",
"proxy-agent": "^2.2.0"
Expand Down
4 changes: 2 additions & 2 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ describe('lib/main', function () {
})

describe('_codeDirectory', () => {
it('.lambda in the current directory', () => {
assert.equal(lambda._codeDirectory(), path.resolve('.', '.lambda'))
it('Working directory in the /tmp directory', () => {
assert.equal(lambda._codeDirectory(), path.join(os.tmpdir(), 'node-lambda-lambda'))
})
})

Expand Down
28 changes: 12 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -827,15 +827,13 @@ [email protected]:
dependencies:
samsam "~1.1"

fs-extra@^0.30.0:
version "0.30.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-0.30.0.tgz#f233ffcc08d4da7d432daa449776989db1df93f0"
fs-extra@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-6.0.1.tgz#8abc128f7946e310135ddc93b98bddb410e7a34b"
dependencies:
graceful-fs "^4.1.2"
jsonfile "^2.1.0"
klaw "^1.0.0"
path-is-absolute "^1.0.0"
rimraf "^2.2.8"
jsonfile "^4.0.0"
universalify "^0.1.0"

fs.realpath@^1.0.0:
version "1.0.0"
Expand Down Expand Up @@ -1147,9 +1145,9 @@ [email protected]:
version "3.3.2"
resolved "https://registry.yarnpkg.com/json3/-/json3-3.3.2.tgz#3c0434743df93e2f5c42aee7b19bcb483575f4e1"

jsonfile@^2.1.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-2.4.0.tgz#3736a2b428b87bbda0cc83b53fa3d633a35c2ae8"
jsonfile@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb"
optionalDependencies:
graceful-fs "^4.1.6"

Expand All @@ -1165,12 +1163,6 @@ [email protected]:
dependencies:
pako "~0.2.5"

klaw@^1.0.0:
version "1.3.1"
resolved "https://registry.yarnpkg.com/klaw/-/klaw-1.3.1.tgz#4088433b46b3b1ba259d78785d8e96f73ba02439"
optionalDependencies:
graceful-fs "^4.1.9"

klaw@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/klaw/-/klaw-2.1.1.tgz#42b76894701169cc910fd0d19ce677b5fb378af1"
Expand Down Expand Up @@ -1946,6 +1938,10 @@ uniq@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/uniq/-/uniq-1.0.1.tgz#b31c5ae8254844a3a8281541ce2b04b865a734ff"

universalify@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.1.tgz#fa71badd4437af4c148841e3b3b165f9e9e590b7"

[email protected]:
version "1.0.0"
resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"
Expand Down

0 comments on commit cb9b930

Please sign in to comment.