Skip to content

Commit

Permalink
Merge pull request #12693 from dnalborczyk/node-prefix
Browse files Browse the repository at this point in the history
feat: add node: prefixed modules
  • Loading branch information
sokra committed Jun 21, 2021
2 parents 93b96c1 + 2b210f9 commit de5365b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/node/NodeTargetPlugin.js
Expand Up @@ -55,6 +55,7 @@ const builtins = [
"wasi",
"worker_threads",
"zlib",
/^node:/,

// cspell:word pnpapi
// Yarn PnP adds pnpapi as "builtin"
Expand Down
6 changes: 5 additions & 1 deletion test/ConfigTestCases.template.js
Expand Up @@ -413,7 +413,11 @@ const describeCases = config => {
module in testConfig.modules
) {
return testConfig.modules[module];
} else return require(module);
} else {
return require(module.startsWith("node:")
? module.slice(5)
: module);
}
};

results.push(
Expand Down
8 changes: 8 additions & 0 deletions test/configCases/node/node-prefix/index.js
@@ -0,0 +1,8 @@
import vm1 from "vm";
import vm2 from "node:vm";

it("should allow importing node builtin modules with the node: prefix", () => {
expect(require("node:fs")).toBe(require("fs"));
expect(require("node:path")).toBe(require("path"));
expect(vm2).toBe(vm1);
});
4 changes: 4 additions & 0 deletions test/configCases/node/node-prefix/webpack.config.js
@@ -0,0 +1,4 @@
/** @type {import("../../../../").Configuration} */
module.exports = {
target: "node"
};

0 comments on commit de5365b

Please sign in to comment.