From 0836c8d80bec86c723fe94753f3267ee768e0588 Mon Sep 17 00:00:00 2001 From: abetomo Date: Mon, 26 Jun 2017 12:14:49 +0900 Subject: [PATCH 01/11] Add archiver.js --- package-lock.json | 78 +++++++++++++++++++++++++++++++- package.json | 1 + yarn.lock | 113 ++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 186 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0c2f73c9..da8da2ff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -72,6 +72,16 @@ "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", "dev": true }, + "archiver": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/archiver/-/archiver-1.3.0.tgz", + "integrity": "sha1-TyGU1tj5nfP1MeaIHxTxXVX6ryI=" + }, + "archiver-utils": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/archiver-utils/-/archiver-utils-1.3.0.tgz", + "integrity": "sha1-5QtMCccL89aA4y/xt5lOn52JUXQ=" + }, "argparse": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.9.tgz", @@ -113,6 +123,11 @@ "resolved": "https://registry.npmjs.org/ast-types/-/ast-types-0.9.12.tgz", "integrity": "sha1-sTYwDWcCZiWuFTJpgsqZGOXbc8k=" }, + "async": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/async/-/async-2.5.0.tgz", + "integrity": "sha512-e+lJAJeNWuPCNyxZKOBdaJGyLGHugXVQtrAwtuAe2vhxTYxFTKE73p8JuTmdH0qdQZtDvI4dhJwjZc5zsfIsYw==" + }, "aws-sdk": { "version": "2.71.0", "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.71.0.tgz", @@ -140,6 +155,11 @@ "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.2.0.tgz", "integrity": "sha1-o5mS1yNYSBGYK+XikLtqU9hnAPE=" }, + "bl": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/bl/-/bl-1.2.1.tgz", + "integrity": "sha1-ysMo977kVzDUBLaSID/LWQ4XLV4=" + }, "brace-expansion": { "version": "1.1.8", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz", @@ -155,6 +175,11 @@ "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.0.6.tgz", "integrity": "sha1-LqZp9+7Atu2gWwj4tf9mGyhXNYg=" }, + "buffer-crc32": { + "version": "0.2.13", + "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", + "integrity": "sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI=" + }, "builtin-modules": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz", @@ -232,6 +257,11 @@ "resolved": "https://registry.npmjs.org/commander/-/commander-2.9.0.tgz", "integrity": "sha1-nJkJQXbhIkDLItbFFGCYQA/g99Q=" }, + "compress-commons": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/compress-commons/-/compress-commons-1.2.0.tgz", + "integrity": "sha1-WFhwku8g03y1i68AARLJJ4/3O58=" + }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -254,6 +284,16 @@ "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" }, + "crc": { + "version": "3.4.4", + "resolved": "https://registry.npmjs.org/crc/-/crc-3.4.4.tgz", + "integrity": "sha1-naHpgOO9RPxck79as9ozeNheRms=" + }, + "crc32-stream": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/crc32-stream/-/crc32-stream-2.0.0.tgz", + "integrity": "sha1-483TtN8xaN10494/u8t7KX/pCPQ=" + }, "crypto-browserify": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/crypto-browserify/-/crypto-browserify-1.0.9.tgz", @@ -339,6 +379,11 @@ "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-0.4.0.tgz", "integrity": "sha1-9vs1E2PC2SIHJFxzeALJq1rhSVo=" }, + "end-of-stream": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.0.tgz", + "integrity": "sha1-epDYM+/abPpurA9JSduw+tOmMgY=" + }, "error-ex": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.1.tgz", @@ -957,6 +1002,11 @@ "resolved": "https://registry.npmjs.org/klaw/-/klaw-1.3.1.tgz", "integrity": "sha1-QIhDO0azsbolnXh4XY6W9zugJDk=" }, + "lazystream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/lazystream/-/lazystream-1.0.0.tgz", + "integrity": "sha1-9plf4PggOS9hOWvolGJAe7dxaOQ=" + }, "levn": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz", @@ -1113,6 +1163,11 @@ "resolved": "https://registry.npmjs.org/node-zip/-/node-zip-1.1.1.tgz", "integrity": "sha1-lNGtZ0o81GoViN1zb0qaeMdX62I=" }, + "normalize-path": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-2.1.1.tgz", + "integrity": "sha1-GrKLVW4Zg2Oowab35vogE3/mrtk=" + }, "number-is-nan": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", @@ -1336,6 +1391,11 @@ "integrity": "sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=", "dev": true }, + "remove-trailing-separator": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/remove-trailing-separator/-/remove-trailing-separator-1.0.2.tgz", + "integrity": "sha1-abBi2XhyetFNxrVrpKt3L9jXBRE=" + }, "require-uncached": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/require-uncached/-/require-uncached-1.0.3.tgz", @@ -1530,6 +1590,11 @@ } } }, + "tar-stream": { + "version": "1.5.4", + "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-1.5.4.tgz", + "integrity": "sha1-NlSc8E7RrumyowwBQyUiONr5QBY=" + }, "text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", @@ -1622,6 +1687,11 @@ "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.0.1.tgz", "integrity": "sha1-ZUS7ot/ajBzxfmKaOjBeK7H+5sE=" }, + "walkdir": { + "version": "0.0.11", + "resolved": "https://registry.npmjs.org/walkdir/-/walkdir-0.0.11.tgz", + "integrity": "sha1-oW0CXrkxvQO1LzCMrtD0D86+lTI=" + }, "wordwrap": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", @@ -1656,8 +1726,12 @@ "xtend": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", - "integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68=", - "dev": true + "integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68=" + }, + "zip-stream": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/zip-stream/-/zip-stream-1.2.0.tgz", + "integrity": "sha1-qLxF9MG0lpnGuQGYuqyqzbzUugQ=" } } } diff --git a/package.json b/package.json index a79b4580..3e76a3fd 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "standard": "^10.0.2" }, "dependencies": { + "archiver": "^1.3.0", "aws-sdk": "^2.71.0", "commander": "^2.5.0", "dotenv": "^0.4.0", diff --git a/yarn.lock b/yarn.lock index 7e8e8318..fa44b353 100644 --- a/yarn.lock +++ b/yarn.lock @@ -50,6 +50,31 @@ ansi-styles@^2.2.1: version "2.2.1" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe" +archiver-utils@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/archiver-utils/-/archiver-utils-1.3.0.tgz#e50b4c09c70bf3d680e32ff1b7994e9f9d895174" + dependencies: + glob "^7.0.0" + graceful-fs "^4.1.0" + lazystream "^1.0.0" + lodash "^4.8.0" + normalize-path "^2.0.0" + readable-stream "^2.0.0" + +archiver@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/archiver/-/archiver-1.3.0.tgz#4f2194d6d8f99df3f531e6881f14f15d55faaf22" + dependencies: + archiver-utils "^1.3.0" + async "^2.0.0" + buffer-crc32 "^0.2.1" + glob "^7.0.0" + lodash "^4.8.0" + readable-stream "^2.0.0" + tar-stream "^1.5.0" + walkdir "^0.0.11" + zip-stream "^1.1.0" + argparse@^1.0.7: version "1.0.9" resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.9.tgz#73d83bc263f86e97f8cc4f6bae1b0e90a7d22c86" @@ -85,6 +110,12 @@ ast-types@0.x.x: version "0.9.12" resolved "https://registry.yarnpkg.com/ast-types/-/ast-types-0.9.12.tgz#b136300d67026625ae15326982ca9918e5db73c9" +async@^2.0.0: + version "2.5.0" + resolved "https://registry.yarnpkg.com/async/-/async-2.5.0.tgz#843190fd6b7357a0b9e1c956edddd5ec8462b54d" + dependencies: + lodash "^4.14.0" + aws-sdk-mock@^1.6.1: version "1.7.0" resolved "https://registry.yarnpkg.com/aws-sdk-mock/-/aws-sdk-mock-1.7.0.tgz#7698b3ba82f493f71ff060ae2123cd0806ad8676" @@ -123,6 +154,12 @@ base64-js@^1.0.2: version "1.2.0" resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.2.0.tgz#a39992d723584811982be5e290bb6a53d86700f1" +bl@^1.0.0: + version "1.2.1" + resolved "https://registry.yarnpkg.com/bl/-/bl-1.2.1.tgz#cac328f7bee45730d404b692203fcb590e172d5e" + dependencies: + readable-stream "^2.0.5" + brace-expansion@^1.1.7: version "1.1.8" resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.8.tgz#c07b211c7c952ec1f8efd51a77ef0d1d3990a292" @@ -134,6 +171,10 @@ browser-stdout@1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/browser-stdout/-/browser-stdout-1.3.0.tgz#f351d32969d32fa5d7a5567154263d928ae3bd1f" +buffer-crc32@^0.2.1: + version "0.2.13" + resolved "https://registry.yarnpkg.com/buffer-crc32/-/buffer-crc32-0.2.13.tgz#0d333e3f00eac50aa1454abd30ef8c2a5d9a7242" + buffer@5.0.6: version "5.0.6" resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.0.6.tgz#2ea669f7eec0b6eda05b08f8b5ff661b28573588" @@ -208,6 +249,15 @@ commander@2.9.0, commander@^2.5.0: dependencies: graceful-readlink ">= 1.0.0" +compress-commons@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/compress-commons/-/compress-commons-1.2.0.tgz#58587092ef20d37cb58baf000112c9278ff73b9f" + dependencies: + buffer-crc32 "^0.2.1" + crc32-stream "^2.0.0" + normalize-path "^2.0.0" + readable-stream "^2.0.0" + concat-map@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" @@ -228,6 +278,17 @@ core-util-is@~1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" +crc32-stream@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/crc32-stream/-/crc32-stream-2.0.0.tgz#e3cdd3b4df3168dd74e3de3fbbcb7b297fe908f4" + dependencies: + crc "^3.4.4" + readable-stream "^2.0.0" + +crc@^3.4.4: + version "3.4.4" + resolved "https://registry.yarnpkg.com/crc/-/crc-3.4.4.tgz#9da1e980e3bd44fc5c93bf5ab3da3378d85e466b" + crypto-browserify@1.0.9: version "1.0.9" resolved "https://registry.yarnpkg.com/crypto-browserify/-/crypto-browserify-1.0.9.tgz#cc5449685dfb85eb11c9828acc7cb87ab5bbfcc0" @@ -334,6 +395,12 @@ dotenv@^0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-0.4.0.tgz#f6fb351363c2d92207245c737802c9ab5ae1495a" +end-of-stream@^1.0.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.0.tgz#7a90d833efda6cfa6eac0f4949dbb0fad3a63206" + dependencies: + once "^1.4.0" + error-ex@^1.2.0: version "1.3.1" resolved "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.1.tgz#f855a86ce61adc4e8621c3cda21e7a7612c3a8dc" @@ -732,7 +799,7 @@ globby@^5.0.0: pify "^2.0.0" pinkie-promise "^2.0.0" -graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.1.9: +graceful-fs@^4.1.0, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.1.9: version "4.1.11" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658" @@ -967,6 +1034,12 @@ klaw@^1.0.0: optionalDependencies: graceful-fs "^4.1.9" +lazystream@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/lazystream/-/lazystream-1.0.0.tgz#f6995fe0f820392f61396be89462407bb77168e4" + dependencies: + readable-stream "^2.0.5" + levn@^0.3.0, levn@~0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/levn/-/levn-0.3.0.tgz#3b09924edf9f083c0490fdd4c0bc4421e04764ee" @@ -1041,7 +1114,7 @@ lodash.keys@^3.0.0: lodash.isarguments "^3.0.0" lodash.isarray "^3.0.0" -lodash@^4.0.0, lodash@^4.3.0: +lodash@^4.0.0, lodash@^4.14.0, lodash@^4.3.0, lodash@^4.8.0: version "4.17.4" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" @@ -1119,6 +1192,12 @@ node-zip@^1.1.0: dependencies: jszip "2.5.0" +normalize-path@^2.0.0: + version "2.1.1" + resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-2.1.1.tgz#1ab28b556e198363a8c1a6f7e6fa20137fe6aed9" + dependencies: + remove-trailing-separator "^1.0.1" + number-is-nan@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d" @@ -1139,7 +1218,7 @@ object.assign@^4.0.4: function-bind "^1.1.0" object-keys "^1.0.10" -once@^1.3.0: +once@^1.3.0, once@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" dependencies: @@ -1325,7 +1404,7 @@ readable-stream@1.1.x: isarray "0.0.1" string_decoder "~0.10.x" -readable-stream@2, readable-stream@^2.2.2: +readable-stream@2, readable-stream@^2.0.0, readable-stream@^2.0.5, readable-stream@^2.2.2: version "2.2.11" resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.2.11.tgz#0796b31f8d7688007ff0b93a8088d34aa17c0f72" dependencies: @@ -1351,6 +1430,10 @@ rechoir@^0.6.2: dependencies: resolve "^1.1.6" +remove-trailing-separator@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/remove-trailing-separator/-/remove-trailing-separator-1.0.2.tgz#69b062d978727ad14dc6b56ba4ab772fd8d70511" + require-uncached@^1.0.2: version "1.0.3" resolved "https://registry.yarnpkg.com/require-uncached/-/require-uncached-1.0.3.tgz#4e0d56d6c9662fd31e43011c4b95aa49955421d3" @@ -1548,6 +1631,15 @@ table@^3.7.8: slice-ansi "0.0.4" string-width "^2.0.0" +tar-stream@^1.5.0: + version "1.5.4" + resolved "https://registry.yarnpkg.com/tar-stream/-/tar-stream-1.5.4.tgz#36549cf04ed1aee9b2a30c0143252238daf94016" + dependencies: + bl "^1.0.0" + end-of-stream "^1.0.0" + readable-stream "^2.0.0" + xtend "^4.0.0" + text-table@~0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4" @@ -1617,6 +1709,10 @@ uuid@3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.0.1.tgz#6544bba2dfda8c1cf17e629a3a305e2bb1fee6c1" +walkdir@^0.0.11: + version "0.0.11" + resolved "https://registry.yarnpkg.com/walkdir/-/walkdir-0.0.11.tgz#a16d025eb931bd03b52f308caed0f40fcebe9532" + wordwrap@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb" @@ -1651,3 +1747,12 @@ xregexp@2.0.0: xtend@^4.0.0, xtend@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af" + +zip-stream@^1.1.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/zip-stream/-/zip-stream-1.2.0.tgz#a8bc45f4c1b49699c6b90198baacaacdbcd4ba04" + dependencies: + archiver-utils "^1.3.0" + compress-commons "^1.2.0" + lodash "^4.8.0" + readable-stream "^2.0.0" From 3d133abcb1359ed629d028267fb720c55f2e65e4 Mon Sep 17 00:00:00 2001 From: abetomo Date: Mon, 26 Jun 2017 12:18:41 +0900 Subject: [PATCH 02/11] Fix to use `archiver` instead of `node-zip` We want to keep file mode. --- lib/main.js | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/lib/main.js b/lib/main.js index a3770efb..3204c7e0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -1,6 +1,7 @@ 'use strict' const path = require('path') +const os = require('os') const aws = require('aws-sdk') const exec = require('child_process').exec const execSync = require('child_process').execSync @@ -8,7 +9,7 @@ const execFile = require('child_process').execFile const fs = require('fs-extra') const packageJson = require(path.join(__dirname, '..', 'package.json')) const minimatch = require('minimatch') -const zip = new (require('node-zip'))() +const archiver = require('archiver') const dotenv = require('dotenv') const proxy = require('proxy-agent') const ScheduleEvents = require(path.join(__dirname, 'schedule_events')) @@ -373,23 +374,41 @@ Lambda.prototype._postInstallScript = (program, codeDirectory) => { } Lambda.prototype._zip = (program, codeDirectory) => { - const options = { - type: 'nodebuffer', - compression: 'DEFLATE' - } - console.log('=> Zipping repo. This might take up to 30 seconds') + + const tmpZipFile = path.join(os.tmpdir(), +(new Date()) + '.zip') + const output = fs.createWriteStream(tmpZipFile) + const archive = archiver('zip', { + zlib: { level: 9 } // Sets the compression level. + }) return new Promise((resolve) => { + output.on('close', () => { + const contents = fs.readFileSync(tmpZipFile) + fs.unlinkSync(tmpZipFile) + resolve(contents) + }) + archive.pipe(output) fs.walk(codeDirectory) .on('data', (file) => { - if (!file.stats.isDirectory()) { - const content = fs.readFileSync(file.path) - const filePath = file.path.replace(path.join(codeDirectory, path.sep), '') - zip.file(filePath, content) + if (file.stats.isDirectory()) return + + const filePath = file.path.replace(path.join(codeDirectory, path.sep), '') + if (file.stats.isSymbolicLink()) { + // # archiver.js + // Implementation supporting symlink has been done, + // but it seems that release has not been done yet } + + archive.append( + fs.createReadStream(file.path), + { + name: filePath, + stats: file.stats + } + ) }) .on('end', () => { - resolve(zip.generate(options)) + archive.finalize() }) }) } From f07f04bf1008900861112d39aaf9b0f83a2d5bc7 Mon Sep 17 00:00:00 2001 From: abetomo Date: Mon, 26 Jun 2017 12:21:22 +0900 Subject: [PATCH 03/11] Add test of file mode --- test/main.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/test/main.js b/test/main.js index e0e29881..f871d185 100644 --- a/test/main.js +++ b/test/main.js @@ -522,15 +522,23 @@ describe('lib/main', function () { }) }) - it('zips the file and has an index.js file', function () { + it('Compress the file. `index.js` and `bin/uuid` are included and the permission is also preserved.', function () { _timeout({ this: this, sec: 30 }) // give it time to zip return lambda._zip(program, codeDirectory).then((data) => { const archive = new Zip(data) - const contents = Object.keys(archive.files).map((k) => { - return archive.files[k].name.toString() - }) - assert.include(contents, 'index.js') + assert.include(archive.files['index.js'].name, 'index.js') + assert.equal( + archive.files['index.js'].unixPermissions.toString(8), + '100644' + ) + + const binUuid = path.join('node_modules', 'uuid', 'bin', 'uuid') + assert.include(archive.files[binUuid].name, binUuid) + assert.equal( + archive.files[binUuid].unixPermissions.toString(8), + '100755' + ) }) }) }) From ccd85ba7a7d74be1965ca2a66682ccb0b5187e4e Mon Sep 17 00:00:00 2001 From: abetomo Date: Mon, 26 Jun 2017 12:35:29 +0900 Subject: [PATCH 04/11] Fix to test mode in non-Windows --- test/main.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/test/main.js b/test/main.js index f871d185..2adc5225 100644 --- a/test/main.js +++ b/test/main.js @@ -528,17 +528,19 @@ describe('lib/main', function () { return lambda._zip(program, codeDirectory).then((data) => { const archive = new Zip(data) assert.include(archive.files['index.js'].name, 'index.js') - assert.equal( - archive.files['index.js'].unixPermissions.toString(8), - '100644' - ) - const binUuid = path.join('node_modules', 'uuid', 'bin', 'uuid') assert.include(archive.files[binUuid].name, binUuid) - assert.equal( - archive.files[binUuid].unixPermissions.toString(8), - '100755' - ) + + if (process.platform !== 'win32') { + assert.equal( + archive.files['index.js'].unixPermissions.toString(8), + '100644' + ) + assert.equal( + archive.files[binUuid].unixPermissions.toString(8), + '100755' + ) + } }) }) }) From f563eb60b4ec8bf07cba94a6fcc55dc5fd1e937c Mon Sep 17 00:00:00 2001 From: abetomo Date: Mon, 26 Jun 2017 12:58:09 +0900 Subject: [PATCH 05/11] Modify the file used for testing --- test/main.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/main.js b/test/main.js index 2adc5225..96a21b24 100644 --- a/test/main.js +++ b/test/main.js @@ -522,14 +522,14 @@ describe('lib/main', function () { }) }) - it('Compress the file. `index.js` and `bin/uuid` are included and the permission is also preserved.', function () { + it('Compress the file. `index.js` and `rimraf/bin.js` are included and the permission is also preserved.', function () { _timeout({ this: this, sec: 30 }) // give it time to zip return lambda._zip(program, codeDirectory).then((data) => { const archive = new Zip(data) assert.include(archive.files['index.js'].name, 'index.js') - const binUuid = path.join('node_modules', 'uuid', 'bin', 'uuid') - assert.include(archive.files[binUuid].name, binUuid) + const rimrafBin = path.join('node_modules', 'rimraf', 'bin.js') + assert.include(archive.files[rimrafBin].name, rimrafBin) if (process.platform !== 'win32') { assert.equal( @@ -537,7 +537,7 @@ describe('lib/main', function () { '100644' ) assert.equal( - archive.files[binUuid].unixPermissions.toString(8), + archive.files[rimrafBin].unixPermissions.toString(8), '100755' ) } From e7a6ce792ffb851e8fd732bab1095e18e87bfacf Mon Sep 17 00:00:00 2001 From: abetomo Date: Mon, 26 Jun 2017 13:06:22 +0900 Subject: [PATCH 06/11] Modify the file used for testing --- test/main.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/main.js b/test/main.js index 96a21b24..b48f7b84 100644 --- a/test/main.js +++ b/test/main.js @@ -522,14 +522,14 @@ describe('lib/main', function () { }) }) - it('Compress the file. `index.js` and `rimraf/bin.js` are included and the permission is also preserved.', function () { + it('Compress the file. `index.js` and `bin/node-lambda` are included and the permission is also preserved.', function () { _timeout({ this: this, sec: 30 }) // give it time to zip return lambda._zip(program, codeDirectory).then((data) => { const archive = new Zip(data) assert.include(archive.files['index.js'].name, 'index.js') - const rimrafBin = path.join('node_modules', 'rimraf', 'bin.js') - assert.include(archive.files[rimrafBin].name, rimrafBin) + const binNodeLambda = path.join('bin', 'node-lambda') + assert.include(archive.files[binNodeLambda].name, binNodeLambda) if (process.platform !== 'win32') { assert.equal( @@ -537,7 +537,7 @@ describe('lib/main', function () { '100644' ) assert.equal( - archive.files[rimrafBin].unixPermissions.toString(8), + archive.files[binNodeLambda].unixPermissions.toString(8), '100755' ) } From bfea2d4296d61cf06aa10d991c637d3941b66fa8 Mon Sep 17 00:00:00 2001 From: abetomo Date: Mon, 26 Jun 2017 13:24:30 +0900 Subject: [PATCH 07/11] Modify archive.files's key archive.files's key is a slash delimiter regardless of platform. --- test/main.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/main.js b/test/main.js index b48f7b84..846c4e51 100644 --- a/test/main.js +++ b/test/main.js @@ -528,8 +528,10 @@ describe('lib/main', function () { return lambda._zip(program, codeDirectory).then((data) => { const archive = new Zip(data) assert.include(archive.files['index.js'].name, 'index.js') - const binNodeLambda = path.join('bin', 'node-lambda') - assert.include(archive.files[binNodeLambda].name, binNodeLambda) + assert.include( + archive.files['bin/node-lambda'].name, + path.join('bin', 'node-lambda') + ) if (process.platform !== 'win32') { assert.equal( @@ -537,7 +539,7 @@ describe('lib/main', function () { '100644' ) assert.equal( - archive.files[binNodeLambda].unixPermissions.toString(8), + archive.files['bin/node-lambda'].unixPermissions.toString(8), '100755' ) } From 4cd0c75bbf7d9b9795f6ca784c42d109a77d4d25 Mon Sep 17 00:00:00 2001 From: abetomo Date: Mon, 26 Jun 2017 13:34:40 +0900 Subject: [PATCH 08/11] Modify archive.files's name archive.files's name is a slash delimiter regardless of platform. --- test/main.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/main.js b/test/main.js index 846c4e51..dde034e2 100644 --- a/test/main.js +++ b/test/main.js @@ -528,10 +528,7 @@ describe('lib/main', function () { return lambda._zip(program, codeDirectory).then((data) => { const archive = new Zip(data) assert.include(archive.files['index.js'].name, 'index.js') - assert.include( - archive.files['bin/node-lambda'].name, - path.join('bin', 'node-lambda') - ) + assert.include(archive.files['bin/node-lambda'].name, 'bin/node-lambda') if (process.platform !== 'win32') { assert.equal( From 2e4f53e6fae7914905d2bf50dd5a338f41561326 Mon Sep 17 00:00:00 2001 From: abetomo Date: Mon, 26 Jun 2017 14:42:41 +0900 Subject: [PATCH 09/11] Modify path delimiter archive.files's name is a slash delimiter regardless of platform. --- test/main.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/main.js b/test/main.js index dde034e2..0341a7ae 100644 --- a/test/main.js +++ b/test/main.js @@ -545,6 +545,7 @@ describe('lib/main', function () { }) describe('_archive', () => { + // archive.files's name is a slash delimiter regardless of platform. it('installs and zips with an index.js file and node_modules/aws-sdk', function (done) { _timeout({ this: this, sec: 30 }) // give it time to zip @@ -555,7 +556,7 @@ describe('lib/main', function () { return archive.files[k].name.toString() }) assert.include(contents, 'index.js') - assert.include(contents, path.join('node_modules', 'aws-sdk', 'lib', 'aws.js')) + assert.include(contents, 'node_modules/aws-sdk/lib/aws.js') done() }) }) @@ -583,9 +584,9 @@ describe('lib/main', function () { }); [ 'testa', - path.join('d', 'testb'), - path.join('node_modules', 'a') - ].forEach(function (needle) { + 'd/testb', + 'node_modules/a' + ].forEach((needle) => { assert.include(contents, needle, `Target: "${needle}"`) }) done() @@ -649,7 +650,7 @@ describe('lib/main', function () { return archive.files[k].name.toString() }) assert.include(contents, 'index.js') - assert.include(contents, path.join('node_modules', 'aws-sdk', 'lib', 'aws.js')) + assert.include(contents, 'node_modules/aws-sdk/lib/aws.js') done() }) }) From 5d6cdfd727d615a8232cf6aa626d4aa0c6d69913 Mon Sep 17 00:00:00 2001 From: abetomo Date: Mon, 26 Jun 2017 14:43:03 +0900 Subject: [PATCH 10/11] Modify to Arrow function and modify of variable declaration --- test/main.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/test/main.js b/test/main.js index 0341a7ae..d281ab4a 100644 --- a/test/main.js +++ b/test/main.js @@ -563,10 +563,8 @@ describe('lib/main', function () { it('packages a prebuilt module without installing', function (done) { _timeout({ this: this, sec: 30 }) // give it time to zip - var buildDir = '.build_' + Date.now() - after(function () { - fs.removeSync(buildDir) - }) + let buildDir = '.build_' + Date.now() + after(() => fs.removeSync(buildDir)) fs.mkdirSync(buildDir) fs.mkdirSync(path.join(buildDir, 'd')) @@ -576,10 +574,10 @@ describe('lib/main', function () { fs.writeFileSync(path.join(buildDir, 'd', 'testb'), '...') program.prebuiltDirectory = buildDir - lambda._archive(program, function (err, data) { + lambda._archive(program, (err, data) => { assert.isNull(err) - var archive = new Zip(data) - var contents = Object.keys(archive.files).map(function (k) { + const archive = new Zip(data) + const contents = Object.keys(archive.files).map((k) => { return archive.files[k].name.toString() }); [ From 0db10630cda36f4017df25e2075ff678af86f6d1 Mon Sep 17 00:00:00 2001 From: abetomo Date: Mon, 26 Jun 2017 15:08:29 +0900 Subject: [PATCH 11/11] Fix to get mode from file --- test/main.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/main.js b/test/main.js index d281ab4a..ad09bd18 100644 --- a/test/main.js +++ b/test/main.js @@ -526,18 +526,21 @@ describe('lib/main', function () { _timeout({ this: this, sec: 30 }) // give it time to zip return lambda._zip(program, codeDirectory).then((data) => { + const indexJsStat = fs.lstatSync('index.js') + const binNodeLambdaStat = fs.lstatSync(path.join('bin', 'node-lambda')) + const archive = new Zip(data) assert.include(archive.files['index.js'].name, 'index.js') assert.include(archive.files['bin/node-lambda'].name, 'bin/node-lambda') if (process.platform !== 'win32') { assert.equal( - archive.files['index.js'].unixPermissions.toString(8), - '100644' + archive.files['index.js'].unixPermissions, + indexJsStat.mode ) assert.equal( - archive.files['bin/node-lambda'].unixPermissions.toString(8), - '100755' + archive.files['bin/node-lambda'].unixPermissions, + binNodeLambdaStat.mode ) } })