Skip to content

Commit

Permalink
reconstruct outputs everytime
Browse files Browse the repository at this point in the history
fix browserify#68, browserify#59

- To avoid writing to ended writeStream, outputs will be constructed everytime
- In the scenario that user wanna use outpipe, the `outopt` will be
kept as string, so we can determine the user's attempt in later codes
and do the relavant opperations
  • Loading branch information
jcppman committed Jun 19, 2015
1 parent dfcf69a commit 0afba71
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,6 @@ module.exports = function f (b, opts) {
var needRecords = !files.length;

var outopt = defined(opts.outputs, opts.output, opts.o);
if (outopt && !isarray(outopt)) outopt = [outopt];
var outputs = defined(outopt, []).map(function (o) {
if (isStream(o)) return o;
else return fs.createWriteStream(o);
});
if (!isarray(outputs) && isStream(outputs)) outputs = [ outputs ];
else if (!isarray(outputs)) outputs = [];

function moreOutputs (file) {
if (isarray(outopt)) return [];
if (!outopt) return [];
var xopts = { env: xtend(process.env, { FILE: file }) };
return [ outpipe(outopt, xopts) ];
}

opts.objectMode = true;
opts.raw = true;
Expand All @@ -57,6 +43,23 @@ module.exports = function f (b, opts) {
addHooks();

function addHooks () {
var outputs;
if (isarray(outopt)) {
outputs = outopt.map(function (o) {
if (isStream(o)) return o;
return fs.createWriteStream(o);
});
} else {
outputs = [];
}

function moreOutputs (file) {
if (isarray(outopt)) return [];
if (!outopt) return [];
var xopts = { env: xtend(process.env, { FILE: file }) };
return [ outpipe(outopt, xopts) ];
}

b.pipeline.get('record').push(through.obj(function(row, enc, next) {
if (row.file && needRecords) {
files.push(row.file);
Expand Down

0 comments on commit 0afba71

Please sign in to comment.