webpack 5.90.3 → 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 (174) 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 +262 -93
  12. package/lib/Compiler.js +199 -83
  13. package/lib/ConditionalInitFragment.js +4 -5
  14. package/lib/ContextModule.js +2 -0
  15. package/lib/ContextModuleFactory.js +4 -2
  16. package/lib/ContextReplacementPlugin.js +3 -2
  17. package/lib/DefinePlugin.js +4 -2
  18. package/lib/Dependency.js +4 -2
  19. package/lib/DependencyTemplate.js +7 -2
  20. package/lib/DllModule.js +1 -0
  21. package/lib/DllReferencePlugin.js +6 -2
  22. package/lib/EntryOptionPlugin.js +4 -1
  23. package/lib/EntryPlugin.js +6 -1
  24. package/lib/Entrypoint.js +1 -1
  25. package/lib/ExportsInfo.js +1 -4
  26. package/lib/ExternalModule.js +118 -24
  27. package/lib/ExternalModuleFactoryPlugin.js +37 -2
  28. package/lib/FileSystemInfo.js +1 -1
  29. package/lib/Generator.js +2 -1
  30. package/lib/HookWebpackError.js +2 -2
  31. package/lib/InitFragment.js +5 -3
  32. package/lib/LibManifestPlugin.js +15 -7
  33. package/lib/Module.js +30 -2
  34. package/lib/ModuleFilenameHelpers.js +1 -1
  35. package/lib/ModuleGraph.js +56 -27
  36. package/lib/ModuleGraphConnection.js +2 -1
  37. package/lib/MultiCompiler.js +26 -8
  38. package/lib/NodeStuffPlugin.js +14 -3
  39. package/lib/NormalModule.js +3 -1
  40. package/lib/NormalModuleFactory.js +1 -1
  41. package/lib/NormalModuleReplacementPlugin.js +5 -1
  42. package/lib/ProvidePlugin.js +3 -1
  43. package/lib/RawModule.js +2 -1
  44. package/lib/ResolverFactory.js +3 -1
  45. package/lib/RuntimeModule.js +4 -4
  46. package/lib/RuntimePlugin.js +1 -0
  47. package/lib/RuntimeTemplate.js +102 -34
  48. package/lib/SourceMapDevToolPlugin.js +4 -1
  49. package/lib/Stats.js +10 -3
  50. package/lib/TemplatedPathPlugin.js +32 -6
  51. package/lib/Watching.js +67 -60
  52. package/lib/WebpackError.js +6 -6
  53. package/lib/WebpackOptionsApply.js +18 -5
  54. package/lib/asset/RawDataUrlModule.js +3 -1
  55. package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
  56. package/lib/buildChunkGraph.js +117 -64
  57. package/lib/cache/IdleFileCachePlugin.js +8 -3
  58. package/lib/cache/MemoryCachePlugin.js +1 -1
  59. package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
  60. package/lib/cache/PackFileCacheStrategy.js +49 -16
  61. package/lib/cache/ResolverCachePlugin.js +14 -6
  62. package/lib/cache/getLazyHashedEtag.js +1 -1
  63. package/lib/config/defaults.js +24 -1
  64. package/lib/config/normalization.js +3 -1
  65. package/lib/container/ContainerEntryDependency.js +2 -1
  66. package/lib/container/ContainerEntryModule.js +3 -1
  67. package/lib/container/ContainerPlugin.js +14 -10
  68. package/lib/container/FallbackModule.js +1 -1
  69. package/lib/container/RemoteRuntimeModule.js +12 -3
  70. package/lib/css/CssExportsGenerator.js +34 -17
  71. package/lib/css/CssGenerator.js +20 -2
  72. package/lib/css/CssLoadingRuntimeModule.js +212 -96
  73. package/lib/css/CssModulesPlugin.js +47 -13
  74. package/lib/debug/ProfilingPlugin.js +27 -2
  75. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
  76. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
  77. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
  78. package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
  79. package/lib/dependencies/CommonJsExportsDependency.js +13 -5
  80. package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
  81. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
  82. package/lib/dependencies/ContextDependencyHelpers.js +49 -29
  83. package/lib/dependencies/ContextElementDependency.js +8 -1
  84. package/lib/dependencies/CssLocalIdentifierDependency.js +63 -8
  85. package/lib/dependencies/CssUrlDependency.js +5 -3
  86. package/lib/dependencies/ExportsInfoDependency.js +4 -3
  87. package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
  88. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
  89. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
  90. package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
  91. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
  92. package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
  93. package/lib/dependencies/HarmonyImportDependency.js +28 -12
  94. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +44 -16
  95. package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
  96. package/lib/dependencies/HarmonyImportSpecifierDependency.js +6 -5
  97. package/lib/dependencies/ImportDependency.js +9 -2
  98. package/lib/dependencies/ImportEagerDependency.js +4 -2
  99. package/lib/dependencies/ImportMetaContextDependency.js +7 -0
  100. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
  101. package/lib/dependencies/ImportParserPlugin.js +12 -4
  102. package/lib/dependencies/ImportWeakDependency.js +4 -2
  103. package/lib/dependencies/LoaderDependency.js +2 -1
  104. package/lib/dependencies/LoaderImportDependency.js +2 -1
  105. package/lib/dependencies/ModuleDependency.js +4 -5
  106. package/lib/dependencies/PureExpressionDependency.js +4 -1
  107. package/lib/dependencies/RequireContextPlugin.js +1 -1
  108. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
  109. package/lib/dependencies/RequireEnsureDependency.js +1 -1
  110. package/lib/dependencies/URLDependency.js +7 -4
  111. package/lib/dependencies/WorkerPlugin.js +2 -1
  112. package/lib/dependencies/getFunctionExpression.js +3 -1
  113. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +2 -1
  114. package/lib/javascript/BasicEvaluatedExpression.js +2 -2
  115. package/lib/javascript/ChunkHelpers.js +2 -2
  116. package/lib/javascript/JavascriptParser.js +169 -57
  117. package/lib/javascript/JavascriptParserHelpers.js +1 -1
  118. package/lib/javascript/StartupHelpers.js +22 -5
  119. package/lib/logging/Logger.js +27 -2
  120. package/lib/logging/createConsoleLogger.js +11 -7
  121. package/lib/node/NodeEnvironmentPlugin.js +13 -7
  122. package/lib/node/NodeWatchFileSystem.js +37 -26
  123. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
  124. package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
  125. package/lib/node/nodeConsole.js +24 -1
  126. package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
  127. package/lib/optimize/ConcatenatedModule.js +138 -54
  128. package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
  129. package/lib/optimize/InnerGraph.js +7 -2
  130. package/lib/optimize/InnerGraphPlugin.js +36 -13
  131. package/lib/optimize/ModuleConcatenationPlugin.js +12 -2
  132. package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
  133. package/lib/optimize/RuntimeChunkPlugin.js +6 -1
  134. package/lib/optimize/SideEffectsFlagPlugin.js +46 -15
  135. package/lib/optimize/SplitChunksPlugin.js +2 -2
  136. package/lib/performance/SizeLimitsPlugin.js +11 -0
  137. package/lib/rules/ObjectMatcherRulePlugin.js +4 -0
  138. package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
  139. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
  140. package/lib/serialization/FileMiddleware.js +1 -0
  141. package/lib/serialization/ObjectMiddleware.js +2 -0
  142. package/lib/serialization/Serializer.js +19 -0
  143. package/lib/sharing/ConsumeSharedModule.js +1 -1
  144. package/lib/sharing/ConsumeSharedPlugin.js +17 -3
  145. package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
  146. package/lib/sharing/ProvideSharedPlugin.js +12 -5
  147. package/lib/sharing/resolveMatchedConfigs.js +2 -2
  148. package/lib/sharing/utils.js +13 -6
  149. package/lib/util/StackedCacheMap.js +26 -0
  150. package/lib/util/WeakTupleMap.js +57 -13
  151. package/lib/util/cleverMerge.js +24 -11
  152. package/lib/util/comparators.js +34 -14
  153. package/lib/util/conventions.js +129 -0
  154. package/lib/util/fs.js +379 -65
  155. package/lib/util/hash/BatchedHash.js +3 -0
  156. package/lib/util/hash/xxhash64.js +2 -2
  157. package/lib/util/runtime.js +1 -1
  158. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
  159. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +15 -6
  160. package/lib/wasm-sync/WebAssemblyGenerator.js +27 -6
  161. package/lib/wasm-sync/WebAssemblyParser.js +7 -4
  162. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -1
  163. package/lib/webpack.js +7 -3
  164. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
  165. package/package.json +25 -26
  166. package/schemas/WebpackOptions.check.js +1 -1
  167. package/schemas/WebpackOptions.json +69 -8
  168. package/schemas/plugins/BannerPlugin.check.js +1 -1
  169. package/schemas/plugins/BannerPlugin.json +5 -1
  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 +1668 -613
