@depup/webpack 5.106.0-depup.0 → 5.109.0-depup.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 (667) hide show
  1. package/README.md +9 -11
  2. package/changes.json +16 -24
  3. package/hot/dev-server.js +2 -0
  4. package/lib/APIPlugin.js +60 -35
  5. package/lib/AsyncDependenciesBlock.js +3 -0
  6. package/lib/AutomaticPrefetchPlugin.js +6 -1
  7. package/lib/BannerPlugin.js +13 -5
  8. package/lib/Cache.js +27 -5
  9. package/lib/CacheFacade.js +41 -0
  10. package/lib/Chunk.js +71 -25
  11. package/lib/ChunkGraph.js +141 -9
  12. package/lib/ChunkGroup.js +115 -28
  13. package/lib/ChunkTemplate.js +9 -0
  14. package/lib/CircularModulesPlugin.js +190 -0
  15. package/lib/CleanPlugin.js +23 -26
  16. package/lib/CodeGenerationResults.js +19 -0
  17. package/lib/CompatibilityPlugin.js +54 -37
  18. package/lib/Compilation.js +635 -107
  19. package/lib/Compiler.js +93 -31
  20. package/lib/ConcatenationScope.js +34 -4
  21. package/lib/ConditionalInitFragment.js +6 -0
  22. package/lib/ConstPlugin.js +15 -12
  23. package/lib/ContextExclusionPlugin.js +3 -1
  24. package/lib/ContextModule.js +345 -55
  25. package/lib/ContextModuleFactory.js +193 -51
  26. package/lib/ContextReplacementPlugin.js +8 -1
  27. package/lib/DefinePlugin.js +498 -127
  28. package/lib/DependenciesBlock.js +6 -1
  29. package/lib/Dependency.js +159 -11
  30. package/lib/DependencyTemplate.js +7 -1
  31. package/lib/DependencyTemplates.js +4 -0
  32. package/lib/DotenvPlugin.js +3 -0
  33. package/lib/DynamicEntryPlugin.js +3 -1
  34. package/lib/EntryOptionPlugin.js +42 -2
  35. package/lib/EntryPlugin.js +4 -1
  36. package/lib/Entrypoint.js +5 -1
  37. package/lib/EnvironmentPlugin.js +3 -2
  38. package/lib/ErrorHelpers.js +7 -0
  39. package/lib/EvalDevToolModulePlugin.js +3 -1
  40. package/lib/EvalSourceMapDevToolPlugin.js +11 -11
  41. package/lib/ExportsInfo.js +399 -108
  42. package/lib/ExportsInfoApiPlugin.js +4 -3
  43. package/lib/ExternalModule.js +376 -78
  44. package/lib/ExternalModuleFactoryPlugin.js +75 -3
  45. package/lib/ExternalsPlugin.js +3 -1
  46. package/lib/FileSystemInfo.js +575 -149
  47. package/lib/FlagAllModulesAsUsedPlugin.js +3 -6
  48. package/lib/FlagDependencyExportsPlugin.js +82 -9
  49. package/lib/FlagDependencyUsagePlugin.js +92 -6
  50. package/lib/FlagEntryExportAsUsedPlugin.js +4 -1
  51. package/lib/Generator.js +24 -3
  52. package/lib/HotModuleReplacementPlugin.js +110 -44
  53. package/lib/IgnorePlugin.js +5 -2
  54. package/lib/IgnoreWarningsPlugin.js +2 -1
  55. package/lib/InitFragment.js +15 -0
  56. package/lib/JavascriptMetaInfoPlugin.js +9 -6
  57. package/lib/LazyBarrel.js +389 -0
  58. package/lib/LibraryTemplatePlugin.js +2 -1
  59. package/lib/LoaderOptionsPlugin.js +3 -1
  60. package/lib/LoaderTargetPlugin.js +3 -1
  61. package/lib/MainTemplate.js +15 -0
  62. package/lib/ManifestPlugin.js +9 -2
  63. package/lib/Module.js +121 -60
  64. package/lib/ModuleFactory.js +6 -1
  65. package/lib/ModuleFilenameHelpers.js +5 -2
  66. package/lib/ModuleGraph.js +69 -2
  67. package/lib/ModuleGraphConnection.js +9 -0
  68. package/lib/ModuleInfoHeaderPlugin.js +5 -0
  69. package/lib/ModuleNotFoundError.js +3 -83
  70. package/lib/ModuleProfile.js +27 -1
  71. package/lib/ModuleSourceTypeConstants.js +52 -19
  72. package/lib/ModuleTemplate.js +10 -0
  73. package/lib/ModuleTypeConstants.js +20 -4
  74. package/lib/MultiCompiler.js +59 -4
  75. package/lib/MultiStats.js +9 -0
  76. package/lib/MultiWatching.js +6 -0
  77. package/lib/NoEmitOnErrorsPlugin.js +1 -1
  78. package/lib/NodeStuffPlugin.js +78 -46
  79. package/lib/NormalModule.js +485 -181
  80. package/lib/NormalModuleFactory.js +148 -29
  81. package/lib/NormalModuleReplacementPlugin.js +3 -1
  82. package/lib/NullFactory.js +1 -0
  83. package/lib/OptionsApply.js +1 -0
  84. package/lib/Parser.js +3 -1
  85. package/lib/PlatformPlugin.js +2 -1
  86. package/lib/PrefetchPlugin.js +4 -1
  87. package/lib/ProgressPlugin.js +351 -161
  88. package/lib/ProvidePlugin.js +6 -3
  89. package/lib/RawModule.js +32 -16
  90. package/lib/RecordIdsPlugin.js +9 -0
  91. package/lib/RequestShortener.js +8 -0
  92. package/lib/ResolverFactory.js +5 -0
  93. package/lib/RuntimeGlobals.js +58 -5
  94. package/lib/RuntimeModule.js +22 -7
  95. package/lib/RuntimePlugin.js +104 -26
  96. package/lib/RuntimeTemplate.js +616 -37
  97. package/lib/SelfModuleFactory.js +3 -0
  98. package/lib/SourceMapDevToolModuleOptionsPlugin.js +2 -0
  99. package/lib/SourceMapDevToolPlugin.js +341 -63
  100. package/lib/Stats.js +6 -0
  101. package/lib/Template.js +29 -3
  102. package/lib/TemplatedPathPlugin.js +505 -138
  103. package/lib/UseStrictPlugin.js +3 -2
  104. package/lib/WarnCaseSensitiveModulesPlugin.js +72 -3
  105. package/lib/WarnDeprecatedOptionPlugin.js +6 -2
  106. package/lib/WarnNoModeSetPlugin.js +18 -2
  107. package/lib/WatchIgnorePlugin.js +5 -1
  108. package/lib/Watching.js +25 -3
  109. package/lib/WebpackError.js +3 -74
  110. package/lib/WebpackIsIncludedPlugin.js +4 -2
  111. package/lib/WebpackOptionsApply.js +88 -25
  112. package/lib/WebpackOptionsDefaulter.js +1 -0
  113. package/lib/asset/AssetBytesGenerator.js +28 -10
  114. package/lib/asset/AssetBytesParser.js +1 -0
  115. package/lib/asset/AssetGenerator.js +199 -60
  116. package/lib/asset/AssetModule.js +47 -0
  117. package/lib/asset/AssetModulesPlugin.js +115 -24
  118. package/lib/asset/AssetParser.js +4 -2
  119. package/lib/asset/AssetSourceGenerator.js +26 -8
  120. package/lib/asset/AssetSourceParser.js +1 -0
  121. package/lib/asset/RawDataUrlModule.js +23 -13
  122. package/lib/asset/WebManifestGenerator.js +164 -0
  123. package/lib/asset/WebManifestParser.js +130 -0
  124. package/lib/async-modules/AsyncModuleHelpers.js +1 -0
  125. package/lib/async-modules/AwaitDependenciesInitFragment.js +18 -4
  126. package/lib/async-modules/InferAsyncModulesPlugin.js +1 -1
  127. package/lib/async-modules/isGeneratorLowered.js +26 -0
  128. package/lib/buildChunkGraph.js +107 -15
  129. package/lib/bun/BunTargetPlugin.js +42 -0
  130. package/lib/cache/AddBuildDependenciesPlugin.js +3 -1
  131. package/lib/cache/AddManagedPathsPlugin.js +5 -1
  132. package/lib/cache/IdleFileCachePlugin.js +6 -1
  133. package/lib/cache/MemoryCachePlugin.js +1 -1
  134. package/lib/cache/MemoryWithGcCachePlugin.js +4 -1
  135. package/lib/cache/PackFileCacheStrategy.js +43 -7
  136. package/lib/cache/ResolverCachePlugin.js +12 -1
  137. package/lib/cache/getLazyHashedEtag.js +13 -2
  138. package/lib/cache/mergeEtags.js +4 -0
  139. package/lib/cli.js +142 -20
  140. package/lib/config/browserslistTargetHandler.js +141 -0
  141. package/lib/config/defaults.js +591 -41
  142. package/lib/config/defineConfig.js +31 -0
  143. package/lib/config/normalization.js +46 -1
  144. package/lib/config/target.js +200 -2
  145. package/lib/container/ContainerEntryDependency.js +2 -0
  146. package/lib/container/ContainerEntryModule.js +27 -14
  147. package/lib/container/ContainerEntryModuleFactory.js +1 -0
  148. package/lib/container/ContainerExposedDependency.js +6 -2
  149. package/lib/container/ContainerPlugin.js +2 -1
  150. package/lib/container/ContainerReferencePlugin.js +3 -2
  151. package/lib/container/FallbackDependency.js +9 -7
  152. package/lib/container/FallbackItemDependency.js +1 -0
  153. package/lib/container/FallbackModule.js +22 -9
  154. package/lib/container/FallbackModuleFactory.js +1 -0
  155. package/lib/container/ModuleFederationPlugin.js +12 -26
  156. package/lib/container/RemoteModule.js +33 -10
  157. package/lib/container/RemoteRuntimeModule.js +15 -12
  158. package/lib/container/RemoteToExternalDependency.js +1 -0
  159. package/lib/container/options.js +7 -0
  160. package/lib/css/CssGenerator.js +534 -272
  161. package/lib/css/CssInjectStyleRuntimeModule.js +86 -70
  162. package/lib/css/CssLoadingRuntimeModule.js +156 -77
  163. package/lib/{CssModule.js → css/CssModule.js} +72 -37
  164. package/lib/css/CssModulesPlugin.js +356 -204
  165. package/lib/css/CssParser.js +3452 -1950
  166. package/lib/css/syntax.js +4058 -0
  167. package/lib/debug/ProfilingPlugin.js +33 -2
  168. package/lib/deno/DenoTargetPlugin.js +41 -0
  169. package/lib/dependencies/AMDDefineDependency.js +29 -17
  170. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +19 -6
  171. package/lib/dependencies/AMDPlugin.js +6 -3
  172. package/lib/dependencies/AMDRequireArrayDependency.js +13 -11
  173. package/lib/dependencies/AMDRequireContextDependency.js +10 -11
  174. package/lib/dependencies/AMDRequireDependenciesBlock.js +1 -0
  175. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +28 -14
  176. package/lib/dependencies/AMDRequireDependency.js +28 -20
  177. package/lib/dependencies/AMDRequireItemDependency.js +1 -0
  178. package/lib/dependencies/AMDRuntimeModules.js +3 -0
  179. package/lib/dependencies/CachedConstDependency.js +9 -1
  180. package/lib/dependencies/CommonJsDependencyHelpers.js +104 -0
  181. package/lib/dependencies/CommonJsExportRequireDependency.js +138 -38
  182. package/lib/dependencies/CommonJsExportsDependency.js +74 -20
  183. package/lib/dependencies/CommonJsExportsParserPlugin.js +246 -15
  184. package/lib/dependencies/CommonJsFullRequireDependency.js +62 -27
  185. package/lib/dependencies/CommonJsImportsParserPlugin.js +187 -24
  186. package/lib/dependencies/CommonJsPlugin.js +7 -4
  187. package/lib/dependencies/CommonJsRequireContextDependency.js +13 -13
  188. package/lib/dependencies/CommonJsRequireDependency.js +135 -13
  189. package/lib/dependencies/CommonJsSelfReferenceDependency.js +60 -16
  190. package/lib/dependencies/ConstDependency.js +22 -12
  191. package/lib/dependencies/ContextDependency.js +13 -2
  192. package/lib/dependencies/ContextDependencyHelpers.js +7 -4
  193. package/lib/dependencies/ContextDependencyTemplateAsId.js +2 -1
  194. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +1 -0
  195. package/lib/dependencies/ContextElementDependency.js +27 -14
  196. package/lib/dependencies/CreateRequireParserPlugin.js +14 -7
  197. package/lib/dependencies/CreateScriptUrlDependency.js +9 -7
  198. package/lib/dependencies/CriticalDependencyWarning.js +3 -1
  199. package/lib/dependencies/CssIcssExportDependency.js +682 -368
  200. package/lib/dependencies/CssIcssImportDependency.js +62 -17
  201. package/lib/dependencies/CssIcssSymbolDependency.js +36 -17
  202. package/lib/dependencies/CssImportDependency.js +37 -1
  203. package/lib/dependencies/CssUrlDependency.js +87 -14
  204. package/lib/dependencies/DelegatedSourceDependency.js +1 -0
  205. package/lib/dependencies/DllEntryDependency.js +12 -13
  206. package/lib/dependencies/DynamicExports.js +5 -0
  207. package/lib/dependencies/EntryDependency.js +1 -0
  208. package/lib/dependencies/ExportBindingInitFragment.js +164 -0
  209. package/lib/dependencies/ExportsInfoDependency.js +18 -12
  210. package/lib/dependencies/ExternalModuleDependency.js +13 -5
  211. package/lib/dependencies/ExternalModuleInitFragment.js +10 -5
  212. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +19 -12
  213. package/lib/dependencies/HarmonyAcceptDependency.js +24 -26
  214. package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -0
  215. package/lib/dependencies/HarmonyCompatibilityDependency.js +33 -14
  216. package/lib/dependencies/HarmonyDetectionParserPlugin.js +108 -30
  217. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +32 -2
  218. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +70 -33
  219. package/lib/dependencies/HarmonyExportExpressionDependency.js +140 -46
  220. package/lib/dependencies/HarmonyExportHeaderDependency.js +11 -9
  221. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +253 -37
  222. package/lib/dependencies/HarmonyExportInitFragment.js +28 -20
  223. package/lib/dependencies/HarmonyExportSpecifierDependency.js +88 -18
  224. package/lib/dependencies/HarmonyExports.js +6 -1
  225. package/lib/dependencies/HarmonyImportDependency.js +59 -3
  226. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +139 -146
  227. package/lib/dependencies/HarmonyImportGuard.js +426 -0
  228. package/lib/dependencies/HarmonyImportSideEffectDependency.js +22 -1
  229. package/lib/dependencies/HarmonyImportSpecifierDependency.js +136 -17
  230. package/lib/{HarmonyLinkingError.js → dependencies/HarmonyLinkingError.js} +6 -3
  231. package/lib/dependencies/HarmonyModulesPlugin.js +11 -1
  232. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +2 -1
  233. package/lib/dependencies/HtmlEntryDependency.js +1295 -0
  234. package/lib/dependencies/HtmlInlineHtmlDependency.js +107 -0
  235. package/lib/dependencies/HtmlInlineScriptDependency.js +126 -0
  236. package/lib/dependencies/HtmlInlineStyleDependency.js +152 -0
  237. package/lib/dependencies/HtmlSourceDependency.js +172 -0
  238. package/lib/dependencies/ImportContextDependency.js +9 -9
  239. package/lib/dependencies/ImportDependency.js +92 -3
  240. package/lib/dependencies/ImportEagerDependency.js +2 -0
  241. package/lib/dependencies/ImportMetaContextDependency.js +1 -0
  242. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +35 -19
  243. package/lib/dependencies/ImportMetaContextPlugin.js +40 -8
  244. package/lib/dependencies/ImportMetaGlobDependency.js +81 -0
  245. package/lib/dependencies/ImportMetaGlobDependencyParserPlugin.js +78 -0
  246. package/lib/dependencies/ImportMetaGlobHelpers.js +660 -0
  247. package/lib/dependencies/ImportMetaHotAcceptDependency.js +2 -0
  248. package/lib/dependencies/ImportMetaHotDeclineDependency.js +2 -0
  249. package/lib/dependencies/ImportMetaPlugin.js +595 -209
  250. package/lib/dependencies/ImportMetaResolveDependency.js +90 -0
  251. package/lib/dependencies/ImportParserPlugin.js +114 -27
  252. package/lib/dependencies/ImportPhase.js +17 -11
  253. package/lib/dependencies/ImportPlugin.js +2 -1
  254. package/lib/dependencies/ImportWeakDependency.js +3 -0
  255. package/lib/dependencies/JsonExportsDependency.js +15 -10
  256. package/lib/dependencies/LoaderDependency.js +2 -0
  257. package/lib/dependencies/LoaderImportDependency.js +3 -0
  258. package/lib/dependencies/LoaderPlugin.js +9 -2
  259. package/lib/dependencies/LocalModule.js +15 -12
  260. package/lib/dependencies/LocalModuleDependency.js +15 -13
  261. package/lib/dependencies/LocalModulesHelpers.js +3 -0
  262. package/lib/dependencies/ModuleDecoratorDependency.js +16 -10
  263. package/lib/dependencies/ModuleDependency.js +14 -0
  264. package/lib/dependencies/ModuleDependencyTemplateAsId.js +1 -0
  265. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
  266. package/lib/dependencies/ModuleHotAcceptDependency.js +2 -0
  267. package/lib/dependencies/ModuleHotDeclineDependency.js +2 -0
  268. package/lib/dependencies/ModuleInitFragmentDependency.js +19 -11
  269. package/lib/dependencies/NullDependency.js +2 -0
  270. package/lib/dependencies/PrefetchDependency.js +1 -0
  271. package/lib/dependencies/ProvidedDependency.js +36 -27
  272. package/lib/dependencies/PureExpressionDependency.js +14 -10
  273. package/lib/dependencies/RequireContextDependency.js +1 -0
  274. package/lib/dependencies/RequireContextDependencyParserPlugin.js +2 -1
  275. package/lib/dependencies/RequireContextPlugin.js +2 -1
  276. package/lib/dependencies/RequireEnsureDependenciesBlock.js +1 -0
  277. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +4 -6
  278. package/lib/dependencies/RequireEnsureDependency.js +16 -13
  279. package/lib/dependencies/RequireEnsureItemDependency.js +1 -0
  280. package/lib/dependencies/RequireEnsurePlugin.js +2 -1
  281. package/lib/dependencies/RequireHeaderDependency.js +7 -4
  282. package/lib/dependencies/RequireIncludeDependency.js +2 -0
  283. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +11 -12
  284. package/lib/dependencies/RequireIncludePlugin.js +2 -1
  285. package/lib/{RequireJsStuffPlugin.js → dependencies/RequireJsStuffPlugin.js} +9 -8
  286. package/lib/dependencies/RequireResolveContextDependency.js +10 -11
  287. package/lib/dependencies/RequireResolveDependency.js +2 -0
  288. package/lib/dependencies/RequireResolveHeaderDependency.js +8 -5
  289. package/lib/dependencies/RuntimeRequirementsDependency.js +11 -8
  290. package/lib/dependencies/StaticExportsDependency.js +13 -10
  291. package/lib/dependencies/SystemPlugin.js +9 -6
  292. package/lib/dependencies/SystemRuntimeModule.js +1 -0
  293. package/lib/dependencies/TopLevelAwaitDependency.js +93 -0
  294. package/lib/dependencies/URLContextDependency.js +8 -7
  295. package/lib/dependencies/URLDependency.js +157 -33
  296. package/lib/dependencies/URLPlugin.js +2 -0
  297. package/lib/dependencies/UnsupportedDependency.js +12 -13
  298. package/lib/dependencies/WebAssemblyExportImportedDependency.js +15 -16
  299. package/lib/dependencies/WebAssemblyImportDependency.js +19 -18
  300. package/lib/dependencies/WebpackIsIncludedDependency.js +3 -0
  301. package/lib/dependencies/{WorkerPlugin.js → WorkerAndWorkletPlugin.js} +364 -114
  302. package/lib/dependencies/WorkerDependency.js +111 -27
  303. package/lib/dependencies/WorkletDependency.js +278 -0
  304. package/lib/dependencies/getFunctionExpression.js +1 -0
  305. package/lib/dependencies/processExportInfo.js +14 -11
  306. package/lib/{DelegatedModule.js → dll/DelegatedModule.js} +71 -44
  307. package/lib/{DelegatedModuleFactoryPlugin.js → dll/DelegatedModuleFactoryPlugin.js} +27 -4
  308. package/lib/{DelegatedPlugin.js → dll/DelegatedPlugin.js} +5 -3
  309. package/lib/{DllEntryPlugin.js → dll/DllEntryPlugin.js} +9 -5
  310. package/lib/{DllModule.js → dll/DllModule.js} +36 -24
  311. package/lib/{DllModuleFactory.js → dll/DllModuleFactory.js} +5 -4
  312. package/lib/{DllPlugin.js → dll/DllPlugin.js} +24 -6
  313. package/lib/{DllReferencePlugin.js → dll/DllReferencePlugin.js} +26 -18
  314. package/lib/{LibManifestPlugin.js → dll/LibManifestPlugin.js} +14 -10
  315. package/lib/electron/ElectronTargetPlugin.js +24 -5
  316. package/lib/{AbstractMethodError.js → errors/AbstractMethodError.js} +10 -1
  317. package/lib/{AsyncDependencyToInitialChunkError.js → errors/AsyncDependencyToInitialChunkError.js} +8 -3
  318. package/lib/errors/BuildCycleError.js +1 -1
  319. package/lib/{ChunkRenderError.js → errors/ChunkRenderError.js} +1 -1
  320. package/lib/{CodeGenerationError.js → errors/CodeGenerationError.js} +1 -1
  321. package/lib/{CommentCompilationWarning.js → errors/CommentCompilationWarning.js} +9 -3
  322. package/lib/{ConcurrentCompilationError.js → errors/ConcurrentCompilationError.js} +5 -2
  323. package/lib/{EnvironmentNotSupportAsyncWarning.js → errors/EnvironmentNotSupportAsyncWarning.js} +5 -5
  324. package/lib/{HookWebpackError.js → errors/HookWebpackError.js} +20 -16
  325. package/lib/{IgnoreErrorModuleFactory.js → errors/IgnoreErrorModuleFactory.js} +7 -4
  326. package/lib/{InvalidDependenciesModuleWarning.js → errors/InvalidDependenciesModuleWarning.js} +6 -3
  327. package/lib/errors/JSONParseError.js +115 -0
  328. package/lib/errors/LoaderLoadingError.js +20 -0
  329. package/lib/{ModuleBuildError.js → errors/ModuleBuildError.js} +22 -16
  330. package/lib/{ModuleDependencyError.js → errors/ModuleDependencyError.js} +10 -3
  331. package/lib/{ModuleDependencyWarning.js → errors/ModuleDependencyWarning.js} +13 -5
  332. package/lib/{ModuleError.js → errors/ModuleError.js} +10 -14
  333. package/lib/{ModuleHashingError.js → errors/ModuleHashingError.js} +5 -1
  334. package/lib/errors/ModuleNotFoundError.js +94 -0
  335. package/lib/errors/ModuleParseError.js +141 -0
  336. package/lib/{ModuleRestoreError.js → errors/ModuleRestoreError.js} +4 -1
  337. package/lib/{ModuleStoreError.js → errors/ModuleStoreError.js} +5 -1
  338. package/lib/{ModuleWarning.js → errors/ModuleWarning.js} +13 -14
  339. package/lib/{NodeStuffInWebError.js → errors/NodeStuffInWebError.js} +7 -5
  340. package/lib/errors/NonErrorEmittedError.js +30 -0
  341. package/lib/{UnhandledSchemeError.js → errors/UnhandledSchemeError.js} +9 -2
  342. package/lib/{UnsupportedFeatureWarning.js → errors/UnsupportedFeatureWarning.js} +4 -3
  343. package/lib/errors/WebpackError.js +84 -0
  344. package/lib/esm/ExportWebpackRequireRuntimeModule.js +2 -0
  345. package/lib/esm/ModuleChunkFormatPlugin.js +52 -15
  346. package/lib/esm/ModuleChunkLoadingPlugin.js +11 -3
  347. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +71 -49
  348. package/lib/hmr/HotModuleReplacement.runtime.js +175 -30
  349. package/lib/hmr/HotModuleReplacementRuntimeModule.js +8 -0
  350. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +173 -26
  351. package/lib/hmr/JavascriptHotModuleReplacementHelper.js +1 -0
  352. package/lib/hmr/LazyCompilationPlugin.js +154 -7
  353. package/lib/hmr/lazyCompilationBackend.js +34 -8
  354. package/lib/html/HtmlGenerator.js +1470 -0
  355. package/lib/html/HtmlModule.js +41 -0
  356. package/lib/html/HtmlModulesPlugin.js +1111 -0
  357. package/lib/html/HtmlParser.js +1970 -0
  358. package/lib/html/favicon.svg +1 -0
  359. package/lib/html/syntax.js +9020 -0
  360. package/lib/ids/ChunkModuleIdRangePlugin.js +3 -1
  361. package/lib/ids/DeterministicChunkIdsPlugin.js +3 -1
  362. package/lib/ids/DeterministicModuleIdsPlugin.js +3 -1
  363. package/lib/ids/HashedModuleIdsPlugin.js +2 -1
  364. package/lib/ids/IdHelpers.js +25 -2
  365. package/lib/ids/NamedChunkIdsPlugin.js +3 -1
  366. package/lib/ids/NamedModuleIdsPlugin.js +3 -1
  367. package/lib/ids/NaturalChunkIdsPlugin.js +1 -1
  368. package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
  369. package/lib/ids/OccurrenceChunkIdsPlugin.js +2 -1
  370. package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -1
  371. package/lib/ids/SyncModuleIdsPlugin.js +3 -1
  372. package/lib/index.js +66 -15
  373. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +5 -6
  374. package/lib/javascript/BasicEvaluatedExpression.js +370 -49
  375. package/lib/javascript/ChunkFormatHelpers.js +2 -1
  376. package/lib/javascript/ChunkHelpers.js +1 -0
  377. package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
  378. package/lib/javascript/EnableChunkLoadingPlugin.js +6 -1
  379. package/lib/javascript/JavascriptGenerator.js +213 -51
  380. package/lib/javascript/JavascriptModule.js +54 -0
  381. package/lib/javascript/JavascriptModulesPlugin.js +579 -183
  382. package/lib/javascript/JavascriptParser.js +1289 -462
  383. package/lib/javascript/JavascriptParserHelpers.js +10 -7
  384. package/lib/javascript/StartupHelpers.js +5 -0
  385. package/lib/javascript/syntax.js +4380 -0
  386. package/lib/json/JsonData.js +5 -0
  387. package/lib/json/JsonGenerator.js +21 -0
  388. package/lib/json/JsonModule.js +40 -0
  389. package/lib/json/JsonModulesPlugin.js +8 -1
  390. package/lib/json/JsonParser.js +18 -27
  391. package/lib/library/AbstractLibraryPlugin.js +17 -2
  392. package/lib/library/AmdLibraryPlugin.js +8 -0
  393. package/lib/library/AssignLibraryPlugin.js +21 -3
  394. package/lib/library/EnableLibraryPlugin.js +8 -2
  395. package/lib/library/ExportPropertyLibraryPlugin.js +10 -0
  396. package/lib/{FalseIIFEUmdWarning.js → library/FalseIIFEUmdWarning.js} +2 -1
  397. package/lib/library/JsonpLibraryPlugin.js +8 -0
  398. package/lib/library/ModuleLibraryPlugin.js +154 -7
  399. package/lib/library/SystemLibraryPlugin.js +11 -3
  400. package/lib/library/UmdLibraryPlugin.js +16 -0
  401. package/lib/loaders/LoaderRunner.js +714 -0
  402. package/lib/loaders/loadLoader.js +100 -0
  403. package/lib/logging/Logger.js +17 -0
  404. package/lib/logging/createConsoleLogger.js +7 -0
  405. package/lib/logging/runtime.js +2 -0
  406. package/lib/logging/truncateArgs.js +2 -0
  407. package/lib/node/CommonJsChunkLoadingPlugin.js +5 -1
  408. package/lib/node/NodeEnvironmentPlugin.js +7 -3
  409. package/lib/node/NodeSourcePlugin.js +1 -1
  410. package/lib/node/NodeTargetPlugin.js +4 -63
  411. package/lib/node/NodeTemplatePlugin.js +3 -1
  412. package/lib/node/NodeWatchFileSystem.js +40 -22
  413. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +13 -9
  414. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +23 -1
  415. package/lib/node/ReadFileCompileWasmPlugin.js +18 -1
  416. package/lib/node/RequireChunkLoadingRuntimeModule.js +21 -16
  417. package/lib/node/nodeBuiltins.js +80 -0
  418. package/lib/node/nodeConsole.js +116 -64
  419. package/lib/optimize/AggressiveMergingPlugin.js +3 -1
  420. package/lib/optimize/AggressiveSplittingPlugin.js +6 -1
  421. package/lib/optimize/ConcatenatedModule.js +585 -116
  422. package/lib/optimize/ConstExportsPlugin.js +211 -0
  423. package/lib/optimize/EnsureChunkConditionsPlugin.js +2 -1
  424. package/lib/optimize/FlagIncludedChunksPlugin.js +15 -4
  425. package/lib/optimize/InlineExports.js +178 -0
  426. package/lib/optimize/InnerGraph.js +374 -262
  427. package/lib/optimize/InnerGraphPlugin.js +246 -117
  428. package/lib/optimize/LimitChunkCountPlugin.js +9 -0
  429. package/lib/optimize/MangleExportsPlugin.js +5 -1
  430. package/lib/optimize/MergeDuplicateChunksPlugin.js +2 -0
  431. package/lib/optimize/MinChunkSizePlugin.js +2 -1
  432. package/lib/optimize/MinMaxSizeWarning.js +5 -4
  433. package/lib/optimize/ModuleConcatenationPlugin.js +159 -34
  434. package/lib/optimize/RealContentHashPlugin.js +125 -50
  435. package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -1
  436. package/lib/optimize/RemoveParentModulesPlugin.js +3 -1
  437. package/lib/optimize/RuntimeChunkPlugin.js +2 -1
  438. package/lib/optimize/SideEffectsFlagPlugin.js +381 -55
  439. package/lib/optimize/SplitChunksPlugin.js +54 -6
  440. package/lib/performance/AssetsOverSizeLimitWarning.js +3 -2
  441. package/lib/performance/EntrypointsOverSizeLimitWarning.js +3 -2
  442. package/lib/performance/NoAsyncChunksWarning.js +5 -3
  443. package/lib/performance/SizeLimitsPlugin.js +8 -2
  444. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +1 -0
  445. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +21 -0
  446. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +1 -0
  447. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +5 -1
  448. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +25 -13
  449. package/lib/prefetch/ResourceHintPlugin.js +663 -0
  450. package/lib/prefetch/ResourceHintRuntimeModule.js +149 -0
  451. package/lib/prefetch/StartupAssetHintRuntimeModule.js +210 -0
  452. package/lib/prefetch/parseResourceHintOptions.js +103 -0
  453. package/lib/rules/BasicEffectRulePlugin.js +3 -0
  454. package/lib/rules/BasicMatcherRulePlugin.js +3 -0
  455. package/lib/rules/ObjectMatcherRulePlugin.js +3 -0
  456. package/lib/rules/RuleSetCompiler.js +132 -0
  457. package/lib/rules/UseEffectRulePlugin.js +10 -3
  458. package/lib/runtime/AsyncModuleGeneratorRuntimeModule.js +56 -0
  459. package/lib/runtime/AsyncModuleRuntimeModule.js +52 -33
  460. package/lib/runtime/AutoPublicPathRuntimeModule.js +22 -9
  461. package/lib/runtime/BaseUriRuntimeModule.js +1 -0
  462. package/lib/runtime/ChunkNameRuntimeModule.js +1 -0
  463. package/lib/runtime/CommonJsWrapRuntimeModule.js +37 -0
  464. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +2 -1
  465. package/lib/runtime/CompatRuntimeModule.js +2 -0
  466. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +7 -4
  467. package/lib/runtime/CreateScriptRuntimeModule.js +1 -0
  468. package/lib/runtime/CreateScriptUrlRuntimeModule.js +1 -0
  469. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +34 -4
  470. package/lib/runtime/EnsureChunkRuntimeModule.js +1 -0
  471. package/lib/runtime/GetChunkFilenameRuntimeModule.js +88 -8
  472. package/lib/runtime/GetFullHashRuntimeModule.js +1 -0
  473. package/lib/runtime/GetMainFilenameRuntimeModule.js +1 -0
  474. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
  475. package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +59 -0
  476. package/lib/runtime/GlobalRuntimeModule.js +1 -0
  477. package/lib/runtime/HasOwnPropertyRuntimeModule.js +2 -1
  478. package/lib/runtime/HelperRuntimeModule.js +5 -0
  479. package/lib/runtime/LoadScriptRuntimeModule.js +28 -37
  480. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +354 -37
  481. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +2 -1
  482. package/lib/runtime/NonceRuntimeModule.js +1 -0
  483. package/lib/runtime/OnChunksLoadedRuntimeModule.js +5 -4
  484. package/lib/runtime/PublicPathRuntimeModule.js +1 -0
  485. package/lib/runtime/RelativeUrlRuntimeModule.js +4 -2
  486. package/lib/runtime/RuntimeIdRuntimeModule.js +1 -0
  487. package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +38 -0
  488. package/lib/runtime/StartupChunkDependenciesPlugin.js +13 -1
  489. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +2 -1
  490. package/lib/runtime/StartupEntrypointRuntimeModule.js +5 -3
  491. package/lib/runtime/SystemContextRuntimeModule.js +1 -0
  492. package/lib/runtime/ToBinaryRuntimeModule.js +1 -0
  493. package/lib/runtime/WorkerRuntimeModule.js +33 -0
  494. package/lib/schemes/DataUriPlugin.js +14 -2
  495. package/lib/schemes/FileUriPlugin.js +1 -1
  496. package/lib/schemes/HttpUriPlugin.js +86 -4
  497. package/lib/schemes/VirtualUrlPlugin.js +8 -4
  498. package/lib/serialization/AggregateErrorSerializer.js +9 -6
  499. package/lib/serialization/ArraySerializer.js +6 -8
  500. package/lib/serialization/BinaryMiddleware.js +552 -463
  501. package/lib/serialization/DateObjectSerializer.js +4 -2
  502. package/lib/serialization/ErrorObjectSerializer.js +10 -6
  503. package/lib/serialization/FileMiddleware.js +50 -3
  504. package/lib/serialization/MapObjectSerializer.js +7 -9
  505. package/lib/serialization/NullPrototypeObjectSerializer.js +9 -9
  506. package/lib/serialization/ObjectMiddleware.js +73 -13
  507. package/lib/serialization/PlainObjectSerializer.js +16 -8
  508. package/lib/serialization/RegExpObjectSerializer.js +4 -2
  509. package/lib/serialization/Serializer.js +6 -0
  510. package/lib/serialization/SerializerMiddleware.js +14 -2
  511. package/lib/serialization/SetObjectSerializer.js +6 -8
  512. package/lib/serialization/SingleItemMiddleware.js +3 -0
  513. package/lib/sharing/ConsumeSharedFallbackDependency.js +1 -0
  514. package/lib/sharing/ConsumeSharedModule.js +21 -7
  515. package/lib/sharing/ConsumeSharedPlugin.js +11 -11
  516. package/lib/sharing/ConsumeSharedRuntimeModule.js +55 -45
  517. package/lib/sharing/ProvideForSharedDependency.js +1 -0
  518. package/lib/sharing/ProvideSharedDependency.js +34 -15
  519. package/lib/sharing/ProvideSharedModule.js +42 -12
  520. package/lib/sharing/ProvideSharedModuleFactory.js +1 -0
  521. package/lib/sharing/ProvideSharedPlugin.js +13 -8
  522. package/lib/sharing/SharePlugin.js +5 -1
  523. package/lib/sharing/ShareRuntimeModule.js +19 -16
  524. package/lib/sharing/resolveMatchedConfigs.js +6 -2
  525. package/lib/sharing/utils.js +9 -1
  526. package/lib/stats/DefaultStatsFactoryPlugin.js +94 -12
  527. package/lib/stats/DefaultStatsPresetPlugin.js +14 -2
  528. package/lib/stats/DefaultStatsPrinterPlugin.js +64 -18
  529. package/lib/stats/StatsFactory.js +39 -18
  530. package/lib/stats/StatsPrinter.js +16 -2
  531. package/lib/typescript/TypeScriptPlugin.js +210 -0
  532. package/lib/url/URLParserPlugin.js +111 -23
  533. package/lib/util/ArrayHelpers.js +1 -0
  534. package/lib/util/ArrayQueue.js +10 -5
  535. package/lib/util/AsyncQueue.js +154 -74
  536. package/lib/util/Hash.js +2 -2
  537. package/lib/util/IterableHelpers.js +3 -0
  538. package/lib/util/LazyBucketSortedSet.js +26 -0
  539. package/lib/util/LazySet.js +45 -4
  540. package/lib/util/LocConverter.js +64 -0
  541. package/lib/util/ParallelismFactorCalculator.js +1 -0
  542. package/lib/util/Queue.js +6 -3
  543. package/lib/util/Semaphore.js +15 -1
  544. package/lib/util/SetHelpers.js +4 -1
  545. package/lib/util/SortableSet.js +7 -1
  546. package/lib/util/SourceProcessor.js +119 -0
  547. package/lib/util/StackedCacheMap.js +20 -3
  548. package/lib/util/StackedMap.js +162 -43
  549. package/lib/util/StringXor.js +1 -1
  550. package/lib/util/TupleQueue.js +7 -3
  551. package/lib/util/TupleSet.js +14 -0
  552. package/lib/util/URLAbsoluteSpecifier.js +1 -0
  553. package/lib/util/WeakTupleMap.js +60 -1
  554. package/lib/util/binarySearchBounds.js +3 -2
  555. package/lib/util/chainedImports.js +3 -3
  556. package/lib/util/cleverMerge.js +19 -2
  557. package/lib/util/comparators.js +35 -4
  558. package/lib/util/compileBooleanMatcher.js +9 -0
  559. package/lib/util/concatenate.js +80 -24
  560. package/lib/util/conventions.js +46 -1
  561. package/lib/util/createHash.js +0 -1
  562. package/lib/util/createHooksRegistry.js +43 -0
  563. package/lib/util/createMappings.js +118 -0
  564. package/lib/util/dataURL.js +3 -2
  565. package/lib/util/deprecation.js +19 -0
  566. package/lib/util/deterministicGrouping.js +46 -17
  567. package/lib/util/extractSourceMap.js +2 -1
  568. package/lib/util/extractUrlAndGlobal.js +1 -0
  569. package/lib/util/findGraphRoots.js +7 -0
  570. package/lib/{formatLocation.js → util/formatLocation.js} +4 -2
  571. package/lib/{SizeFormatHelpers.js → util/formatSize.js} +10 -3
  572. package/lib/util/fs.js +87 -14
  573. package/lib/util/generateDebugId.js +1 -0
  574. package/lib/util/globUtils.js +710 -0
  575. package/lib/util/hash/BatchedHash.js +1 -0
  576. package/lib/util/hash/BulkUpdateHash.js +1 -0
  577. package/lib/util/hash/DebugHash.js +1 -0
  578. package/lib/util/hash/hash-digest.js +32 -15
  579. package/lib/util/hash/md4.js +1 -1
  580. package/lib/util/hash/wasm-hash.js +5 -0
  581. package/lib/util/hash/xxhash64.js +1 -1
  582. package/lib/util/identifier.js +97 -6
  583. package/lib/util/implicitTypeLoaderFallback.js +62 -0
  584. package/lib/util/internalSerializables.js +102 -60
  585. package/lib/util/magicComment.js +149 -7
  586. package/lib/util/makeSerializable.js +7 -0
  587. package/lib/util/memoize.js +2 -0
  588. package/lib/util/mimeTypes.js +176 -0
  589. package/lib/util/nonNumericOnlyHash.js +31 -1
  590. package/lib/util/numberHash.js +2 -2
  591. package/lib/util/parseJson.js +41 -0
  592. package/lib/util/processAsyncTree.js +8 -0
  593. package/lib/util/property.js +9 -2
  594. package/lib/util/publicPathPlaceholder.js +64 -0
  595. package/lib/util/registerExternalSerializer.js +24 -4
  596. package/lib/util/removeBOM.js +1 -0
  597. package/lib/util/runtime.js +32 -0
  598. package/lib/util/semver.js +15 -0
  599. package/lib/util/serialization.js +2 -0
  600. package/lib/util/smartGrouping.js +8 -0
  601. package/lib/util/source.js +23 -0
  602. package/lib/util/topologicalSort.js +69 -0
  603. package/lib/validateSchema.js +1 -0
  604. package/lib/wasm/EnableWasmLoadingPlugin.js +15 -1
  605. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +25 -18
  606. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +34 -22
  607. package/lib/wasm-async/AsyncWasmModule.js +77 -0
  608. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +6 -0
  609. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +6 -1
  610. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +22 -126
  611. package/lib/wasm-async/AsyncWebAssemblyParser.js +3 -2
  612. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +13 -2
  613. package/lib/wasm-sync/SyncWasmModule.js +39 -0
  614. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +7 -3
  615. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +86 -19
  616. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +4 -3
  617. package/lib/wasm-sync/WebAssemblyGenerator.js +27 -1
  618. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +9 -3
  619. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +4 -0
  620. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +20 -1
  621. package/lib/wasm-sync/WebAssemblyParser.js +9 -3
  622. package/lib/wasm-sync/WebAssemblyUtils.js +2 -0
  623. package/lib/web/FetchCompileAsyncWasmPlugin.js +29 -1
  624. package/lib/web/FetchCompileWasmPlugin.js +27 -1
  625. package/lib/web/JsonpChunkLoadingPlugin.js +11 -1
  626. package/lib/web/JsonpChunkLoadingRuntimeModule.js +58 -64
  627. package/lib/web/JsonpTemplatePlugin.js +2 -1
  628. package/lib/webpack.js +78 -1
  629. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +10 -1
  630. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +15 -10
  631. package/lib/webworker/WebWorkerTemplatePlugin.js +1 -1
  632. package/module.d.ts +21 -0
  633. package/package.json +79 -77
  634. package/schemas/WebpackOptions.check.js +1 -1
  635. package/schemas/WebpackOptions.json +1117 -79
  636. package/schemas/plugins/{DllPlugin.check.d.ts → HtmlGeneratorOptions.check.d.ts} +1 -1
  637. package/schemas/plugins/HtmlGeneratorOptions.check.js +6 -0
  638. package/schemas/plugins/HtmlGeneratorOptions.json +3 -0
  639. package/schemas/plugins/{DllReferencePlugin.check.d.ts → HtmlParserOptions.check.d.ts} +1 -1
  640. package/schemas/plugins/HtmlParserOptions.check.js +6 -0
  641. package/schemas/plugins/HtmlParserOptions.json +3 -0
  642. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  643. package/schemas/plugins/ProgressPlugin.json +38 -0
  644. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  645. package/schemas/plugins/container/ContainerReferencePlugin.json +2 -0
  646. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  647. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  648. package/schemas/plugins/container/ModuleFederationPlugin.json +2 -0
  649. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.d.ts +7 -0
  650. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +6 -0
  651. package/schemas/plugins/css/CssAutoOrModuleParserOptions.json +3 -0
  652. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  653. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  654. package/schemas/plugins/dll/DllPlugin.check.d.ts +7 -0
  655. package/schemas/plugins/dll/DllReferencePlugin.check.d.ts +7 -0
  656. package/types.d.ts +8608 -1159
  657. package/lib/CaseSensitiveModulesWarning.js +0 -72
  658. package/lib/GraphHelpers.js +0 -46
  659. package/lib/ModuleParseError.js +0 -125
  660. package/lib/NoModeWarning.js +0 -23
  661. package/lib/css/CssMergeStyleSheetsRuntimeModule.js +0 -56
  662. package/lib/css/walkCssTokens.js +0 -1843
  663. package/lib/util/AppendOnlyStackedSet.js +0 -78
  664. /package/schemas/plugins/{DllPlugin.check.js → dll/DllPlugin.check.js} +0 -0
  665. /package/schemas/plugins/{DllPlugin.json → dll/DllPlugin.json} +0 -0
  666. /package/schemas/plugins/{DllReferencePlugin.check.js → dll/DllReferencePlugin.check.js} +0 -0
  667. /package/schemas/plugins/{DllReferencePlugin.json → dll/DllReferencePlugin.json} +0 -0
