diff --git a/lib/index.js b/lib/index.js index e4ff743..8c3c371 100644 --- a/lib/index.js +++ b/lib/index.js @@ -4,13 +4,28 @@ var stream = require("stream"); var combiner = require("stream-combiner2"); var plumber = require("gulp-plumber"); var namedLog = require("gulp-named-log"); +var util = require("util"); module.exports = function (name, streams) { var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; var logger = namedLog(name, options.logger); - var streamList = [plumber(logger.error)].concat(streams).concat([logger.stream()]); + var streamList = streams.concat([logger.stream()]); - return combiner.obj(streamList); + /* We need to patch in the `pipe` handler manually, as this monkeypatch doesn't + * carry over to Duplex streams that are created by `stream-combiner2`. The + * `stream-combiner2` library will take care of re-emitting the errors on the + * combined stream, so we don't need `gulp-plumber` in our actual pipeline. + */ + var plumberStream = plumber(function (err) { + logger.error(err.toString()); + /* Ensure that the task finishes, so as to not break `gulp.watch`. */ + this.emit("end"); + }); + var combinedStream = combiner.obj(streamList); + + plumberStream.pipe(combinedStream); + + return combinedStream; }; \ No newline at end of file diff --git a/src/index.js b/src/index.js index 805dd70..0709f7d 100644 --- a/src/index.js +++ b/src/index.js @@ -4,15 +4,28 @@ const stream = require("stream"); const combiner = require("stream-combiner2"); const plumber = require("gulp-plumber"); const namedLog = require("gulp-named-log"); +const util = require("util"); module.exports = function(name, streams, options = {}) { let logger = namedLog(name, options.logger); - let streamList = [ - plumber(logger.error) - ].concat(streams).concat([ + let streamList = streams.concat([ logger.stream() ]); - return combiner.obj(streamList) + /* We need to patch in the `pipe` handler manually, as this monkeypatch doesn't + * carry over to Duplex streams that are created by `stream-combiner2`. The + * `stream-combiner2` library will take care of re-emitting the errors on the + * combined stream, so we don't need `gulp-plumber` in our actual pipeline. + */ + let plumberStream = plumber(function(err) { + logger.error(err.toString()); + /* Ensure that the task finishes, so as to not break `gulp.watch`. */ + this.emit("end"); + }); + let combinedStream = combiner.obj(streamList); + + plumberStream.pipe(combinedStream); + + return combinedStream; } \ No newline at end of file