webpack 5.59.0 → 5.94.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (570) hide show
  1. package/README.md +48 -38
  2. package/bin/webpack.js +34 -10
  3. package/hot/dev-server.js +19 -5
  4. package/hot/lazy-compilation-node.js +13 -1
  5. package/hot/lazy-compilation-web.js +9 -0
  6. package/hot/log-apply-result.js +5 -0
  7. package/hot/log.js +23 -4
  8. package/hot/only-dev-server.js +3 -2
  9. package/hot/poll.js +5 -2
  10. package/hot/signal.js +6 -2
  11. package/lib/APIPlugin.js +226 -122
  12. package/lib/AbstractMethodError.js +10 -5
  13. package/lib/AsyncDependenciesBlock.js +13 -5
  14. package/lib/AutomaticPrefetchPlugin.js +2 -1
  15. package/lib/BannerPlugin.js +33 -12
  16. package/lib/Cache.js +16 -12
  17. package/lib/CacheFacade.js +13 -16
  18. package/lib/CaseSensitiveModulesWarning.js +8 -8
  19. package/lib/Chunk.js +60 -33
  20. package/lib/ChunkGraph.js +207 -72
  21. package/lib/ChunkGroup.js +40 -20
  22. package/lib/ChunkTemplate.js +43 -0
  23. package/lib/CleanPlugin.js +117 -32
  24. package/lib/CodeGenerationResults.js +8 -7
  25. package/lib/CommentCompilationWarning.js +0 -1
  26. package/lib/CompatibilityPlugin.js +85 -46
  27. package/lib/Compilation.js +712 -392
  28. package/lib/Compiler.js +393 -172
  29. package/lib/ConcatenationScope.js +10 -13
  30. package/lib/ConditionalInitFragment.js +22 -14
  31. package/lib/ConstPlugin.js +104 -64
  32. package/lib/ContextExclusionPlugin.js +3 -3
  33. package/lib/ContextModule.js +283 -108
  34. package/lib/ContextModuleFactory.js +151 -63
  35. package/lib/ContextReplacementPlugin.js +25 -10
  36. package/lib/CssModule.js +166 -0
  37. package/lib/DefinePlugin.js +254 -148
  38. package/lib/DelegatedModule.js +29 -6
  39. package/lib/DelegatedModuleFactoryPlugin.js +42 -22
  40. package/lib/DelegatedPlugin.js +4 -0
  41. package/lib/DependenciesBlock.js +17 -2
  42. package/lib/Dependency.js +58 -29
  43. package/lib/DependencyTemplate.js +24 -3
  44. package/lib/DependencyTemplates.js +2 -2
  45. package/lib/DllEntryPlugin.js +18 -1
  46. package/lib/DllModule.js +21 -4
  47. package/lib/DllModuleFactory.js +2 -1
  48. package/lib/DllPlugin.js +9 -7
  49. package/lib/DllReferencePlugin.js +50 -19
  50. package/lib/EntryOptionPlugin.js +6 -1
  51. package/lib/EntryPlugin.js +7 -4
  52. package/lib/Entrypoint.js +2 -2
  53. package/lib/EnvironmentNotSupportAsyncWarning.js +52 -0
  54. package/lib/EnvironmentPlugin.js +5 -2
  55. package/lib/ErrorHelpers.js +65 -26
  56. package/lib/EvalDevToolModulePlugin.js +37 -13
  57. package/lib/EvalSourceMapDevToolPlugin.js +50 -20
  58. package/lib/ExportsInfo.js +234 -133
  59. package/lib/ExportsInfoApiPlugin.js +31 -15
  60. package/lib/ExternalModule.js +391 -129
  61. package/lib/ExternalModuleFactoryPlugin.js +65 -17
  62. package/lib/FileSystemInfo.js +1038 -523
  63. package/lib/FlagAllModulesAsUsedPlugin.js +27 -27
  64. package/lib/FlagDependencyExportsPlugin.js +352 -349
  65. package/lib/FlagDependencyUsagePlugin.js +10 -10
  66. package/lib/FlagEntryExportAsUsedPlugin.js +26 -23
  67. package/lib/Generator.js +16 -8
  68. package/lib/GraphHelpers.js +3 -2
  69. package/lib/HookWebpackError.js +11 -13
  70. package/lib/HotModuleReplacementPlugin.js +221 -128
  71. package/lib/IgnoreErrorModuleFactory.js +4 -4
  72. package/lib/IgnorePlugin.js +5 -4
  73. package/lib/IgnoreWarningsPlugin.js +6 -9
  74. package/lib/InitFragment.js +39 -15
  75. package/lib/JavascriptMetaInfoPlugin.js +27 -15
  76. package/lib/LibManifestPlugin.js +45 -16
  77. package/lib/LoaderOptionsPlugin.js +13 -3
  78. package/lib/MainTemplate.js +74 -21
  79. package/lib/Module.js +155 -34
  80. package/lib/ModuleBuildError.js +13 -11
  81. package/lib/ModuleDependencyError.js +6 -4
  82. package/lib/ModuleDependencyWarning.js +6 -4
  83. package/lib/ModuleError.js +10 -5
  84. package/lib/ModuleFactory.js +4 -4
  85. package/lib/ModuleFilenameHelpers.js +164 -54
  86. package/lib/ModuleGraph.js +93 -53
  87. package/lib/ModuleGraphConnection.js +27 -13
  88. package/lib/ModuleHashingError.js +29 -0
  89. package/lib/ModuleInfoHeaderPlugin.js +92 -33
  90. package/lib/ModuleNotFoundError.js +5 -2
  91. package/lib/ModuleParseError.js +17 -9
  92. package/lib/ModuleProfile.js +1 -0
  93. package/lib/ModuleRestoreError.js +3 -1
  94. package/lib/ModuleStoreError.js +3 -2
  95. package/lib/ModuleTemplate.js +33 -1
  96. package/lib/ModuleTypeConstants.js +168 -0
  97. package/lib/ModuleWarning.js +10 -5
  98. package/lib/MultiCompiler.js +115 -38
  99. package/lib/MultiStats.js +75 -33
  100. package/lib/MultiWatching.js +6 -2
  101. package/lib/NodeStuffPlugin.js +136 -37
  102. package/lib/NormalModule.js +437 -194
  103. package/lib/NormalModuleFactory.js +313 -116
  104. package/lib/NormalModuleReplacementPlugin.js +10 -4
  105. package/lib/NullFactory.js +1 -1
  106. package/lib/OptimizationStages.js +3 -3
  107. package/lib/Parser.js +1 -1
  108. package/lib/PlatformPlugin.js +39 -0
  109. package/lib/PrefetchPlugin.js +4 -0
  110. package/lib/ProgressPlugin.js +83 -28
  111. package/lib/ProvidePlugin.js +37 -19
  112. package/lib/RawModule.js +18 -5
  113. package/lib/RecordIdsPlugin.js +8 -8
  114. package/lib/RequireJsStuffPlugin.js +22 -15
  115. package/lib/ResolverFactory.js +8 -4
  116. package/lib/RuntimeGlobals.js +99 -65
  117. package/lib/RuntimeModule.js +17 -15
  118. package/lib/RuntimePlugin.js +116 -13
  119. package/lib/RuntimeTemplate.js +304 -102
  120. package/lib/SelfModuleFactory.js +12 -0
  121. package/lib/SizeFormatHelpers.js +2 -4
  122. package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
  123. package/lib/SourceMapDevToolPlugin.js +89 -42
  124. package/lib/Stats.js +12 -7
  125. package/lib/Template.js +30 -33
  126. package/lib/TemplatedPathPlugin.js +102 -34
  127. package/lib/UseStrictPlugin.js +37 -12
  128. package/lib/WarnCaseSensitiveModulesPlugin.js +12 -0
  129. package/lib/WarnDeprecatedOptionPlugin.js +6 -0
  130. package/lib/WatchIgnorePlugin.js +46 -13
  131. package/lib/Watching.js +139 -76
  132. package/lib/WebpackError.js +14 -5
  133. package/lib/WebpackIsIncludedPlugin.js +22 -13
  134. package/lib/WebpackOptionsApply.js +162 -56
  135. package/lib/WebpackOptionsDefaulter.js +10 -3
  136. package/lib/asset/AssetGenerator.js +351 -99
  137. package/lib/asset/AssetModulesPlugin.js +57 -33
  138. package/lib/asset/AssetParser.js +15 -6
  139. package/lib/asset/AssetSourceGenerator.js +30 -10
  140. package/lib/asset/AssetSourceParser.js +8 -2
  141. package/lib/asset/RawDataUrlModule.js +162 -0
  142. package/lib/async-modules/AwaitDependenciesInitFragment.js +16 -13
  143. package/lib/async-modules/InferAsyncModulesPlugin.js +1 -1
  144. package/lib/buildChunkGraph.js +376 -420
  145. package/lib/cache/AddManagedPathsPlugin.js +6 -1
  146. package/lib/cache/IdleFileCachePlugin.js +26 -13
  147. package/lib/cache/MemoryCachePlugin.js +1 -1
  148. package/lib/cache/MemoryWithGcCachePlugin.js +13 -7
  149. package/lib/cache/PackFileCacheStrategy.js +172 -94
  150. package/lib/cache/ResolverCachePlugin.js +115 -43
  151. package/lib/cache/getLazyHashedEtag.js +2 -2
  152. package/lib/cache/mergeEtags.js +16 -21
  153. package/lib/cli.js +195 -110
  154. package/lib/config/browserslistTargetHandler.js +106 -41
  155. package/lib/config/defaults.js +572 -154
  156. package/lib/config/normalization.js +361 -322
  157. package/lib/config/target.js +105 -66
  158. package/lib/container/ContainerEntryDependency.js +2 -1
  159. package/lib/container/ContainerEntryModule.js +27 -11
  160. package/lib/container/ContainerEntryModuleFactory.js +1 -1
  161. package/lib/container/ContainerExposedDependency.js +9 -0
  162. package/lib/container/ContainerPlugin.js +18 -12
  163. package/lib/container/ContainerReferencePlugin.js +1 -1
  164. package/lib/container/FallbackDependency.js +13 -0
  165. package/lib/container/FallbackItemDependency.js +3 -0
  166. package/lib/container/FallbackModule.js +19 -8
  167. package/lib/container/FallbackModuleFactory.js +1 -1
  168. package/lib/container/ModuleFederationPlugin.js +2 -0
  169. package/lib/container/RemoteModule.js +17 -4
  170. package/lib/container/RemoteRuntimeModule.js +31 -17
  171. package/lib/container/RemoteToExternalDependency.js +3 -0
  172. package/lib/container/options.js +18 -4
  173. package/lib/css/CssExportsGenerator.js +203 -0
  174. package/lib/css/CssGenerator.js +151 -0
  175. package/lib/css/CssLoadingRuntimeModule.js +592 -0
  176. package/lib/css/CssModulesPlugin.js +888 -0
  177. package/lib/css/CssParser.js +1049 -0
  178. package/lib/css/walkCssTokens.js +775 -0
  179. package/lib/debug/ProfilingPlugin.js +102 -54
  180. package/lib/dependencies/AMDDefineDependency.js +54 -10
  181. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +204 -61
  182. package/lib/dependencies/AMDPlugin.js +44 -24
  183. package/lib/dependencies/AMDRequireArrayDependency.js +34 -10
  184. package/lib/dependencies/AMDRequireContextDependency.js +15 -0
  185. package/lib/dependencies/AMDRequireDependenciesBlock.js +6 -0
  186. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +185 -54
  187. package/lib/dependencies/AMDRequireDependency.js +21 -6
  188. package/lib/dependencies/AMDRequireItemDependency.js +6 -0
  189. package/lib/dependencies/AMDRuntimeModules.js +4 -4
  190. package/lib/dependencies/CachedConstDependency.js +22 -1
  191. package/lib/dependencies/CommonJsDependencyHelpers.js +16 -2
  192. package/lib/dependencies/CommonJsExportRequireDependency.js +77 -47
  193. package/lib/dependencies/CommonJsExportsDependency.js +28 -5
  194. package/lib/dependencies/CommonJsExportsParserPlugin.js +111 -39
  195. package/lib/dependencies/CommonJsFullRequireDependency.js +42 -8
  196. package/lib/dependencies/CommonJsImportsParserPlugin.js +530 -130
  197. package/lib/dependencies/CommonJsPlugin.js +51 -26
  198. package/lib/dependencies/CommonJsRequireContextDependency.js +23 -2
  199. package/lib/dependencies/CommonJsRequireDependency.js +9 -1
  200. package/lib/dependencies/CommonJsSelfReferenceDependency.js +22 -8
  201. package/lib/dependencies/ConstDependency.js +12 -3
  202. package/lib/dependencies/ContextDependency.js +32 -5
  203. package/lib/dependencies/ContextDependencyHelpers.js +92 -62
  204. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -1
  205. package/lib/dependencies/ContextElementDependency.js +41 -4
  206. package/lib/dependencies/CreateScriptUrlDependency.js +22 -1
  207. package/lib/dependencies/CriticalDependencyWarning.js +4 -1
  208. package/lib/dependencies/CssExportDependency.js +156 -0
  209. package/lib/dependencies/CssImportDependency.js +125 -0
  210. package/lib/dependencies/CssLocalIdentifierDependency.js +245 -0
  211. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +111 -0
  212. package/lib/dependencies/CssUrlDependency.js +164 -0
  213. package/lib/dependencies/DelegatedSourceDependency.js +3 -0
  214. package/lib/dependencies/DllEntryDependency.js +14 -0
  215. package/lib/dependencies/DynamicExports.js +15 -11
  216. package/lib/dependencies/ExportsInfoDependency.js +26 -5
  217. package/lib/dependencies/ExternalModuleDependency.js +109 -0
  218. package/lib/dependencies/ExternalModuleInitFragment.js +133 -0
  219. package/lib/dependencies/HarmonyAcceptDependency.js +11 -2
  220. package/lib/dependencies/HarmonyAcceptImportDependency.js +9 -4
  221. package/lib/dependencies/HarmonyCompatibilityDependency.js +6 -5
  222. package/lib/dependencies/HarmonyDetectionParserPlugin.js +29 -3
  223. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +152 -0
  224. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +96 -51
  225. package/lib/dependencies/HarmonyExportExpressionDependency.js +21 -4
  226. package/lib/dependencies/HarmonyExportHeaderDependency.js +13 -0
  227. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +216 -108
  228. package/lib/dependencies/HarmonyExportInitFragment.js +21 -9
  229. package/lib/dependencies/HarmonyExportSpecifierDependency.js +12 -0
  230. package/lib/dependencies/HarmonyExports.js +13 -7
  231. package/lib/dependencies/HarmonyImportDependency.js +65 -19
  232. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +268 -74
  233. package/lib/dependencies/HarmonyImportSideEffectDependency.js +11 -5
  234. package/lib/dependencies/HarmonyImportSpecifierDependency.js +180 -36
  235. package/lib/dependencies/HarmonyModulesPlugin.js +33 -5
  236. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
  237. package/lib/dependencies/ImportContextDependency.js +15 -2
  238. package/lib/dependencies/ImportDependency.js +50 -12
  239. package/lib/dependencies/ImportEagerDependency.js +11 -6
  240. package/lib/dependencies/ImportMetaContextDependency.js +42 -0
  241. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +301 -0
  242. package/lib/dependencies/ImportMetaContextPlugin.js +72 -0
  243. package/lib/dependencies/ImportMetaHotAcceptDependency.js +6 -0
  244. package/lib/dependencies/ImportMetaHotDeclineDependency.js +6 -0
  245. package/lib/dependencies/ImportMetaPlugin.js +128 -59
  246. package/lib/dependencies/ImportParserPlugin.js +153 -83
  247. package/lib/dependencies/ImportPlugin.js +21 -7
  248. package/lib/dependencies/ImportWeakDependency.js +11 -6
  249. package/lib/dependencies/JsonExportsDependency.js +38 -30
  250. package/lib/dependencies/LoaderDependency.js +14 -0
  251. package/lib/dependencies/LoaderImportDependency.js +14 -0
  252. package/lib/dependencies/LoaderPlugin.js +54 -40
  253. package/lib/dependencies/LocalModule.js +17 -1
  254. package/lib/dependencies/LocalModuleDependency.js +15 -0
  255. package/lib/dependencies/LocalModulesHelpers.js +22 -4
  256. package/lib/dependencies/ModuleDecoratorDependency.js +9 -1
  257. package/lib/dependencies/ModuleDependency.js +24 -7
  258. package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
  259. package/lib/dependencies/ModuleHotAcceptDependency.js +6 -0
  260. package/lib/dependencies/ModuleHotDeclineDependency.js +6 -0
  261. package/lib/dependencies/PrefetchDependency.js +3 -0
  262. package/lib/dependencies/ProvidedDependency.js +43 -8
  263. package/lib/dependencies/PureExpressionDependency.js +73 -39
  264. package/lib/dependencies/RequireContextDependency.js +6 -16
  265. package/lib/dependencies/RequireContextDependencyParserPlugin.js +14 -6
  266. package/lib/dependencies/RequireContextPlugin.js +20 -7
  267. package/lib/dependencies/RequireEnsureDependenciesBlock.js +7 -0
  268. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +29 -12
  269. package/lib/dependencies/RequireEnsureDependency.js +16 -2
  270. package/lib/dependencies/RequireEnsureItemDependency.js +3 -0
  271. package/lib/dependencies/RequireEnsurePlugin.js +27 -7
  272. package/lib/dependencies/RequireHeaderDependency.js +14 -1
  273. package/lib/dependencies/RequireIncludeDependency.js +6 -1
  274. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +29 -5
  275. package/lib/dependencies/RequireIncludePlugin.js +25 -5
  276. package/lib/dependencies/RequireResolveContextDependency.js +19 -2
  277. package/lib/dependencies/RequireResolveDependency.js +8 -1
  278. package/lib/dependencies/RequireResolveHeaderDependency.js +18 -0
  279. package/lib/dependencies/RuntimeRequirementsDependency.js +9 -1
  280. package/lib/dependencies/StaticExportsDependency.js +8 -0
  281. package/lib/dependencies/SystemPlugin.js +49 -22
  282. package/lib/dependencies/SystemRuntimeModule.js +1 -1
  283. package/lib/dependencies/URLDependency.js +20 -13
  284. package/lib/dependencies/URLPlugin.js +115 -27
  285. package/lib/dependencies/UnsupportedDependency.js +13 -0
  286. package/lib/dependencies/WebAssemblyExportImportedDependency.js +14 -0
  287. package/lib/dependencies/WebAssemblyImportDependency.js +9 -1
  288. package/lib/dependencies/WebpackIsIncludedDependency.js +6 -1
  289. package/lib/dependencies/WorkerDependency.js +47 -3
  290. package/lib/dependencies/WorkerPlugin.js +143 -59
  291. package/lib/dependencies/getFunctionExpression.js +9 -0
  292. package/lib/dependencies/processExportInfo.js +3 -1
  293. package/lib/electron/ElectronTargetPlugin.js +1 -0
  294. package/lib/esm/ExportWebpackRequireRuntimeModule.js +3 -2
  295. package/lib/esm/ModuleChunkFormatPlugin.js +92 -55
  296. package/lib/esm/ModuleChunkLoadingPlugin.js +12 -1
  297. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +141 -25
  298. package/lib/formatLocation.js +1 -2
  299. package/lib/hmr/HotModuleReplacement.runtime.js +37 -25
  300. package/lib/hmr/HotModuleReplacementRuntimeModule.js +2 -1
  301. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +13 -15
  302. package/lib/hmr/LazyCompilationPlugin.js +94 -41
  303. package/lib/hmr/lazyCompilationBackend.js +107 -44
  304. package/lib/ids/ChunkModuleIdRangePlugin.js +12 -3
  305. package/lib/ids/DeterministicChunkIdsPlugin.js +13 -6
  306. package/lib/ids/DeterministicModuleIdsPlugin.js +59 -35
  307. package/lib/ids/HashedModuleIdsPlugin.js +24 -16
  308. package/lib/ids/IdHelpers.js +59 -49
  309. package/lib/ids/NamedChunkIdsPlugin.js +13 -1
  310. package/lib/ids/NamedModuleIdsPlugin.js +20 -12
  311. package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
  312. package/lib/ids/OccurrenceChunkIdsPlugin.js +6 -2
  313. package/lib/ids/OccurrenceModuleIdsPlugin.js +14 -11
  314. package/lib/ids/SyncModuleIdsPlugin.js +146 -0
  315. package/lib/index.js +44 -5
  316. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +9 -7
  317. package/lib/javascript/BasicEvaluatedExpression.js +133 -19
  318. package/lib/javascript/ChunkHelpers.js +33 -0
  319. package/lib/javascript/CommonJsChunkFormatPlugin.js +18 -15
  320. package/lib/javascript/EnableChunkLoadingPlugin.js +11 -6
  321. package/lib/javascript/JavascriptGenerator.js +37 -6
  322. package/lib/javascript/JavascriptModulesPlugin.js +523 -295
  323. package/lib/javascript/JavascriptParser.js +1591 -574
  324. package/lib/javascript/JavascriptParserHelpers.js +58 -37
  325. package/lib/javascript/StartupHelpers.js +69 -47
  326. package/lib/json/JsonData.js +33 -0
  327. package/lib/json/JsonGenerator.js +29 -21
  328. package/lib/json/JsonModulesPlugin.js +13 -7
  329. package/lib/json/JsonParser.js +30 -16
  330. package/lib/library/AbstractLibraryPlugin.js +6 -2
  331. package/lib/library/AmdLibraryPlugin.js +34 -18
  332. package/lib/library/AssignLibraryPlugin.js +68 -32
  333. package/lib/library/EnableLibraryPlugin.js +39 -14
  334. package/lib/library/ExportPropertyLibraryPlugin.js +14 -5
  335. package/lib/library/JsonpLibraryPlugin.js +4 -3
  336. package/lib/library/ModernModuleLibraryPlugin.js +144 -0
  337. package/lib/library/ModuleLibraryPlugin.js +12 -7
  338. package/lib/library/SystemLibraryPlugin.js +6 -4
  339. package/lib/library/UmdLibraryPlugin.js +119 -100
  340. package/lib/logging/Logger.js +59 -6
  341. package/lib/logging/createConsoleLogger.js +25 -40
  342. package/lib/logging/runtime.js +8 -9
  343. package/lib/logging/truncateArgs.js +9 -8
  344. package/lib/node/CommonJsChunkLoadingPlugin.js +18 -2
  345. package/lib/node/NodeEnvironmentPlugin.js +14 -8
  346. package/lib/node/NodeTargetPlugin.js +7 -0
  347. package/lib/node/NodeTemplatePlugin.js +10 -2
  348. package/lib/node/NodeWatchFileSystem.js +100 -50
  349. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +51 -26
  350. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +13 -2
  351. package/lib/node/ReadFileCompileWasmPlugin.js +21 -3
  352. package/lib/node/RequireChunkLoadingRuntimeModule.js +49 -26
  353. package/lib/node/nodeConsole.js +48 -31
  354. package/lib/optimize/AggressiveMergingPlugin.js +10 -4
  355. package/lib/optimize/AggressiveSplittingPlugin.js +26 -21
  356. package/lib/optimize/ConcatenatedModule.js +353 -212
  357. package/lib/optimize/EnsureChunkConditionsPlugin.js +4 -1
  358. package/lib/optimize/FlagIncludedChunksPlugin.js +14 -8
  359. package/lib/optimize/InnerGraph.js +30 -25
  360. package/lib/optimize/InnerGraphPlugin.js +105 -64
  361. package/lib/optimize/LimitChunkCountPlugin.js +32 -9
  362. package/lib/optimize/MangleExportsPlugin.js +7 -2
  363. package/lib/optimize/MinMaxSizeWarning.js +6 -1
  364. package/lib/optimize/ModuleConcatenationPlugin.js +150 -83
  365. package/lib/optimize/RealContentHashPlugin.js +99 -43
  366. package/lib/optimize/RemoveParentModulesPlugin.js +131 -48
  367. package/lib/optimize/RuntimeChunkPlugin.js +15 -2
  368. package/lib/optimize/SideEffectsFlagPlugin.js +119 -63
  369. package/lib/optimize/SplitChunksPlugin.js +129 -78
  370. package/lib/performance/SizeLimitsPlugin.js +22 -8
  371. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +4 -2
  372. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +4 -1
  373. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +8 -5
  374. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +5 -3
  375. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +5 -3
  376. package/lib/rules/BasicEffectRulePlugin.js +7 -1
  377. package/lib/rules/BasicMatcherRulePlugin.js +8 -1
  378. package/lib/rules/ObjectMatcherRulePlugin.js +19 -2
  379. package/lib/rules/RuleSetCompiler.js +53 -32
  380. package/lib/rules/UseEffectRulePlugin.js +42 -36
  381. package/lib/runtime/AsyncModuleRuntimeModule.js +56 -69
  382. package/lib/runtime/AutoPublicPathRuntimeModule.js +25 -9
  383. package/lib/runtime/BaseUriRuntimeModule.js +35 -0
  384. package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
  385. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +5 -2
  386. package/lib/runtime/CompatRuntimeModule.js +7 -2
  387. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +7 -4
  388. package/lib/runtime/CreateScriptRuntimeModule.js +38 -0
  389. package/lib/runtime/CreateScriptUrlRuntimeModule.js +13 -36
  390. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +6 -3
  391. package/lib/runtime/EnsureChunkRuntimeModule.js +29 -15
  392. package/lib/runtime/GetChunkFilenameRuntimeModule.js +56 -43
  393. package/lib/runtime/GetFullHashRuntimeModule.js +4 -3
  394. package/lib/runtime/GetMainFilenameRuntimeModule.js +5 -2
  395. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +98 -0
  396. package/lib/runtime/GlobalRuntimeModule.js +1 -1
  397. package/lib/runtime/HasOwnPropertyRuntimeModule.js +5 -2
  398. package/lib/runtime/LoadScriptRuntimeModule.js +61 -45
  399. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +5 -2
  400. package/lib/runtime/NonceRuntimeModule.js +24 -0
  401. package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -2
  402. package/lib/runtime/PublicPathRuntimeModule.js +9 -2
  403. package/lib/runtime/RelativeUrlRuntimeModule.js +5 -2
  404. package/lib/runtime/RuntimeIdRuntimeModule.js +6 -2
  405. package/lib/runtime/StartupChunkDependenciesPlugin.js +15 -0
  406. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +36 -28
  407. package/lib/runtime/StartupEntrypointRuntimeModule.js +13 -9
  408. package/lib/runtime/SystemContextRuntimeModule.js +1 -1
  409. package/lib/schemes/DataUriPlugin.js +16 -3
  410. package/lib/schemes/HttpUriPlugin.js +336 -120
  411. package/lib/serialization/ArraySerializer.js +22 -6
  412. package/lib/serialization/BinaryMiddleware.js +212 -33
  413. package/lib/serialization/DateObjectSerializer.js +16 -4
  414. package/lib/serialization/ErrorObjectSerializer.js +23 -6
  415. package/lib/serialization/FileMiddleware.js +187 -86
  416. package/lib/serialization/MapObjectSerializer.js +25 -8
  417. package/lib/serialization/NullPrototypeObjectSerializer.js +26 -8
  418. package/lib/serialization/ObjectMiddleware.js +96 -66
  419. package/lib/serialization/PlainObjectSerializer.js +51 -14
  420. package/lib/serialization/RegExpObjectSerializer.js +17 -5
  421. package/lib/serialization/Serializer.js +23 -5
  422. package/lib/serialization/SerializerMiddleware.js +8 -8
  423. package/lib/serialization/SetObjectSerializer.js +22 -6
  424. package/lib/serialization/SingleItemMiddleware.js +2 -2
  425. package/lib/serialization/types.js +2 -2
  426. package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
  427. package/lib/sharing/ConsumeSharedModule.js +40 -17
  428. package/lib/sharing/ConsumeSharedPlugin.js +139 -102
  429. package/lib/sharing/ConsumeSharedRuntimeModule.js +144 -130
  430. package/lib/sharing/ProvideForSharedDependency.js +0 -1
  431. package/lib/sharing/ProvideSharedDependency.js +17 -0
  432. package/lib/sharing/ProvideSharedModule.js +19 -6
  433. package/lib/sharing/ProvideSharedModuleFactory.js +1 -1
  434. package/lib/sharing/ProvideSharedPlugin.js +37 -30
  435. package/lib/sharing/SharePlugin.js +2 -2
  436. package/lib/sharing/ShareRuntimeModule.js +20 -10
  437. package/lib/sharing/resolveMatchedConfigs.js +6 -5
  438. package/lib/sharing/utils.js +338 -34
  439. package/lib/stats/DefaultStatsFactoryPlugin.js +660 -396
  440. package/lib/stats/DefaultStatsPresetPlugin.js +85 -25
  441. package/lib/stats/DefaultStatsPrinterPlugin.js +525 -145
  442. package/lib/stats/StatsFactory.js +128 -57
  443. package/lib/stats/StatsPrinter.js +77 -46
  444. package/lib/util/ArrayHelpers.js +35 -1
  445. package/lib/util/ArrayQueue.js +15 -22
  446. package/lib/util/AsyncQueue.js +37 -16
  447. package/lib/util/IterableHelpers.js +3 -4
  448. package/lib/util/LazyBucketSortedSet.js +60 -44
  449. package/lib/util/LazySet.js +11 -2
  450. package/lib/util/MapHelpers.js +17 -5
  451. package/lib/util/ParallelismFactorCalculator.js +11 -1
  452. package/lib/util/Queue.js +9 -3
  453. package/lib/util/Semaphore.js +4 -7
  454. package/lib/util/SetHelpers.js +5 -5
  455. package/lib/util/SortableSet.js +19 -6
  456. package/lib/util/StackedCacheMap.js +33 -3
  457. package/lib/util/StackedMap.js +1 -3
  458. package/lib/util/StringXor.js +46 -0
  459. package/lib/util/TupleQueue.js +9 -3
  460. package/lib/util/TupleSet.js +15 -5
  461. package/lib/util/URLAbsoluteSpecifier.js +8 -8
  462. package/lib/util/WeakTupleMap.js +70 -28
  463. package/lib/util/binarySearchBounds.js +51 -9
  464. package/lib/util/chainedImports.js +97 -0
  465. package/lib/util/cleverMerge.js +51 -36
  466. package/lib/util/comparators.js +146 -83
  467. package/lib/util/compileBooleanMatcher.js +35 -7
  468. package/lib/util/conventions.js +126 -0
  469. package/lib/util/create-schema-validation.js +9 -2
  470. package/lib/util/createHash.js +49 -14
  471. package/lib/util/deprecation.js +48 -15
  472. package/lib/util/deterministicGrouping.js +71 -39
  473. package/lib/util/extractUrlAndGlobal.js +3 -0
  474. package/lib/util/findGraphRoots.js +7 -5
  475. package/lib/util/fs.js +419 -94
  476. package/lib/util/hash/BatchedHash.js +10 -4
  477. package/lib/util/hash/md4.js +20 -0
  478. package/lib/util/hash/wasm-hash.js +163 -0
  479. package/lib/util/hash/xxhash64.js +7 -141
  480. package/lib/util/identifier.js +140 -93
  481. package/lib/util/internalSerializables.js +22 -0
  482. package/lib/util/makeSerializable.js +7 -0
  483. package/lib/util/memoize.js +10 -10
  484. package/lib/util/mergeScope.js +76 -0
  485. package/lib/util/nonNumericOnlyHash.js +22 -0
  486. package/lib/util/numberHash.js +84 -34
  487. package/lib/util/objectToMap.js +0 -1
  488. package/lib/util/processAsyncTree.js +7 -1
  489. package/lib/util/propertyAccess.js +7 -55
  490. package/lib/util/propertyName.js +77 -0
  491. package/lib/util/registerExternalSerializer.js +2 -2
  492. package/lib/util/runtime.js +188 -133
  493. package/lib/util/semver.js +64 -56
  494. package/lib/util/serialization.js +26 -1
  495. package/lib/util/smartGrouping.js +10 -10
  496. package/lib/util/source.js +1 -1
  497. package/lib/validateSchema.js +6 -2
  498. package/lib/wasm/EnableWasmLoadingPlugin.js +9 -4
  499. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +70 -30
  500. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +9 -1
  501. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +34 -16
  502. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +32 -12
  503. package/lib/wasm-async/AsyncWebAssemblyParser.js +17 -4
  504. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +72 -31
  505. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +17 -6
  506. package/lib/wasm-sync/WebAssemblyGenerator.js +72 -52
  507. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -4
  508. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +53 -43
  509. package/lib/wasm-sync/WebAssemblyParser.js +23 -9
  510. package/lib/wasm-sync/WebAssemblyUtils.js +5 -4
  511. package/lib/web/FetchCompileAsyncWasmPlugin.js +11 -1
  512. package/lib/web/FetchCompileWasmPlugin.js +59 -42
  513. package/lib/web/JsonpChunkLoadingPlugin.js +9 -0
  514. package/lib/web/JsonpChunkLoadingRuntimeModule.js +71 -41
  515. package/lib/webpack.js +43 -12
  516. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +15 -12
  517. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +55 -40
  518. package/module.d.ts +233 -0
  519. package/package.json +85 -139
  520. package/schemas/WebpackOptions.check.js +1 -1
  521. package/schemas/WebpackOptions.json +679 -47
  522. package/schemas/plugins/BannerPlugin.check.js +1 -1
  523. package/schemas/plugins/BannerPlugin.json +9 -1
  524. package/schemas/plugins/DllReferencePlugin.check.js +1 -1
  525. package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
  526. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  527. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  528. package/schemas/plugins/SourceMapDevToolPlugin.json +4 -0
  529. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  530. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +1 -1
  531. package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
  532. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  533. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  534. package/schemas/plugins/container/ContainerPlugin.json +10 -1
  535. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  536. package/schemas/plugins/container/ContainerReferencePlugin.json +2 -0
  537. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  538. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  539. package/schemas/plugins/container/ModuleFederationPlugin.json +12 -1
  540. package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +7 -0
  541. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +6 -0
  542. package/schemas/plugins/css/CssAutoGeneratorOptions.json +3 -0
  543. package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +7 -0
  544. package/schemas/plugins/css/CssAutoParserOptions.check.js +6 -0
  545. package/schemas/plugins/css/CssAutoParserOptions.json +3 -0
  546. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
  547. package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
  548. package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
  549. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +7 -0
  550. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +6 -0
  551. package/schemas/plugins/css/CssGlobalGeneratorOptions.json +3 -0
  552. package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +7 -0
  553. package/schemas/plugins/css/CssGlobalParserOptions.check.js +6 -0
  554. package/schemas/plugins/css/CssGlobalParserOptions.json +3 -0
  555. package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +7 -0
  556. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +6 -0
  557. package/schemas/plugins/css/CssModuleGeneratorOptions.json +3 -0
  558. package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +7 -0
  559. package/schemas/plugins/css/CssModuleParserOptions.check.js +6 -0
  560. package/schemas/plugins/css/CssModuleParserOptions.json +3 -0
  561. package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
  562. package/schemas/plugins/css/CssParserOptions.check.js +6 -0
  563. package/schemas/plugins/css/CssParserOptions.json +3 -0
  564. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
  565. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
  566. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
  567. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  568. package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
  569. package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
  570. package/types.d.ts +5026 -1756
