webpack 5.99.4 → 5.99.6

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 (87) hide show
  1. package/README.md +1 -1
  2. package/lib/APIPlugin.js +2 -2
  3. package/lib/Cache.js +1 -1
  4. package/lib/Chunk.js +12 -9
  5. package/lib/Compilation.js +36 -27
  6. package/lib/Compiler.js +4 -3
  7. package/lib/ContextModule.js +2 -1
  8. package/lib/HotModuleReplacementPlugin.js +3 -3
  9. package/lib/Module.js +10 -2
  10. package/lib/ModuleFilenameHelpers.js +1 -1
  11. package/lib/ModuleGraph.js +15 -10
  12. package/lib/NormalModule.js +1 -1
  13. package/lib/PrefetchPlugin.js +1 -1
  14. package/lib/RecordIdsPlugin.js +1 -1
  15. package/lib/SourceMapDevToolPlugin.js +1 -1
  16. package/lib/Template.js +1 -1
  17. package/lib/WebpackOptionsApply.js +17 -2
  18. package/lib/buildChunkGraph.js +7 -2
  19. package/lib/cache/IdleFileCachePlugin.js +1 -1
  20. package/lib/cache/MemoryCachePlugin.js +2 -1
  21. package/lib/cache/MemoryWithGcCachePlugin.js +3 -2
  22. package/lib/cache/PackFileCacheStrategy.js +13 -21
  23. package/lib/cache/ResolverCachePlugin.js +14 -16
  24. package/lib/cli.js +3 -3
  25. package/lib/config/defaults.js +2 -2
  26. package/lib/config/target.js +6 -6
  27. package/lib/css/CssParser.js +1 -1
  28. package/lib/debug/ProfilingPlugin.js +1 -1
  29. package/lib/dependencies/ContextDependencyHelpers.js +1 -1
  30. package/lib/dependencies/CssIcssImportDependency.js +3 -2
  31. package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
  32. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
  33. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +1 -1
  34. package/lib/dependencies/JsonExportsDependency.js +1 -1
  35. package/lib/dependencies/LocalModulesHelpers.js +1 -1
  36. package/lib/dependencies/RequireResolveDependency.js +1 -1
  37. package/lib/dependencies/WorkerPlugin.js +2 -2
  38. package/lib/esm/ModuleChunkLoadingPlugin.js +20 -0
  39. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +11 -9
  40. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
  41. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  42. package/lib/ids/NamedChunkIdsPlugin.js +2 -2
  43. package/lib/ids/NamedModuleIdsPlugin.js +2 -2
  44. package/lib/index.js +1 -1
  45. package/lib/javascript/BasicEvaluatedExpression.js +2 -2
  46. package/lib/javascript/JavascriptParser.js +66 -72
  47. package/lib/library/EnableLibraryPlugin.js +15 -2
  48. package/lib/library/ModuleLibraryPlugin.js +6 -1
  49. package/lib/logging/createConsoleLogger.js +0 -1
  50. package/lib/node/CommonJsChunkLoadingPlugin.js +2 -2
  51. package/lib/node/NodeTemplatePlugin.js +2 -2
  52. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -2
  53. package/lib/node/ReadFileCompileWasmPlugin.js +3 -3
  54. package/lib/optimize/AggressiveMergingPlugin.js +1 -1
  55. package/lib/optimize/SplitChunksPlugin.js +2 -1
  56. package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -4
  57. package/lib/serialization/BinaryMiddleware.js +22 -38
  58. package/lib/serialization/FileMiddleware.js +29 -33
  59. package/lib/serialization/ObjectMiddleware.js +29 -30
  60. package/lib/serialization/Serializer.js +29 -18
  61. package/lib/serialization/SerializerMiddleware.js +105 -72
  62. package/lib/serialization/SingleItemMiddleware.js +4 -5
  63. package/lib/stats/DefaultStatsFactoryPlugin.js +39 -24
  64. package/lib/stats/DefaultStatsPrinterPlugin.js +267 -80
  65. package/lib/stats/StatsFactory.js +47 -10
  66. package/lib/stats/StatsPrinter.js +52 -31
  67. package/lib/util/ArrayQueue.js +1 -1
  68. package/lib/util/AsyncQueue.js +1 -1
  69. package/lib/util/TupleQueue.js +9 -7
  70. package/lib/util/TupleSet.js +37 -18
  71. package/lib/util/WeakTupleMap.js +50 -37
  72. package/lib/util/cleverMerge.js +2 -2
  73. package/lib/util/comparators.js +1 -1
  74. package/lib/util/createHash.js +1 -1
  75. package/lib/util/fs.js +1 -1
  76. package/lib/util/makeSerializable.js +1 -1
  77. package/lib/util/runtime.js +1 -0
  78. package/lib/util/serialization.js +50 -42
  79. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
  80. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -1
  81. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
  82. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -1
  83. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
  84. package/lib/web/FetchCompileWasmPlugin.js +2 -2
  85. package/lib/webpack.js +1 -1
  86. package/package.json +1 -1
  87. package/types.d.ts +125 -74
