webpack 5.91.0 → 5.92.1

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 (174) hide show
  1. package/bin/webpack.js +1 -2
  2. package/lib/APIPlugin.js +6 -2
  3. package/lib/Cache.js +1 -1
  4. package/lib/Chunk.js +7 -4
  5. package/lib/ChunkGraph.js +20 -7
  6. package/lib/ChunkGroup.js +9 -3
  7. package/lib/CleanPlugin.js +1 -1
  8. package/lib/Compilation.js +33 -27
  9. package/lib/Compiler.js +28 -8
  10. package/lib/ConcatenationScope.js +3 -3
  11. package/lib/ContextModule.js +95 -43
  12. package/lib/DefinePlugin.js +14 -4
  13. package/lib/Dependency.js +8 -8
  14. package/lib/DependencyTemplate.js +10 -5
  15. package/lib/DllReferencePlugin.js +1 -1
  16. package/lib/EvalDevToolModulePlugin.js +11 -0
  17. package/lib/ExportsInfo.js +22 -4
  18. package/lib/ExternalModule.js +49 -18
  19. package/lib/FileSystemInfo.js +68 -41
  20. package/lib/FlagDependencyExportsPlugin.js +21 -7
  21. package/lib/Generator.js +2 -3
  22. package/lib/HotModuleReplacementPlugin.js +108 -45
  23. package/lib/IgnorePlugin.js +4 -1
  24. package/lib/LibManifestPlugin.js +2 -2
  25. package/lib/Module.js +11 -12
  26. package/lib/ModuleFactory.js +3 -3
  27. package/lib/ModuleFilenameHelpers.js +29 -16
  28. package/lib/ModuleGraph.js +5 -5
  29. package/lib/MultiCompiler.js +36 -1
  30. package/lib/NormalModule.js +10 -12
  31. package/lib/NormalModuleFactory.js +17 -8
  32. package/lib/Parser.js +1 -1
  33. package/lib/PlatformPlugin.js +39 -0
  34. package/lib/ProgressPlugin.js +1 -1
  35. package/lib/RecordIdsPlugin.js +4 -4
  36. package/lib/ResolverFactory.js +3 -3
  37. package/lib/RuntimeTemplate.js +22 -18
  38. package/lib/Stats.js +1 -1
  39. package/lib/Template.js +5 -5
  40. package/lib/TemplatedPathPlugin.js +16 -1
  41. package/lib/asset/AssetGenerator.js +15 -0
  42. package/lib/buildChunkGraph.js +3 -3
  43. package/lib/cache/MemoryWithGcCachePlugin.js +1 -1
  44. package/lib/cache/PackFileCacheStrategy.js +2 -2
  45. package/lib/cache/ResolverCachePlugin.js +8 -8
  46. package/lib/cache/getLazyHashedEtag.js +1 -1
  47. package/lib/cli.js +5 -5
  48. package/lib/config/browserslistTargetHandler.js +7 -1
  49. package/lib/config/defaults.js +85 -34
  50. package/lib/config/target.js +18 -11
  51. package/lib/container/ContainerEntryModule.js +1 -1
  52. package/lib/css/CssExportsGenerator.js +43 -17
  53. package/lib/css/CssGenerator.js +22 -12
  54. package/lib/css/CssLoadingRuntimeModule.js +8 -5
  55. package/lib/css/CssModulesPlugin.js +197 -100
  56. package/lib/css/CssParser.js +24 -15
  57. package/lib/css/walkCssTokens.js +1 -1
  58. package/lib/debug/ProfilingPlugin.js +1 -1
  59. package/lib/dependencies/ContextElementDependency.js +2 -2
  60. package/lib/dependencies/CssExportDependency.js +2 -2
  61. package/lib/dependencies/CssLocalIdentifierDependency.js +9 -2
  62. package/lib/dependencies/CssUrlDependency.js +5 -4
  63. package/lib/dependencies/ExportsInfoDependency.js +1 -1
  64. package/lib/dependencies/ExternalModuleDependency.js +4 -2
  65. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +2 -2
  66. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -2
  67. package/lib/dependencies/HarmonyImportDependency.js +2 -2
  68. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +41 -18
  69. package/lib/dependencies/HarmonyImportSideEffectDependency.js +2 -2
  70. package/lib/dependencies/HarmonyImportSpecifierDependency.js +43 -32
  71. package/lib/dependencies/ImportDependency.js +2 -2
  72. package/lib/dependencies/ImportEagerDependency.js +2 -2
  73. package/lib/dependencies/ImportMetaPlugin.js +1 -1
  74. package/lib/dependencies/ImportParserPlugin.js +3 -1
  75. package/lib/dependencies/ImportWeakDependency.js +2 -2
  76. package/lib/dependencies/LoaderPlugin.js +2 -2
  77. package/lib/dependencies/ModuleDependency.js +2 -2
  78. package/lib/dependencies/PureExpressionDependency.js +63 -49
  79. package/lib/dependencies/WorkerDependency.js +1 -1
  80. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +90 -2
  81. package/lib/hmr/LazyCompilationPlugin.js +2 -2
  82. package/lib/ids/ChunkModuleIdRangePlugin.js +1 -1
  83. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
  84. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  85. package/lib/ids/IdHelpers.js +6 -6
  86. package/lib/ids/NamedChunkIdsPlugin.js +1 -1
  87. package/lib/ids/NamedModuleIdsPlugin.js +1 -1
  88. package/lib/ids/SyncModuleIdsPlugin.js +2 -2
  89. package/lib/index.js +11 -0
  90. package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
  91. package/lib/javascript/JavascriptGenerator.js +0 -1
  92. package/lib/javascript/JavascriptModulesPlugin.js +174 -17
  93. package/lib/javascript/JavascriptParser.js +37 -16
  94. package/lib/library/AbstractLibraryPlugin.js +2 -2
  95. package/lib/library/AmdLibraryPlugin.js +2 -2
  96. package/lib/library/AssignLibraryPlugin.js +3 -3
  97. package/lib/library/ExportPropertyLibraryPlugin.js +2 -2
  98. package/lib/library/JsonpLibraryPlugin.js +2 -2
  99. package/lib/library/ModuleLibraryPlugin.js +2 -2
  100. package/lib/library/SystemLibraryPlugin.js +2 -2
  101. package/lib/library/UmdLibraryPlugin.js +33 -12
  102. package/lib/logging/createConsoleLogger.js +2 -2
  103. package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
  104. package/lib/node/NodeEnvironmentPlugin.js +1 -1
  105. package/lib/node/NodeTemplatePlugin.js +1 -1
  106. package/lib/node/ReadFileCompileWasmPlugin.js +1 -1
  107. package/lib/node/nodeConsole.js +1 -1
  108. package/lib/optimize/AggressiveMergingPlugin.js +1 -1
  109. package/lib/optimize/ConcatenatedModule.js +11 -76
  110. package/lib/optimize/InnerGraph.js +1 -1
  111. package/lib/optimize/LimitChunkCountPlugin.js +1 -2
  112. package/lib/optimize/ModuleConcatenationPlugin.js +1 -1
  113. package/lib/optimize/RealContentHashPlugin.js +3 -3
  114. package/lib/optimize/SideEffectsFlagPlugin.js +2 -2
  115. package/lib/optimize/SplitChunksPlugin.js +8 -8
  116. package/lib/performance/SizeLimitsPlugin.js +2 -2
  117. package/lib/rules/ObjectMatcherRulePlugin.js +11 -1
  118. package/lib/rules/RuleSetCompiler.js +9 -7
  119. package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
  120. package/lib/runtime/StartupChunkDependenciesPlugin.js +1 -1
  121. package/lib/schemes/HttpUriPlugin.js +1 -1
  122. package/lib/serialization/BinaryMiddleware.js +4 -4
  123. package/lib/serialization/FileMiddleware.js +3 -3
  124. package/lib/serialization/NullPrototypeObjectSerializer.js +2 -2
  125. package/lib/serialization/ObjectMiddleware.js +6 -5
  126. package/lib/serialization/PlainObjectSerializer.js +2 -2
  127. package/lib/serialization/SerializerMiddleware.js +2 -2
  128. package/lib/serialization/SingleItemMiddleware.js +2 -2
  129. package/lib/serialization/types.js +1 -1
  130. package/lib/sharing/ConsumeSharedModule.js +1 -1
  131. package/lib/sharing/ProvideSharedPlugin.js +1 -1
  132. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  133. package/lib/stats/DefaultStatsFactoryPlugin.js +20 -20
  134. package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
  135. package/lib/stats/StatsFactory.js +2 -2
  136. package/lib/stats/StatsPrinter.js +6 -6
  137. package/lib/util/ArrayQueue.js +14 -21
  138. package/lib/util/AsyncQueue.js +1 -1
  139. package/lib/util/Queue.js +8 -2
  140. package/lib/util/SortableSet.js +16 -4
  141. package/lib/util/TupleQueue.js +8 -2
  142. package/lib/util/WeakTupleMap.js +3 -3
  143. package/lib/util/binarySearchBounds.js +1 -1
  144. package/lib/util/cleverMerge.js +2 -2
  145. package/lib/util/comparators.js +4 -2
  146. package/lib/util/conventions.js +1 -1
  147. package/lib/util/createHash.js +3 -5
  148. package/lib/util/deprecation.js +3 -3
  149. package/lib/util/deterministicGrouping.js +2 -2
  150. package/lib/util/findGraphRoots.js +1 -1
  151. package/lib/util/fs.js +15 -15
  152. package/lib/util/identifier.js +5 -5
  153. package/lib/util/mergeScope.js +79 -0
  154. package/lib/util/runtime.js +2 -17
  155. package/lib/util/semver.js +3 -0
  156. package/lib/util/smartGrouping.js +3 -3
  157. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +4 -2
  158. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
  159. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
  160. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +1 -1
  161. package/lib/wasm-sync/WebAssemblyGenerator.js +17 -17
  162. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
  163. package/lib/wasm-sync/WebAssemblyUtils.js +2 -1
  164. package/lib/web/FetchCompileWasmPlugin.js +1 -1
  165. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
  166. package/lib/webpack.js +12 -3
  167. package/package.json +20 -18
  168. package/schemas/WebpackOptions.check.js +1 -1
  169. package/schemas/WebpackOptions.json +30 -2
  170. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
  171. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  172. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  173. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  174. package/types.d.ts +213 -81
