webpack 5.97.1 → 5.104.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.
Files changed (610) hide show
  1. package/README.md +368 -434
  2. package/bin/webpack.js +15 -9
  3. package/hot/dev-server.js +18 -3
  4. package/hot/emitter-event-target.js +7 -0
  5. package/hot/lazy-compilation-node.js +45 -29
  6. package/hot/lazy-compilation-universal.js +18 -0
  7. package/hot/lazy-compilation-web.js +15 -5
  8. package/hot/load-http.js +7 -0
  9. package/hot/log.js +15 -15
  10. package/hot/only-dev-server.js +19 -4
  11. package/hot/poll.js +1 -0
  12. package/lib/APIPlugin.js +48 -50
  13. package/lib/AbstractMethodError.js +1 -0
  14. package/lib/AsyncDependenciesBlock.js +4 -5
  15. package/lib/AutomaticPrefetchPlugin.js +22 -22
  16. package/lib/BannerPlugin.js +35 -40
  17. package/lib/Cache.js +12 -9
  18. package/lib/CacheFacade.js +13 -13
  19. package/lib/CaseSensitiveModulesWarning.js +6 -6
  20. package/lib/Chunk.js +68 -47
  21. package/lib/ChunkGraph.js +174 -95
  22. package/lib/ChunkGroup.js +32 -24
  23. package/lib/ChunkTemplate.js +8 -8
  24. package/lib/CleanPlugin.js +90 -42
  25. package/lib/CodeGenerationResults.js +12 -9
  26. package/lib/CompatibilityPlugin.js +70 -21
  27. package/lib/Compilation.js +827 -550
  28. package/lib/Compiler.js +137 -109
  29. package/lib/ConcatenationScope.js +45 -8
  30. package/lib/ConditionalInitFragment.js +1 -1
  31. package/lib/ConstPlugin.js +89 -59
  32. package/lib/ContextExclusionPlugin.js +5 -4
  33. package/lib/ContextModule.js +66 -51
  34. package/lib/ContextModuleFactory.js +51 -30
  35. package/lib/ContextReplacementPlugin.js +89 -34
  36. package/lib/CssModule.js +8 -4
  37. package/lib/DefinePlugin.js +209 -57
  38. package/lib/DelegatedModule.js +34 -23
  39. package/lib/DelegatedModuleFactoryPlugin.js +27 -24
  40. package/lib/DelegatedPlugin.js +4 -2
  41. package/lib/DependenciesBlock.js +0 -2
  42. package/lib/Dependency.js +37 -19
  43. package/lib/DependencyTemplate.js +2 -0
  44. package/lib/DependencyTemplates.js +5 -6
  45. package/lib/DllEntryPlugin.js +8 -4
  46. package/lib/DllModule.js +11 -12
  47. package/lib/DllModuleFactory.js +2 -2
  48. package/lib/DllPlugin.js +9 -6
  49. package/lib/DllReferencePlugin.js +60 -65
  50. package/lib/DotenvPlugin.js +462 -0
  51. package/lib/DynamicEntryPlugin.js +8 -8
  52. package/lib/EntryOptionPlugin.js +8 -6
  53. package/lib/EntryPlugin.js +5 -3
  54. package/lib/Entrypoint.js +19 -0
  55. package/lib/EnvironmentNotSupportAsyncWarning.js +0 -3
  56. package/lib/EnvironmentPlugin.js +26 -19
  57. package/lib/ErrorHelpers.js +6 -6
  58. package/lib/EvalDevToolModulePlugin.js +17 -14
  59. package/lib/EvalSourceMapDevToolPlugin.js +156 -142
  60. package/lib/ExportsInfo.js +180 -115
  61. package/lib/ExportsInfoApiPlugin.js +2 -2
  62. package/lib/ExternalModule.js +256 -102
  63. package/lib/ExternalModuleFactoryPlugin.js +66 -29
  64. package/lib/ExternalsPlugin.js +57 -2
  65. package/lib/FileSystemInfo.js +313 -247
  66. package/lib/FlagAllModulesAsUsedPlugin.js +2 -2
  67. package/lib/FlagDependencyExportsPlugin.js +29 -19
  68. package/lib/FlagDependencyUsagePlugin.js +9 -10
  69. package/lib/FlagEntryExportAsUsedPlugin.js +1 -1
  70. package/lib/Generator.js +43 -10
  71. package/lib/GraphHelpers.js +11 -3
  72. package/lib/HookWebpackError.js +35 -7
  73. package/lib/HotModuleReplacementPlugin.js +149 -108
  74. package/lib/HotUpdateChunk.js +0 -3
  75. package/lib/IgnoreErrorModuleFactory.js +2 -2
  76. package/lib/IgnorePlugin.js +16 -13
  77. package/lib/IgnoreWarningsPlugin.js +6 -4
  78. package/lib/InitFragment.js +41 -23
  79. package/lib/InvalidDependenciesModuleWarning.js +2 -3
  80. package/lib/JavascriptMetaInfoPlugin.js +2 -4
  81. package/lib/LibManifestPlugin.js +12 -13
  82. package/lib/LoaderOptionsPlugin.js +12 -14
  83. package/lib/LoaderTargetPlugin.js +5 -3
  84. package/lib/MainTemplate.js +18 -29
  85. package/lib/ManifestPlugin.js +235 -0
  86. package/lib/Module.js +138 -60
  87. package/lib/ModuleBuildError.js +4 -2
  88. package/lib/ModuleDependencyError.js +4 -3
  89. package/lib/ModuleDependencyWarning.js +4 -3
  90. package/lib/ModuleError.js +1 -1
  91. package/lib/ModuleFactory.js +10 -3
  92. package/lib/ModuleFilenameHelpers.js +63 -60
  93. package/lib/ModuleGraph.js +195 -70
  94. package/lib/ModuleGraphConnection.js +14 -20
  95. package/lib/ModuleInfoHeaderPlugin.js +15 -16
  96. package/lib/ModuleNotFoundError.js +1 -1
  97. package/lib/ModuleParseError.js +8 -4
  98. package/lib/ModuleSourceTypeConstants.js +189 -0
  99. package/lib/ModuleTemplate.js +7 -8
  100. package/lib/ModuleTypeConstants.js +37 -15
  101. package/lib/ModuleWarning.js +1 -1
  102. package/lib/MultiCompiler.js +64 -49
  103. package/lib/MultiStats.js +19 -14
  104. package/lib/MultiWatching.js +7 -11
  105. package/lib/NoEmitOnErrorsPlugin.js +5 -3
  106. package/lib/NodeStuffPlugin.js +438 -126
  107. package/lib/NormalModule.js +322 -201
  108. package/lib/NormalModuleFactory.js +230 -117
  109. package/lib/NormalModuleReplacementPlugin.js +37 -39
  110. package/lib/NullFactory.js +3 -2
  111. package/lib/OptimizationStages.js +1 -1
  112. package/lib/OptionsApply.js +1 -1
  113. package/lib/Parser.js +5 -3
  114. package/lib/PlatformPlugin.js +3 -1
  115. package/lib/PrefetchPlugin.js +6 -4
  116. package/lib/ProgressPlugin.js +48 -49
  117. package/lib/ProvidePlugin.js +7 -5
  118. package/lib/RawModule.js +26 -12
  119. package/lib/RecordIdsPlugin.js +88 -110
  120. package/lib/RequestShortener.js +3 -1
  121. package/lib/ResolverFactory.js +15 -14
  122. package/lib/RuntimeGlobals.js +216 -153
  123. package/lib/RuntimeModule.js +7 -6
  124. package/lib/RuntimePlugin.js +115 -62
  125. package/lib/RuntimeTemplate.js +248 -76
  126. package/lib/SelfModuleFactory.js +2 -2
  127. package/lib/SizeFormatHelpers.js +2 -2
  128. package/lib/SourceMapDevToolModuleOptionsPlugin.js +17 -27
  129. package/lib/SourceMapDevToolPlugin.js +72 -59
  130. package/lib/Stats.js +2 -3
  131. package/lib/Template.js +31 -24
  132. package/lib/TemplatedPathPlugin.js +24 -21
  133. package/lib/UseStrictPlugin.js +1 -1
  134. package/lib/WarnCaseSensitiveModulesPlugin.js +36 -37
  135. package/lib/WarnDeprecatedOptionPlugin.js +7 -8
  136. package/lib/WarnNoModeSetPlugin.js +3 -1
  137. package/lib/WatchIgnorePlugin.js +11 -9
  138. package/lib/Watching.js +27 -29
  139. package/lib/WebpackError.js +10 -3
  140. package/lib/WebpackIsIncludedPlugin.js +4 -5
  141. package/lib/WebpackOptionsApply.js +263 -135
  142. package/lib/asset/AssetBytesGenerator.js +171 -0
  143. package/lib/asset/AssetBytesParser.js +37 -0
  144. package/lib/asset/AssetGenerator.js +285 -223
  145. package/lib/asset/AssetModulesPlugin.js +103 -41
  146. package/lib/asset/AssetParser.js +7 -3
  147. package/lib/asset/AssetSourceGenerator.js +41 -17
  148. package/lib/asset/RawDataUrlModule.js +17 -9
  149. package/lib/async-modules/AsyncModuleHelpers.js +52 -0
  150. package/lib/async-modules/AwaitDependenciesInitFragment.js +39 -24
  151. package/lib/async-modules/InferAsyncModulesPlugin.js +25 -26
  152. package/lib/buildChunkGraph.js +36 -17
  153. package/lib/cache/AddBuildDependenciesPlugin.js +5 -6
  154. package/lib/cache/IdleFileCachePlugin.js +22 -20
  155. package/lib/cache/MemoryCachePlugin.js +3 -3
  156. package/lib/cache/MemoryWithGcCachePlugin.js +17 -11
  157. package/lib/cache/PackFileCacheStrategy.js +198 -170
  158. package/lib/cache/ResolverCachePlugin.js +58 -48
  159. package/lib/cache/getLazyHashedEtag.js +5 -4
  160. package/lib/cli.js +197 -39
  161. package/lib/config/browserslistTargetHandler.js +110 -85
  162. package/lib/config/defaults.js +514 -113
  163. package/lib/config/normalization.js +91 -64
  164. package/lib/config/target.js +30 -18
  165. package/lib/container/ContainerEntryDependency.js +0 -1
  166. package/lib/container/ContainerEntryModule.js +16 -15
  167. package/lib/container/ContainerEntryModuleFactory.js +2 -2
  168. package/lib/container/ContainerPlugin.js +5 -6
  169. package/lib/container/ContainerReferencePlugin.js +27 -30
  170. package/lib/container/FallbackDependency.js +2 -1
  171. package/lib/container/FallbackModule.js +19 -14
  172. package/lib/container/FallbackModuleFactory.js +2 -2
  173. package/lib/container/HoistContainerReferencesPlugin.js +7 -7
  174. package/lib/container/ModuleFederationPlugin.js +4 -4
  175. package/lib/container/RemoteModule.js +14 -14
  176. package/lib/container/RemoteRuntimeModule.js +2 -2
  177. package/lib/container/options.js +9 -9
  178. package/lib/css/CssGenerator.js +366 -74
  179. package/lib/css/CssLoadingRuntimeModule.js +26 -16
  180. package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
  181. package/lib/css/CssModulesPlugin.js +191 -142
  182. package/lib/css/CssParser.js +1756 -740
  183. package/lib/css/walkCssTokens.js +180 -67
  184. package/lib/debug/ProfilingPlugin.js +135 -51
  185. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +29 -28
  186. package/lib/dependencies/AMDPlugin.js +18 -11
  187. package/lib/dependencies/AMDRequireArrayDependency.js +5 -4
  188. package/lib/dependencies/AMDRequireContextDependency.js +2 -1
  189. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +35 -26
  190. package/lib/dependencies/AMDRuntimeModules.js +3 -1
  191. package/lib/dependencies/CachedConstDependency.js +24 -18
  192. package/lib/dependencies/CommonJsExportRequireDependency.js +31 -24
  193. package/lib/dependencies/CommonJsExportsDependency.js +2 -1
  194. package/lib/dependencies/CommonJsExportsParserPlugin.js +50 -36
  195. package/lib/dependencies/CommonJsFullRequireDependency.js +7 -13
  196. package/lib/dependencies/CommonJsImportsParserPlugin.js +146 -127
  197. package/lib/dependencies/CommonJsPlugin.js +29 -18
  198. package/lib/dependencies/CommonJsRequireContextDependency.js +4 -3
  199. package/lib/dependencies/CommonJsSelfReferenceDependency.js +4 -4
  200. package/lib/dependencies/ConstDependency.js +2 -2
  201. package/lib/dependencies/ContextDependency.js +10 -5
  202. package/lib/dependencies/ContextDependencyHelpers.js +21 -13
  203. package/lib/dependencies/ContextDependencyTemplateAsId.js +10 -9
  204. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +13 -10
  205. package/lib/dependencies/ContextElementDependency.js +23 -12
  206. package/lib/dependencies/CssIcssExportDependency.js +402 -22
  207. package/lib/dependencies/CssIcssImportDependency.js +116 -51
  208. package/lib/dependencies/CssIcssSymbolDependency.js +33 -35
  209. package/lib/dependencies/CssImportDependency.js +17 -14
  210. package/lib/dependencies/CssUrlDependency.js +8 -13
  211. package/lib/dependencies/DynamicExports.js +19 -19
  212. package/lib/dependencies/ExportsInfoDependency.js +13 -10
  213. package/lib/dependencies/ExternalModuleDependency.js +7 -7
  214. package/lib/dependencies/ExternalModuleInitFragment.js +3 -2
  215. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +96 -0
  216. package/lib/dependencies/HarmonyAcceptDependency.js +96 -5
  217. package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -5
  218. package/lib/dependencies/HarmonyCompatibilityDependency.js +0 -1
  219. package/lib/dependencies/HarmonyDetectionParserPlugin.js +10 -30
  220. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +19 -8
  221. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +136 -99
  222. package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
  223. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +152 -61
  224. package/lib/dependencies/HarmonyExportInitFragment.js +2 -2
  225. package/lib/dependencies/HarmonyExportSpecifierDependency.js +2 -2
  226. package/lib/dependencies/HarmonyExports.js +5 -5
  227. package/lib/dependencies/HarmonyImportDependency.js +92 -45
  228. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +201 -163
  229. package/lib/dependencies/HarmonyImportSideEffectDependency.js +5 -6
  230. package/lib/dependencies/HarmonyImportSpecifierDependency.js +69 -42
  231. package/lib/dependencies/HarmonyModulesPlugin.js +16 -11
  232. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -15
  233. package/lib/dependencies/ImportContextDependency.js +15 -1
  234. package/lib/dependencies/ImportDependency.js +25 -7
  235. package/lib/dependencies/ImportEagerDependency.js +7 -5
  236. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +23 -13
  237. package/lib/dependencies/ImportMetaContextPlugin.js +2 -2
  238. package/lib/dependencies/ImportMetaPlugin.js +172 -20
  239. package/lib/dependencies/ImportParserPlugin.js +327 -49
  240. package/lib/dependencies/ImportPhase.js +121 -0
  241. package/lib/dependencies/ImportPlugin.js +3 -1
  242. package/lib/dependencies/ImportWeakDependency.js +7 -5
  243. package/lib/dependencies/JsonExportsDependency.js +54 -28
  244. package/lib/dependencies/LoaderDependency.js +0 -3
  245. package/lib/dependencies/LoaderImportDependency.js +0 -3
  246. package/lib/dependencies/LoaderPlugin.js +24 -25
  247. package/lib/dependencies/LocalModulesHelpers.js +4 -4
  248. package/lib/dependencies/ModuleDecoratorDependency.js +2 -4
  249. package/lib/dependencies/ModuleDependency.js +14 -13
  250. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
  251. package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
  252. package/lib/dependencies/NullDependency.js +2 -0
  253. package/lib/dependencies/ProvidedDependency.js +8 -10
  254. package/lib/dependencies/PureExpressionDependency.js +1 -2
  255. package/lib/dependencies/RequireContextDependency.js +2 -1
  256. package/lib/dependencies/RequireContextDependencyParserPlugin.js +47 -44
  257. package/lib/dependencies/RequireContextPlugin.js +5 -2
  258. package/lib/dependencies/RequireEnsureDependenciesBlock.js +3 -3
  259. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +101 -99
  260. package/lib/dependencies/RequireEnsurePlugin.js +6 -6
  261. package/lib/dependencies/RequireIncludeDependency.js +2 -2
  262. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +33 -34
  263. package/lib/dependencies/RequireIncludePlugin.js +1 -0
  264. package/lib/dependencies/RequireResolveContextDependency.js +1 -1
  265. package/lib/dependencies/RequireResolveDependency.js +3 -3
  266. package/lib/dependencies/RuntimeRequirementsDependency.js +3 -4
  267. package/lib/dependencies/StaticExportsDependency.js +3 -5
  268. package/lib/dependencies/SystemPlugin.js +4 -4
  269. package/lib/dependencies/URLContextDependency.js +65 -0
  270. package/lib/dependencies/URLDependency.js +3 -8
  271. package/lib/dependencies/URLPlugin.js +18 -159
  272. package/lib/dependencies/WebAssemblyExportImportedDependency.js +3 -3
  273. package/lib/dependencies/WebAssemblyImportDependency.js +2 -2
  274. package/lib/dependencies/WebpackIsIncludedDependency.js +2 -3
  275. package/lib/dependencies/WorkerDependency.js +8 -6
  276. package/lib/dependencies/WorkerPlugin.js +131 -67
  277. package/lib/dependencies/getFunctionExpression.js +2 -2
  278. package/lib/dependencies/processExportInfo.js +4 -4
  279. package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -1
  280. package/lib/esm/ModuleChunkFormatPlugin.js +232 -179
  281. package/lib/esm/ModuleChunkLoadingPlugin.js +112 -57
  282. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +102 -28
  283. package/lib/formatLocation.js +2 -2
  284. package/lib/hmr/HotModuleReplacement.runtime.js +41 -29
  285. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  286. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +43 -33
  287. package/lib/hmr/JavascriptHotModuleReplacementHelper.js +37 -0
  288. package/lib/hmr/LazyCompilationPlugin.js +67 -54
  289. package/lib/hmr/lazyCompilationBackend.js +23 -18
  290. package/lib/ids/ChunkModuleIdRangePlugin.js +14 -11
  291. package/lib/ids/DeterministicChunkIdsPlugin.js +32 -37
  292. package/lib/ids/DeterministicModuleIdsPlugin.js +52 -52
  293. package/lib/ids/HashedModuleIdsPlugin.js +15 -13
  294. package/lib/ids/IdHelpers.js +66 -49
  295. package/lib/ids/NamedChunkIdsPlugin.js +14 -17
  296. package/lib/ids/NamedModuleIdsPlugin.js +12 -14
  297. package/lib/ids/NaturalChunkIdsPlugin.js +6 -4
  298. package/lib/ids/NaturalModuleIdsPlugin.js +4 -3
  299. package/lib/ids/OccurrenceChunkIdsPlugin.js +7 -5
  300. package/lib/ids/OccurrenceModuleIdsPlugin.js +8 -7
  301. package/lib/ids/SyncModuleIdsPlugin.js +18 -13
  302. package/lib/index.js +54 -14
  303. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +116 -119
  304. package/lib/javascript/BasicEvaluatedExpression.js +26 -18
  305. package/lib/javascript/ChunkFormatHelpers.js +70 -0
  306. package/lib/javascript/ChunkHelpers.js +17 -5
  307. package/lib/javascript/CommonJsChunkFormatPlugin.js +114 -141
  308. package/lib/javascript/EnableChunkLoadingPlugin.js +7 -4
  309. package/lib/javascript/JavascriptGenerator.js +122 -100
  310. package/lib/javascript/JavascriptModulesPlugin.js +332 -152
  311. package/lib/javascript/JavascriptParser.js +1488 -1052
  312. package/lib/javascript/JavascriptParserHelpers.js +48 -47
  313. package/lib/javascript/StartupHelpers.js +23 -22
  314. package/lib/json/JsonData.js +4 -4
  315. package/lib/json/JsonGenerator.js +66 -32
  316. package/lib/json/JsonModulesPlugin.js +16 -6
  317. package/lib/json/JsonParser.js +23 -8
  318. package/lib/library/AbstractLibraryPlugin.js +45 -10
  319. package/lib/library/AmdLibraryPlugin.js +7 -5
  320. package/lib/library/AssignLibraryPlugin.js +71 -17
  321. package/lib/library/EnableLibraryPlugin.js +51 -25
  322. package/lib/library/ExportPropertyLibraryPlugin.js +12 -18
  323. package/lib/library/JsonpLibraryPlugin.js +5 -2
  324. package/lib/library/ModuleLibraryPlugin.js +230 -18
  325. package/lib/library/SystemLibraryPlugin.js +29 -11
  326. package/lib/library/UmdLibraryPlugin.js +35 -32
  327. package/lib/logging/Logger.js +18 -15
  328. package/lib/logging/createConsoleLogger.js +27 -27
  329. package/lib/logging/runtime.js +11 -11
  330. package/lib/logging/truncateArgs.js +5 -5
  331. package/lib/node/CommonJsChunkLoadingPlugin.js +72 -75
  332. package/lib/node/NodeEnvironmentPlugin.js +9 -3
  333. package/lib/node/NodeTargetPlugin.js +9 -1
  334. package/lib/node/NodeTemplatePlugin.js +2 -2
  335. package/lib/node/NodeWatchFileSystem.js +4 -4
  336. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -38
  337. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +10 -11
  338. package/lib/node/ReadFileCompileWasmPlugin.js +11 -14
  339. package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -30
  340. package/lib/node/nodeConsole.js +12 -7
  341. package/lib/optimize/AggressiveMergingPlugin.js +46 -47
  342. package/lib/optimize/AggressiveSplittingPlugin.js +233 -238
  343. package/lib/optimize/ConcatenatedModule.js +620 -251
  344. package/lib/optimize/EnsureChunkConditionsPlugin.js +58 -58
  345. package/lib/optimize/FlagIncludedChunksPlugin.js +93 -96
  346. package/lib/optimize/InnerGraph.js +139 -124
  347. package/lib/optimize/InnerGraphPlugin.js +29 -24
  348. package/lib/optimize/LimitChunkCountPlugin.js +32 -8
  349. package/lib/optimize/MangleExportsPlugin.js +22 -22
  350. package/lib/optimize/MergeDuplicateChunksPlugin.js +80 -81
  351. package/lib/optimize/MinChunkSizePlugin.js +12 -7
  352. package/lib/optimize/ModuleConcatenationPlugin.js +92 -71
  353. package/lib/optimize/RealContentHashPlugin.js +58 -44
  354. package/lib/optimize/RemoveEmptyChunksPlugin.js +8 -5
  355. package/lib/optimize/RemoveParentModulesPlugin.js +7 -4
  356. package/lib/optimize/RuntimeChunkPlugin.js +22 -25
  357. package/lib/optimize/SideEffectsFlagPlugin.js +44 -26
  358. package/lib/optimize/SplitChunksPlugin.js +209 -158
  359. package/lib/performance/AssetsOverSizeLimitWarning.js +1 -1
  360. package/lib/performance/EntrypointsOverSizeLimitWarning.js +2 -2
  361. package/lib/performance/SizeLimitsPlugin.js +8 -5
  362. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +5 -7
  363. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +61 -64
  364. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +3 -4
  365. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +2 -2
  366. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +2 -2
  367. package/lib/rules/BasicEffectRulePlugin.js +14 -5
  368. package/lib/rules/BasicMatcherRulePlugin.js +18 -7
  369. package/lib/rules/ObjectMatcherRulePlugin.js +17 -6
  370. package/lib/rules/RuleSetCompiler.js +73 -32
  371. package/lib/rules/UseEffectRulePlugin.js +61 -25
  372. package/lib/runtime/AsyncModuleRuntimeModule.js +74 -9
  373. package/lib/runtime/AutoPublicPathRuntimeModule.js +9 -4
  374. package/lib/runtime/BaseUriRuntimeModule.js +2 -2
  375. package/lib/runtime/CompatRuntimeModule.js +0 -1
  376. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +1 -1
  377. package/lib/runtime/GetChunkFilenameRuntimeModule.js +34 -35
  378. package/lib/runtime/GetMainFilenameRuntimeModule.js +1 -1
  379. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
  380. package/lib/runtime/LoadScriptRuntimeModule.js +0 -2
  381. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +248 -0
  382. package/lib/runtime/PublicPathRuntimeModule.js +2 -2
  383. package/lib/runtime/RuntimeIdRuntimeModule.js +2 -1
  384. package/lib/runtime/StartupChunkDependenciesPlugin.js +39 -42
  385. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +10 -9
  386. package/lib/runtime/StartupEntrypointRuntimeModule.js +0 -1
  387. package/lib/runtime/SystemContextRuntimeModule.js +0 -2
  388. package/lib/runtime/ToBinaryRuntimeModule.js +64 -0
  389. package/lib/schemes/DataUriPlugin.js +9 -31
  390. package/lib/schemes/FileUriPlugin.js +11 -6
  391. package/lib/schemes/HttpUriPlugin.js +381 -261
  392. package/lib/schemes/VirtualUrlPlugin.js +222 -0
  393. package/lib/serialization/AggregateErrorSerializer.js +41 -0
  394. package/lib/serialization/BinaryMiddleware.js +51 -33
  395. package/lib/serialization/ErrorObjectSerializer.js +7 -2
  396. package/lib/serialization/FileMiddleware.js +101 -71
  397. package/lib/serialization/NullPrototypeObjectSerializer.js +5 -3
  398. package/lib/serialization/ObjectMiddleware.js +130 -54
  399. package/lib/serialization/PlainObjectSerializer.js +1 -1
  400. package/lib/serialization/Serializer.js +38 -20
  401. package/lib/serialization/SerializerMiddleware.js +121 -49
  402. package/lib/serialization/SingleItemMiddleware.js +9 -7
  403. package/lib/serialization/types.js +1 -1
  404. package/lib/sharing/ConsumeSharedModule.js +9 -9
  405. package/lib/sharing/ConsumeSharedPlugin.js +14 -14
  406. package/lib/sharing/ConsumeSharedRuntimeModule.js +11 -8
  407. package/lib/sharing/ProvideSharedModule.js +9 -11
  408. package/lib/sharing/ProvideSharedModuleFactory.js +5 -3
  409. package/lib/sharing/ProvideSharedPlugin.js +15 -10
  410. package/lib/sharing/SharePlugin.js +3 -4
  411. package/lib/sharing/ShareRuntimeModule.js +7 -6
  412. package/lib/sharing/resolveMatchedConfigs.js +27 -13
  413. package/lib/sharing/utils.js +37 -43
  414. package/lib/stats/DefaultStatsFactoryPlugin.js +455 -286
  415. package/lib/stats/DefaultStatsPresetPlugin.js +77 -46
  416. package/lib/stats/DefaultStatsPrinterPlugin.js +583 -419
  417. package/lib/stats/StatsFactory.js +75 -32
  418. package/lib/stats/StatsPrinter.js +71 -51
  419. package/lib/url/URLParserPlugin.js +264 -0
  420. package/lib/util/ArrayHelpers.js +6 -8
  421. package/lib/util/ArrayQueue.js +1 -1
  422. package/lib/util/AsyncQueue.js +11 -10
  423. package/lib/util/Hash.js +37 -5
  424. package/lib/util/IterableHelpers.js +4 -4
  425. package/lib/util/LazyBucketSortedSet.js +46 -27
  426. package/lib/util/LazySet.js +16 -10
  427. package/lib/util/MapHelpers.js +1 -1
  428. package/lib/util/ParallelismFactorCalculator.js +2 -2
  429. package/lib/util/Semaphore.js +3 -3
  430. package/lib/util/SetHelpers.js +6 -6
  431. package/lib/util/SortableSet.js +11 -9
  432. package/lib/util/StackedCacheMap.js +2 -2
  433. package/lib/util/StackedMap.js +3 -3
  434. package/lib/util/StringXor.js +2 -1
  435. package/lib/util/TupleQueue.js +11 -8
  436. package/lib/util/TupleSet.js +44 -19
  437. package/lib/util/URLAbsoluteSpecifier.js +3 -4
  438. package/lib/util/WeakTupleMap.js +56 -42
  439. package/lib/util/binarySearchBounds.js +4 -3
  440. package/lib/util/chainedImports.js +3 -1
  441. package/lib/util/cleverMerge.js +171 -107
  442. package/lib/util/comparators.js +265 -162
  443. package/lib/util/compileBooleanMatcher.js +120 -41
  444. package/lib/util/concatenate.js +20 -16
  445. package/lib/util/conventions.js +73 -74
  446. package/lib/util/create-schema-validation.js +8 -8
  447. package/lib/util/createHash.js +32 -135
  448. package/lib/util/dataURL.js +39 -0
  449. package/lib/util/deprecation.js +119 -116
  450. package/lib/util/deterministicGrouping.js +56 -47
  451. package/lib/util/extractSourceMap.js +319 -0
  452. package/lib/util/extractUrlAndGlobal.js +1 -1
  453. package/lib/util/findGraphRoots.js +19 -9
  454. package/lib/util/fs.js +169 -141
  455. package/lib/util/hash/BatchedHash.js +50 -10
  456. package/lib/util/hash/BulkUpdateHash.js +138 -0
  457. package/lib/util/hash/DebugHash.js +75 -0
  458. package/lib/util/hash/hash-digest.js +216 -0
  459. package/lib/util/hash/md4.js +2 -2
  460. package/lib/util/hash/wasm-hash.js +59 -17
  461. package/lib/util/identifier.js +124 -61
  462. package/lib/util/internalSerializables.js +4 -6
  463. package/lib/util/magicComment.js +9 -5
  464. package/lib/util/makeSerializable.js +2 -2
  465. package/lib/util/memoize.js +5 -2
  466. package/lib/util/objectToMap.js +3 -2
  467. package/lib/util/processAsyncTree.js +5 -5
  468. package/lib/util/propertyAccess.js +1 -1
  469. package/lib/util/propertyName.js +2 -3
  470. package/lib/util/registerExternalSerializer.js +16 -20
  471. package/lib/util/removeBOM.js +25 -0
  472. package/lib/util/runtime.js +72 -56
  473. package/lib/util/semver.js +44 -33
  474. package/lib/util/serialization.js +56 -56
  475. package/lib/util/smartGrouping.js +42 -27
  476. package/lib/util/source.js +5 -4
  477. package/lib/util/traverseDestructuringAssignmentProperties.js +45 -0
  478. package/lib/validateSchema.js +7 -9
  479. package/lib/wasm/EnableWasmLoadingPlugin.js +22 -12
  480. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +9 -5
  481. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +15 -3
  482. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +28 -22
  483. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +47 -57
  484. package/lib/wasm-async/AsyncWebAssemblyParser.js +2 -10
  485. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +8 -4
  486. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +23 -17
  487. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +55 -57
  488. package/lib/wasm-sync/WebAssemblyGenerator.js +56 -41
  489. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +6 -3
  490. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +25 -10
  491. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +11 -12
  492. package/lib/wasm-sync/WebAssemblyParser.js +10 -17
  493. package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
  494. package/lib/web/FetchCompileAsyncWasmPlugin.js +4 -4
  495. package/lib/web/FetchCompileWasmPlugin.js +6 -8
  496. package/lib/web/JsonpChunkLoadingPlugin.js +74 -74
  497. package/lib/web/JsonpChunkLoadingRuntimeModule.js +10 -26
  498. package/lib/web/JsonpTemplatePlugin.js +0 -1
  499. package/lib/webpack.js +107 -87
  500. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +79 -75
  501. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +38 -51
  502. package/lib/webworker/WebWorkerTemplatePlugin.js +1 -0
  503. package/module.d.ts +5 -0
  504. package/package.json +149 -129
  505. package/schemas/WebpackOptions.check.d.ts +1 -1
  506. package/schemas/WebpackOptions.check.js +2 -2
  507. package/schemas/WebpackOptions.json +543 -190
  508. package/schemas/plugins/BannerPlugin.check.d.ts +1 -1
  509. package/schemas/plugins/BannerPlugin.check.js +2 -2
  510. package/schemas/plugins/BannerPlugin.json +4 -0
  511. package/schemas/plugins/DllPlugin.check.d.ts +1 -1
  512. package/schemas/plugins/DllPlugin.check.js +1 -1
  513. package/schemas/plugins/DllReferencePlugin.check.d.ts +1 -1
  514. package/schemas/plugins/DllReferencePlugin.check.js +1 -1
  515. package/schemas/plugins/IgnorePlugin.check.d.ts +1 -1
  516. package/schemas/plugins/IgnorePlugin.check.js +1 -1
  517. package/schemas/plugins/IgnorePlugin.json +1 -1
  518. package/schemas/plugins/LoaderOptionsPlugin.check.d.ts +1 -1
  519. package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
  520. package/schemas/plugins/{HashedModuleIdsPlugin.check.d.ts → ManifestPlugin.check.d.ts} +2 -2
  521. package/schemas/plugins/ManifestPlugin.check.js +6 -0
  522. package/schemas/plugins/ManifestPlugin.json +98 -0
  523. package/schemas/plugins/ProgressPlugin.check.d.ts +1 -1
  524. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  525. package/schemas/plugins/ProgressPlugin.json +1 -1
  526. package/schemas/plugins/SourceMapDevToolPlugin.check.d.ts +1 -1
  527. package/schemas/plugins/SourceMapDevToolPlugin.check.js +2 -2
  528. package/schemas/plugins/SourceMapDevToolPlugin.json +23 -6
  529. package/schemas/plugins/WatchIgnorePlugin.check.d.ts +1 -1
  530. package/schemas/plugins/WatchIgnorePlugin.check.js +1 -1
  531. package/schemas/plugins/asset/AssetGeneratorOptions.check.d.ts +1 -1
  532. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  533. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.d.ts +1 -1
  534. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +1 -1
  535. package/schemas/plugins/asset/AssetParserOptions.check.d.ts +1 -1
  536. package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
  537. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.d.ts +1 -1
  538. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  539. package/schemas/plugins/container/ContainerPlugin.check.d.ts +1 -1
  540. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  541. package/schemas/plugins/container/ContainerReferencePlugin.check.d.ts +1 -1
  542. package/schemas/plugins/container/ContainerReferencePlugin.check.js +2 -2
  543. package/schemas/plugins/container/ContainerReferencePlugin.json +4 -1
  544. package/schemas/plugins/container/ExternalsType.check.d.ts +1 -1
  545. package/schemas/plugins/container/ExternalsType.check.js +2 -2
  546. package/schemas/plugins/container/ModuleFederationPlugin.check.d.ts +1 -1
  547. package/schemas/plugins/container/ModuleFederationPlugin.check.js +2 -2
  548. package/schemas/plugins/container/ModuleFederationPlugin.json +4 -1
  549. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +1 -1
  550. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  551. package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +1 -1
  552. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +2 -2
  553. package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +1 -1
  554. package/schemas/plugins/css/CssModuleParserOptions.check.js +2 -2
  555. package/schemas/plugins/css/CssParserOptions.check.d.ts +1 -1
  556. package/schemas/plugins/css/CssParserOptions.check.js +2 -2
  557. package/schemas/plugins/debug/ProfilingPlugin.check.d.ts +1 -1
  558. package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
  559. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.d.ts +7 -0
  560. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +6 -0
  561. package/schemas/plugins/{HashedModuleIdsPlugin.json → ids/HashedModuleIdsPlugin.json} +15 -2
  562. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.d.ts +1 -1
  563. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +1 -1
  564. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.d.ts +1 -1
  565. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +1 -1
  566. package/schemas/plugins/{css/CssGlobalParserOptions.check.d.ts → json/JsonModulesPluginGenerator.check.d.ts} +1 -1
  567. package/schemas/plugins/json/JsonModulesPluginGenerator.check.js +6 -0
  568. package/schemas/plugins/json/JsonModulesPluginGenerator.json +3 -0
  569. package/schemas/plugins/{css/CssGlobalGeneratorOptions.check.d.ts → json/JsonModulesPluginParser.check.d.ts} +1 -1
  570. package/schemas/plugins/json/JsonModulesPluginParser.check.js +6 -0
  571. package/schemas/plugins/json/JsonModulesPluginParser.json +3 -0
  572. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.d.ts +1 -1
  573. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
  574. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.d.ts +1 -1
  575. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
  576. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.d.ts +1 -1
  577. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +1 -1
  578. package/schemas/plugins/optimize/MinChunkSizePlugin.check.d.ts +1 -1
  579. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
  580. package/schemas/plugins/schemes/HttpUriPlugin.check.d.ts +1 -1
  581. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  582. package/schemas/plugins/schemes/VirtualUrlPlugin.check.d.ts +7 -0
  583. package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +6 -0
  584. package/schemas/plugins/schemes/VirtualUrlPlugin.json +77 -0
  585. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.d.ts +1 -1
  586. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +1 -1
  587. package/schemas/plugins/sharing/ProvideSharedPlugin.check.d.ts +1 -1
  588. package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +1 -1
  589. package/schemas/plugins/sharing/SharePlugin.check.d.ts +1 -1
  590. package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
  591. package/types.d.ts +5115 -1863
  592. package/SECURITY.md +0 -9
  593. package/lib/ModuleSourceTypesConstants.js +0 -112
  594. package/lib/dependencies/CssLocalIdentifierDependency.js +0 -250
  595. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +0 -111
  596. package/lib/library/ModernModuleLibraryPlugin.js +0 -144
  597. package/schemas/plugins/HashedModuleIdsPlugin.check.js +0 -6
  598. package/schemas/plugins/JsonModulesPluginParser.check.d.ts +0 -7
  599. package/schemas/plugins/JsonModulesPluginParser.check.js +0 -6
  600. package/schemas/plugins/JsonModulesPluginParser.json +0 -12
  601. package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +0 -7
  602. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +0 -6
  603. package/schemas/plugins/css/CssAutoGeneratorOptions.json +0 -3
  604. package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +0 -7
  605. package/schemas/plugins/css/CssAutoParserOptions.check.js +0 -6
  606. package/schemas/plugins/css/CssAutoParserOptions.json +0 -3
  607. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +0 -6
  608. package/schemas/plugins/css/CssGlobalGeneratorOptions.json +0 -3
  609. package/schemas/plugins/css/CssGlobalParserOptions.check.js +0 -6
  610. package/schemas/plugins/css/CssGlobalParserOptions.json +0 -3
