Skip to content

Commit

Permalink
New: Pass options to through2 instances
Browse files Browse the repository at this point in the history
  • Loading branch information
Vineet Hawal authored and phated committed Nov 28, 2017
1 parent 7be0cfd commit bcfd342
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 10 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ fs.src(['*.js', '!b*.js'])
- `false` will make `file.symlink` equal the original symlink's target path.
- Any glob-related options are documented in [glob-stream] and [node-glob].

- Any through2-related options are documented in [through2]

- Returns a Readable stream by default, or a Duplex stream if the `passthrough` option is set to `true`.
- This stream emits matching [vinyl] File objects.

Expand Down Expand Up @@ -107,6 +109,8 @@ _Note:_ UTF-8 BOM will be stripped from all UTF-8 files read with `.src`.
- Any other options are passed through to `gulp-sourcemaps`
- fs.dest('./', {<br> sourcemaps: {<br> path: '.',<br> addComment: false,<br> includeContent: false<br> }<br>})

- Any through2-related options are documented in [through2]

- Returns a Readable/Writable stream.
- On write the stream will save the [vinyl] File to disk at the folder/cwd specified.
- After writing the file to disk, it will be emitted from the stream so you can keep piping these around.
Expand All @@ -129,6 +133,8 @@ _Note:_ UTF-8 BOM will be stripped from all UTF-8 files read with `.src`.
- dirMode - Specify the mode the directory should be created with.
- Default is the process mode.

- Any through2-related options are documented in [through2]

- Returns a Readable/Writable stream.
- On write the stream will create a symbolic link (i.e. symlink) on disk at the folder/cwd specified.
- After creating the symbolic link, it will be emitted from the stream so you can keep piping these around.
Expand All @@ -138,8 +144,9 @@ _Note:_ UTF-8 BOM will be stripped from all UTF-8 files read with `.src`.
[glob-stream]: https://github.com/gulpjs/glob-stream
[node-glob]: https://github.com/isaacs/node-glob
[gaze]: https://github.com/shama/gaze
[glob-watcher]: https://github.com/gulpjs/glob-watcher
[vinyl]: https://github.com/gulpjs/vinyl
[glob-watcher]: https://github.com/wearefractal/glob-watcher
[vinyl]: https://github.com/wearefractal/vinyl
[through2]: https://github.com/rvagg/through2
[npm-url]: https://www.npmjs.com/package/vinyl-fs
[npm-image]: https://badge.fury.io/js/vinyl-fs.svg
[travis-url]: https://travis-ci.org/gulpjs/vinyl-fs
Expand Down
3 changes: 1 addition & 2 deletions lib/dest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ function dest(outFolder, opt) {
});
}

var saveStream = through2.obj(saveFile);

var saveStream = through2.obj(opt, saveFile);
if (!opt.sourcemaps) {
// Sink the save stream to start flowing
// Do this on nextTick, it will flow at slowest speed of piped streams
Expand Down
2 changes: 1 addition & 1 deletion lib/src/getContents/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var bufferFile = require('./bufferFile');
var streamFile = require('./streamFile');

function getContents(opt) {
return through2.obj(function(file, enc, cb) {
return through2.obj(opt, function(file, enc, cb) {
// don't fail to read a directory
if (file.isDirectory()) {
return readDir(file, opt, cb);
Expand Down
6 changes: 3 additions & 3 deletions lib/src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var assign = require('object-assign');
var through = require('through2');
var through2 = require('through2');
var gs = require('glob-stream');
var File = require('vinyl');
var duplexify = require('duplexify');
Expand Down Expand Up @@ -37,7 +37,7 @@ function src(glob, opt) {

var outputStream = globStream
.pipe(resolveSymlinks(options))
.pipe(through.obj(createFile));
.pipe(through2.obj(opt, createFile));

if (options.since != null) {
outputStream = outputStream
Expand All @@ -50,7 +50,7 @@ function src(glob, opt) {
}

if (options.passthrough === true) {
inputPass = through.obj();
inputPass = through2.obj(opt);
outputStream = duplexify.obj(inputPass, merge(outputStream, inputPass));
}
if (options.sourcemaps === true) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/resolveSymlinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function resolveSymlinks(options) {
});
}

return through2.obj(resolveFile);
return through2.obj(options, resolveFile);
}

module.exports = resolveSymlinks;
2 changes: 1 addition & 1 deletion lib/symlink/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function symlink(outFolder, opt) {
});
}

var stream = through2.obj(linkFile);
var stream = through2.obj(opt, linkFile);
// TODO: option for either backpressure or lossy
stream.resume();
return stream;
Expand Down
21 changes: 21 additions & 0 deletions test/dest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1326,4 +1326,25 @@ describe('dest stream', function() {
.pipe(destStream)
.pipe(slowCountFiles);
});

it('should pass options to through2',function(done){
var srcPath = path.join(__dirname, './fixtures/test.coffee');
var content = fs.readFileSync(srcPath);
var stream = vfs.dest('./out-fixtures/', {cwd: __dirname, objectMode: false});

stream.on('error', function(err){
err.should.match(/Invalid non-string\/buffer chunk/);
done()
});

var file = new File({
path: srcPath,
cwd: __dirname,
contents: content
})

stream.write(file);
stream.end();
});

});
21 changes: 21 additions & 0 deletions test/symlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,4 +415,25 @@ describe('symlink stream', function() {
stream.end();
});
});

it('should pass options to through2',function(done){
var srcPath = path.join(__dirname, './fixtures/test.coffee');
var content = fs.readFileSync(srcPath);
var stream = vfs.symlink('./out-fixtures/', {cwd: __dirname, objectMode: false});

stream.on('error', function(err){
err.should.match(/Invalid non-string\/buffer chunk/);
done()
});

var file = new File({
path: srcPath,
cwd: __dirname,
contents: content
})

stream.write(file);
stream.end();
});

});

0 comments on commit bcfd342

Please sign in to comment.