webpack 5.86.0 → 5.88.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 (207) hide show
  1. package/README.md +5 -2
  2. package/lib/APIPlugin.js +1 -1
  3. package/lib/AsyncDependenciesBlock.js +3 -3
  4. package/lib/CaseSensitiveModulesWarning.js +3 -1
  5. package/lib/ChunkGraph.js +4 -4
  6. package/lib/ChunkGroup.js +10 -3
  7. package/lib/CompatibilityPlugin.js +50 -30
  8. package/lib/Compilation.js +2 -1
  9. package/lib/Compiler.js +3 -1
  10. package/lib/ConcatenationScope.js +2 -2
  11. package/lib/ConditionalInitFragment.js +11 -1
  12. package/lib/ConstPlugin.js +57 -29
  13. package/lib/ContextModule.js +4 -1
  14. package/lib/ContextReplacementPlugin.js +13 -0
  15. package/lib/DelegatedModule.js +15 -3
  16. package/lib/DelegatedModuleFactoryPlugin.js +6 -0
  17. package/lib/Dependency.js +11 -5
  18. package/lib/DllEntryPlugin.js +11 -1
  19. package/lib/DllReferencePlugin.js +13 -1
  20. package/lib/Entrypoint.js +1 -1
  21. package/lib/ErrorHelpers.js +1 -0
  22. package/lib/EvalSourceMapDevToolPlugin.js +4 -0
  23. package/lib/ExportsInfo.js +17 -3
  24. package/lib/ExportsInfoApiPlugin.js +14 -5
  25. package/lib/ExternalModule.js +5 -0
  26. package/lib/FlagAllModulesAsUsedPlugin.js +6 -1
  27. package/lib/FlagDependencyUsagePlugin.js +3 -1
  28. package/lib/FlagEntryExportAsUsedPlugin.js +4 -0
  29. package/lib/HotModuleReplacementPlugin.js +8 -0
  30. package/lib/InitFragment.js +28 -5
  31. package/lib/JavascriptMetaInfoPlugin.js +11 -6
  32. package/lib/LibManifestPlugin.js +20 -4
  33. package/lib/Module.js +7 -2
  34. package/lib/ModuleDependencyError.js +4 -2
  35. package/lib/ModuleDependencyWarning.js +4 -2
  36. package/lib/ModuleGraph.js +31 -24
  37. package/lib/ModuleGraphConnection.js +19 -6
  38. package/lib/ModuleInfoHeaderPlugin.js +9 -2
  39. package/lib/ModuleNotFoundError.js +5 -2
  40. package/lib/ModuleProfile.js +1 -0
  41. package/lib/ModuleRestoreError.js +2 -0
  42. package/lib/ModuleStoreError.js +2 -1
  43. package/lib/ModuleTypeConstants.js +7 -0
  44. package/lib/MultiWatching.js +4 -0
  45. package/lib/NodeStuffPlugin.js +32 -6
  46. package/lib/ProvidePlugin.js +13 -4
  47. package/lib/RawModule.js +3 -1
  48. package/lib/RequireJsStuffPlugin.js +7 -0
  49. package/lib/RuntimeGlobals.js +5 -0
  50. package/lib/RuntimeModule.js +3 -3
  51. package/lib/RuntimePlugin.js +6 -3
  52. package/lib/RuntimeTemplate.js +22 -4
  53. package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
  54. package/lib/SourceMapDevToolPlugin.js +7 -2
  55. package/lib/UseStrictPlugin.js +10 -3
  56. package/lib/WebpackError.js +6 -5
  57. package/lib/WebpackIsIncludedPlugin.js +6 -4
  58. package/lib/WebpackOptionsApply.js +1 -1
  59. package/lib/WebpackOptionsDefaulter.js +10 -3
  60. package/lib/asset/AssetGenerator.js +2 -1
  61. package/lib/asset/AssetParser.js +11 -6
  62. package/lib/asset/AssetSourceParser.js +8 -3
  63. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -0
  64. package/lib/cache/IdleFileCachePlugin.js +2 -1
  65. package/lib/cache/PackFileCacheStrategy.js +35 -14
  66. package/lib/config/browserslistTargetHandler.js +7 -7
  67. package/lib/config/defaults.js +43 -26
  68. package/lib/container/RemoteRuntimeModule.js +1 -1
  69. package/lib/css/CssLoadingRuntimeModule.js +30 -13
  70. package/lib/css/CssModulesPlugin.js +5 -2
  71. package/lib/css/CssParser.js +22 -0
  72. package/lib/dependencies/AMDDefineDependency.js +34 -4
  73. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +5 -0
  74. package/lib/dependencies/AMDRuntimeModules.js +2 -2
  75. package/lib/dependencies/CommonJsExportsParserPlugin.js +14 -4
  76. package/lib/dependencies/CommonJsImportsParserPlugin.js +169 -59
  77. package/lib/dependencies/CommonJsPlugin.js +13 -8
  78. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
  79. package/lib/dependencies/ConstDependency.js +2 -2
  80. package/lib/dependencies/ContextDependency.js +7 -2
  81. package/lib/dependencies/CssImportDependency.js +1 -1
  82. package/lib/dependencies/CssLocalIdentifierDependency.js +5 -0
  83. package/lib/dependencies/CssUrlDependency.js +3 -3
  84. package/lib/dependencies/DllEntryDependency.js +5 -0
  85. package/lib/dependencies/DynamicExports.js +10 -6
  86. package/lib/dependencies/ExportsInfoDependency.js +14 -4
  87. package/lib/dependencies/HarmonyCompatibilityDependency.js +2 -1
  88. package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -1
  89. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -5
  90. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +2 -0
  91. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +4 -4
  92. package/lib/dependencies/HarmonyExports.js +9 -5
  93. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +32 -17
  94. package/lib/dependencies/HarmonyImportSideEffectDependency.js +1 -2
  95. package/lib/dependencies/HarmonyImportSpecifierDependency.js +19 -9
  96. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
  97. package/lib/dependencies/ImportDependency.js +5 -3
  98. package/lib/dependencies/ImportEagerDependency.js +5 -3
  99. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +19 -0
  100. package/lib/dependencies/ImportMetaPlugin.js +31 -15
  101. package/lib/dependencies/ImportParserPlugin.js +62 -25
  102. package/lib/dependencies/ImportWeakDependency.js +5 -3
  103. package/lib/dependencies/ModuleDependency.js +1 -1
  104. package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
  105. package/lib/dependencies/ProvidedDependency.js +4 -1
  106. package/lib/dependencies/RequireContextDependencyParserPlugin.js +13 -5
  107. package/lib/dependencies/RequireEnsureDependenciesBlock.js +5 -2
  108. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +6 -1
  109. package/lib/dependencies/RequireHeaderDependency.js +4 -0
  110. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +26 -5
  111. package/lib/dependencies/RequireResolveHeaderDependency.js +9 -0
  112. package/lib/dependencies/SystemPlugin.js +17 -5
  113. package/lib/dependencies/SystemRuntimeModule.js +1 -1
  114. package/lib/dependencies/URLDependency.js +2 -2
  115. package/lib/dependencies/URLPlugin.js +9 -4
  116. package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
  117. package/lib/dependencies/WorkerPlugin.js +59 -22
  118. package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -1
  119. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
  120. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  121. package/lib/ids/HashedModuleIdsPlugin.js +1 -1
  122. package/lib/ids/SyncModuleIdsPlugin.js +1 -0
  123. package/lib/javascript/BasicEvaluatedExpression.js +23 -15
  124. package/lib/javascript/CommonJsChunkFormatPlugin.js +6 -2
  125. package/lib/javascript/JavascriptParser.js +135 -63
  126. package/lib/javascript/JavascriptParserHelpers.js +37 -15
  127. package/lib/logging/runtime.js +1 -1
  128. package/lib/logging/truncateArgs.js +4 -0
  129. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -6
  130. package/lib/node/RequireChunkLoadingRuntimeModule.js +10 -6
  131. package/lib/optimize/InnerGraph.js +1 -1
  132. package/lib/optimize/InnerGraphPlugin.js +2 -1
  133. package/lib/performance/SizeLimitsPlugin.js +7 -4
  134. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +4 -2
  135. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
  136. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +6 -3
  137. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -2
  138. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +4 -2
  139. package/lib/rules/BasicEffectRulePlugin.js +4 -0
  140. package/lib/rules/BasicMatcherRulePlugin.js +5 -0
  141. package/lib/rules/RuleSetCompiler.js +3 -3
  142. package/lib/rules/UseEffectRulePlugin.js +6 -4
  143. package/lib/runtime/AsyncModuleRuntimeModule.js +8 -5
  144. package/lib/runtime/AutoPublicPathRuntimeModule.js +4 -2
  145. package/lib/runtime/BaseUriRuntimeModule.js +3 -3
  146. package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
  147. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +5 -2
  148. package/lib/runtime/CompatRuntimeModule.js +7 -2
  149. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +5 -2
  150. package/lib/runtime/CreateScriptRuntimeModule.js +4 -2
  151. package/lib/runtime/CreateScriptUrlRuntimeModule.js +4 -2
  152. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +5 -2
  153. package/lib/runtime/EnsureChunkRuntimeModule.js +15 -4
  154. package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -10
  155. package/lib/runtime/GetFullHashRuntimeModule.js +4 -3
  156. package/lib/runtime/GetMainFilenameRuntimeModule.js +5 -2
  157. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +4 -2
  158. package/lib/runtime/GlobalRuntimeModule.js +1 -1
  159. package/lib/runtime/HasOwnPropertyRuntimeModule.js +5 -2
  160. package/lib/runtime/LoadScriptRuntimeModule.js +64 -48
  161. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +5 -2
  162. package/lib/runtime/NonceRuntimeModule.js +1 -1
  163. package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -2
  164. package/lib/runtime/PublicPathRuntimeModule.js +4 -2
  165. package/lib/runtime/RelativeUrlRuntimeModule.js +5 -2
  166. package/lib/runtime/RuntimeIdRuntimeModule.js +6 -2
  167. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -3
  168. package/lib/runtime/StartupEntrypointRuntimeModule.js +3 -2
  169. package/lib/runtime/SystemContextRuntimeModule.js +1 -1
  170. package/lib/serialization/ObjectMiddleware.js +6 -3
  171. package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
  172. package/lib/sharing/ConsumeSharedRuntimeModule.js +14 -5
  173. package/lib/sharing/ProvideSharedDependency.js +11 -0
  174. package/lib/sharing/ProvideSharedModule.js +4 -0
  175. package/lib/sharing/ProvideSharedPlugin.js +22 -21
  176. package/lib/sharing/ShareRuntimeModule.js +12 -5
  177. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  178. package/lib/sharing/utils.js +32 -5
  179. package/lib/util/AsyncQueue.js +4 -2
  180. package/lib/util/ParallelismFactorCalculator.js +10 -0
  181. package/lib/util/Semaphore.js +1 -1
  182. package/lib/util/createHash.js +30 -9
  183. package/lib/util/deprecation.js +10 -3
  184. package/lib/util/deterministicGrouping.js +50 -11
  185. package/lib/util/findGraphRoots.js +4 -2
  186. package/lib/util/memoize.js +3 -3
  187. package/lib/util/processAsyncTree.js +7 -1
  188. package/lib/util/registerExternalSerializer.js +1 -1
  189. package/lib/util/runtime.js +14 -1
  190. package/lib/util/smartGrouping.js +1 -1
  191. package/lib/validateSchema.js +6 -2
  192. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +6 -2
  193. package/lib/wasm-async/AsyncWebAssemblyParser.js +7 -3
  194. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +14 -7
  195. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +3 -1
  196. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
  197. package/lib/wasm-sync/WebAssemblyParser.js +6 -2
  198. package/lib/web/JsonpChunkLoadingRuntimeModule.js +14 -4
  199. package/lib/webpack.js +11 -2
  200. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +15 -16
  201. package/module.d.ts +1 -0
  202. package/package.json +5 -4
  203. package/schemas/WebpackOptions.check.js +1 -1
  204. package/schemas/WebpackOptions.json +39 -5
  205. package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
  206. package/schemas/plugins/css/CssParserOptions.json +1 -1
  207. package/types.d.ts +519 -222
