webpack 5.104.1 → 5.105.4

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.
Files changed (333) hide show
  1. package/README.md +2 -2
  2. package/bin/webpack.js +6 -3
  3. package/lib/APIPlugin.js +85 -15
  4. package/lib/AbstractMethodError.js +1 -0
  5. package/lib/AsyncDependenciesBlock.js +17 -2
  6. package/lib/AsyncDependencyToInitialChunkError.js +3 -0
  7. package/lib/AutomaticPrefetchPlugin.js +1 -1
  8. package/lib/BannerPlugin.js +5 -1
  9. package/lib/CacheFacade.js +2 -2
  10. package/lib/CaseSensitiveModulesWarning.js +1 -0
  11. package/lib/Chunk.js +9 -5
  12. package/lib/ChunkGraph.js +30 -9
  13. package/lib/ChunkGroup.js +6 -3
  14. package/lib/ChunkRenderError.js +9 -2
  15. package/lib/CleanPlugin.js +5 -1
  16. package/lib/CodeGenerationError.js +7 -1
  17. package/lib/CodeGenerationResults.js +10 -3
  18. package/lib/CommentCompilationWarning.js +2 -1
  19. package/lib/Compilation.js +294 -244
  20. package/lib/Compiler.js +4 -3
  21. package/lib/ConcatenationScope.js +2 -1
  22. package/lib/ConcurrentCompilationError.js +3 -3
  23. package/lib/ContextModule.js +255 -112
  24. package/lib/ContextModuleFactory.js +14 -2
  25. package/lib/DefinePlugin.js +15 -8
  26. package/lib/DelegatedModule.js +6 -0
  27. package/lib/DelegatedModuleFactoryPlugin.js +2 -0
  28. package/lib/Dependency.js +7 -2
  29. package/lib/DependencyTemplates.js +3 -2
  30. package/lib/DllModule.js +2 -0
  31. package/lib/DllReferencePlugin.js +1 -0
  32. package/lib/DotenvPlugin.js +11 -5
  33. package/lib/DynamicEntryPlugin.js +8 -1
  34. package/lib/EnvironmentNotSupportAsyncWarning.js +2 -0
  35. package/lib/EvalDevToolModulePlugin.js +3 -0
  36. package/lib/EvalSourceMapDevToolPlugin.js +25 -14
  37. package/lib/ExportsInfo.js +8 -34
  38. package/lib/ExternalModule.js +18 -2
  39. package/lib/ExternalModuleFactoryPlugin.js +9 -2
  40. package/lib/ExternalsPlugin.js +2 -1
  41. package/lib/FalseIIFEUmdWarning.js +1 -0
  42. package/lib/FileSystemInfo.js +49 -25
  43. package/lib/FlagDependencyExportsPlugin.js +8 -1
  44. package/lib/FlagDependencyUsagePlugin.js +9 -7
  45. package/lib/HarmonyLinkingError.js +1 -0
  46. package/lib/HookWebpackError.js +2 -0
  47. package/lib/HotModuleReplacementPlugin.js +16 -2
  48. package/lib/IgnoreWarningsPlugin.js +5 -2
  49. package/lib/InitFragment.js +1 -0
  50. package/lib/InvalidDependenciesModuleWarning.js +1 -0
  51. package/lib/LibManifestPlugin.js +1 -0
  52. package/lib/ManifestPlugin.js +8 -1
  53. package/lib/Module.js +51 -8
  54. package/lib/ModuleBuildError.js +3 -1
  55. package/lib/ModuleDependencyError.js +1 -0
  56. package/lib/ModuleDependencyWarning.js +1 -0
  57. package/lib/ModuleError.js +4 -1
  58. package/lib/ModuleFilenameHelpers.js +4 -2
  59. package/lib/ModuleGraph.js +3 -0
  60. package/lib/ModuleGraphConnection.js +10 -10
  61. package/lib/ModuleHashingError.js +2 -0
  62. package/lib/ModuleInfoHeaderPlugin.js +6 -1
  63. package/lib/ModuleNotFoundError.js +1 -0
  64. package/lib/ModuleParseError.js +5 -1
  65. package/lib/ModuleProfile.js +1 -1
  66. package/lib/ModuleRestoreError.js +2 -0
  67. package/lib/ModuleSourceTypeConstants.js +1 -11
  68. package/lib/ModuleStoreError.js +2 -0
  69. package/lib/ModuleWarning.js +3 -1
  70. package/lib/MultiCompiler.js +11 -7
  71. package/lib/MultiStats.js +5 -5
  72. package/lib/MultiWatching.js +2 -2
  73. package/lib/NoModeWarning.js +1 -0
  74. package/lib/NodeStuffInWebError.js +1 -0
  75. package/lib/NormalModule.js +28 -5
  76. package/lib/NormalModuleFactory.js +20 -4
  77. package/lib/OptionsApply.js +3 -1
  78. package/lib/ProgressPlugin.js +4 -0
  79. package/lib/RawModule.js +2 -0
  80. package/lib/RuntimeModule.js +28 -1
  81. package/lib/RuntimePlugin.js +7 -9
  82. package/lib/RuntimeTemplate.js +14 -7
  83. package/lib/SourceMapDevToolModuleOptionsPlugin.js +1 -0
  84. package/lib/SourceMapDevToolPlugin.js +40 -25
  85. package/lib/Stats.js +3 -2
  86. package/lib/Template.js +10 -5
  87. package/lib/TemplatedPathPlugin.js +4 -2
  88. package/lib/UnhandledSchemeError.js +1 -0
  89. package/lib/UnsupportedFeatureWarning.js +3 -0
  90. package/lib/WarnDeprecatedOptionPlugin.js +1 -0
  91. package/lib/WatchIgnorePlugin.js +1 -1
  92. package/lib/Watching.js +5 -0
  93. package/lib/WebpackError.js +4 -0
  94. package/lib/WebpackOptionsApply.js +74 -44
  95. package/lib/asset/AssetBytesGenerator.js +1 -0
  96. package/lib/asset/AssetGenerator.js +18 -3
  97. package/lib/asset/AssetModulesPlugin.js +48 -2
  98. package/lib/asset/AssetParser.js +4 -0
  99. package/lib/asset/AssetSourceGenerator.js +1 -0
  100. package/lib/asset/RawDataUrlModule.js +9 -1
  101. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -1
  102. package/lib/buildChunkGraph.js +31 -2
  103. package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
  104. package/lib/cache/PackFileCacheStrategy.js +41 -8
  105. package/lib/cache/getLazyHashedEtag.js +13 -4
  106. package/lib/cache/mergeEtags.js +3 -1
  107. package/lib/cli.js +3 -1
  108. package/lib/config/defaults.js +65 -44
  109. package/lib/config/normalization.js +96 -0
  110. package/lib/container/ContainerEntryDependency.js +3 -0
  111. package/lib/container/ContainerEntryModule.js +7 -0
  112. package/lib/container/ContainerExposedDependency.js +1 -0
  113. package/lib/container/FallbackDependency.js +1 -0
  114. package/lib/container/FallbackItemDependency.js +1 -0
  115. package/lib/container/FallbackModule.js +4 -0
  116. package/lib/container/HoistContainerReferencesPlugin.js +6 -0
  117. package/lib/container/ModuleFederationPlugin.js +1 -1
  118. package/lib/container/RemoteModule.js +42 -1
  119. package/lib/css/CssGenerator.js +38 -4
  120. package/lib/css/CssModulesPlugin.js +33 -30
  121. package/lib/css/CssParser.js +12 -9
  122. package/lib/debug/ProfilingPlugin.js +1 -0
  123. package/lib/dependencies/AMDDefineDependency.js +3 -1
  124. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -0
  125. package/lib/dependencies/AMDPlugin.js +1 -1
  126. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +7 -1
  127. package/lib/dependencies/CachedConstDependency.js +1 -0
  128. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -0
  129. package/lib/dependencies/CommonJsExportRequireDependency.js +5 -0
  130. package/lib/dependencies/CommonJsFullRequireDependency.js +2 -0
  131. package/lib/dependencies/CommonJsImportsParserPlugin.js +315 -506
  132. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
  133. package/lib/dependencies/CommonJsSelfReferenceDependency.js +1 -0
  134. package/lib/dependencies/ConstDependency.js +1 -0
  135. package/lib/dependencies/ContextDependencyHelpers.js +11 -4
  136. package/lib/dependencies/ContextElementDependency.js +1 -0
  137. package/lib/dependencies/CreateRequireParserPlugin.js +356 -0
  138. package/lib/dependencies/CriticalDependencyWarning.js +1 -0
  139. package/lib/dependencies/CssIcssExportDependency.js +7 -4
  140. package/lib/dependencies/CssIcssSymbolDependency.js +1 -0
  141. package/lib/dependencies/CssUrlDependency.js +2 -3
  142. package/lib/dependencies/ExternalModuleInitFragment.js +4 -1
  143. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +0 -9
  144. package/lib/dependencies/HarmonyAcceptDependency.js +3 -0
  145. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +3 -1
  146. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +4 -8
  147. package/lib/dependencies/HarmonyExportExpressionDependency.js +4 -0
  148. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +8 -1
  149. package/lib/dependencies/HarmonyExportInitFragment.js +17 -3
  150. package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
  151. package/lib/dependencies/HarmonyImportDependency.js +31 -1
  152. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +217 -49
  153. package/lib/dependencies/HarmonyImportSideEffectDependency.js +11 -5
  154. package/lib/dependencies/HarmonyImportSpecifierDependency.js +22 -3
  155. package/lib/dependencies/HarmonyModulesPlugin.js +4 -0
  156. package/lib/dependencies/ImportDependency.js +1 -0
  157. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
  158. package/lib/dependencies/ImportMetaPlugin.js +53 -11
  159. package/lib/dependencies/ImportParserPlugin.js +8 -23
  160. package/lib/dependencies/ImportPhase.js +4 -0
  161. package/lib/dependencies/LoaderPlugin.js +3 -0
  162. package/lib/dependencies/ModuleDecoratorDependency.js +1 -0
  163. package/lib/dependencies/ModuleDependency.js +1 -0
  164. package/lib/dependencies/ModuleInitFragmentDependency.js +87 -0
  165. package/lib/dependencies/ProvidedDependency.js +1 -0
  166. package/lib/dependencies/RequireContextPlugin.js +1 -0
  167. package/lib/dependencies/RequireEnsureDependenciesBlock.js +1 -1
  168. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +7 -2
  169. package/lib/dependencies/RuntimeRequirementsDependency.js +1 -0
  170. package/lib/dependencies/WorkerDependency.js +9 -3
  171. package/lib/dependencies/WorkerPlugin.js +1 -0
  172. package/lib/dependencies/getFunctionExpression.js +3 -1
  173. package/lib/electron/ElectronTargetPlugin.js +3 -1
  174. package/lib/errors/BuildCycleError.js +4 -1
  175. package/lib/esm/ModuleChunkFormatPlugin.js +6 -4
  176. package/lib/esm/ModuleChunkLoadingPlugin.js +1 -0
  177. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -0
  178. package/lib/hmr/LazyCompilationPlugin.js +5 -0
  179. package/lib/hmr/lazyCompilationBackend.js +3 -2
  180. package/lib/ids/ChunkModuleIdRangePlugin.js +9 -7
  181. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -0
  182. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -0
  183. package/lib/ids/HashedModuleIdsPlugin.js +3 -8
  184. package/lib/ids/IdHelpers.js +10 -8
  185. package/lib/ids/NamedChunkIdsPlugin.js +7 -5
  186. package/lib/ids/NamedModuleIdsPlugin.js +1 -0
  187. package/lib/ids/OccurrenceChunkIdsPlugin.js +2 -2
  188. package/lib/ids/OccurrenceModuleIdsPlugin.js +18 -10
  189. package/lib/ids/SyncModuleIdsPlugin.js +30 -20
  190. package/lib/javascript/BasicEvaluatedExpression.js +1 -0
  191. package/lib/javascript/EnableChunkLoadingPlugin.js +5 -2
  192. package/lib/javascript/JavascriptModulesPlugin.js +104 -30
  193. package/lib/javascript/JavascriptParser.js +48 -15
  194. package/lib/json/JsonGenerator.js +1 -0
  195. package/lib/json/JsonParser.js +9 -2
  196. package/lib/library/AbstractLibraryPlugin.js +4 -1
  197. package/lib/library/AmdLibraryPlugin.js +2 -1
  198. package/lib/library/AssignLibraryPlugin.js +6 -2
  199. package/lib/library/EnableLibraryPlugin.js +1 -0
  200. package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
  201. package/lib/library/JsonpLibraryPlugin.js +1 -1
  202. package/lib/library/ModuleLibraryPlugin.js +130 -13
  203. package/lib/library/SystemLibraryPlugin.js +4 -1
  204. package/lib/library/UmdLibraryPlugin.js +4 -3
  205. package/lib/logging/Logger.js +9 -5
  206. package/lib/logging/createConsoleLogger.js +4 -0
  207. package/lib/logging/truncateArgs.js +1 -1
  208. package/lib/node/CommonJsChunkLoadingPlugin.js +6 -4
  209. package/lib/node/NodeEnvironmentPlugin.js +1 -0
  210. package/lib/node/NodeTargetPlugin.js +10 -1
  211. package/lib/node/NodeTemplatePlugin.js +1 -0
  212. package/lib/node/NodeWatchFileSystem.js +6 -0
  213. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +1 -0
  214. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -0
  215. package/lib/node/ReadFileCompileWasmPlugin.js +1 -0
  216. package/lib/node/RequireChunkLoadingRuntimeModule.js +1 -0
  217. package/lib/node/nodeConsole.js +18 -1
  218. package/lib/optimize/AggressiveMergingPlugin.js +2 -1
  219. package/lib/optimize/AggressiveSplittingPlugin.js +15 -6
  220. package/lib/optimize/ConcatenatedModule.js +36 -19
  221. package/lib/optimize/FlagIncludedChunksPlugin.js +11 -1
  222. package/lib/optimize/InnerGraph.js +5 -3
  223. package/lib/optimize/InnerGraphPlugin.js +25 -25
  224. package/lib/optimize/LimitChunkCountPlugin.js +3 -2
  225. package/lib/optimize/MangleExportsPlugin.js +14 -2
  226. package/lib/optimize/MergeDuplicateChunksPlugin.js +5 -1
  227. package/lib/optimize/MinChunkSizePlugin.js +5 -2
  228. package/lib/optimize/ModuleConcatenationPlugin.js +23 -5
  229. package/lib/optimize/RealContentHashPlugin.js +37 -27
  230. package/lib/optimize/RemoveParentModulesPlugin.js +12 -3
  231. package/lib/optimize/RuntimeChunkPlugin.js +3 -5
  232. package/lib/optimize/SideEffectsFlagPlugin.js +3 -0
  233. package/lib/optimize/SplitChunksPlugin.js +23 -5
  234. package/lib/performance/AssetsOverSizeLimitWarning.js +7 -2
  235. package/lib/performance/EntrypointsOverSizeLimitWarning.js +7 -2
  236. package/lib/performance/NoAsyncChunksWarning.js +1 -0
  237. package/lib/performance/SizeLimitsPlugin.js +7 -6
  238. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +2 -0
  239. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +3 -1
  240. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +1 -0
  241. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +1 -0
  242. package/lib/rules/BasicEffectRulePlugin.js +2 -0
  243. package/lib/rules/BasicMatcherRulePlugin.js +3 -0
  244. package/lib/rules/ObjectMatcherRulePlugin.js +5 -1
  245. package/lib/rules/RuleSetCompiler.js +6 -0
  246. package/lib/runtime/AsyncModuleRuntimeModule.js +1 -0
  247. package/lib/runtime/ChunkNameRuntimeModule.js +1 -0
  248. package/lib/runtime/CompatRuntimeModule.js +1 -0
  249. package/lib/runtime/EnsureChunkRuntimeModule.js +1 -0
  250. package/lib/runtime/GetChunkFilenameRuntimeModule.js +5 -0
  251. package/lib/runtime/GetFullHashRuntimeModule.js +1 -0
  252. package/lib/runtime/GetMainFilenameRuntimeModule.js +2 -0
  253. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -0
  254. package/lib/runtime/LoadScriptRuntimeModule.js +2 -0
  255. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +16 -32
  256. package/lib/runtime/PublicPathRuntimeModule.js +1 -0
  257. package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -0
  258. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -0
  259. package/lib/runtime/StartupEntrypointRuntimeModule.js +1 -0
  260. package/lib/runtime/ToBinaryRuntimeModule.js +14 -6
  261. package/lib/schemes/HttpUriPlugin.js +39 -20
  262. package/lib/schemes/VirtualUrlPlugin.js +28 -2
  263. package/lib/serialization/BinaryMiddleware.js +4 -0
  264. package/lib/serialization/FileMiddleware.js +9 -4
  265. package/lib/serialization/ObjectMiddleware.js +34 -11
  266. package/lib/serialization/PlainObjectSerializer.js +2 -0
  267. package/lib/sharing/ConsumeSharedModule.js +78 -1
  268. package/lib/sharing/ConsumeSharedPlugin.js +5 -4
  269. package/lib/sharing/ProvideSharedModule.js +4 -0
  270. package/lib/sharing/ProvideSharedPlugin.js +24 -25
  271. package/lib/sharing/resolveMatchedConfigs.js +2 -2
  272. package/lib/sharing/utils.js +8 -6
  273. package/lib/stats/DefaultStatsFactoryPlugin.js +20 -12
  274. package/lib/stats/DefaultStatsPrinterPlugin.js +6 -5
  275. package/lib/stats/StatsFactory.js +2 -2
  276. package/lib/url/URLParserPlugin.js +5 -3
  277. package/lib/util/AppendOnlyStackedSet.js +78 -0
  278. package/lib/util/Hash.js +1 -0
  279. package/lib/util/IterableHelpers.js +1 -0
  280. package/lib/util/LazyBucketSortedSet.js +1 -0
  281. package/lib/util/LazySet.js +1 -0
  282. package/lib/util/ParallelismFactorCalculator.js +1 -0
  283. package/lib/util/SortableSet.js +1 -0
  284. package/lib/util/StringXor.js +1 -0
  285. package/lib/util/binarySearchBounds.js +15 -8
  286. package/lib/util/chainedImports.js +1 -1
  287. package/lib/util/cleverMerge.js +6 -1
  288. package/lib/util/comparators.js +21 -1
  289. package/lib/util/compileBooleanMatcher.js +3 -3
  290. package/lib/util/concatenate.js +3 -2
  291. package/lib/util/conventions.js +3 -2
  292. package/lib/util/deterministicGrouping.js +13 -1
  293. package/lib/util/extractSourceMap.js +12 -13
  294. package/lib/util/findGraphRoots.js +79 -109
  295. package/lib/util/fs.js +15 -19
  296. package/lib/util/hash/BatchedHash.js +4 -0
  297. package/lib/util/hash/BulkUpdateHash.js +8 -1
  298. package/lib/util/hash/hash-digest.js +1 -0
  299. package/lib/util/hash/wasm-hash.js +18 -2
  300. package/lib/util/identifier.js +7 -2
  301. package/lib/util/magicComment.js +1 -1
  302. package/lib/util/propertyName.js +1 -1
  303. package/lib/util/registerExternalSerializer.js +1 -0
  304. package/lib/util/runtime.js +15 -1
  305. package/lib/util/semver.js +1 -0
  306. package/lib/util/serialization.js +2 -2
  307. package/lib/wasm/EnableWasmLoadingPlugin.js +2 -0
  308. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +11 -3
  309. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -0
  310. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -2
  311. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -1
  312. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +3 -0
  313. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
  314. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +7 -3
  315. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -2
  316. package/lib/wasm-sync/WebAssemblyParser.js +3 -1
  317. package/lib/web/FetchCompileWasmPlugin.js +1 -0
  318. package/lib/web/JsonpChunkLoadingPlugin.js +1 -0
  319. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -0
  320. package/lib/webpack.js +16 -4
  321. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
  322. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -0
  323. package/package.json +40 -40
  324. package/schemas/WebpackOptions.check.js +1 -1
  325. package/schemas/WebpackOptions.json +121 -55
  326. package/schemas/plugins/BannerPlugin.json +2 -2
  327. package/schemas/plugins/IgnorePlugin.json +1 -1
  328. package/schemas/plugins/ManifestPlugin.json +3 -3
  329. package/schemas/plugins/ProgressPlugin.json +1 -1
  330. package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
  331. package/schemas/plugins/schemes/HttpUriPlugin.json +1 -1
  332. package/schemas/plugins/schemes/VirtualUrlPlugin.json +3 -3
  333. package/types.d.ts +677 -230
