webpack 5.85.0 → 5.88.1

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 (249) hide show
  1. package/README.md +5 -2
  2. package/lib/APIPlugin.js +150 -99
  3. package/lib/AsyncDependenciesBlock.js +3 -3
  4. package/lib/BannerPlugin.js +2 -1
  5. package/lib/CaseSensitiveModulesWarning.js +3 -1
  6. package/lib/Chunk.js +35 -17
  7. package/lib/ChunkGraph.js +4 -4
  8. package/lib/ChunkGroup.js +20 -9
  9. package/lib/CompatibilityPlugin.js +50 -30
  10. package/lib/Compilation.js +2 -1
  11. package/lib/Compiler.js +10 -9
  12. package/lib/ConcatenationScope.js +2 -2
  13. package/lib/ConditionalInitFragment.js +11 -1
  14. package/lib/ConstPlugin.js +73 -32
  15. package/lib/ContextModule.js +8 -3
  16. package/lib/ContextModuleFactory.js +1 -0
  17. package/lib/ContextReplacementPlugin.js +13 -0
  18. package/lib/DelegatedModule.js +15 -3
  19. package/lib/DelegatedModuleFactoryPlugin.js +6 -0
  20. package/lib/DependenciesBlock.js +1 -1
  21. package/lib/Dependency.js +11 -5
  22. package/lib/DependencyTemplates.js +1 -1
  23. package/lib/DllEntryPlugin.js +11 -1
  24. package/lib/DllModule.js +6 -0
  25. package/lib/DllReferencePlugin.js +13 -1
  26. package/lib/Entrypoint.js +1 -1
  27. package/lib/ErrorHelpers.js +1 -0
  28. package/lib/EvalSourceMapDevToolPlugin.js +6 -1
  29. package/lib/ExportsInfo.js +22 -4
  30. package/lib/ExportsInfoApiPlugin.js +14 -5
  31. package/lib/ExternalModule.js +20 -8
  32. package/lib/FileSystemInfo.js +52 -24
  33. package/lib/FlagAllModulesAsUsedPlugin.js +6 -1
  34. package/lib/FlagDependencyUsagePlugin.js +3 -1
  35. package/lib/FlagEntryExportAsUsedPlugin.js +4 -0
  36. package/lib/Generator.js +7 -0
  37. package/lib/HotModuleReplacementPlugin.js +8 -0
  38. package/lib/InitFragment.js +28 -5
  39. package/lib/JavascriptMetaInfoPlugin.js +11 -6
  40. package/lib/LibManifestPlugin.js +20 -4
  41. package/lib/Module.js +14 -3
  42. package/lib/ModuleDependencyError.js +4 -2
  43. package/lib/ModuleDependencyWarning.js +4 -2
  44. package/lib/ModuleGraph.js +31 -24
  45. package/lib/ModuleGraphConnection.js +19 -6
  46. package/lib/ModuleInfoHeaderPlugin.js +9 -2
  47. package/lib/ModuleNotFoundError.js +5 -2
  48. package/lib/ModuleProfile.js +1 -0
  49. package/lib/ModuleRestoreError.js +2 -0
  50. package/lib/ModuleStoreError.js +2 -1
  51. package/lib/ModuleTypeConstants.js +7 -0
  52. package/lib/MultiWatching.js +4 -0
  53. package/lib/NodeStuffPlugin.js +32 -6
  54. package/lib/ProgressPlugin.js +71 -15
  55. package/lib/ProvidePlugin.js +13 -4
  56. package/lib/RawModule.js +3 -1
  57. package/lib/RequireJsStuffPlugin.js +7 -0
  58. package/lib/RuntimeGlobals.js +5 -0
  59. package/lib/RuntimeModule.js +3 -3
  60. package/lib/RuntimePlugin.js +6 -3
  61. package/lib/RuntimeTemplate.js +22 -4
  62. package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
  63. package/lib/SourceMapDevToolPlugin.js +7 -2
  64. package/lib/UseStrictPlugin.js +10 -3
  65. package/lib/Watching.js +62 -25
  66. package/lib/WebpackError.js +6 -5
  67. package/lib/WebpackIsIncludedPlugin.js +6 -4
  68. package/lib/WebpackOptionsApply.js +4 -2
  69. package/lib/WebpackOptionsDefaulter.js +10 -3
  70. package/lib/asset/AssetGenerator.js +2 -1
  71. package/lib/asset/AssetParser.js +11 -6
  72. package/lib/asset/AssetSourceParser.js +8 -3
  73. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -0
  74. package/lib/buildChunkGraph.js +37 -21
  75. package/lib/cache/IdleFileCachePlugin.js +2 -1
  76. package/lib/cache/PackFileCacheStrategy.js +53 -22
  77. package/lib/config/browserslistTargetHandler.js +7 -7
  78. package/lib/config/defaults.js +43 -26
  79. package/lib/container/RemoteRuntimeModule.js +1 -1
  80. package/lib/css/CssExportsGenerator.js +9 -0
  81. package/lib/css/CssGenerator.js +1 -1
  82. package/lib/css/CssLoadingRuntimeModule.js +43 -19
  83. package/lib/css/CssModulesPlugin.js +42 -14
  84. package/lib/css/CssParser.js +22 -0
  85. package/lib/dependencies/AMDDefineDependency.js +34 -4
  86. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +5 -0
  87. package/lib/dependencies/AMDRuntimeModules.js +2 -2
  88. package/lib/dependencies/CommonJsExportsParserPlugin.js +14 -4
  89. package/lib/dependencies/CommonJsImportsParserPlugin.js +169 -59
  90. package/lib/dependencies/CommonJsPlugin.js +13 -8
  91. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
  92. package/lib/dependencies/ConstDependency.js +2 -2
  93. package/lib/dependencies/ContextDependency.js +7 -2
  94. package/lib/dependencies/CssImportDependency.js +1 -1
  95. package/lib/dependencies/CssLocalIdentifierDependency.js +5 -0
  96. package/lib/dependencies/CssUrlDependency.js +3 -3
  97. package/lib/dependencies/DllEntryDependency.js +5 -0
  98. package/lib/dependencies/DynamicExports.js +10 -6
  99. package/lib/dependencies/ExportsInfoDependency.js +14 -4
  100. package/lib/dependencies/HarmonyCompatibilityDependency.js +2 -1
  101. package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -1
  102. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -5
  103. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +2 -0
  104. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +4 -4
  105. package/lib/dependencies/HarmonyExports.js +9 -5
  106. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +40 -27
  107. package/lib/dependencies/HarmonyImportSideEffectDependency.js +1 -2
  108. package/lib/dependencies/HarmonyImportSpecifierDependency.js +31 -21
  109. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
  110. package/lib/dependencies/ImportDependency.js +5 -3
  111. package/lib/dependencies/ImportEagerDependency.js +5 -3
  112. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +19 -0
  113. package/lib/dependencies/ImportMetaPlugin.js +31 -15
  114. package/lib/dependencies/ImportParserPlugin.js +62 -25
  115. package/lib/dependencies/ImportWeakDependency.js +5 -3
  116. package/lib/dependencies/JsonExportsDependency.js +1 -1
  117. package/lib/dependencies/ModuleDependency.js +1 -1
  118. package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
  119. package/lib/dependencies/ProvidedDependency.js +4 -1
  120. package/lib/dependencies/RequireContextDependencyParserPlugin.js +13 -5
  121. package/lib/dependencies/RequireEnsureDependenciesBlock.js +5 -2
  122. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +6 -1
  123. package/lib/dependencies/RequireHeaderDependency.js +4 -0
  124. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +26 -5
  125. package/lib/dependencies/RequireResolveHeaderDependency.js +9 -0
  126. package/lib/dependencies/SystemPlugin.js +17 -5
  127. package/lib/dependencies/SystemRuntimeModule.js +1 -1
  128. package/lib/dependencies/URLDependency.js +2 -2
  129. package/lib/dependencies/URLPlugin.js +9 -4
  130. package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
  131. package/lib/dependencies/WorkerPlugin.js +59 -22
  132. package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -1
  133. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
  134. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  135. package/lib/ids/HashedModuleIdsPlugin.js +1 -1
  136. package/lib/ids/SyncModuleIdsPlugin.js +1 -0
  137. package/lib/javascript/BasicEvaluatedExpression.js +28 -19
  138. package/lib/javascript/CommonJsChunkFormatPlugin.js +6 -2
  139. package/lib/javascript/JavascriptModulesPlugin.js +25 -5
  140. package/lib/javascript/JavascriptParser.js +157 -85
  141. package/lib/javascript/JavascriptParserHelpers.js +37 -15
  142. package/lib/json/JsonData.js +2 -2
  143. package/lib/json/JsonParser.js +25 -12
  144. package/lib/library/AmdLibraryPlugin.js +2 -2
  145. package/lib/library/AssignLibraryPlugin.js +13 -1
  146. package/lib/library/EnableLibraryPlugin.js +4 -0
  147. package/lib/library/SystemLibraryPlugin.js +1 -1
  148. package/lib/library/UmdLibraryPlugin.js +20 -2
  149. package/lib/logging/runtime.js +1 -1
  150. package/lib/logging/truncateArgs.js +4 -0
  151. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -6
  152. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -1
  153. package/lib/node/RequireChunkLoadingRuntimeModule.js +10 -6
  154. package/lib/optimize/AggressiveMergingPlugin.js +8 -0
  155. package/lib/optimize/AggressiveSplittingPlugin.js +9 -2
  156. package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -0
  157. package/lib/optimize/FlagIncludedChunksPlugin.js +11 -5
  158. package/lib/optimize/InnerGraph.js +5 -5
  159. package/lib/optimize/InnerGraphPlugin.js +2 -1
  160. package/lib/optimize/LimitChunkCountPlugin.js +29 -4
  161. package/lib/optimize/MangleExportsPlugin.js +1 -1
  162. package/lib/optimize/MinMaxSizeWarning.js +5 -0
  163. package/lib/optimize/ModuleConcatenationPlugin.js +59 -2
  164. package/lib/optimize/RealContentHashPlugin.js +80 -30
  165. package/lib/optimize/RemoveParentModulesPlugin.js +6 -0
  166. package/lib/optimize/RuntimeChunkPlugin.js +9 -1
  167. package/lib/optimize/SideEffectsFlagPlugin.js +10 -1
  168. package/lib/optimize/SplitChunksPlugin.js +71 -31
  169. package/lib/performance/SizeLimitsPlugin.js +7 -4
  170. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +4 -2
  171. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
  172. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +6 -3
  173. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -2
  174. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +4 -2
  175. package/lib/rules/BasicEffectRulePlugin.js +4 -0
  176. package/lib/rules/BasicMatcherRulePlugin.js +5 -0
  177. package/lib/rules/RuleSetCompiler.js +3 -3
  178. package/lib/rules/UseEffectRulePlugin.js +6 -4
  179. package/lib/runtime/AsyncModuleRuntimeModule.js +8 -5
  180. package/lib/runtime/AutoPublicPathRuntimeModule.js +4 -2
  181. package/lib/runtime/BaseUriRuntimeModule.js +3 -3
  182. package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
  183. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +5 -2
  184. package/lib/runtime/CompatRuntimeModule.js +7 -2
  185. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +5 -2
  186. package/lib/runtime/CreateScriptRuntimeModule.js +4 -2
  187. package/lib/runtime/CreateScriptUrlRuntimeModule.js +4 -2
  188. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +5 -2
  189. package/lib/runtime/EnsureChunkRuntimeModule.js +15 -4
  190. package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -10
  191. package/lib/runtime/GetFullHashRuntimeModule.js +4 -3
  192. package/lib/runtime/GetMainFilenameRuntimeModule.js +5 -2
  193. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +4 -2
  194. package/lib/runtime/GlobalRuntimeModule.js +1 -1
  195. package/lib/runtime/HasOwnPropertyRuntimeModule.js +5 -2
  196. package/lib/runtime/LoadScriptRuntimeModule.js +64 -48
  197. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +5 -2
  198. package/lib/runtime/NonceRuntimeModule.js +1 -1
  199. package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -2
  200. package/lib/runtime/PublicPathRuntimeModule.js +4 -2
  201. package/lib/runtime/RelativeUrlRuntimeModule.js +5 -2
  202. package/lib/runtime/RuntimeIdRuntimeModule.js +6 -2
  203. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -3
  204. package/lib/runtime/StartupEntrypointRuntimeModule.js +3 -2
  205. package/lib/runtime/SystemContextRuntimeModule.js +1 -1
  206. package/lib/serialization/BinaryMiddleware.js +143 -1
  207. package/lib/serialization/ErrorObjectSerializer.js +3 -0
  208. package/lib/serialization/ObjectMiddleware.js +9 -3
  209. package/lib/serialization/types.js +1 -1
  210. package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
  211. package/lib/sharing/ConsumeSharedRuntimeModule.js +14 -5
  212. package/lib/sharing/ProvideSharedDependency.js +11 -0
  213. package/lib/sharing/ProvideSharedModule.js +4 -0
  214. package/lib/sharing/ProvideSharedPlugin.js +22 -21
  215. package/lib/sharing/ShareRuntimeModule.js +12 -5
  216. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  217. package/lib/sharing/utils.js +32 -5
  218. package/lib/util/AsyncQueue.js +4 -2
  219. package/lib/util/ParallelismFactorCalculator.js +10 -0
  220. package/lib/util/Semaphore.js +1 -1
  221. package/lib/util/StackedCacheMap.js +1 -1
  222. package/lib/util/URLAbsoluteSpecifier.js +1 -1
  223. package/lib/util/createHash.js +30 -9
  224. package/lib/util/deprecation.js +10 -3
  225. package/lib/util/deterministicGrouping.js +50 -11
  226. package/lib/util/findGraphRoots.js +4 -2
  227. package/lib/util/memoize.js +3 -3
  228. package/lib/util/processAsyncTree.js +7 -1
  229. package/lib/util/registerExternalSerializer.js +1 -1
  230. package/lib/util/runtime.js +84 -21
  231. package/lib/util/semver.js +1 -0
  232. package/lib/util/smartGrouping.js +1 -1
  233. package/lib/validateSchema.js +6 -2
  234. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +6 -2
  235. package/lib/wasm-async/AsyncWebAssemblyParser.js +7 -3
  236. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +14 -7
  237. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +3 -1
  238. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
  239. package/lib/wasm-sync/WebAssemblyParser.js +6 -2
  240. package/lib/web/JsonpChunkLoadingRuntimeModule.js +14 -4
  241. package/lib/webpack.js +11 -2
  242. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +15 -16
  243. package/module.d.ts +1 -0
  244. package/package.json +5 -4
  245. package/schemas/WebpackOptions.check.js +1 -1
  246. package/schemas/WebpackOptions.json +52 -6
  247. package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
  248. package/schemas/plugins/css/CssParserOptions.json +1 -1
  249. package/types.d.ts +606 -292
@@ -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.85.0",
3
+ "version": "5.88.1",
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",