Skip to content

Commit 6e752df

Browse files
committed
Merge pull request #20 from christianklotz/master
Remove adm-zip dependency from tests and use native zip command to preserve file permission on binaries
2 parents 115a2c7 + 1a0ec81 commit 6e752df

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

lib/main.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,25 @@ Lambda.prototype._zip = function(program, codeDirectory, callback) {
128128
zip.file(file, content);
129129
}
130130
});
131-
131+
132132
var data = zip.generate(options);
133133

134134
return callback(null, data);
135135
};
136136

137+
Lambda.prototype._nativeZip = function(program, codeDirectory, callback) {
138+
var zipfile = this._zipfileTmpPath(program)
139+
, cmd = 'zip -r ' + zipfile + ' .'
140+
, run = exec(cmd, { cwd: codeDirectory }, function (err, stdout, stderr) {
141+
if (err !== null) {
142+
return callback(err, null)
143+
}
144+
145+
var data = fs.readFileSync(zipfile)
146+
callback(null, data)
147+
})
148+
};
149+
137150
Lambda.prototype._codeDirectory = function(program) {
138151
var epoch_time = +new Date;
139152
return os.tmpDir() + '/' + program.functionName + '-' + epoch_time;
@@ -149,7 +162,11 @@ Lambda.prototype.deploy = function(program) {
149162
// Move all files to tmp folder (except .git, .log, event.json and node_modules)
150163
_this._rsync(program, codeDirectory, function(err, result) {
151164
_this._npmInstall(program, codeDirectory, function(err, result) {
152-
_this._zip(program, codeDirectory, function(err, buffer) {
165+
// Use zip from the command line on non-windows systems to preserve file permissions
166+
var archive = process.platform != 'win32' ? _this._nativeZip : _this._zip;
167+
archive = archive.bind(_this)
168+
169+
archive(program, codeDirectory, function(err, buffer) {
153170

154171
console.log('Reading zip file to memory');
155172
//var buffer = fs.readFileSync(zipfile);

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
"author": "motdotla",
3131
"license": "BSD",
3232
"devDependencies": {
33-
"adm-zip": "^0.4.7",
3433
"chai": "^2.0.0",
3534
"hoek": "^2.11.1",
3635
"lodash": "^3.2.0",

test/main.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var lambda = require('../lib/main');
66
var os = require('os');
77
var fs = require('fs');
88
var _ = require('lodash');
9-
var admzip = require('adm-zip');
9+
var zip = require('node-zip');
1010

1111
var assert = chai.assert;
1212

@@ -111,10 +111,9 @@ describe('node-lambda', function() {
111111
it('zips the file and has an index.js file', function(done) {
112112
this.timeout(30000); // give it time to zip
113113

114-
lambda._zip(program, codeDirectory, function(err, zipfilePath) {
115-
var zip = new admzip(zipfilePath);
116-
var zipEntries = zip.getEntries();
117-
var contents = _.map(zipEntries, function(entry) { return entry.entryName.toString() });
114+
lambda._zip(program, codeDirectory, function(err, data) {
115+
var archive = new zip(data);
116+
var contents = _.map(archive.files, function(f) { return f.name.toString() });
118117
var result = _.includes(contents, 'index.js');
119118
assert.equal(result, true);
120119

0 commit comments

Comments
 (0)