@@ -42,19 +42,28 @@ const {
42
42
  WEBPACK_MODULE_TYPE_RUNTIME
43
43
  } = require("./ModuleTypeConstants");
44
44
 
45
+ /** @typedef {import("estree").CallExpression} CallExpression */
46
+ /** @typedef {import("estree").Expression} Expression */
45
47
  /** @typedef {import("./Chunk")} Chunk */
48
+ /** @typedef {import("./Chunk").ChunkId} ChunkId */
46
49
  /** @typedef {import("./Compilation").AssetInfo} AssetInfo */
47
50
  /** @typedef {import("./Compiler")} Compiler */
51
+ /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
48
52
  /** @typedef {import("./Module")} Module */
53
+ /** @typedef {import("./Module").BuildInfo} BuildInfo */
49
54
  /** @typedef {import("./RuntimeModule")} RuntimeModule */
55
+ /** @typedef {import("./javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
56
+ /** @typedef {import("./javascript/JavascriptParserHelpers").Range} Range */
50
57
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
51
58
 
52
59
  /**
53
- * @typedef {Object} HMRJavascriptParserHooks
60
+ * @typedef {object} HMRJavascriptParserHooks
54
61
  * @property {SyncBailHook<[TODO, string[]], void>} hotAcceptCallback
55
62
  * @property {SyncBailHook<[TODO, string[]], void>} hotAcceptWithoutCallback
56
63
  */
