Skip to content

Commit 26c56a9

Browse files
committed
added test for skipping transpilation
this revealed a subtle inconsistency WRT reference directories
1 parent b1317eb commit 26c56a9

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

lib/bundle/babel.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ module.exports = function generateTranspiler({ features = [], jsx, exclude }) {
1212
// distinguish paths from package identifiers - as per Node's
1313
// resolution algorithm <https://nodejs.org/api/modules.html>, a
1414
// string is a path if it begins with `/`, `./` or `../`
15+
// FIXME: duplicates `AssetManager#resolvePath`, resulting in
16+
// inconsistency WRT working directory
1517
return /^\.{0,2}\//.test(pkg) ? pkg : `node_modules/${pkg}/**`;
1618
});
1719
}

test/unit/fixtures/node_modules/my-lib/dist.js

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/unit/fixtures/src/alt2.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import MYLIB from "my-lib/dist";
2+
3+
console.log(`[…] ${MYLIB}`); // eslint-disable-line no-console

test/unit/test_bundling.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,58 @@ console.log("[\\u2026] " + util); // eslint-disable-line no-console
5050
});
5151
});
5252

53+
it("should support skipping transpilation for select packages", () => {
54+
let cwd = process.cwd();
55+
process.chdir(FIXTURES_DIR); // XXX: should not be test-specific!?
56+
let restore = _ => process.chdir(cwd);
57+
58+
let config = [{
59+
source: "./src/alt2.js",
60+
target: "./dist/bundle.js",
61+
transpiler: {
62+
features: ["es2015"],
63+
exclude: ["my-lib"]
64+
}
65+
}];
66+
let assetManager = new MockAssetManager(FIXTURES_DIR);
67+
68+
return faucetJS(config, assetManager).
69+
then(restore, restore). // XXX: hacky
70+
then(_ => {
71+
assetManager.assertWrites([{
72+
filepath: path.resolve(FIXTURES_DIR, "./dist/bundle.js"),
73+
/* eslint-disable max-len */
74+
content: makeBundle(`
75+
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
76+
77+
78+
79+
80+
81+
function createCommonjsModule(fn, module) {
82+
return module = { exports: {} }, fn(module, module.exports), module.exports;
83+
}
84+
85+
var dist = createCommonjsModule(function (module) {
86+
/* eslint-disable */
87+
(function(window) {
88+
89+
var MYLIB = "MY-LIB";
90+
91+
{
92+
module.exports = MYLIB;
93+
}
94+
95+
}(commonjsGlobal));
96+
});
97+
98+
console.log("[\\u2026] " + dist); // eslint-disable-line no-console
99+
`.trim())
100+
/* eslint-enable max-len */
101+
}]);
102+
});
103+
});
104+
53105
it("should support custom file extensions", () => {
54106
let config = [{
55107
source: "./src/index.coffee",

0 commit comments

Comments
 (0)