webpack 5.94.0 → 5.96.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/README.md +1 -1
  2. package/lib/AsyncDependenciesBlock.js +1 -1
  3. package/lib/BannerPlugin.js +2 -1
  4. package/lib/Chunk.js +30 -0
  5. package/lib/ChunkGraph.js +11 -6
  6. package/lib/ChunkGroup.js +2 -2
  7. package/lib/CleanPlugin.js +4 -5
  8. package/lib/CodeGenerationResults.js +6 -5
  9. package/lib/Compilation.js +71 -48
  10. package/lib/Compiler.js +7 -5
  11. package/lib/ConcatenationScope.js +7 -20
  12. package/lib/ContextModule.js +7 -8
  13. package/lib/CssModule.js +25 -21
  14. package/lib/DefinePlugin.js +14 -8
  15. package/lib/DelegatedModule.js +3 -3
  16. package/lib/DllModule.js +4 -4
  17. package/lib/DynamicEntryPlugin.js +29 -22
  18. package/lib/EnvironmentPlugin.js +3 -2
  19. package/lib/EvalDevToolModulePlugin.js +5 -2
  20. package/lib/EvalSourceMapDevToolPlugin.js +5 -2
  21. package/lib/ExternalModule.js +118 -99
  22. package/lib/ExternalModuleFactoryPlugin.js +33 -9
  23. package/lib/FileSystemInfo.js +12 -8
  24. package/lib/Generator.js +5 -4
  25. package/lib/HotModuleReplacementPlugin.js +8 -6
  26. package/lib/IgnorePlugin.js +19 -1
  27. package/lib/LoaderOptionsPlugin.js +3 -1
  28. package/lib/Module.js +9 -8
  29. package/lib/ModuleSourceTypesConstants.js +100 -0
  30. package/lib/NormalModule.js +27 -13
  31. package/lib/NormalModuleFactory.js +38 -22
  32. package/lib/OptionsApply.js +12 -1
  33. package/lib/ProgressPlugin.js +50 -10
  34. package/lib/RawModule.js +3 -4
  35. package/lib/RuntimeModule.js +3 -4
  36. package/lib/RuntimePlugin.js +11 -4
  37. package/lib/RuntimeTemplate.js +13 -42
  38. package/lib/SourceMapDevToolPlugin.js +10 -7
  39. package/lib/TemplatedPathPlugin.js +9 -3
  40. package/lib/Watching.js +2 -2
  41. package/lib/WebpackOptionsApply.js +42 -21
  42. package/lib/asset/AssetGenerator.js +347 -194
  43. package/lib/asset/AssetModulesPlugin.js +2 -1
  44. package/lib/asset/AssetSourceGenerator.js +82 -27
  45. package/lib/asset/RawDataUrlModule.js +5 -4
  46. package/lib/buildChunkGraph.js +79 -62
  47. package/lib/cache/PackFileCacheStrategy.js +69 -31
  48. package/lib/cache/ResolverCachePlugin.js +248 -173
  49. package/lib/config/defaults.js +135 -126
  50. package/lib/container/ContainerEntryModule.js +3 -4
  51. package/lib/container/ContainerPlugin.js +8 -0
  52. package/lib/container/FallbackModule.js +2 -2
  53. package/lib/container/HoistContainerReferencesPlugin.js +250 -0
  54. package/lib/container/ModuleFederationPlugin.js +38 -1
  55. package/lib/container/RemoteModule.js +4 -2
  56. package/lib/container/RemoteRuntimeModule.js +4 -2
  57. package/lib/css/CssExportsGenerator.js +16 -12
  58. package/lib/css/CssGenerator.js +22 -16
  59. package/lib/css/CssLoadingRuntimeModule.js +7 -6
  60. package/lib/css/CssModulesPlugin.js +122 -77
  61. package/lib/css/CssParser.js +655 -526
  62. package/lib/css/walkCssTokens.js +1168 -338
  63. package/lib/debug/ProfilingPlugin.js +5 -0
  64. package/lib/dependencies/CommonJsExportsParserPlugin.js +5 -2
  65. package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -6
  66. package/lib/dependencies/ContextDependency.js +6 -1
  67. package/lib/dependencies/ContextElementDependency.js +33 -6
  68. package/lib/dependencies/CssExportDependency.js +3 -3
  69. package/lib/dependencies/CssLocalIdentifierDependency.js +26 -17
  70. package/lib/dependencies/CssUrlDependency.js +33 -3
  71. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -3
  72. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +39 -14
  73. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +15 -82
  74. package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -2
  75. package/lib/dependencies/ImportParserPlugin.js +9 -7
  76. package/lib/dependencies/LoaderPlugin.js +19 -0
  77. package/lib/dependencies/SystemPlugin.js +2 -1
  78. package/lib/dependencies/URLPlugin.js +7 -1
  79. package/lib/dependencies/WorkerPlugin.js +1 -1
  80. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +4 -2
  81. package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
  82. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
  83. package/lib/hmr/LazyCompilationPlugin.js +16 -4
  84. package/lib/hmr/lazyCompilationBackend.js +1 -7
  85. package/lib/index.js +35 -6
  86. package/lib/javascript/EnableChunkLoadingPlugin.js +2 -2
  87. package/lib/javascript/JavascriptGenerator.js +8 -8
  88. package/lib/javascript/JavascriptModulesPlugin.js +166 -88
  89. package/lib/javascript/JavascriptParser.js +338 -117
  90. package/lib/json/JsonGenerator.js +5 -5
  91. package/lib/library/EnableLibraryPlugin.js +2 -2
  92. package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
  93. package/lib/library/UmdLibraryPlugin.js +16 -8
  94. package/lib/logging/Logger.js +11 -11
  95. package/lib/logging/createConsoleLogger.js +14 -14
  96. package/lib/logging/truncateArgs.js +1 -1
  97. package/lib/node/NodeWatchFileSystem.js +3 -1
  98. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +20 -18
  99. package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
  100. package/lib/node/nodeConsole.js +11 -8
  101. package/lib/optimize/AggressiveSplittingPlugin.js +21 -7
  102. package/lib/optimize/ConcatenatedModule.js +44 -148
  103. package/lib/optimize/FlagIncludedChunksPlugin.js +6 -0
  104. package/lib/optimize/InnerGraphPlugin.js +57 -16
  105. package/lib/optimize/LimitChunkCountPlugin.js +2 -4
  106. package/lib/optimize/MergeDuplicateChunksPlugin.js +2 -2
  107. package/lib/optimize/ModuleConcatenationPlugin.js +4 -2
  108. package/lib/optimize/RealContentHashPlugin.js +1 -1
  109. package/lib/optimize/SideEffectsFlagPlugin.js +6 -3
  110. package/lib/rules/RuleSetCompiler.js +2 -2
  111. package/lib/runtime/GetChunkFilenameRuntimeModule.js +2 -2
  112. package/lib/schemes/DataUriPlugin.js +1 -1
  113. package/lib/serialization/BinaryMiddleware.js +32 -19
  114. package/lib/serialization/ObjectMiddleware.js +23 -9
  115. package/lib/serialization/SerializerMiddleware.js +3 -2
  116. package/lib/serialization/types.js +2 -2
  117. package/lib/sharing/ConsumeSharedModule.js +2 -3
  118. package/lib/sharing/ConsumeSharedRuntimeModule.js +3 -1
  119. package/lib/sharing/ProvideSharedModule.js +2 -3
  120. package/lib/stats/DefaultStatsFactoryPlugin.js +22 -20
  121. package/lib/stats/StatsFactory.js +12 -12
  122. package/lib/stats/StatsPrinter.js +7 -7
  123. package/lib/util/AsyncQueue.js +17 -1
  124. package/lib/util/IterableHelpers.js +1 -1
  125. package/lib/util/LazySet.js +12 -0
  126. package/lib/util/SetHelpers.js +1 -1
  127. package/lib/util/cleverMerge.js +48 -24
  128. package/lib/util/concatenate.js +227 -0
  129. package/lib/util/create-schema-validation.js +22 -9
  130. package/lib/util/deprecation.js +86 -28
  131. package/lib/util/fs.js +10 -10
  132. package/lib/util/hash/wasm-hash.js +12 -1
  133. package/lib/util/magicComment.js +21 -0
  134. package/lib/util/makeSerializable.js +24 -1
  135. package/lib/util/memoize.js +2 -1
  136. package/lib/util/runtime.js +10 -1
  137. package/lib/util/semver.js +130 -23
  138. package/lib/wasm/EnableWasmLoadingPlugin.js +2 -2
  139. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
  140. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +5 -5
  141. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -5
  142. package/lib/wasm-sync/WebAssemblyGenerator.js +8 -9
  143. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -5
  144. package/lib/web/FetchCompileAsyncWasmPlugin.js +1 -2
  145. package/lib/web/FetchCompileWasmPlugin.js +1 -2
  146. package/lib/web/JsonpChunkLoadingRuntimeModule.js +6 -6
  147. package/package.json +19 -20
  148. package/schemas/WebpackOptions.check.js +1 -1
  149. package/schemas/WebpackOptions.json +12 -2
  150. package/types.d.ts +817 -269
  151. package/lib/util/mergeScope.js +0 -76
