webpack 5.97.1 → 5.104.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (610) hide show
  1. package/README.md +368 -434
  2. package/bin/webpack.js +15 -9
  3. package/hot/dev-server.js +18 -3
  4. package/hot/emitter-event-target.js +7 -0
  5. package/hot/lazy-compilation-node.js +45 -29
  6. package/hot/lazy-compilation-universal.js +18 -0
  7. package/hot/lazy-compilation-web.js +15 -5
  8. package/hot/load-http.js +7 -0
  9. package/hot/log.js +15 -15
  10. package/hot/only-dev-server.js +19 -4
  11. package/hot/poll.js +1 -0
  12. package/lib/APIPlugin.js +48 -50
  13. package/lib/AbstractMethodError.js +1 -0
  14. package/lib/AsyncDependenciesBlock.js +4 -5
  15. package/lib/AutomaticPrefetchPlugin.js +22 -22
  16. package/lib/BannerPlugin.js +35 -40
  17. package/lib/Cache.js +12 -9
  18. package/lib/CacheFacade.js +13 -13
  19. package/lib/CaseSensitiveModulesWarning.js +6 -6
  20. package/lib/Chunk.js +68 -47
  21. package/lib/ChunkGraph.js +174 -95
  22. package/lib/ChunkGroup.js +32 -24
  23. package/lib/ChunkTemplate.js +8 -8
  24. package/lib/CleanPlugin.js +90 -42
  25. package/lib/CodeGenerationResults.js +12 -9
  26. package/lib/CompatibilityPlugin.js +70 -21
  27. package/lib/Compilation.js +827 -550
  28. package/lib/Compiler.js +137 -109
  29. package/lib/ConcatenationScope.js +45 -8
  30. package/lib/ConditionalInitFragment.js +1 -1
  31. package/lib/ConstPlugin.js +89 -59
  32. package/lib/ContextExclusionPlugin.js +5 -4
  33. package/lib/ContextModule.js +66 -51
  34. package/lib/ContextModuleFactory.js +51 -30
  35. package/lib/ContextReplacementPlugin.js +89 -34
  36. package/lib/CssModule.js +8 -4
  37. package/lib/DefinePlugin.js +209 -57
  38. package/lib/DelegatedModule.js +34 -23
  39. package/lib/DelegatedModuleFactoryPlugin.js +27 -24
  40. package/lib/DelegatedPlugin.js +4 -2
  41. package/lib/DependenciesBlock.js +0 -2
  42. package/lib/Dependency.js +37 -19
  43. package/lib/DependencyTemplate.js +2 -0
  44. package/lib/DependencyTemplates.js +5 -6
  45. package/lib/DllEntryPlugin.js +8 -4
  46. package/lib/DllModule.js +11 -12
  47. package/lib/DllModuleFactory.js +2 -2
  48. package/lib/DllPlugin.js +9 -6
  49. package/lib/DllReferencePlugin.js +60 -65
  50. package/lib/DotenvPlugin.js +462 -0
  51. package/lib/DynamicEntryPlugin.js +8 -8
  52. package/lib/EntryOptionPlugin.js +8 -6
  53. package/lib/EntryPlugin.js +5 -3
  54. package/lib/Entrypoint.js +19 -0
  55. package/lib/EnvironmentNotSupportAsyncWarning.js +0 -3
  56. package/lib/EnvironmentPlugin.js +26 -19
  57. package/lib/ErrorHelpers.js +6 -6
  58. package/lib/EvalDevToolModulePlugin.js +17 -14
  59. package/lib/EvalSourceMapDevToolPlugin.js +156 -142
  60. package/lib/ExportsInfo.js +180 -115
  61. package/lib/ExportsInfoApiPlugin.js +2 -2
  62. package/lib/ExternalModule.js +256 -102
  63. package/lib/ExternalModuleFactoryPlugin.js +66 -29
  64. package/lib/ExternalsPlugin.js +57 -2
  65. package/lib/FileSystemInfo.js +313 -247
  66. package/lib/FlagAllModulesAsUsedPlugin.js +2 -2
  67. package/lib/FlagDependencyExportsPlugin.js +29 -19
  68. package/lib/FlagDependencyUsagePlugin.js +9 -10
  69. package/lib/FlagEntryExportAsUsedPlugin.js +1 -1
  70. package/lib/Generator.js +43 -10
  71. package/lib/GraphHelpers.js +11 -3
  72. package/lib/HookWebpackError.js +35 -7
  73. package/lib/HotModuleReplacementPlugin.js +149 -108
  74. package/lib/HotUpdateChunk.js +0 -3
  75. package/lib/IgnoreErrorModuleFactory.js +2 -2
  76. package/lib/IgnorePlugin.js +16 -13
  77. package/lib/IgnoreWarningsPlugin.js +6 -4
  78. package/lib/InitFragment.js +41 -23
  79. package/lib/InvalidDependenciesModuleWarning.js +2 -3
  80. package/lib/JavascriptMetaInfoPlugin.js +2 -4
  81. package/lib/LibManifestPlugin.js +12 -13
  82. package/lib/LoaderOptionsPlugin.js +12 -14
  83. package/lib/LoaderTargetPlugin.js +5 -3
  84. package/lib/MainTemplate.js +18 -29
  85. package/lib/ManifestPlugin.js +235 -0
  86. package/lib/Module.js +138 -60
  87. package/lib/ModuleBuildError.js +4 -2
  88. package/lib/ModuleDependencyError.js +4 -3
  89. package/lib/ModuleDependencyWarning.js +4 -3
  90. package/lib/ModuleError.js +1 -1
  91. package/lib/ModuleFactory.js +10 -3
  92. package/lib/ModuleFilenameHelpers.js +63 -60
  93. package/lib/ModuleGraph.js +195 -70
  94. package/lib/ModuleGraphConnection.js +14 -20
  95. package/lib/ModuleInfoHeaderPlugin.js +15 -16
  96. package/lib/ModuleNotFoundError.js +1 -1
  97. package/lib/ModuleParseError.js +8 -4
  98. package/lib/ModuleSourceTypeConstants.js +189 -0
  99. package/lib/ModuleTemplate.js +7 -8
  100. package/lib/ModuleTypeConstants.js +37 -15
  101. package/lib/ModuleWarning.js +1 -1
  102. package/lib/MultiCompiler.js +64 -49
  103. package/lib/MultiStats.js +19 -14
  104. package/lib/MultiWatching.js +7 -11
  105. package/lib/NoEmitOnErrorsPlugin.js +5 -3
  106. package/lib/NodeStuffPlugin.js +438 -126
  107. package/lib/NormalModule.js +322 -201
  108. package/lib/NormalModuleFactory.js +230 -117
  109. package/lib/NormalModuleReplacementPlugin.js +37 -39
  110. package/lib/NullFactory.js +3 -2
  111. package/lib/OptimizationStages.js +1 -1
  112. package/lib/OptionsApply.js +1 -1
  113. package/lib/Parser.js +5 -3
  114. package/lib/PlatformPlugin.js +3 -1
  115. package/lib/PrefetchPlugin.js +6 -4
  116. package/lib/ProgressPlugin.js +48 -49
  117. package/lib/ProvidePlugin.js +7 -5
  118. package/lib/RawModule.js +26 -12
  119. package/lib/RecordIdsPlugin.js +88 -110
  120. package/lib/RequestShortener.js +3 -1
  121. package/lib/ResolverFactory.js +15 -14
  122. package/lib/RuntimeGlobals.js +216 -153
  123. package/lib/RuntimeModule.js +7 -6
  124. package/lib/RuntimePlugin.js +115 -62
  125. package/lib/RuntimeTemplate.js +248 -76
  126. package/lib/SelfModuleFactory.js +2 -2
  127. package/lib/SizeFormatHelpers.js +2 -2
  128. package/lib/SourceMapDevToolModuleOptionsPlugin.js +17 -27
  129. package/lib/SourceMapDevToolPlugin.js +72 -59
  130. package/lib/Stats.js +2 -3
  131. package/lib/Template.js +31 -24
  132. package/lib/TemplatedPathPlugin.js +24 -21
  133. package/lib/UseStrictPlugin.js +1 -1
  134. package/lib/WarnCaseSensitiveModulesPlugin.js +36 -37
  135. package/lib/WarnDeprecatedOptionPlugin.js +7 -8
  136. package/lib/WarnNoModeSetPlugin.js +3 -1
  137. package/lib/WatchIgnorePlugin.js +11 -9
  138. package/lib/Watching.js +27 -29
  139. package/lib/WebpackError.js +10 -3
  140. package/lib/WebpackIsIncludedPlugin.js +4 -5
  141. package/lib/WebpackOptionsApply.js +263 -135
  142. package/lib/asset/AssetBytesGenerator.js +171 -0
  143. package/lib/asset/AssetBytesParser.js +37 -0
  144. package/lib/asset/AssetGenerator.js +285 -223
  145. package/lib/asset/AssetModulesPlugin.js +103 -41
  146. package/lib/asset/AssetParser.js +7 -3
  147. package/lib/asset/AssetSourceGenerator.js +41 -17
  148. package/lib/asset/RawDataUrlModule.js +17 -9
  149. package/lib/async-modules/AsyncModuleHelpers.js +52 -0
  150. package/lib/async-modules/AwaitDependenciesInitFragment.js +39 -24
  151. package/lib/async-modules/InferAsyncModulesPlugin.js +25 -26
  152. package/lib/buildChunkGraph.js +36 -17
  153. package/lib/cache/AddBuildDependenciesPlugin.js +5 -6
  154. package/lib/cache/IdleFileCachePlugin.js +22 -20
  155. package/lib/cache/MemoryCachePlugin.js +3 -3
  156. package/lib/cache/MemoryWithGcCachePlugin.js +17 -11
  157. package/lib/cache/PackFileCacheStrategy.js +198 -170
  158. package/lib/cache/ResolverCachePlugin.js +58 -48
  159. package/lib/cache/getLazyHashedEtag.js +5 -4
  160. package/lib/cli.js +197 -39
  161. package/lib/config/browserslistTargetHandler.js +110 -85
  162. package/lib/config/defaults.js +514 -113
  163. package/lib/config/normalization.js +91 -64
  164. package/lib/config/target.js +30 -18
  165. package/lib/container/ContainerEntryDependency.js +0 -1
  166. package/lib/container/ContainerEntryModule.js +16 -15
  167. package/lib/container/ContainerEntryModuleFactory.js +2 -2
  168. package/lib/container/ContainerPlugin.js +5 -6
  169. package/lib/container/ContainerReferencePlugin.js +27 -30
  170. package/lib/container/FallbackDependency.js +2 -1
  171. package/lib/container/FallbackModule.js +19 -14
  172. package/lib/container/FallbackModuleFactory.js +2 -2
  173. package/lib/container/HoistContainerReferencesPlugin.js +7 -7
  174. package/lib/container/ModuleFederationPlugin.js +4 -4
  175. package/lib/container/RemoteModule.js +14 -14
  176. package/lib/container/RemoteRuntimeModule.js +2 -2
  177. package/lib/container/options.js +9 -9
  178. package/lib/css/CssGenerator.js +366 -74
  179. package/lib/css/CssLoadingRuntimeModule.js +26 -16
  180. package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
  181. package/lib/css/CssModulesPlugin.js +191 -142
  182. package/lib/css/CssParser.js +1756 -740
  183. package/lib/css/walkCssTokens.js +180 -67
  184. package/lib/debug/ProfilingPlugin.js +135 -51
  185. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +29 -28
  186. package/lib/dependencies/AMDPlugin.js +18 -11
  187. package/lib/dependencies/AMDRequireArrayDependency.js +5 -4
  188. package/lib/dependencies/AMDRequireContextDependency.js +2 -1
  189. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +35 -26
  190. package/lib/dependencies/AMDRuntimeModules.js +3 -1
  191. package/lib/dependencies/CachedConstDependency.js +24 -18
  192. package/lib/dependencies/CommonJsExportRequireDependency.js +31 -24
  193. package/lib/dependencies/CommonJsExportsDependency.js +2 -1
  194. package/lib/dependencies/CommonJsExportsParserPlugin.js +50 -36
  195. package/lib/dependencies/CommonJsFullRequireDependency.js +7 -13
  196. package/lib/dependencies/CommonJsImportsParserPlugin.js +146 -127
  197. package/lib/dependencies/CommonJsPlugin.js +29 -18
  198. package/lib/dependencies/CommonJsRequireContextDependency.js +4 -3
  199. package/lib/dependencies/CommonJsSelfReferenceDependency.js +4 -4
  200. package/lib/dependencies/ConstDependency.js +2 -2
  201. package/lib/dependencies/ContextDependency.js +10 -5
  202. package/lib/dependencies/ContextDependencyHelpers.js +21 -13
  203. package/lib/dependencies/ContextDependencyTemplateAsId.js +10 -9
  204. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +13 -10
  205. package/lib/dependencies/ContextElementDependency.js +23 -12
  206. package/lib/dependencies/CssIcssExportDependency.js +402 -22
  207. package/lib/dependencies/CssIcssImportDependency.js +116 -51
  208. package/lib/dependencies/CssIcssSymbolDependency.js +33 -35
  209. package/lib/dependencies/CssImportDependency.js +17 -14
  210. package/lib/dependencies/CssUrlDependency.js +8 -13
  211. package/lib/dependencies/DynamicExports.js +19 -19
  212. package/lib/dependencies/ExportsInfoDependency.js +13 -10
  213. package/lib/dependencies/ExternalModuleDependency.js +7 -7
  214. package/lib/dependencies/ExternalModuleInitFragment.js +3 -2
  215. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +96 -0
  216. package/lib/dependencies/HarmonyAcceptDependency.js +96 -5
  217. package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -5
  218. package/lib/dependencies/HarmonyCompatibilityDependency.js +0 -1
  219. package/lib/dependencies/HarmonyDetectionParserPlugin.js +10 -30
  220. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +19 -8
  221. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +136 -99
  222. package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
  223. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +152 -61
  224. package/lib/dependencies/HarmonyExportInitFragment.js +2 -2
  225. package/lib/dependencies/HarmonyExportSpecifierDependency.js +2 -2
  226. package/lib/dependencies/HarmonyExports.js +5 -5
  227. package/lib/dependencies/HarmonyImportDependency.js +92 -45
  228. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +201 -163
  229. package/lib/dependencies/HarmonyImportSideEffectDependency.js +5 -6
  230. package/lib/dependencies/HarmonyImportSpecifierDependency.js +69 -42
  231. package/lib/dependencies/HarmonyModulesPlugin.js +16 -11
  232. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -15
  233. package/lib/dependencies/ImportContextDependency.js +15 -1
  234. package/lib/dependencies/ImportDependency.js +25 -7
  235. package/lib/dependencies/ImportEagerDependency.js +7 -5
  236. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +23 -13
  237. package/lib/dependencies/ImportMetaContextPlugin.js +2 -2
  238. package/lib/dependencies/ImportMetaPlugin.js +172 -20
  239. package/lib/dependencies/ImportParserPlugin.js +327 -49
  240. package/lib/dependencies/ImportPhase.js +121 -0
  241. package/lib/dependencies/ImportPlugin.js +3 -1
  242. package/lib/dependencies/ImportWeakDependency.js +7 -5
  243. package/lib/dependencies/JsonExportsDependency.js +54 -28
  244. package/lib/dependencies/LoaderDependency.js +0 -3
  245. package/lib/dependencies/LoaderImportDependency.js +0 -3
  246. package/lib/dependencies/LoaderPlugin.js +24 -25
  247. package/lib/dependencies/LocalModulesHelpers.js +4 -4
  248. package/lib/dependencies/ModuleDecoratorDependency.js +2 -4
  249. package/lib/dependencies/ModuleDependency.js +14 -13
  250. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
  251. package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
  252. package/lib/dependencies/NullDependency.js +2 -0
  253. package/lib/dependencies/ProvidedDependency.js +8 -10
  254. package/lib/dependencies/PureExpressionDependency.js +1 -2
  255. package/lib/dependencies/RequireContextDependency.js +2 -1
  256. package/lib/dependencies/RequireContextDependencyParserPlugin.js +47 -44
  257. package/lib/dependencies/RequireContextPlugin.js +5 -2
  258. package/lib/dependencies/RequireEnsureDependenciesBlock.js +3 -3
  259. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +101 -99
  260. package/lib/dependencies/RequireEnsurePlugin.js +6 -6
  261. package/lib/dependencies/RequireIncludeDependency.js +2 -2
  262. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +33 -34
  263. package/lib/dependencies/RequireIncludePlugin.js +1 -0
  264. package/lib/dependencies/RequireResolveContextDependency.js +1 -1
  265. package/lib/dependencies/RequireResolveDependency.js +3 -3
  266. package/lib/dependencies/RuntimeRequirementsDependency.js +3 -4
  267. package/lib/dependencies/StaticExportsDependency.js +3 -5
  268. package/lib/dependencies/SystemPlugin.js +4 -4
  269. package/lib/dependencies/URLContextDependency.js +65 -0
  270. package/lib/dependencies/URLDependency.js +3 -8
  271. package/lib/dependencies/URLPlugin.js +18 -159
  272. package/lib/dependencies/WebAssemblyExportImportedDependency.js +3 -3
  273. package/lib/dependencies/WebAssemblyImportDependency.js +2 -2
  274. package/lib/dependencies/WebpackIsIncludedDependency.js +2 -3
  275. package/lib/dependencies/WorkerDependency.js +8 -6
  276. package/lib/dependencies/WorkerPlugin.js +131 -67
  277. package/lib/dependencies/getFunctionExpression.js +2 -2
  278. package/lib/dependencies/processExportInfo.js +4 -4
  279. package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -1
  280. package/lib/esm/ModuleChunkFormatPlugin.js +232 -179
  281. package/lib/esm/ModuleChunkLoadingPlugin.js +112 -57
  282. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +102 -28
  283. package/lib/formatLocation.js +2 -2
  284. package/lib/hmr/HotModuleReplacement.runtime.js +41 -29
  285. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  286. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +43 -33
  287. package/lib/hmr/JavascriptHotModuleReplacementHelper.js +37 -0
  288. package/lib/hmr/LazyCompilationPlugin.js +67 -54
  289. package/lib/hmr/lazyCompilationBackend.js +23 -18
  290. package/lib/ids/ChunkModuleIdRangePlugin.js +14 -11
  291. package/lib/ids/DeterministicChunkIdsPlugin.js +32 -37
  292. package/lib/ids/DeterministicModuleIdsPlugin.js +52 -52
  293. package/lib/ids/HashedModuleIdsPlugin.js +15 -13
  294. package/lib/ids/IdHelpers.js +66 -49
  295. package/lib/ids/NamedChunkIdsPlugin.js +14 -17
  296. package/lib/ids/NamedModuleIdsPlugin.js +12 -14
  297. package/lib/ids/NaturalChunkIdsPlugin.js +6 -4
  298. package/lib/ids/NaturalModuleIdsPlugin.js +4 -3
  299. package/lib/ids/OccurrenceChunkIdsPlugin.js +7 -5
  300. package/lib/ids/OccurrenceModuleIdsPlugin.js +8 -7
  301. package/lib/ids/SyncModuleIdsPlugin.js +18 -13
  302. package/lib/index.js +54 -14
  303. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +116 -119
  304. package/lib/javascript/BasicEvaluatedExpression.js +26 -18
  305. package/lib/javascript/ChunkFormatHelpers.js +70 -0
  306. package/lib/javascript/ChunkHelpers.js +17 -5
  307. package/lib/javascript/CommonJsChunkFormatPlugin.js +114 -141
  308. package/lib/javascript/EnableChunkLoadingPlugin.js +7 -4
  309. package/lib/javascript/JavascriptGenerator.js +122 -100
  310. package/lib/javascript/JavascriptModulesPlugin.js +332 -152
  311. package/lib/javascript/JavascriptParser.js +1488 -1052
  312. package/lib/javascript/JavascriptParserHelpers.js +48 -47
  313. package/lib/javascript/StartupHelpers.js +23 -22
  314. package/lib/json/JsonData.js +4 -4
  315. package/lib/json/JsonGenerator.js +66 -32
  316. package/lib/json/JsonModulesPlugin.js +16 -6
  317. package/lib/json/JsonParser.js +23 -8
  318. package/lib/library/AbstractLibraryPlugin.js +45 -10
  319. package/lib/library/AmdLibraryPlugin.js +7 -5
  320. package/lib/library/AssignLibraryPlugin.js +71 -17
  321. package/lib/library/EnableLibraryPlugin.js +51 -25
  322. package/lib/library/ExportPropertyLibraryPlugin.js +12 -18
  323. package/lib/library/JsonpLibraryPlugin.js +5 -2
  324. package/lib/library/ModuleLibraryPlugin.js +230 -18
  325. package/lib/library/SystemLibraryPlugin.js +29 -11
  326. package/lib/library/UmdLibraryPlugin.js +35 -32
  327. package/lib/logging/Logger.js +18 -15
  328. package/lib/logging/createConsoleLogger.js +27 -27
  329. package/lib/logging/runtime.js +11 -11
  330. package/lib/logging/truncateArgs.js +5 -5
  331. package/lib/node/CommonJsChunkLoadingPlugin.js +72 -75
  332. package/lib/node/NodeEnvironmentPlugin.js +9 -3
  333. package/lib/node/NodeTargetPlugin.js +9 -1
  334. package/lib/node/NodeTemplatePlugin.js +2 -2
  335. package/lib/node/NodeWatchFileSystem.js +4 -4
  336. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -38
  337. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +10 -11
  338. package/lib/node/ReadFileCompileWasmPlugin.js +11 -14
  339. package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -30
  340. package/lib/node/nodeConsole.js +12 -7
  341. package/lib/optimize/AggressiveMergingPlugin.js +46 -47
  342. package/lib/optimize/AggressiveSplittingPlugin.js +233 -238
  343. package/lib/optimize/ConcatenatedModule.js +620 -251
  344. package/lib/optimize/EnsureChunkConditionsPlugin.js +58 -58
  345. package/lib/optimize/FlagIncludedChunksPlugin.js +93 -96
  346. package/lib/optimize/InnerGraph.js +139 -124
  347. package/lib/optimize/InnerGraphPlugin.js +29 -24
  348. package/lib/optimize/LimitChunkCountPlugin.js +32 -8
  349. package/lib/optimize/MangleExportsPlugin.js +22 -22
  350. package/lib/optimize/MergeDuplicateChunksPlugin.js +80 -81
  351. package/lib/optimize/MinChunkSizePlugin.js +12 -7
  352. package/lib/optimize/ModuleConcatenationPlugin.js +92 -71
  353. package/lib/optimize/RealContentHashPlugin.js +58 -44
  354. package/lib/optimize/RemoveEmptyChunksPlugin.js +8 -5
  355. package/lib/optimize/RemoveParentModulesPlugin.js +7 -4
  356. package/lib/optimize/RuntimeChunkPlugin.js +22 -25
  357. package/lib/optimize/SideEffectsFlagPlugin.js +44 -26
  358. package/lib/optimize/SplitChunksPlugin.js +209 -158
  359. package/lib/performance/AssetsOverSizeLimitWarning.js +1 -1
  360. package/lib/performance/EntrypointsOverSizeLimitWarning.js +2 -2
  361. package/lib/performance/SizeLimitsPlugin.js +8 -5
  362. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +5 -7
  363. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +61 -64
  364. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +3 -4
  365. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +2 -2
  366. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +2 -2
  367. package/lib/rules/BasicEffectRulePlugin.js +14 -5
  368. package/lib/rules/BasicMatcherRulePlugin.js +18 -7
  369. package/lib/rules/ObjectMatcherRulePlugin.js +17 -6
  370. package/lib/rules/RuleSetCompiler.js +73 -32
  371. package/lib/rules/UseEffectRulePlugin.js +61 -25
  372. package/lib/runtime/AsyncModuleRuntimeModule.js +74 -9
  373. package/lib/runtime/AutoPublicPathRuntimeModule.js +9 -4
  374. package/lib/runtime/BaseUriRuntimeModule.js +2 -2
  375. package/lib/runtime/CompatRuntimeModule.js +0 -1
  376. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +1 -1
  377. package/lib/runtime/GetChunkFilenameRuntimeModule.js +34 -35
  378. package/lib/runtime/GetMainFilenameRuntimeModule.js +1 -1
  379. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
  380. package/lib/runtime/LoadScriptRuntimeModule.js +0 -2
  381. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +248 -0
  382. package/lib/runtime/PublicPathRuntimeModule.js +2 -2
  383. package/lib/runtime/RuntimeIdRuntimeModule.js +2 -1
  384. package/lib/runtime/StartupChunkDependenciesPlugin.js +39 -42
  385. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +10 -9
  386. package/lib/runtime/StartupEntrypointRuntimeModule.js +0 -1
  387. package/lib/runtime/SystemContextRuntimeModule.js +0 -2
  388. package/lib/runtime/ToBinaryRuntimeModule.js +64 -0
  389. package/lib/schemes/DataUriPlugin.js +9 -31
  390. package/lib/schemes/FileUriPlugin.js +11 -6
  391. package/lib/schemes/HttpUriPlugin.js +381 -261
  392. package/lib/schemes/VirtualUrlPlugin.js +222 -0
  393. package/lib/serialization/AggregateErrorSerializer.js +41 -0
  394. package/lib/serialization/BinaryMiddleware.js +51 -33
  395. package/lib/serialization/ErrorObjectSerializer.js +7 -2
  396. package/lib/serialization/FileMiddleware.js +101 -71
  397. package/lib/serialization/NullPrototypeObjectSerializer.js +5 -3
  398. package/lib/serialization/ObjectMiddleware.js +130 -54
  399. package/lib/serialization/PlainObjectSerializer.js +1 -1
  400. package/lib/serialization/Serializer.js +38 -20
  401. package/lib/serialization/SerializerMiddleware.js +121 -49
  402. package/lib/serialization/SingleItemMiddleware.js +9 -7
  403. package/lib/serialization/types.js +1 -1
  404. package/lib/sharing/ConsumeSharedModule.js +9 -9
  405. package/lib/sharing/ConsumeSharedPlugin.js +14 -14
  406. package/lib/sharing/ConsumeSharedRuntimeModule.js +11 -8
  407. package/lib/sharing/ProvideSharedModule.js +9 -11
  408. package/lib/sharing/ProvideSharedModuleFactory.js +5 -3
  409. package/lib/sharing/ProvideSharedPlugin.js +15 -10
  410. package/lib/sharing/SharePlugin.js +3 -4
  411. package/lib/sharing/ShareRuntimeModule.js +7 -6
  412. package/lib/sharing/resolveMatchedConfigs.js +27 -13
  413. package/lib/sharing/utils.js +37 -43
  414. package/lib/stats/DefaultStatsFactoryPlugin.js +455 -286
  415. package/lib/stats/DefaultStatsPresetPlugin.js +77 -46
  416. package/lib/stats/DefaultStatsPrinterPlugin.js +583 -419
  417. package/lib/stats/StatsFactory.js +75 -32
  418. package/lib/stats/StatsPrinter.js +71 -51
  419. package/lib/url/URLParserPlugin.js +264 -0
  420. package/lib/util/ArrayHelpers.js +6 -8
  421. package/lib/util/ArrayQueue.js +1 -1
  422. package/lib/util/AsyncQueue.js +11 -10
  423. package/lib/util/Hash.js +37 -5
  424. package/lib/util/IterableHelpers.js +4 -4
  425. package/lib/util/LazyBucketSortedSet.js +46 -27
  426. package/lib/util/LazySet.js +16 -10
  427. package/lib/util/MapHelpers.js +1 -1
  428. package/lib/util/ParallelismFactorCalculator.js +2 -2
  429. package/lib/util/Semaphore.js +3 -3
  430. package/lib/util/SetHelpers.js +6 -6
  431. package/lib/util/SortableSet.js +11 -9
  432. package/lib/util/StackedCacheMap.js +2 -2
  433. package/lib/util/StackedMap.js +3 -3
  434. package/lib/util/StringXor.js +2 -1
  435. package/lib/util/TupleQueue.js +11 -8
  436. package/lib/util/TupleSet.js +44 -19
  437. package/lib/util/URLAbsoluteSpecifier.js +3 -4
  438. package/lib/util/WeakTupleMap.js +56 -42
  439. package/lib/util/binarySearchBounds.js +4 -3
  440. package/lib/util/chainedImports.js +3 -1
  441. package/lib/util/cleverMerge.js +171 -107
  442. package/lib/util/comparators.js +265 -162
  443. package/lib/util/compileBooleanMatcher.js +120 -41
  444. package/lib/util/concatenate.js +20 -16
  445. package/lib/util/conventions.js +73 -74
  446. package/lib/util/create-schema-validation.js +8 -8
  447. package/lib/util/createHash.js +32 -135
  448. package/lib/util/dataURL.js +39 -0
  449. package/lib/util/deprecation.js +119 -116
  450. package/lib/util/deterministicGrouping.js +56 -47
  451. package/lib/util/extractSourceMap.js +319 -0
  452. package/lib/util/extractUrlAndGlobal.js +1 -1
  453. package/lib/util/findGraphRoots.js +19 -9
  454. package/lib/util/fs.js +169 -141
  455. package/lib/util/hash/BatchedHash.js +50 -10
  456. package/lib/util/hash/BulkUpdateHash.js +138 -0
  457. package/lib/util/hash/DebugHash.js +75 -0
  458. package/lib/util/hash/hash-digest.js +216 -0
  459. package/lib/util/hash/md4.js +2 -2
  460. package/lib/util/hash/wasm-hash.js +59 -17
  461. package/lib/util/identifier.js +124 -61
  462. package/lib/util/internalSerializables.js +4 -6
  463. package/lib/util/magicComment.js +9 -5
  464. package/lib/util/makeSerializable.js +2 -2
  465. package/lib/util/memoize.js +5 -2
  466. package/lib/util/objectToMap.js +3 -2
  467. package/lib/util/processAsyncTree.js +5 -5
  468. package/lib/util/propertyAccess.js +1 -1
  469. package/lib/util/propertyName.js +2 -3
  470. package/lib/util/registerExternalSerializer.js +16 -20
  471. package/lib/util/removeBOM.js +25 -0
  472. package/lib/util/runtime.js +72 -56
  473. package/lib/util/semver.js +44 -33
  474. package/lib/util/serialization.js +56 -56
  475. package/lib/util/smartGrouping.js +42 -27
  476. package/lib/util/source.js +5 -4
  477. package/lib/util/traverseDestructuringAssignmentProperties.js +45 -0
  478. package/lib/validateSchema.js +7 -9
  479. package/lib/wasm/EnableWasmLoadingPlugin.js +22 -12
  480. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +9 -5
  481. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +15 -3
  482. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +28 -22
  483. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +47 -57
  484. package/lib/wasm-async/AsyncWebAssemblyParser.js +2 -10
  485. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +8 -4
  486. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +23 -17
  487. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +55 -57
  488. package/lib/wasm-sync/WebAssemblyGenerator.js +56 -41
  489. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +6 -3
  490. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +25 -10
  491. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +11 -12
  492. package/lib/wasm-sync/WebAssemblyParser.js +10 -17
  493. package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
  494. package/lib/web/FetchCompileAsyncWasmPlugin.js +4 -4
  495. package/lib/web/FetchCompileWasmPlugin.js +6 -8
  496. package/lib/web/JsonpChunkLoadingPlugin.js +74 -74
  497. package/lib/web/JsonpChunkLoadingRuntimeModule.js +10 -26
  498. package/lib/web/JsonpTemplatePlugin.js +0 -1
  499. package/lib/webpack.js +107 -87
  500. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +79 -75
  501. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +38 -51
  502. package/lib/webworker/WebWorkerTemplatePlugin.js +1 -0
  503. package/module.d.ts +5 -0
  504. package/package.json +149 -129
  505. package/schemas/WebpackOptions.check.d.ts +1 -1
  506. package/schemas/WebpackOptions.check.js +2 -2
  507. package/schemas/WebpackOptions.json +543 -190
  508. package/schemas/plugins/BannerPlugin.check.d.ts +1 -1
  509. package/schemas/plugins/BannerPlugin.check.js +2 -2
  510. package/schemas/plugins/BannerPlugin.json +4 -0
  511. package/schemas/plugins/DllPlugin.check.d.ts +1 -1
  512. package/schemas/plugins/DllPlugin.check.js +1 -1
  513. package/schemas/plugins/DllReferencePlugin.check.d.ts +1 -1
  514. package/schemas/plugins/DllReferencePlugin.check.js +1 -1
  515. package/schemas/plugins/IgnorePlugin.check.d.ts +1 -1
  516. package/schemas/plugins/IgnorePlugin.check.js +1 -1
  517. package/schemas/plugins/IgnorePlugin.json +1 -1
  518. package/schemas/plugins/LoaderOptionsPlugin.check.d.ts +1 -1
  519. package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
  520. package/schemas/plugins/{HashedModuleIdsPlugin.check.d.ts → ManifestPlugin.check.d.ts} +2 -2
  521. package/schemas/plugins/ManifestPlugin.check.js +6 -0
  522. package/schemas/plugins/ManifestPlugin.json +98 -0
  523. package/schemas/plugins/ProgressPlugin.check.d.ts +1 -1
  524. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  525. package/schemas/plugins/ProgressPlugin.json +1 -1
  526. package/schemas/plugins/SourceMapDevToolPlugin.check.d.ts +1 -1
  527. package/schemas/plugins/SourceMapDevToolPlugin.check.js +2 -2
  528. package/schemas/plugins/SourceMapDevToolPlugin.json +23 -6
  529. package/schemas/plugins/WatchIgnorePlugin.check.d.ts +1 -1
  530. package/schemas/plugins/WatchIgnorePlugin.check.js +1 -1
  531. package/schemas/plugins/asset/AssetGeneratorOptions.check.d.ts +1 -1
  532. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  533. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.d.ts +1 -1
  534. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +1 -1
  535. package/schemas/plugins/asset/AssetParserOptions.check.d.ts +1 -1
  536. package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
  537. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.d.ts +1 -1
  538. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  539. package/schemas/plugins/container/ContainerPlugin.check.d.ts +1 -1
  540. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  541. package/schemas/plugins/container/ContainerReferencePlugin.check.d.ts +1 -1
  542. package/schemas/plugins/container/ContainerReferencePlugin.check.js +2 -2
  543. package/schemas/plugins/container/ContainerReferencePlugin.json +4 -1
  544. package/schemas/plugins/container/ExternalsType.check.d.ts +1 -1
  545. package/schemas/plugins/container/ExternalsType.check.js +2 -2
  546. package/schemas/plugins/container/ModuleFederationPlugin.check.d.ts +1 -1
  547. package/schemas/plugins/container/ModuleFederationPlugin.check.js +2 -2
  548. package/schemas/plugins/container/ModuleFederationPlugin.json +4 -1
  549. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +1 -1
  550. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  551. package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +1 -1
  552. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +2 -2
  553. package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +1 -1
  554. package/schemas/plugins/css/CssModuleParserOptions.check.js +2 -2
  555. package/schemas/plugins/css/CssParserOptions.check.d.ts +1 -1
  556. package/schemas/plugins/css/CssParserOptions.check.js +2 -2
  557. package/schemas/plugins/debug/ProfilingPlugin.check.d.ts +1 -1
  558. package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
  559. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.d.ts +7 -0
  560. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +6 -0
  561. package/schemas/plugins/{HashedModuleIdsPlugin.json → ids/HashedModuleIdsPlugin.json} +15 -2
  562. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.d.ts +1 -1
  563. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +1 -1
  564. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.d.ts +1 -1
  565. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +1 -1
  566. package/schemas/plugins/{css/CssGlobalParserOptions.check.d.ts → json/JsonModulesPluginGenerator.check.d.ts} +1 -1
  567. package/schemas/plugins/json/JsonModulesPluginGenerator.check.js +6 -0
  568. package/schemas/plugins/json/JsonModulesPluginGenerator.json +3 -0
  569. package/schemas/plugins/{css/CssGlobalGeneratorOptions.check.d.ts → json/JsonModulesPluginParser.check.d.ts} +1 -1
  570. package/schemas/plugins/json/JsonModulesPluginParser.check.js +6 -0
  571. package/schemas/plugins/json/JsonModulesPluginParser.json +3 -0
  572. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.d.ts +1 -1
  573. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
  574. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.d.ts +1 -1
  575. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
  576. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.d.ts +1 -1
  577. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +1 -1
  578. package/schemas/plugins/optimize/MinChunkSizePlugin.check.d.ts +1 -1
  579. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
  580. package/schemas/plugins/schemes/HttpUriPlugin.check.d.ts +1 -1
  581. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  582. package/schemas/plugins/schemes/VirtualUrlPlugin.check.d.ts +7 -0
  583. package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +6 -0
  584. package/schemas/plugins/schemes/VirtualUrlPlugin.json +77 -0
  585. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.d.ts +1 -1
  586. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +1 -1
  587. package/schemas/plugins/sharing/ProvideSharedPlugin.check.d.ts +1 -1
  588. package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +1 -1
  589. package/schemas/plugins/sharing/SharePlugin.check.d.ts +1 -1
  590. package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
  591. package/types.d.ts +5115 -1863
  592. package/SECURITY.md +0 -9
  593. package/lib/ModuleSourceTypesConstants.js +0 -112
  594. package/lib/dependencies/CssLocalIdentifierDependency.js +0 -250
  595. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +0 -111
  596. package/lib/library/ModernModuleLibraryPlugin.js +0 -144
  597. package/schemas/plugins/HashedModuleIdsPlugin.check.js +0 -6
  598. package/schemas/plugins/JsonModulesPluginParser.check.d.ts +0 -7
  599. package/schemas/plugins/JsonModulesPluginParser.check.js +0 -6
  600. package/schemas/plugins/JsonModulesPluginParser.json +0 -12
  601. package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +0 -7
  602. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +0 -6
  603. package/schemas/plugins/css/CssAutoGeneratorOptions.json +0 -3
  604. package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +0 -7
  605. package/schemas/plugins/css/CssAutoParserOptions.check.js +0 -6
  606. package/schemas/plugins/css/CssAutoParserOptions.json +0 -3
  607. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +0 -6
  608. package/schemas/plugins/css/CssGlobalGeneratorOptions.json +0 -3
  609. package/schemas/plugins/css/CssGlobalParserOptions.check.js +0 -6
  610. package/schemas/plugins/css/CssGlobalParserOptions.json +0 -3
