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
@@ -36,6 +36,12 @@ const validate = createSchemaValidation(
36
36
  * @property {number} bSize
37
37
  */
38
38
 
39
+ /**
40
+ * @template K, V
41
+ * @param {Map<K, Set<V>>} map map
42
+ * @param {K} key key
43
+ * @param {V} value value
44
+ */
39
45
  const addToSetMap = (map, key, value) => {
40
46
  const set = map.get(key);
41
47
  if (set === undefined) {
@@ -68,7 +74,9 @@ class LimitChunkCountPlugin {
68
74
  },
69
75
  chunks => {
70
76
  const chunkGraph = compilation.chunkGraph;
71
- const maxChunks = options.maxChunks;
77
+ const maxChunks =
78
+ /** @type {LimitChunkCountPluginOptions} */
79
+ (options).maxChunks;
72
80
  if (!maxChunks) return;
73
81
  if (maxChunks < 1) return;
74
82
  if (compilation.chunks.size <= maxChunks) return;
@@ -88,9 +96,17 @@ class LimitChunkCountPlugin {
88
96
  c => c.sizeDiff,
89
97
  (a, b) => b - a,
90
98
  // Layer 2: ordered by smallest combined size
99
+ /**
100
+ * @param {ChunkCombination} c combination
101
+ * @returns {number} integrated size
102
+ */
91
103
  c => c.integratedSize,
92
104
  (a, b) => a - b,
93
105
  // Layer 3: ordered by position difference in orderedChunk (-> to be deterministic)
106
+ /**
107
+ * @param {ChunkCombination} c combination
108
+ * @returns {number} position difference
109
+ */
94
110
  c => c.bIdx - c.aIdx,
95
111
  (a, b) => a - b,
96
112
  // Layer 4: ordered by position in orderedChunk (-> to be deterministic)
@@ -193,14 +209,18 @@ class LimitChunkCountPlugin {
193
209
  // Update all affected combinations
194
210
  // delete all combination with the removed chunk
195
211
  // we will use combinations with the kept chunk instead
196
- for (const combination of combinationsByChunk.get(a)) {
212
+ for (const combination of /** @type {Set<ChunkCombination>} */ (
213
+ combinationsByChunk.get(a)
214
+ )) {
197
215
  if (combination.deleted) continue;
198
216
  combination.deleted = true;
199
217
  combinations.delete(combination);
200
218
  }
201
219
 
202
220
  // Update combinations with the kept chunk with new sizes
203
- for (const combination of combinationsByChunk.get(b)) {
221
+ for (const combination of /** @type {Set<ChunkCombination>} */ (
222
+ combinationsByChunk.get(b)
223
+ )) {
204
224
  if (combination.deleted) continue;
205
225
  if (combination.a === b) {
206
226
  if (!chunkGraph.canChunksBeIntegrated(a, combination.b)) {
@@ -243,7 +263,12 @@ class LimitChunkCountPlugin {
243
263
  finishUpdate();
244
264
  }
245
265
  }
246
- combinationsByChunk.set(a, combinationsByChunk.get(b));
266
+ combinationsByChunk.set(
267
+ a,
268
+ /** @type {Set<ChunkCombination>} */ (
269
+ combinationsByChunk.get(b)
270
+ )
271
+ );
247
272
  combinationsByChunk.delete(b);
248
273
  }
249
274
  }
@@ -39,7 +39,7 @@ const comparator = compareSelect(e => e.name, compareStringsNumeric);
39
39
  /**
40
40
  * @param {boolean} deterministic use deterministic names
41
41
  * @param {ExportsInfo} exportsInfo exports info
42
- * @param {boolean} isNamespace is namespace object
42
+ * @param {boolean | undefined} isNamespace is namespace object
43
43
  * @returns {void}
44
44
  */
45
45
  const mangleExportsInfo = (deterministic, exportsInfo, isNamespace) => {
@@ -9,6 +9,11 @@ const SizeFormatHelpers = require("../SizeFormatHelpers");
9
9
  const WebpackError = require("../WebpackError");
10
10
 
11
11
  class MinMaxSizeWarning extends WebpackError {
12
+ /**
13
+ * @param {string[] | undefined} keys keys
14
+ * @param {number} minSize minimum size
15
+ * @param {number} maxSize maximum size
16
+ */
12
17
  constructor(keys, minSize, maxSize) {
13
18
  let keysMessage = "Fallback cache group";
14
19
  if (keys) {
@@ -40,6 +40,10 @@ const ConcatenatedModule = require("./ConcatenatedModule");
40
40
  * @property {number} added
41
41
  */
42
42
 
43
+ /**
44
+ * @param {string} msg message
45
+ * @returns {string} formatted message
46
+ */
43
47
  const formatBailoutReason = msg => {
44
48
  return "ModuleConcatenation bailout: " + msg;
45
49
  };
@@ -64,8 +68,13 @@ class ModuleConcatenationPlugin {
64
68
  );
65
69
  }
66
70
  const moduleGraph = compilation.moduleGraph;
71
+ /** @type {Map<Module, string | ((requestShortener: RequestShortener) => string)>} */
67
72
  const bailoutReasonMap = new Map();
68
73
 
74
+ /**
75
+ * @param {Module} module the module
76
+ * @param {string | ((requestShortener: RequestShortener) => string)} reason the reason
77
+ */
69
78
  const setBailoutReason = (module, reason) => {
70
79
  setInnerBailoutReason(module, reason);
71
80
  moduleGraph
@@ -77,16 +86,30 @@ class ModuleConcatenationPlugin {
77
86
  );
78
87
  };
79
88
 
89
+ /**
90
+ * @param {Module} module the module
91
+ * @param {string | ((requestShortener: RequestShortener) => string)} reason the reason
92
+ */
80
93
  const setInnerBailoutReason = (module, reason) => {
81
94
  bailoutReasonMap.set(module, reason);
82
95
  };
83
96
 
97
+ /**
98
+ * @param {Module} module the module
99
+ * @param {RequestShortener} requestShortener the request shortener
100
+ * @returns {string | ((requestShortener: RequestShortener) => string) | undefined} the reason
101
+ */
84
102
  const getInnerBailoutReason = (module, requestShortener) => {
85
103
  const reason = bailoutReasonMap.get(module);
86
104
  if (typeof reason === "function") return reason(requestShortener);
87
105
  return reason;
88
106
  };
89
107
 
108
+ /**
109
+ * @param {Module} module the module
110
+ * @param {Module | function(RequestShortener): string} problem the problem
111
+ * @returns {(requestShortener: RequestShortener) => string} the reason
112
+ */
90
113
  const formatBailoutWarning = (module, problem) => requestShortener => {
91
114
  if (typeof problem === "function") {
92
115
  return formatBailoutReason(
@@ -460,7 +483,7 @@ class ModuleConcatenationPlugin {
460
483
  c.module === rootModule ? c.originModule : c.module;
461
484
  const innerConnection =
462
485
  c.dependency instanceof HarmonyImportDependency &&
463
- modules.has(otherModule);
486
+ modules.has(/** @type {Module} */ (otherModule));
464
487
  return !innerConnection;
465
488
  });
466
489
  // add concatenated module to the compilation
@@ -533,7 +556,7 @@ class ModuleConcatenationPlugin {
533
556
  * @param {ChunkGraph} chunkGraph the chunk graph
534
557
  * @param {boolean} avoidMutateOnFailure avoid mutating the config when adding fails
535
558
  * @param {Statistics} statistics gathering metrics
536
- * @returns {Module | function(RequestShortener): string} the problematic module
559
+ * @returns {null | Module | function(RequestShortener): string} the problematic module
537
560
  */
538
561
  _tryToAdd(
539
562
  compilation,
@@ -572,6 +595,10 @@ class ModuleConcatenationPlugin {
572
595
  chunkGraph.getModuleChunksIterable(config.rootModule)
573
596
  ).filter(chunk => !chunkGraph.isModuleInChunk(module, chunk));
574
597
  if (missingChunks.length > 0) {
598
+ /**
599
+ * @param {RequestShortener} requestShortener request shortener
600
+ * @returns {string} problem description
601
+ */
575
602
  const problem = requestShortener => {
576
603
  const missingChunksList = Array.from(
577
604
  new Set(missingChunks.map(chunk => chunk.name || "unnamed chunk(s)"))
@@ -609,6 +636,10 @@ class ModuleConcatenationPlugin {
609
636
  return connection.isActive(runtime);
610
637
  });
611
638
  if (activeNonModulesConnections.length > 0) {
639
+ /**
640
+ * @param {RequestShortener} requestShortener request shortener
641
+ * @returns {string} problem description
642
+ */
612
643
  const problem = requestShortener => {
613
644
  const importingExplanations = new Set(
614
645
  activeNonModulesConnections.map(c => c.explanation).filter(Boolean)
@@ -666,6 +697,10 @@ class ModuleConcatenationPlugin {
666
697
  return false;
667
698
  });
668
699
  if (otherChunkModules.length > 0) {
700
+ /**
701
+ * @param {RequestShortener} requestShortener request shortener
702
+ * @returns {string} problem description
703
+ */
669
704
  const problem = requestShortener => {
670
705
  const names = otherChunkModules
671
706
  .map(m => m.readableIdentifier(requestShortener))
@@ -693,6 +728,10 @@ class ModuleConcatenationPlugin {
693
728
  nonHarmonyConnections.set(originModule, connections);
694
729
  }
695
730
  if (nonHarmonyConnections.size > 0) {
731
+ /**
732
+ * @param {RequestShortener} requestShortener request shortener
733
+ * @returns {string} problem description
734
+ */
696
735
  const problem = requestShortener => {
697
736
  const names = Array.from(nonHarmonyConnections)
698
737
  .map(([originModule, connections]) => {
@@ -753,6 +792,10 @@ class ModuleConcatenationPlugin {
753
792
  }
754
793
  }
755
794
  if (otherRuntimeConnections.length > 0) {
795
+ /**
796
+ * @param {RequestShortener} requestShortener request shortener
797
+ * @returns {string} problem description
798
+ */
756
799
  const problem = requestShortener => {
757
800
  return `Module ${module.readableIdentifier(
758
801
  requestShortener
@@ -831,10 +874,17 @@ class ConcatConfiguration {
831
874
  this.warnings = new Map();
832
875
  }
833
876
 
877
+ /**
878
+ * @param {Module} module the module
879
+ */
834
880
  add(module) {
835
881
  this.modules.add(module);
836
882
  }
837
883
 
884
+ /**
885
+ * @param {Module} module the module
886
+ * @returns {boolean} true, when the module is in the module set
887
+ */
838
888
  has(module) {
839
889
  return this.modules.has(module);
840
890
  }
@@ -843,10 +893,17 @@ class ConcatConfiguration {
843
893
  return this.modules.size === 1;
844
894
  }
845
895
 
896
+ /**
897
+ * @param {Module} module the module
898
+ * @param {Module | function(RequestShortener): string} problem the problem
899
+ */
846
900
  addWarning(module, problem) {
847
901
  this.warnings.set(module, problem);
848
902
  }
849
903
 
904
+ /**
905
+ * @returns {Map<Module, Module | function(RequestShortener): string>} warnings
906
+ */
850
907
  getWarningsSorted() {
851
908
  return new Map(
852
909
  Array.from(this.warnings).sort((a, b) => {
@@ -13,12 +13,18 @@ const { compareSelect, compareStrings } = require("../util/comparators");
13
13
  const createHash = require("../util/createHash");
14
14
 
15
15
  /** @typedef {import("webpack-sources").Source} Source */
16
+ /** @typedef {import("../Cache").Etag} Etag */
16
17
  /** @typedef {import("../Compilation").AssetInfo} AssetInfo */
17
18
  /** @typedef {import("../Compiler")} Compiler */
18
19
  /** @typedef {typeof import("../util/Hash")} Hash */
19
20
 
20
21
  const EMPTY_SET = new Set();
21
22
 
23
+ /**
24
+ * @template T
25
+ * @param {T | T[]} itemOrItems item or items
26
+ * @param {Set<T>} list list
27
+ */
22
28
  const addToList = (itemOrItems, list) => {
23
29
  if (Array.isArray(itemOrItems)) {
24
30
  for (const item of itemOrItems) {
@@ -61,6 +67,10 @@ const quoteMeta = str => {
61
67
 
62
68
  const cachedSourceMap = new WeakMap();
63
69
 
70
+ /**
71
+ * @param {Source} source source
72
+ * @returns {CachedSource} cached source
73
+ */
64
74
  const toCachedSource = source => {
65
75
  if (source instanceof CachedSource) {
66
76
  return source;
@@ -72,6 +82,10 @@ const toCachedSource = source => {
72
82
  return newSource;
73
83
  };
74
84
 
85
+ /** @typedef {Set<string>} OwnHashes */
86
+ /** @typedef {Set<string>} ReferencedHashes */
87
+ /** @typedef {Set<string>} Hashes */
88
+
75
89
  /**
76
90
  * @typedef {Object} AssetInfoForRealContentHash
77
91
  * @property {string} name
@@ -80,11 +94,11 @@ const toCachedSource = source => {
80
94
  * @property {RawSource | undefined} newSource
81
95
  * @property {RawSource | undefined} newSourceWithoutOwn
82
96
  * @property {string} content
83
- * @property {Set<string>} ownHashes
84
- * @property {Promise} contentComputePromise
85
- * @property {Promise} contentComputeWithoutOwnPromise
86
- * @property {Set<string>} referencedHashes
87
- * @property {Set<string>} hashes
97
+ * @property {OwnHashes | undefined} ownHashes
98
+ * @property {Promise<void> | undefined} contentComputePromise
99
+ * @property {Promise<void> | undefined} contentComputeWithoutOwnPromise
100
+ * @property {ReferencedHashes | undefined} referencedHashes
101
+ * @property {Hashes} hashes
88
102
  */
89
103
 
90
104
  /**
@@ -149,27 +163,25 @@ class RealContentHashPlugin {
149
163
  const assets = compilation.getAssets();
150
164
  /** @type {AssetInfoForRealContentHash[]} */
151
165
  const assetsWithInfo = [];
166
+ /** @type {Map<string, [AssetInfoForRealContentHash]>} */
152
167
  const hashToAssets = new Map();
153
168
  for (const { source, info, name } of assets) {
154
169
  const cachedSource = toCachedSource(source);
155
- const content = cachedSource.source();
156
- /** @type {Set<string>} */
170
+ const content = /** @type {string} */ (cachedSource.source());
171
+ /** @type {Hashes} */
157
172
  const hashes = new Set();
158
173
  addToList(info.contenthash, hashes);
174
+ /** @type {AssetInfoForRealContentHash} */
159
175
  const data = {
160
176
  name,
161
177
  info,
162
178
  source: cachedSource,
163
- /** @type {RawSource | undefined} */
164
179
  newSource: undefined,
165
- /** @type {RawSource | undefined} */
166
180
  newSourceWithoutOwn: undefined,
167
181
  content,
168
- /** @type {Set<string>} */
169
182
  ownHashes: undefined,
170
183
  contentComputePromise: undefined,
171
184
  contentComputeWithoutOwnPromise: undefined,
172
- /** @type {Set<string>} */
173
185
  referencedHashes: undefined,
174
186
  hashes
175
187
  };
@@ -218,11 +230,17 @@ class RealContentHashPlugin {
218
230
  });
219
231
  })
220
232
  );
233
+ /**
234
+ * @param {string} hash the hash
235
+ * @returns {undefined | ReferencedHashes} the referenced hashes
236
+ */
221
237
  const getDependencies = hash => {
222
238
  const assets = hashToAssets.get(hash);
223
239
  if (!assets) {
224
240
  const referencingAssets = assetsWithInfo.filter(asset =>
225
- asset.referencedHashes.has(hash)
241
+ /** @type {ReferencedHashes} */ (asset.referencedHashes).has(
242
+ hash
243
+ )
226
244
  );
227
245
  const err = new WebpackError(`RealContentHashPlugin
228
246
  Some kind of unexpected caching problem occurred.
@@ -242,23 +260,36 @@ ${referencingAssets
242
260
  }
243
261
  const hashes = new Set();
244
262
  for (const { referencedHashes, ownHashes } of assets) {
245
- if (!ownHashes.has(hash)) {
246
- for (const hash of ownHashes) {
263
+ if (!(/** @type {OwnHashes} */ (ownHashes).has(hash))) {
264
+ for (const hash of /** @type {OwnHashes} */ (ownHashes)) {
247
265
  hashes.add(hash);
248
266
  }
249
267
  }
250
- for (const hash of referencedHashes) {
268
+ for (const hash of /** @type {ReferencedHashes} */ (
269
+ referencedHashes
270
+ )) {
251
271
  hashes.add(hash);
252
272
  }
253
273
  }
254
274
  return hashes;
255
275
  };
276
+ /**
277
+ * @param {string} hash the hash
278
+ * @returns {string} the hash info
279
+ */
256
280
  const hashInfo = hash => {
257
281
  const assets = hashToAssets.get(hash);
258
- return `${hash} (${Array.from(assets, a => a.name)})`;
282
+ return `${hash} (${Array.from(
283
+ /** @type {AssetInfoForRealContentHash[]} */ (assets),
284
+ a => a.name
285
+ )})`;
259
286
  };
260
287
  const hashesInOrder = new Set();
261
288
  for (const hash of hashToAssets.keys()) {
289
+ /**
290
+ * @param {string} hash the hash
291
+ * @param {Set<string>} stack stack of hashes
292
+ */
262
293
  const add = (hash, stack) => {
263
294
  const deps = getDependencies(hash);
264
295
  if (!deps) return;
@@ -282,21 +313,31 @@ ${referencingAssets
282
313
  add(hash, new Set());
283
314
  }
284
315
  const hashToNewHash = new Map();
316
+ /**
317
+ * @param {AssetInfoForRealContentHash} asset asset info
318
+ * @returns {Etag} etag
319
+ */
285
320
  const getEtag = asset =>
286
321
  cacheGenerate.mergeEtags(
287
322
  cacheGenerate.getLazyHashedEtag(asset.source),
288
- Array.from(asset.referencedHashes, hash =>
289
- hashToNewHash.get(hash)
323
+ Array.from(
324
+ /** @type {ReferencedHashes} */ (asset.referencedHashes),
325
+ hash => hashToNewHash.get(hash)
290
326
  ).join("|")
291
327
  );
328
+ /**
329
+ * @param {AssetInfoForRealContentHash} asset asset info
330
+ * @returns {Promise<void>}
331
+ */
292
332
  const computeNewContent = asset => {
293
333
  if (asset.contentComputePromise) return asset.contentComputePromise;
294
334
  return (asset.contentComputePromise = (async () => {
295
335
  if (
296
- asset.ownHashes.size > 0 ||
297
- Array.from(asset.referencedHashes).some(
298
- hash => hashToNewHash.get(hash) !== hash
299
- )
336
+ /** @type {OwnHashes} */ (asset.ownHashes).size > 0 ||
337
+ Array.from(
338
+ /** @type {ReferencedHashes} */
339
+ (asset.referencedHashes)
340
+ ).some(hash => hashToNewHash.get(hash) !== hash)
300
341
  ) {
301
342
  const identifier = asset.name;
302
343
  const etag = getEtag(asset);
@@ -313,15 +354,20 @@ ${referencingAssets
313
354
  }
314
355
  })());
315
356
  };
357
+ /**
358
+ * @param {AssetInfoForRealContentHash} asset asset info
359
+ * @returns {Promise<void>}
360
+ */
316
361
  const computeNewContentWithoutOwn = asset => {
317
362
  if (asset.contentComputeWithoutOwnPromise)
318
363
  return asset.contentComputeWithoutOwnPromise;
319
364
  return (asset.contentComputeWithoutOwnPromise = (async () => {
320
365
  if (
321
- asset.ownHashes.size > 0 ||
322
- Array.from(asset.referencedHashes).some(
323
- hash => hashToNewHash.get(hash) !== hash
324
- )
366
+ /** @type {OwnHashes} */ (asset.ownHashes).size > 0 ||
367
+ Array.from(
368
+ /** @type {ReferencedHashes} */
369
+ (asset.referencedHashes)
370
+ ).some(hash => hashToNewHash.get(hash) !== hash)
325
371
  ) {
326
372
  const identifier = asset.name + "|without-own";
327
373
  const etag = getEtag(asset);
@@ -332,7 +378,9 @@ ${referencingAssets
332
378
  const newContent = asset.content.replace(
333
379
  hashRegExp,
334
380
  hash => {
335
- if (asset.ownHashes.has(hash)) {
381
+ if (
382
+ /** @type {OwnHashes} */ (asset.ownHashes).has(hash)
383
+ ) {
336
384
  return "";
337
385
  }
338
386
  return hashToNewHash.get(hash);
@@ -346,17 +394,19 @@ ${referencingAssets
346
394
  };
347
395
  const comparator = compareSelect(a => a.name, compareStrings);
348
396
  for (const oldHash of hashesInOrder) {
349
- const assets = hashToAssets.get(oldHash);
397
+ const assets =
398
+ /** @type {AssetInfoForRealContentHash[]} */
399
+ (hashToAssets.get(oldHash));
350
400
  assets.sort(comparator);
351
401
  await Promise.all(
352
402
  assets.map(asset =>
353
- asset.ownHashes.has(oldHash)
403
+ /** @type {OwnHashes} */ (asset.ownHashes).has(oldHash)
354
404
  ? computeNewContentWithoutOwn(asset)
355
405
  : computeNewContent(asset)
356
406
  )
357
407
  );
358
408
  const assetsContent = mapAndDeduplicateBuffers(assets, asset => {
359
- if (asset.ownHashes.has(oldHash)) {
409
+ if (/** @type {OwnHashes} */ (asset.ownHashes).has(oldHash)) {
360
410
  return asset.newSourceWithoutOwn
361
411
  ? asset.newSourceWithoutOwn.buffer()
362
412
  : asset.source.buffer();
@@ -9,6 +9,8 @@ const { STAGE_BASIC } = require("../OptimizationStages");
9
9
  const Queue = require("../util/Queue");
10
10
  const { intersect } = require("../util/SetHelpers");
11
11
 
12
+ /** @typedef {import("../Chunk")} Chunk */
13
+ /** @typedef {import("../ChunkGroup")} ChunkGroup */
12
14
  /** @typedef {import("../Compiler")} Compiler */
13
15
 
14
16
  class RemoveParentModulesPlugin {
@@ -18,6 +20,10 @@ class RemoveParentModulesPlugin {
18
20
  */
19
21
  apply(compiler) {
20
22
  compiler.hooks.compilation.tap("RemoveParentModulesPlugin", compilation => {
23
+ /**
24
+ * @param {Iterable<Chunk>} chunks the chunks
25
+ * @param {ChunkGroup[]} chunkGroups the chunk groups
26
+ */
21
27
  const handler = (chunks, chunkGroups) => {
22
28
  const chunkGraph = compilation.chunkGraph;
23
29
  const queue = new Queue();
@@ -5,11 +5,17 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ /** @typedef {import("../Compilation").EntryData} EntryData */
8
9
  /** @typedef {import("../Compiler")} Compiler */
10
+ /** @typedef {import("../Entrypoint")} Entrypoint */
9
11
 
10
12
  class RuntimeChunkPlugin {
11
13
  constructor(options) {
12
14
  this.options = {
15
+ /**
16
+ * @param {Entrypoint} entrypoint entrypoint name
17
+ * @returns {string} runtime chunk name
18
+ */
13
19
  name: entrypoint => `runtime~${entrypoint.name}`,
14
20
  ...options
15
21
  };
@@ -26,7 +32,9 @@ class RuntimeChunkPlugin {
26
32
  "RuntimeChunkPlugin",
27
33
  (_, { name: entryName }) => {
28
34
  if (entryName === undefined) return;
29
- const data = compilation.entries.get(entryName);
35
+ const data =
36
+ /** @type {EntryData} */
37
+ (compilation.entries.get(entryName));
30
38
  if (data.options.runtime === undefined && !data.options.dependOn) {
31
39
  // Determine runtime chunk name
32
40
  let name = this.options.name;
@@ -16,6 +16,8 @@ const HarmonyExportImportedSpecifierDependency = require("../dependencies/Harmon
16
16
  const HarmonyImportSpecifierDependency = require("../dependencies/HarmonyImportSpecifierDependency");
17
17
  const formatLocation = require("../formatLocation");
18
18
 
19
+ /** @typedef {import("estree").ModuleDeclaration} ModuleDeclaration */
20
+ /** @typedef {import("estree").Statement} Statement */
19
21
  /** @typedef {import("../Compiler")} Compiler */
20
22
  /** @typedef {import("../Dependency")} Dependency */
21
23
  /** @typedef {import("../Module")} Module */
@@ -117,6 +119,7 @@ class SideEffectsFlagPlugin {
117
119
  * @returns {void}
118
120
  */
119
121
  const parserHandler = parser => {
122
+ /** @type {undefined | Statement | ModuleDeclaration} */
120
123
  let sideEffectsStatement;
121
124
  parser.hooks.program.tap(PLUGIN_NAME, () => {
122
125
  sideEffectsStatement = undefined;
@@ -258,7 +261,7 @@ class SideEffectsFlagPlugin {
258
261
  // TODO improve for export *
259
262
  if (isReexport && dep.name) {
260
263
  const exportInfo = moduleGraph.getExportInfo(
261
- connection.originModule,
264
+ /** @type {Module} */ (connection.originModule),
262
265
  dep.name
263
266
  );
264
267
  exportInfo.moveTarget(
@@ -319,6 +322,12 @@ class SideEffectsFlagPlugin {
319
322
  );
320
323
  }
321
324
 
325
+ /**
326
+ * @param {string} moduleName the module name
327
+ * @param {undefined | boolean | string | string[]} flagValue the flag value
328
+ * @param {Map<string, RegExp>} cache cache for glob to regexp
329
+ * @returns {boolean | undefined} true, when the module has side effects, undefined or false when not
330
+ */
322
331
  static moduleHasSideEffects(moduleName, flagValue, cache) {
323
332
  switch (typeof flagValue) {
324
333
  case "undefined":