@@ -21,42 +21,38 @@ const { MultiItemCache } = require("./CacheFacade");
21
21
  const Chunk = require("./Chunk");
22
22
  const ChunkGraph = require("./ChunkGraph");
23
23
  const ChunkGroup = require("./ChunkGroup");
24
- const ChunkRenderError = require("./ChunkRenderError");
25
24
  const ChunkTemplate = require("./ChunkTemplate");
26
- const CodeGenerationError = require("./CodeGenerationError");
27
25
  const CodeGenerationResults = require("./CodeGenerationResults");
28
26
  const Dependency = require("./Dependency");
29
27
  const DependencyTemplates = require("./DependencyTemplates");
30
28
  const Entrypoint = require("./Entrypoint");
31
29
  const ErrorHelpers = require("./ErrorHelpers");
32
30
  const FileSystemInfo = require("./FileSystemInfo");
33
- const {
34
- connectChunkGroupAndChunk,
35
- connectChunkGroupParentAndChild,
36
- connectEntrypointAndDependOn
37
- } = require("./GraphHelpers");
38
- const {
39
- makeWebpackError,
40
- tryRunOrWebpackError
41
- } = require("./HookWebpackError");
31
+ const LazyBarrelController = require("./LazyBarrel");
42
32
  const MainTemplate = require("./MainTemplate");