@@ -14,51 +14,59 @@ const AggressiveSplittingPlugin = require("../optimize/AggressiveSplittingPlugin
14
14
  const SizeLimitsPlugin = require("../performance/SizeLimitsPlugin");
15
15
  const { countIterable } = require("../util/IterableHelpers");
16
16
  const {
17
- compareLocations,
18
17
  compareChunksById,
19
- compareNumbers,
20
18
  compareIds,
21
- concatComparators,
19
+ compareLocations,
20
+ compareModulesByIdentifier,
21
+ compareNumbers,
22
22
  compareSelect,
23
- compareModulesByIdentifier
23
+ concatComparators
24
24
  } = require("../util/comparators");
25
25
  const { makePathsRelative, parseResource } = require("../util/identifier");
26
26
 
27
27
  /** @typedef {import("webpack-sources").Source} Source */
28
+ /** @typedef {import("../../declarations/WebpackOptions").StatsValue} StatsValue */
29
+ /** @typedef {import("./StatsFactory")} StatsFactory */
30
+ /** @typedef {import("./StatsFactory").StatsFactoryContext} StatsFactoryContext */
28
31
  /** @typedef {import("../Chunk")} Chunk */
29
32
  /** @typedef {import("../Chunk").ChunkId} ChunkId */
33
+ /** @typedef {import("../Chunk").ChunkName} ChunkName */
34
+ /** @typedef {import("../ChunkGraph").ModuleId} ModuleId */
30
35
  /** @typedef {import("../ChunkGroup")} ChunkGroup */
31
36
  /** @typedef {import("../ChunkGroup").OriginRecord} OriginRecord */
32
37
  /** @typedef {import("../Compilation")} Compilation */
33
38
  /** @typedef {import("../Compilation").Asset} Asset */
34
39
  /** @typedef {import("../Compilation").AssetInfo} AssetInfo */
40
+ /** @typedef {import("../Compilation").ExcludeModulesType} ExcludeModulesType */
41
+ /** @typedef {import("../Compilation").KnownNormalizedStatsOptions} KnownNormalizedStatsOptions */
35
42
  /** @typedef {import("../Compilation").NormalizedStatsOptions} NormalizedStatsOptions */
36
43
  /** @typedef {import("../Compiler")} Compiler */
37
- /** @typedef {import("../ChunkGraph").ModuleId} ModuleId */
38
44
  /** @typedef {import("../Dependency")} Dependency */
39
45
  /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
40
46
  /** @typedef {import("../Module")} Module */
47
+ /** @typedef {import("../Module").NameForCondition} NameForCondition */
41
48
  /** @typedef {import("../Module").BuildInfo} BuildInfo */
42
49
  /** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
43
50
  /** @typedef {import("../ModuleProfile")} ModuleProfile */
44
- /** @typedef {import("../RequestShortener")} RequestShortener */
45
51
  /** @typedef {import("../WebpackError")} WebpackError */
46
- /** @typedef {import("../TemplatedPathPlugin").TemplatePath} TemplatePath */
52
+ /** @typedef {import("../serialization/AggregateErrorSerializer").AggregateError} AggregateError */
53
+ /** @typedef {import("../serialization/ErrorObjectSerializer").ErrorWithCause} ErrorWithCause */
54
+ /** @typedef {import("../ExportsInfo").ExportInfoName} ExportInfoName */
55
+
47
56
  /**
48
57
  * @template T
49
58
  * @typedef {import("../util/comparators").Comparator<T>} Comparator<T>
50
59
  */
51
- /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
60
+
52
61
  /**
53
- * @template T, R
54
- * @typedef {import("../util/smartGrouping").GroupConfig<T, R>} GroupConfig
62
+ * @template I, G
63
+ * @typedef {import("../util/smartGrouping").GroupConfig<I, G>} GroupConfig
55
64
  */
56
- /** @typedef {import("./StatsFactory")} StatsFactory */
57
- /** @typedef {import("./StatsFactory").StatsFactoryContext} StatsFactoryContext */
58
- /** @typedef {Record<string, EXPECTED_ANY> & KnownStatsCompilation} StatsCompilation */
65
+
66
+ /** @typedef {KnownStatsCompilation & Record<string, EXPECTED_ANY>} StatsCompilation */
59
67
  /**
60
68
  * @typedef {object} KnownStatsCompilation
61
- * @property {any=} env
69
+ * @property {EXPECTED_ANY=} env
62
70
  * @property {string=} name
63
71
  * @property {string=} hash
64
72
  * @property {string=} version
@@ -81,9 +89,11 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
81
89
  * @property {number=} warningsCount
82
90
  * @property {StatsCompilation[]=} children
83
91
  * @property {Record<string, StatsLogging>=} logging
92
+ * @property {number=} filteredWarningDetailsCount
93
+ * @property {number=} filteredErrorDetailsCount
84
94
  */
85
95
 
86
- /** @typedef {Record<string, EXPECTED_ANY> & KnownStatsLogging} StatsLogging */
96
+ /** @typedef {KnownStatsLogging & Record<string, EXPECTED_ANY>} StatsLogging */
87
97
  /**
88
98
  * @typedef {object} KnownStatsLogging
89
99
  * @property {StatsLoggingEntry[]} entries
@@ -91,18 +101,19 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
91
101
  * @property {boolean} debug
92
102
  */
93
103
 
94
- /** @typedef {Record<string, EXPECTED_ANY> & KnownStatsLoggingEntry} StatsLoggingEntry */
104
+ /** @typedef {KnownStatsLoggingEntry & Record<string, EXPECTED_ANY>} StatsLoggingEntry */
95
105
  /**
96
106
  * @typedef {object} KnownStatsLoggingEntry
97
107
  * @property {string} type
98
108
  * @property {string=} message
99
109
  * @property {string[]=} trace
100
110
  * @property {StatsLoggingEntry[]=} children
101
- * @property {any[]=} args
111
+ * @property {EXPECTED_ANY[]=} args
102
112
  * @property {number=} time
103
113
  */
104
114
 
105
- /** @typedef {Record<string, EXPECTED_ANY> & KnownStatsAsset} StatsAsset */
115
+ /** @typedef {KnownStatsAsset & Record<string, EXPECTED_ANY>} StatsAsset */
116
+ /** @typedef {string[]} ChunkIdHints */
106
117
  /**
107
118
  * @typedef {object} KnownStatsAsset
108
119
  * @property {string} type
@@ -113,33 +124,34 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
113
124
  * @property {boolean} comparedForEmit
114
125
  * @property {boolean} cached
115
126
  * @property {StatsAsset[]=} related
116
- * @property {(string|number)[]=} chunkNames
117
- * @property {(string|number)[]=} chunkIdHints
118
- * @property {(string|number)[]=} chunks
119
- * @property {(string|number)[]=} auxiliaryChunkNames
120
- * @property {(string|number)[]=} auxiliaryChunks
121
- * @property {(string|number)[]=} auxiliaryChunkIdHints
127
+ * @property {ChunkId[]=} chunks
128
+ * @property {ChunkName[]=} chunkNames
129
+ * @property {ChunkIdHints=} chunkIdHints
130
+ * @property {ChunkId[]=} auxiliaryChunks
131
+ * @property {ChunkName[]=} auxiliaryChunkNames
132
+ * @property {ChunkIdHints=} auxiliaryChunkIdHints
122
133
  * @property {number=} filteredRelated
123
134
  * @property {boolean=} isOverSizeLimit
124
135
  */
125
136
 
126
- /** @typedef {Record<string, EXPECTED_ANY> & KnownStatsChunkGroup} StatsChunkGroup */
137
+ /** @typedef {KnownStatsChunkGroup & Record<string, EXPECTED_ANY>} StatsChunkGroup */
127
138
  /**
128
139
  * @typedef {object} KnownStatsChunkGroup
129
- * @property {(string | null)=} name
130
- * @property {(string | number)[]=} chunks
140
+ * @property {ChunkName=} name
141
+ * @property {ChunkId[]=} chunks
131
142
  * @property {({ name: string, size?: number })[]=} assets
132
143
  * @property {number=} filteredAssets
133
144
  * @property {number=} assetsSize
134
145
  * @property {({ name: string, size?: number })[]=} auxiliaryAssets
135
146
  * @property {number=} filteredAuxiliaryAssets
136
147
  * @property {number=} auxiliaryAssetsSize
137
- * @property {{ [x: string]: StatsChunkGroup[] }=} children
138
- * @property {{ [x: string]: string[] }=} childAssets
148
+ * @property {Record<string, StatsChunkGroup[]>=} children
149
+ * @property {Record<string, string[]>=} childAssets
139
150
  * @property {boolean=} isOverSizeLimit
140
151
  */
141
152
 
142
- /** @typedef {Record<string, EXPECTED_ANY> & KnownStatsModule} StatsModule */
153
+ /** @typedef {Module[]} ModuleIssuerPath */
154
+ /** @typedef {KnownStatsModule & Record<string, EXPECTED_ANY>} StatsModule */
143
155
  /**
144
156
  * @typedef {object} KnownStatsModule
145
157
  * @property {string=} type
@@ -147,13 +159,13 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
147
159
  * @property {(string | null)=} layer
148
160
  * @property {string=} identifier
149
161
  * @property {string=} name
150
- * @property {(string | null)=} nameForCondition
162
+ * @property {NameForCondition | null=} nameForCondition
151
163
  * @property {number=} index
152
164
  * @property {number=} preOrderIndex
153
165
  * @property {number=} index2
154
166
  * @property {number=} postOrderIndex
155
167
  * @property {number=} size
156
- * @property {{ [x: string]: number }=} sizes
168
+ * @property {Record<string, number>=} sizes
157
169
  * @property {boolean=} cacheable
158
170
  * @property {boolean=} built
159
171
  * @property {boolean=} codeGenerated
@@ -161,21 +173,21 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
161
173
  * @property {boolean=} cached
162
174
  * @property {boolean=} optional
163
175
  * @property {boolean=} orphan
164
- * @property {string | number=} id
165
- * @property {string | number | null=} issuerId
166
- * @property {(string | number)[]=} chunks
167
- * @property {(string | number)[]=} assets
176
+ * @property {ModuleId=} id
177
+ * @property {ModuleId | null=} issuerId
178
+ * @property {ChunkId[]=} chunks
179
+ * @property {string[]=} assets
168
180
  * @property {boolean=} dependent
169
181
  * @property {(string | null)=} issuer
170
182
  * @property {(string | null)=} issuerName
171
- * @property {StatsModuleIssuer[]=} issuerPath
183
+ * @property {StatsModuleIssuer[] | null=} issuerPath
172
184
  * @property {boolean=} failed
173
185
  * @property {number=} errors
174
186
  * @property {number=} warnings
175
187
  * @property {StatsProfile=} profile
176
188
  * @property {StatsModuleReason[]=} reasons
177
- * @property {(boolean | null | string[])=} usedExports
178
- * @property {(string[] | null)=} providedExports
189
+ * @property {boolean | null | ExportInfoName[]=} usedExports
190
+ * @property {ExportInfoName[] | null=} providedExports
179
191
  * @property {string[]=} optimizationBailout
180
192
  * @property {(number | null)=} depth
181
193
  * @property {StatsModule[]=} modules
@@ -183,7 +195,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
183
195
  * @property {ReturnType<Source["source"]>=} source
184
196
  */
185
197
 
186
- /** @typedef {Record<string, EXPECTED_ANY> & KnownStatsProfile} StatsProfile */
198
+ /** @typedef {KnownStatsProfile & Record<string, EXPECTED_ANY>} StatsProfile */
187
199
  /**
188
200
  * @typedef {object} KnownStatsProfile
189
201
  * @property {number} total
@@ -198,16 +210,16 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
198
210
  * @property {number} dependencies
199
211
  */
200
212
 
201
- /** @typedef {Record<string, EXPECTED_ANY> & KnownStatsModuleIssuer} StatsModuleIssuer */
213
+ /** @typedef {KnownStatsModuleIssuer & Record<string, EXPECTED_ANY>} StatsModuleIssuer */
202
214
  /**
203
215
  * @typedef {object} KnownStatsModuleIssuer
204
216
  * @property {string} identifier
205
217
  * @property {string} name
206
- * @property {(string|number)=} id
218
+ * @property {ModuleId=} id
207
219
  * @property {StatsProfile} profile
208
220
  */
209
221
 
210
- /** @typedef {Record<string, EXPECTED_ANY> & KnownStatsModuleReason} StatsModuleReason */
222
+ /** @typedef {KnownStatsModuleReason & Record<string, EXPECTED_ANY>} StatsModuleReason */
211
223
  /**
212
224
  * @typedef {object} KnownStatsModuleReason
213
225
  * @property {string | null} moduleIdentifier
@@ -220,11 +232,11 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
220
232
  * @property {string | null} explanation
221
233
  * @property {string | null} userRequest
222
234
  * @property {(string | null)=} loc
223
- * @property {(string | number | null)=} moduleId
224
- * @property {(string | number | null)=} resolvedModuleId
235
+ * @property {ModuleId | null=} moduleId
236
+ * @property {ModuleId | null=} resolvedModuleId
225
237
  */
226
238
 
227
- /** @typedef {Record<string, EXPECTED_ANY> & KnownStatsChunk} StatsChunk */
239
+ /** @typedef {KnownStatsChunk & Record<string, EXPECTED_ANY>} StatsChunk */
228
240
  /**
229
241
  * @typedef {object} KnownStatsChunk
230
242
  * @property {boolean} rendered
@@ -240,17 +252,17 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
240
252
  * @property {string[]} files
241
253
  * @property {string[]} auxiliaryFiles
242
254
  * @property {string} hash
243
- * @property {Record<string, (string|number)[]>} childrenByOrder
244
- * @property {(string|number)=} id
245
- * @property {(string|number)[]=} siblings
246
- * @property {(string|number)[]=} parents
247
- * @property {(string|number)[]=} children
255
+ * @property {Record<string, ChunkId[]>} childrenByOrder
256
+ * @property {ChunkId=} id
257
+ * @property {ChunkId[]=} siblings
258
+ * @property {ChunkId[]=} parents
259
+ * @property {ChunkId[]=} children
248
260
  * @property {StatsModule[]=} modules
249
261
  * @property {number=} filteredModules
250
262
  * @property {StatsChunkOrigin[]=} origins
251
263
  */
252
264
 
253
- /** @typedef {Record<string, EXPECTED_ANY> & KnownStatsChunkOrigin} StatsChunkOrigin */
265
+ /** @typedef {KnownStatsChunkOrigin & Record<string, EXPECTED_ANY>} StatsChunkOrigin */
254
266
  /**
255
267
  * @typedef {object} KnownStatsChunkOrigin
256
268
  * @property {string} module
@@ -258,10 +270,10 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
258
270
  * @property {string} moduleName
259
271
  * @property {string} loc
260
272
  * @property {string} request
261
- * @property {(string | number)=} moduleId
273
+ * @property {ModuleId=} moduleId
262
274
  */
263
275
 
264
- /** @typedef { Record<string, EXPECTED_ANY> & KnownStatsModuleTraceItem} StatsModuleTraceItem */
276
+ /** @typedef {KnownStatsModuleTraceItem & Record<string, EXPECTED_ANY>} StatsModuleTraceItem */
265
277
  /**
266
278
  * @typedef {object} KnownStatsModuleTraceItem
267
279
  * @property {string=} originIdentifier
@@ -269,17 +281,17 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
269
281
  * @property {string=} moduleIdentifier
270
282
  * @property {string=} moduleName
271
283
  * @property {StatsModuleTraceDependency[]=} dependencies
272
- * @property {(string|number)=} originId
273
- * @property {(string|number)=} moduleId
284
+ * @property {ModuleId=} originId
285
+ * @property {ModuleId=} moduleId
274
286
  */
275
287
 
276
- /** @typedef {Record<string, EXPECTED_ANY> & KnownStatsModuleTraceDependency} StatsModuleTraceDependency */
288
+ /** @typedef {KnownStatsModuleTraceDependency & Record<string, EXPECTED_ANY>} StatsModuleTraceDependency */
277
289
  /**
278
290
  * @typedef {object} KnownStatsModuleTraceDependency
279
291
  * @property {string=} loc
280
292
  */
281
293
 
282
- /** @typedef {Record<string, EXPECTED_ANY> & KnownStatsError} StatsError */
294
+ /** @typedef {KnownStatsError & Record<string, EXPECTED_ANY>} StatsError */
283
295
  /**
284
296
  * @typedef {object} KnownStatsError
285
297
  * @property {string} message
@@ -291,10 +303,13 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
291
303
  * @property {string=} moduleName
292
304
  * @property {string=} loc
293
305
  * @property {ChunkId=} chunkId
294
- * @property {string|number=} moduleId
306
+ * @property {ModuleId=} moduleId
295
307
  * @property {StatsModuleTraceItem[]=} moduleTrace
296
- * @property {any=} details
308
+ * @property {string=} details
297
309
  * @property {string=} stack
310
+ * @property {KnownStatsError=} cause
311
+ * @property {KnownStatsError[]=} errors
312
+ * @property {string=} compilerPath
298
313
  */
299
314
 
300
315
  /** @typedef {Asset & { type: string, related: PreprocessedAsset[] | undefined }} PreprocessedAsset */
@@ -305,12 +320,15 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
305
320
  * @typedef {Record<string, (object: O, data: T, context: StatsFactoryContext, options: NormalizedStatsOptions, factory: StatsFactory) => void>} ExtractorsByOption
306
321
  */
307
322
 
323
+ /** @typedef {{ name: string, chunkGroup: ChunkGroup }} ChunkGroupInfoWithName */
324
+ /** @typedef {{ origin: Module, module: Module }} ModuleTrace */
325
+
308
326
  /**
309
327
  * @typedef {object} SimpleExtractors
310
328
  * @property {ExtractorsByOption<Compilation, StatsCompilation>} compilation
311
329
  * @property {ExtractorsByOption<PreprocessedAsset, StatsAsset>} asset
312
330
  * @property {ExtractorsByOption<PreprocessedAsset, StatsAsset>} asset$visible
313
- * @property {ExtractorsByOption<{ name: string, chunkGroup: ChunkGroup }, StatsChunkGroup>} chunkGroup
331
+ * @property {ExtractorsByOption<ChunkGroupInfoWithName, StatsChunkGroup>} chunkGroup
314
332
  * @property {ExtractorsByOption<Module, StatsModule>} module
315
333
  * @property {ExtractorsByOption<Module, StatsModule>} module$visible
316
334
  * @property {ExtractorsByOption<Module, StatsModuleIssuer>} moduleIssuer
@@ -320,7 +338,8 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
320
338
  * @property {ExtractorsByOption<OriginRecord, StatsChunkOrigin>} chunkOrigin
321
339
  * @property {ExtractorsByOption<WebpackError, StatsError>} error
322
340
  * @property {ExtractorsByOption<WebpackError, StatsError>} warning
323
- * @property {ExtractorsByOption<{ origin: Module, module: Module }, StatsModuleTraceItem>} moduleTraceItem
341
+ * @property {ExtractorsByOption<WebpackError, StatsError>} cause
342
+ * @property {ExtractorsByOption<ModuleTrace, StatsModuleTraceItem>} moduleTraceItem
324
343
  * @property {ExtractorsByOption<Dependency, StatsModuleTraceDependency>} moduleTraceDependency
325
344
  */
326
345
 
@@ -328,7 +347,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
328
347
  * @template T
329
348
  * @template I
330
349
  * @param {Iterable<T>} items items to select from
331
- * @param {function(T): Iterable<I>} selector selector function to select values from item
350
+ * @param {(item: T) => Iterable<I>} selector selector function to select values from item
332
351
  * @returns {I[]} array of values
333
352
  */
334
353
  const uniqueArray = (items, selector) => {
@@ -339,27 +358,31 @@ const uniqueArray = (items, selector) => {
339
358
  set.add(i);
340
359
  }
341
360
  }
342
- return Array.from(set);
361
+ return [...set];
343
362
  };
