webpack 5.90.2 → 5.91.0

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.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (182) hide show
  1. package/README.md +5 -5
  2. package/bin/webpack.js +5 -1
  3. package/lib/APIPlugin.js +8 -4
  4. package/lib/AutomaticPrefetchPlugin.js +1 -1
  5. package/lib/BannerPlugin.js +3 -1
  6. package/lib/Cache.js +7 -1
  7. package/lib/CacheFacade.js +3 -3
  8. package/lib/ChunkGraph.js +32 -18
  9. package/lib/ChunkGroup.js +14 -14
  10. package/lib/CleanPlugin.js +7 -5
  11. package/lib/Compilation.js +263 -94
  12. package/lib/Compiler.js +199 -83
  13. package/lib/ConditionalInitFragment.js +4 -5
  14. package/lib/ContextModule.js +4 -1
  15. package/lib/ContextModuleFactory.js +4 -2
  16. package/lib/ContextReplacementPlugin.js +3 -2
  17. package/lib/CssModule.js +0 -3
  18. package/lib/DefinePlugin.js +4 -2
  19. package/lib/DelegatedModule.js +2 -1
  20. package/lib/Dependency.js +4 -2
  21. package/lib/DependencyTemplate.js +7 -2
  22. package/lib/DllModule.js +3 -1
  23. package/lib/DllReferencePlugin.js +6 -2
  24. package/lib/EntryOptionPlugin.js +4 -1
  25. package/lib/EntryPlugin.js +6 -1
  26. package/lib/Entrypoint.js +1 -1
  27. package/lib/ExportsInfo.js +1 -4
  28. package/lib/ExternalModule.js +120 -25
  29. package/lib/ExternalModuleFactoryPlugin.js +37 -2
  30. package/lib/FileSystemInfo.js +1 -1
  31. package/lib/Generator.js +2 -1
  32. package/lib/HookWebpackError.js +2 -2
  33. package/lib/InitFragment.js +5 -3
  34. package/lib/LibManifestPlugin.js +15 -7
  35. package/lib/Module.js +54 -5
  36. package/lib/ModuleFilenameHelpers.js +1 -1
  37. package/lib/ModuleGraph.js +56 -27
  38. package/lib/ModuleGraphConnection.js +2 -1
  39. package/lib/MultiCompiler.js +61 -17
  40. package/lib/NodeStuffPlugin.js +14 -3
  41. package/lib/NormalModule.js +239 -86
  42. package/lib/NormalModuleFactory.js +163 -32
  43. package/lib/NormalModuleReplacementPlugin.js +5 -1
  44. package/lib/ProvidePlugin.js +3 -1
  45. package/lib/RawModule.js +4 -2
  46. package/lib/ResolverFactory.js +5 -1
  47. package/lib/RuntimeModule.js +6 -5
  48. package/lib/RuntimePlugin.js +1 -0
  49. package/lib/RuntimeTemplate.js +102 -34
  50. package/lib/SourceMapDevToolPlugin.js +4 -1
  51. package/lib/Stats.js +12 -5
  52. package/lib/TemplatedPathPlugin.js +32 -6
  53. package/lib/Watching.js +67 -60
  54. package/lib/WebpackError.js +6 -6
  55. package/lib/WebpackOptionsApply.js +18 -5
  56. package/lib/asset/RawDataUrlModule.js +5 -2
  57. package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
  58. package/lib/buildChunkGraph.js +220 -392
  59. package/lib/cache/IdleFileCachePlugin.js +8 -3
  60. package/lib/cache/MemoryCachePlugin.js +1 -1
  61. package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
  62. package/lib/cache/PackFileCacheStrategy.js +49 -16
  63. package/lib/cache/ResolverCachePlugin.js +14 -6
  64. package/lib/cache/getLazyHashedEtag.js +1 -1
  65. package/lib/config/defaults.js +24 -1
  66. package/lib/config/normalization.js +3 -1
  67. package/lib/container/ContainerEntryDependency.js +2 -1
  68. package/lib/container/ContainerEntryModule.js +5 -2
  69. package/lib/container/ContainerPlugin.js +14 -10
  70. package/lib/container/FallbackModule.js +3 -2
  71. package/lib/container/RemoteModule.js +2 -1
  72. package/lib/container/RemoteRuntimeModule.js +12 -3
  73. package/lib/css/CssExportsGenerator.js +34 -17
  74. package/lib/css/CssGenerator.js +20 -2
  75. package/lib/css/CssLoadingRuntimeModule.js +212 -96
  76. package/lib/css/CssModulesPlugin.js +47 -13
  77. package/lib/debug/ProfilingPlugin.js +27 -2
  78. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
  79. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
  80. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
  81. package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
  82. package/lib/dependencies/CommonJsExportsDependency.js +13 -5
  83. package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
  84. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
  85. package/lib/dependencies/ContextDependencyHelpers.js +49 -29
  86. package/lib/dependencies/ContextElementDependency.js +8 -1
  87. package/lib/dependencies/CssLocalIdentifierDependency.js +63 -8
  88. package/lib/dependencies/CssUrlDependency.js +5 -3
  89. package/lib/dependencies/ExportsInfoDependency.js +4 -3
  90. package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
  91. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
  92. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
  93. package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
  94. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
  95. package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
  96. package/lib/dependencies/HarmonyImportDependency.js +28 -12
  97. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +44 -16
  98. package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
  99. package/lib/dependencies/HarmonyImportSpecifierDependency.js +21 -10
  100. package/lib/dependencies/ImportDependency.js +9 -2
  101. package/lib/dependencies/ImportEagerDependency.js +4 -2
  102. package/lib/dependencies/ImportMetaContextDependency.js +7 -0
  103. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
  104. package/lib/dependencies/ImportParserPlugin.js +12 -4
  105. package/lib/dependencies/ImportWeakDependency.js +4 -2
  106. package/lib/dependencies/LoaderDependency.js +2 -1
  107. package/lib/dependencies/LoaderImportDependency.js +2 -1
  108. package/lib/dependencies/ModuleDependency.js +4 -5
  109. package/lib/dependencies/PureExpressionDependency.js +4 -1
  110. package/lib/dependencies/RequireContextPlugin.js +1 -1
  111. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
  112. package/lib/dependencies/RequireEnsureDependency.js +1 -1
  113. package/lib/dependencies/URLDependency.js +7 -4
  114. package/lib/dependencies/WorkerDependency.js +1 -1
  115. package/lib/dependencies/WorkerPlugin.js +6 -5
  116. package/lib/dependencies/getFunctionExpression.js +3 -1
  117. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +2 -1
  118. package/lib/hmr/LazyCompilationPlugin.js +2 -1
  119. package/lib/javascript/BasicEvaluatedExpression.js +2 -2
  120. package/lib/javascript/ChunkHelpers.js +2 -2
  121. package/lib/javascript/JavascriptParser.js +169 -57
  122. package/lib/javascript/JavascriptParserHelpers.js +1 -1
  123. package/lib/javascript/StartupHelpers.js +22 -5
  124. package/lib/logging/Logger.js +27 -2
  125. package/lib/logging/createConsoleLogger.js +11 -7
  126. package/lib/node/NodeEnvironmentPlugin.js +13 -7
  127. package/lib/node/NodeWatchFileSystem.js +37 -26
  128. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
  129. package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
  130. package/lib/node/nodeConsole.js +24 -1
  131. package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
  132. package/lib/optimize/ConcatenatedModule.js +140 -55
  133. package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
  134. package/lib/optimize/InnerGraph.js +7 -2
  135. package/lib/optimize/InnerGraphPlugin.js +36 -13
  136. package/lib/optimize/ModuleConcatenationPlugin.js +12 -2
  137. package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
  138. package/lib/optimize/RuntimeChunkPlugin.js +6 -1
  139. package/lib/optimize/SideEffectsFlagPlugin.js +46 -15
  140. package/lib/optimize/SplitChunksPlugin.js +2 -2
  141. package/lib/performance/SizeLimitsPlugin.js +11 -0
  142. package/lib/rules/ObjectMatcherRulePlugin.js +4 -0
  143. package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
  144. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
  145. package/lib/serialization/FileMiddleware.js +1 -0
  146. package/lib/serialization/ObjectMiddleware.js +2 -0
  147. package/lib/serialization/Serializer.js +19 -0
  148. package/lib/sharing/ConsumeSharedModule.js +3 -2
  149. package/lib/sharing/ConsumeSharedPlugin.js +17 -3
  150. package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
  151. package/lib/sharing/ProvideSharedModule.js +2 -1
  152. package/lib/sharing/ProvideSharedPlugin.js +12 -5
  153. package/lib/sharing/resolveMatchedConfigs.js +2 -2
  154. package/lib/sharing/utils.js +13 -6
  155. package/lib/util/StackedCacheMap.js +26 -0
  156. package/lib/util/WeakTupleMap.js +57 -13
  157. package/lib/util/cleverMerge.js +24 -11
  158. package/lib/util/comparators.js +34 -14
  159. package/lib/util/conventions.js +129 -0
  160. package/lib/util/fs.js +379 -65
  161. package/lib/util/hash/BatchedHash.js +3 -0
  162. package/lib/util/hash/xxhash64.js +2 -2
  163. package/lib/util/memoize.js +2 -0
  164. package/lib/util/runtime.js +1 -1
  165. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
  166. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +15 -6
  167. package/lib/wasm-sync/WebAssemblyGenerator.js +27 -6
  168. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +2 -1
  169. package/lib/wasm-sync/WebAssemblyParser.js +7 -4
  170. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -1
  171. package/lib/webpack.js +11 -5
  172. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
  173. package/package.json +25 -26
  174. package/schemas/WebpackOptions.check.js +1 -1
  175. package/schemas/WebpackOptions.json +69 -8
  176. package/schemas/plugins/BannerPlugin.check.js +1 -1
  177. package/schemas/plugins/BannerPlugin.json +5 -1
  178. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
  179. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  180. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  181. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  182. package/types.d.ts +1772 -673
