From ddbacce4e92ae9d606d051eea37502710d5fa2c8 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Wed, 29 May 2019 01:13:16 +0700 Subject: [PATCH] Require Node.js 8 --- .travis.yml | 2 +- index.js | 25 ++++++++++++++----------- package.json | 19 +++++++++++-------- readme.md | 11 +++-------- test.js | 20 ++++++++++++++++---- 5 files changed, 45 insertions(+), 32 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2ae9d62..f98fed0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: node_js node_js: + - '12' - '10' - '8' - - '6' diff --git a/index.js b/index.js index c0343d4..d484c2f 100644 --- a/index.js +++ b/index.js @@ -11,14 +11,15 @@ module.exports = (filename, options) => { throw new PluginError('gulp-zip', '`filename` required'); } - options = Object.assign({ - compress: true - }, options); + options = { + compress: true, + ...options + }; let firstFile; const zip = new Yazl.ZipFile(); - return through.obj((file, enc, cb) => { + return through.obj((file, encoding, callback) => { if (!firstFile) { firstFile = file; } @@ -27,7 +28,7 @@ module.exports = (filename, options) => { const pathname = file.relative.replace(/\\/g, '/'); if (!pathname) { - cb(); + callback(); return; } @@ -52,14 +53,16 @@ module.exports = (filename, options) => { } } - cb(); - }, function (cb) { + callback(); + }, function (callback) { if (!firstFile) { - cb(); + callback(); return; } - getStream.buffer(zip.outputStream).then(data => { + (async () => { + const data = await getStream.buffer(zip.outputStream); + this.push(new Vinyl({ cwd: firstFile.cwd, base: firstFile.base, @@ -67,8 +70,8 @@ module.exports = (filename, options) => { contents: data })); - cb(); - }); + callback(); + })(); zip.end(); }); diff --git a/package.json b/package.json index efa2b28..7805194 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "url": "sindresorhus.com" }, "engines": { - "node": ">=6" + "node": ">=8" }, "scripts": { "test": "xo && ava" @@ -28,18 +28,21 @@ "file" ], "dependencies": { - "get-stream": "^3.0.0", - "plugin-error": "^0.1.2", - "through2": "^2.0.1", + "get-stream": "^5.1.0", + "plugin-error": "^1.0.1", + "through2": "^3.0.1", "vinyl": "^2.1.0", - "yazl": "^2.1.0" + "yazl": "^2.5.1" }, "devDependencies": { - "ava": "*", + "ava": "^1.4.1", "decompress-unzip": "^3.0.0", - "gulp": "^3.9.1", + "gulp": "^4.0.2", "vinyl-assign": "^1.2.1", "vinyl-file": "^3.0.0", - "xo": "*" + "xo": "^0.24.0" + }, + "peerDependencies": { + "gulp": ">=4" } } diff --git a/readme.md b/readme.md index 4ef9daa..683d449 100644 --- a/readme.md +++ b/readme.md @@ -28,7 +28,7 @@ gulp.task('default', () => Supports [streaming mode](https://github.com/gulpjs/gulp/blob/master/docs/API.md#optionsbuffer). -### zip(filename, [options]) +### zip(filename, options?) #### filename @@ -36,7 +36,7 @@ Type: `string` #### options -Type: `Object` +Type: `object` ##### compress @@ -50,9 +50,4 @@ Default: `undefined` Overrides the modification timestamp for all files added to the archive. -Tip: Setting it to the same value across executions enables you to create stable archives—archives that change only when the contents of their entries change, regardless of whether those entries were "touched" or regenerated. - - -## License - -MIT © [Sindre Sorhus](https://sindresorhus.com) +Tip: Setting it to the same value across executions enables you to create stable archives that change only when the contents of their entries change, regardless of whether those entries were "touched" or regenerated. diff --git a/test.js b/test.js index 3559683..bd02f07 100644 --- a/test.js +++ b/test.js @@ -15,7 +15,10 @@ test.cb('should zip files', t => { const stats = fs.statSync(path.join(__dirname, 'fixture/fixture.txt')); const files = []; - unzipper.on('data', files.push.bind(files)); + unzipper.on('data', file => { + files.push(file); + }); + unzipper.on('end', () => { t.is(files[0].path, 'fixture.txt'); t.is(files[1].path, 'fixture2.txt'); @@ -65,7 +68,10 @@ test.cb('should zip files (using streams)', t => { const unzipper = unzip(); const files = []; - unzipper.on('data', files.push.bind(files)); + unzipper.on('data', file => { + files.push(file); + }); + unzipper.on('end', () => { t.is(files[0].path, 'fixture/fixture.txt'); t.is(files[0].contents.toString(), 'hello world\n'); @@ -93,7 +99,10 @@ test.cb('should not skip empty directories', t => { } }; - unzipper.on('data', files.push.bind(files)); + unzipper.on('data', file => { + files.push(file); + }); + unzipper.on('end', () => { t.is(files[0].path, 'foo'); t.end(); @@ -128,7 +137,9 @@ test.cb('when `options.modifiedTime` is specified, should override files\' actua // Save each file to an array as it emerges from the end of the pipeline. const files = []; - unzipper.on('data', files.push.bind(files)); + unzipper.on('data', file => { + files.push(file); + }); // Once the pipeline has completed, ensure that all files that went through it have the manually specified // timestamp (to the granularity that the zip format supports). @@ -136,6 +147,7 @@ test.cb('when `options.modifiedTime` is specified, should override files\' actua for (const file of files) { t.deepEqual(yazl.dateToDosDateTime(file.stat.mtime), yazl.dateToDosDateTime(modifiedTime)); } + t.end(); });