@@ -28,6 +28,8 @@ const ConcatenatedModule = require("./ConcatenatedModule");
28
28
  /** @typedef {import("../RequestShortener")} RequestShortener */
29
29
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
30
30
 
31
+ /** @typedef {Module | ((requestShortener: RequestShortener) => string)} Problem */
32
+
31
33
  /**
32
34
  * @typedef {object} Statistics
33
35
  * @property {number} cached
@@ -104,7 +106,7 @@ class ModuleConcatenationPlugin {
104
106
 
105
107
  /**
106
108
  * @param {Module} module the module
107
- * @param {Module | ((requestShortener: RequestShortener) => string)} problem the problem
109
+ * @param {Problem} problem the problem
108
110
  * @returns {(requestShortener: RequestShortener) => string} the reason
109
111
  */
110
112
  const formatBailoutWarning = (module, problem) => (requestShortener) => {
@@ -143,7 +145,9 @@ class ModuleConcatenationPlugin {
143
145
  "webpack.ModuleConcatenationPlugin"
144
146
  );
145
147
  const { chunkGraph, moduleGraph } = compilation;
148
+ /** @type {Module[]} */
146
149
  const relevantModules = [];
150
+ /** @type {Set<Module>} */
147
151
  const possibleInners = new Set();
148
152
  const context = {
149
153
  chunkGraph,
@@ -265,7 +269,9 @@ class ModuleConcatenationPlugin {
265
269
  let statsEmptyConfigurations = 0;
266
270
 
267
271
  logger.time("find modules to concatenate");
272
+ /** @type {ConcatConfiguration[]} */
268
273
  const concatConfigurations = [];
274
+ /** @type {Set<Module>} */
269
275
  const usedAsInner = new Set();
270
276
  for (const currentRoot of relevantModules) {
271
277
  // when used by another configuration as inner:
@@ -273,6 +279,7 @@ class ModuleConcatenationPlugin {
273
279
  // TODO reconsider that when it's only used in a different runtime
274
280
  if (usedAsInner.has(currentRoot)) continue;
275
281
 
282
+ /** @type {RuntimeSpec} */
276
283
  let chunkRuntime;
277
284
  for (const r of chunkGraph.getModuleRuntimes(currentRoot)) {
278
285
  chunkRuntime = mergeRuntimeOwned(chunkRuntime, r);
@@ -295,6 +302,7 @@ class ModuleConcatenationPlugin {
295
302
  );
296
303
 
297
304
  // cache failures to add modules
305
+ /** @type {Map<Module, Problem>} */
298
306
  const failureCache = new Map();
299
307
 
300
308
  // potential optional import candidates
@@ -311,6 +319,7 @@ class ModuleConcatenationPlugin {
311
319
  }
312
320
 
313
321
  for (const imp of candidates) {
322
+ /** @type {Set<Module>} */
314
323
  const impCandidates = new Set();
315
324
  const problem = this._tryToAdd(
316
325
  compilation,
@@ -373,6 +382,7 @@ class ModuleConcatenationPlugin {
373
382
  logger.time("sort concat configurations");
374
383
  concatConfigurations.sort((a, b) => b.modules.size - a.modules.size);
375
384
  logger.timeEnd("sort concat configurations");
385
+ /** @type {Set<Module>} */
376
386
  const usedModules = new Set();
377
387
 
378
388
  logger.time("create concatenated modules");
@@ -456,7 +466,10 @@ class ModuleConcatenationPlugin {
456
466
  chunk,
457
467
  m
458
468
  );
459
- if (sourceTypes.size === 1) {
469
+ if (
470
+ sourceTypes.size === 1 &&
471
+ sourceTypes.has(JAVASCRIPT_TYPE)
472
+ ) {
460
473
  chunkGraph.disconnectChunkAndModule(chunk, m);
461
474
  } else {
462
475
  const newSourceTypes = new Set(sourceTypes);
@@ -515,6 +528,7 @@ class ModuleConcatenationPlugin {
515
528
  */
516
529
  _getImports(compilation, module, runtime) {
517
530
  const moduleGraph = compilation.moduleGraph;
531
+ /** @type {Set<Module>} */
518
532
  const set = new Set();
519
533
  for (const dep of module.dependencies) {
520
534
  // Get reference info only for harmony Dependencies
@@ -555,11 +569,11 @@ class ModuleConcatenationPlugin {
555
569
  * @param {RuntimeSpec} activeRuntime the runtime scope of the root module
556
570
  * @param {Set<Module>} possibleModules modules that are candidates
557
571
  * @param {Set<Module>} candidates list of potential candidates (will be added to)
558
- * @param {Map<Module, Module | ((requestShortener: RequestShortener) => string)>} failureCache cache for problematic modules to be more performant
572
+ * @param {Map<Module, Problem>} failureCache cache for problematic modules to be more performant
559
573
  * @param {ChunkGraph} chunkGraph the chunk graph
560
574
  * @param {boolean} avoidMutateOnFailure avoid mutating the config when adding fails
561
575
  * @param {Statistics} statistics gathering metrics
562
- * @returns {null | Module | ((requestShortener: RequestShortener) => string)} the problematic module
576
+ * @returns {null | Problem} the problematic module
563
577
  */
564
578
  _tryToAdd(
565
579
  compilation,
@@ -646,6 +660,7 @@ class ModuleConcatenationPlugin {
646
660
  * @returns {string} problem description
647
661
  */
648
662
  const problem = (requestShortener) => {
663
+ /** @type {Set<string>} */
649
664
  const importingExplanations = new Set(
650
665
  activeNonModulesConnections
651
666
  .map((c) => c.explanation)
@@ -674,6 +689,7 @@ class ModuleConcatenationPlugin {
674
689
  if (chunkGraph.getNumberOfModuleChunks(originModule) === 0) continue;
675
690
 
676
691
  // We don't care for connections from other runtimes
692
+ /** @type {RuntimeSpec} */
677
693
  let originRuntime;
678
694
  for (const r of chunkGraph.getModuleRuntimes(originModule)) {
679
695
  originRuntime = mergeRuntimeOwned(originRuntime, r);
@@ -822,6 +838,7 @@ class ModuleConcatenationPlugin {
822
838
  }
823
839
  }
824
840
 
841
+ /** @type {undefined | number} */
825
842
  let backup;
826
843
  if (avoidMutateOnFailure) {
827
844
  backup = config.snapshot();
@@ -864,7 +881,6 @@ class ModuleConcatenationPlugin {
864
881
  }
865
882
  }
866
883
 
867
- /** @typedef {Module | ((requestShortener: RequestShortener) => string)} Problem */
868
884
  /** @typedef {Map<Module, Problem>} Warnings */
869
885
 
870
886
  class ConcatConfiguration {
@@ -873,7 +889,9 @@ class ConcatConfiguration {
873
889
  * @param {RuntimeSpec} runtime the runtime
874
890
  */
875
891
  constructor(rootModule, runtime) {
892
+ /** @type {Module} */
876
893
  this.rootModule = rootModule;
894
+ /** @type {RuntimeSpec} */
877
895
  this.runtime = runtime;
878
896
  /** @type {Set<Module>} */
879
897
  this.modules = new Set();
@@ -20,6 +20,12 @@ const createHash = require("../util/createHash");
20
20
  /** @typedef {import("../Compiler")} Compiler */
21
21
  /** @typedef {typeof import("../util/Hash")} Hash */
22
22
 
23
+ /**
24
+ * @template T
25
+ * @typedef {import("../util/comparators").Comparator<T>} Comparator
26
+ */
27
+
28
+ /** @type {Hashes} */
23
29
  const EMPTY_SET = new Set();
24
30
 
25
31
  /**
@@ -47,6 +53,7 @@ const mapAndDeduplicateBuffers = (input, fn) => {
47
53
  // Buffer.equals compares size first so this should be efficient enough
48
54
  // If it becomes a performance problem we can use a map and group by size
49
55
  // instead of looping over all assets.
56
+ /** @type {Buffer[]} */
50
57
  const result = [];
51
58
  outer: for (const value of input) {
52
59
  const buf = fn(value);
@@ -65,6 +72,7 @@ const mapAndDeduplicateBuffers = (input, fn) => {
65
72
  */
66
73
  const quoteMeta = (str) => str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
67
74
 
75
+ /** @type {WeakMap<Source, CachedSource>} */
68
76
  const cachedSourceMap = new WeakMap();
69
77
 
70
78
  /**
@@ -82,8 +90,6 @@ const toCachedSource = (source) => {
82
90
  return newSource;
83
91
  };
84
92
 
85
- /** @typedef {Set<string>} OwnHashes */
86
- /** @typedef {Set<string>} ReferencedHashes */
87
93
  /** @typedef {Set<string>} Hashes */
88
94
 
89
95
  /**
@@ -94,10 +100,10 @@ const toCachedSource = (source) => {
94
100
  * @property {RawSource | undefined} newSource
95
101
  * @property {RawSource | undefined} newSourceWithoutOwn
96
102
  * @property {string} content
97
- * @property {OwnHashes | undefined} ownHashes
103
+ * @property {Hashes | undefined} ownHashes
98
104
  * @property {Promise<void> | undefined} contentComputePromise
99
105
  * @property {Promise<void> | undefined} contentComputeWithoutOwnPromise
100
- * @property {ReferencedHashes | undefined} referencedHashes
106
+ * @property {Hashes | undefined} referencedHashes
101
107
  * @property {Hashes} hashes
102
108
  */
103
109
 
@@ -142,7 +148,9 @@ class RealContentHashPlugin {
142
148
  * @param {RealContentHashPluginOptions} options options
143
149
  */
144
150
  constructor({ hashFunction, hashDigest }) {
151
+ /** @type {HashFunction} */
145
152
  this._hashFunction = hashFunction;
153
+ /** @type {HashDigest} */
146
154
  this._hashDigest = hashDigest;
147
155
  }
148
156
 
@@ -220,7 +228,9 @@ class RealContentHashPlugin {
220
228
  );
221
229
  [asset.referencedHashes, asset.ownHashes] =
222
230
  await cacheAnalyse.providePromise(name, etag, () => {
231
+ /** @type {Hashes} */
223
232
  const referencedHashes = new Set();
233
+ /** @type {Hashes} */
224
234
  const ownHashes = new Set();
225
235
  const inContent = content.match(hashRegExp);
226
236
  if (inContent) {
@@ -238,15 +248,13 @@ class RealContentHashPlugin {
238
248
  );
239
249
  /**
240
250
  * @param {string} hash the hash
241
- * @returns {undefined | ReferencedHashes} the referenced hashes
251
+ * @returns {undefined | Hashes} the referenced hashes
242
252
  */
243
253
  const getDependencies = (hash) => {
244
254
  const assets = hashToAssets.get(hash);
245
255
  if (!assets) {
246
256
  const referencingAssets = assetsWithInfo.filter((asset) =>
247
- /** @type {ReferencedHashes} */ (asset.referencedHashes).has(
248
- hash
249
- )
257
+ /** @type {Hashes} */ (asset.referencedHashes).has(hash)
250
258
  );
251
259
  const err = new WebpackError(`RealContentHashPlugin
252
260
  Some kind of unexpected caching problem occurred.
@@ -264,16 +272,15 @@ ${referencingAssets
264
272
  compilation.errors.push(err);
265
273
  return;
266
274
  }
275
+ /** @type {Hashes} */
267
276
  const hashes = new Set();
268
277
  for (const { referencedHashes, ownHashes } of assets) {
269
- if (!(/** @type {OwnHashes} */ (ownHashes).has(hash))) {
270
- for (const hash of /** @type {OwnHashes} */ (ownHashes)) {
278
+ if (!(/** @type {Hashes} */ (ownHashes).has(hash))) {
279
+ for (const hash of /** @type {Hashes} */ (ownHashes)) {
271
280
  hashes.add(hash);
272
281
  }
273
282
  }
274
- for (const hash of /** @type {ReferencedHashes} */ (
275
- referencedHashes
276
- )) {
283
+ for (const hash of /** @type {Hashes} */ (referencedHashes)) {
277
284
  hashes.add(hash);
278
285
  }
279
286
  }
@@ -290,7 +297,7 @@ ${referencingAssets
290
297
  (a) => a.name
291
298
  )})`;
292
299
  };
293
- /** @type {Set<string>} */
300
+ /** @type {Hashes} */
294
301
  const hashesInOrder = new Set();
295
302
  for (const hash of hashToAssets.keys()) {
296
303
  /**
@@ -329,7 +336,7 @@ ${referencingAssets
329
336
  cacheGenerate.mergeEtags(
330
337
  cacheGenerate.getLazyHashedEtag(asset.source),
331
338
  Array.from(
332
- /** @type {ReferencedHashes} */ (asset.referencedHashes),
339
+ /** @type {Hashes} */ (asset.referencedHashes),
333
340
  (hash) => hashToNewHash.get(hash)
334
341
  ).join("|")
335
342
  );
@@ -341,10 +348,10 @@ ${referencingAssets
341
348
  if (asset.contentComputePromise) return asset.contentComputePromise;
342
349
  return (asset.contentComputePromise = (async () => {
343
350
  if (
344
- /** @type {OwnHashes} */ (asset.ownHashes).size > 0 ||
345
- [
346
- .../** @type {ReferencedHashes} */ (asset.referencedHashes)
347
- ].some((hash) => hashToNewHash.get(hash) !== hash)
351
+ /** @type {Hashes} */ (asset.ownHashes).size > 0 ||
352
+ [.../** @type {Hashes} */ (asset.referencedHashes)].some(
353
+ (hash) => hashToNewHash.get(hash) !== hash
354
+ )
348
355
  ) {
349
356
  const identifier = asset.name;
350
357
  const etag = getEtag(asset);
@@ -372,10 +379,10 @@ ${referencingAssets
372
379
  }
373
380
  return (asset.contentComputeWithoutOwnPromise = (async () => {
374
381
  if (
375
- /** @type {OwnHashes} */ (asset.ownHashes).size > 0 ||
376
- [
377
- .../** @type {ReferencedHashes} */ (asset.referencedHashes)
378
- ].some((hash) => hashToNewHash.get(hash) !== hash)
382
+ /** @type {Hashes} */ (asset.ownHashes).size > 0 ||
383
+ [.../** @type {Hashes} */ (asset.referencedHashes)].some(
384
+ (hash) => hashToNewHash.get(hash) !== hash
385
+ )
379
386
  ) {
380
387
  const identifier = `${asset.name}|without-own`;
381
388
  const etag = getEtag(asset);
@@ -387,7 +394,7 @@ ${referencingAssets
387
394
  hashRegExp,
388
395
  (hash) => {
389
396
  if (
390
- /** @type {OwnHashes} */
397
+ /** @type {Hashes} */
391
398
  (asset.ownHashes).has(hash)
392
399
  ) {
393
400
  return "";
@@ -401,6 +408,7 @@ ${referencingAssets
401
408
  }
402
409
  })());
403
410
  };
411
+ /** @type {Comparator<AssetInfoForRealContentHash>} */
404
412
  const comparator = compareSelect((a) => a.name, compareStrings);
405
413
  for (const oldHash of hashesInOrder) {
406
414
  const assets =
@@ -409,13 +417,13 @@ ${referencingAssets
409
417
  assets.sort(comparator);
410
418
  await Promise.all(
411
419
  assets.map((asset) =>
412
- /** @type {OwnHashes} */ (asset.ownHashes).has(oldHash)
420
+ /** @type {Hashes} */ (asset.ownHashes).has(oldHash)
413
421
  ? computeNewContentWithoutOwn(asset)
414
422
  : computeNewContent(asset)
415
423
  )
416
424
  );
417
425
  const assetsContent = mapAndDeduplicateBuffers(assets, (asset) => {
418
- if (/** @type {OwnHashes} */ (asset.ownHashes).has(oldHash)) {
426
+ if (/** @type {Hashes} */ (asset.ownHashes).has(oldHash)) {
419
427
  return asset.newSourceWithoutOwn
420
428
  ? asset.newSourceWithoutOwn.buffer()
421
429
  : asset.source.buffer();
@@ -447,7 +455,9 @@ ${referencingAssets
447
455
  );
448
456
 
449
457
  const infoUpdate = {};
450
- const hash = /** @type {string} */ (asset.info.contenthash);
458
+ const hash =
459
+ /** @type {Exclude<AssetInfo["contenthash"], undefined>} */
460
+ (asset.info.contenthash);
451
461
  infoUpdate.contenthash = Array.isArray(hash)
452
462
  ? hash.map(
453
463
  (hash) => /** @type {string} */ (hashToNewHash.get(hash))
@@ -33,7 +33,7 @@ const THIRTY_TWO_BIGINT = BigInt(32);
33
33
  * Parses the module mask and returns the modules represented by it
34
34
  * @param {bigint} mask the module mask
35
35
  * @param {Module[]} ordinalModules the modules in the order they were added to the mask (LSB is index 0)
36
- * @returns {Generator<Module>} the modules represented by the mask
36
+ * @returns {Generator<Module, undefined, undefined>} the modules represented by the mask
37
37
  */
38
38
  function* getModulesFromMask(mask, ordinalModules) {
39
39
  let offset = 31;
@@ -74,10 +74,13 @@ class RemoveParentModulesPlugin {
74
74
  */
75
75
  const handler = (chunks, chunkGroups) => {
76
76
  const chunkGraph = compilation.chunkGraph;
77
+ /** @type {Set<ChunkGroup>} */
77
78
  const queue = new Set();
79
+ /** @type {WeakMap<ChunkGroup, bigint | undefined>} */
78
80
  const availableModulesMap = new WeakMap();
79
81
 
80
82
  let nextModuleMask = ONE_BIGINT;
83
+ /** @type {WeakMap<Module, bigint>} */
81
84
  const maskByModule = new WeakMap();
82
85
  /** @type {Module[]} */
83
86
  const ordinalModules = [];
@@ -99,6 +102,7 @@ class RemoveParentModulesPlugin {
99
102
  };
100
103
 
101
104
  // Initialize masks by chunk and by chunk group for quicker comparisons
105
+ /** @type {WeakMap<Chunk, bigint>} */
102
106
  const chunkMasks = new WeakMap();
103
107
  for (const chunk of chunks) {
104
108
  let mask = ZERO_BIGINT;
@@ -109,6 +113,7 @@ class RemoveParentModulesPlugin {
109
113
  chunkMasks.set(chunk, mask);
110
114
  }
111
115
 
116
+ /** @type {WeakMap<ChunkGroup, bigint>} */
112
117
  const chunkGroupMasks = new WeakMap();
113
118
  for (const chunkGroup of chunkGroups) {
114
119
  let mask = ZERO_BIGINT;
@@ -143,7 +148,8 @@ class RemoveParentModulesPlugin {
143
148
  const availableModulesInParent = availableModulesMap.get(parent);
144
149
  if (availableModulesInParent !== undefined) {
145
150
  const parentMask =
146
- availableModulesInParent | chunkGroupMasks.get(parent);
151
+ availableModulesInParent |
152
+ /** @type {bigint} */ (chunkGroupMasks.get(parent));
147
153
  // If we know the available modules in parent: process these
148
154
  if (availableModulesMask === undefined) {
149
155
  // if we have not own info yet: create new entry
@@ -181,7 +187,10 @@ class RemoveParentModulesPlugin {
181
187
  );
182
188
  if (availableModulesSets.includes(undefined)) continue; // No info about this chunk group
183
189
 
184
- const availableModulesMask = intersectMasks(availableModulesSets);
190
+ const availableModulesMask = intersectMasks(
191
+ /** @type {bigint[]} */
192
+ (availableModulesSets)
193
+ );
185
194
  const toRemoveMask = chunkMask & availableModulesMask;
186
195
  if (toRemoveMask !== ZERO_BIGINT) {
187
196
  for (const module of getModulesFromMask(
@@ -16,9 +16,9 @@ class RuntimeChunkPlugin {
16
16
  /**
17
17
  * @param {{ name?: RuntimeChunkFunction }=} options options
18
18
  */
19
- constructor(options) {
19
+ constructor(options = {}) {
20
+ /** @type {{ name: string | RuntimeChunkFunction }} */
20
21
  this.options = {
21
- /** @type {RuntimeChunkFunction} */
22
22
  name: (entrypoint) => `runtime~${entrypoint.name}`,
23
23
  ...options
24
24
  };
@@ -38,9 +38,7 @@ class RuntimeChunkPlugin {
38
38
  (compilation.entries.get(entryName));
39
39
  if (data.options.runtime === undefined && !data.options.dependOn) {
40
40
  // Determine runtime chunk name
41
- let name =
42
- /** @type {string | RuntimeChunkFunction} */
43
- (this.options.name);
41
+ let name = this.options.name;
44
42
  if (typeof name === "function") {
45
43
  name = name({ name: entryName });
46
44
  }
@@ -68,6 +68,7 @@ class SideEffectsFlagPlugin {
68
68
  * @param {boolean} analyseSource analyse source code for side effects
69
69
  */
70
70
  constructor(analyseSource = true) {
71
+ /** @type {boolean} */
71
72
  this._analyseSource = analyseSource;
72
73
  }
73
74
 
@@ -277,6 +278,7 @@ class SideEffectsFlagPlugin {
277
278
 
278
279
  logger.time("update dependencies");
279
280
 
281
+ /** @type {Set<Module>} */
280
282
  const optimizedModules = new Set();
281
283
 
282
284
  /**
@@ -291,6 +293,7 @@ class SideEffectsFlagPlugin {
291
293
  module
292
294
  )) {
293
295
  const dep = connection.dependency;
296
+ /** @type {boolean} */
294
297
  let isReexport;
295
298
  if (
296
299
  (isReexport =
@@ -22,7 +22,6 @@ const memoize = require("../util/memoize");
22
22
  const MinMaxSizeWarning = require("./MinMaxSizeWarning");
23
23
 
24
24
  /** @typedef {import("../../declarations/WebpackOptions").OptimizationSplitChunksCacheGroup} OptimizationSplitChunksCacheGroup */
25
- /** @typedef {import("../../declarations/WebpackOptions").OptimizationSplitChunksGetCacheGroups} OptimizationSplitChunksGetCacheGroups */
26
25
  /** @typedef {import("../../declarations/WebpackOptions").OptimizationSplitChunksOptions} OptimizationSplitChunksOptions */
27
26
  /** @typedef {import("../../declarations/WebpackOptions").OptimizationSplitChunksSizes} OptimizationSplitChunksSizes */
28
27
  /** @typedef {import("../config/defaults").OutputNormalizedWithDefaults} OutputOptions */
@@ -36,6 +35,7 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
36
35
  /** @typedef {import("../TemplatedPathPlugin").TemplatePath} TemplatePath */
37
36
  /** @typedef {import("../util/deterministicGrouping").GroupedItems<Module>} DeterministicGroupingGroupedItemsForModule */
38
37
  /** @typedef {import("../util/deterministicGrouping").Options<Module>} DeterministicGroupingOptionsForModule */
38
+ /** @typedef {import("../util/deterministicGrouping").Sizes} Sizes */
39
39
 
40
40
  /**
41
41
  * @callback ChunkFilterFn
@@ -123,6 +123,8 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
123
123
  * @property {ChunkGraph} chunkGraph
124
124
  */
125
125
 
126
+ /** @typedef {(module: Module) => OptimizationSplitChunksCacheGroup | OptimizationSplitChunksCacheGroup[] | void} RawGetCacheGroups */
127
+
126
128
  /**
127
129
  * @callback GetCacheGroups
128
130
  * @param {Module} module
@@ -220,9 +222,10 @@ const getRequests = (chunk) => {
220
222
  * @returns {T} result
221
223
  */
222
224
  const mapObject = (obj, fn) => {
225
+ /** @type {T} */
223
226
  const newObj = Object.create(null);
224
227
  for (const key of Object.keys(obj)) {
225
- newObj[key] = fn(
228
+ newObj[/** @type {keyof T} */ (key)] = fn(
226
229
  obj[/** @type {keyof T} */ (key)],
227
230
  /** @type {keyof T} */
228
231
  (key)
@@ -454,7 +457,7 @@ const normalizeChunksFilter = (chunks) => {
454
457
  };
455
458
 
456
459
  /**
457
- * @param {undefined | GetCacheGroups | Record<string, false | string | RegExp | OptimizationSplitChunksGetCacheGroups | OptimizationSplitChunksCacheGroup>} cacheGroups the cache group options
460
+ * @param {undefined | GetCacheGroups | Record<string, false | string | RegExp | RawGetCacheGroups | OptimizationSplitChunksCacheGroup>} cacheGroups the cache group options
458
461
  * @param {DefaultSizeTypes} defaultSizeTypes the default size types
459
462
  * @returns {GetCacheGroups} a function to get the cache groups
460
463
  */
@@ -478,6 +481,7 @@ const normalizeCacheGroups = (cacheGroups, defaultSizeTypes) => {
478
481
  }
479
482
  });
480
483
  } else if (typeof option === "function") {
484
+ /** @type {WeakMap<OptimizationSplitChunksCacheGroup, CacheGroupSource>} */
481
485
  const cache = new WeakMap();
482
486
  handlers.push((module, context, results) => {
483
487
  const result = option(module);
@@ -530,6 +534,8 @@ const normalizeCacheGroups = (cacheGroups, defaultSizeTypes) => {
530
534
  return () => null;
531
535
  };
532
536
 
537
+ /** @typedef {(module: Module, context: CacheGroupsContext) => boolean} CheckTestFn */
538
+
533
539
  /**
534
540
  * @param {OptimizationSplitChunksCacheGroup["test"]} test test option
535
541
  * @param {Module} module the module
@@ -553,6 +559,8 @@ const checkTest = (test, module, context) => {
553
559
  return false;
554
560
  };
555
561
 
562
+ /** @typedef {(type: string) => boolean} CheckModuleTypeFn */
563
+
556
564
  /**
557
565
  * @param {OptimizationSplitChunksCacheGroup["type"]} test type option
558
566
  * @param {Module} module the module
@@ -574,6 +582,8 @@ const checkModuleType = (test, module) => {
574
582
  return false;
575
583
  };
576
584
 
585
+ /** @typedef {(layer: string | null) => boolean} CheckModuleLayerFn */
586
+
577
587
  /**
578
588
  * @param {OptimizationSplitChunksCacheGroup["layer"]} test type option
579
589
  * @param {Module} module the module
@@ -868,7 +878,7 @@ module.exports = class SplitChunksPlugin {
868
878
  index <<= ONE;
869
879
  }
870
880
  /**
871
- * @param {Iterable<Chunk>} chunks list of chunks
881
+ * @param {Iterable<Chunk, undefined, undefined>} chunks list of chunks
872
882
  * @returns {bigint | Chunk} key of the chunks
873
883
  */
874
884
  const getKey = (chunks) => {
@@ -921,6 +931,7 @@ module.exports = class SplitChunksPlugin {
921
931
  */
922
932
  const groupChunksByExports = (module) => {
923
933
  const exportsInfo = moduleGraph.getExportsInfo(module);
934
+ /** @type {Map<string, Chunk[]>} */
924
935
  const groupedByUsedExports = new Map();
925
936
  for (const chunk of chunkGraph.getModuleChunksIterable(module)) {
926
937
  const key = exportsInfo.getUsageKey(chunk.runtime);
@@ -1082,7 +1093,8 @@ module.exports = class SplitChunksPlugin {
1082
1093
  * @property {bigint | Chunk} key a key of the list
1083
1094
  */
1084
1095
 
1085
- /** @type {WeakMap<ChunkSet | Chunk, WeakMap<ChunkFilterFn, SelectedChunksResult>>} */
1096
+ /** @typedef {WeakMap<ChunkFilterFn, SelectedChunksResult>} ChunkMap */
1097
+ /** @type {WeakMap<ChunkSet | Chunk, ChunkMap>} */
1086
1098
  const selectedChunksCacheByChunksSet = new WeakMap();
1087
1099
 
1088
1100
  /**
@@ -1095,6 +1107,7 @@ module.exports = class SplitChunksPlugin {
1095
1107
  const getSelectedChunks = (chunks, chunkFilter) => {
1096
1108
  let entry = selectedChunksCacheByChunksSet.get(chunks);
1097
1109
  if (entry === undefined) {
1110
+ /** @type {ChunkMap} */
1098
1111
  entry = new WeakMap();
1099
1112
  selectedChunksCacheByChunksSet.set(chunks, entry);
1100
1113
  }
@@ -1392,7 +1405,9 @@ module.exports = class SplitChunksPlugin {
1392
1405
 
1393
1406
  while (chunksInfoMap.size > 0) {
1394
1407
  // Find best matching entry
1408
+ /** @type {undefined | string} */
1395
1409
  let bestEntryKey;
1410
+ /** @type {undefined | ChunksInfoItem} */
1396
1411
  let bestEntry;
1397
1412
  for (const pair of chunksInfoMap) {
1398
1413
  const key = pair[0];
@@ -1471,6 +1486,7 @@ module.exports = class SplitChunksPlugin {
1471
1486
  item.cacheGroup._conditionalEnforce &&
1472
1487
  checkMinSize(item.sizes, item.cacheGroup.enforceSizeThreshold);
1473
1488
 
1489
+ /** @type {Set<Chunk>} */
1474
1490
  const usedChunks = new Set(item.chunks);
1475
1491
 
1476
1492
  // Check if maxRequests condition can be fulfilled
@@ -1533,6 +1549,7 @@ module.exports = class SplitChunksPlugin {
1533
1549
  usedChunks.size === 1
1534
1550
  ) {
1535
1551
  const [chunk] = usedChunks;
1552
+ /** @type {SplitChunksSizes} */
1536
1553
  const chunkSizes = Object.create(null);
1537
1554
  for (const module of chunkGraph.getChunkModulesIterable(chunk)) {
1538
1555
  if (!item.modules.has(module)) {
@@ -1763,6 +1780,7 @@ module.exports = class SplitChunksPlugin {
1763
1780
  return key;
1764
1781
  },
1765
1782
  getSize(module) {
1783
+ /** @type {Sizes} */
1766
1784
  const size = Object.create(null);
1767
1785
  for (const key of module.getSourceTypes()) {
1768
1786
  size[key] = module.size(key);
@@ -10,7 +10,7 @@ const WebpackError = require("../WebpackError");
10
10
 
11
11
  /** @typedef {import("./SizeLimitsPlugin").AssetDetails} AssetDetails */
12
12
 
13
- module.exports = class AssetsOverSizeLimitWarning extends WebpackError {
13
+ class AssetsOverSizeLimitWarning extends WebpackError {
14
14
  /**
15
15
  * @param {AssetDetails[]} assetsOverSizeLimit the assets
16
16
  * @param {number} assetLimit the size limit
@@ -26,7 +26,12 @@ module.exports = class AssetsOverSizeLimitWarning extends WebpackError {
26
26
  This can impact web performance.
27
27
  Assets: ${assetLists}`);
28
28
 
29
+ /** @type {string} */
29
30
  this.name = "AssetsOverSizeLimitWarning";
31
+ /** @type {AssetDetails[]} */
30
32
  this.assets = assetsOverSizeLimit;
31
33
  }
32
- };
34
+ }
35
+
36
+ /** @type {typeof AssetsOverSizeLimitWarning} */
37
+ module.exports = AssetsOverSizeLimitWarning;
@@ -10,7 +10,7 @@ const WebpackError = require("../WebpackError");
10
10
 
11
11
  /** @typedef {import("./SizeLimitsPlugin").EntrypointDetails} EntrypointDetails */
12
12
 
13
- module.exports = class EntrypointsOverSizeLimitWarning extends WebpackError {
13
+ class EntrypointsOverSizeLimitWarning extends WebpackError {
14
14
  /**
15
15
  * @param {EntrypointDetails[]} entrypoints the entrypoints
16
16
  * @param {number} entrypointLimit the size limit
@@ -29,7 +29,12 @@ module.exports = class EntrypointsOverSizeLimitWarning extends WebpackError {
29
29
  )}). This can impact web performance.
30
30
  Entrypoints:${entrypointList}\n`);
31
31
 
32
+ /** @type {string} */
32
33
  this.name = "EntrypointsOverSizeLimitWarning";
34
+ /** @type {EntrypointDetails[]} */
33
35
  this.entrypoints = entrypoints;
34
36
  }
35
- };
37
+ }
38
+
39
+ /** @type {typeof EntrypointsOverSizeLimitWarning} */
40
+ module.exports = EntrypointsOverSizeLimitWarning;
@@ -15,6 +15,7 @@ module.exports = class NoAsyncChunksWarning extends WebpackError {
15
15
  "For more info visit https://webpack.js.org/guides/code-splitting/"
16
16
  );
17
17
 
18
+ /** @type {string} */
18
19
  this.name = "NoAsyncChunksWarning";
19
20
  }
20
21
  };
@@ -34,12 +34,9 @@ const NoAsyncChunksWarning = require("./NoAsyncChunksWarning");
34
34
  /** @type {WeakSet<Entrypoint | ChunkGroup | Source>} */
35
35
  const isOverSizeLimitSet = new WeakSet();
36
36
 
37
- /**
38
- * @param {Asset["name"]} name the name
39
- * @param {Asset["source"]} source the source
40
- * @param {Asset["info"]} info the info
41
- * @returns {boolean} result
42
- */
37
+ /** @typedef {(name: Asset["name"], source: Asset["source"], assetInfo: Asset["info"]) => boolean} AssetFilter */
38
+
39
+ /** @type {AssetFilter} */
43
40
  const excludeSourceMap = (name, source, info) => !info.development;
44
41
 
45
42
  const PLUGIN_NAME = "SizeLimitsPlugin";
@@ -49,9 +46,13 @@ module.exports = class SizeLimitsPlugin {
49
46
  * @param {PerformanceOptions} options the plugin options
50
47
  */
51
48
  constructor(options) {
49
+ /** @type {PerformanceOptions["hints"]} */
52
50
  this.hints = options.hints;
51
+ /** @type {number | undefined} */
53
52
  this.maxAssetSize = options.maxAssetSize;
53
+ /** @type {number | undefined} */
54
54
  this.maxEntrypointSize = options.maxEntrypointSize;
55
+ /** @type {AssetFilter | undefined} */
55
56
  this.assetFilter = options.assetFilter;
56
57
  }
57
58