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,13 +6,12 @@
6
6
 
7
7
  const SerializerMiddleware = require("./SerializerMiddleware");
8
8
 
9
- /** @typedef {import("./SerializerMiddleware").Context} Context */
10
-
11
- /** @typedef {any} DeserializedType */
12
- /** @typedef {any[]} SerializedType */
9
+ /** @typedef {EXPECTED_ANY} DeserializedType */
10
+ /** @typedef {EXPECTED_ANY[]} SerializedType */
11
+ /** @typedef {{}} Context */
13
12
 
14
13
  /**
15
- * @extends {SerializerMiddleware<DeserializedType, SerializedType>}
14
+ * @extends {SerializerMiddleware<DeserializedType, SerializedType, Context>}
16
15
  */
17
16
  class SingleItemMiddleware extends SerializerMiddleware {
18
17
  /**
@@ -36,6 +36,8 @@ const validate = createSchemaValidation(
36
36
 
37
37
  /** @typedef {Map<string, { config: ProvideOptions, version: string | undefined | false }>} ResolvedProvideMap */
38
38
 
39
+ const PLUGIN_NAME = "ProvideSharedPlugin";
40
+
39
41
  class ProvideSharedPlugin {
40
42
  /**
41
43
  * @param {ProvideSharedPluginOptions} options options
@@ -83,7 +85,7 @@ class ProvideSharedPlugin {
83
85
  const compilationData = new WeakMap();
84
86
 
85
87
  compiler.hooks.compilation.tap(
86
- "ProvideSharedPlugin",
88
+ PLUGIN_NAME,
87
89
  (compilation, { normalModuleFactory }) => {
88
90
  /** @type {ResolvedProvideMap} */
89
91
  const resolvedProvideMap = new Map();
@@ -156,7 +158,7 @@ class ProvideSharedPlugin {
156
158
  });
157
159
  };
