Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send options to through2 via dest(), src(), symlink() #107

Merged
merged 18 commits into from
Dec 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ Default: `true`
##### other

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

### `dest(folder[, options])`

Expand Down Expand Up @@ -224,6 +225,10 @@ Type: `Boolean` or `Object`

Default: `undefined` (do not write sourcemaps)

##### other
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should pull the documentation from the through2 repo instead of linking

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally agree with surfacing docs but I don't think people should be using these options so I'm good with them not being surfaced.


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

### `symlink(folder[, options])`

Takes a folder path string or a function as the first argument and an options object as the second. If given a function, it will be called with each [vinyl] `File` object and must return a folder path.
Expand Down Expand Up @@ -258,9 +263,14 @@ Type: `Number`

Default: The process mode.

##### other

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

[glob-stream]: https://github.com/gulpjs/glob-stream
[gulp-sourcemaps]: https://github.com/floridoo/gulp-sourcemaps
[node-glob]: https://github.com/isaacs/node-glob
[through2]: https://github.com/rvagg/through2
[vinyl]: https://github.com/gulpjs/vinyl

[downloads-image]: http://img.shields.io/npm/dm/vinyl-fs.svg
Expand Down
2 changes: 1 addition & 1 deletion lib/dest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +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
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@
"engines": {
"node": ">=0.10"
},
"license": "MIT"
"licenses": "MIT"
}
21 changes: 21 additions & 0 deletions test/dest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1336,4 +1336,25 @@ describe('dest stream', function() {
.pipe(destStream)
.once('finish', done);
});

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();
});

});