@depup/webpack 5.105.4-depup.37

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 (709) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +38 -0
  3. package/bin/webpack.js +196 -0
  4. package/hot/dev-server.js +90 -0
  5. package/hot/emitter-event-target.js +7 -0
  6. package/hot/emitter.js +2 -0
  7. package/hot/lazy-compilation-node.js +66 -0
  8. package/hot/lazy-compilation-universal.js +18 -0
  9. package/hot/lazy-compilation-web.js +93 -0
  10. package/hot/load-http.js +7 -0
  11. package/hot/log-apply-result.js +49 -0
  12. package/hot/log.js +78 -0
  13. package/hot/only-dev-server.js +118 -0
  14. package/hot/poll.js +41 -0
  15. package/hot/signal.js +66 -0
  16. package/lib/APIPlugin.js +392 -0
  17. package/lib/AbstractMethodError.js +56 -0
  18. package/lib/AsyncDependenciesBlock.js +128 -0
  19. package/lib/AsyncDependencyToInitialChunkError.js +34 -0
  20. package/lib/AutomaticPrefetchPlugin.js +66 -0
  21. package/lib/BannerPlugin.js +138 -0
  22. package/lib/Cache.js +168 -0
  23. package/lib/CacheFacade.js +349 -0
  24. package/lib/CaseSensitiveModulesWarning.js +72 -0
  25. package/lib/Chunk.js +899 -0
  26. package/lib/ChunkGraph.js +1968 -0
  27. package/lib/ChunkGroup.js +615 -0
  28. package/lib/ChunkRenderError.js +38 -0
  29. package/lib/ChunkTemplate.js +181 -0
  30. package/lib/CleanPlugin.js +495 -0
  31. package/lib/CodeGenerationError.js +35 -0
  32. package/lib/CodeGenerationResults.js +167 -0
  33. package/lib/CommentCompilationWarning.js +33 -0
  34. package/lib/CompatibilityPlugin.js +240 -0
  35. package/lib/Compilation.js +5876 -0
  36. package/lib/Compiler.js +1413 -0
  37. package/lib/ConcatenationScope.js +181 -0
  38. package/lib/ConcurrentCompilationError.js +18 -0
  39. package/lib/ConditionalInitFragment.js +120 -0
  40. package/lib/ConstPlugin.js +567 -0
  41. package/lib/ContextExclusionPlugin.js +33 -0
  42. package/lib/ContextModule.js +1411 -0
  43. package/lib/ContextModuleFactory.js +514 -0
  44. package/lib/ContextReplacementPlugin.js +227 -0
  45. package/lib/CssModule.js +179 -0
  46. package/lib/DefinePlugin.js +878 -0
  47. package/lib/DelegatedModule.js +279 -0
  48. package/lib/DelegatedModuleFactoryPlugin.js +116 -0
  49. package/lib/DelegatedPlugin.js +49 -0
  50. package/lib/DependenciesBlock.js +120 -0
  51. package/lib/Dependency.js +390 -0
  52. package/lib/DependencyTemplate.js +71 -0
  53. package/lib/DependencyTemplates.js +67 -0
  54. package/lib/DllEntryPlugin.js +76 -0
  55. package/lib/DllModule.js +175 -0
  56. package/lib/DllModuleFactory.js +38 -0
  57. package/lib/DllPlugin.js +73 -0
  58. package/lib/DllReferencePlugin.js +189 -0
  59. package/lib/DotenvPlugin.js +468 -0
  60. package/lib/DynamicEntryPlugin.js +93 -0
  61. package/lib/EntryOptionPlugin.js +98 -0
  62. package/lib/EntryPlugin.js +72 -0
  63. package/lib/Entrypoint.js +120 -0
  64. package/lib/EnvironmentNotSupportAsyncWarning.js +51 -0
  65. package/lib/EnvironmentPlugin.js +74 -0
  66. package/lib/ErrorHelpers.js +100 -0
  67. package/lib/EvalDevToolModulePlugin.js +135 -0
  68. package/lib/EvalSourceMapDevToolPlugin.js +252 -0
  69. package/lib/ExportsInfo.js +1663 -0
  70. package/lib/ExportsInfoApiPlugin.js +87 -0
  71. package/lib/ExternalModule.js +1169 -0
  72. package/lib/ExternalModuleFactoryPlugin.js +370 -0
  73. package/lib/ExternalsPlugin.js +93 -0
  74. package/lib/FalseIIFEUmdWarning.js +20 -0
  75. package/lib/FileSystemInfo.js +4131 -0
  76. package/lib/FlagAllModulesAsUsedPlugin.js +55 -0
  77. package/lib/FlagDependencyExportsPlugin.js +437 -0
  78. package/lib/FlagDependencyUsagePlugin.js +348 -0
  79. package/lib/FlagEntryExportAsUsedPlugin.js +56 -0
  80. package/lib/Generator.js +188 -0
  81. package/lib/GraphHelpers.js +46 -0
  82. package/lib/HarmonyLinkingError.js +17 -0
  83. package/lib/HookWebpackError.js +121 -0
  84. package/lib/HotModuleReplacementPlugin.js +930 -0
  85. package/lib/HotUpdateChunk.js +16 -0
  86. package/lib/IgnoreErrorModuleFactory.js +39 -0
  87. package/lib/IgnorePlugin.js +105 -0
  88. package/lib/IgnoreWarningsPlugin.js +41 -0
  89. package/lib/InitFragment.js +204 -0
  90. package/lib/InvalidDependenciesModuleWarning.js +44 -0
  91. package/lib/JavascriptMetaInfoPlugin.js +78 -0
  92. package/lib/LibManifestPlugin.js +144 -0
  93. package/lib/LibraryTemplatePlugin.js +48 -0
  94. package/lib/LoaderOptionsPlugin.js +81 -0
  95. package/lib/LoaderTargetPlugin.js +39 -0
  96. package/lib/MainTemplate.js +371 -0
  97. package/lib/ManifestPlugin.js +242 -0
  98. package/lib/Module.js +1319 -0
  99. package/lib/ModuleBuildError.js +83 -0
  100. package/lib/ModuleDependencyError.js +44 -0
  101. package/lib/ModuleDependencyWarning.js +49 -0
  102. package/lib/ModuleError.js +69 -0
  103. package/lib/ModuleFactory.js +57 -0
  104. package/lib/ModuleFilenameHelpers.js +388 -0
  105. package/lib/ModuleGraph.js +1024 -0
  106. package/lib/ModuleGraphConnection.js +199 -0
  107. package/lib/ModuleHashingError.js +31 -0
  108. package/lib/ModuleInfoHeaderPlugin.js +318 -0
  109. package/lib/ModuleNotFoundError.js +90 -0
  110. package/lib/ModuleParseError.js +125 -0
  111. package/lib/ModuleProfile.js +108 -0
  112. package/lib/ModuleRestoreError.js +46 -0
  113. package/lib/ModuleSourceTypeConstants.js +179 -0
  114. package/lib/ModuleStoreError.js +45 -0
  115. package/lib/ModuleTemplate.js +173 -0
  116. package/lib/ModuleTypeConstants.js +190 -0
  117. package/lib/ModuleWarning.js +68 -0
  118. package/lib/MultiCompiler.js +678 -0
  119. package/lib/MultiStats.js +213 -0
  120. package/lib/MultiWatching.js +77 -0
  121. package/lib/NoEmitOnErrorsPlugin.js +30 -0
  122. package/lib/NoModeWarning.js +23 -0
  123. package/lib/NodeStuffInWebError.js +35 -0
  124. package/lib/NodeStuffPlugin.js +587 -0
  125. package/lib/NormalModule.js +1798 -0
  126. package/lib/NormalModuleFactory.js +1455 -0
  127. package/lib/NormalModuleReplacementPlugin.js +75 -0
  128. package/lib/NullFactory.js +24 -0
  129. package/lib/OptimizationStages.js +10 -0
  130. package/lib/OptionsApply.js +24 -0
  131. package/lib/Parser.js +40 -0
  132. package/lib/PlatformPlugin.js +41 -0
  133. package/lib/PrefetchPlugin.js +56 -0
  134. package/lib/ProgressPlugin.js +712 -0
  135. package/lib/ProvidePlugin.js +121 -0
  136. package/lib/RawModule.js +180 -0
  137. package/lib/RecordIdsPlugin.js +216 -0
  138. package/lib/RequestShortener.js +36 -0
  139. package/lib/RequireJsStuffPlugin.js +84 -0
  140. package/lib/ResolverFactory.js +156 -0
  141. package/lib/RuntimeGlobals.js +450 -0
  142. package/lib/RuntimeModule.js +242 -0
  143. package/lib/RuntimePlugin.js +547 -0
  144. package/lib/RuntimeTemplate.js +1288 -0
  145. package/lib/SelfModuleFactory.js +33 -0
  146. package/lib/SingleEntryPlugin.js +8 -0
  147. package/lib/SizeFormatHelpers.js +25 -0
  148. package/lib/SourceMapDevToolModuleOptionsPlugin.js +52 -0
  149. package/lib/SourceMapDevToolPlugin.js +646 -0
  150. package/lib/Stats.js +89 -0
  151. package/lib/Template.js +427 -0
  152. package/lib/TemplatedPathPlugin.js +400 -0
  153. package/lib/UnhandledSchemeError.js +34 -0
  154. package/lib/UnsupportedFeatureWarning.js +35 -0
  155. package/lib/UseStrictPlugin.js +81 -0
  156. package/lib/WarnCaseSensitiveModulesPlugin.js +64 -0
  157. package/lib/WarnDeprecatedOptionPlugin.js +60 -0
  158. package/lib/WarnNoModeSetPlugin.js +27 -0
  159. package/lib/WatchIgnorePlugin.js +155 -0
  160. package/lib/Watching.js +531 -0
  161. package/lib/WebpackError.js +81 -0
  162. package/lib/WebpackIsIncludedPlugin.js +93 -0
  163. package/lib/WebpackOptionsApply.js +941 -0
  164. package/lib/WebpackOptionsDefaulter.js +26 -0
  165. package/lib/asset/AssetBytesGenerator.js +172 -0
  166. package/lib/asset/AssetBytesParser.js +37 -0
  167. package/lib/asset/AssetGenerator.js +816 -0
  168. package/lib/asset/AssetModulesPlugin.js +358 -0
  169. package/lib/asset/AssetParser.js +73 -0
  170. package/lib/asset/AssetSourceGenerator.js +171 -0
  171. package/lib/asset/AssetSourceParser.js +37 -0
  172. package/lib/asset/RawDataUrlModule.js +179 -0
  173. package/lib/async-modules/AsyncModuleHelpers.js +52 -0
  174. package/lib/async-modules/AwaitDependenciesInitFragment.js +90 -0
  175. package/lib/async-modules/InferAsyncModulesPlugin.js +54 -0
  176. package/lib/buildChunkGraph.js +1392 -0
  177. package/lib/cache/AddBuildDependenciesPlugin.js +32 -0
  178. package/lib/cache/AddManagedPathsPlugin.js +40 -0
  179. package/lib/cache/IdleFileCachePlugin.js +242 -0
  180. package/lib/cache/MemoryCachePlugin.js +57 -0
  181. package/lib/cache/MemoryWithGcCachePlugin.js +142 -0
  182. package/lib/cache/PackFileCacheStrategy.js +1600 -0
  183. package/lib/cache/ResolverCachePlugin.js +450 -0
  184. package/lib/cache/getLazyHashedEtag.js +91 -0
  185. package/lib/cache/mergeEtags.js +71 -0
  186. package/lib/cli.js +859 -0
  187. package/lib/config/browserslistTargetHandler.js +388 -0
  188. package/lib/config/defaults.js +2086 -0
  189. package/lib/config/normalization.js +681 -0
  190. package/lib/config/target.js +389 -0
  191. package/lib/container/ContainerEntryDependency.js +50 -0
  192. package/lib/container/ContainerEntryModule.js +303 -0
  193. package/lib/container/ContainerEntryModuleFactory.js +27 -0
  194. package/lib/container/ContainerExposedDependency.js +62 -0
  195. package/lib/container/ContainerPlugin.js +118 -0
  196. package/lib/container/ContainerReferencePlugin.js +139 -0
  197. package/lib/container/FallbackDependency.js +66 -0
  198. package/lib/container/FallbackItemDependency.js +34 -0
  199. package/lib/container/FallbackModule.js +193 -0
  200. package/lib/container/FallbackModuleFactory.js +27 -0
  201. package/lib/container/HoistContainerReferencesPlugin.js +256 -0
  202. package/lib/container/ModuleFederationPlugin.js +131 -0
  203. package/lib/container/RemoteModule.js +225 -0
  204. package/lib/container/RemoteRuntimeModule.js +144 -0
  205. package/lib/container/RemoteToExternalDependency.js +33 -0
  206. package/lib/container/options.js +105 -0
  207. package/lib/css/CssGenerator.js +587 -0
  208. package/lib/css/CssLoadingRuntimeModule.js +513 -0
  209. package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
  210. package/lib/css/CssModulesPlugin.js +939 -0
  211. package/lib/css/CssParser.js +2621 -0
  212. package/lib/css/walkCssTokens.js +1740 -0
  213. package/lib/debug/ProfilingPlugin.js +589 -0
  214. package/lib/dependencies/AMDDefineDependency.js +267 -0
  215. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +504 -0
  216. package/lib/dependencies/AMDPlugin.js +243 -0
  217. package/lib/dependencies/AMDRequireArrayDependency.js +124 -0
  218. package/lib/dependencies/AMDRequireContextDependency.js +69 -0
  219. package/lib/dependencies/AMDRequireDependenciesBlock.js +28 -0
  220. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +425 -0
  221. package/lib/dependencies/AMDRequireDependency.js +189 -0
  222. package/lib/dependencies/AMDRequireItemDependency.js +41 -0
  223. package/lib/dependencies/AMDRuntimeModules.js +50 -0
  224. package/lib/dependencies/CachedConstDependency.js +135 -0
  225. package/lib/dependencies/CommonJsDependencyHelpers.js +65 -0
  226. package/lib/dependencies/CommonJsExportRequireDependency.js +416 -0
  227. package/lib/dependencies/CommonJsExportsDependency.js +184 -0
  228. package/lib/dependencies/CommonJsExportsParserPlugin.js +425 -0
  229. package/lib/dependencies/CommonJsFullRequireDependency.js +162 -0
  230. package/lib/dependencies/CommonJsImportsParserPlugin.js +611 -0
  231. package/lib/dependencies/CommonJsPlugin.js +316 -0
  232. package/lib/dependencies/CommonJsRequireContextDependency.js +73 -0
  233. package/lib/dependencies/CommonJsRequireDependency.js +42 -0
  234. package/lib/dependencies/CommonJsSelfReferenceDependency.js +156 -0
  235. package/lib/dependencies/ConstDependency.js +118 -0
  236. package/lib/dependencies/ContextDependency.js +183 -0
  237. package/lib/dependencies/ContextDependencyHelpers.js +277 -0
  238. package/lib/dependencies/ContextDependencyTemplateAsId.js +63 -0
  239. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +62 -0
  240. package/lib/dependencies/ContextElementDependency.js +147 -0
  241. package/lib/dependencies/CreateRequireParserPlugin.js +356 -0
  242. package/lib/dependencies/CreateScriptUrlDependency.js +75 -0
  243. package/lib/dependencies/CriticalDependencyWarning.js +29 -0
  244. package/lib/dependencies/CssIcssExportDependency.js +539 -0
  245. package/lib/dependencies/CssIcssImportDependency.js +183 -0
  246. package/lib/dependencies/CssIcssSymbolDependency.js +131 -0
  247. package/lib/dependencies/CssImportDependency.js +120 -0
  248. package/lib/dependencies/CssUrlDependency.js +189 -0
  249. package/lib/dependencies/DelegatedSourceDependency.js +33 -0
  250. package/lib/dependencies/DllEntryDependency.js +61 -0
  251. package/lib/dependencies/DynamicExports.js +73 -0
  252. package/lib/dependencies/EntryDependency.js +30 -0
  253. package/lib/dependencies/ExportsInfoDependency.js +161 -0
  254. package/lib/dependencies/ExternalModuleDependency.js +109 -0
  255. package/lib/dependencies/ExternalModuleInitFragment.js +137 -0
  256. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +87 -0
  257. package/lib/dependencies/HarmonyAcceptDependency.js +237 -0
  258. package/lib/dependencies/HarmonyAcceptImportDependency.js +37 -0
  259. package/lib/dependencies/HarmonyCompatibilityDependency.js +91 -0
  260. package/lib/dependencies/HarmonyDetectionParserPlugin.js +103 -0
  261. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +165 -0
  262. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +254 -0
  263. package/lib/dependencies/HarmonyExportExpressionDependency.js +211 -0
  264. package/lib/dependencies/HarmonyExportHeaderDependency.js +78 -0
  265. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +1494 -0
  266. package/lib/dependencies/HarmonyExportInitFragment.js +191 -0
  267. package/lib/dependencies/HarmonyExportSpecifierDependency.js +127 -0
  268. package/lib/dependencies/HarmonyExports.js +46 -0
  269. package/lib/dependencies/HarmonyImportDependency.js +459 -0
  270. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +576 -0
  271. package/lib/dependencies/HarmonyImportSideEffectDependency.js +91 -0
  272. package/lib/dependencies/HarmonyImportSpecifierDependency.js +514 -0
  273. package/lib/dependencies/HarmonyModulesPlugin.js +158 -0
  274. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +39 -0
  275. package/lib/dependencies/ImportContextDependency.js +81 -0
  276. package/lib/dependencies/ImportDependency.js +158 -0
  277. package/lib/dependencies/ImportEagerDependency.js +76 -0
  278. package/lib/dependencies/ImportMetaContextDependency.js +42 -0
  279. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +312 -0
  280. package/lib/dependencies/ImportMetaContextPlugin.js +72 -0
  281. package/lib/dependencies/ImportMetaHotAcceptDependency.js +41 -0
  282. package/lib/dependencies/ImportMetaHotDeclineDependency.js +42 -0
  283. package/lib/dependencies/ImportMetaPlugin.js +447 -0
  284. package/lib/dependencies/ImportParserPlugin.js +602 -0
  285. package/lib/dependencies/ImportPhase.js +125 -0
  286. package/lib/dependencies/ImportPlugin.js +98 -0
  287. package/lib/dependencies/ImportWeakDependency.js +74 -0
  288. package/lib/dependencies/JsonExportsDependency.js +137 -0
  289. package/lib/dependencies/LoaderDependency.js +38 -0
  290. package/lib/dependencies/LoaderImportDependency.js +39 -0
  291. package/lib/dependencies/LoaderPlugin.js +294 -0
  292. package/lib/dependencies/LocalModule.js +60 -0
  293. package/lib/dependencies/LocalModuleDependency.js +84 -0
  294. package/lib/dependencies/LocalModulesHelpers.js +68 -0
  295. package/lib/dependencies/ModuleDecoratorDependency.js +136 -0
  296. package/lib/dependencies/ModuleDependency.js +100 -0
  297. package/lib/dependencies/ModuleDependencyTemplateAsId.js +35 -0
  298. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +39 -0
  299. package/lib/dependencies/ModuleHotAcceptDependency.js +41 -0
  300. package/lib/dependencies/ModuleHotDeclineDependency.js +42 -0
  301. package/lib/dependencies/ModuleInitFragmentDependency.js +87 -0
  302. package/lib/dependencies/NullDependency.js +42 -0
  303. package/lib/dependencies/PrefetchDependency.js +27 -0
  304. package/lib/dependencies/ProvidedDependency.js +156 -0
  305. package/lib/dependencies/PureExpressionDependency.js +161 -0
  306. package/lib/dependencies/RequireContextDependency.js +38 -0
  307. package/lib/dependencies/RequireContextDependencyParserPlugin.js +69 -0
  308. package/lib/dependencies/RequireContextPlugin.js +167 -0
  309. package/lib/dependencies/RequireEnsureDependenciesBlock.js +29 -0
  310. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +145 -0
  311. package/lib/dependencies/RequireEnsureDependency.js +115 -0
  312. package/lib/dependencies/RequireEnsureItemDependency.js +36 -0
  313. package/lib/dependencies/RequireEnsurePlugin.js +86 -0
  314. package/lib/dependencies/RequireHeaderDependency.js +70 -0
  315. package/lib/dependencies/RequireIncludeDependency.js +79 -0
  316. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +100 -0
  317. package/lib/dependencies/RequireIncludePlugin.js +63 -0
  318. package/lib/dependencies/RequireResolveContextDependency.js +67 -0
  319. package/lib/dependencies/RequireResolveDependency.js +58 -0
  320. package/lib/dependencies/RequireResolveHeaderDependency.js +81 -0
  321. package/lib/dependencies/RuntimeRequirementsDependency.js +85 -0
  322. package/lib/dependencies/StaticExportsDependency.js +72 -0
  323. package/lib/dependencies/SystemPlugin.js +168 -0
  324. package/lib/dependencies/SystemRuntimeModule.js +35 -0
  325. package/lib/dependencies/URLContextDependency.js +65 -0
  326. package/lib/dependencies/URLDependency.js +165 -0
  327. package/lib/dependencies/URLPlugin.js +67 -0
  328. package/lib/dependencies/UnsupportedDependency.js +82 -0
  329. package/lib/dependencies/WebAssemblyExportImportedDependency.js +93 -0
  330. package/lib/dependencies/WebAssemblyImportDependency.js +108 -0
  331. package/lib/dependencies/WebpackIsIncludedDependency.js +84 -0
  332. package/lib/dependencies/WorkerDependency.js +141 -0
  333. package/lib/dependencies/WorkerPlugin.js +565 -0
  334. package/lib/dependencies/getFunctionExpression.js +66 -0
  335. package/lib/dependencies/processExportInfo.js +67 -0
  336. package/lib/electron/ElectronTargetPlugin.js +71 -0
  337. package/lib/errors/BuildCycleError.js +30 -0
  338. package/lib/esm/ExportWebpackRequireRuntimeModule.js +30 -0
  339. package/lib/esm/ModuleChunkFormatPlugin.js +273 -0
  340. package/lib/esm/ModuleChunkLoadingPlugin.js +143 -0
  341. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +426 -0
  342. package/lib/formatLocation.js +67 -0
  343. package/lib/hmr/HotModuleReplacement.runtime.js +419 -0
  344. package/lib/hmr/HotModuleReplacementRuntimeModule.js +42 -0
  345. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +471 -0
  346. package/lib/hmr/JavascriptHotModuleReplacementHelper.js +37 -0
  347. package/lib/hmr/LazyCompilationPlugin.js +473 -0
  348. package/lib/hmr/lazyCompilationBackend.js +167 -0
  349. package/lib/ids/ChunkModuleIdRangePlugin.js +94 -0
  350. package/lib/ids/DeterministicChunkIdsPlugin.js +73 -0
  351. package/lib/ids/DeterministicModuleIdsPlugin.js +98 -0
  352. package/lib/ids/HashedModuleIdsPlugin.js +85 -0
  353. package/lib/ids/IdHelpers.js +492 -0
  354. package/lib/ids/NamedChunkIdsPlugin.js +92 -0
  355. package/lib/ids/NamedModuleIdsPlugin.js +68 -0
  356. package/lib/ids/NaturalChunkIdsPlugin.js +35 -0
  357. package/lib/ids/NaturalModuleIdsPlugin.js +40 -0
  358. package/lib/ids/OccurrenceChunkIdsPlugin.js +86 -0
  359. package/lib/ids/OccurrenceModuleIdsPlugin.js +168 -0
  360. package/lib/ids/SyncModuleIdsPlugin.js +161 -0
  361. package/lib/index.js +681 -0
  362. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +153 -0
  363. package/lib/javascript/BasicEvaluatedExpression.js +603 -0
  364. package/lib/javascript/ChunkFormatHelpers.js +70 -0
  365. package/lib/javascript/ChunkHelpers.js +45 -0
  366. package/lib/javascript/CommonJsChunkFormatPlugin.js +148 -0
  367. package/lib/javascript/EnableChunkLoadingPlugin.js +127 -0
  368. package/lib/javascript/JavascriptGenerator.js +277 -0
  369. package/lib/javascript/JavascriptModulesPlugin.js +1905 -0
  370. package/lib/javascript/JavascriptParser.js +5476 -0
  371. package/lib/javascript/JavascriptParserHelpers.js +129 -0
  372. package/lib/javascript/StartupHelpers.js +178 -0
  373. package/lib/json/JsonData.js +74 -0
  374. package/lib/json/JsonGenerator.js +234 -0
  375. package/lib/json/JsonModulesPlugin.js +66 -0
  376. package/lib/json/JsonParser.js +93 -0
  377. package/lib/library/AbstractLibraryPlugin.js +339 -0
  378. package/lib/library/AmdLibraryPlugin.js +181 -0
  379. package/lib/library/AssignLibraryPlugin.js +445 -0
  380. package/lib/library/EnableLibraryPlugin.js +306 -0
  381. package/lib/library/ExportPropertyLibraryPlugin.js +116 -0
  382. package/lib/library/JsonpLibraryPlugin.js +92 -0
  383. package/lib/library/ModuleLibraryPlugin.js +438 -0
  384. package/lib/library/SystemLibraryPlugin.js +256 -0
  385. package/lib/library/UmdLibraryPlugin.js +355 -0
  386. package/lib/logging/Logger.js +223 -0
  387. package/lib/logging/createConsoleLogger.js +217 -0
  388. package/lib/logging/runtime.js +45 -0
  389. package/lib/logging/truncateArgs.js +83 -0
  390. package/lib/node/CommonJsChunkLoadingPlugin.js +120 -0
  391. package/lib/node/NodeEnvironmentPlugin.js +73 -0
  392. package/lib/node/NodeSourcePlugin.js +19 -0
  393. package/lib/node/NodeTargetPlugin.js +102 -0
  394. package/lib/node/NodeTemplatePlugin.js +42 -0
  395. package/lib/node/NodeWatchFileSystem.js +198 -0
  396. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +286 -0
  397. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +123 -0
  398. package/lib/node/ReadFileCompileWasmPlugin.js +127 -0
  399. package/lib/node/RequireChunkLoadingRuntimeModule.js +239 -0
  400. package/lib/node/nodeConsole.js +185 -0
  401. package/lib/optimize/AggressiveMergingPlugin.js +98 -0
  402. package/lib/optimize/AggressiveSplittingPlugin.js +352 -0
  403. package/lib/optimize/ConcatenatedModule.js +2290 -0
  404. package/lib/optimize/EnsureChunkConditionsPlugin.js +88 -0
  405. package/lib/optimize/FlagIncludedChunksPlugin.js +137 -0
  406. package/lib/optimize/InnerGraph.js +368 -0
  407. package/lib/optimize/InnerGraphPlugin.js +455 -0
  408. package/lib/optimize/LimitChunkCountPlugin.js +302 -0
  409. package/lib/optimize/MangleExportsPlugin.js +194 -0
  410. package/lib/optimize/MergeDuplicateChunksPlugin.js +138 -0
  411. package/lib/optimize/MinChunkSizePlugin.js +121 -0
  412. package/lib/optimize/MinMaxSizeWarning.js +35 -0
  413. package/lib/optimize/ModuleConcatenationPlugin.js +971 -0
  414. package/lib/optimize/RealContentHashPlugin.js +488 -0
  415. package/lib/optimize/RemoveEmptyChunksPlugin.js +60 -0
  416. package/lib/optimize/RemoveParentModulesPlugin.js +216 -0
  417. package/lib/optimize/RuntimeChunkPlugin.js +52 -0
  418. package/lib/optimize/SideEffectsFlagPlugin.js +417 -0
  419. package/lib/optimize/SplitChunksPlugin.js +1836 -0
  420. package/lib/performance/AssetsOverSizeLimitWarning.js +37 -0
  421. package/lib/performance/EntrypointsOverSizeLimitWarning.js +40 -0
  422. package/lib/performance/NoAsyncChunksWarning.js +21 -0
  423. package/lib/performance/SizeLimitsPlugin.js +183 -0
  424. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +46 -0
  425. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +95 -0
  426. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +56 -0
  427. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +52 -0
  428. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +46 -0
  429. package/lib/rules/BasicEffectRulePlugin.js +56 -0
  430. package/lib/rules/BasicMatcherRulePlugin.js +68 -0
  431. package/lib/rules/ObjectMatcherRulePlugin.js +79 -0
  432. package/lib/rules/RuleSetCompiler.js +447 -0
  433. package/lib/rules/UseEffectRulePlugin.js +236 -0
  434. package/lib/runtime/AsyncModuleRuntimeModule.js +199 -0
  435. package/lib/runtime/AutoPublicPathRuntimeModule.js +90 -0
  436. package/lib/runtime/BaseUriRuntimeModule.js +35 -0
  437. package/lib/runtime/ChunkNameRuntimeModule.js +28 -0
  438. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +40 -0
  439. package/lib/runtime/CompatRuntimeModule.js +83 -0
  440. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +69 -0
  441. package/lib/runtime/CreateScriptRuntimeModule.js +38 -0
  442. package/lib/runtime/CreateScriptUrlRuntimeModule.js +38 -0
  443. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +42 -0
  444. package/lib/runtime/EnsureChunkRuntimeModule.js +69 -0
  445. package/lib/runtime/GetChunkFilenameRuntimeModule.js +299 -0
  446. package/lib/runtime/GetFullHashRuntimeModule.js +31 -0
  447. package/lib/runtime/GetMainFilenameRuntimeModule.js +49 -0
  448. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +99 -0
  449. package/lib/runtime/GlobalRuntimeModule.js +47 -0
  450. package/lib/runtime/HasOwnPropertyRuntimeModule.js +35 -0
  451. package/lib/runtime/HelperRuntimeModule.js +18 -0
  452. package/lib/runtime/LoadScriptRuntimeModule.js +174 -0
  453. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +232 -0
  454. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +39 -0
  455. package/lib/runtime/NonceRuntimeModule.js +24 -0
  456. package/lib/runtime/OnChunksLoadedRuntimeModule.js +78 -0
  457. package/lib/runtime/PublicPathRuntimeModule.js +38 -0
  458. package/lib/runtime/RelativeUrlRuntimeModule.js +44 -0
  459. package/lib/runtime/RuntimeIdRuntimeModule.js +33 -0
  460. package/lib/runtime/StartupChunkDependenciesPlugin.js +88 -0
  461. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +77 -0
  462. package/lib/runtime/StartupEntrypointRuntimeModule.js +54 -0
  463. package/lib/runtime/SystemContextRuntimeModule.js +23 -0
  464. package/lib/runtime/ToBinaryRuntimeModule.js +72 -0
  465. package/lib/schemes/DataUriPlugin.js +47 -0
  466. package/lib/schemes/FileUriPlugin.js +54 -0
  467. package/lib/schemes/HttpUriPlugin.js +1410 -0
  468. package/lib/schemes/VirtualUrlPlugin.js +248 -0
  469. package/lib/serialization/AggregateErrorSerializer.js +41 -0
  470. package/lib/serialization/ArraySerializer.js +38 -0
  471. package/lib/serialization/BinaryMiddleware.js +1164 -0
  472. package/lib/serialization/DateObjectSerializer.js +28 -0
  473. package/lib/serialization/ErrorObjectSerializer.js +49 -0
  474. package/lib/serialization/FileMiddleware.js +766 -0
  475. package/lib/serialization/MapObjectSerializer.js +48 -0
  476. package/lib/serialization/NullPrototypeObjectSerializer.js +53 -0
  477. package/lib/serialization/ObjectMiddleware.js +877 -0
  478. package/lib/serialization/PlainObjectSerializer.js +119 -0
  479. package/lib/serialization/RegExpObjectSerializer.js +29 -0
  480. package/lib/serialization/Serializer.js +82 -0
  481. package/lib/serialization/SerializerMiddleware.js +226 -0
  482. package/lib/serialization/SetObjectSerializer.js +40 -0
  483. package/lib/serialization/SingleItemMiddleware.js +36 -0
  484. package/lib/serialization/types.js +13 -0
  485. package/lib/sharing/ConsumeSharedFallbackDependency.js +33 -0
  486. package/lib/sharing/ConsumeSharedModule.js +344 -0
  487. package/lib/sharing/ConsumeSharedPlugin.js +380 -0
  488. package/lib/sharing/ConsumeSharedRuntimeModule.js +358 -0
  489. package/lib/sharing/ProvideForSharedDependency.js +33 -0
  490. package/lib/sharing/ProvideSharedDependency.js +80 -0
  491. package/lib/sharing/ProvideSharedModule.js +196 -0
  492. package/lib/sharing/ProvideSharedModuleFactory.js +37 -0
  493. package/lib/sharing/ProvideSharedPlugin.js +248 -0
  494. package/lib/sharing/SharePlugin.js +91 -0
  495. package/lib/sharing/ShareRuntimeModule.js +152 -0
  496. package/lib/sharing/resolveMatchedConfigs.js +106 -0
  497. package/lib/sharing/utils.js +421 -0
  498. package/lib/stats/DefaultStatsFactoryPlugin.js +2791 -0
  499. package/lib/stats/DefaultStatsPresetPlugin.js +417 -0
  500. package/lib/stats/DefaultStatsPrinterPlugin.js +1860 -0
  501. package/lib/stats/StatsFactory.js +406 -0
  502. package/lib/stats/StatsPrinter.js +300 -0
  503. package/lib/url/URLParserPlugin.js +266 -0
  504. package/lib/util/AppendOnlyStackedSet.js +78 -0
  505. package/lib/util/ArrayHelpers.js +46 -0
  506. package/lib/util/ArrayQueue.js +104 -0
  507. package/lib/util/AsyncQueue.js +411 -0
  508. package/lib/util/Hash.js +68 -0
  509. package/lib/util/IterableHelpers.js +46 -0
  510. package/lib/util/LazyBucketSortedSet.js +272 -0
  511. package/lib/util/LazySet.js +236 -0
  512. package/lib/util/MapHelpers.js +34 -0
  513. package/lib/util/ParallelismFactorCalculator.js +70 -0
  514. package/lib/util/Queue.js +52 -0
  515. package/lib/util/Semaphore.js +51 -0
  516. package/lib/util/SetHelpers.js +94 -0
  517. package/lib/util/SortableSet.js +176 -0
  518. package/lib/util/StackedCacheMap.js +140 -0
  519. package/lib/util/StackedMap.js +164 -0
  520. package/lib/util/StringXor.js +103 -0
  521. package/lib/util/TupleQueue.js +70 -0
  522. package/lib/util/TupleSet.js +185 -0
  523. package/lib/util/URLAbsoluteSpecifier.js +86 -0
  524. package/lib/util/WeakTupleMap.js +227 -0
  525. package/lib/util/binarySearchBounds.js +136 -0
  526. package/lib/util/chainedImports.js +99 -0
  527. package/lib/util/cleverMerge.js +676 -0
  528. package/lib/util/comparators.js +645 -0
  529. package/lib/util/compileBooleanMatcher.js +313 -0
  530. package/lib/util/concatenate.js +232 -0
  531. package/lib/util/conventions.js +126 -0
  532. package/lib/util/create-schema-validation.js +41 -0
  533. package/lib/util/createHash.js +91 -0
  534. package/lib/util/dataURL.js +39 -0
  535. package/lib/util/deprecation.js +350 -0
  536. package/lib/util/deterministicGrouping.js +561 -0
  537. package/lib/util/extractSourceMap.js +318 -0
  538. package/lib/util/extractUrlAndGlobal.js +18 -0
  539. package/lib/util/findGraphRoots.js +211 -0
  540. package/lib/util/fs.js +675 -0
  541. package/lib/util/generateDebugId.js +33 -0
  542. package/lib/util/hash/BatchedHash.js +115 -0
  543. package/lib/util/hash/BulkUpdateHash.js +145 -0
  544. package/lib/util/hash/DebugHash.js +75 -0
  545. package/lib/util/hash/hash-digest.js +217 -0
  546. package/lib/util/hash/md4.js +20 -0
  547. package/lib/util/hash/wasm-hash.js +232 -0
  548. package/lib/util/hash/xxhash64.js +20 -0
  549. package/lib/util/identifier.js +471 -0
  550. package/lib/util/internalSerializables.js +222 -0
  551. package/lib/util/magicComment.js +25 -0
  552. package/lib/util/makeSerializable.js +60 -0
  553. package/lib/util/memoize.js +36 -0
  554. package/lib/util/nonNumericOnlyHash.js +22 -0
  555. package/lib/util/numberHash.js +95 -0
  556. package/lib/util/objectToMap.js +15 -0
  557. package/lib/util/processAsyncTree.js +68 -0
  558. package/lib/util/propertyAccess.js +30 -0
  559. package/lib/util/propertyName.js +76 -0
  560. package/lib/util/registerExternalSerializer.js +334 -0
  561. package/lib/util/removeBOM.js +25 -0
  562. package/lib/util/runtime.js +717 -0
  563. package/lib/util/semver.js +604 -0
  564. package/lib/util/serialization.js +153 -0
  565. package/lib/util/smartGrouping.js +221 -0
  566. package/lib/util/source.js +62 -0
  567. package/lib/util/traverseDestructuringAssignmentProperties.js +45 -0
  568. package/lib/validateSchema.js +177 -0
  569. package/lib/wasm/EnableWasmLoadingPlugin.js +146 -0
  570. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +154 -0
  571. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +74 -0
  572. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +212 -0
  573. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +209 -0
  574. package/lib/wasm-async/AsyncWebAssemblyParser.js +80 -0
  575. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +107 -0
  576. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +20 -0
  577. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +422 -0
  578. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +91 -0
  579. package/lib/wasm-sync/WebAssemblyGenerator.js +535 -0
  580. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +111 -0
  581. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +236 -0
  582. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +151 -0
  583. package/lib/wasm-sync/WebAssemblyParser.js +201 -0
  584. package/lib/wasm-sync/WebAssemblyUtils.js +66 -0
  585. package/lib/web/FetchCompileAsyncWasmPlugin.js +70 -0
  586. package/lib/web/FetchCompileWasmPlugin.js +86 -0
  587. package/lib/web/JsonpChunkLoadingPlugin.js +101 -0
  588. package/lib/web/JsonpChunkLoadingRuntimeModule.js +455 -0
  589. package/lib/web/JsonpTemplatePlugin.js +37 -0
  590. package/lib/webpack.js +227 -0
  591. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +110 -0
  592. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +231 -0
  593. package/lib/webworker/WebWorkerTemplatePlugin.js +26 -0
  594. package/module.d.ts +238 -0
  595. package/package.json +258 -0
  596. package/schemas/WebpackOptions.check.d.ts +7 -0
  597. package/schemas/WebpackOptions.check.js +6 -0
  598. package/schemas/WebpackOptions.json +6179 -0
  599. package/schemas/_container.json +155 -0
  600. package/schemas/_sharing.json +118 -0
  601. package/schemas/plugins/BannerPlugin.check.d.ts +7 -0
  602. package/schemas/plugins/BannerPlugin.check.js +6 -0
  603. package/schemas/plugins/BannerPlugin.json +115 -0
  604. package/schemas/plugins/DllPlugin.check.d.ts +7 -0
  605. package/schemas/plugins/DllPlugin.check.js +6 -0
  606. package/schemas/plugins/DllPlugin.json +36 -0
  607. package/schemas/plugins/DllReferencePlugin.check.d.ts +7 -0
  608. package/schemas/plugins/DllReferencePlugin.check.js +6 -0
  609. package/schemas/plugins/DllReferencePlugin.json +206 -0
  610. package/schemas/plugins/IgnorePlugin.check.d.ts +7 -0
  611. package/schemas/plugins/IgnorePlugin.check.js +6 -0
  612. package/schemas/plugins/IgnorePlugin.json +34 -0
  613. package/schemas/plugins/LoaderOptionsPlugin.check.d.ts +7 -0
  614. package/schemas/plugins/LoaderOptionsPlugin.check.js +6 -0
  615. package/schemas/plugins/LoaderOptionsPlugin.json +27 -0
  616. package/schemas/plugins/ManifestPlugin.check.d.ts +7 -0
  617. package/schemas/plugins/ManifestPlugin.check.js +6 -0
  618. package/schemas/plugins/ManifestPlugin.json +98 -0
  619. package/schemas/plugins/ProgressPlugin.check.d.ts +7 -0
  620. package/schemas/plugins/ProgressPlugin.check.js +6 -0
  621. package/schemas/plugins/ProgressPlugin.json +65 -0
  622. package/schemas/plugins/SourceMapDevToolPlugin.check.d.ts +7 -0
  623. package/schemas/plugins/SourceMapDevToolPlugin.check.js +6 -0
  624. package/schemas/plugins/SourceMapDevToolPlugin.json +168 -0
  625. package/schemas/plugins/WatchIgnorePlugin.check.d.ts +7 -0
  626. package/schemas/plugins/WatchIgnorePlugin.check.js +6 -0
  627. package/schemas/plugins/WatchIgnorePlugin.json +25 -0
  628. package/schemas/plugins/asset/AssetGeneratorOptions.check.d.ts +7 -0
  629. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +6 -0
  630. package/schemas/plugins/asset/AssetGeneratorOptions.json +3 -0
  631. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.d.ts +7 -0
  632. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +6 -0
  633. package/schemas/plugins/asset/AssetInlineGeneratorOptions.json +3 -0
  634. package/schemas/plugins/asset/AssetParserOptions.check.d.ts +7 -0
  635. package/schemas/plugins/asset/AssetParserOptions.check.js +6 -0
  636. package/schemas/plugins/asset/AssetParserOptions.json +3 -0
  637. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.d.ts +7 -0
  638. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +6 -0
  639. package/schemas/plugins/asset/AssetResourceGeneratorOptions.json +3 -0
  640. package/schemas/plugins/container/ContainerPlugin.check.d.ts +7 -0
  641. package/schemas/plugins/container/ContainerPlugin.check.js +6 -0
  642. package/schemas/plugins/container/ContainerPlugin.json +294 -0
  643. package/schemas/plugins/container/ContainerReferencePlugin.check.d.ts +7 -0
  644. package/schemas/plugins/container/ContainerReferencePlugin.check.js +6 -0
  645. package/schemas/plugins/container/ContainerReferencePlugin.json +132 -0
  646. package/schemas/plugins/container/ExternalsType.check.d.ts +7 -0
  647. package/schemas/plugins/container/ExternalsType.check.js +6 -0
  648. package/schemas/plugins/container/ExternalsType.json +3 -0
  649. package/schemas/plugins/container/ModuleFederationPlugin.check.d.ts +7 -0
  650. package/schemas/plugins/container/ModuleFederationPlugin.check.js +6 -0
  651. package/schemas/plugins/container/ModuleFederationPlugin.json +525 -0
  652. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
  653. package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
  654. package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
  655. package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +7 -0
  656. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +6 -0
  657. package/schemas/plugins/css/CssModuleGeneratorOptions.json +3 -0
  658. package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +7 -0
  659. package/schemas/plugins/css/CssModuleParserOptions.check.js +6 -0
  660. package/schemas/plugins/css/CssModuleParserOptions.json +3 -0
  661. package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
  662. package/schemas/plugins/css/CssParserOptions.check.js +6 -0
  663. package/schemas/plugins/css/CssParserOptions.json +3 -0
  664. package/schemas/plugins/debug/ProfilingPlugin.check.d.ts +7 -0
  665. package/schemas/plugins/debug/ProfilingPlugin.check.js +6 -0
  666. package/schemas/plugins/debug/ProfilingPlugin.json +12 -0
  667. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.d.ts +7 -0
  668. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +6 -0
  669. package/schemas/plugins/ids/HashedModuleIdsPlugin.json +57 -0
  670. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.d.ts +7 -0
  671. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +6 -0
  672. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.json +11 -0
  673. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.d.ts +7 -0
  674. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +6 -0
  675. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.json +11 -0
  676. package/schemas/plugins/json/JsonModulesPluginGenerator.check.d.ts +7 -0
  677. package/schemas/plugins/json/JsonModulesPluginGenerator.check.js +6 -0
  678. package/schemas/plugins/json/JsonModulesPluginGenerator.json +3 -0
  679. package/schemas/plugins/json/JsonModulesPluginParser.check.d.ts +7 -0
  680. package/schemas/plugins/json/JsonModulesPluginParser.check.js +6 -0
  681. package/schemas/plugins/json/JsonModulesPluginParser.json +3 -0
  682. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.d.ts +7 -0
  683. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +6 -0
  684. package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +23 -0
  685. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.d.ts +7 -0
  686. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +6 -0
  687. package/schemas/plugins/optimize/LimitChunkCountPlugin.json +21 -0
  688. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.d.ts +7 -0
  689. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +6 -0
  690. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.json +11 -0
  691. package/schemas/plugins/optimize/MinChunkSizePlugin.check.d.ts +7 -0
  692. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +6 -0
  693. package/schemas/plugins/optimize/MinChunkSizePlugin.json +20 -0
  694. package/schemas/plugins/schemes/HttpUriPlugin.check.d.ts +7 -0
  695. package/schemas/plugins/schemes/HttpUriPlugin.check.js +6 -0
  696. package/schemas/plugins/schemes/HttpUriPlugin.json +74 -0
  697. package/schemas/plugins/schemes/VirtualUrlPlugin.check.d.ts +7 -0
  698. package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +6 -0
  699. package/schemas/plugins/schemes/VirtualUrlPlugin.json +77 -0
  700. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.d.ts +7 -0
  701. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +6 -0
  702. package/schemas/plugins/sharing/ConsumeSharedPlugin.json +120 -0
  703. package/schemas/plugins/sharing/ProvideSharedPlugin.check.d.ts +7 -0
  704. package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +6 -0
  705. package/schemas/plugins/sharing/ProvideSharedPlugin.json +94 -0
  706. package/schemas/plugins/sharing/SharePlugin.check.d.ts +7 -0
  707. package/schemas/plugins/sharing/SharePlugin.check.js +6 -0
  708. package/schemas/plugins/sharing/SharePlugin.json +133 -0
  709. package/types.d.ts +20217 -0