43
33
  const Module = require("./Module");
44
- const ModuleDependencyError = require("./ModuleDependencyError");
45
- const ModuleDependencyWarning = require("./ModuleDependencyWarning");
46
34
  const ModuleGraph = require("./ModuleGraph");
47
- const ModuleHashingError = require("./ModuleHashingError");
48
- const ModuleNotFoundError = require("./ModuleNotFoundError");
49
35
  const ModuleProfile = require("./ModuleProfile");
50
- const ModuleRestoreError = require("./ModuleRestoreError");
51
- const ModuleStoreError = require("./ModuleStoreError");
52
36
  const ModuleTemplate = require("./ModuleTemplate");
53
37
  const { WEBPACK_MODULE_TYPE_RUNTIME } = require("./ModuleTypeConstants");
54
38
  const RuntimeGlobals = require("./RuntimeGlobals");
55
39
  const RuntimeTemplate = require("./RuntimeTemplate");
56
40
  const Stats = require("./Stats");
57
- const WebpackError = require("./WebpackError");
58
41
  const buildChunkGraph = require("./buildChunkGraph");
59
42
  const BuildCycleError = require("./errors/BuildCycleError");
43
+ const ChunkRenderError = require("./errors/ChunkRenderError");
44
+ const CodeGenerationError = require("./errors/CodeGenerationError");
45
+ const {
46
+ makeWebpackError,
47
+ tryRunOrWebpackError
48
+ } = require("./errors/HookWebpackError");
49
+ const ModuleDependencyError = require("./errors/ModuleDependencyError");
50
+ const ModuleDependencyWarning = require("./errors/ModuleDependencyWarning");
51
+ const ModuleHashingError = require("./errors/ModuleHashingError");
52
+ const ModuleNotFoundError = require("./errors/ModuleNotFoundError");
53
+ const ModuleRestoreError = require("./errors/ModuleRestoreError");
54
+ const ModuleStoreError = require("./errors/ModuleStoreError");
55
+ const WebpackError = require("./errors/WebpackError");
60
56
  const { LogType, Logger } = require("./logging/Logger");
61
57
  const StatsFactory = require("./stats/StatsFactory");
62
58
  const StatsPrinter = require("./stats/StatsPrinter");
@@ -113,6 +109,7 @@ const { isSourceEqual } = require("./util/source");
113
109
  /** @typedef {import("./Module").BuildInfo} BuildInfo */
114
110
  /** @typedef {import("./Module").ValueCacheVersions} ValueCacheVersions */
115
111
  /** @typedef {import("./Module").RuntimeRequirements} RuntimeRequirements */
112
+ /** @typedef {import("./Module").SourceTypes} SourceTypes */
116
113
  /** @typedef {import("./NormalModule").NormalModuleCompilationHooks} NormalModuleCompilationHooks */
117
114
  /** @typedef {import("./Module").FactoryMeta} FactoryMeta */
118
115
  /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
@@ -137,11 +134,13 @@ const { isSourceEqual } = require("./util/source");
137
134
  /** @typedef {import("./util/Hash")} Hash */
138
135
 
139
136
  /**
137
+ * Defines the shared type used by this module.
140
138
  * @template T
141
139
  * @typedef {import("tapable").AsArray<T>} AsArray<T>
142
140
  */
143
141
 
144
142
  /**
143
+ * Defines the shared type used by this module.
145
144
  * @template T
146
145
  * @typedef {import("./util/deprecation").FakeHook<T>} FakeHook<T>
147
146
  */
@@ -149,12 +148,14 @@ const { isSourceEqual } = require("./util/source");
149
148
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
150
149
 
151
150
  /**
151
+ * Defines the callback callback.
152
152
  * @callback Callback
153
153
  * @param {(WebpackError | null)=} err
154
154
  * @returns {void}
155
155
  */
156
156
 
157
157
  /**
158
+ * Defines the module callback callback.
158
159
  * @callback ModuleCallback
159
160
  * @param {WebpackError | null=} err
160
161
  * @param {Module | null=} result
@@ -162,6 +163,7 @@ const { isSourceEqual } = require("./util/source");
162
163
  */
163
164
 
164
165
  /**
166
+ * Defines the module factory result callback callback.
165
167
  * @callback ModuleFactoryResultCallback
166
168
  * @param {WebpackError | null=} err
167
169
  * @param {ModuleFactoryResult | null=} result
@@ -169,6 +171,7 @@ const { isSourceEqual } = require("./util/source");
169
171
  */
170
172
 