@@ -58,6 +58,16 @@ const { getEntryRuntime, mergeRuntime } = require("./util/runtime");
58
58
  * @property {ChunkGroup} chunkGroup referenced chunk group
59
59
  */
60
60
 
61
+ /** @typedef {(Module | ConnectionState | ModuleGraphConnection)[]} BlockModulesInTuples */
62
+ /** @typedef {(Module | ConnectionState | ModuleGraphConnection[])[]} BlockModulesInFlattenTuples */
63
+ /** @typedef {Map<DependenciesBlock, BlockModulesInFlattenTuples>} BlockModulesMap */
64
+ /** @typedef {Map<Chunk, bigint>} MaskByChunk */
65
+ /** @typedef {Set<DependenciesBlock>} BlocksWithNestedBlocks */
66
+ /** @typedef {Map<AsyncDependenciesBlock, BlockChunkGroupConnection[]>} BlockConnections */
67
+ /** @typedef {Map<ChunkGroup, ChunkGroupInfo>} ChunkGroupInfoMap */
68
+ /** @typedef {Set<ChunkGroup>} AllCreatedChunkGroups */
69
+ /** @typedef {Map<Entrypoint, Module[]>} InputEntrypointsAndModules */
70
+
61
71
  const ZERO_BIGINT = BigInt(0);
62
72
  const ONE_BIGINT = BigInt(1);
63
73
 
@@ -88,15 +98,26 @@ const getActiveStateOfConnections = (connections, runtime) => {
88
98
  return merged;
89
99
  };
90
100
 
