webpack 5.85.1 → 5.87.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


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

Files changed (140) hide show
  1. package/README.md +5 -2
  2. package/lib/APIPlugin.js +150 -99
  3. package/lib/CaseSensitiveModulesWarning.js +3 -1
  4. package/lib/Chunk.js +35 -17
  5. package/lib/ChunkGroup.js +11 -6
  6. package/lib/Compiler.js +4 -3
  7. package/lib/ConcatenationScope.js +2 -2
  8. package/lib/ConditionalInitFragment.js +11 -1
  9. package/lib/ConstPlugin.js +57 -29
  10. package/lib/ContextModule.js +4 -2
  11. package/lib/ContextModuleFactory.js +1 -0
  12. package/lib/DependenciesBlock.js +1 -1
  13. package/lib/DllModule.js +6 -0
  14. package/lib/EvalSourceMapDevToolPlugin.js +2 -1
  15. package/lib/ExternalModule.js +15 -8
  16. package/lib/FlagEntryExportAsUsedPlugin.js +4 -0
  17. package/lib/Module.js +7 -1
  18. package/lib/ModuleDependencyError.js +4 -2
  19. package/lib/ModuleDependencyWarning.js +4 -2
  20. package/lib/ModuleGraph.js +31 -24
  21. package/lib/ModuleGraphConnection.js +19 -6
  22. package/lib/ModuleInfoHeaderPlugin.js +9 -2
  23. package/lib/ModuleNotFoundError.js +5 -2
  24. package/lib/ModuleStoreError.js +2 -1
  25. package/lib/ModuleTypeConstants.js +7 -0
  26. package/lib/MultiWatching.js +4 -0
  27. package/lib/ProgressPlugin.js +71 -15
  28. package/lib/RuntimeGlobals.js +5 -0
  29. package/lib/RuntimePlugin.js +2 -1
  30. package/lib/RuntimeTemplate.js +20 -2
  31. package/lib/WebpackError.js +6 -5
  32. package/lib/WebpackOptionsApply.js +4 -2
  33. package/lib/WebpackOptionsDefaulter.js +10 -3
  34. package/lib/config/defaults.js +31 -2
  35. package/lib/css/CssExportsGenerator.js +9 -0
  36. package/lib/css/CssGenerator.js +1 -1
  37. package/lib/css/CssLoadingRuntimeModule.js +13 -6
  38. package/lib/css/CssModulesPlugin.js +42 -14
  39. package/lib/css/CssParser.js +12 -0
  40. package/lib/dependencies/ConstDependency.js +2 -2
  41. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +19 -0
  42. package/lib/dependencies/ImportParserPlugin.js +25 -1
  43. package/lib/dependencies/JsonExportsDependency.js +1 -1
  44. package/lib/ids/SyncModuleIdsPlugin.js +1 -0
  45. package/lib/javascript/BasicEvaluatedExpression.js +23 -15
  46. package/lib/javascript/CommonJsChunkFormatPlugin.js +6 -2
  47. package/lib/javascript/JavascriptModulesPlugin.js +1 -0
  48. package/lib/javascript/JavascriptParser.js +118 -58
  49. package/lib/javascript/JavascriptParserHelpers.js +37 -15
  50. package/lib/json/JsonData.js +2 -2
  51. package/lib/json/JsonParser.js +25 -12
  52. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -1
  53. package/lib/optimize/AggressiveMergingPlugin.js +8 -0
  54. package/lib/optimize/AggressiveSplittingPlugin.js +9 -2
  55. package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -0
  56. package/lib/optimize/FlagIncludedChunksPlugin.js +11 -5
  57. package/lib/optimize/InnerGraph.js +4 -4
  58. package/lib/optimize/LimitChunkCountPlugin.js +29 -4
  59. package/lib/optimize/MangleExportsPlugin.js +1 -1
  60. package/lib/optimize/MinMaxSizeWarning.js +5 -0
  61. package/lib/optimize/ModuleConcatenationPlugin.js +59 -2
  62. package/lib/optimize/RealContentHashPlugin.js +80 -30
  63. package/lib/optimize/RemoveParentModulesPlugin.js +6 -0
  64. package/lib/optimize/RuntimeChunkPlugin.js +9 -1
  65. package/lib/optimize/SideEffectsFlagPlugin.js +10 -1
  66. package/lib/optimize/SplitChunksPlugin.js +71 -31
  67. package/lib/performance/SizeLimitsPlugin.js +7 -4
  68. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +3 -1
  69. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
  70. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +5 -2
  71. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +3 -1
  72. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +3 -1
  73. package/lib/rules/BasicEffectRulePlugin.js +4 -0
  74. package/lib/rules/BasicMatcherRulePlugin.js +5 -0
  75. package/lib/rules/RuleSetCompiler.js +3 -3
  76. package/lib/rules/UseEffectRulePlugin.js +6 -4
  77. package/lib/runtime/AsyncModuleRuntimeModule.js +4 -1
  78. package/lib/runtime/AutoPublicPathRuntimeModule.js +3 -1
  79. package/lib/runtime/BaseUriRuntimeModule.js +2 -2
  80. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +4 -1
  81. package/lib/runtime/CompatRuntimeModule.js +6 -1
  82. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +4 -1
  83. package/lib/runtime/CreateScriptRuntimeModule.js +3 -1
  84. package/lib/runtime/CreateScriptUrlRuntimeModule.js +3 -1
  85. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +4 -1
  86. package/lib/runtime/EnsureChunkRuntimeModule.js +14 -3
  87. package/lib/runtime/GetChunkFilenameRuntimeModule.js +5 -9
  88. package/lib/runtime/GetFullHashRuntimeModule.js +3 -2
  89. package/lib/runtime/GetMainFilenameRuntimeModule.js +4 -1
  90. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +3 -1
  91. package/lib/runtime/HasOwnPropertyRuntimeModule.js +4 -1
  92. package/lib/runtime/LoadScriptRuntimeModule.js +63 -47
  93. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +4 -1
  94. package/lib/runtime/OnChunksLoadedRuntimeModule.js +3 -1
  95. package/lib/runtime/PublicPathRuntimeModule.js +3 -1
  96. package/lib/runtime/RelativeUrlRuntimeModule.js +4 -1
  97. package/lib/runtime/RuntimeIdRuntimeModule.js +5 -1
  98. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +8 -2
  99. package/lib/runtime/StartupEntrypointRuntimeModule.js +2 -1
  100. package/lib/serialization/BinaryMiddleware.js +143 -1
  101. package/lib/serialization/ErrorObjectSerializer.js +3 -0
  102. package/lib/serialization/ObjectMiddleware.js +9 -3
  103. package/lib/serialization/types.js +1 -1
  104. package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
  105. package/lib/sharing/ConsumeSharedRuntimeModule.js +13 -4
  106. package/lib/sharing/ProvideSharedDependency.js +11 -0
  107. package/lib/sharing/ProvideSharedModule.js +4 -0
  108. package/lib/sharing/ProvideSharedPlugin.js +22 -21
  109. package/lib/sharing/ShareRuntimeModule.js +11 -4
  110. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  111. package/lib/sharing/utils.js +32 -5
  112. package/lib/util/AsyncQueue.js +4 -2
  113. package/lib/util/ParallelismFactorCalculator.js +10 -0
  114. package/lib/util/Semaphore.js +1 -1
  115. package/lib/util/createHash.js +30 -9
  116. package/lib/util/deprecation.js +10 -3
  117. package/lib/util/deterministicGrouping.js +50 -11
  118. package/lib/util/findGraphRoots.js +4 -2
  119. package/lib/util/memoize.js +3 -3
  120. package/lib/util/processAsyncTree.js +7 -1
  121. package/lib/util/registerExternalSerializer.js +1 -1
  122. package/lib/util/runtime.js +14 -1
  123. package/lib/util/smartGrouping.js +1 -1
  124. package/lib/validateSchema.js +6 -2
  125. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +5 -1
  126. package/lib/wasm-async/AsyncWebAssemblyParser.js +7 -3
  127. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +13 -6
  128. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +3 -1
  129. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
  130. package/lib/wasm-sync/WebAssemblyParser.js +6 -2
  131. package/lib/web/JsonpChunkLoadingRuntimeModule.js +13 -3
  132. package/lib/webpack.js +11 -2
  133. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +14 -15
  134. package/module.d.ts +1 -0
  135. package/package.json +4 -4
  136. package/schemas/WebpackOptions.check.js +1 -1
  137. package/schemas/WebpackOptions.json +51 -5
  138. package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
  139. package/schemas/plugins/css/CssParserOptions.json +1 -1
  140. package/types.d.ts +476 -218