57
64
 
65
+ /** @typedef {Map<string, { updatedChunkIds: Set<ChunkId>, removedChunkIds: Set<ChunkId>, removedModules: Set<Module>, filename: string, assetInfo: AssetInfo }>} HotUpdateMainContentByRuntime */
66
+
58
67
  /** @type {WeakMap<JavascriptParser, HMRJavascriptParserHooks>} */
59
68
  const parserHooksMap = new WeakMap();
60
69
 
@@ -82,6 +91,9 @@ class HotModuleReplacementPlugin {
82
91
  return hooks;
83
92
  }
84
93
 
94
+ /**
95
+ * @param {object=} options options
96
+ */
85
97
  constructor(options) {
86
98
  this.options = options || {};
87
99
  }
@@ -97,6 +109,11 @@ class HotModuleReplacementPlugin {
97
109
  compiler.options.output.strictModuleErrorHandling = true;
98
110
  const runtimeRequirements = [RuntimeGlobals.module];
99
111
 
112
+ /**
113
+ * @param {JavascriptParser} parser the parser
114
+ * @param {typeof ModuleHotAcceptDependency} ParamDependency dependency
115
+ * @returns {(expr: CallExpression) => boolean | undefined} callback
116
+ */
100
117
  const createAcceptHandler = (parser, ParamDependency) => {
101
118
  const { hotAcceptCallback, hotAcceptWithoutCallback } =
102
119
  HotModuleReplacementPlugin.getParserHooks(parser);
@@ -105,27 +122,38 @@ class HotModuleReplacementPlugin {
105
122
  const module = parser.state.module;
106
123
  const dep = new ConstDependency(
107
124
  `${module.moduleArgument}.hot.accept`,
108
- expr.callee.range,
125
+ /** @type {Range} */ (expr.callee.range),
109
126
  runtimeRequirements
110
127
  );
111
- dep.loc = expr.loc;
128
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
112
129
  module.addPresentationalDependency(dep);
113
- module.buildInfo.moduleConcatenationBailout = "Hot Module Replacement";
130
+ /** @type {BuildInfo} */
131
+ (module.buildInfo).moduleConcatenationBailout =
132
+ "Hot Module Replacement";
114
133
  if (expr.arguments.length >= 1) {
115
134
  const arg = parser.evaluateExpression(expr.arguments[0]);
135
+ /** @type {BasicEvaluatedExpression[]} */
116
136
  let params = [];
117
- let requests = [];
118
137
  if (arg.isString()) {
119
138
  params = [arg];
120
139
  } else if (arg.isArray()) {
121
- params = arg.items.filter(param => param.isString());
140
+ params =
141
+ /** @type {BasicEvaluatedExpression[]} */
142
+ (arg.items).filter(param => param.isString());
122
143
  }
144
+ /** @type {string[]} */
145
+ let requests = [];
123
146
  if (params.length > 0) {
124
147
  params.forEach((param, idx) => {
125
- const request = param.string;
126
- const dep = new ParamDependency(request, param.range);
148
+ const request = /** @type {string} */ (param.string);
149
+ const dep = new ParamDependency(
150
+ request,
151
+ /** @type {Range} */ (param.range)
152
+ );
127
153
  dep.optional = true;
128
- dep.loc = Object.create(expr.loc);
154
+ dep.loc = Object.create(
155
+ /** @type {DependencyLocation} */ (expr.loc)
156
+ );
129
157
  dep.loc.index = idx;
130
158
  module.addDependency(dep);
131
159
  requests.push(request);
@@ -147,28 +175,40 @@ class HotModuleReplacementPlugin {
147
175
  };
148
176
  };
149
177
 
178
+ /**
179
+ * @param {JavascriptParser} parser the parser
180
+ * @param {typeof ModuleHotDeclineDependency} ParamDependency dependency
181
+ * @returns {(expr: CallExpression) => boolean | undefined} callback
182
+ */
150
183
  const createDeclineHandler = (parser, ParamDependency) => expr => {
151
184
  const module = parser.state.module;
152
185
  const dep = new ConstDependency(
153
186
  `${module.moduleArgument}.hot.decline`,
154
- expr.callee.range,
187
+ /** @type {Range} */ (expr.callee.range),
155
188
  runtimeRequirements
156
189
  );
157
- dep.loc = expr.loc;
190
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
158
191
  module.addPresentationalDependency(dep);
159
- module.buildInfo.moduleConcatenationBailout = "Hot Module Replacement";
192
+ /** @type {BuildInfo} */
193
+ (module.buildInfo).moduleConcatenationBailout = "Hot Module Replacement";
160
194
  if (expr.arguments.length === 1) {
161
195
  const arg = parser.evaluateExpression(expr.arguments[0]);
196
+ /** @type {BasicEvaluatedExpression[]} */
162
197
  let params = [];
163
198
  if (arg.isString()) {
164
199
  params = [arg];
165
200
  } else if (arg.isArray()) {
166
- params = arg.items.filter(param => param.isString());
201
+ params =
202
+ /** @type {BasicEvaluatedExpression[]} */
203
+ (arg.items).filter(param => param.isString());
167
204
  }
168
205
  params.forEach((param, idx) => {
169
- const dep = new ParamDependency(param.string, param.range);
206
+ const dep = new ParamDependency(
207
+ /** @type {string} */ (param.string),
208
+ /** @type {Range} */ (param.range)
209
+ );
170
210
  dep.optional = true;
171
- dep.loc = Object.create(expr.loc);
211
+ dep.loc = Object.create(/** @type {DependencyLocation} */ (expr.loc));
172
212
  dep.loc.index = idx;
173
213
  module.addDependency(dep);
174
214
  });
@@ -176,16 +216,21 @@ class HotModuleReplacementPlugin {
176
216
  return true;
177
217
  };
178
218
 
219
+ /**
220
+ * @param {JavascriptParser} parser the parser
221
+ * @returns {(expr: Expression) => boolean | undefined} callback
222
+ */
179
223
  const createHMRExpressionHandler = parser => expr => {
180
224
  const module = parser.state.module;
181
225
  const dep = new ConstDependency(
182
226
  `${module.moduleArgument}.hot`,
183
- expr.range,
227
+ /** @type {Range} */ (expr.range),
184
228
  runtimeRequirements
185
229
  );
186
- dep.loc = expr.loc;
230
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
187
231
  module.addPresentationalDependency(dep);
188
- module.buildInfo.moduleConcatenationBailout = "Hot Module Replacement";
232
+ /** @type {BuildInfo} */
233
+ (module.buildInfo).moduleConcatenationBailout = "Hot Module Replacement";
189
234
  return true;
190
235
  };
191
236
 
@@ -303,7 +348,9 @@ class HotModuleReplacementPlugin {
303
348
  //#endregion
304
349
 
305
350
  let hotIndex = 0;
351
+ /** @type {Record<string, string>} */
306
352
  const fullHashChunkModuleHashes = {};
353
+ /** @type {Record<string, string>} */
307
354
  const chunkModuleHashes = {};
308
355
 
309
356
  compilation.hooks.record.tap(PLUGIN_NAME, (compilation, records) => {
@@ -316,18 +363,20 @@ class HotModuleReplacementPlugin {
316
363
  records.chunkHashes = {};
317
364
  records.chunkRuntime = {};
318
365
  for (const chunk of compilation.chunks) {
319
- records.chunkHashes[chunk.id] = chunk.hash;
320
- records.chunkRuntime[chunk.id] = getRuntimeKey(chunk.runtime);
366
+ const chunkId = /** @type {ChunkId} */ (chunk.id);
367
+ records.chunkHashes[chunkId] = chunk.hash;
368
+ records.chunkRuntime[chunkId] = getRuntimeKey(chunk.runtime);
321
369
  }
322
370
  records.chunkModuleIds = {};
323
371
  for (const chunk of compilation.chunks) {
324
- records.chunkModuleIds[chunk.id] = Array.from(
325
- chunkGraph.getOrderedChunkModulesIterable(
326
- chunk,
327
- compareModulesById(chunkGraph)
328
- ),
329
- m => chunkGraph.getModuleId(m)
330
- );
372
+ records.chunkModuleIds[/** @type {ChunkId} */ (chunk.id)] =
373
+ Array.from(
374
+ chunkGraph.getOrderedChunkModulesIterable(
375
+ chunk,
376
+ compareModulesById(chunkGraph)
377
+ ),
378
+ m => chunkGraph.getModuleId(m)
379
+ );
331
380
  }
332
381
  });
333
382
  /** @type {TupleSet<[Module, Chunk]>} */
@@ -340,6 +389,10 @@ class HotModuleReplacementPlugin {
340
389
  const chunkGraph = compilation.chunkGraph;
341
390
  const records = compilation.records;
342
391
  for (const chunk of compilation.chunks) {
392
+ /**
393
+ * @param {Module} module module
394
+ * @returns {string} module hash
395
+ */
343
396
  const getModuleHash = module => {
344
397
  if (
345
398
  compilation.codeGenerationResults.has(module, chunk.runtime)
@@ -454,7 +507,7 @@ class HotModuleReplacementPlugin {
454
507
  chunkModuleHashes[key] = hash;
455
508
  }
456
509
 
457
- /** @type {Map<string, { updatedChunkIds: Set<string|number>, removedChunkIds: Set<string|number>, removedModules: Set<Module>, filename: string, assetInfo: AssetInfo }>} */
510
+ /** @type {HotUpdateMainContentByRuntime} */
458
511
  const hotUpdateMainContentByRuntime = new Map();
459
512
  let allOldRuntime;
460
513
  for (const key of Object.keys(records.chunkRuntime)) {
@@ -470,13 +523,16 @@ class HotModuleReplacementPlugin {
470
523
  runtime
471
524
  }
472
525
  );
473
- hotUpdateMainContentByRuntime.set(runtime, {
474
- updatedChunkIds: new Set(),
475
- removedChunkIds: new Set(),
476
- removedModules: new Set(),
477
- filename,
478
- assetInfo
479
- });
526
+ hotUpdateMainContentByRuntime.set(
527
+ /** @type {string} */ (runtime),
528
+ {
529
+ updatedChunkIds: new Set(),
530
+ removedChunkIds: new Set(),
531
+ removedModules: new Set(),
532
+ filename,
533
+ assetInfo
534
+ }
535
+ );
480
536
  });
481
537
  if (hotUpdateMainContentByRuntime.size === 0) return;
482
538
 
@@ -506,6 +562,7 @@ class HotModuleReplacementPlugin {
506
562
  }
507
563
  }
508
564
 
565
+ /** @type {ChunkId | null} */
509
566
  let chunkId;
510
567
  let newModules;
511
568
  let newRuntimeModules;
@@ -554,9 +611,10 @@ class HotModuleReplacementPlugin {
554
611
  if (removedFromRuntime) {
555
612
  // chunk was removed from some runtimes
556
613
  forEachRuntime(removedFromRuntime, runtime => {
557
- hotUpdateMainContentByRuntime
558
- .get(runtime)
559
- .removedChunkIds.add(chunkId);
614
+ const item = hotUpdateMainContentByRuntime.get(
615
+ /** @type {string} */ (runtime)
616
+ );
617
+ item.removedChunkIds.add(/** @type {ChunkId} */ (chunkId));
560
618
  });
561
619
  // dispose modules from the chunk in these runtimes
562
620
  // where they are no longer in this runtime
@@ -597,12 +655,16 @@ class HotModuleReplacementPlugin {
597
655
  if (typeof moduleRuntime === "string") {
598
656
  if (moduleRuntime === runtime) return;
599
657
  } else if (moduleRuntime !== undefined) {
600
- if (moduleRuntime.has(runtime)) return;
658
+ if (
659
+ moduleRuntime.has(/** @type {string} */ (runtime))
660
+ )
661
+ return;
601
662
  }
602
663
  }
603
- hotUpdateMainContentByRuntime
604
- .get(runtime)
605
- .removedModules.add(module);
664
+ const item = hotUpdateMainContentByRuntime.get(
665
+ /** @type {string} */ (runtime)
666
+ );
667
+ item.removedModules.add(module);
606
668
  });
607
669
  }
608
670
  }
@@ -676,9 +738,10 @@ class HotModuleReplacementPlugin {
676
738
  }
677
739
  }
678
740
  forEachRuntime(newRuntime, runtime => {
679
- hotUpdateMainContentByRuntime
680
- .get(runtime)
681
- .updatedChunkIds.add(chunkId);
741
+ const item = hotUpdateMainContentByRuntime.get(
742
+ /** @type {string} */ (runtime)
743
+ );
744
+ item.updatedChunkIds.add(/** @type {ChunkId} */ (chunkId));
682
745
  });
683
746
  }
684
747
  }
@@ -28,7 +28,10 @@ class IgnorePlugin {
28
28
  validate(options);
29
29
  this.options = options;
30
30
 
31
- /** @private @type {Function} */
31
+ /**
32
+ * @private
33
+ * @type {Function}
34
+ */
32
35
  this.checkIgnore = this.checkIgnore.bind(this);
33
36
  }
34
37
 
@@ -16,14 +16,14 @@ const { dirname, mkdirp } = require("./util/fs");
16
16
  /** @typedef {import("./Module").BuildMeta} BuildMeta */
17
17
 
18
18
  /**
19
- * @typedef {Object} ManifestModuleData
19
+ * @typedef {object} ManifestModuleData
20
20
  * @property {string | number} id
21
21
  * @property {BuildMeta} buildMeta
22
22
  * @property {boolean | string[] | undefined} exports
23
23
  */
24
24
 
25
25
  /**
26
- * @typedef {Object} LibManifestPluginOptions
26
+ * @typedef {object} LibManifestPluginOptions
27
27
  * @property {string=} context Context of requests in the manifest file (defaults to the webpack context).
28
28
  * @property {boolean=} entryOnly If true, only entry points will be exposed (default: true).
29
29
  * @property {boolean=} format If true, manifest json file (output) will be formatted.
package/lib/Module.js CHANGED
@@ -45,7 +45,7 @@ const makeSerializable = require("./util/makeSerializable");
45
45
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
46
46
 
47
47
  /**
48
- * @typedef {Object} SourceContext
48
+ * @typedef {object} SourceContext
49
49
  * @property {DependencyTemplates} dependencyTemplates the dependency templates
50
50
  * @property {RuntimeTemplate} runtimeTemplate the runtime template
51
51
  * @property {ModuleGraph} moduleGraph the module graph
@@ -56,13 +56,12 @@ const makeSerializable = require("./util/makeSerializable");
56
56
 
57
57
  // TODO webpack 6: compilation will be required in CodeGenerationContext
58
58
  /**
59
- * @typedef {Object} CodeGenerationContext
59
+ * @typedef {object} CodeGenerationContext
60
60
  * @property {DependencyTemplates} dependencyTemplates the dependency templates
61
61
  * @property {RuntimeTemplate} runtimeTemplate the runtime template
62
62
  * @property {ModuleGraph} moduleGraph the module graph
63
63
  * @property {ChunkGraph} chunkGraph the chunk graph
64
- * @property {RuntimeSpec} runtime the runtime code should be generated for
65
- * @property {RuntimeSpec[]} [runtimes] the runtimes code should be generated for
64
+ * @property {RuntimeSpec} runtime the runtimes code should be generated for
66
65
  * @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules
67
66
  * @property {CodeGenerationResults | undefined} codeGenerationResults code generation results of other modules (need to have a codeGenerationDependency to use that)
68
67
  * @property {Compilation=} compilation the compilation
@@ -70,7 +69,7 @@ const makeSerializable = require("./util/makeSerializable");
70
69
  */
71
70
 
72
71
  /**
73
- * @typedef {Object} ConcatenationBailoutReasonContext
72
+ * @typedef {object} ConcatenationBailoutReasonContext
74
73
  * @property {ModuleGraph} moduleGraph the module graph
75
74
  * @property {ChunkGraph} chunkGraph the chunk graph
76
75
  */
@@ -79,7 +78,7 @@ const makeSerializable = require("./util/makeSerializable");
79
78
  /** @typedef {ReadonlySet<string>} ReadOnlyRuntimeRequirements */
80
79
 
81
80
  /**
82
- * @typedef {Object} CodeGenerationResult
81
+ * @typedef {object} CodeGenerationResult
83
82
  * @property {Map<string, Source>} sources the resulting sources for all source types
84
83
  * @property {Map<string, any>=} data the resulting data for all source types
85
84
  * @property {ReadOnlyRuntimeRequirements} runtimeRequirements the runtime requirements
@@ -87,13 +86,13 @@ const makeSerializable = require("./util/makeSerializable");
87
86
  */
88
87
 
89
88
  /**
90
- * @typedef {Object} LibIdentOptions
89
+ * @typedef {object} LibIdentOptions
91
90
  * @property {string} context absolute context path to which lib ident is relative to
92
- * @property {Object=} associatedObjectForCache object for caching
91
+ * @property {object=} associatedObjectForCache object for caching
93
92
  */
94
93
 
95
94
  /**
96
- * @typedef {Object} KnownBuildMeta
95
+ * @typedef {object} KnownBuildMeta
97
96
  * @property {string=} moduleArgument
98
97
  * @property {string=} exportsArgument
99
98
  * @property {boolean=} strict
@@ -106,7 +105,7 @@ const makeSerializable = require("./util/makeSerializable");
106
105
  */
107
106
 
108
107
  /**
109
- * @typedef {Object} KnownBuildInfo
108
+ * @typedef {object} KnownBuildInfo
110
109
  * @property {boolean=} cacheable
111
110
  * @property {boolean=} parsed
112
111
  * @property {LazySet<string>=} fileDependencies
@@ -121,7 +120,7 @@ const makeSerializable = require("./util/makeSerializable");
121
120
  */
122
121
 
123
122
  /**
124
- * @typedef {Object} NeedBuildContext
123
+ * @typedef {object} NeedBuildContext
125
124
  * @property {Compilation} compilation
126
125
  * @property {FileSystemInfo} fileSystemInfo
127
126
  * @property {Map<string, string | Set<string>>} valueCacheVersions
@@ -131,7 +130,7 @@ const makeSerializable = require("./util/makeSerializable");
131
130
  /** @typedef {KnownBuildInfo & Record<string, any>} BuildInfo */
132
131
 
133
132
  /**
134
- * @typedef {Object} FactoryMeta
133
+ * @typedef {object} FactoryMeta
135
134
  * @property {boolean=} sideEffectFree
136
135
  */
137
136
 
@@ -10,7 +10,7 @@
10
10
  /** @typedef {import("./Module")} Module */
11
11
 
12
12
  /**
13
- * @typedef {Object} ModuleFactoryResult
13
+ * @typedef {object} ModuleFactoryResult
14
14
  * @property {Module=} module the created module or unset if no module was created
15
15
  * @property {Set<string>=} fileDependencies
16
16
  * @property {Set<string>=} contextDependencies
@@ -19,14 +19,14 @@
19
19
  */
20
20
 
21
21
  /**
22
- * @typedef {Object} ModuleFactoryCreateDataContextInfo
22
+ * @typedef {object} ModuleFactoryCreateDataContextInfo
23
23
  * @property {string} issuer
24
24
  * @property {string | null=} issuerLayer
25
25
  * @property {string} compiler
26
26
  */
27
27
 
28
28
  /**
29
- * @typedef {Object} ModuleFactoryCreateData
29
+ * @typedef {object} ModuleFactoryCreateData
30
30
  * @property {ModuleFactoryCreateDataContextInfo} contextInfo
31
31
  * @property {ResolveOptions=} resolveOptions
32
32
  * @property {string} context
@@ -46,11 +46,13 @@ ModuleFilenameHelpers.REGEXP_HASH = /\[hash\]/gi;
46
46
  ModuleFilenameHelpers.NAMESPACE = "[namespace]";
47
47
  ModuleFilenameHelpers.REGEXP_NAMESPACE = /\[namespace\]/gi;
48
48
 
49
+ /** @typedef {() => string} ReturnStringCallback */
50
+
49
51
  /**
50
52
  * Returns a function that returns the part of the string after the token
51
- * @param {() => string} strFn the function to get the string
53
+ * @param {ReturnStringCallback} strFn the function to get the string
52
54
  * @param {string} token the token to search for
53
- * @returns {() => string} a function that returns the part of the string after the token
55
+ * @returns {ReturnStringCallback} a function that returns the part of the string after the token
54
56
  */
55
57
  const getAfter = (strFn, token) => {
56
58
  return () => {
@@ -62,9 +64,9 @@ const getAfter = (strFn, token) => {
62
64
 
63
65
  /**
64
66
  * Returns a function that returns the part of the string before the token
65
- * @param {() => string} strFn the function to get the string
67
+ * @param {ReturnStringCallback} strFn the function to get the string
66
68
  * @param {string} token the token to search for
67
- * @returns {() => string} a function that returns the part of the string before the token
69
+ * @returns {ReturnStringCallback} a function that returns the part of the string before the token
68
70
  */
69
71
  const getBefore = (strFn, token) => {
70
72
  return () => {
@@ -76,11 +78,11 @@ const getBefore = (strFn, token) => {
76
78
 
77
79
  /**
78
80
  * Returns a function that returns a hash of the string
79
- * @param {() => string} strFn the function to get the string
80
- * @param {string | Hash} hashFunction the hash function to use
81
- * @returns {() => string} a function that returns the hash of the string
81
+ * @param {ReturnStringCallback} strFn the function to get the string
82
+ * @param {string | Hash=} hashFunction the hash function to use
83
+ * @returns {ReturnStringCallback} a function that returns the hash of the string
82
84
  */
83
- const getHash = (strFn, hashFunction) => {
85
+ const getHash = (strFn, hashFunction = "md4") => {
84
86
  return () => {
85
87
  const hash = createHash(hashFunction);
86
88
  hash.update(strFn());
@@ -116,7 +118,7 @@ const asRegExp = test => {
116
118
  * Returns a lazy object. The object is lazy in the sense that the properties are
117
119
  * only evaluated when they are accessed. This is only obtained by setting a function as the value for each key.
118
120
  * @param {Record<string, () => T>} obj the object to convert to a lazy access object
119
- * @returns {Object} the lazy access object
121
+ * @returns {object} the lazy access object
120
122
  */
121
123
  const lazyObject = obj => {
122
124
  const newObj = {};
@@ -144,10 +146,10 @@ const SQUARE_BRACKET_TAG_REGEXP = /\[\\*([\w-]+)\\*\]/gi;
144
146
  *
145
147
  * @param {Module | string} module the module
146
148
  * @param {TODO} options options
147
- * @param {Object} contextInfo context info
149
+ * @param {object} contextInfo context info
148
150
  * @param {RequestShortener} contextInfo.requestShortener requestShortener
149
151
  * @param {ChunkGraph} contextInfo.chunkGraph chunk graph
150
- * @param {string | Hash} contextInfo.hashFunction the hash function to use
152
+ * @param {string | Hash=} contextInfo.hashFunction the hash function to use
151
153
  * @returns {string} the filename
152
154
  */
153
155
  ModuleFilenameHelpers.createFilename = (
@@ -167,11 +169,16 @@ ModuleFilenameHelpers.createFilename = (
167
169
 
168
170
  let absoluteResourcePath;
169
171
  let hash;
172
+ /** @type {ReturnStringCallback} */
170
173
  let identifier;
174
+ /** @type {ReturnStringCallback} */
171
175
  let moduleId;
176
+ /** @type {ReturnStringCallback} */
172
177
  let shortIdentifier;
173
178
  if (typeof module === "string") {
174
- shortIdentifier = memoize(() => requestShortener.shorten(module));
179
+ shortIdentifier =
180
+ /** @type {ReturnStringCallback} */
181
+ (memoize(() => requestShortener.shorten(module)));
175
182
  identifier = shortIdentifier;
176
183
  moduleId = () => "";
177
184
  absoluteResourcePath = () => module.split("!").pop();
@@ -180,15 +187,21 @@ ModuleFilenameHelpers.createFilename = (
180
187
  shortIdentifier = memoize(() =>
181
188
  module.readableIdentifier(requestShortener)
182
189
  );
183
- identifier = memoize(() => requestShortener.shorten(module.identifier()));
184
- moduleId = () => chunkGraph.getModuleId(module);
190
+ identifier =
191
+ /** @type {ReturnStringCallback} */
192
+ (memoize(() => requestShortener.shorten(module.identifier())));
193
+ moduleId =
194
+ /** @type {ReturnStringCallback} */
195
+ (() => chunkGraph.getModuleId(module));
185
196
  absoluteResourcePath = () =>
186
197
  module instanceof NormalModule
187
198
  ? module.resource
188
199
  : module.identifier().split("!").pop();
189
200
  hash = getHash(identifier, hashFunction);
190
201
  }
191
- const resource = memoize(() => shortIdentifier().split("!").pop());
202
+ const resource =
203
+ /** @type {ReturnStringCallback} */
204
+ (memoize(() => shortIdentifier().split("!").pop()));
192
205
 
193
206
  const loaders = getBefore(shortIdentifier, "!");
194
207
  const allLoaders = getBefore(identifier, "!");
@@ -249,7 +262,7 @@ ModuleFilenameHelpers.createFilename = (
249
262
  ]);
250
263
 
251
264
  // TODO webpack 6: consider removing weird double placeholders
252
- return opts.moduleFilenameTemplate
265
+ return /** @type {string} */ (opts.moduleFilenameTemplate)
253
266
  .replace(ModuleFilenameHelpers.REGEXP_ALL_LOADERS_RESOURCE, "[identifier]")
254
267
  .replace(
255
268
  ModuleFilenameHelpers.REGEXP_LOADERS_RESOURCE,
@@ -132,7 +132,7 @@ class ModuleGraph {
132
132
  */
133
133
  this._moduleMap = new Map();
134
134
  /**
135
- * @type {WeakMap<any, Object>}
135
+ * @type {WeakMap<any, object>}
136
136
  * @private
137
137
  */
138
138
  this._metaMap = new WeakMap();
@@ -757,20 +757,20 @@ class ModuleGraph {
757
757
 
758
758
  /**
759
759
  * @param {any} thing any thing
760
- * @returns {Object} metadata
760
+ * @returns {object} metadata
761
761
  */
762
762
  getMeta(thing) {
763
763
  let meta = this._metaMap.get(thing);
764
764
  if (meta === undefined) {
765
765
  meta = Object.create(null);
766
- this._metaMap.set(thing, /** @type {Object} */ (meta));
766
+ this._metaMap.set(thing, /** @type {object} */ (meta));
767
767
  }
768
- return /** @type {Object} */ (meta);
768
+ return /** @type {object} */ (meta);
769
769
  }
770
770
 
771
771
  /**
772
772
  * @param {any} thing any thing
773
- * @returns {Object | undefined} metadata
773
+ * @returns {object | undefined} metadata
774
774
  */
775
775
  getMetaIfExisting(thing) {
776
776
  return this._metaMap.get(thing);
@@ -11,6 +11,7 @@ const { SyncHook, MultiHook } = require("tapable");
11
11
  const ConcurrentCompilationError = require("./ConcurrentCompilationError");
12
12
  const MultiStats = require("./MultiStats");
13
13
  const MultiWatching = require("./MultiWatching");
14
+ const WebpackError = require("./WebpackError");
14
15
  const ArrayQueue = require("./util/ArrayQueue");
15
16
 
16
17
  /** @template T @typedef {import("tapable").AsyncSeriesHook<T>} AsyncSeriesHook<T> */
@@ -39,7 +40,7 @@ const ArrayQueue = require("./util/ArrayQueue");
39
40
  */
40
41
 
41
42
  /**
42
- * @typedef {Object} MultiCompilerOptions
43
+ * @typedef {object} MultiCompilerOptions
43
44
  * @property {number=} parallelism how many Compilers are allows to run at the same time in parallel
44
45
  */
45
46
 
@@ -109,6 +110,40 @@ module.exports = class MultiCompiler {
109
110
  }
110
111
  });
111
112
  }
113
+ this._validateCompilersOptions();
114
+ }
115
+
116
+ _validateCompilersOptions() {
117
+ if (this.compilers.length < 2) return;
118
+ /**
119
+ * @param {Compiler} compiler compiler
120
+ * @param {WebpackError} warning warning
121
+ */
122
+ const addWarning = (compiler, warning) => {
123
+ compiler.hooks.thisCompilation.tap("MultiCompiler", compilation => {
124
+ compilation.warnings.push(warning);
125
+ });
126
+ };
127
+ const cacheNames = new Set();
128
+ for (const compiler of this.compilers) {
129
+ if (compiler.options.cache && "name" in compiler.options.cache) {
130
+ const name = compiler.options.cache.name;
131
+ if (cacheNames.has(name)) {
132
+ addWarning(
133
+ compiler,
134
+ new WebpackError(
135
+ `${
136
+ compiler.name
137
+ ? `Compiler with name "${compiler.name}" doesn't use unique cache name. `
138
+ : ""
139
+ }Please set unique "cache.name" option. Name "${name}" already used.`
140
+ )
141
+ );
142
+ } else {
143
+ cacheNames.add(name);
144
+ }
145
+ }
146
+ }
112
147
  }
113
148
 
114
149
  get options() {