webpack 5.101.2 → 5.102.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (323) hide show
  1. package/README.md +21 -26
  2. package/lib/APIPlugin.js +30 -36
  3. package/lib/AsyncDependenciesBlock.js +1 -4
  4. package/lib/BannerPlugin.js +0 -1
  5. package/lib/Cache.js +7 -6
  6. package/lib/CacheFacade.js +0 -1
  7. package/lib/Chunk.js +49 -31
  8. package/lib/ChunkGraph.js +35 -25
  9. package/lib/ChunkGroup.js +8 -10
  10. package/lib/ChunkTemplate.js +1 -1
  11. package/lib/CleanPlugin.js +3 -3
  12. package/lib/CodeGenerationResults.js +2 -1
  13. package/lib/CompatibilityPlugin.js +29 -12
  14. package/lib/Compilation.js +204 -185
  15. package/lib/Compiler.js +36 -35
  16. package/lib/ConcatenationScope.js +6 -1
  17. package/lib/ConditionalInitFragment.js +1 -1
  18. package/lib/ConstPlugin.js +18 -10
  19. package/lib/ContextExclusionPlugin.js +0 -1
  20. package/lib/ContextModule.js +22 -20
  21. package/lib/ContextModuleFactory.js +30 -11
  22. package/lib/ContextReplacementPlugin.js +38 -15
  23. package/lib/DefinePlugin.js +18 -8
  24. package/lib/DelegatedModule.js +7 -11
  25. package/lib/DependenciesBlock.js +0 -2
  26. package/lib/Dependency.js +9 -11
  27. package/lib/DependencyTemplates.js +1 -3
  28. package/lib/DllModule.js +1 -7
  29. package/lib/DllReferencePlugin.js +2 -4
  30. package/lib/DynamicEntryPlugin.js +0 -2
  31. package/lib/EntryOptionPlugin.js +0 -5
  32. package/lib/EnvironmentNotSupportAsyncWarning.js +0 -3
  33. package/lib/EvalDevToolModulePlugin.js +4 -3
  34. package/lib/EvalSourceMapDevToolPlugin.js +3 -4
  35. package/lib/ExportsInfo.js +50 -49
  36. package/lib/ExternalModule.js +84 -52
  37. package/lib/ExternalModuleFactoryPlugin.js +27 -7
  38. package/lib/ExternalsPlugin.js +24 -17
  39. package/lib/FileSystemInfo.js +96 -78
  40. package/lib/FlagDependencyUsagePlugin.js +3 -4
  41. package/lib/Generator.js +2 -13
  42. package/lib/GraphHelpers.js +0 -3
  43. package/lib/HookWebpackError.js +0 -2
  44. package/lib/HotModuleReplacementPlugin.js +22 -24
  45. package/lib/HotUpdateChunk.js +0 -3
  46. package/lib/IgnorePlugin.js +5 -2
  47. package/lib/InitFragment.js +41 -29
  48. package/lib/InvalidDependenciesModuleWarning.js +0 -1
  49. package/lib/LibManifestPlugin.js +4 -6
  50. package/lib/LoaderOptionsPlugin.js +1 -10
  51. package/lib/MainTemplate.js +8 -19
  52. package/lib/Module.js +32 -20
  53. package/lib/ModuleFactory.js +1 -1
  54. package/lib/ModuleFilenameHelpers.js +41 -24
  55. package/lib/ModuleGraph.js +30 -16
  56. package/lib/ModuleInfoHeaderPlugin.js +0 -1
  57. package/lib/ModuleTemplate.js +0 -2
  58. package/lib/ModuleTypeConstants.js +11 -1
  59. package/lib/MultiCompiler.js +23 -15
  60. package/lib/MultiWatching.js +6 -10
  61. package/lib/NodeStuffPlugin.js +2 -10
  62. package/lib/NormalModule.js +145 -88
  63. package/lib/NormalModuleFactory.js +59 -40
  64. package/lib/OptionsApply.js +1 -1
  65. package/lib/Parser.js +1 -1
  66. package/lib/ProgressPlugin.js +6 -10
  67. package/lib/ProvidePlugin.js +5 -7
  68. package/lib/RawModule.js +1 -6
  69. package/lib/RecordIdsPlugin.js +10 -6
  70. package/lib/ResolverFactory.js +0 -2
  71. package/lib/RuntimeGlobals.js +5 -0
  72. package/lib/RuntimeModule.js +1 -3
  73. package/lib/RuntimePlugin.js +26 -22
  74. package/lib/RuntimeTemplate.js +12 -11
  75. package/lib/SourceMapDevToolModuleOptionsPlugin.js +2 -2
  76. package/lib/SourceMapDevToolPlugin.js +6 -11
  77. package/lib/Stats.js +0 -1
  78. package/lib/Template.js +6 -11
  79. package/lib/TemplatedPathPlugin.js +2 -1
  80. package/lib/WatchIgnorePlugin.js +2 -3
  81. package/lib/Watching.js +15 -15
  82. package/lib/WebpackIsIncludedPlugin.js +0 -2
  83. package/lib/WebpackOptionsApply.js +74 -107
  84. package/lib/asset/AssetBytesGenerator.js +166 -0
  85. package/lib/asset/AssetBytesParser.js +37 -0
  86. package/lib/asset/AssetGenerator.js +20 -34
  87. package/lib/asset/AssetModulesPlugin.js +34 -16
  88. package/lib/asset/AssetParser.js +7 -3
  89. package/lib/asset/AssetSourceGenerator.js +1 -1
  90. package/lib/asset/RawDataUrlModule.js +3 -2
  91. package/lib/async-modules/AsyncModuleHelpers.js +6 -4
  92. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -1
  93. package/lib/buildChunkGraph.js +0 -1
  94. package/lib/cache/MemoryCachePlugin.js +0 -2
  95. package/lib/cache/MemoryWithGcCachePlugin.js +0 -2
  96. package/lib/cache/PackFileCacheStrategy.js +14 -1
  97. package/lib/cache/ResolverCachePlugin.js +9 -15
  98. package/lib/config/defaults.js +155 -21
  99. package/lib/config/normalization.js +18 -3
  100. package/lib/container/ContainerEntryDependency.js +0 -1
  101. package/lib/container/ContainerEntryModule.js +3 -7
  102. package/lib/container/ContainerPlugin.js +1 -2
  103. package/lib/container/ContainerReferencePlugin.js +0 -1
  104. package/lib/container/FallbackDependency.js +2 -1
  105. package/lib/container/FallbackModule.js +6 -7
  106. package/lib/container/ModuleFederationPlugin.js +0 -1
  107. package/lib/container/RemoteModule.js +8 -8
  108. package/lib/container/RemoteRuntimeModule.js +2 -2
  109. package/lib/css/CssGenerator.js +3 -6
  110. package/lib/css/CssLoadingRuntimeModule.js +6 -9
  111. package/lib/css/CssModulesPlugin.js +11 -13
  112. package/lib/css/CssParser.js +3 -3
  113. package/lib/css/walkCssTokens.js +1 -1
  114. package/lib/debug/ProfilingPlugin.js +35 -8
  115. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +12 -17
  116. package/lib/dependencies/AMDPlugin.js +2 -2
  117. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -2
  118. package/lib/dependencies/CachedConstDependency.js +0 -4
  119. package/lib/dependencies/CommonJsExportRequireDependency.js +20 -14
  120. package/lib/dependencies/CommonJsExportsDependency.js +2 -1
  121. package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -5
  122. package/lib/dependencies/CommonJsFullRequireDependency.js +6 -4
  123. package/lib/dependencies/CommonJsImportsParserPlugin.js +16 -7
  124. package/lib/dependencies/CommonJsRequireContextDependency.js +1 -1
  125. package/lib/dependencies/CommonJsSelfReferenceDependency.js +4 -4
  126. package/lib/dependencies/ConstDependency.js +2 -2
  127. package/lib/dependencies/ContextDependency.js +9 -4
  128. package/lib/dependencies/ContextDependencyHelpers.js +2 -2
  129. package/lib/dependencies/ContextDependencyTemplateAsId.js +9 -9
  130. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +9 -9
  131. package/lib/dependencies/ContextElementDependency.js +22 -11
  132. package/lib/dependencies/CssIcssImportDependency.js +0 -2
  133. package/lib/dependencies/CssIcssSymbolDependency.js +2 -2
  134. package/lib/dependencies/CssImportDependency.js +0 -8
  135. package/lib/dependencies/CssLocalIdentifierDependency.js +3 -4
  136. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -2
  137. package/lib/dependencies/CssUrlDependency.js +0 -6
  138. package/lib/dependencies/ExportsInfoDependency.js +7 -9
  139. package/lib/dependencies/ExternalModuleDependency.js +0 -3
  140. package/lib/dependencies/ExternalModuleInitFragment.js +1 -1
  141. package/lib/dependencies/HarmonyAcceptDependency.js +1 -1
  142. package/lib/dependencies/HarmonyAcceptImportDependency.js +0 -4
  143. package/lib/dependencies/HarmonyCompatibilityDependency.js +0 -1
  144. package/lib/dependencies/HarmonyDetectionParserPlugin.js +0 -14
  145. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +3 -3
  146. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +4 -1
  147. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +29 -35
  148. package/lib/dependencies/HarmonyImportDependency.js +30 -14
  149. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +38 -24
  150. package/lib/dependencies/HarmonyImportSideEffectDependency.js +0 -4
  151. package/lib/dependencies/HarmonyImportSpecifierDependency.js +46 -31
  152. package/lib/dependencies/HarmonyModulesPlugin.js +3 -3
  153. package/lib/dependencies/ImportDependency.js +18 -6
  154. package/lib/dependencies/ImportEagerDependency.js +2 -3
  155. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +8 -5
  156. package/lib/dependencies/ImportMetaContextPlugin.js +0 -1
  157. package/lib/dependencies/ImportMetaPlugin.js +8 -1
  158. package/lib/dependencies/ImportParserPlugin.js +294 -45
  159. package/lib/dependencies/ImportWeakDependency.js +2 -3
  160. package/lib/dependencies/JsonExportsDependency.js +0 -1
  161. package/lib/dependencies/LoaderDependency.js +0 -3
  162. package/lib/dependencies/LoaderImportDependency.js +0 -3
  163. package/lib/dependencies/LoaderPlugin.js +11 -5
  164. package/lib/dependencies/ModuleDecoratorDependency.js +2 -4
  165. package/lib/dependencies/ModuleDependency.js +3 -9
  166. package/lib/dependencies/NullDependency.js +2 -0
  167. package/lib/dependencies/ProvidedDependency.js +6 -8
  168. package/lib/dependencies/PureExpressionDependency.js +0 -1
  169. package/lib/dependencies/RequireEnsureDependenciesBlock.js +0 -1
  170. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +1 -2
  171. package/lib/dependencies/RequireIncludeDependency.js +2 -2
  172. package/lib/dependencies/RequireResolveDependency.js +2 -2
  173. package/lib/dependencies/RuntimeRequirementsDependency.js +2 -3
  174. package/lib/dependencies/StaticExportsDependency.js +3 -5
  175. package/lib/dependencies/URLDependency.js +2 -7
  176. package/lib/dependencies/URLPlugin.js +1 -2
  177. package/lib/dependencies/WebAssemblyExportImportedDependency.js +2 -2
  178. package/lib/dependencies/WebAssemblyImportDependency.js +2 -2
  179. package/lib/dependencies/WebpackIsIncludedDependency.js +2 -3
  180. package/lib/dependencies/WorkerDependency.js +2 -3
  181. package/lib/dependencies/WorkerPlugin.js +3 -9
  182. package/lib/dependencies/processExportInfo.js +2 -3
  183. package/lib/esm/ModuleChunkFormatPlugin.js +0 -3
  184. package/lib/esm/ModuleChunkLoadingPlugin.js +2 -1
  185. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +7 -7
  186. package/lib/hmr/LazyCompilationPlugin.js +6 -4
  187. package/lib/hmr/lazyCompilationBackend.js +13 -10
  188. package/lib/ids/DeterministicChunkIdsPlugin.js +0 -1
  189. package/lib/ids/NamedChunkIdsPlugin.js +1 -6
  190. package/lib/ids/NamedModuleIdsPlugin.js +1 -5
  191. package/lib/ids/NaturalChunkIdsPlugin.js +0 -1
  192. package/lib/ids/NaturalModuleIdsPlugin.js +0 -1
  193. package/lib/ids/OccurrenceChunkIdsPlugin.js +0 -1
  194. package/lib/ids/OccurrenceModuleIdsPlugin.js +0 -1
  195. package/lib/ids/SyncModuleIdsPlugin.js +4 -3
  196. package/lib/index.js +8 -7
  197. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -1
  198. package/lib/javascript/BasicEvaluatedExpression.js +13 -6
  199. package/lib/javascript/ChunkFormatHelpers.js +1 -1
  200. package/lib/javascript/CommonJsChunkFormatPlugin.js +0 -1
  201. package/lib/javascript/JavascriptGenerator.js +2 -3
  202. package/lib/javascript/JavascriptModulesPlugin.js +44 -21
  203. package/lib/javascript/JavascriptParser.js +159 -93
  204. package/lib/javascript/JavascriptParserHelpers.js +2 -2
  205. package/lib/javascript/StartupHelpers.js +2 -4
  206. package/lib/json/JsonData.js +1 -1
  207. package/lib/json/JsonGenerator.js +4 -5
  208. package/lib/json/JsonModulesPlugin.js +0 -3
  209. package/lib/json/JsonParser.js +4 -2
  210. package/lib/library/AbstractLibraryPlugin.js +2 -2
  211. package/lib/library/AmdLibraryPlugin.js +0 -1
  212. package/lib/library/AssignLibraryPlugin.js +23 -12
  213. package/lib/library/EnableLibraryPlugin.js +7 -11
  214. package/lib/library/ExportPropertyLibraryPlugin.js +8 -20
  215. package/lib/library/JsonpLibraryPlugin.js +5 -2
  216. package/lib/library/ModuleLibraryPlugin.js +88 -43
  217. package/lib/library/SystemLibraryPlugin.js +0 -1
  218. package/lib/library/UmdLibraryPlugin.js +12 -18
  219. package/lib/logging/Logger.js +12 -10
  220. package/lib/logging/createConsoleLogger.js +15 -14
  221. package/lib/logging/truncateArgs.js +1 -1
  222. package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
  223. package/lib/node/NodeWatchFileSystem.js +4 -4
  224. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -2
  225. package/lib/node/RequireChunkLoadingRuntimeModule.js +5 -2
  226. package/lib/node/nodeConsole.js +2 -2
  227. package/lib/optimize/AggressiveSplittingPlugin.js +2 -0
  228. package/lib/optimize/ConcatenatedModule.js +142 -100
  229. package/lib/optimize/InnerGraph.js +17 -11
  230. package/lib/optimize/InnerGraphPlugin.js +0 -3
  231. package/lib/optimize/ModuleConcatenationPlugin.js +3 -4
  232. package/lib/optimize/RuntimeChunkPlugin.js +0 -1
  233. package/lib/optimize/SideEffectsFlagPlugin.js +3 -10
  234. package/lib/optimize/SplitChunksPlugin.js +46 -40
  235. package/lib/performance/SizeLimitsPlugin.js +2 -1
  236. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +5 -7
  237. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +0 -2
  238. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +0 -1
  239. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +2 -2
  240. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +2 -2
  241. package/lib/rules/BasicMatcherRulePlugin.js +0 -2
  242. package/lib/rules/ObjectMatcherRulePlugin.js +0 -1
  243. package/lib/rules/RuleSetCompiler.js +8 -6
  244. package/lib/runtime/BaseUriRuntimeModule.js +2 -2
  245. package/lib/runtime/CompatRuntimeModule.js +0 -1
  246. package/lib/runtime/GetChunkFilenameRuntimeModule.js +8 -9
  247. package/lib/runtime/LoadScriptRuntimeModule.js +0 -2
  248. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +1 -1
  249. package/lib/runtime/PublicPathRuntimeModule.js +2 -2
  250. package/lib/runtime/StartupEntrypointRuntimeModule.js +0 -1
  251. package/lib/runtime/SystemContextRuntimeModule.js +0 -2
  252. package/lib/runtime/ToBinaryRuntimeModule.js +64 -0
  253. package/lib/schemes/DataUriPlugin.js +2 -28
  254. package/lib/schemes/FileUriPlugin.js +5 -2
  255. package/lib/schemes/HttpUriPlugin.js +4 -2
  256. package/lib/schemes/VirtualUrlPlugin.js +11 -11
  257. package/lib/serialization/NullPrototypeObjectSerializer.js +5 -3
  258. package/lib/serialization/ObjectMiddleware.js +30 -19
  259. package/lib/serialization/SerializerMiddleware.js +1 -3
  260. package/lib/serialization/types.js +1 -1
  261. package/lib/sharing/ConsumeSharedModule.js +3 -5
  262. package/lib/sharing/ConsumeSharedPlugin.js +2 -4
  263. package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -6
  264. package/lib/sharing/ProvideSharedModule.js +3 -7
  265. package/lib/sharing/SharePlugin.js +0 -2
  266. package/lib/sharing/ShareRuntimeModule.js +4 -1
  267. package/lib/sharing/resolveMatchedConfigs.js +14 -6
  268. package/lib/sharing/utils.js +0 -6
  269. package/lib/stats/DefaultStatsFactoryPlugin.js +178 -94
  270. package/lib/stats/DefaultStatsPresetPlugin.js +15 -9
  271. package/lib/stats/DefaultStatsPrinterPlugin.js +77 -113
  272. package/lib/stats/StatsFactory.js +14 -11
  273. package/lib/url/URLParserPlugin.js +2 -4
  274. package/lib/util/ArrayHelpers.js +4 -4
  275. package/lib/util/AsyncQueue.js +1 -0
  276. package/lib/util/LazySet.js +2 -2
  277. package/lib/util/StackedCacheMap.js +0 -2
  278. package/lib/util/TupleSet.js +9 -4
  279. package/lib/util/URLAbsoluteSpecifier.js +0 -1
  280. package/lib/util/WeakTupleMap.js +1 -1
  281. package/lib/util/chainedImports.js +3 -1
  282. package/lib/util/cleverMerge.js +15 -18
  283. package/lib/util/comparators.js +2 -4
  284. package/lib/util/compileBooleanMatcher.js +11 -9
  285. package/lib/util/concatenate.js +1 -2
  286. package/lib/util/create-schema-validation.js +0 -1
  287. package/lib/util/dataURL.js +39 -0
  288. package/lib/util/deprecation.js +29 -31
  289. package/lib/util/deterministicGrouping.js +34 -30
  290. package/lib/util/extractSourceMap.js +319 -0
  291. package/lib/util/findGraphRoots.js +15 -5
  292. package/lib/util/fs.js +29 -8
  293. package/lib/util/semver.js +9 -8
  294. package/lib/util/smartGrouping.js +41 -26
  295. package/lib/util/traverseDestructuringAssignmentProperties.js +45 -0
  296. package/lib/wasm/EnableWasmLoadingPlugin.js +3 -2
  297. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +5 -1
  298. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +2 -13
  299. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +2 -9
  300. package/lib/wasm-async/AsyncWebAssemblyParser.js +2 -1
  301. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +6 -4
  302. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -3
  303. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -4
  304. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -7
  305. package/lib/wasm-sync/WebAssemblyParser.js +1 -4
  306. package/lib/web/JsonpChunkLoadingPlugin.js +2 -1
  307. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
  308. package/lib/web/JsonpTemplatePlugin.js +0 -1
  309. package/lib/webpack.js +21 -8
  310. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +2 -1
  311. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
  312. package/package.json +13 -13
  313. package/schemas/WebpackOptions.check.js +1 -1
  314. package/schemas/WebpackOptions.json +77 -93
  315. package/schemas/plugins/BannerPlugin.check.js +1 -1
  316. package/schemas/plugins/BannerPlugin.json +4 -0
  317. package/schemas/plugins/IgnorePlugin.json +1 -1
  318. package/schemas/plugins/ProgressPlugin.json +1 -1
  319. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  320. package/schemas/plugins/SourceMapDevToolPlugin.json +5 -1
  321. package/schemas/plugins/schemes/VirtualUrlPlugin.json +3 -3
  322. package/types.d.ts +1140 -505
  323. package/SECURITY.md +0 -9
