Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Commit

Permalink
Move functions around, simplify for workers.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Dec 4, 2019
1 parent 740406c commit f6d77fa
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 41 deletions.
59 changes: 34 additions & 25 deletions lib/fs_utils/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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};
12 changes: 1 addition & 11 deletions lib/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -261,6 +252,5 @@ module.exports = {
fsExists,
isSymlink,
frozenMap,
frozenSet,
pull,
frozenSet
};
6 changes: 1 addition & 5 deletions lib/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit f6d77fa

Please sign in to comment.