171
173
  /**
174
+ * Defines the module or module factory result callback callback.
172
175
  * @callback ModuleOrModuleFactoryResultCallback
173
176
  * @param {WebpackError | null=} err
174
177
  * @param {Module | ModuleFactoryResult | null=} result
@@ -176,6 +179,7 @@ const { isSourceEqual } = require("./util/source");
176
179
  */
177
180
 
178
181
  /**
182
+ * Defines the execute module callback callback.
179
183
  * @callback ExecuteModuleCallback
180
184
  * @param {WebpackError | null=} err
181
185
  * @param {ExecuteModuleResult | null=} result
@@ -187,6 +191,7 @@ const { isSourceEqual } = require("./util/source");
187
191
  /** @typedef {Record<string, Source>} CompilationAssets */
188
192
 
189
193
  /**
194
+ * Defines the available modules chunk group mapping type used by this module.
190
195
  * @typedef {object} AvailableModulesChunkGroupMapping
191
196
  * @property {ChunkGroup} chunkGroup
192
197
  * @property {Set<Module>} availableModules
@@ -194,6 +199,7 @@ const { isSourceEqual } = require("./util/source");
194
199
  */
195
200
 
196
201
  /**
202
+ * Defines the dependencies block like type used by this module.
197
203
  * @typedef {object} DependenciesBlockLike
198
204
  * @property {Dependency[]} dependencies
199
205
  * @property {AsyncDependenciesBlock[]} blocks
@@ -202,16 +208,20 @@ const { isSourceEqual } = require("./util/source");
202
208
  /** @typedef {Set<Chunk>} Chunks */
203
209
 
204
210
  /**
211
+ * Defines the chunk path data type used by this module.
205
212
  * @typedef {object} ChunkPathData
206
213
  * @property {string | number} id
207
214
  * @property {string=} name
208
215
  * @property {string} hash
209
216
  * @property {HashWithLengthFunction=} hashWithLength
217
+ * @property {HashWithDigestFunction=} hashWithDigest builds `[chunkhash:<digest>]` per chunk in the runtime chunk-filename map
210
218
  * @property {(Record<string, string>)=} contentHash
211
219
  * @property {(Record<string, HashWithLengthFunction>)=} contentHashWithLength
220
+ * @property {(Record<string, HashWithDigestFunction>)=} contentHashWithDigest builds `[contenthash:<digest>]` per chunk in the runtime chunk-filename map
212
221
  */
213
222
 
214
223
  /**
224
+ * Defines the chunk hash context type used by this module.
215
225
  * @typedef {object} ChunkHashContext
216
226
  * @property {CodeGenerationResults} codeGenerationResults results of code generation
217
227
  * @property {RuntimeTemplate} runtimeTemplate the runtime template
@@ -220,12 +230,14 @@ const { isSourceEqual } = require("./util/source");
220
230
  */
221
231
 
222
232
  /**
233
+ * Defines the runtime requirements context type used by this module.
223
234
  * @typedef {object} RuntimeRequirementsContext
224
235
  * @property {ChunkGraph} chunkGraph the chunk graph
225
236
  * @property {CodeGenerationResults} codeGenerationResults the code generation results
226
237
  */
227
238
 
228
239
  /**
240
+ * Defines the execute module options type used by this module.
229
241
  * @typedef {object} ExecuteModuleOptions
230
242
  * @property {EntryOptions=} entryOptions
231
243
  */
@@ -235,9 +247,11 @@ const { isSourceEqual } = require("./util/source");
235
247
  /** @typedef {EXPECTED_ANY} ExecuteModuleExports */
236
248
 
237
249
  /**
250
+ * Defines the execute module result type used by this module.
238
251
  * @typedef {object} ExecuteModuleResult
239
252
  * @property {ExecuteModuleExports} exports
240
253
  * @property {boolean} cacheable
254
+ * @property {string[]} notCacheableReasons reasons why the executed modules are not cacheable
241
255
  * @property {ExecuteModuleAssets} assets
242
256
  * @property {FileSystemDependencies} fileDependencies
243
257
  * @property {FileSystemDependencies} contextDependencies
@@ -246,6 +260,7 @@ const { isSourceEqual } = require("./util/source");
246
260
  */
247
261
 
248
262
  /**
263
+ * Defines the execute module object type used by this module.
249
264
  * @typedef {object} ExecuteModuleObject
250
265
  * @property {string=} id module id
251
266
  * @property {ExecuteModuleExports} exports exports
@@ -254,6 +269,7 @@ const { isSourceEqual } = require("./util/source");
254
269
  */
255
270
 
256
271
  /**
272
+ * Defines the execute module argument type used by this module.
257
273
  * @typedef {object} ExecuteModuleArgument
258
274
  * @property {Module} module
259
275
  * @property {ExecuteModuleObject=} moduleObject
@@ -263,6 +279,7 @@ const { isSourceEqual } = require("./util/source");
263
279
  /** @typedef {((id: string) => ExecuteModuleExports) & { i?: ((options: ExecuteOptions) => void)[], c?: Record<string, ExecuteModuleObject> }} WebpackRequire */
264
280
 
265
281
  /**
282
+ * Defines the execute options type used by this module.
266
283
  * @typedef {object} ExecuteOptions
267
284
  * @property {string=} id module id
268
285
  * @property {ExecuteModuleObject} module module
@@ -272,6 +289,7 @@ const { isSourceEqual } = require("./util/source");
272
289
  /** @typedef {Map<string, { source: Source, info: AssetInfo | undefined }>} ExecuteModuleAssets */
273
290
 
274
291
  /**
292
+ * Defines the execute module context type used by this module.
275
293
  * @typedef {object} ExecuteModuleContext
276
294
  * @property {ExecuteModuleAssets} assets
277
295
  * @property {Chunk} chunk
@@ -280,6 +298,7 @@ const { isSourceEqual } = require("./util/source");
280
298
  */
281
299
 
282
300
  /**
301
+ * Defines the entry data type used by this module.
283
302
  * @typedef {object} EntryData
284
303
  * @property {Dependency[]} dependencies dependencies of the entrypoint that should be evaluated at startup
285
304
  * @property {Dependency[]} includeDependencies dependencies of the entrypoint that should be included but not evaluated
@@ -287,6 +306,7 @@ const { isSourceEqual } = require("./util/source");
287
306
  */
288
307
 
289
308
  /**
309
+ * Defines the log entry type used by this module.
290
310
  * @typedef {object} LogEntry
291
311
  * @property {keyof LogType} type
292
312
  * @property {EXPECTED_ANY[]=} args
@@ -295,6 +315,7 @@ const { isSourceEqual } = require("./util/source");
295
315
  */
296
316
 
297
317
  /**
318
+ * Defines the known asset info type used by this module.
298
319
  * @typedef {object} KnownAssetInfo
299
320
  * @property {boolean=} immutable true, if the asset can be long term cached forever (contains a hash)
300
321
  * @property {boolean=} minimized whether the asset is minimized
@@ -302,6 +323,7 @@ const { isSourceEqual } = require("./util/source");
302
323
  * @property {string | string[]=} chunkhash the value(s) of the chunk hash used for this asset
303
324
  * @property {string | string[]=} modulehash the value(s) of the module hash used for this asset
304
325
  * @property {string | string[]=} contenthash the value(s) of the content hash used for this asset
326
+ * @property {Record<string, string>=} contenthashDigest maps a `[contenthash:<digest>]` value to its digest, so `RealContentHashPlugin` re-encodes the recomputed hash in it
305
327
  * @property {string=} sourceFilename when asset was created from a source file (potentially transformed), the original filename relative to compilation context
306
328
  * @property {number=} size size in bytes, only set after asset has been emitted
307
329
  * @property {boolean=} development true, when asset is only used for development and doesn't count towards user-facing assets
@@ -316,6 +338,7 @@ const { isSourceEqual } = require("./util/source");
316
338
  /** @typedef {{ path: string, info: AssetInfo }} InterpolatedPathAndAssetInfo */
317
339
 
318
340
  /**
341
+ * Defines the asset type used by this module.
319
342
  * @typedef {object} Asset
320
343
  * @property {string} name the filename of the asset
321
344
  * @property {Source} source source of the asset
@@ -324,7 +347,10 @@ const { isSourceEqual } = require("./util/source");
324
347
 
325
348
  /** @typedef {(length: number) => string} HashWithLengthFunction */
326
349
 
350
+ /** @typedef {(digest: string, length?: number) => string} HashWithDigestFunction */
351
+
327
352
  /**
353
+ * Defines the module path data type used by this module.
328
354
  * @typedef {object} ModulePathData
329
355
  * @property {string | number} id
330
356
  * @property {string} hash
@@ -334,10 +360,14 @@ const { isSourceEqual } = require("./util/source");
334
360
  /** @typedef {(id: string | number) => string | number} PrepareIdFunction */
335
361
 
336
362
  /**
363
+ * Defines the path data type used by this module.
337
364
  * @typedef {object} PathData
338
365
  * @property {ChunkGraph=} chunkGraph
339
366
  * @property {string=} hash
367
+ * @property {string=} fullHash untruncated compilation hash, for re-encoding `[fullhash:<digest>]`
368
+ * @property {string=} fullHashDigest digest `fullHash` is encoded in (defaults to `hashDigest`)
340
369
  * @property {HashWithLengthFunction=} hashWithLength
370
+ * @property {HashWithDigestFunction=} hashWithDigest builds `[fullhash:<digest>]`/`[hash:<digest>]` in the runtime chunk-filename context, where it throws because a runtime `getFullHash()` expression cannot be re-encoded
341
371
  * @property {(Chunk | ChunkPathData)=} chunk
342
372
  * @property {(Module | ModulePathData)=} module
343
373
  * @property {RuntimeSpec=} runtime
@@ -346,16 +376,40 @@ const { isSourceEqual } = require("./util/source");
346
376
  * @property {string=} query
347
377
  * @property {string=} contentHashType
348
378
  * @property {string=} contentHash
379
+ * @property {string=} contentHashFull untruncated module/asset content hash, for re-encoding `[contenthash:<digest>]` from full entropy
349
380
  * @property {HashWithLengthFunction=} contentHashWithLength
381
+ * @property {string=} hashDigest digest the stored hashes are encoded in (for `[hash:<digest>]`)
382
+ * @property {boolean=} realContentHash whether `optimization.realContentHash` recomputes content hashes (records an inline `[contenthash:<digest>]` so it re-encodes in that digest)
383
+ * @property {boolean=} hashAsFullHash treat `[hash]` as `[fullhash]` rather than the module hash (CSS local idents)
350
384
  * @property {boolean=} noChunkHash
351
385
  * @property {string=} url
352
386
  * @property {string=} local
387
+ * @property {string=} uniqueName
353
388
  * @property {PrepareIdFunction=} prepareId
354
389
  */
355
390
 
391
+ /**
392
+ * Path data narrowed for the chunk filename / chunk asset interpolation context,
393
+ * where `chunk` is always provided. Use as the type parameter to `TemplatePathFn`
394
+ * for callbacks that receive a chunk context (for example `output.filename`,
395
+ * `output.chunkFilename`, `output.cssFilename`, `output.cssChunkFilename`,
396
+ * `optimization.splitChunks.cacheGroups[*].filename`).
397
+ * @typedef {PathData & { chunk: Chunk | ChunkPathData }} PathDataChunk
398
+ */
399
+
400
+ /**
401
+ * Path data narrowed for the module asset interpolation context, where `module`
402
+ * and `chunkGraph` are always provided. Use as the type parameter to
403
+ * `TemplatePathFn` for callbacks that receive a module context (for example
404
+ * `output.assetModuleFilename`, the per-module `generator.filename` /
405
+ * `generator.outputPath`, and `module.parser.css.localIdentName`).
406
+ * @typedef {PathData & { module: Module | ModulePathData, chunkGraph: ChunkGraph }} PathDataModule
407
+ */
408
+
356
409
  /** @typedef {"module" | "chunk" | "root-of-chunk" | "nested"} ExcludeModulesType */
357
410
 
358
411
  /**
412
+ * Defines the known normalized stats options type used by this module.
359
413
  * @typedef {object} KnownNormalizedStatsOptions
360
414
  * @property {string} context
361
415
  * @property {RequestShortener} requestShortener
@@ -400,6 +454,7 @@ const { isSourceEqual } = require("./util/source");
400
454
  /** @typedef {KnownNormalizedStatsOptions & Omit<StatsOptions, keyof KnownNormalizedStatsOptions> & Record<string, EXPECTED_ANY>} NormalizedStatsOptions */
401
455
 
402
456
  /**
457
+ * Defines the known create stats options context type used by this module.
403
458
  * @typedef {object} KnownCreateStatsOptionsContext
404
459
  * @property {boolean=} forToString
405
460
  */
@@ -422,6 +477,7 @@ const esmDependencyCategory = "esm";
422
477
  // TODO webpack 6: remove
423
478
  const deprecatedNormalModuleLoaderHook = util.deprecate(
424
479
  /**
480
+ * Handles the callback logic for this hook.
425
481
  * @param {Compilation} compilation compilation
426
482
  * @returns {NormalModuleCompilationHooks["loader"]} hooks
427
483
  */
@@ -433,6 +489,7 @@ const deprecatedNormalModuleLoaderHook = util.deprecate(
433
489
 
434
490
  // TODO webpack 6: remove
435
491
  /**
492
+ * Define removed module templates.
436
493
  * @param {ModuleTemplates | undefined} moduleTemplates module templates
437
494
  */
438
495
  const defineRemovedModuleTemplates = (moduleTemplates) => {
@@ -481,6 +538,7 @@ const byLocation = compareSelect((err) => err.loc, compareLocations);
481
538
  const compareErrors = concatComparators(byModule, byLocation, byMessage);
482
539
 
483
540
  /**
541
+ * Defines the known unsafe cache data type used by this module.
484
542
  * @typedef {object} KnownUnsafeCacheData
485
543
  * @property {FactoryMeta=} factoryMeta factory meta
486
544
  * @property {ResolveOptions=} resolveOptions resolve options
@@ -491,6 +549,7 @@ const compareErrors = concatComparators(byModule, byLocation, byMessage);
491
549
  /** @typedef {KnownUnsafeCacheData & Record<string, EXPECTED_ANY>} UnsafeCacheData */
492
550
 
493
551
  /**
552
+ * Defines the module with restore from unsafe cache type used by this module.
494
553
  * @typedef {Module & { restoreFromUnsafeCache?: (unsafeCacheData: UnsafeCacheData, moduleFactory: ModuleFactory, compilationParams: CompilationParams) => void }} ModuleWithRestoreFromUnsafeCache
495
554
  */
496
555
 
@@ -502,7 +561,38 @@ const unsafeCacheDependencies = new WeakMap();
502
561
  /** @type {WeakMap<ModuleWithRestoreFromUnsafeCache, UnsafeCacheData>} */
503
562
  const unsafeCacheData = new WeakMap();
504
563
 
505
- /** @typedef {{ id: ModuleId, modules?: Map<Module, ModuleId>, blocks?: (ChunkId | null)[] }} References */
564
+ /** @typedef {EXPECTED_OBJECT} DependencyReportCacheToken */
565
+
566
+ /**
567
+ * Renewed when the module or a transitively referenced module is rebuilt.
568
+ * @type {WeakMap<Module, DependencyReportCacheToken>}
569
+ */
570
+ const dependencyReportCacheTokens = new WeakMap();
571
+
572
+ /**
573
+ * Modules known to have no dependency errors/warnings, per cache token.
574
+ * @type {WeakMap<DependencyReportCacheToken, WeakSet<Module>>}
575
+ */
576
+ const modulesWithoutProblems = new WeakMap();
577
+
578
+ /**
579
+ * Reduce affect type.
580
+ * @param {Readonly<ModuleGraphConnection[]>} connections connections
581
+ * @returns {symbol | boolean} result
582
+ */
583
+ const reduceAffectType = (connections) => {
584
+ let affected = false;
585
+ for (const { dependency } of connections) {
586
+ if (!dependency) continue;
587
+ const type = dependency.couldAffectReferencingModule();
588
+ if (type === Dependency.TRANSITIVE) return Dependency.TRANSITIVE;
589
+ if (type === false) continue;
590
+ affected = true;
591
+ }
592
+ return affected;
593
+ };
594
+
595
+ /** @typedef {{ id: ModuleId, modules?: Map<Module, ModuleId>, blocks?: (ChunkId | null)[], sourceTypes?: SourceTypes }} References */
506
596
  /** @typedef {Map<Module, WeakTupleMap<EXPECTED_ANY[], EXPECTED_ANY>>} ModuleMemCaches */
507
597
 
508
598
  class Compilation {
@@ -512,6 +602,7 @@ class Compilation {
512
602
  * @param {CompilationParams} params the compilation parameters
513
603
  */
514
604
  constructor(compiler, params) {
605
+ /** @type {boolean} */
515
606
  this._backCompat = compiler._backCompat;
516
607
 
517
608
  const getNormalModuleLoader = () => deprecatedNormalModuleLoaderHook(this);
@@ -522,6 +613,7 @@ class Compilation {
522
613
  /** @type {Set<string>} */
523
614
  let savedAssets = new Set();
524
615
  /**
616
+ * Returns new assets.
525
617
  * @param {CompilationAssets} assets assets
526
618
  * @returns {CompilationAssets} new assets
527
619
  */
@@ -554,6 +646,7 @@ class Compilation {
554
646
  /** @type {ProcessedAssets | undefined} */
555
647
  const processedAssets = additionalAssetsFn ? new WeakSet() : undefined;
556
648
  /**
649
+ * Gets available assets.
557
650
  * @param {CompilationAssets} assets to be processed by additionalAssetsFn
558
651
  * @returns {CompilationAssets} available assets
559
652
  */
@@ -584,6 +677,7 @@ class Compilation {
584
677
  ...remainingTap,
585
678
  type: "async",
586
679
  /**
680
+ * Processes the provided asset.
587
681
  * @param {CompilationAssets} assets assets
588
682
  * @param {(err?: Error | null, result?: void) => void} callback callback
589
683
  * @returns {void}
@@ -629,6 +723,7 @@ class Compilation {
629
723
  return {
630
724
  ...remainingTap,
631
725
  /**
726
+ * Processes the provided asset.
632
727
  * @param {CompilationAssets} assets assets
633
728
  * @param {(err?: Error | null, result?: void) => void} callback callback
634
729
  * @returns {void}
@@ -637,6 +732,7 @@ class Compilation {
637
732
  fn(
638
733
  assets,
639
734
  /**
735
+ * Handles the callback logic for this hook.
640
736
  * @param {Error} err err
641
737
  * @returns {void}
642
738
  */
@@ -673,6 +769,7 @@ class Compilation {
673
769
  return {
674
770
  ...remainingTap,
675
771
  /**
772
+ * Returns result.
676
773
  * @param {CompilationAssets} assets assets
677
774
  * @returns {Promise<CompilationAssets>} result
678
775
  */
@@ -700,6 +797,7 @@ class Compilation {
700
797
  const afterProcessAssetsHook = new SyncHook(["assets"]);
701
798
 
702
799
  /**
800
+ * Creates a process assets hook.
703
801
  * @template T
704
802
  * @param {string} name name of the hook
705
803
  * @param {number} stage new stage
@@ -710,6 +808,7 @@ class Compilation {
710
808
  const createProcessAssetsHook = (name, stage, getArgs, code) => {
711
809
  if (!this._backCompat && code) return;
712
810
  /**
811
+ * Returns error message.
713
812
  * @param {string} reason reason
714
813
  * @returns {string} error message
715
814
  */
@@ -718,6 +817,7 @@ class Compilation {
718
817
  ) => `Can't automatically convert plugin using Compilation.hooks.${name} to Compilation.hooks.processAssets because ${reason}.
719
818
  BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a single Compilation.hooks.processAssets hook.`;
720
819
  /**
820
+ * Normalizes tap options for migrated process-assets hooks.
721
821
  * @param {string | (import("tapable").TapOptions & { name: string } & ProcessAssetsAdditionalOptions)} options hook options
722
822
  * @returns {import("tapable").TapOptions & { name: string } & ProcessAssetsAdditionalOptions} modified options
723
823
  */
@@ -1042,6 +1142,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1042
1142
  statsPrinter: new SyncHook(["statsPrinter", "options"]),
1043
1143
 
1044
1144
  /**
1145
+ * Gets normal module loader.
1045
1146
  * @deprecated
1046
1147
  * @returns {SyncHook<[AnyLoaderContext, NormalModule]>} normal module loader hook
1047
1148
  */
@@ -1062,6 +1163,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1062
1163
  this.inputFileSystem =
1063
1164
  /** @type {InputFileSystem} */
1064
1165
  (compiler.inputFileSystem);
1166
+ /** @type {FileSystemInfo} */
1065
1167
  this.fileSystemInfo = new FileSystemInfo(this.inputFileSystem, {
1066
1168
  unmanagedPaths: compiler.unmanagedPaths,
1067
1169
  managedPaths: compiler.managedPaths,
@@ -1080,7 +1182,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1080
1182
  }
1081
1183
  /** @type {ValueCacheVersions} */
1082
1184
  this.valueCacheVersions = new Map();
1185
+ /** @type {RequestShortener} */
1083
1186
  this.requestShortener = compiler.requestShortener;
1187
+ /** @type {string} */
1084
1188
  this.compilerPath = compiler.compilerPath;
1085
1189
 
1086
1190
  this.logger = this.getLogger("webpack.Compilation");
@@ -1095,9 +1199,13 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1095
1199
  /** @type {boolean} */
1096
1200
  this.profile = (options && options.profile) || false;
1097
1201
 
1202
+ /** @type {CompilationParams} */
1098
1203
  this.params = params;
1204
+ /** @type {MainTemplate} */
1099
1205
  this.mainTemplate = new MainTemplate(this.outputOptions, this);
1206
+ /** @type {ChunkTemplate} */
1100
1207
  this.chunkTemplate = new ChunkTemplate(this.outputOptions, this);
1208
+ /** @type {RuntimeTemplate} */
1101
1209
  this.runtimeTemplate = new RuntimeTemplate(
1102
1210
  this,
1103
1211
  this.outputOptions,
@@ -1207,6 +1315,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1207
1315
  this.assetsInfo = new Map();
1208
1316
  /** @type {Map<string, Map<string, Set<string>>>} */
1209
1317
  this._assetsRelatedIn = new Map();
1318
+ /** @type {Map<string, Set<Chunk>> | undefined} */
1319
+ this._assetToChunkIndex = undefined;
1320
+ /** @type {Map<string, Set<Chunk>> | undefined} */
1321
+ this._assetToChunkAuxiliaryIndex = undefined;
1210
1322
  /** @type {Error[]} */
1211
1323
  this.errors = [];
1212
1324
  /** @type {Error[]} */
@@ -1259,6 +1371,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1259
1371
  this.compilationDependencies = {
1260
1372
  add: util.deprecate(
1261
1373
  /**
1374
+ * Handles the add callback for this hook.
1262
1375
  * @param {string} item item
1263
1376
  * @returns {FileSystemDependencies} file dependencies
1264
1377
  */
@@ -1268,8 +1381,11 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1268
1381
  )
1269
1382
  };
1270
1383
 
1384
+ /** @type {CacheFacade} */
1271
1385
  this._modulesCache = this.getCache("Compilation/modules");
1386
+ /** @type {CacheFacade} */
1272
1387
  this._assetsCache = this.getCache("Compilation/assets");
1388
+ /** @type {CacheFacade} */
1273
1389
  this._codeGenerationCache = this.getCache("Compilation/codeGeneration");
1274
1390
 
1275
1391
  const unsafeCache = options.module.unsafeCache;
@@ -1278,6 +1394,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1278
1394
  /** @type {UnsafeCachePredicate} */
1279
1395
  this._unsafeCachePredicate =
1280
1396
  typeof unsafeCache === "function" ? unsafeCache : () => true;
1397
+
1398
+ /** @type {LazyBarrelController} */
1399
+ this._lazyBarrelController = new LazyBarrelController(this);
1281
1400
  }
1282
1401
 
1283
1402
  getStats() {
@@ -1285,6 +1404,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1285
1404
  }
1286
1405
 
1287
1406
  /**
1407
+ * Creates a stats options.
1288
1408
  * @param {string | boolean | StatsOptions | undefined} optionsOrPreset stats option value
1289
1409
  * @param {CreateStatsOptionsContext=} context context
1290
1410
  * @returns {NormalizedStatsOptions} normalized options
@@ -1318,6 +1438,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1318
1438
  }
1319
1439
 
1320
1440
  /**
1441
+ * Creates a stats factory.
1321
1442
  * @param {NormalizedStatsOptions} options options
1322
1443
  * @returns {StatsFactory} the stats factory
1323
1444
  */
@@ -1328,6 +1449,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1328
1449
  }
1329
1450
 
1330
1451
  /**
1452
+ * Creates a stats printer.
1331
1453
  * @param {NormalizedStatsOptions} options options
1332
1454
  * @returns {StatsPrinter} the stats printer
1333
1455
  */
@@ -1338,6 +1460,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1338
1460
  }
1339
1461
 
1340
1462
  /**
1463
+ * Returns the cache facade instance.
1341
1464
  * @param {string} name cache name
1342
1465
  * @returns {CacheFacade} the cache facade instance
1343
1466
  */
@@ -1346,6 +1469,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1346
1469
  }
1347
1470
 
1348
1471
  /**
1472
+ * Returns a logger with that name.
1349
1473
  * @param {string | (() => string)} name name of the logger, or function called once to get the logger name
1350
1474
  * @returns {Logger} a logger with that name
1351
1475
  */
@@ -1392,7 +1516,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1392
1516
  typeof console.profileEnd === "function"
1393
1517
  ) {
1394
1518
  console.profileEnd(
1395
- `[${name}] ${/** @type {NonNullable<LogEntry["args"]>} */ (logEntry.args)[0]}`
1519
+ `[${name}] ${
1520
+ /** @type {NonNullable<LogEntry["args"]>} */ (logEntry.args)[0]
1521
+ }`
1396
1522
  );
1397
1523
  }
1398
1524
  if (logEntries === undefined) {
@@ -1471,6 +1597,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1471
1597
  }
1472
1598
 
1473
1599
  /**
1600
+ * Adds the provided module to the compilation.
1474
1601
  * @param {Module} module module to be added that was created
1475
1602
  * @param {ModuleCallback} callback returns the module in the compilation,
1476
1603
  * it could be the passed one (if new), or an already existing in the compilation
@@ -1481,6 +1608,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1481
1608
  }
1482
1609
 
1483
1610
  /**
1611
+ * Adds the provided module to the compilation.
1484
1612
  * @param {Module} module module to be added that was created
1485
1613
  * @param {ModuleCallback} callback returns the module in the compilation,
1486
1614
  * it could be the passed one (if new), or an already existing in the compilation
@@ -1630,6 +1758,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1630
1758
  }
1631
1759
 
1632
1760
  /**
1761
+ * Process module dependencies.
1633
1762
  * @param {Module} module to be processed for deps
1634
1763
  * @param {ModuleCallback} callback callback to be triggered
1635
1764
  * @returns {void}
@@ -1639,11 +1768,13 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1639
1768
  }
1640
1769
 
1641
1770
  /**
1771
+ * Process module dependencies non recursive.
1642
1772
  * @param {Module} module to be processed for deps
1643
1773
  * @returns {void}
1644
1774
  */
1645
1775
  processModuleDependenciesNonRecursive(module) {
1646
1776
  /**
1777
+ * Process dependencies block.
1647
1778
  * @param {DependenciesBlock} block block
1648
1779
  */
1649
1780
  const processDependenciesBlock = (block) => {
@@ -1662,6 +1793,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1662
1793
  }
1663
1794
 
1664
1795
  /**
1796
+ * Process module dependencies.
1665
1797
  * @param {Module} module to be processed for deps
1666
1798
  * @param {ModuleCallback} callback callback to be triggered
1667
1799
  * @returns {void}
@@ -1674,6 +1806,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1674
1806
  Dependency.isLowPriorityDependency
1675
1807
  );
1676
1808
 
1809
+ // lazy barrel: defer re-export targets of side-effect-free modules
1810
+ const hasLazyBarrel = this._lazyBarrelController.classify(module);
1811
+
1677
1812
  /** @type {DependenciesBlock} */
1678
1813
  let currentBlock;
1679
1814
 
@@ -1697,6 +1832,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1697
1832
  let inProgressTransitive = 1;
1698
1833
 
1699
1834
  /**
1835
+ * On dependencies sorted.
1700
1836
  * @param {WebpackError=} err error
1701
1837
  * @returns {void}
1702
1838
  */
@@ -1733,6 +1869,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1733
1869
  };
1734
1870
 
1735
1871
  /**
1872
+ * On transitive tasks finished.
1736
1873
  * @param {WebpackError=} err error
1737
1874
  * @returns {void}
1738
1875
  */
@@ -1744,12 +1881,23 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1744
1881
  };
1745
1882
 
1746
1883
  /**
1884
+ * Process dependency.
1747
1885
  * @param {Dependency} dep dependency
1748
1886
  * @param {number} index index in block
1749
1887
  * @returns {void}
1750
1888
  */
1751
1889
  const processDependency = (dep, index) => {
1752
1890
  this.moduleGraph.setParents(dep, currentBlock, module, index);
1891
+ if (
1892
+ hasLazyBarrel &&
1893
+ // TODO remove in webpack 6
1894
+ // It may be missing on custom dependency types not extending the base Dependency
1895
+ "isLazy" in dep &&
1896
+ dep.isLazy()
1897
+ ) {
1898
+ return;
1899
+ }
1900
+
1753
1901
  if (this._unsafeCache) {
1754
1902
  try {
1755
1903
  const unsafeCachedModule = unsafeCacheDependencies.get(dep);
@@ -1763,6 +1911,11 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1763
1911
  dep,
1764
1912
  unsafeCachedModule
1765
1913
  );
1914
+ this._lazyBarrelController.unlazyForDependency(
1915
+ unsafeCachedModule,
1916
+ dep,
1917
+ sortedDependencies
1918
+ );
1766
1919
  return;
1767
1920
  }
1768
1921
  const identifier = unsafeCachedModule.identifier();
@@ -1776,6 +1929,11 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1776
1929
  dep,
1777
1930
  cachedModule
1778
1931
  );
1932
+ this._lazyBarrelController.unlazyForDependency(
1933
+ cachedModule,
1934
+ dep,
1935
+ sortedDependencies
1936
+ );
1779
1937
  return;
1780
1938
  }
1781
1939
  inProgressSorting++;
@@ -1836,6 +1994,11 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1836
1994
  dep,
1837
1995
  cachedModule
1838
1996
  ); // a3
1997
+ this._lazyBarrelController.unlazyForDependency(
1998
+ cachedModule,
1999
+ dep,
2000
+ sortedDependencies
2001
+ );
1839
2002
  } catch (err) {
1840
2003
  if (inProgressSorting <= 0) return;
1841
2004
  inProgressSorting = -1;
@@ -1855,6 +2018,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1855
2018
  };
1856
2019
 
1857
2020
  /**
2021
+ * Process dependency for resolving.
1858
2022
  * @param {Dependency} dep dependency
1859
2023
  * @returns {void}
1860
2024
  */
@@ -1973,6 +2137,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1973
2137
  }
1974
2138
 
1975
2139
  /**
2140
+ * Handle new module from unsafe cache.
1976
2141
  * @private
1977
2142
  * @param {Module} originModule original module
1978
2143
  * @param {Dependency} dependency dependency
@@ -2000,11 +2165,13 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2000
2165
  module,
2001
2166
  true,
2002
2167
  false,
2168
+ [dependency],
2003
2169
  callback
2004
2170
  );
2005
2171
  }
2006
2172
 
2007
2173
  /**
2174
+ * Handle existing module from unsafe cache.
2008
2175
  * @private
2009
2176
  * @param {Module} originModule original modules
2010
2177
  * @param {Dependency} dependency dependency
@@ -2017,6 +2184,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2017
2184
  }
2018
2185
 
2019
2186
  /**
2187
+ * Processes the provided factorize module option.
2020
2188
  * @param {FactorizeModuleOptions} options options
2021
2189
  * @param {ModuleOrModuleFactoryResultCallback} callback callback
2022
2190
  * @returns {void}
@@ -2103,18 +2271,21 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2103
2271
  }
2104
2272
 
2105
2273
  /**
2274
+ * Processes the provided module callback.
2106
2275
  * @overload
2107
2276
  * @param {FactorizeModuleOptions & { factoryResult?: false }} options options
2108
2277
  * @param {ModuleCallback} callback callback
2109
2278
  * @returns {void}
2110
2279
  */
2111
2280
  /**
2281
+ * Processes the provided module factory result callback.
2112
2282
  * @overload
2113
2283
  * @param {FactorizeModuleOptions & { factoryResult: true }} options options
2114
2284
  * @param {ModuleFactoryResultCallback} callback callback
2115
2285
  * @returns {void}
2116
2286
  */
2117
2287
  /**
2288
+ * Processes the provided |.
2118
2289
  * @param {FactorizeModuleOptions & { factoryResult?: false } | FactorizeModuleOptions & { factoryResult: true }} options options
2119
2290
  * @param {ModuleCallback | ModuleFactoryResultCallback} callback callback
2120
2291
  */
@@ -2127,6 +2298,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2127
2298
  }
2128
2299
 
2129
2300
  /**
2301
+ * Defines the handle module creation options type used by this module.
2130
2302
  * @typedef {object} HandleModuleCreationOptions
2131
2303
  * @property {ModuleFactory} factory
2132
2304
  * @property {Dependency[]} dependencies
@@ -2139,6 +2311,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2139
2311
  */
2140
2312
 
2141
2313
  /**
2314
+ * Handle module creation.
2142
2315
  * @param {HandleModuleCreationOptions} options options object
2143
2316
  * @param {ModuleCallback} callback callback
2144
2317
  * @returns {void}
@@ -2202,7 +2375,6 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2202
2375
  applyFactoryResultDependencies();
2203
2376
  return callback();
2204
2377
  }
2205
-
2206
2378
  if (currentProfile !== undefined) {
2207
2379
  moduleGraph.setProfile(newModule, currentProfile);
2208
2380
  }
@@ -2275,6 +2447,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2275
2447
  module,
2276
2448
  recursive,
2277
2449
  checkCycle,
2450
+ dependencies,
2278
2451
  callback
2279
2452
  );
2280
2453
  });
@@ -2283,11 +2456,13 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2283
2456
  }
2284
2457
 
2285
2458
  /**
2459
+ * Handle module build and dependencies.
2286
2460
  * @private
2287
2461
  * @param {Module | null} originModule original module
2288
2462
  * @param {Module} module module
2289
2463
  * @param {boolean} recursive true if make it recursive, otherwise false
2290
2464
  * @param {boolean} checkCycle true if need to check cycle, otherwise false
2465
+ * @param {Dependency[]} dependencies the dependencies that resolved to the module (lazy barrel)
2291
2466
  * @param {ModuleCallback} callback callback
2292
2467
  * @returns {void}
2293
2468
  */
@@ -2296,6 +2471,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2296
2471
  module,
2297
2472
  recursive,
2298
2473
  checkCycle,
2474
+ dependencies,
2299
2475
  callback
2300
2476
  ) {
2301
2477
  // Check for cycles when build is trigger inside another build
@@ -2360,21 +2536,60 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2360
2536
  return;
2361
2537
  }
2362
2538
 
2363
- // This avoids deadlocks for circular dependencies
2364
- if (this.processDependenciesQueue.isProcessing(module)) {
2365
- return callback(null, module);
2366
- }
2539
+ // lazy barrel:
2540
+ // 1. first call: barrel module is not classified yet, so this records the requested
2541
+ // ids and returns undefined; the targets get built below when
2542
+ // `processModuleDependencies` runs `_lazyBarrelController.classify` and replays them.
2543
+ // 2. later call: barrel module is already built, so `processModuleDependencies` won't
2544
+ // re-walk it; the newly requested targets must be built here.
2545
+ const unlazyItems = this._lazyBarrelController.request(
2546
+ module,
2547
+ dependencies
2548
+ );
2367
2549
 
2368
- this.processModuleDependencies(module, (err) => {
2369
- if (err) {
2370
- return callback(err);
2550
+ if (unlazyItems !== undefined) {
2551
+ let inProgress = unlazyItems.length + 1; // +1 = the module's own dep processing
2552
+ let errored = false;
2553
+ /**
2554
+ * @param {(WebpackError | null)=} err error
2555
+ * @returns {void}
2556
+ */
2557
+ const onJobDone = (err) => {
2558
+ if (errored) return;
2559
+ if (err) {
2560
+ errored = true;
2561
+ return callback(err);
2562
+ }
2563
+ if (--inProgress === 0) callback(null, module);
2564
+ };
2565
+ for (const item of unlazyItems) {
2566
+ this.handleModuleCreation(item, (err) => {
2567
+ onJobDone(err && this.bail ? err : null);
2568
+ });
2371
2569
  }
2372
- callback(null, module);
2373
- });
2570
+ if (this.processDependenciesQueue.isProcessing(module)) {
2571
+ onJobDone();
2572
+ } else {
2573
+ this.processModuleDependencies(module, onJobDone);
2574
+ }
2575
+ } else {
2576
+ // This avoids deadlocks for circular dependencies
2577
+ if (this.processDependenciesQueue.isProcessing(module)) {
2578
+ return callback(null, module);
2579
+ }
2580
+
2581
+ this.processModuleDependencies(module, (err) => {
2582
+ if (err) {
2583
+ return callback(err);
2584
+ }
2585
+ callback(null, module);
2586
+ });
2587
+ }
2374
2588
  });
2375
2589
  }
