Skip to content

Commit b12d722

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 b12d722

File tree

4 files changed

+47
-15
lines changed

4 files changed

+47
-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/bundler.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
let { debug } = require("../util");
12
let rollup = require("rollup");
23

34
let SMPREFIX = "//# sourceMappingURL=";
@@ -8,6 +9,8 @@ module.exports = function generateBundle(entryPoint, config, cache) {
89
input: entryPoint,
910
cache
1011
});
12+
13+
debug("Rollup configuration:", options, writeConfig);
1114
return rollup.rollup(options).
1215
then(bundle => {
1316
cache = bundle;

lib/bundle/config.js

Lines changed: 27 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));
@@ -157,7 +168,9 @@ function determineCompacting(type = true) {
157168
switch(type) {
158169
case true: // default
159170
case "compact":
160-
return require("rollup-plugin-cleanup")();
171+
var plugin = "rollup-plugin-cleanup"; // eslint-disable-line no-var
172+
debug("plugin:", plugin);
173+
return require(plugin)();
161174
case "minify":
162175
var options = { compress: false, mangle: false }; // eslint-disable-line no-var
163176
break;
@@ -168,8 +181,10 @@ function determineCompacting(type = true) {
168181
abort(`unknown compacting option ${type}`);
169182
}
170183

171-
let { terser } = loadExtension("rollup-plugin-terser",
172-
"failed to activate minification", "faucet-pipeline-jsmin");
184+
plugin = "rollup-plugin-terser";
185+
let { terser } = loadExtension(plugin, "failed to activate minification",
186+
"faucet-pipeline-jsmin");
187+
debug("plugin:", plugin, options);
173188
return terser(options);
174189
}
175190

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)