webpack 5.104.1 → 5.105.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.
Files changed (279) hide show
  1. package/bin/webpack.js +6 -3
  2. package/lib/APIPlugin.js +85 -15
  3. package/lib/AbstractMethodError.js +1 -0
  4. package/lib/AsyncDependenciesBlock.js +13 -1
  5. package/lib/AsyncDependencyToInitialChunkError.js +1 -0
  6. package/lib/AutomaticPrefetchPlugin.js +1 -1
  7. package/lib/BannerPlugin.js +2 -0
  8. package/lib/CacheFacade.js +2 -2
  9. package/lib/CaseSensitiveModulesWarning.js +1 -0
  10. package/lib/Chunk.js +8 -4
  11. package/lib/ChunkGraph.js +30 -9
  12. package/lib/ChunkGroup.js +6 -3
  13. package/lib/ChunkRenderError.js +2 -0
  14. package/lib/CleanPlugin.js +4 -1
  15. package/lib/CodeGenerationError.js +7 -1
  16. package/lib/CodeGenerationResults.js +10 -3
  17. package/lib/CommentCompilationWarning.js +2 -1
  18. package/lib/Compilation.js +280 -236
  19. package/lib/Compiler.js +3 -2
  20. package/lib/ConcatenationScope.js +2 -1
  21. package/lib/ConcurrentCompilationError.js +3 -3
  22. package/lib/ContextModule.js +248 -111
  23. package/lib/ContextModuleFactory.js +14 -2
  24. package/lib/DefinePlugin.js +3 -1
  25. package/lib/DelegatedModule.js +6 -0
  26. package/lib/DelegatedModuleFactoryPlugin.js +2 -0
  27. package/lib/Dependency.js +6 -1
  28. package/lib/DependencyTemplates.js +3 -2
  29. package/lib/DllModule.js +2 -0
  30. package/lib/DllReferencePlugin.js +1 -0
  31. package/lib/DotenvPlugin.js +11 -5
  32. package/lib/DynamicEntryPlugin.js +1 -0
  33. package/lib/EnvironmentNotSupportAsyncWarning.js +1 -0
  34. package/lib/EvalSourceMapDevToolPlugin.js +17 -13
  35. package/lib/ExportsInfo.js +8 -4
  36. package/lib/ExternalModule.js +16 -0
  37. package/lib/FalseIIFEUmdWarning.js +1 -0
  38. package/lib/FileSystemInfo.js +49 -25
  39. package/lib/FlagDependencyExportsPlugin.js +8 -1
  40. package/lib/FlagDependencyUsagePlugin.js +9 -7
  41. package/lib/HarmonyLinkingError.js +1 -0
  42. package/lib/HookWebpackError.js +2 -0
  43. package/lib/HotModuleReplacementPlugin.js +16 -2
  44. package/lib/InitFragment.js +1 -0
  45. package/lib/InvalidDependenciesModuleWarning.js +1 -0
  46. package/lib/LibManifestPlugin.js +1 -0
  47. package/lib/ManifestPlugin.js +4 -1
  48. package/lib/Module.js +7 -4
  49. package/lib/ModuleBuildError.js +3 -1
  50. package/lib/ModuleDependencyError.js +1 -0
  51. package/lib/ModuleDependencyWarning.js +1 -0
  52. package/lib/ModuleError.js +2 -1
  53. package/lib/ModuleFilenameHelpers.js +2 -1
  54. package/lib/ModuleGraph.js +3 -0
  55. package/lib/ModuleGraphConnection.js +10 -1
  56. package/lib/ModuleHashingError.js +2 -0
  57. package/lib/ModuleInfoHeaderPlugin.js +6 -1
  58. package/lib/ModuleNotFoundError.js +1 -0
  59. package/lib/ModuleParseError.js +5 -1
  60. package/lib/ModuleProfile.js +1 -1
  61. package/lib/ModuleRestoreError.js +2 -0
  62. package/lib/ModuleSourceTypeConstants.js +1 -11
  63. package/lib/ModuleStoreError.js +2 -0
  64. package/lib/ModuleWarning.js +3 -1
  65. package/lib/MultiCompiler.js +11 -7
  66. package/lib/MultiWatching.js +2 -2
  67. package/lib/NoModeWarning.js +1 -0
  68. package/lib/NodeStuffInWebError.js +1 -0
  69. package/lib/NormalModule.js +26 -5
  70. package/lib/NormalModuleFactory.js +20 -4
  71. package/lib/OptionsApply.js +3 -1
  72. package/lib/ProgressPlugin.js +4 -0
  73. package/lib/RawModule.js +2 -0
  74. package/lib/RuntimeModule.js +10 -0
  75. package/lib/RuntimePlugin.js +7 -9
  76. package/lib/RuntimeTemplate.js +14 -7
  77. package/lib/SourceMapDevToolPlugin.js +30 -23
  78. package/lib/Template.js +10 -5
  79. package/lib/TemplatedPathPlugin.js +4 -2
  80. package/lib/UnhandledSchemeError.js +1 -0
  81. package/lib/UnsupportedFeatureWarning.js +1 -0
  82. package/lib/WarnDeprecatedOptionPlugin.js +1 -0
  83. package/lib/WatchIgnorePlugin.js +1 -1
  84. package/lib/Watching.js +5 -0
  85. package/lib/WebpackError.js +4 -0
  86. package/lib/WebpackOptionsApply.js +60 -40
  87. package/lib/asset/AssetBytesGenerator.js +1 -0
  88. package/lib/asset/AssetGenerator.js +9 -3
  89. package/lib/asset/AssetModulesPlugin.js +33 -2
  90. package/lib/asset/AssetSourceGenerator.js +1 -0
  91. package/lib/asset/RawDataUrlModule.js +4 -0
  92. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -1
  93. package/lib/buildChunkGraph.js +31 -2
  94. package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
  95. package/lib/cache/PackFileCacheStrategy.js +41 -8
  96. package/lib/cache/getLazyHashedEtag.js +13 -4
  97. package/lib/cache/mergeEtags.js +3 -1
  98. package/lib/cli.js +3 -1
  99. package/lib/config/defaults.js +65 -44
  100. package/lib/config/normalization.js +96 -0
  101. package/lib/container/ContainerEntryModule.js +4 -0
  102. package/lib/container/FallbackModule.js +2 -0
  103. package/lib/container/HoistContainerReferencesPlugin.js +6 -0
  104. package/lib/container/RemoteModule.js +19 -0
  105. package/lib/css/CssGenerator.js +31 -4
  106. package/lib/css/CssModulesPlugin.js +26 -30
  107. package/lib/css/CssParser.js +12 -9
  108. package/lib/debug/ProfilingPlugin.js +1 -0
  109. package/lib/dependencies/AMDDefineDependency.js +3 -1
  110. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -0
  111. package/lib/dependencies/AMDPlugin.js +1 -1
  112. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +7 -1
  113. package/lib/dependencies/CachedConstDependency.js +1 -0
  114. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -0
  115. package/lib/dependencies/CommonJsExportRequireDependency.js +1 -0
  116. package/lib/dependencies/CommonJsFullRequireDependency.js +2 -0
  117. package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -0
  118. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
  119. package/lib/dependencies/CommonJsSelfReferenceDependency.js +1 -0
  120. package/lib/dependencies/ConstDependency.js +1 -0
  121. package/lib/dependencies/ContextDependencyHelpers.js +11 -4
  122. package/lib/dependencies/ContextElementDependency.js +1 -0
  123. package/lib/dependencies/CriticalDependencyWarning.js +1 -0
  124. package/lib/dependencies/CssIcssExportDependency.js +5 -4
  125. package/lib/dependencies/CssIcssSymbolDependency.js +1 -0
  126. package/lib/dependencies/CssUrlDependency.js +2 -3
  127. package/lib/dependencies/ExternalModuleInitFragment.js +4 -1
  128. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +0 -9
  129. package/lib/dependencies/HarmonyAcceptDependency.js +3 -0
  130. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +1 -0
  131. package/lib/dependencies/HarmonyExportExpressionDependency.js +4 -0
  132. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +8 -1
  133. package/lib/dependencies/HarmonyExportInitFragment.js +17 -3
  134. package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
  135. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +266 -5
  136. package/lib/dependencies/HarmonyImportSpecifierDependency.js +22 -3
  137. package/lib/dependencies/ImportDependency.js +1 -0
  138. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
  139. package/lib/dependencies/ImportMetaPlugin.js +53 -11
  140. package/lib/dependencies/ImportParserPlugin.js +7 -12
  141. package/lib/dependencies/LoaderPlugin.js +3 -0
  142. package/lib/dependencies/ModuleDecoratorDependency.js +1 -0
  143. package/lib/dependencies/ModuleDependency.js +1 -0
  144. package/lib/dependencies/ModuleInitFragmentDependency.js +87 -0
  145. package/lib/dependencies/ProvidedDependency.js +1 -0
  146. package/lib/dependencies/RequireContextPlugin.js +1 -0
  147. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +7 -2
  148. package/lib/dependencies/RuntimeRequirementsDependency.js +1 -0
  149. package/lib/dependencies/WorkerDependency.js +9 -3
  150. package/lib/dependencies/WorkerPlugin.js +1 -0
  151. package/lib/dependencies/getFunctionExpression.js +3 -1
  152. package/lib/errors/BuildCycleError.js +4 -1
  153. package/lib/esm/ModuleChunkFormatPlugin.js +6 -4
  154. package/lib/esm/ModuleChunkLoadingPlugin.js +1 -0
  155. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -0
  156. package/lib/hmr/LazyCompilationPlugin.js +5 -0
  157. package/lib/hmr/lazyCompilationBackend.js +3 -2
  158. package/lib/ids/ChunkModuleIdRangePlugin.js +2 -0
  159. package/lib/ids/IdHelpers.js +10 -8
  160. package/lib/ids/OccurrenceModuleIdsPlugin.js +15 -7
  161. package/lib/ids/SyncModuleIdsPlugin.js +5 -1
  162. package/lib/javascript/BasicEvaluatedExpression.js +1 -0
  163. package/lib/javascript/EnableChunkLoadingPlugin.js +5 -2
  164. package/lib/javascript/JavascriptModulesPlugin.js +29 -8
  165. package/lib/javascript/JavascriptParser.js +47 -14
  166. package/lib/json/JsonParser.js +6 -0
  167. package/lib/library/AbstractLibraryPlugin.js +4 -1
  168. package/lib/library/AmdLibraryPlugin.js +2 -1
  169. package/lib/library/AssignLibraryPlugin.js +6 -2
  170. package/lib/library/EnableLibraryPlugin.js +1 -0
  171. package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
  172. package/lib/library/JsonpLibraryPlugin.js +1 -1
  173. package/lib/library/ModuleLibraryPlugin.js +130 -13
  174. package/lib/library/SystemLibraryPlugin.js +4 -1
  175. package/lib/library/UmdLibraryPlugin.js +4 -3
  176. package/lib/logging/createConsoleLogger.js +3 -0
  177. package/lib/logging/truncateArgs.js +1 -1
  178. package/lib/node/CommonJsChunkLoadingPlugin.js +1 -0
  179. package/lib/node/NodeTargetPlugin.js +1 -0
  180. package/lib/node/NodeWatchFileSystem.js +3 -0
  181. package/lib/node/nodeConsole.js +18 -1
  182. package/lib/optimize/AggressiveMergingPlugin.js +2 -1
  183. package/lib/optimize/AggressiveSplittingPlugin.js +10 -6
  184. package/lib/optimize/ConcatenatedModule.js +33 -19
  185. package/lib/optimize/FlagIncludedChunksPlugin.js +11 -1
  186. package/lib/optimize/InnerGraph.js +5 -3
  187. package/lib/optimize/InnerGraphPlugin.js +25 -25
  188. package/lib/optimize/MangleExportsPlugin.js +14 -2
  189. package/lib/optimize/MergeDuplicateChunksPlugin.js +3 -0
  190. package/lib/optimize/MinChunkSizePlugin.js +5 -2
  191. package/lib/optimize/ModuleConcatenationPlugin.js +19 -4
  192. package/lib/optimize/RealContentHashPlugin.js +35 -27
  193. package/lib/optimize/RemoveParentModulesPlugin.js +12 -3
  194. package/lib/optimize/SideEffectsFlagPlugin.js +3 -0
  195. package/lib/optimize/SplitChunksPlugin.js +14 -3
  196. package/lib/performance/AssetsOverSizeLimitWarning.js +6 -2
  197. package/lib/performance/EntrypointsOverSizeLimitWarning.js +6 -2
  198. package/lib/performance/NoAsyncChunksWarning.js +1 -0
  199. package/lib/rules/BasicEffectRulePlugin.js +2 -0
  200. package/lib/rules/BasicMatcherRulePlugin.js +3 -0
  201. package/lib/rules/ObjectMatcherRulePlugin.js +5 -1
  202. package/lib/rules/RuleSetCompiler.js +2 -0
  203. package/lib/runtime/AsyncModuleRuntimeModule.js +1 -0
  204. package/lib/runtime/ChunkNameRuntimeModule.js +1 -0
  205. package/lib/runtime/CompatRuntimeModule.js +1 -0
  206. package/lib/runtime/EnsureChunkRuntimeModule.js +1 -0
  207. package/lib/runtime/GetChunkFilenameRuntimeModule.js +4 -0
  208. package/lib/runtime/GetMainFilenameRuntimeModule.js +2 -0
  209. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -0
  210. package/lib/runtime/LoadScriptRuntimeModule.js +2 -0
  211. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +15 -32
  212. package/lib/runtime/PublicPathRuntimeModule.js +1 -0
  213. package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -0
  214. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -0
  215. package/lib/runtime/StartupEntrypointRuntimeModule.js +1 -0
  216. package/lib/schemes/HttpUriPlugin.js +27 -7
  217. package/lib/schemes/VirtualUrlPlugin.js +7 -2
  218. package/lib/serialization/BinaryMiddleware.js +4 -0
  219. package/lib/serialization/FileMiddleware.js +9 -4
  220. package/lib/serialization/ObjectMiddleware.js +34 -11
  221. package/lib/serialization/PlainObjectSerializer.js +2 -0
  222. package/lib/sharing/ConsumeSharedModule.js +60 -0
  223. package/lib/sharing/ConsumeSharedPlugin.js +5 -4
  224. package/lib/sharing/ProvideSharedModule.js +4 -0
  225. package/lib/sharing/ProvideSharedPlugin.js +24 -25
  226. package/lib/sharing/resolveMatchedConfigs.js +2 -2
  227. package/lib/sharing/utils.js +8 -6
  228. package/lib/stats/DefaultStatsFactoryPlugin.js +14 -12
  229. package/lib/stats/DefaultStatsPrinterPlugin.js +6 -5
  230. package/lib/stats/StatsFactory.js +2 -2
  231. package/lib/url/URLParserPlugin.js +4 -3
  232. package/lib/util/AppendOnlyStackedSet.js +57 -0
  233. package/lib/util/Hash.js +1 -0
  234. package/lib/util/IterableHelpers.js +1 -0
  235. package/lib/util/LazyBucketSortedSet.js +1 -0
  236. package/lib/util/LazySet.js +1 -0
  237. package/lib/util/ParallelismFactorCalculator.js +1 -0
  238. package/lib/util/SortableSet.js +1 -0
  239. package/lib/util/StringXor.js +1 -0
  240. package/lib/util/binarySearchBounds.js +15 -8
  241. package/lib/util/chainedImports.js +1 -1
  242. package/lib/util/cleverMerge.js +6 -1
  243. package/lib/util/comparators.js +21 -1
  244. package/lib/util/compileBooleanMatcher.js +3 -3
  245. package/lib/util/concatenate.js +3 -2
  246. package/lib/util/conventions.js +3 -2
  247. package/lib/util/deterministicGrouping.js +13 -1
  248. package/lib/util/extractSourceMap.js +12 -13
  249. package/lib/util/fs.js +15 -19
  250. package/lib/util/hash/BatchedHash.js +3 -0
  251. package/lib/util/hash/BulkUpdateHash.js +7 -1
  252. package/lib/util/hash/hash-digest.js +1 -0
  253. package/lib/util/hash/wasm-hash.js +16 -1
  254. package/lib/util/identifier.js +7 -2
  255. package/lib/util/magicComment.js +1 -1
  256. package/lib/util/propertyName.js +1 -1
  257. package/lib/util/registerExternalSerializer.js +1 -0
  258. package/lib/util/runtime.js +15 -1
  259. package/lib/util/semver.js +1 -0
  260. package/lib/util/serialization.js +2 -2
  261. package/lib/wasm/EnableWasmLoadingPlugin.js +1 -0
  262. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +11 -3
  263. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -0
  264. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -2
  265. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -1
  266. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +3 -0
  267. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
  268. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +7 -3
  269. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -2
  270. package/lib/wasm-sync/WebAssemblyParser.js +3 -1
  271. package/lib/web/FetchCompileWasmPlugin.js +1 -0
  272. package/lib/web/JsonpChunkLoadingPlugin.js +1 -0
  273. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -0
  274. package/lib/webpack.js +13 -3
  275. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
  276. package/package.json +20 -28
  277. package/schemas/WebpackOptions.check.js +1 -1
  278. package/schemas/WebpackOptions.json +71 -5
  279. package/types.d.ts +339 -93