@@ -6,6 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  const util = require("util");
9
+ const { WEBPACK_MODULE_TYPE_RUNTIME } = require("../ModuleTypeConstants");
9
10
  const ModuleDependency = require("../dependencies/ModuleDependency");
10
11
  const formatLocation = require("../formatLocation");
11
12
  const { LogType } = require("../logging/Logger");
@@ -25,6 +26,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
25
26
 
26
27
  /** @typedef {import("webpack-sources").Source} Source */
27
28
  /** @typedef {import("../Chunk")} Chunk */
29
+ /** @typedef {import("../Chunk").ChunkId} ChunkId */
28
30
  /** @typedef {import("../ChunkGroup")} ChunkGroup */
29
31
  /** @typedef {import("../ChunkGroup").OriginRecord} OriginRecord */
30
32
  /** @typedef {import("../Compilation")} Compilation */
@@ -32,22 +34,30 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
32
34
  /** @typedef {import("../Compilation").AssetInfo} AssetInfo */
33
35
  /** @typedef {import("../Compilation").NormalizedStatsOptions} NormalizedStatsOptions */
34
36
  /** @typedef {import("../Compiler")} Compiler */
37
+ /** @typedef {import("../ChunkGraph").ModuleId} ModuleId */
35
38
  /** @typedef {import("../Dependency")} Dependency */
