Skip to content

Commit

Permalink
Require Node.js 8 and Gulp 4
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Aug 18, 2019
1 parent 19ef2c0 commit 5f6103e
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 39 deletions.
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* text=auto
*.js text eol=lf
* text=auto eol=lf
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ node_js:
- '12'
- '10'
- '8'
- '6'
4 changes: 2 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const gulp = require('gulp');
const gzip = require('gulp-gzip');
const tar = require('.');

gulp.task('default', () => {
exports.default = () => {
// Tar in buffer mode
gulp.src('fixture/fixture.txt')
.pipe(tar('test1.tar'))
Expand All @@ -30,4 +30,4 @@ gulp.task('default', () => {
gulp.src('fixture/fixture.txt')
.pipe(tar('test_options.tar', {mtime: 0}))
.pipe(gulp.dest('dest'));
});
};
19 changes: 10 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,27 @@ module.exports = (filename, options) => {
let firstFile;
const archive = archiver('tar', options);

return through.obj((file, enc, cb) => {
return through.obj((file, encoding, callback) => {
if (file.relative === '') {
cb();
callback();
return;
}

if (firstFile === undefined) {
firstFile = file;
}

archive.append(file.contents, Object.assign({
archive.append(file.contents, {
name: file.relative.replace(/\\/g, '/') + (file.isNull() ? '/' : ''),
mode: file.stat && file.stat.mode,
date: file.stat && file.stat.mtime ? file.stat.mtime : null
}, options));
date: file.stat && file.stat.mtime ? file.stat.mtime : null,
...options
});

cb();
}, function (cb) {
callback();
}, function (callback) {
if (firstFile === undefined) {
cb();
callback();
return;
}

Expand All @@ -45,6 +46,6 @@ module.exports = (filename, options) => {
contents: archive
}));

cb();
callback();
});
};
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"url": "sindresorhus.com"
},
"engines": {
"node": ">=6"
"node": ">=8"
},
"scripts": {
"test": "xo && mocha"
Expand All @@ -32,17 +32,20 @@
"streams"
],
"dependencies": {
"archiver": "^1.0.0",
"plugin-error": "^0.1.2",
"through2": "^2.0.0",
"archiver": "^3.1.1",
"plugin-error": "^1.0.1",
"through2": "^3.0.1",
"vinyl": "^2.1.0"
},
"devDependencies": {
"gulp": "*",
"gulp": "^4.0.2",
"gulp-gzip": "^1.2.0",
"mocha": "*",
"tar-stream": "^1.0.2",
"mocha": "^6.2.0",
"tar-stream": "^2.1.0",
"vinyl-map": "^1.0.1",
"xo": "*"
"xo": "^0.24.0"
},
"peerDependencies": {
"gulp": ">=4"
}
}
13 changes: 4 additions & 9 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# gulp-tar [![Build Status](https://travis-ci.org/sindresorhus/gulp-tar.svg?branch=master)](https://travis-ci.org/sindresorhus/gulp-tar)

> Create [tarball](http://en.wikipedia.org/wiki/Tar_(computing)) from files
> Create [tarball](https://en.wikipedia.org/wiki/Tar_(computing)) from files

## Install
Expand All @@ -17,7 +17,7 @@ const gulp = require('gulp');
const tar = require('gulp-tar');
const gzip = require('gulp-gzip');

gulp.task('default', () =>
exports.default = () => (
gulp.src('src/*')
.pipe(tar('archive.tar'))
.pipe(gzip())
Expand All @@ -28,7 +28,7 @@ gulp.task('default', () =>

## API

### tar(filename, [options])
### tar(filename, options?)

#### filename

Expand All @@ -38,11 +38,6 @@ Filename for the output tar archive.

#### options

Type: `Object`
Type: `object`

Default options passed to [Archiver](https://github.com/archiverjs/node-archiver)'s [constructor](https://archiverjs.com/docs/Archiver.html) and merged into the [data](https://archiverjs.com/docs/global.html#TarEntryData) passed to its [`append`](https://archiverjs.com/docs/Archiver.html#append) method.


## License

MIT © [Sindre Sorhus](https://sindresorhus.com)
16 changes: 8 additions & 8 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ const vinylMap = require('vinyl-map');
const Vinyl = require('vinyl');
const tar = require('.');

it('should tar files in buffer mode', cb => {
it('should tar files in buffer mode', callback => {
const stream = tar('test.tar');

stream.on('data', file => {
assert.strictEqual(file.path, path.join(__dirname, 'fixture', 'test.tar'));
assert.strictEqual(file.relative, 'test.tar');
cb();
callback();
});

stream.write(new Vinyl({
Expand All @@ -34,7 +34,7 @@ it('should tar files in buffer mode', cb => {
stream.end();
});

it('should tar files in stream mode', cb => {
it('should tar files in stream mode', callback => {
const stream = tar('test.tar');

const stringStream1 = new Stream.Readable();
Expand All @@ -53,7 +53,7 @@ it('should tar files in stream mode', cb => {
assert.strictEqual(file.relative, 'test.tar');
});

stream.on('end', cb);
stream.on('end', callback);

stream.write(new Vinyl({
cwd: __dirname,
Expand All @@ -72,12 +72,12 @@ it('should tar files in stream mode', cb => {
stream.end();
});

it('should output file.contents as a Stream', cb => {
it('should output file.contents as a Stream', callback => {
const stream = tar('test.tar');

stream.on('data', file => {
assert(file.contents instanceof Stream, 'File contents should be a Stream object');
cb();
callback();
});

stream.write(new Vinyl({
Expand All @@ -90,7 +90,7 @@ it('should output file.contents as a Stream', cb => {
stream.end();
});

it.skip('should include directories', cb => {
it.skip('should include directories', callback => {
const stream = tar('test.tar');

const evaluate = vinylMap(code => {
Expand All @@ -101,7 +101,7 @@ it.skip('should include directories', cb => {
stream.on('end', () => {
assert.strictEqual(header.type, 'directory');
assert.strictEqual(header.name, 'fixture2/');
cb();
callback();
});

stream.resume();
Expand Down

0 comments on commit 5f6103e

Please sign in to comment.