344
363
 
345
364
  /**
346
365
  * @template T
347
366
  * @template I
348
367
  * @param {Iterable<T>} items items to select from
349
- * @param {function(T): Iterable<I>} selector selector function to select values from item
368
+ * @param {(item: T) => Iterable<I>} selector selector function to select values from item
350
369
  * @param {Comparator<I>} comparator comparator function
351
370
  * @returns {I[]} array of values
352
371
  */
353
372
  const uniqueOrderedArray = (items, selector, comparator) =>
354
373
  uniqueArray(items, selector).sort(comparator);
355
374
 
356
- /** @template T @template R @typedef {{ [P in keyof T]: R }} MappedValues<T, R> */
375
+ /**
376
+ * @template T
377
+ * @template R
378
+ * @typedef {{ [P in keyof T]: R }} MappedValues<T, R>
379
+ */
357
380
 
358
381
  /**
359
382
  * @template {object} T
360
383
  * @template {object} R
361
384
  * @param {T} obj object to be mapped
362
- * @param {function(T[keyof T], keyof T): R} fn mapping function
385
+ * @param {(value: T[keyof T], key: keyof T) => R} fn mapping function
363
386
  * @returns {MappedValues<T, R>} mapped object
364
387
  */
365
388
  const mapObject = (obj, fn) => {
@@ -374,8 +397,9 @@ const mapObject = (obj, fn) => {
374
397
  };
375
398
 
376
399
  /**
400
+ * @template T
377
401
  * @param {Compilation} compilation the compilation
378
- * @param {function(Compilation, string): any[]} getItems get items
402
+ * @param {(compilation: Compilation, name: string) => T[]} getItems get items
379
403
  * @returns {number} total number
380
404
  */
381
405
  const countWithChildren = (compilation, getItems) => {
@@ -388,53 +412,72 @@ const countWithChildren = (compilation, getItems) => {
388
412
  return count;
389
413
  };
390
414
 
391
- /** @type {ExtractorsByOption<WebpackError | string, StatsError>} */
415
+ /** @type {ExtractorsByOption<string | ErrorWithCause | AggregateError | WebpackError, StatsError>} */
392
416
  const EXTRACT_ERROR = {
393
417
  _: (object, error, context, { requestShortener }) => {
394
418
  // TODO webpack 6 disallow strings in the errors/warnings list
395
419
  if (typeof error === "string") {
396
420
  object.message = error;
397
421
  } else {
398
- if (error.chunk) {
399
- object.chunkName = error.chunk.name;
400
- object.chunkEntry = error.chunk.hasRuntime();
401
- object.chunkInitial = error.chunk.canBeInitial();
422
+ if (/** @type {WebpackError} */ (error).chunk) {
423
+ const chunk = /** @type {WebpackError} */ (error).chunk;
424
+ object.chunkName =
425
+ /** @type {string | undefined} */
426
+ (chunk.name);
427
+ object.chunkEntry = chunk.hasRuntime();
428
+ object.chunkInitial = chunk.canBeInitial();
402
429
  }
403
- if (error.file) {
404
- object.file = error.file;
430
+
431
+ if (/** @type {WebpackError} */ (error).file) {
432
+ object.file = /** @type {WebpackError} */ (error).file;
405
433
  }
406
- if (error.module) {
407
- object.moduleIdentifier = error.module.identifier();
408
- object.moduleName = error.module.readableIdentifier(requestShortener);
434
+
435
+ if (/** @type {WebpackError} */ (error).module) {
436
+ object.moduleIdentifier =
437
+ /** @type {WebpackError} */
438
+ (error).module.identifier();
439
+ object.moduleName =
440
+ /** @type {WebpackError} */
441
+ (error).module.readableIdentifier(requestShortener);
409
442
  }
410
- if (error.loc) {
411
- object.loc = formatLocation(error.loc);
443
+
444
+ if (/** @type {WebpackError} */ (error).loc) {
445
+ object.loc = formatLocation(/** @type {WebpackError} */ (error).loc);
412
446
  }
447
+
413
448
  object.message = error.message;
414
449
  }
415
450
  },
416
451
  ids: (object, error, { compilation: { chunkGraph } }) => {
417
452
  if (typeof error !== "string") {
418
- if (error.chunk) {
419
- object.chunkId = /** @type {ChunkId} */ (error.chunk.id);
453
+ if (/** @type {WebpackError} */ (error).chunk) {
454
+ object.chunkId = /** @type {ChunkId} */ (
455
+ /** @type {WebpackError} */
456
+ (error).chunk.id
457
+ );
420
458
  }
421
- if (error.module) {
459
+
460
+ if (/** @type {WebpackError} */ (error).module) {
422
461
  object.moduleId =
423
462
  /** @type {ModuleId} */
424
- (chunkGraph.getModuleId(error.module));
463
+ (chunkGraph.getModuleId(/** @type {WebpackError} */ (error).module));
425
464
  }
426
465
  }
427
466
  },
428
467
  moduleTrace: (object, error, context, options, factory) => {
429
- if (typeof error !== "string" && error.module) {
468
+ if (
469
+ typeof error !== "string" &&
470
+ /** @type {WebpackError} */ (error).module
471
+ ) {
430
472
  const {
431
473
  type,
432
474
  compilation: { moduleGraph }
433
475
  } = context;
434
476
  /** @type {Set<Module>} */
435
477
  const visitedModules = new Set();
478
+ /** @type {ModuleTrace[]} */
436
479
  const moduleTrace = [];
437
- let current = error.module;
480
+ let current = /** @type {WebpackError} */ (error).module;
438
481
  while (current) {
439
482
  if (visitedModules.has(current)) break; // circular (technically impossible, but how knows)
440
483
  visitedModules.add(current);
@@ -453,7 +496,7 @@ const EXTRACT_ERROR = {
453
496
  errorDetails: (
454
497
  object,
455
498
  error,
456
- { type, compilation, cachedGetErrors, cachedGetWarnings },
499
+ { type, compilation, cachedGetErrors },
457
500
  { errorDetails }
458
501
  ) => {
459
502
  if (
@@ -461,13 +504,44 @@ const EXTRACT_ERROR = {
461
504
  (errorDetails === true ||
462
505
  (type.endsWith(".error") && cachedGetErrors(compilation).length < 3))
463
506
  ) {
464
- object.details = error.details;
507
+ object.details = /** @type {WebpackError} */ (error).details;
465
508
  }
466
509
  },
467
510
  errorStack: (object, error) => {
468
511
  if (typeof error !== "string") {
469
512
  object.stack = error.stack;
470
513
  }
514
+ },
515
+ errorCause: (object, error, context, options, factory) => {
516
+ if (
517
+ typeof error !== "string" &&
518
+ /** @type {ErrorWithCause} */ (error).cause
519
+ ) {
520
+ const rawCause = /** @type {ErrorWithCause} */ (error).cause;
521
+ /** @type {Error} */
522
+ const cause =
523
+ typeof rawCause === "string"
524
+ ? /** @type {Error} */ ({ message: rawCause })
525
+ : /** @type {Error} */ (rawCause);
526
+ const { type } = context;
527
+
528
+ object.cause = factory.create(`${type}.cause`, cause, context);
529
+ }
530
+ },
531
+ errorErrors: (object, error, context, options, factory) => {
532
+ if (
533
+ typeof error !== "string" &&
534
+ /** @type {AggregateError} */
535
+ (error).errors
536
+ ) {
537
+ const { type } = context;
538
+ object.errors = factory.create(
539
+ `${type}.errors`,
540
+ /** @type {Error[]} */
541
+ (/** @type {AggregateError} */ (error).errors),
542
+ context
543
+ );
544
+ }
471
545
  }
472
546
  };
473
547
 
@@ -482,20 +556,22 @@ const SIMPLE_EXTRACTORS = {
482
556
  );
483
557
  }
484
558
  if (!context.cachedGetErrors) {
559
+ /** @type {WeakMap<Compilation, Error[]>} */
485
560
  const map = new WeakMap();
486
- context.cachedGetErrors = compilation =>
561
+ context.cachedGetErrors = (compilation) =>
487
562
  map.get(compilation) ||
488
563
  // eslint-disable-next-line no-sequences
489
- (errors => (map.set(compilation, errors), errors))(
564
+ ((errors) => (map.set(compilation, errors), errors))(
490
565
  compilation.getErrors()
491
566
  );
492
567
  }
493
568
  if (!context.cachedGetWarnings) {
569
+ /** @type {WeakMap<Compilation, Error[]>} */
494
570
  const map = new WeakMap();
495
- context.cachedGetWarnings = compilation =>
571
+ context.cachedGetWarnings = (compilation) =>
496
572
  map.get(compilation) ||
497
573
  // eslint-disable-next-line no-sequences
498
- (warnings => (map.set(compilation, warnings), warnings))(
574
+ ((warnings) => (map.set(compilation, warnings), warnings))(
499
575
  compilation.getWarnings()
500
576
  );
501
577
  }
@@ -509,6 +585,7 @@ const SIMPLE_EXTRACTORS = {
509
585
  const { logging, loggingDebug, loggingTrace } = options;
510
586
  if (logging || (loggingDebug && loggingDebug.length > 0)) {
511
587
  const util = require("util");
588
+
512
589
  object.logging = {};
513
590
  let acceptedTypes;
514
591
  let collapsedGroups = false;
@@ -565,7 +642,7 @@ const SIMPLE_EXTRACTORS = {
565
642
  );
566
643
  let depthInCollapsedGroup = 0;
567
644
  for (const [origin, logEntries] of compilation.logging) {
568
- const debugMode = loggingDebug.some(fn => fn(origin));
645
+ const debugMode = loggingDebug.some((fn) => fn(origin));
569
646
  if (logging === false && !debugMode) continue;
570
647
  /** @type {KnownStatsLoggingEntry[]} */
571
648
  const groupStack = [];
@@ -581,8 +658,9 @@ const SIMPLE_EXTRACTORS = {
581
658
  if (
582
659
  type === LogType.groupCollapsed &&
583
660
  (debugMode || collapsedGroups)
584
- )
661
+ ) {
585
662
  type = LogType.group;
663
+ }
586
664
 
587
665
  if (depthInCollapsedGroup === 0) {
588
666
  processedLogEntries++;
@@ -647,9 +725,9 @@ const SIMPLE_EXTRACTORS = {
647
725
  }
648
726
  },
649
727
  hash: (object, compilation) => {
650
- object.hash = /** @type {string} */ (compilation.hash);
728
+ object.hash = compilation.hash;
651
729
  },
652
- version: object => {
730
+ version: (object) => {
653
731
  object.version = require("../../package.json").version;
654
732
  },
655
733
  env: (object, compilation, context, { _env }) => {
@@ -665,14 +743,11 @@ const SIMPLE_EXTRACTORS = {
665
743
  },
666
744
  publicPath: (object, compilation) => {
667
745
  object.publicPath = compilation.getPath(
668
- /** @type {TemplatePath} */
669
- (compilation.outputOptions.publicPath)
746
+ compilation.outputOptions.publicPath
670
747
  );
671
748
  },
672
749
  outputPath: (object, compilation) => {
673
- object.outputPath = /** @type {string} */ (
674
- compilation.outputOptions.path
675
- );
750
+ object.outputPath = compilation.outputOptions.path;
676
751
  },
677
752
  assets: (object, compilation, context, options, factory) => {
678
753
  const { type } = context;
@@ -721,6 +796,7 @@ const SIMPLE_EXTRACTORS = {
721
796
  ? relatedEntry
722
797
  : [relatedEntry];
723
798
  for (const dep of deps) {
799
+ if (!dep) continue;
724
800
  const depItem = assetMap.get(dep);
725
801
  if (!depItem) continue;
726
802
  assets.delete(depItem);
@@ -732,7 +808,10 @@ const SIMPLE_EXTRACTORS = {
732
808
  }
733
809
 
734
810
  object.assetsByChunkName = {};
735
- for (const [file, chunks] of compilationFileToChunks) {
811
+ for (const [file, chunks] of [
812
+ ...compilationFileToChunks,
813
+ ...compilationAuxiliaryFileToChunks
814
+ ]) {
736
815
  for (const chunk of chunks) {
737
816
  const name = chunk.name;
738
817
  if (!name) continue;
@@ -748,15 +827,11 @@ const SIMPLE_EXTRACTORS = {
748
827
  }
749
828
  }
750
829
 
751
- const groupedAssets = factory.create(
752
- `${type}.assets`,
753
- Array.from(assets),
754
- {
755
- ...context,
756
- compilationFileToChunks,
757
- compilationAuxiliaryFileToChunks
758
- }
759
- );
830
+ const groupedAssets = factory.create(`${type}.assets`, [...assets], {
831
+ ...context,
832
+ compilationFileToChunks,
833
+ compilationAuxiliaryFileToChunks
834
+ });
760
835
  const limited = spaceLimited(
761
836
  groupedAssets,
762
837
  /** @type {number} */ (options.assetsSpace)
@@ -768,13 +843,13 @@ const SIMPLE_EXTRACTORS = {
768
843
  const { type } = context;
769
844
  object.chunks = factory.create(
770
845
  `${type}.chunks`,
771
- Array.from(compilation.chunks),
846
+ [...compilation.chunks],
772
847
  context
773
848
  );
774
849
  },
775
850
  modules: (object, compilation, context, options, factory) => {
776
851
  const { type } = context;
777
- const array = Array.from(compilation.modules);
852
+ const array = [...compilation.modules];
778
853
  const groupedModules = factory.create(`${type}.modules`, array, context);
779
854
  const limited = spaceLimited(groupedModules, options.modulesSpace);
780
855
  object.modules = limited.children;
@@ -788,6 +863,7 @@ const SIMPLE_EXTRACTORS = {
788
863
  factory
789
864
  ) => {
790
865
  const { type } = context;
866
+ /** @type {ChunkGroupInfoWithName[]} */
791
867
  const array = Array.from(compilation.entrypoints, ([key, value]) => ({
792
868
  name: key,
793
869
  chunkGroup: value
@@ -840,7 +916,10 @@ const SIMPLE_EXTRACTORS = {
840
916
  let filtered = 0;
841
917
  if (options.errorDetails === "auto" && rawErrors.length >= 3) {
842
918
  filtered = rawErrors
843
- .map(e => typeof e !== "string" && e.details)
919
+ .map(
920
+ (e) =>
921
+ typeof e !== "string" && /** @type {WebpackError} */ (e).details
922
+ )
844
923
  .filter(Boolean).length;
845
924
  }
846
925
  if (
@@ -860,7 +939,7 @@ const SIMPLE_EXTRACTORS = {
860
939
  object.errors = errors;
861
940
  },
862
941
  errorsCount: (object, compilation, { cachedGetErrors }) => {
863
- object.errorsCount = countWithChildren(compilation, c =>
942
+ object.errorsCount = countWithChildren(compilation, (c) =>
864
943
  cachedGetErrors(c)
865
944
  );
866
945
  },
@@ -874,7 +953,10 @@ const SIMPLE_EXTRACTORS = {
874
953
  let filtered = 0;
875
954
  if (options.errorDetails === "auto") {
876
955
  filtered = cachedGetWarnings(compilation)
877
- .map(e => typeof e !== "string" && e.details)
956
+ .map(
957
+ (e) =>
958
+ typeof e !== "string" && /** @type {WebpackError} */ (e).details
959
+ )
878
960
  .filter(Boolean).length;
879
961
  }
880
962
  if (
@@ -904,25 +986,27 @@ const SIMPLE_EXTRACTORS = {
904
986
  object.warningsCount = countWithChildren(compilation, (c, childType) => {
905
987
  if (
906
988
  !warningsFilter &&
907
- /** @type {((warning: StatsError, textValue: string) => boolean)[]} */
989
+ /** @type {KnownNormalizedStatsOptions["warningsFilter"]} */
908
990
  (warningsFilter).length === 0
909
- )
910
- return cachedGetWarnings(c);
991
+ ) {
992
+ // Type is wrong, because we don't need the real value for counting
993
+ return /** @type {EXPECTED_ANY[]} */ (cachedGetWarnings(c));
994
+ }
911
995
  return factory
912
996
  .create(`${type}${childType}.warnings`, cachedGetWarnings(c), context)
913
997
  .filter(
914
998
  /**
915
- * @param {TODO} warning warning
999
+ * @param {StatsError} warning warning
916
1000
  * @returns {boolean} result
917
1001
  */
918
- warning => {
1002
+ (warning) => {
919
1003
  const warningString = Object.keys(warning)
920
1004
  .map(
921
- key =>
1005
+ (key) =>
922
1006
  `${warning[/** @type {keyof KnownStatsError} */ (key)]}`
923
1007
  )
924
1008
  .join("\n");
925
- return !warningsFilter.some(filter =>
1009
+ return !warningsFilter.some((filter) =>
926
1010
  filter(warning, warningString)
927
1011
  );
928
1012
  }
@@ -963,29 +1047,29 @@ const SIMPLE_EXTRACTORS = {
963
1047
  _: (
964
1048
  object,
965
1049
  asset,
966
- { compilation, compilationFileToChunks, compilationAuxiliaryFileToChunks }
1050
+ { compilationFileToChunks, compilationAuxiliaryFileToChunks }
967
1051
  ) => {
968
1052
  const chunks = compilationFileToChunks.get(asset.name) || [];
969
1053
  const auxiliaryChunks =
970
1054
  compilationAuxiliaryFileToChunks.get(asset.name) || [];
971
1055
  object.chunkNames = uniqueOrderedArray(
972
1056
  chunks,
973
- c => (c.name ? [c.name] : []),
1057
+ (c) => (c.name ? [c.name] : []),
974
1058
  compareIds
975
1059
  );
976
1060
  object.chunkIdHints = uniqueOrderedArray(
977
1061
  chunks,
978
- c => Array.from(c.idNameHints),
1062
+ (c) => [...c.idNameHints],
979
1063
  compareIds
980
1064
  );
981
1065
  object.auxiliaryChunkNames = uniqueOrderedArray(
982
1066
  auxiliaryChunks,
983
- c => (c.name ? [c.name] : []),
1067
+ (c) => (c.name ? [c.name] : []),
984
1068
  compareIds
985
1069
  );
986
1070
  object.auxiliaryChunkIdHints = uniqueOrderedArray(
987
1071
  auxiliaryChunks,
988
- c => Array.from(c.idNameHints),
1072
+ (c) => [...c.idNameHints],
989
1073
  compareIds
990
1074
  );
991
1075
  object.filteredRelated = asset.related ? asset.related.length : undefined;
@@ -1012,12 +1096,12 @@ const SIMPLE_EXTRACTORS = {
1012
1096
  compilationAuxiliaryFileToChunks.get(asset.name) || [];
1013
1097
  object.chunks = uniqueOrderedArray(
1014
1098
  chunks,
1015
- c => /** @type {ChunkId[]} */ (c.ids),
1099
+ (c) => /** @type {ChunkId[]} */ (c.ids),
1016
1100
  compareIds
1017
1101
  );
1018
1102
  object.auxiliaryChunks = uniqueOrderedArray(
1019
1103
  auxiliaryChunks,
1020
- c => /** @type {ChunkId[]} */ (c.ids),
1104
+ (c) => /** @type {ChunkId[]} */ (c.ids),
1021
1105
  compareIds
1022
1106
  );
1023
1107
  },
@@ -1039,7 +1123,7 @@ const SIMPLE_EXTRACTORS = {
1039
1123
  * @param {string} name Name
1040
1124
  * @returns {{ name: string, size: number }} Asset object
1041
1125
  */
1042
- const toAsset = name => {
1126
+ const toAsset = (name) => {
1043
1127
  const asset = compilation.getAsset(name);
1044
1128
  return {
1045
1129
  name,
@@ -1048,10 +1132,12 @@ const SIMPLE_EXTRACTORS = {
1048
1132
  };
1049
1133
  /** @type {(total: number, asset: { size: number }) => number} */
1050
1134
  const sizeReducer = (total, { size }) => total + size;
1051
- const assets = uniqueArray(chunkGroup.chunks, c => c.files).map(toAsset);
1135
+ const assets = uniqueArray(chunkGroup.chunks, (c) => c.files).map(
1136
+ toAsset
1137
+ );
1052
1138
  const auxiliaryAssets = uniqueOrderedArray(
1053
1139
  chunkGroup.chunks,
1054
- c => c.auxiliaryFiles,
1140
+ (c) => c.auxiliaryFiles,
1055
1141
  compareIds
1056
1142
  ).map(toAsset);
1057
1143
  const assetsSize = assets.reduce(sizeReducer, 0);
@@ -1060,7 +1146,7 @@ const SIMPLE_EXTRACTORS = {
1060
1146
  const statsChunkGroup = {
1061
1147
  name,
1062
1148
  chunks: ids
1063
- ? /** @type {ChunkId[]} */ (chunkGroup.chunks.map(c => c.id))
1149
+ ? /** @type {ChunkId[]} */ (chunkGroup.chunks.map((c) => c.id))
1064
1150
  : undefined,
1065
1151
  assets: assets.length <= chunkGroupMaxAssets ? assets : undefined,
1066
1152
  filteredAssets:
@@ -1076,14 +1162,14 @@ const SIMPLE_EXTRACTORS = {
1076
1162
  : auxiliaryAssets.length,
1077
1163
  auxiliaryAssetsSize,
1078
1164
  children: children
1079
- ? mapObject(children, groups =>
1080
- groups.map(group => {
1081
- const assets = uniqueArray(group.chunks, c => c.files).map(
1165
+ ? mapObject(children, (groups) =>
1166
+ groups.map((group) => {
1167
+ const assets = uniqueArray(group.chunks, (c) => c.files).map(
1082
1168
  toAsset
1083
1169
  );
1084
1170
  const auxiliaryAssets = uniqueOrderedArray(
1085
1171
  group.chunks,
1086
- c => c.auxiliaryFiles,
1172
+ (c) => c.auxiliaryFiles,
1087
1173
  compareIds
1088
1174
  ).map(toAsset);
1089
1175
 
@@ -1092,7 +1178,7 @@ const SIMPLE_EXTRACTORS = {
1092
1178
  name: group.name,
1093
1179
  chunks: ids
1094
1180
  ? /** @type {ChunkId[]} */
1095
- (group.chunks.map(c => c.id))
1181
+ (group.chunks.map((c) => c.id))
1096
1182
  : undefined,
1097
1183
  assets:
1098
1184
  assets.length <= chunkGroupMaxAssets ? assets : undefined,
@@ -1115,7 +1201,7 @@ const SIMPLE_EXTRACTORS = {
1115
1201
  )
1116
1202
  : undefined,
1117
1203
  childAssets: children
1118
- ? mapObject(children, groups => {
1204
+ ? mapObject(children, (groups) => {
1119
1205
  /** @type {Set<string>} */
1120
1206
  const set = new Set();
1121
1207
  for (const group of groups) {
@@ -1125,7 +1211,7 @@ const SIMPLE_EXTRACTORS = {
1125
1211
  }
1126
1212
  }
1127
1213
  }
1128
- return Array.from(set);
1214
+ return [...set];
1129
1215
  })
1130
1216
  : undefined
1131
1217
  };
@@ -1161,7 +1247,6 @@ const SIMPLE_EXTRACTORS = {
1161
1247
  cached: !built && !codeGenerated
1162
1248
  };
1163
1249
  Object.assign(object, statsModule);
1164
-
1165
1250
  if (built || codeGenerated || options.cachedModules) {
1166
1251
  Object.assign(
1167
1252
  object,
@@ -1175,7 +1260,7 @@ const SIMPLE_EXTRACTORS = {
1175
1260
  const { type, rootModules } = context;
1176
1261
  const compilation = /** @type {Compilation} */ (context.compilation);
1177
1262
  const { moduleGraph } = compilation;
1178
- /** @type {Module[]} */
1263
+ /** @type {ModuleIssuerPath} */
1179
1264
  const path = [];
1180
1265
  const issuer = moduleGraph.getIssuer(module);
1181
1266
  let current = issuer;
@@ -1213,7 +1298,8 @@ const SIMPLE_EXTRACTORS = {
1213
1298
  issuerName: issuer && issuer.readableIdentifier(requestShortener),
1214
1299
  issuerPath:
1215
1300
  issuer &&
1216
- factory.create(`${type.slice(0, -8)}.issuerPath`, path, context),
1301
+ /** @type {StatsModuleIssuer[] | undefined} */
1302
+ (factory.create(`${type.slice(0, -8)}.issuerPath`, path, context)),
1217
1303
  failed: errorsCount > 0,
1218
1304
  errors: errorsCount,
1219
1305
  warnings: warningsCount
@@ -1239,7 +1325,7 @@ const SIMPLE_EXTRACTORS = {
1239
1325
  module,
1240
1326
  compareChunksById
1241
1327
  ),
1242
- chunk => chunk.id
1328
+ (chunk) => chunk.id
1243
1329
  )
1244
1330
  );
1245
1331
  },
@@ -1255,7 +1341,7 @@ const SIMPLE_EXTRACTORS = {
1255
1341
  } = context;
1256
1342
  const groupsReasons = factory.create(
1257
1343
  `${type.slice(0, -8)}.reasons`,
1258
- Array.from(moduleGraph.getIncomingConnections(module)),
1344
+ [...moduleGraph.getIncomingConnections(module)],
1259
1345
  context
1260
1346
  );
1261
1347
  const limited = spaceLimited(
@@ -1277,7 +1363,7 @@ const SIMPLE_EXTRACTORS = {
1277
1363
  } else if (typeof usedExports === "boolean") {
1278
1364
  object.usedExports = usedExports;
1279
1365
  } else {
1280
- object.usedExports = Array.from(usedExports);
1366
+ object.usedExports = [...usedExports];
1281
1367
  }
1282
1368
  },
1283
1369
  providedExports: (object, module, { compilation: { moduleGraph } }) => {
@@ -1294,7 +1380,7 @@ const SIMPLE_EXTRACTORS = {
1294
1380
  ) => {
1295
1381
  object.optimizationBailout = moduleGraph
1296
1382
  .getOptimizationBailout(module)
1297
- .map(item => {
1383
+ .map((item) => {
1298
1384
  if (typeof item === "function") return item(requestShortener);
1299
1385
  return item;
1300
1386
  });
@@ -1431,15 +1517,15 @@ const SIMPLE_EXTRACTORS = {
1431
1517
  size: chunkGraph.getChunkModulesSize(chunk),
1432
1518
  sizes: chunkGraph.getChunkModulesSizes(chunk),
1433
1519
  names: chunk.name ? [chunk.name] : [],
1434
- idHints: Array.from(chunk.idNameHints),
1520
+ idHints: [...chunk.idNameHints],
1435
1521
  runtime:
1436
1522
  chunk.runtime === undefined
1437
1523
  ? undefined
1438
1524
  : typeof chunk.runtime === "string"
1439
1525
  ? [makePathsRelative(chunk.runtime)]
1440
1526
  : Array.from(chunk.runtime.sort(), makePathsRelative),
1441
- files: Array.from(chunk.files),
1442
- auxiliaryFiles: Array.from(chunk.auxiliaryFiles).sort(compareIds),
1527
+ files: [...chunk.files],
1528
+ auxiliaryFiles: [...chunk.auxiliaryFiles].sort(compareIds),
1443
1529
  hash: /** @type {string} */ (chunk.renderedHash),
1444
1530
  childrenByOrder: childIdByOrder
1445
1531
  };
@@ -1448,12 +1534,13 @@ const SIMPLE_EXTRACTORS = {
1448
1534
  ids: (object, chunk) => {
1449
1535
  object.id = /** @type {ChunkId} */ (chunk.id);
1450
1536
  },
1451
- chunkRelations: (object, chunk, { compilation: { chunkGraph } }) => {
1452
- /** @type {Set<string|number>} */
1537
+ chunkRelations: (object, chunk, _context) => {
1538
+ /** @typedef {Set<ChunkId>} ChunkRelations */
1539
+ /** @type {ChunkRelations} */
1453
1540
  const parents = new Set();
1454
- /** @type {Set<string|number>} */
1541
+ /** @type {ChunkRelations} */
1455
1542
  const children = new Set();
1456
- /** @type {Set<string|number>} */
1543
+ /** @type {ChunkRelations} */
1457
1544
  const siblings = new Set();
1458
1545
 
1459
1546
  for (const chunkGroup of chunk.groupsIterable) {
@@ -1468,13 +1555,14 @@ const SIMPLE_EXTRACTORS = {
1468
1555
  }
1469
1556
  }
1470
1557
  for (const sibling of chunkGroup.chunks) {
1471
- if (sibling !== chunk)
1558
+ if (sibling !== chunk) {
1472
1559
  siblings.add(/** @type {ChunkId} */ (sibling.id));
1560
+ }
1473
1561
  }
1474
1562
  }
1475
- object.siblings = Array.from(siblings).sort(compareIds);
1476
- object.parents = Array.from(parents).sort(compareIds);
1477
- object.children = Array.from(children).sort(compareIds);
1563
+ object.siblings = [...siblings].sort(compareIds);
1564
+ object.parents = [...parents].sort(compareIds);
1565
+ object.children = [...children].sort(compareIds);
1478
1566
  },
1479
1567
  chunkModules: (object, chunk, context, options, factory) => {
1480
1568
  const {
@@ -1498,11 +1586,12 @@ const SIMPLE_EXTRACTORS = {
1498
1586
  } = context;
1499
1587
  /** @type {Set<string>} */
1500
1588
  const originsKeySet = new Set();
1589
+ /** @type {OriginRecord[]} */
1501
1590
  const origins = [];
1502
1591
  for (const g of chunk.groupsIterable) {
1503
1592
  origins.push(...g.origins);
1504
1593
  }
1505
- const array = origins.filter(origin => {
1594
+ const array = origins.filter((origin) => {
1506
1595
  const key = [
1507
1596
  origin.module ? chunkGraph.getModuleId(origin.module) : undefined,
1508
1597
  formatLocation(origin.loc),
@@ -1537,6 +1626,7 @@ const SIMPLE_EXTRACTORS = {
1537
1626
  },
1538
1627
  error: EXTRACT_ERROR,
1539
1628
  warning: EXTRACT_ERROR,
1629
+ cause: EXTRACT_ERROR,
1540
1630
  moduleTraceItem: {
1541
1631
  _: (object, { origin, module }, context, { requestShortener }, factory) => {
1542
1632
  const {
@@ -1547,14 +1637,13 @@ const SIMPLE_EXTRACTORS = {
1547
1637
  object.originName = origin.readableIdentifier(requestShortener);
1548
1638
  object.moduleIdentifier = module.identifier();
1549
1639
  object.moduleName = module.readableIdentifier(requestShortener);
1550
- const dependencies = Array.from(
1551
- moduleGraph.getIncomingConnections(module)
1552
- )
1553
- .filter(c => c.resolvedOriginModule === origin && c.dependency)
1554
- .map(c => c.dependency);
1640
+ const dependencies = [...moduleGraph.getIncomingConnections(module)]
1641
+ .filter((c) => c.resolvedOriginModule === origin && c.dependency)
1642
+ .map((c) => c.dependency);
1555
1643
  object.dependencies = factory.create(
1556
1644
  `${type}.dependencies`,
1557
- Array.from(new Set(dependencies)),
1645
+ /** @type {Dependency[]} */
1646
+ ([...new Set(dependencies)]),
1558
1647
  context
1559
1648
  );
1560
1649
  },
@@ -1574,7 +1663,7 @@ const SIMPLE_EXTRACTORS = {
1574
1663
  }
1575
1664
  };
1576
1665
 
1577
- /** @type {Record<string, Record<string, (thing: any, context: StatsFactoryContext, options: NormalizedStatsOptions) => boolean | undefined>>} */
1666
+ /** @type {Record<string, Record<string, (thing: ModuleGraphConnection, context: StatsFactoryContext, options: NormalizedStatsOptions, idx: number, i: number) => boolean | undefined>>} */
1578
1667
  const FILTER = {
1579
1668
  "module.reasons": {
1580
1669
  "!orphanModules": (reason, { compilation: { chunkGraph } }) => {
@@ -1588,15 +1677,17 @@ const FILTER = {
1588
1677
  }
1589
1678
  };
1590
1679
 
1591
- /** @type {Record<string, Record<string, (thing: KnownStatsError, context: StatsFactoryContext, options: NormalizedStatsOptions) => boolean | undefined>>} */
1680
+ /** @type {Record<string, Record<string, (thing: KnownStatsError, context: StatsFactoryContext, options: NormalizedStatsOptions, idx: number, i: number) => boolean | undefined>>} */
1592
1681
  const FILTER_RESULTS = {
1593
1682
  "compilation.warnings": {
1594
1683
  warningsFilter: util.deprecate(
1595
1684
  (warning, context, { warningsFilter }) => {
1596
1685
  const warningString = Object.keys(warning)
1597
- .map(key => `${warning[/** @type {keyof KnownStatsError} */ (key)]}`)
1686
+ .map(
1687
+ (key) => `${warning[/** @type {keyof KnownStatsError} */ (key)]}`
1688
+ )
1598
1689
  .join("\n");
1599
- return !warningsFilter.some(filter => filter(warning, warningString));
1690
+ return !warningsFilter.some((filter) => filter(warning, warningString));
1600
1691
  },
1601
1692
  "config.stats.warningsFilter is deprecated in favor of config.ignoreWarnings",
1602
1693
  "DEP_WEBPACK_STATS_WARNINGS_FILTER"
@@ -1604,43 +1695,32 @@ const FILTER_RESULTS = {
1604
1695
  }
1605
1696
  };
1606
1697
 
1607
- /** @type {Record<string, (comparators: Function[], context: StatsFactoryContext) => void>} */
1698
+ /** @type {Record<string, (comparators: Comparator<Module>[], context: StatsFactoryContext) => void>} */
1608
1699
  const MODULES_SORTER = {
1609
1700
  _: (comparators, { compilation: { moduleGraph } }) => {
1610
1701
  comparators.push(
1611
- compareSelect(
1612
- /**
1613
- * @param {Module} m module
1614
- * @returns {number | null} depth
1615
- */
1616
- m => moduleGraph.getDepth(m),
1617
- compareNumbers
1618
- ),
1619
- compareSelect(
1620
- /**
1621
- * @param {Module} m module
1622
- * @returns {number | null} index
1623
- */
1624
- m => moduleGraph.getPreOrderIndex(m),
1625
- compareNumbers
1626
- ),
1627
- compareSelect(
1628
- /**
1629
- * @param {Module} m module
1630
- * @returns {string} identifier
1631
- */
1632
- m => m.identifier(),
1633
- compareIds
1634
- )
1702
+ compareSelect((m) => moduleGraph.getDepth(m), compareNumbers),
1703
+ compareSelect((m) => moduleGraph.getPreOrderIndex(m), compareNumbers),
1704
+ compareSelect((m) => m.identifier(), compareIds)
1635
1705
  );
1636
1706
  }
1637
1707
  };
1638
1708
 
1639
- /** @type {Record<string, Record<string, (comparators: Function[], context: StatsFactoryContext) => void>>} */
1709
+ /**
1710
+ * @type {{
1711
+ * "compilation.chunks": Record<string, (comparators: Comparator<Chunk>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>,
1712
+ * "compilation.modules": Record<string, (comparators: Comparator<Module>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>,
1713
+ * "chunk.rootModules": Record<string, (comparators: Comparator<Module>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>,
1714
+ * "chunk.modules": Record<string, (comparators: Comparator<Module>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>,
1715
+ * "module.modules": Record<string, (comparators: Comparator<Module>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>,
1716
+ * "module.reasons": Record<string, (comparators: Comparator<ModuleGraphConnection>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>,
1717
+ * "chunk.origins": Record<string, (comparators: Comparator<OriginRecord>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>,
1718
+ * }}
1719
+ */
1640
1720
  const SORTERS = {
1641
1721
  "compilation.chunks": {
1642
- _: comparators => {
1643
- comparators.push(compareSelect(c => c.id, compareIds));
1722
+ _: (comparators) => {
1723
+ comparators.push(compareSelect((c) => c.id, compareIds));
1644
1724
  }
1645
1725
  },
1646
1726
  "compilation.modules": MODULES_SORTER,
@@ -1648,26 +1728,26 @@ const SORTERS = {
1648
1728
  "chunk.modules": MODULES_SORTER,
1649
1729
  "module.modules": MODULES_SORTER,
1650
1730
  "module.reasons": {
1651
- _: (comparators, { compilation: { chunkGraph } }) => {
1731
+ _: (comparators, _context) => {
1652
1732
  comparators.push(
1653
- compareSelect(x => x.originModule, compareModulesByIdentifier)
1733
+ compareSelect((x) => x.originModule, compareModulesByIdentifier)
1654
1734
  );
1655
1735
  comparators.push(
1656
- compareSelect(x => x.resolvedOriginModule, compareModulesByIdentifier)
1736
+ compareSelect((x) => x.resolvedOriginModule, compareModulesByIdentifier)
1657
1737
  );
1658
1738
  comparators.push(
1659
1739
  compareSelect(
1660
- x => x.dependency,
1740
+ (x) => x.dependency,
1661
1741
  concatComparators(
1662
1742
  compareSelect(
1663
1743
  /**
1664
1744
  * @param {Dependency} x dependency
1665
1745
  * @returns {DependencyLocation} location
1666
1746
  */
1667
- x => x.loc,
1747
+ (x) => x.loc,
1668
1748
  compareLocations
1669
1749
  ),
1670
- compareSelect(x => x.type, compareIds)
1750
+ compareSelect((x) => x.type, compareIds)
1671
1751
  )
1672
1752
  )
1673
1753
  );
@@ -1677,12 +1757,12 @@ const SORTERS = {
1677
1757
  _: (comparators, { compilation: { chunkGraph } }) => {
1678
1758
  comparators.push(
1679
1759
  compareSelect(
1680
- origin =>
1760
+ (origin) =>
1681
1761
  origin.module ? chunkGraph.getModuleId(origin.module) : undefined,
1682
1762
  compareIds
1683
1763
  ),
1684
- compareSelect(origin => formatLocation(origin.loc), compareIds),
1685
- compareSelect(origin => origin.request, compareIds)
1764
+ compareSelect((origin) => formatLocation(origin.loc), compareIds),
1765
+ compareSelect((origin) => origin.request, compareIds)
1686
1766
  );
1687
1767
  }
1688
1768
  }
@@ -1690,7 +1770,7 @@ const SORTERS = {
1690
1770
 
1691
1771
  /**
1692
1772
  * @template T
1693
- * @typedef {T & { children: Children<T>[] | undefined, filteredChildren?: number }} Children
1773
+ * @typedef {T & { children?: Children<T>[] | undefined, filteredChildren?: number }} Children
1694
1774
  */
1695
1775
 
1696
1776
  /**
@@ -1698,7 +1778,7 @@ const SORTERS = {
1698
1778
  * @param {Children<T>} item item
1699
1779
  * @returns {number} item size
1700
1780
  */
1701
- const getItemSize = item =>
1781
+ const getItemSize = (item) =>
1702
1782
  // Each item takes 1 line
1703
1783
  // + the size of the children
1704
1784
  // + 1 extra line when it has children and filteredChildren
@@ -1713,7 +1793,7 @@ const getItemSize = item =>
1713
1793
  * @param {Children<T>[]} children children
1714
1794
  * @returns {number} total size
1715
1795
  */
1716
- const getTotalSize = children => {
1796
+ const getTotalSize = (children) => {
1717
1797
  let size = 0;
1718
1798
  for (const child of children) {
1719
1799
  size += getItemSize(child);
@@ -1726,7 +1806,7 @@ const getTotalSize = children => {
1726
1806
  * @param {Children<T>[]} children children
1727
1807
  * @returns {number} total items
1728
1808
  */
1729
- const getTotalItems = children => {
1809
+ const getTotalItems = (children) => {
1730
1810
  let count = 0;
1731
1811
  for (const child of children) {
1732
1812
  if (!child.children && !child.filteredChildren) {
@@ -1744,7 +1824,7 @@ const getTotalItems = children => {
1744
1824
  * @param {Children<T>[]} children children
1745
1825
  * @returns {Children<T>[]} collapsed children
1746
1826
  */
1747
- const collapse = children => {
1827
+ const collapse = (children) => {
1748
1828
  // After collapse each child must take exactly one line
1749
1829
  const newChildren = [];
1750
1830
  for (const child of children) {
@@ -1811,7 +1891,7 @@ const spaceLimited = (
1811
1891
  if (groupsSize + items.length <= max) {
1812
1892
  // The total size in the current state fits into the max
1813
1893
  // keep all
1814
- children = groups.length > 0 ? groups.concat(items) : items;
1894
+ children = groups.length > 0 ? [...groups, ...items] : items;
1815
1895
  } else if (groups.length === 0) {
1816
1896
  // slice items to max
1817
1897
  // inner space marks that lines for filteredChildren already reserved
@@ -1852,7 +1932,7 @@ const spaceLimited = (
1852
1932
  // So it should always end up being smaller
1853
1933
  const headerSize = group.filteredChildren ? 2 : 1;
1854
1934
  const limited = spaceLimited(
1855
- /** @type {Children<T>} */ (group.children),
1935
+ /** @type {Children<T>[]} */ (group.children),
1856
1936
  maxGroupSize -
1857
1937
  // we should use ceil to always feet in max
1858
1938
  Math.ceil(oversize / groups.length) -
@@ -1874,7 +1954,7 @@ const spaceLimited = (
1874
1954
  }
1875
1955
  }
1876
1956
  }
1877
- children = groups.concat(items);
1957
+ children = [...groups, ...items];
1878
1958
  } else if (limit === max) {
1879
1959
  // If we have only enough space to show one line per group and one line for the filtered items
1880
1960
  // collapse all groups and items
@@ -1899,15 +1979,16 @@ const errorsSpaceLimit = (errors, max) => {
1899
1979
  let filtered = 0;
1900
1980
  // Can not fit into limit
1901
1981
  // print only messages
1902
- if (errors.length + 1 >= max)
1982
+ if (errors.length + 1 >= max) {
1903
1983
  return [
1904
- errors.map(error => {
1984
+ errors.map((error) => {
1905
1985
  if (typeof error === "string" || !error.details) return error;
1906
1986
  filtered++;
1907
1987
  return { ...error, details: "" };
1908
1988
  }),
1909
1989
  filtered
1910
1990
  ];
1991
+ }
1911
1992
  let fullLength = errors.length;
1912
1993
  let result = errors;
1913
1994
 
@@ -1924,7 +2005,9 @@ const errorsSpaceLimit = (errors, max) => {
1924
2005
  const error = errors[i++];
1925
2006
  result.push({
1926
2007
  ...error,
1927
- details: error.details.split("\n").slice(0, -overLimit).join("\n"),
2008
+ details:
2009
+ /** @type {string} */
2010
+ (error.details).split("\n").slice(0, -overLimit).join("\n"),
1928
2011
  filteredDetails: overLimit
1929
2012
  });
1930
2013
  filtered = errors.length - i;
@@ -1952,8 +2035,7 @@ const errorsSpaceLimit = (errors, max) => {
1952
2035
 
1953
2036
  /**
1954
2037
  * @template {{ size: number }} T
1955
- * @template {{ size: number }} R
1956
- * @param {(R | T)[]} children children
2038
+ * @param {T[]} children children
1957
2039
  * @param {T[]} assets assets
1958
2040
  * @returns {{ size: number }} asset size
1959
2041
  */
@@ -1965,11 +2047,13 @@ const assetGroup = (children, assets) => {
1965
2047
  return { size };
1966
2048
  };
1967
2049
 
2050
+ /** @typedef {{ size: number, sizes: Record<string, number> }} ModuleGroupBySizeResult */
2051
+
1968
2052
  /**
1969
- * @template {{ size: number, sizes: Record<string, number> }} T
2053
+ * @template {ModuleGroupBySizeResult} T
1970
2054
  * @param {Children<T>[]} children children
1971
2055
  * @param {KnownStatsModule[]} modules modules
1972
- * @returns {{ size: number, sizes: Record<string, number>}} size and sizes
2056
+ * @returns {ModuleGroupBySizeResult} size and sizes
1973
2057
  */
1974
2058
  const moduleGroup = (children, modules) => {
1975
2059
  let size = 0;
@@ -2006,7 +2090,21 @@ const reasonGroup = (children, reasons) => {
2006
2090
  const GROUP_EXTENSION_REGEXP = /(\.[^.]+?)(?:\?|(?: \+ \d+ modules?)?$)/;
2007
2091
  const GROUP_PATH_REGEXP = /(.+)[/\\][^/\\]+?(?:\?|(?: \+ \d+ modules?)?$)/;
2008
2092
 
2009
- /** @typedef {Record<string, (groupConfigs: GroupConfig<KnownStatsAsset, TODO>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>} AssetsGroupers */
2093
+ /** @typedef {{ type: string }} BaseGroup */
2094
+
2095
+ /**
2096
+ * @template T
2097
+ * @typedef {BaseGroup & { children: T[], size: number }} BaseGroupWithChildren
2098
+ */
2099
+
2100
+ /**
2101
+ * @typedef {{
2102
+ * _: (groupConfigs: GroupConfig<KnownStatsAsset, BaseGroup & { filteredChildren: number, size: number } | BaseGroupWithChildren<KnownStatsAsset>>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void,
2103
+ * groupAssetsByInfo: (groupConfigs: GroupConfig<KnownStatsAsset, BaseGroupWithChildren<KnownStatsAsset>>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void,
2104
+ * groupAssetsByChunk: (groupConfigs: GroupConfig<KnownStatsAsset, BaseGroupWithChildren<KnownStatsAsset>>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void,
2105
+ * excludeAssets: (groupConfigs: GroupConfig<KnownStatsAsset, BaseGroup & { filteredChildren: number, size: number }>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void,
2106
+ * }} AssetsGroupers
2107
+ */
2010
2108
 
2011
2109
  /** @type {AssetsGroupers} */
2012
2110
  const ASSETS_GROUPERS = {
@@ -2017,7 +2115,7 @@ const ASSETS_GROUPERS = {
2017
2115
  */
2018
2116
  const groupByFlag = (name, exclude) => {
2019
2117
  groupConfigs.push({
2020
- getKeys: asset => (asset[name] ? ["1"] : undefined),
2118
+ getKeys: (asset) => (asset[name] ? ["1"] : undefined),
2021
2119
  getOptions: () => ({
2022
2120
  groupChildren: !exclude,
2023
2121
  force: exclude
@@ -2053,22 +2151,24 @@ const ASSETS_GROUPERS = {
2053
2151
  }
2054
2152
  if (groupAssetsByPath || groupAssetsByExtension) {
2055
2153
  groupConfigs.push({
2056
- getKeys: asset => {
2154
+ getKeys: (asset) => {
2057
2155
  const extensionMatch =
2058
2156
  groupAssetsByExtension && GROUP_EXTENSION_REGEXP.exec(asset.name);
2059
2157
  const extension = extensionMatch ? extensionMatch[1] : "";
2060
2158
  const pathMatch =
2061
2159
  groupAssetsByPath && GROUP_PATH_REGEXP.exec(asset.name);
2062
2160
  const path = pathMatch ? pathMatch[1].split(/[/\\]/) : [];
2161
+ /** @type {string[]} */
2063
2162
  const keys = [];
2064
2163
  if (groupAssetsByPath) {
2065
2164
  keys.push(".");
2066
- if (extension)
2165
+ if (extension) {
2067
2166
  keys.push(
2068
2167
  path.length
2069
2168
  ? `${path.join("/")}/*${extension}`
2070
2169
  : `*${extension}`
2071
2170
  );
2171
+ }
2072
2172
  while (path.length > 0) {
2073
2173
  keys.push(`${path.join("/")}/`);
2074
2174
  path.pop();
@@ -2087,13 +2187,14 @@ const ASSETS_GROUPERS = {
2087
2187
  });
2088
2188
  }
2089
2189
  },
2090
- groupAssetsByInfo: (groupConfigs, context, options) => {
2190
+ groupAssetsByInfo: (groupConfigs, _context, _options) => {
2091
2191
  /**
2092
2192
  * @param {string} name name
2093
2193
  */
2094
- const groupByAssetInfoFlag = name => {
2194
+ const groupByAssetInfoFlag = (name) => {
2095
2195
  groupConfigs.push({
2096
- getKeys: asset => (asset.info && asset.info[name] ? ["1"] : undefined),
2196
+ getKeys: (asset) =>
2197
+ asset.info && asset.info[name] ? ["1"] : undefined,
2097
2198
  createGroup: (key, children, assets) => ({
2098
2199
  type: "assets by info",
2099
2200
  info: {
@@ -2108,13 +2209,13 @@ const ASSETS_GROUPERS = {
2108
2209
  groupByAssetInfoFlag("development");
2109
2210
  groupByAssetInfoFlag("hotModuleReplacement");
2110
2211
  },
2111
- groupAssetsByChunk: (groupConfigs, context, options) => {
2212
+ groupAssetsByChunk: (groupConfigs, _context, _options) => {
2112
2213
  /**
2113
2214
  * @param {keyof KnownStatsAsset} name name
2114
2215
  */
2115
- const groupByNames = name => {
2216
+ const groupByNames = (name) => {
2116
2217
  groupConfigs.push({
2117
- getKeys: asset => /** @type {string[]} */ (asset[name]),
2218
+ getKeys: (asset) => /** @type {string[]} */ (asset[name]),
2118
2219
  createGroup: (key, children, assets) => ({
2119
2220
  type: "assets by chunk",
2120
2221
  [name]: [key],
@@ -2130,9 +2231,9 @@ const ASSETS_GROUPERS = {
2130
2231
  },
2131
2232
  excludeAssets: (groupConfigs, context, { excludeAssets }) => {
2132
2233
  groupConfigs.push({
2133
- getKeys: asset => {
2234
+ getKeys: (asset) => {
2134
2235
  const ident = asset.name;
2135
- const excluded = excludeAssets.some(fn => fn(ident, asset));
2236
+ const excluded = excludeAssets.some((fn) => fn(ident, asset));
2136
2237
  if (excluded) return ["excluded"];
2137
2238
  },
2138
2239
  getOptions: () => ({
@@ -2148,10 +2249,17 @@ const ASSETS_GROUPERS = {
2148
2249
  }
2149
2250
  };
2150
2251
 
2151
- /** @typedef {Record<string, (groupConfigs: GroupConfig<KnownStatsModule, TODO>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>} ModulesGroupers */
2252
+ /**
2253
+ * @typedef {{
2254
+ * _: (groupConfigs: GroupConfig<KnownStatsModule, BaseGroup & { filteredChildren?: number, children?: KnownStatsModule[], size: number, sizes: Record<string, number> }>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void,
2255
+ * excludeModules: (groupConfigs: GroupConfig<KnownStatsModule, BaseGroup & { filteredChildren: number, size: number, sizes: Record<string, number> }>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void,
2256
+ * }} ModulesGroupers
2257
+ */
2152
2258
 
2153
- /** @type {function("module" | "chunk" | "root-of-chunk" | "nested"): ModulesGroupers} */
2154
- const MODULES_GROUPERS = type => ({
2259
+ /**
2260
+ * @type {(type: ExcludeModulesType) => ModulesGroupers}
2261
+ */
2262
+ const MODULES_GROUPERS = (type) => ({
2155
2263
  _: (groupConfigs, context, options) => {
2156
2264
  /**
2157
2265
  * @param {keyof KnownStatsModule} name name
@@ -2160,7 +2268,7 @@ const MODULES_GROUPERS = type => ({
2160
2268
  */
2161
2269
  const groupByFlag = (name, type, exclude) => {
2162
2270
  groupConfigs.push({
2163
- getKeys: module => (module[name] ? ["1"] : undefined),
2271
+ getKeys: (module) => (module[name] ? ["1"] : undefined),
2164
2272
  getOptions: () => ({
2165
2273
  groupChildren: !exclude,
2166
2274
  force: exclude
@@ -2169,7 +2277,11 @@ const MODULES_GROUPERS = type => ({
2169
2277
  type,
2170
2278
  [name]: Boolean(key),
2171
2279
  ...(exclude ? { filteredChildren: modules.length } : { children }),
2172
- ...moduleGroup(children, modules)
2280
+ ...moduleGroup(
2281
+ /** @type {(KnownStatsModule & ModuleGroupBySizeResult)[]} */
2282
+ (children),
2283
+ modules
2284
+ )
2173
2285
  })
2174
2286
  });
2175
2287
  };
@@ -2203,7 +2315,7 @@ const MODULES_GROUPERS = type => ({
2203
2315
  }
2204
2316
  if (groupModulesByType || !options.runtimeModules) {
2205
2317
  groupConfigs.push({
2206
- getKeys: module => {
2318
+ getKeys: (module) => {
2207
2319
  if (!module.moduleType) return;
2208
2320
  if (groupModulesByType) {
2209
2321
  return [module.moduleType.split("/", 1)[0]];
@@ -2211,7 +2323,7 @@ const MODULES_GROUPERS = type => ({
2211
2323
  return [WEBPACK_MODULE_TYPE_RUNTIME];
2212
2324
  }
2213
2325
  },
2214
- getOptions: key => {
2326
+ getOptions: (key) => {
2215
2327
  const exclude =
2216
2328
  key === WEBPACK_MODULE_TYPE_RUNTIME && !options.runtimeModules;
2217
2329
  return {
@@ -2226,25 +2338,33 @@ const MODULES_GROUPERS = type => ({
2226
2338
  type: `${key} modules`,
2227
2339
  moduleType: key,
2228
2340
  ...(exclude ? { filteredChildren: modules.length } : { children }),
2229
- ...moduleGroup(children, modules)
2341
+ ...moduleGroup(
2342
+ /** @type {(KnownStatsModule & ModuleGroupBySizeResult)[]} */
2343
+ (children),
2344
+ modules
2345
+ )
2230
2346
  };
2231
2347
  }
2232
2348
  });
2233
2349
  }
2234
2350
  if (groupModulesByLayer) {
2235
2351
  groupConfigs.push({
2236
- getKeys: module => /** @type {string[]} */ ([module.layer]),
2352
+ getKeys: (module) => /** @type {string[]} */ ([module.layer]),
2237
2353
  createGroup: (key, children, modules) => ({
2238
2354
  type: "modules by layer",
2239
2355
  layer: key,
2240
2356
  children,
2241
- ...moduleGroup(children, modules)
2357
+ ...moduleGroup(
2358
+ /** @type {(KnownStatsModule & ModuleGroupBySizeResult)[]} */
2359
+ (children),
2360
+ modules
2361
+ )
2242
2362
  })
2243
2363
  });
2244
2364
  }
2245
2365
  if (groupModulesByPath || groupModulesByExtension) {
2246
2366
  groupConfigs.push({
2247
- getKeys: module => {
2367
+ getKeys: (module) => {
2248
2368
  if (!module.name) return;
2249
2369
  const resource = parseResource(
2250
2370
  /** @type {string} */ (module.name.split("!").pop())
@@ -2259,12 +2379,13 @@ const MODULES_GROUPERS = type => ({
2259
2379
  const path = pathMatch ? pathMatch[1].split(/[/\\]/) : [];
2260
2380
  const keys = [];
2261
2381
  if (groupModulesByPath) {
2262
- if (extension)
2382
+ if (extension) {
2263
2383
  keys.push(
2264
2384
  path.length
2265
2385
  ? `${path.join("/")}/*${extension}`
2266
2386
  : `*${extension}`
2267
2387
  );
2388
+ }
2268
2389
  while (path.length > 0) {
2269
2390
  keys.push(`${path.join("/")}/`);
2270
2391
  path.pop();
@@ -2284,7 +2405,11 @@ const MODULES_GROUPERS = type => ({
2284
2405
  : "modules by extension",
2285
2406
  name: isDataUrl ? key.slice(/* 'data:'.length */ 5) : key,
2286
2407
  children,
2287
- ...moduleGroup(children, modules)
2408
+ ...moduleGroup(
2409
+ /** @type {(KnownStatsModule & ModuleGroupBySizeResult)[]} */
2410
+ (children),
2411
+ modules
2412
+ )
2288
2413
  };
2289
2414
  }
2290
2415
  });
@@ -2292,10 +2417,10 @@ const MODULES_GROUPERS = type => ({
2292
2417
  },
2293
2418
  excludeModules: (groupConfigs, context, { excludeModules }) => {
2294
2419
  groupConfigs.push({
2295
- getKeys: module => {
2420
+ getKeys: (module) => {
2296
2421
  const name = module.name;
2297
2422
  if (name) {
2298
- const excluded = excludeModules.some(fn => fn(name, module, type));
2423
+ const excluded = excludeModules.some((fn) => fn(name, module, type));
2299
2424
  if (excluded) return ["1"];
2300
2425
  }
2301
2426
  },
@@ -2306,19 +2431,27 @@ const MODULES_GROUPERS = type => ({
2306
2431
  createGroup: (key, children, modules) => ({
2307
2432
  type: "hidden modules",
2308
2433
  filteredChildren: children.length,
2309
- ...moduleGroup(children, modules)
2434
+ ...moduleGroup(
2435
+ /** @type {(KnownStatsModule & ModuleGroupBySizeResult)[]} */
2436
+ (children),
2437
+ modules
2438
+ )
2310
2439
  })
2311
2440
  });
2312
2441
  }
2313
2442
  });
2314
2443
 
2315
- /** @typedef {Record<string, (groupConfigs: import("../util/smartGrouping").GroupConfig<KnownStatsModuleReason, TODO>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>} ModuleReasonsGroupers */
2444
+ /**
2445
+ * @typedef {{
2446
+ * groupReasonsByOrigin: (groupConfigs: GroupConfig<KnownStatsModuleReason, BaseGroup & { module: string, children: KnownStatsModuleReason[], active: boolean }>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void
2447
+ * }} ModuleReasonsGroupers
2448
+ */
2316
2449
 
2317
2450
  /** @type {ModuleReasonsGroupers} */
2318
2451
  const MODULE_REASONS_GROUPERS = {
2319
- groupReasonsByOrigin: groupConfigs => {
2452
+ groupReasonsByOrigin: (groupConfigs) => {
2320
2453
  groupConfigs.push({
2321
- getKeys: reason => /** @type {string[]} */ ([reason.module]),
2454
+ getKeys: (reason) => /** @type {string[]} */ ([reason.module]),
2322
2455
  createGroup: (key, children, reasons) => ({
2323
2456
  type: "from origin",
2324
2457
  module: key,
@@ -2329,7 +2462,17 @@ const MODULE_REASONS_GROUPERS = {
2329
2462
  }
2330
2463
  };
2331
2464
 
2332
- /** @type {Record<string, AssetsGroupers | ModulesGroupers | ModuleReasonsGroupers>} */
2465
+ /**
2466
+ * @type {{
2467
+ * "compilation.assets": AssetsGroupers,
2468
+ * "asset.related": AssetsGroupers,
2469
+ * "compilation.modules": ModulesGroupers,
2470
+ * "chunk.modules": ModulesGroupers,
2471
+ * "chunk.rootModules": ModulesGroupers,
2472
+ * "module.modules": ModulesGroupers,
2473
+ * "module.reasons": ModuleReasonsGroupers,
2474
+ * }}
2475
+ */
2333
2476
  const RESULT_GROUPERS = {
2334
2477
  "compilation.assets": ASSETS_GROUPERS,
2335
2478
  "asset.related": ASSETS_GROUPERS,
@@ -2345,7 +2488,7 @@ const RESULT_GROUPERS = {
2345
2488
  * @param {string} field a field name
2346
2489
  * @returns {field} normalized field
2347
2490
  */
2348
- const normalizeFieldKey = field => {
2491
+ const normalizeFieldKey = (field) => {
2349
2492
  if (field[0] === "!") {
2350
2493
  return field.slice(1);
2351
2494
  }
@@ -2357,7 +2500,7 @@ const normalizeFieldKey = field => {
2357
2500
  * @param {string} field a field name
2358
2501
  * @returns {boolean} result
2359
2502
  */
2360
- const sortOrderRegular = field => {
2503
+ const sortOrderRegular = (field) => {
2361
2504
  if (field[0] === "!") {
2362
2505
  return false;
2363
2506
  }
@@ -2366,15 +2509,15 @@ const sortOrderRegular = field => {
2366
2509
 
2367
2510
  /**
2368
2511
  * @template T
2369
- * @param {string} field field name
2370
- * @returns {function(T, T): 0 | 1 | -1} comparators
2512
+ * @param {string | false} field field name
2513
+ * @returns {(a: T, b: T) => 0 | 1 | -1} comparators
2371
2514
  */
2372
- const sortByField = field => {
2515
+ const sortByField = (field) => {
2373
2516
  if (!field) {
2374
2517
  /**
2375
- * @param {any} a first
2376
- * @param {any} b second
2377
- * @returns {-1|0|1} zero
2518
+ * @param {T} a first
2519
+ * @param {T} b second
2520
+ * @returns {-1 | 0 | 1} zero
2378
2521
  */
2379
2522
  const noSort = (a, b) => 0;
2380
2523
  return noSort;
@@ -2382,7 +2525,7 @@ const sortByField = field => {
2382
2525
 
2383
2526
  const fieldKey = normalizeFieldKey(field);
2384
2527
 
2385
- let sortFn = compareSelect(m => m[fieldKey], compareIds);
2528
+ let sortFn = compareSelect((m) => m[fieldKey], compareIds);
2386
2529
 
2387
2530
  // if a field is prefixed with a "!" the sort is reversed!
2388
2531
  const sortIsRegular = sortOrderRegular(field);
@@ -2395,17 +2538,33 @@ const sortByField = field => {
2395
2538
  return sortFn;
2396
2539
  };
2397
2540
 
2398
- /** @type {Record<string, (comparators: Comparator<TODO>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>} */
2541
+ /**
2542
+ * @typedef {{
2543
+ * assetsSort: (comparators: Comparator<Asset>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void,
2544
+ * _: (comparators: Comparator<Asset>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void
2545
+ * }} AssetSorters
2546
+ */
2547
+
2548
+ /** @type {AssetSorters} */
2399
2549
  const ASSET_SORTERS = {
2400
2550
  assetsSort: (comparators, context, { assetsSort }) => {
2401
2551
  comparators.push(sortByField(assetsSort));
2402
2552
  },
2403
- _: comparators => {
2404
- comparators.push(compareSelect(a => a.name, compareIds));
2553
+ _: (comparators) => {
2554
+ comparators.push(compareSelect((a) => a.name, compareIds));
2405
2555
  }
2406
2556
  };
2407
2557
 
2408
- /** @type {Record<string, Record<string, (comparators: Comparator<TODO>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>>} */
2558
+ /**
2559
+ * @type {{
2560
+ * "compilation.chunks": { chunksSort: (comparators: Comparator<Chunk>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void },
2561
+ * "compilation.modules": { modulesSort: (comparators: Comparator<Module>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void },
2562
+ * "chunk.modules": { chunkModulesSort: (comparators: Comparator<Module>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void },
2563
+ * "module.modules": { nestedModulesSort: (comparators: Comparator<Module>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void },
2564
+ * "compilation.assets": AssetSorters,
2565
+ * "asset.related": AssetSorters,
2566
+ * }}
2567
+ */
2409
2568
  const RESULT_SORTERS = {
2410
2569
  "compilation.chunks": {
2411
2570
  chunksSort: (comparators, context, { chunksSort }) => {
@@ -2432,9 +2591,15 @@ const RESULT_SORTERS = {
2432
2591
  };
2433
2592
 
2434
2593
  /**
2435
- * @param {Record<string, Record<string, Function>>} config the config see above
2594
+ * @template T
2595
+ * @typedef {T extends Record<string, Record<string, infer F>> ? F : never} ExtractFunction
2596
+ */
2597
+
2598
+ /**
2599
+ * @template {Record<string, Record<string, EXPECTED_ANY>>} T
2600
+ * @param {T} config the config see above
2436
2601
  * @param {NormalizedStatsOptions} options stats options
2437
- * @param {function(string, Function): void} fn handler function called for every active line in config
2602
+ * @param {(hookFor: keyof T, fn: ExtractFunction<T>) => void} fn handler function called for every active line in config
2438
2603
  * @returns {void}
2439
2604
  */
2440
2605
  const iterateConfig = (config, options, fn) => {
@@ -2450,8 +2615,9 @@ const iterateConfig = (config, options, fn) => {
2450
2615
  value === false ||
2451
2616
  value === undefined ||
2452
2617
  (Array.isArray(value) && value.length === 0)
2453
- )
2618
+ ) {
2454
2619
  continue;
2620
+ }
2455
2621
  }
2456
2622
  }
2457
2623
  fn(hookFor, subConfig[option]);
@@ -2467,6 +2633,8 @@ const ITEM_NAMES = {
2467
2633
  "compilation.namedChunkGroups[]": "chunkGroup",
2468
2634
  "compilation.errors[]": "error",
2469
2635
  "compilation.warnings[]": "warning",
2636
+ "error.errors[]": "error",
2637
+ "warning.errors[]": "error",
2470
2638
  "chunk.modules[]": "module",
2471
2639
  "chunk.rootModules[]": "module",
2472
2640
  "chunk.origins[]": "chunkOrigin",
@@ -2491,7 +2659,7 @@ const ITEM_NAMES = {
2491
2659
  * @param {T[]} items items to be merged
2492
2660
  * @returns {NamedObject<T>} an object
2493
2661
  */
2494
- const mergeToObject = items => {
2662
+ const mergeToObject = (items) => {
2495
2663
  const obj = Object.create(null);
2496
2664
  for (const item of items) {
2497
2665
  obj[item.name] = item;
@@ -2508,6 +2676,8 @@ const MERGER = {
2508
2676
  "compilation.namedChunkGroups": mergeToObject
2509
2677
  };
2510
2678
 
2679
+ const PLUGIN_NAME = "DefaultStatsFactoryPlugin";
2680
+
2511
2681
  class DefaultStatsFactoryPlugin {
2512
2682
  /**
2513
2683
  * Apply the plugin
@@ -2515,9 +2685,9 @@ class DefaultStatsFactoryPlugin {
2515
2685
  * @returns {void}
2516
2686
  */
2517
2687
  apply(compiler) {
2518
- compiler.hooks.compilation.tap("DefaultStatsFactoryPlugin", compilation => {
2688
+ compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
2519
2689
  compilation.hooks.statsFactory.tap(
2520
- "DefaultStatsFactoryPlugin",
2690
+ PLUGIN_NAME,
2521
2691
  /**
2522
2692
  * @param {StatsFactory} stats stats factory
2523
2693
  * @param {NormalizedStatsOptions} options stats options
@@ -2526,61 +2696,59 @@ class DefaultStatsFactoryPlugin {
2526
2696
  iterateConfig(SIMPLE_EXTRACTORS, options, (hookFor, fn) => {
2527
2697
  stats.hooks.extract
2528
2698
  .for(hookFor)
2529
- .tap("DefaultStatsFactoryPlugin", (obj, data, ctx) =>
2699
+ .tap(PLUGIN_NAME, (obj, data, ctx) =>
2530
2700
  fn(obj, data, ctx, options, stats)
2531
2701
  );
2532
2702
  });
2533
2703
  iterateConfig(FILTER, options, (hookFor, fn) => {
2534
2704
  stats.hooks.filter
2535
2705
  .for(hookFor)
2536
- .tap("DefaultStatsFactoryPlugin", (item, ctx, idx, i) =>
2706
+ .tap(PLUGIN_NAME, (item, ctx, idx, i) =>
2537
2707
  fn(item, ctx, options, idx, i)
2538
2708
  );
2539
2709
  });
2540
2710
  iterateConfig(FILTER_RESULTS, options, (hookFor, fn) => {
2541
2711
  stats.hooks.filterResults
2542
2712
  .for(hookFor)
2543
- .tap("DefaultStatsFactoryPlugin", (item, ctx, idx, i) =>
2713
+ .tap(PLUGIN_NAME, (item, ctx, idx, i) =>
2544
2714
  fn(item, ctx, options, idx, i)
2545
2715
  );
2546
2716
  });
2547
2717
  iterateConfig(SORTERS, options, (hookFor, fn) => {
2548
2718
  stats.hooks.sort
2549
2719
  .for(hookFor)
2550
- .tap("DefaultStatsFactoryPlugin", (comparators, ctx) =>
2720
+ .tap(PLUGIN_NAME, (comparators, ctx) =>
2551
2721
  fn(comparators, ctx, options)
2552
2722
  );
2553
2723
  });
2554
2724
  iterateConfig(RESULT_SORTERS, options, (hookFor, fn) => {
2555
2725
  stats.hooks.sortResults
2556
2726
  .for(hookFor)
2557
- .tap("DefaultStatsFactoryPlugin", (comparators, ctx) =>
2727
+ .tap(PLUGIN_NAME, (comparators, ctx) =>
2558
2728
  fn(comparators, ctx, options)
2559
2729
  );
2560
2730
  });
2561
2731
  iterateConfig(RESULT_GROUPERS, options, (hookFor, fn) => {
2562
2732
  stats.hooks.groupResults
2563
2733
  .for(hookFor)
2564
- .tap("DefaultStatsFactoryPlugin", (groupConfigs, ctx) =>
2734
+ .tap(PLUGIN_NAME, (groupConfigs, ctx) =>
2565
2735
  fn(groupConfigs, ctx, options)
2566
2736
  );
2567
2737
  });
2568
2738
  for (const key of Object.keys(ITEM_NAMES)) {
2569
2739
  const itemName = ITEM_NAMES[key];
2570
- stats.hooks.getItemName
2571
- .for(key)
2572
- .tap("DefaultStatsFactoryPlugin", () => itemName);
2740
+ stats.hooks.getItemName.for(key).tap(PLUGIN_NAME, () => itemName);
2573
2741
  }
2574
2742
  for (const key of Object.keys(MERGER)) {
2575
2743
  const merger = MERGER[key];
2576
- stats.hooks.merge.for(key).tap("DefaultStatsFactoryPlugin", merger);
2744
+ stats.hooks.merge.for(key).tap(PLUGIN_NAME, merger);
2577
2745
  }
2578
2746
  if (options.children) {
2579
2747
  if (Array.isArray(options.children)) {
2580
2748
  stats.hooks.getItemFactory
2581
2749
  .for("compilation.children[].compilation")
2582
2750
  .tap(
2583
- "DefaultStatsFactoryPlugin",
2751
+ PLUGIN_NAME,
2584
2752
  /**
2585
2753
  * @param {Compilation} comp compilation
2586
2754
  * @param {StatsFactoryContext} options options
@@ -2588,7 +2756,7 @@ class DefaultStatsFactoryPlugin {
2588
2756
  */
2589
2757
  (comp, { _index: idx }) => {
2590
2758
  const children =
2591
- /** @type {TODO} */
2759
+ /** @type {StatsValue[]} */
2592
2760
  (options.children);
2593
2761
  if (idx < children.length) {
2594
2762
  return compilation.createStatsFactory(
@@ -2603,7 +2771,7 @@ class DefaultStatsFactoryPlugin {
2603
2771
  );
2604
2772
  stats.hooks.getItemFactory
2605
2773
  .for("compilation.children[].compilation")
2606
- .tap("DefaultStatsFactoryPlugin", () => childFactory);
2774
+ .tap(PLUGIN_NAME, () => childFactory);
2607
2775
  }
2608
2776
  }
2609
2777
  }
@@ -2611,4 +2779,5 @@ class DefaultStatsFactoryPlugin {
2611
2779
  });
2612
2780
  }
2613
2781
  }
2782
+
2614
2783
  module.exports = DefaultStatsFactoryPlugin;