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
@@ -35,14 +35,15 @@ const getConnectionsByOriginModule = set => {
35
35
  const map = new Map();
36
36
  /** @type {Module | 0} */
37
37
  let lastModule = 0;
38
- /** @type {ModuleGraphConnection[]} */
38
+ /** @type {ModuleGraphConnection[] | undefined} */
39
39
  let lastList = undefined;
40
40
  for (const connection of set) {
41
41
  const { originModule } = connection;
42
42
  if (lastModule === originModule) {
43
- lastList.push(connection);
43
+ /** @type {ModuleGraphConnection[]} */
44
+ (lastList).push(connection);
44
45
  } else {
45
- lastModule = originModule;
46
+ lastModule = /** @type {Module} */ (originModule);
46
47
  const list = map.get(originModule);
47
48
  if (list !== undefined) {
48
49
  lastList = list;
@@ -65,12 +66,13 @@ const getConnectionsByModule = set => {
65
66
  const map = new Map();
66
67
  /** @type {Module | 0} */
67
68
  let lastModule = 0;
68
- /** @type {ModuleGraphConnection[]} */
69
+ /** @type {ModuleGraphConnection[] | undefined} */
69
70
  let lastList = undefined;
70
71
  for (const connection of set) {
71
72
  const { module } = connection;
72
73
  if (lastModule === module) {
73
- lastList.push(connection);
74
+ /** @type {ModuleGraphConnection[]} */
75
+ (lastList).push(connection);
74
76
  } else {
75
77
  lastModule = module;
76
78
  const list = map.get(module);
@@ -99,13 +101,13 @@ class ModuleGraphModule {
99
101
  this.optimizationBailout = [];
100
102
  /** @type {ExportsInfo} */
101
103
  this.exports = new ExportsInfo();
102
- /** @type {number} */
104
+ /** @type {number | null} */
103
105
  this.preOrderIndex = null;
104
- /** @type {number} */
106
+ /** @type {number | null} */
105
107
  this.postOrderIndex = null;
106
- /** @type {number} */
108
+ /** @type {number | null} */
107
109
  this.depth = null;
108
- /** @type {ModuleProfile} */
110
+ /** @type {ModuleProfile | undefined | null} */
109
111
  this.profile = undefined;
110
112
  /** @type {boolean} */
111
113
  this.async = false;
@@ -116,20 +118,20 @@ class ModuleGraphModule {
116
118
 
117
119
  class ModuleGraph {
118
120
  constructor() {
119
- /** @type {WeakMap<Dependency, ModuleGraphConnection>} */
121
+ /** @type {WeakMap<Dependency, ModuleGraphConnection | null>} */
120
122
  this._dependencyMap = new WeakMap();
121
123
  /** @type {Map<Module, ModuleGraphModule>} */
122
124
  this._moduleMap = new Map();
123
125
  /** @type {WeakMap<any, Object>} */
124
126
  this._metaMap = new WeakMap();
125
127
 
126
- /** @type {WeakTupleMap<any[], any>} */
128
+ /** @type {WeakTupleMap<any[], any> | undefined} */
127
129
  this._cache = undefined;
128
130
 
129
131
  /** @type {Map<Module, WeakTupleMap<any, any>>} */
130
132
  this._moduleMemCaches = undefined;
131
133
 
132
- /** @type {string} */
134
+ /** @type {string | undefined} */
133
135
  this._cacheStage = undefined;
134
136
  }
135
137
 
@@ -221,7 +223,9 @@ class ModuleGraph {
221
223
  * @returns {void}
222
224
  */
223
225
  updateModule(dependency, module) {
224
- const connection = this.getConnection(dependency);
226
+ const connection =
227
+ /** @type {ModuleGraphConnection} */
228
+ (this.getConnection(dependency));
225
229
  if (connection.module === module) return;
226
230
  const newConnection = connection.clone();
227
231
  newConnection.module = module;
@@ -375,7 +379,7 @@ class ModuleGraph {
375
379
 
376
380
  /**
377
381
  * @param {Dependency} dependency the dependency to look for a referenced module
378
- * @returns {Module} the referenced module
382
+ * @returns {Module | null} the referenced module
379
383
  */
380
384
  getResolvedModule(dependency) {
381
385
  const connection = this.getConnection(dependency);
@@ -398,7 +402,10 @@ class ModuleGraph {
398
402
  ) {
399
403
  let foundConnection;
400
404
  for (const connection of mgm._unassignedConnections) {
401
- this._dependencyMap.set(connection.dependency, connection);
405
+ this._dependencyMap.set(
406
+ /** @type {Dependency} */ (connection.dependency),
407
+ connection
408
+ );
402
409
  if (connection.dependency === dependency)
403
410
  foundConnection = connection;
404
411
  }
@@ -416,7 +423,7 @@ class ModuleGraph {
416
423
 
417
424
  /**
418
425
  * @param {Dependency} dependency the dependency to look for a referenced module
419
- * @returns {Module} the referenced module
426
+ * @returns {Module | null} the referenced module
420
427
  */
421
428
  getModule(dependency) {
422
429
  const connection = this.getConnection(dependency);
@@ -425,7 +432,7 @@ class ModuleGraph {
425
432
 
426
433
  /**
427
434
  * @param {Dependency} dependency the dependency to look for a referencing module
428
- * @returns {Module} the referencing module
435
+ * @returns {Module | null} the referencing module
429
436
  */
430
437
  getOrigin(dependency) {
431
438
  const connection = this.getConnection(dependency);
@@ -434,7 +441,7 @@ class ModuleGraph {
434
441
 
435
442
  /**
436
443
  * @param {Dependency} dependency the dependency to look for a referencing module
437
- * @returns {Module} the original referencing module
444
+ * @returns {Module | null} the original referencing module
438
445
  */
439
446
  getResolvedOrigin(dependency) {
440
447
  const connection = this.getConnection(dependency);
@@ -604,7 +611,7 @@ class ModuleGraph {
604
611
 
605
612
  /**
606
613
  * @param {Module} module the module
607
- * @returns {number} the index of the module
614
+ * @returns {number | null} the index of the module
608
615
  */
609
616
  getPreOrderIndex(module) {
610
617
  const mgm = this._getModuleGraphModule(module);
@@ -613,7 +620,7 @@ class ModuleGraph {
613
620
 
614
621
  /**
615
622
  * @param {Module} module the module
616
- * @returns {number} the index of the module
623
+ * @returns {number | null} the index of the module
617
624
  */
618
625
  getPostOrderIndex(module) {
619
626
  const mgm = this._getModuleGraphModule(module);
@@ -670,7 +677,7 @@ class ModuleGraph {
670
677
 
671
678
  /**
672
679
  * @param {Module} module the module
673
- * @returns {number} the depth of the module
680
+ * @returns {number | null} the depth of the module
674
681
  */
675
682
  getDepth(module) {
676
683
  const mgm = this._getModuleGraphModule(module);
@@ -727,14 +734,14 @@ class ModuleGraph {
727
734
  let meta = this._metaMap.get(thing);
728
735
  if (meta === undefined) {
729
736
  meta = Object.create(null);
730
- this._metaMap.set(thing, meta);
737
+ this._metaMap.set(thing, /** @type {Object} */ (meta));
731
738
  }
732
- return meta;
739
+ return /** @type {Object} */ (meta);
733
740
  }
734
741
 
735
742
  /**
736
743
  * @param {any} thing any thing
737
- * @returns {Object} metadata
744
+ * @returns {Object | undefined} metadata
738
745
  */
739
746
  getMetaIfExisting(thing) {
740
747
  return this._metaMap.get(thing);
@@ -74,9 +74,9 @@ class ModuleGraphConnection {
74
74
  this.weak = weak;
75
75
  this.conditional = !!condition;
76
76
  this._active = condition !== false;
77
- /** @type {function(ModuleGraphConnection, RuntimeSpec): ConnectionState} */
77
+ /** @type {(function(ModuleGraphConnection, RuntimeSpec): ConnectionState) | undefined} */
78
78
  this.condition = condition || undefined;
79
- /** @type {Set<string>} */
79
+ /** @type {Set<string> | undefined} */
80
80
  this.explanations = undefined;
81
81
  if (explanation) {
82
82
  this.explanations = new Set();
@@ -107,7 +107,9 @@ class ModuleGraphConnection {
107
107
  */
108
108
  addCondition(condition) {
109
109
  if (this.conditional) {
110
- const old = this.condition;
110
+ const old =
111
+ /** @type {(function(ModuleGraphConnection, RuntimeSpec): ConnectionState)} */
112
+ (this.condition);
111
113
  this.condition = (c, r) =>
112
114
  intersectConnectionStates(old(c, r), condition(c, r));
113
115
  } else if (this._active) {
@@ -143,7 +145,12 @@ class ModuleGraphConnection {
143
145
  */
144
146
  isActive(runtime) {
145
147
  if (!this.conditional) return this._active;
146
- return this.condition(this, runtime) !== false;
148
+
149
+ return (
150
+ /** @type {(function(ModuleGraphConnection, RuntimeSpec): ConnectionState)} */ (
151
+ this.condition
152
+ )(this, runtime) !== false
153
+ );
147
154
  }
148
155
 
149
156
  /**
@@ -152,7 +159,11 @@ class ModuleGraphConnection {
152
159
  */
153
160
  isTargetActive(runtime) {
154
161
  if (!this.conditional) return this._active;
155
- return this.condition(this, runtime) === true;
162
+ return (
163
+ /** @type {(function(ModuleGraphConnection, RuntimeSpec): ConnectionState)} */ (
164
+ this.condition
165
+ )(this, runtime) === true
166
+ );
156
167
  }
157
168
 
158
169
  /**
@@ -161,7 +172,9 @@ class ModuleGraphConnection {
161
172
  */
162
173
  getActiveState(runtime) {
163
174
  if (!this.conditional) return this._active;
164
- return this.condition(this, runtime);
175
+ return /** @type {(function(ModuleGraphConnection, RuntimeSpec): ConnectionState)} */ (
176
+ this.condition
177
+ )(this, runtime);
165
178
  }
166
179
 
167
180
  /**
@@ -15,10 +15,16 @@ const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
15
15
  /** @typedef {import("./ExportsInfo")} ExportsInfo */
16
16
  /** @typedef {import("./ExportsInfo").ExportInfo} ExportInfo */
17
17
  /** @typedef {import("./Module")} Module */
18
+ /** @typedef {import("./Module").BuildMeta} BuildMeta */
18
19
  /** @typedef {import("./ModuleGraph")} ModuleGraph */
19
20
  /** @typedef {import("./ModuleTemplate")} ModuleTemplate */
20
21
  /** @typedef {import("./RequestShortener")} RequestShortener */
21
22
 
23
+ /**
24
+ * @template T
25
+ * @param {Iterable<T>} iterable iterable
26
+ * @returns {string} joined with comma
27
+ */
22
28
  const joinIterableWithComma = iterable => {
23
29
  // This is more performant than Array.from().join(", ")
24
30
  // as it doesn't create an array
@@ -139,7 +145,7 @@ const printExportsInfoToSource = (
139
145
  }
140
146
  };
141
147
 
142
- /** @type {WeakMap<RequestShortener, WeakMap<Module, { header: RawSource, full: WeakMap<Source, CachedSource> }>>} */
148
+ /** @type {WeakMap<RequestShortener, WeakMap<Module, { header: RawSource | undefined, full: WeakMap<Source, CachedSource> }>>} */
143
149
  const caches = new WeakMap();
144
150
 
145
151
  class ModuleInfoHeaderPlugin {
@@ -197,7 +203,8 @@ class ModuleInfoHeaderPlugin {
197
203
  }
198
204
  source.add(header);
199
205
  if (verbose) {
200
- const exportsType = module.buildMeta.exportsType;
206
+ const exportsType = /** @type {BuildMeta} */ (module.buildMeta)
207
+ .exportsType;
201
208
  source.add(
202
209
  Template.toComment(
203
210
  exportsType
@@ -43,7 +43,7 @@ const previouslyPolyfilledBuiltinModules = {
43
43
 
44
44
  class ModuleNotFoundError extends WebpackError {
45
45
  /**
46
- * @param {Module} module module tied to dependency
46
+ * @param {Module | null} module module tied to dependency
47
47
  * @param {Error&any} err error thrown
48
48
  * @param {DependencyLocation} loc location of dependency
49
49
  */
@@ -54,7 +54,10 @@ class ModuleNotFoundError extends WebpackError {
54
54
  const match = err.message.match(/Can't resolve '([^']+)'/);
55
55
  if (match) {
56
56
  const request = match[1];
57
- const alias = previouslyPolyfilledBuiltinModules[request];
57
+ const alias =
58
+ previouslyPolyfilledBuiltinModules[
59
+ /** @type {keyof previouslyPolyfilledBuiltinModules} */ (request)
60
+ ];
58
61
  if (alias) {
59
62
  const pathIndex = alias.indexOf("/");
60
63
  const dependency = pathIndex > 0 ? alias.slice(0, pathIndex) : alias;
@@ -34,6 +34,7 @@ class ModuleProfile {
34
34
  this.storing = 0;
35
35
  this.storingParallelismFactor = 0;
36
36
 
37
+ /** @type {{ start: number, end: number }[] | undefined } */
37
38
  this.additionalFactoryTimes = undefined;
38
39
  this.additionalFactories = 0;
39
40
  this.additionalFactoriesParallelismFactor = 0;
@@ -16,6 +16,7 @@ class ModuleRestoreError extends WebpackError {
16
16
  */
17
17
  constructor(module, err) {
18
18
  let message = "Module restore failed: ";
19
+ /** @type {string | undefined} */
19
20
  let details = undefined;
20
21
  if (err !== null && typeof err === "object") {
21
22
  if (typeof err.stack === "string" && err.stack) {
@@ -33,6 +34,7 @@ class ModuleRestoreError extends WebpackError {
33
34
  super(message);
34
35
 
35
36
  this.name = "ModuleRestoreError";
37
+ /** @type {string | undefined} */
36
38
  this.details = details;
37
39
  this.module = module;
38
40
  this.error = err;
@@ -16,6 +16,7 @@ class ModuleStoreError extends WebpackError {
16
16
  */
17
17
  constructor(module, err) {
18
18
  let message = "Module storing failed: ";
19
+ /** @type {string | undefined} */
19
20
  let details = undefined;
20
21
  if (err !== null && typeof err === "object") {
21
22
  if (typeof err.stack === "string" && err.stack) {
@@ -33,7 +34,7 @@ class ModuleStoreError extends WebpackError {
33
34
  super(message);
34
35
 
35
36
  this.name = "ModuleStoreError";
36
- this.details = details;
37
+ this.details = /** @type {string | undefined} */ (details);
37
38
  this.module = module;
38
39
  this.error = err;
39
40
  }
@@ -60,6 +60,12 @@ const CSS_MODULE_TYPE_GLOBAL = "css/global";
60
60
  */
61
61
  const CSS_MODULE_TYPE_MODULE = "css/module";
62
62
 
63
+ /**
64
+ * @type {Readonly<"css/auto">}
65
+ * This is the module type used for CSS files, the module will be parsed as CSS modules if it's filename contains `.module.` or `.modules.`.
66
+ */
67
+ const CSS_MODULE_TYPE_AUTO = "css/auto";
68
+
63
69
  /**
64
70
  * @type {Readonly<"asset">}
65
71
  * This is the module type used for automatically choosing between `asset/inline`, `asset/resource` based on asset size limit (8096).
@@ -152,6 +158,7 @@ exports.WEBASSEMBLY_MODULE_TYPE_SYNC = WEBASSEMBLY_MODULE_TYPE_SYNC;
152
158
  exports.CSS_MODULE_TYPE = CSS_MODULE_TYPE;
153
159
  exports.CSS_MODULE_TYPE_GLOBAL = CSS_MODULE_TYPE_GLOBAL;
154
160
  exports.CSS_MODULE_TYPE_MODULE = CSS_MODULE_TYPE_MODULE;
161
+ exports.CSS_MODULE_TYPE_AUTO = CSS_MODULE_TYPE_AUTO;
155
162
  exports.WEBPACK_MODULE_TYPE_RUNTIME = WEBPACK_MODULE_TYPE_RUNTIME;
156
163
  exports.WEBPACK_MODULE_TYPE_FALLBACK = WEBPACK_MODULE_TYPE_FALLBACK;
157
164
  exports.WEBPACK_MODULE_TYPE_REMOTE = WEBPACK_MODULE_TYPE_REMOTE;
@@ -27,6 +27,10 @@ class MultiWatching {
27
27
  this.compiler = compiler;
28
28
  }
29
29
 
30
+ /**
31
+ * @param {Callback<void>=} callback signals when the build has completed again
32
+ * @returns {void}
33
+ */
30
34
  invalidate(callback) {
31
35
  if (callback) {
32
36
  asyncLib.each(
@@ -21,14 +21,23 @@ const { relative } = require("./util/fs");
21
21
  const { parseResource } = require("./util/identifier");
22
22
 
23
23
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
24
+ /** @typedef {import("../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
25
+ /** @typedef {import("../declarations/WebpackOptions").NodeOptions} NodeOptions */
24
26
  /** @typedef {import("./Compiler")} Compiler */
25
27
  /** @typedef {import("./Dependency")} Dependency */
28
+ /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
26
29
  /** @typedef {import("./DependencyTemplates")} DependencyTemplates */
30
+ /** @typedef {import("./NormalModule")} NormalModule */
27
31
  /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
32
+ /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
33
+ /** @typedef {import("./javascript/JavascriptParser").Range} Range */
28
34
 
29
35
  const PLUGIN_NAME = "NodeStuffPlugin";
30
36
 
31
37
  class NodeStuffPlugin {
38
+ /**
39
+ * @param {NodeOptions} options options
40
+ */
32
41
  constructor(options) {
33
42
  this.options = options;
34
43
  }
@@ -43,6 +52,11 @@ class NodeStuffPlugin {
43
52
  compiler.hooks.compilation.tap(
44
53
  PLUGIN_NAME,
45
54
  (compilation, { normalModuleFactory }) => {
55
+ /**
56
+ * @param {JavascriptParser} parser the parser
57
+ * @param {JavascriptParserOptions} parserOptions options
58
+ * @returns {void}
59
+ */
46
60
  const handler = (parser, parserOptions) => {
47
61
  if (parserOptions.node === false) return;
48
62
 
@@ -56,10 +70,10 @@ class NodeStuffPlugin {
56
70
  parser.hooks.expression.for("global").tap(PLUGIN_NAME, expr => {
57
71
  const dep = new ConstDependency(
58
72
  RuntimeGlobals.global,
59
- expr.range,
73
+ /** @type {Range} */ (expr.range),
60
74
  [RuntimeGlobals.global]
61
75
  );
62
- dep.loc = expr.loc;
76
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
63
77
  parser.state.module.addPresentationalDependency(dep);
64
78
 
65
79
  // TODO webpack 6 remove
@@ -76,25 +90,31 @@ class NodeStuffPlugin {
76
90
  parser.hooks.rename.for("global").tap(PLUGIN_NAME, expr => {
77
91
  const dep = new ConstDependency(
78
92
  RuntimeGlobals.global,
79
- expr.range,
93
+ /** @type {Range} */ (expr.range),
80
94
  [RuntimeGlobals.global]
81
95
  );
82
- dep.loc = expr.loc;
96
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
83
97
  parser.state.module.addPresentationalDependency(dep);
84
98
  return false;
85
99
  });
86
100
  }
87
101
 
102
+ /**
103
+ * @param {string} expressionName expression name
104
+ * @param {(module: NormalModule) => string} fn function
105
+ * @param {string=} warning warning
106
+ * @returns {void}
107
+ */
88
108
  const setModuleConstant = (expressionName, fn, warning) => {
89
109
  parser.hooks.expression
90
110
  .for(expressionName)
91
111
  .tap(PLUGIN_NAME, expr => {
92
112
  const dep = new CachedConstDependency(
93
113
  JSON.stringify(fn(parser.state.module)),
94
- expr.range,
114
+ /** @type {Range} */ (expr.range),
95
115
  expressionName
96
116
  );
97
- dep.loc = expr.loc;
117
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
98
118
  parser.state.module.addPresentationalDependency(dep);
99
119
 
100
120
  // TODO webpack 6 remove
@@ -108,6 +128,12 @@ class NodeStuffPlugin {
108
128
  });
109
129
  };
110
130
 
131
+ /**
132
+ * @param {string} expressionName expression name
133
+ * @param {string} value value
134
+ * @param {string=} warning warning
135
+ * @returns {void}
136
+ */
111
137
  const setConstant = (expressionName, value, warning) =>
112
138
  setModuleConstant(expressionName, () => value, warning);
113
139
 
@@ -14,7 +14,11 @@ const ConstDependency = require("./dependencies/ConstDependency");
14
14
  const ProvidedDependency = require("./dependencies/ProvidedDependency");
15
15
  const { approve } = require("./javascript/JavascriptParserHelpers");
16
16
 
17
+ /** @typedef {import("../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
17
18
  /** @typedef {import("./Compiler")} Compiler */
19
+ /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
20
+ /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
21
+ /** @typedef {import("./javascript/JavascriptParser").Range} Range */
18
22
 
19
23
  const PLUGIN_NAME = "ProvidePlugin";
20
24
 
@@ -48,6 +52,11 @@ class ProvidePlugin {
48
52
  ProvidedDependency,
49
53
  new ProvidedDependency.Template()
50
54
  );
55
+ /**
56
+ * @param {JavascriptParser} parser the parser
57
+ * @param {JavascriptParserOptions} parserOptions options
58
+ * @returns {void}
59
+ */
51
60
  const handler = (parser, parserOptions) => {
52
61
  Object.keys(definitions).forEach(name => {
53
62
  const request = [].concat(definitions[name]);
@@ -67,9 +76,9 @@ class ProvidePlugin {
67
76
  request[0],
68
77
  nameIdentifier,
69
78
  request.slice(1),
70
- expr.range
79
+ /** @type {Range} */ (expr.range)
71
80
  );
72
- dep.loc = expr.loc;
81
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
73
82
  parser.state.module.addDependency(dep);
74
83
  return true;
75
84
  });
@@ -82,9 +91,9 @@ class ProvidePlugin {
82
91
  request[0],
83
92
  nameIdentifier,
84
93
  request.slice(1),
85
- expr.callee.range
94
+ /** @type {Range} */ (expr.callee.range)
86
95
  );
87
- dep.loc = expr.callee.loc;
96
+ dep.loc = /** @type {DependencyLocation} */ (expr.callee.loc);
88
97
  parser.state.module.addDependency(dep);
89
98
  parser.walkExpressions(expr.arguments);
90
99
  return true;
package/lib/RawModule.js CHANGED
@@ -72,7 +72,9 @@ class RawModule extends Module {
72
72
  * @returns {string} a user readable identifier of the module
73
73
  */
74
74
  readableIdentifier(requestShortener) {
75
- return requestShortener.shorten(this.readableIdentifierStr);
75
+ return /** @type {string} */ (
76
+ requestShortener.shorten(this.readableIdentifierStr)
77
+ );
76
78
  }
77
79
 
78
80
  /**
@@ -15,7 +15,9 @@ const {
15
15
  toConstantDependency
16
16
  } = require("./javascript/JavascriptParserHelpers");
17
17
 
18
+ /** @typedef {import("../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
18
19
  /** @typedef {import("./Compiler")} Compiler */
20
+ /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
19
21
 
20
22
  const PLUGIN_NAME = "RequireJsStuffPlugin";
21
23
 
@@ -33,6 +35,11 @@ module.exports = class RequireJsStuffPlugin {
33
35
  ConstDependency,
34
36
  new ConstDependency.Template()
35
37
  );
38
+ /**
39
+ * @param {JavascriptParser} parser the parser
40
+ * @param {JavascriptParserOptions} parserOptions options
41
+ * @returns {void}
42
+ */
36
43
  const handler = (parser, parserOptions) => {
37
44
  if (
38
45
  parserOptions.requireJs === undefined ||
@@ -188,6 +188,11 @@ exports.createScriptUrl = "__webpack_require__.tu";
188
188
  */
189
189
  exports.getTrustedTypesPolicy = "__webpack_require__.tt";
190
190
 
191
+ /**
192
+ * a flag when a chunk has a fetch priority
193
+ */
194
+ exports.hasFetchPriority = "has fetch priority";
195
+
191
196
  /**
192
197
  * the chunk name of the chunk with the runtime
193
198
  */
@@ -166,7 +166,7 @@ class RuntimeModule extends Module {
166
166
  /* istanbul ignore next */
167
167
  /**
168
168
  * @abstract
169
- * @returns {string} runtime code
169
+ * @returns {string | null} runtime code
170
170
  */
171
171
  generate() {
172
172
  const AbstractMethodError = require("./AbstractMethodError");
@@ -174,11 +174,11 @@ class RuntimeModule extends Module {
174
174
  }
175
175
 
176
176
  /**
177
- * @returns {string} runtime code
177
+ * @returns {string | null} runtime code
178
178
  */
179
179
  getGeneratedCode() {
180
180
  if (this._cachedGeneratedCode) {
181
- return this._cachedGeneratedCode;
181
+ return /** @type {string | null} */ (this._cachedGeneratedCode);
182
182
  }
183
183
  return (this._cachedGeneratedCode = this.generate());
184
184
  }
@@ -128,7 +128,8 @@ class RuntimePlugin {
128
128
  });
129
129
  }
130
130
  for (const req of Object.keys(TREE_DEPENDENCIES)) {
131
- const deps = TREE_DEPENDENCIES[req];
131
+ const deps =
132
+ TREE_DEPENDENCIES[/** @type {keyof TREE_DEPENDENCIES} */ (req)];
132
133
  compilation.hooks.runtimeRequirementInTree
133
134
  .for(req)
134
135
  .tap("RuntimePlugin", (chunk, set) => {
@@ -136,7 +137,8 @@ class RuntimePlugin {
136
137
  });
137
138
  }
138
139
  for (const req of Object.keys(MODULE_DEPENDENCIES)) {
139
- const deps = MODULE_DEPENDENCIES[req];
140
+ const deps =
141
+ MODULE_DEPENDENCIES[/** @type {keyof MODULE_DEPENDENCIES} */ (req)];
140
142
  compilation.hooks.runtimeRequirementInModule
141
143
  .for(req)
142
144
  .tap("RuntimePlugin", (chunk, set) => {
@@ -377,9 +379,10 @@ class RuntimePlugin {
377
379
  if (withCreateScriptUrl) {
378
380
  set.add(RuntimeGlobals.createScriptUrl);
379
381
  }
382
+ const withFetchPriority = set.has(RuntimeGlobals.hasFetchPriority);
380
383
  compilation.addRuntimeModule(
381
384
  chunk,
382
- new LoadScriptRuntimeModule(withCreateScriptUrl)
385
+ new LoadScriptRuntimeModule(withCreateScriptUrl, withFetchPriority)
383
386
  );
384
387
  return true;
385
388
  });
@@ -396,7 +396,7 @@ class RuntimeTemplate {
396
396
 
397
397
  /**
398
398
  * @param {Object} options options object
399
- * @param {Module} options.module the module
399
+ * @param {Module | null} options.module the module
400
400
  * @param {ChunkGraph} options.chunkGraph the chunk graph
401
401
  * @param {string} options.request the request that should be printed as comment
402
402
  * @param {boolean=} options.weak if the dependency is weak (will create a nice error message)
@@ -439,7 +439,7 @@ class RuntimeTemplate {
439
439
 
440
440
  /**
441
441
  * @param {Object} options options object
442
- * @param {Module} options.module the module
442
+ * @param {Module | null} options.module the module
443
443
  * @param {ChunkGraph} options.chunkGraph the chunk graph
444
444
  * @param {string} options.request the request that should be printed as comment
445
445
  * @param {boolean=} options.weak if the dependency is weak (will create a nice error message)
@@ -939,11 +939,29 @@ class RuntimeTemplate {
939
939
  if (chunks.length === 1) {
940
940
  const chunkId = JSON.stringify(chunks[0].id);
941
941
  runtimeRequirements.add(RuntimeGlobals.ensureChunk);
942
- return `${RuntimeGlobals.ensureChunk}(${comment}${chunkId})`;
942
+
943
+ const fetchPriority = chunkGroup.options.fetchPriority;
944
+
945
+ if (fetchPriority) {
946
+ runtimeRequirements.add(RuntimeGlobals.hasFetchPriority);
947
+ }
948
+
949
+ return `${RuntimeGlobals.ensureChunk}(${comment}${chunkId}${
950
+ fetchPriority ? `, ${JSON.stringify(fetchPriority)}` : ""
951
+ })`;
943
952
  } else if (chunks.length > 0) {
944
953
  runtimeRequirements.add(RuntimeGlobals.ensureChunk);
954
+
955
+ const fetchPriority = chunkGroup.options.fetchPriority;
956
+
957
+ if (fetchPriority) {
958
+ runtimeRequirements.add(RuntimeGlobals.hasFetchPriority);
959
+ }
960
+
945
961
  const requireChunkId = chunk =>
946
- `${RuntimeGlobals.ensureChunk}(${JSON.stringify(chunk.id)})`;
962
+ `${RuntimeGlobals.ensureChunk}(${JSON.stringify(chunk.id)}${
963
+ fetchPriority ? `, ${JSON.stringify(fetchPriority)}` : ""
964
+ })`;
947
965
  return `Promise.all(${comment.trim()}[${chunks
948
966
  .map(requireChunkId)
949
967
  .join(", ")}])`;