@@ -86,12 +86,14 @@ const { isSourceEqual } = require("./util/source");
86
86
 
87
87
  /** @template T @typedef {import("tapable").AsArray<T>} AsArray<T> */
88
88
  /** @typedef {import("webpack-sources").Source} Source */
89
- /** @typedef {import("../declarations/WebpackOptions").EntryDescriptionNormalized} EntryDescription */
90
89
  /** @typedef {import("../declarations/WebpackOptions").OutputNormalized} OutputOptions */
90
+ /** @typedef {import("../declarations/WebpackOptions").HashFunction} HashFunction */
91
+ /** @typedef {import("../declarations/WebpackOptions").HashDigest} HashDigest */
92
+ /** @typedef {import("../declarations/WebpackOptions").HashDigestLength} HashDigestLength */
91
93
  /** @typedef {import("../declarations/WebpackOptions").StatsOptions} StatsOptions */
92
- /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
93
- /** @typedef {import("../declarations/WebpackOptions").WebpackPluginFunction} WebpackPluginFunction */
94
- /** @typedef {import("../declarations/WebpackOptions").WebpackPluginInstance} WebpackPluginInstance */
94
+ /** @typedef {import("../declarations/WebpackOptions").Plugins} Plugins */
95
+ /** @typedef {import("./config/defaults").WebpackOptionsNormalizedWithDefaults} WebpackOptions */
96
+ /** @typedef {import("./config/defaults").OutputNormalizedWithDefaults} OutputOptionsWithDefaults */
95
97
  /** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
96
98
  /** @typedef {import("./Cache")} Cache */
97
99
  /** @typedef {import("./CacheFacade")} CacheFacade */
@@ -106,9 +108,9 @@ const { isSourceEqual } = require("./util/source");
106
108
  /** @typedef {import("./Compiler").Records} Records */
107
109
  /** @typedef {import("./DependenciesBlock")} DependenciesBlock */
108
110
  /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
109
- /** @typedef {import("./Dependency").ReferencedExport} ReferencedExport */
110
- /** @typedef {import("./DependencyTemplate")} DependencyTemplate */
111
+ /** @typedef {import("./Dependency").ReferencedExports} ReferencedExports */
111
112
  /** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
113
+ /** @typedef {import("./Module").NameForCondition} NameForCondition */
112
114
  /** @typedef {import("./Module").BuildInfo} BuildInfo */
113
115
  /** @typedef {import("./Module").ValueCacheVersions} ValueCacheVersions */
114
116
  /** @typedef {import("./Module").RuntimeRequirements} RuntimeRequirements */
@@ -132,13 +134,13 @@ const { isSourceEqual } = require("./util/source");
132
134
  /** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsModule} StatsModule */
133
135
  /** @typedef {import("./TemplatedPathPlugin").TemplatePath} TemplatePath */
134
136
  /** @typedef {import("./util/Hash")} Hash */
