Skip to content

Commit 2b1aa54

Browse files
fix(externals): name a core module external by its key whichever spelling the code uses
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
1 parent 01ee7b7 commit 2b1aa54

4 files changed

Lines changed: 34 additions & 3 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack": patch
3+
---
4+
5+
Name a core module external by its key whichever spelling the code uses.

‎lib/externals/ExternalModuleFactoryPlugin.js‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,15 @@ class ExternalModuleFactoryPlugin {
175175
* @param {ExternalValue} value the external config
176176
* @param {ExternalsType | undefined} type type of external
177177
* @param {HandleExternalCallback} callback callback
178+
* @param {string=} userRequest the request naming the module, the one written when omitted
178179
* @returns {void}
179180
*/
180-
const handleExternal = (value, type, callback) => {
181+
const handleExternal = (
182+
value,
183+
type,
184+
callback,
185+
userRequest = originalRequest
186+
) => {
181187
/** @type {boolean | undefined} */
182188
let sideEffects;
183189
/** @type {ExternalTargetValue} */
@@ -303,7 +309,7 @@ class ExternalModuleFactoryPlugin {
303309
new ExternalModule(
304310
externalConfig,
305311
resolvedType,
306-
originalRequest,
312+
userRequest,
307313
dependencyMeta,
308314
interop,
309315
sideEffects
@@ -479,10 +485,12 @@ class ExternalModuleFactoryPlugin {
479485
alternateRequest
480486
)
481487
) {
488+
// Named by the key, so both spellings share one module id.
482489
return handleExternal(
483490
resolvedExternals[alternateRequest],
484491
undefined,
485-
callback
492+
callback,
493+
alternateRequest
486494
);
487495
}
488496
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const fs = require("node:fs");
2+
const path = require("path");
3+
4+
it("should name a core module external by the key it matched, whichever spelling the code uses", () => {
5+
expect(typeof fs.readFileSync).toBe("function");
6+
expect(typeof path.join).toBe("function");
7+
expect(require.resolveWeak("node:fs")).toBe("fs");
8+
expect(require.resolveWeak("path")).toBe("node:path");
9+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"use strict";
2+
3+
/** @type {import("../../../../").Configuration} */
4+
module.exports = {
5+
mode: "development",
6+
target: "web",
7+
externals: { fs: "commonjs fs", "node:path": "commonjs node:path" },
8+
output: { libraryTarget: "commonjs2" }
9+
};

0 commit comments

Comments
 (0)