158
160
  normalModuleFactory.hooks.module.tap(
159
- "ProvideSharedPlugin",
161
+ PLUGIN_NAME,
160
162
  (module, { resource, resourceResolveData }, resolveData) => {
161
163
  if (resolvedProvideMap.has(/** @type {string} */ (resource))) {
162
164
  return module;
@@ -194,7 +196,7 @@ class ProvideSharedPlugin {
194
196
  );
195
197
  }
196
198
  );
197
- compiler.hooks.finishMake.tapPromise("ProvideSharedPlugin", compilation => {
199
+ compiler.hooks.finishMake.tapPromise(PLUGIN_NAME, compilation => {
198
200
  const resolvedProvideMap = compilationData.get(compilation);
199
201
  if (!resolvedProvideMap) return Promise.resolve();
200
202
  return Promise.all(
@@ -225,7 +227,7 @@ class ProvideSharedPlugin {
225
227
  });
226
228
 
227
229
  compiler.hooks.compilation.tap(
228
- "ProvideSharedPlugin",
230
+ PLUGIN_NAME,
229
231
  (compilation, { normalModuleFactory }) => {
230
232
  compilation.dependencyFactories.set(
231
233
  ProvideForSharedDependency,
@@ -27,12 +27,14 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
27
27
  /** @typedef {import("webpack-sources").Source} Source */
28
28
  /** @typedef {import("../Chunk")} Chunk */
29
29
  /** @typedef {import("../Chunk").ChunkId} ChunkId */
30
+ /** @typedef {import("../Chunk").ChunkName} ChunkName */
30
31
  /** @typedef {import("../ChunkGraph").ModuleId} ModuleId */
31
32
  /** @typedef {import("../ChunkGroup")} ChunkGroup */
32
33
  /** @typedef {import("../ChunkGroup").OriginRecord} OriginRecord */
33
34
  /** @typedef {import("../Compilation")} Compilation */
34
35
  /** @typedef {import("../Compilation").Asset} Asset */
35
36
  /** @typedef {import("../Compilation").AssetInfo} AssetInfo */
37
+ /** @typedef {import("../Compilation").ExcludeModulesType} ExcludeModulesType */
36
38
  /** @typedef {import("../Compilation").KnownNormalizedStatsOptions} KnownNormalizedStatsOptions */
37
39
  /** @typedef {import("../Compilation").NormalizedStatsOptions} NormalizedStatsOptions */
38
40
  /** @typedef {import("../Compiler")} Compiler */
@@ -62,7 +64,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
62
64
  /** @typedef {KnownStatsCompilation & Record<string, EXPECTED_ANY>} StatsCompilation */
63
65
  /**
64
66
  * @typedef {object} KnownStatsCompilation
65
- * @property {any=} env
67
+ * @property {Record<string, EXPECTED_ANY>=} env
66
68
  * @property {string=} name
67
69
  * @property {string=} hash
68
70
  * @property {string=} version
@@ -85,6 +87,8 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
85
87
  * @property {number=} warningsCount
86
88
  * @property {StatsCompilation[]=} children
87
89
  * @property {Record<string, StatsLogging>=} logging
90
+ * @property {number=} filteredWarningDetailsCount
91
+ * @property {number=} filteredErrorDetailsCount
88
92
  */
89
93
 
90
94
  /** @typedef {KnownStatsLogging & Record<string, EXPECTED_ANY>} StatsLogging */
@@ -107,6 +111,9 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
107
111
  */
108
112
 
109
113
  /** @typedef {KnownStatsAsset & Record<string, EXPECTED_ANY>} StatsAsset */
114
+ /** @typedef {ChunkId} KnownStatsAssetChunk */
115
+ /** @typedef {ChunkName} KnownStatsAssetChunkName */
116
+ /** @typedef {string} KnownStatsAssetChunkIdHint */
110
117
  /**
111
118
  * @typedef {object} KnownStatsAsset
112
119
  * @property {string} type
@@ -117,12 +124,12 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
117
124
  * @property {boolean} comparedForEmit
118
125
  * @property {boolean} cached
119
126
  * @property {StatsAsset[]=} related
120
- * @property {(string|number)[]=} chunkNames
121
- * @property {(string|number)[]=} chunkIdHints
122
- * @property {(string|number)[]=} chunks
123
- * @property {(string|number)[]=} auxiliaryChunkNames
124
- * @property {(string|number)[]=} auxiliaryChunks
125
- * @property {(string|number)[]=} auxiliaryChunkIdHints
127
+ * @property {KnownStatsAssetChunk[]=} chunks
128
+ * @property {KnownStatsAssetChunkName[]=} chunkNames
129
+ * @property {KnownStatsAssetChunkIdHint[]=} chunkIdHints
130
+ * @property {KnownStatsAssetChunk[]=} auxiliaryChunks
131
+ * @property {KnownStatsAssetChunkName[]=} auxiliaryChunkNames
132
+ * @property {KnownStatsAssetChunkIdHint[]=} auxiliaryChunkIdHints
126
133
  * @property {number=} filteredRelated
127
134
  * @property {boolean=} isOverSizeLimit
128
135
  */
@@ -143,6 +150,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
143
150
  * @property {boolean=} isOverSizeLimit
144
151
  */
145
152
 
153
+ /** @typedef {Module[]} ModuleIssuerPath */
146
154
  /** @typedef {KnownStatsModule & Record<string, EXPECTED_ANY>} StatsModule */
147
155
  /**
148
156
  * @typedef {object} KnownStatsModule
@@ -172,7 +180,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
172
180
  * @property {boolean=} dependent
173
181
  * @property {(string | null)=} issuer
174
182
  * @property {(string | null)=} issuerName
175
- * @property {StatsModuleIssuer[]=} issuerPath
183
+ * @property {StatsModuleIssuer[] | null=} issuerPath
176
184
  * @property {boolean=} failed
177
185
  * @property {number=} errors
178
186
  * @property {number=} warnings
@@ -244,7 +252,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
244
252
  * @property {string[]} files
245
253
  * @property {string[]} auxiliaryFiles
246
254
  * @property {string} hash
247
- * @property {Record<string, (string|number)[]>} childrenByOrder
255
+ * @property {Record<string, ChunkId[]>} childrenByOrder
248
256
  * @property {(string|number)=} id
249
257
  * @property {(string|number)[]=} siblings
250
258
  * @property {(string|number)[]=} parents
@@ -299,6 +307,8 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
299
307
  * @property {StatsModuleTraceItem[]=} moduleTrace
300
308
  * @property {string=} details
301
309
  * @property {string=} stack
310
+ * @property {KnownStatsError=} cause
311
+ * @property {KnownStatsError[]=} errors
302
312
  * @property {string=} compilerPath
303
313
  */
304
314
 
@@ -310,12 +320,15 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
310
320
  * @typedef {Record<string, (object: O, data: T, context: StatsFactoryContext, options: NormalizedStatsOptions, factory: StatsFactory) => void>} ExtractorsByOption
311
321
  */
312
322
 
323
+ /** @typedef {{ name: string, chunkGroup: ChunkGroup }} ChunkGroupInfoWithName */
324
+ /** @typedef {{ origin: Module, module: Module }} ModuleTrace */
325
+
313
326
  /**
314
327
  * @typedef {object} SimpleExtractors
315
328
  * @property {ExtractorsByOption<Compilation, StatsCompilation>} compilation
316
329
  * @property {ExtractorsByOption<PreprocessedAsset, StatsAsset>} asset
317
330
  * @property {ExtractorsByOption<PreprocessedAsset, StatsAsset>} asset$visible
318
- * @property {ExtractorsByOption<{ name: string, chunkGroup: ChunkGroup }, StatsChunkGroup>} chunkGroup
331
+ * @property {ExtractorsByOption<ChunkGroupInfoWithName, StatsChunkGroup>} chunkGroup
319
332
  * @property {ExtractorsByOption<Module, StatsModule>} module
320
333
  * @property {ExtractorsByOption<Module, StatsModule>} module$visible
321
334
  * @property {ExtractorsByOption<Module, StatsModuleIssuer>} moduleIssuer
@@ -325,7 +338,8 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
325
338
  * @property {ExtractorsByOption<OriginRecord, StatsChunkOrigin>} chunkOrigin
326
339
  * @property {ExtractorsByOption<WebpackError, StatsError>} error
327
340
  * @property {ExtractorsByOption<WebpackError, StatsError>} warning
328
- * @property {ExtractorsByOption<{ origin: Module, module: Module }, StatsModuleTraceItem>} moduleTraceItem
341
+ * @property {ExtractorsByOption<WebpackError, StatsError>} cause
342
+ * @property {ExtractorsByOption<ModuleTrace, StatsModuleTraceItem>} moduleTraceItem
329
343
  * @property {ExtractorsByOption<Dependency, StatsModuleTraceDependency>} moduleTraceDependency
330
344
  */
331
345
 
@@ -394,55 +408,75 @@ const countWithChildren = (compilation, getItems) => {
394
408
  return count;
395
409
  };
396
410
 
397
- /** @type {ExtractorsByOption<WebpackError | string, StatsError>} */
411
+ /** @typedef {Error & { cause?: unknown }} ErrorWithCause */
412
+ /** @typedef {Error & { errors: EXPECTED_ANY[] }} AggregateError */
413
+
414
+ /** @type {ExtractorsByOption<string | ErrorWithCause | AggregateError | WebpackError, StatsError>} */
398
415
  const EXTRACT_ERROR = {
399
416
  _: (object, error, context, { requestShortener }) => {
400
417
  // TODO webpack 6 disallow strings in the errors/warnings list
401
418
  if (typeof error === "string") {
402
419
  object.message = error;
403
420
  } else {
404
- if (error.chunk) {
421
+ if (/** @type {WebpackError} */ (error).chunk) {
422
+ const chunk = /** @type {WebpackError} */ (error).chunk;
405
423
  object.chunkName =
406
424
  /** @type {string | undefined} */
407
- (error.chunk.name);
408
- object.chunkEntry = error.chunk.hasRuntime();
409
- object.chunkInitial = error.chunk.canBeInitial();
425
+ (chunk.name);
426
+ object.chunkEntry = chunk.hasRuntime();
427
+ object.chunkInitial = chunk.canBeInitial();
410
428
  }
411
- if (error.file) {
412
- object.file = error.file;
429
+
430
+ if (/** @type {WebpackError} */ (error).file) {
431
+ object.file = /** @type {WebpackError} */ (error).file;
413
432
  }
414
- if (error.module) {
415
- object.moduleIdentifier = error.module.identifier();
416
- object.moduleName = error.module.readableIdentifier(requestShortener);
433
+
434
+ if (/** @type {WebpackError} */ (error).module) {
435
+ object.moduleIdentifier =
436
+ /** @type {WebpackError} */
437
+ (error).module.identifier();
438
+ object.moduleName =
439
+ /** @type {WebpackError} */
440
+ (error).module.readableIdentifier(requestShortener);
417
441
  }
418
- if (error.loc) {
419
- object.loc = formatLocation(error.loc);
442
+
443
+ if (/** @type {WebpackError} */ (error).loc) {
444
+ object.loc = formatLocation(/** @type {WebpackError} */ (error).loc);
420
445
  }
446
+
421
447
  object.message = error.message;
422
448
  }
423
449
  },
424
450
  ids: (object, error, { compilation: { chunkGraph } }) => {
425
451
  if (typeof error !== "string") {
426
- if (error.chunk) {
427
- object.chunkId = /** @type {ChunkId} */ (error.chunk.id);
452
+ if (/** @type {WebpackError} */ (error).chunk) {
453
+ object.chunkId = /** @type {ChunkId} */ (
454
+ /** @type {WebpackError} */
455
+ (error).chunk.id
456
+ );
428
457
  }
429
- if (error.module) {
458
+
459
+ if (/** @type {WebpackError} */ (error).module) {
430
460
  object.moduleId =
431
461
  /** @type {ModuleId} */
432
- (chunkGraph.getModuleId(error.module));
462
+ (chunkGraph.getModuleId(/** @type {WebpackError} */ (error).module));
433
463
  }
434
464
  }
435
465
  },
436
466
  moduleTrace: (object, error, context, options, factory) => {
437
- if (typeof error !== "string" && error.module) {
467
+ if (
468
+ typeof error !== "string" &&
469
+ /** @type {WebpackError} */ (error).module
470
+ ) {
438
471
  const {
439
472
  type,
440
473
  compilation: { moduleGraph }
441
474
  } = context;
442
475
  /** @type {Set<Module>} */
443
476
  const visitedModules = new Set();
477
+ /** @type {ModuleTrace[]} */
444
478
  const moduleTrace = [];
445
- let current = error.module;
479
+ let current = /** @type {WebpackError} */ (error).module;
446
480
  while (current) {
447
481
  if (visitedModules.has(current)) break; // circular (technically impossible, but how knows)
448
482
  visitedModules.add(current);
@@ -469,13 +503,44 @@ const EXTRACT_ERROR = {
469
503
  (errorDetails === true ||
470
504
  (type.endsWith(".error") && cachedGetErrors(compilation).length < 3))
471
505
  ) {
472
- object.details = error.details;
506
+ object.details = /** @type {WebpackError} */ (error).details;
473
507
  }
474
508
  },
475
509
  errorStack: (object, error) => {
476
510
  if (typeof error !== "string") {
477
511
  object.stack = error.stack;
478
512
  }
513
+ },
514
+ errorCause: (object, error, context, options, factory) => {
515
+ if (
516
+ typeof error !== "string" &&
517
+ /** @type {ErrorWithCause} */ (error).cause
518
+ ) {
519
+ const rawCause = /** @type {ErrorWithCause} */ (error).cause;
520
+ /** @type {Error} */
521
+ const cause =
522
+ typeof rawCause === "string"
523
+ ? /** @type {Error} */ ({ message: rawCause })
524
+ : /** @type {Error} */ (rawCause);
525
+ const { type } = context;
526
+
527
+ object.cause = factory.create(`${type}.cause`, cause, context);
528
+ }
529
+ },
530
+ errorErrors: (object, error, context, options, factory) => {
531
+ if (
532
+ typeof error !== "string" &&
533
+ /** @type {AggregateError} */
534
+ (error).errors
535
+ ) {
536
+ const { type } = context;
537
+ object.errors = factory.create(
538
+ `${type}.errors`,
539
+ /** @type {Error[]} */
540
+ (/** @type {AggregateError} */ (error).errors),
541
+ context
542
+ );
543
+ }
479
544
  }
480
545
  };
481
546
 
@@ -796,6 +861,7 @@ const SIMPLE_EXTRACTORS = {
796
861
  factory
797
862
  ) => {
798
863
  const { type } = context;
864
+ /** @type {ChunkGroupInfoWithName[]} */
799
865
  const array = Array.from(compilation.entrypoints, ([key, value]) => ({
800
866
  name: key,
801
867
  chunkGroup: value
@@ -915,12 +981,13 @@ const SIMPLE_EXTRACTORS = {
915
981
  /** @type {KnownNormalizedStatsOptions["warningsFilter"]} */
916
982
  (warningsFilter).length === 0
917
983
  )
918
- return cachedGetWarnings(c);
984
+ // Type is wrong, because we don't need the real value for counting
985
+ return /** @type {EXPECTED_ANY[]} */ (cachedGetWarnings(c));
919
986
  return factory
920
987
  .create(`${type}${childType}.warnings`, cachedGetWarnings(c), context)
921
988
  .filter(
922
989
  /**
923
- * @param {TODO} warning warning
990
+ * @param {StatsError} warning warning
924
991
  * @returns {boolean} result
925
992
  */
926
993
  warning => {
@@ -1169,7 +1236,6 @@ const SIMPLE_EXTRACTORS = {
1169
1236
  cached: !built && !codeGenerated
1170
1237
  };
1171
1238
  Object.assign(object, statsModule);
1172
-
1173
1239
  if (built || codeGenerated || options.cachedModules) {
1174
1240
  Object.assign(
1175
1241
  object,
@@ -1183,7 +1249,7 @@ const SIMPLE_EXTRACTORS = {
1183
1249
  const { type, rootModules } = context;
1184
1250
  const compilation = /** @type {Compilation} */ (context.compilation);
1185
1251
  const { moduleGraph } = compilation;
1186
- /** @type {Module[]} */
1252
+ /** @type {ModuleIssuerPath} */
1187
1253
  const path = [];
1188
1254
  const issuer = moduleGraph.getIssuer(module);
1189
1255
  let current = issuer;
@@ -1221,7 +1287,8 @@ const SIMPLE_EXTRACTORS = {
1221
1287
  issuerName: issuer && issuer.readableIdentifier(requestShortener),
1222
1288
  issuerPath:
1223
1289
  issuer &&
1224
- factory.create(`${type.slice(0, -8)}.issuerPath`, path, context),
1290
+ /** @type {StatsModuleIssuer[] | undefined} */
1291
+ (factory.create(`${type.slice(0, -8)}.issuerPath`, path, context)),
1225
1292
  failed: errorsCount > 0,
1226
1293
  errors: errorsCount,
1227
1294
  warnings: warningsCount
@@ -1506,6 +1573,7 @@ const SIMPLE_EXTRACTORS = {
1506
1573
  } = context;
1507
1574
  /** @type {Set<string>} */
1508
1575
  const originsKeySet = new Set();
1576
+ /** @type {OriginRecord[]} */
1509
1577
  const origins = [];
1510
1578
  for (const g of chunk.groupsIterable) {
1511
1579
  origins.push(...g.origins);
@@ -1545,6 +1613,7 @@ const SIMPLE_EXTRACTORS = {
1545
1613
  },
1546
1614
  error: EXTRACT_ERROR,
1547
1615
  warning: EXTRACT_ERROR,
1616
+ cause: EXTRACT_ERROR,
1548
1617
  moduleTraceItem: {
1549
1618
  _: (object, { origin, module }, context, { requestShortener }, factory) => {
1550
1619
  const {
@@ -1562,7 +1631,8 @@ const SIMPLE_EXTRACTORS = {
1562
1631
  .map(c => c.dependency);
1563
1632
  object.dependencies = factory.create(
1564
1633
  `${type}.dependencies`,
1565
- Array.from(new Set(dependencies)),
1634
+ /** @type {Dependency[]} */
1635
+ (Array.from(new Set(dependencies))),
1566
1636
  context
1567
1637
  );
1568
1638
  },
@@ -1612,9 +1682,7 @@ const FILTER_RESULTS = {
1612
1682
  }
1613
1683
  };
1614
1684
 
1615
- /**
1616
- * @type {Record<string, (comparators: Comparator<Module>[], context: StatsFactoryContext) => void>}
1617
- */
1685
+ /** @type {Record<string, (comparators: Comparator<Module>[], context: StatsFactoryContext) => void>} */
1618
1686
  const MODULES_SORTER = {
1619
1687
  _: (comparators, { compilation: { moduleGraph } }) => {
1620
1688
  comparators.push(
@@ -1625,7 +1693,7 @@ const MODULES_SORTER = {
1625
1693
  }
1626
1694
  };
1627
1695
 
1628
- /** @type {Record<string, Record<string, (comparators: Comparator<any>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>>} */
1696
+ /** @type {Record<string, Record<string, (comparators: Comparator<TODO>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>>} */
1629
1697
  const SORTERS = {
1630
1698
  "compilation.chunks": {
1631
1699
  _: comparators => {
@@ -1679,7 +1747,7 @@ const SORTERS = {
1679
1747
 
1680
1748
  /**
1681
1749
  * @template T
1682
- * @typedef {T & { children: Children<T>[] | undefined, filteredChildren?: number }} Children
1750
+ * @typedef {T & { children?: Children<T>[] | undefined, filteredChildren?: number }} Children
1683
1751
  */
1684
1752
 
1685
1753
  /**
@@ -2051,6 +2119,7 @@ const ASSETS_GROUPERS = {
2051
2119
  const pathMatch =
2052
2120
  groupAssetsByPath && GROUP_PATH_REGEXP.exec(asset.name);
2053
2121
  const path = pathMatch ? pathMatch[1].split(/[/\\]/) : [];
2122
+ /** @type {string[]} */
2054
2123
  const keys = [];
2055
2124
  if (groupAssetsByPath) {
2056
2125
  keys.push(".");
@@ -2141,7 +2210,7 @@ const ASSETS_GROUPERS = {
2141
2210
 
2142
2211
  /** @typedef {Record<string, (groupConfigs: GroupConfig<KnownStatsModule, TODO>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>} ModulesGroupers */
2143
2212
 
2144
- /** @type {(type: "module" | "chunk" | "root-of-chunk" | "nested") => ModulesGroupers} */
2213
+ /** @type {(type: ExcludeModulesType) => ModulesGroupers} */
2145
2214
  const MODULES_GROUPERS = type => ({
2146
2215
  _: (groupConfigs, context, options) => {
2147
2216
  /**
@@ -2386,7 +2455,7 @@ const sortByField = field => {
2386
2455
  return sortFn;
2387
2456
  };
2388
2457
 
2389
- /** @type {Record<string, (comparators: Comparator<TODO>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>} */
2458
+ /** @type {Record<string, (comparators: Comparator<Asset>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>} */
2390
2459
  const ASSET_SORTERS = {
2391
2460
  assetsSort: (comparators, context, { assetsSort }) => {
2392
2461
  comparators.push(sortByField(assetsSort));
@@ -2459,6 +2528,8 @@ const ITEM_NAMES = {
2459
2528
  "compilation.namedChunkGroups[]": "chunkGroup",
2460
2529
  "compilation.errors[]": "error",
2461
2530
  "compilation.warnings[]": "warning",
2531
+ "error.errors[]": "error",
2532
+ "warning.errors[]": "error",
2462
2533
  "chunk.modules[]": "module",
2463
2534
  "chunk.rootModules[]": "module",
2464
2535
  "chunk.origins[]": "chunkOrigin",
@@ -2500,6 +2571,8 @@ const MERGER = {
2500
2571
  "compilation.namedChunkGroups": mergeToObject
2501
2572
  };
2502
2573
 
2574
+ const PLUGIN_NAME = "DefaultStatsFactoryPlugin";
2575
+
2503
2576
  class DefaultStatsFactoryPlugin {
2504
2577
  /**
2505
2578
  * Apply the plugin
@@ -2507,9 +2580,9 @@ class DefaultStatsFactoryPlugin {
2507
2580
  * @returns {void}
2508
2581
  */
2509
2582
  apply(compiler) {
2510
- compiler.hooks.compilation.tap("DefaultStatsFactoryPlugin", compilation => {
2583
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
2511
2584
  compilation.hooks.statsFactory.tap(
2512
- "DefaultStatsFactoryPlugin",
2585
+ PLUGIN_NAME,
2513
2586
  /**
2514
2587
  * @param {StatsFactory} stats stats factory
2515
2588
  * @param {NormalizedStatsOptions} options stats options
@@ -2522,7 +2595,7 @@ class DefaultStatsFactoryPlugin {
2522
2595
  (hookFor, fn) => {
2523
2596
  stats.hooks.extract
2524
2597
  .for(hookFor)
2525
- .tap("DefaultStatsFactoryPlugin", (obj, data, ctx) =>
2598
+ .tap(PLUGIN_NAME, (obj, data, ctx) =>
2526
2599
  fn(obj, data, ctx, options, stats)
2527
2600
  );
2528
2601
  }
@@ -2530,28 +2603,28 @@ class DefaultStatsFactoryPlugin {
2530
2603
  iterateConfig(FILTER, options, (hookFor, fn) => {
2531
2604
  stats.hooks.filter
2532
2605
  .for(hookFor)
2533
- .tap("DefaultStatsFactoryPlugin", (item, ctx, idx, i) =>
2606
+ .tap(PLUGIN_NAME, (item, ctx, idx, i) =>
2534
2607
  fn(item, ctx, options, idx, i)
2535
2608
  );
2536
2609
  });
2537
2610
  iterateConfig(FILTER_RESULTS, options, (hookFor, fn) => {
2538
2611
  stats.hooks.filterResults
2539
2612
  .for(hookFor)
2540
- .tap("DefaultStatsFactoryPlugin", (item, ctx, idx, i) =>
2613
+ .tap(PLUGIN_NAME, (item, ctx, idx, i) =>
2541
2614
  fn(item, ctx, options, idx, i)
2542
2615
  );
2543
2616
  });
2544
2617
  iterateConfig(SORTERS, options, (hookFor, fn) => {
2545
2618
  stats.hooks.sort
2546
2619
  .for(hookFor)
2547
- .tap("DefaultStatsFactoryPlugin", (comparators, ctx) =>
2620
+ .tap(PLUGIN_NAME, (comparators, ctx) =>
2548
2621
  fn(comparators, ctx, options)
2549
2622
  );
2550
2623
  });
2551
2624
  iterateConfig(RESULT_SORTERS, options, (hookFor, fn) => {
2552
2625
  stats.hooks.sortResults
2553
2626
  .for(hookFor)
2554
- .tap("DefaultStatsFactoryPlugin", (comparators, ctx) =>
2627
+ .tap(PLUGIN_NAME, (comparators, ctx) =>
2555
2628
  fn(comparators, ctx, options)
2556
2629
  );
2557
2630
  });
@@ -2562,27 +2635,25 @@ class DefaultStatsFactoryPlugin {
2562
2635
  (hookFor, fn) => {
2563
2636
  stats.hooks.groupResults
2564
2637
  .for(hookFor)
2565
- .tap("DefaultStatsFactoryPlugin", (groupConfigs, ctx) =>
2638
+ .tap(PLUGIN_NAME, (groupConfigs, ctx) =>
2566
2639
  fn(groupConfigs, ctx, options)
2567
2640
  );
2568
2641
  }
2569
2642
  );
2570
2643
  for (const key of Object.keys(ITEM_NAMES)) {
2571
2644
  const itemName = ITEM_NAMES[key];
2572
- stats.hooks.getItemName
2573
- .for(key)
2574
- .tap("DefaultStatsFactoryPlugin", () => itemName);
2645
+ stats.hooks.getItemName.for(key).tap(PLUGIN_NAME, () => itemName);
2575
2646
  }
2576
2647
  for (const key of Object.keys(MERGER)) {
2577
2648
  const merger = MERGER[key];
2578
- stats.hooks.merge.for(key).tap("DefaultStatsFactoryPlugin", merger);
2649
+ stats.hooks.merge.for(key).tap(PLUGIN_NAME, merger);
2579
2650
  }
2580
2651
  if (options.children) {
2581
2652
  if (Array.isArray(options.children)) {
2582
2653
  stats.hooks.getItemFactory
2583
2654
  .for("compilation.children[].compilation")
2584
2655
  .tap(
2585
- "DefaultStatsFactoryPlugin",
2656
+ PLUGIN_NAME,
2586
2657
  /**
2587
2658
  * @param {Compilation} comp compilation
2588
2659
  * @param {StatsFactoryContext} options options
@@ -2605,7 +2676,7 @@ class DefaultStatsFactoryPlugin {
2605
2676
  );
2606
2677
  stats.hooks.getItemFactory
2607
2678
  .for("compilation.children[].compilation")
2608
- .tap("DefaultStatsFactoryPlugin", () => childFactory);
2679
+ .tap(PLUGIN_NAME, () => childFactory);
2609
2680
  }
2610
2681
  }
2611
2682
  }
@@ -55,6 +55,8 @@ const NAMED_PRESETS = {
55
55
  optimizationBailout: true,
56
56
  errorDetails: true,
57
57
  errorStack: true,
58
+ errorCause: true,
59
+ errorErrors: true,
58
60
  publicPath: true,
59
61
  logging: "verbose",
60
62
  orphanModules: true,
@@ -84,6 +86,8 @@ const NAMED_PRESETS = {
84
86
  providedExports: true,
85
87
  optimizationBailout: true,
86
88
  errorDetails: true,
89
+ errorCause: true,
90
+ errorErrors: true,
87
91
  publicPath: true,
88
92
  logging: true,
89
93
  runtimeModules: true,
@@ -260,6 +264,8 @@ const DEFAULTS = {
260
264
  errorsCount: NORMAL_ON,
261
265
  errorDetails: AUTO_FOR_TO_STRING,
262
266
  errorStack: OFF_FOR_TO_STRING,
267
+ errorCause: AUTO_FOR_TO_STRING,
268
+ errorErrors: AUTO_FOR_TO_STRING,
263
269
  warnings: NORMAL_ON,
264
270
  warningsCount: NORMAL_ON,
265
271
  publicPath: OFF_FOR_TO_STRING,
@@ -364,6 +370,8 @@ const NORMALIZER = {
364
370
  }
365
371
  };
366
372
 
373
+ const PLUGIN_NAME = "DefaultStatsPresetPlugin";
374
+
367
375
  class DefaultStatsPresetPlugin {
368
376
  /**
369
377
  * Apply the plugin
@@ -371,35 +379,32 @@ class DefaultStatsPresetPlugin {
371
379
  * @returns {void}
372
380
  */
373
381
  apply(compiler) {
374
- compiler.hooks.compilation.tap("DefaultStatsPresetPlugin", compilation => {
382
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
375
383
  for (const key of Object.keys(NAMED_PRESETS)) {
376
384
  const defaults = NAMED_PRESETS[/** @type {keyof NamedPresets} */ (key)];
377
385
  compilation.hooks.statsPreset
378
386
  .for(key)
379
- .tap("DefaultStatsPresetPlugin", (options, context) => {
387
+ .tap(PLUGIN_NAME, (options, context) => {
380
388
  applyDefaults(options, defaults);
381
389
  });
382
390
  }
383
- compilation.hooks.statsNormalize.tap(
384
- "DefaultStatsPresetPlugin",
385
- (options, context) => {
386
- for (const key of Object.keys(DEFAULTS)) {
387
- if (options[key] === undefined)
388
- options[key] =
389
- /** @type {Defaults[DefaultsKeys]} */
390
- (DEFAULTS[/** @type {DefaultsKeys} */ (key)])(
391
- options,
392
- context,
393
- compilation
394
- );
395
- }
396
- for (const key of Object.keys(NORMALIZER)) {
391
+ compilation.hooks.statsNormalize.tap(PLUGIN_NAME, (options, context) => {
392
+ for (const key of Object.keys(DEFAULTS)) {
393
+ if (options[key] === undefined)
397
394
  options[key] =
398
- /** @type {TODO} */
399
- (NORMALIZER[/** @type {NormalizerKeys} */ (key)])(options[key]);
400
- }
395
+ /** @type {Defaults[DefaultsKeys]} */
396
+ (DEFAULTS[/** @type {DefaultsKeys} */ (key)])(
397
+ options,
398
+ context,
399
+ compilation
400
+ );
401
+ }
402
+ for (const key of Object.keys(NORMALIZER)) {
403
+ options[key] =
404
+ /** @type {TODO} */
405
+ (NORMALIZER[/** @type {NormalizerKeys} */ (key)])(options[key]);
401
406
  }
402
- );
407
+ });
403
408
  });
404
409
  }
405
410
  }