@@ -19,6 +19,7 @@ const ArrayQueue = require("./util/ArrayQueue");
19
19
  /** @typedef {import("./Compiler")} Compiler */
20
20
  /** @typedef {import("./Stats")} Stats */
21
21
  /** @typedef {import("./Watching")} Watching */
22
+ /** @typedef {import("./logging/Logger").Logger} Logger */
22
23
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
23
24
  /** @typedef {import("./util/fs").IntermediateFileSystem} IntermediateFileSystem */
24
25
  /** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
@@ -27,7 +28,7 @@ const ArrayQueue = require("./util/ArrayQueue");
27
28
  /**
28
29
  * @template T
29
30
  * @callback Callback
30
- * @param {(Error | null)=} err
31
+ * @param {Error | null} err
31
32
  * @param {T=} result
32
33
  */
33
34
 
@@ -49,9 +50,11 @@ module.exports = class MultiCompiler {
49
50
  */
50
51
  constructor(compilers, options) {
51
52
  if (!Array.isArray(compilers)) {
53
+ /** @type {Compiler[]} */
52
54
  compilers = Object.keys(compilers).map(name => {
53
- compilers[name].name = name;
54
- return compilers[name];
55
+ /** @type {Record<string, Compiler>} */
56
+ (compilers)[name].name = name;
57
+ return /** @type {Record<string, Compiler>} */ (compilers)[name];
55
58
  });
56
59
  }
57
60
 
@@ -80,7 +83,7 @@ module.exports = class MultiCompiler {
80
83
  this.dependencies = new WeakMap();
81
84
  this.running = false;
82
85
 
83
- /** @type {Stats[]} */
86
+ /** @type {(Stats | null)[]} */
84
87
  const compilerStats = this.compilers.map(() => null);
85
88
  let doneCompilers = 0;
86
89
  for (let index = 0; index < this.compilers.length; index++) {
@@ -94,7 +97,9 @@ module.exports = class MultiCompiler {
94
97
  }
95
98
  compilerStats[compilerIndex] = stats;
96
99
  if (doneCompilers === this.compilers.length) {
97
- this.hooks.done.call(new MultiStats(compilerStats));
100
+ this.hooks.done.call(
101
+ new MultiStats(/** @type {Stats[]} */ (compilerStats))
102
+ );
98
103
  }
99
104
  });
100
105
  compiler.hooks.invalid.tap("MultiCompiler", () => {
@@ -180,6 +185,10 @@ module.exports = class MultiCompiler {
180
185
  }
181
186
  }
182
187
 
188
+ /**
189
+ * @param {string | (function(): string)} name name of the logger, or function called once to get the logger name
190
+ * @returns {Logger} a logger with that name
191
+ */
183
192
  getInfrastructureLogger(name) {
184
193
  return this.compilers[0].getInfrastructureLogger(name);
185
194
  }
@@ -202,6 +211,10 @@ module.exports = class MultiCompiler {
202
211
  const edges = new Set();
203
212
  /** @type {string[]} */
204
213
  const missing = [];
214
+ /**
215
+ * @param {Compiler} compiler compiler
216
+ * @returns {boolean} target was found
217
+ */
205
218
  const targetFound = compiler => {
206
219
  for (const edge of edges) {
207
220
  if (edge.target === compiler) {
@@ -210,10 +223,19 @@ module.exports = class MultiCompiler {
210
223
  }
211
224
  return false;
212
225
  };
226
+ /**
227
+ * @param {{source: Compiler, target: Compiler}} e1 edge 1
228
+ * @param {{source: Compiler, target: Compiler}} e2 edge 2
229
+ * @returns {number} result
230
+ */
213
231
  const sortEdges = (e1, e2) => {
214
232
  return (
215
- e1.source.name.localeCompare(e2.source.name) ||
216
- e1.target.name.localeCompare(e2.target.name)
233
+ /** @type {string} */
234
+ (e1.source.name).localeCompare(
235
+ /** @type {string} */ (e2.source.name)
236
+ ) ||
237
+ /** @type {string} */
238
+ (e1.target.name).localeCompare(/** @type {string} */ (e2.target.name))
217
239
  );
218
240
  };
219
241
  for (const source of this.compilers) {
@@ -274,7 +296,14 @@ module.exports = class MultiCompiler {
274
296
  runWithDependencies(compilers, fn, callback) {
275
297
  const fulfilledNames = new Set();
276
298
  let remainingCompilers = compilers;
299
+ /**
300
+ * @param {string} d dependency
301
+ * @returns {boolean} when dependency was fulfilled
302
+ */
277
303
  const isDependencyFulfilled = d => fulfilledNames.has(d);
304
+ /**
305
+ * @returns {Compiler[]} compilers
306
+ */
278
307
  const getReadyCompilers = () => {
279
308
  let readyCompilers = [];
280
309
  let list = remainingCompilers;
@@ -291,8 +320,12 @@ module.exports = class MultiCompiler {
291
320
  }
292
321
  return readyCompilers;
293
322
  };
323
+ /**
324
+ * @param {Callback<MultiStats>} callback callback
325
+ * @returns {void}
326
+ */
294
327
  const runCompilers = callback => {
295
- if (remainingCompilers.length === 0) return callback();
328
+ if (remainingCompilers.length === 0) return callback(null);
296
329
  asyncLib.map(
297
330
  getReadyCompilers(),
298
331
  (compiler, callback) => {
@@ -302,7 +335,9 @@ module.exports = class MultiCompiler {
302
335
  runCompilers(callback);
303
336
  });
304
337
  },
305
- callback
338
+ (err, results) => {
339
+ callback(err, /** @type {TODO} */ (results));
340
+ }
306
341
  );
307
342
  };
308
343
  runCompilers(callback);
@@ -316,7 +351,7 @@ module.exports = class MultiCompiler {
316
351
  * @returns {SetupResult[]} result of setup
317
352
  */
318
353
  _runGraph(setup, run, callback) {
319
- /** @typedef {{ compiler: Compiler, setupResult: SetupResult, result: Stats, state: "pending" | "blocked" | "queued" | "starting" | "running" | "running-outdated" | "done", children: Node[], parents: Node[] }} Node */
354
+ /** @typedef {{ compiler: Compiler, setupResult: undefined | SetupResult, result: undefined | Stats, state: "pending" | "blocked" | "queued" | "starting" | "running" | "running-outdated" | "done", children: Node[], parents: Node[] }} Node */
320
355
 
321
356
  // State transitions for nodes:
322
357
  // -> blocked (initial)
@@ -341,12 +376,14 @@ module.exports = class MultiCompiler {
341
376
  }));
342
377
  /** @type {Map<string, Node>} */
343
378
  const compilerToNode = new Map();
344
- for (const node of nodes) compilerToNode.set(node.compiler.name, node);
379
+ for (const node of nodes) {
380
+ compilerToNode.set(/** @type {string} */ (node.compiler.name), node);
381
+ }
345
382
  for (const node of nodes) {
346
383
  const dependencies = this.dependencies.get(node.compiler);
347
384
  if (!dependencies) continue;
348
385
  for (const dep of dependencies) {
349
- const parent = compilerToNode.get(dep);
386
+ const parent = /** @type {Node} */ (compilerToNode.get(dep));
350
387
  node.parents.push(parent);
351
388
  parent.children.push(node);
352
389
  }
@@ -361,10 +398,10 @@ module.exports = class MultiCompiler {
361
398
  }
362
399
  let errored = false;
363
400
  let running = 0;
364
- const parallelism = this._options.parallelism;
401
+ const parallelism = /** @type {number} */ (this._options.parallelism);
365
402
  /**
366
403
  * @param {Node} node node
367
- * @param {Error=} err error
404
+ * @param {(Error | null)=} err error
368
405
  * @param {Stats=} stats result
369
406
  * @returns {void}
370
407
  */
@@ -440,6 +477,7 @@ module.exports = class MultiCompiler {
440
477
  }
441
478
  };
442
479
 
480
+ /** @type {SetupResult[]} */
443
481
  const setupResults = [];
444
482
  nodes.forEach((node, i) => {
445
483
  setupResults.push(
@@ -461,7 +499,7 @@ module.exports = class MultiCompiler {
461
499
  };
462
500
  const processQueueWorker = () => {
463
501
  while (running < parallelism && queue.length > 0 && !errored) {
464
- const node = queue.dequeue();
502
+ const node = /** @type {Node} */ (queue.dequeue());
465
503
  if (
466
504
  node.state === "queued" ||
467
505
  (node.state === "blocked" &&
@@ -469,7 +507,11 @@ module.exports = class MultiCompiler {
469
507
  ) {
470
508
  running++;
471
509
  node.state = "starting";
472
- run(node.compiler, node.setupResult, nodeDone.bind(null, node));
510
+ run(
511
+ node.compiler,
512
+ /** @type {SetupResult} */ (node.setupResult),
513
+ nodeDone.bind(null, node)
514
+ );
473
515
  node.state = "running";
474
516
  }
475
517
  }
@@ -576,7 +618,9 @@ module.exports = class MultiCompiler {
576
618
  (compiler, callback) => {
577
619
  compiler.close(callback);
578
620
  },
579
- callback
621
+ error => {
622
+ callback(error);
623
+ }
580
624
  );
581
625
  }
582
626
  };
@@ -32,6 +32,7 @@ const { parseResource } = require("./util/identifier");
32
32
  /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
33
33
  /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
34
34
  /** @typedef {import("./javascript/JavascriptParser").Range} Range */
35
+ /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
35
36
 
36
37
  const PLUGIN_NAME = "NodeStuffPlugin";
37
38
 
@@ -193,7 +194,11 @@ class NodeStuffPlugin {
193
194
  break;
194
195
  case true:
195
196
  setModuleConstant("__filename", module =>
196
- relative(compiler.inputFileSystem, context, module.resource)
197
+ relative(
198
+ /** @type {InputFileSystem} */ (compiler.inputFileSystem),
199
+ context,
200
+ module.resource
201
+ )
197
202
  );
198
203
  break;
199
204
  }
@@ -227,7 +232,11 @@ class NodeStuffPlugin {
227
232
  break;
228
233
  case true:
229
234
  setModuleConstant("__dirname", module =>
230
- relative(compiler.inputFileSystem, context, module.context)
235
+ relative(
236
+ /** @type {InputFileSystem} */ (compiler.inputFileSystem),
237
+ context,
238
+ /** @type {string} */ (module.context)
239
+ )
231
240
  );
232
241
  break;
233
242
  }
@@ -236,7 +245,9 @@ class NodeStuffPlugin {
236
245
  .for("__dirname")
237
246
  .tap(PLUGIN_NAME, expr => {
238
247
  if (!parser.state.module) return;
239
- return evaluateToString(parser.state.module.context)(expr);
248
+ return evaluateToString(
249
+ /** @type {string} */ (parser.state.module.context)
250
+ )(expr);
240
251
  });
241
252
  }
242
253
  parser.hooks.expression