webpack 5.99.5 → 5.99.7

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 (169) hide show
  1. package/README.md +1 -1
  2. package/lib/APIPlugin.js +2 -2
  3. package/lib/AutomaticPrefetchPlugin.js +21 -22
  4. package/lib/BannerPlugin.js +31 -35
  5. package/lib/Cache.js +1 -1
  6. package/lib/Chunk.js +12 -9
  7. package/lib/CleanPlugin.js +5 -3
  8. package/lib/Compilation.js +45 -35
  9. package/lib/Compiler.js +6 -4
  10. package/lib/ContextExclusionPlugin.js +4 -2
  11. package/lib/ContextModule.js +2 -1
  12. package/lib/ContextReplacementPlugin.js +5 -3
  13. package/lib/DelegatedPlugin.js +4 -2
  14. package/lib/DllEntryPlugin.js +4 -2
  15. package/lib/DllPlugin.js +5 -3
  16. package/lib/DllReferencePlugin.js +56 -60
  17. package/lib/DynamicEntryPlugin.js +4 -2
  18. package/lib/EntryOptionPlugin.js +3 -1
  19. package/lib/EntryPlugin.js +4 -2
  20. package/lib/EnvironmentPlugin.js +4 -2
  21. package/lib/EvalDevToolModulePlugin.js +9 -7
  22. package/lib/EvalSourceMapDevToolPlugin.js +137 -138
  23. package/lib/ExternalsPlugin.js +3 -1
  24. package/lib/FlagDependencyExportsPlugin.js +2 -1
  25. package/lib/HotModuleReplacementPlugin.js +3 -3
  26. package/lib/IgnorePlugin.js +6 -4
  27. package/lib/IgnoreWarningsPlugin.js +4 -2
  28. package/lib/LibManifestPlugin.js +3 -4
  29. package/lib/LoaderOptionsPlugin.js +4 -2
  30. package/lib/LoaderTargetPlugin.js +4 -2
  31. package/lib/Module.js +29 -14
  32. package/lib/ModuleFilenameHelpers.js +1 -1
  33. package/lib/ModuleGraph.js +15 -10
  34. package/lib/ModuleInfoHeaderPlugin.js +11 -12
  35. package/lib/MultiCompiler.js +5 -3
  36. package/lib/NoEmitOnErrorsPlugin.js +5 -3
  37. package/lib/NormalModule.js +6 -2
  38. package/lib/NormalModuleReplacementPlugin.js +33 -36
  39. package/lib/PlatformPlugin.js +3 -1
  40. package/lib/PrefetchPlugin.js +5 -3
  41. package/lib/ProgressPlugin.js +23 -26
  42. package/lib/RecordIdsPlugin.js +73 -103
  43. package/lib/RuntimePlugin.js +34 -32
  44. package/lib/SourceMapDevToolPlugin.js +8 -6
  45. package/lib/Template.js +1 -1
  46. package/lib/WarnCaseSensitiveModulesPlugin.js +36 -37
  47. package/lib/WarnNoModeSetPlugin.js +3 -1
  48. package/lib/WatchIgnorePlugin.js +3 -1
  49. package/lib/WebpackError.js +11 -3
  50. package/lib/WebpackOptionsApply.js +22 -5
  51. package/lib/async-modules/InferAsyncModulesPlugin.js +25 -26
  52. package/lib/buildChunkGraph.js +7 -2
  53. package/lib/cache/IdleFileCachePlugin.js +12 -13
  54. package/lib/cache/MemoryCachePlugin.js +2 -1
  55. package/lib/cache/MemoryWithGcCachePlugin.js +10 -7
  56. package/lib/cache/PackFileCacheStrategy.js +13 -21
  57. package/lib/cache/ResolverCachePlugin.js +22 -22
  58. package/lib/cli.js +8 -4
  59. package/lib/config/defaults.js +2 -2
  60. package/lib/config/normalization.js +9 -3
  61. package/lib/config/target.js +6 -6
  62. package/lib/container/ContainerReferencePlugin.js +24 -26
  63. package/lib/container/ModuleFederationPlugin.js +2 -1
  64. package/lib/css/CssGenerator.js +1 -1
  65. package/lib/css/CssModulesPlugin.js +6 -4
  66. package/lib/css/CssParser.js +1 -1
  67. package/lib/debug/ProfilingPlugin.js +1 -1
  68. package/lib/dependencies/ContextDependencyHelpers.js +1 -1
  69. package/lib/dependencies/CssIcssImportDependency.js +3 -2
  70. package/lib/dependencies/HarmonyDetectionParserPlugin.js +9 -15
  71. package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
  72. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
  73. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +1 -1
  74. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -15
  75. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +4 -2
  76. package/lib/dependencies/JsonExportsDependency.js +1 -1
  77. package/lib/dependencies/LoaderPlugin.js +5 -3
  78. package/lib/dependencies/LocalModulesHelpers.js +1 -1
  79. package/lib/dependencies/RequireContextDependencyParserPlugin.js +46 -46
  80. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +94 -100
  81. package/lib/dependencies/RequireResolveDependency.js +1 -1
  82. package/lib/dependencies/WorkerPlugin.js +2 -2
  83. package/lib/esm/ModuleChunkLoadingPlugin.js +76 -57
  84. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +11 -9
  85. package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
  86. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +0 -1
  87. package/lib/hmr/LazyCompilationPlugin.js +17 -18
  88. package/lib/ids/ChunkModuleIdRangePlugin.js +6 -6
  89. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
  90. package/lib/ids/DeterministicModuleIdsPlugin.js +48 -49
  91. package/lib/ids/HashedModuleIdsPlugin.js +4 -2
  92. package/lib/ids/NamedChunkIdsPlugin.js +6 -4
  93. package/lib/ids/NamedModuleIdsPlugin.js +6 -4
  94. package/lib/ids/NaturalChunkIdsPlugin.js +4 -2
  95. package/lib/ids/NaturalModuleIdsPlugin.js +4 -2
  96. package/lib/ids/OccurrenceChunkIdsPlugin.js +4 -2
  97. package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -2
  98. package/lib/index.js +1 -1
  99. package/lib/javascript/BasicEvaluatedExpression.js +2 -2
  100. package/lib/javascript/JavascriptParser.js +670 -688
  101. package/lib/library/EnableLibraryPlugin.js +15 -2
  102. package/lib/library/ModuleLibraryPlugin.js +66 -43
  103. package/lib/logging/createConsoleLogger.js +0 -1
  104. package/lib/node/CommonJsChunkLoadingPlugin.js +71 -75
  105. package/lib/node/NodeEnvironmentPlugin.js +3 -1
  106. package/lib/node/NodeTemplatePlugin.js +2 -2
  107. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -2
  108. package/lib/node/ReadFileCompileWasmPlugin.js +3 -3
  109. package/lib/optimize/AggressiveMergingPlugin.js +1 -1
  110. package/lib/optimize/AggressiveSplittingPlugin.js +224 -232
  111. package/lib/optimize/ConcatenatedModule.js +12 -15
  112. package/lib/optimize/FlagIncludedChunksPlugin.js +92 -97
  113. package/lib/optimize/LimitChunkCountPlugin.js +4 -2
  114. package/lib/optimize/MangleExportsPlugin.js +15 -16
  115. package/lib/optimize/MinChunkSizePlugin.js +4 -2
  116. package/lib/optimize/ModuleConcatenationPlugin.js +4 -2
  117. package/lib/optimize/RealContentHashPlugin.js +4 -2
  118. package/lib/optimize/RemoveEmptyChunksPlugin.js +5 -3
  119. package/lib/optimize/RemoveParentModulesPlugin.js +4 -2
  120. package/lib/optimize/RuntimeChunkPlugin.js +17 -18
  121. package/lib/optimize/SplitChunksPlugin.js +9 -6
  122. package/lib/performance/SizeLimitsPlugin.js +3 -1
  123. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +61 -62
  124. package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -4
  125. package/lib/runtime/StartupChunkDependenciesPlugin.js +39 -42
  126. package/lib/schemes/DataUriPlugin.js +5 -3
  127. package/lib/schemes/FileUriPlugin.js +5 -3
  128. package/lib/schemes/HttpUriPlugin.js +32 -39
  129. package/lib/serialization/AggregateErrorSerializer.js +42 -0
  130. package/lib/serialization/BinaryMiddleware.js +22 -38
  131. package/lib/serialization/ErrorObjectSerializer.js +7 -2
  132. package/lib/serialization/FileMiddleware.js +29 -33
  133. package/lib/serialization/ObjectMiddleware.js +42 -30
  134. package/lib/serialization/Serializer.js +29 -18
  135. package/lib/serialization/SerializerMiddleware.js +105 -72
  136. package/lib/serialization/SingleItemMiddleware.js +4 -5
  137. package/lib/sharing/ProvideSharedPlugin.js +6 -4
  138. package/lib/stats/DefaultStatsFactoryPlugin.js +128 -57
  139. package/lib/stats/DefaultStatsPresetPlugin.js +25 -20
  140. package/lib/stats/DefaultStatsPrinterPlugin.js +486 -334
  141. package/lib/stats/StatsFactory.js +47 -10
  142. package/lib/stats/StatsPrinter.js +52 -31
  143. package/lib/util/ArrayQueue.js +1 -1
  144. package/lib/util/AsyncQueue.js +1 -1
  145. package/lib/util/TupleQueue.js +9 -7
  146. package/lib/util/TupleSet.js +37 -18
  147. package/lib/util/WeakTupleMap.js +50 -37
  148. package/lib/util/cleverMerge.js +2 -2
  149. package/lib/util/comparators.js +1 -1
  150. package/lib/util/concatenate.js +4 -2
  151. package/lib/util/createHash.js +1 -1
  152. package/lib/util/fs.js +1 -1
  153. package/lib/util/makeSerializable.js +1 -1
  154. package/lib/util/runtime.js +1 -0
  155. package/lib/util/serialization.js +50 -42
  156. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
  157. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -1
  158. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
  159. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +55 -57
  160. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -1
  161. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
  162. package/lib/web/FetchCompileWasmPlugin.js +2 -2
  163. package/lib/web/JsonpChunkLoadingPlugin.js +73 -74
  164. package/lib/webpack.js +1 -1
  165. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +77 -78
  166. package/package.json +4 -3
  167. package/schemas/WebpackOptions.check.js +1 -1
  168. package/schemas/WebpackOptions.json +24 -2
  169. package/types.d.ts +273 -128
