webpack 5.95.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 (145) 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/EvalDevToolModulePlugin.js +5 -2
  19. package/lib/EvalSourceMapDevToolPlugin.js +5 -2
  20. package/lib/ExternalModule.js +40 -7
  21. package/lib/ExternalModuleFactoryPlugin.js +33 -9
  22. package/lib/FileSystemInfo.js +12 -8
  23. package/lib/Generator.js +5 -4
  24. package/lib/HotModuleReplacementPlugin.js +8 -6
  25. package/lib/IgnorePlugin.js +19 -1
  26. package/lib/LoaderOptionsPlugin.js +3 -1
  27. package/lib/Module.js +9 -8
  28. package/lib/ModuleSourceTypesConstants.js +100 -0
  29. package/lib/NormalModule.js +27 -17
  30. package/lib/NormalModuleFactory.js +38 -22
  31. package/lib/OptionsApply.js +12 -1
  32. package/lib/ProgressPlugin.js +50 -10
  33. package/lib/RawModule.js +3 -4
  34. package/lib/RuntimeModule.js +3 -4
  35. package/lib/RuntimePlugin.js +11 -4
  36. package/lib/RuntimeTemplate.js +13 -42
  37. package/lib/SourceMapDevToolPlugin.js +10 -7
  38. package/lib/Watching.js +2 -2
  39. package/lib/WebpackOptionsApply.js +42 -21
  40. package/lib/asset/AssetGenerator.js +347 -194
  41. package/lib/asset/AssetModulesPlugin.js +2 -1
  42. package/lib/asset/AssetSourceGenerator.js +82 -27
  43. package/lib/asset/RawDataUrlModule.js +5 -4
  44. package/lib/buildChunkGraph.js +2 -2
  45. package/lib/cache/PackFileCacheStrategy.js +69 -31
  46. package/lib/cache/ResolverCachePlugin.js +248 -173
  47. package/lib/config/defaults.js +134 -126
  48. package/lib/container/ContainerEntryModule.js +3 -4
  49. package/lib/container/ContainerPlugin.js +8 -0
  50. package/lib/container/FallbackModule.js +2 -2
  51. package/lib/container/HoistContainerReferencesPlugin.js +250 -0
  52. package/lib/container/ModuleFederationPlugin.js +38 -1
  53. package/lib/container/RemoteModule.js +4 -2
  54. package/lib/container/RemoteRuntimeModule.js +4 -2
  55. package/lib/css/CssExportsGenerator.js +16 -12
  56. package/lib/css/CssGenerator.js +22 -16
  57. package/lib/css/CssLoadingRuntimeModule.js +7 -6
  58. package/lib/css/CssModulesPlugin.js +122 -77
  59. package/lib/css/CssParser.js +655 -526
  60. package/lib/css/walkCssTokens.js +1168 -338
  61. package/lib/debug/ProfilingPlugin.js +5 -0
  62. package/lib/dependencies/CommonJsExportsParserPlugin.js +5 -2
  63. package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -6
  64. package/lib/dependencies/CssExportDependency.js +3 -3
  65. package/lib/dependencies/CssLocalIdentifierDependency.js +26 -17
  66. package/lib/dependencies/CssUrlDependency.js +33 -3
  67. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -3
  68. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +39 -14
  69. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +15 -82
  70. package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -2
  71. package/lib/dependencies/ImportParserPlugin.js +9 -7
  72. package/lib/dependencies/LoaderPlugin.js +19 -0
  73. package/lib/dependencies/SystemPlugin.js +2 -1
  74. package/lib/dependencies/URLPlugin.js +7 -1
  75. package/lib/dependencies/WorkerPlugin.js +1 -1
  76. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +4 -2
  77. package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
  78. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
  79. package/lib/hmr/LazyCompilationPlugin.js +16 -4
  80. package/lib/hmr/lazyCompilationBackend.js +1 -7
  81. package/lib/index.js +35 -6
  82. package/lib/javascript/EnableChunkLoadingPlugin.js +2 -2
  83. package/lib/javascript/JavascriptGenerator.js +8 -8
  84. package/lib/javascript/JavascriptModulesPlugin.js +126 -73
  85. package/lib/javascript/JavascriptParser.js +338 -117
  86. package/lib/json/JsonGenerator.js +5 -5
  87. package/lib/library/EnableLibraryPlugin.js +2 -2
  88. package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
  89. package/lib/library/UmdLibraryPlugin.js +16 -8
  90. package/lib/logging/Logger.js +11 -11
  91. package/lib/logging/createConsoleLogger.js +14 -14
  92. package/lib/logging/truncateArgs.js +1 -1
  93. package/lib/node/NodeWatchFileSystem.js +3 -1
  94. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +20 -18
  95. package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
  96. package/lib/node/nodeConsole.js +11 -8
  97. package/lib/optimize/AggressiveSplittingPlugin.js +21 -7
  98. package/lib/optimize/ConcatenatedModule.js +43 -145
  99. package/lib/optimize/FlagIncludedChunksPlugin.js +6 -0
  100. package/lib/optimize/InnerGraphPlugin.js +57 -16
  101. package/lib/optimize/LimitChunkCountPlugin.js +2 -4
  102. package/lib/optimize/ModuleConcatenationPlugin.js +4 -2
  103. package/lib/optimize/RealContentHashPlugin.js +1 -1
  104. package/lib/optimize/SideEffectsFlagPlugin.js +6 -3
  105. package/lib/rules/RuleSetCompiler.js +2 -2
  106. package/lib/runtime/GetChunkFilenameRuntimeModule.js +2 -2
  107. package/lib/schemes/DataUriPlugin.js +1 -1
  108. package/lib/serialization/BinaryMiddleware.js +32 -19
  109. package/lib/serialization/ObjectMiddleware.js +23 -9
  110. package/lib/serialization/SerializerMiddleware.js +3 -2
  111. package/lib/serialization/types.js +2 -2
  112. package/lib/sharing/ConsumeSharedModule.js +2 -3
  113. package/lib/sharing/ConsumeSharedRuntimeModule.js +3 -1
  114. package/lib/sharing/ProvideSharedModule.js +2 -3
  115. package/lib/stats/DefaultStatsFactoryPlugin.js +22 -20
  116. package/lib/stats/StatsFactory.js +12 -12
  117. package/lib/stats/StatsPrinter.js +7 -7
  118. package/lib/util/AsyncQueue.js +17 -1
  119. package/lib/util/IterableHelpers.js +1 -1
  120. package/lib/util/SetHelpers.js +1 -1
  121. package/lib/util/cleverMerge.js +48 -24
  122. package/lib/util/concatenate.js +227 -0
  123. package/lib/util/create-schema-validation.js +22 -9
  124. package/lib/util/deprecation.js +86 -28
  125. package/lib/util/fs.js +9 -9
  126. package/lib/util/hash/wasm-hash.js +12 -1
  127. package/lib/util/magicComment.js +21 -0
  128. package/lib/util/makeSerializable.js +24 -1
  129. package/lib/util/memoize.js +2 -1
  130. package/lib/util/runtime.js +4 -1
  131. package/lib/util/semver.js +130 -23
  132. package/lib/wasm/EnableWasmLoadingPlugin.js +2 -2
  133. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
  134. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +5 -5
  135. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -5
  136. package/lib/wasm-sync/WebAssemblyGenerator.js +8 -9
  137. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -5
  138. package/lib/web/FetchCompileAsyncWasmPlugin.js +1 -2
  139. package/lib/web/FetchCompileWasmPlugin.js +1 -2
  140. package/lib/web/JsonpChunkLoadingRuntimeModule.js +6 -6
  141. package/package.json +17 -18
  142. package/schemas/WebpackOptions.check.js +1 -1
  143. package/schemas/WebpackOptions.json +8 -2
  144. package/types.d.ts +801 -259
  145. package/lib/util/mergeScope.js +0 -76