2376
2590
 
2377
2591
  /**
2592
+ * Adds the provided string to the compilation.
2378
2593
  * @param {string} context context string path
2379
2594
  * @param {Dependency} dependency dependency used to create Module chain
2380
2595
  * @param {ModuleCallback} callback callback for when module chain is complete
@@ -2385,6 +2600,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2385
2600
  }
2386
2601
 
2387
2602
  /**
2603
+ * Adds the provided object to the compilation.
2388
2604
  * @param {object} options options
2389
2605
  * @param {string} options.context context string path
2390
2606
  * @param {Dependency} options.dependency dependency used to create Module chain
@@ -2439,6 +2655,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2439
2655
  }
2440
2656
 
2441
2657
  /**
2658
+ * Adds the provided string to the compilation.
2442
2659
  * @param {string} context context path for entry
2443
2660
  * @param {Dependency} entry entry dependency that should be followed
2444
2661
  * @param {string | EntryOptions} optionsOrName options or deprecated name of entry
@@ -2456,6 +2673,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2456
2673
  }
2457
2674
 
2458
2675
  /**
2676
+ * Adds the provided string to the compilation.
2459
2677
  * @param {string} context context path for entry
2460
2678
  * @param {Dependency} dependency dependency that should be followed
2461
2679
  * @param {EntryOptions} options options
@@ -2473,6 +2691,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2473
2691
  }
2474
2692
 
2475
2693
  /**
2694
+ * Adds the provided string to the compilation.
2476
2695
  * @param {string} context context path for entry
2477
2696
  * @param {Dependency} entry entry dependency that should be followed
2478
2697
  * @param {"dependencies" | "includeDependencies"} target type of entry
@@ -2553,6 +2772,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2553
2772
  }
2554
2773
 
2555
2774
  /**
2775
+ * Processes the provided module.
2556
2776
  * @param {Module} module module to be rebuilt
2557
2777
  * @param {ModuleCallback} callback callback when module finishes rebuilding
2558
2778
  * @returns {void}
@@ -2562,6 +2782,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2562
2782
  }
2563
2783
 
2564
2784
  /**
2785
+ * Processes the provided module.
2565
2786
  * @param {Module} module module to be rebuilt
2566
2787
  * @param {ModuleCallback} callback callback when module finishes rebuilding
2567
2788
  * @returns {void}
@@ -2607,6 +2828,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2607
2828
  }
2608
2829
 
2609
2830
  /**
2831
+ * Compute affected modules.
2610
2832
  * @private
2611
2833
  * @param {Set<Module>} modules modules
2612
2834
  */
@@ -2629,6 +2851,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2629
2851
  let statWithoutBuild = 0;
2630
2852
 
2631
2853
  /**
2854
+ * Compute references.
2632
2855
  * @param {Module} module module
2633
2856
  * @returns {WeakReferences | undefined} references
2634
2857
  */
@@ -2646,6 +2869,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2646
2869
  };
2647
2870
 
2648
2871
  /**
2872
+ * Compares references.
2649
2873
  * @param {Module} module the module
2650
2874
  * @param {WeakReferences | undefined} references references
2651
2875
  * @returns {boolean} true, when the references differ
@@ -2721,21 +2945,6 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2721
2945
  }
2722
2946
  }
2723
2947
 
2724
- /**
2725
- * @param {Readonly<ModuleGraphConnection[]>} connections connections
2726
- * @returns {symbol | boolean} result
2727
- */
2728
- const reduceAffectType = (connections) => {
2729
- let affected = false;
2730
- for (const { dependency } of connections) {
2731
- if (!dependency) continue;
2732
- const type = dependency.couldAffectReferencingModule();
2733
- if (type === Dependency.TRANSITIVE) return Dependency.TRANSITIVE;
2734
- if (type === false) continue;
2735
- affected = true;
2736
- }
2737
- return affected;
2738
- };
2739
2948
  /** @type {Set<Module>} */
2740
2949
  const directOnlyInfectedModules = new Set();
2741
2950
  for (const module of infectedModules) {
@@ -2804,6 +3013,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2804
3013
  let statChanged = 0;
2805
3014
  let statNew = 0;
2806
3015
  /**
3016
+ * Compute references.
2807
3017
  * @param {Module} module module
2808
3018
  * @returns {References} references
2809
3019
  */
@@ -2837,17 +3047,27 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2837
3047
  queue.push.apply(queue, block.blocks);
2838
3048
  }
2839
3049
  }
2840
- return { id, modules, blocks };
3050
+ return {
3051
+ id,
3052
+ modules,
3053
+ blocks,
3054
+ sourceTypes: module.getReferencedSourceTypes()
3055
+ };
2841
3056
  };
2842
3057
  /**
3058
+ * Compares references.
2843
3059
  * @param {Module} module module
2844
3060
  * @param {object} references references
2845
3061
  * @param {string | number} references.id id
2846
3062
  * @param {Map<Module, string | number | undefined>=} references.modules modules
2847
3063
  * @param {(string | number | null)[]=} references.blocks blocks
3064
+ * @param {SourceTypes=} references.sourceTypes connection-dependent source types
2848
3065
  * @returns {boolean} ok?
2849
3066
  */
2850
- const compareReferences = (module, { id, modules, blocks }) => {
3067
+ const compareReferences = (
3068
+ module,
3069
+ { id, modules, blocks, sourceTypes }
3070
+ ) => {
2851
3071
  if (id !== chunkGraph.getModuleId(module)) return false;
2852
3072
  if (modules !== undefined) {
2853
3073
  for (const [module, id] of modules) {
@@ -2871,6 +3091,13 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2871
3091
  }
2872
3092
  if (i !== blocks.length) return false;
2873
3093
  }
3094
+ // getReferencedSourceTypes() returns interned type sets, compare by reference. #20800
3095
+ if (
3096
+ sourceTypes !== undefined &&
3097
+ module.getReferencedSourceTypes() !== sourceTypes
3098
+ ) {
3099
+ return false;
3100
+ }
2874
3101
  return true;
2875
3102
  };
2876
3103
 
@@ -2907,6 +3134,58 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2907
3134
  }
2908
3135
 
2909
3136
  /**
3137
+ * Assigns a fresh dependency report cache token to every module whose
3138
+ * dependency errors/warnings could have changed since the previous
3139
+ * compilation: built modules and their (transitive) parents.
3140
+ * @private
3141
+ * @param {Set<Module>} modules modules
3142
+ * @returns {void}
3143
+ */
3144
+ _flagModulesForDependencyReporting(modules) {
3145
+ /** @type {DependencyReportCacheToken} */
3146
+ const token = {};
3147
+ const { moduleGraph, builtModules } = this;
3148
+ /** @type {Set<Module>} */
3149
+ const updatedModules = new Set();
3150
+ for (const module of modules) {
3151
+ if (
3152
+ builtModules.has(module) ||
3153
+ !dependencyReportCacheTokens.has(module)
3154
+ ) {
3155
+ updatedModules.add(module);
3156
+ }
3157
+ }
3158
+ // skip the parent walk when everything is updated anyway (initial build)
3159
+ if (updatedModules.size !== modules.size) {
3160
+ /** @type {Set<Module>} */
3161
+ const directOnlyUpdatedModules = new Set();
3162
+ for (const module of updatedModules) {
3163
+ for (const [
3164
+ referencingModule,
3165
+ connections
3166
+ ] of moduleGraph.getIncomingConnectionsByOriginModule(module)) {
3167
+ if (!referencingModule) continue;
3168
+ if (updatedModules.has(referencingModule)) continue;
3169
+ const type = reduceAffectType(connections);
3170
+ if (!type) continue;
3171
+ if (type === true) {
3172
+ directOnlyUpdatedModules.add(referencingModule);
3173
+ } else {
3174
+ updatedModules.add(referencingModule);
3175
+ }
3176
+ }
3177
+ }
3178
+ for (const module of directOnlyUpdatedModules) {
3179
+ updatedModules.add(module);
3180
+ }
3181
+ }
3182
+ for (const module of updatedModules) {
3183
+ dependencyReportCacheTokens.set(module, token);
3184
+ }
3185
+ }
3186
+
3187
+ /**
3188
+ * Processes the provided callback.
2910
3189
  * @param {Callback} callback callback
2911
3190
  */
2912
3191
  finish(callback) {
@@ -2966,6 +3245,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2966
3245
  const logger = this.getLogger("webpack.Compilation.ModuleProfile");
2967
3246
  // Avoid coverage problems due indirect changes
2968
3247
  /**
3248
+ * Processes the provided value.
2969
3249
  * @param {number} value value
2970
3250
  * @param {string} msg message
2971
3251
  */
@@ -2984,6 +3264,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2984
3264
  }
2985
3265
  };
2986
3266
  /**
3267
+ * Log normal summary.
2987
3268
  * @param {string} category a category
2988
3269
  * @param {(profile: ModuleProfile) => number} getDuration get duration callback
2989
3270
  * @param {(profile: ModuleProfile) => number} getParallelism get parallelism callback
@@ -3013,6 +3294,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3013
3294
  );
3014
3295
  };
3015
3296
  /**
3297
+ * Log by loaders summary.
3016
3298
  * @param {string} category a category
3017
3299
  * @param {(profile: ModuleProfile) => number} getDuration get duration callback
3018
3300
  * @param {(profile: ModuleProfile) => number} getParallelism get parallelism callback
@@ -3040,16 +3322,18 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3040
3322
  if (d === 0 || p === 0) continue;
3041
3323
  const t = d / p;
3042
3324
  innerSum += t;
3043
- if (t <= 10) continue;
3044
- logByValue(
3045
- t,
3046
- ` | | ${Math.round(t)} ms${
3047
- p >= 1.1 ? ` (parallelism ${Math.round(p * 10) / 10})` : ""
3048
- } ${category} > ${module.readableIdentifier(
3049
- this.requestShortener
3050
- )}`
3051
- );
3052
- innerMax = Math.max(innerMax, t);
3325
+ /* istanbul ignore next -- @preserve: only slow (>10ms) modules are logged, timing-dependent */
3326
+ if (t > 10) {
3327
+ logByValue(
3328
+ t,
3329
+ ` | | ${Math.round(t)} ms${
3330
+ p >= 1.1 ? ` (parallelism ${Math.round(p * 10) / 10})` : ""
3331
+ } ${category} > ${module.readableIdentifier(
3332
+ this.requestShortener
3333
+ )}`
3334
+ );
3335
+ innerMax = Math.max(innerMax, t);
3336
+ }
3053
3337
  }
3054
3338
  sum += innerSum;
3055
3339
  if (innerSum <= 10) continue;
@@ -3120,19 +3404,28 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3120
3404
 
3121
3405
  // extract warnings and errors from modules
3122
3406
  this.moduleGraph.freeze("dependency errors");
3123
- // TODO keep a cacheToken (= {}) for each module in the graph
3124
- // create a new one per compilation and flag all updated files
3125
- // and parents with it
3126
3407
  this.logger.time("report dependency errors and warnings");