@@ -0,0 +1,1836 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const Chunk = require("../Chunk");
9
+ const { STAGE_ADVANCED } = require("../OptimizationStages");
10
+ const WebpackError = require("../WebpackError");
11
+ const { requestToId } = require("../ids/IdHelpers");
12
+ const { isSubset } = require("../util/SetHelpers");
13
+ const SortableSet = require("../util/SortableSet");
14
+ const {
15
+ compareIterables,
16
+ compareModulesByIdentifier
17
+ } = require("../util/comparators");
18
+ const createHash = require("../util/createHash");
19
+ const deterministicGrouping = require("../util/deterministicGrouping");
20
+ const { makePathsRelative } = require("../util/identifier");
21
+ const memoize = require("../util/memoize");
22
+ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
23
+
24
+ /** @typedef {import("../../declarations/WebpackOptions").OptimizationSplitChunksCacheGroup} OptimizationSplitChunksCacheGroup */
25
+ /** @typedef {import("../../declarations/WebpackOptions").OptimizationSplitChunksOptions} OptimizationSplitChunksOptions */
26
+ /** @typedef {import("../../declarations/WebpackOptions").OptimizationSplitChunksSizes} OptimizationSplitChunksSizes */
27
+ /** @typedef {import("../config/defaults").OutputNormalizedWithDefaults} OutputOptions */
28
+ /** @typedef {import("../Chunk").ChunkName} ChunkName */
29
+ /** @typedef {import("../ChunkGraph")} ChunkGraph */
30
+ /** @typedef {import("../ChunkGroup")} ChunkGroup */
31
+ /** @typedef {import("../Compiler")} Compiler */
32
+ /** @typedef {import("../Module")} Module */
33
+ /** @typedef {import("../Module").SourceType} SourceType */
34
+ /** @typedef {import("../ModuleGraph")} ModuleGraph */
35
+ /** @typedef {import("../TemplatedPathPlugin").TemplatePath} TemplatePath */
36
+ /** @typedef {import("../util/deterministicGrouping").GroupedItems<Module>} DeterministicGroupingGroupedItemsForModule */
37
+ /** @typedef {import("../util/deterministicGrouping").Options<Module>} DeterministicGroupingOptionsForModule */
38
+ /** @typedef {import("../util/deterministicGrouping").Sizes} Sizes */
39
+
40
+ /**
41
+ * @callback ChunkFilterFn
42
+ * @param {Chunk} chunk
43
+ * @returns {boolean | undefined}
44
+ */
45
+
46
+ /** @typedef {number} Priority */
47
+ /** @typedef {number} Size */
48
+ /** @typedef {number} CountOfChunk */
49
+ /** @typedef {number} CountOfRequest */
50
+
51
+ /**
52
+ * @callback CombineSizeFunction
53
+ * @param {Size} a
54
+ * @param {Size} b
55
+ * @returns {Size}
56
+ */
57
+
58
+ /** @typedef {SourceType[]} SourceTypes */
59
+ /** @typedef {SourceType[]} DefaultSizeTypes */
60
+ /** @typedef {Record<SourceType, Size>} SplitChunksSizes */
61
+
62
+ /**
63
+ * @typedef {object} CacheGroupSource
64
+ * @property {string} key
65
+ * @property {Priority=} priority
66
+ * @property {GetNameFn=} getName
67
+ * @property {ChunkFilterFn=} chunksFilter
68
+ * @property {boolean=} enforce
69
+ * @property {SplitChunksSizes} minSize
70
+ * @property {SplitChunksSizes} minSizeReduction
71
+ * @property {SplitChunksSizes} minRemainingSize
72
+ * @property {SplitChunksSizes} enforceSizeThreshold
73
+ * @property {SplitChunksSizes} maxAsyncSize
74
+ * @property {SplitChunksSizes} maxInitialSize
75
+ * @property {CountOfChunk=} minChunks
76
+ * @property {CountOfRequest=} maxAsyncRequests
77
+ * @property {CountOfRequest=} maxInitialRequests
78
+ * @property {TemplatePath=} filename
79
+ * @property {string=} idHint
80
+ * @property {string=} automaticNameDelimiter
81
+ * @property {boolean=} reuseExistingChunk
82
+ * @property {boolean=} usedExports
83
+ */
84
+
85
+ /**
86
+ * @typedef {object} CacheGroup
87
+ * @property {string} key
88
+ * @property {Priority} priority
89
+ * @property {GetNameFn=} getName
90
+ * @property {ChunkFilterFn} chunksFilter
91
+ * @property {SplitChunksSizes} minSize
92
+ * @property {SplitChunksSizes} minSizeReduction
93
+ * @property {SplitChunksSizes} minRemainingSize
94
+ * @property {SplitChunksSizes} enforceSizeThreshold
95
+ * @property {SplitChunksSizes} maxAsyncSize
96
+ * @property {SplitChunksSizes} maxInitialSize
97
+ * @property {CountOfChunk} minChunks
98
+ * @property {CountOfRequest} maxAsyncRequests
99
+ * @property {CountOfRequest} maxInitialRequests
100
+ * @property {TemplatePath=} filename
101
+ * @property {string} idHint
102
+ * @property {string} automaticNameDelimiter
103
+ * @property {boolean} reuseExistingChunk
104
+ * @property {boolean} usedExports
105
+ * @property {boolean} _validateSize
106
+ * @property {boolean} _validateRemainingSize
107
+ * @property {SplitChunksSizes} _minSizeForMaxSize
108
+ * @property {boolean} _conditionalEnforce
109
+ */
110
+
111
+ /**
112
+ * @typedef {object} FallbackCacheGroup
113
+ * @property {ChunkFilterFn} chunksFilter
114
+ * @property {SplitChunksSizes} minSize
115
+ * @property {SplitChunksSizes} maxAsyncSize
116
+ * @property {SplitChunksSizes} maxInitialSize
117
+ * @property {string} automaticNameDelimiter
118
+ */
119
+
120
+ /**
121
+ * @typedef {object} CacheGroupsContext
122
+ * @property {ModuleGraph} moduleGraph
123
+ * @property {ChunkGraph} chunkGraph
124
+ */
125
+
126
+ /** @typedef {(module: Module) => OptimizationSplitChunksCacheGroup | OptimizationSplitChunksCacheGroup[] | void} RawGetCacheGroups */
127
+
128
+ /**
129
+ * @callback GetCacheGroups
130
+ * @param {Module} module
131
+ * @param {CacheGroupsContext} context
132
+ * @returns {CacheGroupSource[] | null}
133
+ */
134
+
135
+ /**
136
+ * @callback GetNameFn
137
+ * @param {Module} module
138
+ * @param {Chunk[]} chunks
139
+ * @param {string} key
140
+ * @returns {string | undefined}
141
+ */
142
+
143
+ /**
144
+ * @typedef {object} SplitChunksOptions
145
+ * @property {ChunkFilterFn} chunksFilter
146
+ * @property {DefaultSizeTypes} defaultSizeTypes
147
+ * @property {SplitChunksSizes} minSize
148
+ * @property {SplitChunksSizes} minSizeReduction
149
+ * @property {SplitChunksSizes} minRemainingSize
150
+ * @property {SplitChunksSizes} enforceSizeThreshold
151
+ * @property {SplitChunksSizes} maxInitialSize
152
+ * @property {SplitChunksSizes} maxAsyncSize
153
+ * @property {CountOfChunk} minChunks
154
+ * @property {CountOfRequest} maxAsyncRequests
155
+ * @property {CountOfRequest} maxInitialRequests
156
+ * @property {boolean} hidePathInfo
157
+ * @property {TemplatePath=} filename
158
+ * @property {string} automaticNameDelimiter
159
+ * @property {GetCacheGroups} getCacheGroups
160
+ * @property {GetNameFn} getName
161
+ * @property {boolean} usedExports
162
+ * @property {FallbackCacheGroup} fallbackCacheGroup
163
+ */
164
+
165
+ /** @typedef {Set<Chunk>} ChunkSet */
166
+
167
+ /**
168
+ * @typedef {object} ChunksInfoItem
169
+ * @property {SortableSet<Module>} modules
170
+ * @property {CacheGroup} cacheGroup
171
+ * @property {number} cacheGroupIndex
172
+ * @property {string=} name
173
+ * @property {SplitChunksSizes} sizes
174
+ * @property {ChunkSet} chunks
175
+ * @property {ChunkSet} reusableChunks
176
+ * @property {Set<bigint | Chunk>} chunksKeys
177
+ */
178
+
179
+ /** @type {GetNameFn} */
180
+ const defaultGetName = () => undefined;
181
+
182
+ const deterministicGroupingForModules =
183
+ /** @type {(options: DeterministicGroupingOptionsForModule) => DeterministicGroupingGroupedItemsForModule[]} */
184
+ (deterministicGrouping);
185
+
186
+ /** @type {WeakMap<Module, string>} */
187
+ const getKeyCache = new WeakMap();
188
+
189
+ /**
190
+ * @param {string} name a filename to hash
191
+ * @param {OutputOptions} outputOptions hash function used
192
+ * @returns {string} hashed filename
193
+ */
194
+ const hashFilename = (name, outputOptions) => {
195
+ const digest =
196
+ /** @type {string} */
197
+ (
198
+ createHash(outputOptions.hashFunction)
199
+ .update(name)
200
+ .digest(outputOptions.hashDigest)
201
+ );
202
+ return digest.slice(0, 8);
203
+ };
204
+
205
+ /**
206
+ * @param {Chunk} chunk the chunk
207
+ * @returns {CountOfRequest} the number of requests
208
+ */
209
+ const getRequests = (chunk) => {
210
+ let requests = 0;
211
+ for (const chunkGroup of chunk.groupsIterable) {
212
+ requests = Math.max(requests, chunkGroup.chunks.length);
213
+ }
214
+ return requests;
215
+ };
216
+
217
+ /**
218
+ * @template {object} T
219
+ * @template {object} R
220
+ * @param {T} obj obj an object
221
+ * @param {(obj: T[keyof T], key: keyof T) => T[keyof T]} fn fn
222
+ * @returns {T} result
223
+ */
224
+ const mapObject = (obj, fn) => {
225
+ /** @type {T} */
226
+ const newObj = Object.create(null);
227
+ for (const key of Object.keys(obj)) {
228
+ newObj[/** @type {keyof T} */ (key)] = fn(
229
+ obj[/** @type {keyof T} */ (key)],
230
+ /** @type {keyof T} */
231
+ (key)
232
+ );
233
+ }
234
+ return newObj;
235
+ };
236
+
237
+ /**
238
+ * @template T
239
+ * @param {Set<T>} a set
240
+ * @param {Set<T>} b other set
241
+ * @returns {boolean} true if at least one item of a is in b
242
+ */
243
+ const isOverlap = (a, b) => {
244
+ for (const item of a) {
245
+ if (b.has(item)) return true;
246
+ }
247
+ return false;
248
+ };
249
+
250
+ const compareModuleIterables = compareIterables(compareModulesByIdentifier);
251
+
252
+ /**
253
+ * @param {ChunksInfoItem} a item
254
+ * @param {ChunksInfoItem} b item
255
+ * @returns {number} compare result
256
+ */
257
+ const compareEntries = (a, b) => {
258
+ // 1. by priority
259
+ const diffPriority = a.cacheGroup.priority - b.cacheGroup.priority;
260
+ if (diffPriority) return diffPriority;
261
+ // 2. by number of chunks
262
+ const diffCount = a.chunks.size - b.chunks.size;
263
+ if (diffCount) return diffCount;
264
+ // 3. by size reduction
265
+ const aSizeReduce = totalSize(a.sizes) * (a.chunks.size - 1);
266
+ const bSizeReduce = totalSize(b.sizes) * (b.chunks.size - 1);
267
+ const diffSizeReduce = aSizeReduce - bSizeReduce;
268
+ if (diffSizeReduce) return diffSizeReduce;
269
+ // 4. by cache group index
270
+ const indexDiff = b.cacheGroupIndex - a.cacheGroupIndex;
271
+ if (indexDiff) return indexDiff;
272
+ // 5. by number of modules (to be able to compare by identifier)
273
+ const modulesA = a.modules;
274
+ const modulesB = b.modules;
275
+ const diff = modulesA.size - modulesB.size;
276
+ if (diff) return diff;
277
+ // 6. by module identifiers
278
+ modulesA.sort();
279
+ modulesB.sort();
280
+ return compareModuleIterables(modulesA, modulesB);
281
+ };
282
+
283
+ /**
284
+ * @param {Chunk} chunk the chunk
285
+ * @returns {boolean} true, if the chunk is an entry chunk
286
+ */
287
+ const INITIAL_CHUNK_FILTER = (chunk) => chunk.canBeInitial();
288
+ /**
289
+ * @param {Chunk} chunk the chunk
290
+ * @returns {boolean} true, if the chunk is an async chunk
291
+ */
292
+ const ASYNC_CHUNK_FILTER = (chunk) => !chunk.canBeInitial();
293
+ /**
294
+ * @param {Chunk} _chunk the chunk
295
+ * @returns {boolean} always true
296
+ */
297
+ const ALL_CHUNK_FILTER = (_chunk) => true;
298
+
299
+ /**
300
+ * @param {OptimizationSplitChunksSizes | undefined} value the sizes
301
+ * @param {DefaultSizeTypes} defaultSizeTypes the default size types
302
+ * @returns {SplitChunksSizes} normalized representation
303
+ */
304
+ const normalizeSizes = (value, defaultSizeTypes) => {
305
+ if (typeof value === "number") {
306
+ /** @type {SplitChunksSizes} */
307
+ const o = {};
308
+ for (const sizeType of defaultSizeTypes) o[sizeType] = value;
309
+ return o;
310
+ } else if (typeof value === "object" && value !== null) {
311
+ return { ...value };
312
+ }
313
+ return {};
314
+ };
315
+
316
+ /**
317
+ * @param {...(SplitChunksSizes | undefined)} sizes the sizes
318
+ * @returns {SplitChunksSizes} the merged sizes
319
+ */
320
+ const mergeSizes = (...sizes) => {
321
+ /** @type {SplitChunksSizes} */
322
+ let merged = {};
323
+ for (let i = sizes.length - 1; i >= 0; i--) {
324
+ merged = Object.assign(merged, sizes[i]);
325
+ }
326
+ return merged;
327
+ };
328
+
329
+ /**
330
+ * @param {SplitChunksSizes} sizes the sizes
331
+ * @returns {boolean} true, if there are sizes > 0
332
+ */
333
+ const hasNonZeroSizes = (sizes) => {
334
+ for (const key of /** @type {SourceType[]} */ (Object.keys(sizes))) {
335
+ if (sizes[key] > 0) return true;
336
+ }
337
+ return false;
338
+ };
339
+
340
+ /**
341
+ * @param {SplitChunksSizes} a first sizes
342
+ * @param {SplitChunksSizes} b second sizes
343
+ * @param {CombineSizeFunction} combine a function to combine sizes
344
+ * @returns {SplitChunksSizes} the combine sizes
345
+ */
346
+ const combineSizes = (a, b, combine) => {
347
+ const aKeys = /** @type {Set<SourceType>} */ (new Set(Object.keys(a)));
348
+ const bKeys = /** @type {Set<SourceType>} */ (new Set(Object.keys(b)));
349
+ /** @type {SplitChunksSizes} */
350
+ const result = {};
351
+ for (const key of aKeys) {
352
+ result[key] = bKeys.has(key) ? combine(a[key], b[key]) : a[key];
353
+ }
354
+ for (const key of bKeys) {
355
+ if (!aKeys.has(key)) {
356
+ result[key] = b[key];
357
+ }
358
+ }
359
+ return result;
360
+ };
361
+
362
+ /**
363
+ * @param {SplitChunksSizes} sizes the sizes
364
+ * @param {SplitChunksSizes} minSize the min sizes
365
+ * @returns {boolean} true if there are sizes and all existing sizes are at least `minSize`
366
+ */
367
+ const checkMinSize = (sizes, minSize) => {
368
+ for (const key of /** @type {SourceType[]} */ (Object.keys(minSize))) {
369
+ const size = sizes[key];
370
+ if (size === undefined || size === 0) continue;
371
+ if (size < minSize[key]) return false;
372
+ }
373
+ return true;
374
+ };
375
+
376
+ /**
377
+ * @param {SplitChunksSizes} sizes the sizes
378
+ * @param {SplitChunksSizes} minSizeReduction the min sizes
379
+ * @param {CountOfChunk} chunkCount number of chunks
380
+ * @returns {boolean} true if there are sizes and all existing sizes are at least `minSizeReduction`
381
+ */
382
+ const checkMinSizeReduction = (sizes, minSizeReduction, chunkCount) => {
383
+ for (const key of /** @type {SourceType[]} */ (
384
+ Object.keys(minSizeReduction)
385
+ )) {
386
+ const size = sizes[key];
387
+ if (size === undefined || size === 0) continue;
388
+ if (size * chunkCount < minSizeReduction[key]) return false;
389
+ }
390
+ return true;
391
+ };
392
+
393
+ /**
394
+ * @param {SplitChunksSizes} sizes the sizes
395
+ * @param {SplitChunksSizes} minSize the min sizes
396
+ * @returns {undefined | SourceTypes} list of size types that are below min size
397
+ */
398
+ const getViolatingMinSizes = (sizes, minSize) => {
399
+ /** @type {SourceTypes | undefined} */
400
+ let list;
401
+ for (const key of /** @type {SourceType[]} */ (Object.keys(minSize))) {
402
+ const size = sizes[key];
403
+ if (size === undefined || size === 0) continue;
404
+ if (size < minSize[key]) {
405
+ if (list === undefined) list = [key];
406
+ else list.push(key);
407
+ }
408
+ }
409
+ return list;
410
+ };
411
+
412
+ /**
413
+ * @param {SplitChunksSizes} sizes the sizes
414
+ * @returns {Size} the total size
415
+ */
416
+ const totalSize = (sizes) => {
417
+ let size = 0;
418
+ for (const key of /** @type {SourceType[]} */ (Object.keys(sizes))) {
419
+ size += sizes[key];
420
+ }
421
+ return size;
422
+ };
423
+
424
+ /**
425
+ * @param {OptimizationSplitChunksCacheGroup["name"]} name the chunk name
426
+ * @returns {GetNameFn | undefined} a function to get the name of the chunk
427
+ */
428
+ const normalizeName = (name) => {
429
+ if (typeof name === "string") {
430
+ return () => name;
431
+ }
432
+ if (typeof name === "function") {
433
+ return /** @type {GetNameFn} */ (name);
434
+ }
435
+ };
436
+
437
+ /**
438
+ * @param {OptimizationSplitChunksCacheGroup["chunks"]} chunks the chunk filter option
439
+ * @returns {ChunkFilterFn | undefined} the chunk filter function
440
+ */
441
+ const normalizeChunksFilter = (chunks) => {
442
+ if (chunks === "initial") {
443
+ return INITIAL_CHUNK_FILTER;
444
+ }
445
+ if (chunks === "async") {
446
+ return ASYNC_CHUNK_FILTER;
447
+ }
448
+ if (chunks === "all") {
449
+ return ALL_CHUNK_FILTER;
450
+ }
451
+ if (chunks instanceof RegExp) {
452
+ return (chunk) => (chunk.name ? chunks.test(chunk.name) : false);
453
+ }
454
+ if (typeof chunks === "function") {
455
+ return chunks;
456
+ }
457
+ };
458
+
459
+ /**
460
+ * @param {undefined | GetCacheGroups | Record<string, false | string | RegExp | RawGetCacheGroups | OptimizationSplitChunksCacheGroup>} cacheGroups the cache group options
461
+ * @param {DefaultSizeTypes} defaultSizeTypes the default size types
462
+ * @returns {GetCacheGroups} a function to get the cache groups
463
+ */
464
+ const normalizeCacheGroups = (cacheGroups, defaultSizeTypes) => {
465
+ if (typeof cacheGroups === "function") {
466
+ return cacheGroups;
467
+ }
468
+ if (typeof cacheGroups === "object" && cacheGroups !== null) {
469
+ /** @type {((module: Module, context: CacheGroupsContext, results: CacheGroupSource[]) => void)[]} */
470
+ const handlers = [];
471
+ for (const key of Object.keys(cacheGroups)) {
472
+ const option = cacheGroups[key];
473
+ if (option === false) {
474
+ continue;
475
+ }
476
+ if (typeof option === "string" || option instanceof RegExp) {
477
+ const source = createCacheGroupSource({}, key, defaultSizeTypes);
478
+ handlers.push((module, context, results) => {
479
+ if (checkTest(option, module, context)) {
480
+ results.push(source);
481
+ }
482
+ });
483
+ } else if (typeof option === "function") {
484
+ /** @type {WeakMap<OptimizationSplitChunksCacheGroup, CacheGroupSource>} */
485
+ const cache = new WeakMap();
486
+ handlers.push((module, context, results) => {
487
+ const result = option(module);
488
+ if (result) {
489
+ const groups = Array.isArray(result) ? result : [result];
490
+ for (const group of groups) {
491
+ const cachedSource = cache.get(group);
492
+ if (cachedSource !== undefined) {
493
+ results.push(cachedSource);
494
+ } else {
495
+ const source = createCacheGroupSource(
496
+ group,
497
+ key,
498
+ defaultSizeTypes
499
+ );
500
+ cache.set(group, source);
501
+ results.push(source);
502
+ }
503
+ }
504
+ }
505
+ });
506
+ } else {
507
+ const source = createCacheGroupSource(option, key, defaultSizeTypes);
508
+ handlers.push((module, context, results) => {
509
+ if (
510
+ checkTest(option.test, module, context) &&
511
+ checkModuleType(option.type, module) &&
512
+ checkModuleLayer(option.layer, module)
513
+ ) {
514
+ results.push(source);
515
+ }
516
+ });
517
+ }
518
+ }
519
+ /**
520
+ * @param {Module} module the current module
521
+ * @param {CacheGroupsContext} context the current context
522
+ * @returns {CacheGroupSource[]} the matching cache groups
523
+ */
524
+ const fn = (module, context) => {
525
+ /** @type {CacheGroupSource[]} */
526
+ const results = [];
527
+ for (const fn of handlers) {
528
+ fn(module, context, results);
529
+ }
530
+ return results;
531
+ };
532
+ return fn;
533
+ }
534
+ return () => null;
535
+ };
536
+
537
+ /** @typedef {(module: Module, context: CacheGroupsContext) => boolean} CheckTestFn */
538
+
539
+ /**
540
+ * @param {OptimizationSplitChunksCacheGroup["test"]} test test option
541
+ * @param {Module} module the module
542
+ * @param {CacheGroupsContext} context context object
543
+ * @returns {boolean} true, if the module should be selected
544
+ */
545
+ const checkTest = (test, module, context) => {
546
+ if (test === undefined) return true;
547
+ if (typeof test === "function") {
548
+ return test(module, context);
549
+ }
550
+ if (typeof test === "boolean") return test;
551
+ if (typeof test === "string") {
552
+ const name = module.nameForCondition();
553
+ return name ? name.startsWith(test) : false;
554
+ }
555
+ if (test instanceof RegExp) {
556
+ const name = module.nameForCondition();
557
+ return name ? test.test(name) : false;
558
+ }
559
+ return false;
560
+ };
561
+
562
+ /** @typedef {(type: string) => boolean} CheckModuleTypeFn */
563
+
564
+ /**
565
+ * @param {OptimizationSplitChunksCacheGroup["type"]} test type option
566
+ * @param {Module} module the module
567
+ * @returns {boolean} true, if the module should be selected
568
+ */
569
+ const checkModuleType = (test, module) => {
570
+ if (test === undefined) return true;
571
+ if (typeof test === "function") {
572
+ return test(module.type);
573
+ }
574
+ if (typeof test === "string") {
575
+ const type = module.type;
576
+ return test === type;
577
+ }
578
+ if (test instanceof RegExp) {
579
+ const type = module.type;
580
+ return test.test(type);
581
+ }
582
+ return false;
583
+ };
584
+
585
+ /** @typedef {(layer: string | null) => boolean} CheckModuleLayerFn */
586
+
587
+ /**
588
+ * @param {OptimizationSplitChunksCacheGroup["layer"]} test type option
589
+ * @param {Module} module the module
590
+ * @returns {boolean} true, if the module should be selected
591
+ */
592
+ const checkModuleLayer = (test, module) => {
593
+ if (test === undefined) return true;
594
+ if (typeof test === "function") {
595
+ return test(module.layer);
596
+ }
597
+ if (typeof test === "string") {
598
+ const layer = module.layer;
599
+ return test === "" ? !layer : layer ? layer.startsWith(test) : false;
600
+ }
601
+ if (test instanceof RegExp) {
602
+ const layer = module.layer;
603
+ return layer ? test.test(layer) : false;
604
+ }
605
+ return false;
606
+ };
607
+
608
+ /**
609
+ * @param {OptimizationSplitChunksCacheGroup} options the group options
610
+ * @param {string} key key of cache group
611
+ * @param {DefaultSizeTypes} defaultSizeTypes the default size types
612
+ * @returns {CacheGroupSource} the normalized cached group
613
+ */
614
+ const createCacheGroupSource = (options, key, defaultSizeTypes) => {
615
+ const minSize = normalizeSizes(options.minSize, defaultSizeTypes);
616
+ const minSizeReduction = normalizeSizes(
617
+ options.minSizeReduction,
618
+ defaultSizeTypes
619
+ );
620
+ const maxSize = normalizeSizes(options.maxSize, defaultSizeTypes);
621
+ return {
622
+ key,
623
+ priority: options.priority,
624
+ getName: normalizeName(options.name),
625
+ chunksFilter: normalizeChunksFilter(options.chunks),
626
+ enforce: options.enforce,
627
+ minSize,
628
+ minSizeReduction,
629
+ minRemainingSize: mergeSizes(
630
+ normalizeSizes(options.minRemainingSize, defaultSizeTypes),
631
+ minSize
632
+ ),
633
+ enforceSizeThreshold: normalizeSizes(
634
+ options.enforceSizeThreshold,
635
+ defaultSizeTypes
636
+ ),
637
+ maxAsyncSize: mergeSizes(
638
+ normalizeSizes(options.maxAsyncSize, defaultSizeTypes),
639
+ maxSize
640
+ ),
641
+ maxInitialSize: mergeSizes(
642
+ normalizeSizes(options.maxInitialSize, defaultSizeTypes),
643
+ maxSize
644
+ ),
645
+ minChunks: options.minChunks,
646
+ maxAsyncRequests: options.maxAsyncRequests,
647
+ maxInitialRequests: options.maxInitialRequests,
648
+ filename: options.filename,
649
+ idHint: options.idHint,
650
+ automaticNameDelimiter: options.automaticNameDelimiter,
651
+ reuseExistingChunk: options.reuseExistingChunk,
652
+ usedExports: options.usedExports
653
+ };
654
+ };
655
+
656
+ const PLUGIN_NAME = "SplitChunksPlugin";
657
+
658
+ module.exports = class SplitChunksPlugin {
659
+ /**
660
+ * @param {OptimizationSplitChunksOptions=} options plugin options
661
+ */
662
+ constructor(options = {}) {
663
+ const defaultSizeTypes = options.defaultSizeTypes || [
664
+ "javascript",
665
+ "unknown"
666
+ ];
667
+ const fallbackCacheGroup = options.fallbackCacheGroup || {};
668
+ const minSize = normalizeSizes(options.minSize, defaultSizeTypes);
669
+ const minSizeReduction = normalizeSizes(
670
+ options.minSizeReduction,
671
+ defaultSizeTypes
672
+ );
673
+ const maxSize = normalizeSizes(options.maxSize, defaultSizeTypes);
674
+
675
+ /** @type {SplitChunksOptions} */
676
+ this.options = {
677
+ chunksFilter:
678
+ /** @type {ChunkFilterFn} */
679
+ (normalizeChunksFilter(options.chunks || "all")),
680
+ defaultSizeTypes,
681
+ minSize,
682
+ minSizeReduction,
683
+ minRemainingSize: mergeSizes(
684
+ normalizeSizes(options.minRemainingSize, defaultSizeTypes),
685
+ minSize
686
+ ),
687
+ enforceSizeThreshold: normalizeSizes(
688
+ options.enforceSizeThreshold,
689
+ defaultSizeTypes
690
+ ),
691
+ maxAsyncSize: mergeSizes(
692
+ normalizeSizes(options.maxAsyncSize, defaultSizeTypes),
693
+ maxSize
694
+ ),
695
+ maxInitialSize: mergeSizes(
696
+ normalizeSizes(options.maxInitialSize, defaultSizeTypes),
697
+ maxSize
698
+ ),
699
+ minChunks: options.minChunks || 1,
700
+ maxAsyncRequests: options.maxAsyncRequests || 1,
701
+ maxInitialRequests: options.maxInitialRequests || 1,
702
+ hidePathInfo: options.hidePathInfo || false,
703
+ filename: options.filename || undefined,
704
+ getCacheGroups: normalizeCacheGroups(
705
+ options.cacheGroups,
706
+ defaultSizeTypes
707
+ ),
708
+ getName: options.name
709
+ ? /** @type {GetNameFn} */ (normalizeName(options.name))
710
+ : defaultGetName,
711
+ automaticNameDelimiter: options.automaticNameDelimiter || "-",
712
+ usedExports: options.usedExports || false,
713
+ fallbackCacheGroup: {
714
+ chunksFilter:
715
+ /** @type {ChunkFilterFn} */
716
+ (
717
+ normalizeChunksFilter(
718
+ fallbackCacheGroup.chunks || options.chunks || "all"
719
+ )
720
+ ),
721
+ minSize: mergeSizes(
722
+ normalizeSizes(fallbackCacheGroup.minSize, defaultSizeTypes),
723
+ minSize
724
+ ),
725
+ maxAsyncSize: mergeSizes(
726
+ normalizeSizes(fallbackCacheGroup.maxAsyncSize, defaultSizeTypes),
727
+ normalizeSizes(fallbackCacheGroup.maxSize, defaultSizeTypes),
728
+ normalizeSizes(options.maxAsyncSize, defaultSizeTypes),
729
+ normalizeSizes(options.maxSize, defaultSizeTypes)
730
+ ),
731
+ maxInitialSize: mergeSizes(
732
+ normalizeSizes(fallbackCacheGroup.maxInitialSize, defaultSizeTypes),
733
+ normalizeSizes(fallbackCacheGroup.maxSize, defaultSizeTypes),
734
+ normalizeSizes(options.maxInitialSize, defaultSizeTypes),
735
+ normalizeSizes(options.maxSize, defaultSizeTypes)
736
+ ),
737
+ automaticNameDelimiter:
738
+ fallbackCacheGroup.automaticNameDelimiter ||
739
+ options.automaticNameDelimiter ||
740
+ "~"
741
+ }
742
+ };
743
+
744
+ /** @type {WeakMap<CacheGroupSource, CacheGroup>} */
745
+ this._cacheGroupCache = new WeakMap();
746
+ }
747
+
748
+ /**
749
+ * @param {CacheGroupSource} cacheGroupSource source
750
+ * @returns {CacheGroup} the cache group (cached)
751
+ */
752
+ _getCacheGroup(cacheGroupSource) {
753
+ const cacheEntry = this._cacheGroupCache.get(cacheGroupSource);
754
+ if (cacheEntry !== undefined) return cacheEntry;
755
+ const minSize = mergeSizes(
756
+ cacheGroupSource.minSize,
757
+ cacheGroupSource.enforce ? undefined : this.options.minSize
758
+ );
759
+ const minSizeReduction = mergeSizes(
760
+ cacheGroupSource.minSizeReduction,
761
+ cacheGroupSource.enforce ? undefined : this.options.minSizeReduction
762
+ );
763
+ const minRemainingSize = mergeSizes(
764
+ cacheGroupSource.minRemainingSize,
765
+ cacheGroupSource.enforce ? undefined : this.options.minRemainingSize
766
+ );
767
+ const enforceSizeThreshold = mergeSizes(
768
+ cacheGroupSource.enforceSizeThreshold,
769
+ cacheGroupSource.enforce ? undefined : this.options.enforceSizeThreshold
770
+ );
771
+ /** @type {CacheGroup} */
772
+ const cacheGroup = {
773
+ key: cacheGroupSource.key,
774
+ priority: cacheGroupSource.priority || 0,
775
+ chunksFilter: cacheGroupSource.chunksFilter || this.options.chunksFilter,
776
+ minSize,
777
+ minSizeReduction,
778
+ minRemainingSize,
779
+ enforceSizeThreshold,
780
+ maxAsyncSize: mergeSizes(
781
+ cacheGroupSource.maxAsyncSize,
782
+ cacheGroupSource.enforce ? undefined : this.options.maxAsyncSize
783
+ ),
784
+ maxInitialSize: mergeSizes(
785
+ cacheGroupSource.maxInitialSize,
786
+ cacheGroupSource.enforce ? undefined : this.options.maxInitialSize
787
+ ),
788
+ minChunks:
789
+ cacheGroupSource.minChunks !== undefined
790
+ ? cacheGroupSource.minChunks
791
+ : cacheGroupSource.enforce
792
+ ? 1
793
+ : this.options.minChunks,
794
+ maxAsyncRequests:
795
+ cacheGroupSource.maxAsyncRequests !== undefined
796
+ ? cacheGroupSource.maxAsyncRequests
797
+ : cacheGroupSource.enforce
798
+ ? Infinity
799
+ : this.options.maxAsyncRequests,
800
+ maxInitialRequests:
801
+ cacheGroupSource.maxInitialRequests !== undefined
802
+ ? cacheGroupSource.maxInitialRequests
803
+ : cacheGroupSource.enforce
804
+ ? Infinity
805
+ : this.options.maxInitialRequests,
806
+ getName:
807
+ cacheGroupSource.getName !== undefined
808
+ ? cacheGroupSource.getName
809
+ : this.options.getName,
810
+ usedExports:
811
+ cacheGroupSource.usedExports !== undefined
812
+ ? cacheGroupSource.usedExports
813
+ : this.options.usedExports,
814
+ filename:
815
+ cacheGroupSource.filename !== undefined
816
+ ? cacheGroupSource.filename
817
+ : this.options.filename,
818
+ automaticNameDelimiter:
819
+ cacheGroupSource.automaticNameDelimiter !== undefined
820
+ ? cacheGroupSource.automaticNameDelimiter
821
+ : this.options.automaticNameDelimiter,
822
+ idHint:
823
+ cacheGroupSource.idHint !== undefined
824
+ ? cacheGroupSource.idHint
825
+ : cacheGroupSource.key,
826
+ reuseExistingChunk: cacheGroupSource.reuseExistingChunk || false,
827
+ _validateSize: hasNonZeroSizes(minSize),
828
+ _validateRemainingSize: hasNonZeroSizes(minRemainingSize),
829
+ _minSizeForMaxSize: mergeSizes(
830
+ cacheGroupSource.minSize,
831
+ this.options.minSize
832
+ ),
833
+ _conditionalEnforce: hasNonZeroSizes(enforceSizeThreshold)
834
+ };
835
+ this._cacheGroupCache.set(cacheGroupSource, cacheGroup);
836
+ return cacheGroup;
837
+ }
838
+
839
+ /**
840
+ * Apply the plugin
841
+ * @param {Compiler} compiler the compiler instance
842
+ * @returns {void}
843
+ */
844
+ apply(compiler) {
845
+ const cachedMakePathsRelative = makePathsRelative.bindContextCache(
846
+ compiler.context,
847
+ compiler.root
848
+ );
849
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
850
+ const logger = compilation.getLogger(`webpack.${PLUGIN_NAME}`);
851
+ let alreadyOptimized = false;
852
+ compilation.hooks.unseal.tap(PLUGIN_NAME, () => {
853
+ alreadyOptimized = false;
854
+ });
855
+ compilation.hooks.optimizeChunks.tap(
856
+ {
857
+ name: PLUGIN_NAME,
858
+ stage: STAGE_ADVANCED
859
+ },
860
+ (chunks) => {
861
+ if (alreadyOptimized) return;
862
+ alreadyOptimized = true;
863
+ logger.time("prepare");
864
+ const chunkGraph = compilation.chunkGraph;
865
+ const moduleGraph = compilation.moduleGraph;
866
+ // Give each selected chunk an index (to create strings from chunks)
867
+ /** @type {Map<Chunk, bigint>} */
868
+ const chunkIndexMap = new Map();
869
+ const ZERO = BigInt("0");
870
+ const ONE = BigInt("1");
871
+ const START = ONE << BigInt("31");
872
+ let index = START;
873
+ for (const chunk of chunks) {
874
+ chunkIndexMap.set(
875
+ chunk,
876
+ index | BigInt((Math.random() * 0x7fffffff) | 0)
877
+ );
878
+ index <<= ONE;
879
+ }
880
+ /**
881
+ * @param {Iterable<Chunk, undefined, undefined>} chunks list of chunks
882
+ * @returns {bigint | Chunk} key of the chunks
883
+ */
884
+ const getKey = (chunks) => {
885
+ const iterator = chunks[Symbol.iterator]();
886
+ let result = iterator.next();
887
+ if (result.done) return ZERO;
888
+ const first = result.value;
889
+ result = iterator.next();
890
+ if (result.done) return first;
891
+ let key =
892
+ /** @type {bigint} */ (chunkIndexMap.get(first)) |
893
+ /** @type {bigint} */ (chunkIndexMap.get(result.value));
894
+ while (!(result = iterator.next()).done) {
895
+ const raw = chunkIndexMap.get(result.value);
896
+ key ^= /** @type {bigint} */ (raw);
897
+ }
898
+ return key;
899
+ };
900
+ /**
901
+ * @param {bigint | Chunk} key key of the chunks
902
+ * @returns {string} stringified key
903
+ */
904
+ const keyToString = (key) => {
905
+ if (typeof key === "bigint") return key.toString(16);
906
+ return /** @type {bigint} */ (chunkIndexMap.get(key)).toString(16);
907
+ };
908
+
909
+ const getChunkSetsInGraph = memoize(() => {
910
+ /** @type {Map<bigint, ChunkSet>} */
911
+ const chunkSetsInGraph = new Map();
912
+ /** @type {ChunkSet} */
913
+ const singleChunkSets = new Set();
914
+ for (const module of compilation.modules) {
915
+ const chunks = chunkGraph.getModuleChunksIterable(module);
916
+ const chunksKey = getKey(chunks);
917
+ if (typeof chunksKey === "bigint") {
918
+ if (!chunkSetsInGraph.has(chunksKey)) {
919
+ chunkSetsInGraph.set(chunksKey, new Set(chunks));
920
+ }
921
+ } else {
922
+ singleChunkSets.add(chunksKey);
923
+ }
924
+ }
925
+ return { chunkSetsInGraph, singleChunkSets };
926
+ });
927
+
928
+ /**
929
+ * @param {Module} module the module
930
+ * @returns {Iterable<Chunk[]>} groups of chunks with equal exports
931
+ */
932
+ const groupChunksByExports = (module) => {
933
+ const exportsInfo = moduleGraph.getExportsInfo(module);
934
+ /** @type {Map<string, Chunk[]>} */
935
+ const groupedByUsedExports = new Map();
936
+ for (const chunk of chunkGraph.getModuleChunksIterable(module)) {
937
+ const key = exportsInfo.getUsageKey(chunk.runtime);
938
+ const list = groupedByUsedExports.get(key);
939
+ if (list !== undefined) {
940
+ list.push(chunk);
941
+ } else {
942
+ groupedByUsedExports.set(key, [chunk]);
943
+ }
944
+ }
945
+ return groupedByUsedExports.values();
946
+ };
947
+
948
+ /** @type {Map<Module, Iterable<Chunk[]>>} */
949
+ const groupedByExportsMap = new Map();
950
+
951
+ /** @typedef {Map<bigint | Chunk, ChunkSet>} ChunkSetsInGraph */
952
+
953
+ const getExportsChunkSetsInGraph = memoize(() => {
954
+ /** @type {ChunkSetsInGraph} */
955
+ const chunkSetsInGraph = new Map();
956
+ /** @type {ChunkSet} */
957
+ const singleChunkSets = new Set();
958
+ for (const module of compilation.modules) {
959
+ const groupedChunks = [...groupChunksByExports(module)];
960
+ groupedByExportsMap.set(module, groupedChunks);
961
+ for (const chunks of groupedChunks) {
962
+ if (chunks.length === 1) {
963
+ singleChunkSets.add(chunks[0]);
964
+ } else {
965
+ const chunksKey = getKey(chunks);
966
+ if (!chunkSetsInGraph.has(chunksKey)) {
967
+ chunkSetsInGraph.set(chunksKey, new Set(chunks));
968
+ }
969
+ }
970
+ }
971
+ }
972
+ return { chunkSetsInGraph, singleChunkSets };
973
+ });
974
+
975
+ /** @typedef {Map<CountOfChunk, ChunkSet[]>} ChunkSetsByCount */
976
+
977
+ // group these set of chunks by count
978
+ // to allow to check less sets via isSubset
979
+ // (only smaller sets can be subset)
980
+ /**
981
+ * @param {IterableIterator<ChunkSet>} chunkSets set of sets of chunks
982
+ * @returns {ChunkSetsByCount} map of sets of chunks by count
983
+ */
984
+ const groupChunkSetsByCount = (chunkSets) => {
985
+ /** @type {ChunkSetsByCount} */
986
+ const chunkSetsByCount = new Map();
987
+ for (const chunksSet of chunkSets) {
988
+ const count = chunksSet.size;
989
+ let array = chunkSetsByCount.get(count);
990
+ if (array === undefined) {
991
+ array = [];
992
+ chunkSetsByCount.set(count, array);
993
+ }
994
+ array.push(chunksSet);
995
+ }
996
+ return chunkSetsByCount;
997
+ };
998
+ const getChunkSetsByCount = memoize(() =>
999
+ groupChunkSetsByCount(
1000
+ getChunkSetsInGraph().chunkSetsInGraph.values()
1001
+ )
1002
+ );
1003
+ const getExportsChunkSetsByCount = memoize(() =>
1004
+ groupChunkSetsByCount(
1005
+ getExportsChunkSetsInGraph().chunkSetsInGraph.values()
1006
+ )
1007
+ );
1008
+
1009
+ /** @typedef {(ChunkSet | Chunk)[]} Combinations */
1010
+
1011
+ // Create a list of possible combinations
1012
+ /**
1013
+ * @param {ChunkSetsInGraph} chunkSets chunk sets
1014
+ * @param {ChunkSet} singleChunkSets single chunks sets
1015
+ * @param {ChunkSetsByCount} chunkSetsByCount chunk sets by count
1016
+ * @returns {(key: bigint | Chunk) => Combinations} combinations
1017
+ */
1018
+ const createGetCombinations = (
1019
+ chunkSets,
1020
+ singleChunkSets,
1021
+ chunkSetsByCount
1022
+ ) => {
1023
+ /** @type {Map<bigint | Chunk, Combinations>} */
1024
+ const combinationsCache = new Map();
1025
+
1026
+ return (key) => {
1027
+ const cacheEntry = combinationsCache.get(key);
1028
+ if (cacheEntry !== undefined) return cacheEntry;
1029
+ if (key instanceof Chunk) {
1030
+ const result = [key];
1031
+ combinationsCache.set(key, result);
1032
+ return result;
1033
+ }
1034
+ const chunksSet =
1035
+ /** @type {ChunkSet} */
1036
+ (chunkSets.get(key));
1037
+ /** @type {Combinations} */
1038
+ const array = [chunksSet];
1039
+ for (const [count, setArray] of chunkSetsByCount) {
1040
+ // "equal" is not needed because they would have been merge in the first step
1041
+ if (count < chunksSet.size) {
1042
+ for (const set of setArray) {
1043
+ if (isSubset(chunksSet, set)) {
1044
+ array.push(set);
1045
+ }
1046
+ }
1047
+ }
1048
+ }
1049
+ for (const chunk of singleChunkSets) {
1050
+ if (chunksSet.has(chunk)) {
1051
+ array.push(chunk);
1052
+ }
1053
+ }
1054
+ combinationsCache.set(key, array);
1055
+ return array;
1056
+ };
1057
+ };
1058
+
1059
+ const getCombinationsFactory = memoize(() => {
1060
+ const { chunkSetsInGraph, singleChunkSets } = getChunkSetsInGraph();
1061
+ return createGetCombinations(
1062
+ chunkSetsInGraph,
1063
+ singleChunkSets,
1064
+ getChunkSetsByCount()
1065
+ );
1066
+ });
1067
+
1068
+ /**
1069
+ * @param {bigint | Chunk} key key
1070
+ * @returns {Combinations} combinations by key
1071
+ */
1072
+ const getCombinations = (key) => getCombinationsFactory()(key);
1073
+
1074
+ const getExportsCombinationsFactory = memoize(() => {
1075
+ const { chunkSetsInGraph, singleChunkSets } =
1076
+ getExportsChunkSetsInGraph();
1077
+ return createGetCombinations(
1078
+ chunkSetsInGraph,
1079
+ singleChunkSets,
1080
+ getExportsChunkSetsByCount()
1081
+ );
1082
+ });
1083
+ /**
1084
+ * @param {bigint | Chunk} key key
1085
+ * @returns {Combinations} exports combinations by key
1086
+ */
1087
+ const getExportsCombinations = (key) =>
1088
+ getExportsCombinationsFactory()(key);
1089
+
1090
+ /**
1091
+ * @typedef {object} SelectedChunksResult
1092
+ * @property {Chunk[]} chunks the list of chunks
1093
+ * @property {bigint | Chunk} key a key of the list
1094
+ */
1095
+
1096
+ /** @typedef {WeakMap<ChunkFilterFn, SelectedChunksResult>} ChunkMap */
1097
+ /** @type {WeakMap<ChunkSet | Chunk, ChunkMap>} */
1098
+ const selectedChunksCacheByChunksSet = new WeakMap();
1099
+
1100
+ /**
1101
+ * get list and key by applying the filter function to the list
1102
+ * It is cached for performance reasons
1103
+ * @param {ChunkSet | Chunk} chunks list of chunks
1104
+ * @param {ChunkFilterFn} chunkFilter filter function for chunks
1105
+ * @returns {SelectedChunksResult} list and key
1106
+ */
1107
+ const getSelectedChunks = (chunks, chunkFilter) => {
1108
+ let entry = selectedChunksCacheByChunksSet.get(chunks);
1109
+ if (entry === undefined) {
1110
+ /** @type {ChunkMap} */
1111
+ entry = new WeakMap();
1112
+ selectedChunksCacheByChunksSet.set(chunks, entry);
1113
+ }
1114
+ let entry2 =
1115
+ /** @type {SelectedChunksResult} */
1116
+ (entry.get(chunkFilter));
1117
+ if (entry2 === undefined) {
1118
+ /** @type {Chunk[]} */
1119
+ const selectedChunks = [];
1120
+ if (chunks instanceof Chunk) {
1121
+ if (chunkFilter(chunks)) selectedChunks.push(chunks);
1122
+ } else {
1123
+ for (const chunk of chunks) {
1124
+ if (chunkFilter(chunk)) selectedChunks.push(chunk);
1125
+ }
1126
+ }
1127
+ entry2 = {
1128
+ chunks: selectedChunks,
1129
+ key: getKey(selectedChunks)
1130
+ };
1131
+ entry.set(chunkFilter, entry2);
1132
+ }
1133
+ return entry2;
1134
+ };
1135
+
1136
+ /** @type {Map<string, boolean>} */
1137
+ const alreadyValidatedParents = new Map();
1138
+ /** @type {Set<string>} */
1139
+ const alreadyReportedErrors = new Set();
1140
+
1141
+ // Map a list of chunks to a list of modules
1142
+ // For the key the chunk "index" is used, the value is a SortableSet of modules
1143
+ /** @type {Map<string, ChunksInfoItem>} */
1144
+ const chunksInfoMap = new Map();
1145
+
1146
+ /**
1147
+ * @param {CacheGroup} cacheGroup the current cache group
1148
+ * @param {number} cacheGroupIndex the index of the cache group of ordering
1149
+ * @param {Chunk[]} selectedChunks chunks selected for this module
1150
+ * @param {bigint | Chunk} selectedChunksKey a key of selectedChunks
1151
+ * @param {Module} module the current module
1152
+ * @returns {void}
1153
+ */
1154
+ const addModuleToChunksInfoMap = (
1155
+ cacheGroup,
1156
+ cacheGroupIndex,
1157
+ selectedChunks,
1158
+ selectedChunksKey,
1159
+ module
1160
+ ) => {
1161
+ // Break if minimum number of chunks is not reached
1162
+ if (selectedChunks.length < cacheGroup.minChunks) return;
1163
+ // Determine name for split chunk
1164
+
1165
+ const name =
1166
+ /** @type {GetNameFn} */
1167
+ (cacheGroup.getName)(module, selectedChunks, cacheGroup.key);
1168
+ // Check if the name is ok
1169
+ const existingChunk = name && compilation.namedChunks.get(name);
1170
+ if (existingChunk) {
1171
+ const parentValidationKey = `${name}|${
1172
+ typeof selectedChunksKey === "bigint"
1173
+ ? selectedChunksKey
1174
+ : selectedChunksKey.debugId
1175
+ }`;
1176
+ const valid = alreadyValidatedParents.get(parentValidationKey);
1177
+ if (valid === false) return;
1178
+ if (valid === undefined) {
1179
+ // Module can only be moved into the existing chunk if the existing chunk
1180
+ // is a parent of all selected chunks
1181
+ let isInAllParents = true;
1182
+ /** @type {Set<ChunkGroup>} */
1183
+ const queue = new Set();
1184
+ for (const chunk of selectedChunks) {
1185
+ for (const group of chunk.groupsIterable) {
1186
+ queue.add(group);
1187
+ }
1188
+ }
1189
+ for (const group of queue) {
1190
+ if (existingChunk.isInGroup(group)) continue;
1191
+ let hasParent = false;
1192
+ for (const parent of group.parentsIterable) {
1193
+ hasParent = true;
1194
+ queue.add(parent);
1195
+ }
1196
+ if (!hasParent) {
1197
+ isInAllParents = false;
1198
+ }
1199
+ }
1200
+ const valid = isInAllParents;
1201
+ alreadyValidatedParents.set(parentValidationKey, valid);
1202
+ if (!valid) {
1203
+ if (!alreadyReportedErrors.has(name)) {
1204
+ alreadyReportedErrors.add(name);
1205
+ compilation.errors.push(
1206
+ new WebpackError(
1207
+ `${PLUGIN_NAME}\n` +
1208
+ `Cache group "${cacheGroup.key}" conflicts with existing chunk.\n` +
1209
+ `Both have the same name "${name}" and existing chunk is not a parent of the selected modules.\n` +
1210
+ "Use a different name for the cache group or make sure that the existing chunk is a parent (e. g. via dependOn).\n" +
1211
+ 'HINT: You can omit "name" to automatically create a name.\n' +
1212
+ "BREAKING CHANGE: webpack < 5 used to allow to use an entrypoint as splitChunk. " +
1213
+ "This is no longer allowed when the entrypoint is not a parent of the selected modules.\n" +
1214
+ "Remove this entrypoint and add modules to cache group's 'test' instead. " +
1215
+ "If you need modules to be evaluated on startup, add them to the existing entrypoints (make them arrays). " +
1216
+ "See migration guide of more info."
1217
+ )
1218
+ );
1219
+ }
1220
+ return;
1221
+ }
1222
+ }
1223
+ }
1224
+ // Create key for maps
1225
+ // When it has a name we use the name as key
1226
+ // Otherwise we create the key from chunks and cache group key
1227
+ // This automatically merges equal names
1228
+ const key =
1229
+ cacheGroup.key +
1230
+ (name
1231
+ ? ` name:${name}`
1232
+ : ` chunks:${keyToString(selectedChunksKey)}`);
1233
+ // Add module to maps
1234
+ let info = chunksInfoMap.get(key);
1235
+ if (info === undefined) {
1236
+ chunksInfoMap.set(
1237
+ key,
1238
+ (info = {
1239
+ modules: new SortableSet(
1240
+ undefined,
1241
+ compareModulesByIdentifier
1242
+ ),
1243
+ cacheGroup,
1244
+ cacheGroupIndex,
1245
+ name,
1246
+ sizes: {},
1247
+ chunks: new Set(),
1248
+ reusableChunks: new Set(),
1249
+ chunksKeys: new Set()
1250
+ })
1251
+ );
1252
+ }
1253
+ const oldSize = info.modules.size;
1254
+ info.modules.add(module);
1255
+ if (info.modules.size !== oldSize) {
1256
+ for (const type of module.getSourceTypes()) {
1257
+ info.sizes[type] = (info.sizes[type] || 0) + module.size(type);
1258
+ }
1259
+ }
1260
+ const oldChunksKeysSize = info.chunksKeys.size;
1261
+ info.chunksKeys.add(selectedChunksKey);
1262
+ if (oldChunksKeysSize !== info.chunksKeys.size) {
1263
+ for (const chunk of selectedChunks) {
1264
+ info.chunks.add(chunk);
1265
+ }
1266
+ }
1267
+ };
1268
+
1269
+ const context = {
1270
+ moduleGraph,
1271
+ chunkGraph
1272
+ };
1273
+
1274
+ logger.timeEnd("prepare");
1275
+
1276
+ logger.time("modules");
1277
+
1278
+ // Walk through all modules
1279
+ for (const module of compilation.modules) {
1280
+ // Get cache group
1281
+ const cacheGroups = this.options.getCacheGroups(module, context);
1282
+ if (!Array.isArray(cacheGroups) || cacheGroups.length === 0) {
1283
+ continue;
1284
+ }
1285
+
1286
+ // Prepare some values (usedExports = false)
1287
+ const getCombs = memoize(() => {
1288
+ const chunks = chunkGraph.getModuleChunksIterable(module);
1289
+ const chunksKey = getKey(chunks);
1290
+ return getCombinations(chunksKey);
1291
+ });
1292
+
1293
+ // Prepare some values (usedExports = true)
1294
+ const getCombsByUsedExports = memoize(() => {
1295
+ // fill the groupedByExportsMap
1296
+ getExportsChunkSetsInGraph();
1297
+ /** @type {Set<ChunkSet | Chunk>} */
1298
+ const set = new Set();
1299
+ const groupedByUsedExports =
1300
+ /** @type {Iterable<Chunk[]>} */
1301
+ (groupedByExportsMap.get(module));
1302
+ for (const chunks of groupedByUsedExports) {
1303
+ const chunksKey = getKey(chunks);
1304
+ for (const comb of getExportsCombinations(chunksKey)) {
1305
+ set.add(comb);
1306
+ }
1307
+ }
1308
+ return set;
1309
+ });
1310
+
1311
+ let cacheGroupIndex = 0;
1312
+ for (const cacheGroupSource of cacheGroups) {
1313
+ const cacheGroup = this._getCacheGroup(cacheGroupSource);
1314
+
1315
+ const combs = cacheGroup.usedExports
1316
+ ? getCombsByUsedExports()
1317
+ : getCombs();
1318
+ // For all combination of chunk selection
1319
+ for (const chunkCombination of combs) {
1320
+ // Break if minimum number of chunks is not reached
1321
+ const count =
1322
+ chunkCombination instanceof Chunk ? 1 : chunkCombination.size;
1323
+ if (count < cacheGroup.minChunks) continue;
1324
+ // Select chunks by configuration
1325
+ const { chunks: selectedChunks, key: selectedChunksKey } =
1326
+ getSelectedChunks(
1327
+ chunkCombination,
1328
+ /** @type {ChunkFilterFn} */
1329
+ (cacheGroup.chunksFilter)
1330
+ );
1331
+
1332
+ addModuleToChunksInfoMap(
1333
+ cacheGroup,
1334
+ cacheGroupIndex,
1335
+ selectedChunks,
1336
+ selectedChunksKey,
1337
+ module
1338
+ );
1339
+ }
1340
+ cacheGroupIndex++;
1341
+ }
1342
+ }
1343
+
1344
+ logger.timeEnd("modules");
1345
+
1346
+ logger.time("queue");
1347
+
1348
+ /**
1349
+ * @param {ChunksInfoItem} info entry
1350
+ * @param {SourceTypes} sourceTypes source types to be removed
1351
+ */
1352
+ const removeModulesWithSourceType = (info, sourceTypes) => {
1353
+ for (const module of info.modules) {
1354
+ const types = module.getSourceTypes();
1355
+ if (sourceTypes.some((type) => types.has(type))) {
1356
+ info.modules.delete(module);
1357
+ for (const type of types) {
1358
+ info.sizes[type] -= module.size(type);
1359
+ }
1360
+ }
1361
+ }
1362
+ };
1363
+
1364
+ /**
1365
+ * @param {ChunksInfoItem} info entry
1366
+ * @returns {boolean} true, if entry become empty
1367
+ */
1368
+ const removeMinSizeViolatingModules = (info) => {
1369
+ if (!info.cacheGroup._validateSize) return false;
1370
+ const violatingSizes = getViolatingMinSizes(
1371
+ info.sizes,
1372
+ info.cacheGroup.minSize
1373
+ );
1374
+ if (violatingSizes === undefined) return false;
1375
+ removeModulesWithSourceType(info, violatingSizes);
1376
+ return info.modules.size === 0;
1377
+ };
1378
+
1379
+ // Filter items were size < minSize
1380
+ for (const [key, info] of chunksInfoMap) {
1381
+ if (removeMinSizeViolatingModules(info)) {
1382
+ chunksInfoMap.delete(key);
1383
+ } else if (
1384
+ !checkMinSizeReduction(
1385
+ info.sizes,
1386
+ info.cacheGroup.minSizeReduction,
1387
+ info.chunks.size
1388
+ )
1389
+ ) {
1390
+ chunksInfoMap.delete(key);
1391
+ }
1392
+ }
1393
+
1394
+ /**
1395
+ * @typedef {object} MaxSizeQueueItem
1396
+ * @property {SplitChunksSizes} minSize
1397
+ * @property {SplitChunksSizes} maxAsyncSize
1398
+ * @property {SplitChunksSizes} maxInitialSize
1399
+ * @property {string} automaticNameDelimiter
1400
+ * @property {string[]} keys
1401
+ */
1402
+
1403
+ /** @type {Map<Chunk, MaxSizeQueueItem>} */
1404
+ const maxSizeQueueMap = new Map();
1405
+
1406
+ while (chunksInfoMap.size > 0) {
1407
+ // Find best matching entry
1408
+ /** @type {undefined | string} */
1409
+ let bestEntryKey;
1410
+ /** @type {undefined | ChunksInfoItem} */
1411
+ let bestEntry;
1412
+ for (const pair of chunksInfoMap) {
1413
+ const key = pair[0];
1414
+ const info = pair[1];
1415
+ if (
1416
+ bestEntry === undefined ||
1417
+ compareEntries(bestEntry, info) < 0
1418
+ ) {
1419
+ bestEntry = info;
1420
+ bestEntryKey = key;
1421
+ }
1422
+ }
1423
+
1424
+ const item = /** @type {ChunksInfoItem} */ (bestEntry);
1425
+ chunksInfoMap.delete(/** @type {string} */ (bestEntryKey));
1426
+
1427
+ /** @type {ChunkName | undefined} */
1428
+ let chunkName = item.name;
1429
+ // Variable for the new chunk (lazy created)
1430
+ /** @type {Chunk | undefined} */
1431
+ let newChunk;
1432
+ // When no chunk name, check if we can reuse a chunk instead of creating a new one
1433
+ let isExistingChunk = false;
1434
+ let isReusedWithAllModules = false;
1435
+ if (chunkName) {
1436
+ const chunkByName = compilation.namedChunks.get(chunkName);
1437
+ if (chunkByName !== undefined) {
1438
+ newChunk = chunkByName;
1439
+ const oldSize = item.chunks.size;
1440
+ item.chunks.delete(newChunk);
1441
+ isExistingChunk = item.chunks.size !== oldSize;
1442
+ }
1443
+ } else if (item.cacheGroup.reuseExistingChunk) {
1444
+ outer: for (const chunk of item.chunks) {
1445
+ if (
1446
+ chunkGraph.getNumberOfChunkModules(chunk) !==
1447
+ item.modules.size
1448
+ ) {
1449
+ continue;
1450
+ }
1451
+ if (
1452
+ item.chunks.size > 1 &&
1453
+ chunkGraph.getNumberOfEntryModules(chunk) > 0
1454
+ ) {
1455
+ continue;
1456
+ }
1457
+ for (const module of item.modules) {
1458
+ if (!chunkGraph.isModuleInChunk(module, chunk)) {
1459
+ continue outer;
1460
+ }
1461
+ }
1462
+ if (!newChunk || !newChunk.name) {
1463
+ newChunk = chunk;
1464
+ } else if (
1465
+ chunk.name &&
1466
+ chunk.name.length < newChunk.name.length
1467
+ ) {
1468
+ newChunk = chunk;
1469
+ } else if (
1470
+ chunk.name &&
1471
+ chunk.name.length === newChunk.name.length &&
1472
+ chunk.name < newChunk.name
1473
+ ) {
1474
+ newChunk = chunk;
1475
+ }
1476
+ }
1477
+ if (newChunk) {
1478
+ item.chunks.delete(newChunk);
1479
+ chunkName = undefined;
1480
+ isExistingChunk = true;
1481
+ isReusedWithAllModules = true;
1482
+ }
1483
+ }
1484
+
1485
+ const enforced =
1486
+ item.cacheGroup._conditionalEnforce &&
1487
+ checkMinSize(item.sizes, item.cacheGroup.enforceSizeThreshold);
1488
+
1489
+ /** @type {Set<Chunk>} */
1490
+ const usedChunks = new Set(item.chunks);
1491
+
1492
+ // Check if maxRequests condition can be fulfilled
1493
+ if (
1494
+ !enforced &&
1495
+ (Number.isFinite(item.cacheGroup.maxInitialRequests) ||
1496
+ Number.isFinite(item.cacheGroup.maxAsyncRequests))
1497
+ ) {
1498
+ for (const chunk of usedChunks) {
1499
+ // respect max requests
1500
+ const maxRequests = chunk.isOnlyInitial()
1501
+ ? item.cacheGroup.maxInitialRequests
1502
+ : chunk.canBeInitial()
1503
+ ? Math.min(
1504
+ item.cacheGroup.maxInitialRequests,
1505
+ item.cacheGroup.maxAsyncRequests
1506
+ )
1507
+ : item.cacheGroup.maxAsyncRequests;
1508
+ if (
1509
+ Number.isFinite(maxRequests) &&
1510
+ getRequests(chunk) >= maxRequests
1511
+ ) {
1512
+ usedChunks.delete(chunk);
1513
+ }
1514
+ }
1515
+ }
1516
+
1517
+ outer: for (const chunk of usedChunks) {
1518
+ for (const module of item.modules) {
1519
+ if (chunkGraph.isModuleInChunk(module, chunk)) continue outer;
1520
+ }
1521
+ usedChunks.delete(chunk);
1522
+ }
1523
+
1524
+ // Were some (invalid) chunks removed from usedChunks?
1525
+ // => readd all modules to the queue, as things could have been changed
1526
+ if (usedChunks.size < item.chunks.size) {
1527
+ if (isExistingChunk) {
1528
+ usedChunks.add(/** @type {Chunk} */ (newChunk));
1529
+ }
1530
+ if (usedChunks.size >= item.cacheGroup.minChunks) {
1531
+ const chunksArr = [...usedChunks];
1532
+ for (const module of item.modules) {
1533
+ addModuleToChunksInfoMap(
1534
+ item.cacheGroup,
1535
+ item.cacheGroupIndex,
1536
+ chunksArr,
1537
+ getKey(usedChunks),
1538
+ module
1539
+ );
1540
+ }
1541
+ }
1542
+ continue;
1543
+ }
1544
+
1545
+ // Validate minRemainingSize constraint when a single chunk is left over
1546
+ if (
1547
+ !enforced &&
1548
+ item.cacheGroup._validateRemainingSize &&
1549
+ usedChunks.size === 1
1550
+ ) {
1551
+ const [chunk] = usedChunks;
1552
+ /** @type {SplitChunksSizes} */
1553
+ const chunkSizes = Object.create(null);
1554
+ for (const module of chunkGraph.getChunkModulesIterable(chunk)) {
1555
+ if (!item.modules.has(module)) {
1556
+ for (const type of module.getSourceTypes()) {
1557
+ chunkSizes[type] =
1558
+ (chunkSizes[type] || 0) + module.size(type);
1559
+ }
1560
+ }
1561
+ }
1562
+ const violatingSizes = getViolatingMinSizes(
1563
+ chunkSizes,
1564
+ item.cacheGroup.minRemainingSize
1565
+ );
1566
+ if (violatingSizes !== undefined) {
1567
+ const oldModulesSize = item.modules.size;
1568
+ removeModulesWithSourceType(item, violatingSizes);
1569
+ if (
1570
+ item.modules.size > 0 &&
1571
+ item.modules.size !== oldModulesSize
1572
+ ) {
1573
+ // queue this item again to be processed again
1574
+ // without violating modules
1575
+ chunksInfoMap.set(/** @type {string} */ (bestEntryKey), item);
1576
+ }
1577
+ continue;
1578
+ }
1579
+ }
1580
+
1581
+ // Create the new chunk if not reusing one
1582
+ if (newChunk === undefined) {
1583
+ newChunk = compilation.addChunk(chunkName);
1584
+ }
1585
+ // Walk through all chunks
1586
+ for (const chunk of usedChunks) {
1587
+ // Add graph connections for splitted chunk
1588
+ chunk.split(newChunk);
1589
+ }
1590
+
1591
+ // Add a note to the chunk
1592
+ newChunk.chunkReason =
1593
+ (newChunk.chunkReason ? `${newChunk.chunkReason}, ` : "") +
1594
+ (isReusedWithAllModules
1595
+ ? "reused as split chunk"
1596
+ : "split chunk");
1597
+ if (item.cacheGroup.key) {
1598
+ newChunk.chunkReason += ` (cache group: ${item.cacheGroup.key})`;
1599
+ }
1600
+ if (chunkName) {
1601
+ newChunk.chunkReason += ` (name: ${chunkName})`;
1602
+ }
1603
+ if (item.cacheGroup.filename) {
1604
+ newChunk.filenameTemplate = item.cacheGroup.filename;
1605
+ }
1606
+ if (item.cacheGroup.idHint) {
1607
+ newChunk.idNameHints.add(item.cacheGroup.idHint);
1608
+ }
1609
+ if (!isReusedWithAllModules) {
1610
+ // Add all modules to the new chunk
1611
+ for (const module of item.modules) {
1612
+ if (!module.chunkCondition(newChunk, compilation)) continue;
1613
+ // Add module to new chunk
1614
+ chunkGraph.connectChunkAndModule(newChunk, module);
1615
+ // Remove module from used chunks
1616
+ for (const chunk of usedChunks) {
1617
+ chunkGraph.disconnectChunkAndModule(chunk, module);
1618
+ }
1619
+ }
1620
+ } else {
1621
+ // Remove all modules from used chunks
1622
+ for (const module of item.modules) {
1623
+ for (const chunk of usedChunks) {
1624
+ chunkGraph.disconnectChunkAndModule(chunk, module);
1625
+ }
1626
+ }
1627
+ }
1628
+
1629
+ if (
1630
+ Object.keys(item.cacheGroup.maxAsyncSize).length > 0 ||
1631
+ Object.keys(item.cacheGroup.maxInitialSize).length > 0
1632
+ ) {
1633
+ const oldMaxSizeSettings = maxSizeQueueMap.get(newChunk);
1634
+ maxSizeQueueMap.set(newChunk, {
1635
+ minSize: oldMaxSizeSettings
1636
+ ? combineSizes(
1637
+ oldMaxSizeSettings.minSize,
1638
+ item.cacheGroup._minSizeForMaxSize,
1639
+ Math.max
1640
+ )
1641
+ : item.cacheGroup.minSize,
1642
+ maxAsyncSize: oldMaxSizeSettings
1643
+ ? combineSizes(
1644
+ oldMaxSizeSettings.maxAsyncSize,
1645
+ item.cacheGroup.maxAsyncSize,
1646
+ Math.min
1647
+ )
1648
+ : item.cacheGroup.maxAsyncSize,
1649
+ maxInitialSize: oldMaxSizeSettings
1650
+ ? combineSizes(
1651
+ oldMaxSizeSettings.maxInitialSize,
1652
+ item.cacheGroup.maxInitialSize,
1653
+ Math.min
1654
+ )
1655
+ : item.cacheGroup.maxInitialSize,
1656
+ automaticNameDelimiter: item.cacheGroup.automaticNameDelimiter,
1657
+ keys: oldMaxSizeSettings
1658
+ ? [...oldMaxSizeSettings.keys, item.cacheGroup.key]
1659
+ : [item.cacheGroup.key]
1660
+ });
1661
+ }
1662
+
1663
+ // remove all modules from other entries and update size
1664
+ for (const [key, info] of chunksInfoMap) {
1665
+ if (isOverlap(info.chunks, usedChunks)) {
1666
+ // update modules and total size
1667
+ // may remove it from the map when < minSize
1668
+ let updated = false;
1669
+ for (const module of item.modules) {
1670
+ if (info.modules.has(module)) {
1671
+ // remove module
1672
+ info.modules.delete(module);
1673
+ // update size
1674
+ for (const key of module.getSourceTypes()) {
1675
+ info.sizes[key] -= module.size(key);
1676
+ }
1677
+ updated = true;
1678
+ }
1679
+ }
1680
+ if (updated) {
1681
+ if (info.modules.size === 0) {
1682
+ chunksInfoMap.delete(key);
1683
+ continue;
1684
+ }
1685
+ if (
1686
+ removeMinSizeViolatingModules(info) ||
1687
+ !checkMinSizeReduction(
1688
+ info.sizes,
1689
+ info.cacheGroup.minSizeReduction,
1690
+ info.chunks.size
1691
+ )
1692
+ ) {
1693
+ chunksInfoMap.delete(key);
1694
+ continue;
1695
+ }
1696
+ }
1697
+ }
1698
+ }
1699
+ }
1700
+
1701
+ logger.timeEnd("queue");
1702
+
1703
+ logger.time("maxSize");
1704
+
1705
+ /** @type {Set<string>} */
1706
+ const incorrectMinMaxSizeSet = new Set();
1707
+
1708
+ const { outputOptions } = compilation;
1709
+
1710
+ // Make sure that maxSize is fulfilled
1711
+ const { fallbackCacheGroup } = this.options;
1712
+ for (const chunk of compilation.chunks) {
1713
+ const chunkConfig = maxSizeQueueMap.get(chunk);
1714
+ const {
1715
+ minSize,
1716
+ maxAsyncSize,
1717
+ maxInitialSize,
1718
+ automaticNameDelimiter
1719
+ } = chunkConfig || fallbackCacheGroup;
1720
+ if (!chunkConfig && !fallbackCacheGroup.chunksFilter(chunk)) {
1721
+ continue;
1722
+ }
1723
+ /** @type {SplitChunksSizes} */
1724
+ let maxSize;
1725
+ if (chunk.isOnlyInitial()) {
1726
+ maxSize = maxInitialSize;
1727
+ } else if (chunk.canBeInitial()) {
1728
+ maxSize = combineSizes(maxAsyncSize, maxInitialSize, Math.min);
1729
+ } else {
1730
+ maxSize = maxAsyncSize;
1731
+ }
1732
+ if (Object.keys(maxSize).length === 0) {
1733
+ continue;
1734
+ }
1735
+ for (const key of /** @type {SourceType[]} */ (
1736
+ Object.keys(maxSize)
1737
+ )) {
1738
+ const maxSizeValue = maxSize[key];
1739
+ const minSizeValue = minSize[key];
1740
+ if (
1741
+ typeof minSizeValue === "number" &&
1742
+ minSizeValue > maxSizeValue
1743
+ ) {
1744
+ const keys = chunkConfig && chunkConfig.keys;
1745
+ const warningKey = `${
1746
+ keys && keys.join()
1747
+ } ${minSizeValue} ${maxSizeValue}`;
1748
+ if (!incorrectMinMaxSizeSet.has(warningKey)) {
1749
+ incorrectMinMaxSizeSet.add(warningKey);
1750
+ compilation.warnings.push(
1751
+ new MinMaxSizeWarning(keys, minSizeValue, maxSizeValue)
1752
+ );
1753
+ }
1754
+ }
1755
+ }
1756
+ const results = deterministicGroupingForModules({
1757
+ minSize,
1758
+ maxSize: mapObject(maxSize, (value, key) => {
1759
+ const minSizeValue = minSize[key];
1760
+ return typeof minSizeValue === "number"
1761
+ ? Math.max(value, minSizeValue)
1762
+ : value;
1763
+ }),
1764
+ items: chunkGraph.getChunkModulesIterable(chunk),
1765
+ getKey(module) {
1766
+ const cache = getKeyCache.get(module);
1767
+ if (cache !== undefined) return cache;
1768
+ const ident = cachedMakePathsRelative(module.identifier());
1769
+ const nameForCondition =
1770
+ module.nameForCondition && module.nameForCondition();
1771
+ const name = nameForCondition
1772
+ ? cachedMakePathsRelative(nameForCondition)
1773
+ : ident.replace(/^.*!|\?[^?!]*$/g, "");
1774
+ const fullKey =
1775
+ name +
1776
+ automaticNameDelimiter +
1777
+ hashFilename(ident, outputOptions);
1778
+ const key = requestToId(fullKey);
1779
+ getKeyCache.set(module, key);
1780
+ return key;
1781
+ },
1782
+ getSize(module) {
1783
+ /** @type {Sizes} */
1784
+ const size = Object.create(null);
1785
+ for (const key of module.getSourceTypes()) {
1786
+ size[key] = module.size(key);
1787
+ }
1788
+ return size;
1789
+ }
1790
+ });
1791
+ if (results.length <= 1) {
1792
+ continue;
1793
+ }
1794
+ for (let i = 0; i < results.length; i++) {
1795
+ const group = results[i];
1796
+ const key = this.options.hidePathInfo
1797
+ ? hashFilename(group.key, outputOptions)
1798
+ : group.key;
1799
+ let name = chunk.name
1800
+ ? chunk.name + automaticNameDelimiter + key
1801
+ : null;
1802
+ if (name && name.length > 100) {
1803
+ name =
1804
+ name.slice(0, 100) +
1805
+ automaticNameDelimiter +
1806
+ hashFilename(name, outputOptions);
1807
+ }
1808
+ if (i !== results.length - 1) {
1809
+ const newPart = compilation.addChunk(name);
1810
+ chunk.split(newPart);
1811
+ newPart.chunkReason = chunk.chunkReason;
1812
+ if (chunk.filenameTemplate) {
1813
+ newPart.filenameTemplate = chunk.filenameTemplate;
1814
+ }
1815
+ // Add all modules to the new chunk
1816
+ for (const module of group.items) {
1817
+ if (!module.chunkCondition(newPart, compilation)) {
1818
+ continue;
1819
+ }
1820
+ // Add module to new chunk
1821
+ chunkGraph.connectChunkAndModule(newPart, module);
1822
+ // Remove module from used chunks
1823
+ chunkGraph.disconnectChunkAndModule(chunk, module);
1824
+ }
1825
+ } else {
1826
+ // change the chunk to be a part
1827
+ chunk.name = name;
1828
+ }
1829
+ }
1830
+ }
1831
+ logger.timeEnd("maxSize");
1832
+ }
1833
+ );
1834
+ });
1835
+ }
1836
+ };