Skip to content

Commit

Permalink
Never exclude package.json, even when specified in excludeGlobs. (#141)
Browse files Browse the repository at this point in the history
* Never exclude package.json, even when specified in excludeGlobs.

* Do not force include package.json if --prebuiltDirectory is used.
  • Loading branch information
droustchev authored and DeviaVir committed Sep 6, 2016
1 parent c7c2bbb commit 447512e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,12 @@ Lambda.prototype._rsync = function (program, src, dest, excludeNodeModules, call
return callback(err);
}

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

// we need the extra / after src to make sure we are copying the content
// of the directory, not the directory itself.
exec('rsync -rL ' + excludeArgs + ' ' + src.trim() + '/ ' + dest, function (err) {
exec('rsync -rL ' + includeArgs + excludeArgs + ' ' + src.trim() + '/ ' + dest, function (err) {
if (err) {
return callback(err);
}
Expand Down
33 changes: 33 additions & 0 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,39 @@ describe('node-lambda', function () {
done();
});
});

it('rsync should not exclude package.json, even when excluded by excludeGlobs', function (done) {
program.excludeGlobs="*.json"
lambda._rsync(program, '.', codeDirectory, true, function(err, result) {
var contents = fs.readdirSync(codeDirectory);
result = _.includes(contents, 'package.json');
assert.equal(result, true);

done();
});
});

it('rsync should not include package.json when --prebuiltDirectory is set', function (done) {
var path = '.build_' + Date.now();
after(function() {
rimraf.sync(path, fs);
});

fs.mkdirSync(path);
fs.writeFileSync(path + '/testa');
fs.writeFileSync(path + '/package.json');

program.excludeGlobs = "*.json"
program.prebuiltDirectory = path;
lambda._rsync(program, path, codeDirectory, true, function(err, result) {
var contents = fs.readdirSync(codeDirectory);
result = !_.includes(contents, 'package.json') &&
_.includes(contents, 'testa');
assert.equal(result, true);

done();
});
});
});
});

Expand Down

0 comments on commit 447512e

Please sign in to comment.