@@ -5,17 +5,17 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const util = require("util");
8
9
  const asyncLib = require("neo-async");
9
10
  const {
11
+ AsyncParallelHook,
12
+ AsyncSeriesBailHook,
13
+ AsyncSeriesHook,
10
14
  HookMap,
11
- SyncHook,
12
15
  SyncBailHook,
13
- SyncWaterfallHook,
14
- AsyncSeriesHook,
15
- AsyncSeriesBailHook,
16
- AsyncParallelHook
16
+ SyncHook,
17
+ SyncWaterfallHook
17
18
  } = require("tapable");
18
- const util = require("util");
19
19
  const { CachedSource } = require("webpack-sources");
20
20
  const { MultiItemCache } = require("./CacheFacade");
21
21
  const Chunk = require("./Chunk");
@@ -32,7 +32,8 @@ const ErrorHelpers = require("./ErrorHelpers");
32
32
  const FileSystemInfo = require("./FileSystemInfo");
33
33
  const {
34
34
  connectChunkGroupAndChunk,
35
- connectChunkGroupParentAndChild
35
+ connectChunkGroupParentAndChild,
36
+ connectEntrypointAndDependOn
36
37
  } = require("./GraphHelpers");
37
38
  const {
38
39
  makeWebpackError,
@@ -56,7 +57,7 @@ const Stats = require("./Stats");
56
57
  const WebpackError = require("./WebpackError");
57
58
  const buildChunkGraph = require("./buildChunkGraph");
58
59
  const BuildCycleError = require("./errors/BuildCycleError");
59
- const { Logger, LogType } = require("./logging/Logger");
60
+ const { LogType, Logger } = require("./logging/Logger");
60
61
  const StatsFactory = require("./stats/StatsFactory");
61
62
  const StatsPrinter = require("./stats/StatsPrinter");
62
63
  const { equals: arrayEquals } = require("./util/ArrayHelpers");
@@ -66,53 +67,63 @@ const { getOrInsert } = require("./util/MapHelpers");
66
67
  const WeakTupleMap = require("./util/WeakTupleMap");
67
68
  const { cachedCleverMerge } = require("./util/cleverMerge");
68
69
  const {
70
+ compareIds,
69
71
  compareLocations,
70
- concatComparators,
72
+ compareModulesByIdentifier,
71
73
  compareSelect,
72
- compareIds,
73
74
  compareStringsNumeric,
74
- compareModulesByIdentifier
75
+ concatComparators
75
76
  } = require("./util/comparators");
76
77
  const createHash = require("./util/createHash");
77
78
  const {
78
79
  arrayToSetDeprecation,
79
- soonFrozenObjectDeprecation,
80
- createFakeHook
80
+ createFakeHook,
81
+ soonFrozenObjectDeprecation
81
82
  } = require("./util/deprecation");
82
83
  const processAsyncTree = require("./util/processAsyncTree");
83
84
  const { getRuntimeKey } = require("./util/runtime");
84
85
  const { isSourceEqual } = require("./util/source");
85
86
 
86
- /** @template T @typedef {import("tapable").AsArray<T>} AsArray<T> */
87
87
  /** @typedef {import("webpack-sources").Source} Source */
88
- /** @typedef {import("../declarations/WebpackOptions").EntryDescriptionNormalized} EntryDescription */
89
88
  /** @typedef {import("../declarations/WebpackOptions").OutputNormalized} OutputOptions */
89
+ /** @typedef {import("../declarations/WebpackOptions").HashFunction} HashFunction */
90
+ /** @typedef {import("../declarations/WebpackOptions").HashDigest} HashDigest */
91
+ /** @typedef {import("../declarations/WebpackOptions").HashDigestLength} HashDigestLength */
90
92
  /** @typedef {import("../declarations/WebpackOptions").StatsOptions} StatsOptions */
91
- /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
92
- /** @typedef {import("../declarations/WebpackOptions").WebpackPluginFunction} WebpackPluginFunction */
93
- /** @typedef {import("../declarations/WebpackOptions").WebpackPluginInstance} WebpackPluginInstance */
93
+ /** @typedef {import("../declarations/WebpackOptions").Plugins} Plugins */
94
+ /** @typedef {import("./config/defaults").WebpackOptionsNormalizedWithDefaults} WebpackOptions */
95
+ /** @typedef {import("./config/defaults").OutputNormalizedWithDefaults} OutputOptionsWithDefaults */
94
96
  /** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
95
97
  /** @typedef {import("./Cache")} Cache */
96
98
  /** @typedef {import("./CacheFacade")} CacheFacade */
99
+ /** @typedef {import("./Chunk").ChunkName} ChunkName */
97
100
  /** @typedef {import("./Chunk").ChunkId} ChunkId */
98
101
  /** @typedef {import("./ChunkGroup").ChunkGroupOptions} ChunkGroupOptions */
99
102
  /** @typedef {import("./Compiler")} Compiler */
100
103
  /** @typedef {import("./Compiler").CompilationParams} CompilationParams */
104
+ /** @typedef {import("./Compiler").MemCache} MemCache */
105
+ /** @typedef {import("./Compiler").WeakReferences} WeakReferences */
101
106
  /** @typedef {import("./Compiler").ModuleMemCachesItem} ModuleMemCachesItem */
107
+ /** @typedef {import("./Compiler").Records} Records */
102
108
  /** @typedef {import("./DependenciesBlock")} DependenciesBlock */
103
109
  /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
104
- /** @typedef {import("./Dependency").ReferencedExport} ReferencedExport */
105
- /** @typedef {import("./DependencyTemplate")} DependencyTemplate */
110
+ /** @typedef {import("./Dependency").ReferencedExports} ReferencedExports */
106
111
  /** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
112
+ /** @typedef {import("./Module").NameForCondition} NameForCondition */
107
113
  /** @typedef {import("./Module").BuildInfo} BuildInfo */
108
114
  /** @typedef {import("./Module").ValueCacheVersions} ValueCacheVersions */
115
+ /** @typedef {import("./Module").RuntimeRequirements} RuntimeRequirements */
109
116
  /** @typedef {import("./NormalModule").NormalModuleCompilationHooks} NormalModuleCompilationHooks */
117
+ /** @typedef {import("./Module").FactoryMeta} FactoryMeta */
110
118
  /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
111
119
  /** @typedef {import("./ModuleFactory")} ModuleFactory */
120
+ /** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
112
121
  /** @typedef {import("./ChunkGraph").ModuleId} ModuleId */
113
122
  /** @typedef {import("./ModuleGraphConnection")} ModuleGraphConnection */
114
123
  /** @typedef {import("./ModuleFactory").ModuleFactoryCreateDataContextInfo} ModuleFactoryCreateDataContextInfo */
115
124
  /** @typedef {import("./ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */
125
+ /** @typedef {import("./NormalModule").ParserOptions} ParserOptions */
126
+ /** @typedef {import("./NormalModule").GeneratorOptions} GeneratorOptions */
116
127
  /** @typedef {import("./RequestShortener")} RequestShortener */
117
128
  /** @typedef {import("./RuntimeModule")} RuntimeModule */
118
129
  /** @typedef {import("./Template").RenderManifestEntry} RenderManifestEntry */
@@ -122,14 +133,19 @@ const { isSourceEqual } = require("./util/source");
122
133
  /** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsModule} StatsModule */
123
134
  /** @typedef {import("./TemplatedPathPlugin").TemplatePath} TemplatePath */
124
135
  /** @typedef {import("./util/Hash")} Hash */
125
- /** @typedef {import("./util/createHash").Algorithm} Algorithm */
136
+
137
+ /**
138
+ * @template T
139
+ * @typedef {import("tapable").AsArray<T>} AsArray<T>
140
+ */
141
+
126
142
  /**
127
143
  * @template T
128
144
  * @typedef {import("./util/deprecation").FakeHook<T>} FakeHook<T>
129
145
  */
130
146
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
131
- /** @typedef {WeakMap<Dependency, Module>} References */
132
147
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
148
+
133
149
  /**
134
150
  * @callback Callback
135
151
  * @param {(WebpackError | null)=} err
@@ -138,39 +154,33 @@ const { isSourceEqual } = require("./util/source");
138
154
 
139
155
  /**
140
156
  * @callback ModuleCallback
141
- * @param {(WebpackError | null)=} err
142
- * @param {(Module | null)=} result
157
+ * @param {WebpackError | null=} err
158
+ * @param {Module | null=} result
143
159
  * @returns {void}
144
160
  */
145
161
 
146
162
  /**
147
163
  * @callback ModuleFactoryResultCallback
148
- * @param {(WebpackError | null)=} err
149
- * @param {ModuleFactoryResult=} result
164
+ * @param {WebpackError | null=} err
165
+ * @param {ModuleFactoryResult | null=} result
150
166
  * @returns {void}
151
167
  */
152
168
 
153
169
  /**
154
- * @callback ModuleOrFactoryResultCallback
155
- * @param {(WebpackError | null)=} err
156
- * @param {Module | ModuleFactoryResult=} result
170
+ * @callback ModuleOrModuleFactoryResultCallback
171
+ * @param {WebpackError | null=} err
172
+ * @param {Module | ModuleFactoryResult | null=} result
157
173
  * @returns {void}
158
174
  */
159
175
 
160
176
  /**
161
177
  * @callback ExecuteModuleCallback
162
- * @param {WebpackError | null} err
163
- * @param {ExecuteModuleResult=} result
178
+ * @param {WebpackError | null=} err
179
+ * @param {ExecuteModuleResult | null=} result
164
180
  * @returns {void}
165
181
  */
166
182
 
167
- /**
168
- * @callback DepBlockVarDependenciesCallback
169
- * @param {Dependency} dependency
170
- * @returns {any}
171
- */
172
-
173
- /** @typedef {new (...args: any[]) => Dependency} DepConstructor */
183
+ /** @typedef {new (...args: EXPECTED_ANY[]) => Dependency} DependencyConstructor */
174
184
 
175
185
  /** @typedef {Record<string, Source>} CompilationAssets */
176
186
 
@@ -187,14 +197,16 @@ const { isSourceEqual } = require("./util/source");
187
197
  * @property {AsyncDependenciesBlock[]} blocks
188
198
  */
189
199
 
200
+ /** @typedef {Set<Chunk>} Chunks */
201
+
190
202
  /**
191
203
  * @typedef {object} ChunkPathData
192
- * @property {string|number} id
204
+ * @property {string | number} id
193
205
  * @property {string=} name
194
206
  * @property {string} hash
195
- * @property {function(number): string=} hashWithLength
207
+ * @property {HashWithLengthFunction=} hashWithLength
196
208
  * @property {(Record<string, string>)=} contentHash
197
- * @property {(Record<string, (length: number) => string>)=} contentHashWithLength
209
+ * @property {(Record<string, HashWithLengthFunction>)=} contentHashWithLength
198
210
  */
199
211
 
200
212
  /**
@@ -216,34 +228,53 @@ const { isSourceEqual } = require("./util/source");
216
228
  * @property {EntryOptions=} entryOptions
217
229
  */
218
230
 
231
+ /** @typedef {LazySet<string>} FileSystemDependencies */
232
+
233
+ /** @typedef {EXPECTED_ANY} ExecuteModuleExports */
234
+
219
235
  /**
220
236
  * @typedef {object} ExecuteModuleResult
221
- * @property {any} exports
237
+ * @property {ExecuteModuleExports} exports
222
238
  * @property {boolean} cacheable
223
- * @property {Map<string, { source: Source, info: AssetInfo }>} assets
224
- * @property {LazySet<string>} fileDependencies
225
- * @property {LazySet<string>} contextDependencies
226
- * @property {LazySet<string>} missingDependencies
227
- * @property {LazySet<string>} buildDependencies
239
+ * @property {ExecuteModuleAssets} assets
240
+ * @property {FileSystemDependencies} fileDependencies
241
+ * @property {FileSystemDependencies} contextDependencies
242
+ * @property {FileSystemDependencies} missingDependencies
243
+ * @property {FileSystemDependencies} buildDependencies
244
+ */
245
+
246
+ /**
247
+ * @typedef {object} ExecuteModuleObject
248
+ * @property {string=} id module id
249
+ * @property {ExecuteModuleExports} exports exports
250
+ * @property {boolean} loaded is loaded
251
+ * @property {Error=} error error
228
252
  */
229
253
 
230
254
  /**
231
- * @typedef {{ id: string, exports: any, loaded: boolean }} ModuleObject
232
- *
233
- * /**
234
255
  * @typedef {object} ExecuteModuleArgument
235
256
  * @property {Module} module
236
- * @property {ModuleObject=} moduleObject
237
- * @property {any} preparedInfo
257
+ * @property {ExecuteModuleObject=} moduleObject
238
258
  * @property {CodeGenerationResult} codeGenerationResult
239
259
  */
240
260
 
261
+ /** @typedef {((id: string) => ExecuteModuleExports) & { i?: ((options: ExecuteOptions) => void)[], c?: Record<string, ExecuteModuleObject> }} WebpackRequire */
262
+
263
+ /**
264
+ * @typedef {object} ExecuteOptions
265
+ * @property {string=} id module id
266
+ * @property {ExecuteModuleObject} module module
267
+ * @property {WebpackRequire} require require function
268
+ */
269
+
270
+ /** @typedef {Map<string, { source: Source, info: AssetInfo | undefined }>} ExecuteModuleAssets */
271
+
241
272
  /**
242
273
  * @typedef {object} ExecuteModuleContext
243
- * @property {Map<string, { source: Source, info: AssetInfo }>} assets
274
+ * @property {ExecuteModuleAssets} assets
244
275
  * @property {Chunk} chunk
245
276
  * @property {ChunkGraph} chunkGraph
246
- * @property {function(string): any=} __webpack_require__
277
+ * @property {WebpackRequire=} __webpack_require__
247
278
  */
248
279
 
249
280
  /**
@@ -256,7 +287,7 @@ const { isSourceEqual } = require("./util/source");
256
287
  /**
257
288
  * @typedef {object} LogEntry
258
289
  * @property {string} type
259
- * @property {any[]=} args
290
+ * @property {EXPECTED_ANY[]=} args
260
291
  * @property {number} time
261
292
  * @property {string[]=} trace
262
293
  */
@@ -274,10 +305,11 @@ const { isSourceEqual } = require("./util/source");
274
305
  * @property {boolean=} development true, when asset is only used for development and doesn't count towards user-facing assets
275
306
  * @property {boolean=} hotModuleReplacement true, when asset ships data for updating an existing application (HMR)
276
307
  * @property {boolean=} javascriptModule true, when asset is javascript and an ESM
277
- * @property {Record<string, string | string[]>=} related object of pointers to other assets, keyed by type of relation (only points from parent to child)
308
+ * @property {boolean=} manifest true, when file is a manifest
309
+ * @property {Record<string, null | string | string[]>=} related object of pointers to other assets, keyed by type of relation (only points from parent to child)
278
310
  */
279
311
 
280
- /** @typedef {KnownAssetInfo & Record<string, any>} AssetInfo */
312
+ /** @typedef {KnownAssetInfo & Record<string, EXPECTED_ANY>} AssetInfo */
281
313
 
282
314
  /** @typedef {{ path: string, info: AssetInfo }} InterpolatedPathAndAssetInfo */
283
315
 
@@ -288,40 +320,47 @@ const { isSourceEqual } = require("./util/source");
288
320
  * @property {AssetInfo} info info about the asset
289
321
  */
290
322
 
323
+ /** @typedef {(length: number) => string} HashWithLengthFunction */
324
+
291
325
  /**
292
326
  * @typedef {object} ModulePathData
293
- * @property {string|number} id
327
+ * @property {string | number} id
294
328
  * @property {string} hash
295
- * @property {function(number): string=} hashWithLength
329
+ * @property {HashWithLengthFunction=} hashWithLength
296
330
  */
297
331
 
332
+ /** @typedef {(id: string | number) => string | number} PrepareIdFunction */
333
+
298
334
  /**
299
335
  * @typedef {object} PathData
300
336
  * @property {ChunkGraph=} chunkGraph
301
337
  * @property {string=} hash
302
- * @property {function(number): string=} hashWithLength
303
- * @property {(Chunk|ChunkPathData)=} chunk
304
- * @property {(Module|ModulePathData)=} module
338
+ * @property {HashWithLengthFunction=} hashWithLength
339
+ * @property {(Chunk | ChunkPathData)=} chunk
340
+ * @property {(Module | ModulePathData)=} module
305
341
  * @property {RuntimeSpec=} runtime
306
342
  * @property {string=} filename
307
343
  * @property {string=} basename
308
344
  * @property {string=} query
309
345
  * @property {string=} contentHashType
310
346
  * @property {string=} contentHash
311
- * @property {function(number): string=} contentHashWithLength
347
+ * @property {HashWithLengthFunction=} contentHashWithLength
312
348
  * @property {boolean=} noChunkHash
313
349
  * @property {string=} url
350
+ * @property {PrepareIdFunction=} prepareId
314
351
  */
315
352
 
353
+ /** @typedef {"module" | "chunk" | "root-of-chunk" | "nested"} ExcludeModulesType */
354
+
316
355
  /**
317
356
  * @typedef {object} KnownNormalizedStatsOptions
318
357
  * @property {string} context
319
358
  * @property {RequestShortener} requestShortener
320
- * @property {string} chunksSort
321
- * @property {string} modulesSort
322
- * @property {string} chunkModulesSort
323
- * @property {string} nestedModulesSort
324
- * @property {string} assetsSort
359
+ * @property {string | false} chunksSort
360
+ * @property {string | false} modulesSort
361
+ * @property {string | false} chunkModulesSort
362
+ * @property {string | false} nestedModulesSort
363
+ * @property {string | false} assetsSort
325
364
  * @property {boolean} ids
326
365
  * @property {boolean} cachedAssets
327
366
  * @property {boolean} groupAssetsByEmitStatus
@@ -329,7 +368,7 @@ const { isSourceEqual } = require("./util/source");
329
368
  * @property {boolean} groupAssetsByExtension
330
369
  * @property {number} assetsSpace
331
370
  * @property {((value: string, asset: StatsAsset) => boolean)[]} excludeAssets
332
- * @property {((name: string, module: StatsModule, type: "module" | "chunk" | "root-of-chunk" | "nested") => boolean)[]} excludeModules
371
+ * @property {((name: string, module: StatsModule, type: ExcludeModulesType) => boolean)[]} excludeModules
333
372
  * @property {((warning: StatsError, textValue: string) => boolean)[]} warningsFilter
334
373
  * @property {boolean} cachedModules
335
374
  * @property {boolean} orphanModules
@@ -349,22 +388,24 @@ const { isSourceEqual } = require("./util/source");
349
388
  * @property {number} modulesSpace
350
389
  * @property {number} chunkModulesSpace
351
390
  * @property {number} nestedModulesSpace
352
- * @property {false|"none"|"error"|"warn"|"info"|"log"|"verbose"} logging
391
+ * @property {false | "none" | "error" | "warn" | "info" | "log" | "verbose"} logging
353
392
  * @property {((value: string) => boolean)[]} loggingDebug
354
393
  * @property {boolean} loggingTrace
355
- * @property {any} _env
394
+ * @property {EXPECTED_ANY} _env
356
395
  */
357
396
 
358
- /** @typedef {KnownNormalizedStatsOptions & Omit<StatsOptions, keyof KnownNormalizedStatsOptions> & Record<string, any>} NormalizedStatsOptions */
397
+ /** @typedef {KnownNormalizedStatsOptions & Omit<StatsOptions, keyof KnownNormalizedStatsOptions> & Record<string, EXPECTED_ANY>} NormalizedStatsOptions */
359
398
 
360
399
  /**
361
400
  * @typedef {object} KnownCreateStatsOptionsContext
362
401
  * @property {boolean=} forToString
363
402
  */
364
403
 
365
- /** @typedef {Record<string, any> & KnownCreateStatsOptionsContext} CreateStatsOptionsContext */
404
+ /** @typedef {KnownCreateStatsOptionsContext & Record<string, EXPECTED_ANY>} CreateStatsOptionsContext */
405
+
406
+ /** @typedef {{ module: Module, hash: string, runtime: RuntimeSpec, runtimes: RuntimeSpec[]}} CodeGenerationJob */
366
407
 
367
- /** @typedef {{module: Module, hash: string, runtime: RuntimeSpec, runtimes: RuntimeSpec[]}[]} CodeGenerationJobs */
408
+ /** @typedef {CodeGenerationJob[]} CodeGenerationJobs */
368
409
 
369
410
  /** @typedef {{javascript: ModuleTemplate}} ModuleTemplates */
370
411
 
@@ -381,7 +422,7 @@ const deprecatedNormalModuleLoaderHook = util.deprecate(
381
422
  * @param {Compilation} compilation compilation
382
423
  * @returns {NormalModuleCompilationHooks["loader"]} hooks
383
424
  */
384
- compilation =>
425
+ (compilation) =>
385
426
  require("./NormalModule").getCompilationHooks(compilation).loader,
386
427
  "Compilation.hooks.normalModuleLoader was moved to NormalModule.getCompilationHooks(compilation).loader",
387
428
  "DEP_WEBPACK_COMPILATION_NORMAL_MODULE_LOADER_HOOK"
@@ -391,7 +432,7 @@ const deprecatedNormalModuleLoaderHook = util.deprecate(
391
432
  /**
392
433
  * @param {ModuleTemplates | undefined} moduleTemplates module templates
393
434
  */
394
- const defineRemovedModuleTemplates = moduleTemplates => {
435
+ const defineRemovedModuleTemplates = (moduleTemplates) => {
395
436
  Object.defineProperties(moduleTemplates, {
396
437
  asset: {
397
438
  enumerable: false,
@@ -415,30 +456,50 @@ const defineRemovedModuleTemplates = moduleTemplates => {
415
456
  moduleTemplates = undefined;
416
457
  };
417
458
 
418
- const byId = compareSelect(c => c.id, compareIds);
459
+ const byId = compareSelect((c) => c.id, compareIds);
419
460
 
420
461
  const byNameOrHash = concatComparators(
421
- compareSelect(c => c.name, compareIds),
422
- compareSelect(c => c.fullHash, compareIds)
462
+ compareSelect((c) => c.name, compareIds),
463
+ compareSelect((c) => c.fullHash, compareIds)
423
464
  );
424
465
 
425
- const byMessage = compareSelect(err => `${err.message}`, compareStringsNumeric);
466
+ const byMessage = compareSelect(
467
+ (err) => `${err.message}`,
468
+ compareStringsNumeric
469
+ );
426
470
 
427
471
  const byModule = compareSelect(
428
- err => (err.module && err.module.identifier()) || "",
472
+ (err) => (err.module && err.module.identifier()) || "",
429
473
  compareStringsNumeric
430
474
  );
431
475
 
432
- const byLocation = compareSelect(err => err.loc, compareLocations);
476
+ const byLocation = compareSelect((err) => err.loc, compareLocations);
433
477
 
434
478
  const compareErrors = concatComparators(byModule, byLocation, byMessage);
435
479
 
436
- /** @type {WeakMap<Dependency, Module & { restoreFromUnsafeCache: Function } | null>} */
480
+ /**
481
+ * @typedef {object} KnownUnsafeCacheData
482
+ * @property {FactoryMeta=} factoryMeta factory meta
483
+ * @property {ResolveOptions=} resolveOptions resolve options
484
+ * @property {ParserOptions=} parserOptions
485
+ * @property {GeneratorOptions=} generatorOptions
486
+ */
487
+
488
+ /** @typedef {KnownUnsafeCacheData & Record<string, EXPECTED_ANY>} UnsafeCacheData */
489
+
490
+ /**
491
+ * @typedef {Module & { restoreFromUnsafeCache?: (unsafeCacheData: UnsafeCacheData, moduleFactory: ModuleFactory, compilationParams: CompilationParams) => void }} ModuleWithRestoreFromUnsafeCache
492
+ */
493
+
494
+ /** @type {WeakMap<Dependency, ModuleWithRestoreFromUnsafeCache | null>} */
437
495
  const unsafeCacheDependencies = new WeakMap();
438
496
 
439
- /** @type {WeakMap<Module & { restoreFromUnsafeCache: Function }, object>} */
497
+ /** @type {WeakMap<ModuleWithRestoreFromUnsafeCache, UnsafeCacheData>} */
440
498
  const unsafeCacheData = new WeakMap();
441
499
 
500
+ /** @typedef {{ id: ModuleId, modules?: Map<Module, ModuleId>, blocks?: (ChunkId | null)[] }} References */
501
+ /** @typedef {Map<Module, WeakTupleMap<EXPECTED_ANY[], EXPECTED_ANY>>} ModuleMemCaches */
502
+
442
503
  class Compilation {
443
504
  /**
444
505
  * Creates an instance of Compilation.
@@ -449,7 +510,7 @@ class Compilation {
449
510
  this._backCompat = compiler._backCompat;
450
511
 
451
512
  const getNormalModuleLoader = () => deprecatedNormalModuleLoaderHook(this);
452
- /** @typedef {{ additionalAssets?: true | Function }} ProcessAssetsAdditionalOptions */
513
+ /** @typedef {{ additionalAssets?: boolean | ((assets: CompilationAssets) => void) }} ProcessAssetsAdditionalOptions */
453
514
  /** @type {AsyncSeriesHook<[CompilationAssets], ProcessAssetsAdditionalOptions>} */
454
515
  const processAssetsHook = new AsyncSeriesHook(["assets"]);
455
516
 
@@ -458,7 +519,7 @@ class Compilation {
458
519
  * @param {CompilationAssets} assets assets
459
520
  * @returns {CompilationAssets} new assets
460
521
  */
461
- const popNewAssets = assets => {
522
+ const popNewAssets = (assets) => {
462
523
  let newAssets;
463
524
  for (const file of Object.keys(assets)) {
464
525
  if (savedAssets.has(file)) continue;
@@ -475,31 +536,59 @@ class Compilation {
475
536
  call: () => {
476
537
  savedAssets = new Set(Object.keys(this.assets));
477
538
  },
478
- register: tap => {
539
+ register: (tap) => {
479
540
  const { type, name } = tap;
480
541
  const { fn, additionalAssets, ...remainingTap } = tap;
481
542
  const additionalAssetsFn =
482
543
  additionalAssets === true ? fn : additionalAssets;
544
+ /** @typedef {WeakSet<CompilationAssets>} ProcessedAssets */
545
+
546
+ /** @type {ProcessedAssets | undefined} */
483
547
  const processedAssets = additionalAssetsFn ? new WeakSet() : undefined;
548
+ /**
549
+ * @param {CompilationAssets} assets to be processed by additionalAssetsFn
550
+ * @returns {CompilationAssets} available assets
551
+ */
552
+ const getAvailableAssets = (assets) => {
553
+ /** @type {CompilationAssets} */
554
+ const availableAssets = {};
555
+ for (const file of Object.keys(assets)) {
556
+ // https://github.com/webpack-contrib/compression-webpack-plugin/issues/390
557
+ if (this.assets[file]) {
558
+ availableAssets[file] = assets[file];
559
+ }
560
+ }
561
+ return availableAssets;
562
+ };
484
563
  switch (type) {
485
564
  case "sync":
486
565
  if (additionalAssetsFn) {
487
- this.hooks.processAdditionalAssets.tap(name, assets => {
488
- if (processedAssets.has(this.assets))
489
- additionalAssetsFn(assets);
566
+ this.hooks.processAdditionalAssets.tap(name, (assets) => {
567
+ if (
568
+ /** @type {ProcessedAssets} */
569
+ (processedAssets).has(this.assets)
570
+ ) {
571
+ additionalAssetsFn(getAvailableAssets(assets));
572
+ }
490
573
  });
491
574
  }
492
575
  return {
493
576
  ...remainingTap,
494
577
  type: "async",
578
+ /**
579
+ * @param {CompilationAssets} assets assets
580
+ * @param {(err?: Error | null, result?: void) => void} callback callback
581
+ * @returns {void}
582
+ */
495
583
  fn: (assets, callback) => {
496
584
  try {
497
585
  fn(assets);
498
586
  } catch (err) {
499
- return callback(err);
587
+ return callback(/** @type {Error} */ (err));
500
588
  }
501
- if (processedAssets !== undefined)
589
+ if (processedAssets !== undefined) {
502
590
  processedAssets.add(this.assets);
591
+ }
503
592
  const newAssets = popNewAssets(assets);
504
593
  if (newAssets !== undefined) {
505
594
  this.hooks.processAdditionalAssets.callAsync(
@@ -516,47 +605,76 @@ class Compilation {
516
605
  this.hooks.processAdditionalAssets.tapAsync(
517
606
  name,
518
607
  (assets, callback) => {
519
- if (processedAssets.has(this.assets))
520
- return additionalAssetsFn(assets, callback);
608
+ if (
609
+ /** @type {ProcessedAssets} */
610
+ (processedAssets).has(this.assets)
611
+ ) {
612
+ return additionalAssetsFn(
613
+ getAvailableAssets(assets),
614
+ callback
615
+ );
616
+ }
521
617
  callback();
522
618
  }
523
619
  );
524
620
  }
525
621
  return {
526
622
  ...remainingTap,
623
+ /**
624
+ * @param {CompilationAssets} assets assets
625
+ * @param {(err?: Error | null, result?: void) => void} callback callback
626
+ * @returns {void}
627
+ */
527
628
  fn: (assets, callback) => {
528
- fn(assets, err => {
529
- if (err) return callback(err);
530
- if (processedAssets !== undefined)
531
- processedAssets.add(this.assets);
532
- const newAssets = popNewAssets(assets);
533
- if (newAssets !== undefined) {
534
- this.hooks.processAdditionalAssets.callAsync(
535
- newAssets,
536
- callback
537
- );
538
- return;
629
+ fn(
630
+ assets,
631
+ /**
632
+ * @param {Error} err err
633
+ * @returns {void}
634
+ */
635
+ (err) => {
636
+ if (err) return callback(err);
637
+ if (processedAssets !== undefined) {
638
+ processedAssets.add(this.assets);
639
+ }
640
+ const newAssets = popNewAssets(assets);
641
+ if (newAssets !== undefined) {
642
+ this.hooks.processAdditionalAssets.callAsync(
643
+ newAssets,
644
+ callback
645
+ );
646
+ return;
647
+ }
648
+ callback();
539
649
  }
540
- callback();
541
- });
650
+ );
542
651
  }
543
652
  };
544
653
  case "promise":
545
654
  if (additionalAssetsFn) {
546
- this.hooks.processAdditionalAssets.tapPromise(name, assets => {
547
- if (processedAssets.has(this.assets))
548
- return additionalAssetsFn(assets);
655
+ this.hooks.processAdditionalAssets.tapPromise(name, (assets) => {
656
+ if (
657
+ /** @type {ProcessedAssets} */
658
+ (processedAssets).has(this.assets)
659
+ ) {
660
+ return additionalAssetsFn(getAvailableAssets(assets));
661
+ }
549
662
  return Promise.resolve();
550
663
  });
551
664
  }
552
665
  return {
553
666
  ...remainingTap,
554
- fn: assets => {
667
+ /**
668
+ * @param {CompilationAssets} assets assets
669
+ * @returns {Promise<CompilationAssets>} result
670
+ */
671
+ fn: (assets) => {
555
672
  const p = fn(assets);
556
673
  if (!p || !p.then) return p;
557
674
  return p.then(() => {
558
- if (processedAssets !== undefined)
675
+ if (processedAssets !== undefined) {
559
676
  processedAssets.add(this.assets);
677
+ }
560
678
  const newAssets = popNewAssets(assets);
561
679
  if (newAssets !== undefined) {
562
680
  return this.hooks.processAdditionalAssets.promise(
@@ -577,9 +695,9 @@ class Compilation {
577
695
  * @template T
578
696
  * @param {string} name name of the hook
579
697
  * @param {number} stage new stage
580
- * @param {function(): AsArray<T>} getArgs get old hook function args
698
+ * @param {() => AsArray<T>} getArgs get old hook function args
581
699
  * @param {string=} code deprecation code (not deprecated when unset)
582
- * @returns {FakeHook<Pick<AsyncSeriesHook<T>, "tap" | "tapAsync" | "tapPromise" | "name">>} fake hook which redirects
700
+ * @returns {FakeHook<Pick<AsyncSeriesHook<T>, "tap" | "tapAsync" | "tapPromise" | "name">> | undefined} fake hook which redirects
583
701
  */
584
702
  const createProcessAssetsHook = (name, stage, getArgs, code) => {
585
703
  if (!this._backCompat && code) return;
@@ -587,10 +705,15 @@ class Compilation {
587
705
  * @param {string} reason reason
588
706
  * @returns {string} error message
589
707
  */
590
- const errorMessage =
591
- reason => `Can't automatically convert plugin using Compilation.hooks.${name} to Compilation.hooks.processAssets because ${reason}.
708
+ const errorMessage = (
709
+ reason
710
+ ) => `Can't automatically convert plugin using Compilation.hooks.${name} to Compilation.hooks.processAssets because ${reason}.
592
711
  BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a single Compilation.hooks.processAssets hook.`;
593
- const getOptions = options => {
712
+ /**
713
+ * @param {string | (import("tapable").TapOptions & { name: string } & ProcessAssetsAdditionalOptions)} options hook options
714
+ * @returns {import("tapable").TapOptions & { name: string } & ProcessAssetsAdditionalOptions} modified options
715
+ */
716
+ const getOptions = (options) => {
594
717
  if (typeof options === "string") options = { name: options };
595
718
  if (options.stage) {
596
719
  throw new Error(errorMessage("it's using the 'stage' option"));
@@ -601,7 +724,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
601
724
  {
602
725
  name,
603
726
  /** @type {AsyncSeriesHook<T>["intercept"]} */
604
- intercept(interceptor) {
727
+ intercept(_interceptor) {
605
728
  throw new Error(errorMessage("it's using 'intercept'"));
606
729
  },
607
730
  /** @type {AsyncSeriesHook<T>["tap"]} */
@@ -613,7 +736,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
613
736
  processAssetsHook.tapAsync(
614
737
  getOptions(options),
615
738
  (assets, callback) =>
616
- /** @type {any} */ (fn)(...getArgs(), callback)
739
+ /** @type {EXPECTED_ANY} */ (fn)(...getArgs(), callback)
617
740
  );
618
741
  },
619
742
  /** @type {AsyncSeriesHook<T>["tapPromise"]} */
@@ -646,7 +769,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
646
769
  /** @type {SyncHook<[Dependency, EntryOptions, Module]>} */
647
770
  succeedEntry: new SyncHook(["entry", "options", "module"]),
648
771
 
649
- /** @type {SyncWaterfallHook<[(string[] | ReferencedExport)[], Dependency, RuntimeSpec]>} */
772
+ /** @type {SyncWaterfallHook<[ReferencedExports, Dependency, RuntimeSpec]>} */
650
773
  dependencyReferencedExports: new SyncWaterfallHook([
651
774
  "referencedExports",
652
775
  "dependency",
@@ -706,33 +829,33 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
706
829
  /** @type {SyncBailHook<[], boolean | void>} */
707
830
  shouldRecord: new SyncBailHook([]),
708
831
 
709
- /** @type {SyncHook<[Chunk, Set<string>, RuntimeRequirementsContext]>} */
832
+ /** @type {SyncHook<[Chunk, RuntimeRequirements, RuntimeRequirementsContext]>} */
710
833
  additionalChunkRuntimeRequirements: new SyncHook([
711
834
  "chunk",
712
835
  "runtimeRequirements",
713
836
  "context"
714
837
  ]),
715
- /** @type {HookMap<SyncBailHook<[Chunk, Set<string>, RuntimeRequirementsContext], void>>} */
838
+ /** @type {HookMap<SyncBailHook<[Chunk, RuntimeRequirements, RuntimeRequirementsContext], void>>} */
716
839
  runtimeRequirementInChunk: new HookMap(
717
840
  () => new SyncBailHook(["chunk", "runtimeRequirements", "context"])
718
841
  ),
719
- /** @type {SyncHook<[Module, Set<string>, RuntimeRequirementsContext]>} */
842
+ /** @type {SyncHook<[Module, RuntimeRequirements, RuntimeRequirementsContext]>} */
720
843
  additionalModuleRuntimeRequirements: new SyncHook([
721
844
  "module",
722
845
  "runtimeRequirements",
723
846
  "context"
724
847
  ]),
725
- /** @type {HookMap<SyncBailHook<[Module, Set<string>, RuntimeRequirementsContext], void>>} */
848
+ /** @type {HookMap<SyncBailHook<[Module, RuntimeRequirements, RuntimeRequirementsContext], void>>} */
726
849
  runtimeRequirementInModule: new HookMap(
727
850
  () => new SyncBailHook(["module", "runtimeRequirements", "context"])
728
851
  ),
729
- /** @type {SyncHook<[Chunk, Set<string>, RuntimeRequirementsContext]>} */
852
+ /** @type {SyncHook<[Chunk, RuntimeRequirements, RuntimeRequirementsContext]>} */
730
853
  additionalTreeRuntimeRequirements: new SyncHook([
731
854
  "chunk",
732
855
  "runtimeRequirements",
733
856
  "context"
734
857
  ]),
735
- /** @type {HookMap<SyncBailHook<[Chunk, Set<string>, RuntimeRequirementsContext], void>>} */
858
+ /** @type {HookMap<SyncBailHook<[Chunk, RuntimeRequirements, RuntimeRequirementsContext], void>>} */
736
859
  runtimeRequirementInTree: new HookMap(
737
860
  () => new SyncBailHook(["chunk", "runtimeRequirements", "context"])
738
861
  ),
@@ -740,7 +863,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
740
863
  /** @type {SyncHook<[RuntimeModule, Chunk]>} */
741
864
  runtimeModule: new SyncHook(["module", "chunk"]),
742
865
 
743
- /** @type {SyncHook<[Iterable<Module>, any]>} */
866
+ /** @type {SyncHook<[Iterable<Module>, Records]>} */
744
867
  reviveModules: new SyncHook(["modules", "records"]),
745
868
  /** @type {SyncHook<[Iterable<Module>]>} */
746
869
  beforeModuleIds: new SyncHook(["modules"]),
@@ -751,7 +874,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
751
874
  /** @type {SyncHook<[Iterable<Module>]>} */
752
875
  afterOptimizeModuleIds: new SyncHook(["modules"]),
753
876
 
754
- /** @type {SyncHook<[Iterable<Chunk>, any]>} */
877
+ /** @type {SyncHook<[Iterable<Chunk>, Records]>} */
755
878
  reviveChunks: new SyncHook(["chunks", "records"]),
756
879
  /** @type {SyncHook<[Iterable<Chunk>]>} */
757
880
  beforeChunkIds: new SyncHook(["chunks"]),
@@ -762,9 +885,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
762
885
  /** @type {SyncHook<[Iterable<Chunk>]>} */
763
886
  afterOptimizeChunkIds: new SyncHook(["chunks"]),
764
887
 
765
- /** @type {SyncHook<[Iterable<Module>, any]>} */
888
+ /** @type {SyncHook<[Iterable<Module>, Records]>} */
766
889
  recordModules: new SyncHook(["modules", "records"]),
767
- /** @type {SyncHook<[Iterable<Chunk>, any]>} */
890
+ /** @type {SyncHook<[Iterable<Chunk>, Records]>} */
768
891
  recordChunks: new SyncHook(["chunks", "records"]),
769
892
 
770
893
  /** @type {SyncHook<[Iterable<Module>]>} */
@@ -791,9 +914,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
791
914
  contentHash: new SyncHook(["chunk"]),
792
915
  /** @type {SyncHook<[]>} */
793
916
  afterHash: new SyncHook([]),
794
- /** @type {SyncHook<[any]>} */
917
+ /** @type {SyncHook<[Records]>} */
795
918
  recordHash: new SyncHook(["records"]),
796
- /** @type {SyncHook<[Compilation, any]>} */
919
+ /** @type {SyncHook<[Compilation, Records]>} */
797
920
  record: new SyncHook(["compilation", "records"]),
798
921
 
799
922
  /** @type {SyncHook<[]>} */
@@ -804,36 +927,52 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
804
927
  beforeChunkAssets: new SyncHook([]),
805
928
  // TODO webpack 6 remove
806
929
  /** @deprecated */
807
- additionalChunkAssets: createProcessAssetsHook(
808
- "additionalChunkAssets",
809
- Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
810
- () => [this.chunks],
811
- "DEP_WEBPACK_COMPILATION_ADDITIONAL_CHUNK_ASSETS"
812
- ),
930
+ additionalChunkAssets:
931
+ /** @type {FakeHook<Pick<AsyncSeriesHook<[Chunks]>, "tap" | "tapAsync" | "tapPromise" | "name">>} */
932
+ (
933
+ createProcessAssetsHook(
934
+ "additionalChunkAssets",
935
+ Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
936
+ () => [this.chunks],
937
+ "DEP_WEBPACK_COMPILATION_ADDITIONAL_CHUNK_ASSETS"
938
+ )
939
+ ),
813
940
 
814
941
  // TODO webpack 6 deprecate
815
942
  /** @deprecated */
816
- additionalAssets: createProcessAssetsHook(
817
- "additionalAssets",
818
- Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
819
- () => []
820
- ),
943
+ additionalAssets:
944
+ /** @type {FakeHook<Pick<AsyncSeriesHook<[]>, "tap" | "tapAsync" | "tapPromise" | "name">>} */
945
+ (
946
+ createProcessAssetsHook(
947
+ "additionalAssets",
948
+ Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
949
+ () => []
950
+ )
951
+ ),
821
952
  // TODO webpack 6 remove
822
953
  /** @deprecated */
823
- optimizeChunkAssets: createProcessAssetsHook(
824
- "optimizeChunkAssets",
825
- Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE,
826
- () => [this.chunks],
827
- "DEP_WEBPACK_COMPILATION_OPTIMIZE_CHUNK_ASSETS"
828
- ),
954
+ optimizeChunkAssets:
955
+ /** @type {FakeHook<Pick<AsyncSeriesHook<[Chunks]>, "tap" | "tapAsync" | "tapPromise" | "name">>} */
956
+ (
957
+ createProcessAssetsHook(
958
+ "optimizeChunkAssets",
959
+ Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE,
960
+ () => [this.chunks],
961
+ "DEP_WEBPACK_COMPILATION_OPTIMIZE_CHUNK_ASSETS"
962
+ )
963
+ ),
829
964
  // TODO webpack 6 remove
830
965
  /** @deprecated */
831
- afterOptimizeChunkAssets: createProcessAssetsHook(
832
- "afterOptimizeChunkAssets",
833
- Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE + 1,
834
- () => [this.chunks],
835
- "DEP_WEBPACK_COMPILATION_AFTER_OPTIMIZE_CHUNK_ASSETS"
836
- ),
966
+ afterOptimizeChunkAssets:
967
+ /** @type {FakeHook<Pick<AsyncSeriesHook<[Chunks]>, "tap" | "tapAsync" | "tapPromise" | "name">>} */
968
+ (
969
+ createProcessAssetsHook(
970
+ "afterOptimizeChunkAssets",
971
+ Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE + 1,
972
+ () => [this.chunks],
973
+ "DEP_WEBPACK_COMPILATION_AFTER_OPTIMIZE_CHUNK_ASSETS"
974
+ )
975
+ ),
837
976
  // TODO webpack 6 deprecate
838
977
  /** @deprecated */
839
978
  optimizeAssets: processAssetsHook,
@@ -864,7 +1003,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
864
1003
  /** @type {SyncHook<[Chunk, string]>} */
865
1004
  chunkAsset: new SyncHook(["chunk", "filename"]),
866
1005
 
867
- /** @type {SyncWaterfallHook<[string, object, AssetInfo | undefined]>} */
1006
+ /** @type {SyncWaterfallHook<[string, PathData, AssetInfo | undefined]>} */
868
1007
  assetPath: new SyncWaterfallHook(["path", "options", "assetInfo"]),
869
1008
 
870
1009
  /** @type {SyncBailHook<[], boolean | void>} */
@@ -880,9 +1019,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
880
1019
  /** @type {SyncBailHook<[string, LogEntry], boolean | void>} */
881
1020
  log: new SyncBailHook(["origin", "logEntry"]),
882
1021
 
883
- /** @type {SyncWaterfallHook<[WebpackError[]]>} */
1022
+ /** @type {SyncWaterfallHook<[Error[]]>} */
884
1023
  processWarnings: new SyncWaterfallHook(["warnings"]),
885
- /** @type {SyncWaterfallHook<[WebpackError[]]>} */
1024
+ /** @type {SyncWaterfallHook<[Error[]]>} */
886
1025
  processErrors: new SyncWaterfallHook(["errors"]),
887
1026
 
888
1027
  /** @type {HookMap<SyncHook<[Partial<NormalizedStatsOptions>, CreateStatsOptionsContext]>>} */
@@ -936,7 +1075,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
936
1075
 
937
1076
  const options = /** @type {WebpackOptions} */ (compiler.options);
938
1077
  this.options = options;
939
- this.outputOptions = options && options.output;
1078
+ this.outputOptions =
1079
+ /** @type {OutputOptionsWithDefaults} */
1080
+ (options && options.output);
940
1081
  /** @type {boolean} */
941
1082
  this.bail = (options && options.bail) || false;
942
1083
  /** @type {boolean} */
@@ -956,14 +1097,19 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
956
1097
  };
957
1098
  defineRemovedModuleTemplates(this.moduleTemplates);
958
1099
 
959
- /** @type {Map<Module, WeakTupleMap<any, any>> | undefined} */
1100
+ // We need to think how implement types here
1101
+ /** @type {ModuleMemCaches | undefined} */
960
1102
  this.moduleMemCaches = undefined;
961
- /** @type {Map<Module, WeakTupleMap<any, any>> | undefined} */
1103
+ /** @type {ModuleMemCaches | undefined} */
962
1104
  this.moduleMemCaches2 = undefined;
1105
+ /** @type {ModuleGraph} */
963
1106
  this.moduleGraph = new ModuleGraph();
964
1107
  /** @type {ChunkGraph} */
965
- this.chunkGraph = undefined;
966
- /** @type {CodeGenerationResults} */
1108
+ this.chunkGraph = new ChunkGraph(
1109
+ this.moduleGraph,
1110
+ this.outputOptions.hashFunction
1111
+ );
1112
+ /** @type {CodeGenerationResults | undefined} */
967
1113
  this.codeGenerationResults = undefined;
968
1114
 
969
1115
  /** @type {AsyncQueue<Module, Module, Module>} */
@@ -976,7 +1122,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
976
1122
  this.addModuleQueue = new AsyncQueue({
977
1123
  name: "addModule",
978
1124
  parent: this.processDependenciesQueue,
979
- getKey: module => module.identifier(),
1125
+ getKey: (module) => module.identifier(),
980
1126
  processor: this._addModule.bind(this)
981
1127
  });
982
1128
  /** @type {AsyncQueue<FactorizeModuleOptions, string, Module | ModuleFactoryResult>} */
@@ -1006,7 +1152,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1006
1152
  */
1007
1153
  this.creatingModuleDuringBuild = new WeakMap();
1008
1154
 
1009
- /** @type {Map<string, EntryData>} */
1155
+ /** @type {Map<Exclude<ChunkName, null>, EntryData>} */
1010
1156
  this.entries = new Map();
1011
1157
  /** @type {EntryData} */
1012
1158
  this.globalEntry = {
@@ -1020,7 +1166,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1020
1166
  this.entrypoints = new Map();
1021
1167
  /** @type {Entrypoint[]} */
1022
1168
  this.asyncEntrypoints = [];
1023
- /** @type {Set<Chunk>} */
1169
+ /** @type {Chunks} */
1024
1170
  this.chunks = new Set();
1025
1171
  /** @type {ChunkGroup[]} */
1026
1172
  this.chunkGroups = [];
@@ -1039,6 +1185,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1039
1185
  * @type {Map<string, Module>}
1040
1186
  */
1041
1187
  this._modules = new Map();
1188
+ /** @type {Records | null} */
1042
1189
  this.records = null;
1043
1190
  /** @type {string[]} */
1044
1191
  this.additionalChunkAssets = [];
@@ -1048,15 +1195,15 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1048
1195
  this.assetsInfo = new Map();
1049
1196
  /** @type {Map<string, Map<string, Set<string>>>} */
1050
1197
  this._assetsRelatedIn = new Map();
1051
- /** @type {WebpackError[]} */
1198
+ /** @type {Error[]} */
1052
1199
  this.errors = [];
1053
- /** @type {WebpackError[]} */
1200
+ /** @type {Error[]} */
1054
1201
  this.warnings = [];
1055
1202
  /** @type {Compilation[]} */
1056
1203
  this.children = [];
1057
1204
  /** @type {Map<string, LogEntry[]>} */
1058
1205
  this.logging = new Map();
1059
- /** @type {Map<DepConstructor, ModuleFactory>} */
1206
+ /** @type {Map<DependencyConstructor, ModuleFactory>} */
1060
1207
  this.dependencyFactories = new Map();
1061
1208
  /** @type {DependencyTemplates} */
1062
1209
  this.dependencyTemplates = new DependencyTemplates(
@@ -1064,15 +1211,15 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1064
1211
  );
1065
1212
  /** @type {Record<string, number>} */
1066
1213
  this.childrenCounters = {};
1067
- /** @type {Set<number|string>} */
1214
+ /** @type {Set<number> | null} */
1068
1215
  this.usedChunkIds = null;
1069
- /** @type {Set<number>} */
1216
+ /** @type {Set<number> | null} */
1070
1217
  this.usedModuleIds = null;
1071
1218
  /** @type {boolean} */
1072
1219
  this.needAdditionalPass = false;
1073
- /** @type {Set<Module & { restoreFromUnsafeCache: Function }>} */
1220
+ /** @type {Set<ModuleWithRestoreFromUnsafeCache>} */
1074
1221
  this._restoredUnsafeCacheModuleEntries = new Set();
1075
- /** @type {Map<string, Module & { restoreFromUnsafeCache: Function }>} */
1222
+ /** @type {Map<string, ModuleWithRestoreFromUnsafeCache>} */
1076
1223
  this._restoredUnsafeCacheEntries = new Map();
1077
1224
  /** @type {WeakSet<Module>} */
1078
1225
  this.builtModules = new WeakSet();
@@ -1084,22 +1231,22 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1084
1231
  this.emittedAssets = new Set();
1085
1232
  /** @type {Set<string>} */
1086
1233
  this.comparedForEmitAssets = new Set();
1087
- /** @type {LazySet<string>} */
1234
+ /** @type {FileSystemDependencies} */
1088
1235
  this.fileDependencies = new LazySet();
1089
- /** @type {LazySet<string>} */
1236
+ /** @type {FileSystemDependencies} */
1090
1237
  this.contextDependencies = new LazySet();
1091
- /** @type {LazySet<string>} */
1238
+ /** @type {FileSystemDependencies} */
1092
1239
  this.missingDependencies = new LazySet();
1093
- /** @type {LazySet<string>} */
1240
+ /** @type {FileSystemDependencies} */
1094
1241
  this.buildDependencies = new LazySet();
1095
1242
  // TODO webpack 6 remove
1096
1243
  this.compilationDependencies = {
1097
1244
  add: util.deprecate(
1098
1245
  /**
1099
1246
  * @param {string} item item
1100
- * @returns {LazySet<string>} file dependencies
1247
+ * @returns {FileSystemDependencies} file dependencies
1101
1248
  */
1102
- item => this.fileDependencies.add(item),
1249
+ (item) => this.fileDependencies.add(item),
1103
1250
  "Compilation.compilationDependencies is deprecated (used Compilation.fileDependencies instead)",
1104
1251
  "DEP_WEBPACK_COMPILATION_COMPILATION_DEPENDENCIES"
1105
1252
  )
@@ -1137,7 +1284,6 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1137
1284
  // properties in the prototype chain
1138
1285
  /** @type {Partial<NormalizedStatsOptions>} */
1139
1286
  const options = {};
1140
- // eslint-disable-next-line guard-for-in
1141
1287
  for (const key in optionsOrPreset) {
1142
1288
  options[key] = optionsOrPreset[/** @type {keyof StatsOptions} */ (key)];
1143
1289
  }
@@ -1182,7 +1328,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1182
1328
  }
1183
1329
 
1184
1330
  /**
1185
- * @param {string | (function(): string)} name name of the logger, or function called once to get the logger name
1331
+ * @param {string | (() => string)} name name of the logger, or function called once to get the logger name
1186
1332
  * @returns {Logger} a logger with that name
1187
1333
  */
1188
1334
  getLogger(name) {
@@ -1220,6 +1366,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1220
1366
  args,
1221
1367
  trace
1222
1368
  };
1369
+ /* eslint-disable no-console */
1223
1370
  if (this.hooks.log.call(name, logEntry) === undefined) {
1224
1371
  if (
1225
1372
  logEntry.type === LogType.profileEnd &&
@@ -1248,9 +1395,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1248
1395
  }`
1249
1396
  );
1250
1397
  }
1398
+ /* eslint-enable no-console */
1251
1399
  }
1252
1400
  },
1253
- childName => {
1401
+ (childName) => {
1254
1402
  if (typeof name === "function") {
1255
1403
  if (typeof childName === "function") {
1256
1404
  return this.getLogger(() => {
@@ -1348,8 +1496,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1348
1496
  }
1349
1497
  this._modules.set(identifier, module);
1350
1498
  this.modules.add(module);
1351
- if (this._backCompat)
1499
+ if (this._backCompat) {
1352
1500
  ModuleGraph.setModuleGraphForModule(module, this.moduleGraph);
1501
+ }
1353
1502
  if (currentProfile !== undefined) {
1354
1503
  currentProfile.markIntegrationEnd();
1355
1504
  }
@@ -1423,8 +1572,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1423
1572
  this.options,
1424
1573
  this,
1425
1574
  this.resolverFactory.get("normal", module.resolveOptions),
1426
- /** @type {InputFileSystem} */ (this.inputFileSystem),
1427
- err => {
1575
+ /** @type {InputFileSystem} */
1576
+ (this.inputFileSystem),
1577
+ (err) => {
1428
1578
  if (currentProfile !== undefined) {
1429
1579
  currentProfile.markBuildingEnd();
1430
1580
  }
@@ -1435,20 +1585,25 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1435
1585
  if (currentProfile !== undefined) {
1436
1586
  currentProfile.markStoringStart();
1437
1587
  }
1438
- this._modulesCache.store(module.identifier(), null, module, err => {
1439
- if (currentProfile !== undefined) {
1440
- currentProfile.markStoringEnd();
1441
- }
1442
- if (err) {
1443
- this.hooks.failedModule.call(
1444
- module,
1445
- /** @type {WebpackError} */ (err)
1446
- );
1447
- return callback(new ModuleStoreError(module, err));
1588
+ this._modulesCache.store(
1589
+ module.identifier(),
1590
+ null,
1591
+ module,
1592
+ (err) => {
1593
+ if (currentProfile !== undefined) {
1594
+ currentProfile.markStoringEnd();
1595
+ }
1596
+ if (err) {
1597
+ this.hooks.failedModule.call(
1598
+ module,
1599
+ /** @type {WebpackError} */ (err)
1600
+ );
1601
+ return callback(new ModuleStoreError(module, err));
1602
+ }
1603
+ this.hooks.succeedModule.call(module);
1604
+ return callback();
1448
1605
  }
1449
- this.hooks.succeedModule.call(module);
1450
- return callback();
1451
- });
1606
+ );
1452
1607
  }
1453
1608
  );
1454
1609
  }
@@ -1472,7 +1627,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1472
1627
  /**
1473
1628
  * @param {DependenciesBlock} block block
1474
1629
  */
1475
- const processDependenciesBlock = block => {
1630
+ const processDependenciesBlock = (block) => {
1476
1631
  if (block.dependencies) {
1477
1632
  let i = 0;
1478
1633
  for (const dep of block.dependencies) {
@@ -1493,15 +1648,19 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1493
1648
  * @returns {void}
1494
1649
  */
1495
1650
  _processModuleDependencies(module, callback) {
1496
- /** @type {Array<{factory: ModuleFactory, dependencies: Dependency[], context: string|undefined, originModule: Module|null}>} */
1651
+ /** @type {{ factory: ModuleFactory, dependencies: Dependency[], context: string | undefined, originModule: Module | null }[]} */
1497
1652
  const sortedDependencies = [];
1653
+ /** @type {boolean} */
1654
+ const hasLowPriorityDependencies = module.dependencies.some(
1655
+ Dependency.isLowPriorityDependency
1656
+ );
1498
1657
 
1499
1658
  /** @type {DependenciesBlock} */
1500
1659
  let currentBlock;
1501
1660
 
1502
1661
  /** @type {Map<ModuleFactory, Map<string, Dependency[]>>} */
1503
1662
  let dependencies;
1504
- /** @type {DepConstructor} */
1663
+ /** @type {DependencyConstructor} */
1505
1664
  let factoryCacheKey;
1506
1665
  /** @type {ModuleFactory} */
1507
1666
  let factoryCacheKey2;
@@ -1522,7 +1681,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1522
1681
  * @param {WebpackError=} err error
1523
1682
  * @returns {void}
1524
1683
  */
1525
- const onDependenciesSorted = err => {
1684
+ const onDependenciesSorted = (err) => {
1526
1685
  if (err) return callback(err);
1527
1686
 
1528
1687
  // early exit without changing parallelism back and forth
@@ -1536,7 +1695,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1536
1695
  for (const item of sortedDependencies) {
1537
1696
  inProgressTransitive++;
1538
1697
  // eslint-disable-next-line no-loop-func
1539
- this.handleModuleCreation(item, err => {
1698
+ this.handleModuleCreation(item, (err) => {
1540
1699
  // In V8, the Error objects keep a reference to the functions on the stack. These warnings &
1541
1700
  // errors are created inside closures that keep a reference to the Compilation, so errors are
1542
1701
  // leaking the Compilation object.
@@ -1558,7 +1717,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1558
1717
  * @param {WebpackError=} err error
1559
1718
  * @returns {void}
1560
1719
  */
1561
- const onTransitiveTasksFinished = err => {
1720
+ const onTransitiveTasksFinished = (err) => {
1562
1721
  if (err) return callback(err);
1563
1722
  this.processDependenciesQueue.decreaseParallelism();
1564
1723
 
@@ -1635,14 +1794,15 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1635
1794
  module,
1636
1795
  dep,
1637
1796
  cachedModule,
1638
- err => {
1797
+ (err) => {
1639
1798
  if (err) {
1640
1799
  if (inProgressTransitive <= 0) return;
1641
1800
  inProgressTransitive = -1;
1642
1801
  onTransitiveTasksFinished(err);
1643
1802
  }
1644
- if (--inProgressTransitive === 0)
1803
+ if (--inProgressTransitive === 0) {
1645
1804
  return onTransitiveTasksFinished();
1805
+ }
1646
1806
  }
1647
1807
  );
1648
1808
  if (--inProgressSorting === 0) onDependenciesSorted();
@@ -1668,6 +1828,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1668
1828
  return;
1669
1829
  }
1670
1830
  } catch (err) {
1831
+ // eslint-disable-next-line no-console
1671
1832
  console.error(err);
1672
1833
  }
1673
1834
  }
@@ -1678,11 +1839,13 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1678
1839
  * @param {Dependency} dep dependency
1679
1840
  * @returns {void}
1680
1841
  */
1681
- const processDependencyForResolving = dep => {
1842
+ const processDependencyForResolving = (dep) => {
1682
1843
  const resourceIdent = dep.getResourceIdentifier();
1683
1844
  if (resourceIdent !== undefined && resourceIdent !== null) {
1684
1845
  const category = dep.category;
1685
- const constructor = /** @type {DepConstructor} */ (dep.constructor);
1846
+ const constructor =
1847
+ /** @type {DependencyConstructor} */
1848
+ (dep.constructor);
1686
1849
  if (factoryCacheKey === constructor) {
1687
1850
  // Fast path 1: same constructor as prev item
1688
1851
  if (listCacheKey1 === category && listCacheKey2 === resourceIdent) {
@@ -1738,12 +1901,29 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1738
1901
  if (list === undefined) {
1739
1902
  /** @type {FactoryCacheValue} */
1740
1903
  (factoryCacheValue).set(cacheKey, (list = []));
1741
- sortedDependencies.push({
1904
+ const newItem = {
1742
1905
  factory: factoryCacheKey2,
1743
1906
  dependencies: list,
1744
1907
  context: dep.getContext(),
1745
1908
  originModule: module
1746
- });
1909
+ };
1910
+ if (hasLowPriorityDependencies) {
1911
+ let insertIndex = sortedDependencies.length;
1912
+ while (insertIndex > 0) {
1913
+ const item = sortedDependencies[insertIndex - 1];
1914
+ const isAllLowPriorityDependencies = item.dependencies.every(
1915
+ Dependency.isLowPriorityDependency
1916
+ );
1917
+ if (isAllLowPriorityDependencies) {
1918
+ insertIndex--;
1919
+ } else {
1920
+ break;
1921
+ }
1922
+ }
1923
+ sortedDependencies.splice(insertIndex, 0, newItem);
1924
+ } else {
1925
+ sortedDependencies.push(newItem);
1926
+ }
1747
1927
  }
1748
1928
  list.push(dep);
1749
1929
  listCacheKey1 = category;
@@ -1792,8 +1972,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1792
1972
 
1793
1973
  this._modules.set(module.identifier(), module);
1794
1974
  this.modules.add(module);
1795
- if (this._backCompat)
1975
+ if (this._backCompat) {
1796
1976
  ModuleGraph.setModuleGraphForModule(module, this.moduleGraph);
1977
+ }
1797
1978
 
1798
1979
  this._handleModuleBuildAndDependencies(
1799
1980
  originModule,
@@ -1816,6 +1997,116 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1816
1997
  moduleGraph.setResolvedModule(originModule, dependency, module);
1817
1998
  }
1818
1999
 
2000
+ /**
2001
+ * @param {FactorizeModuleOptions} options options
2002
+ * @param {ModuleOrModuleFactoryResultCallback} callback callback
2003
+ * @returns {void}
2004
+ */
2005
+ _factorizeModule(
2006
+ {
2007
+ currentProfile,
2008
+ factory,
2009
+ dependencies,
2010
+ originModule,
2011
+ factoryResult,
2012
+ contextInfo,
2013
+ context
2014
+ },
2015
+ callback
2016
+ ) {
2017
+ if (currentProfile !== undefined) {
2018
+ currentProfile.markFactoryStart();
2019
+ }
2020
+ factory.create(
2021
+ {
2022
+ contextInfo: {
2023
+ issuer: originModule
2024
+ ? /** @type {NameForCondition} */ (originModule.nameForCondition())
2025
+ : "",
2026
+ issuerLayer: originModule ? originModule.layer : null,
2027
+ compiler: this.compiler.name,
2028
+ ...contextInfo
2029
+ },
2030
+ resolveOptions: originModule ? originModule.resolveOptions : undefined,
2031
+ context:
2032
+ context ||
2033
+ (originModule
2034
+ ? /** @type {string} */ (originModule.context)
2035
+ : this.compiler.context),
2036
+ dependencies
2037
+ },
2038
+ (err, result) => {
2039
+ if (result) {
2040
+ // TODO webpack 6: remove
2041
+ // For backward-compat
2042
+ if (result.module === undefined && result instanceof Module) {
2043
+ result = {
2044
+ module: result
2045
+ };
2046
+ }
2047
+ if (!factoryResult) {
2048
+ const {
2049
+ fileDependencies,
2050
+ contextDependencies,
2051
+ missingDependencies
2052
+ } = result;
2053
+ if (fileDependencies) {
2054
+ this.fileDependencies.addAll(fileDependencies);
2055
+ }
2056
+ if (contextDependencies) {
2057
+ this.contextDependencies.addAll(contextDependencies);
2058
+ }
2059
+ if (missingDependencies) {
2060
+ this.missingDependencies.addAll(missingDependencies);
2061
+ }
2062
+ }
2063
+ }
2064
+ if (err) {
2065
+ const notFoundError = new ModuleNotFoundError(
2066
+ originModule,
2067
+ err,
2068
+ /** @type {DependencyLocation} */
2069
+ (dependencies.map((d) => d.loc).find(Boolean))
2070
+ );
2071
+ return callback(notFoundError, factoryResult ? result : undefined);
2072
+ }
2073
+ if (!result) {
2074
+ return callback();
2075
+ }
2076
+
2077
+ if (currentProfile !== undefined) {
2078
+ currentProfile.markFactoryEnd();
2079
+ }
2080
+
2081
+ callback(null, factoryResult ? result : result.module);
2082
+ }
2083
+ );
2084
+ }
2085
+
2086
+ /**
2087
+ * @overload
2088
+ * @param {FactorizeModuleOptions & { factoryResult?: false }} options options
2089
+ * @param {ModuleCallback} callback callback
2090
+ * @returns {void}
2091
+ */
2092
+ /**
2093
+ * @overload
2094
+ * @param {FactorizeModuleOptions & { factoryResult: true }} options options
2095
+ * @param {ModuleFactoryResultCallback} callback callback
2096
+ * @returns {void}
2097
+ */
2098
+ /**
2099
+ * @param {FactorizeModuleOptions & { factoryResult?: false } | FactorizeModuleOptions & { factoryResult: true }} options options
2100
+ * @param {ModuleCallback | ModuleFactoryResultCallback} callback callback
2101
+ */
2102
+ factorizeModule(options, callback) {
2103
+ this.factorizeQueue.add(
2104
+ options,
2105
+ /** @type {ModuleOrModuleFactoryResultCallback} */
2106
+ (callback)
2107
+ );
2108
+ }
2109
+
1819
2110
  /**
1820
2111
  * @typedef {object} HandleModuleCreationOptions
1821
2112
  * @property {ModuleFactory} factory
@@ -1876,7 +2167,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1876
2167
  };
1877
2168
  if (err) {
1878
2169
  if (factoryResult) applyFactoryResultDependencies();
1879
- if (dependencies.every(d => d.optional)) {
2170
+ if (dependencies.every((d) => d.optional)) {
1880
2171
  this.warnings.push(err);
1881
2172
  return callback();
1882
2173
  }
@@ -1909,7 +2200,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1909
2200
  }
1910
2201
 
1911
2202
  const module =
1912
- /** @type {Module & { restoreFromUnsafeCache?: Function }} */
2203
+ /** @type {ModuleWithRestoreFromUnsafeCache} */
1913
2204
  (_module);
1914
2205
 
1915
2206
  if (
@@ -1920,10 +2211,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1920
2211
  this._unsafeCachePredicate(module)
1921
2212
  ) {
1922
2213
  const unsafeCacheableModule =
1923
- /** @type {Module & { restoreFromUnsafeCache: Function }} */
2214
+ /** @type {ModuleWithRestoreFromUnsafeCache} */
1924
2215
  (module);
1925
- for (let i = 0; i < dependencies.length; i++) {
1926
- const dependency = dependencies[i];
2216
+ for (const dependency of dependencies) {
1927
2217
  moduleGraph.setResolvedModule(
1928
2218
  connectOrigin ? originModule : null,
1929
2219
  dependency,
@@ -1939,8 +2229,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1939
2229
  }
1940
2230
  } else {
1941
2231
  applyFactoryResultDependencies();
1942
- for (let i = 0; i < dependencies.length; i++) {
1943
- const dependency = dependencies[i];
2232
+ for (const dependency of dependencies) {
1944
2233
  moduleGraph.setResolvedModule(
1945
2234
  connectOrigin ? originModule : null,
1946
2235
  dependency,
@@ -1976,7 +2265,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1976
2265
 
1977
2266
  /**
1978
2267
  * @private
1979
- * @param {Module} originModule original module
2268
+ * @param {Module | null} originModule original module
1980
2269
  * @param {Module} module module
1981
2270
  * @param {boolean} recursive true if make it recursive, otherwise false
1982
2271
  * @param {boolean} checkCycle true if need to check cycle, otherwise false
@@ -1993,14 +2282,20 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1993
2282
  // Check for cycles when build is trigger inside another build
1994
2283
  /** @type {Set<Module> | undefined} */
1995
2284
  let creatingModuleDuringBuildSet;
1996
- if (checkCycle && this.buildQueue.isProcessing(originModule)) {
2285
+ if (
2286
+ checkCycle &&
2287
+ this.buildQueue.isProcessing(/** @type {Module} */ (originModule))
2288
+ ) {
1997
2289
  // Track build dependency
1998
- creatingModuleDuringBuildSet =
1999
- this.creatingModuleDuringBuild.get(originModule);
2290
+ creatingModuleDuringBuildSet = this.creatingModuleDuringBuild.get(
2291
+ /** @type {Module} */
2292
+ (originModule)
2293
+ );
2000
2294
  if (creatingModuleDuringBuildSet === undefined) {
2001
2295
  creatingModuleDuringBuildSet = new Set();
2002
2296
  this.creatingModuleDuringBuild.set(
2003
- originModule,
2297
+ /** @type {Module} */
2298
+ (originModule),
2004
2299
  creatingModuleDuringBuildSet
2005
2300
  );
2006
2301
  }
@@ -2026,7 +2321,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2026
2321
  }
2027
2322
  }
2028
2323
 
2029
- this.buildModule(module, err => {
2324
+ this.buildModule(module, (err) => {
2030
2325
  if (creatingModuleDuringBuildSet !== undefined) {
2031
2326
  creatingModuleDuringBuildSet.delete(module);
2032
2327
  }
@@ -2050,7 +2345,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2050
2345
  return callback(null, module);
2051
2346
  }
2052
2347
 
2053
- this.processModuleDependencies(module, err => {
2348
+ this.processModuleDependencies(module, (err) => {
2054
2349
  if (err) {
2055
2350
  return callback(err);
2056
2351
  }
@@ -2059,88 +2354,6 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2059
2354
  });
2060
2355
  }
2061
2356
 
2062
- /**
2063
- * @param {FactorizeModuleOptions} options options object
2064
- * @param {ModuleOrFactoryResultCallback} callback callback
2065
- * @returns {void}
2066
- */
2067
- _factorizeModule(
2068
- {
2069
- currentProfile,
2070
- factory,
2071
- dependencies,
2072
- originModule,
2073
- factoryResult,
2074
- contextInfo,
2075
- context
2076
- },
2077
- callback
2078
- ) {
2079
- if (currentProfile !== undefined) {
2080
- currentProfile.markFactoryStart();
2081
- }
2082
- factory.create(
2083
- {
2084
- contextInfo: {
2085
- issuer: originModule ? originModule.nameForCondition() : "",
2086
- issuerLayer: originModule ? originModule.layer : null,
2087
- compiler: this.compiler.name,
2088
- ...contextInfo
2089
- },
2090
- resolveOptions: originModule ? originModule.resolveOptions : undefined,
2091
- context:
2092
- context ||
2093
- (originModule ? originModule.context : this.compiler.context),
2094
- dependencies
2095
- },
2096
- (err, result) => {
2097
- if (result) {
2098
- // TODO webpack 6: remove
2099
- // For backward-compat
2100
- if (result.module === undefined && result instanceof Module) {
2101
- result = {
2102
- module: result
2103
- };
2104
- }
2105
- if (!factoryResult) {
2106
- const {
2107
- fileDependencies,
2108
- contextDependencies,
2109
- missingDependencies
2110
- } = result;
2111
- if (fileDependencies) {
2112
- this.fileDependencies.addAll(fileDependencies);
2113
- }
2114
- if (contextDependencies) {
2115
- this.contextDependencies.addAll(contextDependencies);
2116
- }
2117
- if (missingDependencies) {
2118
- this.missingDependencies.addAll(missingDependencies);
2119
- }
2120
- }
2121
- }
2122
- if (err) {
2123
- const notFoundError = new ModuleNotFoundError(
2124
- originModule,
2125
- err,
2126
- /** @type {DependencyLocation} */
2127
- (dependencies.map(d => d.loc).find(Boolean))
2128
- );
2129
- return callback(notFoundError, factoryResult ? result : undefined);
2130
- }
2131
- if (!result) {
2132
- return callback();
2133
- }
2134
-
2135
- if (currentProfile !== undefined) {
2136
- currentProfile.markFactoryEnd();
2137
- }
2138
-
2139
- callback(null, factoryResult ? result : result.module);
2140
- }
2141
- );
2142
- }
2143
-
2144
2357
  /**
2145
2358
  * @param {string} context context string path
2146
2359
  * @param {Dependency} dependency dependency used to create Module chain
@@ -2169,7 +2382,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2169
2382
  new WebpackError("Parameter 'dependency' must be a Dependency")
2170
2383
  );
2171
2384
  }
2172
- const Dep = /** @type {DepConstructor} */ (dependency.constructor);
2385
+ const Dep =
2386
+ /** @type {DependencyConstructor} */
2387
+ (dependency.constructor);
2173
2388
  const moduleFactory = this.dependencyFactories.get(Dep);
2174
2389
  if (!moduleFactory) {
2175
2390
  return callback(
@@ -2247,6 +2462,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2247
2462
  */
2248
2463
  _addEntryItem(context, entry, target, options, callback) {
2249
2464
  const { name } = options;
2465
+ /** @type {EntryData | undefined} */
2250
2466
  let entryData =
2251
2467
  name !== undefined ? this.entries.get(name) : this.globalEntry;
2252
2468
  if (entryData === undefined) {
@@ -2260,12 +2476,14 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2260
2476
  };
2261
2477
  entryData[target].push(entry);
2262
2478
  this.entries.set(
2263
- /** @type {NonNullable<EntryOptions["name"]>} */ (name),
2479
+ /** @type {NonNullable<EntryOptions["name"]>} */
2480
+ (name),
2264
2481
  entryData
2265
2482
  );
2266
2483
  } else {
2267
2484
  entryData[target].push(entry);
2268
- for (const key of Object.keys(options)) {
2485
+ for (const key_ of Object.keys(options)) {
2486
+ const key = /** @type {keyof EntryOptions} */ (key_);
2269
2487
  if (options[key] === undefined) continue;
2270
2488
  if (entryData.options[key] === options[key]) continue;
2271
2489
  if (
@@ -2276,7 +2494,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2276
2494
  continue;
2277
2495
  }
2278
2496
  if (entryData.options[key] === undefined) {
2279
- entryData.options[key] = options[key];
2497
+ /** @type {EntryOptions[keyof EntryOptions]} */
2498
+ (entryData.options[key]) = options[key];
2280
2499
  } else {
2281
2500
  return callback(
2282
2501
  new WebpackError(
@@ -2302,7 +2521,12 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2302
2521
  this.hooks.failedEntry.call(entry, options, err);
2303
2522
  return callback(err);
2304
2523
  }
2305
- this.hooks.succeedEntry.call(entry, options, module);
2524
+ this.hooks.succeedEntry.call(
2525
+ entry,
2526
+ options,
2527
+ /** @type {Module} */
2528
+ (module)
2529
+ );
2306
2530
  return callback(null, module);
2307
2531
  }
2308
2532
  );
@@ -2324,13 +2548,13 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2324
2548
  */
2325
2549
  _rebuildModule(module, callback) {
2326
2550
  this.hooks.rebuildModule.call(module);
2327
- const oldDependencies = module.dependencies.slice();
2328
- const oldBlocks = module.blocks.slice();
2551
+ const oldDependencies = [...module.dependencies];
2552
+ const oldBlocks = [...module.blocks];
2329
2553
  module.invalidateBuild();
2330
2554
  this.buildQueue.invalidate(module);
2331
- this.buildModule(module, err => {
2555
+ this.buildModule(module, (err) => {
2332
2556
  if (err) {
2333
- return this.hooks.finishRebuildingModule.callAsync(module, err2 => {
2557
+ return this.hooks.finishRebuildingModule.callAsync(module, (err2) => {
2334
2558
  if (err2) {
2335
2559
  callback(
2336
2560
  makeWebpackError(err2, "Compilation.hooks.finishRebuildingModule")
@@ -2343,13 +2567,13 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2343
2567
 
2344
2568
  this.processDependenciesQueue.invalidate(module);
2345
2569
  this.moduleGraph.unfreeze();
2346
- this.processModuleDependencies(module, err => {
2570
+ this.processModuleDependencies(module, (err) => {
2347
2571
  if (err) return callback(err);
2348
2572
  this.removeReasonsOfDependencyBlock(module, {
2349
2573
  dependencies: oldDependencies,
2350
2574
  blocks: oldBlocks
2351
2575
  });
2352
- this.hooks.finishRebuildingModule.callAsync(module, err2 => {
2576
+ this.hooks.finishRebuildingModule.callAsync(module, (err2) => {
2353
2577
  if (err2) {
2354
2578
  callback(
2355
2579
  makeWebpackError(err2, "Compilation.hooks.finishRebuildingModule")
@@ -2384,10 +2608,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2384
2608
 
2385
2609
  /**
2386
2610
  * @param {Module} module module
2387
- * @returns {References | undefined} references
2611
+ * @returns {WeakReferences | undefined} references
2388
2612
  */
2389
- const computeReferences = module => {
2390
- /** @type {References | undefined} */
2613
+ const computeReferences = (module) => {
2614
+ /** @type {WeakReferences | undefined} */
2391
2615
  let references;
2392
2616
  for (const connection of moduleGraph.getOutgoingConnections(module)) {
2393
2617
  const d = connection.dependency;
@@ -2401,7 +2625,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2401
2625
 
2402
2626
  /**
2403
2627
  * @param {Module} module the module
2404
- * @param {References | undefined} references references
2628
+ * @param {WeakReferences | undefined} references references
2405
2629
  * @returns {boolean} true, when the references differ
2406
2630
  */
2407
2631
  const compareReferences = (module, references) => {
@@ -2423,6 +2647,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2423
2647
  if (buildInfo) {
2424
2648
  if (cachedMemCache.buildInfo !== buildInfo) {
2425
2649
  // use a new one
2650
+ /** @type {MemCache} */
2426
2651
  const memCache = new WeakTupleMap();
2427
2652
  moduleMemCaches.set(module, memCache);
2428
2653
  affectedModules.add(module);
@@ -2432,6 +2657,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2432
2657
  statChanged++;
2433
2658
  } else if (!compareReferences(module, cachedMemCache.references)) {
2434
2659
  // use a new one
2660
+ /** @type {MemCache} */
2435
2661
  const memCache = new WeakTupleMap();
2436
2662
  moduleMemCaches.set(module, memCache);
2437
2663
  affectedModules.add(module);
@@ -2474,10 +2700,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2474
2700
  }
2475
2701
 
2476
2702
  /**
2477
- * @param {readonly ModuleGraphConnection[]} connections connections
2478
- * @returns {symbol|boolean} result
2703
+ * @param {Readonly<ModuleGraphConnection[]>} connections connections
2704
+ * @returns {symbol | boolean} result
2479
2705
  */
2480
- const reduceAffectType = connections => {
2706
+ const reduceAffectType = (connections) => {
2481
2707
  let affected = false;
2482
2708
  for (const { dependency } of connections) {
2483
2709
  if (!dependency) continue;
@@ -2522,6 +2748,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2522
2748
  } else {
2523
2749
  affectedModules.add(referencingModule);
2524
2750
  }
2751
+ /** @type {MemCache} */
2525
2752
  const memCache = new WeakTupleMap();
2526
2753
  const cache =
2527
2754
  /** @type {ModuleMemCachesItem} */
@@ -2554,13 +2781,13 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2554
2781
  let statNew = 0;
2555
2782
  /**
2556
2783
  * @param {Module} module module
2557
- * @returns {{ id: ModuleId, modules?: Map<Module, string | number | undefined>, blocks?: (string | number | null)[] }} references
2784
+ * @returns {References} references
2558
2785
  */
2559
- const computeReferences = module => {
2786
+ const computeReferences = (module) => {
2560
2787
  const id = /** @type {ModuleId} */ (chunkGraph.getModuleId(module));
2561
- /** @type {Map<Module, string | number | undefined> | undefined} */
2788
+ /** @type {Map<Module, ModuleId> | undefined} */
2562
2789
  let modules;
2563
- /** @type {(string | number | null)[] | undefined} */
2790
+ /** @type {(ChunkId | null)[] | undefined} */
2564
2791
  let blocks;
2565
2792
  const outgoing = moduleGraph.getOutgoingConnectionsByModule(module);
2566
2793
  if (outgoing !== undefined) {
@@ -2572,7 +2799,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2572
2799
  }
2573
2800
  if (module.blocks.length > 0) {
2574
2801
  blocks = [];
2575
- const queue = Array.from(module.blocks);
2802
+ const queue = [...module.blocks];
2576
2803
  for (const block of queue) {
2577
2804
  const chunkGroup = chunkGraph.getBlockChunkGroup(block);
2578
2805
  if (chunkGroup) {
@@ -2604,7 +2831,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2604
2831
  }
2605
2832
  }
2606
2833
  if (blocks !== undefined) {
2607
- const queue = Array.from(module.blocks);
2834
+ const queue = [...module.blocks];
2608
2835
  let i = 0;
2609
2836
  for (const block of queue) {
2610
2837
  const chunkGroup = chunkGraph.getBlockChunkGroup(block);
@@ -2624,9 +2851,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2624
2851
  };
2625
2852
 
2626
2853
  for (const [module, memCache] of moduleMemCaches) {
2627
- /** @type {{ references: { id: string | number, modules?: Map<Module, string | number | undefined>, blocks?: (string | number | null)[]}, memCache: WeakTupleMap<any[], any> }} */
2854
+ /** @type {{ references: References, memCache: MemCache } | undefined} */
2628
2855
  const cache = memCache.get(key);
2629
2856
  if (cache === undefined) {
2857
+ /** @type {WeakTupleMap<Module[], RuntimeRequirements | null> | undefined} */
2630
2858
  const memCache2 = new WeakTupleMap();
2631
2859
  memCache.set(key, {
2632
2860
  references: computeReferences(module),
@@ -2635,6 +2863,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2635
2863
  moduleMemCaches2.set(module, memCache2);
2636
2864
  statNew++;
2637
2865
  } else if (!compareReferences(module, cache.references)) {
2866
+ /** @type {WeakTupleMap<Module[], RuntimeRequirements | null> | undefined} */
2638
2867
  const memCache = new WeakTupleMap();
2639
2868
  cache.references = computeReferences(module);
2640
2869
  cache.memCache = memCache;
@@ -2660,7 +2889,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2660
2889
  this.factorizeQueue.clear();
2661
2890
  if (this.profile) {
2662
2891
  this.logger.time("finish module profiles");
2892
+
2663
2893
  const ParallelismFactorCalculator = require("./util/ParallelismFactorCalculator");
2894
+
2664
2895
  const p = new ParallelismFactorCalculator();
2665
2896
  const moduleGraph = this.moduleGraph;
2666
2897
  /** @type {Map<Module, ModuleProfile>} */
@@ -2672,27 +2903,27 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2672
2903
  p.range(
2673
2904
  profile.buildingStartTime,
2674
2905
  profile.buildingEndTime,
2675
- f => (profile.buildingParallelismFactor = f)
2906
+ (f) => (profile.buildingParallelismFactor = f)
2676
2907
  );
2677
2908
  p.range(
2678
2909
  profile.factoryStartTime,
2679
2910
  profile.factoryEndTime,
2680
- f => (profile.factoryParallelismFactor = f)
2911
+ (f) => (profile.factoryParallelismFactor = f)
2681
2912
  );
2682
2913
  p.range(
2683
2914
  profile.integrationStartTime,
2684
2915
  profile.integrationEndTime,
2685
- f => (profile.integrationParallelismFactor = f)
2916
+ (f) => (profile.integrationParallelismFactor = f)
2686
2917
  );
2687
2918
  p.range(
2688
2919
  profile.storingStartTime,
2689
2920
  profile.storingEndTime,
2690
- f => (profile.storingParallelismFactor = f)
2921
+ (f) => (profile.storingParallelismFactor = f)
2691
2922
  );
2692
2923
  p.range(
2693
2924
  profile.restoringStartTime,
2694
2925
  profile.restoringEndTime,
2695
- f => (profile.restoringParallelismFactor = f)
2926
+ (f) => (profile.restoringParallelismFactor = f)
2696
2927
  );
2697
2928
  if (profile.additionalFactoryTimes) {
2698
2929
  for (const { start, end } of profile.additionalFactoryTimes) {
@@ -2700,7 +2931,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2700
2931
  p.range(
2701
2932
  start,
2702
2933
  end,
2703
- f =>
2934
+ (f) =>
2704
2935
  (profile.additionalFactoriesParallelismFactor += f * influence)
2705
2936
  );
2706
2937
  }
@@ -2823,33 +3054,33 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2823
3054
  };
2824
3055
  logNormalSummary(
2825
3056
  "resolve to new modules",
2826
- p => p.factory,
2827
- p => p.factoryParallelismFactor
3057
+ (p) => p.factory,
3058
+ (p) => p.factoryParallelismFactor
2828
3059
  );
2829
3060
  logNormalSummary(
2830
3061
  "resolve to existing modules",
2831
- p => p.additionalFactories,
2832
- p => p.additionalFactoriesParallelismFactor
3062
+ (p) => p.additionalFactories,
3063
+ (p) => p.additionalFactoriesParallelismFactor
2833
3064
  );
2834
3065
  logNormalSummary(
2835
3066
  "integrate modules",
2836
- p => p.restoring,
2837
- p => p.restoringParallelismFactor
3067
+ (p) => p.restoring,
3068
+ (p) => p.restoringParallelismFactor
2838
3069
  );
2839
3070
  logByLoadersSummary(
2840
3071
  "build modules",
2841
- p => p.building,
2842
- p => p.buildingParallelismFactor
3072
+ (p) => p.building,
3073
+ (p) => p.buildingParallelismFactor
2843
3074
  );
2844
3075
  logNormalSummary(
2845
3076
  "store modules",
2846
- p => p.storing,
2847
- p => p.storingParallelismFactor
3077
+ (p) => p.storing,
3078
+ (p) => p.storingParallelismFactor
2848
3079
  );
2849
3080
  logNormalSummary(
2850
3081
  "restore modules",
2851
- p => p.restoring,
2852
- p => p.restoringParallelismFactor
3082
+ (p) => p.restoring,
3083
+ (p) => p.restoringParallelismFactor
2853
3084
  );
2854
3085
  this.logger.timeEnd("finish module profiles");
2855
3086
  }
@@ -2858,7 +3089,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2858
3089
  this.logger.timeEnd("compute affected modules");
2859
3090
  this.logger.time("finish modules");
2860
3091
  const { modules, moduleMemCaches } = this;
2861
- this.hooks.finishModules.callAsync(modules, err => {
3092
+ this.hooks.finishModules.callAsync(modules, (err) => {
2862
3093
  this.logger.timeEnd("finish modules");
2863
3094
  if (err) return callback(/** @type {WebpackError} */ (err));
2864
3095
 
@@ -2929,7 +3160,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2929
3160
  * @param {WebpackError=} err err
2930
3161
  * @returns {void}
2931
3162
  */
2932
- const finalCallback = err => {
3163
+ const finalCallback = (err) => {
2933
3164
  this.factorizeQueue.clear();
2934
3165
  this.buildQueue.clear();
2935
3166
  this.rebuildQueue.clear();
@@ -2937,15 +3168,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2937
3168
  this.addModuleQueue.clear();
2938
3169
  return callback(err);
2939
3170
  };
2940
- const chunkGraph = new ChunkGraph(
2941
- this.moduleGraph,
2942
- this.outputOptions.hashFunction
2943
- );
2944
- this.chunkGraph = chunkGraph;
2945
3171
 
2946
3172
  if (this._backCompat) {
2947
3173
  for (const module of this.modules) {
2948
- ChunkGraph.setChunkGraphForModule(module, chunkGraph);
3174
+ ChunkGraph.setChunkGraphForModule(module, this.chunkGraph);
2949
3175
  }
2950
3176
  }
2951
3177
 
@@ -2981,11 +3207,16 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2981
3207
 
2982
3208
  const entryModules = new Set();
2983
3209
  for (const dep of [...this.globalEntry.dependencies, ...dependencies]) {
2984
- entrypoint.addOrigin(null, { name }, /** @type {any} */ (dep).request);
3210
+ entrypoint.addOrigin(
3211
+ null,
3212
+ { name },
3213
+ /** @type {Dependency & { request: string }} */
3214
+ (dep).request
3215
+ );
2985
3216
 
2986
3217
  const module = this.moduleGraph.getModule(dep);
2987
3218
  if (module) {
2988
- chunkGraph.connectChunkAndEntryModule(chunk, module, entrypoint);
3219
+ this.chunkGraph.connectChunkAndEntryModule(chunk, module, entrypoint);
2989
3220
  entryModules.add(module);
2990
3221
  const modulesList = chunkGraphInit.get(entrypoint);
2991
3222
  if (modulesList === undefined) {
@@ -3002,11 +3233,11 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3002
3233
  * @param {Dependency[]} deps deps
3003
3234
  * @returns {Module[]} sorted deps
3004
3235
  */
3005
- const mapAndSort = deps =>
3236
+ const mapAndSort = (deps) =>
3006
3237
  /** @type {Module[]} */
3007
- (deps.map(dep => this.moduleGraph.getModule(dep)).filter(Boolean)).sort(
3008
- compareModulesByIdentifier
3009
- );
3238
+ (
3239
+ deps.map((dep) => this.moduleGraph.getModule(dep)).filter(Boolean)
3240
+ ).sort(compareModulesByIdentifier);
3010
3241
  const includedModules = [
3011
3242
  ...mapAndSort(this.globalEntry.includeDependencies),
3012
3243
  ...mapAndSort(includeDependencies)
@@ -3043,7 +3274,6 @@ Remove the 'runtime' option from the entrypoint.`);
3043
3274
  const referencedChunks = entry
3044
3275
  .getEntrypointChunk()
3045
3276
  .getAllReferencedChunks();
3046
- const dependOnEntries = [];
3047
3277
  for (const dep of dependOn) {
3048
3278
  const dependency = this.entrypoints.get(dep);
3049
3279
  if (!dependency) {
@@ -3061,9 +3291,7 @@ Remove the 'runtime' option from the entrypoint.`);
3061
3291
  entry.setRuntimeChunk(entryChunk);
3062
3292
  continue outer;
3063
3293
  }
3064
- dependOnEntries.push(dependency);
3065
- }
3066
- for (const dependency of dependOnEntries) {
3294
+ connectEntrypointAndDependOn(entry, dependency);
3067
3295
  connectChunkGroupParentAndChild(dependency, entry);
3068
3296
  }
3069
3297
  } else if (runtime) {
@@ -3096,6 +3324,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3096
3324
  entry.setRuntimeChunk(chunk);
3097
3325
  }
3098
3326
  }
3327
+
3099
3328
  buildChunkGraph(this, chunkGraphInit);
3100
3329
  this.hooks.afterChunks.call(this.chunks);
3101
3330
  this.logger.timeEnd("create chunks");
@@ -3113,7 +3342,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3113
3342
  }
3114
3343
  this.hooks.afterOptimizeChunks.call(this.chunks, this.chunkGroups);
3115
3344
 
3116
- this.hooks.optimizeTree.callAsync(this.chunks, this.modules, err => {
3345
+ this.hooks.optimizeTree.callAsync(this.chunks, this.modules, (err) => {
3117
3346
  if (err) {
3118
3347
  return finalCallback(
3119
3348
  makeWebpackError(err, "Compilation.hooks.optimizeTree")
@@ -3125,7 +3354,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3125
3354
  this.hooks.optimizeChunkModules.callAsync(
3126
3355
  this.chunks,
3127
3356
  this.modules,
3128
- err => {
3357
+ (err) => {
3129
3358
  if (err) {
3130
3359
  return finalCallback(
3131
3360
  makeWebpackError(err, "Compilation.hooks.optimizeChunkModules")
@@ -3136,13 +3365,21 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3136
3365
 
3137
3366
  const shouldRecord = this.hooks.shouldRecord.call() !== false;
3138
3367
 
3139
- this.hooks.reviveModules.call(this.modules, this.records);
3368
+ this.hooks.reviveModules.call(
3369
+ this.modules,
3370
+ /** @type {Records} */
3371
+ (this.records)
3372
+ );
3140
3373
  this.hooks.beforeModuleIds.call(this.modules);
3141
3374
  this.hooks.moduleIds.call(this.modules);
3142
3375
  this.hooks.optimizeModuleIds.call(this.modules);
3143
3376
  this.hooks.afterOptimizeModuleIds.call(this.modules);
3144
3377
 
3145
- this.hooks.reviveChunks.call(this.chunks, this.records);
3378
+ this.hooks.reviveChunks.call(
3379
+ this.chunks,
3380
+ /** @type {Records} */
3381
+ (this.records)
3382
+ );
3146
3383
  this.hooks.beforeChunkIds.call(this.chunks);
3147
3384
  this.hooks.chunkIds.call(this.chunks);
3148
3385
  this.hooks.optimizeChunkIds.call(this.chunks);
@@ -3157,8 +3394,16 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3157
3394
  this.sortItemsWithChunkIds();
3158
3395
 
3159
3396
  if (shouldRecord) {
3160
- this.hooks.recordModules.call(this.modules, this.records);
3161
- this.hooks.recordChunks.call(this.chunks, this.records);
3397
+ this.hooks.recordModules.call(
3398
+ this.modules,
3399
+ /** @type {Records} */
3400
+ (this.records)
3401
+ );
3402
+ this.hooks.recordChunks.call(
3403
+ this.chunks,
3404
+ /** @type {Records} */
3405
+ (this.records)
3406
+ );
3162
3407
  }
3163
3408
 
3164
3409
  this.hooks.optimizeCodeGeneration.call(this.modules);
@@ -3172,7 +3417,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3172
3417
 
3173
3418
  this.logger.time("code generation");
3174
3419
  this.hooks.beforeCodeGeneration.call();
3175
- this.codeGeneration(err => {
3420
+ this.codeGeneration((err) => {
3176
3421
  if (err) {
3177
3422
  return finalCallback(err);
3178
3423
  }
@@ -3191,14 +3436,17 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3191
3436
  this.hooks.afterHash.call();
3192
3437
  this.logger.timeEnd("hashing");
3193
3438
 
3194
- this._runCodeGenerationJobs(codeGenerationJobs, err => {
3439
+ this._runCodeGenerationJobs(codeGenerationJobs, (err) => {
3195
3440
  if (err) {
3196
3441
  return finalCallback(err);
3197
3442
  }
3198
3443
 
3199
3444
  if (shouldRecord) {
3200
3445
  this.logger.time("record hash");
3201
- this.hooks.recordHash.call(this.records);
3446
+ this.hooks.recordHash.call(
3447
+ /** @type {Records} */
3448
+ (this.records)
3449
+ );
3202
3450
  this.logger.timeEnd("record hash");
3203
3451
  }
3204
3452
 
@@ -3211,7 +3459,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3211
3459
 
3212
3460
  const cont = () => {
3213
3461
  this.logger.time("process assets");
3214
- this.hooks.processAssets.callAsync(this.assets, err => {
3462
+ this.hooks.processAssets.callAsync(this.assets, (err) => {
3215
3463
  if (err) {
3216
3464
  return finalCallback(
3217
3465
  makeWebpackError(err, "Compilation.hooks.processAssets")
@@ -3219,29 +3467,35 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3219
3467
  }
3220
3468
  this.hooks.afterProcessAssets.call(this.assets);
3221
3469
  this.logger.timeEnd("process assets");
3222
- this.assets = /** @type {CompilationAssets} */ (
3223
- this._backCompat
3224
- ? soonFrozenObjectDeprecation(
3225
- this.assets,
3226
- "Compilation.assets",
3227
- "DEP_WEBPACK_COMPILATION_ASSETS",
3228
- `BREAKING CHANGE: No more changes should happen to Compilation.assets after sealing the Compilation.
3470
+ this.assets =
3471
+ /** @type {CompilationAssets} */
3472
+ (
3473
+ this._backCompat
3474
+ ? soonFrozenObjectDeprecation(
3475
+ this.assets,
3476
+ "Compilation.assets",
3477
+ "DEP_WEBPACK_COMPILATION_ASSETS",
3478
+ `BREAKING CHANGE: No more changes should happen to Compilation.assets after sealing the Compilation.
3229
3479
  Do changes to assets earlier, e. g. in Compilation.hooks.processAssets.
3230
3480
  Make sure to select an appropriate stage from Compilation.PROCESS_ASSETS_STAGE_*.`
3231
- )
3232
- : Object.freeze(this.assets)
3233
- );
3481
+ )
3482
+ : Object.freeze(this.assets)
3483
+ );
3234
3484
 
3235
3485
  this.summarizeDependencies();
3236
3486
  if (shouldRecord) {
3237
- this.hooks.record.call(this, this.records);
3487
+ this.hooks.record.call(
3488
+ this,
3489
+ /** @type {Records} */
3490
+ (this.records)
3491
+ );
3238
3492
  }
3239
3493
 
3240
3494
  if (this.hooks.needAdditionalSeal.call()) {
3241
3495
  this.unseal();
3242
3496
  return this.seal(callback);
3243
3497
  }
3244
- return this.hooks.afterSeal.callAsync(err => {
3498
+ return this.hooks.afterSeal.callAsync((err) => {
3245
3499
  if (err) {
3246
3500
  return finalCallback(
3247
3501
  makeWebpackError(err, "Compilation.hooks.afterSeal")
@@ -3256,7 +3510,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3256
3510
  this.logger.time("create chunk assets");
3257
3511
  if (this.hooks.shouldGenerateChunkAssets.call() !== false) {
3258
3512
  this.hooks.beforeChunkAssets.call();
3259
- this.createChunkAssets(err => {
3513
+ this.createChunkAssets((err) => {
3260
3514
  this.logger.timeEnd("create chunk assets");
3261
3515
  if (err) {
3262
3516
  return finalCallback(err);
@@ -3281,18 +3535,13 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3281
3535
  */
3282
3536
  reportDependencyErrorsAndWarnings(module, blocks) {
3283
3537
  let hasProblems = false;
3284
- for (let indexBlock = 0; indexBlock < blocks.length; indexBlock++) {
3285
- const block = blocks[indexBlock];
3538
+ for (const block of blocks) {
3286
3539
  const dependencies = block.dependencies;
3287
3540
 
3288
- for (let indexDep = 0; indexDep < dependencies.length; indexDep++) {
3289
- const d = dependencies[indexDep];
3290
-
3541
+ for (const d of dependencies) {
3291
3542
  const warnings = d.getWarnings(this.moduleGraph);
3292
3543
  if (warnings) {
3293
- for (let indexWar = 0; indexWar < warnings.length; indexWar++) {
3294
- const w = warnings[indexWar];
3295
-
3544
+ for (const w of warnings) {
3296
3545
  const warning = new ModuleDependencyWarning(module, w, d.loc);
3297
3546
  this.warnings.push(warning);
3298
3547
  hasProblems = true;
@@ -3300,9 +3549,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3300
3549
  }
3301
3550
  const errors = d.getErrors(this.moduleGraph);
3302
3551
  if (errors) {
3303
- for (let indexErr = 0; indexErr < errors.length; indexErr++) {
3304
- const e = errors[indexErr];
3305
-
3552
+ for (const e of errors) {
3306
3553
  const error = new ModuleDependencyError(module, e, d.loc);
3307
3554
  this.errors.push(error);
3308
3555
  hasProblems = true;
@@ -3310,8 +3557,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3310
3557
  }
3311
3558
  }
3312
3559
 
3313
- if (this.reportDependencyErrorsAndWarnings(module, block.blocks))
3560
+ if (this.reportDependencyErrorsAndWarnings(module, block.blocks)) {
3314
3561
  hasProblems = true;
3562
+ }
3315
3563
  }
3316
3564
  return hasProblems;
3317
3565
  }
@@ -3367,7 +3615,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3367
3615
  let statModulesGenerated = 0;
3368
3616
  const { chunkGraph, moduleGraph, dependencyTemplates, runtimeTemplate } =
3369
3617
  this;
3370
- const results = this.codeGenerationResults;
3618
+ const results =
3619
+ /** @type {CodeGenerationResults} */
3620
+ (this.codeGenerationResults);
3371
3621
  /** @type {WebpackError[]} */
3372
3622
  const errors = [];
3373
3623
  /** @type {NotCodeGeneratedModules | undefined} */
@@ -3378,15 +3628,14 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3378
3628
  let delayedModules = new Set();
3379
3629
  asyncLib.eachLimit(
3380
3630
  jobs,
3381
- /** @type {number} */
3382
- (this.options.parallelism),
3631
+ this.options.parallelism,
3383
3632
  (job, callback) => {
3384
3633
  const { module } = job;
3385
3634
  const { codeGenerationDependencies } = module;
3386
3635
  if (
3387
3636
  codeGenerationDependencies !== undefined &&
3388
3637
  (notCodeGeneratedModules === undefined ||
3389
- codeGenerationDependencies.some(dep => {
3638
+ codeGenerationDependencies.some((dep) => {
3390
3639
  const referencedModule = /** @type {Module} */ (
3391
3640
  moduleGraph.getModule(dep)
3392
3641
  );
@@ -3418,7 +3667,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3418
3667
  }
3419
3668
  );
3420
3669
  },
3421
- err => {
3670
+ (err) => {
3422
3671
  if (err) return callback(err);
3423
3672
  if (delayedJobs.length > 0) {
3424
3673
  if (delayedJobs.length === jobs.length) {
@@ -3427,7 +3676,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3427
3676
  new Error(
3428
3677
  `Unable to make progress during code generation because of circular code generation dependency: ${Array.from(
3429
3678
  delayedModules,
3430
- m => m.identifier()
3679
+ (m) => m.identifier()
3431
3680
  ).join(", ")}`
3432
3681
  )
3433
3682
  )
@@ -3441,7 +3690,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3441
3690
  }
3442
3691
  if (errors.length > 0) {
3443
3692
  errors.sort(
3444
- compareSelect(err => err.module, compareModulesByIdentifier)
3693
+ compareSelect((err) => err.module, compareModulesByIdentifier)
3445
3694
  );
3446
3695
  for (const error of errors) {
3447
3696
  this.errors.push(error);
@@ -3471,7 +3720,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3471
3720
  * @param {RuntimeTemplate} runtimeTemplate runtimeTemplate
3472
3721
  * @param {WebpackError[]} errors errors
3473
3722
  * @param {CodeGenerationResults} results results
3474
- * @param {function((WebpackError | null)=, boolean=): void} callback callback
3723
+ * @param {(err?: WebpackError | null, result?: boolean) => void} callback callback
3475
3724
  */
3476
3725
  _codeGenerationModule(
3477
3726
  module,
@@ -3488,7 +3737,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3488
3737
  ) {
3489
3738
  let codeGenerated = false;
3490
3739
  const cache = new MultiItemCache(
3491
- runtimes.map(runtime =>
3740
+ runtimes.map((runtime) =>
3492
3741
  this._codeGenerationCache.getItemCache(
3493
3742
  `${module.identifier()}|${getRuntimeKey(runtime)}`,
3494
3743
  `${hash}|${dependencyTemplates.getHash()}`
@@ -3508,6 +3757,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3508
3757
  dependencyTemplates,
3509
3758
  runtimeTemplate,
3510
3759
  runtime,
3760
+ runtimes,
3511
3761
  codeGenerationResults: results,
3512
3762
  compilation: this
3513
3763
  });
@@ -3527,7 +3777,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3527
3777
  results.add(module, runtime, result);
3528
3778
  }
3529
3779
  if (!cachedResult) {
3530
- cache.store(result, err =>
3780
+ cache.store(result, (err) =>
3531
3781
  callback(/** @type {WebpackError} */ (err), codeGenerated)
3532
3782
  );
3533
3783
  } else {
@@ -3563,7 +3813,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3563
3813
  chunkGraph = this.chunkGraph,
3564
3814
  modules = this.modules,
3565
3815
  chunks = this.chunks,
3566
- codeGenerationResults = this.codeGenerationResults,
3816
+ codeGenerationResults = /** @type {CodeGenerationResults} */ (
3817
+ this.codeGenerationResults
3818
+ ),
3567
3819
  chunkGraphEntries = this._getChunkGraphEntries()
3568
3820
  } = {}) {
3569
3821
  const context = { chunkGraph, codeGenerationResults };
@@ -3585,7 +3837,8 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3585
3837
  chunkGraph.addModuleRuntimeRequirements(
3586
3838
  module,
3587
3839
  runtime,
3588
- cached,
3840
+ /** @type {RuntimeRequirements} */
3841
+ (cached),
3589
3842
  false
3590
3843
  );
3591
3844
  }
@@ -3642,6 +3895,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3642
3895
 
3643
3896
  this.logger.time("runtime requirements.chunks");
3644
3897
  for (const chunk of chunks) {
3898
+ /** @type {RuntimeRequirements} */
3645
3899
  const set = new Set();
3646
3900
  for (const module of chunkGraph.getChunkModulesIterable(chunk)) {
3647
3901
  const runtimeRequirements = chunkGraph.getModuleRuntimeRequirements(
@@ -3662,6 +3916,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3662
3916
 
3663
3917
  this.logger.time("runtime requirements.entries");
3664
3918
  for (const treeEntry of chunkGraphEntries) {
3919
+ /** @type {RuntimeRequirements} */
3665
3920
  const set = new Set();
3666
3921
  for (const chunk of treeEntry.getAllReferencedChunks()) {
3667
3922
  const runtimeRequirements =
@@ -3695,8 +3950,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3695
3950
  */
3696
3951
  addRuntimeModule(chunk, module, chunkGraph = this.chunkGraph) {
3697
3952
  // Deprecated ModuleGraph association
3698
- if (this._backCompat)
3953
+ if (this._backCompat) {
3699
3954
  ModuleGraph.setModuleGraphForModule(module, this.moduleGraph);
3955
+ }
3700
3956
 
3701
3957
  // add it to the list
3702
3958
  this.modules.add(module);
@@ -3752,7 +4008,6 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3752
4008
  groupOptions = { name: groupOptions };
3753
4009
  }
3754
4010
  const name = groupOptions.name;
3755
-
3756
4011
  if (name) {
3757
4012
  const chunkGroup = this.namedChunkGroups.get(name);
3758
4013
  if (chunkGroup !== undefined) {
@@ -3761,20 +4016,23 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3761
4016
  module,
3762
4017
  /** @type {DependencyLocation} */
3763
4018
  (loc),
3764
- request
4019
+ /** @type {string} */
4020
+ (request)
3765
4021
  );
3766
4022
  }
3767
4023
  return chunkGroup;
3768
4024
  }
3769
4025
  }
3770
4026
  const chunkGroup = new ChunkGroup(groupOptions);
3771
- if (module)
4027
+ if (module) {
3772
4028
  chunkGroup.addOrigin(
3773
4029
  module,
3774
4030
  /** @type {DependencyLocation} */
3775
4031
  (loc),
3776
- request
4032
+ /** @type {string} */
4033
+ (request)
3777
4034
  );
4035
+ }
3778
4036
  const chunk = this.addChunk(name);
3779
4037
 
3780
4038
  connectChunkGroupAndChunk(chunkGroup, chunk);
@@ -3798,12 +4056,10 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3798
4056
  if (name) {
3799
4057
  const entrypoint = this.namedChunkGroups.get(name);
3800
4058
  if (entrypoint instanceof Entrypoint) {
3801
- if (entrypoint !== undefined) {
3802
- if (module) {
3803
- entrypoint.addOrigin(module, loc, request);
3804
- }
3805
- return entrypoint;
4059
+ if (module) {
4060
+ entrypoint.addOrigin(module, loc, request);
3806
4061
  }
4062
+ return entrypoint;
3807
4063
  } else if (entrypoint) {
3808
4064
  throw new Error(
3809
4065
  `Cannot add an async entrypoint with the name '${name}', because there is already an chunk group with this name`
@@ -3832,7 +4088,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3832
4088
  /**
3833
4089
  * This method first looks to see if a name is provided for a new chunk,
3834
4090
  * and first looks to see if any named chunks already exist and reuse that chunk instead.
3835
- * @param {string=} name optional chunk name to be provided
4091
+ * @param {ChunkName=} name optional chunk name to be provided
3836
4092
  * @returns {Chunk} create a chunk (invoked during seal event)
3837
4093
  */
3838
4094
  addChunk(name) {
@@ -3844,8 +4100,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3844
4100
  }
3845
4101
  const chunk = new Chunk(name, this._backCompat);
3846
4102
  this.chunks.add(chunk);
3847
- if (this._backCompat)
4103
+ if (this._backCompat) {
3848
4104
  ChunkGraph.setChunkGraphForChunk(chunk, this.chunkGraph);
4105
+ }
3849
4106
  if (name) {
3850
4107
  this.namedChunks.set(name, chunk);
3851
4108
  }
@@ -3870,7 +4127,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3870
4127
  * @param {Module} module module for processing
3871
4128
  * @returns {void}
3872
4129
  */
3873
- const processModule = module => {
4130
+ const processModule = (module) => {
3874
4131
  if (!moduleGraph.setDepthIfLower(module, depth)) return;
3875
4132
  queue.add(module);
3876
4133
  };
@@ -3895,35 +4152,37 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3895
4152
  assignDepths(modules) {
3896
4153
  const moduleGraph = this.moduleGraph;
3897
4154
 
3898
- /** @type {Set<Module | number>} */
4155
+ /** @type {Set<Module>} */
3899
4156
  const queue = new Set(modules);
3900
- queue.add(1);
4157
+ // Track these in local variables so that queue only has one data type
4158
+ let nextDepthAt = queue.size;
3901
4159
  let depth = 0;
3902
4160
 
3903
4161
  let i = 0;
3904
4162
  for (const module of queue) {
3905
- i++;
3906
- if (typeof module === "number") {
3907
- depth = module;
3908
- if (queue.size === i) return;
3909
- queue.add(depth + 1);
3910
- } else {
3911
- moduleGraph.setDepth(module, depth);
3912
- for (const { module: refModule } of moduleGraph.getOutgoingConnections(
3913
- module
3914
- )) {
3915
- if (refModule) {
3916
- queue.add(refModule);
3917
- }
4163
+ moduleGraph.setDepth(module, depth);
4164
+ // Some of these results come from cache, which speeds this up
4165
+ const connections = moduleGraph.getOutgoingConnectionsByModule(module);
4166
+ // connections will be undefined if there are no outgoing connections
4167
+ if (connections) {
4168
+ for (const refModule of connections.keys()) {
4169
+ if (refModule) queue.add(refModule);
3918
4170
  }
3919
4171
  }
4172
+ i++;
4173
+ // Since this is a breadth-first search, all modules added to the queue
4174
+ // while at depth N will be depth N+1
4175
+ if (i >= nextDepthAt) {
4176
+ depth++;
4177
+ nextDepthAt = queue.size;
4178
+ }
3920
4179
  }
3921
4180
  }
3922
4181
 
3923
4182
  /**
3924
4183
  * @param {Dependency} dependency the dependency
3925
4184
  * @param {RuntimeSpec} runtime the runtime
3926
- * @returns {(string[] | ReferencedExport)[]} referenced exports
4185
+ * @returns {ReferencedExports} referenced exports
3927
4186
  */
3928
4187
  getDependencyReferencedExports(dependency, runtime) {
3929
4188
  const referencedExports = dependency.getReferencedExports(
@@ -3939,7 +4198,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3939
4198
 
3940
4199
  /**
3941
4200
  * @param {Module} module module relationship for removal
3942
- * @param {DependenciesBlockLike} block //TODO: good description
4201
+ * @param {DependenciesBlockLike} block dependencies block
3943
4202
  * @returns {void}
3944
4203
  */
3945
4204
  removeReasonsOfDependencyBlock(module, block) {
@@ -3994,7 +4253,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3994
4253
  /**
3995
4254
  * @param {Dependency} d dependency to (maybe) patch up
3996
4255
  */
3997
- const iteratorDependency = d => {
4256
+ const iteratorDependency = (d) => {
3998
4257
  const depModule = this.moduleGraph.getModule(d);
3999
4258
  if (!depModule) {
4000
4259
  return;
@@ -4003,16 +4262,14 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4003
4262
  };
4004
4263
 
4005
4264
  const blocks = block.blocks;
4006
- for (let indexBlock = 0; indexBlock < blocks.length; indexBlock++) {
4007
- const asyncBlock = blocks[indexBlock];
4265
+ for (const asyncBlock of blocks) {
4008
4266
  const chunkGroup =
4009
4267
  /** @type {ChunkGroup} */
4010
4268
  (this.chunkGraph.getBlockChunkGroup(asyncBlock));
4011
4269
  // Grab all chunks from the first Block's AsyncDepBlock
4012
4270
  const chunks = chunkGroup.chunks;
4013
4271
  // For each chunk in chunkGroup
4014
- for (let indexChunk = 0; indexChunk < chunks.length; indexChunk++) {
4015
- const iteratedChunk = chunks[indexChunk];
4272
+ for (const iteratedChunk of chunks) {
4016
4273
  chunkGroup.removeChunk(iteratedChunk);
4017
4274
  // Recurse
4018
4275
  this.removeChunkFromDependencies(block, iteratedChunk);
@@ -4029,7 +4286,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4029
4286
  /**
4030
4287
  * @param {Entrypoint} ep an entrypoint
4031
4288
  */
4032
- const processEntrypoint = ep => {
4289
+ const processEntrypoint = (ep) => {
4033
4290
  const runtime = /** @type {string} */ (ep.options.runtime || ep.name);
4034
4291
  const chunk = /** @type {Chunk} */ (ep.getRuntimeChunk());
4035
4292
  chunkGraph.setRuntimeId(runtime, /** @type {ChunkId} */ (chunk.id));
@@ -4053,13 +4310,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4053
4310
  }
4054
4311
 
4055
4312
  summarizeDependencies() {
4056
- for (
4057
- let indexChildren = 0;
4058
- indexChildren < this.children.length;
4059
- indexChildren++
4060
- ) {
4061
- const child = this.children[indexChildren];
4062
-
4313
+ for (const child of this.children) {
4063
4314
  this.fileDependencies.addAll(child.fileDependencies);
4064
4315
  this.contextDependencies.addAll(child.contextDependencies);
4065
4316
  this.missingDependencies.addAll(child.missingDependencies);
@@ -4087,7 +4338,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4087
4338
  const memCache = moduleMemCaches2 && moduleMemCaches2.get(module);
4088
4339
  for (const runtime of chunkGraph.getModuleRuntimes(module)) {
4089
4340
  if (memCache) {
4090
- const digest = memCache.get(`moduleHash-${getRuntimeKey(runtime)}`);
4341
+ const digest =
4342
+ /** @type {string} */
4343
+ (memCache.get(`moduleHash-${getRuntimeKey(runtime)}`));
4091
4344
  if (digest !== undefined) {
4092
4345
  chunkGraph.setModuleHashes(
4093
4346
  module,
@@ -4116,7 +4369,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4116
4369
  }
4117
4370
  }
4118
4371
  if (errors.length > 0) {
4119
- errors.sort(compareSelect(err => err.module, compareModulesByIdentifier));
4372
+ errors.sort(
4373
+ compareSelect((err) => err.module, compareModulesByIdentifier)
4374
+ );
4120
4375
  for (const error of errors) {
4121
4376
  this.errors.push(error);
4122
4377
  }
@@ -4135,10 +4390,10 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4135
4390
  * @param {Module} module module
4136
4391
  * @param {ChunkGraph} chunkGraph the chunk graph
4137
4392
  * @param {RuntimeSpec} runtime runtime
4138
- * @param {OutputOptions["hashFunction"]} hashFunction hash function
4393
+ * @param {HashFunction} hashFunction hash function
4139
4394
  * @param {RuntimeTemplate} runtimeTemplate runtime template
4140
- * @param {OutputOptions["hashDigest"]} hashDigest hash digest
4141
- * @param {OutputOptions["hashDigestLength"]} hashDigestLength hash digest length
4395
+ * @param {HashDigest} hashDigest hash digest
4396
+ * @param {HashDigestLength} hashDigestLength hash digest length
4142
4397
  * @param {WebpackError[]} errors errors
4143
4398
  * @returns {string} module hash digest
4144
4399
  */
@@ -4154,13 +4409,13 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4154
4409
  ) {
4155
4410
  let moduleHashDigest;
4156
4411
  try {
4157
- const moduleHash = createHash(/** @type {Algorithm} */ (hashFunction));
4412
+ const moduleHash = createHash(hashFunction);
4158
4413
  module.updateHash(moduleHash, {
4159
4414
  chunkGraph,
4160
4415
  runtime,
4161
4416
  runtimeTemplate
4162
4417
  });
4163
- moduleHashDigest = /** @type {string} */ (moduleHash.digest(hashDigest));
4418
+ moduleHashDigest = moduleHash.digest(hashDigest);
4164
4419
  } catch (err) {
4165
4420
  errors.push(new ModuleHashingError(module, /** @type {Error} */ (err)));
4166
4421
  moduleHashDigest = "XXXXXX";
@@ -4182,7 +4437,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4182
4437
  const hashFunction = outputOptions.hashFunction;
4183
4438
  const hashDigest = outputOptions.hashDigest;
4184
4439
  const hashDigestLength = outputOptions.hashDigestLength;
4185
- const hash = createHash(/** @type {Algorithm} */ (hashFunction));
4440
+ const hash = createHash(hashFunction);
4186
4441
  if (outputOptions.hashSalt) {
4187
4442
  hash.update(outputOptions.hashSalt);
4188
4443
  }
@@ -4223,16 +4478,21 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4223
4478
  /** @type {Chunk[]} */
4224
4479
  const unorderedRuntimeChunks = [];
4225
4480
  /** @type {Chunk[]} */
4226
- const otherChunks = [];
4481
+ const initialChunks = [];
4482
+ /** @type {Chunk[]} */
4483
+ const asyncChunks = [];
4227
4484
  for (const c of this.chunks) {
4228
4485
  if (c.hasRuntime()) {
4229
4486
  unorderedRuntimeChunks.push(c);
4487
+ } else if (c.canBeInitial()) {
4488
+ initialChunks.push(c);
4230
4489
  } else {
4231
- otherChunks.push(c);
4490
+ asyncChunks.push(c);
4232
4491
  }
4233
4492
  }
4234
4493
  unorderedRuntimeChunks.sort(byId);
4235
- otherChunks.sort(byId);
4494
+ initialChunks.sort(byId);
4495
+ asyncChunks.sort(byId);
4236
4496
 
4237
4497
  /** @typedef {{ chunk: Chunk, referencedBy: RuntimeChunkInfo[], remaining: number }} RuntimeChunkInfo */
4238
4498
  /** @type {Map<Chunk, RuntimeChunkInfo>} */
@@ -4247,8 +4507,8 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4247
4507
  let remaining = 0;
4248
4508
  for (const info of runtimeChunksMap.values()) {
4249
4509
  for (const other of new Set(
4250
- Array.from(info.chunk.getAllReferencedAsyncEntrypoints()).map(
4251
- e => e.chunks[e.chunks.length - 1]
4510
+ [...info.chunk.getAllReferencedAsyncEntrypoints()].map(
4511
+ (e) => e.chunks[e.chunks.length - 1]
4252
4512
  )
4253
4513
  )) {
4254
4514
  const otherInfo =
@@ -4301,11 +4561,11 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4301
4561
  circularRuntimeChunkInfo.push(info);
4302
4562
  }
4303
4563
  }
4304
- circularRuntimeChunkInfo.sort(compareSelect(i => i.chunk, byId));
4564
+ circularRuntimeChunkInfo.sort(compareSelect((i) => i.chunk, byId));
4305
4565
  const err =
4306
4566
  new WebpackError(`Circular dependency between chunks with runtime (${Array.from(
4307
4567
  circularRuntimeChunkInfo,
4308
- c => c.chunk.name || c.chunk.id
4568
+ (c) => c.chunk.name || c.chunk.id
4309
4569
  ).join(", ")})
4310
4570
  This prevents using hashes of each other and should be avoided.`);
4311
4571
  err.chunk = circularRuntimeChunkInfo[0].chunk;
@@ -4315,9 +4575,9 @@ This prevents using hashes of each other and should be avoided.`);
4315
4575
  this.logger.timeEnd("hashing: sort chunks");
4316
4576
 
4317
4577
  const fullHashChunks = new Set();
4318
- /** @type {{module: Module, hash: string, runtime: RuntimeSpec, runtimes: RuntimeSpec[]}[]} */
4578
+ /** @type {CodeGenerationJobs} */
4319
4579
  const codeGenerationJobs = [];
4320
- /** @type {Map<string, Map<Module, {module: Module, hash: string, runtime: RuntimeSpec, runtimes: RuntimeSpec[]}>>} */
4580
+ /** @type {Map<string, Map<Module, CodeGenerationJob>>} */
4321
4581
  const codeGenerationJobsMap = new Map();
4322
4582
  /** @type {WebpackError[]} */
4323
4583
  const errors = [];
@@ -4325,7 +4585,7 @@ This prevents using hashes of each other and should be avoided.`);
4325
4585
  /**
4326
4586
  * @param {Chunk} chunk chunk
4327
4587
  */
4328
- const processChunk = chunk => {
4588
+ const processChunk = (chunk) => {
4329
4589
  // Last minute module hash generation for modules that depend on chunk hashes
4330
4590
  this.logger.time("hashing: hash runtime modules");
4331
4591
  const runtime = chunk.runtime;
@@ -4365,20 +4625,20 @@ This prevents using hashes of each other and should be avoided.`);
4365
4625
  this.logger.timeAggregate("hashing: hash runtime modules");
4366
4626
  try {
4367
4627
  this.logger.time("hashing: hash chunks");
4368
- const chunkHash = createHash(/** @type {Algorithm} */ (hashFunction));
4628
+ const chunkHash = createHash(hashFunction);
4369
4629
  if (outputOptions.hashSalt) {
4370
4630
  chunkHash.update(outputOptions.hashSalt);
4371
4631
  }
4372
4632
  chunk.updateHash(chunkHash, chunkGraph);
4373
4633
  this.hooks.chunkHash.call(chunk, chunkHash, {
4374
4634
  chunkGraph,
4375
- codeGenerationResults: this.codeGenerationResults,
4635
+ codeGenerationResults:
4636
+ /** @type {CodeGenerationResults} */
4637
+ (this.codeGenerationResults),
4376
4638
  moduleGraph: this.moduleGraph,
4377
4639
  runtimeTemplate: this.runtimeTemplate
4378
4640
  });
4379
- const chunkHashDigest = /** @type {string} */ (
4380
- chunkHash.digest(hashDigest)
4381
- );
4641
+ const chunkHashDigest = chunkHash.digest(hashDigest);
4382
4642
  hash.update(chunkHashDigest);
4383
4643
  chunk.hash = chunkHashDigest;
4384
4644
  chunk.renderedHash = chunk.hash.slice(0, hashDigestLength);
@@ -4396,10 +4656,13 @@ This prevents using hashes of each other and should be avoided.`);
4396
4656
  }
4397
4657
  this.logger.timeAggregate("hashing: hash chunks");
4398
4658
  };
4399
- for (const chunk of otherChunks) processChunk(chunk);
4659
+ for (const chunk of asyncChunks) processChunk(chunk);
4400
4660
  for (const chunk of runtimeChunks) processChunk(chunk);
4661
+ for (const chunk of initialChunks) processChunk(chunk);
4401
4662
  if (errors.length > 0) {
4402
- errors.sort(compareSelect(err => err.module, compareModulesByIdentifier));
4663
+ errors.sort(
4664
+ compareSelect((err) => err.module, compareModulesByIdentifier)
4665
+ );
4403
4666
  for (const error of errors) {
4404
4667
  this.errors.push(error);
4405
4668
  }
@@ -4409,7 +4672,7 @@ This prevents using hashes of each other and should be avoided.`);
4409
4672
  this.logger.timeAggregateEnd("hashing: hash chunks");
4410
4673
  this.logger.time("hashing: hash digest");
4411
4674
  this.hooks.fullHash.call(hash);
4412
- this.fullHash = /** @type {string} */ (hash.digest(hashDigest));
4675
+ this.fullHash = hash.digest(hashDigest);
4413
4676
  this.hash = this.fullHash.slice(0, hashDigestLength);
4414
4677
  this.logger.timeEnd("hashing: hash digest");
4415
4678
 
@@ -4418,15 +4681,13 @@ This prevents using hashes of each other and should be avoided.`);
4418
4681
  for (const module of /** @type {Iterable<RuntimeModule>} */ (
4419
4682
  chunkGraph.getChunkFullHashModulesIterable(chunk)
4420
4683
  )) {
4421
- const moduleHash = createHash(/** @type {Algorithm} */ (hashFunction));
4684
+ const moduleHash = createHash(hashFunction);
4422
4685
  module.updateHash(moduleHash, {
4423
4686
  chunkGraph,
4424
4687
  runtime: chunk.runtime,
4425
4688
  runtimeTemplate
4426
4689
  });
4427
- const moduleHashDigest = /** @type {string} */ (
4428
- moduleHash.digest(hashDigest)
4429
- );
4690
+ const moduleHashDigest = moduleHash.digest(hashDigest);
4430
4691
  const oldHash = chunkGraph.getModuleHash(module, chunk.runtime);
4431
4692
  chunkGraph.setModuleHashes(
4432
4693
  module,
@@ -4434,14 +4695,16 @@ This prevents using hashes of each other and should be avoided.`);
4434
4695
  moduleHashDigest,
4435
4696
  moduleHashDigest.slice(0, hashDigestLength)
4436
4697
  );
4437
- codeGenerationJobsMap.get(oldHash).get(module).hash = moduleHashDigest;
4698
+ /** @type {CodeGenerationJob} */
4699
+ (
4700
+ /** @type {Map<Module, CodeGenerationJob>} */
4701
+ (codeGenerationJobsMap.get(oldHash)).get(module)
4702
+ ).hash = moduleHashDigest;
4438
4703
  }
4439
- const chunkHash = createHash(/** @type {Algorithm} */ (hashFunction));
4704
+ const chunkHash = createHash(hashFunction);
4440
4705
  chunkHash.update(chunk.hash);
4441
4706
  chunkHash.update(this.hash);
4442
- const chunkHashDigest =
4443
- /** @type {string} */
4444
- (chunkHash.digest(hashDigest));
4707
+ const chunkHashDigest = chunkHash.digest(hashDigest);
4445
4708
  chunk.hash = chunkHashDigest;
4446
4709
  chunk.renderedHash = chunk.hash.slice(0, hashDigestLength);
4447
4710
  this.hooks.contentHash.call(chunk);
@@ -4484,7 +4747,7 @@ This prevents using hashes of each other and should be avoided.`);
4484
4747
  /**
4485
4748
  * @private
4486
4749
  * @param {string} file file name
4487
- * @param {AssetInfo} newInfo new asset information
4750
+ * @param {AssetInfo=} newInfo new asset information
4488
4751
  * @param {AssetInfo=} oldInfo old asset information
4489
4752
  */
4490
4753
  _setAssetInfo(file, newInfo, oldInfo = this.assetsInfo.get(file)) {
@@ -4500,7 +4763,7 @@ This prevents using hashes of each other and should be avoided.`);
4500
4763
  /**
4501
4764
  * @param {string} name name
4502
4765
  */
4503
- const remove = name => {
4766
+ const remove = (name) => {
4504
4767
  const relatedIn = this._assetsRelatedIn.get(name);
4505
4768
  if (relatedIn === undefined) return;
4506
4769
  const entry = relatedIn.get(key);
@@ -4525,7 +4788,7 @@ This prevents using hashes of each other and should be avoided.`);
4525
4788
  /**
4526
4789
  * @param {string} name name
4527
4790
  */
4528
- const add = name => {
4791
+ const add = (name) => {
4529
4792
  let relatedIn = this._assetsRelatedIn.get(name);
4530
4793
  if (relatedIn === undefined) {
4531
4794
  this._assetsRelatedIn.set(name, (relatedIn = new Map()));
@@ -4550,8 +4813,8 @@ This prevents using hashes of each other and should be avoided.`);
4550
4813
 
4551
4814
  /**
4552
4815
  * @param {string} file file name
4553
- * @param {Source | function(Source): Source} newSourceOrFunction new asset source or function converting old to new
4554
- * @param {(AssetInfo | function(AssetInfo | undefined): AssetInfo) | undefined} assetInfoUpdateOrFunction new asset info or function converting old to new
4816
+ * @param {Source | ((source: Source) => Source)} newSourceOrFunction new asset source or function converting old to new
4817
+ * @param {(AssetInfo | ((assetInfo?: AssetInfo) => AssetInfo | undefined)) | undefined} assetInfoUpdateOrFunction new asset info or function converting old to new
4555
4818
  */
4556
4819
  updateAsset(
4557
4820
  file,
@@ -4612,10 +4875,12 @@ This prevents using hashes of each other and should be avoided.`);
4612
4875
  const entry = related[key];
4613
4876
  let newEntry;
4614
4877
  if (Array.isArray(entry)) {
4615
- newEntry = entry.map(x => (x === file ? newFile : x));
4878
+ newEntry = entry.map((x) => (x === file ? newFile : x));
4616
4879
  } else if (entry === file) {
4617
4880
  newEntry = newFile;
4618
- } else continue;
4881
+ } else {
4882
+ continue;
4883
+ }
4619
4884
  this.assetsInfo.set(name, {
4620
4885
  ...info,
4621
4886
  related: {
@@ -4664,7 +4929,7 @@ This prevents using hashes of each other and should be avoided.`);
4664
4929
  /**
4665
4930
  * @param {string} file file
4666
4931
  */
4667
- const checkUsedAndDelete = file => {
4932
+ const checkUsedAndDelete = (file) => {
4668
4933
  if (!this._assetsRelatedIn.has(file)) {
4669
4934
  this.deleteAsset(file);
4670
4935
  }
@@ -4777,7 +5042,9 @@ This prevents using hashes of each other and should be avoided.`);
4777
5042
  hash: /** @type {string} */ (this.hash),
4778
5043
  fullHash: /** @type {string} */ (this.fullHash),
4779
5044
  outputOptions,
4780
- codeGenerationResults: this.codeGenerationResults,
5045
+ codeGenerationResults:
5046
+ /** @type {CodeGenerationResults} */
5047
+ (this.codeGenerationResults),
4781
5048
  moduleTemplates: this.moduleTemplates,
4782
5049
  dependencyTemplates: this.dependencyTemplates,
4783
5050
  chunkGraph: this.chunkGraph,
@@ -4794,7 +5061,7 @@ This prevents using hashes of each other and should be avoided.`);
4794
5061
  manifest,
4795
5062
  (fileManifest, callback) => {
4796
5063
  const ident = fileManifest.identifier;
4797
- const usedHash = fileManifest.hash;
5064
+ const usedHash = /** @type {string} */ (fileManifest.hash);
4798
5065
 
4799
5066
  const assetCacheItem = this._assetsCache.getItemCache(
4800
5067
  ident,
@@ -4814,7 +5081,7 @@ This prevents using hashes of each other and should be avoided.`);
4814
5081
  * @param {Error} err error
4815
5082
  * @returns {void}
4816
5083
  */
4817
- const errorAndCallback = err => {
5084
+ const errorAndCallback = (err) => {
4818
5085
  const filename =
4819
5086
  file ||
4820
5087
  (typeof file === "string"
@@ -4895,7 +5162,7 @@ This prevents using hashes of each other and should be avoided.`);
4895
5162
  chunk
4896
5163
  });
4897
5164
  if (source !== sourceFromCache) {
4898
- assetCacheItem.store(source, err => {
5165
+ assetCacheItem.store(source, (err) => {
4899
5166
  if (err) return errorAndCallback(err);
4900
5167
  inTry = false;
4901
5168
  return callback();
@@ -4990,7 +5257,7 @@ This prevents using hashes of each other and should be avoided.`);
4990
5257
  * from parent (or top level compiler) and creates a child Compilation
4991
5258
  * @param {string} name name of the child compiler
4992
5259
  * @param {Partial<OutputOptions>=} outputOptions // Need to convert config schema to types for this
4993
- * @param {Array<WebpackPluginInstance | WebpackPluginFunction>=} plugins webpack plugins that will be applied
5260
+ * @param {Plugins=} plugins webpack plugins that will be applied
4994
5261
  * @returns {Compiler} creates a child Compiler instance
4995
5262
  */
4996
5263
  createChildCompiler(name, outputOptions, plugins) {
@@ -5017,9 +5284,9 @@ This prevents using hashes of each other and should be avoided.`);
5017
5284
  modules,
5018
5285
  10,
5019
5286
  (module, push, callback) => {
5020
- this.buildQueue.waitFor(module, err => {
5287
+ this.buildQueue.waitFor(module, (err) => {
5021
5288
  if (err) return callback(err);
5022
- this.processDependenciesQueue.waitFor(module, err => {
5289
+ this.processDependenciesQueue.waitFor(module, (err) => {
5023
5290
  if (err) return callback(err);
5024
5291
  for (const { module: m } of this.moduleGraph.getOutgoingConnections(
5025
5292
  module
@@ -5032,7 +5299,7 @@ This prevents using hashes of each other and should be avoided.`);
5032
5299
  });
5033
5300
  });
5034
5301
  },
5035
- err => {
5302
+ (err) => {
5036
5303
  if (err) return callback(/** @type {WebpackError} */ (err));
5037
5304
 
5038
5305
  // Create new chunk graph, chunk and entrypoint for the build time execution
@@ -5106,7 +5373,7 @@ This prevents using hashes of each other and should be avoided.`);
5106
5373
  runtimeTemplate,
5107
5374
  errors,
5108
5375
  codeGenerationResults,
5109
- (err, codeGenerated) => {
5376
+ (err, _codeGenerated) => {
5110
5377
  callback(err);
5111
5378
  }
5112
5379
  );
@@ -5115,7 +5382,7 @@ This prevents using hashes of each other and should be avoided.`);
5115
5382
  const reportErrors = () => {
5116
5383
  if (errors.length > 0) {
5117
5384
  errors.sort(
5118
- compareSelect(err => err.module, compareModulesByIdentifier)
5385
+ compareSelect((err) => err.module, compareModulesByIdentifier)
5119
5386
  );
5120
5387
  for (const error of errors) {
5121
5388
  this.errors.push(error);
@@ -5125,7 +5392,7 @@ This prevents using hashes of each other and should be avoided.`);
5125
5392
  };
5126
5393
 
5127
5394
  // Generate code for all aggregated modules
5128
- asyncLib.eachLimit(modules, 10, codeGen, err => {
5395
+ asyncLib.eachLimit(modules, 10, codeGen, (err) => {
5129
5396
  if (err) return callback(err);
5130
5397
  reportErrors();
5131
5398
 
@@ -5161,7 +5428,7 @@ This prevents using hashes of each other and should be avoided.`);
5161
5428
  }
5162
5429
 
5163
5430
  // Generate code for all runtime modules
5164
- asyncLib.eachLimit(runtimeModules, 10, codeGen, err => {
5431
+ asyncLib.eachLimit(runtimeModules, 10, codeGen, (err) => {
5165
5432
  if (err) return callback(err);
5166
5433
  reportErrors();
5167
5434
 
@@ -5205,7 +5472,6 @@ This prevents using hashes of each other and should be avoided.`);
5205
5472
  const moduleArgument = {
5206
5473
  module,
5207
5474
  codeGenerationResult,
5208
- preparedInfo: undefined,
5209
5475
  moduleObject: undefined
5210
5476
  };
5211
5477
  moduleArgumentsMap.set(module, moduleArgument);
@@ -5237,45 +5503,58 @@ This prevents using hashes of each other and should be avoided.`);
5237
5503
  callback
5238
5504
  );
5239
5505
  },
5240
- err => {
5506
+ (err) => {
5241
5507
  if (err) return callback(err);
5242
5508
 
5509
+ /** @type {ExecuteModuleExports | undefined} */
5243
5510
  let exports;
5244
5511
  try {
5245
5512
  const {
5246
5513
  strictModuleErrorHandling,
5247
5514
  strictModuleExceptionHandling
5248
5515
  } = this.outputOptions;
5249
- const __webpack_require__ = id => {
5516
+
5517
+ /** @type {WebpackRequire} */
5518
+ const __webpack_require__ = (id) => {
5250
5519
  const cached = moduleCache[id];
5251
5520
  if (cached !== undefined) {
5252
5521
  if (cached.error) throw cached.error;
5253
5522
  return cached.exports;
5254
5523
  }
5255
5524
  const moduleArgument = moduleArgumentsById.get(id);
5256
- return __webpack_require_module__(moduleArgument, id);
5525
+ return __webpack_require_module__(
5526
+ /** @type {ExecuteModuleArgument} */
5527
+ (moduleArgument),
5528
+ id
5529
+ );
5257
5530
  };
5258
5531
  const interceptModuleExecution = (__webpack_require__[
5259
- RuntimeGlobals.interceptModuleExecution.replace(
5260
- `${RuntimeGlobals.require}.`,
5261
- ""
5532
+ /** @type {"i"} */
5533
+ (
5534
+ RuntimeGlobals.interceptModuleExecution.replace(
5535
+ `${RuntimeGlobals.require}.`,
5536
+ ""
5537
+ )
5262
5538
  )
5263
- ] = []);
5539
+ ] = /** @type {NonNullable<WebpackRequire["i"]>} */ ([]));
5264
5540
  const moduleCache = (__webpack_require__[
5265
- RuntimeGlobals.moduleCache.replace(
5266
- `${RuntimeGlobals.require}.`,
5267
- ""
5541
+ /** @type {"c"} */ (
5542
+ RuntimeGlobals.moduleCache.replace(
5543
+ `${RuntimeGlobals.require}.`,
5544
+ ""
5545
+ )
5268
5546
  )
5269
- ] = {});
5547
+ ] = /** @type {NonNullable<WebpackRequire["c"]>} */ ({}));
5270
5548
 
5271
5549
  context.__webpack_require__ = __webpack_require__;
5272
5550
 
5273
5551
  /**
5274
5552
  * @param {ExecuteModuleArgument} moduleArgument the module argument
5275
5553
  * @param {string=} id id
5276
- * @returns {any} exports
5554
+ * @returns {ExecuteModuleExports} exports
5277
5555
  */
5278
5556
  const __webpack_require_module__ = (moduleArgument, id) => {
5557
+ /** @type {ExecuteOptions} */
5279
5558
  const execOptions = {
5280
5559
  id,
5281
5560
  module: {
@@ -5310,9 +5589,14 @@ This prevents using hashes of each other and should be avoided.`);
5310
5589
  if (strictModuleExceptionHandling) {
5311
5590
  if (id) delete moduleCache[id];
5312
5591
  } else if (strictModuleErrorHandling) {
5313
- moduleObject.error = execErr;
5592
+ moduleObject.error =
5593
+ /** @type {WebpackError} */
5594
+ (execErr);
5595
+ }
5596
+ if (!(/** @type {WebpackError} */ (execErr).module)) {
5597
+ /** @type {WebpackError} */
5598
+ (execErr).module = module;
5314
5599
  }
5315
- if (!execErr.module) execErr.module = module;
5316
5600
  throw execErr;
5317
5601
  }
5318
5602
  };
@@ -5325,15 +5609,21 @@ This prevents using hashes of each other and should be avoided.`);
5325
5609
  (moduleArgumentsMap.get(runtimeModule))
5326
5610
  );
5327
5611
  }
5612
+
5328
5613
  exports = __webpack_require__(module.identifier());
5329
5614
  } catch (execErr) {
5615
+ const { message, stack, module } =
5616
+ /** @type {WebpackError} */
5617
+ (execErr);
5330
5618
  const err = new WebpackError(
5331
- `Execution of module code from module graph (${module.readableIdentifier(
5332
- this.requestShortener
5333
- )}) failed: ${execErr.message}`
5619
+ `Execution of module code from module graph (${
5620
+ /** @type {Module} */
5621
+ (module).readableIdentifier(this.requestShortener)
5622
+ }) failed: ${message}`,
5623
+ { cause: execErr }
5334
5624
  );
5335
- err.stack = execErr.stack;
5336
- err.module = execErr.module;
5625
+ err.stack = stack;
5626
+ err.module = module;
5337
5627
  return callback(err);
5338
5628
  }
5339
5629
 
@@ -5357,7 +5647,7 @@ This prevents using hashes of each other and should be avoided.`);
5357
5647
  checkConstraints() {
5358
5648
  const chunkGraph = this.chunkGraph;
5359
5649
 
5360
- /** @type {Set<number|string>} */
5650
+ /** @type {Set<ModuleId>} */
5361
5651
  const usedIds = new Set();
5362
5652
 
5363
5653
  for (const module of this.modules) {
@@ -5412,19 +5702,6 @@ This prevents using hashes of each other and should be avoided.`);
5412
5702
  * @returns {void}
5413
5703
  */
5414
5704
 
5415
- // Workaround for typescript as it doesn't support function overloading in jsdoc within a class
5416
- /* eslint-disable jsdoc/require-asterisk-prefix */
5417
- Compilation.prototype.factorizeModule = /**
5418
- @type {{
5419
- (options: FactorizeModuleOptions & { factoryResult?: false }, callback: ModuleCallback): void;
5420
- (options: FactorizeModuleOptions & { factoryResult: true }, callback: ModuleFactoryResultCallback): void;
5421
- }} */ (
5422
- function (options, callback) {
5423
- this.factorizeQueue.add(options, callback);
5424
- }
5425
- );
5426
- /* eslint-enable jsdoc/require-asterisk-prefix */
5427
-
5428
5705
  // Hide from typescript
5429
5706
  const compilationPrototype = Compilation.prototype;
5430
5707
 
@@ -5449,7 +5726,7 @@ Object.defineProperty(compilationPrototype, "cache", {
5449
5726
  * @this {Compilation} the compilation
5450
5727
  * @returns {Cache} the cache
5451
5728
  */
5452
- function () {
5729
+ function cache() {
5453
5730
  return this.compiler.cache;
5454
5731
  },
5455
5732
  "Compilation.cache was removed in favor of Compilation.getCache()",
@@ -5457,9 +5734,9 @@ Object.defineProperty(compilationPrototype, "cache", {
5457
5734
  ),
5458
5735
  set: util.deprecate(
5459
5736
  /**
5460
- * @param {any} v value
5737
+ * @param {EXPECTED_ANY} _v value
5461
5738
  */
5462
- v => {},
5739
+ (_v) => {},
5463
5740
  "Compilation.cache was removed in favor of Compilation.getCache()",
5464
5741
  "DEP_WEBPACK_COMPILATION_CACHE"
5465
5742
  )