webpack 5.108.0 → 5.108.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/lib/CleanPlugin.js +8 -25
  2. package/lib/Compilation.js +0 -1
  3. package/lib/DefinePlugin.js +8 -19
  4. package/lib/ExternalModule.js +64 -19
  5. package/lib/ExternalModuleFactoryPlugin.js +37 -1
  6. package/lib/LazyBarrel.js +4 -3
  7. package/lib/NormalModule.js +49 -59
  8. package/lib/RuntimeTemplate.js +3 -3
  9. package/lib/bun/BunTargetPlugin.js +1 -7
  10. package/lib/container/ModuleFederationPlugin.js +9 -25
  11. package/lib/css/CssInjectStyleRuntimeModule.js +9 -24
  12. package/lib/css/CssLoadingRuntimeModule.js +12 -27
  13. package/lib/css/CssModulesPlugin.js +15 -31
  14. package/lib/debug/ProfilingPlugin.js +12 -1
  15. package/lib/deno/DenoTargetPlugin.js +1 -7
  16. package/lib/dependencies/CommonJsExportRequireDependency.js +3 -3
  17. package/lib/dependencies/CommonJsExportsDependency.js +2 -2
  18. package/lib/dependencies/CommonJsFullRequireDependency.js +1 -1
  19. package/lib/dependencies/CommonJsSelfReferenceDependency.js +1 -1
  20. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +22 -0
  21. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +1 -1
  22. package/lib/dependencies/HarmonyImportDependency.js +2 -0
  23. package/lib/dependencies/ImportMetaPlugin.js +9 -25
  24. package/lib/dependencies/ProvidedDependency.js +1 -1
  25. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +10 -26
  26. package/lib/javascript/JavascriptModulesPlugin.js +38 -54
  27. package/lib/node/NodeTargetPlugin.js +1 -62
  28. package/lib/node/nodeBuiltins.js +80 -0
  29. package/lib/optimize/ConcatenatedModule.js +20 -30
  30. package/lib/optimize/RealContentHashPlugin.js +8 -24
  31. package/lib/runtime/LoadScriptRuntimeModule.js +9 -24
  32. package/lib/util/createHooksRegistry.js +35 -0
  33. package/lib/util/property.js +1 -1
  34. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +12 -29
  35. package/lib/web/JsonpChunkLoadingRuntimeModule.js +10 -25
  36. package/package.json +2 -1
  37. package/types.d.ts +84 -71
@@ -0,0 +1,80 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author sheo13666q @sheo13666q
4
+ */
5
+
6
+ "use strict";
7
+
8
+ // node.js built-in modules externalized by the node/deno/bun target presets.
9
+ const builtins = [
10
+ "assert",
11
+ "assert/strict",
12
+ "async_hooks",
13
+ "buffer",
14
+ "child_process",
15
+ "cluster",
16
+ "console",
17
+ "constants",
18
+ "crypto",
19
+ "dgram",
20
+ "diagnostics_channel",
21
+ "dns",
22
+ "dns/promises",
23
+ "domain",
24
+ "events",
25
+ "fs",
26
+ "fs/promises",
27
+ "http",
28
+ "http2",
29
+ "https",
30
+ "inspector",
31
+ "inspector/promises",
32
+ "module",
33
+ "net",
34
+ "os",
35
+ "path",
36
+ "path/posix",
37
+ "path/win32",
38
+ "perf_hooks",
39
+ "process",
40
+ "punycode",
41
+ "querystring",
42
+ "readline",
43
+ "readline/promises",
44
+ "repl",
45
+ "stream",
46
+ "stream/consumers",
47
+ "stream/promises",
48
+ "stream/web",
49
+ "string_decoder",
50
+ "sys",
51
+ "timers",
52
+ "timers/promises",
53
+ "tls",
54
+ "trace_events",
55
+ "tty",
56
+ "url",
57
+ "util",
58
+ "util/types",
59
+ "v8",
60
+ "vm",
61
+ "wasi",
62
+ "worker_threads",
63
+ "zlib",
64
+ /^node:/,
65
+
66
+ // cspell:word pnpapi
67
+ // Yarn PnP adds pnpapi as "builtin"
68
+ "pnpapi"
69
+ ];
70
+
71
+ // Bare core module names (no `node:` prefix, no regex, no pnpapi), used to
72
+ // recognize a request that has a `node:`-prefixed equivalent.
73
+ const coreModules = new Set(
74
+ builtins.filter(
75
+ (builtin) => typeof builtin === "string" && builtin !== "pnpapi"
76
+ )
77
+ );
78
+
79
+ module.exports.builtins = builtins;
80
+ module.exports.coreModules = coreModules;
@@ -43,6 +43,7 @@ const {
43
43
  getUsedNamesInScopeInfo
44
44
  } = require("../util/concatenate");
