diff --git a/lib/bundle/babel.js b/lib/bundle/babel.js index e730823..aa0faaf 100644 --- a/lib/bundle/babel.js +++ b/lib/bundle/babel.js @@ -1,5 +1,6 @@ "use strict"; +let { debug } = require("../util"); let { loadExtension } = require("faucet-pipeline-core/lib/util"); module.exports = function generateTranspiler({ esnext, jsx, exclude }, { browsers }) { @@ -33,15 +34,19 @@ module.exports = function generateTranspiler({ esnext, jsx, exclude }, { browser extensions.push(".jsx"); let { pragma } = jsx; let options = pragma ? { pragma } : {}; - plugins.push(["@babel/plugin-transform-react-jsx", options]); + let plugin = ["@babel/plugin-transform-react-jsx", options]; + debug("transpiler plugin:", ...plugin); + plugins.push(plugin); } if(plugins.length) { settings.plugins = plugins; } - let babel = loadExtension("rollup-plugin-babel", - "failed to activate ESNext transpiler", "faucet-pipeline-esnext"); + let plugin = "rollup-plugin-babel"; + debug("plugin:", plugin, settings); + let babel = loadExtension(plugin, "failed to activate ESNext transpiler", + "faucet-pipeline-esnext"); return { plugin: babel(settings), extensions diff --git a/lib/bundle/bundler.js b/lib/bundle/bundler.js index f0fb301..8e6cf5f 100644 --- a/lib/bundle/bundler.js +++ b/lib/bundle/bundler.js @@ -1,3 +1,4 @@ +let { debug } = require("../util"); let rollup = require("rollup"); let SMPREFIX = "//# sourceMappingURL="; @@ -8,6 +9,8 @@ module.exports = function generateBundle(entryPoint, config, cache) { input: entryPoint, cache }); + + debug("Rollup configuration:", options, writeConfig); return rollup.rollup(options). then(bundle => { cache = bundle; diff --git a/lib/bundle/config.js b/lib/bundle/config.js index be4929d..2121b26 100644 --- a/lib/bundle/config.js +++ b/lib/bundle/config.js @@ -2,9 +2,12 @@ "use strict"; let generateTranspiler = require("./babel"); +let { debug } = require("../util"); let { loadExtension, abort, repr } = require("faucet-pipeline-core/lib/util"); -let commonjs = require("rollup-plugin-commonjs"); -let nodeResolve = require("rollup-plugin-node-resolve"); +let COMMONJS = "rollup-plugin-commonjs"; +let commonjs = require(COMMONJS); +let NODE_RESOLVE = "rollup-plugin-node-resolve"; +let nodeResolve = require(NODE_RESOLVE); let MODULE_FORMATS = { // maps faucet identifiers to Rollup identifiers esm: true, @@ -62,9 +65,11 @@ function generateConfig({ extensions = [], // eslint-disable-next-line indent if(esnext || jsx) { let transpiler = Object.assign({}, esnext, jsx); if(esnext) { + debug("ESNext transpilation"); transpiler.esnext = true; } if(jsx) { + debug("JSX transpilation"); // just to be safe, discard JSX-specifics on parent object delete transpiler.pragma; delete transpiler.fragment; @@ -86,11 +91,15 @@ function generateConfig({ extensions = [], // eslint-disable-next-line indent plugins.push(plugin); } if(typescript) { - let ts = loadExtension("rollup-plugin-typescript2", - "failed to activate TypeScript", "faucet-pipeline-typescript"); + debug("TypeScript transpilation"); + let plugin = "rollup-plugin-typescript2"; + let ts = loadExtension(plugin, "failed to activate TypeScript", + "faucet-pipeline-typescript"); extensions.push(".ts"); // TODO: provide defaults and abstractions for low-level options? - plugins.push(typescript === true ? ts() : ts(typescript)); + let config = typescript === true ? [] : [typescript]; // spread arguments + plugins.push(ts(...config)); + debug("plugin:", plugin, ...config); } let resolve = { @@ -100,11 +109,13 @@ function generateConfig({ extensions = [], // eslint-disable-next-line indent if(extensions.length) { resolve.extensions = [".js"].concat(extensions); } + plugins.push(nodeResolve(resolve)); + debug("plugin:", NODE_RESOLVE, resolve); + + let _cfg = { include: "node_modules/**" }; + plugins.push(commonjs(_cfg)); + debug("plugin:", COMMONJS, _cfg); - plugins = plugins.concat([ - nodeResolve(resolve), - commonjs({ include: "node_modules/**" }) - ]); if(compact) { cfg.compact = true; plugins = plugins.concat(determineCompacting(compact)); @@ -157,7 +168,9 @@ function determineCompacting(type = true) { switch(type) { case true: // default case "compact": - return require("rollup-plugin-cleanup")(); + var plugin = "rollup-plugin-cleanup"; // eslint-disable-line no-var + debug("plugin:", plugin); + return require(plugin)(); case "minify": var options = { compress: false, mangle: false }; // eslint-disable-line no-var break; @@ -168,8 +181,10 @@ function determineCompacting(type = true) { abort(`unknown compacting option ${type}`); } - let { terser } = loadExtension("rollup-plugin-terser", - "failed to activate minification", "faucet-pipeline-jsmin"); + plugin = "rollup-plugin-terser"; + let { terser } = loadExtension(plugin, "failed to activate minification", + "faucet-pipeline-jsmin"); + debug("plugin:", plugin, options); return terser(options); } diff --git a/lib/util.js b/lib/util.js index d5b8359..add8336 100644 --- a/lib/util.js +++ b/lib/util.js @@ -2,6 +2,13 @@ let NOTIFY = '(typeof alert !== "undefined" ? alert : console.error)'; +// TODO: move into faucet-core +exports.DEBUG = process.env.FAUCET_ENV === "DEBUG"; +exports.debug = exports.DEBUG === false ? noop : (...msg) => { + msg = msg.map(arg => (arg && !arg.substr) ? JSON.stringify(arg, null, 4) : arg); + console.error("[DEBUG]", ...msg); +}; + exports.generateError = err => { let msg = `ERROR: ${err}`; console.error(`✗ ${msg}`); @@ -28,3 +35,5 @@ function reportCodeFrame(err, prop) { console.error(err); console.error(`\n${frame}\n`); } + +function noop() {}