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,16 +6,27 @@
6
6
  "use strict";
7
7
 
8
8
  /** @typedef {import("../Compiler")} Compiler */
9
+ /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsChunkGroup} KnownStatsChunkGroup */
9
10
  /** @typedef {import("./StatsPrinter")} StatsPrinter */
11
+ /** @typedef {import("./StatsPrinter").KnownStatsPrinterColorFn} KnownStatsPrinterColorFn */
12
+ /** @typedef {import("./StatsPrinter").KnownStatsPrinterFormaters} KnownStatsPrinterFormaters */
10
13
  /** @typedef {import("./StatsPrinter").StatsPrinterContext} StatsPrinterContext */
11
14
 
15
+ const DATA_URI_CONTENT_LENGTH = 16;
16
+ const MAX_MODULE_IDENTIFIER_LENGTH = 80;
17
+
18
+ /**
19
+ * @param {number} n a number
20
+ * @param {string} singular singular
21
+ * @param {string} plural plural
22
+ * @returns {string} if n is 1, singular, else plural
23
+ */
12
24
  const plural = (n, singular, plural) => (n === 1 ? singular : plural);
13
25
 
14
26
  /**
15
27
  * @param {Record<string, number>} sizes sizes by source type
16
- * @param {Object} options options
17
- * @param {(number) => string=} options.formatSize size formatter
18
- * @returns {string} text
28
+ * @param {StatsPrinterContext} options options
29
+ * @returns {string | undefined} text
19
30
  */
20
31
  const printSizes = (sizes, { formatSize = n => `${n}` }) => {
21
32
  const keys = Object.keys(sizes);
@@ -26,6 +37,51 @@ const printSizes = (sizes, { formatSize = n => `${n}` }) => {
26
37
  }
27
38
  };
28
39
 
40
+ /**
41
+ * @param {string} resource resource
42
+ * @returns {string} resource name for display
43
+ */
44
+ const getResourceName = resource => {
45
+ const dataUrl = /^data:[^,]+,/.exec(resource);
46
+ if (!dataUrl) return resource;
47
+
48
+ const len = dataUrl[0].length + DATA_URI_CONTENT_LENGTH;
49
+ if (resource.length < len) return resource;
50
+ return `${resource.slice(
51
+ 0,
52
+ Math.min(resource.length - /* '..'.length */ 2, len)
53
+ )}..`;
54
+ };
55
+
56
+ /**
57
+ * @param {string} name module name
58
+ * @returns {[string,string]} prefix and module name
59
+ */
60
+ const getModuleName = name => {
61
+ const [, prefix, resource] =
62
+ /** @type {[any, string, string]} */
63
+ (/** @type {unknown} */ (/^(.*!)?([^!]*)$/.exec(name)));
64
+
65
+ if (resource.length > MAX_MODULE_IDENTIFIER_LENGTH) {
66
+ const truncatedResource = `${resource.slice(
67
+ 0,
68
+ Math.min(
69
+ resource.length - /* '...(truncated)'.length */ 14,
70
+ MAX_MODULE_IDENTIFIER_LENGTH
71
+ )
72
+ )}...(truncated)`;
73
+
74
+ return [prefix, getResourceName(truncatedResource)];
75
+ }
76
+
77
+ return [prefix, getResourceName(resource)];
78
+ };
79
+
80
+ /**
81
+ * @param {string} str string
82
+ * @param {function(string): string} fn function to apply to each line
83
+ * @returns {string} joined string
84
+ */
29
85
  const mapLines = (str, fn) => str.split("\n").map(fn).join("\n");
30
86
 
31
87
  /**
@@ -34,12 +90,29 @@ const mapLines = (str, fn) => str.split("\n").map(fn).join("\n");
34
90
  */
35
91
  const twoDigit = n => (n >= 10 ? `${n}` : `0${n}`);
36
92
 
37
- const isValidId = id => {
38
- return typeof id === "number" || id;
39
- };
93
+ /**
94
+ * @param {string | number} id an id
95
+ * @returns {boolean | string} is i
96
+ */
97
+ const isValidId = id => typeof id === "number" || id;
98
+
99
+ /**
100
+ * @template T
101
+ * @param {Array<T> | undefined} list of items
102
+ * @param {number} count number of items to show
103
+ * @returns {string} string representation of list
104
+ */
105
+ const moreCount = (list, count) =>
106
+ list && list.length > 0 ? `+ ${count}` : `${count}`;
40
107
 
