Skip to content
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
23 changes: 21 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ Lambda.prototype._fileCopy = function (program, src, dest, excludeNodeModules, c
});
};

// `_rsync` will be replaced by` _fileCopy`.
Lambda.prototype._rsync = function (program, src, dest, excludeNodeModules, callback) {
var excludes = ['.git*', '*.swp', '.editorconfig', '.lambda', 'deploy.env', '*.log', '/build/'],
excludeGlobs = [];
Expand Down Expand Up @@ -452,7 +453,16 @@ Lambda.prototype._archive = function (program, archive_callback) {
Lambda.prototype._archivePrebuilt = function (program, archive_callback) {
var codeDirectory = this._codeDirectory(program);
var _this = this;
this._rsync(program, program.prebuiltDirectory, codeDirectory, false, function (err) {

// It is switched to `_ rsync` by environment variable.
// (Used if there is a problem with `_ fileCopy`)
// If there is no problem even if deleting `_rsync`, this switching process is deleted
var copyFunction = '_fileCopy';
if (process.env.NODE_LAMBDA_COPY_FUNCTION == 'rsync') {
console.log('=> INFO: Use rsync for copy');
copyFunction = '_rsync';
}
this[copyFunction](program, program.prebuiltDirectory, codeDirectory, false, function (err) {
if (err) {
return archive_callback(err);
}
Expand Down Expand Up @@ -484,8 +494,17 @@ Lambda.prototype._buildAndArchive = function (program, archive_callback) {
return archive_callback(err);
}
console.log('=> Moving files to temporary directory');

// It is switched to `_ rsync` by environment variable.
// (Used if there is a problem with `_ fileCopy`)
// If there is no problem even if deleting `_rsync`, this switching process is deleted
var copyFunction = '_fileCopy';
if (process.env.NODE_LAMBDA_COPY_FUNCTION == 'rsync') {
console.log('=> INFO: Use rsync for copy');
copyFunction = '_rsync';
}
// Move files to tmp folder
_this._rsync(program, '.', codeDirectory, true, function (err) {
_this[copyFunction](program, '.', codeDirectory, true, function (err) {
if (err) {
return archive_callback(err);
}
Expand Down
12 changes: 8 additions & 4 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ describe('node-lambda', function () {
});

it('`codeDirectory` is empty. (For `codeDirectory` where the file was present)', function (done) {
lambda._rsync(program, '.', codeDirectory, true, function (err, result) {
lambda._fileCopy(program, '.', codeDirectory, true, function (err, result) {
const contents = fs.readdirSync(codeDirectory);
assert.isTrue(contents.length > 0);
lambda._cleanDirectory(codeDirectory, function () {
Expand Down Expand Up @@ -285,8 +285,12 @@ describe('node-lambda', function () {
});
}

describe('_rsync', function() { rsyncTests('_rsync'); });
describe('_fileCopy', function() { rsyncTests('_fileCopy'); });
if (process.platform == 'win32') {
it('For Windows, `_rsync` tests pending');
} else {
describe('_rsync', function() { rsyncTests('_rsync'); });
}

describe('_npmInstall', function () {
beforeEach(function (done) {
Expand All @@ -295,7 +299,7 @@ describe('node-lambda', function () {
return done(err);
}

lambda._rsync(program, '.', codeDirectory, true, function (err) {
lambda._fileCopy(program, '.', codeDirectory, true, function (err) {
if (err) {
return done(err);
}
Expand Down Expand Up @@ -381,7 +385,7 @@ describe('node-lambda', function () {
return done(err);
}

lambda._rsync(program, '.', codeDirectory, true, function (err) {
lambda._fileCopy(program, '.', codeDirectory, true, function (err) {
if (err) {
return done(err);
}
Expand Down