@@ -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
@@ -310,12 +318,15 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
310
318
  * @typedef {Record<string, (object: O, data: T, context: StatsFactoryContext, options: NormalizedStatsOptions, factory: StatsFactory) => void>} ExtractorsByOption
311
319
  */
312
320
 
321
+ /** @typedef {{ name: string, chunkGroup: ChunkGroup }} ChunkGroupInfoWithName */
322
+ /** @typedef {{ origin: Module, module: Module }} ModuleTrace */
323
+
313
324
  /**
314
325
  * @typedef {object} SimpleExtractors
315
326
  * @property {ExtractorsByOption<Compilation, StatsCompilation>} compilation
316
327
  * @property {ExtractorsByOption<PreprocessedAsset, StatsAsset>} asset
317
328
  * @property {ExtractorsByOption<PreprocessedAsset, StatsAsset>} asset$visible
318
- * @property {ExtractorsByOption<{ name: string, chunkGroup: ChunkGroup }, StatsChunkGroup>} chunkGroup
329
+ * @property {ExtractorsByOption<ChunkGroupInfoWithName, StatsChunkGroup>} chunkGroup
319
330
  * @property {ExtractorsByOption<Module, StatsModule>} module
320
331
  * @property {ExtractorsByOption<Module, StatsModule>} module$visible
321
332
  * @property {ExtractorsByOption<Module, StatsModuleIssuer>} moduleIssuer
@@ -325,7 +336,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
325
336
  * @property {ExtractorsByOption<OriginRecord, StatsChunkOrigin>} chunkOrigin
326
337
  * @property {ExtractorsByOption<WebpackError, StatsError>} error
327
338
  * @property {ExtractorsByOption<WebpackError, StatsError>} warning
328
- * @property {ExtractorsByOption<{ origin: Module, module: Module }, StatsModuleTraceItem>} moduleTraceItem
339
+ * @property {ExtractorsByOption<ModuleTrace, StatsModuleTraceItem>} moduleTraceItem
329
340
  * @property {ExtractorsByOption<Dependency, StatsModuleTraceDependency>} moduleTraceDependency
330
341
  */
331
342
 
@@ -441,6 +452,7 @@ const EXTRACT_ERROR = {
441
452
  } = context;
442
453
  /** @type {Set<Module>} */
443
454
  const visitedModules = new Set();
455
+ /** @type {ModuleTrace[]} */
444
456
  const moduleTrace = [];
445
457
  let current = error.module;