@@ -8,6 +8,7 @@ const RuntimeGlobals = require("../RuntimeGlobals");
8
8
  const RuntimeModule = require("../RuntimeModule");
9
9
  const Template = require("../Template");
10
10
 
11
+ /** @typedef {import("../Compilation")} Compilation */
11
12
  /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
12
13
 
13
14
  class ChunkPreloadTriggerRuntimeModule extends RuntimeModule {
@@ -24,7 +25,8 @@ class ChunkPreloadTriggerRuntimeModule extends RuntimeModule {
24
25
  */
25
26
  generate() {
26
27
  const { chunkMap } = this;
27
- const { runtimeTemplate } = this.compilation;
28
+ const compilation = /** @type {Compilation} */ (this.compilation);
29
+ const { runtimeTemplate } = compilation;
28
30
  const body = [
29
31
  "var chunks = chunkToChildrenMap[chunkId];",
30
32
  `Array.isArray(chunks) && chunks.map(${RuntimeGlobals.preloadChunk});`
@@ -8,6 +8,10 @@
8
8
  /** @typedef {import("./RuleSetCompiler")} RuleSetCompiler */
9
9
 
10
10
  class BasicEffectRulePlugin {
11
+ /**
12
+ * @param {string} ruleProperty the rule property
13
+ * @param {string=} effectType the effect type
14
+ */
11
15
  constructor(ruleProperty, effectType) {
12
16
  this.ruleProperty = ruleProperty;
13
17
  this.effectType = effectType || ruleProperty;
@@ -9,6 +9,11 @@
9
9
  /** @typedef {import("./RuleSetCompiler").RuleCondition} RuleCondition */
10
10
 
11
11
  class BasicMatcherRulePlugin {
12
+ /**
13
+ * @param {string} ruleProperty the rule property
14
+ * @param {string=} dataProperty the data property
15
+ * @param {boolean=} invert if true, inverts the condition
16
+ */
12
17
  constructor(ruleProperty, dataProperty, invert) {
13
18
  this.ruleProperty = ruleProperty;
14
19
  this.dataProperty = dataProperty || ruleProperty;
@@ -150,9 +150,9 @@ class RuleSetCompiler {
150
150
  * @returns {CompiledRule[]} rules
151
151
  */
152
152
  compileRules(path, rules, refs) {
153
- return rules.map((rule, i) =>
154
- this.compileRule(`${path}[${i}]`, rule, refs)
155
- );
153
+ return rules
154
+ .filter(Boolean)
155
+ .map((rule, i) => this.compileRule(`${path}[${i}]`, rule, refs));
156
156
  }
157
157
 
158
158
  /**
@@ -106,9 +106,11 @@ class UseEffectRulePlugin {
106
106
  */
107
107
  const useToEffectsWithoutIdent = (path, items) => {
108
108
  if (Array.isArray(items)) {
109
- return items.map((item, idx) =>
110
- useToEffectRaw(`${path}[${idx}]`, "[[missing ident]]", item)
111
- );
109
+ return items
110
+ .filter(Boolean)
111
+ .map((item, idx) =>
112
+ useToEffectRaw(`${path}[${idx}]`, "[[missing ident]]", item)
113
+ );
112
114
  }
113
115
  return [useToEffectRaw(path, "[[missing ident]]", items)];
114
116
  };
@@ -120,7 +122,7 @@ class UseEffectRulePlugin {
120
122
  */
121
123
  const useToEffects = (path, items) => {
122
124
  if (Array.isArray(items)) {
123
- return items.map((item, idx) => {
125
+ return items.filter(Boolean).map((item, idx) => {
124
126
  const subPath = `${path}[${idx}]`;
125
127
  return useToEffect(subPath, subPath, item);
126
128
  });
@@ -8,6 +8,8 @@ const RuntimeGlobals = require("../RuntimeGlobals");
8
8
  const Template = require("../Template");
9
9
  const HelperRuntimeModule = require("./HelperRuntimeModule");
10
10
 
11
+ /** @typedef {import("../Compilation")} Compilation */
12
+
11
13
  class AsyncModuleRuntimeModule extends HelperRuntimeModule {
12
14
  constructor() {
13
15
  super("async module");
@@ -17,7 +19,8 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
17
19
  * @returns {string} runtime code
18
20
  */
19
21
  generate() {
20
- const { runtimeTemplate } = this.compilation;
22
+ const compilation = /** @type {Compilation} */ (this.compilation);
23
+ const { runtimeTemplate } = compilation;
21
24
  const fn = RuntimeGlobals.asyncModule;
22
25
  return Template.asString([
23
26
  'var webpackQueues = typeof Symbol === "function" ? Symbol("webpack queues") : "__webpack_queues__";',
@@ -10,6 +10,8 @@ const Template = require("../Template");
10
10
  const JavascriptModulesPlugin = require("../javascript/JavascriptModulesPlugin");
11
11
  const { getUndoPath } = require("../util/identifier");
12
12
 
13
+ /** @typedef {import("../Compilation")} Compilation */
14
+
13
15
  class AutoPublicPathRuntimeModule extends RuntimeModule {
14
16
  constructor() {
15
17
  super("publicPath", RuntimeModule.STAGE_BASIC);
@@ -19,7 +21,7 @@ class AutoPublicPathRuntimeModule extends RuntimeModule {
19
21
  * @returns {string} runtime code
20
22
  */
21
23
  generate() {
22
- const { compilation } = this;
24
+ const compilation = /** @type {Compilation} */ (this.compilation);
23
25
  const { scriptType, importMetaName, path } = compilation.outputOptions;
24
26
  const chunkName = compilation.getPath(
25
27
  JavascriptModulesPlugin.getChunkFilenameTemplate(
@@ -9,6 +9,7 @@ const RuntimeGlobals = require("../RuntimeGlobals");
9
9
  const RuntimeModule = require("../RuntimeModule");
10
10
 
11
11
  /** @typedef {import("../../declarations/WebpackOptions").EntryDescriptionNormalized} EntryDescriptionNormalized */
12
+ /** @typedef {import("../Chunk")} Chunk */
12
13
 
13
14
  class BaseUriRuntimeModule extends RuntimeModule {
14
15
  constructor() {
@@ -19,8 +20,7 @@ class BaseUriRuntimeModule extends RuntimeModule {
19
20
  * @returns {string} runtime code
20
21
  */
21
22
  generate() {
22
- const { chunk } = this;
23
-
23
+ const chunk = /** @type {Chunk} */ (this.chunk);
24
24
  const options =
25
25
  /** @type {EntryDescriptionNormalized} */
26
26
  (chunk.getEntryOptions());
@@ -8,6 +8,8 @@ const RuntimeGlobals = require("../RuntimeGlobals");
8
8
  const Template = require("../Template");
9
9
  const HelperRuntimeModule = require("./HelperRuntimeModule");
10
10
 
11
+ /** @typedef {import("../Compilation")} Compilation */
12
+
11
13
  class CompatGetDefaultExportRuntimeModule extends HelperRuntimeModule {
12
14
  constructor() {
13
15
  super("compat get default export");
@@ -17,7 +19,8 @@ class CompatGetDefaultExportRuntimeModule extends HelperRuntimeModule {
17
19
  * @returns {string} runtime code
18
20
  */
19
21
  generate() {
20
- const { runtimeTemplate } = this.compilation;
22
+ const compilation = /** @type {Compilation} */ (this.compilation);
23
+ const { runtimeTemplate } = compilation;
21
24
  const fn = RuntimeGlobals.compatGetDefaultExport;
22
25
  return Template.asString([
23
26
  "// getDefaultExport function for compatibility with non-harmony modules",
@@ -7,6 +7,9 @@
7
7
  const RuntimeGlobals = require("../RuntimeGlobals");
8
8
  const RuntimeModule = require("../RuntimeModule");
9
9
 
10
+ /** @typedef {import("../Chunk")} Chunk */
11
+ /** @typedef {import("../ChunkGraph")} ChunkGraph */
12
+ /** @typedef {import("../Compilation")} Compilation */
10
13
  /** @typedef {import("../MainTemplate")} MainTemplate */
11
14
 
12
15
  class CompatRuntimeModule extends RuntimeModule {
@@ -19,7 +22,9 @@ class CompatRuntimeModule extends RuntimeModule {
19
22
  * @returns {string} runtime code
20
23
  */
21
24
  generate() {
22
- const { chunkGraph, chunk, compilation } = this;
25
+ const compilation = /** @type {Compilation} */ (this.compilation);
26
+ const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
27
+ const chunk = /** @type {Chunk} */ (this.chunk);
23
28
  const {
24
29
  runtimeTemplate,
25
30
  mainTemplate,
@@ -8,6 +8,8 @@ const RuntimeGlobals = require("../RuntimeGlobals");
8
8
  const Template = require("../Template");
9
9
  const HelperRuntimeModule = require("./HelperRuntimeModule");
10
10
 
11
+ /** @typedef {import("../Compilation")} Compilation */
12
+
11
13
  class CreateFakeNamespaceObjectRuntimeModule extends HelperRuntimeModule {
12
14
  constructor() {
13
15
  super("create fake namespace object");
@@ -17,7 +19,8 @@ class CreateFakeNamespaceObjectRuntimeModule extends HelperRuntimeModule {
17
19
  * @returns {string} runtime code
18
20
  */
19
21
  generate() {
20
- const { runtimeTemplate } = this.compilation;
22
+ const compilation = /** @type {Compilation} */ (this.compilation);
23
+ const { runtimeTemplate } = compilation;
21
24
  const fn = RuntimeGlobals.createFakeNamespaceObject;
22
25
  return Template.asString([
23
26
  `var getProto = Object.getPrototypeOf ? ${runtimeTemplate.returningFunction(
@@ -8,6 +8,8 @@ const RuntimeGlobals = require("../RuntimeGlobals");
8
8
  const Template = require("../Template");
9
9
  const HelperRuntimeModule = require("./HelperRuntimeModule");
10
10
 
11
+ /** @typedef {import("../Compilation")} Compilation */
12
+
11
13
  class CreateScriptRuntimeModule extends HelperRuntimeModule {
12
14
  constructor() {
13
15
  super("trusted types script");
@@ -17,7 +19,7 @@ class CreateScriptRuntimeModule extends HelperRuntimeModule {
17
19
  * @returns {string} runtime code
18
20
  */
19
21
  generate() {
20
- const { compilation } = this;
22
+ const compilation = /** @type {Compilation} */ (this.compilation);
21
23
  const { runtimeTemplate, outputOptions } = compilation;
22
24
  const { trustedTypes } = outputOptions;
23
25
  const fn = RuntimeGlobals.createScript;
@@ -8,6 +8,8 @@ const RuntimeGlobals = require("../RuntimeGlobals");
8
8
  const Template = require("../Template");
9
9
  const HelperRuntimeModule = require("./HelperRuntimeModule");
10
10
 
11
+ /** @typedef {import("../Compilation")} Compilation */
12
+
11
13
  class CreateScriptUrlRuntimeModule extends HelperRuntimeModule {
12
14
  constructor() {
13
15
  super("trusted types script url");
@@ -17,7 +19,7 @@ class CreateScriptUrlRuntimeModule extends HelperRuntimeModule {
17
19
  * @returns {string} runtime code
18
20
  */
19
21
  generate() {
20
- const { compilation } = this;
22
+ const compilation = /** @type {Compilation} */ (this.compilation);
21
23
  const { runtimeTemplate, outputOptions } = compilation;
22
24
  const { trustedTypes } = outputOptions;
23
25
  const fn = RuntimeGlobals.createScriptUrl;
@@ -8,6 +8,8 @@ const RuntimeGlobals = require("../RuntimeGlobals");
8
8
  const Template = require("../Template");
9
9
  const HelperRuntimeModule = require("./HelperRuntimeModule");
10
10
 
11
+ /** @typedef {import("../Compilation")} Compilation */
12
+
11
13
  class DefinePropertyGettersRuntimeModule extends HelperRuntimeModule {
12
14
  constructor() {
13
15
  super("define property getters");
@@ -17,7 +19,8 @@ class DefinePropertyGettersRuntimeModule extends HelperRuntimeModule {
17
19
  * @returns {string} runtime code
18
20
  */
19
21
  generate() {
20
- const { runtimeTemplate } = this.compilation;
22
+ const compilation = /** @type {Compilation} */ (this.compilation);
23
+ const { runtimeTemplate } = compilation;
21
24
  const fn = RuntimeGlobals.definePropertyGetters;
22
25
  return Template.asString([
23
26
  "// define getter functions for harmony exports",
@@ -8,6 +8,8 @@ const RuntimeGlobals = require("../RuntimeGlobals");
8
8
  const RuntimeModule = require("../RuntimeModule");
9
9
  const Template = require("../Template");
10
10
 
11
+ /** @typedef {import("../Compilation")} Compilation */
12
+
11
13
  class EnsureChunkRuntimeModule extends RuntimeModule {
12
14
  /**
13
15
  * @param {ReadonlySet<string>} runtimeRequirements runtime requirements
@@ -21,20 +23,29 @@ class EnsureChunkRuntimeModule extends RuntimeModule {
21
23
  * @returns {string} runtime code
22
24
  */
23
25
  generate() {
24
- const { runtimeTemplate } = this.compilation;
26
+ const compilation = /** @type {Compilation} */ (this.compilation);
27
+ const { runtimeTemplate } = compilation;
25
28
  // Check if there are non initial chunks which need to be imported using require-ensure
26
29
  if (this.runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers)) {
30
+ const withFetchPriority = this.runtimeRequirements.has(
31
+ RuntimeGlobals.hasFetchPriority
32
+ );
27
33
  const handlers = RuntimeGlobals.ensureChunkHandlers;
28
34
  return Template.asString([
29
35
  `${handlers} = {};`,
30
36
  "// This file contains only the entry chunk.",
31
37
  "// The chunk loading function for additional chunks",
32
38
  `${RuntimeGlobals.ensureChunk} = ${runtimeTemplate.basicFunction(
33
- "chunkId",
39
+ `chunkId${withFetchPriority ? ", fetchPriority" : ""}`,
34
40
  [
35
41
  `return Promise.all(Object.keys(${handlers}).reduce(${runtimeTemplate.basicFunction(
36
42
  "promises, key",
37
- [`${handlers}[key](chunkId, promises);`, "return promises;"]
43
+ [
44
+ `${handlers}[key](chunkId, promises${
45
+ withFetchPriority ? ", fetchPriority" : ""
46
+ });`,
47
+ "return promises;"
48
+ ]
38
49
  )}, []));`
39
50
  ]
40
51
  )};`
@@ -10,6 +10,7 @@ const Template = require("../Template");
10
10
  const { first } = require("../util/SetHelpers");
11
11
 
12
12
  /** @typedef {import("../Chunk")} Chunk */
13
+ /** @typedef {import("../ChunkGraph")} ChunkGraph */
13
14
  /** @typedef {import("../Compilation")} Compilation */
14
15
  /** @typedef {import("../Compilation").AssetInfo} AssetInfo */
15
16
  /** @typedef {import("../Compilation").PathData} PathData */
@@ -37,15 +38,10 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
37
38
  * @returns {string} runtime code
38
39
  */
39
40
  generate() {
40
- const {
41
- global,
42
- chunk,
43
- chunkGraph,
44
- contentType,
45
- getFilenameForChunk,
46
- allChunks,
47
- compilation
48
- } = this;
41
+ const { global, contentType, getFilenameForChunk, allChunks } = this;
42
+ const compilation = /** @type {Compilation} */ (this.compilation);
43
+ const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
44
+ const chunk = /** @type {Chunk} */ (this.chunk);
49
45
  const { runtimeTemplate } = compilation;
50
46
 
51
47
  /** @type {Map<string | FilenameFunction, Set<Chunk>>} */
@@ -19,9 +19,10 @@ class GetFullHashRuntimeModule extends RuntimeModule {
19
19
  * @returns {string} runtime code
20
20
  */
21
21
  generate() {
22
- const { runtimeTemplate } = this.compilation;
22
+ const compilation = /** @type {Compilation} */ (this.compilation);
23
+ const { runtimeTemplate } = compilation;
23
24
  return `${RuntimeGlobals.getFullHash} = ${runtimeTemplate.returningFunction(
24
- JSON.stringify(this.compilation.hash || "XXXX")
25
+ JSON.stringify(compilation.hash || "XXXX")
25
26
  )}`;
26
27
  }
27
28
  }
@@ -8,6 +8,7 @@ const RuntimeGlobals = require("../RuntimeGlobals");
8
8
  const RuntimeModule = require("../RuntimeModule");
9
9
  const Template = require("../Template");
10
10
 
11
+ /** @typedef {import("../Chunk")} Chunk */
11
12
  /** @typedef {import("../Compilation")} Compilation */
12
13
 
13
14
  class GetMainFilenameRuntimeModule extends RuntimeModule {
@@ -26,7 +27,9 @@ class GetMainFilenameRuntimeModule extends RuntimeModule {
26
27
  * @returns {string} runtime code
27
28
  */
28
29
  generate() {
29
- const { global, filename, compilation, chunk } = this;
30
+ const { global, filename } = this;
31
+ const compilation = /** @type {Compilation} */ (this.compilation);
32
+ const chunk = /** @type {Chunk} */ (this.chunk);
30
33
  const { runtimeTemplate } = compilation;
31
34
  const url = compilation.getPath(JSON.stringify(filename), {
32
35
  hash: `" + ${RuntimeGlobals.getFullHash}() + "`,
@@ -8,6 +8,8 @@ const RuntimeGlobals = require("../RuntimeGlobals");
8
8
  const Template = require("../Template");
9
9
  const HelperRuntimeModule = require("./HelperRuntimeModule");
10
10
 
11
+ /** @typedef {import("../Compilation")} Compilation */
12
+
11
13
  class GetTrustedTypesPolicyRuntimeModule extends HelperRuntimeModule {
12
14
  /**
13
15
  * @param {ReadonlySet<string>} runtimeRequirements runtime requirements
@@ -21,7 +23,7 @@ class GetTrustedTypesPolicyRuntimeModule extends HelperRuntimeModule {
21
23
  * @returns {string} runtime code
22
24
  */
23
25
  generate() {
24
- const { compilation } = this;
26
+ const compilation = /** @type {Compilation} */ (this.compilation);
25
27
  const { runtimeTemplate, outputOptions } = compilation;
26
28
  const { trustedTypes } = outputOptions;
27
29
  const fn = RuntimeGlobals.getTrustedTypesPolicy;
@@ -9,6 +9,8 @@ const RuntimeGlobals = require("../RuntimeGlobals");
9
9
  const RuntimeModule = require("../RuntimeModule");
10
10
  const Template = require("../Template");
11
11
 
12
+ /** @typedef {import("../Compilation")} Compilation */
13
+
12
14
  class HasOwnPropertyRuntimeModule extends RuntimeModule {
13
15
  constructor() {
14
16
  super("hasOwnProperty shorthand");
@@ -18,7 +20,8 @@ class HasOwnPropertyRuntimeModule extends RuntimeModule {
18
20
  * @returns {string} runtime code
19
21
  */
20
22
  generate() {
21
- const { runtimeTemplate } = this.compilation;
23
+ const compilation = /** @type {Compilation} */ (this.compilation);
24
+ const { runtimeTemplate } = compilation;
22
25
 
23
26
  return Template.asString([
24
27
  `${RuntimeGlobals.hasOwnProperty} = ${runtimeTemplate.returningFunction(
@@ -44,17 +44,19 @@ class LoadScriptRuntimeModule extends HelperRuntimeModule {
44
44
 
45
45
  /**
46
46
  * @param {boolean=} withCreateScriptUrl use create script url for trusted types
47
+ * @param {boolean=} withFetchPriority use `fetchPriority` attribute
47
48
  */
48
- constructor(withCreateScriptUrl) {
49
+ constructor(withCreateScriptUrl, withFetchPriority) {
49
50
  super("load script");
50
51
  this._withCreateScriptUrl = withCreateScriptUrl;
52
+ this._withFetchPriority = withFetchPriority;
51
53
  }
52
54
 
53
55
  /**
54
56
  * @returns {string} runtime code
55
57
  */
56
58
  generate() {
57
- const { compilation } = this;
59
+ const compilation = /** @type {Compilation} */ (this.compilation);
58
60
  const { runtimeTemplate, outputOptions } = compilation;
59
61
  const {
60
62
  scriptType,
@@ -81,6 +83,15 @@ class LoadScriptRuntimeModule extends HelperRuntimeModule {
81
83
  uniqueName
82
84
  ? 'script.setAttribute("data-webpack", dataWebpackPrefix + key);'
83
85
  : "",
86
+ this._withFetchPriority
87
+ ? Template.asString([
88
+ "if(fetchPriority) {",
89
+ Template.indent(
90
+ 'script.setAttribute("fetchpriority", fetchPriority);'
91
+ ),
92
+ "}"
93
+ ])
94
+ : "",
84
95
  `script.src = ${
85
96
  this._withCreateScriptUrl
86
97
  ? `${RuntimeGlobals.createScriptUrl}(url)`
@@ -105,53 +116,58 @@ class LoadScriptRuntimeModule extends HelperRuntimeModule {
105
116
  ? `var dataWebpackPrefix = ${JSON.stringify(uniqueName + ":")};`
106
117
  : "// data-webpack is not used as build has no uniqueName",
107
118
  "// loadScript function to load a script via script tag",
108
- `${fn} = ${runtimeTemplate.basicFunction("url, done, key, chunkId", [
109
- "if(inProgress[url]) { inProgress[url].push(done); return; }",
110
- "var script, needAttach;",
111
- "if(key !== undefined) {",
112
- Template.indent([
113
- 'var scripts = document.getElementsByTagName("script");',
114
- "for(var i = 0; i < scripts.length; i++) {",
119
+ `${fn} = ${runtimeTemplate.basicFunction(
120
+ `url, done, key, chunkId${
121
+ this._withFetchPriority ? ", fetchPriority" : ""
122
+ }`,
123
+ [
124
+ "if(inProgress[url]) { inProgress[url].push(done); return; }",
125
+ "var script, needAttach;",
126
+ "if(key !== undefined) {",
127
+ Template.indent([
128
+ 'var scripts = document.getElementsByTagName("script");',
129
+ "for(var i = 0; i < scripts.length; i++) {",
130
+ Template.indent([
131
+ "var s = scripts[i];",
132
+ `if(s.getAttribute("src") == url${
133
+ uniqueName
134
+ ? ' || s.getAttribute("data-webpack") == dataWebpackPrefix + key'
135
+ : ""
136
+ }) { script = s; break; }`
137
+ ]),
138
+ "}"
139
+ ]),
140
+ "}",
141
+ "if(!script) {",
115
142
  Template.indent([
116
- "var s = scripts[i];",
117
- `if(s.getAttribute("src") == url${
118
- uniqueName
119
- ? ' || s.getAttribute("data-webpack") == dataWebpackPrefix + key'
120
- : ""
121
- }) { script = s; break; }`
143
+ "needAttach = true;",
144
+ createScript.call(code, /** @type {Chunk} */ (this.chunk))
122
145
  ]),
123
- "}"
124
- ]),
125
- "}",
126
- "if(!script) {",
127
- Template.indent([
128
- "needAttach = true;",
129
- createScript.call(code, this.chunk)
130
- ]),
131
- "}",
132
- "inProgress[url] = [done];",
133
- "var onScriptComplete = " +
134
- runtimeTemplate.basicFunction(
135
- "prev, event",
136
- Template.asString([
137
- "// avoid mem leaks in IE.",
138
- "script.onerror = script.onload = null;",
139
- "clearTimeout(timeout);",
140
- "var doneFns = inProgress[url];",
141
- "delete inProgress[url];",
142
- "script.parentNode && script.parentNode.removeChild(script);",
143
- `doneFns && doneFns.forEach(${runtimeTemplate.returningFunction(
144
- "fn(event)",
145
- "fn"
146
- )});`,
147
- "if(prev) return prev(event);"
148
- ])
149
- ),
150
- `var timeout = setTimeout(onScriptComplete.bind(null, undefined, { type: 'timeout', target: script }), ${loadTimeout});`,
151
- "script.onerror = onScriptComplete.bind(null, script.onerror);",
152
- "script.onload = onScriptComplete.bind(null, script.onload);",
153
- "needAttach && document.head.appendChild(script);"
154
- ])};`
146
+ "}",
147
+ "inProgress[url] = [done];",
148
+ "var onScriptComplete = " +
149
+ runtimeTemplate.basicFunction(
150
+ "prev, event",
151
+ Template.asString([
152
+ "// avoid mem leaks in IE.",
153
+ "script.onerror = script.onload = null;",
154
+ "clearTimeout(timeout);",
155
+ "var doneFns = inProgress[url];",
156
+ "delete inProgress[url];",
157
+ "script.parentNode && script.parentNode.removeChild(script);",
158
+ `doneFns && doneFns.forEach(${runtimeTemplate.returningFunction(
159
+ "fn(event)",
160
+ "fn"
161
+ )});`,
162
+ "if(prev) return prev(event);"
163
+ ])
164
+ ),
165
+ `var timeout = setTimeout(onScriptComplete.bind(null, undefined, { type: 'timeout', target: script }), ${loadTimeout});`,
166
+ "script.onerror = onScriptComplete.bind(null, script.onerror);",
167
+ "script.onload = onScriptComplete.bind(null, script.onload);",
168
+ "needAttach && document.head.appendChild(script);"
169
+ ]
170
+ )};`
155
171
  ]);
156
172
  }
157
173
  }
@@ -8,6 +8,8 @@ const RuntimeGlobals = require("../RuntimeGlobals");
8
8
  const Template = require("../Template");
9
9
  const HelperRuntimeModule = require("./HelperRuntimeModule");
10
10
 
11
+ /** @typedef {import("../Compilation")} Compilation */
12
+
11
13
  class MakeNamespaceObjectRuntimeModule extends HelperRuntimeModule {
12
14
  constructor() {
13
15
  super("make namespace object");
@@ -17,7 +19,8 @@ class MakeNamespaceObjectRuntimeModule extends HelperRuntimeModule {
17
19
  * @returns {string} runtime code
18
20
  */
19
21
  generate() {
20
- const { runtimeTemplate } = this.compilation;
22
+ const compilation = /** @type {Compilation} */ (this.compilation);
23
+ const { runtimeTemplate } = compilation;
21
24
  const fn = RuntimeGlobals.makeNamespaceObject;
22
25
  return Template.asString([
23
26
  "// define __esModule on exports",
@@ -8,6 +8,8 @@ const RuntimeGlobals = require("../RuntimeGlobals");
8
8
  const RuntimeModule = require("../RuntimeModule");
9
9
  const Template = require("../Template");
10
10
 
11
+ /** @typedef {import("../Compilation")} Compilation */
12
+
11
13
  class OnChunksLoadedRuntimeModule extends RuntimeModule {
12
14
  constructor() {
13
15
  super("chunk loaded");
@@ -17,7 +19,7 @@ class OnChunksLoadedRuntimeModule extends RuntimeModule {
17
19
  * @returns {string} runtime code
18
20
  */
19
21
  generate() {
20
- const { compilation } = this;
22
+ const compilation = /** @type {Compilation} */ (this.compilation);
21
23
  const { runtimeTemplate } = compilation;
22
24
  return Template.asString([
23
25
  "var deferred = [];",
@@ -8,6 +8,7 @@ const RuntimeGlobals = require("../RuntimeGlobals");
8
8
  const RuntimeModule = require("../RuntimeModule");
9
9
 
10
10
  /** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} OutputOptions */
11
+ /** @typedef {import("../Compilation")} Compilation */
11
12
 
12
13
  class PublicPathRuntimeModule extends RuntimeModule {
13
14
  /**
@@ -22,7 +23,8 @@ class PublicPathRuntimeModule extends RuntimeModule {
22
23
  * @returns {string} runtime code
23
24
  */
24
25
  generate() {
25
- const { compilation, publicPath } = this;
26
+ const { publicPath } = this;
27
+ const compilation = /** @type {Compilation} */ (this.compilation);
26
28
 
27
29
  return `${RuntimeGlobals.publicPath} = ${JSON.stringify(
28
30
  compilation.getPath(publicPath || "", {
@@ -8,6 +8,8 @@ const RuntimeGlobals = require("../RuntimeGlobals");
8
8
  const Template = require("../Template");
9
9
  const HelperRuntimeModule = require("./HelperRuntimeModule");
10
10
 
11
+ /** @typedef {import("../Compilation")} Compilation */
12
+
11
13
  class RelativeUrlRuntimeModule extends HelperRuntimeModule {
12
14
  constructor() {
13
15
  super("relative url");
@@ -17,7 +19,8 @@ class RelativeUrlRuntimeModule extends HelperRuntimeModule {
17
19
  * @returns {string} runtime code
18
20
  */
19
21
  generate() {
20
- const { runtimeTemplate } = this.compilation;
22
+ const compilation = /** @type {Compilation} */ (this.compilation);
23
+ const { runtimeTemplate } = compilation;
21
24
  return Template.asString([
22
25
  `${RuntimeGlobals.relativeUrl} = function RelativeURL(url) {`,
23
26
  Template.indent([
@@ -7,6 +7,9 @@
7
7
  const RuntimeGlobals = require("../RuntimeGlobals");
8
8
  const RuntimeModule = require("../RuntimeModule");
9
9
 
10
+ /** @typedef {import("../Chunk")} Chunk */
11
+ /** @typedef {import("../ChunkGraph")} ChunkGraph */
12
+
10
13
  class RuntimeIdRuntimeModule extends RuntimeModule {
11
14
  constructor() {
12
15
  super("runtimeId");
@@ -16,7 +19,8 @@ class RuntimeIdRuntimeModule extends RuntimeModule {
16
19
  * @returns {string} runtime code
17
20
  */
18
21
  generate() {
19
- const { chunkGraph, chunk } = this;
22
+ const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
23
+ const chunk = /** @type {Chunk} */ (this.chunk);
20
24
  const runtime = chunk.runtime;
21
25
  if (typeof runtime !== "string")
22
26
  throw new Error("RuntimeIdRuntimeModule must be in a single runtime");