41
- /** @type {Record<string, (thing: any, context: StatsPrinterContext, printer: StatsPrinter) => string | void>} */
42
- const SIMPLE_PRINTERS = {
108
+ /**
109
+ * @template T
110
+ * @template {keyof T} K
111
+ * @typedef {{ [P in K]-?: T[P] }} WithRequired
112
+ */
113
+
114
+ /** @type {Record<string, (thing: any, context: Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormaters> & WithRequired<StatsPrinterContext, "type" | "compilation">, printer: StatsPrinter) => string | undefined>} */
115
+ const COMPILATION_SIMPLE_PRINTERS = {
43
116
  "compilation.summary!": (
44
117
  _,
45
118
  {
@@ -63,14 +136,16 @@ const SIMPLE_PRINTERS = {
63
136
  ) => {
64
137
  const root = type === "compilation.summary!";
65
138
  const warningsMessage =
66
- warningsCount > 0
139
+ /** @type {number} */ (warningsCount) > 0
67
140
  ? yellow(
68
- `${warningsCount} ${plural(warningsCount, "warning", "warnings")}`
69
- )
141
+ `${warningsCount} ${plural(/** @type {number} */ (warningsCount), "warning", "warnings")}`
142
+ )
70
143
  : "";
71
144
  const errorsMessage =
72
- errorsCount > 0
73
- ? red(`${errorsCount} ${plural(errorsCount, "error", "errors")}`)
145
+ /** @type {number} */ (errorsCount) > 0
146
+ ? red(
147
+ `${errorsCount} ${plural(/** @type {number} */ (errorsCount), "error", "errors")}`
148
+ )
74
149
  : "";
75
150
  const timeMessage = root && time ? ` in ${formatTime(time)}` : "";
76
151
  const hashMessage = hash ? ` (${hash})` : "";
@@ -81,10 +156,10 @@ const SIMPLE_PRINTERS = {
81
156
  root && name
82
157
  ? bold(name)
83
158
  : name
84
- ? `Child ${bold(name)}`
85
- : root
86
- ? ""
87
- : "Child";
159
+ ? `Child ${bold(name)}`
160
+ : root
161
+ ? ""
162
+ : "Child";
88
163
  const subjectMessage =
89
164
  nameMessage && versionMessage
90
165
  ? `${nameMessage} (${versionMessage})`
@@ -99,7 +174,7 @@ const SIMPLE_PRINTERS = {
99
174
  } else if (errorsCount === 0 && warningsCount === 0) {
100
175
  statusMessage = `compiled ${green("successfully")}`;
101
176
  } else {
102
- statusMessage = `compiled`;
177
+ statusMessage = "compiled";
103
178
  }
104
179
  if (
105
180
  builtAtMessage ||
@@ -118,7 +193,7 @@ const SIMPLE_PRINTERS = {
118
193
  count,
119
194
  "warning has",
120
195
  "warnings have"
121
- )} detailed information that is not shown.\nUse 'stats.errorDetails: true' resp. '--stats-error-details' to show it.`
196
+ )} detailed information that is not shown.\nUse 'stats.errorDetails: true' resp. '--stats-error-details' to show it.`
122
197
  : undefined,
123
198
  "compilation.filteredErrorDetailsCount": (count, { yellow }) =>
124
199
  count
@@ -128,7 +203,7 @@ const SIMPLE_PRINTERS = {
128
203
  "error has",
129
204
  "errors have"
130
205
  )} detailed information that is not shown.\nUse 'stats.errorDetails: true' resp. '--stats-error-details' to show it.`
131
- )
206
+ )
132
207
  : undefined,
133
208
  "compilation.env": (env, { bold }) =>
134
209
  env
@@ -142,7 +217,7 @@ const SIMPLE_PRINTERS = {
142
217
  : printer.print(context.type, Object.values(entrypoints), {
143
218
  ...context,
144
219
  chunkGroupKind: "Entrypoint"
145
- }),
220
+ }),
146
221
  "compilation.namedChunkGroups": (namedChunkGroups, context, printer) => {
147
222
  if (!Array.isArray(namedChunkGroups)) {
148
223
  const {
@@ -163,13 +238,27 @@ const SIMPLE_PRINTERS = {
163
238
  },
164
239
  "compilation.assetsByChunkName": () => "",
165
240
 
166
- "compilation.filteredModules": filteredModules =>
241
+ "compilation.filteredModules": (
242
+ filteredModules,
243
+ { compilation: { modules } }
244
+ ) =>
167
245
  filteredModules > 0
168
- ? `${filteredModules} ${plural(filteredModules, "module", "modules")}`
246
+ ? `${moreCount(modules, filteredModules)} ${plural(
247
+ filteredModules,
248
+ "module",
249
+ "modules"
250
+ )}`
169
251
  : undefined,
170
- "compilation.filteredAssets": (filteredAssets, { compilation: { assets } }) =>
252
+ "compilation.filteredAssets": (
253
+ filteredAssets,
254
+ { compilation: { assets } }
255
+ ) =>
171
256
  filteredAssets > 0
172
- ? `${filteredAssets} ${plural(filteredAssets, "asset", "assets")}`
257
+ ? `${moreCount(assets, filteredAssets)} ${plural(
258
+ filteredAssets,
259
+ "asset",
260
+ "assets"
261
+ )}`
173
262
  : undefined,
174
263
  "compilation.logging": (logging, context, printer) =>
175
264
  Array.isArray(logging)
@@ -178,15 +267,16 @@ const SIMPLE_PRINTERS = {
178
267
  context.type,
179
268
  Object.entries(logging).map(([name, value]) => ({ ...value, name })),
180
269
  context
181
- ),
270
+ ),
182
271
  "compilation.warningsInChildren!": (_, { yellow, compilation }) => {
183
272
  if (
184
273
  !compilation.children &&
185
- compilation.warningsCount > 0 &&
274
+ /** @type {number} */ (compilation.warningsCount) > 0 &&
186
275
  compilation.warnings
187
276
  ) {
188
277
  const childWarnings =
189
- compilation.warningsCount - compilation.warnings.length;
278
+ /** @type {number} */ (compilation.warningsCount) -
279
+ compilation.warnings.length;
190
280
  if (childWarnings > 0) {
191
281
  return yellow(
192
282
  `${childWarnings} ${plural(
@@ -205,10 +295,12 @@ const SIMPLE_PRINTERS = {
205
295
  "compilation.errorsInChildren!": (_, { red, compilation }) => {
206
296
  if (
207
297
  !compilation.children &&
208
- compilation.errorsCount > 0 &&
298
+ /** @type {number} */ (compilation.errorsCount) > 0 &&
209
299
  compilation.errors
210
300
  ) {
211
- const childErrors = compilation.errorsCount - compilation.errors.length;
301
+ const childErrors =
302
+ /** @type {number} */ (compilation.errorsCount) -
303
+ compilation.errors.length;
212
304
  if (childErrors > 0) {
213
305
  return red(
214
306
  `${childErrors} ${plural(
@@ -223,15 +315,16 @@ const SIMPLE_PRINTERS = {
223
315
  );
224
316
  }
225
317
  }
226
- },
318
+ }
319
+ };
227
320
 
321
+ /** @type {Record<string, (thing: any, context: Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormaters> & WithRequired<StatsPrinterContext, "type" | "compilation" | "asset">, printer: StatsPrinter) => string | undefined>} */
322
+ const ASSET_SIMPLE_PRINTERS = {
228
323
  "asset.type": type => type,
229
324
  "asset.name": (name, { formatFilename, asset: { isOverSizeLimit } }) =>
230
325
  formatFilename(name, isOverSizeLimit),
231
- "asset.size": (
232
- size,
233
- { asset: { isOverSizeLimit }, yellow, green, formatSize }
234
- ) => (isOverSizeLimit ? yellow(formatSize(size)) : formatSize(size)),
326
+ "asset.size": (size, { asset: { isOverSizeLimit }, yellow, formatSize }) =>
327
+ isOverSizeLimit ? yellow(formatSize(size)) : formatSize(size),
235
328
  "asset.emitted": (emitted, { green, formatFlag }) =>
236
329
  emitted ? green(formatFlag("emitted")) : undefined,
237
330
  "asset.comparedForEmit": (comparedForEmit, { yellow, formatFlag }) =>
@@ -251,7 +344,7 @@ const SIMPLE_PRINTERS = {
251
344
  sourceFilename === true
252
345
  ? "from source file"
253
346
  : `from: ${sourceFilename}`
254
- )
347
+ )
255
348
  : undefined,
256
349
  "asset.info.development": (development, { green, formatFlag }) =>
257
350
  development ? green(formatFlag("dev")) : undefined,
@@ -262,28 +355,35 @@ const SIMPLE_PRINTERS = {
262
355
  "asset.separator!": () => "\n",
263
356
  "asset.filteredRelated": (filteredRelated, { asset: { related } }) =>
264
357
  filteredRelated > 0
265
- ? `${filteredRelated} related ${plural(
358
+ ? `${moreCount(related, filteredRelated)} related ${plural(
266
359
  filteredRelated,
267
360
  "asset",
268
361
  "assets"
269
- )}`
362
+ )}`
270
363
  : undefined,
271
- "asset.filteredChildren": filteredChildren =>
364
+ "asset.filteredChildren": (filteredChildren, { asset: { children } }) =>
272
365
  filteredChildren > 0
273
- ? `${filteredChildren} ${plural(filteredChildren, "asset", "assets")}`
366
+ ? `${moreCount(children, filteredChildren)} ${plural(
367
+ filteredChildren,
368
+ "asset",
369
+ "assets"
370
+ )}`
274
371
  : undefined,
275
372
 
276
373
  assetChunk: (id, { formatChunkId }) => formatChunkId(id),
277
374
 
278
375
  assetChunkName: name => name,
279
- assetChunkIdHint: name => name,
376
+ assetChunkIdHint: name => name
377
+ };
280
378
 
379
+ /** @type {Record<string, (thing: any, context: Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormaters> & WithRequired<StatsPrinterContext, "type" | "compilation" | "module">, printer: StatsPrinter) => string | undefined>} */
380
+ const MODULE_SIMPLE_PRINTERS = {
281
381
  "module.type": type => (type !== "module" ? type : undefined),
282
382
  "module.id": (id, { formatModuleId }) =>
283
383
  isValidId(id) ? formatModuleId(id) : undefined,
284
384
  "module.name": (name, { bold }) => {
285
- const [, prefix, resource] = /^(.*!)?([^!]*)$/.exec(name);
286
- return (prefix || "") + bold(resource);
385
+ const [prefix, resource] = getModuleName(name);
386
+ return `${prefix || ""}${bold(resource || "")}`;
287
387
  },
288
388
  "module.identifier": identifier => undefined,
289
389
  "module.layer": (layer, { formatLayer }) =>
@@ -316,22 +416,22 @@ const SIMPLE_PRINTERS = {
316
416
  formatFlag(
317
417
  `${assets.length} ${plural(assets.length, "asset", "assets")}`
318
418
  )
319
- )
419
+ )
320
420
  : undefined,
321
421
  "module.warnings": (warnings, { formatFlag, yellow }) =>
322
422
  warnings === true
323
423
  ? yellow(formatFlag("warnings"))
324
424
  : warnings
325
- ? yellow(
326
- formatFlag(`${warnings} ${plural(warnings, "warning", "warnings")}`)
327
- )
328
- : undefined,
425
+ ? yellow(
426
+ formatFlag(`${warnings} ${plural(warnings, "warning", "warnings")}`)
427
+ )
428
+ : undefined,
329
429
  "module.errors": (errors, { formatFlag, red }) =>
330
430
  errors === true
331
431
  ? red(formatFlag("errors"))
332
432
  : errors
333
- ? red(formatFlag(`${errors} ${plural(errors, "error", "errors")}`))
334
- : undefined,
433
+ ? red(formatFlag(`${errors} ${plural(errors, "error", "errors")}`))
434
+ : undefined,
335
435
  "module.providedExports": (providedExports, { formatFlag, cyan }) => {
336
436
  if (Array.isArray(providedExports)) {
337
437
  if (providedExports.length === 0) return cyan(formatFlag("no exports"));
@@ -353,11 +453,11 @@ const SIMPLE_PRINTERS = {
353
453
  providedExportsCount === usedExports.length
354
454
  ) {
355
455
  return cyan(formatFlag("all exports used"));
356
- } else {
357
- return cyan(
358
- formatFlag(`only some exports used: ${usedExports.join(", ")}`)
359
- );
360
456
  }
457
+
458
+ return cyan(
459
+ formatFlag(`only some exports used: ${usedExports.join(", ")}`)
460
+ );
361
461
  }
362
462
  }
363
463
  },
@@ -366,29 +466,44 @@ const SIMPLE_PRINTERS = {
366
466
  "module.issuerPath": (issuerPath, { module }) =>
367
467
  module.profile ? undefined : "",
368
468
  "module.profile": profile => undefined,
369
- "module.filteredModules": filteredModules =>
469
+ "module.filteredModules": (filteredModules, { module: { modules } }) =>
370
470
  filteredModules > 0
371
- ? `${filteredModules} nested ${plural(
471
+ ? `${moreCount(modules, filteredModules)} nested ${plural(
372
472
  filteredModules,
373
473
  "module",
374
474
  "modules"
375
- )}`
475
+ )}`
376
476
  : undefined,
377
- "module.filteredReasons": filteredReasons =>
477
+ "module.filteredReasons": (filteredReasons, { module: { reasons } }) =>
378
478
  filteredReasons > 0
379
- ? `${filteredReasons} ${plural(filteredReasons, "reason", "reasons")}`
479
+ ? `${moreCount(reasons, filteredReasons)} ${plural(
480
+ filteredReasons,
481
+ "reason",
482
+ "reasons"
483
+ )}`
380
484
  : undefined,
381
- "module.filteredChildren": filteredChildren =>
485
+ "module.filteredChildren": (filteredChildren, { module: { children } }) =>
382
486
  filteredChildren > 0
383
- ? `${filteredChildren} ${plural(filteredChildren, "module", "modules")}`
487
+ ? `${moreCount(children, filteredChildren)} ${plural(
488
+ filteredChildren,
489
+ "module",
490
+ "modules"
491
+ )}`
384
492
  : undefined,
385
- "module.separator!": () => "\n",
493
+ "module.separator!": () => "\n"
494
+ };
386
495
 
496
+ /** @type {Record<string, (thing: any, context: Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormaters> & WithRequired<StatsPrinterContext, "type" | "compilation" | "moduleIssuer">, printer: StatsPrinter) => string | undefined>} */
497
+ const MODULE_ISSUER_PRINTERS = {
387
498
  "moduleIssuer.id": (id, { formatModuleId }) => formatModuleId(id),
388
- "moduleIssuer.profile.total": (value, { formatTime }) => formatTime(value),
499
+ "moduleIssuer.profile.total": (value, { formatTime }) => formatTime(value)
500
+ };
389
501
 
502
+ /** @type {Record<string, (thing: any, context: Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormaters> & WithRequired<StatsPrinterContext, "type" | "compilation" | "moduleReason">, printer: StatsPrinter) => string | undefined>} */
503
+ const MODULE_REASON_PRINTERS = {
390
504
  "moduleReason.type": type => type,
391
- "moduleReason.userRequest": (userRequest, { cyan }) => cyan(userRequest),
505
+ "moduleReason.userRequest": (userRequest, { cyan }) =>
506
+ cyan(getResourceName(userRequest)),
392
507
  "moduleReason.moduleId": (moduleId, { formatModuleId }) =>
393
508
  isValidId(moduleId) ? formatModuleId(moduleId) : undefined,
394
509
  "moduleReason.module": (module, { magenta }) => magenta(module),
@@ -397,11 +512,21 @@ const SIMPLE_PRINTERS = {
397
512
  "moduleReason.active": (active, { formatFlag }) =>
398
513
  active ? undefined : formatFlag("inactive"),
399
514
  "moduleReason.resolvedModule": (module, { magenta }) => magenta(module),
400
- "moduleReason.filteredChildren": filteredChildren =>
515
+ "moduleReason.filteredChildren": (
516
+ filteredChildren,
517
+ { moduleReason: { children } }
518
+ ) =>
401
519
  filteredChildren > 0
402
- ? `${filteredChildren} ${plural(filteredChildren, "reason", "reasons")}`
403
- : undefined,
520
+ ? `${moreCount(children, filteredChildren)} ${plural(
521
+ filteredChildren,
522
+ "reason",
523
+ "reasons"
524
+ )}`
525
+ : undefined
526
+ };
404
527
 
528
+ /** @type {Record<string, (thing: any, context: Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormaters> & WithRequired<StatsPrinterContext, "type" | "compilation" | "profile">, printer: StatsPrinter) => string | undefined>} */
529
+ const MODULE_PROFILE_PRINTERS = {
405
530
  "module.profile.total": (value, { formatTime }) => formatTime(value),
406
531
  "module.profile.resolving": (value, { formatTime }) =>
407
532
  `resolving: ${formatTime(value)}`,
@@ -416,8 +541,11 @@ const SIMPLE_PRINTERS = {
416
541
  "module.profile.additionalResolving": (value, { formatTime }) =>
417
542
  value ? `additional resolving: ${formatTime(value)}` : undefined,
418
543
  "module.profile.additionalIntegration": (value, { formatTime }) =>
419
- value ? `additional integration: ${formatTime(value)}` : undefined,
544
+ value ? `additional integration: ${formatTime(value)}` : undefined
545
+ };
420
546
 
547
+ /** @type {Record<string, (thing: any, context: Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormaters> & WithRequired<StatsPrinterContext, "type" | "compilation" | "chunkGroupKind" | "chunkGroup">, printer: StatsPrinter) => string | undefined>} */
548
+ const CHUNK_GROUP_PRINTERS = {
421
549
  "chunkGroup.kind!": (_, { chunkGroupKind }) => chunkGroupKind,
422
550
  "chunkGroup.separator!": () => "\n",
423
551
  "chunkGroup.name": (name, { bold }) => bold(name),
@@ -427,17 +555,29 @@ const SIMPLE_PRINTERS = {
427
555
  size ? formatSize(size) : undefined,
428
556
  "chunkGroup.auxiliaryAssetsSize": (size, { formatSize }) =>
429
557
  size ? `(${formatSize(size)})` : undefined,
430
- "chunkGroup.filteredAssets": n =>
431
- n > 0 ? `${n} ${plural(n, "asset", "assets")}` : undefined,
432
- "chunkGroup.filteredAuxiliaryAssets": n =>
433
- n > 0 ? `${n} auxiliary ${plural(n, "asset", "assets")}` : undefined,
558
+ "chunkGroup.filteredAssets": (n, { chunkGroup: { assets } }) =>
559
+ n > 0
560
+ ? `${moreCount(assets, n)} ${plural(n, "asset", "assets")}`
561
+ : undefined,
562
+ "chunkGroup.filteredAuxiliaryAssets": (
563
+ n,
564
+ { chunkGroup: { auxiliaryAssets } }
565
+ ) =>
566
+ n > 0
567
+ ? `${moreCount(auxiliaryAssets, n)} auxiliary ${plural(
568
+ n,
569
+ "asset",
570
+ "assets"
571
+ )}`
572
+ : undefined,
434
573
  "chunkGroup.is!": () => "=",
435
574
  "chunkGroupAsset.name": (asset, { green }) => green(asset),
436
575
  "chunkGroupAsset.size": (size, { formatSize, chunkGroup }) =>
437
- chunkGroup.assets.length > 1 ||
576
+ chunkGroup.assets &&
577
+ (chunkGroup.assets.length > 1 ||
438
578
  (chunkGroup.auxiliaryAssets && chunkGroup.auxiliaryAssets.length > 0)
439
579
  ? formatSize(size)
440
- : undefined,
580
+ : undefined),
441
581
  "chunkGroup.children": (children, context, printer) =>
442
582
  Array.isArray(children)
443
583
  ? undefined
@@ -448,13 +588,16 @@ const SIMPLE_PRINTERS = {
448
588
  children: children[key]
449
589
  })),
450
590
  context
451
- ),
591
+ ),
452
592
  "chunkGroupChildGroup.type": type => `${type}:`,
453
593
  "chunkGroupChild.assets[]": (file, { formatFilename }) =>
454
594
  formatFilename(file),
455
595
  "chunkGroupChild.chunks[]": (id, { formatChunkId }) => formatChunkId(id),
456
- "chunkGroupChild.name": name => (name ? `(name: ${name})` : undefined),
596
+ "chunkGroupChild.name": name => (name ? `(name: ${name})` : undefined)
597
+ };
457
598
 
599
+ /** @type {Record<string, (thing: any, context: Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormaters> & WithRequired<StatsPrinterContext, "type" | "compilation" | "chunk">, printer: StatsPrinter) => string | undefined>} */
600
+ const CHUNK_PRINTERS = {
458
601
  "chunk.id": (id, { formatChunkId }) => formatChunkId(id),
459
602
  "chunk.files[]": (file, { formatFilename }) => formatFilename(file),
460
603
  "chunk.names[]": name => name,
@@ -477,7 +620,7 @@ const SIMPLE_PRINTERS = {
477
620
  children: childrenByOrder[key]
478
621
  })),
479
622
  context
480
- ),
623
+ ),
481
624
  "chunk.childrenByOrder[].type": type => `${type}:`,
482
625
  "chunk.childrenByOrder[].children[]": (id, { formatChunkId }) =>
483
626
  isValidId(id) ? formatChunkId(id) : undefined,
@@ -490,13 +633,13 @@ const SIMPLE_PRINTERS = {
490
633
  "chunk.recorded": (recorded, { formatFlag, green }) =>
491
634
  recorded ? green(formatFlag("recorded")) : undefined,
492
635
  "chunk.reason": (reason, { yellow }) => (reason ? yellow(reason) : undefined),
493
- "chunk.filteredModules": filteredModules =>
636
+ "chunk.filteredModules": (filteredModules, { chunk: { modules } }) =>
494
637
  filteredModules > 0
495
- ? `${filteredModules} chunk ${plural(
638
+ ? `${moreCount(modules, filteredModules)} chunk ${plural(
496
639
  filteredModules,
497
640
  "module",
498
641
  "modules"
499
- )}`
642
+ )}`
500
643
  : undefined,
501
644
  "chunk.separator!": () => "\n",
502
645
 
@@ -504,8 +647,11 @@ const SIMPLE_PRINTERS = {
504
647
  "chunkOrigin.moduleId": (moduleId, { formatModuleId }) =>
505
648
  isValidId(moduleId) ? formatModuleId(moduleId) : undefined,
506
649
  "chunkOrigin.moduleName": (moduleName, { bold }) => bold(moduleName),
507
- "chunkOrigin.loc": loc => loc,
650
+ "chunkOrigin.loc": loc => loc
651
+ };
508
652
 
653
+ /** @type {Record<string, (thing: any, context: Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormaters> & WithRequired<StatsPrinterContext, "type" | "compilation" | "error">, printer: StatsPrinter) => string | undefined>} */
654
+ const ERROR_PRINTERS = {
509
655
  "error.compilerPath": (compilerPath, { bold }) =>
510
656
  compilerPath ? bold(`(${compilerPath})`) : undefined,
511
657
  "error.chunkId": (chunkId, { formatChunkId }) =>
@@ -515,19 +661,23 @@ const SIMPLE_PRINTERS = {
515
661
  "error.chunkInitial": (chunkInitial, { formatFlag }) =>
516
662
  chunkInitial ? formatFlag("initial") : undefined,
517
663
  "error.file": (file, { bold }) => bold(file),
518
- "error.moduleName": (moduleName, { bold }) => {
519
- return moduleName.includes("!")
664
+ "error.moduleName": (moduleName, { bold }) =>
665
+ moduleName.includes("!")
520
666
  ? `${bold(moduleName.replace(/^(\s|\S)*!/, ""))} (${moduleName})`
521
- : `${bold(moduleName)}`;
522
- },
667
+ : `${bold(moduleName)}`,
523
668
  "error.loc": (loc, { green }) => green(loc),
524
669
  "error.message": (message, { bold, formatError }) =>
525
- message.includes("\u001b[") ? message : bold(formatError(message)),
670
+ message.includes("\u001B[") ? message : bold(formatError(message)),
526
671
  "error.details": (details, { formatError }) => formatError(details),
672
+ "error.filteredDetails": filteredDetails =>
673
+ filteredDetails ? `+ ${filteredDetails} hidden lines` : undefined,
527
674
  "error.stack": stack => stack,
528
675
  "error.moduleTrace": moduleTrace => undefined,
529
- "error.separator!": () => "\n",
676
+ "error.separator!": () => "\n"
677
+ };
530
678
 
679
+ /** @type {Record<string, (thing: any, context: Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormaters> & WithRequired<StatsPrinterContext, "type" | "compilation" | "logging">, printer: StatsPrinter) => string | undefined>} */
680
+ const LOG_ENTRY_PRINTERS = {
531
681
  "loggingEntry(error).loggingEntry.message": (message, { red }) =>
532
682
  mapLines(message, x => `<e> ${red(x)}`),
533
683
  "loggingEntry(warn).loggingEntry.message": (message, { yellow }) =>
@@ -557,20 +707,26 @@ const SIMPLE_PRINTERS = {
557
707
  "loggingEntry.trace[]": trace =>
558
708
  trace ? mapLines(trace, x => `| ${x}`) : undefined,
559
709
 
560
- "moduleTraceItem.originName": originName => originName,
561
-
562
710
  loggingGroup: loggingGroup =>
563
711
  loggingGroup.entries.length === 0 ? "" : undefined,
564
712
  "loggingGroup.debug": (flag, { red }) => (flag ? red("DEBUG") : undefined),
565
713
  "loggingGroup.name": (name, { bold }) => bold(`LOG from ${name}`),
566
714
  "loggingGroup.separator!": () => "\n",
567
715
  "loggingGroup.filteredEntries": filteredEntries =>
568
- filteredEntries > 0 ? `+ ${filteredEntries} hidden lines` : undefined,
716
+ filteredEntries > 0 ? `+ ${filteredEntries} hidden lines` : undefined
717
+ };
718
+
719
+ /** @type {Record<string, (thing: any, context: Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormaters> & WithRequired<StatsPrinterContext, "type" | "compilation" | "moduleTraceItem">, printer: StatsPrinter) => string | undefined>} */
720
+ const MODULE_TRACE_ITEM_PRINTERS = {
721
+ "moduleTraceItem.originName": originName => originName
722
+ };
569
723
 
724
+ /** @type {Record<string, (thing: any, context: Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormaters> & WithRequired<StatsPrinterContext, "type" | "compilation" | "moduleTraceDependency">, printer: StatsPrinter) => string | undefined>} */
725
+ const MODULE_TRACE_DEPENDENCY_PRINTERS = {
570
726
  "moduleTraceDependency.loc": loc => loc
571
727
  };
572
728
 
573
- /** @type {Record<string, string | Function>} */
729
+ /** @type {Record<string, string | function(any): string>} */
574
730
  const ITEM_NAMES = {
575
731
  "compilation.assets[]": "asset",
576
732
  "compilation.modules[]": "module",
@@ -624,6 +780,8 @@ const ERROR_PREFERRED_ORDER = [
624
780
  "separator!",
625
781
  "details",
626
782
  "separator!",
783
+ "filteredDetails",
784
+ "separator!",
627
785
  "stack",
628
786
  "separator!",
629
787
  "missing",
@@ -797,19 +955,27 @@ const PREFERRED_ORDERS = {
797
955
  loggingEntry: ["message", "trace", "children"]
798
956
  };
799
957
 
958
+ /** @typedef {(items: string[]) => string | undefined} SimpleItemsJoiner */
959
+
960
+ /** @type {SimpleItemsJoiner} */
800
961
  const itemsJoinOneLine = items => items.filter(Boolean).join(" ");
962
+ /** @type {SimpleItemsJoiner} */
801
963
  const itemsJoinOneLineBrackets = items =>
802
964
  items.length > 0 ? `(${items.filter(Boolean).join(" ")})` : undefined;
965
+ /** @type {SimpleItemsJoiner} */
803
966
  const itemsJoinMoreSpacing = items => items.filter(Boolean).join("\n\n");
967
+ /** @type {SimpleItemsJoiner} */
804
968
  const itemsJoinComma = items => items.filter(Boolean).join(", ");
969
+ /** @type {SimpleItemsJoiner} */
805
970
  const itemsJoinCommaBrackets = items =>
806
971
  items.length > 0 ? `(${items.filter(Boolean).join(", ")})` : undefined;
972
+ /** @type {function(string): SimpleItemsJoiner} */
807
973
  const itemsJoinCommaBracketsWithName = name => items =>
808
974
  items.length > 0
809
975
  ? `(${name}: ${items.filter(Boolean).join(", ")})`
810
976
  : undefined;
811
977
 
812
- /** @type {Record<string, (items: string[]) => string>} */
978
+ /** @type {Record<string, SimpleItemsJoiner>} */
813
979
  const SIMPLE_ITEMS_JOINER = {
814
980
  "chunk.parents": itemsJoinOneLine,
815
981
  "chunk.siblings": itemsJoinOneLine,
@@ -841,18 +1007,27 @@ const SIMPLE_ITEMS_JOINER = {
841
1007
  "compilation.errors": itemsJoinMoreSpacing,
842
1008
  "compilation.warnings": itemsJoinMoreSpacing,
843
1009
  "compilation.logging": itemsJoinMoreSpacing,
844
- "compilation.children": items => indent(itemsJoinMoreSpacing(items), " "),
1010
+ "compilation.children": items =>
1011
+ indent(/** @type {string} */ (itemsJoinMoreSpacing(items)), " "),
845
1012
  "moduleTraceItem.dependencies": itemsJoinOneLine,
846
1013
  "loggingEntry.children": items =>
847
1014
  indent(items.filter(Boolean).join("\n"), " ", false)
848
1015
  };
849
1016
 
1017
+ /**
1018
+ * @param {Item[]} items items
1019
+ * @returns {string} result
1020
+ */
850
1021
  const joinOneLine = items =>
851
1022
  items
852
1023
  .map(item => item.content)
853
1024
  .filter(Boolean)
854
1025
  .join(" ");
855
1026
 
1027
+ /**
1028
+ * @param {Item[]} items items
1029
+ * @returns {string} result
1030
+ */
856
1031
  const joinInBrackets = items => {
857
1032
  const res = [];
858
1033
  let mode = 0;
@@ -895,13 +1070,24 @@ const joinInBrackets = items => {
895
1070
  return res.join("");
896
1071
  };
897
1072
 
1073
+ /**
1074
+ * @param {string} str a string
1075
+ * @param {string} prefix prefix
1076
+ * @param {boolean=} noPrefixInFirstLine need prefix in the first line?
1077
+ * @returns {string} result
1078
+ */
898
1079
  const indent = (str, prefix, noPrefixInFirstLine) => {
899
- const rem = str.replace(/\n([^\n])/g, "\n" + prefix + "$1");
1080
+ const rem = str.replace(/\n([^\n])/g, `\n${prefix}$1`);
900
1081
  if (noPrefixInFirstLine) return rem;
901
1082
  const ind = str[0] === "\n" ? "" : prefix;
902
1083
  return ind + rem;
903
1084
  };
904
1085
 
1086
+ /**
1087
+ * @param {(false | Item)[]} items items
1088
+ * @param {string} indenter indenter
1089
+ * @returns {string} result
1090
+ */
905
1091
  const joinExplicitNewLine = (items, indenter) => {
906
1092
  let firstInLine = true;
907
1093
  let first = true;
@@ -916,22 +1102,34 @@ const joinExplicitNewLine = (items, indenter) => {
916
1102
  first = false;
917
1103
  const noJoiner = firstInLine || content.startsWith("\n");
918
1104
  firstInLine = content.endsWith("\n");
919
- return noJoiner ? content : " " + content;
1105
+ return noJoiner ? content : ` ${content}`;
920
1106
  })
921
1107
  .filter(Boolean)
922
1108
  .join("")
923
1109
  .trim();
924
1110
  };
925
1111
 
1112
+ /**
1113
+ * @param {boolean} error is an error
1114
+ * @returns {SimpleElementJoiner} joiner
1115
+ */
926
1116
  const joinError =
927
1117
  error =>
1118
+ /**
1119
+ * @param {Item[]} items items
1120
+ * @param {Required<StatsPrinterContext>} ctx context
1121
+ * @returns {string} result
1122
+ */
928
1123
  (items, { red, yellow }) =>
929
1124
  `${error ? red("ERROR") : yellow("WARNING")} in ${joinExplicitNewLine(
930
1125
  items,
931
1126
  ""
932
1127
  )}`;
933
1128
 
934
- /** @type {Record<string, (items: ({ element: string, content: string })[], context: StatsPrinterContext) => string>} */
1129
+ /** @typedef {{ element: string, content: string }} Item */
1130
+ /** @typedef {(items: Item[], context: Required<StatsPrinterContext>) => string} SimpleElementJoiner */
1131
+
1132
+ /** @type {Record<string, SimpleElementJoiner>} */
935
1133
  const SIMPLE_ELEMENT_JOINERS = {
936
1134
  compilation: items => {
937
1135
  const result = [];
@@ -1008,23 +1206,20 @@ const SIMPLE_ELEMENT_JOINERS = {
1008
1206
  },
1009
1207
  chunk: items => {
1010
1208
  let hasEntry = false;
1011
- return (
1012
- "chunk " +
1013
- joinExplicitNewLine(
1014
- items.filter(item => {
1015
- switch (item.element) {
1016
- case "entry":
1017
- if (item.content) hasEntry = true;
1018
- break;
1019
- case "initial":
1020
- if (hasEntry) return false;
1021
- break;
1022
- }
1023
- return true;
1024
- }),
1025
- " "
1026
- )
1027
- );
1209
+ return `chunk ${joinExplicitNewLine(
1210
+ items.filter(item => {
1211
+ switch (item.element) {
1212
+ case "entry":
1213
+ if (item.content) hasEntry = true;
1214
+ break;
1215
+ case "initial":
1216
+ if (hasEntry) return false;
1217
+ break;
1218
+ }
1219
+ return true;
1220
+ }),
1221
+ " "
1222
+ )}`;
1028
1223
  },
1029
1224
  "chunk.childrenByOrder[]": items => `(${joinOneLine(items)})`,
1030
1225
  chunkGroup: items => joinExplicitNewLine(items, " "),
@@ -1085,23 +1280,27 @@ const SIMPLE_ELEMENT_JOINERS = {
1085
1280
  },
1086
1281
  "module.profile": joinInBrackets,
1087
1282
  moduleIssuer: joinOneLine,
1088
- chunkOrigin: items => "> " + joinOneLine(items),
1283
+ chunkOrigin: items => `> ${joinOneLine(items)}`,
1089
1284
  "errors[].error": joinError(true),
1090
1285
  "warnings[].error": joinError(false),
1091
- loggingGroup: items => joinExplicitNewLine(items, "").trimRight(),
1092
- moduleTraceItem: items => " @ " + joinOneLine(items),
1286
+ loggingGroup: items => joinExplicitNewLine(items, "").trimEnd(),
1287
+ moduleTraceItem: items => ` @ ${joinOneLine(items)}`,
1093
1288
  moduleTraceDependency: joinOneLine
1094
1289
  };
1095
1290
 
1291
+ /** @typedef {"bold" | "yellow" | "red" | "green" | "cyan" | "magenta"} ColorNames */
1292
+
1293
+ /** @type {Record<ColorNames, string>} */
1096
1294
  const AVAILABLE_COLORS = {
1097
- bold: "\u001b[1m",
1098
- yellow: "\u001b[1m\u001b[33m",
1099
- red: "\u001b[1m\u001b[31m",
1100
- green: "\u001b[1m\u001b[32m",
1101
- cyan: "\u001b[1m\u001b[36m",
1102
- magenta: "\u001b[1m\u001b[35m"
1295
+ bold: "\u001B[1m",
1296
+ yellow: "\u001B[1m\u001B[33m",
1297
+ red: "\u001B[1m\u001B[31m",
1298
+ green: "\u001B[1m\u001B[32m",
1299
+ cyan: "\u001B[1m\u001B[36m",
1300
+ magenta: "\u001B[1m\u001B[35m"
1103
1301
  };
1104
1302
 
1303
+ /** @type {Record<string, function(any, Required<KnownStatsPrinterColorFn> & StatsPrinterContext, ...any): string>} */
1105
1304
  const AVAILABLE_FORMATS = {
1106
1305
  formatChunkId: (id, { yellow }, direction) => {
1107
1306
  switch (direction) {
@@ -1145,13 +1344,12 @@ const AVAILABLE_FORMATS = {
1145
1344
  else if (time < times[2]) return bold(`${time}${unit}`);
1146
1345
  else if (time < times[1]) return green(`${time}${unit}`);
1147
1346
  else if (time < times[0]) return yellow(`${time}${unit}`);
1148
- else return red(`${time}${unit}`);
1149
- } else {
1150
- return `${boldQuantity ? bold(time) : time}${unit}`;
1347
+ return red(`${time}${unit}`);
1151
1348
  }
1349
+ return `${boldQuantity ? bold(time) : time}${unit}`;
1152
1350
  },
1153
1351
  formatError: (message, { green, yellow, red }) => {
1154
- if (message.includes("\u001b[")) return message;
1352
+ if (message.includes("\u001B[")) return message;
1155
1353
  const highlights = [
1156
1354
  { regExp: /(Did you mean .+)/g, format: green },
1157
1355
  {
@@ -1160,7 +1358,7 @@ const AVAILABLE_FORMATS = {
1160
1358
  },
1161
1359
  { regExp: /(\(module has no exports\))/g, format: red },
1162
1360
  { regExp: /\(possible exports: (.+)\)/g, format: green },
1163
- { regExp: /\s*(.+ doesn't exist)/g, format: red },
1361
+ { regExp: /(?:^|\n)(.* doesn't exist)/g, format: red },
1164
1362
  { regExp: /('\w+' option has not been set)/g, format: red },
1165
1363
  {
1166
1364
  regExp: /(Emitted value instead of an instance of Error)/g,
@@ -1179,23 +1377,36 @@ const AVAILABLE_FORMATS = {
1179
1377
  }
1180
1378
  ];
1181
1379
  for (const { regExp, format } of highlights) {
1182
- message = message.replace(regExp, (match, content) => {
1183
- return match.replace(content, format(content));
1184
- });
1380
+ message = message.replace(
1381
+ regExp,
1382
+ /**
1383
+ * @param {string} match match
1384
+ * @param {string} content content
1385
+ * @returns {string} result
1386
+ */
1387
+ (match, content) => match.replace(content, format(content))
1388
+ );
1185
1389
  }
1186
1390
  return message;
1187
1391
  }
1188
1392
  };
1189
1393
 
1394
+ /** @typedef {function(string): string} ResultModifierFn */
1395
+ /** @type {Record<string, ResultModifierFn>} */
1190
1396
  const RESULT_MODIFIER = {
1191
- "module.modules": result => {
1192
- return indent(result, "| ");
1193
- }
1397
+ "module.modules": result => indent(result, "| ")
1194
1398
  };
1195
1399
 
1400
+ /**
1401
+ * @param {string[]} array array
1402
+ * @param {string[]} preferredOrder preferred order
1403
+ * @returns {string[]} result
1404
+ */
1196
1405
  const createOrder = (array, preferredOrder) => {
1197
1406
  const originalArray = array.slice();
1407
+ /** @type {Set<string>} */
1198
1408
  const set = new Set(array);
1409
+ /** @type {Set<string>} */
1199
1410
  const usedSet = new Set();
1200
1411
  array.length = 0;
1201
1412
  for (const element of preferredOrder) {
@@ -1222,49 +1433,218 @@ class DefaultStatsPrinterPlugin {
1222
1433
  compiler.hooks.compilation.tap("DefaultStatsPrinterPlugin", compilation => {
1223
1434
  compilation.hooks.statsPrinter.tap(
1224
1435
  "DefaultStatsPrinterPlugin",
1225
- (stats, options, context) => {
1436
+ (stats, options) => {
1226
1437
  // Put colors into context
1227
1438
  stats.hooks.print
1228
1439
  .for("compilation")
1229
1440
  .tap("DefaultStatsPrinterPlugin", (compilation, context) => {
1230
1441
  for (const color of Object.keys(AVAILABLE_COLORS)) {
1442
+ const name = /** @type {ColorNames} */ (color);
1443
+ /** @type {string | undefined} */
1231
1444
  let start;
1232
1445
  if (options.colors) {
1233
1446
  if (
1234
1447
  typeof options.colors === "object" &&
1235
- typeof options.colors[color] === "string"
1448
+ typeof options.colors[name] === "string"
1236
1449
  ) {
1237
- start = options.colors[color];
1450
+ start = options.colors[name];
1238
1451
  } else {
1239
- start = AVAILABLE_COLORS[color];
1452
+ start = AVAILABLE_COLORS[name];
1240
1453
  }
1241
1454
  }
1242
1455
  if (start) {
1456
+ /**
1457
+ * @param {string} str string
1458
+ * @returns {string} string with color
1459
+ */
1243
1460
  context[color] = str =>
1244
1461
  `${start}${
1245
1462
  typeof str === "string"
1246
1463
  ? str.replace(
1247
- /((\u001b\[39m|\u001b\[22m|\u001b\[0m)+)/g,
1464
+ /((\u001B\[39m|\u001B\[22m|\u001B\[0m)+)/g,
1248
1465
  `$1${start}`
1249
- )
1466
+ )
1250
1467
  : str
1251
- }\u001b[39m\u001b[22m`;
1468
+ }\u001B[39m\u001B[22m`;
1252
1469
  } else {
1470
+ /**
1471
+ * @param {string} str string
1472
+ * @returns {string} str string
1473
+ */
1253
1474
  context[color] = str => str;
1254
1475
  }
1255
1476
  }
1256
1477
  for (const format of Object.keys(AVAILABLE_FORMATS)) {
1257
- context[format] = (content, ...args) =>
1258
- AVAILABLE_FORMATS[format](content, context, ...args);
1478
+ context[format] =
1479
+ /**
1480
+ * @param {string | number} content content
1481
+ * @param {...TODO} args args
1482
+ * @returns {string} result
1483
+ */
1484
+ (content, ...args) =>
1485
+ AVAILABLE_FORMATS[format](
1486
+ content,
1487
+ /** @type {Required<KnownStatsPrinterColorFn> & StatsPrinterContext} */
1488
+ (context),
1489
+ ...args
1490
+ );
1259
1491
  }
1260
1492
  context.timeReference = compilation.time;
1261
1493
  });
1262
1494
 
1263
- for (const key of Object.keys(SIMPLE_PRINTERS)) {
1495
+ for (const key of Object.keys(COMPILATION_SIMPLE_PRINTERS)) {
1264
1496
  stats.hooks.print
1265
1497
  .for(key)
1266
1498
  .tap("DefaultStatsPrinterPlugin", (obj, ctx) =>
1267
- SIMPLE_PRINTERS[key](obj, ctx, stats)
1499
+ COMPILATION_SIMPLE_PRINTERS[key](
1500
+ obj,
1501
+ /** @type {Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormaters> & WithRequired<StatsPrinterContext, "type" | "compilation">} */
1502
+ (ctx),
1503
+ stats
1504
+ )
1505
+ );
1506
+ }
1507
+
1508
+ for (const key of Object.keys(ASSET_SIMPLE_PRINTERS)) {
1509
+ stats.hooks.print
1510
+ .for(key)
1511
+ .tap("DefaultStatsPrinterPlugin", (obj, ctx) =>
1512
+ ASSET_SIMPLE_PRINTERS[key](
1513
+ obj,
1514
+ /** @type {Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormaters> & WithRequired<StatsPrinterContext, "type" | "compilation" | "asset">} */
1515
+ (ctx),
1516
+ stats
1517
+ )
1518
+ );
1519
+ }
1520
+
1521
+ for (const key of Object.keys(MODULE_SIMPLE_PRINTERS)) {
1522
+ stats.hooks.print
1523
+ .for(key)
1524
+ .tap("DefaultStatsPrinterPlugin", (obj, ctx) =>
1525
+ MODULE_SIMPLE_PRINTERS[key](
1526
+ obj,
1527
+ /** @type {Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormaters> & WithRequired<StatsPrinterContext, "type" | "compilation" | "module">} */
1528
+ (ctx),
1529
+ stats
1530
+ )
1531
+ );
1532
+ }
1533
+
1534
+ for (const key of Object.keys(MODULE_ISSUER_PRINTERS)) {
1535
+ stats.hooks.print
1536
+ .for(key)
1537
+ .tap("DefaultStatsPrinterPlugin", (obj, ctx) =>
1538
+ MODULE_ISSUER_PRINTERS[key](
1539
+ obj,
1540
+ /** @type {Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormaters> & WithRequired<StatsPrinterContext, "type" | "compilation" | "moduleIssuer">} */
1541
+ (ctx),
1542
+ stats
1543
+ )
1544
+ );
1545
+ }
1546
+
1547
+ for (const key of Object.keys(MODULE_REASON_PRINTERS)) {
1548
+ stats.hooks.print
1549
+ .for(key)
1550
+ .tap("DefaultStatsPrinterPlugin", (obj, ctx) =>
1551
+ MODULE_REASON_PRINTERS[key](
1552
+ obj,
1553
+ /** @type {Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormaters> & WithRequired<StatsPrinterContext, "type" | "compilation" | "moduleReason">} */
1554
+ (ctx),
1555
+ stats
1556
+ )
1557
+ );
1558
+ }
1559
+
1560
+ for (const key of Object.keys(MODULE_PROFILE_PRINTERS)) {
1561
+ stats.hooks.print
1562
+ .for(key)
1563
+ .tap("DefaultStatsPrinterPlugin", (obj, ctx) =>
1564
+ MODULE_PROFILE_PRINTERS[key](
1565
+ obj,
1566
+ /** @type {Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormaters> & WithRequired<StatsPrinterContext, "type" | "compilation" | "profile">} */
1567
+ (ctx),
1568
+ stats
1569
+ )
1570
+ );
1571
+ }
1572
+
1573
+ for (const key of Object.keys(CHUNK_GROUP_PRINTERS)) {
1574
+ stats.hooks.print
1575
+ .for(key)
1576
+ .tap("DefaultStatsPrinterPlugin", (obj, ctx) =>
1577
+ CHUNK_GROUP_PRINTERS[key](
1578
+ obj,
1579
+ /** @type {Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormaters> & WithRequired<StatsPrinterContext, "type" | "compilation" | "chunkGroupKind" | "chunkGroup">} */
1580
+ (ctx),
1581
+ stats
1582
+ )
1583
+ );
1584
+ }
1585
+
1586
+ for (const key of Object.keys(CHUNK_PRINTERS)) {
1587
+ stats.hooks.print
1588
+ .for(key)
1589
+ .tap("DefaultStatsPrinterPlugin", (obj, ctx) =>
1590
+ CHUNK_PRINTERS[key](
1591
+ obj,
1592
+ /** @type {Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormaters> & WithRequired<StatsPrinterContext, "type" | "compilation" | "chunk">} */
1593
+ (ctx),
1594
+ stats
1595
+ )
1596
+ );
1597
+ }
1598
+
1599
+ for (const key of Object.keys(ERROR_PRINTERS)) {
1600
+ stats.hooks.print
1601
+ .for(key)
1602
+ .tap("DefaultStatsPrinterPlugin", (obj, ctx) =>
1603
+ ERROR_PRINTERS[key](
1604
+ obj,
1605
+ /** @type {Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormaters> & WithRequired<StatsPrinterContext, "type" | "compilation" | "error">} */
1606
+ (ctx),
1607
+ stats
1608
+ )
1609
+ );
1610
+ }
1611
+
1612
+ for (const key of Object.keys(LOG_ENTRY_PRINTERS)) {
1613
+ stats.hooks.print
1614
+ .for(key)
1615
+ .tap("DefaultStatsPrinterPlugin", (obj, ctx) =>
1616
+ LOG_ENTRY_PRINTERS[key](
1617
+ obj,
1618
+ /** @type {Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormaters> & WithRequired<StatsPrinterContext, "type" | "compilation" | "logging">} */
1619
+ (ctx),
1620
+ stats
1621
+ )
1622
+ );
1623
+ }
1624
+
1625
+ for (const key of Object.keys(MODULE_TRACE_DEPENDENCY_PRINTERS)) {
1626
+ stats.hooks.print
1627
+ .for(key)
1628
+ .tap("DefaultStatsPrinterPlugin", (obj, ctx) =>
1629
+ MODULE_TRACE_DEPENDENCY_PRINTERS[key](
1630
+ obj,
1631
+ /** @type {Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormaters> & WithRequired<StatsPrinterContext, "type" | "compilation" | "moduleTraceDependency">} */
1632
+ (ctx),
1633
+ stats
1634
+ )
1635
+ );
1636
+ }
1637
+
1638
+ for (const key of Object.keys(MODULE_TRACE_ITEM_PRINTERS)) {
1639
+ stats.hooks.print
1640
+ .for(key)
1641
+ .tap("DefaultStatsPrinterPlugin", (obj, ctx) =>
1642
+ MODULE_TRACE_ITEM_PRINTERS[key](
1643
+ obj,
1644
+ /** @type {Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormaters> & WithRequired<StatsPrinterContext, "type" | "compilation" | "moduleTraceItem">} */
1645
+ (ctx),
1646
+ stats
1647
+ )
1268
1648
  );
1269
1649
  }
1270
1650
 
@@ -1298,7 +1678,7 @@ class DefaultStatsPrinterPlugin {
1298
1678
  const joiner = SIMPLE_ELEMENT_JOINERS[key];
1299
1679
  stats.hooks.printElements
1300
1680
  .for(key)
1301
- .tap("DefaultStatsPrinterPlugin", joiner);
1681
+ .tap("DefaultStatsPrinterPlugin", /** @type {TODO} */ (joiner));
1302
1682
  }
1303
1683
 
1304
1684
  for (const key of Object.keys(RESULT_MODIFIER)) {