@@ -13,18 +13,18 @@
13
13
  */
14
14
  const memoize = fn => {
15
15
  let cache = false;
16
- /** @type {T} */
16
+ /** @type {T | undefined} */
17
17
  let result = undefined;
18
18
  return () => {
19
19
  if (cache) {
20
- return result;
20
+ return /** @type {T} */ (result);
21
21
  } else {
22
22
  result = fn();
23
23
  cache = true;
24
24
  // Allow to clean up memory for fn
25
25
  // and all dependent resources
26
26
  fn = undefined;
27
- return result;
27
+ return /** @type {T} */ (result);
28
28
  }
29
29
  };
30
30
  };
@@ -21,6 +21,9 @@ const processAsyncTree = (items, concurrency, processor, callback) => {
21
21
  let finished = false;
22
22
  let processScheduled = true;
23
23
 
24
+ /**
25
+ * @param {T} item item
26
+ */
24
27
  const push = item => {
25
28
  queue.push(item);
26
29
  if (!processScheduled && processing < concurrency) {
@@ -29,6 +32,9 @@ const processAsyncTree = (items, concurrency, processor, callback) => {
29
32
  }
30
33
  };
31
34
 
35
+ /**
36
+ * @param {E | null | undefined} err error
37
+ */
32
38
  const processorCallback = err => {
33
39
  processing--;
34
40
  if (err && !finished) {
@@ -46,7 +52,7 @@ const processAsyncTree = (items, concurrency, processor, callback) => {
46
52
  if (finished) return;
47
53
  while (processing < concurrency && queue.length > 0) {
48
54
  processing++;
49
- const item = queue.pop();
55
+ const item = /** @type {T} */ (queue.pop());
50
56
  processor(item, push, processorCallback);
51
57
  }
52
58
  processScheduled = false;
@@ -26,7 +26,7 @@ const {
26
26
  /** @typedef {import("./serialization").ObjectDeserializerContext} ObjectDeserializerContext */
27
27
  /** @typedef {import("./serialization").ObjectSerializerContext} ObjectSerializerContext */
28
28
 
29
- /** @typedef {ObjectSerializerContext & { writeLazy?: (any) => void }} WebpackObjectSerializerContext */
29
+ /** @typedef {ObjectSerializerContext & { writeLazy?: (value: any) => void }} WebpackObjectSerializerContext */
30
30
 
31
31
  const CURRENT_MODULE = "webpack/lib/util/registerExternalSerializer";
32
32
 
@@ -434,7 +434,7 @@ class RuntimeSpecMap {
434
434
 
435
435
  /**
436
436
  * @param {RuntimeSpec} runtime the runtimes
437
- * @returns {T} value
437
+ * @returns {T | undefined} value
438
438
  */
439
439
  get(runtime) {
440
440
  switch (this._mode) {
@@ -517,6 +517,9 @@ class RuntimeSpecMap {
517
517
  }
518
518
  }
519
519
 
520
+ /**
521
+ * @param {RuntimeSpec} runtime the runtimes
522
+ */
520
523
  delete(runtime) {
521
524
  switch (this._mode) {
522
525
  case 0:
@@ -593,6 +596,9 @@ class RuntimeSpecMap {
593
596
  exports.RuntimeSpecMap = RuntimeSpecMap;
594
597
 
595
598
  class RuntimeSpecSet {
599
+ /**
600
+ * @param {Iterable<RuntimeSpec>=} iterable iterable
601
+ */
596
602
  constructor(iterable) {
597
603
  /** @type {Map<string, RuntimeSpec>} */
598
604
  this._map = new Map();
@@ -603,10 +609,17 @@ class RuntimeSpecSet {
603
609
  }
604
610
  }
605
611
 
612
+ /**
613
+ * @param {RuntimeSpec} runtime runtime
614
+ */
606
615
  add(runtime) {
607
616
  this._map.set(getRuntimeKey(runtime), runtime);
608
617
  }
609
618
 
619
+ /**
620
+ * @param {RuntimeSpec} runtime runtime
621
+ * @returns {boolean} true, when the runtime exists
622
+ */
610
623
  has(runtime) {
611
624
  return this._map.has(getRuntimeKey(runtime));
612
625
  }
@@ -110,7 +110,7 @@ const smartGrouping = (items, groupConfigs) => {
110
110
  /** @type {(T | R)[]} */
111
111
  const results = [];
112
112
  for (;;) {
113
- /** @type {Group<T, R>} */
113
+ /** @type {Group<T, R> | undefined} */
114
114
  let bestGroup = undefined;
115
115
  let bestGroupSize = -1;
116
116
  let bestGroupItems = undefined;
@@ -119,7 +119,9 @@ const validateSchema = (schema, options, validationConfiguration) => {
119
119
  )
120
120
  ) {
121
121
  return `${formattedError}\nDid you mean ${
122
- DID_YOU_MEAN[params.additionalProperty]
122
+ DID_YOU_MEAN[
123
+ /** @type {keyof DID_YOU_MEAN} */ (params.additionalProperty)
124
+ ]
123
125
  }?`;
124
126
  }
125
127
 
@@ -129,7 +131,9 @@ const validateSchema = (schema, options, validationConfiguration) => {
129
131
  params.additionalProperty
130
132
  )
131
133
  ) {
132
- return `${formattedError}\n${REMOVED[params.additionalProperty]}?`;
134
+ return `${formattedError}\n${
135
+ REMOVED[/** @type {keyof REMOVED} */ (params.additionalProperty)]
136
+ }?`;
133
137
  }
134
138
 
135
139
  if (!error.dataPath) {
@@ -9,6 +9,9 @@ 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("../Compilation")} Compilation */
14
+
12
15
  /**
13
16
  * @typedef {Object} AsyncWasmLoadingRuntimeModuleOptions
14
17
  * @property {function(string): string} generateLoadBinaryCode
@@ -26,10 +29,11 @@ class AsyncWasmLoadingRuntimeModule extends RuntimeModule {
26
29
  }
27
30
 
28
31
  /**
29
- * @returns {string} runtime code
32
+ * @returns {string | null} runtime code
30
33
  */
31
34
  generate() {
32
- const { compilation, chunk } = this;
35
+ const compilation = /** @type {Compilation} */ (this.compilation);
36
+ const chunk = /** @type {Chunk} */ (this.chunk);
33
37
  const { outputOptions, runtimeTemplate } = compilation;
34
38
  const fn = RuntimeGlobals.instantiateWasm;
35
39
  const wasmModuleSrcPath = compilation.getPath(
@@ -11,6 +11,8 @@ const Parser = require("../Parser");
11
11
  const StaticExportsDependency = require("../dependencies/StaticExportsDependency");
12
12
  const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency");
13
13
 
14
+ /** @typedef {import("../Module").BuildInfo} BuildInfo */
15
+ /** @typedef {import("../Module").BuildMeta} BuildMeta */
14
16
  /** @typedef {import("../Parser").ParserState} ParserState */
15
17
  /** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
16
18
 
@@ -43,9 +45,11 @@ class WebAssemblyParser extends Parser {
43
45
  }
44
46
 
45
47
  // flag it as async module
46
- state.module.buildInfo.strict = true;
47
- state.module.buildMeta.exportsType = "namespace";
48
- state.module.buildMeta.async = true;
48
+ const buildInfo = /** @type {BuildInfo} */ (state.module.buildInfo);
49
+ buildInfo.strict = true;
50
+ const BuildMeta = /** @type {BuildMeta} */ (state.module.buildMeta);
51
+ BuildMeta.exportsType = "namespace";
52
+ BuildMeta.async = true;
49
53
 
50
54
  // parse it
51
55
  const program = decode(source, decoderOpts);
@@ -10,6 +10,7 @@ const Template = require("../Template");
10
10
  const { compareModulesByIdentifier } = require("../util/comparators");
11
11
  const WebAssemblyUtils = require("./WebAssemblyUtils");
12
12
 
13
+ /** @typedef {import("@webassemblyjs/ast").Signature} Signature */
13
14
  /** @typedef {import("../Chunk")} Chunk */
14
15
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
15
16
  /** @typedef {import("../Compilation")} Compilation */
@@ -91,9 +92,11 @@ const generateImportObject = (
91
92
  value: `${instanceVar}[${JSON.stringify(usedName)}]`
92
93
  });
93
94
  } else {
94
- const params = description.signature.params.map(
95
- (param, k) => "p" + k + param.valtype
96
- );
95
+ const params =
96
+ /** @type {Signature} */
97
+ (description.signature).params.map(
98
+ (param, k) => "p" + k + param.valtype
99
+ );
97
100
 
98
101
  const mod = `${RuntimeGlobals.moduleCache}[${JSON.stringify(
99
102
  chunkGraph.getModuleId(importedModule)
@@ -130,6 +133,7 @@ const generateImportObject = (
130
133
  "};"
131
134
  ];
132
135
  } else {
136
+ /** @type {Map<string, Array<{ name: string, value: string }>>} */
133
137
  const propertiesByModule = new Map();
134
138
  for (const p of properties) {
135
139
  let list = propertiesByModule.get(p.module);
@@ -222,23 +226,26 @@ class WasmChunkLoadingRuntimeModule extends RuntimeModule {
222
226
  }
223
227
 
224
228
  /**
225
- * @returns {string} runtime code
229
+ * @returns {string | null} runtime code
226
230
  */
227
231
  generate() {
228
- const { chunkGraph, compilation, chunk, mangleImports } = this;
229
- const { moduleGraph, outputOptions } = compilation;
230
232
  const fn = RuntimeGlobals.ensureChunkHandlers;
231
233
  const withHmr = this._runtimeRequirements.has(
232
234
  RuntimeGlobals.hmrDownloadUpdateHandlers
233
235
  );
236
+ const compilation = /** @type {Compilation} */ (this.compilation);
237
+ const { moduleGraph, outputOptions } = compilation;
238
+ const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
239
+ const chunk = /** @type {Chunk} */ (this.chunk);
234
240
  const wasmModules = getAllWasmModules(moduleGraph, chunkGraph, chunk);
241
+ const { mangleImports } = this;
235
242
  /** @type {string[]} */
236
243
  const declarations = [];
237
244
  const importObjects = wasmModules.map(module => {
238
245
  return generateImportObject(
239
246
  chunkGraph,
240
247
  module,
241
- this.mangleImports,
248
+ mangleImports,
242
249
  declarations,
243
250
  chunk.runtime
244
251
  );
@@ -11,6 +11,7 @@ const UnsupportedWebAssemblyFeatureError = require("./UnsupportedWebAssemblyFeat
11
11
  /** @typedef {import("../Compiler")} Compiler */
12
12
  /** @typedef {import("../Dependency")} Dependency */
13
13
  /** @typedef {import("../Module")} Module */
14
+ /** @typedef {import("../Module").BuildMeta} BuildMeta */
14
15
 
15
16
  class WasmFinalizeExportsPlugin {
16
17
  /**
@@ -27,7 +28,8 @@ class WasmFinalizeExportsPlugin {
27
28
  // 1. if a WebAssembly module
28
29
  if (module.type.startsWith("webassembly") === true) {
29
30
  const jsIncompatibleExports =
30
- module.buildMeta.jsIncompatibleExports;
31
+ /** @type {BuildMeta} */
32
+ (module.buildMeta).jsIncompatibleExports;
31
33
 
32
34
  if (jsIncompatibleExports === undefined) {
33
35
  continue;
@@ -174,6 +174,7 @@ const createDefaultInitForGlobal = globalType => {
174
174
  */
175
175
  const rewriteImportedGlobals = state => bin => {
176
176
  const additionalInitCode = state.additionalInitCode;
177
+ /** @type {Array<t.Global>} */
177
178
  const newGlobals = [];
178
179
 
179
180
  bin = editWithAST(state.ast, bin, {
@@ -14,6 +14,8 @@ const WebAssemblyExportImportedDependency = require("../dependencies/WebAssembly
14
14
  const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency");
15
15
 
16
16
  /** @typedef {import("../Module")} Module */
17
+ /** @typedef {import("../Module").BuildInfo} BuildInfo */
18
+ /** @typedef {import("../Module").BuildMeta} BuildMeta */
17
19
  /** @typedef {import("../Parser").ParserState} ParserState */
18
20
  /** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
19
21
 
@@ -81,8 +83,10 @@ class WebAssemblyParser extends Parser {
81
83
  }
82
84
 
83
85
  // flag it as ESM
84
- state.module.buildInfo.strict = true;
85
- state.module.buildMeta.exportsType = "namespace";
86
+ /** @type {BuildInfo} */
87
+ (state.module.buildInfo).strict = true;
88
+ /** @type {BuildMeta} */
89
+ (state.module.buildMeta).exportsType = "namespace";
86
90
 
87
91
  // parse it
88
92
  const program = decode(source, decoderOpts);
@@ -14,6 +14,7 @@ const { getInitialChunkIds } = require("../javascript/StartupHelpers");
14
14
  const compileBooleanMatcher = require("../util/compileBooleanMatcher");
15
15
 
16
16
  /** @typedef {import("../Chunk")} Chunk */
17
+ /** @typedef {import("../ChunkGraph")} ChunkGraph */
17
18
 
18
19
  /**
19
20
  * @typedef {Object} JsonpCompilationPluginHooks
@@ -69,10 +70,10 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
69
70
  }
70
71
 
71
72
  /**
72
- * @returns {string} runtime code
73
+ * @returns {string | null} runtime code
73
74
  */
74
75
  generate() {
75
- const { chunkGraph, compilation, chunk } = this;
76
+ const compilation = /** @type {Compilation} */ (this.compilation);
76
77
  const {
77
78
  runtimeTemplate,
78
79
  outputOptions: {
@@ -108,9 +109,14 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
108
109
  const withPreload = this._runtimeRequirements.has(
109
110
  RuntimeGlobals.preloadChunkHandlers
110
111
  );
112
+ const withFetchPriority = this._runtimeRequirements.has(
113
+ RuntimeGlobals.hasFetchPriority
114
+ );
111
115
  const chunkLoadingGlobalExpr = `${globalObject}[${JSON.stringify(
112
116
  chunkLoadingGlobal
113
117
  )}]`;
118
+ const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
119
+ const chunk = /** @type {Chunk} */ (this.chunk);
114
120
  const conditionMap = chunkGraph.getChunkConditionMap(chunk, chunkHasJs);
115
121
  const hasJsMatcher = compileBooleanMatcher(conditionMap);
116
122
  const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs);
@@ -138,7 +144,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
138
144
  withLoading
139
145
  ? Template.asString([
140
146
  `${fn}.j = ${runtimeTemplate.basicFunction(
141
- "chunkId, promises",
147
+ `chunkId, promises${withFetchPriority ? ", fetchPriority" : ""}`,
142
148
  hasJsMatcher !== false
143
149
  ? Template.indent([
144
150
  "// JSONP chunk loading for javascript",
@@ -190,7 +196,11 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
190
196
  "}"
191
197
  ]
192
198
  )};`,
193
- `${RuntimeGlobals.loadScript}(url, loadingEnded, "chunk-" + chunkId, chunkId);`
199
+ `${
200
+ RuntimeGlobals.loadScript
201
+ }(url, loadingEnded, "chunk-" + chunkId, chunkId${
202
+ withFetchPriority ? ", fetchPriority" : ""
203
+ });`
194
204
  ]),
195
205
  hasJsMatcher === true
196
206
  ? "}"
package/lib/webpack.js CHANGED
@@ -61,7 +61,10 @@ const createMultiCompiler = (childOptions, options) => {
61
61
  const createCompiler = rawOptions => {
62
62
  const options = getNormalizedWebpackOptions(rawOptions);
63
63
  applyWebpackOptionsBaseDefaults(options);
64
- const compiler = new Compiler(options.context, options);
64
+ const compiler = new Compiler(
65
+ /** @type {string} */ (options.context),
66
+ options
67
+ );
65
68
  new NodeEnvironmentPlugin({
66
69
  infrastructureLogging: options.infrastructureLogging
67
70
  }).apply(compiler);
@@ -69,7 +72,7 @@ const createCompiler = rawOptions => {
69
72
  for (const plugin of options.plugins) {
70
73
  if (typeof plugin === "function") {
71
74
  plugin.call(compiler, compiler);
72
- } else {
75
+ } else if (plugin) {
73
76
  plugin.apply(compiler);
74
77
  }
75
78
  }
@@ -96,6 +99,11 @@ const createCompiler = rawOptions => {
96
99
  * @returns {MultiCompiler} the multi compiler object
97
100
  */
98
101
 
102
+ /**
103
+ * @template T
104
+ * @param {Array<T> | T} options options
105
+ * @returns {Array<T>} array of options
106
+ */
99
107
  const asArray = options =>
100
108
  Array.isArray(options) ? Array.from(options) : [options];
101
109
 
@@ -117,6 +125,7 @@ const webpack = /** @type {WebpackFunctionSingle & WebpackFunctionMulti} */ (
117
125
  }
118
126
  /** @type {MultiCompiler|Compiler} */
119
127
  let compiler;
128
+ /** @type {boolean | undefined} */
120
129
  let watch = false;
121
130
  /** @type {WatchOptions|WatchOptions[]} */
122
131
  let watchOptions;
@@ -16,6 +16,8 @@ const compileBooleanMatcher = require("../util/compileBooleanMatcher");
16
16
  const { getUndoPath } = require("../util/identifier");
17
17
 
18
18
  /** @typedef {import("../Chunk")} Chunk */
19
+ /** @typedef {import("../ChunkGraph")} ChunkGraph */
20
+ /** @typedef {import("../Compilation")} Compilation */
19
21
 
20
22
  class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
21
23
  /**
@@ -38,8 +40,9 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
38
40
  if (options && options.baseUri) {
39
41
  return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;
40
42
  }
41
- const outputName = this.compilation.getPath(
42
- getChunkFilenameTemplate(chunk, this.compilation.outputOptions),
43
+ const compilation = /** @type {Compilation} */ (this.compilation);
44
+ const outputName = compilation.getPath(
45
+ getChunkFilenameTemplate(chunk, compilation.outputOptions),
43
46
  {
44
47
  chunk,
45
48
  contentHashType: "javascript"
@@ -47,7 +50,7 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
47
50
  );
48
51
  const rootOutputDir = getUndoPath(
49
52
  outputName,
50
- /** @type {string} */ (this.compilation.outputOptions.path),
53
+ /** @type {string} */ (compilation.outputOptions.path),
51
54
  false
52
55
  );
53
56
  return `${RuntimeGlobals.baseURI} = self.location + ${JSON.stringify(
@@ -56,19 +59,10 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
56
59
  }
57
60
 
58
61
  /**
59
- * @returns {string} runtime code
62
+ * @returns {string | null} runtime code
60
63
  */
61
64
  generate() {
62
- const {
63
- chunk,
64
- chunkGraph,
65
- compilation: {
66
- runtimeTemplate,
67
- outputOptions: { chunkLoadingGlobal, hotUpdateGlobal }
68
- },
69
- _withCreateScriptUrl: withCreateScriptUrl
70
- } = this;
71
- const globalObject = runtimeTemplate.globalObject;
65
+ const compilation = /** @type {Compilation} */ (this.compilation);
72
66
  const fn = RuntimeGlobals.ensureChunkHandlers;
73
67
  const withBaseURI = this.runtimeRequirements.has(RuntimeGlobals.baseURI);
74
68
  const withLoading = this.runtimeRequirements.has(
@@ -80,9 +74,12 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
80
74
  const withHmrManifest = this.runtimeRequirements.has(
81
75
  RuntimeGlobals.hmrDownloadManifest
82
76
  );
77
+ const globalObject = compilation.runtimeTemplate.globalObject;
83
78
  const chunkLoadingGlobalExpr = `${globalObject}[${JSON.stringify(
84
- chunkLoadingGlobal
79
+ compilation.outputOptions.chunkLoadingGlobal
85
80
  )}]`;
81
+ const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
82
+ const chunk = /** @type {Chunk} */ (this.chunk);
86
83
  const hasJsMatcher = compileBooleanMatcher(
87
84
  chunkGraph.getChunkConditionMap(chunk, chunkHasJs)
88
85
  );
@@ -91,6 +88,8 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
91
88
  const stateExpression = withHmr
92
89
  ? `${RuntimeGlobals.hmrRuntimeStatePrefix}_importScripts`
93
90
  : undefined;
91
+ const runtimeTemplate = compilation.runtimeTemplate;
92
+ const { _withCreateScriptUrl: withCreateScriptUrl } = this;
94
93
 
95
94
  return Template.asString([
96
95
  withBaseURI ? this._generateBaseUri(chunk) : "// no baseURI",
@@ -169,7 +168,7 @@ class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
169
168
  Template.indent([
170
169
  "var success = false;",
171
170
  `${globalObject}[${JSON.stringify(
172
- hotUpdateGlobal
171
+ compilation.outputOptions.hotUpdateGlobal
173
172
  )}] = ${runtimeTemplate.basicFunction("_, moreModules, runtime", [
174
173
  "for(var moduleId in moreModules) {",
175
174
  Template.indent([
package/module.d.ts CHANGED
@@ -174,6 +174,7 @@ interface ImportMeta {
174
174
  exclude?: RegExp;
175
175
  preload?: boolean | number;
176
176
  prefetch?: boolean | number;
177
+ fetchPriority?: "low" | "high" | "auto";
177
178
  chunkName?: string;
178
179
  exports?: string | string[][];
179
180
  mode?: "sync" | "eager" | "weak" | "lazy" | "lazy-once";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "5.86.0",
3
+ "version": "5.88.0",
4
4
  "author": "Tobias Koppers @sokra",
5
5
  "description": "Packs ECMAScript/CommonJs/AMD modules for the browser. Allows you to split your codebase into multiple bundles, which can be loaded on demand. Supports loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
6
6
  "license": "MIT",
@@ -14,7 +14,7 @@
14
14
  "acorn-import-assertions": "^1.9.0",
15
15
  "browserslist": "^4.14.5",
16
16
  "chrome-trace-event": "^1.0.2",
17
- "enhanced-resolve": "^5.14.1",
17
+ "enhanced-resolve": "^5.15.0",
18
18
  "es-module-lexer": "^1.2.1",
19
19
  "eslint-scope": "5.1.1",
20
20
  "events": "^3.2.0",
@@ -24,7 +24,7 @@
24
24
  "loader-runner": "^4.2.0",
25
25
  "mime-types": "^2.1.27",
26
26
  "neo-async": "^2.6.2",
27
- "schema-utils": "^3.1.2",
27
+ "schema-utils": "^3.2.0",
28
28
  "tapable": "^2.1.1",
29
29
  "terser-webpack-plugin": "^5.3.7",
30
30
  "watchpack": "^2.4.0",
@@ -39,6 +39,7 @@
39
39
  "@babel/core": "^7.21.4",
40
40
  "@babel/preset-react": "^7.18.6",
41
41
  "@types/jest": "^29.5.0",
42
+ "@types/mime-types": "^2.1.1",
42
43
  "@types/node": "^20.1.7",
43
44
  "assemblyscript": "^0.27.2",
44
45
  "babel-loader": "^8.1.0",
@@ -97,7 +98,7 @@
97
98
  "style-loader": "^2.0.0",
98
99
  "terser": "^5.17.0",
99
100
  "toml": "^3.0.0",
100
- "tooling": "webpack/tooling#v1.22.1",
101
+ "tooling": "webpack/tooling#v1.23.0",
101
102
  "ts-loader": "^9.4.2",
102
103
  "typescript": "^5.0.4",
103
104
  "url-loader": "^4.1.0",