@@ -10,7 +10,7 @@ const { SyncHook } = require("tapable");
10
10
  /** @typedef {import("../../declarations/WebpackOptions").RuleSetRule} RuleSetRule */
11
11
  /** @typedef {import("../../declarations/WebpackOptions").RuleSetRules} RuleSetRules */
12
12
 
13
- /** @typedef {function(string): boolean} RuleConditionFunction */
13
+ /** @typedef {function(string | EffectData): boolean} RuleConditionFunction */
14
14
 
15
15
  /**
16
16
  * @typedef {object} RuleCondition
@@ -106,7 +106,7 @@ class RuleSetCompiler {
106
106
  }
107
107
  }
108
108
  if (current !== undefined) {
109
- if (!condition.fn(/** @type {string} */ (current))) return false;
109
+ if (!condition.fn(current)) return false;
110
110
  continue;
111
111
  }
112
112
  } else if (p in data) {
@@ -20,7 +20,7 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
20
20
  * @param {string} contentType the contentType to use the content hash for
21
21
  * @param {string} name kind of filename
22
22
  * @param {string} global function name to be assigned
23
- * @param {function(Chunk): TemplatePath} getFilenameForChunk functor to get the filename or function
23
+ * @param {function(Chunk): TemplatePath | false} getFilenameForChunk functor to get the filename or function
24
24
  * @param {boolean} allChunks when false, only async chunks are included
25
25
  */
26
26
  constructor(contentType, name, global, getFilenameForChunk, allChunks) {
@@ -244,7 +244,7 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
244
244
  hashWithLength: length =>
245
245
  `" + ${RuntimeGlobals.getFullHash}().slice(0, ${length}) + "`,
246
246
  chunk: {
247
- id: `" + chunkId + "`,
247
+ id: '" + chunkId + "',
248
248
  hash: mapExpr(c => /** @type {string} */ (c.renderedHash)),
249
249
  hashWithLength: mapExprWithLength(
250
250
  c => /** @type {string} */ (c.renderedHash)
@@ -11,7 +11,7 @@ const NormalModule = require("../NormalModule");
11
11
 
12
12
  // data URL scheme: "data:text/javascript;charset=utf-8;base64,some-string"
13
13
  // http://www.ietf.org/rfc/rfc2397.txt
14
- const URIRegEx = /^data:([^;,]+)?((?:;[^;,]+)*?)(?:;(base64))?,(.*)$/i;
14
+ const URIRegEx = /^data:([^;,]+)?((?:;[^;,]+)*?)(?:;(base64)?)?,(.*)$/i;
15
15
 
16
16
  /**
17
17
  * @param {string} uri data URI
@@ -135,6 +135,8 @@ const identifyBigInt = n => {
135
135
  return 2;
136
136
  };
137
137
 
138
+ /** @typedef {TODO} Context */
139
+
138
140
  /**
139
141
  * @typedef {PrimitiveSerializableType[]} DeserializedType
140
142
  * @typedef {BufferSerializableType[]} SerializedType
@@ -152,7 +154,7 @@ class BinaryMiddleware extends SerializerMiddleware {
152
154
 
153
155
  /**
154
156
  * @param {function(): Promise<any> | any} fn lazy function
155
- * @param {object} context serialize function
157
+ * @param {TODO} context serialize function
156
158
  * @returns {function(): Promise<any> | any} new lazy
157
159
  */
158
160
  _serializeLazy(fn, context) {
@@ -163,7 +165,7 @@ class BinaryMiddleware extends SerializerMiddleware {
163
165
 
164
166
  /**
165
167
  * @param {DeserializedType} data data
166
- * @param {object} context context object
168
+ * @param {TODO} context context object
167
169
  * @param {{ leftOverBuffer: Buffer | null, allocationSize: number, increaseCounter: number }} allocationScope allocation scope
168
170
  * @returns {SerializedType} serialized data
169
171
  */
@@ -634,9 +636,9 @@ class BinaryMiddleware extends SerializerMiddleware {
634
636
  // avoid leaking memory
635
637
  currentBuffer = null;
636
638
  leftOverBuffer = null;
637
- allocationScope = undefined;
639
+ allocationScope = /** @type {EXPECTED_ANY} */ (undefined);
638
640
  const _buffers = buffers;
639
- buffers = undefined;
641
+ buffers = /** @type {EXPECTED_ANY} */ (undefined);
640
642
  return _buffers;
641
643
  }
642
644
 
@@ -666,19 +668,21 @@ class BinaryMiddleware extends SerializerMiddleware {
666
668
 
667
669
  /**
668
670
  * @param {SerializedType} data data
669
- * @param {object} context context object
671
+ * @param {TODO} context context object
670
672
  * @returns {DeserializedType} deserialized data
671
673
  */
672
674
  _deserialize(data, context) {
673
675
  let currentDataItem = 0;
676
+ /** @type {BufferSerializableType | null} */
674
677
  let currentBuffer = data[0];
675
678
  let currentIsBuffer = Buffer.isBuffer(currentBuffer);
676
679
  let currentPosition = 0;
677
680
 
681
+ /** @type {(x: Buffer) => Buffer} */
678
682
  const retainedBuffer = context.retainedBuffer || (x => x);
679
683
 
680
684
  const checkOverflow = () => {
681
- if (currentPosition >= currentBuffer.length) {
685
+ if (currentPosition >= /** @type {Buffer} */ (currentBuffer).length) {
682
686
  currentPosition = 0;
683
687
  currentDataItem++;
684
688
  currentBuffer =
@@ -691,7 +695,8 @@ class BinaryMiddleware extends SerializerMiddleware {
691
695
  * @returns {boolean} true when in current buffer, otherwise false
692
696
  */
693
697
  const isInCurrentBuffer = n =>
694
- currentIsBuffer && n + currentPosition <= currentBuffer.length;
698
+ currentIsBuffer &&
699
+ n + currentPosition <= /** @type {Buffer} */ (currentBuffer).length;
695
700
  const ensureBuffer = () => {
696
701
  if (!currentIsBuffer) {
697
702
  throw new Error(
@@ -708,12 +713,13 @@ class BinaryMiddleware extends SerializerMiddleware {
708
713
  */
709
714
  const read = n => {
710
715
  ensureBuffer();
711
- const rem = currentBuffer.length - currentPosition;
716
+ const rem =
717
+ /** @type {Buffer} */ (currentBuffer).length - currentPosition;
712
718
  if (rem < n) {
713
719
  const buffers = [read(rem)];
714
720
  n -= rem;
715
721
  ensureBuffer();
716
- while (currentBuffer.length < n) {
722
+ while (/** @type {Buffer} */ (currentBuffer).length < n) {
717
723
  const b = /** @type {Buffer} */ (currentBuffer);
718
724
  buffers.push(b);
719
725
  n -= b.length;
@@ -739,7 +745,9 @@ class BinaryMiddleware extends SerializerMiddleware {
739
745
  */
740
746
  const readUpTo = n => {
741
747
  ensureBuffer();
742
- const rem = currentBuffer.length - currentPosition;
748
+ const rem =
749
+ /** @type {Buffer} */
750
+ (currentBuffer).length - currentPosition;
743
751
  if (rem < n) {
744
752
  n = rem;
745
753
  }
@@ -901,7 +909,8 @@ class BinaryMiddleware extends SerializerMiddleware {
901
909
  const len = readU32();
902
910
  if (isInCurrentBuffer(len) && currentPosition + len < 0x7fffffff) {
903
911
  result.push(
904
- currentBuffer.toString(
912
+ /** @type {Buffer} */
913
+ (currentBuffer).toString(
905
914
  undefined,
906
915
  currentPosition,
907
916
  currentPosition + len
@@ -919,7 +928,8 @@ class BinaryMiddleware extends SerializerMiddleware {
919
928
  return () => {
920
929
  if (currentIsBuffer && currentPosition < 0x7ffffffe) {
921
930
  result.push(
922
- currentBuffer.toString(
931
+ /** @type {Buffer} */
932
+ (currentBuffer).toString(
923
933
  "latin1",
924
934
  currentPosition,
925
935
  currentPosition + 1
@@ -992,11 +1002,13 @@ class BinaryMiddleware extends SerializerMiddleware {
992
1002
  return () => {
993
1003
  const len = readU32();
994
1004
  if (isInCurrentBuffer(len) && currentPosition + len < 0x7fffffff) {
995
- const value = currentBuffer.toString(
996
- undefined,
997
- currentPosition,
998
- currentPosition + len
999
- );
1005
+ const value =
1006
+ /** @type {Buffer} */
1007
+ (currentBuffer).toString(
1008
+ undefined,
1009
+ currentPosition,
1010
+ currentPosition + len
1011
+ );
1000
1012
 
1001
1013
  result.push(BigInt(value));
1002
1014
  currentPosition += len;
@@ -1018,7 +1030,8 @@ class BinaryMiddleware extends SerializerMiddleware {
1018
1030
  currentPosition + len < 0x7fffffff
1019
1031
  ) {
1020
1032
  result.push(
1021
- currentBuffer.toString(
1033
+ /** @type {Buffer} */
1034
+ (currentBuffer).toString(
1022
1035
  "latin1",
1023
1036
  currentPosition,
1024
1037
  currentPosition + len
@@ -1118,7 +1131,7 @@ class BinaryMiddleware extends SerializerMiddleware {
1118
1131
  // avoid leaking memory in context
1119
1132
  // eslint-disable-next-line prefer-const
1120
1133
  let _result = result;
1121
- result = undefined;
1134
+ result = /** @type {EXPECTED_ANY} */ (undefined);
1122
1135
  return _result;
1123
1136
  }
1124
1137
  }
@@ -281,8 +281,8 @@ class ObjectMiddleware extends SerializerMiddleware {
281
281
 
282
282
  /**
283
283
  * @param {string} request request
284
- * @param {TODO} name name
285
- * @returns {ObjectSerializer} serializer
284
+ * @param {string} name name
285
+ * @returns {ObjectSerializer | undefined} serializer
286
286
  */
287
287
  static _getDeserializerForWithoutError(request, name) {
288
288
  const key = `${request}/${name}`;
@@ -304,6 +304,10 @@ class ObjectMiddleware extends SerializerMiddleware {
304
304
  referenceable.set(item, currentPos++);
305
305
  };
306
306
  let bufferDedupeMap = new Map();
307
+ /**
308
+ * @param {Buffer} buf buffer
309
+ * @returns {Buffer} deduped buffer
310
+ */
307
311
  const dedupeBuffer = buf => {
308
312
  const len = buf.length;
309
313
  const entry = bufferDedupeMap.get(len);
@@ -412,6 +416,7 @@ class ObjectMiddleware extends SerializerMiddleware {
412
416
  })
413
417
  .join(" -> ");
414
418
  };
419
+ /** @type {WeakSet<Error>} */
415
420
  let hasDebugInfoAttached;
416
421
  let ctx = {
417
422
  write(value, key) {
@@ -421,9 +426,10 @@ class ObjectMiddleware extends SerializerMiddleware {
421
426
  if (err !== NOT_SERIALIZABLE) {
422
427
  if (hasDebugInfoAttached === undefined)
423
428
  hasDebugInfoAttached = new WeakSet();
424
- if (!hasDebugInfoAttached.has(err)) {
425
- err.message += `\nwhile serializing ${stackToString(value)}`;
426
- hasDebugInfoAttached.add(err);
429
+ if (!hasDebugInfoAttached.has(/** @type {Error} */ (err))) {
430
+ /** @type {Error} */
431
+ (err).message += `\nwhile serializing ${stackToString(value)}`;
432
+ hasDebugInfoAttached.add(/** @type {Error} */ (err));
427
433
  }
428
434
  }
429
435
  throw err;
@@ -586,7 +592,8 @@ class ObjectMiddleware extends SerializerMiddleware {
586
592
  bufferDedupeMap =
587
593
  objectTypeLookup =
588
594
  ctx =
589
- undefined;
595
+ /** @type {EXPECTED_ANY} */
596
+ (undefined);
590
597
  }
591
598
  }
592
599
 
@@ -657,7 +664,7 @@ class ObjectMiddleware extends SerializerMiddleware {
657
664
  `at position ${currentDataPos - 1}`
658
665
  );
659
666
  }
660
- const name = read();
667
+ const name = /** @type {string} */ (read());
661
668
 
662
669
  serializer = ObjectMiddleware._getDeserializerForWithoutError(
663
670
  request,
@@ -721,7 +728,8 @@ class ObjectMiddleware extends SerializerMiddleware {
721
728
  : serializerEntry[1].name
722
729
  ? `${serializerEntry[1].request} ${serializerEntry[1].name}`
723
730
  : serializerEntry[1].request;
724
- err.message += `\n(during deserialization of ${name})`;
731
+ /** @type {Error} */
732
+ (err).message += `\n(during deserialization of ${name})`;
725
733
  throw err;
726
734
  }
727
735
  }
@@ -755,7 +763,13 @@ class ObjectMiddleware extends SerializerMiddleware {
755
763
  // This happens because the optimized code v8 generates
756
764
  // is optimized for our "ctx.read" method so it will reference
757
765
  // it from e. g. Dependency.prototype.deserialize -(IC)-> ctx.read
758
- result = referenceable = data = objectTypeLookup = ctx = undefined;
766
+ result =
767
+ referenceable =
768
+ data =
769
+ objectTypeLookup =
770
+ ctx =
771
+ /** @type {EXPECTED_ANY} */
772
+ (undefined);
759
773
  }
760
774
  }
761
775
  }
@@ -112,9 +112,10 @@ class SerializerMiddleware {
112
112
  }
113
113
 
114
114
  /**
115
+ * @template T
115
116
  * @param {function(): Promise<any> | any} lazy lazy function
116
- * @param {function(any): Promise<any> | any} deserialize deserialize function
117
- * @returns {function(): Promise<any> | any} new lazy
117
+ * @param {function(T): Promise<T> | T} deserialize deserialize function
118
+ * @returns {function(): Promise<T> | T} new lazy
118
119
  */
119
120
  static deserializeLazy(lazy, deserialize) {
120
121
  const fn = memoize(() => {
@@ -6,8 +6,8 @@
6
6
 
7
7
  /** @typedef {undefined | null | number | string | boolean | Buffer | object | (() => ComplexSerializableType[] | Promise<ComplexSerializableType[]>)} ComplexSerializableType */
8
8
 
9
- /** @typedef {undefined|null|number|bigint|string|boolean|Buffer|(() => PrimitiveSerializableType[] | Promise<PrimitiveSerializableType[]>)} PrimitiveSerializableType */
9
+ /** @typedef {undefined | null | number | bigint | string | boolean | Buffer | (() => PrimitiveSerializableType[] | Promise<PrimitiveSerializableType[]>)} PrimitiveSerializableType */
10
10
 
11
- /** @typedef {Buffer|(() => BufferSerializableType[] | Promise<BufferSerializableType[]>)} BufferSerializableType */
11
+ /** @typedef {Buffer | (() => BufferSerializableType[] | Promise<BufferSerializableType[]>)} BufferSerializableType */
12
12
 
13
13
  module.exports = {};
@@ -8,6 +8,7 @@
8
8
  const { RawSource } = require("webpack-sources");
9
9
  const AsyncDependenciesBlock = require("../AsyncDependenciesBlock");
10
10
  const Module = require("../Module");
11
+ const { CONSUME_SHARED_TYPES } = require("../ModuleSourceTypesConstants");
11
12
  const {
12
13
  WEBPACK_MODULE_TYPE_CONSUME_SHARED_MODULE
13
14
  } = require("../ModuleTypeConstants");
@@ -48,8 +49,6 @@ const ConsumeSharedFallbackDependency = require("./ConsumeSharedFallbackDependen
48
49
  * @property {boolean} eager include the fallback module in a sync way
49
50
  */
50
51
 
51
- const TYPES = new Set(["consume-shared"]);
52
-
53
52
  class ConsumeSharedModule extends Module {
54
53
  /**
55
54
  * @param {string} context context
@@ -151,7 +150,7 @@ class ConsumeSharedModule extends Module {
151
150
  * @returns {SourceTypes} types available (do not mutate)
152
151
  */
153
152
  getSourceTypes() {
154
- return TYPES;
153
+ return CONSUME_SHARED_TYPES;
155
154
  }
156
155
 
157
156
  /**
@@ -67,7 +67,9 @@ class ConsumeSharedRuntimeModule extends RuntimeModule {
67
67
  );
68
68
  }
69
69
  };
70
- for (const chunk of /** @type {Chunk} */ (this.chunk).getAllAsyncChunks()) {
70
+ for (const chunk of /** @type {Chunk} */ (
71
+ this.chunk
72
+ ).getAllReferencedChunks()) {
71
73
  const modules = chunkGraph.getChunkModulesIterableBySourceType(
72
74
  chunk,
73
75
  "consume-shared"
@@ -7,6 +7,7 @@
7
7
 
8
8
  const AsyncDependenciesBlock = require("../AsyncDependenciesBlock");
9
9
  const Module = require("../Module");
10
+ const { SHARED_INIT_TYPES } = require("../ModuleSourceTypesConstants");
10
11
  const { WEBPACK_MODULE_TYPE_PROVIDE } = require("../ModuleTypeConstants");
11
12
  const RuntimeGlobals = require("../RuntimeGlobals");
12
13
  const makeSerializable = require("../util/makeSerializable");
@@ -30,8 +31,6 @@ const ProvideForSharedDependency = require("./ProvideForSharedDependency");
30
31
  /** @typedef {import("../util/Hash")} Hash */
31
32
  /** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
32
33
 
33
- const TYPES = new Set(["share-init"]);
34
-
35
34
  class ProvideSharedModule extends Module {
36
35
  /**
37
36
  * @param {string} shareScope shared scope name
@@ -124,7 +123,7 @@ class ProvideSharedModule extends Module {
124
123
  * @returns {SourceTypes} types available (do not mutate)
125
124
  */
126
125
  getSourceTypes() {
127
- return TYPES;
126
+ return SHARED_INIT_TYPES;
128
127
  }
129
128
 
130
129
  /**
@@ -55,7 +55,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
55
55
  */
56
56
  /** @typedef {import("./StatsFactory")} StatsFactory */
57
57
  /** @typedef {import("./StatsFactory").StatsFactoryContext} StatsFactoryContext */
58
- /** @typedef {Record<string, any> & KnownStatsCompilation} StatsCompilation */
58
+ /** @typedef {Record<string, EXPECTED_ANY> & KnownStatsCompilation} StatsCompilation */
59
59
  /**
60
60
  * @typedef {object} KnownStatsCompilation
61
61
  * @property {any=} env
@@ -83,7 +83,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
83
83
  * @property {Record<string, StatsLogging>=} logging
84
84
  */
85
85
 
86
- /** @typedef {Record<string, any> & KnownStatsLogging} StatsLogging */
86
+ /** @typedef {Record<string, EXPECTED_ANY> & KnownStatsLogging} StatsLogging */
87
87
  /**
88
88
  * @typedef {object} KnownStatsLogging
89
89
  * @property {StatsLoggingEntry[]} entries
@@ -91,7 +91,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
91
91
  * @property {boolean} debug
92
92
  */
93
93
 
94
- /** @typedef {Record<string, any> & KnownStatsLoggingEntry} StatsLoggingEntry */
94
+ /** @typedef {Record<string, EXPECTED_ANY> & KnownStatsLoggingEntry} StatsLoggingEntry */
95
95
  /**
96
96
  * @typedef {object} KnownStatsLoggingEntry
97
97
  * @property {string} type
@@ -102,7 +102,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
102
102
  * @property {number=} time
103
103
  */
104
104
 
105
- /** @typedef {Record<string, any> & KnownStatsAsset} StatsAsset */
105
+ /** @typedef {Record<string, EXPECTED_ANY> & KnownStatsAsset} StatsAsset */
106
106
  /**
107
107
  * @typedef {object} KnownStatsAsset
108
108
  * @property {string} type
@@ -123,11 +123,11 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
123
123
  * @property {boolean=} isOverSizeLimit
124
124
  */
125
125
 
126
- /** @typedef {Record<string, any> & KnownStatsChunkGroup} StatsChunkGroup */
126
+ /** @typedef {Record<string, EXPECTED_ANY> & KnownStatsChunkGroup} StatsChunkGroup */
127
127
  /**
128
128
  * @typedef {object} KnownStatsChunkGroup
129
- * @property {string=} name
130
- * @property {(string|number)[]=} chunks
129
+ * @property {(string | null)=} name
130
+ * @property {(string | number)[]=} chunks
131
131
  * @property {({ name: string, size?: number })[]=} assets
132
132
  * @property {number=} filteredAssets
133
133
  * @property {number=} assetsSize
@@ -139,7 +139,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
139
139
  * @property {boolean=} isOverSizeLimit
140
140
  */
141
141
 
142
- /** @typedef {Record<string, any> & KnownStatsModule} StatsModule */
142
+ /** @typedef {Record<string, EXPECTED_ANY> & KnownStatsModule} StatsModule */
143
143
  /**
144
144
  * @typedef {object} KnownStatsModule
145
145
  * @property {string=} type
@@ -183,7 +183,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
183
183
  * @property {ReturnType<Source["source"]>=} source
184
184
  */
185
185
 
186
- /** @typedef {Record<string, any> & KnownStatsProfile} StatsProfile */
186
+ /** @typedef {Record<string, EXPECTED_ANY> & KnownStatsProfile} StatsProfile */
187
187
  /**
188
188
  * @typedef {object} KnownStatsProfile
189
189
  * @property {number} total
@@ -198,7 +198,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
198
198
  * @property {number} dependencies
199
199
  */
200
200
 
201
- /** @typedef {Record<string, any> & KnownStatsModuleIssuer} StatsModuleIssuer */
201
+ /** @typedef {Record<string, EXPECTED_ANY> & KnownStatsModuleIssuer} StatsModuleIssuer */
202
202
  /**
203
203
  * @typedef {object} KnownStatsModuleIssuer
204
204
  * @property {string} identifier
@@ -207,7 +207,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
207
207
  * @property {StatsProfile} profile
208
208
  */
209
209
 
210
- /** @typedef {Record<string, any> & KnownStatsModuleReason} StatsModuleReason */
210
+ /** @typedef {Record<string, EXPECTED_ANY> & KnownStatsModuleReason} StatsModuleReason */
211
211
  /**
212
212
  * @typedef {object} KnownStatsModuleReason
213
213
  * @property {string | null} moduleIdentifier
@@ -224,7 +224,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
224
224
  * @property {(string | number | null)=} resolvedModuleId
225
225
  */
226
226
 
227
- /** @typedef {Record<string, any> & KnownStatsChunk} StatsChunk */
227
+ /** @typedef {Record<string, EXPECTED_ANY> & KnownStatsChunk} StatsChunk */
228
228
  /**
229
229
  * @typedef {object} KnownStatsChunk
230
230
  * @property {boolean} rendered
@@ -250,7 +250,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
250
250
  * @property {StatsChunkOrigin[]=} origins
251
251
  */
252
252
 
253
- /** @typedef {Record<string, any> & KnownStatsChunkOrigin} StatsChunkOrigin */
253
+ /** @typedef {Record<string, EXPECTED_ANY> & KnownStatsChunkOrigin} StatsChunkOrigin */
254
254
  /**
255
255
  * @typedef {object} KnownStatsChunkOrigin
256
256
  * @property {string} module
@@ -261,7 +261,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
261
261
  * @property {(string | number)=} moduleId
262
262
  */
263
263
 
264
- /** @typedef { Record<string, any> & KnownStatsModuleTraceItem} StatsModuleTraceItem */
264
+ /** @typedef { Record<string, EXPECTED_ANY> & KnownStatsModuleTraceItem} StatsModuleTraceItem */
265
265
  /**
266
266
  * @typedef {object} KnownStatsModuleTraceItem
267
267
  * @property {string=} originIdentifier
@@ -273,13 +273,13 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
273
273
  * @property {(string|number)=} moduleId
274
274
  */
275
275
 
276
- /** @typedef {Record<string, any> & KnownStatsModuleTraceDependency} StatsModuleTraceDependency */
276
+ /** @typedef {Record<string, EXPECTED_ANY> & KnownStatsModuleTraceDependency} StatsModuleTraceDependency */
277
277
  /**
278
278
  * @typedef {object} KnownStatsModuleTraceDependency
279
279
  * @property {string=} loc
280
280
  */
281
281
 
282
- /** @typedef {Record<string, any> & KnownStatsError} StatsError */
282
+ /** @typedef {Record<string, EXPECTED_ANY> & KnownStatsError} StatsError */
283
283
  /**
284
284
  * @typedef {object} KnownStatsError
285
285
  * @property {string} message
@@ -601,9 +601,10 @@ const SIMPLE_EXTRACTORS = {
601
601
  }
602
602
  let message;
603
603
  if (entry.type === LogType.time) {
604
- message = `${entry.args[0]}: ${
605
- entry.args[1] * 1000 + entry.args[2] / 1000000
606
- } ms`;
604
+ const [label, first, second] =
605
+ /** @type {[string, number, number]} */
606
+ (entry.args);
607
+ message = `${label}: ${first * 1000 + second / 1000000} ms`;
607
608
  } else if (entry.args && entry.args.length > 0) {
608
609
  message = util.format(entry.args[0], ...entry.args.slice(1));
609
610
  }
@@ -2369,8 +2370,9 @@ const sortOrderRegular = field => {
2369
2370
  };
2370
2371
 
2371
2372
  /**
2373
+ * @template T
2372
2374
  * @param {string} field field name
2373
- * @returns {function(object, object): 0 | 1 | -1} comparators
2375
+ * @returns {function(T, T): 0 | 1 | -1} comparators
2374
2376
  */
2375
2377
  const sortByField = field => {
2376
2378
  if (!field) {
@@ -41,17 +41,17 @@ const smartGrouping = require("../util/smartGrouping");
41
41
 
42
42
  /**
43
43
  * @typedef {object} StatsFactoryHooks
44
- * @property {HookMap<SyncBailHook<[ObjectForExtract, FactoryData, StatsFactoryContext], undefined>>} extract
45
- * @property {HookMap<SyncBailHook<[FactoryDataItem, StatsFactoryContext, number, number], boolean | undefined>>} filter
46
- * @property {HookMap<SyncBailHook<[Comparator[], StatsFactoryContext], undefined>>} sort
47
- * @property {HookMap<SyncBailHook<[FactoryDataItem, StatsFactoryContext, number, number], boolean | undefined>>} filterSorted
48
- * @property {HookMap<SyncBailHook<[GroupConfig[], StatsFactoryContext], undefined>>} groupResults
49
- * @property {HookMap<SyncBailHook<[Comparator[], StatsFactoryContext], undefined>>} sortResults
50
- * @property {HookMap<SyncBailHook<[FactoryDataItem, StatsFactoryContext, number, number], boolean | undefined>>} filterResults
51
- * @property {HookMap<SyncBailHook<[FactoryDataItem[], StatsFactoryContext], Result>>} merge
44
+ * @property {HookMap<SyncBailHook<[ObjectForExtract, FactoryData, StatsFactoryContext], void>>} extract
45
+ * @property {HookMap<SyncBailHook<[FactoryDataItem, StatsFactoryContext, number, number], boolean | void>>} filter
46
+ * @property {HookMap<SyncBailHook<[Comparator[], StatsFactoryContext], void>>} sort
47
+ * @property {HookMap<SyncBailHook<[FactoryDataItem, StatsFactoryContext, number, number], boolean | void>>} filterSorted
48
+ * @property {HookMap<SyncBailHook<[GroupConfig[], StatsFactoryContext], void>>} groupResults
49
+ * @property {HookMap<SyncBailHook<[Comparator[], StatsFactoryContext], void>>} sortResults
50
+ * @property {HookMap<SyncBailHook<[FactoryDataItem, StatsFactoryContext, number, number], boolean | void>>} filterResults
51
+ * @property {HookMap<SyncBailHook<[FactoryDataItem[], StatsFactoryContext], Result | void>>} merge
52
52
  * @property {HookMap<SyncBailHook<[Result, StatsFactoryContext], Result>>} result
53
- * @property {HookMap<SyncBailHook<[FactoryDataItem, StatsFactoryContext], string>>} getItemName
54
- * @property {HookMap<SyncBailHook<[FactoryDataItem, StatsFactoryContext], StatsFactory | undefined>>} getItemFactory
53
+ * @property {HookMap<SyncBailHook<[FactoryDataItem, StatsFactoryContext], string | void>>} getItemName
54
+ * @property {HookMap<SyncBailHook<[FactoryDataItem, StatsFactoryContext], StatsFactory | void>>} getItemFactory
55
55
  */
56
56
 
57
57
  /**
@@ -128,8 +128,8 @@ class StatsFactory {
128
128
  * @param {HM} hookMap hook map
129
129
  * @param {Caches<H>} cache cache
130
130
  * @param {string} type type
131
- * @param {function(H): R | undefined} fn fn
132
- * @returns {R | undefined} hook
131
+ * @param {function(H): R | void} fn fn
132
+ * @returns {R | void} hook
133
133
  * @private
134
134
  */
135
135
  _forEachLevel(hookMap, cache, type, fn) {
@@ -67,16 +67,16 @@ const { HookMap, SyncWaterfallHook, SyncBailHook } = require("tapable");
67
67
  * @property {(message: string) => string=} formatError
68
68
  */
69
69
 
70
- /** @typedef {Record<string, any> & KnownStatsPrinterColorFn & KnownStatsPrinterFormaters & KnownStatsPrinterContext} StatsPrinterContext */
70
+ /** @typedef {Record<string, EXPECTED_ANY> & KnownStatsPrinterColorFn & KnownStatsPrinterFormaters & KnownStatsPrinterContext} StatsPrinterContext */
71
71
  /** @typedef {any} PrintObject */
72
72
 
73
73
  /**
74
74
  * @typedef {object} StatsPrintHooks
75
75
  * @property {HookMap<SyncBailHook<[string[], StatsPrinterContext], void>>} sortElements
76
- * @property {HookMap<SyncBailHook<[PrintedElement[], StatsPrinterContext], string | undefined>>} printElements
77
- * @property {HookMap<SyncBailHook<[PrintObject[], StatsPrinterContext], true>>} sortItems
78
- * @property {HookMap<SyncBailHook<[PrintObject, StatsPrinterContext], string>>} getItemName
79
- * @property {HookMap<SyncBailHook<[string[], StatsPrinterContext], string | undefined>>} printItems
76
+ * @property {HookMap<SyncBailHook<[PrintedElement[], StatsPrinterContext], string | void>>} printElements
77
+ * @property {HookMap<SyncBailHook<[PrintObject[], StatsPrinterContext], boolean | void>>} sortItems
78
+ * @property {HookMap<SyncBailHook<[PrintObject, StatsPrinterContext], string | void>>} getItemName
79
+ * @property {HookMap<SyncBailHook<[string[], StatsPrinterContext], string | void>>} printItems
80
80
  * @property {HookMap<SyncBailHook<[PrintObject, StatsPrinterContext], string | void>>} print
81
81
  * @property {HookMap<SyncWaterfallHook<[string, StatsPrinterContext]>>} result
82
82
  */
@@ -147,8 +147,8 @@ class StatsPrinter {
147
147
  * @template {H extends import("tapable").Hook<any, infer R> ? R : never} R
148
148
  * @param {HM} hookMap hook map
149
149
  * @param {string} type type
150
- * @param {function(H): R | undefined} fn fn
151
- * @returns {R | undefined} hook
150
+ * @param {function(H): R | void} fn fn
151
+ * @returns {R | void} hook
152
152
  */
153
153
  _forEachLevel(hookMap, type, fn) {
154
154
  for (const hook of this._getAllLevelHooks(hookMap, type)) {
@@ -68,12 +68,14 @@ class AsyncQueue {
68
68
  * @param {object} options options object
69
69
  * @param {string=} options.name name of the queue
70
70
  * @param {number=} options.parallelism how many items should be processed at once
71
+ * @param {string=} options.context context of execution
71
72
  * @param {AsyncQueue<any, any, any>=} options.parent parent queue, which will have priority over this queue and with shared parallelism
72
73
  * @param {getKey<T, K>=} options.getKey extract key from item
73
74
  * @param {Processor<T, R>} options.processor async function to process items
74
75
  */
75
- constructor({ name, parallelism, parent, processor, getKey }) {
76
+ constructor({ name, context, parallelism, parent, processor, getKey }) {
76
77
  this._name = name;
78
+ this._context = context || "normal";
77
79
  this._parallelism = parallelism || 1;
78
80
  this._processor = processor;
79
81
  this._getKey =
@@ -115,6 +117,20 @@ class AsyncQueue {
115
117
  this._ensureProcessing = this._ensureProcessing.bind(this);
116
118
  }
117
119
 
120
+ /**
121
+ * @returns {string} context of execution
122
+ */
123
+ getContext() {
124
+ return this._context;
125
+ }
126
+
127
+ /**
128
+ * @param {string} value context of execution
129
+ */
130
+ setContext(value) {
131
+ this._context = value;
132
+ }
133
+
118
134
  /**
119
135
  * @param {T} item an item
120
136
  * @param {Callback<R>} callback callback function
@@ -19,7 +19,7 @@ const last = set => {
19
19
  /**
20
20
  * @template T
21
21
  * @param {Iterable<T>} iterable iterable
22
- * @param {function(T): boolean} filter predicate
22
+ * @param {function(T): boolean | null | undefined} filter predicate
23
23
  * @returns {boolean} true, if some items match the filter predicate
24
24
  */
25
25
  const someInIterable = (iterable, filter) => {