Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/bundle/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,13 @@ function generateConfig({ externals, format, exports, // eslint-disable-next-lin

plugins = plugins.concat([
nodeResolve({ extensions }),
commonjs({ include: "node_modules/**" })
commonjs({ include: /node_modules/ })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a potentially significant change? I vaguely remember pondering this expression extensively (years ago though), so I'm hesitant to change it without asking: What's the significance in this particular context?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plus one on that

]);

if(process.env.FAUCET_EXPERIMENTAL_SYMLINKS === "true") {
cfg.preserveSymlinks = true;
}

if(compact) {
cfg.compact = true;
plugins = plugins.concat(determineCompacting(compact));
Expand All @@ -111,7 +116,7 @@ function generateConfig({ externals, format, exports, // eslint-disable-next-lin
}

// distinguish between (roughly) read and write settings
let read = ["external", "plugins"];
let read = ["external", "plugins", "preserveSymlinks"];
return Object.keys(cfg).reduce((memo, key) => {
let type = read.includes(key) ? "readConfig" : "writeConfig";
memo[type][key] = cfg[key];
Expand Down
3 changes: 3 additions & 0 deletions test/unit/fixtures/external/cjs-module/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exports.dummy = {
some: "dummy value"
};
Copy link
Contributor

@FND FND Sep 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: We use underscores instead of hyphens in file and directory names.

3 changes: 3 additions & 0 deletions test/unit/fixtures/src/import-symlinked.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { dummy } from "some-cjs-module";

console.log(dummy); // eslint-disable-line no-console
46 changes: 46 additions & 0 deletions test/unit/test_bundling.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

let { MockAssetManager, makeBundle, FIXTURES_DIR } = require("./util");
let faucetJS = require("../../lib").plugin;
const fs = require("fs");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const fs = require("fs");
let fs = require("fs");

for consistency 🙂

let path = require("path");
let assert = require("assert");

Expand Down Expand Up @@ -412,4 +413,49 @@ console.log(\`[DUMMY] $\{util}\`); // eslint-disable-line no-console
assetManager.assertWriteCount(1);
});
});

describe("working with linked modules", () => {
// in case some set this env variable before
let initialFlagValue = process.env.FAUCET_EXPERIMENTAL_SYMLINKS;

beforeEach(() => {
fs.symlinkSync(
path.resolve(FIXTURES_DIR, "./external/cjs-module"),
path.resolve(FIXTURES_DIR, "./node_modules/some-cjs-module"),
"dir"
);

process.env.FAUCET_EXPERIMENTAL_SYMLINKS = "true";
});

afterEach(() => {
fs.unlinkSync(path.resolve(FIXTURES_DIR, "./node_modules/some-cjs-module"));
process.env.FAUCET_EXPERIMENTAL_SYMLINKS = initialFlagValue;
});

it("should preserve symlinks when env varialbe is set", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it("should preserve symlinks when env varialbe is set", () => {
it("should preserve symlinks when env variable is set", () => {

typo 🙂

let config = [{
source: "./src/import-symlinked.js",
target: "./dist/bundle.js",
format: "CommonJS"
}];
let assetManager = new MockAssetManager(FIXTURES_DIR);

return faucetJS(config, assetManager, DEFAULT_OPTIONS)().
then(() => {
assetManager.assertWrites([{
filepath: path.resolve(FIXTURES_DIR, "./dist/bundle.js"),
content: makeBundle(`
'use strict';

var dummy = {
some: "dummy value"
};

console.log(dummy); // eslint-disable-line no-console
`)
}]);
});
});
});
});