135
- /** @typedef {import("../declarations/WebpackOptions").HashFunction} HashFunction */
136
137
  /**
137
138
  * @template T
138
139
  * @typedef {import("./util/deprecation").FakeHook<T>} FakeHook<T>
139
140
  */
140
141
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
141
142
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
143
+
142
144
  /**
143
145
  * @callback Callback
144
146
  * @param {(WebpackError | null)=} err
@@ -147,33 +149,33 @@ const { isSourceEqual } = require("./util/source");
147
149
 
148
150
  /**
149
151
  * @callback ModuleCallback
150
- * @param {(WebpackError | null)=} err
151
- * @param {(Module | null)=} result
152
+ * @param {WebpackError | null=} err
153
+ * @param {Module | null=} result
152
154
  * @returns {void}
153
155
  */
154
156
 
155
157
  /**
156
158
  * @callback ModuleFactoryResultCallback
157
- * @param {(WebpackError | null)=} err
158
- * @param {ModuleFactoryResult=} result
159
+ * @param {WebpackError | null=} err
160
+ * @param {ModuleFactoryResult | null=} result
159
161
  * @returns {void}
160
162
  */
161
163
 
162
164
  /**
163
- * @callback ModuleOrFactoryResultCallback
164
- * @param {(WebpackError | null)=} err
165
- * @param {Module | ModuleFactoryResult=} result
165
+ * @callback ModuleOrModuleFactoryResultCallback
166
+ * @param {WebpackError | null=} err
167
+ * @param {Module | ModuleFactoryResult | null=} result
166
168
  * @returns {void}
167
169
  */
168
170
 
169
171
  /**
170
172
  * @callback ExecuteModuleCallback
171
- * @param {WebpackError | null} err
172
- * @param {ExecuteModuleResult=} result
173
+ * @param {WebpackError | null=} err
174
+ * @param {ExecuteModuleResult | null=} result
173
175
  * @returns {void}
174
176
  */
175
177
 
176
- /** @typedef {new (...args: EXPECTED_ANY[]) => Dependency} DepConstructor */
178
+ /** @typedef {new (...args: EXPECTED_ANY[]) => Dependency} DependencyConstructor */
177
179
 
178
180
  /** @typedef {Record<string, Source>} CompilationAssets */
179
181
 
@@ -190,6 +192,8 @@ const { isSourceEqual } = require("./util/source");
190
192
  * @property {AsyncDependenciesBlock[]} blocks
191
193
  */
192
194
 
195
+ /** @typedef {Set<Chunk>} Chunks */
196
+
193
197
  /**
194
198
  * @typedef {object} ChunkPathData
195
199
  * @property {string | number} id
@@ -244,7 +248,6 @@ const { isSourceEqual } = require("./util/source");
244
248
  * @typedef {object} ExecuteModuleArgument
245
249
  * @property {Module} module
246
250
  * @property {ExecuteModuleObject=} moduleObject
247
- * @property {TODO} preparedInfo
248
251
  * @property {CodeGenerationResult} codeGenerationResult
249
252
  */
250
253
 
@@ -479,7 +482,7 @@ const unsafeCacheDependencies = new WeakMap();
479
482
  /** @type {WeakMap<ModuleWithRestoreFromUnsafeCache, UnsafeCacheData>} */
480
483
  const unsafeCacheData = new WeakMap();
481
484
 
482
- /** @typedef {{ id: ModuleId, modules?: Map<Module, string | number | undefined>, blocks?: (string | number | null)[] }} References */
485
+ /** @typedef {{ id: ModuleId, modules?: Map<Module, ModuleId>, blocks?: (ChunkId | null)[] }} References */
483
486
  /** @typedef {Map<Module, WeakTupleMap<EXPECTED_ANY[], EXPECTED_ANY>>} ModuleMemCaches */
484
487
 