3408
+ // moduleMemCaches has its own invalidation (incl. reference changes),
3409
+ // so cache tokens are only used without it
3410
+ const useReportCacheTokens = moduleMemCaches === undefined;
3411
+ if (useReportCacheTokens) {
3412
+ this._flagModulesForDependencyReporting(modules);
3413
+ }
3127
3414
  for (const module of modules) {
3128
- // TODO only run for modules with changed cacheToken
3129
- // global WeakMap<CacheToken, WeakSet<Module>> to keep modules without errors/warnings
3130
3415
  const memCache = moduleMemCaches && moduleMemCaches.get(module);
3131
3416
  if (memCache && memCache.get("noWarningsOrErrors")) continue;
3417
+ let token;
3418
+ if (useReportCacheTokens) {
3419
+ token = dependencyReportCacheTokens.get(module);
3420
+ const cleanModules = modulesWithoutProblems.get(
3421
+ /** @type {DependencyReportCacheToken} */ (token)
3422
+ );
3423
+ if (cleanModules !== undefined && cleanModules.has(module)) continue;
3424
+ }
3132
3425
  let hasProblems = this.reportDependencyErrorsAndWarnings(module, [
3133
3426
  module
3134
3427
  ]);
3135
- const errors = module.getErrors();
3428
+ const errors = /** @type {WebpackError[]} */ (module.getErrors());
3136
3429
  if (errors !== undefined) {
3137
3430
  for (const error of errors) {
3138
3431
  if (!error.module) {
@@ -3142,7 +3435,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3142
3435
  hasProblems = true;
3143
3436
  }
3144
3437
  }
3145
- const warnings = module.getWarnings();
3438
+ const warnings = /** @type {WebpackError[]} */ (module.getWarnings());
3146
3439
  if (warnings !== undefined) {
3147
3440
  for (const warning of warnings) {
3148
3441
  if (!warning.module) {
@@ -3152,7 +3445,21 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3152
3445
  hasProblems = true;
3153
3446
  }
3154
3447
  }
3155
- if (!hasProblems && memCache) memCache.set("noWarningsOrErrors", true);
3448
+ if (!hasProblems) {
3449
+ if (memCache) memCache.set("noWarningsOrErrors", true);
3450
+ if (useReportCacheTokens) {
3451
+ let cleanModules = modulesWithoutProblems.get(
3452
+ /** @type {DependencyReportCacheToken} */ (token)
3453
+ );
3454
+ if (cleanModules === undefined) {
3455
+ modulesWithoutProblems.set(
3456
+ /** @type {DependencyReportCacheToken} */ (token),
3457
+ (cleanModules = new WeakSet())
3458
+ );
3459
+ }
3460
+ cleanModules.add(module);
3461
+ }
3462
+ }
3156
3463
  }
3157
3464
  this.moduleGraph.unfreeze();
3158
3465
  this.logger.timeEnd("report dependency errors and warnings");
@@ -3171,17 +3478,21 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3171
3478
  this.additionalChunkAssets.length = 0;
3172
3479
  this.assets = {};
3173
3480
  this.assetsInfo.clear();
3481
+ this._assetToChunkIndex = undefined;
3482
+ this._assetToChunkAuxiliaryIndex = undefined;
3174
3483
  this.moduleGraph.removeAllModuleAttributes();
3175
3484
  this.moduleGraph.unfreeze();
3176
3485
  this.moduleMemCaches2 = undefined;
3177
3486
  }
3178
3487
 
3179
3488
  /**
3489
+ * Processes the provided callback.
3180
3490
  * @param {Callback} callback signals when the call finishes
3181
3491
  * @returns {void}
3182
3492
  */
3183
3493
  seal(callback) {
3184
3494
  /**
3495
+ * Processes the provided err.
3185
3496
  * @param {WebpackError=} err err
3186
3497
  * @returns {void}
3187
3498
  */
@@ -3191,6 +3502,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3191
3502
  this.rebuildQueue.clear();
3192
3503
  this.processDependenciesQueue.clear();
3193
3504
  this.addModuleQueue.clear();
3505
+ // lazy barrel only acts during make; release its bookkeeping now
3506
+ this._lazyBarrelController.clear();
3194
3507
  return callback(err);
3195
3508
  };
3196
3509
 
@@ -3228,7 +3541,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3228
3541
  this.namedChunkGroups.set(name, entrypoint);
3229
3542
  this.entrypoints.set(name, entrypoint);
3230
3543
  this.chunkGroups.push(entrypoint);
3231
- connectChunkGroupAndChunk(entrypoint, chunk);
3544
+
3545
+ if (entrypoint.pushChunk(chunk)) {
3546
+ chunk.addGroup(entrypoint);
3547
+ }
3232
3548
 
3233
3549
  /** @type {Set<Module>} */
3234
3550
  const entryModules = new Set();
@@ -3256,6 +3572,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
3256
3572
  this.assignDepths(entryModules);
3257
3573
 
3258
3574
  /**
3575
+ * Returns sorted deps.
3259
3576
  * @param {Dependency[]} deps deps
3260
3577
  * @returns {Module[]} sorted deps
3261
3578
  */
@@ -3318,8 +3635,12 @@ Remove the 'runtime' option from the entrypoint.`);
3318
3635
  entry.setRuntimeChunk(entryChunk);
3319
3636
  continue outer;
3320
3637
  }
3321
- connectEntrypointAndDependOn(entry, dependency);
3322
- connectChunkGroupParentAndChild(dependency, entry);
3638
+
3639
+ entry.addDependOn(dependency);
3640
+
3641
+ if (dependency.addChild(entry)) {
3642
+ entry.addParent(dependency);
3643
+ }
3323
3644
  }
3324
3645
  } else if (runtime) {
3325
3646
  const entry = /** @type {Entrypoint} */ (this.entrypoints.get(name));
@@ -3556,6 +3877,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3556
3877
  }
3557
3878
 
3558
3879
  /**
3880
+ * Report dependency errors and warnings.
3559
3881
  * @param {Module} module module to report from
3560
3882
  * @param {DependenciesBlock[]} blocks blocks to report from
3561
3883
  * @returns {boolean} true, when it has warnings or errors
@@ -3569,7 +3891,14 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3569
3891
  const warnings = d.getWarnings(this.moduleGraph);
3570
3892
  if (warnings) {
3571
3893
  for (const w of warnings) {
3572
- const warning = new ModuleDependencyWarning(module, w, d.loc);
3894
+ // A consolidated dependency (e.g. CssIcssExportDependency) carries
3895
+ // per-item locations on the error itself; fall back to the
3896
+ // dependency loc for the usual one-loc-per-dependency case.
3897
+ const warning = new ModuleDependencyWarning(
3898
+ module,
3899
+ w,
3900
+ /** @type {EXPECTED_ANY} */ (w).loc || d.loc
3901
+ );
3573
3902
  this.warnings.push(warning);
3574
3903
  hasProblems = true;
3575
3904
  }
@@ -3577,7 +3906,11 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3577
3906
  const errors = d.getErrors(this.moduleGraph);
3578
3907
  if (errors) {
3579
3908
  for (const e of errors) {
3580
- const error = new ModuleDependencyError(module, e, d.loc);
3909
+ const error = new ModuleDependencyError(
3910
+ module,
3911
+ e,
3912
+ /** @type {EXPECTED_ANY} */ (e).loc || d.loc
3913
+ );
3581
3914
  this.errors.push(error);
3582
3915
  hasProblems = true;
3583
3916
  }
@@ -3592,6 +3925,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3592
3925
  }
3593
3926
 
3594
3927
  /**
3928
+ * Generates code and runtime requirements for this module.
3595
3929
  * @param {Callback} callback callback
3596
3930
  */
3597
3931
  codeGeneration(callback) {
@@ -3629,6 +3963,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3629
3963
  }
3630
3964
 
3631
3965
  /**
3966
+ * Run code generation jobs.
3632
3967
  * @private
3633
3968
  * @param {CodeGenerationJobs} jobs code generation jobs
3634
3969
  * @param {Callback} callback callback
@@ -3738,6 +4073,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3738
4073
  }
3739
4074
 
3740
4075
  /**
4076
+ * Code generation module.
3741
4077
  * @param {Module} module module
3742
4078
  * @param {RuntimeSpec} runtime runtime
3743
4079
  * @param {RuntimeSpec[]} runtimes runtimes
@@ -3749,6 +4085,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3749
4085
  * @param {WebpackError[]} errors errors
3750
4086
  * @param {CodeGenerationResults} results results
3751
4087
  * @param {(err?: WebpackError | null, result?: boolean) => void} callback callback
4088
+ * @returns {void}
3752
4089
  */
3753
4090
  _codeGenerationModule(
3754
4091
  module,
@@ -3764,6 +4101,39 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3764
4101
  callback
3765
4102
  ) {
3766
4103
  let codeGenerated = false;
4104
+ // without a cache backend, skip building the cache keys — the module
4105
+ // identifier strings are large (concatenated modules join all inner ids)
4106
+ if (!this._codeGenerationCache.isEnabled()) {
4107
+ /** @type {CodeGenerationResult} */
4108
+ let result;
4109
+ try {
4110
+ codeGenerated = true;
4111
+ this.codeGeneratedModules.add(module);
4112
+ result = module.codeGeneration({
4113
+ chunkGraph,
4114
+ moduleGraph,
4115
+ dependencyTemplates,
4116
+ runtimeTemplate,
4117
+ runtime,
4118
+ runtimes,
4119
+ codeGenerationResults: results,
4120
+ compilation: this
4121
+ });
4122
+ } catch (err) {
4123
+ errors.push(
4124
+ new CodeGenerationError(module, /** @type {Error} */ (err))
4125
+ );
4126
+ result = {
4127
+ sources: new Map(),
4128
+ runtimeRequirements: null,
4129
+ data: undefined
4130
+ };
4131
+ }
4132
+ for (const runtime of runtimes) {
4133
+ results.add(module, runtime, result);
4134
+ }
4135
+ return callback(null, codeGenerated);
4136
+ }
3767
4137
  const cache = new MultiItemCache(
3768
4138
  runtimes.map((runtime) =>
3769
4139
  this._codeGenerationCache.getItemCache(
@@ -3796,7 +4166,8 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3796
4166
  );
3797
4167
  result = cachedResult = {
3798
4168
  sources: new Map(),
3799
- runtimeRequirements: null
4169
+ runtimeRequirements: null,
4170
+ data: undefined
3800
4171
  };
3801
4172
  }
3802
4173
  } else {
@@ -3830,6 +4201,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3830
4201
  }
3831
4202
 
3832
4203
  /**
4204
+ * Process runtime requirements.
3833
4205
  * @param {object} options options
3834
4206
  * @param {ChunkGraph=} options.chunkGraph the chunk graph
3835
4207
  * @param {Iterable<Module>=} options.modules modules
@@ -3973,6 +4345,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3973
4345
 
3974
4346
  // TODO webpack 6 make chunkGraph argument non-optional
3975
4347
  /**
4348
+ * Adds runtime module.
3976
4349
  * @param {Chunk} chunk target chunk
3977
4350
  * @param {RuntimeModule} module runtime module
3978
4351
  * @param {ChunkGraph} chunkGraph the chunk graph
@@ -4065,7 +4438,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4065
4438
  }
4066
4439
  const chunk = this.addChunk(name);
4067
4440
 
4068
- connectChunkGroupAndChunk(chunkGroup, chunk);
4441
+ if (chunkGroup.pushChunk(chunk)) {
4442
+ chunk.addGroup(chunkGroup);
4443
+ }
4069
4444
 
4070
4445
  this.chunkGroups.push(chunkGroup);
4071
4446
  if (name) {
@@ -4075,6 +4450,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4075
4450
  }
4076
4451
 
4077
4452
  /**
4453
+ * Adds the provided async entrypoint to this chunk group.
4078
4454
  * @param {EntryOptions} options options for the entrypoint
4079
4455
  * @param {Module} module the module the references the chunk group
4080
4456
  * @param {DependencyLocation} loc the location from with the chunk group is referenced (inside of module)
@@ -4108,7 +4484,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4108
4484
  }
4109
4485
  this.chunkGroups.push(entrypoint);
4110
4486
  this.asyncEntrypoints.push(entrypoint);
4111
- connectChunkGroupAndChunk(entrypoint, chunk);
4487
+ if (entrypoint.pushChunk(chunk)) {
4488
+ chunk.addGroup(entrypoint);
4489
+ }
4112
4490
  if (module) {
4113
4491
  entrypoint.addOrigin(module, loc, request);
4114
4492
  }
@@ -4140,6 +4518,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4140
4518
  }
4141
4519
 
4142
4520
  /**
4521
+ * Processes the provided module.
4143
4522
  * @deprecated
4144
4523
  * @param {Module} module module to assign depth
4145
4524
  * @returns {void}
@@ -4154,6 +4533,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4154
4533
  moduleGraph.setDepth(module, 0);
4155
4534
 
4156
4535
  /**
4536
+ * Processes the provided module.
4157
4537
  * @param {Module} module module for processing
4158
4538
  * @returns {void}
4159
4539
  */
@@ -4176,7 +4556,8 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4176
4556
  }
4177
4557
 
4178
4558
  /**
4179
- * @param {Module[] | Set<Module>} modules module to assign depth
4559
+ * Assigns depth values to the provided modules.
4560
+ * @param {Module[] | Set<Module>} modules modules to assign depth
4180
4561
  * @returns {void}
4181
4562
  */
4182
4563
  assignDepths(modules) {
@@ -4210,6 +4591,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4210
4591
  }
4211
4592
 
4212
4593
  /**
4594
+ * Gets dependency referenced exports.
4213
4595
  * @param {Dependency} dependency the dependency
4214
4596
  * @param {RuntimeSpec} runtime the runtime
4215
4597
  * @returns {ReferencedExports} referenced exports
@@ -4227,6 +4609,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4227
4609
  }
4228
4610
 
4229
4611
  /**
4612
+ * Removes reasons of dependency block.
4230
4613
  * @param {Module} module module relationship for removal
4231
4614
  * @param {DependenciesBlockLike} block dependencies block
4232
4615
  * @returns {void}
@@ -4257,6 +4640,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4257
4640
  }
4258
4641
 
4259
4642
  /**
4643
+ * Patch chunks after reason removal.
4260
4644
  * @param {Module} module module to patch tie
4261
4645
  * @param {Chunk} chunk chunk to patch tie
4262
4646
  * @returns {void}
@@ -4275,12 +4659,14 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4275
4659
  }
4276
4660
 
4277
4661
  /**
4662
+ * Removes chunk from dependencies.
4278
4663
  * @param {DependenciesBlock} block block tie for Chunk
4279
4664
  * @param {Chunk} chunk chunk to remove from dep
4280
4665
  * @returns {void}
4281
4666
  */
4282
4667
  removeChunkFromDependencies(block, chunk) {
4283
4668
  /**
4669
+ * Iterator dependency.
4284
4670
  * @param {Dependency} d dependency to (maybe) patch up
4285
4671
  */
4286
4672
  const iteratorDependency = (d) => {
@@ -4314,6 +4700,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4314
4700
  assignRuntimeIds() {
4315
4701
  const { chunkGraph } = this;
4316
4702
  /**
4703
+ * Process entrypoint.
4317
4704
  * @param {Entrypoint} ep an entrypoint
4318
4705
  */
4319
4706
  const processEntrypoint = (ep) => {
@@ -4416,6 +4803,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4416
4803
  }
4417
4804
 
4418
4805
  /**
4806
+ * Create module hash.
4419
4807
  * @private
4420
4808
  * @param {Module} module module
4421
4809
  * @param {ChunkGraph} chunkGraph the chunk graph
@@ -4630,6 +5018,7 @@ This prevents using hashes of each other and should be avoided.`);
4630
5018
  const errors = [];
4631
5019
 
4632
5020
  /**
5021
+ * Processes the provided chunk.
4633
5022
  * @param {Chunk} chunk chunk
4634
5023
  */
4635
5024
  const processChunk = (chunk) => {
@@ -4762,12 +5151,18 @@ This prevents using hashes of each other and should be avoided.`);
4762
5151
  }
4763
5152
 
4764
5153
  /**
5154
+ * Processes the provided file.
4765
5155
  * @param {string} file file name
4766
5156
  * @param {Source} source asset source
4767
5157
  * @param {AssetInfo} assetInfo extra asset information
4768
5158
  * @returns {void}
4769
5159
  */
4770
5160
  emitAsset(file, source, assetInfo = {}) {
5161
+ // A file may be attached to a chunk right after any emit (including the
5162
+ // re-emit path for assets shared across chunks in createChunkAssets), so
5163
+ // the lazily-built reverse index is stale after every emitAsset.
5164
+ this._assetToChunkIndex = undefined;
5165
+ this._assetToChunkAuxiliaryIndex = undefined;
4771
5166
  if (this.assets[file]) {
4772
5167
  if (!isSourceEqual(this.assets[file], source)) {
4773
5168
  this.errors.push(
@@ -4793,6 +5188,7 @@ This prevents using hashes of each other and should be avoided.`);
4793
5188
  }
4794
5189
 
4795
5190
  /**
5191
+ * Processes the provided file.
4796
5192
  * @private
4797
5193
  * @param {string} file file name
4798
5194
  * @param {AssetInfo=} newInfo new asset information
@@ -4809,6 +5205,7 @@ This prevents using hashes of each other and should be avoided.`);
4809
5205
  if (oldRelated) {
4810
5206
  for (const key of Object.keys(oldRelated)) {
4811
5207
  /**
5208
+ * Processes the provided name.
4812
5209
  * @param {string} name name
4813
5210
  */
4814
5211
  const remove = (name) => {
@@ -4834,6 +5231,7 @@ This prevents using hashes of each other and should be avoided.`);
4834
5231
  if (newRelated) {
4835
5232
  for (const key of Object.keys(newRelated)) {
4836
5233
  /**
5234
+ * Processes the provided name.
4837
5235
  * @param {string} name name
4838
5236
  */
4839
5237
  const add = (name) => {
@@ -4860,6 +5258,7 @@ This prevents using hashes of each other and should be avoided.`);
4860
5258
  }
4861
5259
 
4862
5260
  /**
5261
+ * Updates asset using the provided file.
4863
5262
  * @param {string} file file name
4864
5263
  * @param {Source | ((source: Source) => Source)} newSourceOrFunction new asset source or function converting old to new
4865
5264
  * @param {(AssetInfo | ((assetInfo?: AssetInfo) => AssetInfo | undefined)) | undefined} assetInfoUpdateOrFunction new asset info or function converting old to new
@@ -4893,6 +5292,7 @@ This prevents using hashes of each other and should be avoided.`);
4893
5292
  }
4894
5293
 
4895
5294
  /**
5295
+ * Processes the provided file.
4896
5296
  * @param {string} file file name
4897
5297
  * @param {string} newFile the new name of file
4898
5298
  */
