From ff06783a5cfc8e1aff0a9ec7518083741153cb32 Mon Sep 17 00:00:00 2001 From: Dimitar Roustchev Date: Wed, 24 Aug 2016 14:02:18 -0400 Subject: [PATCH 1/2] Never exclude package.json, even when specified in excludeGlobs. --- lib/main.js | 2 +- test/main.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index 010b7f88..fcebdcf0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -162,7 +162,7 @@ Lambda.prototype._rsync = function (program, src, dest, excludeNodeModules, call // 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 --include package.json ' + excludeArgs + ' ' + src.trim() + '/ ' + dest, function (err) { if (err) { return callback(err); } diff --git a/test/main.js b/test/main.js index 6e872040..82e87037 100644 --- a/test/main.js +++ b/test/main.js @@ -131,6 +131,17 @@ 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(); + }); + }); }); }); From 5fd50d27190c383a71eac4d4e0adb54360f9709d Mon Sep 17 00:00:00 2001 From: Dimitar Roustchev Date: Tue, 6 Sep 2016 13:39:59 -0400 Subject: [PATCH 2/2] Do not force include package.json if --prebuiltDirectory is used. --- lib/main.js | 5 ++++- test/main.js | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index fcebdcf0..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 --include package.json ' + 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 82e87037..d2d0c533 100644 --- a/test/main.js +++ b/test/main.js @@ -142,6 +142,28 @@ describe('node-lambda', function () { 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(); + }); + }); }); });