webpack 5.85.1 → 5.87.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.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (140) hide show
  1. package/README.md +5 -2
  2. package/lib/APIPlugin.js +150 -99
  3. package/lib/CaseSensitiveModulesWarning.js +3 -1
  4. package/lib/Chunk.js +35 -17
  5. package/lib/ChunkGroup.js +11 -6
  6. package/lib/Compiler.js +4 -3
  7. package/lib/ConcatenationScope.js +2 -2
  8. package/lib/ConditionalInitFragment.js +11 -1
  9. package/lib/ConstPlugin.js +57 -29
  10. package/lib/ContextModule.js +4 -2
  11. package/lib/ContextModuleFactory.js +1 -0
  12. package/lib/DependenciesBlock.js +1 -1
  13. package/lib/DllModule.js +6 -0
  14. package/lib/EvalSourceMapDevToolPlugin.js +2 -1
  15. package/lib/ExternalModule.js +15 -8
  16. package/lib/FlagEntryExportAsUsedPlugin.js +4 -0
  17. package/lib/Module.js +7 -1
  18. package/lib/ModuleDependencyError.js +4 -2
  19. package/lib/ModuleDependencyWarning.js +4 -2
  20. package/lib/ModuleGraph.js +31 -24
  21. package/lib/ModuleGraphConnection.js +19 -6
  22. package/lib/ModuleInfoHeaderPlugin.js +9 -2
  23. package/lib/ModuleNotFoundError.js +5 -2
  24. package/lib/ModuleStoreError.js +2 -1
  25. package/lib/ModuleTypeConstants.js +7 -0
  26. package/lib/MultiWatching.js +4 -0
  27. package/lib/ProgressPlugin.js +71 -15
  28. package/lib/RuntimeGlobals.js +5 -0
  29. package/lib/RuntimePlugin.js +2 -1
  30. package/lib/RuntimeTemplate.js +20 -2
  31. package/lib/WebpackError.js +6 -5
  32. package/lib/WebpackOptionsApply.js +4 -2
  33. package/lib/WebpackOptionsDefaulter.js +10 -3
  34. package/lib/config/defaults.js +31 -2
  35. package/lib/css/CssExportsGenerator.js +9 -0
  36. package/lib/css/CssGenerator.js +1 -1
  37. package/lib/css/CssLoadingRuntimeModule.js +13 -6
  38. package/lib/css/CssModulesPlugin.js +42 -14
  39. package/lib/css/CssParser.js +12 -0
  40. package/lib/dependencies/ConstDependency.js +2 -2
  41. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +19 -0
  42. package/lib/dependencies/ImportParserPlugin.js +25 -1
  43. package/lib/dependencies/JsonExportsDependency.js +1 -1
  44. package/lib/ids/SyncModuleIdsPlugin.js +1 -0
  45. package/lib/javascript/BasicEvaluatedExpression.js +23 -15
  46. package/lib/javascript/CommonJsChunkFormatPlugin.js +6 -2
  47. package/lib/javascript/JavascriptModulesPlugin.js +1 -0
  48. package/lib/javascript/JavascriptParser.js +118 -58
  49. package/lib/javascript/JavascriptParserHelpers.js +37 -15
  50. package/lib/json/JsonData.js +2 -2
  51. package/lib/json/JsonParser.js +25 -12
  52. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -1
  53. package/lib/optimize/AggressiveMergingPlugin.js +8 -0
  54. package/lib/optimize/AggressiveSplittingPlugin.js +9 -2
  55. package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -0
  56. package/lib/optimize/FlagIncludedChunksPlugin.js +11 -5
  57. package/lib/optimize/InnerGraph.js +4 -4
  58. package/lib/optimize/LimitChunkCountPlugin.js +29 -4
  59. package/lib/optimize/MangleExportsPlugin.js +1 -1
  60. package/lib/optimize/MinMaxSizeWarning.js +5 -0
  61. package/lib/optimize/ModuleConcatenationPlugin.js +59 -2
  62. package/lib/optimize/RealContentHashPlugin.js +80 -30
  63. package/lib/optimize/RemoveParentModulesPlugin.js +6 -0
  64. package/lib/optimize/RuntimeChunkPlugin.js +9 -1
  65. package/lib/optimize/SideEffectsFlagPlugin.js +10 -1
  66. package/lib/optimize/SplitChunksPlugin.js +71 -31
  67. package/lib/performance/SizeLimitsPlugin.js +7 -4
  68. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +3 -1
  69. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
  70. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +5 -2
  71. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +3 -1
  72. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +3 -1
  73. package/lib/rules/BasicEffectRulePlugin.js +4 -0
  74. package/lib/rules/BasicMatcherRulePlugin.js +5 -0
  75. package/lib/rules/RuleSetCompiler.js +3 -3
  76. package/lib/rules/UseEffectRulePlugin.js +6 -4
  77. package/lib/runtime/AsyncModuleRuntimeModule.js +4 -1
  78. package/lib/runtime/AutoPublicPathRuntimeModule.js +3 -1
  79. package/lib/runtime/BaseUriRuntimeModule.js +2 -2
  80. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +4 -1
  81. package/lib/runtime/CompatRuntimeModule.js +6 -1
  82. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +4 -1
  83. package/lib/runtime/CreateScriptRuntimeModule.js +3 -1
  84. package/lib/runtime/CreateScriptUrlRuntimeModule.js +3 -1
  85. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +4 -1
  86. package/lib/runtime/EnsureChunkRuntimeModule.js +14 -3
  87. package/lib/runtime/GetChunkFilenameRuntimeModule.js +5 -9
  88. package/lib/runtime/GetFullHashRuntimeModule.js +3 -2
  89. package/lib/runtime/GetMainFilenameRuntimeModule.js +4 -1
  90. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +3 -1
  91. package/lib/runtime/HasOwnPropertyRuntimeModule.js +4 -1
  92. package/lib/runtime/LoadScriptRuntimeModule.js +63 -47
  93. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +4 -1
  94. package/lib/runtime/OnChunksLoadedRuntimeModule.js +3 -1
  95. package/lib/runtime/PublicPathRuntimeModule.js +3 -1
  96. package/lib/runtime/RelativeUrlRuntimeModule.js +4 -1
  97. package/lib/runtime/RuntimeIdRuntimeModule.js +5 -1
  98. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +8 -2
  99. package/lib/runtime/StartupEntrypointRuntimeModule.js +2 -1
  100. package/lib/serialization/BinaryMiddleware.js +143 -1
  101. package/lib/serialization/ErrorObjectSerializer.js +3 -0
  102. package/lib/serialization/ObjectMiddleware.js +9 -3
  103. package/lib/serialization/types.js +1 -1
  104. package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
  105. package/lib/sharing/ConsumeSharedRuntimeModule.js +13 -4
  106. package/lib/sharing/ProvideSharedDependency.js +11 -0
  107. package/lib/sharing/ProvideSharedModule.js +4 -0
  108. package/lib/sharing/ProvideSharedPlugin.js +22 -21
  109. package/lib/sharing/ShareRuntimeModule.js +11 -4
  110. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  111. package/lib/sharing/utils.js +32 -5
  112. package/lib/util/AsyncQueue.js +4 -2
  113. package/lib/util/ParallelismFactorCalculator.js +10 -0
  114. package/lib/util/Semaphore.js +1 -1
  115. package/lib/util/createHash.js +30 -9
  116. package/lib/util/deprecation.js +10 -3
  117. package/lib/util/deterministicGrouping.js +50 -11
  118. package/lib/util/findGraphRoots.js +4 -2
  119. package/lib/util/memoize.js +3 -3
  120. package/lib/util/processAsyncTree.js +7 -1
  121. package/lib/util/registerExternalSerializer.js +1 -1
  122. package/lib/util/runtime.js +14 -1
  123. package/lib/util/smartGrouping.js +1 -1
  124. package/lib/validateSchema.js +6 -2
  125. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +5 -1
  126. package/lib/wasm-async/AsyncWebAssemblyParser.js +7 -3
  127. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +13 -6
  128. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +3 -1
  129. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
  130. package/lib/wasm-sync/WebAssemblyParser.js +6 -2
  131. package/lib/web/JsonpChunkLoadingRuntimeModule.js +13 -3
  132. package/lib/webpack.js +11 -2
  133. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +14 -15
  134. package/module.d.ts +1 -0
  135. package/package.json +4 -4
  136. package/schemas/WebpackOptions.check.js +1 -1
  137. package/schemas/WebpackOptions.json +51 -5
  138. package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
  139. package/schemas/plugins/css/CssParserOptions.json +1 -1
  140. package/types.d.ts +476 -218