@@ -4944,25 +5344,99 @@ This prevents using hashes of each other and should be avoided.`);
4944
5344
  this._setAssetInfo(newFile, assetInfo);
4945
5345
  delete this.assets[file];
4946
5346
  this.assets[newFile] = source;
5347
+ this._buildAssetToChunkIndex();
5348
+ const index = /** @type {Map<string, Set<Chunk>>} */ (
5349
+ this._assetToChunkIndex
5350
+ );
5351
+ const auxiliaryIndex = /** @type {Map<string, Set<Chunk>>} */ (
5352
+ this._assetToChunkAuxiliaryIndex
5353
+ );
5354
+ const chunks = index.get(file);
5355
+ const auxiliaryChunks = auxiliaryIndex.get(file);
5356
+ if (chunks === undefined && auxiliaryChunks === undefined) {
5357
+ // Not tracked in either index: chunk sets may have been mutated
5358
+ // directly (bypassing emitAsset), so scan all chunks to stay correct.
5359
+ for (const chunk of this.chunks) {
5360
+ this._renameAssetInChunk(chunk, chunk.files, index, file, newFile);
5361
+ this._renameAssetInChunk(
5362
+ chunk,
5363
+ chunk.auxiliaryFiles,
5364
+ auxiliaryIndex,
5365
+ file,
5366
+ newFile
5367
+ );
5368
+ }
5369
+ return;
5370
+ }
5371
+ if (chunks !== undefined) {
5372
+ index.delete(file);
5373
+ for (const chunk of chunks) {
5374
+ this._renameAssetInChunk(chunk, chunk.files, index, file, newFile);
5375
+ }
5376
+ }
5377
+ if (auxiliaryChunks !== undefined) {
5378
+ auxiliaryIndex.delete(file);
5379
+ for (const chunk of auxiliaryChunks) {
5380
+ this._renameAssetInChunk(
5381
+ chunk,
5382
+ chunk.auxiliaryFiles,
5383
+ auxiliaryIndex,
5384
+ file,
5385
+ newFile
5386
+ );
5387
+ }
5388
+ }
5389
+ }
5390
+
5391
+ // Lazily build the reverse index file -> chunks. emitAsset() invalidates
5392
+ // it, so chunk.files / chunk.auxiliaryFiles entries added alongside a newly
5393
+ // emitted asset are always picked up on the next rebuild.
5394
+ /**
5395
+ * @private
5396
+ * @returns {void}
5397
+ */
5398
+ _buildAssetToChunkIndex() {
5399
+ if (this._assetToChunkIndex !== undefined) return;
5400
+ /** @type {Map<string, Set<Chunk>>} */
5401
+ const filesIndex = new Map();
5402
+ /** @type {Map<string, Set<Chunk>>} */
5403
+ const auxiliaryIndex = new Map();
4947
5404
  for (const chunk of this.chunks) {
4948
- {
4949
- const size = chunk.files.size;
4950
- chunk.files.delete(file);
4951
- if (size !== chunk.files.size) {
4952
- chunk.files.add(newFile);
4953
- }
5405
+ for (const file of chunk.files) {
5406
+ let set = filesIndex.get(file);
5407
+ if (set === undefined) filesIndex.set(file, (set = new Set()));
5408
+ set.add(chunk);
4954
5409
  }
4955
- {
4956
- const size = chunk.auxiliaryFiles.size;
4957
- chunk.auxiliaryFiles.delete(file);
4958
- if (size !== chunk.auxiliaryFiles.size) {
4959
- chunk.auxiliaryFiles.add(newFile);
4960
- }
5410
+ for (const file of chunk.auxiliaryFiles) {
5411
+ let set = auxiliaryIndex.get(file);
5412
+ if (set === undefined) auxiliaryIndex.set(file, (set = new Set()));
5413
+ set.add(chunk);
4961
5414
  }
4962
5415
  }
5416
+ this._assetToChunkIndex = filesIndex;
5417
+ this._assetToChunkAuxiliaryIndex = auxiliaryIndex;
4963
5418
  }
4964
5419
 
4965
5420
  /**
5421
+ * @private
5422
+ * @param {Chunk} chunk the chunk owning the set
5423
+ * @param {Set<string>} set chunk.files or chunk.auxiliaryFiles
5424
+ * @param {Map<string, Set<Chunk>>} index matching reverse index
5425
+ * @param {string} file old file name
5426
+ * @param {string} newFile new file name
5427
+ * @returns {void}
5428
+ */
5429
+ _renameAssetInChunk(chunk, set, index, file, newFile) {
5430
+ // Only carry the rename to chunks that actually held the old name.
5431
+ if (!set.delete(file)) return;
5432
+ set.add(newFile);
5433
+ let target = index.get(newFile);
5434
+ if (target === undefined) index.set(newFile, (target = new Set()));
5435
+ target.add(chunk);
5436
+ }
5437
+
5438
+ /**
5439
+ * Processes the provided file.
4966
5440
  * @param {string} file file name
4967
5441
  */
4968
5442
  deleteAsset(file) {
@@ -4976,6 +5450,7 @@ This prevents using hashes of each other and should be avoided.`);
4976
5450
  if (related) {
4977
5451
  for (const key of Object.keys(related)) {
4978
5452
  /**
5453
+ * Checks used and delete.
4979
5454
  * @param {string} file file
4980
5455
  */
4981
5456
  const checkUsedAndDelete = (file) => {
@@ -4993,11 +5468,31 @@ This prevents using hashes of each other and should be avoided.`);
4993
5468
  }
4994
5469
  }
4995
5470
  }
4996
- // TODO If this becomes a performance problem
4997
- // store a reverse mapping from asset to chunk
4998
- for (const chunk of this.chunks) {
4999
- chunk.files.delete(file);
5000
- chunk.auxiliaryFiles.delete(file);
5471
+ this._buildAssetToChunkIndex();
5472
+ const index = /** @type {Map<string, Set<Chunk>>} */ (
5473
+ this._assetToChunkIndex
5474
+ );
5475
+ const auxiliaryIndex = /** @type {Map<string, Set<Chunk>>} */ (
5476
+ this._assetToChunkAuxiliaryIndex
5477
+ );
5478
+ const chunks = index.get(file);
5479
+ const auxiliaryChunks = auxiliaryIndex.get(file);
5480
+ if (chunks === undefined && auxiliaryChunks === undefined) {
5481
+ // Not tracked in either index: chunk sets may have been mutated
5482
+ // directly (bypassing emitAsset), so scan all chunks to stay correct.
5483
+ for (const chunk of this.chunks) {
5484
+ chunk.files.delete(file);
5485
+ chunk.auxiliaryFiles.delete(file);
5486
+ }
5487
+ return;
5488
+ }
5489
+ if (chunks !== undefined) {
5490
+ for (const chunk of chunks) chunk.files.delete(file);
5491
+ index.delete(file);
5492
+ }
5493
+ if (auxiliaryChunks !== undefined) {
5494
+ for (const chunk of auxiliaryChunks) chunk.auxiliaryFiles.delete(file);
5495
+ auxiliaryIndex.delete(file);
5001
5496
  }
5002
5497
  }
5003
5498
 
@@ -5017,6 +5512,7 @@ This prevents using hashes of each other and should be avoided.`);
5017
5512
  }
5018
5513
 
5019
5514
  /**
5515
+ * Returns the asset or undefined when not found.
5020
5516
  * @param {string} name the name of the asset
5021
5517
  * @returns {Readonly<Asset> | undefined} the asset or undefined when not found
5022
5518
  */
@@ -5034,6 +5530,8 @@ This prevents using hashes of each other and should be avoided.`);
5034
5530
  chunk.files.clear();
5035
5531
  chunk.auxiliaryFiles.clear();
5036
5532
  }
5533
+ this._assetToChunkIndex = undefined;
5534
+ this._assetToChunkAuxiliaryIndex = undefined;
5037
5535
  }
5038
5536
 
5039
5537
  createModuleAssets() {
@@ -5062,6 +5560,7 @@ This prevents using hashes of each other and should be avoided.`);
5062
5560
  }
5063
5561
 
5064
5562
  /**
5563
+ * Gets render manifest.
5065
5564
  * @param {RenderManifestOptions} options options object
5066
5565
  * @returns {RenderManifestEntry[]} manifest entries
5067
5566
  */
@@ -5070,6 +5569,7 @@ This prevents using hashes of each other and should be avoided.`);
5070
5569
  }
5071
5570
 
5072
5571
  /**
5572
+ * Creates a chunk assets.
5073
5573
  * @param {Callback} callback signals when the call finishes
5074
5574
  * @returns {void}
5075
5575
  */
@@ -5119,7 +5619,7 @@ This prevents using hashes of each other and should be avoided.`);
5119
5619
  );
5120
5620
 
5121
5621
  assetCacheItem.get((err, sourceFromCache) => {
5122
- /** @type {TemplatePath} */
5622
+ /** @type {string | import("./TemplatedPathPlugin").TemplatePathFn<EXPECTED_ANY>} */
5123
5623
  let filenameTemplate;
5124
5624
  /** @type {string} */
5125
5625
  let file;
@@ -5128,6 +5628,7 @@ This prevents using hashes of each other and should be avoided.`);
5128
5628
 
5129
5629
  let inTry = true;
5130
5630
  /**
5631
+ * Error and callback.
5131
5632
  * @param {Error} err error
5132
5633
  * @returns {void}
5133
5634
  */
@@ -5235,11 +5736,13 @@ This prevents using hashes of each other and should be avoided.`);
5235
5736
  }
5236
5737
 
5237
5738
  /**
5238
- * @param {TemplatePath} filename used to get asset path with hash
5239
- * @param {PathData} data context data
5739
+ * Returns interpolated path.
5740
+ * @template {PathData} [T=PathData]
5741
+ * @param {string | import("./TemplatedPathPlugin").TemplatePathFn<T>} filename used to get asset path with hash
5742
+ * @param {T=} data context data
5240
5743
  * @returns {string} interpolated path
5241
5744
  */
5242
- getPath(filename, data = {}) {
5745
+ getPath(filename, data = /** @type {T} */ ({})) {
5243
5746
  if (!data.hash) {
5244
5747
  data = {
5245
5748
  hash: this.hash,
@@ -5250,11 +5753,13 @@ This prevents using hashes of each other and should be avoided.`);
5250
5753
  }
5251
5754
 
5252
5755
  /**
5253
- * @param {TemplatePath} filename used to get asset path with hash
5254
- * @param {PathData} data context data
5756
+ * Gets path with info.
5757
+ * @template {PathData} [T=PathData]
5758
+ * @param {string | import("./TemplatedPathPlugin").TemplatePathFn<T>} filename used to get asset path with hash
5759
+ * @param {T=} data context data
5255
5760
  * @returns {InterpolatedPathAndAssetInfo} interpolated path and asset info
5256
5761
  */
5257
- getPathWithInfo(filename, data = {}) {
5762
+ getPathWithInfo(filename, data = /** @type {T} */ ({})) {
5258
5763
  if (!data.hash) {
5259
5764
  data = {
5260
5765
  hash: this.hash,
@@ -5265,8 +5770,10 @@ This prevents using hashes of each other and should be avoided.`);
5265
5770
  }
5266
5771
 
5267
5772
  /**
5268
- * @param {TemplatePath} filename used to get asset path with hash
5269
- * @param {PathData} data context data
5773
+ * Returns interpolated path.
5774
+ * @template {PathData} [T=PathData]
5775
+ * @param {string | import("./TemplatedPathPlugin").TemplatePathFn<T>} filename used to get asset path with hash
5776
+ * @param {T} data context data
5270
5777
  * @returns {string} interpolated path
5271
5778
  */
5272
5779
  getAssetPath(filename, data) {
@@ -5278,8 +5785,10 @@ This prevents using hashes of each other and should be avoided.`);
5278
5785
  }
5279
5786
 
5280
5787
  /**
5281
- * @param {TemplatePath} filename used to get asset path with hash
5282
- * @param {PathData} data context data
5788
+ * Gets asset path with info.
5789
+ * @template {PathData} [T=PathData]
5790
+ * @param {string | import("./TemplatedPathPlugin").TemplatePathFn<T>} filename used to get asset path with hash
5791
+ * @param {T} data context data
5283
5792
  * @returns {InterpolatedPathAndAssetInfo} interpolated path and asset info
5284
5793
  */
5285
5794
  getAssetPathWithInfo(filename, data) {
@@ -5323,6 +5832,7 @@ This prevents using hashes of each other and should be avoided.`);
5323
5832
  }
5324
5833
 
5325
5834
  /**
5835
+ * Processes the provided module.
5326
5836
  * @param {Module} module the module
5327
5837
  * @param {ExecuteModuleOptions} options options
5328
5838
  * @param {ExecuteModuleCallback} callback callback
@@ -5373,7 +5883,9 @@ This prevents using hashes of each other and should be avoided.`);
5373
5883
  ...options.entryOptions
5374
5884
  });
5375
5885
  chunkGraph.connectChunkAndEntryModule(chunk, module, entrypoint);
5376
- connectChunkGroupAndChunk(entrypoint, chunk);
5886
+ if (entrypoint.pushChunk(chunk)) {
5887
+ chunk.addGroup(entrypoint);
5888
+ }
5377
5889
  entrypoint.setRuntimeChunk(chunk);
5378
5890
  entrypoint.setEntrypointChunk(chunk);
5379
5891
 
@@ -5407,6 +5919,7 @@ This prevents using hashes of each other and should be avoided.`);
5407
5919
  this.outputOptions.hashFunction
5408
5920
  );
5409
5921
  /**
5922
+ * Processes the provided module.
5410
5923
  * @param {Module} module the module
5411
5924
  * @param {Callback} callback callback
5412
5925
  * @returns {void}
@@ -5512,6 +6025,8 @@ This prevents using hashes of each other and should be avoided.`);
5512
6025
  const assets = new Map();
5513
6026
 
5514
6027
  let cacheable = true;
6028
+ /** @type {ExecuteModuleResult["notCacheableReasons"]} */
6029
+ const notCacheableReasons = [];
5515
6030
 
5516
6031
  /** @type {ExecuteModuleContext} */
5517
6032
  const context = {
@@ -5547,11 +6062,18 @@ This prevents using hashes of each other and should be avoided.`);
5547
6062
  missingDependencies,
5548
6063
  buildDependencies
5549
6064
  );
5550
- if (
5551
- /** @type {BuildInfo} */ (module.buildInfo).cacheable ===
5552
- false
5553
- ) {
6065
+ const buildInfo = /** @type {BuildInfo} */ (
6066
+ module.buildInfo
6067
+ );
6068
+ if (buildInfo.cacheable === false) {
5554
6069
  cacheable = false;
6070
+ if (buildInfo.notCacheableReasons) {
6071
+ for (const reason of buildInfo.notCacheableReasons) {
6072
+ if (!notCacheableReasons.includes(reason)) {
6073
+ notCacheableReasons.push(reason);
6074
+ }
6075
+ }
6076
+ }
5555
6077
  }
5556
6078
  if (module.buildInfo && module.buildInfo.assets) {
5557
6079
  const { assets: moduleAssets, assetsInfo } =
@@ -5617,6 +6139,7 @@ This prevents using hashes of each other and should be avoided.`);
5617
6139
  context.__webpack_require__ = __webpack_require__;
5618
6140
 
5619
6141
  /**
6142
+ * Webpack require module.
5620
6143
  * @param {ExecuteModuleArgument} moduleArgument the module argument
5621
6144
  * @param {string=} id id
5622
6145
  * @returns {ExecuteModuleExports} exports
@@ -5702,6 +6225,7 @@ This prevents using hashes of each other and should be avoided.`);
5702
6225
  exports,
5703
6226
  assets,
5704
6227
  cacheable,
6228
+ notCacheableReasons,
5705
6229
  fileDependencies,
5706
6230
  contextDependencies,
5707
6231
  missingDependencies,
@@ -5759,6 +6283,7 @@ This prevents using hashes of each other and should be avoided.`);
5759
6283
  }
5760
6284
 
5761
6285
  /**
6286
+ * Defines the factorize module options type used by this module.
5762
6287
  * @typedef {object} FactorizeModuleOptions
5763
6288
  * @property {ModuleProfile=} currentProfile
5764
6289
  * @property {ModuleFactory} factory
@@ -5770,6 +6295,7 @@ This prevents using hashes of each other and should be avoided.`);
5770
6295
  */
5771
6296
 
5772
6297
  /**
6298
+ * Processes the provided factorize module option.
5773
6299
  * @param {FactorizeModuleOptions} options options object
5774
6300
  * @param {ModuleCallback | ModuleFactoryResultCallback} callback callback
5775
6301
  * @returns {void}
@@ -5796,6 +6322,7 @@ Object.defineProperty(compilationPrototype, "cache", {
5796
6322
  configurable: false,
5797
6323
  get: util.deprecate(
5798
6324
  /**
6325
+ * Returns the cache.
5799
6326
  * @this {Compilation} the compilation
5800
6327
  * @returns {Cache} the cache
5801
6328
  */
@@ -5807,6 +6334,7 @@ Object.defineProperty(compilationPrototype, "cache", {
5807
6334
  ),
5808
6335
  set: util.deprecate(
5809
6336
  /**
6337
+ * Handles the value callback for this hook.
5810
6338
  * @param {EXPECTED_ANY} _v value
5811
6339
  */
5812
6340
  (_v) => {},