@@ -6,17 +6,34 @@
6
6
  "use strict";
7
7
 
8
8
  /** @typedef {import("../Compiler")} Compiler */
9
+ /** @typedef {import("../logging/Logger").LogTypeEnum} LogTypeEnum */
10
+ /** @typedef {import("./DefaultStatsFactoryPlugin").ChunkId} ChunkId */
11
+ /** @typedef {import("./DefaultStatsFactoryPlugin").ChunkName} ChunkName */
12
+ /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsAsset} KnownStatsAsset */
13
+ /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsAssetChunk} KnownStatsAssetChunk */
14
+ /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsAssetChunkIdHint} KnownStatsAssetChunkIdHint */
15
+ /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsAssetChunkName} KnownStatsAssetChunkName */
16
+ /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsChunk} KnownStatsChunk */
9
17
  /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsChunkGroup} KnownStatsChunkGroup */
18
+ /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsChunkOrigin} KnownStatsChunkOrigin */
19
+ /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsCompilation} KnownStatsCompilation */
10
20
  /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsError} KnownStatsError */
21
+ /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsLogging} KnownStatsLogging */
22
+ /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsLoggingEntry} KnownStatsLoggingEntry */
23
+ /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsModule} KnownStatsModule */
11
24
  /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsModuleIssuer} KnownStatsModuleIssuer */
25
+ /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsModuleReason} KnownStatsModuleReason */
12
26
  /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsModuleTraceDependency} KnownStatsModuleTraceDependency */
13
27
  /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsModuleTraceItem} KnownStatsModuleTraceItem */
14
28
  /** @typedef {import("./DefaultStatsFactoryPlugin").KnownStatsProfile} KnownStatsProfile */
29
+ /** @typedef {import("./DefaultStatsFactoryPlugin").StatsCompilation} StatsCompilation */
15
30
  /** @typedef {import("./StatsPrinter")} StatsPrinter */
16
- /** @typedef {import("./StatsPrinter").KnownStatsPrinterColorFn} KnownStatsPrinterColorFn */
31
+ /** @typedef {import("./StatsPrinter").ColorFunction} ColorFunction */
32
+ /** @typedef {import("./StatsPrinter").KnownStatsPrinterColorFunctions} KnownStatsPrinterColorFunctions */
17
33
  /** @typedef {import("./StatsPrinter").KnownStatsPrinterContext} KnownStatsPrinterContext */
18
34
  /** @typedef {import("./StatsPrinter").KnownStatsPrinterFormatters} KnownStatsPrinterFormatters */
19
35
  /** @typedef {import("./StatsPrinter").StatsPrinterContext} StatsPrinterContext */
36
+ /** @typedef {import("./StatsPrinter").StatsPrinterContextWithExtra} StatsPrinterContextWithExtra */
20
37
 
21
38
  const DATA_URI_CONTENT_LENGTH = 16;
22
39
  const MAX_MODULE_IDENTIFIER_LENGTH = 80;
@@ -44,10 +61,11 @@ const printSizes = (sizes, { formatSize = n => `${n}` }) => {
44
61
  };
45
62
 
46
63
  /**
47
- * @param {string} resource resource
64
+ * @param {string | null} resource resource
48
65
  * @returns {string} resource name for display
49
66
  */
