Skip to content

Commit 583c479

Browse files
committed
added debug mode emitting underlying configuration
this might be useful for debugging, but also for recreating the corresponding configuration elsewhere (e.g. independent test cases, migrating away from faucet etc.)
1 parent 53f4f87 commit 583c479

File tree

3 files changed

+45
-15
lines changed

3 files changed

+45
-15
lines changed

lib/bundle/babel.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22

3+
let { debug } = require("../util");
34
let { loadExtension } = require("faucet-pipeline-core/lib/util");
45

56
module.exports = function generateTranspiler({ esnext, jsx, exclude }, { browsers }) {
@@ -33,15 +34,19 @@ module.exports = function generateTranspiler({ esnext, jsx, exclude }, { browser
3334
extensions.push(".jsx");
3435
let { pragma } = jsx;
3536
let options = pragma ? { pragma } : {};
36-
plugins.push(["@babel/plugin-transform-react-jsx", options]);
37+
let plugin = ["@babel/plugin-transform-react-jsx", options];
38+
debug("transpiler plugin:", ...plugin);
39+
plugins.push(plugin);
3740
}
3841

3942
if(plugins.length) {
4043
settings.plugins = plugins;
4144
}
4245

43-
let babel = loadExtension("rollup-plugin-babel",
44-
"failed to activate ESNext transpiler", "faucet-pipeline-esnext");
46+
let plugin = "rollup-plugin-babel";
47+
debug("plugin:", plugin, settings);
48+
let babel = loadExtension(plugin, "failed to activate ESNext transpiler",
49+
"faucet-pipeline-esnext");
4550
return {
4651
plugin: babel(settings),
4752
extensions

lib/bundle/config.js

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
"use strict";
33

44
let generateTranspiler = require("./babel");
5+
let { debug } = require("../util");
56
let { loadExtension, abort, repr } = require("faucet-pipeline-core/lib/util");
6-
let commonjs = require("rollup-plugin-commonjs");
7-
let nodeResolve = require("rollup-plugin-node-resolve");
7+
let COMMONJS = "rollup-plugin-commonjs";
8+
let commonjs = require(COMMONJS);
9+
let NODE_RESOLVE = "rollup-plugin-node-resolve";
10+
let nodeResolve = require(NODE_RESOLVE);
811

912
let MODULE_FORMATS = { // maps faucet identifiers to Rollup identifiers
1013
esm: true,
@@ -62,9 +65,11 @@ function generateConfig({ extensions = [], // eslint-disable-next-line indent
6265
if(esnext || jsx) {
6366
let transpiler = Object.assign({}, esnext, jsx);
6467
if(esnext) {
68+
debug("ESNext transpilation");
6569
transpiler.esnext = true;
6670
}
6771
if(jsx) {
72+
debug("JSX transpilation");
6873
// just to be safe, discard JSX-specifics on parent object
6974
delete transpiler.pragma;
7075
delete transpiler.fragment;
@@ -86,11 +91,15 @@ function generateConfig({ extensions = [], // eslint-disable-next-line indent
8691
plugins.push(plugin);
8792
}
8893
if(typescript) {
89-
let ts = loadExtension("rollup-plugin-typescript2",
90-
"failed to activate TypeScript", "faucet-pipeline-typescript");
94+
debug("TypeScript transpilation");
95+
let plugin = "rollup-plugin-typescript2";
96+
let ts = loadExtension(plugin, "failed to activate TypeScript",
97+
"faucet-pipeline-typescript");
9198
extensions.push(".ts");
9299
// TODO: provide defaults and abstractions for low-level options?
93-
plugins.push(typescript === true ? ts() : ts(typescript));
100+
let config = typescript === true ? [] : [typescript]; // spread arguments
101+
plugins.push(ts(...config));
102+
debug("plugin:", plugin, ...config);
94103
}
95104

96105
let resolve = {
@@ -100,11 +109,13 @@ function generateConfig({ extensions = [], // eslint-disable-next-line indent
100109
if(extensions.length) {
101110
resolve.extensions = [".js"].concat(extensions);
102111
}
112+
plugins.push(nodeResolve(resolve));
113+
debug("plugin:", NODE_RESOLVE, resolve);
114+
115+
let _cfg = { include: "node_modules/**" };
116+
plugins.push(commonjs(_cfg));
117+
debug("plugin:", COMMONJS, _cfg);
103118

104-
plugins = plugins.concat([
105-
nodeResolve(resolve),
106-
commonjs({ include: "node_modules/**" })
107-
]);
108119
if(compact) {
109120
cfg.compact = true;
110121
plugins = plugins.concat(determineCompacting(compact));
@@ -125,6 +136,7 @@ function generateConfig({ extensions = [], // eslint-disable-next-line indent
125136
cfg.globals = externals;
126137
}
127138

139+
debug("Rollup configuration:", cfg);
128140
// distinguish between (roughly) read and write settings
129141
let read = ["external", "plugins"];
130142
return Object.keys(cfg).reduce((memo, key) => {
@@ -157,7 +169,9 @@ function determineCompacting(type = true) {
157169
switch(type) {
158170
case true: // default
159171
case "compact":
160-
return require("rollup-plugin-cleanup")();
172+
var plugin = "rollup-plugin-cleanup"; // eslint-disable-line no-var
173+
debug("plugin:", plugin);
174+
return require(plugin)();
161175
case "minify":
162176
var options = { compress: false, mangle: false }; // eslint-disable-line no-var
163177
break;
@@ -168,8 +182,10 @@ function determineCompacting(type = true) {
168182
abort(`unknown compacting option ${type}`);
169183
}
170184

171-
let { terser } = loadExtension("rollup-plugin-terser",
172-
"failed to activate minification", "faucet-pipeline-jsmin");
185+
plugin = "rollup-plugin-terser";
186+
let { terser } = loadExtension(plugin, "failed to activate minification",
187+
"faucet-pipeline-jsmin");
188+
debug("plugin:", plugin, options);
173189
return terser(options);
174190
}
175191

lib/util.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
let NOTIFY = '(typeof alert !== "undefined" ? alert : console.error)';
44

5+
// TODO: move into faucet-core
6+
exports.DEBUG = process.env.FAUCET_ENV === "DEBUG";
7+
exports.debug = exports.DEBUG === false ? noop : (...msg) => {
8+
msg = msg.map(arg => (arg && !arg.substr) ? JSON.stringify(arg, null, 4) : arg);
9+
console.error("[DEBUG]", ...msg);
10+
};
11+
512
exports.generateError = err => {
613
let msg = `ERROR: ${err}`;
714
console.error(`✗ ${msg}`);
@@ -28,3 +35,5 @@ function reportCodeFrame(err, prop) {
2835
console.error(err);
2936
console.error(`\n${frame}\n`);
3037
}
38+
39+
function noop() {}

0 commit comments

Comments
 (0)