485
488
  class Compilation {
@@ -492,7 +495,7 @@ class Compilation {
492
495
  this._backCompat = compiler._backCompat;
493
496
 
494
497
  const getNormalModuleLoader = () => deprecatedNormalModuleLoaderHook(this);
495
- /** @typedef {{ additionalAssets?: true | TODO }} ProcessAssetsAdditionalOptions */
498
+ /** @typedef {{ additionalAssets?: boolean | ((assets: CompilationAssets) => void) }} ProcessAssetsAdditionalOptions */
496
499
  /** @type {AsyncSeriesHook<[CompilationAssets], ProcessAssetsAdditionalOptions>} */
497
500
  const processAssetsHook = new AsyncSeriesHook(["assets"]);
498
501
 
@@ -718,7 +721,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
718
721
  processAssetsHook.tapAsync(
719
722
  getOptions(options),
720
723
  (assets, callback) =>
721
- /** @type {TODO} */ (fn)(...getArgs(), callback)
724
+ /** @type {EXPECTED_ANY} */ (fn)(...getArgs(), callback)
722
725
  );
723
726
  },
724
727
  /** @type {AsyncSeriesHook<T>["tapPromise"]} */
@@ -751,7 +754,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
751
754
  /** @type {SyncHook<[Dependency, EntryOptions, Module]>} */
752
755
  succeedEntry: new SyncHook(["entry", "options", "module"]),
753
756
 
754
- /** @type {SyncWaterfallHook<[(string[] | ReferencedExport)[], Dependency, RuntimeSpec]>} */
757
+ /** @type {SyncWaterfallHook<[ReferencedExports, Dependency, RuntimeSpec]>} */
755
758
  dependencyReferencedExports: new SyncWaterfallHook([
756
759
  "referencedExports",
757
760
  "dependency",
@@ -811,33 +814,33 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
811
814
  /** @type {SyncBailHook<[], boolean | void>} */
812
815
  shouldRecord: new SyncBailHook([]),
813
816
 
814
- /** @type {SyncHook<[Chunk, Set<string>, RuntimeRequirementsContext]>} */
817
+ /** @type {SyncHook<[Chunk, RuntimeRequirements, RuntimeRequirementsContext]>} */
815
818
  additionalChunkRuntimeRequirements: new SyncHook([
816
819
  "chunk",
817
820
  "runtimeRequirements",
818
821
  "context"
819
822
  ]),
820
- /** @type {HookMap<SyncBailHook<[Chunk, Set<string>, RuntimeRequirementsContext], void>>} */
823
+ /** @type {HookMap<SyncBailHook<[Chunk, RuntimeRequirements, RuntimeRequirementsContext], void>>} */
821
824
  runtimeRequirementInChunk: new HookMap(
822
825
  () => new SyncBailHook(["chunk", "runtimeRequirements", "context"])
823
826
  ),
824
- /** @type {SyncHook<[Module, Set<string>, RuntimeRequirementsContext]>} */
827
+ /** @type {SyncHook<[Module, RuntimeRequirements, RuntimeRequirementsContext]>} */
825
828
  additionalModuleRuntimeRequirements: new SyncHook([
826
829
  "module",
827
830
  "runtimeRequirements",
828
831
  "context"
829
832
  ]),
830
- /** @type {HookMap<SyncBailHook<[Module, Set<string>, RuntimeRequirementsContext], void>>} */
833
+ /** @type {HookMap<SyncBailHook<[Module, RuntimeRequirements, RuntimeRequirementsContext], void>>} */
831
834
  runtimeRequirementInModule: new HookMap(
832
835
  () => new SyncBailHook(["module", "runtimeRequirements", "context"])
833
836
  ),
834
- /** @type {SyncHook<[Chunk, Set<string>, RuntimeRequirementsContext]>} */
837
+ /** @type {SyncHook<[Chunk, RuntimeRequirements, RuntimeRequirementsContext]>} */
835
838
  additionalTreeRuntimeRequirements: new SyncHook([
836
839
  "chunk",
837
840
  "runtimeRequirements",
838
841
  "context"
839
842
  ]),
840
- /** @type {HookMap<SyncBailHook<[Chunk, Set<string>, RuntimeRequirementsContext], void>>} */
843
+ /** @type {HookMap<SyncBailHook<[Chunk, RuntimeRequirements, RuntimeRequirementsContext], void>>} */
841
844
  runtimeRequirementInTree: new HookMap(
842
845
  () => new SyncBailHook(["chunk", "runtimeRequirements", "context"])
843
846
  ),
@@ -910,7 +913,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
910
913
  // TODO webpack 6 remove
911
914
  /** @deprecated */
912
915
  additionalChunkAssets:
913
- /** @type {FakeHook<Pick<AsyncSeriesHook<[Set<Chunk>]>, "tap" | "tapAsync" | "tapPromise" | "name">>} */
916
+ /** @type {FakeHook<Pick<AsyncSeriesHook<[Chunks]>, "tap" | "tapAsync" | "tapPromise" | "name">>} */
914
917
  (
915
918
  createProcessAssetsHook(
916
919
  "additionalChunkAssets",
@@ -934,7 +937,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
934
937
  // TODO webpack 6 remove
935
938
  /** @deprecated */
936
939
  optimizeChunkAssets:
937
- /** @type {FakeHook<Pick<AsyncSeriesHook<[Set<Chunk>]>, "tap" | "tapAsync" | "tapPromise" | "name">>} */
940
+ /** @type {FakeHook<Pick<AsyncSeriesHook<[Chunks]>, "tap" | "tapAsync" | "tapPromise" | "name">>} */
938
941
  (
939
942
  createProcessAssetsHook(
940
943
  "optimizeChunkAssets",
@@ -946,7 +949,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
946
949
  // TODO webpack 6 remove
947
950
  /** @deprecated */
948
951
  afterOptimizeChunkAssets:
949
- /** @type {FakeHook<Pick<AsyncSeriesHook<[Set<Chunk>]>, "tap" | "tapAsync" | "tapPromise" | "name">>} */
952
+ /** @type {FakeHook<Pick<AsyncSeriesHook<[Chunks]>, "tap" | "tapAsync" | "tapPromise" | "name">>} */
950
953
  (
951
954
  createProcessAssetsHook(
952
955
  "afterOptimizeChunkAssets",
@@ -1057,7 +1060,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1057
1060
 
1058
1061
  const options = /** @type {WebpackOptions} */ (compiler.options);
1059
1062
  this.options = options;
1060
- this.outputOptions = options && options.output;
1063
+ this.outputOptions =
1064
+ /** @type {OutputOptionsWithDefaults} */
1065
+ (options && options.output);
1061
1066
  /** @type {boolean} */
1062
1067
  this.bail = (options && options.bail) || false;
1063
1068
  /** @type {boolean} */
@@ -1082,11 +1087,15 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1082
1087
  this.moduleMemCaches = undefined;
1083
1088
  /** @type {ModuleMemCaches | undefined} */
1084
1089
  this.moduleMemCaches2 = undefined;
1090
+ /** @type {ModuleGraph} */
1085
1091
  this.moduleGraph = new ModuleGraph();
1086
1092
  /** @type {ChunkGraph} */
1087
- this.chunkGraph = /** @type {TODO} */ (undefined);
1088
- /** @type {CodeGenerationResults} */
1089
- this.codeGenerationResults = /** @type {TODO} */ (undefined);
1093
+ this.chunkGraph = new ChunkGraph(
1094
+ this.moduleGraph,
1095
+ this.outputOptions.hashFunction
1096
+ );
1097
+ /** @type {CodeGenerationResults | undefined} */
1098
+ this.codeGenerationResults = undefined;
1090
1099
 
1091
1100
  /** @type {AsyncQueue<Module, Module, Module>} */
1092
1101
  this.processDependenciesQueue = new AsyncQueue({
@@ -1142,7 +1151,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1142
1151
  this.entrypoints = new Map();
1143
1152
  /** @type {Entrypoint[]} */
1144
1153
  this.asyncEntrypoints = [];
1145
- /** @type {Set<Chunk>} */
1154
+ /** @type {Chunks} */
1146
1155
  this.chunks = new Set();
1147
1156
  /** @type {ChunkGroup[]} */
1148
1157
  this.chunkGroups = [];
@@ -1179,7 +1188,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1179
1188
  this.children = [];
1180
1189
  /** @type {Map<string, LogEntry[]>} */
1181
1190
  this.logging = new Map();
1182
- /** @type {Map<DepConstructor, ModuleFactory>} */
1191
+ /** @type {Map<DependencyConstructor, ModuleFactory>} */
1183
1192
  this.dependencyFactories = new Map();
1184
1193
  /** @type {DependencyTemplates} */
1185
1194
  this.dependencyTemplates = new DependencyTemplates(
@@ -1187,7 +1196,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1187
1196
  );
1188
1197
  /** @type {Record<string, number>} */
1189
1198
  this.childrenCounters = {};
1190
- /** @type {Set<number|string> | null} */
1199
+ /** @type {Set<number> | null} */
1191
1200
  this.usedChunkIds = null;
1192
1201
  /** @type {Set<number> | null} */
1193
1202
  this.usedModuleIds = null;
@@ -1624,7 +1633,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1624
1633
  * @returns {void}
1625
1634
  */
1626
1635
  _processModuleDependencies(module, callback) {
1627
- /** @type {Array<{factory: ModuleFactory, dependencies: Dependency[], context: string|undefined, originModule: Module|null}>} */
1636
+ /** @type {{ factory: ModuleFactory, dependencies: Dependency[], context: string | undefined, originModule: Module | null }[]} */
1628
1637
  const sortedDependencies = [];
1629
1638
 
1630
1639
  /** @type {DependenciesBlock} */
@@ -1632,7 +1641,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1632
1641
 
1633
1642
  /** @type {Map<ModuleFactory, Map<string, Dependency[]>>} */
1634
1643
  let dependencies;
1635
- /** @type {DepConstructor} */
1644
+ /** @type {DependencyConstructor} */
1636
1645
  let factoryCacheKey;
1637
1646
  /** @type {ModuleFactory} */
1638
1647
  let factoryCacheKey2;
@@ -1815,7 +1824,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1815
1824
  const resourceIdent = dep.getResourceIdentifier();
1816
1825
  if (resourceIdent !== undefined && resourceIdent !== null) {
1817
1826
  const category = dep.category;
1818
- const constructor = /** @type {DepConstructor} */ (dep.constructor);
1827
+ const constructor =
1828
+ /** @type {DependencyConstructor} */
1829
+ (dep.constructor);
1819
1830
  if (factoryCacheKey === constructor) {
1820
1831
  // Fast path 1: same constructor as prev item
1821
1832
  if (listCacheKey1 === category && listCacheKey2 === resourceIdent) {
@@ -1950,6 +1961,116 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1950
1961
  moduleGraph.setResolvedModule(originModule, dependency, module);
1951
1962
  }
1952
1963
 
1964
+ /**
1965
+ * @param {FactorizeModuleOptions} options options
1966
+ * @param {ModuleOrModuleFactoryResultCallback} callback callback
1967
+ * @returns {void}
1968
+ */
1969
+ _factorizeModule(
1970
+ {
1971
+ currentProfile,
1972
+ factory,
1973
+ dependencies,
1974
+ originModule,
1975
+ factoryResult,
1976
+ contextInfo,
1977
+ context
1978
+ },
1979
+ callback
1980
+ ) {
1981
+ if (currentProfile !== undefined) {
1982
+ currentProfile.markFactoryStart();
1983
+ }
1984
+ factory.create(
1985
+ {
1986
+ contextInfo: {
1987
+ issuer: originModule
1988
+ ? /** @type {NameForCondition} */ (originModule.nameForCondition())
1989
+ : "",
1990
+ issuerLayer: originModule ? originModule.layer : null,
1991
+ compiler: this.compiler.name,
1992
+ ...contextInfo
1993
+ },
1994
+ resolveOptions: originModule ? originModule.resolveOptions : undefined,
1995
+ context:
1996
+ context ||
1997
+ (originModule
1998
+ ? /** @type {string} */ (originModule.context)
1999
+ : this.compiler.context),
2000
+ dependencies
2001
+ },
2002
+ (err, result) => {
2003
+ if (result) {
2004
+ // TODO webpack 6: remove
2005
+ // For backward-compat
2006
+ if (result.module === undefined && result instanceof Module) {
2007
+ result = {
2008
+ module: result
2009
+ };
2010
+ }
2011
+ if (!factoryResult) {
2012
+ const {
2013
+ fileDependencies,
2014
+ contextDependencies,
2015
+ missingDependencies
2016
+ } = result;
2017
+ if (fileDependencies) {
2018
+ this.fileDependencies.addAll(fileDependencies);
2019
+ }
2020
+ if (contextDependencies) {
2021
+ this.contextDependencies.addAll(contextDependencies);
2022
+ }
2023
+ if (missingDependencies) {
2024
+ this.missingDependencies.addAll(missingDependencies);
2025
+ }
2026
+ }
2027
+ }
2028
+ if (err) {
2029
+ const notFoundError = new ModuleNotFoundError(
2030
+ originModule,
2031
+ err,
2032
+ /** @type {DependencyLocation} */
2033
+ (dependencies.map((d) => d.loc).find(Boolean))
2034
+ );
2035
+ return callback(notFoundError, factoryResult ? result : undefined);
2036
+ }
2037
+ if (!result) {
2038
+ return callback();
2039
+ }
2040
+
2041
+ if (currentProfile !== undefined) {
2042
+ currentProfile.markFactoryEnd();
2043
+ }
2044
+
2045
+ callback(null, factoryResult ? result : result.module);
2046
+ }
2047
+ );
2048
+ }
2049
+
2050
+ /**
2051
+ * @overload
2052
+ * @param {FactorizeModuleOptions & { factoryResult?: false }} options options
2053
+ * @param {ModuleCallback} callback callback
2054
+ * @returns {void}
2055
+ */
2056
+ /**
2057
+ * @overload
2058
+ * @param {FactorizeModuleOptions & { factoryResult: true }} options options
2059
+ * @param {ModuleFactoryResultCallback} callback callback
2060
+ * @returns {void}
2061
+ */
2062
+ /**
2063
+ * @param {FactorizeModuleOptions & { factoryResult?: false } | FactorizeModuleOptions & { factoryResult: true }} options options
2064
+ * @param {ModuleCallback | ModuleFactoryResultCallback} callback callback
2065
+ */
2066
+ factorizeModule(options, callback) {
2067
+ this.factorizeQueue.add(
2068
+ options,
2069
+ /** @type {ModuleOrModuleFactoryResultCallback} */
2070
+ (callback)
2071
+ );
2072
+ }
2073
+
1953
2074
  /**
1954
2075
  * @typedef {object} HandleModuleCreationOptions
1955
2076
  * @property {ModuleFactory} factory
@@ -2197,92 +2318,6 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2197
2318
  });
2198
2319
  }
2199
2320
 
2200
- /**
2201
- * @param {FactorizeModuleOptions} options options object
2202
- * @param {ModuleOrFactoryResultCallback} callback callback
2203
- * @returns {void}
2204
- */
2205
- _factorizeModule(
2206
- {
2207
- currentProfile,
2208
- factory,
2209
- dependencies,
2210
- originModule,
2211
- factoryResult,
2212
- contextInfo,
2213
- context
2214
- },
2215
- callback
2216
- ) {
2217
- if (currentProfile !== undefined) {
2218
- currentProfile.markFactoryStart();
2219
- }
2220
- factory.create(
2221
- {
2222
- contextInfo: {
2223
- issuer: originModule
2224
- ? /** @type {string} */ (originModule.nameForCondition())
2225
- : "",
2226
- issuerLayer: originModule ? originModule.layer : null,
2227
- compiler: /** @type {string} */ (this.compiler.name),
2228
- ...contextInfo
2229
- },
2230
- resolveOptions: originModule ? originModule.resolveOptions : undefined,
2231
- context:
2232
- context ||
2233
- (originModule
2234
- ? /** @type {string} */ (originModule.context)
2235
- : /** @type {string} */ (this.compiler.context)),
2236
- dependencies
2237
- },
2238
- (err, result) => {
2239
- if (result) {
2240
- // TODO webpack 6: remove
2241
- // For backward-compat
2242
- if (result.module === undefined && result instanceof Module) {
2243
- result = {
2244
- module: result
2245
- };
2246
- }
2247
- if (!factoryResult) {
2248
- const {
2249
- fileDependencies,
2250
- contextDependencies,
2251
- missingDependencies
2252
- } = result;
2253
- if (fileDependencies) {
2254
- this.fileDependencies.addAll(fileDependencies);
2255
- }
2256
- if (contextDependencies) {
2257
- this.contextDependencies.addAll(contextDependencies);
2258
- }
2259
- if (missingDependencies) {
2260
- this.missingDependencies.addAll(missingDependencies);
2261
- }
2262
- }
2263
- }
2264
- if (err) {
2265
- const notFoundError = new ModuleNotFoundError(
2266
- originModule,
2267
- err,
2268
- /** @type {DependencyLocation} */
2269
- (dependencies.map((d) => d.loc).find(Boolean))
2270
- );
2271
- return callback(notFoundError, factoryResult ? result : undefined);
2272
- }
2273
- if (!result) {
2274
- return callback();
2275
- }
2276
-
2277
- if (currentProfile !== undefined) {
2278
- currentProfile.markFactoryEnd();
2279
- }
2280
-
2281
- callback(null, factoryResult ? result : result.module);
2282
- }
2283
- );
2284
- }
2285
-
2286
2321
  /**
2287
2322
  * @param {string} context context string path
2288
2323
  * @param {Dependency} dependency dependency used to create Module chain
@@ -2311,7 +2346,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2311
2346
  new WebpackError("Parameter 'dependency' must be a Dependency")
2312
2347
  );
2313
2348
  }
2314
- const Dep = /** @type {DepConstructor} */ (dependency.constructor);
2349
+ const Dep =
2350
+ /** @type {DependencyConstructor} */
2351
+ (dependency.constructor);
2315
2352
  const moduleFactory = this.dependencyFactories.get(Dep);
2316
2353
  if (!moduleFactory) {
2317
2354
  return callback(
@@ -2409,8 +2446,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2409
2446
  );
2410
2447
  } else {
2411
2448
  entryData[target].push(entry);
2412
- for (const _key of Object.keys(options)) {
2413
- const key = /** @type {keyof EntryOptions} */ (_key);
2449
+ for (const key_ of Object.keys(options)) {
2450
+ const key = /** @type {keyof EntryOptions} */ (key_);
2414
2451
  if (options[key] === undefined) continue;
2415
2452
  if (entryData.options[key] === options[key]) continue;
2416
2453
  if (
@@ -2421,10 +2458,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2421
2458
  continue;
2422
2459
  }
2423
2460
  if (entryData.options[key] === undefined) {
2424
- /** @type {TODO} */
2425
- (entryData.options)[key] =
2426
- /** @type {NonNullable<EntryOptions[keyof EntryOptions]>} */
2427
- (options[key]);
2461
+ /** @type {EntryOptions[keyof EntryOptions]} */
2462
+ (entryData.options[key]) = options[key];
2428
2463
  } else {
2429
2464
  return callback(
2430
2465
  new WebpackError(
@@ -2629,8 +2664,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2629
2664
  }
2630
2665
 
2631
2666
  /**
2632
- * @param {readonly ModuleGraphConnection[]} connections connections
2633
- * @returns {symbol|boolean} result
2667
+ * @param {Readonly<ModuleGraphConnection[]>} connections connections
2668
+ * @returns {symbol | boolean} result
2634
2669
  */
2635
2670
  const reduceAffectType = (connections) => {
2636
2671
  let affected = false;
@@ -2714,9 +2749,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2714
2749
  */
2715
2750
  const computeReferences = (module) => {
2716
2751
  const id = /** @type {ModuleId} */ (chunkGraph.getModuleId(module));
2717
- /** @type {Map<Module, string | number | undefined> | undefined} */
2752
+ /** @type {Map<Module, ModuleId> | undefined} */
2718
2753
  let modules;
2719
- /** @type {(string | number | null)[] | undefined} */
2754
+ /** @type {(ChunkId | null)[] | undefined} */
2720
2755
  let blocks;
2721
2756
  const outgoing = moduleGraph.getOutgoingConnectionsByModule(module);
2722
2757
  if (outgoing !== undefined) {
@@ -3097,15 +3132,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3097
3132
  this.addModuleQueue.clear();
3098
3133
  return callback(err);
3099
3134
  };
3100
- const chunkGraph = new ChunkGraph(
3101
- this.moduleGraph,
3102
- this.outputOptions.hashFunction
3103
- );
3104
- this.chunkGraph = chunkGraph;
3105
3135
 
3106
3136
  if (this._backCompat) {
3107
3137
  for (const module of this.modules) {
3108
- ChunkGraph.setChunkGraphForModule(module, chunkGraph);
3138
+ ChunkGraph.setChunkGraphForModule(module, this.chunkGraph);
3109
3139
  }
3110
3140
  }
3111
3141
 
@@ -3150,7 +3180,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3150
3180
 
3151
3181
  const module = this.moduleGraph.getModule(dep);
3152
3182
  if (module) {
3153
- chunkGraph.connectChunkAndEntryModule(chunk, module, entrypoint);
3183
+ this.chunkGraph.connectChunkAndEntryModule(chunk, module, entrypoint);
3154
3184
  entryModules.add(module);
3155
3185
  const modulesList = chunkGraphInit.get(entrypoint);
3156
3186
  if (modulesList === undefined) {
@@ -3549,7 +3579,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3549
3579
  let statModulesGenerated = 0;
3550
3580
  const { chunkGraph, moduleGraph, dependencyTemplates, runtimeTemplate } =
3551
3581
  this;
3552
- const results = this.codeGenerationResults;
3582
+ const results =
3583
+ /** @type {CodeGenerationResults} */
3584
+ (this.codeGenerationResults);
3553
3585
  /** @type {WebpackError[]} */
3554
3586
  const errors = [];
3555
3587
  /** @type {NotCodeGeneratedModules | undefined} */
@@ -3560,8 +3592,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3560
3592
  let delayedModules = new Set();
3561
3593
  asyncLib.eachLimit(
3562
3594
  jobs,
3563
- /** @type {number} */
3564
- (this.options.parallelism),
3595
+ this.options.parallelism,
3565
3596
  (job, callback) => {
3566
3597
  const { module } = job;
3567
3598
  const { codeGenerationDependencies } = module;
@@ -3745,7 +3776,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3745
3776
  chunkGraph = this.chunkGraph,
3746
3777
  modules = this.modules,
3747
3778
  chunks = this.chunks,
3748
- codeGenerationResults = this.codeGenerationResults,
3779
+ codeGenerationResults = /** @type {CodeGenerationResults} */ (
3780
+ this.codeGenerationResults
3781
+ ),
3749
3782
  chunkGraphEntries = this._getChunkGraphEntries()
3750
3783
  } = {}) {
3751
3784
  const context = { chunkGraph, codeGenerationResults };
@@ -3825,6 +3858,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3825
3858
 
3826
3859
  this.logger.time("runtime requirements.chunks");
3827
3860
  for (const chunk of chunks) {
3861
+ /** @type {RuntimeRequirements} */
3828
3862
  const set = new Set();
3829
3863
  for (const module of chunkGraph.getChunkModulesIterable(chunk)) {
3830
3864
  const runtimeRequirements = chunkGraph.getModuleRuntimeRequirements(
@@ -3845,6 +3879,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3845
3879
 
3846
3880
  this.logger.time("runtime requirements.entries");
3847
3881
  for (const treeEntry of chunkGraphEntries) {
3882
+ /** @type {RuntimeRequirements} */
3848
3883
  const set = new Set();
3849
3884
  for (const chunk of treeEntry.getAllReferencedChunks()) {
3850
3885
  const runtimeRequirements =
@@ -3984,12 +4019,10 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3984
4019
  if (name) {
3985
4020
  const entrypoint = this.namedChunkGroups.get(name);
3986
4021
  if (entrypoint instanceof Entrypoint) {
3987
- if (entrypoint !== undefined) {
3988
- if (module) {
3989
- entrypoint.addOrigin(module, loc, request);
3990
- }
3991
- return entrypoint;
4022
+ if (module) {
4023
+ entrypoint.addOrigin(module, loc, request);
3992
4024
  }
4025
+ return entrypoint;
3993
4026
  } else if (entrypoint) {
3994
4027
  throw new Error(
3995
4028
  `Cannot add an async entrypoint with the name '${name}', because there is already an chunk group with this name`
@@ -4112,7 +4145,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4112
4145
  /**
4113
4146
  * @param {Dependency} dependency the dependency
4114
4147
  * @param {RuntimeSpec} runtime the runtime
4115
- * @returns {(string[] | ReferencedExport)[]} referenced exports
4148
+ * @returns {ReferencedExports} referenced exports
4116
4149
  */
4117
4150
  getDependencyReferencedExports(dependency, runtime) {
4118
4151
  const referencedExports = dependency.getReferencedExports(
@@ -4320,10 +4353,10 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4320
4353
  * @param {Module} module module
4321
4354
  * @param {ChunkGraph} chunkGraph the chunk graph
4322
4355
  * @param {RuntimeSpec} runtime runtime
4323
- * @param {OutputOptions["hashFunction"]} hashFunction hash function
4356
+ * @param {HashFunction} hashFunction hash function
4324
4357
  * @param {RuntimeTemplate} runtimeTemplate runtime template
4325
- * @param {OutputOptions["hashDigest"]} hashDigest hash digest
4326
- * @param {OutputOptions["hashDigestLength"]} hashDigestLength hash digest length
4358
+ * @param {HashDigest} hashDigest hash digest
4359
+ * @param {HashDigestLength} hashDigestLength hash digest length
4327
4360
  * @param {WebpackError[]} errors errors
4328
4361
  * @returns {string} module hash digest
4329
4362
  */
@@ -4339,7 +4372,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4339
4372
  ) {
4340
4373
  let moduleHashDigest;
4341
4374
  try {
4342
- const moduleHash = createHash(/** @type {HashFunction} */ (hashFunction));
4375
+ const moduleHash = createHash(hashFunction);
4343
4376
  module.updateHash(moduleHash, {
4344
4377
  chunkGraph,
4345
4378
  runtime,
@@ -4367,7 +4400,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4367
4400
  const hashFunction = outputOptions.hashFunction;
4368
4401
  const hashDigest = outputOptions.hashDigest;
4369
4402
  const hashDigestLength = outputOptions.hashDigestLength;
4370
- const hash = createHash(/** @type {HashFunction} */ (hashFunction));
4403
+ const hash = createHash(hashFunction);
4371
4404
  if (outputOptions.hashSalt) {
4372
4405
  hash.update(outputOptions.hashSalt);
4373
4406
  }
@@ -4555,16 +4588,16 @@ This prevents using hashes of each other and should be avoided.`);
4555
4588
  this.logger.timeAggregate("hashing: hash runtime modules");
4556
4589
  try {
4557
4590
  this.logger.time("hashing: hash chunks");
4558
- const chunkHash = createHash(
4559
- /** @type {HashFunction} */ (hashFunction)
4560
- );
4591
+ const chunkHash = createHash(hashFunction);
4561
4592
  if (outputOptions.hashSalt) {
4562
4593
  chunkHash.update(outputOptions.hashSalt);
4563
4594
  }
4564
4595
  chunk.updateHash(chunkHash, chunkGraph);
4565
4596
  this.hooks.chunkHash.call(chunk, chunkHash, {
4566
4597
  chunkGraph,
4567
- codeGenerationResults: this.codeGenerationResults,
4598
+ codeGenerationResults:
4599
+ /** @type {CodeGenerationResults} */
4600
+ (this.codeGenerationResults),
4568
4601
  moduleGraph: this.moduleGraph,
4569
4602
  runtimeTemplate: this.runtimeTemplate
4570
4603
  });
@@ -4613,9 +4646,7 @@ This prevents using hashes of each other and should be avoided.`);
4613
4646
  for (const module of /** @type {Iterable<RuntimeModule>} */ (
4614
4647
  chunkGraph.getChunkFullHashModulesIterable(chunk)
4615
4648
  )) {
4616
- const moduleHash = createHash(
4617
- /** @type {HashFunction} */ (hashFunction)
4618
- );
4649
+ const moduleHash = createHash(hashFunction);
4619
4650
  module.updateHash(moduleHash, {
4620
4651
  chunkGraph,
4621
4652
  runtime: chunk.runtime,
@@ -4637,7 +4668,7 @@ This prevents using hashes of each other and should be avoided.`);
4637
4668
  (codeGenerationJobsMap.get(oldHash)).get(module)
4638
4669
  ).hash = moduleHashDigest;
4639
4670
  }
4640
- const chunkHash = createHash(/** @type {HashFunction} */ (hashFunction));
4671
+ const chunkHash = createHash(hashFunction);
4641
4672
  chunkHash.update(chunk.hash);
4642
4673
  chunkHash.update(this.hash);
4643
4674
  const chunkHashDigest =
@@ -4980,7 +5011,9 @@ This prevents using hashes of each other and should be avoided.`);
4980
5011
  hash: /** @type {string} */ (this.hash),
4981
5012
  fullHash: /** @type {string} */ (this.fullHash),
4982
5013
  outputOptions,
4983
- codeGenerationResults: this.codeGenerationResults,
5014
+ codeGenerationResults:
5015
+ /** @type {CodeGenerationResults} */
5016
+ (this.codeGenerationResults),
4984
5017
  moduleTemplates: this.moduleTemplates,
4985
5018
  dependencyTemplates: this.dependencyTemplates,
4986
5019
  chunkGraph: this.chunkGraph,
@@ -5193,7 +5226,7 @@ This prevents using hashes of each other and should be avoided.`);
5193
5226
  * from parent (or top level compiler) and creates a child Compilation
5194
5227
  * @param {string} name name of the child compiler
5195
5228
  * @param {Partial<OutputOptions>=} outputOptions // Need to convert config schema to types for this
5196
- * @param {Array<WebpackPluginInstance | WebpackPluginFunction>=} plugins webpack plugins that will be applied
5229
+ * @param {Plugins=} plugins webpack plugins that will be applied
5197
5230
  * @returns {Compiler} creates a child Compiler instance
5198
5231
  */
5199
5232
  createChildCompiler(name, outputOptions, plugins) {
@@ -5408,7 +5441,6 @@ This prevents using hashes of each other and should be avoided.`);
5408
5441
  const moduleArgument = {
5409
5442
  module,
5410
5443
  codeGenerationResult,
5411
- preparedInfo: undefined,
5412
5444
  moduleObject: undefined
5413
5445
  };
5414
5446
  moduleArgumentsMap.set(module, moduleArgument);
@@ -5584,7 +5616,7 @@ This prevents using hashes of each other and should be avoided.`);
5584
5616
  checkConstraints() {
5585
5617
  const chunkGraph = this.chunkGraph;
5586
5618
 
5587
- /** @type {Set<number|string>} */
5619
+ /** @type {Set<ModuleId>} */
5588
5620
  const usedIds = new Set();
5589
5621
 
5590
5622
  for (const module of this.modules) {
@@ -5639,19 +5671,6 @@ This prevents using hashes of each other and should be avoided.`);
5639
5671
  * @returns {void}
5640
5672
  */
5641
5673
 
5642
- // Workaround for typescript as it doesn't support function overloading in jsdoc within a class
5643
- /* eslint-disable jsdoc/require-asterisk-prefix */
5644
- Compilation.prototype.factorizeModule = /**
5645
- @type {{
5646
- (options: FactorizeModuleOptions & { factoryResult?: false }, callback: ModuleCallback): void;
5647
- (options: FactorizeModuleOptions & { factoryResult: true }, callback: ModuleFactoryResultCallback): void;
5648
- }} */ (
5649
- function factorizeModule(options, callback) {
5650
- this.factorizeQueue.add(options, /** @type {TODO} */ (callback));
5651
- }
5652
- );
5653
- /* eslint-enable jsdoc/require-asterisk-prefix */
5654
-
5655
5674
  // Hide from typescript
5656
5675
  const compilationPrototype = Compilation.prototype;
5657
5676