From b0697e09f901cebb169930f12bb40ee00f7a18fc Mon Sep 17 00:00:00 2001 From: Manuel Mujica Date: Fri, 12 May 2017 14:41:46 -0600 Subject: [PATCH] Use pump library in steal-tools build code With pump we can remove all the intermediate streams for the error handling. --- lib/build/multi.js | 41 +++++++++++++++-------------------------- package.json | 1 + 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/lib/build/multi.js b/lib/build/multi.js index 36960bb6..f9132546 100644 --- a/lib/build/multi.js +++ b/lib/build/multi.js @@ -58,6 +58,7 @@ It manipulates this graph and eventually creates "bundle" graphs. Bundle graphs The nodes in those bundles are written to the filesystem. */ +var pump = require("pump"); var assignDefaultOptions = require("../assign_default_options"); var bundle = require("../stream/bundle"); var createBundleGraphStream = require("../graph/make_graph_with_bundles").createBundleGraphStream; @@ -88,22 +89,21 @@ module.exports = function(config, options){ return Promise.reject(err); } - // Get a stream containing the bundle graph - var graphStream = createBundleGraphStream(config, options); - // Pipe the bundle graph into the multiBuild steps - var transpileStream = graphStream.pipe(transpile()); - var minifyStream = transpileStream.pipe(minify()); - var buildStream = minifyStream.pipe(bundle()); - //var buildStream = graphStream.pipe(multiBuild()); - // Pipe the buildStream into concatenation - var concatStream = buildStream.pipe(concat()); - // Return a Promise that will resolve after bundles have been written; - return new Promise(function(resolve, reject){ - var bundleWriteStream = concatStream.pipe(createWriteStream()); - - // Pipe the build result into a write stream. - var writeStream = bundleWriteStream.pipe(stealWriteStream()); + return new Promise(function(resolve, reject) { + var writeStream = pump( + createBundleGraphStream(config, options), + transpile(), + minify(), + bundle(), + concat(), + createWriteStream(), + stealWriteStream(), + function(err) { + // reject the promise if any of the streams fail + if (err) reject(err); + } + ); writeStream.on("data", function(data){ this.end(); @@ -121,17 +121,6 @@ module.exports = function(config, options){ resolve(data); }); - - [ graphStream, - transpileStream, - minifyStream, - buildStream, - bundleWriteStream, - writeStream - ].forEach(function(stream){ - stream.on("error", reject); - }); }); } - }; diff --git a/package.json b/package.json index 3ab67e69..a587e5bf 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "mocha-lcov-reporter": "^1.2.0", "mock-fs": "4.2.0", "mockery": "^2.0.0", + "pump": "^1.0.2", "rimraf": "^2.5.2", "serve-static": "^1.11.2", "steal-conditional": "^0.3.4",