webpack 5.93.0 → 5.95.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 (344) hide show
  1. package/README.md +8 -5
  2. package/bin/webpack.js +6 -7
  3. package/hot/log.js +1 -2
  4. package/hot/only-dev-server.js +1 -1
  5. package/hot/poll.js +1 -1
  6. package/hot/signal.js +1 -1
  7. package/lib/APIPlugin.js +4 -3
  8. package/lib/AbstractMethodError.js +10 -5
  9. package/lib/AutomaticPrefetchPlugin.js +1 -1
  10. package/lib/BannerPlugin.js +12 -6
  11. package/lib/Cache.js +8 -10
  12. package/lib/CacheFacade.js +3 -3
  13. package/lib/CaseSensitiveModulesWarning.js +5 -7
  14. package/lib/Chunk.js +14 -11
  15. package/lib/ChunkGraph.js +58 -36
  16. package/lib/ChunkGroup.js +2 -3
  17. package/lib/ChunkTemplate.js +43 -0
  18. package/lib/CleanPlugin.js +10 -11
  19. package/lib/CodeGenerationResults.js +6 -5
  20. package/lib/CommentCompilationWarning.js +0 -1
  21. package/lib/Compilation.js +223 -191
  22. package/lib/Compiler.js +81 -82
  23. package/lib/ConcatenationScope.js +3 -6
  24. package/lib/ConditionalInitFragment.js +6 -7
  25. package/lib/ConstPlugin.js +7 -15
  26. package/lib/ContextExclusionPlugin.js +3 -3
  27. package/lib/ContextModule.js +33 -20
  28. package/lib/ContextModuleFactory.js +89 -44
  29. package/lib/ContextReplacementPlugin.js +10 -9
  30. package/lib/DefinePlugin.js +75 -68
  31. package/lib/DelegatedModule.js +7 -3
  32. package/lib/DelegatedModuleFactoryPlugin.js +36 -22
  33. package/lib/DelegatedPlugin.js +4 -0
  34. package/lib/DependenciesBlock.js +0 -1
  35. package/lib/Dependency.js +10 -14
  36. package/lib/DllEntryPlugin.js +4 -2
  37. package/lib/DllModuleFactory.js +1 -0
  38. package/lib/DllPlugin.js +9 -7
  39. package/lib/DllReferencePlugin.js +30 -15
  40. package/lib/EntryPlugin.js +1 -3
  41. package/lib/EnvironmentPlugin.js +6 -2
  42. package/lib/ErrorHelpers.js +11 -12
  43. package/lib/EvalDevToolModulePlugin.js +10 -12
  44. package/lib/EvalSourceMapDevToolPlugin.js +15 -13
  45. package/lib/ExportsInfo.js +185 -120
  46. package/lib/ExternalModule.js +41 -15
  47. package/lib/ExternalModuleFactoryPlugin.js +23 -10
  48. package/lib/FileSystemInfo.js +791 -422
  49. package/lib/FlagAllModulesAsUsedPlugin.js +1 -1
  50. package/lib/FlagDependencyExportsPlugin.js +12 -11
  51. package/lib/FlagDependencyUsagePlugin.js +1 -1
  52. package/lib/Generator.js +2 -5
  53. package/lib/GraphHelpers.js +3 -2
  54. package/lib/HookWebpackError.js +8 -10
  55. package/lib/HotModuleReplacementPlugin.js +78 -64
  56. package/lib/IgnoreErrorModuleFactory.js +3 -3
  57. package/lib/IgnorePlugin.js +1 -3
  58. package/lib/IgnoreWarningsPlugin.js +6 -9
  59. package/lib/InitFragment.js +2 -3
  60. package/lib/LibManifestPlugin.js +4 -3
  61. package/lib/MainTemplate.js +72 -19
  62. package/lib/Module.js +25 -9
  63. package/lib/ModuleBuildError.js +4 -11
  64. package/lib/ModuleDependencyError.js +5 -5
  65. package/lib/ModuleDependencyWarning.js +5 -5
  66. package/lib/ModuleError.js +1 -5
  67. package/lib/ModuleFilenameHelpers.js +29 -46
  68. package/lib/ModuleGraph.js +7 -6
  69. package/lib/ModuleGraphConnection.js +6 -6
  70. package/lib/ModuleInfoHeaderPlugin.js +82 -30
  71. package/lib/ModuleParseError.js +8 -9
  72. package/lib/ModuleRestoreError.js +1 -1
  73. package/lib/ModuleStoreError.js +1 -1
  74. package/lib/ModuleTemplate.js +33 -1
  75. package/lib/ModuleTypeConstants.js +21 -22
  76. package/lib/ModuleWarning.js +1 -5
  77. package/lib/MultiCompiler.js +24 -26
  78. package/lib/MultiStats.js +73 -31
  79. package/lib/MultiWatching.js +1 -1
  80. package/lib/NormalModule.js +130 -69
  81. package/lib/NormalModuleFactory.js +53 -49
  82. package/lib/OptimizationStages.js +3 -3
  83. package/lib/ProgressPlugin.js +9 -9
  84. package/lib/ProvidePlugin.js +4 -4
  85. package/lib/RuntimeGlobals.js +71 -70
  86. package/lib/RuntimeModule.js +1 -1
  87. package/lib/RuntimePlugin.js +24 -12
  88. package/lib/RuntimeTemplate.js +40 -44
  89. package/lib/SizeFormatHelpers.js +2 -4
  90. package/lib/SourceMapDevToolPlugin.js +42 -34
  91. package/lib/Stats.js +5 -11
  92. package/lib/Template.js +18 -24
  93. package/lib/TemplatedPathPlugin.js +21 -13
  94. package/lib/WarnDeprecatedOptionPlugin.js +0 -1
  95. package/lib/WatchIgnorePlugin.js +26 -9
  96. package/lib/Watching.js +10 -5
  97. package/lib/WebpackOptionsApply.js +84 -62
  98. package/lib/asset/AssetGenerator.js +107 -42
  99. package/lib/asset/AssetModulesPlugin.js +29 -23
  100. package/lib/asset/AssetSourceGenerator.js +2 -7
  101. package/lib/async-modules/AwaitDependenciesInitFragment.js +6 -7
  102. package/lib/buildChunkGraph.js +93 -81
  103. package/lib/cache/IdleFileCachePlugin.js +4 -4
  104. package/lib/cache/MemoryWithGcCachePlugin.js +5 -5
  105. package/lib/cache/PackFileCacheStrategy.js +51 -50
  106. package/lib/cache/ResolverCachePlugin.js +6 -6
  107. package/lib/cache/mergeEtags.js +16 -21
  108. package/lib/cli.js +148 -104
  109. package/lib/config/browserslistTargetHandler.js +16 -13
  110. package/lib/config/defaults.js +32 -28
  111. package/lib/config/normalization.js +335 -344
  112. package/lib/config/target.js +42 -52
  113. package/lib/container/ContainerEntryModule.js +2 -2
  114. package/lib/container/ContainerPlugin.js +1 -1
  115. package/lib/container/RemoteRuntimeModule.js +11 -8
  116. package/lib/container/options.js +18 -4
  117. package/lib/css/CssExportsGenerator.js +26 -24
  118. package/lib/css/CssGenerator.js +9 -4
  119. package/lib/css/CssLoadingRuntimeModule.js +10 -10
  120. package/lib/css/CssModulesPlugin.js +127 -47
  121. package/lib/css/CssParser.js +20 -18
  122. package/lib/css/walkCssTokens.js +80 -95
  123. package/lib/debug/ProfilingPlugin.js +19 -20
  124. package/lib/dependencies/AMDDefineDependency.js +1 -1
  125. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +83 -47
  126. package/lib/dependencies/AMDRequireArrayDependency.js +9 -10
  127. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +22 -16
  128. package/lib/dependencies/AMDRuntimeModules.js +2 -2
  129. package/lib/dependencies/CommonJsDependencyHelpers.js +6 -2
  130. package/lib/dependencies/CommonJsExportRequireDependency.js +37 -41
  131. package/lib/dependencies/CommonJsExportsDependency.js +0 -1
  132. package/lib/dependencies/CommonJsExportsParserPlugin.js +19 -23
  133. package/lib/dependencies/CommonJsFullRequireDependency.js +1 -1
  134. package/lib/dependencies/CommonJsImportsParserPlugin.js +52 -61
  135. package/lib/dependencies/CommonJsSelfReferenceDependency.js +6 -8
  136. package/lib/dependencies/ConstDependency.js +1 -1
  137. package/lib/dependencies/ContextDependency.js +7 -2
  138. package/lib/dependencies/ContextDependencyHelpers.js +31 -34
  139. package/lib/dependencies/ContextElementDependency.js +35 -8
  140. package/lib/dependencies/CriticalDependencyWarning.js +1 -1
  141. package/lib/dependencies/CssExportDependency.js +7 -7
  142. package/lib/dependencies/CssImportDependency.js +0 -2
  143. package/lib/dependencies/CssLocalIdentifierDependency.js +3 -3
  144. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
  145. package/lib/dependencies/CssUrlDependency.js +4 -5
  146. package/lib/dependencies/DynamicExports.js +5 -5
  147. package/lib/dependencies/ExportsInfoDependency.js +1 -2
  148. package/lib/dependencies/HarmonyAcceptImportDependency.js +1 -1
  149. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -5
  150. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +27 -16
  151. package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
  152. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +107 -64
  153. package/lib/dependencies/HarmonyExports.js +2 -2
  154. package/lib/dependencies/HarmonyImportDependency.js +2 -4
  155. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +19 -4
  156. package/lib/dependencies/HarmonyImportSpecifierDependency.js +40 -15
  157. package/lib/dependencies/ImportDependency.js +1 -1
  158. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +5 -5
  159. package/lib/dependencies/ImportMetaPlugin.js +11 -13
  160. package/lib/dependencies/ImportParserPlugin.js +39 -44
  161. package/lib/dependencies/JsonExportsDependency.js +22 -18
  162. package/lib/dependencies/LoaderPlugin.js +47 -36
  163. package/lib/dependencies/LocalModule.js +1 -1
  164. package/lib/dependencies/LocalModulesHelpers.js +4 -4
  165. package/lib/dependencies/ModuleDecoratorDependency.js +1 -1
  166. package/lib/dependencies/ProvidedDependency.js +1 -1
  167. package/lib/dependencies/PureExpressionDependency.js +6 -6
  168. package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
  169. package/lib/dependencies/RuntimeRequirementsDependency.js +1 -1
  170. package/lib/dependencies/SystemPlugin.js +1 -1
  171. package/lib/dependencies/URLDependency.js +3 -3
  172. package/lib/dependencies/URLPlugin.js +66 -12
  173. package/lib/dependencies/WorkerPlugin.js +25 -24
  174. package/lib/dependencies/processExportInfo.js +3 -1
  175. package/lib/electron/ElectronTargetPlugin.js +1 -0
  176. package/lib/esm/ModuleChunkFormatPlugin.js +3 -3
  177. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +7 -3
  178. package/lib/formatLocation.js +1 -2
  179. package/lib/hmr/HotModuleReplacement.runtime.js +4 -5
  180. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -0
  181. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +9 -12
  182. package/lib/hmr/LazyCompilationPlugin.js +27 -12
  183. package/lib/hmr/lazyCompilationBackend.js +64 -40
  184. package/lib/ids/ChunkModuleIdRangePlugin.js +1 -3
  185. package/lib/ids/DeterministicChunkIdsPlugin.js +2 -4
  186. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  187. package/lib/ids/HashedModuleIdsPlugin.js +5 -1
  188. package/lib/ids/IdHelpers.js +29 -39
  189. package/lib/ids/SyncModuleIdsPlugin.js +7 -2
  190. package/lib/index.js +1 -5
  191. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +5 -4
  192. package/lib/javascript/BasicEvaluatedExpression.js +4 -19
  193. package/lib/javascript/ChunkHelpers.js +1 -1
  194. package/lib/javascript/CommonJsChunkFormatPlugin.js +3 -2
  195. package/lib/javascript/EnableChunkLoadingPlugin.js +7 -6
  196. package/lib/javascript/JavascriptGenerator.js +23 -7
  197. package/lib/javascript/JavascriptModulesPlugin.js +133 -86
  198. package/lib/javascript/JavascriptParser.js +179 -200
  199. package/lib/javascript/JavascriptParserHelpers.js +20 -21
  200. package/lib/javascript/StartupHelpers.js +41 -13
  201. package/lib/json/JsonGenerator.js +7 -13
  202. package/lib/json/JsonModulesPlugin.js +1 -4
  203. package/lib/json/JsonParser.js +5 -3
  204. package/lib/library/AmdLibraryPlugin.js +12 -16
  205. package/lib/library/AssignLibraryPlugin.js +8 -10
  206. package/lib/library/EnableLibraryPlugin.js +15 -14
  207. package/lib/library/JsonpLibraryPlugin.js +2 -1
  208. package/lib/library/ModernModuleLibraryPlugin.js +8 -6
  209. package/lib/library/ModuleLibraryPlugin.js +2 -1
  210. package/lib/library/SystemLibraryPlugin.js +2 -1
  211. package/lib/library/UmdLibraryPlugin.js +66 -92
  212. package/lib/logging/Logger.js +32 -4
  213. package/lib/logging/createConsoleLogger.js +12 -13
  214. package/lib/logging/runtime.js +7 -8
  215. package/lib/logging/truncateArgs.js +5 -8
  216. package/lib/node/NodeWatchFileSystem.js +3 -18
  217. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -2
  218. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -0
  219. package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -2
  220. package/lib/node/nodeConsole.js +22 -22
  221. package/lib/optimize/AggressiveMergingPlugin.js +2 -4
  222. package/lib/optimize/AggressiveSplittingPlugin.js +16 -19
  223. package/lib/optimize/ConcatenatedModule.js +81 -51
  224. package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
  225. package/lib/optimize/FlagIncludedChunksPlugin.js +3 -3
  226. package/lib/optimize/InnerGraph.js +17 -17
  227. package/lib/optimize/InnerGraphPlugin.js +8 -7
  228. package/lib/optimize/LimitChunkCountPlugin.js +2 -3
  229. package/lib/optimize/MangleExportsPlugin.js +1 -0
  230. package/lib/optimize/MergeDuplicateChunksPlugin.js +2 -2
  231. package/lib/optimize/MinMaxSizeWarning.js +1 -1
  232. package/lib/optimize/ModuleConcatenationPlugin.js +54 -78
  233. package/lib/optimize/RealContentHashPlugin.js +7 -10
  234. package/lib/optimize/RemoveParentModulesPlugin.js +3 -3
  235. package/lib/optimize/SideEffectsFlagPlugin.js +6 -2
  236. package/lib/optimize/SplitChunksPlugin.js +34 -30
  237. package/lib/performance/SizeLimitsPlugin.js +2 -2
  238. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +1 -1
  239. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +1 -1
  240. package/lib/rules/BasicEffectRulePlugin.js +3 -1
  241. package/lib/rules/BasicMatcherRulePlugin.js +3 -1
  242. package/lib/rules/ObjectMatcherRulePlugin.js +4 -1
  243. package/lib/rules/RuleSetCompiler.js +41 -22
  244. package/lib/rules/UseEffectRulePlugin.js +36 -32
  245. package/lib/runtime/AsyncModuleRuntimeModule.js +1 -1
  246. package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
  247. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +2 -2
  248. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +1 -1
  249. package/lib/runtime/EnsureChunkRuntimeModule.js +10 -11
  250. package/lib/runtime/GetChunkFilenameRuntimeModule.js +11 -17
  251. package/lib/runtime/LoadScriptRuntimeModule.js +17 -18
  252. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -3
  253. package/lib/schemes/DataUriPlugin.js +1 -1
  254. package/lib/schemes/HttpUriPlugin.js +241 -126
  255. package/lib/serialization/BinaryMiddleware.js +44 -28
  256. package/lib/serialization/DateObjectSerializer.js +1 -0
  257. package/lib/serialization/ErrorObjectSerializer.js +2 -0
  258. package/lib/serialization/FileMiddleware.js +154 -106
  259. package/lib/serialization/MapObjectSerializer.js +2 -1
  260. package/lib/serialization/NullPrototypeObjectSerializer.js +3 -2
  261. package/lib/serialization/ObjectMiddleware.js +52 -56
  262. package/lib/serialization/PlainObjectSerializer.js +32 -6
  263. package/lib/serialization/RegExpObjectSerializer.js +1 -0
  264. package/lib/serialization/Serializer.js +4 -5
  265. package/lib/serialization/SerializerMiddleware.js +6 -6
  266. package/lib/serialization/SetObjectSerializer.js +2 -1
  267. package/lib/sharing/ConsumeSharedPlugin.js +116 -97
  268. package/lib/sharing/ConsumeSharedRuntimeModule.js +4 -4
  269. package/lib/sharing/ProvideForSharedDependency.js +0 -1
  270. package/lib/sharing/ProvideSharedPlugin.js +2 -2
  271. package/lib/sharing/resolveMatchedConfigs.js +2 -1
  272. package/lib/sharing/utils.js +15 -27
  273. package/lib/stats/DefaultStatsFactoryPlugin.js +424 -281
  274. package/lib/stats/DefaultStatsPresetPlugin.js +73 -18
  275. package/lib/stats/DefaultStatsPrinterPlugin.js +370 -101
  276. package/lib/stats/StatsFactory.js +127 -56
  277. package/lib/stats/StatsPrinter.js +75 -44
  278. package/lib/util/ArrayHelpers.js +8 -4
  279. package/lib/util/ArrayQueue.js +1 -1
  280. package/lib/util/AsyncQueue.js +31 -12
  281. package/lib/util/IterableHelpers.js +3 -4
  282. package/lib/util/LazyBucketSortedSet.js +60 -44
  283. package/lib/util/LazySet.js +13 -0
  284. package/lib/util/MapHelpers.js +1 -3
  285. package/lib/util/ParallelismFactorCalculator.js +1 -1
  286. package/lib/util/Queue.js +1 -1
  287. package/lib/util/Semaphore.js +4 -7
  288. package/lib/util/SetHelpers.js +5 -5
  289. package/lib/util/SortableSet.js +4 -3
  290. package/lib/util/StackedCacheMap.js +4 -6
  291. package/lib/util/StackedMap.js +1 -3
  292. package/lib/util/StringXor.js +0 -5
  293. package/lib/util/TupleQueue.js +1 -1
  294. package/lib/util/TupleSet.js +15 -5
  295. package/lib/util/URLAbsoluteSpecifier.js +7 -7
  296. package/lib/util/WeakTupleMap.js +19 -21
  297. package/lib/util/binarySearchBounds.js +5 -12
  298. package/lib/util/chainedImports.js +1 -1
  299. package/lib/util/cleverMerge.js +21 -19
  300. package/lib/util/comparators.js +57 -52
  301. package/lib/util/compileBooleanMatcher.js +3 -6
  302. package/lib/util/conventions.js +8 -11
  303. package/lib/util/createHash.js +9 -6
  304. package/lib/util/deprecation.js +22 -12
  305. package/lib/util/deterministicGrouping.js +19 -26
  306. package/lib/util/findGraphRoots.js +2 -2
  307. package/lib/util/fs.js +32 -32
  308. package/lib/util/hash/md4.js +2 -2
  309. package/lib/util/hash/wasm-hash.js +7 -7
  310. package/lib/util/hash/xxhash64.js +2 -2
  311. package/lib/util/identifier.js +81 -59
  312. package/lib/util/memoize.js +8 -10
  313. package/lib/util/mergeScope.js +6 -9
  314. package/lib/util/nonNumericOnlyHash.js +2 -2
  315. package/lib/util/numberHash.js +1 -6
  316. package/lib/util/objectToMap.js +0 -1
  317. package/lib/util/propertyAccess.js +2 -5
  318. package/lib/util/propertyName.js +1 -3
  319. package/lib/util/registerExternalSerializer.js +1 -1
  320. package/lib/util/runtime.js +109 -113
  321. package/lib/util/semver.js +29 -27
  322. package/lib/util/serialization.js +16 -1
  323. package/lib/util/smartGrouping.js +5 -5
  324. package/lib/util/source.js +1 -1
  325. package/lib/wasm/EnableWasmLoadingPlugin.js +5 -4
  326. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
  327. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -6
  328. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
  329. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +20 -19
  330. package/lib/wasm-sync/WebAssemblyGenerator.js +14 -29
  331. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -1
  332. package/lib/wasm-sync/WebAssemblyUtils.js +2 -2
  333. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -3
  334. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -1
  335. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
  336. package/package.json +18 -17
  337. package/schemas/WebpackOptions.check.js +1 -1
  338. package/schemas/WebpackOptions.json +5 -0
  339. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  340. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  341. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  342. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  343. package/schemas/plugins/container/ModuleFederationPlugin.json +1 -0
  344. package/types.d.ts +681 -355
@@ -6,7 +6,10 @@
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
 
12
15
  const DATA_URI_CONTENT_LENGTH = 16;
@@ -22,9 +25,8 @@ const plural = (n, singular, plural) => (n === 1 ? singular : plural);
22
25
 
23
26
  /**
24
27
  * @param {Record<string, number>} sizes sizes by source type
25
- * @param {object} options options
26
- * @param {(number) => string=} options.formatSize size formatter
27
- * @returns {string} text
28
+ * @param {StatsPrinterContext} options options
29
+ * @returns {string | undefined} text
28
30
  */
29
31
  const printSizes = (sizes, { formatSize = n => `${n}` }) => {
30
32
  const keys = Object.keys(sizes);
@@ -56,7 +58,9 @@ const getResourceName = resource => {
56
58
  * @returns {[string,string]} prefix and module name
57
59
  */
58
60
  const getModuleName = name => {
59
- const [, prefix, resource] = /^(.*!)?([^!]*)$/.exec(name);
61
+ const [, prefix, resource] =
62
+ /** @type {[any, string, string]} */
63
+ (/** @type {unknown} */ (/^(.*!)?([^!]*)$/.exec(name)));
60
64
 
61
65
  if (resource.length > MAX_MODULE_IDENTIFIER_LENGTH) {
62
66
  const truncatedResource = `${resource.slice(
@@ -86,22 +90,29 @@ const mapLines = (str, fn) => str.split("\n").map(fn).join("\n");
86
90
  */
87
91
  const twoDigit = n => (n >= 10 ? `${n}` : `0${n}`);
88
92
 
89
- const isValidId = id => {
90
- return typeof id === "number" || id;
91
- };
93
+ /**
94
+ * @param {string | number} id an id
95
+ * @returns {boolean | string} is i
96
+ */
97
+ const isValidId = id => typeof id === "number" || id;
92
98
 
93
99
  /**
94
100
  * @template T
95
- * @param {Array<T>} list of items
101
+ * @param {Array<T> | undefined} list of items
96
102
  * @param {number} count number of items to show
97
103
  * @returns {string} string representation of list
98
104
  */
99
- const moreCount = (list, count) => {
100
- return list && list.length > 0 ? `+ ${count}` : `${count}`;
101
- };
105
+ const moreCount = (list, count) =>
106
+ list && list.length > 0 ? `+ ${count}` : `${count}`;
107
+
108
+ /**
109
+ * @template T
110
+ * @template {keyof T} K
111
+ * @typedef {{ [P in K]-?: T[P] }} WithRequired
112
+ */
102
113
 
103
- /** @type {Record<string, (thing: any, context: StatsPrinterContext, printer: StatsPrinter) => string | void>} */
104
- const SIMPLE_PRINTERS = {
114
+ /** @type {Record<string, (thing: any, context: Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormaters> & WithRequired<StatsPrinterContext, "type" | "compilation">, printer: StatsPrinter) => string | undefined>} */
115
+ const COMPILATION_SIMPLE_PRINTERS = {
105
116
  "compilation.summary!": (
106
117
  _,
107
118
  {
@@ -125,14 +136,16 @@ const SIMPLE_PRINTERS = {
125
136
  ) => {
126
137
  const root = type === "compilation.summary!";
127
138
  const warningsMessage =
128
- warningsCount > 0
139
+ /** @type {number} */ (warningsCount) > 0
129
140
  ? yellow(
130
- `${warningsCount} ${plural(warningsCount, "warning", "warnings")}`
141
+ `${warningsCount} ${plural(/** @type {number} */ (warningsCount), "warning", "warnings")}`
131
142
  )
132
143
  : "";
133
144
  const errorsMessage =
134
- errorsCount > 0
135
- ? red(`${errorsCount} ${plural(errorsCount, "error", "errors")}`)
145
+ /** @type {number} */ (errorsCount) > 0
146
+ ? red(
147
+ `${errorsCount} ${plural(/** @type {number} */ (errorsCount), "error", "errors")}`
148
+ )
136
149
  : "";
137
150
  const timeMessage = root && time ? ` in ${formatTime(time)}` : "";
138
151
  const hashMessage = hash ? ` (${hash})` : "";
@@ -161,7 +174,7 @@ const SIMPLE_PRINTERS = {
161
174
  } else if (errorsCount === 0 && warningsCount === 0) {
162
175
  statusMessage = `compiled ${green("successfully")}`;
163
176
  } else {
164
- statusMessage = `compiled`;
177
+ statusMessage = "compiled";
165
178
  }
166
179
  if (
167
180
  builtAtMessage ||
@@ -258,11 +271,12 @@ const SIMPLE_PRINTERS = {
258
271
  "compilation.warningsInChildren!": (_, { yellow, compilation }) => {
259
272
  if (
260
273
  !compilation.children &&
261
- compilation.warningsCount > 0 &&
274
+ /** @type {number} */ (compilation.warningsCount) > 0 &&
262
275
  compilation.warnings
263
276
  ) {
264
277
  const childWarnings =
265
- compilation.warningsCount - compilation.warnings.length;
278
+ /** @type {number} */ (compilation.warningsCount) -
279
+ compilation.warnings.length;
266
280
  if (childWarnings > 0) {
267
281
  return yellow(
268
282
  `${childWarnings} ${plural(
@@ -281,10 +295,12 @@ const SIMPLE_PRINTERS = {
281
295
  "compilation.errorsInChildren!": (_, { red, compilation }) => {
282
296
  if (
283
297
  !compilation.children &&
284
- compilation.errorsCount > 0 &&
298
+ /** @type {number} */ (compilation.errorsCount) > 0 &&
285
299
  compilation.errors
286
300
  ) {
287
- const childErrors = compilation.errorsCount - compilation.errors.length;
301
+ const childErrors =
302
+ /** @type {number} */ (compilation.errorsCount) -
303
+ compilation.errors.length;
288
304
  if (childErrors > 0) {
289
305
  return red(
290
306
  `${childErrors} ${plural(
@@ -299,15 +315,16 @@ const SIMPLE_PRINTERS = {
299
315
  );
300
316
  }
301
317
  }
302
- },
318
+ }
319
+ };
303
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 = {
304
323
  "asset.type": type => type,
305
324
  "asset.name": (name, { formatFilename, asset: { isOverSizeLimit } }) =>
306
325
  formatFilename(name, isOverSizeLimit),
307
- "asset.size": (
308
- size,
309
- { asset: { isOverSizeLimit }, yellow, green, formatSize }
310
- ) => (isOverSizeLimit ? yellow(formatSize(size)) : formatSize(size)),
326
+ "asset.size": (size, { asset: { isOverSizeLimit }, yellow, formatSize }) =>
327
+ isOverSizeLimit ? yellow(formatSize(size)) : formatSize(size),
311
328
  "asset.emitted": (emitted, { green, formatFlag }) =>
312
329
  emitted ? green(formatFlag("emitted")) : undefined,
313
330
  "asset.comparedForEmit": (comparedForEmit, { yellow, formatFlag }) =>
@@ -356,8 +373,11 @@ const SIMPLE_PRINTERS = {
356
373
  assetChunk: (id, { formatChunkId }) => formatChunkId(id),
357
374
 
358
375
  assetChunkName: name => name,
359
- assetChunkIdHint: name => name,
376
+ assetChunkIdHint: name => name
377
+ };
360
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 = {
361
381
  "module.type": type => (type !== "module" ? type : undefined),
362
382
  "module.id": (id, { formatModuleId }) =>
363
383
  isValidId(id) ? formatModuleId(id) : undefined,
@@ -433,11 +453,11 @@ const SIMPLE_PRINTERS = {
433
453
  providedExportsCount === usedExports.length
434
454
  ) {
435
455
  return cyan(formatFlag("all exports used"));
436
- } else {
437
- return cyan(
438
- formatFlag(`only some exports used: ${usedExports.join(", ")}`)
439
- );
440
456
  }
457
+
458
+ return cyan(
459
+ formatFlag(`only some exports used: ${usedExports.join(", ")}`)
460
+ );
441
461
  }
442
462
  }
443
463
  },
@@ -470,11 +490,17 @@ const SIMPLE_PRINTERS = {
470
490
  "modules"
471
491
  )}`
472
492
  : undefined,
473
- "module.separator!": () => "\n",
493
+ "module.separator!": () => "\n"
494
+ };
474
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 = {
475
498
  "moduleIssuer.id": (id, { formatModuleId }) => formatModuleId(id),
476
- "moduleIssuer.profile.total": (value, { formatTime }) => formatTime(value),
499
+ "moduleIssuer.profile.total": (value, { formatTime }) => formatTime(value)
500
+ };
477
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 = {
478
504
  "moduleReason.type": type => type,
479
505
  "moduleReason.userRequest": (userRequest, { cyan }) =>
480
506
  cyan(getResourceName(userRequest)),
@@ -496,8 +522,11 @@ const SIMPLE_PRINTERS = {
496
522
  "reason",
497
523
  "reasons"
498
524
  )}`
499
- : undefined,
525
+ : undefined
526
+ };
500
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 = {
501
530
  "module.profile.total": (value, { formatTime }) => formatTime(value),
502
531
  "module.profile.resolving": (value, { formatTime }) =>
503
532
  `resolving: ${formatTime(value)}`,
@@ -512,8 +541,11 @@ const SIMPLE_PRINTERS = {
512
541
  "module.profile.additionalResolving": (value, { formatTime }) =>
513
542
  value ? `additional resolving: ${formatTime(value)}` : undefined,
514
543
  "module.profile.additionalIntegration": (value, { formatTime }) =>
515
- value ? `additional integration: ${formatTime(value)}` : undefined,
544
+ value ? `additional integration: ${formatTime(value)}` : undefined
545
+ };
516
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 = {
517
549
  "chunkGroup.kind!": (_, { chunkGroupKind }) => chunkGroupKind,
518
550
  "chunkGroup.separator!": () => "\n",
519
551
  "chunkGroup.name": (name, { bold }) => bold(name),
@@ -541,10 +573,11 @@ const SIMPLE_PRINTERS = {
541
573
  "chunkGroup.is!": () => "=",
542
574
  "chunkGroupAsset.name": (asset, { green }) => green(asset),
543
575
  "chunkGroupAsset.size": (size, { formatSize, chunkGroup }) =>
544
- chunkGroup.assets.length > 1 ||
576
+ chunkGroup.assets &&
577
+ (chunkGroup.assets.length > 1 ||
545
578
  (chunkGroup.auxiliaryAssets && chunkGroup.auxiliaryAssets.length > 0)
546
579
  ? formatSize(size)
547
- : undefined,
580
+ : undefined),
548
581
  "chunkGroup.children": (children, context, printer) =>
549
582
  Array.isArray(children)
550
583
  ? undefined
@@ -560,8 +593,11 @@ const SIMPLE_PRINTERS = {
560
593
  "chunkGroupChild.assets[]": (file, { formatFilename }) =>
561
594
  formatFilename(file),
562
595
  "chunkGroupChild.chunks[]": (id, { formatChunkId }) => formatChunkId(id),
563
- "chunkGroupChild.name": name => (name ? `(name: ${name})` : undefined),
596
+ "chunkGroupChild.name": name => (name ? `(name: ${name})` : undefined)
597
+ };
564
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 = {
565
601
  "chunk.id": (id, { formatChunkId }) => formatChunkId(id),
566
602
  "chunk.files[]": (file, { formatFilename }) => formatFilename(file),
567
603
  "chunk.names[]": name => name,
@@ -611,8 +647,11 @@ const SIMPLE_PRINTERS = {
611
647
  "chunkOrigin.moduleId": (moduleId, { formatModuleId }) =>
612
648
  isValidId(moduleId) ? formatModuleId(moduleId) : undefined,
613
649
  "chunkOrigin.moduleName": (moduleName, { bold }) => bold(moduleName),
614
- "chunkOrigin.loc": loc => loc,
650
+ "chunkOrigin.loc": loc => loc
651
+ };
615
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 = {
616
655
  "error.compilerPath": (compilerPath, { bold }) =>
617
656
  compilerPath ? bold(`(${compilerPath})`) : undefined,
618
657
  "error.chunkId": (chunkId, { formatChunkId }) =>
@@ -622,21 +661,23 @@ const SIMPLE_PRINTERS = {
622
661
  "error.chunkInitial": (chunkInitial, { formatFlag }) =>
623
662
  chunkInitial ? formatFlag("initial") : undefined,
624
663
  "error.file": (file, { bold }) => bold(file),
625
- "error.moduleName": (moduleName, { bold }) => {
626
- return moduleName.includes("!")
664
+ "error.moduleName": (moduleName, { bold }) =>
665
+ moduleName.includes("!")
627
666
  ? `${bold(moduleName.replace(/^(\s|\S)*!/, ""))} (${moduleName})`
628
- : `${bold(moduleName)}`;
629
- },
667
+ : `${bold(moduleName)}`,
630
668
  "error.loc": (loc, { green }) => green(loc),
631
669
  "error.message": (message, { bold, formatError }) =>
632
- message.includes("\u001b[") ? message : bold(formatError(message)),
670
+ message.includes("\u001B[") ? message : bold(formatError(message)),
633
671
  "error.details": (details, { formatError }) => formatError(details),
634
672
  "error.filteredDetails": filteredDetails =>
635
673
  filteredDetails ? `+ ${filteredDetails} hidden lines` : undefined,
636
674
  "error.stack": stack => stack,
637
675
  "error.moduleTrace": moduleTrace => undefined,
638
- "error.separator!": () => "\n",
676
+ "error.separator!": () => "\n"
677
+ };
639
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 = {
640
681
  "loggingEntry(error).loggingEntry.message": (message, { red }) =>
641
682
  mapLines(message, x => `<e> ${red(x)}`),
642
683
  "loggingEntry(warn).loggingEntry.message": (message, { yellow }) =>
@@ -666,20 +707,26 @@ const SIMPLE_PRINTERS = {
666
707
  "loggingEntry.trace[]": trace =>
667
708
  trace ? mapLines(trace, x => `| ${x}`) : undefined,
668
709
 
669
- "moduleTraceItem.originName": originName => originName,
670
-
671
710
  loggingGroup: loggingGroup =>
672
711
  loggingGroup.entries.length === 0 ? "" : undefined,
673
712
  "loggingGroup.debug": (flag, { red }) => (flag ? red("DEBUG") : undefined),
674
713
  "loggingGroup.name": (name, { bold }) => bold(`LOG from ${name}`),
675
714
  "loggingGroup.separator!": () => "\n",
676
715
  "loggingGroup.filteredEntries": filteredEntries =>
677
- 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
+ };
678
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 = {
679
726
  "moduleTraceDependency.loc": loc => loc
680
727
  };
681
728
 
682
- /** @type {Record<string, string | Function>} */
729
+ /** @type {Record<string, string | function(any): string>} */
683
730
  const ITEM_NAMES = {
684
731
  "compilation.assets[]": "asset",
685
732
  "compilation.modules[]": "module",
@@ -908,19 +955,27 @@ const PREFERRED_ORDERS = {
908
955
  loggingEntry: ["message", "trace", "children"]
909
956
  };
910
957
 
958
+ /** @typedef {(items: string[]) => string | undefined} SimpleItemsJoiner */
959
+
960
+ /** @type {SimpleItemsJoiner} */
911
961
  const itemsJoinOneLine = items => items.filter(Boolean).join(" ");
962
+ /** @type {SimpleItemsJoiner} */
912
963
  const itemsJoinOneLineBrackets = items =>
913
964
  items.length > 0 ? `(${items.filter(Boolean).join(" ")})` : undefined;
965
+ /** @type {SimpleItemsJoiner} */
914
966
  const itemsJoinMoreSpacing = items => items.filter(Boolean).join("\n\n");
967
+ /** @type {SimpleItemsJoiner} */
915
968
  const itemsJoinComma = items => items.filter(Boolean).join(", ");
969
+ /** @type {SimpleItemsJoiner} */
916
970
  const itemsJoinCommaBrackets = items =>
917
971
  items.length > 0 ? `(${items.filter(Boolean).join(", ")})` : undefined;
972
+ /** @type {function(string): SimpleItemsJoiner} */
918
973
  const itemsJoinCommaBracketsWithName = name => items =>
919
974
  items.length > 0
920
975
  ? `(${name}: ${items.filter(Boolean).join(", ")})`
921
976
  : undefined;
922
977
 
923
- /** @type {Record<string, (items: string[]) => string>} */
978
+ /** @type {Record<string, SimpleItemsJoiner>} */
924
979
  const SIMPLE_ITEMS_JOINER = {
925
980
  "chunk.parents": itemsJoinOneLine,
926
981
  "chunk.siblings": itemsJoinOneLine,
@@ -952,18 +1007,27 @@ const SIMPLE_ITEMS_JOINER = {
952
1007
  "compilation.errors": itemsJoinMoreSpacing,
953
1008
  "compilation.warnings": itemsJoinMoreSpacing,
954
1009
  "compilation.logging": itemsJoinMoreSpacing,
955
- "compilation.children": items => indent(itemsJoinMoreSpacing(items), " "),
1010
+ "compilation.children": items =>
1011
+ indent(/** @type {string} */ (itemsJoinMoreSpacing(items)), " "),
956
1012
  "moduleTraceItem.dependencies": itemsJoinOneLine,
957
1013
  "loggingEntry.children": items =>
958
1014
  indent(items.filter(Boolean).join("\n"), " ", false)
959
1015
  };
960
1016
 
1017
+ /**
1018
+ * @param {Item[]} items items
1019
+ * @returns {string} result
1020
+ */
961
1021
  const joinOneLine = items =>
962
1022
  items
963
1023
  .map(item => item.content)
964
1024
  .filter(Boolean)
965
1025
  .join(" ");
966
1026
 
1027
+ /**
1028
+ * @param {Item[]} items items
1029
+ * @returns {string} result
1030
+ */
967
1031
  const joinInBrackets = items => {
968
1032
  const res = [];
969
1033
  let mode = 0;
@@ -1006,13 +1070,24 @@ const joinInBrackets = items => {
1006
1070
  return res.join("");
1007
1071
  };
1008
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
+ */
1009
1079
  const indent = (str, prefix, noPrefixInFirstLine) => {
1010
- const rem = str.replace(/\n([^\n])/g, "\n" + prefix + "$1");
1080
+ const rem = str.replace(/\n([^\n])/g, `\n${prefix}$1`);
1011
1081
  if (noPrefixInFirstLine) return rem;
1012
1082
  const ind = str[0] === "\n" ? "" : prefix;
1013
1083
  return ind + rem;
1014
1084
  };
1015
1085
 
1086
+ /**
1087
+ * @param {(false | Item)[]} items items
1088
+ * @param {string} indenter indenter
1089
+ * @returns {string} result
1090
+ */
1016
1091
  const joinExplicitNewLine = (items, indenter) => {
1017
1092
  let firstInLine = true;
1018
1093
  let first = true;
@@ -1027,22 +1102,34 @@ const joinExplicitNewLine = (items, indenter) => {
1027
1102
  first = false;
1028
1103
  const noJoiner = firstInLine || content.startsWith("\n");
1029
1104
  firstInLine = content.endsWith("\n");
1030
- return noJoiner ? content : " " + content;
1105
+ return noJoiner ? content : ` ${content}`;
1031
1106
  })
1032
1107
  .filter(Boolean)
1033
1108
  .join("")
1034
1109
  .trim();
1035
1110
  };
1036
1111
 
1112
+ /**
1113
+ * @param {boolean} error is an error
1114
+ * @returns {SimpleElementJoiner} joiner
1115
+ */
1037
1116
  const joinError =
1038
1117
  error =>
1118
+ /**
1119
+ * @param {Item[]} items items
1120
+ * @param {Required<StatsPrinterContext>} ctx context
1121
+ * @returns {string} result
1122
+ */
1039
1123
  (items, { red, yellow }) =>
1040
1124
  `${error ? red("ERROR") : yellow("WARNING")} in ${joinExplicitNewLine(
1041
1125
  items,
1042
1126
  ""
1043
1127
  )}`;
1044
1128
 
1045
- /** @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>} */
1046
1133
  const SIMPLE_ELEMENT_JOINERS = {
1047
1134
  compilation: items => {
1048
1135
  const result = [];
@@ -1119,23 +1206,20 @@ const SIMPLE_ELEMENT_JOINERS = {
1119
1206
  },
1120
1207
  chunk: items => {
1121
1208
  let hasEntry = false;
1122
- return (
1123
- "chunk " +
1124
- joinExplicitNewLine(
1125
- items.filter(item => {
1126
- switch (item.element) {
1127
- case "entry":
1128
- if (item.content) hasEntry = true;
1129
- break;
1130
- case "initial":
1131
- if (hasEntry) return false;
1132
- break;
1133
- }
1134
- return true;
1135
- }),
1136
- " "
1137
- )
1138
- );
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
+ )}`;
1139
1223
  },
1140
1224
  "chunk.childrenByOrder[]": items => `(${joinOneLine(items)})`,
1141
1225
  chunkGroup: items => joinExplicitNewLine(items, " "),
@@ -1196,23 +1280,27 @@ const SIMPLE_ELEMENT_JOINERS = {
1196
1280
  },
1197
1281
  "module.profile": joinInBrackets,
1198
1282
  moduleIssuer: joinOneLine,
1199
- chunkOrigin: items => "> " + joinOneLine(items),
1283
+ chunkOrigin: items => `> ${joinOneLine(items)}`,
1200
1284
  "errors[].error": joinError(true),
1201
1285
  "warnings[].error": joinError(false),
1202
1286
  loggingGroup: items => joinExplicitNewLine(items, "").trimEnd(),
1203
- moduleTraceItem: items => " @ " + joinOneLine(items),
1287
+ moduleTraceItem: items => ` @ ${joinOneLine(items)}`,
1204
1288
  moduleTraceDependency: joinOneLine
1205
1289
  };
1206
1290
 
1291
+ /** @typedef {"bold" | "yellow" | "red" | "green" | "cyan" | "magenta"} ColorNames */
1292
+
1293
+ /** @type {Record<ColorNames, string>} */
1207
1294
  const AVAILABLE_COLORS = {
1208
- bold: "\u001b[1m",
1209
- yellow: "\u001b[1m\u001b[33m",
1210
- red: "\u001b[1m\u001b[31m",
1211
- green: "\u001b[1m\u001b[32m",
1212
- cyan: "\u001b[1m\u001b[36m",
1213
- 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"
1214
1301
  };
1215
1302
 
1303
+ /** @type {Record<string, function(any, Required<KnownStatsPrinterColorFn> & StatsPrinterContext, ...any): string>} */
1216
1304
  const AVAILABLE_FORMATS = {
1217
1305
  formatChunkId: (id, { yellow }, direction) => {
1218
1306
  switch (direction) {
@@ -1256,13 +1344,12 @@ const AVAILABLE_FORMATS = {
1256
1344
  else if (time < times[2]) return bold(`${time}${unit}`);
1257
1345
  else if (time < times[1]) return green(`${time}${unit}`);
1258
1346
  else if (time < times[0]) return yellow(`${time}${unit}`);
1259
- else return red(`${time}${unit}`);
1260
- } else {
1261
- return `${boldQuantity ? bold(time) : time}${unit}`;
1347
+ return red(`${time}${unit}`);
1262
1348
  }
1349
+ return `${boldQuantity ? bold(time) : time}${unit}`;
1263
1350
  },
1264
1351
  formatError: (message, { green, yellow, red }) => {
1265
- if (message.includes("\u001b[")) return message;
1352
+ if (message.includes("\u001B[")) return message;
1266
1353
  const highlights = [
1267
1354
  { regExp: /(Did you mean .+)/g, format: green },
1268
1355
  {
@@ -1290,23 +1377,36 @@ const AVAILABLE_FORMATS = {
1290
1377
  }
1291
1378
  ];
1292
1379
  for (const { regExp, format } of highlights) {
1293
- message = message.replace(regExp, (match, content) => {
1294
- return match.replace(content, format(content));
1295
- });
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
+ );
1296
1389
  }
1297
1390
  return message;
1298
1391
  }
1299
1392
  };
1300
1393
 
1394
+ /** @typedef {function(string): string} ResultModifierFn */
1395
+ /** @type {Record<string, ResultModifierFn>} */
1301
1396
  const RESULT_MODIFIER = {
1302
- "module.modules": result => {
1303
- return indent(result, "| ");
1304
- }
1397
+ "module.modules": result => indent(result, "| ")
1305
1398
  };
1306
1399
 
1400
+ /**
1401
+ * @param {string[]} array array
1402
+ * @param {string[]} preferredOrder preferred order
1403
+ * @returns {string[]} result
1404
+ */
1307
1405
  const createOrder = (array, preferredOrder) => {
1308
1406
  const originalArray = array.slice();
1407
+ /** @type {Set<string>} */
1309
1408
  const set = new Set(array);
1409
+ /** @type {Set<string>} */
1310
1410
  const usedSet = new Set();
1311
1411
  array.length = 0;
1312
1412
  for (const element of preferredOrder) {
@@ -1333,49 +1433,218 @@ class DefaultStatsPrinterPlugin {
1333
1433
  compiler.hooks.compilation.tap("DefaultStatsPrinterPlugin", compilation => {
1334
1434
  compilation.hooks.statsPrinter.tap(
1335
1435
  "DefaultStatsPrinterPlugin",
1336
- (stats, options, context) => {
1436
+ (stats, options) => {
1337
1437
  // Put colors into context
1338
1438
  stats.hooks.print
1339
1439
  .for("compilation")
1340
1440
  .tap("DefaultStatsPrinterPlugin", (compilation, context) => {
1341
1441
  for (const color of Object.keys(AVAILABLE_COLORS)) {
1442
+ const name = /** @type {ColorNames} */ (color);
1443
+ /** @type {string | undefined} */
1342
1444
  let start;
1343
1445
  if (options.colors) {
1344
1446
  if (
1345
1447
  typeof options.colors === "object" &&
1346
- typeof options.colors[color] === "string"
1448
+ typeof options.colors[name] === "string"
1347
1449
  ) {
1348
- start = options.colors[color];
1450
+ start = options.colors[name];
1349
1451
  } else {
1350
- start = AVAILABLE_COLORS[color];
1452
+ start = AVAILABLE_COLORS[name];
1351
1453
  }
1352
1454
  }
1353
1455
  if (start) {
1456
+ /**
1457
+ * @param {string} str string
1458
+ * @returns {string} string with color
1459
+ */
1354
1460
  context[color] = str =>
1355
1461
  `${start}${
1356
1462
  typeof str === "string"
1357
1463
  ? str.replace(
1358
- /((\u001b\[39m|\u001b\[22m|\u001b\[0m)+)/g,
1464
+ /((\u001B\[39m|\u001B\[22m|\u001B\[0m)+)/g,
1359
1465
  `$1${start}`
1360
1466
  )
1361
1467
  : str
1362
- }\u001b[39m\u001b[22m`;
1468
+ }\u001B[39m\u001B[22m`;
1363
1469
  } else {
1470
+ /**
1471
+ * @param {string} str string
1472
+ * @returns {string} str string
1473
+ */
1364
1474
  context[color] = str => str;
1365
1475
  }
1366
1476
  }
1367
1477
  for (const format of Object.keys(AVAILABLE_FORMATS)) {
1368
- context[format] = (content, ...args) =>
1369
- 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
+ );
1370
1491
  }
1371
1492
  context.timeReference = compilation.time;
1372
1493
  });
1373
1494
 
1374
- for (const key of Object.keys(SIMPLE_PRINTERS)) {
1495
+ for (const key of Object.keys(COMPILATION_SIMPLE_PRINTERS)) {
1496
+ stats.hooks.print
1497
+ .for(key)
1498
+ .tap("DefaultStatsPrinterPlugin", (obj, ctx) =>
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)) {
1375
1639
  stats.hooks.print
1376
1640
  .for(key)
1377
1641
  .tap("DefaultStatsPrinterPlugin", (obj, ctx) =>
1378
- SIMPLE_PRINTERS[key](obj, ctx, stats)
1642
+ MODULE_TRACE_ITEM_PRINTERS[key](
1643
+ obj,
1644
+ /** @type {Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormaters> & WithRequired<StatsPrinterContext, "type" | "compilation" | "moduleTraceItem">} */
1645
+ (ctx),
1646
+ stats
1647
+ )
1379
1648
  );
1380
1649
  }
1381
1650
 
@@ -1409,7 +1678,7 @@ class DefaultStatsPrinterPlugin {
1409
1678
  const joiner = SIMPLE_ELEMENT_JOINERS[key];
1410
1679
  stats.hooks.printElements
1411
1680
  .for(key)
1412
- .tap("DefaultStatsPrinterPlugin", joiner);
1681
+ .tap("DefaultStatsPrinterPlugin", /** @type {TODO} */ (joiner));
1413
1682
  }
1414
1683
 
1415
1684
  for (const key of Object.keys(RESULT_MODIFIER)) {