From 7c9d90090a2ef9f61bc66fcd7a095db13d97828e Mon Sep 17 00:00:00 2001 From: emizzle Date: Wed, 17 Oct 2018 10:29:53 +1100 Subject: [PATCH] Replaced async.queue with async.cargo Cargo in fact, bundles up subsequent tasks in to an array, so any tasks that are not immediately run get bundled in to another run later. This helps when lots of changes have been made in a short period of time. --- lib/core/engine.js | 15 ++++++++------- lib/modules/pipeline/index.js | 6 +++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/core/engine.js b/lib/core/engine.js index df22d891d..561fbbbb9 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -108,9 +108,9 @@ class Engine { this.registerModule('pipeline', { webpackConfigName: this.webpackConfigName }); - this.events.on('code-generator-ready', function (modifiedAsset) { + this.events.on('code-generator-ready', function (modifiedAssets) { self.events.request('code', function (abi, contractsJSON) { - self.events.request('pipeline:build', {abi, contractsJSON, modifiedAsset}, () => { + self.events.request('pipeline:build', {abi, contractsJSON, modifiedAssets}, () => { self.events.emit('outputDone'); }); }); @@ -162,15 +162,16 @@ class Engine { this.registerModule('code_generator', {plugins: self.plugins, env: self.env}); - const generateCode = function (modifiedAsset) { + const generateCode = function (modifiedAssets) { self.events.request("code-generator:embarkjs:build", () => { - self.events.emit('code-generator-ready', modifiedAsset); + self.events.emit('code-generator-ready', modifiedAssets); }); }; - const cargo = async.queue((task, callback) => { - generateCode(task.modifiedAsset); + const cargo = async.cargo((tasks, callback) => { + const modifiedAssets = tasks.map(task => task.modifiedAsset); + generateCode(modifiedAssets); self.events.once('outputDone', callback); - }, 3); + }); const addToCargo = function (modifiedAsset) { cargo.push({modifiedAsset}); }; diff --git a/lib/modules/pipeline/index.js b/lib/modules/pipeline/index.js index be0c818e8..f5c42f17c 100644 --- a/lib/modules/pipeline/index.js +++ b/lib/modules/pipeline/index.js @@ -23,7 +23,7 @@ class Pipeline { fs.removeSync(this.buildDir); } - build({modifiedAsset}, callback) { + build({modifiedAssets}, callback) { let self = this; const importsList = {}; let placeholderPage; @@ -86,7 +86,7 @@ class Pipeline { function shouldRunWebpack(next){ // assuming we got here because an asset was changed, let's check our webpack config // to see if the changed asset requires webpack to run - if(modifiedAsset){ + if(modifiedAssets){ const configReader = new WebpackConfigReader({webpackConfigName: self.webpackConfigName}); return configReader.readConfig((err, config) => { if(err) return next(err); @@ -95,7 +95,7 @@ class Pipeline { return next(__('bad webpack config, the resolved config was null or not an object')); } - const shouldRun = config.module.rules.some(rule => rule.test.test(modifiedAsset)); + const shouldRun = modifiedAssets.some(modifiedAsset => config.module.rules.some(rule => rule.test.test(modifiedAsset))); return next(null, !shouldRun); }); }