@@ -20,6 +20,12 @@ const createHash = require("../util/createHash");
20
20
  /** @typedef {import("../Compiler")} Compiler */
21
21
  /** @typedef {typeof import("../util/Hash")} Hash */
22
22
 
23
+ /**
24
+ * @template T
25
+ * @typedef {import("../util/comparators").Comparator<T>} Comparator
26
+ */
27
+
28
+ /** @type {Hashes} */
23
29
  const EMPTY_SET = new Set();
24
30
 
25
31
  /**
@@ -47,6 +53,7 @@ const mapAndDeduplicateBuffers = (input, fn) => {
47
53
  // Buffer.equals compares size first so this should be efficient enough
48
54
  // If it becomes a performance problem we can use a map and group by size
49
55
  // instead of looping over all assets.
56
+ /** @type {Buffer[]} */
50
57
  const result = [];
51
58
  outer: for (const value of input) {
52
59
  const buf = fn(value);
@@ -65,6 +72,7 @@ const mapAndDeduplicateBuffers = (input, fn) => {
65
72
  */
66
73
  const quoteMeta = (str) => str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
67
74
 
75
+ /** @type {WeakMap<Source, CachedSource>} */
68
76
  const cachedSourceMap = new WeakMap();
69
77
 
70
78
  /**
@@ -82,8 +90,6 @@ const toCachedSource = (source) => {
82
90
  return newSource;
83
91
  };
84
92
 
85
- /** @typedef {Set<string>} OwnHashes */
86
- /** @typedef {Set<string>} ReferencedHashes */
87
93
  /** @typedef {Set<string>} Hashes */
88
94
 
89
95
  /**
@@ -94,10 +100,10 @@ const toCachedSource = (source) => {
94
100
  * @property {RawSource | undefined} newSource
95
101
  * @property {RawSource | undefined} newSourceWithoutOwn
96
102
  * @property {string} content
97
- * @property {OwnHashes | undefined} ownHashes
103
+ * @property {Hashes | undefined} ownHashes
98
104
  * @property {Promise<void> | undefined} contentComputePromise
99
105
  * @property {Promise<void> | undefined} contentComputeWithoutOwnPromise
100
- * @property {ReferencedHashes | undefined} referencedHashes
106
+ * @property {Hashes | undefined} referencedHashes
101
107
  * @property {Hashes} hashes
102
108
  */
103
109
 
@@ -220,7 +226,9 @@ class RealContentHashPlugin {
220
226
  );
221
227
  [asset.referencedHashes, asset.ownHashes] =
222
228
  await cacheAnalyse.providePromise(name, etag, () => {
229
+ /** @type {Hashes} */
223
230
  const referencedHashes = new Set();
231
+ /** @type {Hashes} */
224
232
  const ownHashes = new Set();
225
233
  const inContent = content.match(hashRegExp);
226
234
  if (inContent) {
@@ -238,15 +246,13 @@ class RealContentHashPlugin {
238
246
  );
239
247
  /**
240
248
  * @param {string} hash the hash
241
- * @returns {undefined | ReferencedHashes} the referenced hashes
249
+ * @returns {undefined | Hashes} the referenced hashes
242
250
  */
243
251
  const getDependencies = (hash) => {
244
252
  const assets = hashToAssets.get(hash);
245
253
  if (!assets) {
246
254
  const referencingAssets = assetsWithInfo.filter((asset) =>
247
- /** @type {ReferencedHashes} */ (asset.referencedHashes).has(
248
- hash
249
- )
255
+ /** @type {Hashes} */ (asset.referencedHashes).has(hash)
250
256
  );
251
257
  const err = new WebpackError(`RealContentHashPlugin
252
258
  Some kind of unexpected caching problem occurred.
@@ -264,16 +270,15 @@ ${referencingAssets
264
270
  compilation.errors.push(err);
265
271
  return;
266
272
  }
273
+ /** @type {Hashes} */
267
274
  const hashes = new Set();
268
275
  for (const { referencedHashes, ownHashes } of assets) {
269
- if (!(/** @type {OwnHashes} */ (ownHashes).has(hash))) {
270
- for (const hash of /** @type {OwnHashes} */ (ownHashes)) {
276
+ if (!(/** @type {Hashes} */ (ownHashes).has(hash))) {
277
+ for (const hash of /** @type {Hashes} */ (ownHashes)) {
271
278
  hashes.add(hash);
272
279
  }
273
280
  }
274
- for (const hash of /** @type {ReferencedHashes} */ (
275
- referencedHashes
276
- )) {
281
+ for (const hash of /** @type {Hashes} */ (referencedHashes)) {
277
282
  hashes.add(hash);
278
283
  }
279
284
  }
@@ -290,7 +295,7 @@ ${referencingAssets
290
295
  (a) => a.name
291
296
  )})`;
292
297
  };
293
- /** @type {Set<string>} */
298
+ /** @type {Hashes} */
294
299
  const hashesInOrder = new Set();
295
300
  for (const hash of hashToAssets.keys()) {
296
301
  /**
@@ -329,7 +334,7 @@ ${referencingAssets
329
334
  cacheGenerate.mergeEtags(
330
335
  cacheGenerate.getLazyHashedEtag(asset.source),
331
336
  Array.from(
332
- /** @type {ReferencedHashes} */ (asset.referencedHashes),
337
+ /** @type {Hashes} */ (asset.referencedHashes),
333
338
  (hash) => hashToNewHash.get(hash)
334
339
  ).join("|")
335
340
  );
@@ -341,10 +346,10 @@ ${referencingAssets
341
346
  if (asset.contentComputePromise) return asset.contentComputePromise;
342
347
  return (asset.contentComputePromise = (async () => {
343
348
  if (
344
- /** @type {OwnHashes} */ (asset.ownHashes).size > 0 ||
345
- [
346
- .../** @type {ReferencedHashes} */ (asset.referencedHashes)
347
- ].some((hash) => hashToNewHash.get(hash) !== hash)
349
+ /** @type {Hashes} */ (asset.ownHashes).size > 0 ||
350
+ [.../** @type {Hashes} */ (asset.referencedHashes)].some(
351
+ (hash) => hashToNewHash.get(hash) !== hash
352
+ )
348
353
  ) {
349
354
  const identifier = asset.name;
350
355
  const etag = getEtag(asset);
@@ -372,10 +377,10 @@ ${referencingAssets
372
377
  }
373
378
  return (asset.contentComputeWithoutOwnPromise = (async () => {
374
379
  if (
375
- /** @type {OwnHashes} */ (asset.ownHashes).size > 0 ||
376
- [
377
- .../** @type {ReferencedHashes} */ (asset.referencedHashes)
378
- ].some((hash) => hashToNewHash.get(hash) !== hash)
380
+ /** @type {Hashes} */ (asset.ownHashes).size > 0 ||
381
+ [.../** @type {Hashes} */ (asset.referencedHashes)].some(
382
+ (hash) => hashToNewHash.get(hash) !== hash
383
+ )
379
384
  ) {
380
385
  const identifier = `${asset.name}|without-own`;
381
386
  const etag = getEtag(asset);
@@ -387,7 +392,7 @@ ${referencingAssets
387
392
  hashRegExp,
388
393
  (hash) => {
389
394
  if (
390
- /** @type {OwnHashes} */
395
+ /** @type {Hashes} */
391
396
  (asset.ownHashes).has(hash)
392
397
  ) {
393
398
  return "";
@@ -401,6 +406,7 @@ ${referencingAssets
401
406
  }
402
407
  })());
403
408
  };
409
+ /** @type {Comparator<AssetInfoForRealContentHash>} */
404
410
  const comparator = compareSelect((a) => a.name, compareStrings);
405
411
  for (const oldHash of hashesInOrder) {
406
412
  const assets =
@@ -409,13 +415,13 @@ ${referencingAssets
409
415
  assets.sort(comparator);
410
416
  await Promise.all(
411
417
  assets.map((asset) =>
412
- /** @type {OwnHashes} */ (asset.ownHashes).has(oldHash)
418
+ /** @type {Hashes} */ (asset.ownHashes).has(oldHash)
413
419
  ? computeNewContentWithoutOwn(asset)
414
420
  : computeNewContent(asset)
415
421
  )
416
422
  );
417
423
  const assetsContent = mapAndDeduplicateBuffers(assets, (asset) => {
418
- if (/** @type {OwnHashes} */ (asset.ownHashes).has(oldHash)) {
424
+ if (/** @type {Hashes} */ (asset.ownHashes).has(oldHash)) {
419
425
  return asset.newSourceWithoutOwn
420
426
  ? asset.newSourceWithoutOwn.buffer()
421
427
  : asset.source.buffer();
@@ -447,7 +453,9 @@ ${referencingAssets
447
453
  );
448
454
 
449
455
  const infoUpdate = {};
450
- const hash = /** @type {string} */ (asset.info.contenthash);
456
+ const hash =
457
+ /** @type {Exclude<AssetInfo["contenthash"], undefined>} */
458
+ (asset.info.contenthash);
451
459
  infoUpdate.contenthash = Array.isArray(hash)
452
460
  ? hash.map(
453
461
  (hash) => /** @type {string} */ (hashToNewHash.get(hash))
@@ -33,7 +33,7 @@ const THIRTY_TWO_BIGINT = BigInt(32);
33
33
  * Parses the module mask and returns the modules represented by it
34
34
  * @param {bigint} mask the module mask
35
35
  * @param {Module[]} ordinalModules the modules in the order they were added to the mask (LSB is index 0)
36
- * @returns {Generator<Module>} the modules represented by the mask
36
+ * @returns {Generator<Module, undefined, undefined>} the modules represented by the mask
37
37
  */
38
38
  function* getModulesFromMask(mask, ordinalModules) {
39
39
  let offset = 31;
@@ -74,10 +74,13 @@ class RemoveParentModulesPlugin {
74
74
  */
75
75
  const handler = (chunks, chunkGroups) => {
76
76
  const chunkGraph = compilation.chunkGraph;
77
+ /** @type {Set<ChunkGroup>} */
77
78
  const queue = new Set();
79
+ /** @type {WeakMap<ChunkGroup, bigint | undefined>} */
78
80
  const availableModulesMap = new WeakMap();
79
81
 
80
82
  let nextModuleMask = ONE_BIGINT;
83
+ /** @type {WeakMap<Module, bigint>} */
81
84
  const maskByModule = new WeakMap();
82
85
  /** @type {Module[]} */
83
86
  const ordinalModules = [];
@@ -99,6 +102,7 @@ class RemoveParentModulesPlugin {
99
102
  };
100
103
 
101
104
  // Initialize masks by chunk and by chunk group for quicker comparisons
105
+ /** @type {WeakMap<Chunk, bigint>} */
102
106
  const chunkMasks = new WeakMap();
103
107
  for (const chunk of chunks) {
104
108
  let mask = ZERO_BIGINT;
@@ -109,6 +113,7 @@ class RemoveParentModulesPlugin {
109
113
  chunkMasks.set(chunk, mask);
110
114
  }
111
115
 
116
+ /** @type {WeakMap<ChunkGroup, bigint>} */
112
117
  const chunkGroupMasks = new WeakMap();
113
118
  for (const chunkGroup of chunkGroups) {
114
119
  let mask = ZERO_BIGINT;
@@ -143,7 +148,8 @@ class RemoveParentModulesPlugin {
143
148
  const availableModulesInParent = availableModulesMap.get(parent);
144
149
  if (availableModulesInParent !== undefined) {
145
150
  const parentMask =
146
- availableModulesInParent | chunkGroupMasks.get(parent);
151
+ availableModulesInParent |
152
+ /** @type {bigint} */ (chunkGroupMasks.get(parent));
147
153
  // If we know the available modules in parent: process these
148
154
  if (availableModulesMask === undefined) {
149
155
  // if we have not own info yet: create new entry
@@ -181,7 +187,10 @@ class RemoveParentModulesPlugin {
181
187
  );
182
188
  if (availableModulesSets.includes(undefined)) continue; // No info about this chunk group
183
189
 
184
- const availableModulesMask = intersectMasks(availableModulesSets);
190
+ const availableModulesMask = intersectMasks(
191
+ /** @type {bigint[]} */
192
+ (availableModulesSets)
193
+ );
185
194
  const toRemoveMask = chunkMask & availableModulesMask;
186
195
  if (toRemoveMask !== ZERO_BIGINT) {
187
196
  for (const module of getModulesFromMask(
@@ -68,6 +68,7 @@ class SideEffectsFlagPlugin {
68
68
  * @param {boolean} analyseSource analyse source code for side effects
69
69
  */
70
70
  constructor(analyseSource = true) {
71
+ /** @type {boolean} */
71
72
  this._analyseSource = analyseSource;
72
73
  }
73
74
 
@@ -277,6 +278,7 @@ class SideEffectsFlagPlugin {
277
278
 
278
279
  logger.time("update dependencies");
279
280
 
281
+ /** @type {Set<Module>} */
280
282
  const optimizedModules = new Set();
281
283
 
282
284
  /**
@@ -291,6 +293,7 @@ class SideEffectsFlagPlugin {
291
293
  module
292
294
  )) {
293
295
  const dep = connection.dependency;
296
+ /** @type {boolean} */
294
297
  let isReexport;
295
298
  if (
296
299
  (isReexport =
@@ -36,6 +36,7 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
36
36
  /** @typedef {import("../TemplatedPathPlugin").TemplatePath} TemplatePath */
37
37
  /** @typedef {import("../util/deterministicGrouping").GroupedItems<Module>} DeterministicGroupingGroupedItemsForModule */
38
38
  /** @typedef {import("../util/deterministicGrouping").Options<Module>} DeterministicGroupingOptionsForModule */
39
+ /** @typedef {import("../util/deterministicGrouping").Sizes} Sizes */
39
40
 
40
41
  /**
41
42
  * @callback ChunkFilterFn
@@ -220,9 +221,10 @@ const getRequests = (chunk) => {
220
221
  * @returns {T} result
221
222
  */
222
223
  const mapObject = (obj, fn) => {
224
+ /** @type {T} */
223
225
  const newObj = Object.create(null);
224
226
  for (const key of Object.keys(obj)) {
225
- newObj[key] = fn(
227
+ newObj[/** @type {keyof T} */ (key)] = fn(
226
228
  obj[/** @type {keyof T} */ (key)],
227
229
  /** @type {keyof T} */
228
230
  (key)
@@ -478,6 +480,7 @@ const normalizeCacheGroups = (cacheGroups, defaultSizeTypes) => {
478
480
  }
479
481
  });
480
482
  } else if (typeof option === "function") {
483
+ /** @type {WeakMap<OptimizationSplitChunksCacheGroup, CacheGroupSource>} */
481
484
  const cache = new WeakMap();
482
485
  handlers.push((module, context, results) => {
483
486
  const result = option(module);
@@ -868,7 +871,7 @@ module.exports = class SplitChunksPlugin {
868
871
  index <<= ONE;
869
872
  }
870
873
  /**
871
- * @param {Iterable<Chunk>} chunks list of chunks
874
+ * @param {Iterable<Chunk, undefined, undefined>} chunks list of chunks
872
875
  * @returns {bigint | Chunk} key of the chunks
873
876
  */
874
877
  const getKey = (chunks) => {
@@ -921,6 +924,7 @@ module.exports = class SplitChunksPlugin {
921
924
  */
922
925
  const groupChunksByExports = (module) => {
923
926
  const exportsInfo = moduleGraph.getExportsInfo(module);
927
+ /** @type {Map<string, Chunk[]>} */
924
928
  const groupedByUsedExports = new Map();
925
929
  for (const chunk of chunkGraph.getModuleChunksIterable(module)) {
926
930
  const key = exportsInfo.getUsageKey(chunk.runtime);
@@ -1082,7 +1086,8 @@ module.exports = class SplitChunksPlugin {
1082
1086
  * @property {bigint | Chunk} key a key of the list
1083
1087
  */
1084
1088
 
1085
- /** @type {WeakMap<ChunkSet | Chunk, WeakMap<ChunkFilterFn, SelectedChunksResult>>} */
1089
+ /** @typedef {WeakMap<ChunkFilterFn, SelectedChunksResult>} ChunkMap */
1090
+ /** @type {WeakMap<ChunkSet | Chunk, ChunkMap>} */
1086
1091
  const selectedChunksCacheByChunksSet = new WeakMap();
1087
1092
 
1088
1093
  /**
@@ -1095,6 +1100,7 @@ module.exports = class SplitChunksPlugin {
1095
1100
  const getSelectedChunks = (chunks, chunkFilter) => {
1096
1101
  let entry = selectedChunksCacheByChunksSet.get(chunks);
1097
1102
  if (entry === undefined) {
1103
+ /** @type {ChunkMap} */
1098
1104
  entry = new WeakMap();
1099
1105
  selectedChunksCacheByChunksSet.set(chunks, entry);
1100
1106
  }
@@ -1392,7 +1398,9 @@ module.exports = class SplitChunksPlugin {
1392
1398
 
1393
1399
  while (chunksInfoMap.size > 0) {
1394
1400
  // Find best matching entry
1401
+ /** @type {undefined | string} */
1395
1402
  let bestEntryKey;
1403
+ /** @type {undefined | ChunksInfoItem} */
1396
1404
  let bestEntry;
1397
1405
  for (const pair of chunksInfoMap) {
1398
1406
  const key = pair[0];
@@ -1471,6 +1479,7 @@ module.exports = class SplitChunksPlugin {
1471
1479
  item.cacheGroup._conditionalEnforce &&
1472
1480
  checkMinSize(item.sizes, item.cacheGroup.enforceSizeThreshold);
1473
1481
 
1482
+ /** @type {Set<Chunk>} */
1474
1483
  const usedChunks = new Set(item.chunks);
1475
1484
 
1476
1485
  // Check if maxRequests condition can be fulfilled
@@ -1533,6 +1542,7 @@ module.exports = class SplitChunksPlugin {
1533
1542
  usedChunks.size === 1
1534
1543
  ) {
1535
1544
  const [chunk] = usedChunks;
1545
+ /** @type {SplitChunksSizes} */
1536
1546
  const chunkSizes = Object.create(null);
1537
1547
  for (const module of chunkGraph.getChunkModulesIterable(chunk)) {
1538
1548
  if (!item.modules.has(module)) {
@@ -1763,6 +1773,7 @@ module.exports = class SplitChunksPlugin {
1763
1773
  return key;
1764
1774
  },
1765
1775
  getSize(module) {
1776
+ /** @type {Sizes} */
1766
1777
  const size = Object.create(null);
1767
1778
  for (const key of module.getSourceTypes()) {
1768
1779
  size[key] = module.size(key);
@@ -10,7 +10,7 @@ const WebpackError = require("../WebpackError");
10
10
 
11
11
  /** @typedef {import("./SizeLimitsPlugin").AssetDetails} AssetDetails */
12
12
 
13
- module.exports = class AssetsOverSizeLimitWarning extends WebpackError {
13
+ class AssetsOverSizeLimitWarning extends WebpackError {
14
14
  /**
15
15
  * @param {AssetDetails[]} assetsOverSizeLimit the assets
16
16
  * @param {number} assetLimit the size limit
@@ -26,7 +26,11 @@ module.exports = class AssetsOverSizeLimitWarning extends WebpackError {
26
26
  This can impact web performance.
27
27
  Assets: ${assetLists}`);
28
28
 
29
+ /** @type {string} */
29
30
  this.name = "AssetsOverSizeLimitWarning";
30
31
  this.assets = assetsOverSizeLimit;
31
32
  }
32
- };
33
+ }
34
+
35
+ /** @type {typeof AssetsOverSizeLimitWarning} */
36
+ module.exports = AssetsOverSizeLimitWarning;
@@ -10,7 +10,7 @@ const WebpackError = require("../WebpackError");
10
10
 
11
11
  /** @typedef {import("./SizeLimitsPlugin").EntrypointDetails} EntrypointDetails */
12
12
 
13
- module.exports = class EntrypointsOverSizeLimitWarning extends WebpackError {
13
+ class EntrypointsOverSizeLimitWarning extends WebpackError {
14
14
  /**
15
15
  * @param {EntrypointDetails[]} entrypoints the entrypoints
16
16
  * @param {number} entrypointLimit the size limit
@@ -29,7 +29,11 @@ module.exports = class EntrypointsOverSizeLimitWarning extends WebpackError {
29
29
  )}). This can impact web performance.
30
30
  Entrypoints:${entrypointList}\n`);
31
31
 
32
+ /** @type {string} */
32
33
  this.name = "EntrypointsOverSizeLimitWarning";
33
34
  this.entrypoints = entrypoints;
34
35
  }
35
- };
36
+ }
37
+
38
+ /** @type {typeof EntrypointsOverSizeLimitWarning} */
39
+ module.exports = EntrypointsOverSizeLimitWarning;
@@ -15,6 +15,7 @@ module.exports = class NoAsyncChunksWarning extends WebpackError {
15
15
  "For more info visit https://webpack.js.org/guides/code-splitting/"
16
16
  );
17
17
 
18
+ /** @type {string} */
18
19
  this.name = "NoAsyncChunksWarning";
19
20
  }
20
21
  };
@@ -24,7 +24,9 @@ class BasicEffectRulePlugin {
24
24
  * @param {string=} effectType the effect type
25
25
  */
26
26
  constructor(ruleProperty, effectType) {
27
+ /** @type {BasicEffectRuleKeys} */
27
28
  this.ruleProperty = ruleProperty;
29
+ /** @type {string | BasicEffectRuleKeys} */
28
30
  this.effectType = effectType || ruleProperty;
29
31
  }
30
32
 
@@ -27,8 +27,11 @@ class BasicMatcherRulePlugin {
27
27
  * @param {boolean=} invert if true, inverts the condition
28
28
  */
29
29
  constructor(ruleProperty, dataProperty, invert) {
30
+ /** @type {BasicMatcherRuleKeys} */
30
31
  this.ruleProperty = ruleProperty;
32
+ /** @type {string | BasicMatcherRuleKeys} */
31
33
  this.dataProperty = dataProperty || ruleProperty;
34
+ /** @type {boolean} */
32
35
  this.invert = invert || false;
33
36
  }
34
37
 
@@ -18,18 +18,22 @@
18
18
  */
19
19
 
20
20
  /** @typedef {KeysOfTypes<RuleSetRule, { [k: string]: RuleSetConditionOrConditions }>} ObjectMatcherRuleKeys */
21
+ /** @typedef {keyof EffectData} DataProperty */
21
22
 
22
23
  const PLUGIN_NAME = "ObjectMatcherRulePlugin";
23
24
 
24
25
  class ObjectMatcherRulePlugin {
25
26
  /**
26
27
  * @param {ObjectMatcherRuleKeys} ruleProperty the rule property
27
- * @param {keyof EffectData=} dataProperty the data property
28
+ * @param {DataProperty=} dataProperty the data property
28
29
  * @param {RuleConditionFunction=} additionalConditionFunction need to check
29
30
  */
30
31
  constructor(ruleProperty, dataProperty, additionalConditionFunction) {
32
+ /** @type {ObjectMatcherRuleKeys} */
31
33
  this.ruleProperty = ruleProperty;
34
+ /** @type {DataProperty | ObjectMatcherRuleKeys} */
32
35
  this.dataProperty = dataProperty || ruleProperty;
36
+ /** @type {RuleConditionFunction | undefined} */
33
37
  this.additionalConditionFunction = additionalConditionFunction;
34
38
  }
35
39
 
@@ -116,6 +116,7 @@ class RuleSetCompiler {
116
116
  * @returns {RuleSet} compiled RuleSet
117
117
  */
118
118
  compile(ruleSet) {
119
+ /** @type {References} */
119
120
  const refs = new Map();
120
121
  const rules = this.compileRules("ruleSet", ruleSet, refs);
121
122
 
@@ -327,6 +328,7 @@ class RuleSetCompiler {
327
328
  );
328
329
  }
329
330
 
331
+ /** @type {Condition[]} */
330
332
  const conditions = [];
331
333
  for (const key of Object.keys(condition)) {
332
334
  const value = condition[key];
@@ -16,6 +16,7 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
16
16
  */
17
17
  constructor(deferInterop = false) {
18
18
  super("async module");
19
+ /** @type {boolean} */
19
20
  this._deferInterop = deferInterop;
20
21
  }
21
22
 
@@ -13,6 +13,7 @@ class ChunkNameRuntimeModule extends RuntimeModule {
13
13
  */
14
14
  constructor(chunkName) {
15
15
  super("chunkName");
16
+ /** @type {string} */
16
17
  this.chunkName = chunkName;
17
18
  }
18
19
 
@@ -14,6 +14,7 @@ const RuntimeModule = require("../RuntimeModule");
14
14
  class CompatRuntimeModule extends RuntimeModule {
15
15
  constructor() {
16
16
  super("compat", RuntimeModule.STAGE_ATTACH);
17
+ /** @type {boolean} */
17
18
  this.fullHash = true;
18
19
  }
19
20
 
@@ -17,6 +17,7 @@ class EnsureChunkRuntimeModule extends RuntimeModule {
17
17
  */
18
18
  constructor(runtimeRequirements) {
19
19
  super("ensure chunk");
20
+ /** @type {ReadOnlyRuntimeRequirements} */
20
21
  this.runtimeRequirements = runtimeRequirements;
21
22
  }
22
23
 
@@ -26,10 +26,14 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
26
26
  */
27
27
  constructor(contentType, name, global, getFilenameForChunk, allChunks) {
28
28
  super(`get ${name} chunk filename`);
29
+ /** @type {string} */
29
30
  this.contentType = contentType;
31
+ /** @type {string} */
30
32
  this.global = global;
31
33
  this.getFilenameForChunk = getFilenameForChunk;
34
+ /** @type {boolean} */
32
35
  this.allChunks = allChunks;
36
+ /** @type {boolean} */
33
37
  this.dependentHash = true;
34
38
  }
35
39
 
@@ -19,7 +19,9 @@ class GetMainFilenameRuntimeModule extends RuntimeModule {
19
19
  */
20
20
  constructor(name, global, filename) {
21
21
  super(`get ${name} filename`);
22
+ /** @type {string} */
22
23
  this.global = global;
24
+ /** @type {string} */
23
25
  this.filename = filename;
24
26
  }
25
27
 
@@ -17,6 +17,7 @@ class GetTrustedTypesPolicyRuntimeModule extends HelperRuntimeModule {
17
17
  */
18
18
  constructor(runtimeRequirements) {
19
19
  super("trusted types policy");
20
+ /** @type {ReadOnlyRuntimeRequirements} */
20
21
  this.runtimeRequirements = runtimeRequirements;
21
22
  }
22
23
 
@@ -47,7 +47,9 @@ class LoadScriptRuntimeModule extends HelperRuntimeModule {
47
47
  */
48
48
  constructor(withCreateScriptUrl, withFetchPriority) {
49
49
  super("load script");
50
+ /** @type {boolean | undefined} */
50
51
  this._withCreateScriptUrl = withCreateScriptUrl;
52
+ /** @type {boolean | undefined} */
51
53
  this._withFetchPriority = withFetchPriority;
52
54
  }
53
55