Skip to content

Commit d553e74

Browse files
Vineet Hawalphated
Vineet Hawal
authored andcommitted
Send options to through2
1 parent e566008 commit d553e74

File tree

8 files changed

+58
-10
lines changed

8 files changed

+58
-10
lines changed

README.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ fs.src(['*.js', '!b*.js'])
7171

7272
- Any glob-related options are documented in [glob-stream] and [node-glob].
7373

74+
- Any through2-related options are documented in [through2]
75+
7476
- Returns a Readable stream by default, or a Duplex stream if the `passthrough` option is set to `true`.
7577
- This stream emits matching [vinyl] File objects.
7678

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

114+
- Any through2-related options are documented in [through2]
115+
112116
- Returns a Readable/Writable stream.
113117
- On write the stream will save the [vinyl] File to disk at the folder/cwd specified.
114118
- After writing the file to disk, it will be emitted from the stream so you can keep piping these around.
@@ -132,6 +136,8 @@ _Note:_ UTF-8 BOM will be stripped from all UTF-8 files read with `.src`.
132136
- dirMode - Specify the mode the directory should be created with.
133137
- Default is the process mode.
134138

139+
- Any through2-related options are documented in [through2]
140+
135141
- Returns a Readable/Writable stream.
136142
- On write the stream will create a symbolic link (i.e. symlink) on disk at the folder/cwd specified.
137143
- After creating the symbolic link, it will be emitted from the stream so you can keep piping these around.
@@ -141,8 +147,9 @@ _Note:_ UTF-8 BOM will be stripped from all UTF-8 files read with `.src`.
141147
[glob-stream]: https://github.com/gulpjs/glob-stream
142148
[node-glob]: https://github.com/isaacs/node-glob
143149
[gaze]: https://github.com/shama/gaze
144-
[glob-watcher]: https://github.com/gulpjs/glob-watcher
145-
[vinyl]: https://github.com/gulpjs/vinyl
150+
[glob-watcher]: https://github.com/wearefractal/glob-watcher
151+
[vinyl]: https://github.com/wearefractal/vinyl
152+
[through2]: https://github.com/rvagg/through2
146153
[npm-url]: https://www.npmjs.com/package/vinyl-fs
147154
[npm-image]: https://badge.fury.io/js/vinyl-fs.svg
148155
[travis-url]: https://travis-ci.org/gulpjs/vinyl-fs

lib/dest/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ function dest(outFolder, opt) {
2121
});
2222
}
2323

24-
var saveStream = through2.obj(saveFile);
25-
24+
var saveStream = through2.obj(opt, saveFile);
2625
if (!opt.sourcemaps) {
2726
// Sink the save stream to start flowing
2827
// Do this on nextTick, it will flow at slowest speed of piped streams

lib/src/getContents/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var bufferFile = require('./bufferFile');
77
var streamFile = require('./streamFile');
88

99
function getContents(opt) {
10-
return through2.obj(function(file, enc, cb) {
10+
return through2.obj(opt, function(file, enc, cb) {
1111
// don't fail to read a directory
1212
if (file.isDirectory()) {
1313
return readDir(file, opt, cb);

lib/src/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
var assign = require('object-assign');
4-
var through = require('through2');
4+
var through2 = require('through2');
55
var gs = require('glob-stream');
66
var File = require('vinyl');
77
var duplexify = require('duplexify');
@@ -37,7 +37,7 @@ function src(glob, opt) {
3737

3838
var outputStream = globStream
3939
.pipe(resolveSymlinks(options))
40-
.pipe(through.obj(createFile));
40+
.pipe(through2.obj(opt, createFile));
4141

4242
if (options.since != null) {
4343
outputStream = outputStream
@@ -50,7 +50,7 @@ function src(glob, opt) {
5050
}
5151

5252
if (options.passthrough === true) {
53-
inputPass = through.obj();
53+
inputPass = through2.obj(opt);
5454
outputStream = duplexify.obj(inputPass, merge(outputStream, inputPass));
5555
}
5656
if (options.sourcemaps === true) {

lib/src/resolveSymlinks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function resolveSymlinks(options) {
3333
});
3434
}
3535

36-
return through2.obj(resolveFile);
36+
return through2.obj(options, resolveFile);
3737
}
3838

3939
module.exports = resolveSymlinks;

lib/symlink/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function symlink(outFolder, opt) {
2121
});
2222
}
2323

24-
var stream = through2.obj(linkFile);
24+
var stream = through2.obj(opt, linkFile);
2525
// TODO: option for either backpressure or lossy
2626
stream.resume();
2727
return stream;

test/dest.js

+21
Original file line numberDiff line numberDiff line change
@@ -1326,4 +1326,25 @@ describe('dest stream', function() {
13261326
.pipe(destStream)
13271327
.pipe(slowCountFiles);
13281328
});
1329+
1330+
it('should pass options to through2',function(done){
1331+
var srcPath = path.join(__dirname, './fixtures/test.coffee');
1332+
var content = fs.readFileSync(srcPath);
1333+
var stream = vfs.dest('./out-fixtures/', {cwd: __dirname, objectMode: false});
1334+
1335+
stream.on('error', function(err){
1336+
err.should.match(/Invalid non-string\/buffer chunk/);
1337+
done()
1338+
});
1339+
1340+
var file = new File({
1341+
path: srcPath,
1342+
cwd: __dirname,
1343+
contents: content
1344+
})
1345+
1346+
stream.write(file);
1347+
stream.end();
1348+
});
1349+
13291350
});

test/symlink.js

+21
Original file line numberDiff line numberDiff line change
@@ -415,4 +415,25 @@ describe('symlink stream', function() {
415415
stream.end();
416416
});
417417
});
418+
419+
it('should pass options to through2',function(done){
420+
var srcPath = path.join(__dirname, './fixtures/test.coffee');
421+
var content = fs.readFileSync(srcPath);
422+
var stream = vfs.symlink('./out-fixtures/', {cwd: __dirname, objectMode: false});
423+
424+
stream.on('error', function(err){
425+
err.should.match(/Invalid non-string\/buffer chunk/);
426+
done()
427+
});
428+
429+
var file = new File({
430+
path: srcPath,
431+
cwd: __dirname,
432+
contents: content
433+
})
434+
435+
stream.write(file);
436+
stream.end();
437+
});
438+
418439
});

0 commit comments

Comments
 (0)