36
39
  /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
37
40
  /** @typedef {import("../Module")} Module */
41
+ /** @typedef {import("../Module").BuildInfo} BuildInfo */
38
42
  /** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
39
43
  /** @typedef {import("../ModuleProfile")} ModuleProfile */
40
44
  /** @typedef {import("../RequestShortener")} RequestShortener */
41
45
  /** @typedef {import("../WebpackError")} WebpackError */
42
- /** @template T @typedef {import("../util/comparators").Comparator<T>} Comparator<T> */
46
+ /** @typedef {import("../TemplatedPathPlugin").TemplatePath} TemplatePath */
47
+ /**
48
+ * @template T
49
+ * @typedef {import("../util/comparators").Comparator<T>} Comparator<T>
50
+ */
43
51
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
44
- /** @typedef {import("../util/smartGrouping").GroupConfig<any, object>} GroupConfig */
52
+ /**
53
+ * @template T, R
54
+ * @typedef {import("../util/smartGrouping").GroupConfig<T, R>} GroupConfig
55
+ */
45
56
  /** @typedef {import("./StatsFactory")} StatsFactory */
46
57
  /** @typedef {import("./StatsFactory").StatsFactoryContext} StatsFactoryContext */
47
-
48
- /** @typedef {KnownStatsCompilation & Record<string, any>} StatsCompilation */
58
+ /** @typedef {Record<string, any> & KnownStatsCompilation} StatsCompilation */
49
59
  /**
50
- * @typedef {Object} KnownStatsCompilation
60
+ * @typedef {object} KnownStatsCompilation
51
61
  * @property {any=} env
52
62
  * @property {string=} name
53
63
  * @property {string=} hash
@@ -73,28 +83,28 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
73
83
  * @property {Record<string, StatsLogging>=} logging
74
84
  */
75
85
 
76
- /** @typedef {KnownStatsLogging & Record<string, any>} StatsLogging */
86
+ /** @typedef {Record<string, any> & KnownStatsLogging} StatsLogging */
77
87
  /**
78
- * @typedef {Object} KnownStatsLogging
88
+ * @typedef {object} KnownStatsLogging
79
89
  * @property {StatsLoggingEntry[]} entries
80
90
  * @property {number} filteredEntries
81
91
  * @property {boolean} debug
82
92
  */
83
93
 
84
- /** @typedef {KnownStatsLoggingEntry & Record<string, any>} StatsLoggingEntry */
94
+ /** @typedef {Record<string, any> & KnownStatsLoggingEntry} StatsLoggingEntry */
85
95
  /**
86
- * @typedef {Object} KnownStatsLoggingEntry
96
+ * @typedef {object} KnownStatsLoggingEntry
87
97
  * @property {string} type
88
- * @property {string} message
98
+ * @property {string=} message
89
99
  * @property {string[]=} trace
90
100
  * @property {StatsLoggingEntry[]=} children
91
101
  * @property {any[]=} args
92
102
  * @property {number=} time
93
103
  */
94
104
 
95
- /** @typedef {KnownStatsAsset & Record<string, any>} StatsAsset */
105
+ /** @typedef {Record<string, any> & KnownStatsAsset} StatsAsset */
96
106
  /**
97
- * @typedef {Object} KnownStatsAsset
107
+ * @typedef {object} KnownStatsAsset
98
108
  * @property {string} type
99
109
  * @property {string} name
100
110
  * @property {AssetInfo} info
@@ -113,9 +123,9 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
113
123
  * @property {boolean=} isOverSizeLimit
114
124
  */
115
125
 
116
- /** @typedef {KnownStatsChunkGroup & Record<string, any>} StatsChunkGroup */
126
+ /** @typedef {Record<string, any> & KnownStatsChunkGroup} StatsChunkGroup */
117
127
  /**
118
- * @typedef {Object} KnownStatsChunkGroup
128
+ * @typedef {object} KnownStatsChunkGroup
119
129
  * @property {string=} name
120
130
  * @property {(string|number)[]=} chunks
121
131
  * @property {({ name: string, size?: number })[]=} assets
@@ -129,21 +139,21 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
129
139
  * @property {boolean=} isOverSizeLimit
130
140
  */
131
141
 
132
- /** @typedef {KnownStatsModule & Record<string, any>} StatsModule */
142
+ /** @typedef {Record<string, any> & KnownStatsModule} StatsModule */
133
143
  /**
134
- * @typedef {Object} KnownStatsModule
144
+ * @typedef {object} KnownStatsModule
135
145
  * @property {string=} type
136
146
  * @property {string=} moduleType
137
- * @property {string=} layer
147
+ * @property {(string | null)=} layer
138
148
  * @property {string=} identifier
139
149
  * @property {string=} name
140
- * @property {string=} nameForCondition
150
+ * @property {(string | null)=} nameForCondition
141
151
  * @property {number=} index
142
152
  * @property {number=} preOrderIndex
143
153
  * @property {number=} index2
144
154
  * @property {number=} postOrderIndex
145
155
  * @property {number=} size
146
- * @property {{[x: string]: number}=} sizes
156
+ * @property {{ [x: string]: number }=} sizes
147
157
  * @property {boolean=} cacheable
148
158
  * @property {boolean=} built
149
159
  * @property {boolean=} codeGenerated
@@ -151,31 +161,31 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
151
161
  * @property {boolean=} cached
152
162
  * @property {boolean=} optional
153
163
  * @property {boolean=} orphan
154
- * @property {string|number=} id
155
- * @property {string|number=} issuerId
156
- * @property {(string|number)[]=} chunks
157
- * @property {(string|number)[]=} assets
164
+ * @property {string | number=} id
165
+ * @property {string | number | null=} issuerId
166
+ * @property {(string | number)[]=} chunks
167
+ * @property {(string | number)[]=} assets
158
168
  * @property {boolean=} dependent
159
- * @property {string=} issuer
160
- * @property {string=} issuerName
169
+ * @property {(string | null)=} issuer
170
+ * @property {(string | null)=} issuerName
161
171
  * @property {StatsModuleIssuer[]=} issuerPath
162
172
  * @property {boolean=} failed
163
173
  * @property {number=} errors
164
174
  * @property {number=} warnings
165
175
  * @property {StatsProfile=} profile
166
176
  * @property {StatsModuleReason[]=} reasons
167
- * @property {(boolean | string[])=} usedExports
168
- * @property {string[]=} providedExports
177
+ * @property {(boolean | null | string[])=} usedExports
178
+ * @property {(string[] | null)=} providedExports
169
179
  * @property {string[]=} optimizationBailout
170
- * @property {number=} depth
180
+ * @property {(number | null)=} depth
171
181
  * @property {StatsModule[]=} modules
172
182
  * @property {number=} filteredModules
173
183
  * @property {ReturnType<Source["source"]>=} source
174
184
  */
