Skip to content

Commit 8aff9ac

Browse files
authored
Fix #112 (#146)
1 parent 8783620 commit 8aff9ac

File tree

3 files changed

+19
-23
lines changed

3 files changed

+19
-23
lines changed

lib/main.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
var aws = require('aws-sdk');
44
var exec = require('child_process').exec;
5-
var fs = require('fs');
5+
var fs = require('fs-extra');
66
var os = require('os');
77
var packageJson = require('./../package.json');
88
var path = require('path');
99
var async = require('async');
1010
var zip = new require('node-zip')();
11-
var wrench = require('wrench');
1211
var dotenv = require('dotenv');
1312

1413
var Lambda = function () {
@@ -214,19 +213,18 @@ Lambda.prototype._zip = function (program, codeDirectory, callback) {
214213
};
215214

216215
console.log('=> Zipping repo. This might take up to 30 seconds');
217-
var files = wrench.readdirSyncRecursive(codeDirectory);
218-
files.forEach(function (file) {
219-
var filePath = [codeDirectory, file].join('/');
220-
var isFile = fs.lstatSync(filePath).isFile();
221-
if (isFile) {
222-
var content = fs.readFileSync(filePath);
223-
zip.file(file, content);
224-
}
225-
});
226-
227-
var data = zip.generate(options);
228-
229-
return callback(null, data);
216+
fs.walk(codeDirectory)
217+
.on('data', function (file) {
218+
if (!file.stats.isDirectory()) {
219+
var content = fs.readFileSync(file.path);
220+
var filePath = file.path.replace(codeDirectory + '/', '');
221+
zip.file(filePath, content);
222+
}
223+
})
224+
.on('end', function () {
225+
var data = zip.generate(options);
226+
return callback(null, data);
227+
});
230228
};
231229

232230
Lambda.prototype._nativeZip = function (program, codeDirectory, callback) {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
"aws-sdk": "^2.1.24",
4242
"commander": "^2.5.0",
4343
"dotenv": "^0.4.0",
44+
"fs-extra": "^0.30.0",
4445
"node-uuid": "^1.4.2",
4546
"node-zip": "^1.1.0",
46-
"rimraf": "^2.2.8",
47-
"wrench": "^1.5.8"
47+
"rimraf": "^2.2.8"
4848
}
4949
}

test/main.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ describe('node-lambda', function () {
9292
lambda._rsync(program, '.', codeDirectory, true, function (err, result) {
9393
var contents = fs.readdirSync(codeDirectory);
9494

95-
console.log('contents: ', contents);
9695
result = _.includes(contents, 'index.js') &&
9796
_.includes(contents, 'package.json') &&
9897
!_.includes(contents, 'node_modules');
@@ -102,9 +101,9 @@ describe('node-lambda', function () {
102101
});
103102
});
104103

105-
describe("when there are excluded files", function (done) {
104+
describe("when there are excluded files", function () {
106105
beforeEach(function (done) {
107-
program.excludeGlobs="*.png test"
106+
program.excludeGlobs="*.png test";
108107
done();
109108
});
110109

@@ -216,7 +215,7 @@ describe('node-lambda', function () {
216215
result = _.includes(contents, 'node_modules/async/lib/async.js');
217216
assert.equal(result, true);
218217
done();
219-
})
218+
});
220219
});
221220

222221
it('packages a prebuilt module without installing', function (done) {
@@ -238,14 +237,13 @@ describe('node-lambda', function () {
238237
var contents = _.map(archive.files, function (f) {
239238
return f.name.toString();
240239
});
241-
console.log('contents: ', contents);
242240
var result = _.includes(contents, 'testa') &&
243241
_.includes(contents, 'd/testb') &&
244242
_.includes(contents, 'node_modules/a');
245243
assert.equal(result, true);
246244
done();
247245

248-
})
246+
});
249247
});
250248
});
251249

0 commit comments

Comments
 (0)