diff --git a/lib/bundle/babel.js b/lib/bundle/babel.js index e28ec7a..547e4fb 100644 --- a/lib/bundle/babel.js +++ b/lib/bundle/babel.js @@ -12,6 +12,8 @@ module.exports = function generateTranspiler({ features = [], jsx, exclude }) { // distinguish paths from package identifiers - as per Node's // resolution algorithm , a // string is a path if it begins with `/`, `./` or `../` + // FIXME: duplicates `AssetManager#resolvePath`, resulting in + // inconsistency WRT working directory return /^\.{0,2}\//.test(pkg) ? pkg : `node_modules/${pkg}/**`; }); } diff --git a/test/unit/fixtures/node_modules/my-lib/dist.js b/test/unit/fixtures/node_modules/my-lib/dist.js new file mode 100644 index 0000000..f636882 --- /dev/null +++ b/test/unit/fixtures/node_modules/my-lib/dist.js @@ -0,0 +1,16 @@ +/* eslint-disable */ +(function(window) { + +var MYLIB = "MY-LIB"; + +if(typeof module !== "undefined" && typeof module.exports !== "undefined") { + module.exports = MYLIB; +} else if(typeof define === "function" && define.amd) { + define("my-lib", [], function() { + return MYLIB; + }); +} else if(typeof window === "object") { + window.MYLIB = MYLIB; +} + +}(this)); diff --git a/test/unit/fixtures/src/alt2.js b/test/unit/fixtures/src/alt2.js new file mode 100644 index 0000000..c92d685 --- /dev/null +++ b/test/unit/fixtures/src/alt2.js @@ -0,0 +1,3 @@ +import MYLIB from "my-lib/dist"; + +console.log(`[…] ${MYLIB}`); // eslint-disable-line no-console diff --git a/test/unit/test_bundling.js b/test/unit/test_bundling.js index 9b1eaa2..66f5b3b 100644 --- a/test/unit/test_bundling.js +++ b/test/unit/test_bundling.js @@ -50,6 +50,58 @@ console.log("[\\u2026] " + util); // eslint-disable-line no-console }); }); + it("should support skipping transpilation for select packages", () => { + let cwd = process.cwd(); + process.chdir(FIXTURES_DIR); // XXX: should not be test-specific!? + let restore = _ => process.chdir(cwd); + + let config = [{ + source: "./src/alt2.js", + target: "./dist/bundle.js", + transpiler: { + features: ["es2015"], + exclude: ["my-lib"] + } + }]; + let assetManager = new MockAssetManager(FIXTURES_DIR); + + return faucetJS(config, assetManager). + then(restore, restore). // XXX: hacky + then(_ => { + assetManager.assertWrites([{ + filepath: path.resolve(FIXTURES_DIR, "./dist/bundle.js"), + /* eslint-disable max-len */ + content: makeBundle(` +var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; + + + + + +function createCommonjsModule(fn, module) { + return module = { exports: {} }, fn(module, module.exports), module.exports; +} + +var dist = createCommonjsModule(function (module) { +/* eslint-disable */ +(function(window) { + +var MYLIB = "MY-LIB"; + +{ + module.exports = MYLIB; +} + +}(commonjsGlobal)); +}); + +console.log("[\\u2026] " + dist); // eslint-disable-line no-console + `.trim()) + /* eslint-enable max-len */ + }]); + }); + }); + it("should support custom file extensions", () => { let config = [{ source: "./src/index.coffee",