175
185
 
176
- /** @typedef {KnownStatsProfile & Record<string, any>} StatsProfile */
186
+ /** @typedef {Record<string, any> & KnownStatsProfile} StatsProfile */
177
187
  /**
178
- * @typedef {Object} KnownStatsProfile
188
+ * @typedef {object} KnownStatsProfile
179
189
  * @property {number} total
180
190
  * @property {number} resolving
181
191
  * @property {number} restoring
@@ -188,49 +198,49 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
188
198
  * @property {number} dependencies
189
199
  */
190
200
 
191
- /** @typedef {KnownStatsModuleIssuer & Record<string, any>} StatsModuleIssuer */
201
+ /** @typedef {Record<string, any> & KnownStatsModuleIssuer} StatsModuleIssuer */
192
202
  /**
193
- * @typedef {Object} KnownStatsModuleIssuer
194
- * @property {string=} identifier
195
- * @property {string=} name
203
+ * @typedef {object} KnownStatsModuleIssuer
204
+ * @property {string} identifier
205
+ * @property {string} name
196
206
  * @property {(string|number)=} id
197
- * @property {StatsProfile=} profile
207
+ * @property {StatsProfile} profile
198
208
  */
199
209
 
200
- /** @typedef {KnownStatsModuleReason & Record<string, any>} StatsModuleReason */
210
+ /** @typedef {Record<string, any> & KnownStatsModuleReason} StatsModuleReason */
201
211
  /**
202
- * @typedef {Object} KnownStatsModuleReason
203
- * @property {string=} moduleIdentifier
204
- * @property {string=} module
205
- * @property {string=} moduleName
206
- * @property {string=} resolvedModuleIdentifier
207
- * @property {string=} resolvedModule
208
- * @property {string=} type
212
+ * @typedef {object} KnownStatsModuleReason
213
+ * @property {string | null} moduleIdentifier
214
+ * @property {string | null} module
215
+ * @property {string | null} moduleName
216
+ * @property {string | null} resolvedModuleIdentifier
217
+ * @property {string | null} resolvedModule
218
+ * @property {string | null} type
209
219
  * @property {boolean} active
210
- * @property {string=} explanation
211
- * @property {string=} userRequest
212
- * @property {string=} loc
213
- * @property {(string|number)=} moduleId
214
- * @property {(string|number)=} resolvedModuleId
220
+ * @property {string | null} explanation
221
+ * @property {string | null} userRequest
222
+ * @property {(string | null)=} loc
223
+ * @property {(string | number | null)=} moduleId
224
+ * @property {(string | number | null)=} resolvedModuleId
215
225
  */
216
226
 
217
- /** @typedef {KnownStatsChunk & Record<string, any>} StatsChunk */
227
+ /** @typedef {Record<string, any> & KnownStatsChunk} StatsChunk */
218
228
  /**
219
- * @typedef {Object} KnownStatsChunk
229
+ * @typedef {object} KnownStatsChunk
220
230
  * @property {boolean} rendered
221
231
  * @property {boolean} initial
222
232
  * @property {boolean} entry
223
233
  * @property {boolean} recorded
224
234
  * @property {string=} reason
225
235
  * @property {number} size
226
- * @property {Record<string, number>=} sizes
227
- * @property {string[]=} names
228
- * @property {string[]=} idHints
236
+ * @property {Record<string, number>} sizes
237
+ * @property {string[]} names
238
+ * @property {string[]} idHints
229
239
  * @property {string[]=} runtime
230
- * @property {string[]=} files
231
- * @property {string[]=} auxiliaryFiles
240
+ * @property {string[]} files
241
+ * @property {string[]} auxiliaryFiles
232
242
  * @property {string} hash
233
- * @property {Record<string, (string|number)[]>=} childrenByOrder
243
+ * @property {Record<string, (string|number)[]>} childrenByOrder
234
244
  * @property {(string|number)=} id
235
245
  * @property {(string|number)[]=} siblings
236
246
  * @property {(string|number)[]=} parents
@@ -240,20 +250,20 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
240
250
  * @property {StatsChunkOrigin[]=} origins
241
251
  */
242
252
 
243
- /** @typedef {KnownStatsChunkOrigin & Record<string, any>} StatsChunkOrigin */
253
+ /** @typedef {Record<string, any> & KnownStatsChunkOrigin} StatsChunkOrigin */
244
254
  /**
245
- * @typedef {Object} KnownStatsChunkOrigin
246
- * @property {string=} module
247
- * @property {string=} moduleIdentifier
248
- * @property {string=} moduleName
249
- * @property {string=} loc
250
- * @property {string=} request
251
- * @property {(string|number)=} moduleId
255
+ * @typedef {object} KnownStatsChunkOrigin
256
+ * @property {string} module
257
+ * @property {string} moduleIdentifier
258
+ * @property {string} moduleName
259
+ * @property {string} loc
260
+ * @property {string} request
261
+ * @property {(string | number)=} moduleId
252
262
  */
253
263
 
254
- /** @typedef {KnownStatsModuleTraceItem & Record<string, any>} StatsModuleTraceItem */
264
+ /** @typedef { Record<string, any> & KnownStatsModuleTraceItem} StatsModuleTraceItem */
255
265
  /**
256
- * @typedef {Object} KnownStatsModuleTraceItem
266
+ * @typedef {object} KnownStatsModuleTraceItem
257
267
  * @property {string=} originIdentifier
258
268
  * @property {string=} originName
259
269
  * @property {string=} moduleIdentifier
@@ -263,15 +273,15 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
263
273
  * @property {(string|number)=} moduleId
264
274
  */
265
275
 
266
- /** @typedef {KnownStatsModuleTraceDependency & Record<string, any>} StatsModuleTraceDependency */
276
+ /** @typedef {Record<string, any> & KnownStatsModuleTraceDependency} StatsModuleTraceDependency */
267
277
  /**
268
- * @typedef {Object} KnownStatsModuleTraceDependency
278
+ * @typedef {object} KnownStatsModuleTraceDependency
269
279
  * @property {string=} loc
270
280
  */
271
281
 
272
- /** @typedef {KnownStatsError & Record<string, any>} StatsError */
282
+ /** @typedef {Record<string, any> & KnownStatsError} StatsError */
273
283
  /**
274
- * @typedef {Object} KnownStatsError
284
+ * @typedef {object} KnownStatsError
275
285
  * @property {string} message
276
286
  * @property {string=} chunkName
277
287
  * @property {boolean=} chunkEntry
@@ -280,14 +290,14 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
280
290
  * @property {string=} moduleIdentifier
281
291
  * @property {string=} moduleName
282
292
  * @property {string=} loc
283
- * @property {string|number=} chunkId
293
+ * @property {ChunkId=} chunkId
284
294
  * @property {string|number=} moduleId
285
295
  * @property {StatsModuleTraceItem[]=} moduleTrace
286
296
  * @property {any=} details
287
297
  * @property {string=} stack
288
298
  */
289
299
 
290
- /** @typedef {Asset & { type: string, related: PreprocessedAsset[] }} PreprocessedAsset */
300
+ /** @typedef {Asset & { type: string, related: PreprocessedAsset[] | undefined }} PreprocessedAsset */
291
301
 
292
302
  /**
293
303
  * @template T
@@ -296,7 +306,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
296
306
  */
297
307
 
298
308
  /**
299
- * @typedef {Object} SimpleExtractors
309
+ * @typedef {object} SimpleExtractors
300
310
  * @property {ExtractorsByOption<Compilation, StatsCompilation>} compilation
301
311
  * @property {ExtractorsByOption<PreprocessedAsset, StatsAsset>} asset
302
312
  * @property {ExtractorsByOption<PreprocessedAsset, StatsAsset>} asset$visible
@@ -340,15 +350,14 @@ const uniqueArray = (items, selector) => {
340
350
  * @param {Comparator<I>} comparator comparator function
341
351
  * @returns {I[]} array of values
342
352
  */
343
- const uniqueOrderedArray = (items, selector, comparator) => {
344
- return uniqueArray(items, selector).sort(comparator);
345
- };
353
+ const uniqueOrderedArray = (items, selector, comparator) =>
354
+ uniqueArray(items, selector).sort(comparator);
346
355
 
347
356
  /** @template T @template R @typedef {{ [P in keyof T]: R }} MappedValues<T, R> */
348
357
 
349
358
  /**
350
- * @template T
351
- * @template R
359
+ * @template {object} T
360
+ * @template {object} R
352
361
  * @param {T} obj object to be mapped
353
362
  * @param {function(T[keyof T], keyof T): R} fn mapping function
354
363
  * @returns {MappedValues<T, R>} mapped object
@@ -356,7 +365,10 @@ const uniqueOrderedArray = (items, selector, comparator) => {
356
365
  const mapObject = (obj, fn) => {
357
366
  const newObj = Object.create(null);
358
367
  for (const key of Object.keys(obj)) {
359
- newObj[key] = fn(obj[key], /** @type {keyof T} */ (key));
368
+ newObj[key] = fn(
369
+ obj[/** @type {keyof T} */ (key)],
370
+ /** @type {keyof T} */ (key)
371
+ );
360
372
  }
361
373
  return newObj;
362
374
  };
