From 04534db506e4bbd38848a907428d09a5dedeb26d Mon Sep 17 00:00:00 2001 From: David Von Lehman Date: Fri, 21 Oct 2016 22:37:11 -0700 Subject: [PATCH 1/4] Add a test to verify that the native zip command exists --- lib/main.js | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index 27672f69..7576cd81 100644 --- a/lib/main.js +++ b/lib/main.js @@ -366,13 +366,39 @@ Lambda.prototype._archivePrebuilt = function (program, archive_callback) { _this._setEnvironmentVars(program, codeDirectory); } console.log('=> Zipping deployment package'); - var archive = process.platform !== 'win32' ? _this._nativeZip : _this._zip; - archive = archive.bind(_this); + var archive; + if (process.platform === 'win32') { + archive = _this._zip; + } else { + archive = _this._nativeZip; + + // Test if the "zip" command exists. + try { + child_process.execSync('command -v zip 2>/dev/null'); + } catch (err) { + archive = _this._zip; + } + } + + archive = archive.bind(_this); archive(program, codeDirectory, archive_callback); }); }; +Lambda.prototype._whichZipProgram = function() { + if (process.platform === 'win32') return this._zip; + + // Test if the "zip" command exists. + try { + child_process.execSync('command -v zip 2>/dev/null'); + } catch (err) { + return this._zip; + } + + return this._nativeZip; +} + Lambda.prototype._buildAndArchive = function (program, archive_callback) { this._createSampleFile('.env', '.env'); @@ -414,7 +440,7 @@ Lambda.prototype._buildAndArchive = function (program, archive_callback) { } console.log('=> Zipping deployment package'); - var archive = process.platform !== 'win32' ? _this._nativeZip : _this._zip; + var archive = _this._whichZipProgram(); archive = archive.bind(_this); archive(program, codeDirectory, archive_callback); From 0927a899a1235ab8b7d925907be0c5b78c586ad6 Mon Sep 17 00:00:00 2001 From: David Von Lehman Date: Fri, 21 Oct 2016 22:51:31 -0700 Subject: [PATCH 2/4] Use shared _whichZipProgram function --- lib/main.js | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/lib/main.js b/lib/main.js index 7576cd81..ca392f82 100644 --- a/lib/main.js +++ b/lib/main.js @@ -367,20 +367,7 @@ Lambda.prototype._archivePrebuilt = function (program, archive_callback) { } console.log('=> Zipping deployment package'); - var archive; - if (process.platform === 'win32') { - archive = _this._zip; - } else { - archive = _this._nativeZip; - - // Test if the "zip" command exists. - try { - child_process.execSync('command -v zip 2>/dev/null'); - } catch (err) { - archive = _this._zip; - } - } - + var archive = _this._whichZipProgram(); archive = archive.bind(_this); archive(program, codeDirectory, archive_callback); }); From b876ea89aafbfdae6d91d07940bf09c21029dddc Mon Sep 17 00:00:00 2001 From: David Von Lehman Date: Sun, 23 Oct 2016 21:41:08 -0700 Subject: [PATCH 3/4] Require child_process.execSync --- lib/main.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index ca392f82..3b7085a0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -2,6 +2,7 @@ var aws = require('aws-sdk'); var exec = require('child_process').exec; +var execSync = require('child_process').execSync; var fs = require('fs-extra'); var os = require('os'); var packageJson = require('./../package.json'); @@ -10,6 +11,7 @@ var async = require('async'); var zip = new require('node-zip')(); var dotenv = require('dotenv'); + var Lambda = function () { this.version = packageJson.version; @@ -378,8 +380,9 @@ Lambda.prototype._whichZipProgram = function() { // Test if the "zip" command exists. try { - child_process.execSync('command -v zip 2>/dev/null'); + execSync('command -v zip 2>/dev/null'); } catch (err) { + console.log('native zip not defined, error is: ' + err.toString()); return this._zip; } From 5f83e6319e55668300a1ac6c1daf5bc9aa5a7a61 Mon Sep 17 00:00:00 2001 From: David Von Lehman Date: Sun, 23 Oct 2016 21:45:42 -0700 Subject: [PATCH 4/4] Remove leftover debugging statement --- lib/main.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index 3b7085a0..15b92e0b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -382,7 +382,6 @@ Lambda.prototype._whichZipProgram = function() { try { execSync('command -v zip 2>/dev/null'); } catch (err) { - console.log('native zip not defined, error is: ' + err.toString()); return this._zip; }