diff --git a/lib/main.js b/lib/main.js index c7de33cb..a2ef5dc4 100644 --- a/lib/main.js +++ b/lib/main.js @@ -95,9 +95,9 @@ Lambda.prototype._runHandler = function (handler, event, program, context) { Lambda.prototype._params = function (program, buffer) { var params = { - FunctionName: program.functionName - + (program.environment ? '-' + program.environment : '') - + (program.lambdaVersion ? '-' + program.lambdaVersion : ''), + FunctionName: program.functionName + + (program.environment ? '-' + program.environment : '') + + (program.lambdaVersion ? '-' + program.lambdaVersion : ''), Code: { ZipFile: buffer }, @@ -206,10 +206,12 @@ Lambda.prototype._fileCopy = function (program, src, dest, excludeNodeModules, c str = str.substr(0, str.length - 1); dirBlobs.push(str); } - if (str.charAt(0) === path.sep) + if (str.charAt(0) === path.sep) { return path.join(srcAbsolutePath, str); - if (str.indexOf(path.sep) >= 0) + } + if (str.indexOf(path.sep) >= 0) { return path.join(path.resolve('/**'), str); + } return str; }).join(',') + '}'; const dirPatternRegExp = new RegExp(`(${dirBlobs.join('|')})$`); @@ -226,11 +228,13 @@ Lambda.prototype._fileCopy = function (program, src, dest, excludeNodeModules, c return true; } - if (!minimatch(src, pattern, { matchBase: true })) + if (!minimatch(src, pattern, { matchBase: true })) { return true; + } // Directory check. Even if `src` is a directory it will not end with '/'. - if (!dirPatternRegExp.test(src)) + if (!dirPatternRegExp.test(src)) { return false; + } return !fs.statSync(src).isDirectory(); } }; @@ -246,8 +250,8 @@ 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 = []; + var excludes = ['.git*', '*.swp', '.editorconfig', '.lambda', 'deploy.env', '*.log', '/build/']; + var excludeGlobs = []; if (program.excludeGlobs) { excludeGlobs = program.excludeGlobs.split(' '); } @@ -286,9 +290,9 @@ Lambda.prototype._npmInstall = function (program, codeDirectory, callback) { `--prefix ${codeDirectory}`, process.platform === 'win32' ? `--cwd ${codeDirectory}` : null ].join(' '); - var command = program.dockerImage ? - 'docker run --rm -v ' + codeDirectory + ':/var/task ' + program.dockerImage + ' npm -s install --production' : - `npm -s install --production ${installOptions}`; + var command = program.dockerImage + ? 'docker run --rm -v ' + codeDirectory + ':/var/task ' + program.dockerImage + ' npm -s install --production' + : `npm -s install --production ${installOptions}`; exec(command, { maxBuffer: maxBufferSize, env: process.env @@ -317,7 +321,7 @@ Lambda.prototype._postInstallScript = function (program, codeDirectory, callback maxBuffer: maxBufferSize }, function (error, stdout, stderr) { if (error) { - return callback(error + ' stdout: ' + stdout + ' stderr: ' + stderr); + return callback(new Error(`${error} stdout: ${stdout} stderr: ${stderr}`)); } console.log('\t\t' + stdout); callback(null); @@ -438,9 +442,9 @@ Lambda.prototype._archive = function (program, archiveCallback) { if (program.deployZipfile && fs.existsSync(program.deployZipfile)) { return this._readArchive(program, archiveCallback); } - return program.prebuiltDirectory ? - this._archivePrebuilt(program, archiveCallback) : - this._buildAndArchive(program, archiveCallback); + return program.prebuiltDirectory + ? this._archivePrebuilt(program, archiveCallback) + : this._buildAndArchive(program, archiveCallback); }; Lambda.prototype._archivePrebuilt = function (program, archiveCallback) { @@ -632,13 +636,13 @@ Lambda.prototype._updateScheduleEvents = function (scheduleEvents, functionArn, Lambda.prototype.package = function (program) { var _this = this; if (!program.packageDirectory) { - throw 'packageDirectory not specified!'; + throw new Error('packageDirectory not specified!'); } try { var isDir = fs.lstatSync(program.packageDirectory).isDirectory(); if (!isDir) { - throw program.packageDirectory + ' is not a directory!'; + throw new Error(program.packageDirectory + ' is not a directory!'); } } catch (err) { if (err.code === 'ENOENT') { @@ -729,7 +733,7 @@ Lambda.prototype.deploy = function (program) { function (_callback) { // Updating event source(s) _this._updateEventSources(lambda, params.FunctionName, [], eventSourceList.EventSourceMappings, function (err, results) { - _callback(null, results); + _callback(err, results); }); }, function (_callback) { diff --git a/test/handler/index.js b/test/handler/index.js index c3332d90..40a5ec96 100644 --- a/test/handler/index.js +++ b/test/handler/index.js @@ -5,8 +5,10 @@ exports.handler = (event, context, callback) => { context.callbackWaitsForEmptyEventLoop = !!event.callbackWaitsForEmptyEventLoop; - if (event.asyncTest) + if (event.asyncTest) { setTimeout(() => console.log('sleep 3500 msec'), 3500); + } + /* eslint-disable no-eval */ eval(event.callbackCode); }; diff --git a/test/main.js b/test/main.js index 7a5a7ade..603a2386 100644 --- a/test/main.js +++ b/test/main.js @@ -381,8 +381,9 @@ describe('lib/main', function () { }); afterEach(function () { hook.unhook(); - if (fs.existsSync(postInstallScriptPath)) + if (fs.existsSync(postInstallScriptPath)) { fs.unlinkSync(postInstallScriptPath); + } }); it('should not throw any errors if no script', function (done) { @@ -395,7 +396,8 @@ describe('lib/main', function () { it('should throw any errors if script fails', function (done) { fs.writeFileSync(postInstallScriptPath, '___fails___'); lambda._postInstallScript(program, codeDirectory, function (err) { - assert.match(err, /^Error: Command failed:/); + assert.instanceOf(err, Error); + assert.match(err.message, /^Error: Command failed:/); done(); }); });