Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to include only package.json in the source directory #274

Merged
merged 2 commits into from
May 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ Lambda.prototype._fileCopy = function (program, src, dest, excludeNodeModules, c
const options = {
dereference: true, // same meaning as `-L` of `rsync` command
filter: function (src, dest) {
if (!program.prebuiltDirectory && path.basename(src) == 'package.json') {
if (!program.prebuiltDirectory && src === path.join(srcAbsolutePath, 'package.json')) {
// include package.json unless prebuiltDirectory is set
return true;
}
Expand Down Expand Up @@ -272,7 +272,7 @@ Lambda.prototype._rsync = function (program, src, dest, excludeNodeModules, call
}

// include package.json unless prebuiltDirectory is set
var includeArgs = program.prebuiltDirectory ? '' : '--include package.json ';
var includeArgs = program.prebuiltDirectory ? '' : '--include /package.json ';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure, but the / would make the path invalid, or no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The include and exclude options of rsync are complicated, so I can not explain the exact behavior, but the result was as follows.

src directory

% pwd
/tmp/test
% find /tmp/test -type f
/tmp/test/package.json
/tmp/test/foo/package.json

exclude='foo/*'

include='package.json'

% rm -rf /tmp/bar; rsync -rL --include='package.json' --exclude='foo/*' /tmp/test /tmp/bar
% find /tmp/bar -type f
/tmp/bar/test/package.json
/tmp/bar/test/foo/package.json

include='/package.json'

% rm -rf /tmp/bar; rsync -rL --include='/package.json' --exclude='foo/*' /tmp/test /tmp/bar
% find /tmp/bar -type f
/tmp/bar/test/package.json

exclude='foo'

include='package.json'

% rm -rf /tmp/bar; rsync -rL --include='package.json' --exclude='foo' /tmp/test /tmp/bar  
% find /tmp/bar -type f
/tmp/bar/test/package.json

include='/package.json'

% rm -rf /tmp/bar; rsync -rL --include='/package.json' --exclude='foo' /tmp/test /tmp/bar
% find /tmp/bar -type f
/tmp/bar/test/package.json


// we need the extra / after src to make sure we are copying the content
// of the directory, not the directory itself.
Expand Down
1 change: 1 addition & 0 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ describe('node-lambda', function () {
fs.mkdirsSync(path.join('__unittest', 'hoge'));
fs.mkdirsSync(path.join('__unittest', 'fuga'));
fs.writeFileSync(path.join('__unittest', 'hoge', 'piyo'));
fs.writeFileSync(path.join('__unittest', 'hoge', 'package.json'));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fs.writeFileSync('fuga');
});
after(function () {
Expand Down