45
45
  const createHash = require("../util/createHash");
46
+ const createHooksRegistry = require("../util/createHooksRegistry");
46
47
  const { makePathsRelative } = require("../util/identifier");
47
48
  const makeSerializable = require("../util/makeSerializable");
48
49
  const { propertyAccess, propertyName } = require("../util/property");
@@ -817,9 +818,6 @@ const getFinalName = (
817
818
 
818
819
  /** @typedef {BuildInfo & KnownConcatenatedModuleBuildInfo} ConcatenatedModuleBuildInfo */
819
820
 
820
- /** @type {WeakMap<Compilation, ConcatenateModuleHooks>} */
821
- const compilationHooksMap = new WeakMap();
822
-
823
821
  class ConcatenatedModule extends Module {
824
822
  /**
825
823
  * @param {Module} rootModule the root module of the concatenation
@@ -853,30 +851,6 @@ class ConcatenatedModule extends Module {
853
851
  });
854
852
  }
855
853
 
856
- /**
857
- * @param {Compilation} compilation the compilation
858
- * @returns {ConcatenateModuleHooks} the attached hooks
859
- */
860
- static getCompilationHooks(compilation) {
861
- let hooks = compilationHooksMap.get(compilation);
862
- if (hooks === undefined) {
863
- hooks = {
864
- onDemandExportsGeneration: new SyncBailHook([
865
- "module",
866
- "runtimes",
867
- "exportsFinalName",
868
- "exportsSource"
869
- ]),
870
- concatenatedModuleInfo: new SyncBailHook([
871
- "updatedInfo",
872
- "concatenatedModuleInfo"
873
- ])
874
- };
875
- compilationHooksMap.set(compilation, hooks);
876
- }
877
- return hooks;
878
- }
879
-
880
854
  /**
881
855
  * @param {object} options options
882
856
  * @param {string} options.identifier the identifier of the module
@@ -2110,7 +2084,7 @@ class ConcatenatedModule extends Module {
2110
2084
  `\n ${propertyName(exportInfo.name)}: ${runtimeTemplate.returningFunction(
2111
2085
  usedName.render(
2112
2086
  Template.toNormalComment(
2113
- `inlined export ${propertyAccess(exportInfo.name)}`
2087
+ `inlined export ${propertyAccess([exportInfo.name])}`
2114
2088
  )
2115
2089
  )
2116
2090
  )}`
@@ -2120,7 +2094,7 @@ class ConcatenatedModule extends Module {
2120
2094
  // import variable; concatenated ones resolve to an internal binding.
2121
2095
  const finalName =
2122
2096
  info.type === "external"
2123
- ? `${/** @type {string} */ (info.name)}${propertyAccess(usedName)}`
2097
+ ? `${/** @type {string} */ (info.name)}${propertyAccess([usedName])}`
2124
2098
  : getFinalName(
2125
2099
  moduleGraph,
2126
2100
  info,
@@ -2183,7 +2157,7 @@ ${defineGetters}`
2183
2157
  `\n ${propertyName(exportInfo.name)}: ${runtimeTemplate.returningFunction(
2184
2158
  usedName.render(
2185
2159
  Template.toNormalComment(
2186
- `inlined export ${propertyAccess(exportInfo.name)}`
2160
+ `inlined export ${propertyAccess([exportInfo.name])}`
2187
2161
  )
2188
2162
  )
2189
2163
  )}`
@@ -2661,6 +2635,22 @@ ${defineGetters}`
2661
2635
  }
2662
2636
  }
2663
2637
 
2638
+ ConcatenatedModule.getCompilationHooks = createHooksRegistry(
2639
+ () =>
2640
+ /** @type {ConcatenateModuleHooks} */ ({
2641
+ onDemandExportsGeneration: new SyncBailHook([
2642
+ "module",
2643
+ "runtimes",
2644
+ "exportsFinalName",
2645
+ "exportsSource"
2646
+ ]),
2647
+ concatenatedModuleInfo: new SyncBailHook([
2648
+ "updatedInfo",
2649
+ "concatenatedModuleInfo"
2650
+ ])
2651
+ })
2652
+ );
2653
+
2664
2654
  makeSerializable(ConcatenatedModule, "webpack/lib/optimize/ConcatenatedModule");
2665
2655
 
2666
2656
  module.exports = ConcatenatedModule;
@@ -11,6 +11,7 @@ const Compilation = require("../Compilation");
11
11
  const WebpackError = require("../errors/WebpackError");
12
12
  const { compareSelect, compareStrings } = require("../util/comparators");
13
13
  const createHash = require("../util/createHash");
14
+ const createHooksRegistry = require("../util/createHooksRegistry");
14
15
 
15
16
  /** @typedef {import("../../declarations/WebpackOptions").HashFunction} HashFunction */
16
17
  /** @typedef {import("../../declarations/WebpackOptions").HashDigest} HashDigest */
@@ -171,9 +172,6 @@ const toCachedSource = (source) => {
171
172
  * @property {SyncBailHook<[Buffer[], string], string | void>} updateHash
172
173
  */
173
174
 
174
- /** @type {WeakMap<Compilation, CompilationHooks>} */
175
- const compilationHooksMap = new WeakMap();
176
-
177
175
  /**
178
176
  * Defines the real content hash plugin options type used by this module.
179
177
  * @typedef {object} RealContentHashPluginOptions
@@ -184,27 +182,6 @@ const compilationHooksMap = new WeakMap();
184
182
  const PLUGIN_NAME = "RealContentHashPlugin";
185
183
 
186
184
  class RealContentHashPlugin {
187
- /**
188
- * Returns the attached hooks.
189
- * @param {Compilation} compilation the compilation
190
- * @returns {CompilationHooks} the attached hooks
191
- */
192
- static getCompilationHooks(compilation) {
193
- if (!(compilation instanceof Compilation)) {
194
- throw new TypeError(
195
- "The 'compilation' argument must be an instance of Compilation"
196
- );
197
- }
198
- let hooks = compilationHooksMap.get(compilation);
199
- if (hooks === undefined) {
200
- hooks = {
201
- updateHash: new SyncBailHook(["content", "oldHash"])
202
- };
203
- compilationHooksMap.set(compilation, hooks);
204
- }
205
- return hooks;
206
- }
207
-
208
185
  /**
209
186
  * Creates an instance of RealContentHashPlugin.
210
187
  * @param {RealContentHashPluginOptions} options options
@@ -576,4 +553,11 @@ ${referencingAssets
576
553
  }
577
554
  }
578
555
 
556
+ RealContentHashPlugin.getCompilationHooks = createHooksRegistry(
557
+ () =>
558
+ /** @type {CompilationHooks} */ ({
559
+ updateHash: new SyncBailHook(["content", "oldHash"])
560
+ })
561
+ );
562
+
579
563
  module.exports = RealContentHashPlugin;
@@ -5,9 +5,10 @@
5
5
  "use strict";
6
6
 
7
7
  const { SyncWaterfallHook } = require("tapable");
8
- const Compilation = require("../Compilation");
8
+ /** @typedef {import("../Compilation")} Compilation */
9
9
  const RuntimeGlobals = require("../RuntimeGlobals");
10
10
  const Template = require("../Template");
11
+ const createHooksRegistry = require("../util/createHooksRegistry");
11
12
  const HelperRuntimeModule = require("./HelperRuntimeModule");
12
13
 
13
14
  /** @typedef {import("../Chunk")} Chunk */
@@ -17,30 +18,7 @@ const HelperRuntimeModule = require("./HelperRuntimeModule");
17
18
  * @property {SyncWaterfallHook<[string, Chunk]>} createScript
18
19
  */
19
20
 
20
- /** @type {WeakMap<Compilation, LoadScriptCompilationHooks>} */
21
- const compilationHooksMap = new WeakMap();
22
-
23
21
  class LoadScriptRuntimeModule extends HelperRuntimeModule {
24
- /**
25
- * @param {Compilation} compilation the compilation
26
- * @returns {LoadScriptCompilationHooks} hooks
27
- */
28
- static getCompilationHooks(compilation) {
29
- if (!(compilation instanceof Compilation)) {
30
- throw new TypeError(
31
- "The 'compilation' argument must be an instance of Compilation"
32
- );
33
- }
34
- let hooks = compilationHooksMap.get(compilation);
35
- if (hooks === undefined) {
36
- hooks = {
37
- createScript: new SyncWaterfallHook(["source", "chunk"])
38
- };
39
- compilationHooksMap.set(compilation, hooks);
40
- }
41
- return hooks;
42
- }
43
-
44
22
  /**
45
23
  * @param {boolean=} withCreateScriptUrl use create script url for trusted types
46
24
  * @param {boolean=} withFetchPriority use `fetchPriority` attribute
@@ -177,4 +155,11 @@ class LoadScriptRuntimeModule extends HelperRuntimeModule {
177
155
  }
178
156
  }
179
157
 
158
+ LoadScriptRuntimeModule.getCompilationHooks = createHooksRegistry(
159
+ () =>
160
+ /** @type {LoadScriptCompilationHooks} */ ({
161
+ createScript: new SyncWaterfallHook(["source", "chunk"])
162
+ })
163
+ );
164
+
180
165
  module.exports = LoadScriptRuntimeModule;
@@ -0,0 +1,35 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ */
4
+
5
+ "use strict";
6
+
7
+ const memoize = require("./memoize");
8
+
9
+ const getCompilation = memoize(() => require("../Compilation"));
10
+
11
+ /**
12
+ * @template T
13
+ * @param {() => T} createHooks factory that returns a fresh hooks object
14
+ * @returns {(compilation: import("../Compilation")) => T} getter that returns (or creates) hooks for the compilation
15
+ */
16
+ const createHooksRegistry = (createHooks) => {
17
+ /** @type {WeakMap<import("../Compilation"), T>} */
18
+ const map = new WeakMap();
19
+ return (compilation) => {
20
+ const Compilation = getCompilation();
21
+ if (!(compilation instanceof Compilation)) {
22
+ throw new TypeError(
23
+ "The 'compilation' argument must be an instance of Compilation"
24
+ );
25
+ }
26
+ let hooks = map.get(compilation);
27
+ if (hooks === undefined) {
28
+ hooks = createHooks();
29
+ map.set(compilation, hooks);
30
+ }
31
+ return hooks;
32
+ };
33
+ };
34
+
35
+ module.exports = createHooksRegistry;
@@ -75,7 +75,7 @@ const propertyName = (prop) => {
75
75
 
76
76
  /**
77
77
  * Returns chain of property accesses.
78
- * @param {ArrayLike<string>} properties properties
78
+ * @param {readonly string[]} properties properties
79
79
  * @param {number} start start index
80
80
  * @returns {string} chain of property accesses
81
81
  */
@@ -6,12 +6,12 @@
6
6
  "use strict";
7
7
 
8
8
  const { SyncWaterfallHook } = require("tapable");
9
- const Compilation = require("../Compilation");
10
9
  const Generator = require("../Generator");
11
10
  const { WEBASSEMBLY_MODULE_TYPE_ASYNC } = require("../ModuleTypeConstants");
12
11
  const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency");
13
12
  const { tryRunOrWebpackError } = require("../errors/HookWebpackError");
14
13
  const { compareModulesByFullName } = require("../util/comparators");
14
+ const createHooksRegistry = require("../util/createHooksRegistry");
15
15
  const memoize = require("../util/memoize");
16
16
  const AsyncWasmModule = require("./AsyncWasmModule");
17
17
 
@@ -59,37 +59,9 @@ const getAsyncWebAssemblyParser = memoize(() =>
59
59
  * @property {boolean=} mangleImports mangle imports
60
60
  */
61
61
 
62
- /** @type {WeakMap<Compilation, CompilationHooks>} */
63
- const compilationHooksMap = new WeakMap();
64
-
65
62
  const PLUGIN_NAME = "AsyncWebAssemblyModulesPlugin";
66
63
 
67
64
  class AsyncWebAssemblyModulesPlugin {
68
- /**
69
- * Returns the attached hooks.
70
- * @param {Compilation} compilation the compilation
71
- * @returns {CompilationHooks} the attached hooks
72
- */
73
- static getCompilationHooks(compilation) {
74
- if (!(compilation instanceof Compilation)) {
75
- throw new TypeError(
76
- "The 'compilation' argument must be an instance of Compilation"
77
- );
78
- }
79
- let hooks = compilationHooksMap.get(compilation);
80
- if (hooks === undefined) {
81
- hooks = {
82
- renderModuleContent: new SyncWaterfallHook([
83
- "source",
84
- "module",
85
- "renderContext"
86
- ])
87
- };
88
- compilationHooksMap.set(compilation, hooks);
89
- }
90
- return hooks;
91
- }
92
-
93
65
  /**
94
66
  * Creates an instance of AsyncWebAssemblyModulesPlugin.
95
67
  * @param {AsyncWebAssemblyModulesPluginOptions} options options
@@ -224,4 +196,15 @@ class AsyncWebAssemblyModulesPlugin {
224
196
  }
225
197
  }
226
198
 
199
+ AsyncWebAssemblyModulesPlugin.getCompilationHooks = createHooksRegistry(
200
+ () =>
201
+ /** @type {CompilationHooks} */ ({
202
+ renderModuleContent: new SyncWaterfallHook([
203
+ "source",
204
+ "module",
205
+ "renderContext"
206
+ ])
207
+ })
208
+ );
209
+
227
210
  module.exports = AsyncWebAssemblyModulesPlugin;
@@ -5,7 +5,7 @@
5
5
  "use strict";
6
6
 
7
7
  const { SyncWaterfallHook } = require("tapable");
8
- const Compilation = require("../Compilation");
8
+ /** @typedef {import("../Compilation")} Compilation */
9
9
  const RuntimeGlobals = require("../RuntimeGlobals");
10
10
  const RuntimeModule = require("../RuntimeModule");
11
11
  const Template = require("../Template");
@@ -15,6 +15,7 @@ const {
15
15
  const chunkHasJs = require("../javascript/JavascriptModulesPlugin").chunkHasJs;
16
16
  const { getInitialChunkIds } = require("../javascript/StartupHelpers");
17
17
  const compileBooleanMatcher = require("../util/compileBooleanMatcher");
18
+ const createHooksRegistry = require("../util/createHooksRegistry");
18
19
 
19
20
  /** @typedef {import("../Chunk")} Chunk */
20
21
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
@@ -26,31 +27,7 @@ const compileBooleanMatcher = require("../util/compileBooleanMatcher");
26
27
  * @property {SyncWaterfallHook<[string, Chunk]>} linkPrefetch
27
28
  */
28
29
 
29
- /** @type {WeakMap<Compilation, JsonpCompilationPluginHooks>} */
30
- const compilationHooksMap = new WeakMap();
31
-
32
30
  class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
33
- /**
34
- * @param {Compilation} compilation the compilation
35
- * @returns {JsonpCompilationPluginHooks} hooks
36
- */
37
- static getCompilationHooks(compilation) {
38
- if (!(compilation instanceof Compilation)) {
39
- throw new TypeError(
40
- "The 'compilation' argument must be an instance of Compilation"
41
- );
42
- }
43
- let hooks = compilationHooksMap.get(compilation);
44
- if (hooks === undefined) {
45
- hooks = {
46
- linkPreload: new SyncWaterfallHook(["source", "chunk"]),
47
- linkPrefetch: new SyncWaterfallHook(["source", "chunk"])
48
- };
49
- compilationHooksMap.set(compilation, hooks);
50
- }
51
- return hooks;
52
- }
53
-
54
31
  /**
55
32
  * @param {ReadOnlyRuntimeRequirements} runtimeRequirements runtime requirements
56
33
  */
@@ -459,4 +436,12 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
459
436
  }
460
437
  }
461
438
 
439
+ JsonpChunkLoadingRuntimeModule.getCompilationHooks = createHooksRegistry(
440
+ () =>
441
+ /** @type {JsonpCompilationPluginHooks} */ ({
442
+ linkPreload: new SyncWaterfallHook(["source", "chunk"]),
443
+ linkPrefetch: new SyncWaterfallHook(["source", "chunk"])
444
+ })
445
+ );
446
+
462
447
  module.exports = JsonpChunkLoadingRuntimeModule;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "5.108.0",
3
+ "version": "5.108.2",
4
4
  "description": "Packs ECMAScript/CommonJs/AMD modules for the browser. Allows you to split your codebase into multiple bundles, which can be loaded on demand. Supports loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
5
5
  "homepage": "https://github.com/webpack/webpack",
6
6
  "bugs": "https://github.com/webpack/webpack/issues",
@@ -182,6 +182,7 @@
182
182
  "prettier-2": "npm:prettier@^2",
183
183
  "pretty-format": "^30.0.5",
184
184
  "pug": "^3.0.3",
185
+ "puppeteer-core": "^23.11.1",
185
186
  "raw-loader": "^4.0.1",
186
187
  "react": "^19.2.7",
187
188
  "react-dom": "^19.2.7",