@@ -9,6 +9,10 @@ const RuntimeGlobals = require("../RuntimeGlobals");
9
9
  const RuntimeModule = require("../RuntimeModule");
10
10
  const Template = require("../Template");
11
11
 
12
+ /** @typedef {import("../Chunk")} Chunk */
13
+ /** @typedef {import("../ChunkGraph")} ChunkGraph */
14
+ /** @typedef {import("../Compilation")} Compilation */
15
+
12
16
  class StartupChunkDependenciesRuntimeModule extends RuntimeModule {
13
17
  /**
14
18
  * @param {boolean} asyncChunkLoading use async chunk loading
@@ -22,13 +26,15 @@ class StartupChunkDependenciesRuntimeModule extends RuntimeModule {
22
26
  * @returns {string} runtime code
23
27
  */
24
28
  generate() {
25
- const { chunkGraph, chunk, compilation } = this;
26
- const { runtimeTemplate } = compilation;
29
+ const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
30
+ const chunk = /** @type {Chunk} */ (this.chunk);
27
31
  const chunkIds = Array.from(
28
32
  chunkGraph.getChunkEntryDependentChunksIterable(chunk)
29
33
  ).map(chunk => {
30
34
  return chunk.id;
31
35
  });
36
+ const compilation = /** @type {Compilation} */ (this.compilation);
37
+ const { runtimeTemplate } = compilation;
32
38
  return Template.asString([
33
39
  `var next = ${RuntimeGlobals.startup};`,
34
40
  `${RuntimeGlobals.startup} = ${runtimeTemplate.basicFunction(
@@ -7,6 +7,7 @@
7
7
  const RuntimeGlobals = require("../RuntimeGlobals");
8
8
  const RuntimeModule = require("../RuntimeModule");
9
9
 
10
+ /** @typedef {import("../Compilation")} Compilation */
10
11
  /** @typedef {import("../MainTemplate")} MainTemplate */
11
12
 
12
13
  class StartupEntrypointRuntimeModule extends RuntimeModule {
@@ -22,7 +23,7 @@ class StartupEntrypointRuntimeModule extends RuntimeModule {
22
23
  * @returns {string} runtime code
23
24
  */
24
25
  generate() {
25
- const { compilation } = this;
26
+ const compilation = /** @type {Compilation} */ (this.compilation);
26
27
  const { runtimeTemplate } = compilation;
27
28
  return `${
28
29
  RuntimeGlobals.startupEntrypoint
@@ -21,6 +21,9 @@ Section -> NullsSection |
21
21
  I32NumbersSection |
22
22
  I8NumbersSection |
23
23
  ShortStringSection |
24
+ BigIntSection |
25
+ I32BigIntSection |
26
+ I8BigIntSection
24
27
  StringSection |
25
28
  BufferSection |
26
29
  NopSection
@@ -39,6 +42,9 @@ ShortStringSection -> ShortStringSectionHeaderByte ascii-byte*
39
42
  StringSection -> StringSectionHeaderByte i32:length utf8-byte*
40
43
  BufferSection -> BufferSectionHeaderByte i32:length byte*
41
44
  NopSection --> NopSectionHeaderByte
45
+ BigIntSection -> BigIntSectionHeaderByte i32:length ascii-byte*
46
+ I32BigIntSection -> I32BigIntSectionHeaderByte i32
47
+ I8BigIntSection -> I8BigIntSectionHeaderByte i8
42
48
 
43
49
  ShortStringSectionHeaderByte -> 0b1nnn_nnnn (n:length)
44
50
 
@@ -58,6 +64,9 @@ BooleansCountAndBitsByte ->
58
64
  StringSectionHeaderByte -> 0b0000_1110
59
65
  BufferSectionHeaderByte -> 0b0000_1111
60
66
  NopSectionHeaderByte -> 0b0000_1011
67
+ BigIntSectionHeaderByte -> 0b0001_1010
68
+ I32BigIntSectionHeaderByte -> 0b0001_1100
69
+ I8BigIntSectionHeaderByte -> 0b0001_1011
61
70
  FalseHeaderByte -> 0b0000_1100
62
71
  TrueHeaderByte -> 0b0000_1101
63
72
 
@@ -78,6 +87,9 @@ const NULL_AND_I8_HEADER = 0x15;
78
87
  const NULL_AND_I32_HEADER = 0x16;
79
88
  const NULL_AND_TRUE_HEADER = 0x17;
80
89
  const NULL_AND_FALSE_HEADER = 0x18;
90
+ const BIGINT_HEADER = 0x1a;
91
+ const BIGINT_I8_HEADER = 0x1b;
92
+ const BIGINT_I32_HEADER = 0x1c;
81
93
  const STRING_HEADER = 0x1e;
82
94
  const BUFFER_HEADER = 0x1f;
83
95
  const I8_HEADER = 0x60;
@@ -86,7 +98,7 @@ const F64_HEADER = 0x20;
86
98
  const SHORT_STRING_HEADER = 0x80;
87
99
 
88
100
  /** Uplift high-order bits */
89
- const NUMBERS_HEADER_MASK = 0xe0;
101
+ const NUMBERS_HEADER_MASK = 0xe0; // 0b1010_0000
90
102
  const NUMBERS_COUNT_MASK = 0x1f; // 0b0001_1111
91
103
  const SHORT_STRING_LENGTH_MASK = 0x7f; // 0b0111_1111
92
104
 
@@ -113,6 +125,16 @@ const identifyNumber = n => {
113
125
  return 2;
114
126
  };
115
127
 
128
+ /**
129
+ * @param {bigint} n bigint
130
+ * @returns {0 | 1 | 2} type of bigint for serialization
131
+ */
132
+ const identifyBigInt = n => {
133
+ if (n <= BigInt(127) && n >= BigInt(-128)) return 0;
134
+ if (n <= BigInt(2147483647) && n >= BigInt(-2147483648)) return 1;
135
+ return 2;
136
+ };
137
+
116
138
  /**
117
139
  * @typedef {PrimitiveSerializableType[]} DeserializedType
118
140
  * @typedef {BufferSerializableType[]} SerializedType
@@ -331,6 +353,62 @@ class BinaryMiddleware extends SerializerMiddleware {
331
353
  }
332
354
  break;
333
355
  }
356
+ case "bigint": {
357
+ const type = identifyBigInt(thing);
358
+ if (type === 0 && thing >= 0 && thing <= BigInt(10)) {
359
+ // shortcut for very small bigints
360
+ allocate(HEADER_SIZE + I8_SIZE);
361
+ writeU8(BIGINT_I8_HEADER);
362
+ writeU8(Number(thing));
363
+ break;
364
+ }
365
+
366
+ switch (type) {
367
+ case 0: {
368
+ let n = 1;
369
+ allocate(HEADER_SIZE + I8_SIZE * n);
370
+ writeU8(BIGINT_I8_HEADER | (n - 1));
371
+ while (n > 0) {
372
+ currentBuffer.writeInt8(
373
+ Number(/** @type {bigint} */ (data[i])),
374
+ currentPosition
375
+ );
376
+ currentPosition += I8_SIZE;
377
+ n--;
378
+ i++;
379
+ }
380
+ i--;
381
+ break;
382
+ }
383
+ case 1: {
384
+ let n = 1;
385
+ allocate(HEADER_SIZE + I32_SIZE * n);
386
+ writeU8(BIGINT_I32_HEADER | (n - 1));
387
+ while (n > 0) {
388
+ currentBuffer.writeInt32LE(
389
+ Number(/** @type {bigint} */ (data[i])),
390
+ currentPosition
391
+ );
392
+ currentPosition += I32_SIZE;
393
+ n--;
394
+ i++;
395
+ }
396
+ i--;
397
+ break;
398
+ }
399
+ default: {
400
+ const value = thing.toString();
401
+ const len = Buffer.byteLength(value);
402
+ allocate(len + HEADER_SIZE + I32_SIZE);
403
+ writeU8(BIGINT_HEADER);
404
+ writeU32(len);
405
+ currentBuffer.write(value, currentPosition);
406
+ currentPosition += len;
407
+ break;
408
+ }
409
+ }
410
+ break;
411
+ }
334
412
  case "number": {
335
413
  const type = identifyNumber(thing);
336
414
  if (type === 0 && thing >= 0 && thing <= 10) {
@@ -847,6 +925,70 @@ class BinaryMiddleware extends SerializerMiddleware {
847
925
  result.push(read(1).readInt8(0));
848
926
  }
849
927
  };
928
+ case BIGINT_I8_HEADER: {
929
+ const len = 1;
930
+ return () => {
931
+ const need = I8_SIZE * len;
932
+
933
+ if (isInCurrentBuffer(need)) {
934
+ for (let i = 0; i < len; i++) {
935
+ const value =
936
+ /** @type {Buffer} */
937
+ (currentBuffer).readInt8(currentPosition);
938
+ result.push(BigInt(value));
939
+ currentPosition += I8_SIZE;
940
+ }
941
+ checkOverflow();
942
+ } else {
943
+ const buf = read(need);
944
+ for (let i = 0; i < len; i++) {
945
+ const value = buf.readInt8(i * I8_SIZE);
946
+ result.push(BigInt(value));
947
+ }
948
+ }
949
+ };
950
+ }
951
+ case BIGINT_I32_HEADER: {
952
+ const len = 1;
953
+ return () => {
954
+ const need = I32_SIZE * len;
955
+ if (isInCurrentBuffer(need)) {
956
+ for (let i = 0; i < len; i++) {
957
+ const value = /** @type {Buffer} */ (currentBuffer).readInt32LE(
958
+ currentPosition
959
+ );
960
+ result.push(BigInt(value));
961
+ currentPosition += I32_SIZE;
962
+ }
963
+ checkOverflow();
964
+ } else {
965
+ const buf = read(need);
966
+ for (let i = 0; i < len; i++) {
967
+ const value = buf.readInt32LE(i * I32_SIZE);
968
+ result.push(BigInt(value));
969
+ }
970
+ }
971
+ };
972
+ }
973
+ case BIGINT_HEADER: {
974
+ return () => {
975
+ const len = readU32();
976
+ if (isInCurrentBuffer(len) && currentPosition + len < 0x7fffffff) {
977
+ const value = currentBuffer.toString(
978
+ undefined,
979
+ currentPosition,
980
+ currentPosition + len
981
+ );
982
+
983
+ result.push(BigInt(value));
984
+ currentPosition += len;
985
+ checkOverflow();
986
+ } else {
987
+ const value = read(len).toString();
988
+ result.push(BigInt(value));
989
+ }
990
+ };
991
+ }
850
992
  default:
851
993
  if (header <= 10) {
852
994
  return () => result.push(header);
@@ -21,6 +21,7 @@ class ErrorObjectSerializer {
21
21
  serialize(obj, context) {
22
22
  context.write(obj.message);
23
23
  context.write(obj.stack);
24
+ context.write(/** @type {Error & { cause: "unknown" }} */ (obj).cause);
24
25
  }
25
26
  /**
26
27
  * @param {ObjectDeserializerContext} context context
@@ -31,6 +32,8 @@ class ErrorObjectSerializer {
31
32
 
32
33
  err.message = context.read();
33
34
  err.stack = context.read();
35
+ /** @type {Error & { cause: "unknown" }} */
36
+ (err).cause = context.read();
34
37
 
35
38
  return err;
36
39
  }
@@ -107,7 +107,7 @@ const ESCAPE_UNDEFINED = false;
107
107
 
108
108
  const CURRENT_VERSION = 2;
109
109
 
110
- /** @type {Map<Constructor, { request?: string, name?: string | number , serializer?: ObjectSerializer }>} */
110
+ /** @type {Map<Constructor, { request?: string, name?: string | number | null, serializer?: ObjectSerializer }>} */
111
111
  const serializers = new Map();
112
112
  /** @type {Map<string | number, ObjectSerializer>} */
113
113
  const serializerInversed = new Map();
@@ -158,7 +158,10 @@ if (exports.constructor !== Object) {
158
158
  }
159
159
 
160
160
  for (const { request, name, serializer } of serializers.values()) {
161
- serializerInversed.set(`${request}/${name}`, serializer);
161
+ serializerInversed.set(
162
+ `${request}/${name}`,
163
+ /** @type {ObjectSerializer} */ (serializer)
164
+ );
162
165
  }
163
166
 
164
167
  /** @type {Map<RegExp, (request: string) => boolean>} */
@@ -191,7 +194,7 @@ class ObjectMiddleware extends SerializerMiddleware {
191
194
  /**
192
195
  * @param {Constructor} Constructor the constructor
193
196
  * @param {string} request the request which will be required when deserializing
194
- * @param {string} name the name to make multiple serializer unique when sharing a request
197
+ * @param {string | null} name the name to make multiple serializer unique when sharing a request
195
198
  * @param {ObjectSerializer} serializer the serializer
196
199
  * @returns {void}
197
200
  */
@@ -397,6 +400,9 @@ class ObjectMiddleware extends SerializerMiddleware {
397
400
  ", "
398
401
  )} }`;
399
402
  }
403
+ if (typeof item === "bigint") {
404
+ return `BigInt ${item}n`;
405
+ }
400
406
  try {
401
407
  return `${item}`;
402
408
  } catch (e) {
@@ -6,7 +6,7 @@
6
6
 
7
7
  /** @typedef {undefined|null|number|string|boolean|Buffer|Object|(() => ComplexSerializableType[] | Promise<ComplexSerializableType[]>)} ComplexSerializableType */
8
8
 
9
- /** @typedef {undefined|null|number|string|boolean|Buffer|(() => PrimitiveSerializableType[] | Promise<PrimitiveSerializableType[]>)} PrimitiveSerializableType */
9
+ /** @typedef {undefined|null|number|bigint|string|boolean|Buffer|(() => PrimitiveSerializableType[] | Promise<PrimitiveSerializableType[]>)} PrimitiveSerializableType */
10
10
 
11
11
  /** @typedef {Buffer|(() => BufferSerializableType[] | Promise<BufferSerializableType[]>)} BufferSerializableType */
12
12
 
@@ -9,6 +9,9 @@ const ModuleDependency = require("../dependencies/ModuleDependency");
9
9
  const makeSerializable = require("../util/makeSerializable");
10
10
 
11
11
  class ConsumeSharedFallbackDependency extends ModuleDependency {
12
+ /**
13
+ * @param {string} request the request
14
+ */
12
15
  constructor(request) {
13
16
  super(request);
14
17
  }
@@ -17,10 +17,15 @@ const {
17
17
 
18
18
  /** @typedef {import("webpack-sources").Source} Source */
19
19
  /** @typedef {import("../Chunk")} Chunk */
20
+ /** @typedef {import("../ChunkGraph")} ChunkGraph */
21
+ /** @typedef {import("../Compilation")} Compilation */
20
22
  /** @typedef {import("../Module")} Module */
21
23
  /** @typedef {import("./ConsumeSharedModule")} ConsumeSharedModule */
22
24
 
23
25
  class ConsumeSharedRuntimeModule extends RuntimeModule {
26
+ /**
27
+ * @param {ReadonlySet<string>} runtimeRequirements runtime requirements
28
+ */
24
29
  constructor(runtimeRequirements) {
25
30
  super("consumes", RuntimeModule.STAGE_ATTACH);
26
31
  this._runtimeRequirements = runtimeRequirements;
@@ -30,11 +35,13 @@ class ConsumeSharedRuntimeModule extends RuntimeModule {
30
35
  * @returns {string} runtime code
31
36
  */
32
37
  generate() {
33
- const { compilation, chunkGraph } = this;
38
+ const compilation = /** @type {Compilation} */ (this.compilation);
39
+ const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
34
40
  const { runtimeTemplate, codeGenerationResults } = compilation;
35
41
  const chunkToModuleMapping = {};
36
42
  /** @type {Map<string | number, Source>} */
37
43
  const moduleIdToSourceMapping = new Map();
44
+ /** @type {(string | number)[]} */
38
45
  const initialConsumes = [];
39
46
  /**
40
47
  *
@@ -57,7 +64,7 @@ class ConsumeSharedRuntimeModule extends RuntimeModule {
57
64
  );
58
65
  }
59
66
  };
60
- for (const chunk of this.chunk.getAllAsyncChunks()) {
67
+ for (const chunk of /** @type {Chunk} */ (this.chunk).getAllAsyncChunks()) {
61
68
  const modules = chunkGraph.getChunkModulesIterableBySourceType(
62
69
  chunk,
63
70
  "consume-shared"
@@ -65,7 +72,9 @@ class ConsumeSharedRuntimeModule extends RuntimeModule {
65
72
  if (!modules) continue;
66
73
  addModules(modules, chunk, (chunkToModuleMapping[chunk.id] = []));
67
74
  }
68
- for (const chunk of this.chunk.getAllInitialChunks()) {
75
+ for (const chunk of /** @type {Chunk} */ (
76
+ this.chunk
77
+ ).getAllInitialChunks()) {
69
78
  const modules = chunkGraph.getChunkModulesIterableBySourceType(
70
79
  chunk,
71
80
  "consume-shared"
@@ -166,7 +175,7 @@ class ConsumeSharedRuntimeModule extends RuntimeModule {
166
175
  ]
167
176
  )};`,
168
177
  `var warn = ${
169
- this.compilation.options.output.ignoreBrowserWarnings
178
+ compilation.outputOptions.ignoreBrowserWarnings
170
179
  ? runtimeTemplate.basicFunction("", "")
171
180
  : runtimeTemplate.basicFunction("msg", [
172
181
  'if (typeof console !== "undefined" && console.warn) console.warn(msg);'
@@ -12,6 +12,13 @@ const makeSerializable = require("../util/makeSerializable");
12
12
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
13
13
 
14
14
  class ProvideSharedDependency extends Dependency {
15
+ /**
16
+ * @param {string} shareScope share scope
17
+ * @param {string} name module name
18
+ * @param {string | false} version version
19
+ * @param {string} request request
20
+ * @param {boolean} eager true, if this is an eager dependency
21
+ */
15
22
  constructor(shareScope, name, version, request, eager) {
16
23
  super();
17
24
  this.shareScope = shareScope;
@@ -46,6 +53,10 @@ class ProvideSharedDependency extends Dependency {
46
53
  super.serialize(context);
47
54
  }
48
55
 
56
+ /**
57
+ * @param {ObjectDeserializerContext} context context
58
+ * @returns {ProvideSharedDependency} deserialize fallback dependency
59
+ */
49
60
  static deserialize(context) {
50
61
  const { read } = context;
51
62
  const obj = new ProvideSharedDependency(
@@ -174,6 +174,10 @@ class ProvideSharedModule extends Module {
174
174
  super.serialize(context);
175
175
  }
176
176
 
177
+ /**
178
+ * @param {ObjectDeserializerContext} context context
179
+ * @returns {ProvideSharedModule} deserialize fallback dependency
180
+ */
177
181
  static deserialize(context) {
178
182
  const { read } = context;
179
183
  const obj = new ProvideSharedModule(read(), read(), read(), read(), read());
@@ -42,27 +42,28 @@ class ProvideSharedPlugin {
42
42
  constructor(options) {
43
43
  validate(options);
44
44
 
45
- /** @type {[string, ProvideOptions][]} */
46
- this._provides = parseOptions(
47
- options.provides,
48
- item => {
49
- if (Array.isArray(item))
50
- throw new Error("Unexpected array of provides");
51
- /** @type {ProvideOptions} */
52
- const result = {
53
- shareKey: item,
54
- version: undefined,
55
- shareScope: options.shareScope || "default",
56
- eager: false
57
- };
58
- return result;
59
- },
60
- item => ({
61
- shareKey: item.shareKey,
62
- version: item.version,
63
- shareScope: item.shareScope || options.shareScope || "default",
64
- eager: !!item.eager
65
- })
45
+ this._provides = /** @type {[string, ProvideOptions][]} */ (
46
+ parseOptions(
47
+ options.provides,
48
+ item => {
49
+ if (Array.isArray(item))
50
+ throw new Error("Unexpected array of provides");
51
+ /** @type {ProvideOptions} */
52
+ const result = {
53
+ shareKey: item,
54
+ version: undefined,
55
+ shareScope: options.shareScope || "default",
56
+ eager: false
57
+ };
58
+ return result;
59
+ },
60
+ item => ({
61
+ shareKey: item.shareKey,
62
+ version: item.version,
63
+ shareScope: item.shareScope || options.shareScope || "default",
64
+ eager: !!item.eager
65
+ })
66
+ )
66
67
  );
67
68
  this._provides.sort(([a], [b]) => {
68
69
  if (a < b) return -1;
@@ -13,6 +13,10 @@ const {
13
13
  compareStrings
14
14
  } = require("../util/comparators");
15
15
 
16
+ /** @typedef {import("../Chunk")} Chunk */
17
+ /** @typedef {import("../ChunkGraph")} ChunkGraph */
18
+ /** @typedef {import("../Compilation")} Compilation */
19
+
16
20
  class ShareRuntimeModule extends RuntimeModule {
17
21
  constructor() {
18
22
  super("sharing");
@@ -22,15 +26,18 @@ class ShareRuntimeModule extends RuntimeModule {
22
26
  * @returns {string} runtime code
23
27
  */
24
28
  generate() {
25
- const { compilation, chunkGraph } = this;
29
+ const compilation = /** @type {Compilation} */ (this.compilation);
26
30
  const {
27
31
  runtimeTemplate,
28
32
  codeGenerationResults,
29
- outputOptions: { uniqueName }
33
+ outputOptions: { uniqueName, ignoreBrowserWarnings }
30
34
  } = compilation;
35
+ const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
31
36
  /** @type {Map<string, Map<number, Set<string>>>} */
32
37
  const initCodePerScope = new Map();
33
- for (const chunk of this.chunk.getAllReferencedChunks()) {
38
+ for (const chunk of /** @type {Chunk} */ (
39
+ this.chunk
40
+ ).getAllReferencedChunks()) {
34
41
  const modules = chunkGraph.getOrderedChunkModulesIterableBySourceType(
35
42
  chunk,
36
43
  "share-init",
@@ -78,7 +85,7 @@ class ShareRuntimeModule extends RuntimeModule {
78
85
  "// runs all init snippets from all modules reachable",
79
86
  `var scope = ${RuntimeGlobals.shareScopeMap}[name];`,
80
87
  `var warn = ${
81
- this.compilation.options.output.ignoreBrowserWarnings
88
+ ignoreBrowserWarnings
82
89
  ? runtimeTemplate.basicFunction("", "")
83
90
  : runtimeTemplate.basicFunction("msg", [
84
91
  'if (typeof console !== "undefined" && console.warn) console.warn(msg);'
@@ -66,7 +66,7 @@ exports.resolveMatchedConfigs = (compilation, configs) => {
66
66
  );
67
67
  return resolve();
68
68
  }
69
- resolved.set(result, config);
69
+ resolved.set(/** @type {string} */ (result), config);
70
70
  resolve();
71
71
  }
72
72
  );
@@ -52,6 +52,11 @@ const DEF_GIT_PROTOCOL = "git+ssh://";
52
52
 
53
53
  // thanks to https://github.com/npm/hosted-git-info/blob/latest/git-host-info.js
54
54
  const extractCommithashByDomain = {
55
+ /**
56
+ * @param {string} pathname pathname
57
+ * @param {string} hash hash
58
+ * @returns {string | undefined} hash
59
+ */
55
60
  "github.com": (pathname, hash) => {
56
61
  let [, user, project, type, commithash] = pathname.split("/", 5);
57
62
  if (type && type !== "tree") {
@@ -74,6 +79,11 @@ const extractCommithashByDomain = {
74
79
 
75
80
  return commithash;
76
81
  },
82
+ /**
83
+ * @param {string} pathname pathname
84
+ * @param {string} hash hash
85
+ * @returns {string | undefined} hash
86
+ */
77
87
  "gitlab.com": (pathname, hash) => {
78
88
  const path = pathname.slice(1);
79
89
  if (path.includes("/-/") || path.includes("/archive.tar.gz")) {
@@ -81,7 +91,7 @@ const extractCommithashByDomain = {
81
91
  }
82
92
 
83
93
  const segments = path.split("/");
84
- let project = segments.pop();
94
+ let project = /** @type {string} */ (segments.pop());
85
95
  if (project.endsWith(".git")) {
86
96
  project = project.slice(0, -4);
87
97
  }
@@ -93,6 +103,11 @@ const extractCommithashByDomain = {
93
103
 
94
104
  return hash;
95
105
  },
106
+ /**
107
+ * @param {string} pathname pathname
108
+ * @param {string} hash hash
109
+ * @returns {string | undefined} hash
110
+ */
96
111
  "bitbucket.org": (pathname, hash) => {
97
112
  let [, user, project, aux] = pathname.split("/", 4);
98
113
  if (["get"].includes(aux)) {
@@ -109,6 +124,11 @@ const extractCommithashByDomain = {
109
124
 
110
125
  return hash;
111
126
  },
127
+ /**
128
+ * @param {string} pathname pathname
129
+ * @param {string} hash hash
130
+ * @returns {string | undefined} hash
131
+ */
112
132
  "gist.github.com": (pathname, hash) => {
113
133
  let [, user, project, aux] = pathname.split("/", 4);
114
134
  if (aux === "raw") {
@@ -121,7 +141,6 @@ const extractCommithashByDomain = {
121
141
  }
122
142
 
123
143
  project = user;
124
- user = null;
125
144
  }
126
145
 
127
146
  if (project.endsWith(".git")) {
@@ -136,7 +155,7 @@ const extractCommithashByDomain = {
136
155
  * extract commit hash from parsed url
137
156
  *
138
157
  * @inner
139
- * @param {Object} urlParsed parsed url
158
+ * @param {URL} urlParsed parsed url
140
159
  * @returns {string} commithash
141
160
  */
142
161
  function getCommithash(urlParsed) {
@@ -148,8 +167,16 @@ function getCommithash(urlParsed) {
148
167
  // eslint-disable-next-line no-empty
149
168
  } catch (e) {}
150
169
 
151
- if (extractCommithashByDomain[hostname]) {
152
- return extractCommithashByDomain[hostname](pathname, hash) || "";
170
+ if (
171
+ extractCommithashByDomain[
172
+ /** @type {keyof extractCommithashByDomain} */ (hostname)
173
+ ]
174
+ ) {
175
+ return (
176
+ extractCommithashByDomain[
177
+ /** @type {keyof extractCommithashByDomain} */ (hostname)
178
+ ](pathname, hash) || ""
179
+ );
153
180
  }
154
181
 
155
182
  return hash;
@@ -70,7 +70,7 @@ class AsyncQueue {
70
70
  this._entries = new Map();
71
71
  /** @type {ArrayQueue<AsyncQueueEntry<T, K, R>>} */
72
72
  this._queued = new ArrayQueue();
73
- /** @type {AsyncQueue<any, any, any>[]} */
73
+ /** @type {AsyncQueue<any, any, any>[] | undefined} */
74
74
  this._children = undefined;
75
75
  this._activeTasks = 0;
76
76
  this._willEnsureProcessing = false;
@@ -159,7 +159,9 @@ class AsyncQueue {
159
159
  */
160
160
  invalidate(item) {
161
161
  const key = this._getKey(item);
162
- const entry = this._entries.get(key);
162
+ const entry =
163
+ /** @type {AsyncQueueEntry<T, K, R>} */
164
+ (this._entries.get(key));
163
165
  this._entries.delete(key);
164
166
  if (entry.state === QUEUED_STATE) {
165
167
  this._queued.delete(entry);
@@ -7,12 +7,22 @@
7
7
 
8
8
  const binarySearchBounds = require("../util/binarySearchBounds");
9
9
 
10
+ /** @typedef {function(number): void} Callback */
11
+
10
12
  class ParallelismFactorCalculator {
11
13
  constructor() {
14
+ /** @type {number[]} */
12
15
  this._rangePoints = [];
16
+ /** @type {Callback[]} */
13
17
  this._rangeCallbacks = [];
14
18
  }
15
19
 
20
+ /**
21
+ * @param {number} start range start
22
+ * @param {number} end range end
23
+ * @param {Callback} callback callback
24
+ * @returns {void}
25
+ */
16
26
  range(start, end, callback) {
17
27
  if (start === end) return callback(1);
18
28
  this._rangePoints.push(start);
@@ -44,7 +44,7 @@ class Semaphore {
44
44
  if (this.available > 0) {
45
45
  if (this.waiters.length > 0) {
46
46
  this.available--;
47
- const callback = this.waiters.pop();
47
+ const callback = /** @type {(function(): void)} */ (this.waiters.pop());
48
48
  callback();
49
49
  }
50
50
  }