101
+ /**
102
+ * @param {Module} module module
103
+ * @param {ModuleGraph} moduleGraph module graph
104
+ * @param {RuntimeSpec} runtime runtime
105
+ * @param {BlockModulesMap} blockModulesMap block modules map
106
+ */
91
107
  const extractBlockModules = (module, moduleGraph, runtime, blockModulesMap) => {
108
+ /** @type {DependenciesBlock | undefined} */
92
109
  let blockCache;
110
+ /** @type {BlockModulesInTuples | undefined} */
93
111
  let modules;
94
112
 
113
+ /** @type {BlockModulesInTuples[]} */
95
114
  const arrays = [];
96
115
 
116
+ /** @type {DependenciesBlock[]} */
97
117
  const queue = [module];
98
118
  while (queue.length > 0) {
99
- const block = queue.pop();
119
+ const block = /** @type {DependenciesBlock} */ (queue.pop());
120
+ /** @type {Module[]} */
100
121
  const arr = [];
101
122
  arrays.push(arr);
102
123
  blockModulesMap.set(block, arr);
@@ -120,17 +141,26 @@ const extractBlockModules = (module, moduleGraph, runtime, blockModulesMap) => {
120
141
 
121
142
  // deprecated fallback
122
143
  if (index < 0) {
123
- index = block.dependencies.indexOf(d);
144
+ index = /** @type {DependenciesBlock} */ (block).dependencies.indexOf(d);
124
145
  }
125
146
 
126
147
  if (blockCache !== block) {
127
- modules = blockModulesMap.get((blockCache = block));
148
+ modules =
149
+ /** @type {BlockModulesInTuples} */
150
+ (
151
+ blockModulesMap.get(
152
+ (blockCache = /** @type {DependenciesBlock} */ (block))
153
+ )
154
+ );
128
155
  }
129
156
 
130
157
  const i = index * 3;
131
- modules[i] = m;
132
- modules[i + 1] = connection.getActiveState(runtime);
133
- modules[i + 2] = connection;
158
+ /** @type {BlockModulesInTuples} */
159
+ (modules)[i] = m;
160
+ /** @type {BlockModulesInTuples} */
161
+ (modules)[i + 1] = connection.getActiveState(runtime);
162
+ /** @type {BlockModulesInTuples} */
163
+ (modules)[i + 2] = connection;
134
164
  }
135
165
 
136
166
  for (const modules of arrays) {
@@ -140,14 +170,15 @@ const extractBlockModules = (module, moduleGraph, runtime, blockModulesMap) => {
140
170
  outer: for (let j = 0; j < modules.length; j += 3) {
141
171
  const m = modules[j];
142
172
  if (m === undefined) continue;
143
- const state = modules[j + 1];
144
- const connection = modules[j + 2];
173
+ const state = /** @type {ConnectionState} */ (modules[j + 1]);
174
+ const connection = /** @type {ModuleGraphConnection} */ (modules[j + 2]);
145
175
  if (indexMap === undefined) {
146
176
  let i = 0;
147
177
  for (; i < length; i += 3) {
148
178
  if (modules[i] === m) {
149
- const merged = modules[i + 1];
150
- modules[i + 2].push(connection);
179
+ const merged = /** @type {ConnectionState} */ (modules[i + 1]);
180
+ /** @type {ModuleGraphConnection[]} */
181
+ (/** @type {unknown} */ (modules[i + 2])).push(connection);
151
182
  if (merged === true) continue outer;
152
183
  modules[i + 1] = ModuleGraphConnection.addConnectionStates(
153
184
  merged,
@@ -160,7 +191,8 @@ const extractBlockModules = (module, moduleGraph, runtime, blockModulesMap) => {
160
191
  length++;
161
192
  modules[length] = state;
162
193
  length++;
163
- modules[length] = [connection];
194
+ /** @type {ModuleGraphConnection[]} */
195
+ (/** @type {unknown} */ (modules[length])) = [connection];
164
196
  length++;
165
197
  if (length > 30) {
166
198
  // To avoid worse case performance, we will use an index map for
@@ -174,8 +206,9 @@ const extractBlockModules = (module, moduleGraph, runtime, blockModulesMap) => {
174
206
  } else {
175
207
  const idx = indexMap.get(m);
176
208
  if (idx !== undefined) {
177
- const merged = modules[idx];
178
- modules[idx + 1].push(connection);
209
+ const merged = /** @type {ConnectionState} */ (modules[idx]);
210
+ /** @type {ModuleGraphConnection[]} */
211
+ (/** @type {unknown} */ (modules[idx + 1])).push(connection);
179
212
  if (merged === true) continue outer;
180
213
  modules[idx] = ModuleGraphConnection.addConnectionStates(
181
214
  merged,
@@ -187,7 +220,11 @@ const extractBlockModules = (module, moduleGraph, runtime, blockModulesMap) => {
187
220
  modules[length] = state;
188
221
  indexMap.set(m, length);
189
222
  length++;
190
- modules[length] = [connection];
223
+ /** @type {ModuleGraphConnection[]} */
224
+ (
225
+ /** @type {unknown} */
226
+ (modules[length])
227
+ ) = [connection];
191
228
  length++;
192
229
  }
193
230
  }
@@ -200,12 +237,12 @@ const extractBlockModules = (module, moduleGraph, runtime, blockModulesMap) => {
200
237
  *
201
238
  * @param {Logger} logger a logger
202
239
  * @param {Compilation} compilation the compilation
203
- * @param {Map<Entrypoint, Module[]>} inputEntrypointsAndModules chunk groups which are processed with the modules
204
- * @param {Map<ChunkGroup, ChunkGroupInfo>} chunkGroupInfoMap mapping from chunk group to available modules
205
- * @param {Map<AsyncDependenciesBlock, BlockChunkGroupConnection[]>} blockConnections connection for blocks
206
- * @param {Set<DependenciesBlock>} blocksWithNestedBlocks flag for blocks that have nested blocks
207
- * @param {Set<ChunkGroup>} allCreatedChunkGroups filled with all chunk groups that are created here
208
- * @param {Map<Chunk, bigint>} maskByChunk module content mask by chunk
240
+ * @param {InputEntrypointsAndModules} inputEntrypointsAndModules chunk groups which are processed with the modules
241
+ * @param {ChunkGroupInfoMap} chunkGroupInfoMap mapping from chunk group to available modules
242
+ * @param {BlockConnections} blockConnections connection for blocks
243
+ * @param {BlocksWithNestedBlocks} blocksWithNestedBlocks flag for blocks that have nested blocks
244
+ * @param {AllCreatedChunkGroups} allCreatedChunkGroups filled with all chunk groups that are created here
245
+ * @param {MaskByChunk} maskByChunk module content mask by chunk
209
246
  */
210
247
  const visitModules = (
211
248
  logger,
@@ -221,9 +258,7 @@ const visitModules = (
221
258
 
222
259
  const blockModulesRuntimeMap = new Map();
223
260
 
224
- /** @type {RuntimeSpec | false} */
225
- let blockModulesMapRuntime = false;
226
- /** @type {Map<DependenciesBlock, (Module | ConnectionState)[]>} */
261
+ /** @type {BlockModulesMap | undefined} */
227
262
  let blockModulesMap;
228
263
 
229
264
  /** @type {Map<Module, number>} */
@@ -254,15 +289,13 @@ const visitModules = (
254
289
  *
255
290
  * @param {DependenciesBlock} block block
256
291
  * @param {RuntimeSpec} runtime runtime
257
- * @returns {(Module | ConnectionState | ModuleGraphConnection[])[]} block modules in flatten tuples
292
+ * @returns {BlockModulesInFlattenTuples} block modules in flatten tuples
258
293
  */
259
294
  const getBlockModules = (block, runtime) => {
260
- if (blockModulesMapRuntime !== runtime) {
261
- blockModulesMap = blockModulesRuntimeMap.get(runtime);
262
- if (blockModulesMap === undefined) {
263
- blockModulesMap = new Map();
264
- blockModulesRuntimeMap.set(runtime, blockModulesMap);
265
- }
295
+ blockModulesMap = blockModulesRuntimeMap.get(runtime);
296
+ if (blockModulesMap === undefined) {
297
+ blockModulesMap = new Map();
298
+ blockModulesRuntimeMap.set(runtime, blockModulesMap);
266
299
  }
267
300
  let blockModules = blockModulesMap.get(block);
268
301
  if (blockModules !== undefined) return blockModules;
@@ -286,9 +319,11 @@ const visitModules = (
286
319
  } else {
287
320
  logger.time("visitModules: prepare");
288
321
  extractBlockModules(module, moduleGraph, runtime, blockModulesMap);
289
- blockModules = blockModulesMap.get(block);
322
+ blockModules =
323
+ /** @type {BlockModulesInFlattenTuples} */
324
+ (blockModulesMap.get(block));
290
325
  logger.timeAggregate("visitModules: prepare");
291
- return /** @type {(Module | ConnectionState)[]} */ (blockModules);
326
+ return blockModules;
292
327
  }
293
328
  };
294
329
 
@@ -451,6 +486,7 @@ const visitModules = (
451
486
  const iteratorBlock = b => {
452
487
  // 1. We create a chunk group with single chunk in it for this Block
453
488
  // but only once (blockChunkGroups map)
489
+ /** @type {ChunkGroupInfo | undefined} */
454
490
  let cgi = blockChunkGroups.get(b);
455
491
  /** @type {ChunkGroup | undefined} */
456
492
  let c;
@@ -465,8 +501,8 @@ const visitModules = (
465
501
  entrypoint = compilation.addAsyncEntrypoint(
466
502
  entryOptions,
467
503
  module,
468
- b.loc,
469
- b.request
504
+ /** @type {DependencyLocation} */ (b.loc),
505
+ /** @type {string} */ (b.request)
470
506
  );
471
507
  maskByChunk.set(entrypoint.chunks[0], ZERO_BIGINT);
472
508
  entrypoint.index = nextChunkGroupIndex++;
@@ -500,7 +536,11 @@ const visitModules = (
500
536
  } else {
501
537
  entrypoint = /** @type {Entrypoint} */ (cgi.chunkGroup);
502
538
  // TODO merge entryOptions
503
- entrypoint.addOrigin(module, b.loc, b.request);
539
+ entrypoint.addOrigin(
540
+ module,
541
+ /** @type {DependencyLocation} */ (b.loc),
542
+ /** @type {string} */ (b.request)
543
+ );
504
544
  chunkGraph.connectBlockAndChunkGroup(b, entrypoint);
505
545
  }
506
546
 
@@ -524,13 +564,13 @@ const visitModules = (
524
564
  chunkGroupInfo
525
565
  });
526
566
  } else {
527
- cgi = chunkName && namedChunkGroups.get(chunkName);
567
+ cgi = chunkName ? namedChunkGroups.get(chunkName) : undefined;
528
568
  if (!cgi) {
529
569
  c = compilation.addChunkInGroup(
530
570
  b.groupOptions || b.chunkName,
531
571
  module,
532
- b.loc,
533
- b.request
572
+ /** @type {DependencyLocation} */ (b.loc),
573
+ /** @type {string} */ (b.request)
534
574
  );
535
575
  maskByChunk.set(c.chunks[0], ZERO_BIGINT);
536
576
  c.index = nextChunkGroupIndex++;
@@ -561,19 +601,23 @@ const visitModules = (
561
601
  new AsyncDependencyToInitialChunkError(
562
602
  /** @type {string} */ (chunkName),
563
603
  module,
564
- b.loc
604
+ /** @type {DependencyLocation} */ (b.loc)
565
605
  )
566
606
  );
567
607
  c = chunkGroup;
568
608
  } else {
569
609
  c.addOptions(b.groupOptions);
570
610
  }
571
- c.addOrigin(module, b.loc, b.request);
611
+ c.addOrigin(
612
+ module,
613
+ /** @type {DependencyLocation} */ (b.loc),
614
+ /** @type {string} */ (b.request)
615
+ );
572
616
  }
573
617
  blockConnections.set(b, []);
574
618
  }
575
619
  blockChunkGroups.set(b, /** @type {ChunkGroupInfo} */ (cgi));
576
- blockByChunkGroups.set(cgi, b);
620
+ blockByChunkGroups.set(/** @type {ChunkGroupInfo} */ (cgi), b);
577
621
  } else if (entryOptions) {
578
622
  entrypoint = /** @type {Entrypoint} */ (cgi.chunkGroup);
579
623
  } else {
@@ -583,7 +627,8 @@ const visitModules = (
583
627
  if (c !== undefined) {
584
628
  // 2. We store the connection for the block
585
629
  // to connect it later if needed
586
- blockConnections.get(b).push({
630
+ /** @type {BlockChunkGroupConnection[]} */
631
+ (blockConnections.get(b)).push({
587
632
  originChunkGroupInfo: chunkGroupInfo,
588
633
  chunkGroup: c
589
634
  });
@@ -622,7 +667,9 @@ const visitModules = (
622
667
  const blockModules = getBlockModules(block, chunkGroupInfo.runtime);
623
668
 
624
669
  if (blockModules !== undefined) {
625
- const { minAvailableModules } = chunkGroupInfo;
670
+ const minAvailableModules =
671
+ /** @type {bigint} */
672
+ (chunkGroupInfo.minAvailableModules);
626
673
  // Buffer items because order need to be reversed to get indices correct
627
674
  // Traverse all referenced modules
628
675
  for (let i = 0, len = blockModules.length; i < len; i += 3) {
@@ -770,7 +817,7 @@ const visitModules = (
770
817
  // We connect Module and Chunk
771
818
  chunkGraph.connectChunkAndModule(chunk, module);
772
819
  const moduleOrdinal = getModuleOrdinal(module);
773
- let chunkMask = maskByChunk.get(chunk);
820
+ let chunkMask = /** @type {bigint} */ (maskByChunk.get(chunk));
774
821
  chunkMask |= ONE_BIGINT << BigInt(moduleOrdinal);
775
822
  maskByChunk.set(chunk, chunkMask);
776
823
  }
@@ -837,11 +884,13 @@ const visitModules = (
837
884
  if (chunkGroupInfo.resultingAvailableModules !== undefined)
838
885
  return chunkGroupInfo.resultingAvailableModules;
839
886
 
840
- let resultingAvailableModules = chunkGroupInfo.minAvailableModules;
887
+ let resultingAvailableModules = /** @type {bigint} */ (
888
+ chunkGroupInfo.minAvailableModules
889
+ );
841
890
 
842
891
  // add the modules from the chunk group to the set
843
892
  for (const chunk of chunkGroupInfo.chunkGroup.chunks) {
844
- const mask = maskByChunk.get(chunk);
893
+ const mask = /** @type {bigint} */ (maskByChunk.get(chunk));
845
894
  resultingAvailableModules |= mask;
846
895
  }
847
896
 
@@ -986,7 +1035,8 @@ const visitModules = (
986
1035
  const ordinal = getModuleOrdinal(module);
987
1036
  info.skippedModuleConnections.delete(entry);
988
1037
  if (isOrdinalSetInMask(minAvailableModules, ordinal)) {
989
- info.skippedItems.add(module);
1038
+ /** @type {NonNullable<ChunkGroupInfo["skippedItems"]>} */
1039
+ (info.skippedItems).add(module);
990
1040
  continue;
991
1041
  }
992
1042
  }
@@ -1079,13 +1129,11 @@ const visitModules = (
1079
1129
  let preOrderIndex = 0;
1080
1130
  let postOrderIndex = 0;
1081
1131
 
1132
+ /**
1133
+ * @param {DependenciesBlock} current current
1134
+ * @param {BlocksWithNestedBlocks} visited visited dependencies blocks
1135
+ */
1082
1136
  const process = (current, visited) => {
1083
- if (visited.has(current)) {
1084
- return;
1085
- }
1086
-
1087
- visited.add(current);
1088
-
1089
1137
  const blockModules = getBlockModules(current, runtime);
1090
1138
  if (blockModules === undefined) {
1091
1139
  return;
@@ -1099,6 +1147,11 @@ const visitModules = (
1099
1147
  continue;
1100
1148
  }
1101
1149
  const refModule = /** @type {Module} */ (blockModules[i]);
1150
+ if (visited.has(refModule)) {
1151
+ continue;
1152
+ }
1153
+
1154
+ visited.add(refModule);
1102
1155
 
1103
1156
  if (refModule) {
1104
1157
  chunkGroup.setModulePreOrderIndex(refModule, preOrderIndex++);
@@ -1128,9 +1181,9 @@ const visitModules = (
1128
1181
  /**
1129
1182
  *
1130
1183
  * @param {Compilation} compilation the compilation
1131
- * @param {Set<DependenciesBlock>} blocksWithNestedBlocks flag for blocks that have nested blocks
1132
- * @param {Map<AsyncDependenciesBlock, BlockChunkGroupConnection[]>} blockConnections connection for blocks
1133
- * @param {Map<Chunk, bigint>} maskByChunk mapping from chunk to module mask
1184
+ * @param {BlocksWithNestedBlocks} blocksWithNestedBlocks flag for blocks that have nested blocks
1185
+ * @param {BlockConnections} blockConnections connection for blocks
1186
+ * @param {MaskByChunk} maskByChunk mapping from chunk to module mask
1134
1187
  */
1135
1188
  const connectChunkGroups = (
1136
1189
  compilation,
@@ -1149,7 +1202,7 @@ const connectChunkGroups = (
1149
1202
  */
1150
1203
  const areModulesAvailable = (chunkGroup, availableModules) => {
1151
1204
  for (const chunk of chunkGroup.chunks) {
1152
- const chunkMask = maskByChunk.get(chunk);
1205
+ const chunkMask = /** @type {bigint} */ (maskByChunk.get(chunk));
1153
1206
  if ((chunkMask & availableModules) !== chunkMask) return false;
1154
1207
  }
1155
1208
  return true;
@@ -1169,7 +1222,7 @@ const connectChunkGroups = (
1169
1222
  connections.every(({ chunkGroup, originChunkGroupInfo }) =>
1170
1223
  areModulesAvailable(
1171
1224
  chunkGroup,
1172
- originChunkGroupInfo.resultingAvailableModules
1225
+ /** @type {bigint} */ (originChunkGroupInfo.resultingAvailableModules)
1173
1226
  )
1174
1227
  )
1175
1228
  ) {
@@ -1215,7 +1268,7 @@ const cleanupUnconnectedGroups = (compilation, allCreatedChunkGroups) => {
1215
1268
  /**
1216
1269
  * This method creates the Chunk graph from the Module graph
1217
1270
  * @param {Compilation} compilation the compilation
1218
- * @param {Map<Entrypoint, Module[]>} inputEntrypointsAndModules chunk groups which are processed with the modules
1271
+ * @param {InputEntrypointsAndModules} inputEntrypointsAndModules chunk groups which are processed with the modules
1219
1272
  * @returns {void}
1220
1273
  */
1221
1274
  const buildChunkGraph = (compilation, inputEntrypointsAndModules) => {
@@ -1223,19 +1276,19 @@ const buildChunkGraph = (compilation, inputEntrypointsAndModules) => {
1223
1276
 
1224
1277
  // SHARED STATE
1225
1278
 
1226
- /** @type {Map<AsyncDependenciesBlock, BlockChunkGroupConnection[]>} */
1279
+ /** @type {BlockConnections} */
1227
1280
  const blockConnections = new Map();
1228
1281
 
1229
- /** @type {Set<ChunkGroup>} */
1282
+ /** @type {AllCreatedChunkGroups} */
1230
1283
  const allCreatedChunkGroups = new Set();
1231
1284
 
1232
- /** @type {Map<ChunkGroup, ChunkGroupInfo>} */
1285
+ /** @type {ChunkGroupInfoMap} */
1233
1286
  const chunkGroupInfoMap = new Map();
1234
1287
 
1235
- /** @type {Set<DependenciesBlock>} */
1288
+ /** @type {BlocksWithNestedBlocks} */
1236
1289
  const blocksWithNestedBlocks = new Set();
1237
1290
 
1238
- /** @type {Map<Chunk, bigint>} */
1291
+ /** @type {MaskByChunk} */
1239
1292
  const maskByChunk = new Map();
1240
1293
 
1241
1294
  // PART ONE
@@ -9,12 +9,13 @@ const Cache = require("../Cache");
9
9
  const ProgressPlugin = require("../ProgressPlugin");
10
10
 
11
11
  /** @typedef {import("../Compiler")} Compiler */
12
+ /** @typedef {import("./PackFileCacheStrategy")} PackFileCacheStrategy */
12
13
 
13
14
  const BUILD_DEPENDENCIES_KEY = Symbol();
14
15
 
15
16
  class IdleFileCachePlugin {
16
17
  /**
17
- * @param {TODO} strategy cache strategy
18
+ * @param {PackFileCacheStrategy} strategy cache strategy
18
19
  * @param {number} idleTimeout timeout
19
20
  * @param {number} idleTimeoutForInitialStore initial timeout
20
21
  * @param {number} idleTimeoutAfterLargeChanges timeout after changes
@@ -93,7 +94,9 @@ class IdleFileCachePlugin {
93
94
  { name: "IdleFileCachePlugin", stage: Cache.STAGE_DISK },
94
95
  dependencies => {
95
96
  pendingIdleTasks.set(BUILD_DEPENDENCIES_KEY, () =>
96
- strategy.storeBuildDependencies(dependencies)
97
+ Promise.resolve().then(() =>
98
+ strategy.storeBuildDependencies(dependencies)
99
+ )
97
100
  );
98
101
  }
99
102
  );
@@ -227,7 +230,9 @@ class IdleFileCachePlugin {
227
230
  compiler.hooks.done.tap("IdleFileCachePlugin", stats => {
228
231
  // 10% build overhead is ignored, as it's not cacheable
229
232
  timeSpendInBuild *= 0.9;
230
- timeSpendInBuild += stats.endTime - stats.startTime;
233
+ timeSpendInBuild +=
234
+ /** @type {number} */ (stats.endTime) -
235
+ /** @type {number} */ (stats.startTime);
231
236
  });
232
237
  }
233
238
  }
@@ -19,7 +19,7 @@ class MemoryCachePlugin {
19
19
  * @returns {void}
20
20
  */
21
21
  apply(compiler) {
22
- /** @type {Map<string, { etag: Etag | null, data: any }>} */
22
+ /** @type {Map<string, { etag: Etag | null, data: any } | null>} */
23
23
  const cache = new Map();
24
24
  compiler.cache.hooks.store.tap(
25
25
  { name: "MemoryCachePlugin", stage: Cache.STAGE_MEMORY },
@@ -13,6 +13,10 @@ const Cache = require("../Cache");
13
13
  /** @typedef {import("../Module")} Module */
14
14
 
15
15
  class MemoryWithGcCachePlugin {
16
+ /**
17
+ * @param {Object} options Options
18
+ * @param {number} options.maxGenerations max generations
19
+ */
16
20
  constructor({ maxGenerations }) {
17
21
  this._maxGenerations = maxGenerations;
18
22
  }
@@ -23,9 +27,9 @@ class MemoryWithGcCachePlugin {
23
27
  */
24
28
  apply(compiler) {
25
29
  const maxGenerations = this._maxGenerations;
26
- /** @type {Map<string, { etag: Etag | null, data: any }>} */
30
+ /** @type {Map<string, { etag: Etag | null, data: any } | undefined | null>} */
27
31
  const cache = new Map();
28
- /** @type {Map<string, { entry: { etag: Etag | null, data: any }, until: number }>} */
32
+ /** @type {Map<string, { entry: { etag: Etag | null, data: any } | null, until: number }>} */
29
33
  const oldCache = new Map();
30
34
  let generation = 0;
31
35
  let cachePosition = 0;
@@ -28,13 +28,16 @@ const {
28
28
  /** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */
29
29
 
30
30
  /** @typedef {Map<string, string | false>} ResolveResults */
31
+ /** @typedef {Set<string>} Items */
32
+ /** @typedef {Set<string>} BuildDependencies */
33
+ /** @typedef {Map<string, PackItemInfo>} ItemInfo */
31
34
 
32
35
  class PackContainer {
33
36
  /**
34
37
  * @param {Object} data stored data
35
38
  * @param {string} version version identifier
36
39
  * @param {Snapshot} buildSnapshot snapshot of all build dependencies
37
- * @param {Set<string>} buildDependencies list of all unresolved build dependencies captured
40
+ * @param {BuildDependencies} buildDependencies list of all unresolved build dependencies captured
38
41
  * @param {ResolveResults} resolveResults result of the resolved build dependencies
39
42
  * @param {Snapshot} resolveBuildDependenciesSnapshot snapshot of the dependencies of the build dependencies resolving
40
43
  */
@@ -54,13 +57,17 @@ class PackContainer {
54
57
  this.resolveBuildDependenciesSnapshot = resolveBuildDependenciesSnapshot;
55
58
  }
56
59
 
60
+ /**
61
+ * @param {ObjectSerializerContext} context context
62
+ */
57
63
  serialize({ write, writeLazy }) {
58
64
  write(this.version);
59
65
  write(this.buildSnapshot);
60
66
  write(this.buildDependencies);
61
67
  write(this.resolveResults);
62
68
  write(this.resolveBuildDependenciesSnapshot);
63
- writeLazy(this.data);
69
+ /** @type {NonNullable<ObjectSerializerContext["writeLazy"]>} */
70
+ (writeLazy)(this.data);
64
71
  }
65
72
 
66
73
  /**
@@ -104,13 +111,17 @@ class PackItemInfo {
104
111
  }
105
112
 
106
113
  class Pack {
114
+ /**
115
+ * @param {Logger} logger a logger
116
+ * @param {number} maxAge max age of cache items
117
+ */
107
118
  constructor(logger, maxAge) {
108
- /** @type {Map<string, PackItemInfo>} */
119
+ /** @type {ItemInfo} */
109
120
  this.itemInfo = new Map();
110
121
  /** @type {(string | undefined)[]} */
111
122
  this.requests = [];
112
123
  this.requestsTimeout = undefined;
113
- /** @type {Map<string, PackItemInfo>} */
124
+ /** @type {ItemInfo} */
114
125
  this.freshContent = new Map();
115
126
  /** @type {(undefined | PackContent)[]} */
116
127
  this.content = [];
@@ -224,12 +235,18 @@ class Pack {
224
235
  return i;
225
236
  }
226
237
 
238
+ /**
239
+ * @private
240
+ * @param {Items} items items
241
+ * @param {Items} usedItems used items
242
+ * @param {number} newLoc new location
243
+ */
227
244
  _gcAndUpdateLocation(items, usedItems, newLoc) {
228
245
  let count = 0;
229
246
  let lastGC;
230
247
  const now = Date.now();
231
248
  for (const identifier of items) {
232
- const info = this.itemInfo.get(identifier);
249
+ const info = /** @type {PackItemInfo} */ (this.itemInfo.get(identifier));
233
250
  if (now - info.lastAccess > this.maxAge) {
234
251
  this.itemInfo.delete(identifier);
235
252
  items.delete(identifier);
@@ -263,7 +280,7 @@ class Pack {
263
280
  const loc = this._findLocation();
264
281
  this.content[loc] = null; // reserve
265
282
  const pack = {
266
- /** @type {Set<string>} */
283
+ /** @type {Items} */
267
284
  items: new Set(),
268
285
  /** @type {Map<string, any>} */
269
286
  map: new Map(),
@@ -372,9 +389,9 @@ class Pack {
372
389
  }
373
390
 
374
391
  // 4. Determine merged items
375
- /** @type {Set<string>} */
392
+ /** @type {Items} */
376
393
  const mergedItems = new Set();
377
- /** @type {Set<string>} */
394
+ /** @type {Items} */
378
395
  const mergedUsedItems = new Set();
379
396
  /** @type {(function(Map<string, any>): Promise<void>)[]} */
380
397
  const addToMergedMap = [];
@@ -544,6 +561,9 @@ class Pack {
544
561
  }
545
562
  }
546
563
 
564
+ /**
565
+ * @param {ObjectSerializerContext} context context
566
+ */
547
567
  serialize({ write, writeSeparate }) {
548
568
  this._persistFreshContent();
549
569
  this._optimizeSmallContent();
@@ -571,6 +591,9 @@ class Pack {
571
591
  write(null); // null as marker of the end of items
572
592
  }
573
593
 
594
+ /**
595
+ * @param {ObjectDeserializerContext & { logger: Logger }} context context
596
+ */
574
597
  deserialize({ read, logger }) {
575
598
  this.logger = logger;
576
599
  {
@@ -629,6 +652,9 @@ class PackContentItems {
629
652
  this.map = map;
630
653
  }
631
654
 
655
+ /**
656
+ * @param {ObjectSerializerContext & { snapshot: TODO, rollback: TODO, logger: Logger, profile: boolean | undefined }} context context
657
+ */
632
658
  serialize({ write, snapshot, rollback, logger, profile }) {
633
659
  if (profile) {
634
660
  write(false);
@@ -695,6 +721,9 @@ class PackContentItems {
695
721
  }
696
722
  }
697
723
 
724
+ /**
725
+ * @param {ObjectDeserializerContext & { logger: Logger, profile: boolean | undefined }} context context
726
+ */
698
727
  deserialize({ read, logger, profile }) {
699
728
  if (read()) {
700
729
  this.map = read();
@@ -760,17 +789,17 @@ class PackContent {
760
789
  */
761
790
 
762
791
  /**
763
- * @param {Set<string>} items keys
764
- * @param {Set<string>} usedItems used keys
792
+ * @param {Items} items keys
793
+ * @param {Items} usedItems used keys
765
794
  * @param {PackContentItems | function(): Promise<PackContentItems>} dataOrFn sync or async content
766
795
  * @param {Logger=} logger logger for logging
767
796
  * @param {string=} lazyName name of dataOrFn for logging
768
797
  */
769
798
  constructor(items, usedItems, dataOrFn, logger, lazyName) {
770
799
  this.items = items;
771
- /** @type {function(): Promise<PackContentItems> | PackContentItems} */
800
+ /** @type {(function(): Promise<PackContentItems> | PackContentItems) | undefined} */
772
801
  this.lazy = typeof dataOrFn === "function" ? dataOrFn : undefined;
773
- /** @type {Map<string, any>} */
802
+ /** @type {Map<string, any> | undefined} */
774
803
  this.content = typeof dataOrFn === "function" ? undefined : dataOrFn.map;
775
804
  this.outdated = false;
776
805
  this.used = usedItems;
@@ -778,6 +807,10 @@ class PackContent {
778
807
  this.lazyName = lazyName;
779
808
  }
780
809
 
810
+ /**
811
+ * @param {string} identifier identifier
812
+ * @returns {string | Promise<string>} result
813
+ */
781
814
  get(identifier) {
782
815
  this.used.add(identifier);
783
816
  if (this.content) {
@@ -1049,7 +1082,7 @@ class PackFileCacheStrategy {
1049
1082
  ? ".pack.gz"
1050
1083
  : ".pack";
1051
1084
  this.snapshot = snapshot;
1052
- /** @type {Set<string>} */
1085
+ /** @type {BuildDependencies} */
1053
1086
  this.buildDependencies = new Set();
1054
1087
  /** @type {LazySet<string>} */
1055
1088
  this.newBuildDependencies = new LazySet();
@@ -1081,9 +1114,9 @@ class PackFileCacheStrategy {
1081
1114
  const { logger, profile, cacheLocation, version } = this;
1082
1115
  /** @type {Snapshot} */
1083
1116
  let buildSnapshot;
1084
- /** @type {Set<string>} */
1117
+ /** @type {BuildDependencies} */
1085
1118
  let buildDependencies;
1086
- /** @type {Set<string>} */
1119
+ /** @type {BuildDependencies} */
1087
1120
  let newBuildDependencies;
1088
1121
  /** @type {Snapshot} */
1089
1122
  let resolveBuildDependenciesSnapshot;
@@ -1272,7 +1305,7 @@ class PackFileCacheStrategy {
1272
1305
  }
1273
1306
 
1274
1307
  /**
1275
- * @param {LazySet<string>} dependencies dependencies to store
1308
+ * @param {LazySet<string> | Iterable<string>} dependencies dependencies to store
1276
1309
  */
1277
1310
  storeBuildDependencies(dependencies) {
1278
1311
  if (this.readonly) return;