diff --git a/lib/main.js b/lib/main.js index 010b7f88..41bfe1ba 100644 --- a/lib/main.js +++ b/lib/main.js @@ -160,9 +160,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); } diff --git a/test/main.js b/test/main.js index 6e872040..d2d0c533 100644 --- a/test/main.js +++ b/test/main.js @@ -131,6 +131,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(); + }); + }); }); });