446
458
  while (current) {
@@ -796,6 +808,7 @@ const SIMPLE_EXTRACTORS = {
796
808
  factory
797
809
  ) => {
798
810
  const { type } = context;
811
+ /** @type {ChunkGroupInfoWithName[]} */
799
812
  const array = Array.from(compilation.entrypoints, ([key, value]) => ({
800
813
  name: key,
801
814
  chunkGroup: value
@@ -915,12 +928,13 @@ const SIMPLE_EXTRACTORS = {
915
928
  /** @type {KnownNormalizedStatsOptions["warningsFilter"]} */
916
929
  (warningsFilter).length === 0
917
930
  )
918
- return cachedGetWarnings(c);
931
+ // Type is wrong, because we don't need the real value for counting
932
+ return /** @type {EXPECTED_ANY[]} */ (cachedGetWarnings(c));
919
933
  return factory
920
934
  .create(`${type}${childType}.warnings`, cachedGetWarnings(c), context)
921
935
  .filter(
922
936
  /**
923
- * @param {TODO} warning warning
937
+ * @param {StatsError} warning warning
924
938
  * @returns {boolean} result
925
939
  */
926
940
  warning => {
@@ -1169,7 +1183,6 @@ const SIMPLE_EXTRACTORS = {
1169
1183
  cached: !built && !codeGenerated
1170
1184
  };
1171
1185
  Object.assign(object, statsModule);
1172
-
1173
1186
  if (built || codeGenerated || options.cachedModules) {
1174
1187
  Object.assign(
1175
1188
  object,
@@ -1183,7 +1196,7 @@ const SIMPLE_EXTRACTORS = {
1183
1196
  const { type, rootModules } = context;
1184
1197
  const compilation = /** @type {Compilation} */ (context.compilation);
1185
1198
  const { moduleGraph } = compilation;
1186
- /** @type {Module[]} */
1199
+ /** @type {ModuleIssuerPath} */
1187
1200
  const path = [];
1188
1201
  const issuer = moduleGraph.getIssuer(module);
1189
1202
  let current = issuer;
@@ -1221,7 +1234,8 @@ const SIMPLE_EXTRACTORS = {
1221
1234
  issuerName: issuer && issuer.readableIdentifier(requestShortener),
1222
1235
  issuerPath:
1223
1236
  issuer &&
1224
- factory.create(`${type.slice(0, -8)}.issuerPath`, path, context),
1237
+ /** @type {StatsModuleIssuer[] | undefined} */
1238
+ (factory.create(`${type.slice(0, -8)}.issuerPath`, path, context)),
1225
1239
  failed: errorsCount > 0,
1226
1240
  errors: errorsCount,
1227
1241
  warnings: warningsCount
@@ -1506,6 +1520,7 @@ const SIMPLE_EXTRACTORS = {
1506
1520
  } = context;
1507
1521
  /** @type {Set<string>} */
1508
1522
  const originsKeySet = new Set();
1523
+ /** @type {OriginRecord[]} */
1509
1524
  const origins = [];
1510
1525
  for (const g of chunk.groupsIterable) {
1511
1526
  origins.push(...g.origins);
@@ -1562,7 +1577,8 @@ const SIMPLE_EXTRACTORS = {
1562
1577
  .map(c => c.dependency);
1563
1578
  object.dependencies = factory.create(
1564
1579
  `${type}.dependencies`,
1565
- Array.from(new Set(dependencies)),
1580
+ /** @type {Dependency[]} */
1581
+ (Array.from(new Set(dependencies))),
1566
1582
  context
1567
1583
  );
1568
1584
  },
@@ -1612,9 +1628,7 @@ const FILTER_RESULTS = {
1612
1628
  }
1613
1629
  };
1614
1630
 
1615
- /**
1616
- * @type {Record<string, (comparators: Comparator<Module>[], context: StatsFactoryContext) => void>}
1617
- */
1631
+ /** @type {Record<string, (comparators: Comparator<Module>[], context: StatsFactoryContext) => void>} */
1618
1632
  const MODULES_SORTER = {
1619
1633
  _: (comparators, { compilation: { moduleGraph } }) => {
1620
1634
  comparators.push(
@@ -1625,7 +1639,7 @@ const MODULES_SORTER = {
1625
1639
  }
1626
1640
  };
1627
1641
 
1628
- /** @type {Record<string, Record<string, (comparators: Comparator<any>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>>} */
1642
+ /** @type {Record<string, Record<string, (comparators: Comparator<TODO>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>>} */
1629
1643
  const SORTERS = {
1630
1644
  "compilation.chunks": {
1631
1645
  _: comparators => {
@@ -1679,7 +1693,7 @@ const SORTERS = {
1679
1693
 
1680
1694
  /**
1681
1695
  * @template T
1682
- * @typedef {T & { children: Children<T>[] | undefined, filteredChildren?: number }} Children
1696
+ * @typedef {T & { children?: Children<T>[] | undefined, filteredChildren?: number }} Children
1683
1697
  */
1684
1698
 
1685
1699
  /**
@@ -2051,6 +2065,7 @@ const ASSETS_GROUPERS = {
2051
2065
  const pathMatch =
2052
2066
  groupAssetsByPath && GROUP_PATH_REGEXP.exec(asset.name);
2053
2067
  const path = pathMatch ? pathMatch[1].split(/[/\\]/) : [];
2068
+ /** @type {string[]} */
2054
2069
  const keys = [];
2055
2070
  if (groupAssetsByPath) {
2056
2071
  keys.push(".");
@@ -2141,7 +2156,7 @@ const ASSETS_GROUPERS = {
2141
2156
 
2142
2157
  /** @typedef {Record<string, (groupConfigs: GroupConfig<KnownStatsModule, TODO>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>} ModulesGroupers */
2143
2158
 
2144
- /** @type {(type: "module" | "chunk" | "root-of-chunk" | "nested") => ModulesGroupers} */
2159
+ /** @type {(type: ExcludeModulesType) => ModulesGroupers} */
2145
2160
  const MODULES_GROUPERS = type => ({
2146
2161
  _: (groupConfigs, context, options) => {
2147
2162
  /**
@@ -2386,7 +2401,7 @@ const sortByField = field => {
2386
2401
  return sortFn;
2387
2402
  };
2388
2403
 
2389
- /** @type {Record<string, (comparators: Comparator<TODO>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>} */
2404
+ /** @type {Record<string, (comparators: Comparator<Asset>[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>} */
2390
2405
  const ASSET_SORTERS = {
2391
2406
  assetsSort: (comparators, context, { assetsSort }) => {
2392
2407
  comparators.push(sortByField(assetsSort));