@@ -7,16 +7,38 @@
7
7
  const { register } = require("./serialization");
8
8
 
9
9
  /** @typedef {import("../serialization/ObjectMiddleware").Constructor} Constructor */
10
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
11
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
10
12
 
13
+ /** @typedef {{ serialize: (context: ObjectSerializerContext) => void, deserialize: (context: ObjectDeserializerContext) => void }} SerializableClass */
14
+ /**
15
+ * @template {SerializableClass} T
16
+ * @typedef {(new (...params: any[]) => T) & { deserialize?: (context: ObjectDeserializerContext) => T }} SerializableClassConstructor
17
+ */
18
+
19
+ /**
20
+ * @template {SerializableClass} T
21
+ */
11
22
  class ClassSerializer {
23
+ /**
24
+ * @param {SerializableClassConstructor<T>} Constructor constructor
25
+ */
12
26
  constructor(Constructor) {
13
27
  this.Constructor = Constructor;
14
28
  }
15
29
 
30
+ /**
31
+ * @param {T} obj obj
32
+ * @param {ObjectSerializerContext} context context
33
+ */
16
34
  serialize(obj, context) {
17
35
  obj.serialize(context);
18
36
  }
19
37
 
38
+ /**
39
+ * @param {ObjectDeserializerContext} context context
40
+ * @returns {T} obj
41
+ */
20
42
  deserialize(context) {
21
43
  if (typeof this.Constructor.deserialize === "function") {
22
44
  return this.Constructor.deserialize(context);
@@ -28,7 +50,8 @@ class ClassSerializer {
28
50
  }
29
51
 
30
52
  /**
31
- * @param {Constructor} Constructor the constructor
53
+ * @template {Constructor} T
54
+ * @param {T} Constructor the constructor
32
55
  * @param {string} request the request which will be required when deserializing
33
56
  * @param {string | null} [name] the name to make multiple serializer unique when sharing a request
34
57
  */
@@ -24,7 +24,8 @@ const memoize = fn => {
24
24
  cache = true;
25
25
  // Allow to clean up memory for fn
26
26
  // and all dependent resources
27
- fn = undefined;
27
+ /** @type {FunctionReturning<T> | undefined} */
28
+ (fn) = undefined;
28
29
  return /** @type {T} */ (result);
29
30
  };
30
31
  };
@@ -633,7 +633,10 @@ class RuntimeSpecMap {
633
633
  }
634
634
 
635
635
  get size() {
636
- if (/** @type {number} */ (this._mode) <= 1) return this._mode;
636
+ if (/** @type {number} */ (this._mode) <= 1) {
637
+ return /** @type {number} */ (this._mode);
638
+ }
639
+
637
640
  return /** @type {Map<string, T>} */ (this._map).size;
638
641
  }
639
642
  }
@@ -6,30 +6,42 @@
6
6
  "use strict";
7
7
 
8
8
  /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
9
- /** @typedef {(string|number|undefined|[])[]} SemVerRange */
9
+ /** @typedef {string | number | undefined} SemVerRangeItem */
10
+ /** @typedef {(SemVerRangeItem | SemVerRangeItem[])[]} SemVerRange */
10
11
 
11
12
  /**
12
13
  * @param {string} str version string
13
- * @returns {(string|number|undefined|[])[]} parsed version
14
+ * @returns {SemVerRange} parsed version
14
15
  */
15
16
  const parseVersion = str => {
17
+ /**
18
+ * @param {str} str str
19
+ * @returns {(string | number)[]} result
20
+ */
16
21
  var splitAndConvert = function (str) {
17
22
  return str.split(".").map(function (item) {
18
23
  // eslint-disable-next-line eqeqeq
19
- return +item == item ? +item : item;
24
+ return +item == /** @type {EXPECTED_ANY} */ (item) ? +item : item;
20
25
  });
21
26
  };
22
- var match = /^([^-+]+)?(?:-([^+]+))?(?:\+(.+))?$/.exec(str);
23
- /** @type {(string|number|undefined|[])[]} */
27
+
28
+ var match =
29
+ /** @type {RegExpExecArray} */
30
+ (/^([^-+]+)?(?:-([^+]+))?(?:\+(.+))?$/.exec(str));
31
+
32
+ /** @type {(string | number | undefined | [])[]} */
24
33
  var ver = match[1] ? splitAndConvert(match[1]) : [];
34
+
25
35
  if (match[2]) {
26
36
  ver.length++;
27
37
  ver.push.apply(ver, splitAndConvert(match[2]));
28
38
  }
39
+
29
40
  if (match[3]) {
30
41
  ver.push([]);
31
42
  ver.push.apply(ver, splitAndConvert(match[3]));
32
43
  }
44
+
33
45
  return ver;
34
46
  };
35
47
  module.exports.parseVersion = parseVersion;
@@ -89,16 +101,28 @@ module.exports.versionLt = versionLt;
89
101
  * @returns {SemVerRange} parsed range
90
102
  */
91
103
  module.exports.parseRange = str => {
104
+ /**
105
+ * @param {string} str str
106
+ * @returns {(string | number)[]} result
107
+ */
92
108
  const splitAndConvert = str => {
93
109
  return str
94
110
  .split(".")
95
111
  .map(item => (item !== "NaN" && `${+item}` === item ? +item : item));
96
112
  };
113
+
97
114
  // see https://docs.npmjs.com/misc/semver#range-grammar for grammar
115
+ /**
116
+ * @param {string} str str
117
+ * @returns {SemVerRangeItem[]}
118
+ */
98
119
  const parsePartial = str => {
99
- const match = /^([^-+]+)?(?:-([^+]+))?(?:\+(.+))?$/.exec(str);
100
- /** @type {(string|number|undefined|[])[]} */
120
+ const match =
121
+ /** @type {RegExpExecArray} */
122
+ (/^([^-+]+)?(?:-([^+]+))?(?:\+(.+))?$/.exec(str));
123
+ /** @type {SemVerRangeItem[]} */
101
124
  const ver = match[1] ? [0, ...splitAndConvert(match[1])] : [0];
125
+
102
126
  if (match[2]) {
103
127
  ver.length++;
104
128
  ver.push.apply(ver, splitAndConvert(match[2]));
@@ -116,6 +140,12 @@ module.exports.parseRange = str => {
116
140
 
117
141
  return ver;
118
142
  };
143
+
144
+ /**
145
+ *
146
+ * @param {SemVerRangeItem[]} range range
147
+ * @returns {SemVerRangeItem[]}
148
+ */
119
149
  const toFixed = range => {
120
150
  if (range.length === 1) {
121
151
  // Special case for "*" is "x.x.x" instead of "="
@@ -130,9 +160,20 @@ module.exports.parseRange = str => {
130
160
 
131
161
  return [range.length, ...range.slice(1)];
132
162
  };
163
+
164
+ /**
165
+ *
166
+ * @param {SemVerRangeItem[]} range
167
+ * @returns {SemVerRangeItem[]} result
168
+ */
133
169
  const negate = range => {
134
- return [-range[0] - 1, ...range.slice(1)];
170
+ return [-(/** @type { [number]} */ (range)[0]) - 1, ...range.slice(1)];
135
171
  };
172
+
173
+ /**
174
+ * @param {string} str str
175
+ * @returns {SemVerRange}
176
+ */
136
177
  const parseSimple = str => {
137
178
  // simple ::= primitive | partial | tilde | caret
138
179
  // primitive ::= ( '<' | '>' | '>=' | '<=' | '=' | '!' ) ( ' ' ) * partial
@@ -143,6 +184,7 @@ module.exports.parseRange = str => {
143
184
  const remainder = parsePartial(
144
185
  start.length ? str.slice(start.length).trim() : str.trim()
145
186
  );
187
+
146
188
  switch (start) {
147
189
  case "^":
148
190
  if (remainder.length > 1 && remainder[1] === 0) {
@@ -185,6 +227,13 @@ module.exports.parseRange = str => {
185
227
  throw new Error("Unexpected start value");
186
228
  }
187
229
  };
230
+
231
+ /**
232
+ *
233
+ * @param {SemVerRangeItem[][]} items items
234
+ * @param {number} fn fn
235
+ * @returns {SemVerRange} result
236
+ */
188
237
  const combine = (items, fn) => {
189
238
  if (items.length === 1) return items[0];
190
239
  const arr = [];
@@ -195,38 +244,64 @@ module.exports.parseRange = str => {
195
244
  arr.push(...item.slice(1));
196
245
  }
197
246
  }
247
+
198
248
  // eslint-disable-next-line no-sparse-arrays
199
249
  return [, ...arr, ...items.slice(1).map(() => fn)];
200
250
  };
251
+
252
+ /**
253
+ * @param {string} str str
254
+ * @returns {SemVerRange}
255
+ */
201
256
  const parseRange = str => {
202
257
  // range ::= hyphen | simple ( ' ' ( ' ' ) * simple ) * | ''
203
258
  // hyphen ::= partial ( ' ' ) * ' - ' ( ' ' ) * partial
204
259
  const items = str.split(/\s+-\s+/);
260
+
205
261
  if (items.length === 1) {
206
- const items = str
207
- .trim()
208
- .split(/(?<=[-0-9A-Za-z])\s+/g)
209
- .map(parseSimple);
262
+ const items =
263
+ /** @type {SemVerRangeItem[][]} */
264
+ (
265
+ str
266
+ .trim()
267
+ .split(/(?<=[-0-9A-Za-z])\s+/g)
268
+ .map(parseSimple)
269
+ );
270
+
210
271
  return combine(items, 2);
211
272
  }
273
+
212
274
  const a = parsePartial(items[0]);
213
275
  const b = parsePartial(items[1]);
214
276
  // >=a <=b => and( >=a, or( <b, =b ) ) => >=a, <b, =b, or, and
215
277
  // eslint-disable-next-line no-sparse-arrays
216
278
  return [, toFixed(b), negate(b), 1, a, 2];
217
279
  };
280
+
281
+ /**
282
+ * @param {string} str str
283
+ * @returns {SemVerRange}
284
+ */
218
285
  const parseLogicalOr = str => {
219
286
  // range-set ::= range ( logical-or range ) *
220
287
  // logical-or ::= ( ' ' ) * '||' ( ' ' ) *
221
- const items = str.split(/\s*\|\|\s*/).map(parseRange);
288
+ const items =
289
+ /** @type {SemVerRangeItem[][]} */
290
+ (str.split(/\s*\|\|\s*/).map(parseRange));
291
+
222
292
  return combine(items, 1);
223
293
  };
294
+
224
295
  return parseLogicalOr(str);
225
296
  };
226
297
 
227
298
  /* eslint-disable eqeqeq */
299
+ /**
300
+ * @param {SemVerRange} range
301
+ * @returns {string}
302
+ */
228
303
  const rangeToString = range => {
229
- var fixCount = range[0];
304
+ var fixCount = /** @type {number} */ (range[0]);
230
305
  var str = "";
231
306
  if (range.length === 1) {
232
307
  return "*";
@@ -270,7 +345,7 @@ const rangeToString = range => {
270
345
  ? "(" + pop() + " || " + pop() + ")"
271
346
  : item === 2
272
347
  ? stack.pop() + " " + stack.pop()
273
- : rangeToString(item)
348
+ : rangeToString(/** @type {SemVerRange} */ (item))
274
349
  );
275
350
  }
276
351
  return pop();
@@ -279,10 +354,9 @@ const rangeToString = range => {
279
354
  return /** @type {string} */ (stack.pop()).replace(/^\((.+)\)$/, "$1");
280
355
  }
281
356
  };
282
- /* eslint-enable eqeqeq */
357
+
283
358
  module.exports.rangeToString = rangeToString;
284
359
 
285
- /* eslint-disable eqeqeq */
286
360
  /**
287
361
  * @param {SemVerRange} range version range
288
362
  * @param {string} version the version
@@ -341,16 +415,22 @@ const satisfy = (range, version) => {
341
415
  // big-cmp: when negated => return false, else => next-nequ
342
416
  // small-cmp: when negated => next-nequ, else => return false
343
417
 
344
- var rangeType = j < range.length ? (typeof range[j])[0] : "";
418
+ var rangeType =
419
+ /** @type {"s" | "n" | "u" | ""} */
420
+ (j < range.length ? (typeof range[j])[0] : "");
345
421
 
422
+ /** @type {number | string | undefined} */
346
423
  var versionValue;
424
+ /** @type {"n" | "s" | "u" | "o" | undefined} */
347
425
  var versionType;
348
426
 
349
427
  // Handles first column in both tables (end of version or object)
350
428
  if (
351
429
  i >= version.length ||
352
430
  ((versionValue = version[i]),
353
- (versionType = (typeof versionValue)[0]) == "o")
431
+ (versionType = /** @type {"n" | "s" | "u" | "o"} */ (
432
+ (typeof versionValue)[0]
433
+ )) == "o")
354
434
  ) {
355
435
  // Handles nequal
356
436
  if (!isEqual) return true;
@@ -378,7 +458,11 @@ const satisfy = (range, version) => {
378
458
  }
379
459
  } else {
380
460
  // Handles "cmp" cases
381
- if (negated ? versionValue > range[j] : versionValue < range[j]) {
461
+ if (
462
+ negated
463
+ ? versionValue > /** @type {(number | string)[]} */ (range)[j]
464
+ : versionValue < /** @type {(number | string)[]} */ (range)[j]
465
+ ) {
382
466
  return false;
383
467
  }
384
468
  if (versionValue != range[j]) isEqual = false;
@@ -410,17 +494,20 @@ const satisfy = (range, version) => {
410
494
  }
411
495
  }
412
496
  }
497
+
413
498
  /** @type {(boolean | number)[]} */
414
499
  var stack = [];
415
500
  var p = stack.pop.bind(stack);
416
501
  // eslint-disable-next-line no-redeclare
417
502
  for (var i = 1; i < range.length; i++) {
418
- var item = /** @type {SemVerRange | 0 | 1 | 2} */ (range[i]);
503
+ var item = /** @type {SemVerRangeItem[] | 0 | 1 | 2} */ (range[i]);
504
+
419
505
  stack.push(
420
506
  item == 1
421
- ? p() | p()
507
+ ? /** @type {() => number} */ (p)() | /** @type {() => number} */ (p)()
422
508
  : item == 2
423
- ? p() & p()
509
+ ? /** @type {() => number} */ (p)() &
510
+ /** @type {() => number} */ (p)()
424
511
  : item
425
512
  ? satisfy(item, version)
426
513
  : !p()
@@ -431,6 +518,10 @@ const satisfy = (range, version) => {
431
518
  /* eslint-enable eqeqeq */
432
519
  module.exports.satisfy = satisfy;
433
520
 
521
+ /**
522
+ * @param {SemVerRange | string | number | false | undefined} json
523
+ * @returns {string}
524
+ */
434
525
  module.exports.stringifyHoley = json => {
435
526
  switch (typeof json) {
436
527
  case "undefined":
@@ -453,6 +544,10 @@ module.exports.stringifyHoley = json => {
453
544
  };
454
545
 
455
546
  //#region runtime code: parseVersion
547
+ /**
548
+ * @param {RuntimeTemplate} runtimeTemplate
549
+ * @returns {string}
550
+ */
456
551
  exports.parseVersionRuntimeCode = runtimeTemplate =>
457
552
  `var parseVersion = ${runtimeTemplate.basicFunction("str", [
458
553
  "// see webpack/lib/util/semver.js for original code",
@@ -461,6 +556,10 @@ exports.parseVersionRuntimeCode = runtimeTemplate =>
461
556
  //#endregion
462
557
 
463
558
  //#region runtime code: versionLt
559
+ /**
560
+ * @param {RuntimeTemplate} runtimeTemplate
561
+ * @returns {string}
562
+ */
464
563
  exports.versionLtRuntimeCode = runtimeTemplate =>
465
564
  `var versionLt = ${runtimeTemplate.basicFunction("a, b", [
466
565
  "// see webpack/lib/util/semver.js for original code",
@@ -469,6 +568,10 @@ exports.versionLtRuntimeCode = runtimeTemplate =>
469
568
  //#endregion
470
569
 
471
570
  //#region runtime code: rangeToString
571
+ /**
572
+ * @param {RuntimeTemplate} runtimeTemplate
573
+ * @returns {string}
574
+ */
472
575
  exports.rangeToStringRuntimeCode = runtimeTemplate =>
473
576
  `var rangeToString = ${runtimeTemplate.basicFunction("range", [
474
577
  "// see webpack/lib/util/semver.js for original code",
@@ -477,6 +580,10 @@ exports.rangeToStringRuntimeCode = runtimeTemplate =>
477
580
  //#endregion
478
581
 
479
582
  //#region runtime code: satisfy
583
+ /**
584
+ * @param {RuntimeTemplate} runtimeTemplate
585
+ * @returns {string}
586
+ */
480
587
  exports.satisfyRuntimeCode = runtimeTemplate =>
481
588
  `var satisfy = ${runtimeTemplate.basicFunction("range, version", [
482
589
  "// see webpack/lib/util/semver.js for original code",
@@ -52,8 +52,8 @@ class EnableWasmLoadingPlugin {
52
52
  throw new Error(
53
53
  `Library type "${type}" is not enabled. ` +
54
54
  "EnableWasmLoadingPlugin need to be used to enable this type of wasm loading. " +
55
- `This usually happens through the "output.enabledWasmLoadingTypes" option. ` +
56
- `If you are using a function as entry which sets "wasmLoading", you need to add all potential library types to "output.enabledWasmLoadingTypes". ` +
55
+ 'This usually happens through the "output.enabledWasmLoadingTypes" option. ' +
56
+ 'If you are using a function as entry which sets "wasmLoading", you need to add all potential library types to "output.enabledWasmLoadingTypes". ' +
57
57
  `These types are enabled: ${Array.from(
58
58
  getEnabledTypes(compiler)
59
59
  ).join(", ")}`
@@ -44,7 +44,7 @@ class AsyncWasmLoadingRuntimeModule extends RuntimeModule {
44
44
  `" + ${RuntimeGlobals.getFullHash}}().slice(0, ${length}) + "`,
45
45
  module: {
46
46
  id: '" + wasmModuleId + "',
47
- hash: `" + wasmModuleHash + "`,
47
+ hash: '" + wasmModuleHash + "',
48
48
  hashWithLength(length) {
49
49
  return `" + wasmModuleHash.slice(0, ${length}) + "`;
50
50
  }
@@ -75,7 +75,7 @@ class AsyncWasmLoadingRuntimeModule extends RuntimeModule {
75
75
  concat(
76
76
  "return req.then(",
77
77
  runtimeTemplate.basicFunction("res", [
78
- `if (typeof WebAssembly.instantiateStreaming === "function") {`,
78
+ 'if (typeof WebAssembly.instantiateStreaming === "function") {',
79
79
  Template.indent([
80
80
  "return WebAssembly.instantiateStreaming(res, importsObj)",
81
81
  Template.indent([
@@ -86,7 +86,7 @@ class AsyncWasmLoadingRuntimeModule extends RuntimeModule {
86
86
  "res"
87
87
  )},`,
88
88
  runtimeTemplate.basicFunction("e", [
89
- `if(res.headers.get("Content-Type") !== "application/wasm") {`,
89
+ 'if(res.headers.get("Content-Type") !== "application/wasm") {',
90
90
  Template.indent([
91
91
  'console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\\n", e);',
92
92
  "return fallback();"
@@ -6,13 +6,13 @@
6
6
  "use strict";
7
7
 
8
8
  const Generator = require("../Generator");
9
+ const { WEBASSEMBLY_TYPES } = require("../ModuleSourceTypesConstants");
9
10
 
10
11
  /** @typedef {import("webpack-sources").Source} Source */
11
12
  /** @typedef {import("../Generator").GenerateContext} GenerateContext */
13
+ /** @typedef {import("../Module").SourceTypes} SourceTypes */
12
14
  /** @typedef {import("../NormalModule")} NormalModule */
13
15
 
14
- const TYPES = new Set(["webassembly"]);
15
-
16
16
  /**
17
17
  * @typedef {object} AsyncWebAssemblyGeneratorOptions
18
18
  * @property {boolean} [mangleImports] mangle imports
@@ -29,10 +29,10 @@ class AsyncWebAssemblyGenerator extends Generator {
29
29
 
30
30
  /**
31
31
  * @param {NormalModule} module fresh module
32
- * @returns {Set<string>} available types (do not mutate)
32
+ * @returns {SourceTypes} available types (do not mutate)
33
33
  */
34
34
  getTypes(module) {
35
- return TYPES;
35
+ return WEBASSEMBLY_TYPES;
36
36
  }
37
37
 
38
38
  /**
@@ -51,7 +51,7 @@ class AsyncWebAssemblyGenerator extends Generator {
51
51
  /**
52
52
  * @param {NormalModule} module module for which the code should be generated
53
53
  * @param {GenerateContext} generateContext context for generate
54
- * @returns {Source} generated code
54
+ * @returns {Source | null} generated code
55
55
  */
56
56
  generate(module, generateContext) {
57
57
  return /** @type {Source} */ (module.originalSource());
@@ -8,6 +8,7 @@
8
8
  const { RawSource } = require("webpack-sources");
9
9
  const Generator = require("../Generator");
10
10
  const InitFragment = require("../InitFragment");
11
+ const { WEBASSEMBLY_TYPES } = require("../ModuleSourceTypesConstants");
11
12
  const RuntimeGlobals = require("../RuntimeGlobals");
12
13
  const Template = require("../Template");
13
14
  const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency");
@@ -17,11 +18,10 @@ const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDe
17
18
  /** @typedef {import("../DependencyTemplates")} DependencyTemplates */
18
19
  /** @typedef {import("../Generator").GenerateContext} GenerateContext */
19
20
  /** @typedef {import("../Module")} Module */
21
+ /** @typedef {import("../Module").SourceTypes} SourceTypes */
20
22
  /** @typedef {import("../NormalModule")} NormalModule */
21
23
  /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
22
24
 
23
- const TYPES = new Set(["webassembly"]);
24
-
25
25
  /**
26
26
  * @typedef {{ request: string, importVar: string }} ImportObjRequestItem
27
27
  */
@@ -37,10 +37,10 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
37
37
 
38
38
  /**
39
39
  * @param {NormalModule} module fresh module
40
- * @returns {Set<string>} available types (do not mutate)
40
+ * @returns {SourceTypes} available types (do not mutate)
41
41
  */
42
42
  getTypes(module) {
43
- return TYPES;
43
+ return WEBASSEMBLY_TYPES;
44
44
  }
45
45
 
46
46
  /**
@@ -55,7 +55,7 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
55
55
  /**
56
56
  * @param {NormalModule} module module for which the code should be generated
57
57
  * @param {GenerateContext} generateContext context for generate
58
- * @returns {Source} generated code
58
+ * @returns {Source | null} generated code
59
59
  */
60
60
  generate(module, generateContext) {
61
61
  const {
@@ -5,14 +5,14 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const { RawSource } = require("webpack-sources");
9
- const Generator = require("../Generator");
10
- const WebAssemblyUtils = require("./WebAssemblyUtils");
11
-
12
8
  const t = require("@webassemblyjs/ast");
13
9
  const { moduleContextFromModuleAST } = require("@webassemblyjs/ast");
14
10
  const { editWithAST, addWithAST } = require("@webassemblyjs/wasm-edit");
15
11
  const { decode } = require("@webassemblyjs/wasm-parser");
12
+ const { RawSource } = require("webpack-sources");
13
+ const Generator = require("../Generator");
14
+ const { WEBASSEMBLY_TYPES } = require("../ModuleSourceTypesConstants");
15
+ const WebAssemblyUtils = require("./WebAssemblyUtils");
16
16
 
17
17
  const WebAssemblyExportImportedDependency = require("../dependencies/WebAssemblyExportImportedDependency");
18
18
 
@@ -20,6 +20,7 @@ const WebAssemblyExportImportedDependency = require("../dependencies/WebAssembly
20
20
  /** @typedef {import("../DependencyTemplates")} DependencyTemplates */
21
21
  /** @typedef {import("../Generator").GenerateContext} GenerateContext */
22
22
  /** @typedef {import("../Module")} Module */
23
+ /** @typedef {import("../Module").SourceTypes} SourceTypes */
23
24
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
24
25
  /** @typedef {import("../NormalModule")} NormalModule */
25
26
  /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
@@ -400,8 +401,6 @@ const getUsedDependencyMap = (moduleGraph, module, mangle) => {
400
401
  return map;
401
402
  };
402
403
 
403
- const TYPES = new Set(["webassembly"]);
404
-
405
404
  /**
406
405
  * @typedef {object} WebAssemblyGeneratorOptions
407
406
  * @property {boolean} [mangleImports] mangle imports
@@ -418,10 +417,10 @@ class WebAssemblyGenerator extends Generator {
418
417
 
419
418
  /**
420
419
  * @param {NormalModule} module fresh module
421
- * @returns {Set<string>} available types (do not mutate)
420
+ * @returns {SourceTypes} available types (do not mutate)
422
421
  */
423
422
  getTypes(module) {
424
- return TYPES;
423
+ return WEBASSEMBLY_TYPES;
425
424
  }
426
425
 
427
426
  /**
@@ -440,7 +439,7 @@ class WebAssemblyGenerator extends Generator {
440
439
  /**
441
440
  * @param {NormalModule} module module for which the code should be generated
442
441
  * @param {GenerateContext} generateContext context for generate
443
- * @returns {Source} generated code
442
+ * @returns {Source | null} generated code
444
443
  */
445
444
  generate(module, { moduleGraph, runtime }) {
446
445
  const bin = /** @type {Source} */ (module.originalSource()).source();
@@ -9,6 +9,7 @@ const { RawSource } = require("webpack-sources");
9
9
  const { UsageState } = require("../ExportsInfo");
10
10
  const Generator = require("../Generator");
11
11
  const InitFragment = require("../InitFragment");
12
+ const { WEBASSEMBLY_TYPES } = require("../ModuleSourceTypesConstants");
12
13
  const RuntimeGlobals = require("../RuntimeGlobals");
13
14
  const Template = require("../Template");
14
15
  const ModuleDependency = require("../dependencies/ModuleDependency");
@@ -20,18 +21,17 @@ const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDe
20
21
  /** @typedef {import("../DependencyTemplates")} DependencyTemplates */
21
22
  /** @typedef {import("../Generator").GenerateContext} GenerateContext */
22
23
  /** @typedef {import("../Module")} Module */
24
+ /** @typedef {import("../Module").SourceTypes} SourceTypes */
23
25
  /** @typedef {import("../NormalModule")} NormalModule */
24
26
  /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
25
27
 
26
- const TYPES = new Set(["webassembly"]);
27
-
28
28
  class WebAssemblyJavascriptGenerator extends Generator {
29
29
  /**
30
30
  * @param {NormalModule} module fresh module
31
- * @returns {Set<string>} available types (do not mutate)
31
+ * @returns {SourceTypes} available types (do not mutate)
32
32
  */
33
33
  getTypes(module) {
34
- return TYPES;
34
+ return WEBASSEMBLY_TYPES;
35
35
  }
36
36
 
37
37
  /**
@@ -46,7 +46,7 @@ class WebAssemblyJavascriptGenerator extends Generator {
46
46
  /**
47
47
  * @param {NormalModule} module module for which the code should be generated
48
48
  * @param {GenerateContext} generateContext context for generate
49
- * @returns {Source} generated code
49
+ * @returns {Source | null} generated code
50
50
  */
51
51
  generate(module, generateContext) {
52
52
  const {
@@ -44,9 +44,8 @@ class FetchCompileAsyncWasmPlugin {
44
44
 
45
45
  compilation.hooks.runtimeRequirementInTree
46
46
  .for(RuntimeGlobals.instantiateWasm)
47
- .tap("FetchCompileAsyncWasmPlugin", (chunk, set) => {
47
+ .tap("FetchCompileAsyncWasmPlugin", (chunk, set, { chunkGraph }) => {
48
48
  if (!isEnabledForChunk(chunk)) return;
49
- const chunkGraph = compilation.chunkGraph;
50
49
  if (
51
50
  !chunkGraph.hasModuleInGraph(
52
51
  chunk,
@@ -58,9 +58,8 @@ class FetchCompileWasmPlugin {
58
58
 
59
59
  compilation.hooks.runtimeRequirementInTree
60
60
  .for(RuntimeGlobals.ensureChunkHandlers)
61
- .tap(PLUGIN_NAME, (chunk, set) => {
61
+ .tap(PLUGIN_NAME, (chunk, set, { chunkGraph }) => {
62
62
  if (!isEnabledForChunk(chunk)) return;
63
- const chunkGraph = compilation.chunkGraph;
64
63
  if (
65
64
  !chunkGraph.hasModuleInGraph(
66
65
  chunk,
@@ -103,12 +103,6 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
103
103
  const withHmrManifest = this._runtimeRequirements.has(
104
104
  RuntimeGlobals.hmrDownloadManifest
105
105
  );
106
- const withPrefetch = this._runtimeRequirements.has(
107
- RuntimeGlobals.prefetchChunkHandlers
108
- );
109
- const withPreload = this._runtimeRequirements.has(
110
- RuntimeGlobals.preloadChunkHandlers
111
- );
112
106
  const withFetchPriority = this._runtimeRequirements.has(
113
107
  RuntimeGlobals.hasFetchPriority
114
108
  );
@@ -117,6 +111,12 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
117
111
  )}]`;
118
112
  const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
119
113
  const chunk = /** @type {Chunk} */ (this.chunk);
114
+ const withPrefetch =
115
+ this._runtimeRequirements.has(RuntimeGlobals.prefetchChunkHandlers) &&
116
+ chunk.hasChildByOrder(chunkGraph, "prefetch", true, chunkHasJs);
117
+ const withPreload =
118
+ this._runtimeRequirements.has(RuntimeGlobals.preloadChunkHandlers) &&
119
+ chunk.hasChildByOrder(chunkGraph, "preload", true, chunkHasJs);
120
120
  const conditionMap = chunkGraph.getChunkConditionMap(chunk, chunkHasJs);
121
121
  const hasJsMatcher = compileBooleanMatcher(conditionMap);
122
122
  const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs);