diff --git a/lib/fs_utils/pipeline.js b/lib/fs_utils/pipeline.js index fe1e2163c..c97a2cfc1 100644 --- a/lib/fs_utils/pipeline.js +++ b/lib/fs_utils/pipeline.js @@ -4,20 +4,45 @@ const logger = require('loggy'); const debug = require('debug')('brunch:pipeline'); const deppack = require('deppack'); // isNpm const BrunchError = require('../utils/error'); -const {pull} = require('../utils/helpers'); // Pipeline: File -> File. // Takes file and a) lints b) compiles c) extracts dependencies from it. const extRe = /(\.\w+)+$/; -const rethrow = message => error => { - if (!(error instanceof Error)) { - error = new Error(error); - } - error.pipelineCode = message; - throw error; -}; +let plugins = []; +let npmCompilers = []; +function respondTo(key) { + return plugins.filter(plugin => { + return typeof plugin[key] === 'function'; + }); +} + +function setPlugins(_plugins, _npmCompilers) { + plugins = _plugins.all; + npmCompilers = _npmCompilers; + deppack.setPlugins(_plugins, npmCompilers); +} + +function pull(array, predicate) { + const index = array.findIndex(predicate); + if (index === -1) return; + + const item = array[index]; + array.splice(index, 1); + return item; +} + +function rethrow(message) { + return error => { + if (!(error instanceof Error)) { + error = new Error(error); + } + + error.pipelineCode = message; + throw error; + }; +} async function lint(file) { const path = file.path; @@ -156,20 +181,4 @@ async function processFile(file) { return file_; } -const respondTo = key => plugins.filter(plugin => { - return typeof plugin[key] === 'function'; -}); - -let plugins = []; -let npmCompilers = []; - -module.exports = { - processAsset, - processFile, - setPlugins(array) { - plugins = array; - }, - setNpmCompilers(array) { - npmCompilers = array; - }, -}; +module.exports = {processAsset, processFile, setPlugins}; diff --git a/lib/utils/helpers.js b/lib/utils/helpers.js index 9639e76b0..d6309fbfa 100644 --- a/lib/utils/helpers.js +++ b/lib/utils/helpers.js @@ -238,15 +238,6 @@ class FrozenSet extends Set { const frozenMap = new FrozenMap(); const frozenSet = new FrozenSet(); -function pull(array, is) { - const index = array.findIndex(is); - if (index === -1) return; - - const item = array[index]; - array.splice(index, 1); - return item; -} - module.exports = { flatten, deepAssign, @@ -261,6 +252,5 @@ module.exports = { fsExists, isSymlink, frozenMap, - frozenSet, - pull, + frozenSet }; diff --git a/lib/watch.js b/lib/watch.js index 51e18d2ac..d1db1a74d 100644 --- a/lib/watch.js +++ b/lib/watch.js @@ -6,7 +6,6 @@ const chokidar = require('chokidar'); const debug = require('debug')('brunch:watch'); const speed = require('since-app-start'); const {serve} = require('./serve'); -const deppack = require('deppack'); const {installDeps} = require('deps-install'); const write = require('./fs_utils/write'); @@ -95,10 +94,7 @@ class BrunchWatcher { if (options.onCompile) hooks.onCompile.push({onCompile: options.onCompile}); this.hooks = mergeHooks(hooks, cfg.hooks); this.plugins = pluginArgs.plugins; - - pipeline.setPlugins(pluginArgs.plugins.all); - pipeline.setNpmCompilers(cfg.npm.compilers); - deppack.setPlugins(pluginArgs.plugins, cfg.npm.compilers); + pipeline.setPlugins(pluginArgs.plugins, cfg.npm.compilers); await Promise.all(this.hooks.preCompile()); this.initWatcher(watchedPaths); this.initCompilation();