50
67
  const getResourceName = resource => {
68
+ if (!resource) return "";
51
69
  const dataUrl = /^data:[^,]+,/.exec(resource);
52
70
  if (!dataUrl) return resource;
53
71
 
@@ -97,10 +115,16 @@ const mapLines = (str, fn) => str.split("\n").map(fn).join("\n");
97
115
  const twoDigit = n => (n >= 10 ? `${n}` : `0${n}`);
98
116
 
99
117
  /**
100
- * @param {string | number} id an id
101
- * @returns {boolean | string} is i
118
+ * @param {string | number | null} id an id
119
+ * @returns {id is string | number} is i
102
120
  */
103
- const isValidId = id => typeof id === "number" || id;
121
+ const isValidId = id => {
122
+ if (typeof id === "number" || id) {
123
+ return true;
124
+ }
125
+
126
+ return false;
127
+ };
104
128
 
105
129
  /**
106
130
  * @template T
@@ -119,13 +143,13 @@ const moreCount = (list, count) =>
119
143
 
120
144
  /**
121
145
  * @template {keyof StatsPrinterContext} RequiredStatsPrinterContextKeys
122
- * @typedef {Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormatters> & WithRequired<StatsPrinterContext, "type" | "compilation" | RequiredStatsPrinterContextKeys>} DefineStatsPrinterContext
146
+ * @typedef {StatsPrinterContextWithExtra & WithRequired<StatsPrinterContext, "compilation" | RequiredStatsPrinterContextKeys>} DefineStatsPrinterContext
123
147
  */
124
148
 
125
149
  /**
126
150
  * @template T
127
151
  * @template {keyof StatsPrinterContext} RequiredStatsPrinterContextKeys
128
- * @typedef {(thing: Exclude<T, undefined>, context: DefineStatsPrinterContext<RequiredStatsPrinterContextKeys>, printer: StatsPrinter) => string | undefined} ModuleSimplePrinter
152
+ * @typedef {(thing: Exclude<T, undefined>, context: DefineStatsPrinterContext<RequiredStatsPrinterContextKeys>, printer: StatsPrinter) => string | undefined} SimplePrinter
129
153
  */
130
154
 
131
155
  /**
@@ -135,24 +159,52 @@ const moreCount = (list, count) =>
135
159
 
136
160
  /**
137
161
  * @template {object} O
138
- * @template {keyof O} P
162
+ * @template {keyof O} K
163
+ * @template {string} B
164
+ * @typedef {K extends string ? Exclude<O[K], undefined> extends EXPECTED_ANY[] ? never : `${B}.${K}` : never} PropertyName
165
+ */
166
+
167
+ /**
168
+ * @template {object} O
169
+ * @template {keyof O} K
170
+ * @template {string} B
171
+ * @typedef {K extends string ? NonNullable<O[K]> extends EXPECTED_ANY[] ? `${B}.${K}[]` : never : never} ArrayPropertyName
172
+ */
173
+
174
+ /**
175
+ * @template {object} O
176
+ * @template {keyof O} K
139
177
  * @template {string} B
140
- * @typedef {P extends string ? `${B}.${P}` : never} PropertyName
178
+ * @typedef {K extends string ? Exclude<O[K], undefined> extends EXPECTED_ANY[] ? `${B}.${K}` : never : never} MultiplePropertyName
141
179
  */
142
180
 
143
181
  /**
144
- * @template {string} T
145
- * @typedef {{ [property in `${T}.separator!`]: () => string }} Separator
182
+ * @template {object} O
183
+ * @template {string} K
184
+ * @template {string} E
185
+ * @typedef {{ [property in `${K}!`]?: SimplePrinter<O, "compilation" | E> }} Exclamation
146
186
  */
147
187
 
148
188
  /**
149
189
  * @template {object} O
150
190
  * @template {string} B
151
191
  * @template {string} [R=B]
152
- * @typedef {{ [P in keyof O as PropertyName<O, P, B>]?: ModuleSimplePrinter<O[P], R> }} Printers
192
+ * @typedef {{ [K in keyof O as PropertyName<O, K, B>]?: SimplePrinter<O[K], R> } &
193
+ * { [K in keyof O as ArrayPropertyName<O, K, B>]?: Exclude<O[K], undefined> extends (infer I)[] ? SimplePrinter<I, R> : never } &
194
+ * { [K in keyof O as MultiplePropertyName<O, K, B>]?: SimplePrinter<O[K], R> }
195
+ * } Printers
196
+ */
197
+
198
+ /**
199
+ * @typedef {Printers<KnownStatsCompilation, "compilation"> &
200
+ * { ["compilation.summary!"]?: SimplePrinter<KnownStatsCompilation, "compilation"> } &
201
+ * { ["compilation.errorsInChildren!"]?: SimplePrinter<KnownStatsCompilation, "compilation"> } &
202
+ * { ["compilation.warningsInChildren!"]?: SimplePrinter<KnownStatsCompilation, "compilation"> }} CompilationSimplePrinters
153
203
  */
154
204
 
155
- /** @type {Record<string, (thing: any, context: Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormatters> & WithRequired<StatsPrinterContext, "type" | "compilation">, printer: StatsPrinter) => string | undefined>} */
205
+ /**
206
+ * @type {CompilationSimplePrinters}
207
+ */
156
208
  const COMPILATION_SIMPLE_PRINTERS = {
157
209
  "compilation.summary!": (
158
210
  _,
@@ -268,7 +320,11 @@ const COMPILATION_SIMPLE_PRINTERS = {
268
320
  if (entrypoints) {
269
321
  chunkGroups = chunkGroups.filter(
270
322
  group =>
271
- !Object.prototype.hasOwnProperty.call(entrypoints, group.name)
323
+ !Object.prototype.hasOwnProperty.call(
324
+ entrypoints,
325
+ /** @type {string} */
326
+ (group.name)
327
+ )
272
328
  );
273
329
  }
274
330
  return printer.print(context.type, chunkGroups, {
@@ -359,7 +415,17 @@ const COMPILATION_SIMPLE_PRINTERS = {
359
415
  }
360
416
  };
361
417
 
362
- /** @type {Record<string, (thing: any, context: Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormatters> & WithRequired<StatsPrinterContext, "type" | "compilation" | "asset">, printer: StatsPrinter) => string | undefined>} */
418
+ /**
419
+ * @typedef {Printers<KnownStatsAsset, "asset"> &
420
+ * Printers<KnownStatsAsset["info"], "asset.info"> &
421
+ * Exclamation<KnownStatsAsset, "asset.separator", "asset"> &
422
+ * { ["asset.filteredChildren"]?: SimplePrinter<number, "asset"> } &
423
+ * { assetChunk?: SimplePrinter<KnownStatsAssetChunk, "asset"> } &
424
+ * { assetChunkName?: SimplePrinter<KnownStatsAssetChunkName, "asset"> } &
425
+ * { assetChunkIdHint?: SimplePrinter<KnownStatsAssetChunkIdHint, "asset"> }} AssetSimplePrinters
426
+ */
427
+
428
+ /** @type {AssetSimplePrinters} */
363
429
  const ASSET_SIMPLE_PRINTERS = {
364
430
  "asset.type": type => type,
365
431
  "asset.name": (name, { formatFilename, asset: { isOverSizeLimit } }) =>
@@ -407,11 +473,18 @@ const ASSET_SIMPLE_PRINTERS = {
407
473
 
408
474
  assetChunk: (id, { formatChunkId }) => formatChunkId(id),
409
475
 
410
- assetChunkName: name => name,
411
- assetChunkIdHint: name => name
476
+ assetChunkName: name => name || undefined,
477
+ assetChunkIdHint: name => name || undefined
412
478
  };
413
479
 
414
- /** @type {Record<string, (thing: any, context: Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormatters> & WithRequired<StatsPrinterContext, "type" | "compilation" | "module">, printer: StatsPrinter) => string | undefined>} */
480
+ /**
481
+ * @typedef {Printers<KnownStatsModule, "module"> &
482
+ * Exclamation<KnownStatsModule, "module.separator", "module"> &
483
+ * { ["module.filteredChildren"]?: SimplePrinter<number, "module"> } &
484
+ * { ["module.filteredReasons"]?: SimplePrinter<number, "module"> }} ModuleSimplePrinters
485
+ */
486
+
487
+ /** @type {ModuleSimplePrinters} */
415
488
  const MODULE_SIMPLE_PRINTERS = {
416
489
  "module.type": type => (type !== "module" ? type : undefined),
417
490
  "module.id": (id, { formatModuleId }) =>
@@ -431,8 +504,8 @@ const MODULE_SIMPLE_PRINTERS = {
431
504
  cacheable === false ? red(formatFlag("not cacheable")) : undefined,
432
505
  "module.orphan": (orphan, { formatFlag, yellow }) =>
433
506
  orphan ? yellow(formatFlag("orphan")) : undefined,
434
- "module.runtime": (runtime, { formatFlag, yellow }) =>
435
- runtime ? yellow(formatFlag("runtime")) : undefined,
507
+ // "module.runtime": (runtime, { formatFlag, yellow }) =>
508
+ // runtime ? yellow(formatFlag("runtime")) : undefined,
436
509
  "module.optional": (optional, { formatFlag, yellow }) =>
437
510
  optional ? yellow(formatFlag("optional")) : undefined,
438
511
  "module.dependent": (dependent, { formatFlag, cyan }) =>
@@ -454,19 +527,15 @@ const MODULE_SIMPLE_PRINTERS = {
454
527
  )
455
528
  : undefined,
456
529
  "module.warnings": (warnings, { formatFlag, yellow }) =>
457
- warnings === true
458
- ? yellow(formatFlag("warnings"))
459
- : warnings
460
- ? yellow(
461
- formatFlag(`${warnings} ${plural(warnings, "warning", "warnings")}`)
462
- )
463
- : undefined,
530
+ warnings
531
+ ? yellow(
532
+ formatFlag(`${warnings} ${plural(warnings, "warning", "warnings")}`)
533
+ )
534
+ : undefined,
464
535
  "module.errors": (errors, { formatFlag, red }) =>
465
- errors === true
466
- ? red(formatFlag("errors"))
467
- : errors
468
- ? red(formatFlag(`${errors} ${plural(errors, "error", "errors")}`))
469
- : undefined,
536
+ errors
537
+ ? red(formatFlag(`${errors} ${plural(errors, "error", "errors")}`))
538
+ : undefined,
470
539
  "module.providedExports": (providedExports, { formatFlag, cyan }) => {
471
540
  if (Array.isArray(providedExports)) {
472
541
  if (providedExports.length === 0) return cyan(formatFlag("no exports"));
@@ -528,25 +597,38 @@ const MODULE_SIMPLE_PRINTERS = {
528
597
  "module.separator!": () => "\n"
529
598
  };
530
599
 
531
- /** @type {Printers<KnownStatsModuleIssuer, "moduleIssuer"> & Printers<KnownStatsModuleIssuer["profile"], "moduleIssuer.profile", "moduleIssuer">} */
600
+ /**
601
+ * @typedef {Printers<KnownStatsModuleIssuer, "moduleIssuer"> &
602
+ * Printers<KnownStatsModuleIssuer["profile"], "moduleIssuer.profile", "moduleIssuer">} ModuleIssuerPrinters
603
+ */
604
+
605
+ /** @type {ModuleIssuerPrinters} */
532
606
  const MODULE_ISSUER_PRINTERS = {
533
607
  "moduleIssuer.id": (id, { formatModuleId }) => formatModuleId(id),
534
608
  "moduleIssuer.profile.total": (value, { formatTime }) => formatTime(value)
535
609
  };
536
610
 
537
- /** @type {Record<string, (thing: any, context: Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormatters> & WithRequired<StatsPrinterContext, "type" | "compilation" | "moduleReason">, printer: StatsPrinter) => string | undefined>} */
611
+ /**
612
+ * @typedef {Printers<KnownStatsModuleReason, "moduleReason"> &
613
+ * { ["moduleReason.filteredChildren"]?: SimplePrinter<number, "moduleReason"> }} ModuleReasonsPrinters
614
+ */
615
+
616
+ /** @type {ModuleReasonsPrinters} */
538
617
  const MODULE_REASON_PRINTERS = {
539
- "moduleReason.type": type => type,
618
+ "moduleReason.type": type => type || undefined,
540
619
  "moduleReason.userRequest": (userRequest, { cyan }) =>
541
620
  cyan(getResourceName(userRequest)),
542
621
  "moduleReason.moduleId": (moduleId, { formatModuleId }) =>
543
622
  isValidId(moduleId) ? formatModuleId(moduleId) : undefined,
544
- "moduleReason.module": (module, { magenta }) => magenta(module),
545
- "moduleReason.loc": loc => loc,
546
- "moduleReason.explanation": (explanation, { cyan }) => cyan(explanation),
623
+ "moduleReason.module": (module, { magenta }) =>
624
+ module ? magenta(module) : undefined,
625
+ "moduleReason.loc": loc => loc || undefined,
626
+ "moduleReason.explanation": (explanation, { cyan }) =>
627
+ explanation ? cyan(explanation) : undefined,
547
628
  "moduleReason.active": (active, { formatFlag }) =>
548
629
  active ? undefined : formatFlag("inactive"),
549
- "moduleReason.resolvedModule": (module, { magenta }) => magenta(module),
630
+ "moduleReason.resolvedModule": (module, { magenta }) =>
631
+ module ? magenta(module) : undefined,
550
632
  "moduleReason.filteredChildren": (
551
633
  filteredChildren,
552
634
  { moduleReason: { children } }
@@ -560,7 +642,9 @@ const MODULE_REASON_PRINTERS = {
560
642
  : undefined
561
643
  };
562
644
 
563
- /** @type {Printers<KnownStatsProfile, "module.profile", "profile">} */
645
+ /** @typedef {Printers<KnownStatsProfile, "module.profile", "profile">} ModuleProfilePrinters */
646
+
647
+ /** @type {ModuleProfilePrinters} */
564
648
  const MODULE_PROFILE_PRINTERS = {
565
649
  "module.profile.total": (value, { formatTime }) => formatTime(value),
566
650
  "module.profile.resolving": (value, { formatTime }) =>
@@ -579,11 +663,23 @@ const MODULE_PROFILE_PRINTERS = {
579
663
  value ? `additional integration: ${formatTime(value)}` : undefined
580
664
  };
581
665
 
582
- /** @type {Record<string, (thing: any, context: Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormatters> & WithRequired<StatsPrinterContext, "type" | "compilation" | "chunkGroupKind" | "chunkGroup">, printer: StatsPrinter) => string | undefined>} */
666
+ /**
667
+ * @typedef {Exclamation<KnownStatsChunkGroup, "chunkGroup.kind", "chunkGroupKind"> &
668
+ * Exclamation<KnownStatsChunkGroup, "chunkGroup.separator", "chunkGroup"> &
669
+ * Printers<KnownStatsChunkGroup, "chunkGroup"> &
670
+ * Exclamation<KnownStatsChunkGroup, "chunkGroup.is", "chunkGroup"> &
671
+ * Printers<Exclude<KnownStatsChunkGroup["assets"], undefined>[number], "chunkGroupAsset" | "chunkGroup"> &
672
+ * { ['chunkGroupChildGroup.type']?: SimplePrinter<string, "chunkGroupAsset"> } &
673
+ * { ['chunkGroupChild.assets[]']?: SimplePrinter<string, "chunkGroupAsset"> } &
674
+ * { ['chunkGroupChild.chunks[]']?: SimplePrinter<ChunkId, "chunkGroupAsset"> } &
675
+ * { ['chunkGroupChild.name']?: SimplePrinter<ChunkName, "chunkGroupAsset"> }} ChunkGroupPrinters
676
+ */
677
+
678
+ /** @type {ChunkGroupPrinters} */
583
679
  const CHUNK_GROUP_PRINTERS = {
584
680
  "chunkGroup.kind!": (_, { chunkGroupKind }) => chunkGroupKind,
585
681
  "chunkGroup.separator!": () => "\n",
586
- "chunkGroup.name": (name, { bold }) => bold(name),
682
+ "chunkGroup.name": (name, { bold }) => (name ? bold(name) : undefined),
587
683
  "chunkGroup.isOverSizeLimit": (isOverSizeLimit, { formatFlag, yellow }) =>
588
684
  isOverSizeLimit ? yellow(formatFlag("big")) : undefined,
589
685
  "chunkGroup.assetsSize": (size, { formatSize }) =>
@@ -631,7 +727,15 @@ const CHUNK_GROUP_PRINTERS = {
631
727
  "chunkGroupChild.name": name => (name ? `(name: ${name})` : undefined)
632
728
  };
633
729
 
634
- /** @type {Record<string, (thing: any, context: Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormatters> & WithRequired<StatsPrinterContext, "type" | "compilation" | "chunk">, printer: StatsPrinter) => string | undefined>} */
730
+ /**
731
+ * @typedef {Printers<KnownStatsChunk, "chunk"> &
732
+ * { ["chunk.childrenByOrder[].type"]: SimplePrinter<string, "chunk"> } &
733
+ * { ["chunk.childrenByOrder[].children[]"]: SimplePrinter<ChunkId, "chunk"> } &
734
+ * Exclamation<KnownStatsChunk, "chunk.separator", "chunk"> &
735
+ * Printers<KnownStatsChunkOrigin, "chunkOrigin">} ChunkPrinters
736
+ */
737
+
738
+ /** @type {ChunkPrinters} */
635
739
  const CHUNK_PRINTERS = {
636
740
  "chunk.id": (id, { formatChunkId }) => formatChunkId(id),
637
741
  "chunk.files[]": (file, { formatFilename }) => formatFilename(file),
@@ -685,7 +789,15 @@ const CHUNK_PRINTERS = {
685
789
  "chunkOrigin.loc": loc => loc
686
790
  };
687
791
 
688
- /** @type {Printers<KnownStatsError, "error"> & { ["error.filteredDetails"]?: (filteredDetails: number) => string | undefined } & Separator<"error">} */
792
+ /**
793
+ * @typedef {Printers<KnownStatsError, "error"> &
794
+ * { ["error.filteredDetails"]?: SimplePrinter<number, "error"> } &
795
+ * Exclamation<KnownStatsError, "error.separator", "error">} ErrorPrinters
796
+ */
797
+
798
+ /**
799
+ * @type {ErrorPrinters}
800
+ */
689
801
  const ERROR_PRINTERS = {
690
802
  "error.compilerPath": (compilerPath, { bold }) =>
691
803
  compilerPath ? bold(`(${compilerPath})`) : undefined,
@@ -707,11 +819,30 @@ const ERROR_PRINTERS = {
707
819
  "error.filteredDetails": filteredDetails =>
708
820
  filteredDetails ? `+ ${filteredDetails} hidden lines` : undefined,
709
821
  "error.stack": stack => stack,
822
+ "error.cause": (cause, context, printer) =>
823
+ cause
824
+ ? indent(
825
+ `[cause]: ${
826
+ /** @type {string} */
827
+ (printer.print(`${context.type}.error`, cause, context))
828
+ }`,
829
+ " "
830
+ )
831
+ : undefined,
710
832
  "error.moduleTrace": moduleTrace => undefined,
711
833
  "error.separator!": () => "\n"
712
834
  };
713
835
 
714
- /** @type {Record<string, (thing: any, context: Required<KnownStatsPrinterColorFn> & Required<KnownStatsPrinterFormatters> & WithRequired<StatsPrinterContext, "type" | "compilation" | "logging">, printer: StatsPrinter) => string | undefined>} */
836
+ /**
837
+ * @typedef {Printers<KnownStatsLoggingEntry, `loggingEntry(${LogTypeEnum}).loggingEntry`> &
838
+ * { ["loggingEntry(clear).loggingEntry"]?: SimplePrinter<KnownStatsLoggingEntry, "logging"> } &
839
+ * { ["loggingEntry.trace[]"]?: SimplePrinter<Exclude<KnownStatsLoggingEntry["trace"], undefined>[number], "logging"> } &
840
+ * { loggingGroup?: SimplePrinter<KnownStatsLogging[], "logging"> } &
841
+ * Printers<KnownStatsLogging & { name: string }, `loggingGroup`> &
842
+ * Exclamation<KnownStatsLogging, "loggingGroup.separator", "loggingGroup">} LogEntryPrinters
843
+ */
844
+
845
+ /** @type {LogEntryPrinters} */
715
846
  const LOG_ENTRY_PRINTERS = {
716
847
  "loggingEntry(error).loggingEntry.message": (message, { red }) =>
717
848
  mapLines(message, x => `<e> ${red(x)}`),
@@ -751,18 +882,22 @@ const LOG_ENTRY_PRINTERS = {
751
882
  filteredEntries > 0 ? `+ ${filteredEntries} hidden lines` : undefined
752
883
  };
753
884
 
754
- /** @type {Printers<KnownStatsModuleTraceItem, "moduleTraceItem">} */
885
+ /** @typedef {Printers<KnownStatsModuleTraceItem, "moduleTraceItem">} ModuleTraceItemPrinters */
886
+
887
+ /** @type {ModuleTraceItemPrinters} */
755
888
  const MODULE_TRACE_ITEM_PRINTERS = {
756
889
  "moduleTraceItem.originName": originName => originName
757
890
  };
758
891
 
759
- /** @type {Printers<KnownStatsModuleTraceDependency, "moduleTraceDependency">} */
892
+ /** @typedef {Printers<KnownStatsModuleTraceDependency, "moduleTraceDependency">} ModuleTraceDependencyPrinters */
893
+
894
+ /** @type {ModuleTraceDependencyPrinters} */
760
895
  const MODULE_TRACE_DEPENDENCY_PRINTERS = {
761
896
  "moduleTraceDependency.loc": loc => loc
762
897
  };
763
898
 
764
899
  /**
765
- * @type {Record<string, string | ((item: EXPECTED_ANY) => string)>}
900
+ * @type {Record<string, string | ((item: KnownStatsLoggingEntry) => string)>}
766
901
  */
767
902
  const ITEM_NAMES = {
768
903
  "compilation.assets[]": "asset",
@@ -800,6 +935,7 @@ const ITEM_NAMES = {
800
935
  "loggingEntry.children[]": logEntry =>
801
936
  `loggingEntry(${logEntry.type}).loggingEntry`,
802
937
  "error.moduleTrace[]": "moduleTraceItem",
938
+ "error.errors[]": "error",
803
939
  "moduleTraceItem.dependencies[]": "moduleTraceDependency"
804
940
  };
805
941
 
@@ -821,6 +957,8 @@ const ERROR_PREFERRED_ORDER = [
821
957
  "separator!",
822
958
  "stack",
823
959
  "separator!",
960
+ "cause",
961
+ "separator!",
824
962
  "missing",
825
963
  "separator!",
826
964
  "moduleTrace"
@@ -1154,7 +1292,7 @@ const joinError =
1154
1292
  error =>
1155
1293
  /**
1156
1294
  * @param {Item[]} items items
1157
- * @param {Required<StatsPrinterContext>} ctx context
1295
+ * @param {StatsPrinterContextWithExtra} ctx context
1158
1296
  * @returns {string} result
1159
1297
  */
1160
1298
  (items, { red, yellow }) =>
@@ -1163,8 +1301,8 @@ const joinError =
1163
1301
  ""
1164
1302
  )}`;
1165
1303
 
1166
- /** @typedef {{ element: string, content: string }} Item */
1167
- /** @typedef {(items: Item[], context: Required<StatsPrinterContext>) => string} SimpleElementJoiner */
1304
+ /** @typedef {{ element: string, content: string | undefined }} Item */
1305
+ /** @typedef {(items: Item[], context: StatsPrinterContextWithExtra & Required<KnownStatsPrinterContext>) => string} SimpleElementJoiner */
1168
1306
 
1169
1307
  /** @type {Record<string, SimpleElementJoiner>} */
1170
1308
  const SIMPLE_ELEMENT_JOINERS = {
@@ -1263,28 +1401,6 @@ const SIMPLE_ELEMENT_JOINERS = {
1263
1401
  chunkGroupAsset: joinOneLine,
1264
1402
  chunkGroupChildGroup: joinOneLine,
1265
1403
  chunkGroupChild: joinOneLine,
1266
- // moduleReason: (items, { moduleReason }) => {
1267
- // let hasName = false;
1268
- // return joinOneLine(
1269
- // items.filter(item => {
1270
- // switch (item.element) {
1271
- // case "moduleId":
1272
- // if (moduleReason.moduleId === moduleReason.module && item.content)
1273
- // hasName = true;
1274
- // break;
1275
- // case "module":
1276
- // if (hasName) return false;
1277
- // break;
1278
- // case "resolvedModule":
1279
- // return (
1280
- // moduleReason.module !== moduleReason.resolvedModule &&
1281
- // item.content
1282
- // );
1283
- // }
1284
- // return true;
1285
- // })
1286
- // );
1287
- // },
1288
1404
  moduleReason: (items, { moduleReason }) => {
1289
1405
  let hasName = false;
1290
1406
  return joinExplicitNewLine(
@@ -1320,14 +1436,15 @@ const SIMPLE_ELEMENT_JOINERS = {
1320
1436
  chunkOrigin: items => `> ${joinOneLine(items)}`,
1321
1437
  "errors[].error": joinError(true),
1322
1438
  "warnings[].error": joinError(false),
1439
+ error: items => joinExplicitNewLine(items, ""),
1440
+ "error.errors[].error": items =>
1441
+ indent(`[errors]: ${joinExplicitNewLine(items, "")}`, " "),
1323
1442
  loggingGroup: items => joinExplicitNewLine(items, "").trimEnd(),
1324
1443
  moduleTraceItem: items => ` @ ${joinOneLine(items)}`,
1325
1444
  moduleTraceDependency: joinOneLine
1326
1445
  };
1327
1446
 
1328
- /** @typedef {"bold" | "yellow" | "red" | "green" | "cyan" | "magenta"} ColorNames */
1329
-
1330
- /** @type {Record<ColorNames, string>} */
1447
+ /** @type {Record<keyof KnownStatsPrinterColorFunctions, string>} */
1331
1448
  const AVAILABLE_COLORS = {
1332
1449
  bold: "\u001B[1m",
1333
1450
  yellow: "\u001B[1m\u001B[33m",
@@ -1337,7 +1454,9 @@ const AVAILABLE_COLORS = {
1337
1454
  magenta: "\u001B[1m\u001B[35m"
1338
1455
  };
1339
1456
 
1340
- /** @type {Record<string, (value: any, options: Required<KnownStatsPrinterColorFn> & StatsPrinterContext, ...args: any) => string>} */
1457
+ /** @typedef {Required<{ [Key in keyof KnownStatsPrinterFormatters]: (value: Parameters<NonNullable<KnownStatsPrinterFormatters[Key]>>[0], options: Required<KnownStatsPrinterColorFunctions> & StatsPrinterContext, ...args: TODO[]) => string }>} AvailableFormats */
1458
+
1459
+ /** @type {AvailableFormats} */
1341
1460
  const AVAILABLE_FORMATS = {
1342
1461
  formatChunkId: (id, { yellow }, direction) => {
1343
1462
  switch (direction) {
@@ -1460,6 +1579,8 @@ const createOrder = (array, preferredOrder) => {
1460
1579
  return array;
1461
1580
  };
1462
1581
 
1582
+ const PLUGIN_NAME = "DefaultStatsPrinterPlugin";
1583
+
1463
1584
  class DefaultStatsPrinterPlugin {
1464
1585
  /**
1465
1586
  * Apply the plugin
@@ -1467,270 +1588,301 @@ class DefaultStatsPrinterPlugin {
1467
1588
  * @returns {void}
1468
1589
  */
1469
1590
  apply(compiler) {
1470
- compiler.hooks.compilation.tap("DefaultStatsPrinterPlugin", compilation => {
1471
- compilation.hooks.statsPrinter.tap(
1472
- "DefaultStatsPrinterPlugin",
1473
- (stats, options) => {
1474
- // Put colors into context
1475
- stats.hooks.print
1476
- .for("compilation")
1477
- .tap("DefaultStatsPrinterPlugin", (compilation, context) => {
1478
- for (const color of Object.keys(AVAILABLE_COLORS)) {
1479
- const name = /** @type {ColorNames} */ (color);
1480
- /** @type {string | undefined} */
1481
- let start;
1482
- if (options.colors) {
1483
- if (
1484
- typeof options.colors === "object" &&
1485
- typeof options.colors[name] === "string"
1486
- ) {
1487
- start = options.colors[name];
1488
- } else {
1489
- start = AVAILABLE_COLORS[name];
1490
- }
1491
- }
1492
- if (start) {
1493
- /**
1494
- * @param {string} str string
1495
- * @returns {string} string with color
1496
- */
1497
- context[color] = str =>
1498
- `${start}${
1499
- typeof str === "string"
1500
- ? str.replace(
1501
- /((\u001B\[39m|\u001B\[22m|\u001B\[0m)+)/g,
1502
- `$1${start}`
1503
- )
1504
- : str
1505
- }\u001B[39m\u001B[22m`;
1591
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
1592
+ compilation.hooks.statsPrinter.tap(PLUGIN_NAME, (stats, options) => {
1593
+ // Put colors into context
1594
+ stats.hooks.print
1595
+ .for("compilation")
1596
+ .tap(PLUGIN_NAME, (compilation, context) => {
1597
+ for (const color of Object.keys(AVAILABLE_COLORS)) {
1598
+ const name =
1599
+ /** @type {keyof KnownStatsPrinterColorFunctions} */
1600
+ (color);
1601
+ /** @type {string | undefined} */
1602
+ let start;
1603
+ if (options.colors) {
1604
+ if (
1605
+ typeof options.colors === "object" &&
1606
+ typeof options.colors[name] === "string"
1607
+ ) {
1608
+ start = options.colors[name];
1506
1609
  } else {
1507
- /**
1508
- * @param {string} str string
1509
- * @returns {string} str string
1510
- */
1511
- context[color] = str => str;
1610
+ start = AVAILABLE_COLORS[name];
1512
1611
  }
1513
1612
  }
1514
- for (const format of Object.keys(AVAILABLE_FORMATS)) {
1515
- context[format] =
1516
- /**
1517
- * @param {string | number} content content
1518
- * @param {...TODO} args args
1519
- * @returns {string} result
1520
- */
1521
- (content, ...args) =>
1522
- AVAILABLE_FORMATS[format](
1523
- content,
1524
- /** @type {Required<KnownStatsPrinterColorFn> & StatsPrinterContext} */
1525
- (context),
1526
- ...args
1527
- );
1613
+ if (start) {
1614
+ /** @type {ColorFunction} */
1615
+ context[color] = str =>
1616
+ `${start}${
1617
+ typeof str === "string"
1618
+ ? str.replace(
1619
+ /((\u001B\[39m|\u001B\[22m|\u001B\[0m)+)/g,
1620
+ `$1${start}`
1621
+ )
1622
+ : str
1623
+ }\u001B[39m\u001B[22m`;
1624
+ } else {
1625
+ /**
1626
+ * @param {string} str string
1627
+ * @returns {string} str string
1628
+ */
1629
+ context[color] = str => str;
1528
1630
  }
1529
- context.timeReference = compilation.time;
1631
+ }
1632
+ for (const format of Object.keys(AVAILABLE_FORMATS)) {
1633
+ context[format] =
1634
+ /**
1635
+ * @param {string | number} content content
1636
+ * @param {...TODO} args args
1637
+ * @returns {string} result
1638
+ */
1639
+ (content, ...args) =>
1640
+ /** @type {TODO} */
1641
+ (
1642
+ AVAILABLE_FORMATS[
1643
+ /** @type {keyof AvailableFormats} */
1644
+ (format)
1645
+ ]
1646
+ )(
1647
+ content,
1648
+ /** @type {StatsPrinterContext & Required<KnownStatsPrinterColorFunctions>} */
1649
+ (context),
1650
+ ...args
1651
+ );
1652
+ }
1653
+ context.timeReference = compilation.time;
1654
+ });
1655
+
1656
+ for (const key of Object.keys(COMPILATION_SIMPLE_PRINTERS)) {
1657
+ stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
1658
+ /** @type {TODO} */
1659
+ (
1660
+ COMPILATION_SIMPLE_PRINTERS[
1661
+ /** @type {keyof CompilationSimplePrinters} */
1662
+ (key)
1663
+ ]
1664
+ )(
1665
+ obj,
1666
+ /** @type {DefineStatsPrinterContext<"compilation">} */
1667
+ (ctx),
1668
+ stats
1669
+ )
1670
+ );
1671
+ }
1672
+
1673
+ for (const key of Object.keys(ASSET_SIMPLE_PRINTERS)) {
1674
+ stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
1675
+ /** @type {NonNullable<AssetSimplePrinters[keyof AssetSimplePrinters]>} */
1676
+ (
1677
+ ASSET_SIMPLE_PRINTERS[
1678
+ /** @type {keyof AssetSimplePrinters} */
1679
+ (key)
1680
+ ]
1681
+ )(
1682
+ obj,
1683
+ /** @type {DefineStatsPrinterContext<"asset" | "asset.info">} */
1684
+ (ctx),
1685
+ stats
1686
+ )
1687
+ );
1688
+ }
1689
+
1690
+ for (const key of Object.keys(MODULE_SIMPLE_PRINTERS)) {
1691
+ stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
1692
+ /** @type {TODO} */
1693
+ (
1694
+ MODULE_SIMPLE_PRINTERS[
1695
+ /** @type {keyof ModuleSimplePrinters} */
1696
+ (key)
1697
+ ]
1698
+ )(
1699
+ obj,
1700
+ /** @type {DefineStatsPrinterContext<"module">} */
1701
+ (ctx),
1702
+ stats
1703
+ )
1704
+ );
1705
+ }
1706
+
1707
+ for (const key of Object.keys(MODULE_ISSUER_PRINTERS)) {
1708
+ stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
1709
+ /** @type {NonNullable<ModuleIssuerPrinters[keyof ModuleIssuerPrinters]>} */
1710
+ (
1711
+ MODULE_ISSUER_PRINTERS[
1712
+ /** @type {keyof ModuleIssuerPrinters} */
1713
+ (key)
1714
+ ]
1715
+ )(
1716
+ obj,
1717
+ /** @type {DefineStatsPrinterContext<"moduleIssuer">} */
1718
+ (ctx),
1719
+ stats
1720
+ )
1721
+ );
1722
+ }
1723
+
1724
+ for (const key of Object.keys(MODULE_REASON_PRINTERS)) {
1725
+ stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
1726
+ /** @type {TODO} */
1727
+ (
1728
+ MODULE_REASON_PRINTERS[
1729
+ /** @type {keyof ModuleReasonsPrinters} */
1730
+ (key)
1731
+ ]
1732
+ )(
1733
+ obj,
1734
+ /** @type {DefineStatsPrinterContext<"moduleReason">} */
1735
+ (ctx),
1736
+ stats
1737
+ )
1738
+ );
1739
+ }
1740
+
1741
+ for (const key of Object.keys(MODULE_PROFILE_PRINTERS)) {
1742
+ stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
1743
+ /** @type {NonNullable<ModuleProfilePrinters[keyof ModuleProfilePrinters]>} */
1744
+ (
1745
+ MODULE_PROFILE_PRINTERS[
1746
+ /** @type {keyof ModuleProfilePrinters} */
1747
+ (key)
1748
+ ]
1749
+ )(
1750
+ obj,
1751
+ /** @type {DefineStatsPrinterContext<"profile">} */
1752
+ (ctx),
1753
+ stats
1754
+ )
1755
+ );
1756
+ }
1757
+
1758
+ for (const key of Object.keys(CHUNK_GROUP_PRINTERS)) {
1759
+ stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
1760
+ /** @type {TODO} */
1761
+ (
1762
+ CHUNK_GROUP_PRINTERS[
1763
+ /** @type {keyof ChunkGroupPrinters} */
1764
+ (key)
1765
+ ]
1766
+ )(
1767
+ obj,
1768
+ /** @type {DefineStatsPrinterContext<"chunkGroupKind" | "chunkGroup">} */
1769
+ (ctx),
1770
+ stats
1771
+ )
1772
+ );
1773
+ }
1774
+
1775
+ for (const key of Object.keys(CHUNK_PRINTERS)) {
1776
+ stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
1777
+ /** @type {TODO} */
1778
+ (CHUNK_PRINTERS[/** @type {keyof ChunkPrinters} */ (key)])(
1779
+ obj,
1780
+ /** @type {DefineStatsPrinterContext<"chunk">} */
1781
+ (ctx),
1782
+ stats
1783
+ )
1784
+ );
1785
+ }
1786
+
1787
+ for (const key of Object.keys(ERROR_PRINTERS)) {
1788
+ stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
1789
+ /** @type {TODO} */
1790
+ (ERROR_PRINTERS[/** @type {keyof ErrorPrinters} */ (key)])(
1791
+ obj,
1792
+ /** @type {DefineStatsPrinterContext<"error">} */
1793
+ (ctx),
1794
+ stats
1795
+ )
1796
+ );
1797
+ }
1798
+
1799
+ for (const key of Object.keys(LOG_ENTRY_PRINTERS)) {
1800
+ stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
1801
+ /** @type {TODO} */
1802
+ (
1803
+ LOG_ENTRY_PRINTERS[
1804
+ /** @type {keyof LogEntryPrinters} */
1805
+ (key)
1806
+ ]
1807
+ )(
1808
+ obj,
1809
+ /** @type {DefineStatsPrinterContext<"logging">} */
1810
+ (ctx),
1811
+ stats
1812
+ )
1813
+ );
1814
+ }
1815
+
1816
+ for (const key of Object.keys(MODULE_TRACE_DEPENDENCY_PRINTERS)) {
1817
+ stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
1818
+ /** @type {NonNullable<ModuleTraceDependencyPrinters[keyof ModuleTraceDependencyPrinters]>} */
1819
+ (
1820
+ MODULE_TRACE_DEPENDENCY_PRINTERS[
1821
+ /** @type {keyof ModuleTraceDependencyPrinters} */
1822
+ (key)
1823
+ ]
1824
+ )(
1825
+ obj,
1826
+ /** @type {DefineStatsPrinterContext<"moduleTraceDependency">} */
1827
+ (ctx),
1828
+ stats
1829
+ )
1830
+ );
1831
+ }
1832
+
1833
+ for (const key of Object.keys(MODULE_TRACE_ITEM_PRINTERS)) {
1834
+ stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
1835
+ /** @type {NonNullable<ModuleTraceItemPrinters[keyof ModuleTraceItemPrinters]>} */
1836
+ (
1837
+ MODULE_TRACE_ITEM_PRINTERS[
1838
+ /** @type {keyof ModuleTraceItemPrinters} */
1839
+ (key)
1840
+ ]
1841
+ )(
1842
+ obj,
1843
+ /** @type {DefineStatsPrinterContext<"moduleTraceItem">} */
1844
+ (ctx),
1845
+ stats
1846
+ )
1847
+ );
1848
+ }
1849
+
1850
+ for (const key of Object.keys(PREFERRED_ORDERS)) {
1851
+ const preferredOrder = PREFERRED_ORDERS[key];
1852
+ stats.hooks.sortElements
1853
+ .for(key)
1854
+ .tap(PLUGIN_NAME, (elements, context) => {
1855
+ createOrder(elements, preferredOrder);
1530
1856
  });
1857
+ }
1531
1858
 
1532
- for (const key of Object.keys(COMPILATION_SIMPLE_PRINTERS)) {
1533
- stats.hooks.print
1534
- .for(key)
1535
- .tap("DefaultStatsPrinterPlugin", (obj, ctx) =>
1536
- COMPILATION_SIMPLE_PRINTERS[key](
1537
- obj,
1538
- /** @type {DefineStatsPrinterContext<"compilation">} */
1539
- (ctx),
1540
- stats
1541
- )
1542
- );
1543
- }
1544
-
1545
- for (const key of Object.keys(ASSET_SIMPLE_PRINTERS)) {
1546
- stats.hooks.print
1547
- .for(key)
1548
- .tap("DefaultStatsPrinterPlugin", (obj, ctx) =>
1549
- ASSET_SIMPLE_PRINTERS[key](
1550
- obj,
1551
- /** @type {DefineStatsPrinterContext<"asset">} */
1552
- (ctx),
1553
- stats
1554
- )
1555
- );
1556
- }
1557
-
1558
- for (const key of Object.keys(MODULE_SIMPLE_PRINTERS)) {
1559
- stats.hooks.print
1560
- .for(key)
1561
- .tap("DefaultStatsPrinterPlugin", (obj, ctx) =>
1562
- MODULE_SIMPLE_PRINTERS[key](
1563
- obj,
1564
- /** @type {DefineStatsPrinterContext<"module">} */
1565
- (ctx),
1566
- stats
1567
- )
1568
- );
1569
- }
1570
-
1571
- for (const key of Object.keys(MODULE_ISSUER_PRINTERS)) {
1572
- stats.hooks.print
1573
- .for(key)
1574
- .tap("DefaultStatsPrinterPlugin", (obj, ctx) =>
1575
- /** @type {Record<string, ModuleSimplePrinter<KnownStatsModuleIssuer[keyof KnownStatsModuleIssuer] | KnownStatsModuleIssuer["profile"][keyof KnownStatsModuleIssuer["profile"]], "type" | "compilation" | "moduleIssuer">>} */
1576
- (MODULE_ISSUER_PRINTERS)[key](
1577
- obj,
1578
- /** @type {DefineStatsPrinterContext<"moduleIssuer">} */
1579
- (ctx),
1580
- stats
1581
- )
1582
- );
1583
- }
1584
-
1585
- for (const key of Object.keys(MODULE_REASON_PRINTERS)) {
1586
- stats.hooks.print
1587
- .for(key)
1588
- .tap("DefaultStatsPrinterPlugin", (obj, ctx) =>
1589
- MODULE_REASON_PRINTERS[key](
1590
- obj,
1591
- /** @type {DefineStatsPrinterContext<"moduleReason">} */
1592
- (ctx),
1593
- stats
1594
- )
1595
- );
1596
- }
1597
-
1598
- for (const key of Object.keys(MODULE_PROFILE_PRINTERS)) {
1599
- stats.hooks.print
1600
- .for(key)
1601
- .tap("DefaultStatsPrinterPlugin", (obj, ctx) =>
1602
- /** @type {Record<string, ModuleSimplePrinter<KnownStatsProfile[keyof KnownStatsProfile], "type" | "compilation" | "profile">>} */
1603
- (MODULE_PROFILE_PRINTERS)[key](
1604
- obj,
1605
- /** @type {DefineStatsPrinterContext<"profile">} */
1606
- (ctx),
1607
- stats
1608
- )
1609
- );
1610
- }
1611
-
1612
- for (const key of Object.keys(CHUNK_GROUP_PRINTERS)) {
1613
- stats.hooks.print
1614
- .for(key)
1615
- .tap("DefaultStatsPrinterPlugin", (obj, ctx) =>
1616
- CHUNK_GROUP_PRINTERS[key](
1617
- obj,
1618
- /** @type {DefineStatsPrinterContext<"chunkGroupKind" | "chunkGroup">} */
1619
- (ctx),
1620
- stats
1621
- )
1622
- );
1623
- }
1624
-
1625
- for (const key of Object.keys(CHUNK_PRINTERS)) {
1626
- stats.hooks.print
1627
- .for(key)
1628
- .tap("DefaultStatsPrinterPlugin", (obj, ctx) =>
1629
- CHUNK_PRINTERS[key](
1630
- obj,
1631
- /** @type {DefineStatsPrinterContext<"chunk">} */
1632
- (ctx),
1633
- stats
1634
- )
1635
- );
1636
- }
1637
-
1638
- for (const key of Object.keys(ERROR_PRINTERS)) {
1639
- stats.hooks.print
1640
- .for(key)
1641
- .tap("DefaultStatsPrinterPlugin", (obj, ctx) =>
1642
- /** @type {Record<string, ModuleSimplePrinter<KnownStatsError[keyof KnownStatsError], "type" | "compilation" | "error">>} */
1643
- (ERROR_PRINTERS)[key](
1644
- obj,
1645
- /** @type {DefineStatsPrinterContext<"error">} */
1646
- (ctx),
1647
- stats
1648
- )
1649
- );
1650
- }
1651
-
1652
- for (const key of Object.keys(LOG_ENTRY_PRINTERS)) {
1653
- stats.hooks.print
1654
- .for(key)
1655
- .tap("DefaultStatsPrinterPlugin", (obj, ctx) =>
1656
- LOG_ENTRY_PRINTERS[key](
1657
- obj,
1658
- /** @type {DefineStatsPrinterContext<"logging">} */
1659
- (ctx),
1660
- stats
1661
- )
1662
- );
1663
- }
1664
-
1665
- for (const key of Object.keys(MODULE_TRACE_DEPENDENCY_PRINTERS)) {
1666
- stats.hooks.print
1667
- .for(key)
1668
- .tap("DefaultStatsPrinterPlugin", (obj, ctx) =>
1669
- /** @type {Record<string, ModuleSimplePrinter<KnownStatsModuleTraceDependency[keyof KnownStatsModuleTraceDependency], "type" | "compilation" | "moduleTraceDependency">>} */
1670
- (MODULE_TRACE_DEPENDENCY_PRINTERS)[key](
1671
- obj,
1672
- /** @type {DefineStatsPrinterContext<"moduleTraceDependency">} */
1673
- (ctx),
1674
- stats
1675
- )
1676
- );
1677
- }
1678
-
1679
- for (const key of Object.keys(MODULE_TRACE_ITEM_PRINTERS)) {
1680
- stats.hooks.print
1681
- .for(key)
1682
- .tap("DefaultStatsPrinterPlugin", (obj, ctx) =>
1683
- /** @type {Record<string, ModuleSimplePrinter<KnownStatsModuleTraceItem[keyof KnownStatsModuleTraceItem], "type" | "compilation" | "moduleTraceItem">>} */
1684
- (MODULE_TRACE_ITEM_PRINTERS)[key](
1685
- obj,
1686
- /** @type {DefineStatsPrinterContext<"moduleTraceItem">} */
1687
- (ctx),
1688
- stats
1689
- )
1690
- );
1691
- }
1692
-
1693
- for (const key of Object.keys(PREFERRED_ORDERS)) {
1694
- const preferredOrder = PREFERRED_ORDERS[key];
1695
- stats.hooks.sortElements
1696
- .for(key)
1697
- .tap("DefaultStatsPrinterPlugin", (elements, context) => {
1698
- createOrder(elements, preferredOrder);
1699
- });
1700
- }
1701
-
1702
- for (const key of Object.keys(ITEM_NAMES)) {
1703
- const itemName = ITEM_NAMES[key];
1704
- stats.hooks.getItemName
1705
- .for(key)
1706
- .tap(
1707
- "DefaultStatsPrinterPlugin",
1708
- typeof itemName === "string" ? () => itemName : itemName
1709
- );
1710
- }
1711
-
1712
- for (const key of Object.keys(SIMPLE_ITEMS_JOINER)) {
1713
- const joiner = SIMPLE_ITEMS_JOINER[key];
1714
- stats.hooks.printItems
1715
- .for(key)
1716
- .tap("DefaultStatsPrinterPlugin", joiner);
1717
- }
1718
-
1719
- for (const key of Object.keys(SIMPLE_ELEMENT_JOINERS)) {
1720
- const joiner = SIMPLE_ELEMENT_JOINERS[key];
1721
- stats.hooks.printElements
1722
- .for(key)
1723
- .tap("DefaultStatsPrinterPlugin", /** @type {TODO} */ (joiner));
1724
- }
1725
-
1726
- for (const key of Object.keys(RESULT_MODIFIER)) {
1727
- const modifier = RESULT_MODIFIER[key];
1728
- stats.hooks.result
1729
- .for(key)
1730
- .tap("DefaultStatsPrinterPlugin", modifier);
1731
- }
1859
+ for (const key of Object.keys(ITEM_NAMES)) {
1860
+ const itemName = ITEM_NAMES[key];
1861
+ stats.hooks.getItemName
1862
+ .for(key)
1863
+ .tap(
1864
+ PLUGIN_NAME,
1865
+ typeof itemName === "string" ? () => itemName : itemName
1866
+ );
1732
1867
  }
1733
- );
1868
+
1869
+ for (const key of Object.keys(SIMPLE_ITEMS_JOINER)) {
1870
+ const joiner = SIMPLE_ITEMS_JOINER[key];
1871
+ stats.hooks.printItems.for(key).tap(PLUGIN_NAME, joiner);
1872
+ }
1873
+
1874
+ for (const key of Object.keys(SIMPLE_ELEMENT_JOINERS)) {
1875
+ const joiner = SIMPLE_ELEMENT_JOINERS[key];
1876
+ stats.hooks.printElements
1877
+ .for(key)
1878
+ .tap(PLUGIN_NAME, /** @type {TODO} */ (joiner));
1879
+ }
1880
+
1881
+ for (const key of Object.keys(RESULT_MODIFIER)) {
1882
+ const modifier = RESULT_MODIFIER[key];
1883
+ stats.hooks.result.for(key).tap(PLUGIN_NAME, modifier);
1884
+ }
1885
+ });
1734
1886
  });
1735
1887
  }
1736
1888
  }