@@ -404,10 +416,12 @@ const EXTRACT_ERROR = {
404
416
  ids: (object, error, { compilation: { chunkGraph } }) => {
405
417
  if (typeof error !== "string") {
406
418
  if (error.chunk) {
407
- object.chunkId = error.chunk.id;
419
+ object.chunkId = /** @type {ChunkId} */ (error.chunk.id);
408
420
  }
409
421
  if (error.module) {
410
- object.moduleId = chunkGraph.getModuleId(error.module);
422
+ object.moduleId =
423
+ /** @type {ModuleId} */
424
+ (chunkGraph.getModuleId(error.module));
411
425
  }
412
426
  }
413
427
  },
@@ -469,25 +483,21 @@ const SIMPLE_EXTRACTORS = {
469
483
  }
470
484
  if (!context.cachedGetErrors) {
471
485
  const map = new WeakMap();
472
- context.cachedGetErrors = compilation => {
473
- return (
474
- map.get(compilation) ||
475
- (errors => (map.set(compilation, errors), errors))(
476
- compilation.getErrors()
477
- )
486
+ context.cachedGetErrors = compilation =>
487
+ map.get(compilation) ||
488
+ // eslint-disable-next-line no-sequences
489
+ (errors => (map.set(compilation, errors), errors))(
490
+ compilation.getErrors()
478
491
  );
479
- };
480
492
  }
481
493
  if (!context.cachedGetWarnings) {
482
494
  const map = new WeakMap();
483
- context.cachedGetWarnings = compilation => {
484
- return (
485
- map.get(compilation) ||
486
- (warnings => (map.set(compilation, warnings), warnings))(
487
- compilation.getWarnings()
488
- )
495
+ context.cachedGetWarnings = compilation =>
496
+ map.get(compilation) ||
497
+ // eslint-disable-next-line no-sequences
498
+ (warnings => (map.set(compilation, warnings), warnings))(
499
+ compilation.getWarnings()
489
500
  );
490
- };
491
501
  }
492
502
  if (compilation.name) {
493
503
  object.name = compilation.name;
@@ -503,9 +513,6 @@ const SIMPLE_EXTRACTORS = {
503
513
  let acceptedTypes;
504
514
  let collapsedGroups = false;
505
515
  switch (logging) {
506
- default:
507
- acceptedTypes = new Set();
508
- break;
509
516
  case "error":
510
517
  acceptedTypes = new Set([LogType.error]);
511
518
  break;
@@ -548,6 +555,9 @@ const SIMPLE_EXTRACTORS = {
548
555
  ]);
549
556
  collapsedGroups = true;
550
557
  break;
558
+ default:
559
+ acceptedTypes = new Set();
560
+ break;
551
561
  }
552
562
  const cachedMakePathsRelative = makePathsRelative.bindContextCache(
553
563
  options.context,
@@ -580,15 +590,16 @@ const SIMPLE_EXTRACTORS = {
580
590
 
581
591
  if (type === LogType.groupEnd) {
582
592
  groupStack.pop();
583
- if (groupStack.length > 0) {
584
- currentList = groupStack[groupStack.length - 1].children;
585
- } else {
586
- currentList = rootList;
587
- }
593
+ currentList =
594
+ groupStack.length > 0
595
+ ? /** @type {KnownStatsLoggingEntry[]} */ (
596
+ groupStack[groupStack.length - 1].children
597
+ )
598
+ : rootList;
588
599
  if (depthInCollapsedGroup > 0) depthInCollapsedGroup--;
589
600
  continue;
590
601
  }
591
- let message = undefined;
602
+ let message;
592
603
  if (entry.type === LogType.time) {
593
604
  message = `${entry.args[0]}: ${
594
605
  entry.args[1] * 1000 + entry.args[2] / 1000000
@@ -635,7 +646,7 @@ const SIMPLE_EXTRACTORS = {
635
646
  }
636
647
  },
637
648
  hash: (object, compilation) => {
638
- object.hash = compilation.hash;
649
+ object.hash = /** @type {string} */ (compilation.hash);
639
650
  },
640
651
  version: object => {
641
652
  object.version = require("../../package.json").version;
@@ -644,18 +655,23 @@ const SIMPLE_EXTRACTORS = {
644
655
  object.env = _env;
645
656
  },
646
657
  timings: (object, compilation) => {
647
- object.time = compilation.endTime - compilation.startTime;
658
+ object.time =
659
+ /** @type {number} */ (compilation.endTime) -
660
+ /** @type {number} */ (compilation.startTime);
648
661
  },
649
662
  builtAt: (object, compilation) => {
650
- object.builtAt = compilation.endTime;
663
+ object.builtAt = /** @type {number} */ (compilation.endTime);
651
664
  },
652
665
  publicPath: (object, compilation) => {
653
666
  object.publicPath = compilation.getPath(
654
- compilation.outputOptions.publicPath
667
+ /** @type {TemplatePath} */
668
+ (compilation.outputOptions.publicPath)
655
669
  );
656
670
  },
657
671
  outputPath: (object, compilation) => {
658
- object.outputPath = compilation.outputOptions.path;
672
+ object.outputPath = /** @type {string} */ (
673
+ compilation.outputOptions.path
674
+ );
659
675
  },
660
676
  assets: (object, compilation, context, options, factory) => {
661
677
  const { type } = context;
@@ -740,7 +756,10 @@ const SIMPLE_EXTRACTORS = {
740
756
  compilationAuxiliaryFileToChunks
741
757
  }
742
758
  );
743
- const limited = spaceLimited(groupedAssets, options.assetsSpace);
759
+ const limited = spaceLimited(
760
+ groupedAssets,
761
+ /** @type {number} */ (options.assetsSpace)
762
+ );
744
763
  object.assets = limited.children;
745
764
  object.filteredAssets = limited.filteredChildren;
746
765
  },
@@ -811,11 +830,33 @@ const SIMPLE_EXTRACTORS = {
811
830
  },
812
831
  errors: (object, compilation, context, options, factory) => {
813
832
  const { type, cachedGetErrors } = context;
814
- object.errors = factory.create(
833
+ const rawErrors = cachedGetErrors(compilation);
834
+ const factorizedErrors = factory.create(
815
835
  `${type}.errors`,
816
836
  cachedGetErrors(compilation),
817
837
  context
818
838
  );
839
+ let filtered = 0;
840
+ if (options.errorDetails === "auto" && rawErrors.length >= 3) {
841
+ filtered = rawErrors
842
+ .map(e => typeof e !== "string" && e.details)
843
+ .filter(Boolean).length;
844
+ }
845
+ if (
846
+ options.errorDetails === true ||
847
+ !Number.isFinite(options.errorsSpace)
848
+ ) {
849
+ object.errors = factorizedErrors;
850
+ if (filtered) object.filteredErrorDetailsCount = filtered;
851
+ return;
852
+ }
853
+ const [errors, filteredBySpace] = errorsSpaceLimit(
854
+ factorizedErrors,
855
+ /** @type {number} */
856
+ (options.errorsSpace)
857
+ );
858
+ object.filteredErrorDetailsCount = filtered + filteredBySpace;
859
+ object.errors = errors;
819
860
  },
820
861
  errorsCount: (object, compilation, { cachedGetErrors }) => {
821
862
  object.errorsCount = countWithChildren(compilation, c =>
@@ -824,11 +865,32 @@ const SIMPLE_EXTRACTORS = {
824
865
  },
825
866
  warnings: (object, compilation, context, options, factory) => {
826
867
  const { type, cachedGetWarnings } = context;
827
- object.warnings = factory.create(
868
+ const rawWarnings = factory.create(
828
869
  `${type}.warnings`,
829
870
  cachedGetWarnings(compilation),
830
871
  context
831
872
  );
873
+ let filtered = 0;
874
+ if (options.errorDetails === "auto") {
875
+ filtered = cachedGetWarnings(compilation)
876
+ .map(e => typeof e !== "string" && e.details)
877
+ .filter(Boolean).length;
878
+ }
879
+ if (
880
+ options.errorDetails === true ||
881
+ !Number.isFinite(options.warningsSpace)
882
+ ) {
883
+ object.warnings = rawWarnings;
884
+ if (filtered) object.filteredWarningDetailsCount = filtered;
885
+ return;
886
+ }
887
+ const [warnings, filteredBySpace] = errorsSpaceLimit(
888
+ rawWarnings,
889
+ /** @type {number} */
890
+ (options.warningsSpace)
891
+ );
892
+ object.filteredWarningDetailsCount = filtered + filteredBySpace;
893
+ object.warnings = warnings;
832
894
  },
833
895
  warningsCount: (
834
896
  object,
@@ -839,43 +901,33 @@ const SIMPLE_EXTRACTORS = {
839
901
  ) => {
840
902
  const { type, cachedGetWarnings } = context;
841
903
  object.warningsCount = countWithChildren(compilation, (c, childType) => {
842
- if (!warningsFilter && warningsFilter.length === 0)
904
+ if (
905
+ !warningsFilter &&
906
+ /** @type {((warning: StatsError, textValue: string) => boolean)[]} */
907
+ (warningsFilter).length === 0
908
+ )
843
909
  return cachedGetWarnings(c);
844
910
  return factory
845
911
  .create(`${type}${childType}.warnings`, cachedGetWarnings(c), context)
846
- .filter(warning => {
847
- const warningString = Object.keys(warning)
848
- .map(key => `${warning[key]}`)
849
- .join("\n");
850
- return !warningsFilter.some(filter =>
851
- filter(warning, warningString)
852
- );
853
- });
912
+ .filter(
913
+ /**
914
+ * @param {TODO} warning warning
915
+ * @returns {boolean} result
916
+ */
917
+ warning => {
918
+ const warningString = Object.keys(warning)
919
+ .map(
920
+ key =>
921
+ `${warning[/** @type {keyof KnownStatsError} */ (key)]}`
922
+ )
923
+ .join("\n");
924
+ return !warningsFilter.some(filter =>
925
+ filter(warning, warningString)
926
+ );
927
+ }
928
+ );
854
929
  });
855
930
  },
856
- errorDetails: (
857
- object,
858
- compilation,
859
- { cachedGetErrors, cachedGetWarnings },
860
- { errorDetails, errors, warnings }
861
- ) => {
862
- if (errorDetails === "auto") {
863
- if (warnings) {
864
- const warnings = cachedGetWarnings(compilation);
865
- object.filteredWarningDetailsCount = warnings
866
- .map(e => typeof e !== "string" && e.details)
867
- .filter(Boolean).length;
868
- }
869
- if (errors) {
870
- const errors = cachedGetErrors(compilation);
871
- if (errors.length >= 3) {
872
- object.filteredErrorDetailsCount = errors
873
- .map(e => typeof e !== "string" && e.details)
874
- .filter(Boolean).length;
875
- }
876
- }
877
- }
878
- },
879
931
  children: (object, compilation, context, options, factory) => {
880
932
  const { type } = context;
881
933
  object.children = factory.create(
@@ -941,11 +993,12 @@ const SIMPLE_EXTRACTORS = {
941
993
  const { type } = context;
942
994
  object.related = factory.create(
943
995
  `${type.slice(0, -8)}.related`,
944
- asset.related,
996
+ asset.related || [],
945
997
  context
946
998
  );
947
999
  object.filteredRelated = asset.related
948
- ? asset.related.length - object.related.length
1000
+ ? asset.related.length -
1001
+ /** @type {StatsAsset[]} */ (object.related).length
949
1002
  : undefined;
950
1003
  },
951
1004
  ids: (
@@ -956,10 +1009,14 @@ const SIMPLE_EXTRACTORS = {
956
1009
  const chunks = compilationFileToChunks.get(asset.name) || [];
957
1010
  const auxiliaryChunks =
958
1011
  compilationAuxiliaryFileToChunks.get(asset.name) || [];
959
- object.chunks = uniqueOrderedArray(chunks, c => c.ids, compareIds);
1012
+ object.chunks = uniqueOrderedArray(
1013
+ chunks,
1014
+ c => /** @type {ChunkId[]} */ (c.ids),
1015
+ compareIds
1016
+ );
960
1017
  object.auxiliaryChunks = uniqueOrderedArray(
961
1018
  auxiliaryChunks,
962
- c => c.ids,
1019
+ c => /** @type {ChunkId[]} */ (c.ids),
963
1020
  compareIds
964
1021
  );
965
1022
  },
@@ -985,7 +1042,7 @@ const SIMPLE_EXTRACTORS = {
985
1042
  const asset = compilation.getAsset(name);
986
1043
  return {
987
1044
  name,
988
- size: asset ? asset.info.size : -1
1045
+ size: /** @type {number} */ (asset ? asset.info.size : -1)
989
1046
  };
990
1047
  };
991
1048
  /** @type {(total: number, asset: { size: number }) => number} */
@@ -1001,7 +1058,9 @@ const SIMPLE_EXTRACTORS = {
1001
1058
  /** @type {KnownStatsChunkGroup} */
1002
1059
  const statsChunkGroup = {
1003
1060
  name,
1004
- chunks: ids ? chunkGroup.chunks.map(c => c.id) : undefined,
1061
+ chunks: ids
1062
+ ? /** @type {ChunkId[]} */ (chunkGroup.chunks.map(c => c.id))
1063
+ : undefined,
1005
1064
  assets: assets.length <= chunkGroupMaxAssets ? assets : undefined,
1006
1065
  filteredAssets:
1007
1066
  assets.length <= chunkGroupMaxAssets ? 0 : assets.length,
@@ -1030,7 +1089,10 @@ const SIMPLE_EXTRACTORS = {
1030
1089
  /** @type {KnownStatsChunkGroup} */
1031
1090
  const childStatsChunkGroup = {
1032
1091
  name: group.name,
1033
- chunks: ids ? group.chunks.map(c => c.id) : undefined,
1092
+ chunks: ids
1093
+ ? /** @type {ChunkId[]} */
1094
+ (group.chunks.map(c => c.id))
1095
+ : undefined,
1034
1096
  assets:
1035
1097
  assets.length <= chunkGroupMaxAssets ? assets : undefined,
1036
1098
  filteredAssets:
@@ -1049,7 +1111,7 @@ const SIMPLE_EXTRACTORS = {
1049
1111
 
1050
1112
  return childStatsChunkGroup;
1051
1113
  })
1052
- )
1114
+ )
1053
1115
  : undefined,
1054
1116
  childAssets: children
1055
1117
  ? mapObject(children, groups => {
@@ -1063,7 +1125,7 @@ const SIMPLE_EXTRACTORS = {
1063
1125
  }
1064
1126
  }
1065
1127
  return Array.from(set);
1066
- })
1128
+ })
1067
1129
  : undefined
1068
1130
  };
1069
1131
  Object.assign(object, statsChunkGroup);
@@ -1074,7 +1136,8 @@ const SIMPLE_EXTRACTORS = {
1074
1136
  },
1075
1137
  module: {
1076
1138
  _: (object, module, context, options, factory) => {
1077
- const { compilation, type } = context;
1139
+ const { type } = context;
1140
+ const compilation = /** @type {Compilation} */ (context.compilation);
1078
1141
  const built = compilation.builtModules.has(module);
1079
1142
  const codeGenerated = compilation.codeGeneratedModules.has(module);
1080
1143
  const buildTimeExecuted =
@@ -1108,7 +1171,8 @@ const SIMPLE_EXTRACTORS = {
1108
1171
  },
1109
1172
  module$visible: {
1110
1173
  _: (object, module, context, { requestShortener }, factory) => {
1111
- const { compilation, type, rootModules } = context;
1174
+ const { type, rootModules } = context;
1175
+ const compilation = /** @type {Compilation} */ (context.compilation);
1112
1176
  const { moduleGraph } = compilation;
1113
1177
  /** @type {Module[]} */
1114
1178
  const path = [];
@@ -1135,11 +1199,15 @@ const SIMPLE_EXTRACTORS = {
1135
1199
  identifier: module.identifier(),
1136
1200
  name: module.readableIdentifier(requestShortener),
1137
1201
  nameForCondition: module.nameForCondition(),
1138
- index: moduleGraph.getPreOrderIndex(module),
1139
- preOrderIndex: moduleGraph.getPreOrderIndex(module),
1140
- index2: moduleGraph.getPostOrderIndex(module),
1141
- postOrderIndex: moduleGraph.getPostOrderIndex(module),
1142
- cacheable: module.buildInfo.cacheable,
1202
+ index: /** @type {number} */ (moduleGraph.getPreOrderIndex(module)),
1203
+ preOrderIndex: /** @type {number} */ (
1204
+ moduleGraph.getPreOrderIndex(module)
1205
+ ),
1206
+ index2: /** @type {number} */ (moduleGraph.getPostOrderIndex(module)),
1207
+ postOrderIndex: /** @type {number} */ (
1208
+ moduleGraph.getPostOrderIndex(module)
1209
+ ),
1210
+ cacheable: /** @type {BuildInfo} */ (module.buildInfo).cacheable,
1143
1211
  optional: module.isOptional(moduleGraph),
1144
1212
  orphan:
1145
1213
  !type.endsWith("module.modules[].module$visible") &&
@@ -1164,17 +1232,24 @@ const SIMPLE_EXTRACTORS = {
1164
1232
  }
1165
1233
  },
1166
1234
  ids: (object, module, { compilation: { chunkGraph, moduleGraph } }) => {
1167
- object.id = chunkGraph.getModuleId(module);
1235
+ object.id = /** @type {ModuleId} */ (chunkGraph.getModuleId(module));
1168
1236
  const issuer = moduleGraph.getIssuer(module);
1169
1237
  object.issuerId = issuer && chunkGraph.getModuleId(issuer);
1170
- object.chunks = Array.from(
1171
- chunkGraph.getOrderedModuleChunksIterable(module, compareChunksById),
1172
- chunk => chunk.id
1173
- );
1238
+ object.chunks =
1239
+ /** @type {ChunkId[]} */
1240
+ (
1241
+ Array.from(
1242
+ chunkGraph.getOrderedModuleChunksIterable(
1243
+ module,
1244
+ compareChunksById
1245
+ ),
1246
+ chunk => chunk.id
1247
+ )
1248
+ );
1174
1249
  },
1175
1250
  moduleAssets: (object, module) => {
1176
- object.assets = module.buildInfo.assets
1177
- ? Object.keys(module.buildInfo.assets)
1251
+ object.assets = /** @type {BuildInfo} */ (module.buildInfo).assets
1252
+ ? Object.keys(/** @type {BuildInfo} */ (module.buildInfo).assets)
1178
1253
  : [];
1179
1254
  },
1180
1255
  reasons: (object, module, context, options, factory) => {
@@ -1187,7 +1262,11 @@ const SIMPLE_EXTRACTORS = {
1187
1262
  Array.from(moduleGraph.getIncomingConnections(module)),
1188
1263
  context
1189
1264
  );
1190
- const limited = spaceLimited(groupsReasons, options.reasonsSpace);
1265
+ const limited = spaceLimited(
1266
+ groupsReasons,
1267
+ /** @type {number} */
1268
+ (options.reasonsSpace)
1269
+ );
1191
1270
  object.reasons = limited.children;
1192
1271
  object.filteredReasons = limited.filteredChildren;
1193
1272
  },
@@ -1280,10 +1359,11 @@ const SIMPLE_EXTRACTORS = {
1280
1359
  },
1281
1360
  moduleIssuer: {
1282
1361
  _: (object, module, context, { requestShortener }, factory) => {
1283
- const { compilation, type } = context;
1362
+ const { type } = context;
1363
+ const compilation = /** @type {Compilation} */ (context.compilation);
1284
1364
  const { moduleGraph } = compilation;
1285
1365
  const profile = moduleGraph.getProfile(module);
1286
- /** @type {KnownStatsModuleIssuer} */
1366
+ /** @type {Partial<KnownStatsModuleIssuer>} */
1287
1367
  const statsModuleIssuer = {
1288
1368
  identifier: module.identifier(),
1289
1369
  name: module.readableIdentifier(requestShortener)
@@ -1294,7 +1374,7 @@ const SIMPLE_EXTRACTORS = {
1294
1374
  }
1295
1375
  },
1296
1376
  ids: (object, module, { compilation: { chunkGraph } }) => {
1297
- object.id = chunkGraph.getModuleId(module);
1377
+ object.id = /** @type {ModuleId} */ (chunkGraph.getModuleId(module));
1298
1378
  }
1299
1379
  },
1300
1380
  moduleReason: {
@@ -1360,17 +1440,17 @@ const SIMPLE_EXTRACTORS = {
1360
1440
  chunk.runtime === undefined
1361
1441
  ? undefined
1362
1442
  : typeof chunk.runtime === "string"
1363
- ? [makePathsRelative(chunk.runtime)]
1364
- : Array.from(chunk.runtime.sort(), makePathsRelative),
1443
+ ? [makePathsRelative(chunk.runtime)]
1444
+ : Array.from(chunk.runtime.sort(), makePathsRelative),
1365
1445
  files: Array.from(chunk.files),
1366
1446
  auxiliaryFiles: Array.from(chunk.auxiliaryFiles).sort(compareIds),
1367
- hash: chunk.renderedHash,
1447
+ hash: /** @type {string} */ (chunk.renderedHash),
1368
1448
  childrenByOrder: childIdByOrder
1369
1449
  };
1370
1450
  Object.assign(object, statsChunk);
1371
1451
  },
1372
1452
  ids: (object, chunk) => {
1373
- object.id = chunk.id;
1453
+ object.id = /** @type {ChunkId} */ (chunk.id);
1374
1454
  },
1375
1455
  chunkRelations: (object, chunk, { compilation: { chunkGraph } }) => {
1376
1456
  /** @type {Set<string|number>} */
@@ -1383,16 +1463,17 @@ const SIMPLE_EXTRACTORS = {
1383
1463
  for (const chunkGroup of chunk.groupsIterable) {
1384
1464
  for (const parentGroup of chunkGroup.parentsIterable) {
1385
1465
  for (const chunk of parentGroup.chunks) {
1386
- parents.add(chunk.id);
1466
+ parents.add(/** @type {ChunkId} */ (chunk.id));
1387
1467
  }
1388
1468
  }
1389
1469
  for (const childGroup of chunkGroup.childrenIterable) {
1390
1470
  for (const chunk of childGroup.chunks) {
1391
- children.add(chunk.id);
1471
+ children.add(/** @type {ChunkId} */ (chunk.id));
1392
1472
  }
1393
1473
  }
1394
1474
  for (const sibling of chunkGroup.chunks) {
1395
- if (sibling !== chunk) siblings.add(sibling.id);
1475
+ if (sibling !== chunk)
1476
+ siblings.add(/** @type {ChunkId} */ (sibling.id));
1396
1477
  }
1397
1478
  }
1398
1479
  object.siblings = Array.from(siblings).sort(compareIds);
@@ -1454,7 +1535,7 @@ const SIMPLE_EXTRACTORS = {
1454
1535
  },
1455
1536
  ids: (object, origin, { compilation: { chunkGraph } }) => {
1456
1537
  object.moduleId = origin.module
1457
- ? chunkGraph.getModuleId(origin.module)
1538
+ ? /** @type {ModuleId} */ (chunkGraph.getModuleId(origin.module))
1458
1539
  : undefined;
1459
1540
  }
1460
1541
  },
@@ -1482,8 +1563,12 @@ const SIMPLE_EXTRACTORS = {
1482
1563
  );
1483
1564
  },
1484
1565
  ids: (object, { origin, module }, { compilation: { chunkGraph } }) => {
1485
- object.originId = chunkGraph.getModuleId(origin);
1486
- object.moduleId = chunkGraph.getModuleId(module);
1566
+ object.originId =
1567
+ /** @type {ModuleId} */
1568
+ (chunkGraph.getModuleId(origin));
1569
+ object.moduleId =
1570
+ /** @type {ModuleId} */
1571
+ (chunkGraph.getModuleId(module));
1487
1572
  }
1488
1573
  },
1489
1574
  moduleTraceDependency: {
@@ -1507,13 +1592,13 @@ const FILTER = {
1507
1592
  }
1508
1593
  };
1509
1594
 
1510
- /** @type {Record<string, Record<string, (thing: Object, context: StatsFactoryContext, options: NormalizedStatsOptions) => boolean | undefined>>} */
1595
+ /** @type {Record<string, Record<string, (thing: KnownStatsError, context: StatsFactoryContext, options: NormalizedStatsOptions) => boolean | undefined>>} */
1511
1596
  const FILTER_RESULTS = {
1512
1597
  "compilation.warnings": {
1513
1598
  warningsFilter: util.deprecate(
1514
1599
  (warning, context, { warningsFilter }) => {
1515
1600
  const warningString = Object.keys(warning)
1516
- .map(key => `${warning[key]}`)
1601
+ .map(key => `${warning[/** @type {keyof KnownStatsError} */ (key)]}`)
1517
1602
  .join("\n");
1518
1603
  return !warningsFilter.some(filter => filter(warning, warningString));
1519
1604
  },
@@ -1530,7 +1615,7 @@ const MODULES_SORTER = {
1530
1615
  compareSelect(
1531
1616
  /**
1532
1617
  * @param {Module} m module
1533
- * @returns {number} depth
1618
+ * @returns {number | null} depth
1534
1619
  */
1535
1620
  m => moduleGraph.getDepth(m),
1536
1621
  compareNumbers
@@ -1538,7 +1623,7 @@ const MODULES_SORTER = {
1538
1623
  compareSelect(
1539
1624
  /**
1540
1625
  * @param {Module} m module
1541
- * @returns {number} index
1626
+ * @returns {number | null} index
1542
1627
  */
1543
1628
  m => moduleGraph.getPreOrderIndex(m),
1544
1629
  compareNumbers
@@ -1607,17 +1692,31 @@ const SORTERS = {
1607
1692
  }
1608
1693
  };
1609
1694
 
1610
- const getItemSize = item => {
1695
+ /**
1696
+ * @template T
1697
+ * @typedef {T & { children: Children<T>[] | undefined, filteredChildren?: number }} Children
1698
+ */
1699
+
1700
+ /**
1701
+ * @template T
1702
+ * @param {Children<T>} item item
1703
+ * @returns {number} item size
1704
+ */
1705
+ const getItemSize = item =>
1611
1706
  // Each item takes 1 line
1612
1707
  // + the size of the children
1613
1708
  // + 1 extra line when it has children and filteredChildren
1614
- return !item.children
1709
+ !item.children
1615
1710
  ? 1
1616
1711
  : item.filteredChildren
1617
- ? 2 + getTotalSize(item.children)
1618
- : 1 + getTotalSize(item.children);
1619
- };
1712
+ ? 2 + getTotalSize(item.children)
1713
+ : 1 + getTotalSize(item.children);
1620
1714
 
1715
+ /**
1716
+ * @template T
1717
+ * @param {Children<T>[]} children children
1718
+ * @returns {number} total size
1719
+ */
1621
1720
  const getTotalSize = children => {
1622
1721
  let size = 0;
1623
1722
  for (const child of children) {
@@ -1626,6 +1725,11 @@ const getTotalSize = children => {
1626
1725
  return size;
1627
1726
  };
1628
1727
 
1728
+ /**
1729
+ * @template T
1730
+ * @param {Children<T>[]} children children
1731
+ * @returns {number} total items
1732
+ */
1629
1733
  const getTotalItems = children => {
1630
1734
  let count = 0;
1631
1735
  for (const child of children) {
@@ -1639,6 +1743,11 @@ const getTotalItems = children => {
1639
1743
  return count;
1640
1744
  };
1641
1745
 
1746
+ /**
1747
+ * @template T
1748
+ * @param {Children<T>[]} children children
1749
+ * @returns {Children<T>[]} collapsed children
1750
+ */
1642
1751
  const collapse = children => {
1643
1752
  // After collapse each child must take exactly one line
1644
1753
  const newChildren = [];
@@ -1658,102 +1767,217 @@ const collapse = children => {
1658
1767
  return newChildren;
1659
1768
  };
1660
1769
 
1661
- const spaceLimited = (itemsAndGroups, max) => {
1662
- /** @type {any[] | undefined} */
1663
- let children = undefined;
1770
+ /**
1771
+ * @template T
1772
+ * @param {Children<T>[]} itemsAndGroups item and groups
1773
+ * @param {number} max max
1774
+ * @param {boolean=} filteredChildrenLineReserved filtered children line reserved
1775
+ * @returns {Children<T>} result
1776
+ */
1777
+ const spaceLimited = (
1778
+ itemsAndGroups,
1779
+ max,
1780
+ filteredChildrenLineReserved = false
1781
+ ) => {
1782
+ if (max < 1) {
1783
+ return /** @type {Children<T>} */ ({
1784
+ children: undefined,
1785
+ filteredChildren: getTotalItems(itemsAndGroups)
1786
+ });
1787
+ }
1788
+ /** @type {Children<T>[] | undefined} */
1789
+ let children;
1664
1790
  /** @type {number | undefined} */
1665
- let filteredChildren = undefined;
1791
+ let filteredChildren;
1666
1792
  // This are the groups, which take 1+ lines each
1667
- const groups = itemsAndGroups.filter(c => c.children || c.filteredChildren);
1793
+ /** @type {Children<T>[] | undefined} */
1794
+ const groups = [];
1668
1795
  // The sizes of the groups are stored in groupSizes
1669
- const groupSizes = groups.map(g => getItemSize(g));
1796
+ /** @type {number[]} */
1797
+ const groupSizes = [];
1670
1798
  // This are the items, which take 1 line each
1671
- const items = itemsAndGroups.filter(c => !c.children && !c.filteredChildren);
1799
+ const items = [];
1672
1800
  // The total of group sizes
1673
- let groupsSize = groupSizes.reduce((a, b) => a + b, 0);
1801
+ let groupsSize = 0;
1802
+
1803
+ for (const itemOrGroup of itemsAndGroups) {
1804
+ // is item
1805
+ if (!itemOrGroup.children && !itemOrGroup.filteredChildren) {
1806
+ items.push(itemOrGroup);
1807
+ } else {
1808
+ groups.push(itemOrGroup);
1809
+ const size = getItemSize(itemOrGroup);
1810
+ groupSizes.push(size);
1811
+ groupsSize += size;
1812
+ }
1813
+ }
1814
+
1674
1815
  if (groupsSize + items.length <= max) {
1675
1816
  // The total size in the current state fits into the max
1676
1817
  // keep all
1677
- children = groups.concat(items);
1678
- } else if (
1679
- groups.length > 0 &&
1680
- groups.length + Math.min(1, items.length) < max
1681
- ) {
1682
- // If each group would take 1 line the total would be below the maximum
1683
- // collapse some groups, keep items
1684
- while (groupsSize + items.length + (filteredChildren ? 1 : 0) > max) {
1818
+ children = groups.length > 0 ? groups.concat(items) : items;
1819
+ } else if (groups.length === 0) {
1820
+ // slice items to max
1821
+ // inner space marks that lines for filteredChildren already reserved
1822
+ const limit = max - (filteredChildrenLineReserved ? 0 : 1);
1823
+ filteredChildren = items.length - limit;
1824
+ items.length = limit;
1825
+ children = items;
1826
+ } else {
1827
+ // limit is the size when all groups are collapsed
1828
+ const limit =
1829
+ groups.length +
1830
+ (filteredChildrenLineReserved || items.length === 0 ? 0 : 1);
1831
+ if (limit < max) {
1685
1832
  // calculate how much we are over the size limit
1686
1833
  // this allows to approach the limit faster
1687
- // it's always > 1
1688
- const oversize =
1689
- items.length + groupsSize + (filteredChildren ? 1 : 0) - max;
1690
- // Find the maximum group and process only this one
1691
- const maxGroupSize = Math.max(...groupSizes);
1692
- if (maxGroupSize < items.length) {
1693
- filteredChildren = items.length;
1694
- items.length = 0;
1695
- continue;
1834
+ let oversize;
1835
+ // If each group would take 1 line the total would be below the maximum
1836
+ // collapse some groups, keep items
1837
+ while (
1838
+ (oversize =
1839
+ groupsSize +
1840
+ items.length +
1841
+ (filteredChildren && !filteredChildrenLineReserved ? 1 : 0) -
1842
+ max) > 0
1843
+ ) {
1844
+ // Find the maximum group and process only this one
1845
+ const maxGroupSize = Math.max(...groupSizes);
1846
+ if (maxGroupSize < items.length) {
1847
+ filteredChildren = items.length;
1848
+ items.length = 0;
1849
+ continue;
1850
+ }
1851
+ for (let i = 0; i < groups.length; i++) {
1852
+ if (groupSizes[i] === maxGroupSize) {
1853
+ const group = groups[i];
1854
+ // run this algorithm recursively and limit the size of the children to
1855
+ // current size - oversize / number of groups
1856
+ // So it should always end up being smaller
1857
+ const headerSize = group.filteredChildren ? 2 : 1;
1858
+ const limited = spaceLimited(
1859
+ /** @type {Children<T>} */ (group.children),
1860
+ maxGroupSize -
1861
+ // we should use ceil to always feet in max
1862
+ Math.ceil(oversize / groups.length) -
1863
+ // we substitute size of group head
1864
+ headerSize,
1865
+ headerSize === 2
1866
+ );
1867
+ groups[i] = {
1868
+ ...group,
1869
+ children: limited.children,
1870
+ filteredChildren: limited.filteredChildren
1871
+ ? (group.filteredChildren || 0) + limited.filteredChildren
1872
+ : group.filteredChildren
1873
+ };
1874
+ const newSize = getItemSize(groups[i]);
1875
+ groupsSize -= maxGroupSize - newSize;
1876
+ groupSizes[i] = newSize;
1877
+ break;
1878
+ }
1879
+ }
1696
1880
  }
1697
- for (let i = 0; i < groups.length; i++) {
1698
- if (groupSizes[i] === maxGroupSize) {
1699
- const group = groups[i];
1700
- // run this algorithm recursively and limit the size of the children to
1701
- // current size - oversize / number of groups
1702
- // So it should always end up being smaller
1703
- const headerSize = !group.children
1704
- ? 0
1705
- : group.filteredChildren
1706
- ? 2
1707
- : 1;
1708
- const limited = spaceLimited(
1709
- group.children,
1710
- groupSizes[i] - headerSize - oversize / groups.length
1711
- );
1712
- groups[i] = {
1713
- ...group,
1714
- children: limited.children,
1715
- filteredChildren:
1716
- (group.filteredChildren || 0) + limited.filteredChildren
1717
- };
1718
- const newSize = getItemSize(groups[i]);
1719
- groupsSize -= groupSizes[i] - newSize;
1720
- groupSizes[i] = newSize;
1721
- break;
1881
+ children = groups.concat(items);
1882
+ } else if (limit === max) {
1883
+ // If we have only enough space to show one line per group and one line for the filtered items
1884
+ // collapse all groups and items
1885
+ children = collapse(groups);
1886
+ filteredChildren = items.length;
1887
+ } else {
1888
+ // If we have no space
1889
+ // collapse complete group
1890
+ filteredChildren = getTotalItems(itemsAndGroups);
1891
+ }
1892
+ }
1893
+
1894
+ return /** @type {Children<T>} */ ({ children, filteredChildren });
1895
+ };
1896
+
1897
+ /**
1898
+ * @param {StatsError[]} errors errors
1899
+ * @param {number} max max
1900
+ * @returns {[StatsError[], number]} error space limit
1901
+ */
1902
+ const errorsSpaceLimit = (errors, max) => {
1903
+ let filtered = 0;
1904
+ // Can not fit into limit
1905
+ // print only messages
1906
+ if (errors.length + 1 >= max)
1907
+ return [
1908
+ errors.map(error => {
1909
+ if (typeof error === "string" || !error.details) return error;
1910
+ filtered++;
1911
+ return { ...error, details: "" };
1912
+ }),
1913
+ filtered
1914
+ ];
1915
+ let fullLength = errors.length;
1916
+ let result = errors;
1917
+
1918
+ let i = 0;
1919
+ for (; i < errors.length; i++) {
1920
+ const error = errors[i];
1921
+ if (typeof error !== "string" && error.details) {
1922
+ const splitted = error.details.split("\n");
1923
+ const len = splitted.length;
1924
+ fullLength += len;
1925
+ if (fullLength > max) {
1926
+ result = i > 0 ? errors.slice(0, i) : [];
1927
+ const overLimit = fullLength - max + 1;
1928
+ const error = errors[i++];
1929
+ result.push({
1930
+ ...error,
1931
+ details: error.details.split("\n").slice(0, -overLimit).join("\n"),
1932
+ filteredDetails: overLimit
1933
+ });
1934
+ filtered = errors.length - i;
1935
+ for (; i < errors.length; i++) {
1936
+ const error = errors[i];
1937
+ if (typeof error === "string" || !error.details) result.push(error);
1938
+ result.push({ ...error, details: "" });
1722
1939
  }
1940
+ break;
1941
+ } else if (fullLength === max) {
1942
+ result = errors.slice(0, ++i);
1943
+ filtered = errors.length - i;
1944
+ for (; i < errors.length; i++) {
1945
+ const error = errors[i];
1946
+ if (typeof error === "string" || !error.details) result.push(error);
1947
+ result.push({ ...error, details: "" });
1948
+ }
1949
+ break;
1723
1950
  }
1724
1951
  }
1725
- children = groups.concat(items);
1726
- } else if (
1727
- groups.length > 0 &&
1728
- groups.length + Math.min(1, items.length) <= max
1729
- ) {
1730
- // If we have only enough space to show one line per group and one line for the filtered items
1731
- // collapse all groups and items
1732
- children = groups.length ? collapse(groups) : undefined;
1733
- filteredChildren = items.length;
1734
- } else {
1735
- // If we have no space
1736
- // collapse complete group
1737
- filteredChildren = getTotalItems(itemsAndGroups);
1738
1952
  }
1739
- return {
1740
- children,
1741
- filteredChildren
1742
- };
1953
+
1954
+ return [result, filtered];
1743
1955
  };
1744
1956
 
1957
+ /**
1958
+ * @template {{ size: number }} T
1959
+ * @template {{ size: number }} R
1960
+ * @param {(R | T)[]} children children
1961
+ * @param {T[]} assets assets
1962
+ * @returns {{ size: number }} asset size
1963
+ */
1745
1964
  const assetGroup = (children, assets) => {
1746
1965
  let size = 0;
1747
1966
  for (const asset of children) {
1748
1967
  size += asset.size;
1749
1968
  }
1750
- return {
1751
- size
1752
- };
1969
+ return { size };
1753
1970
  };
1754
1971
 
1972
+ /**
1973
+ * @template {{ size: number, sizes: Record<string, number> }} T
1974
+ * @param {Children<T>[]} children children
1975
+ * @param {KnownStatsModule[]} modules modules
1976
+ * @returns {{ size: number, sizes: Record<string, number>}} size and sizes
1977
+ */
1755
1978
  const moduleGroup = (children, modules) => {
1756
1979
  let size = 0;
1980
+ /** @type {Record<string, number>} */
1757
1981
  const sizes = {};
1758
1982
  for (const module of children) {
1759
1983
  size += module.size;
@@ -1767,6 +1991,12 @@ const moduleGroup = (children, modules) => {
1767
1991
  };
1768
1992
  };
1769
1993
 
1994
+ /**
1995
+ * @template {{ active: boolean }} T
1996
+ * @param {Children<T>[]} children children
1997
+ * @param {KnownStatsModuleReason[]} reasons reasons
1998
+ * @returns {{ active: boolean }} reason group
1999
+ */
1770
2000
  const reasonGroup = (children, reasons) => {
1771
2001
  let active = false;
1772
2002
  for (const reason of children) {
@@ -1777,35 +2007,39 @@ const reasonGroup = (children, reasons) => {
1777
2007
  };
1778
2008
  };
1779
2009
 
1780
- /** @type {Record<string, (groupConfigs: GroupConfig[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>} */
2010
+ const GROUP_EXTENSION_REGEXP = /(\.[^.]+?)(?:\?|(?: \+ \d+ modules?)?$)/;
2011
+ const GROUP_PATH_REGEXP = /(.+)[/\\][^/\\]+?(?:\?|(?: \+ \d+ modules?)?$)/;
2012
+
2013
+ /** @typedef {Record<string, (groupConfigs: GroupConfig<KnownStatsAsset, TODO>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>} AssetsGroupers */
2014
+
2015
+ /** @type {AssetsGroupers} */
1781
2016
  const ASSETS_GROUPERS = {
1782
2017
  _: (groupConfigs, context, options) => {
2018
+ /**
2019
+ * @param {keyof KnownStatsAsset} name name
2020
+ * @param {boolean=} exclude need exclude?
2021
+ */
1783
2022
  const groupByFlag = (name, exclude) => {
1784
2023
  groupConfigs.push({
1785
- getKeys: asset => {
1786
- return asset[name] ? ["1"] : undefined;
1787
- },
1788
- getOptions: () => {
1789
- return {
1790
- groupChildren: !exclude,
1791
- force: exclude
1792
- };
1793
- },
1794
- createGroup: (key, children, assets) => {
1795
- return exclude
2024
+ getKeys: asset => (asset[name] ? ["1"] : undefined),
2025
+ getOptions: () => ({
2026
+ groupChildren: !exclude,
2027
+ force: exclude
2028
+ }),
2029
+ createGroup: (key, children, assets) =>
2030
+ exclude
1796
2031
  ? {
1797
2032
  type: "assets by status",
1798
- [name]: !!key,
2033
+ [name]: Boolean(key),
1799
2034
  filteredChildren: assets.length,
1800
2035
  ...assetGroup(children, assets)
1801
- }
2036
+ }
1802
2037
  : {
1803
2038
  type: "assets by status",
1804
- [name]: !!key,
2039
+ [name]: Boolean(key),
1805
2040
  children,
1806
2041
  ...assetGroup(children, assets)
1807
- };
1808
- }
2042
+ }
1809
2043
  });
1810
2044
  };
1811
2045
  const {
@@ -1825,10 +2059,10 @@ const ASSETS_GROUPERS = {
1825
2059
  groupConfigs.push({
1826
2060
  getKeys: asset => {
1827
2061
  const extensionMatch =
1828
- groupAssetsByExtension && /(\.[^.]+)(?:\?.*|$)/.exec(asset.name);
2062
+ groupAssetsByExtension && GROUP_EXTENSION_REGEXP.exec(asset.name);
1829
2063
  const extension = extensionMatch ? extensionMatch[1] : "";
1830
2064
  const pathMatch =
1831
- groupAssetsByPath && /(.+)[/\\][^/\\]+(?:\?.*|$)/.exec(asset.name);
2065
+ groupAssetsByPath && GROUP_PATH_REGEXP.exec(asset.name);
1832
2066
  const path = pathMatch ? pathMatch[1].split(/[/\\]/) : [];
1833
2067
  const keys = [];
1834
2068
  if (groupAssetsByPath) {
@@ -1840,41 +2074,38 @@ const ASSETS_GROUPERS = {
1840
2074
  : `*${extension}`
1841
2075
  );
1842
2076
  while (path.length > 0) {
1843
- keys.push(path.join("/") + "/");
2077
+ keys.push(`${path.join("/")}/`);
1844
2078
  path.pop();
1845
2079
  }
1846
- } else {
1847
- if (extension) keys.push(`*${extension}`);
2080
+ } else if (extension) {
2081
+ keys.push(`*${extension}`);
1848
2082
  }
1849
2083
  return keys;
1850
2084
  },
1851
- createGroup: (key, children, assets) => {
1852
- return {
1853
- type: groupAssetsByPath ? "assets by path" : "assets by extension",
1854
- name: key,
1855
- children,
1856
- ...assetGroup(children, assets)
1857
- };
1858
- }
2085
+ createGroup: (key, children, assets) => ({
2086
+ type: groupAssetsByPath ? "assets by path" : "assets by extension",
2087
+ name: key,
2088
+ children,
2089
+ ...assetGroup(children, assets)
2090
+ })
1859
2091
  });
1860
2092
  }
1861
2093
  },
1862
2094
  groupAssetsByInfo: (groupConfigs, context, options) => {
2095
+ /**
2096
+ * @param {string} name name
2097
+ */
1863
2098
  const groupByAssetInfoFlag = name => {
1864
2099
  groupConfigs.push({
1865
- getKeys: asset => {
1866
- return asset.info && asset.info[name] ? ["1"] : undefined;
1867
- },
1868
- createGroup: (key, children, assets) => {
1869
- return {
1870
- type: "assets by info",
1871
- info: {
1872
- [name]: !!key
1873
- },
1874
- children,
1875
- ...assetGroup(children, assets)
1876
- };
1877
- }
2100
+ getKeys: asset => (asset.info && asset.info[name] ? ["1"] : undefined),
2101
+ createGroup: (key, children, assets) => ({
2102
+ type: "assets by info",
2103
+ info: {
2104
+ [name]: Boolean(key)
2105
+ },
2106
+ children,
2107
+ ...assetGroup(children, assets)
2108
+ })
1878
2109
  });
1879
2110
  };
1880
2111
  groupByAssetInfoFlag("immutable");
@@ -1882,19 +2113,18 @@ const ASSETS_GROUPERS = {
1882
2113
  groupByAssetInfoFlag("hotModuleReplacement");
1883
2114
  },
1884
2115
  groupAssetsByChunk: (groupConfigs, context, options) => {
2116
+ /**
2117
+ * @param {keyof KnownStatsAsset} name name
2118
+ */
1885
2119
  const groupByNames = name => {
1886
2120
  groupConfigs.push({
1887
- getKeys: asset => {
1888
- return asset[name];
1889
- },
1890
- createGroup: (key, children, assets) => {
1891
- return {
1892
- type: "assets by chunk",
1893
- [name]: [key],
1894
- children,
1895
- ...assetGroup(children, assets)
1896
- };
1897
- }
2121
+ getKeys: asset => /** @type {string[]} */ (asset[name]),
2122
+ createGroup: (key, children, assets) => ({
2123
+ type: "assets by chunk",
2124
+ [name]: [key],
2125
+ children,
2126
+ ...assetGroup(children, assets)
2127
+ })
1898
2128
  });
1899
2129
  };
1900
2130
  groupByNames("chunkNames");
@@ -1922,28 +2152,29 @@ const ASSETS_GROUPERS = {
1922
2152
  }
1923
2153
  };
1924
2154
 
1925
- /** @type {function("module" | "chunk" | "root-of-chunk" | "nested"): Record<string, (groupConfigs: GroupConfig[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>} */
2155
+ /** @typedef {Record<string, (groupConfigs: GroupConfig<KnownStatsModule, TODO>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>} ModulesGroupers */
2156
+
2157
+ /** @type {function("module" | "chunk" | "root-of-chunk" | "nested"): ModulesGroupers} */
1926
2158
  const MODULES_GROUPERS = type => ({
1927
2159
  _: (groupConfigs, context, options) => {
2160
+ /**
2161
+ * @param {keyof KnownStatsModule} name name
2162
+ * @param {string} type type
2163
+ * @param {boolean=} exclude need exclude?
2164
+ */
1928
2165
  const groupByFlag = (name, type, exclude) => {
1929
2166
  groupConfigs.push({
1930
- getKeys: module => {
1931
- return module[name] ? ["1"] : undefined;
1932
- },
1933
- getOptions: () => {
1934
- return {
1935
- groupChildren: !exclude,
1936
- force: exclude
1937
- };
1938
- },
1939
- createGroup: (key, children, modules) => {
1940
- return {
1941
- type,
1942
- [name]: !!key,
1943
- ...(exclude ? { filteredChildren: modules.length } : { children }),
1944
- ...moduleGroup(children, modules)
1945
- };
1946
- }
2167
+ getKeys: module => (module[name] ? ["1"] : undefined),
2168
+ getOptions: () => ({
2169
+ groupChildren: !exclude,
2170
+ force: exclude
2171
+ }),
2172
+ createGroup: (key, children, modules) => ({
2173
+ type,
2174
+ [name]: Boolean(key),
2175
+ ...(exclude ? { filteredChildren: modules.length } : { children }),
2176
+ ...moduleGroup(children, modules)
2177
+ })
1947
2178
  });
1948
2179
  };
1949
2180
  const {
@@ -1980,19 +2211,21 @@ const MODULES_GROUPERS = type => ({
1980
2211
  if (!module.moduleType) return;
1981
2212
  if (groupModulesByType) {
1982
2213
  return [module.moduleType.split("/", 1)[0]];
1983
- } else if (module.moduleType === "runtime") {
1984
- return ["runtime"];
2214
+ } else if (module.moduleType === WEBPACK_MODULE_TYPE_RUNTIME) {
2215
+ return [WEBPACK_MODULE_TYPE_RUNTIME];
1985
2216
  }
1986
2217
  },
1987
2218
  getOptions: key => {
1988
- const exclude = key === "runtime" && !options.runtimeModules;
2219
+ const exclude =
2220
+ key === WEBPACK_MODULE_TYPE_RUNTIME && !options.runtimeModules;
1989
2221
  return {
1990
2222
  groupChildren: !exclude,
1991
2223
  force: exclude
1992
2224
  };
1993
2225
  },
1994
2226
  createGroup: (key, children, modules) => {
1995
- const exclude = key === "runtime" && !options.runtimeModules;
2227
+ const exclude =
2228
+ key === WEBPACK_MODULE_TYPE_RUNTIME && !options.runtimeModules;
1996
2229
  return {
1997
2230
  type: `${key} modules`,
1998
2231
  moduleType: key,
@@ -2004,29 +2237,29 @@ const MODULES_GROUPERS = type => ({
2004
2237
  }
2005
2238
  if (groupModulesByLayer) {
2006
2239
  groupConfigs.push({
2007
- getKeys: module => {
2008
- return [module.layer];
2009
- },
2010
- createGroup: (key, children, modules) => {
2011
- return {
2012
- type: "modules by layer",
2013
- layer: key,
2014
- children,
2015
- ...moduleGroup(children, modules)
2016
- };
2017
- }
2240
+ getKeys: module => /** @type {string[]} */ ([module.layer]),
2241
+ createGroup: (key, children, modules) => ({
2242
+ type: "modules by layer",
2243
+ layer: key,
2244
+ children,
2245
+ ...moduleGroup(children, modules)
2246
+ })
2018
2247
  });
2019
2248
  }
2020
2249
  if (groupModulesByPath || groupModulesByExtension) {
2021
2250
  groupConfigs.push({
2022
2251
  getKeys: module => {
2023
2252
  if (!module.name) return;
2024
- const resource = parseResource(module.name.split("!").pop()).path;
2253
+ const resource = parseResource(
2254
+ /** @type {string} */ (module.name.split("!").pop())
2255
+ ).path;
2256
+ const dataUrl = /^data:[^,;]+/.exec(resource);
2257
+ if (dataUrl) return [dataUrl[0]];
2025
2258
  const extensionMatch =
2026
- groupModulesByExtension && /(\.[^.]+)(?:\?.*|$)/.exec(resource);
2259
+ groupModulesByExtension && GROUP_EXTENSION_REGEXP.exec(resource);
2027
2260
  const extension = extensionMatch ? extensionMatch[1] : "";
2028
2261
  const pathMatch =
2029
- groupModulesByPath && /(.+)[/\\][^/\\]+(?:\?.*|$)/.exec(resource);
2262
+ groupModulesByPath && GROUP_PATH_REGEXP.exec(resource);
2030
2263
  const path = pathMatch ? pathMatch[1].split(/[/\\]/) : [];
2031
2264
  const keys = [];
2032
2265
  if (groupModulesByPath) {
@@ -2037,20 +2270,23 @@ const MODULES_GROUPERS = type => ({
2037
2270
  : `*${extension}`
2038
2271
  );
2039
2272
  while (path.length > 0) {
2040
- keys.push(path.join("/") + "/");
2273
+ keys.push(`${path.join("/")}/`);
2041
2274
  path.pop();
2042
2275
  }
2043
- } else {
2044
- if (extension) keys.push(`*${extension}`);
2276
+ } else if (extension) {
2277
+ keys.push(`*${extension}`);
2045
2278
  }
2046
2279
  return keys;
2047
2280
  },
2048
2281
  createGroup: (key, children, modules) => {
2282
+ const isDataUrl = key.startsWith("data:");
2049
2283
  return {
2050
- type: groupModulesByPath
2051
- ? "modules by path"
2052
- : "modules by extension",
2053
- name: key,
2284
+ type: isDataUrl
2285
+ ? "modules by mime type"
2286
+ : groupModulesByPath
2287
+ ? "modules by path"
2288
+ : "modules by extension",
2289
+ name: isDataUrl ? key.slice(/* 'data:'.length */ 5) : key,
2054
2290
  children,
2055
2291
  ...moduleGroup(children, modules)
2056
2292
  };
@@ -2080,7 +2316,24 @@ const MODULES_GROUPERS = type => ({
2080
2316
  }
2081
2317
  });
2082
2318
 
2083
- /** @type {Record<string, Record<string, (groupConfigs: GroupConfig[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>>} */
2319
+ /** @typedef {Record<string, (groupConfigs: import("../util/smartGrouping").GroupConfig<KnownStatsModuleReason, TODO>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>} ModuleReasonsGroupers */
2320
+
2321
+ /** @type {ModuleReasonsGroupers} */
2322
+ const MODULE_REASONS_GROUPERS = {
2323
+ groupReasonsByOrigin: groupConfigs => {
2324
+ groupConfigs.push({
2325
+ getKeys: reason => /** @type {string[]} */ ([reason.module]),
2326
+ createGroup: (key, children, reasons) => ({
2327
+ type: "from origin",
2328
+ module: key,
2329
+ children,
2330
+ ...reasonGroup(children, reasons)
2331
+ })
2332
+ });
2333
+ }
2334
+ };
2335
+
2336
+ /** @type {Record<string, AssetsGroupers | ModulesGroupers | ModuleReasonsGroupers>} */
2084
2337
  const RESULT_GROUPERS = {
2085
2338
  "compilation.assets": ASSETS_GROUPERS,
2086
2339
  "asset.related": ASSETS_GROUPERS,
@@ -2088,34 +2341,26 @@ const RESULT_GROUPERS = {
2088
2341
  "chunk.modules": MODULES_GROUPERS("chunk"),
2089
2342
  "chunk.rootModules": MODULES_GROUPERS("root-of-chunk"),
2090
2343
  "module.modules": MODULES_GROUPERS("nested"),
2091
- "module.reasons": {
2092
- groupReasonsByOrigin: groupConfigs => {
2093
- groupConfigs.push({
2094
- getKeys: reason => {
2095
- return [reason.module];
2096
- },
2097
- createGroup: (key, children, reasons) => {
2098
- return {
2099
- type: "from origin",
2100
- module: key,
2101
- children,
2102
- ...reasonGroup(children, reasons)
2103
- };
2104
- }
2105
- });
2106
- }
2107
- }
2344
+ "module.reasons": MODULE_REASONS_GROUPERS
2108
2345
  };
2109
2346
 
2110
2347
  // remove a prefixed "!" that can be specified to reverse sort order
2348
+ /**
2349
+ * @param {string} field a field name
2350
+ * @returns {field} normalized field
2351
+ */
2111
2352
  const normalizeFieldKey = field => {
2112
2353
  if (field[0] === "!") {
2113
- return field.substr(1);
2354
+ return field.slice(1);
2114
2355
  }
2115
2356
  return field;
2116
2357
  };
2117
2358
 
2118
2359
  // if a field is prefixed by a "!" reverse sort order
2360
+ /**
2361
+ * @param {string} field a field name
2362
+ * @returns {boolean} result
2363
+ */
2119
2364
  const sortOrderRegular = field => {
2120
2365
  if (field[0] === "!") {
2121
2366
  return false;
@@ -2125,7 +2370,7 @@ const sortOrderRegular = field => {
2125
2370
 
2126
2371
  /**
2127
2372
  * @param {string} field field name
2128
- * @returns {function(Object, Object): number} comparators
2373
+ * @returns {function(object, object): 0 | 1 | -1} comparators
2129
2374
  */
2130
2375
  const sortByField = field => {
2131
2376
  if (!field) {
@@ -2153,8 +2398,8 @@ const sortByField = field => {
2153
2398
  return sortFn;
2154
2399
  };
2155
2400
 
2401
+ /** @type {Record<string, (comparators: Comparator<TODO>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>} */
2156
2402
  const ASSET_SORTERS = {
2157
- /** @type {(comparators: Function[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void} */
2158
2403
  assetsSort: (comparators, context, { assetsSort }) => {
2159
2404
  comparators.push(sortByField(assetsSort));
2160
2405
  },
@@ -2163,7 +2408,7 @@ const ASSET_SORTERS = {
2163
2408
  }
2164
2409
  };
2165
2410
 
2166
- /** @type {Record<string, Record<string, (comparators: Function[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>>} */
2411
+ /** @type {Record<string, Record<string, (comparators: Comparator<TODO>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>>} */
2167
2412
  const RESULT_SORTERS = {
2168
2413
  "compilation.chunks": {
2169
2414
  chunksSort: (comparators, context, { chunksSort }) => {
@@ -2240,8 +2485,14 @@ const ITEM_NAMES = {
2240
2485
  };
2241
2486
 
2242
2487
  /**
2243
- * @param {Object[]} items items to be merged
2244
- * @returns {Object} an object
2488
+ * @template T
2489
+ * @typedef {{ name: T }} NamedObject
2490
+ */
2491
+
2492
+ /**
2493
+ * @template {{ name: string }} T
2494
+ * @param {T[]} items items to be merged
2495
+ * @returns {NamedObject<T>} an object
2245
2496
  */
2246
2497
  const mergeToObject = items => {
2247
2498
  const obj = Object.create(null);
@@ -2251,7 +2502,10 @@ const mergeToObject = items => {
2251
2502
  return obj;
2252
2503
  };
2253
2504
 
2254
- /** @type {Record<string, (items: Object[]) => any>} */
2505
+ /**
2506
+ * @template {{ name: string }} T
2507
+ * @type {Record<string, (items: T[]) => NamedObject<T>>}
2508
+ */
2255
2509
  const MERGER = {
2256
2510
  "compilation.entrypoints": mergeToObject,
2257
2511
  "compilation.namedChunkGroups": mergeToObject
@@ -2267,7 +2521,11 @@ class DefaultStatsFactoryPlugin {
2267
2521
  compiler.hooks.compilation.tap("DefaultStatsFactoryPlugin", compilation => {
2268
2522
  compilation.hooks.statsFactory.tap(
2269
2523
  "DefaultStatsFactoryPlugin",
2270
- (stats, options, context) => {
2524
+ /**
2525
+ * @param {StatsFactory} stats stats factory
2526
+ * @param {NormalizedStatsOptions} options stats options
2527
+ */
2528
+ (stats, options) => {
2271
2529
  iterateConfig(SIMPLE_EXTRACTORS, options, (hookFor, fn) => {
2272
2530
  stats.hooks.extract
2273
2531
  .for(hookFor)
@@ -2324,25 +2582,31 @@ class DefaultStatsFactoryPlugin {
2324
2582
  if (Array.isArray(options.children)) {
2325
2583
  stats.hooks.getItemFactory
2326
2584
  .for("compilation.children[].compilation")
2327
- .tap("DefaultStatsFactoryPlugin", (comp, { _index: idx }) => {
2328
- if (idx < options.children.length) {
2329
- return compilation.createStatsFactory(
2330
- compilation.createStatsOptions(
2331
- options.children[idx],
2332
- context
2333
- )
2334
- );
2585
+ .tap(
2586
+ "DefaultStatsFactoryPlugin",
2587
+ /**
2588
+ * @param {Compilation} comp compilation
2589
+ * @param {StatsFactoryContext} options options
2590
+ * @returns {StatsFactory | undefined} stats factory
2591
+ */
2592
+ (comp, { _index: idx }) => {
2593
+ const children =
2594
+ /** @type {TODO} */
2595
+ (options.children);
2596
+ if (idx < children.length) {
2597
+ return compilation.createStatsFactory(
2598
+ compilation.createStatsOptions(children[idx])
2599
+ );
2600
+ }
2335
2601
  }
2336
- });
2602
+ );
2337
2603
  } else if (options.children !== true) {
2338
2604
  const childFactory = compilation.createStatsFactory(
2339
- compilation.createStatsOptions(options.children, context)
2605
+ compilation.createStatsOptions(options.children)
2340
2606
  );
2341
2607
  stats.hooks.getItemFactory
2342
2608
  .for("compilation.children[].compilation")
2343
- .tap("DefaultStatsFactoryPlugin", () => {
2344
- return childFactory;
2345
- });
2609
+ .tap("DefaultStatsFactoryPlugin", () => childFactory);
2346
2610
  }
2347
2611
  }
2348
2612
  }