webpack 5.99.9 → 5.100.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (306) hide show
  1. package/bin/webpack.js +8 -2
  2. package/hot/log.js +15 -15
  3. package/hot/poll.js +1 -0
  4. package/lib/APIPlugin.js +3 -3
  5. package/lib/AbstractMethodError.js +1 -0
  6. package/lib/AutomaticPrefetchPlugin.js +1 -0
  7. package/lib/BannerPlugin.js +1 -1
  8. package/lib/CaseSensitiveModulesWarning.js +4 -4
  9. package/lib/Chunk.js +6 -6
  10. package/lib/ChunkGraph.js +37 -31
  11. package/lib/ChunkGroup.js +4 -4
  12. package/lib/ChunkTemplate.js +1 -1
  13. package/lib/CleanPlugin.js +94 -17
  14. package/lib/CodeGenerationResults.js +1 -1
  15. package/lib/CompatibilityPlugin.js +5 -2
  16. package/lib/Compilation.js +67 -45
  17. package/lib/Compiler.js +46 -16
  18. package/lib/ConcatenationScope.js +15 -6
  19. package/lib/ConstPlugin.js +5 -3
  20. package/lib/ContextModule.js +16 -12
  21. package/lib/ContextModuleFactory.js +4 -3
  22. package/lib/ContextReplacementPlugin.js +4 -2
  23. package/lib/CssModule.js +2 -2
  24. package/lib/DefinePlugin.js +111 -3
  25. package/lib/DelegatedModuleFactoryPlugin.js +18 -18
  26. package/lib/Dependency.js +6 -1
  27. package/lib/DependencyTemplate.js +1 -0
  28. package/lib/DllEntryPlugin.js +3 -1
  29. package/lib/DllPlugin.js +4 -3
  30. package/lib/DllReferencePlugin.js +2 -2
  31. package/lib/DynamicEntryPlugin.js +1 -1
  32. package/lib/EntryOptionPlugin.js +5 -0
  33. package/lib/ErrorHelpers.js +4 -4
  34. package/lib/EvalDevToolModulePlugin.js +3 -3
  35. package/lib/EvalSourceMapDevToolPlugin.js +7 -7
  36. package/lib/ExportsInfo.js +48 -39
  37. package/lib/ExternalModule.js +15 -11
  38. package/lib/ExternalModuleFactoryPlugin.js +5 -2
  39. package/lib/FileSystemInfo.js +51 -36
  40. package/lib/FlagDependencyExportsPlugin.js +14 -7
  41. package/lib/FlagDependencyUsagePlugin.js +1 -1
  42. package/lib/Generator.js +14 -1
  43. package/lib/HookWebpackError.js +1 -0
  44. package/lib/HotModuleReplacementPlugin.js +77 -50
  45. package/lib/IgnorePlugin.js +1 -1
  46. package/lib/InvalidDependenciesModuleWarning.js +1 -1
  47. package/lib/JavascriptMetaInfoPlugin.js +0 -1
  48. package/lib/LibManifestPlugin.js +4 -2
  49. package/lib/LoaderOptionsPlugin.js +6 -4
  50. package/lib/MainTemplate.js +2 -2
  51. package/lib/Module.js +21 -6
  52. package/lib/ModuleFactory.js +1 -0
  53. package/lib/ModuleGraph.js +24 -2
  54. package/lib/ModuleGraphConnection.js +5 -5
  55. package/lib/ModuleInfoHeaderPlugin.js +2 -1
  56. package/lib/ModuleParseError.js +1 -0
  57. package/lib/ModuleSourceTypesConstants.js +12 -12
  58. package/lib/ModuleTemplate.js +1 -1
  59. package/lib/ModuleTypeConstants.js +21 -21
  60. package/lib/MultiCompiler.js +6 -6
  61. package/lib/NormalModule.js +31 -44
  62. package/lib/NormalModuleFactory.js +29 -19
  63. package/lib/NormalModuleReplacementPlugin.js +1 -1
  64. package/lib/NullFactory.js +1 -0
  65. package/lib/OptimizationStages.js +1 -1
  66. package/lib/Parser.js +1 -0
  67. package/lib/ProgressPlugin.js +12 -5
  68. package/lib/ProvidePlugin.js +5 -1
  69. package/lib/RecordIdsPlugin.js +3 -3
  70. package/lib/RuntimeGlobals.js +175 -155
  71. package/lib/RuntimeModule.js +1 -0
  72. package/lib/RuntimePlugin.js +33 -7
  73. package/lib/RuntimeTemplate.js +111 -11
  74. package/lib/SourceMapDevToolModuleOptionsPlugin.js +15 -25
  75. package/lib/SourceMapDevToolPlugin.js +19 -17
  76. package/lib/Template.js +2 -2
  77. package/lib/TemplatedPathPlugin.js +1 -1
  78. package/lib/WarnDeprecatedOptionPlugin.js +7 -8
  79. package/lib/WatchIgnorePlugin.js +4 -3
  80. package/lib/WebpackIsIncludedPlugin.js +2 -1
  81. package/lib/WebpackOptionsApply.js +115 -27
  82. package/lib/asset/AssetGenerator.js +15 -11
  83. package/lib/asset/AssetModulesPlugin.js +19 -17
  84. package/lib/asset/AssetSourceGenerator.js +4 -4
  85. package/lib/asset/RawDataUrlModule.js +4 -2
  86. package/lib/async-modules/AwaitDependenciesInitFragment.js +1 -1
  87. package/lib/buildChunkGraph.js +6 -3
  88. package/lib/cache/AddBuildDependenciesPlugin.js +5 -6
  89. package/lib/cache/IdleFileCachePlugin.js +7 -4
  90. package/lib/cache/MemoryCachePlugin.js +1 -0
  91. package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
  92. package/lib/cache/PackFileCacheStrategy.js +26 -20
  93. package/lib/cache/ResolverCachePlugin.js +16 -8
  94. package/lib/cli.js +15 -10
  95. package/lib/config/browserslistTargetHandler.js +3 -3
  96. package/lib/config/defaults.js +25 -17
  97. package/lib/config/normalization.js +2 -1
  98. package/lib/config/target.js +6 -5
  99. package/lib/container/ContainerPlugin.js +1 -1
  100. package/lib/container/ContainerReferencePlugin.js +1 -1
  101. package/lib/container/FallbackModule.js +2 -1
  102. package/lib/container/HoistContainerReferencesPlugin.js +1 -1
  103. package/lib/container/ModuleFederationPlugin.js +2 -2
  104. package/lib/container/RemoteModule.js +1 -1
  105. package/lib/css/CssGenerator.js +9 -6
  106. package/lib/css/CssModulesPlugin.js +44 -31
  107. package/lib/css/CssParser.js +6 -4
  108. package/lib/css/walkCssTokens.js +33 -37
  109. package/lib/debug/ProfilingPlugin.js +6 -6
  110. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -8
  111. package/lib/dependencies/AMDPlugin.js +12 -8
  112. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +28 -26
  113. package/lib/dependencies/CachedConstDependency.js +1 -5
  114. package/lib/dependencies/CommonJsExportRequireDependency.js +6 -4
  115. package/lib/dependencies/CommonJsExportsParserPlugin.js +22 -25
  116. package/lib/dependencies/CommonJsFullRequireDependency.js +1 -9
  117. package/lib/dependencies/CommonJsImportsParserPlugin.js +100 -114
  118. package/lib/dependencies/CommonJsPlugin.js +15 -16
  119. package/lib/dependencies/ContextDependencyHelpers.js +2 -1
  120. package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -0
  121. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +1 -0
  122. package/lib/dependencies/CssIcssExportDependency.js +1 -1
  123. package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
  124. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
  125. package/lib/dependencies/DynamicExports.js +9 -9
  126. package/lib/dependencies/ExportsInfoDependency.js +1 -1
  127. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +122 -101
  128. package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
  129. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +95 -19
  130. package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
  131. package/lib/dependencies/HarmonyImportDependency.js +11 -5
  132. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +238 -162
  133. package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -1
  134. package/lib/dependencies/HarmonyImportSpecifierDependency.js +20 -9
  135. package/lib/dependencies/HarmonyModulesPlugin.js +23 -12
  136. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
  137. package/lib/dependencies/ImportMetaContextPlugin.js +2 -1
  138. package/lib/dependencies/ImportMetaPlugin.js +2 -2
  139. package/lib/dependencies/ImportParserPlugin.js +40 -9
  140. package/lib/dependencies/ImportPlugin.js +3 -1
  141. package/lib/dependencies/LoaderPlugin.js +1 -0
  142. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
  143. package/lib/dependencies/RequireContextPlugin.js +3 -1
  144. package/lib/dependencies/RequireEnsurePlugin.js +6 -6
  145. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +33 -34
  146. package/lib/dependencies/RequireIncludePlugin.js +1 -0
  147. package/lib/dependencies/RuntimeRequirementsDependency.js +1 -1
  148. package/lib/dependencies/SystemPlugin.js +1 -1
  149. package/lib/dependencies/URLContextDependency.js +65 -0
  150. package/lib/dependencies/URLPlugin.js +17 -157
  151. package/lib/dependencies/WorkerPlugin.js +23 -10
  152. package/lib/dependencies/processExportInfo.js +2 -1
  153. package/lib/esm/ModuleChunkFormatPlugin.js +269 -185
  154. package/lib/esm/ModuleChunkLoadingPlugin.js +39 -1
  155. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +70 -3
  156. package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
  157. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  158. package/lib/hmr/JavascriptHotModuleReplacementHelper.js +37 -0
  159. package/lib/hmr/LazyCompilationPlugin.js +4 -2
  160. package/lib/hmr/lazyCompilationBackend.js +4 -2
  161. package/lib/ids/ChunkModuleIdRangePlugin.js +6 -3
  162. package/lib/ids/DeterministicChunkIdsPlugin.js +30 -35
  163. package/lib/ids/DeterministicModuleIdsPlugin.js +4 -3
  164. package/lib/ids/HashedModuleIdsPlugin.js +5 -4
  165. package/lib/ids/IdHelpers.js +21 -17
  166. package/lib/ids/NamedChunkIdsPlugin.js +5 -5
  167. package/lib/ids/NamedModuleIdsPlugin.js +4 -4
  168. package/lib/ids/NaturalChunkIdsPlugin.js +2 -1
  169. package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
  170. package/lib/ids/OccurrenceChunkIdsPlugin.js +3 -2
  171. package/lib/ids/OccurrenceModuleIdsPlugin.js +1 -1
  172. package/lib/ids/SyncModuleIdsPlugin.js +1 -1
  173. package/lib/index.js +13 -3
  174. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +113 -119
  175. package/lib/javascript/BasicEvaluatedExpression.js +2 -1
  176. package/lib/javascript/ChunkHelpers.js +1 -0
  177. package/lib/javascript/CommonJsChunkFormatPlugin.js +121 -136
  178. package/lib/javascript/EnableChunkLoadingPlugin.js +6 -3
  179. package/lib/javascript/JavascriptGenerator.js +14 -2
  180. package/lib/javascript/JavascriptModulesPlugin.js +68 -27
  181. package/lib/javascript/JavascriptParser.js +117 -76
  182. package/lib/javascript/JavascriptParserHelpers.js +41 -41
  183. package/lib/javascript/StartupHelpers.js +17 -17
  184. package/lib/json/JsonGenerator.js +4 -2
  185. package/lib/json/JsonModulesPlugin.js +2 -2
  186. package/lib/json/JsonParser.js +1 -1
  187. package/lib/library/AbstractLibraryPlugin.js +6 -2
  188. package/lib/library/AssignLibraryPlugin.js +21 -6
  189. package/lib/library/EnableLibraryPlugin.js +23 -3
  190. package/lib/library/UmdLibraryPlugin.js +15 -6
  191. package/lib/logging/createConsoleLogger.js +3 -3
  192. package/lib/logging/runtime.js +9 -9
  193. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +4 -22
  194. package/lib/node/RequireChunkLoadingRuntimeModule.js +4 -22
  195. package/lib/node/nodeConsole.js +4 -2
  196. package/lib/optimize/AggressiveMergingPlugin.js +45 -46
  197. package/lib/optimize/AggressiveSplittingPlugin.js +13 -12
  198. package/lib/optimize/ConcatenatedModule.js +227 -57
  199. package/lib/optimize/EnsureChunkConditionsPlugin.js +58 -58
  200. package/lib/optimize/FlagIncludedChunksPlugin.js +3 -1
  201. package/lib/optimize/InnerGraph.js +115 -112
  202. package/lib/optimize/InnerGraphPlugin.js +2 -2
  203. package/lib/optimize/LimitChunkCountPlugin.js +4 -2
  204. package/lib/optimize/MangleExportsPlugin.js +4 -3
  205. package/lib/optimize/MergeDuplicateChunksPlugin.js +80 -81
  206. package/lib/optimize/MinChunkSizePlugin.js +6 -3
  207. package/lib/optimize/ModuleConcatenationPlugin.js +31 -22
  208. package/lib/optimize/RealContentHashPlugin.js +26 -20
  209. package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -1
  210. package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
  211. package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
  212. package/lib/optimize/SplitChunksPlugin.js +16 -13
  213. package/lib/rules/BasicEffectRulePlugin.js +4 -2
  214. package/lib/rules/BasicMatcherRulePlugin.js +3 -1
  215. package/lib/rules/ObjectMatcherRulePlugin.js +3 -1
  216. package/lib/rules/RuleSetCompiler.js +6 -3
  217. package/lib/rules/UseEffectRulePlugin.js +3 -1
  218. package/lib/runtime/AsyncModuleRuntimeModule.js +64 -9
  219. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +1 -1
  220. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +214 -0
  221. package/lib/runtime/RuntimeIdRuntimeModule.js +2 -1
  222. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +8 -7
  223. package/lib/schemes/FileUriPlugin.js +1 -1
  224. package/lib/schemes/HttpUriPlugin.js +27 -19
  225. package/lib/schemes/VirtualUrlPlugin.js +222 -0
  226. package/lib/serialization/AggregateErrorSerializer.js +1 -1
  227. package/lib/serialization/BinaryMiddleware.js +5 -4
  228. package/lib/serialization/FileMiddleware.js +7 -4
  229. package/lib/serialization/ObjectMiddleware.js +14 -8
  230. package/lib/serialization/Serializer.js +5 -3
  231. package/lib/serialization/SerializerMiddleware.js +2 -0
  232. package/lib/sharing/ConsumeSharedModule.js +1 -1
  233. package/lib/sharing/ConsumeSharedPlugin.js +3 -3
  234. package/lib/sharing/ConsumeSharedRuntimeModule.js +2 -2
  235. package/lib/sharing/ProvideSharedModule.js +1 -1
  236. package/lib/sharing/ProvideSharedPlugin.js +3 -2
  237. package/lib/sharing/SharePlugin.js +2 -1
  238. package/lib/sharing/ShareRuntimeModule.js +3 -5
  239. package/lib/sharing/utils.js +34 -34
  240. package/lib/stats/DefaultStatsFactoryPlugin.js +49 -46
  241. package/lib/stats/DefaultStatsPresetPlugin.js +4 -2
  242. package/lib/stats/DefaultStatsPrinterPlugin.js +15 -9
  243. package/lib/stats/StatsFactory.js +4 -2
  244. package/lib/stats/StatsPrinter.js +3 -2
  245. package/lib/url/URLParserPlugin.js +266 -0
  246. package/lib/util/ArrayQueue.js +1 -1
  247. package/lib/util/AsyncQueue.js +1 -1
  248. package/lib/util/Hash.js +2 -0
  249. package/lib/util/IterableHelpers.js +1 -1
  250. package/lib/util/LazyBucketSortedSet.js +2 -1
  251. package/lib/util/LazySet.js +11 -6
  252. package/lib/util/ParallelismFactorCalculator.js +1 -1
  253. package/lib/util/SetHelpers.js +3 -3
  254. package/lib/util/SortableSet.js +2 -2
  255. package/lib/util/StackedCacheMap.js +3 -1
  256. package/lib/util/StackedMap.js +2 -2
  257. package/lib/util/StringXor.js +1 -0
  258. package/lib/util/TupleSet.js +1 -0
  259. package/lib/util/URLAbsoluteSpecifier.js +1 -1
  260. package/lib/util/cleverMerge.js +12 -8
  261. package/lib/util/comparators.js +154 -127
  262. package/lib/util/compileBooleanMatcher.js +8 -3
  263. package/lib/util/concatenate.js +8 -7
  264. package/lib/util/conventions.js +72 -73
  265. package/lib/util/create-schema-validation.js +2 -1
  266. package/lib/util/createHash.js +10 -4
  267. package/lib/util/deprecation.js +69 -66
  268. package/lib/util/deterministicGrouping.js +4 -2
  269. package/lib/util/extractUrlAndGlobal.js +1 -1
  270. package/lib/util/findGraphRoots.js +2 -2
  271. package/lib/util/fs.js +30 -23
  272. package/lib/util/hash/md4.js +2 -2
  273. package/lib/util/hash/wasm-hash.js +4 -2
  274. package/lib/util/identifier.js +13 -12
  275. package/lib/util/internalSerializables.js +2 -0
  276. package/lib/util/magicComment.js +5 -5
  277. package/lib/util/processAsyncTree.js +1 -1
  278. package/lib/util/propertyAccess.js +1 -1
  279. package/lib/util/propertyName.js +1 -1
  280. package/lib/util/registerExternalSerializer.js +1 -2
  281. package/lib/util/removeBOM.js +1 -1
  282. package/lib/util/runtime.js +29 -21
  283. package/lib/util/semver.js +1 -1
  284. package/lib/util/serialization.js +3 -0
  285. package/lib/util/source.js +3 -2
  286. package/lib/validateSchema.js +1 -0
  287. package/lib/wasm/EnableWasmLoadingPlugin.js +6 -3
  288. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -1
  289. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +46 -49
  290. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
  291. package/lib/wasm-sync/WebAssemblyGenerator.js +2 -3
  292. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +3 -2
  293. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +3 -0
  294. package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
  295. package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -22
  296. package/lib/webpack.js +4 -5
  297. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
  298. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -24
  299. package/lib/webworker/WebWorkerTemplatePlugin.js +1 -0
  300. package/package.json +119 -113
  301. package/schemas/WebpackOptions.check.js +1 -1
  302. package/schemas/WebpackOptions.json +17 -0
  303. package/schemas/plugins/schemes/VirtualUrlPlugin.check.d.ts +7 -0
  304. package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +6 -0
  305. package/schemas/plugins/schemes/VirtualUrlPlugin.json +77 -0
  306. package/types.d.ts +1230 -360
@@ -11,6 +11,8 @@ const { STAGE_BASIC } = require("../OptimizationStages");
11
11
  /** @typedef {import("../ChunkGroup")} ChunkGroup */
12
12
  /** @typedef {import("../Compiler")} Compiler */
13
13
 
14
+ const PLUGIN_NAME = "EnsureChunkConditionsPlugin";
15
+
14
16
  class EnsureChunkConditionsPlugin {
15
17
  /**
16
18
  * Apply the plugin
@@ -18,71 +20,69 @@ class EnsureChunkConditionsPlugin {
18
20
  * @returns {void}
19
21
  */
20
22
  apply(compiler) {
21
- compiler.hooks.compilation.tap(
22
- "EnsureChunkConditionsPlugin",
23
- compilation => {
24
- /**
25
- * @param {Iterable<Chunk>} chunks the chunks
26
- */
27
- const handler = chunks => {
28
- const chunkGraph = compilation.chunkGraph;
29
- // These sets are hoisted here to save memory
30
- // They are cleared at the end of every loop
31
- /** @type {Set<Chunk>} */
32
- const sourceChunks = new Set();
33
- /** @type {Set<ChunkGroup>} */
34
- const chunkGroups = new Set();
35
- for (const module of compilation.modules) {
36
- if (!module.hasChunkCondition()) continue;
37
- for (const chunk of chunkGraph.getModuleChunksIterable(module)) {
38
- if (!module.chunkCondition(chunk, compilation)) {
39
- sourceChunks.add(chunk);
40
- for (const group of chunk.groupsIterable) {
41
- chunkGroups.add(group);
42
- }
23
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
24
+ /**
25
+ * @param {Iterable<Chunk>} chunks the chunks
26
+ */
27
+ const handler = chunks => {
28
+ const chunkGraph = compilation.chunkGraph;
29
+ // These sets are hoisted here to save memory
30
+ // They are cleared at the end of every loop
31
+ /** @type {Set<Chunk>} */
32
+ const sourceChunks = new Set();
33
+ /** @type {Set<ChunkGroup>} */
34
+ const chunkGroups = new Set();
35
+ for (const module of compilation.modules) {
36
+ if (!module.hasChunkCondition()) continue;
37
+ for (const chunk of chunkGraph.getModuleChunksIterable(module)) {
38
+ if (!module.chunkCondition(chunk, compilation)) {
39
+ sourceChunks.add(chunk);
40
+ for (const group of chunk.groupsIterable) {
41
+ chunkGroups.add(group);
43
42
  }
44
43
  }
45
- if (sourceChunks.size === 0) continue;
46
- /** @type {Set<Chunk>} */
47
- const targetChunks = new Set();
48
- chunkGroupLoop: for (const chunkGroup of chunkGroups) {
49
- // Can module be placed in a chunk of this group?
50
- for (const chunk of chunkGroup.chunks) {
51
- if (module.chunkCondition(chunk, compilation)) {
52
- targetChunks.add(chunk);
53
- continue chunkGroupLoop;
54
- }
55
- }
56
- // We reached the entrypoint: fail
57
- if (chunkGroup.isInitial()) {
58
- throw new Error(
59
- `Cannot fulfil chunk condition of ${module.identifier()}`
60
- );
61
- }
62
- // Try placing in all parents
63
- for (const group of chunkGroup.parentsIterable) {
64
- chunkGroups.add(group);
44
+ }
45
+ if (sourceChunks.size === 0) continue;
46
+ /** @type {Set<Chunk>} */
47
+ const targetChunks = new Set();
48
+ chunkGroupLoop: for (const chunkGroup of chunkGroups) {
49
+ // Can module be placed in a chunk of this group?
50
+ for (const chunk of chunkGroup.chunks) {
51
+ if (module.chunkCondition(chunk, compilation)) {
52
+ targetChunks.add(chunk);
53
+ continue chunkGroupLoop;
65
54
  }
66
55
  }
67
- for (const sourceChunk of sourceChunks) {
68
- chunkGraph.disconnectChunkAndModule(sourceChunk, module);
56
+ // We reached the entrypoint: fail
57
+ if (chunkGroup.isInitial()) {
58
+ throw new Error(
59
+ `Cannot fulfil chunk condition of ${module.identifier()}`
60
+ );
69
61
  }
70
- for (const targetChunk of targetChunks) {
71
- chunkGraph.connectChunkAndModule(targetChunk, module);
62
+ // Try placing in all parents
63
+ for (const group of chunkGroup.parentsIterable) {
64
+ chunkGroups.add(group);
72
65
  }
73
- sourceChunks.clear();
74
- chunkGroups.clear();
75
66
  }
76
- };
77
- compilation.hooks.optimizeChunks.tap(
78
- {
79
- name: "EnsureChunkConditionsPlugin",
80
- stage: STAGE_BASIC
81
- },
82
- handler
83
- );
84
- }
85
- );
67
+ for (const sourceChunk of sourceChunks) {
68
+ chunkGraph.disconnectChunkAndModule(sourceChunk, module);
69
+ }
70
+ for (const targetChunk of targetChunks) {
71
+ chunkGraph.connectChunkAndModule(targetChunk, module);
72
+ }
73
+ sourceChunks.clear();
74
+ chunkGroups.clear();
75
+ }
76
+ };
77
+ compilation.hooks.optimizeChunks.tap(
78
+ {
79
+ name: PLUGIN_NAME,
80
+ stage: STAGE_BASIC
81
+ },
82
+ handler
83
+ );
84
+ });
86
85
  }
87
86
  }
87
+
88
88
  module.exports = EnsureChunkConditionsPlugin;
@@ -78,8 +78,9 @@ class FlagIncludedChunksPlugin {
78
78
  bestModule === undefined ||
79
79
  chunkGraph.getNumberOfModuleChunks(bestModule) >
80
80
  chunkGraph.getNumberOfModuleChunks(module)
81
- )
81
+ ) {
82
82
  bestModule = module;
83
+ }
83
84
  }
84
85
  loopB: for (const chunkB of chunkGraph.getModuleChunksIterable(
85
86
  /** @type {Module} */ (bestModule)
@@ -122,4 +123,5 @@ class FlagIncludedChunksPlugin {
122
123
  });
123
124
  }
124
125
  }
126
+
125
127
  module.exports = FlagIncludedChunksPlugin;
@@ -30,6 +30,17 @@ const { UsageState } = require("../ExportsInfo");
30
30
 
31
31
  /** @typedef {false|StateObject} State */
32
32
 
33
+ class TopLevelSymbol {
34
+ /**
35
+ * @param {string} name name of the variable
36
+ */
37
+ constructor(name) {
38
+ this.name = name;
39
+ }
40
+ }
41
+
42
+ module.exports.TopLevelSymbol = TopLevelSymbol;
43
+
33
44
  /** @type {WeakMap<ParserState, State>} */
34
45
  const parserStateMap = new WeakMap();
35
46
  const topLevelSymbolTag = Symbol("top level symbol");
@@ -42,39 +53,6 @@ function getState(parserState) {
42
53
  return parserStateMap.get(parserState);
43
54
  }
44
55
 
45
- /**
46
- * @param {ParserState} parserState parser state
47
- * @returns {void}
48
- */
49
- module.exports.bailout = parserState => {
50
- parserStateMap.set(parserState, false);
51
- };
52
-
53
- /**
54
- * @param {ParserState} parserState parser state
55
- * @returns {void}
56
- */
57
- module.exports.enable = parserState => {
58
- const state = parserStateMap.get(parserState);
59
- if (state === false) {
60
- return;
61
- }
62
- parserStateMap.set(parserState, {
63
- innerGraph: new Map(),
64
- currentTopLevelSymbol: undefined,
65
- usageCallbackMap: new Map()
66
- });
67
- };
68
-
69
- /**
70
- * @param {ParserState} parserState parser state
71
- * @returns {boolean} true, when enabled
72
- */
73
- module.exports.isEnabled = parserState => {
74
- const state = parserStateMap.get(parserState);
75
- return Boolean(state);
76
- };
77
-
78
56
  /**
79
57
  * @param {ParserState} state parser state
80
58
  * @param {TopLevelSymbol | null} symbol the symbol, or null for all symbols
@@ -113,6 +91,71 @@ module.exports.addVariableUsage = (parser, name, usage) => {
113
91
  }
114
92
  };
115
93
 
94
+ /**
95
+ * @param {ParserState} parserState parser state
96
+ * @returns {void}
97
+ */
98
+ module.exports.bailout = parserState => {
99
+ parserStateMap.set(parserState, false);
100
+ };
101
+
102
+ /**
103
+ * @param {ParserState} parserState parser state
104
+ * @returns {void}
105
+ */
106
+ module.exports.enable = parserState => {
107
+ const state = parserStateMap.get(parserState);
108
+ if (state === false) {
109
+ return;
110
+ }
111
+ parserStateMap.set(parserState, {
112
+ innerGraph: new Map(),
113
+ currentTopLevelSymbol: undefined,
114
+ usageCallbackMap: new Map()
115
+ });
116
+ };
117
+
118
+ /**
119
+ * @param {Dependency} dependency the dependency
120
+ * @param {Set<string> | boolean | undefined} usedByExports usedByExports info
121
+ * @param {ModuleGraph} moduleGraph moduleGraph
122
+ * @returns {null | false | GetConditionFn} function to determine if the connection is active
123
+ */
124
+ module.exports.getDependencyUsedByExportsCondition = (
125
+ dependency,
126
+ usedByExports,
127
+ moduleGraph
128
+ ) => {
129
+ if (usedByExports === false) return false;
130
+ if (usedByExports !== true && usedByExports !== undefined) {
131
+ const selfModule =
132
+ /** @type {Module} */
133
+ (moduleGraph.getParentModule(dependency));
134
+ const exportsInfo = moduleGraph.getExportsInfo(selfModule);
135
+ return (connections, runtime) => {
136
+ for (const exportName of usedByExports) {
137
+ if (exportsInfo.getUsed(exportName, runtime) !== UsageState.Unused) {
138
+ return true;
139
+ }
140
+ }
141
+ return false;
142
+ };
143
+ }
144
+ return null;
145
+ };
146
+
147
+ /**
148
+ * @param {ParserState} state parser state
149
+ * @returns {TopLevelSymbol|void} usage data
150
+ */
151
+ module.exports.getTopLevelSymbol = state => {
152
+ const innerGraphState = getState(state);
153
+
154
+ if (innerGraphState) {
155
+ return innerGraphState.currentTopLevelSymbol;
156
+ }
157
+ };
158
+
116
159
  /**
117
160
  * @param {ParserState} state parser state
118
161
  * @returns {void}
@@ -209,6 +252,45 @@ module.exports.inferDependencyUsage = state => {
209
252
  }
210
253
  };
211
254
 
255
+ /**
256
+ * @param {Dependency} dependency the dependency
257
+ * @param {Set<string> | boolean} usedByExports usedByExports info
258
+ * @param {ModuleGraph} moduleGraph moduleGraph
259
+ * @param {RuntimeSpec} runtime runtime
260
+ * @returns {boolean} false, when unused. Otherwise true
261
+ */
262
+ module.exports.isDependencyUsedByExports = (
263
+ dependency,
264
+ usedByExports,
265
+ moduleGraph,
266
+ runtime
267
+ ) => {
268
+ if (usedByExports === false) return false;
269
+ if (usedByExports !== true && usedByExports !== undefined) {
270
+ const selfModule =
271
+ /** @type {Module} */
272
+ (moduleGraph.getParentModule(dependency));
273
+ const exportsInfo = moduleGraph.getExportsInfo(selfModule);
274
+ let used = false;
275
+ for (const exportName of usedByExports) {
276
+ if (exportsInfo.getUsed(exportName, runtime) !== UsageState.Unused) {
277
+ used = true;
278
+ }
279
+ }
280
+ if (!used) return false;
281
+ }
282
+ return true;
283
+ };
284
+
285
+ /**
286
+ * @param {ParserState} parserState parser state
287
+ * @returns {boolean} true, when enabled
288
+ */
289
+ module.exports.isEnabled = parserState => {
290
+ const state = parserStateMap.get(parserState);
291
+ return Boolean(state);
292
+ };
293
+
212
294
  /**
213
295
  * @param {ParserState} state parser state
214
296
  * @param {UsageCallback} onUsageCallback on usage callback
@@ -247,18 +329,6 @@ module.exports.setTopLevelSymbol = (state, symbol) => {
247
329
  }
248
330
  };
249
331
 
250
- /**
251
- * @param {ParserState} state parser state
252
- * @returns {TopLevelSymbol|void} usage data
253
- */
254
- module.exports.getTopLevelSymbol = state => {
255
- const innerGraphState = getState(state);
256
-
257
- if (innerGraphState) {
258
- return innerGraphState.currentTopLevelSymbol;
259
- }
260
- };
261
-
262
332
  /**
263
333
  * @param {JavascriptParser} parser parser
264
334
  * @param {string} name name of variable
@@ -282,71 +352,4 @@ module.exports.tagTopLevelSymbol = (parser, name) => {
282
352
  return fn;
283
353
  };
284
354
 
285
- /**
286
- * @param {Dependency} dependency the dependency
287
- * @param {Set<string> | boolean} usedByExports usedByExports info
288
- * @param {ModuleGraph} moduleGraph moduleGraph
289
- * @param {RuntimeSpec} runtime runtime
290
- * @returns {boolean} false, when unused. Otherwise true
291
- */
292
- module.exports.isDependencyUsedByExports = (
293
- dependency,
294
- usedByExports,
295
- moduleGraph,
296
- runtime
297
- ) => {
298
- if (usedByExports === false) return false;
299
- if (usedByExports !== true && usedByExports !== undefined) {
300
- const selfModule =
301
- /** @type {Module} */
302
- (moduleGraph.getParentModule(dependency));
303
- const exportsInfo = moduleGraph.getExportsInfo(selfModule);
304
- let used = false;
305
- for (const exportName of usedByExports) {
306
- if (exportsInfo.getUsed(exportName, runtime) !== UsageState.Unused)
307
- used = true;
308
- }
309
- if (!used) return false;
310
- }
311
- return true;
312
- };
313
-
314
- /**
315
- * @param {Dependency} dependency the dependency
316
- * @param {Set<string> | boolean | undefined} usedByExports usedByExports info
317
- * @param {ModuleGraph} moduleGraph moduleGraph
318
- * @returns {null | false | GetConditionFn} function to determine if the connection is active
319
- */
320
- module.exports.getDependencyUsedByExportsCondition = (
321
- dependency,
322
- usedByExports,
323
- moduleGraph
324
- ) => {
325
- if (usedByExports === false) return false;
326
- if (usedByExports !== true && usedByExports !== undefined) {
327
- const selfModule =
328
- /** @type {Module} */
329
- (moduleGraph.getParentModule(dependency));
330
- const exportsInfo = moduleGraph.getExportsInfo(selfModule);
331
- return (connections, runtime) => {
332
- for (const exportName of usedByExports) {
333
- if (exportsInfo.getUsed(exportName, runtime) !== UsageState.Unused)
334
- return true;
335
- }
336
- return false;
337
- };
338
- }
339
- return null;
340
- };
341
-
342
- class TopLevelSymbol {
343
- /**
344
- * @param {string} name name of the variable
345
- */
346
- constructor(name) {
347
- this.name = name;
348
- }
349
- }
350
-
351
- module.exports.TopLevelSymbol = TopLevelSymbol;
352
355
  module.exports.topLevelSymbolTag = topLevelSymbolTag;
@@ -195,7 +195,7 @@ class InnerGraphPlugin {
195
195
  }
196
196
  });
197
197
 
198
- parser.hooks.preDeclarator.tap(PLUGIN_NAME, (decl, statement) => {
198
+ parser.hooks.preDeclarator.tap(PLUGIN_NAME, (decl, _statement) => {
199
199
  if (!InnerGraph.isEnabled(parser.state)) return;
200
200
  if (
201
201
  parser.scope.topLevelScope === true &&
@@ -363,7 +363,7 @@ class InnerGraphPlugin {
363
363
  }
364
364
  );
365
365
 
366
- parser.hooks.declarator.tap(PLUGIN_NAME, (decl, statement) => {
366
+ parser.hooks.declarator.tap(PLUGIN_NAME, (decl, _statement) => {
367
367
  if (!InnerGraph.isEnabled(parser.state)) return;
368
368
  const fn = declWithTopLevelSymbol.get(decl);
369
369
 
@@ -15,7 +15,7 @@ const createSchemaValidation = require("../util/create-schema-validation");
15
15
  /** @typedef {import("../Compiler")} Compiler */
16
16
 
17
17
  const validate = createSchemaValidation(
18
- require("../../schemas/plugins/optimize/LimitChunkCountPlugin.check.js"),
18
+ require("../../schemas/plugins/optimize/LimitChunkCountPlugin.check"),
19
19
  () => require("../../schemas/plugins/optimize/LimitChunkCountPlugin.json"),
20
20
  {
21
21
  name: "Limit Chunk Count Plugin",
@@ -85,7 +85,8 @@ class LimitChunkCountPlugin {
85
85
 
86
86
  // order chunks in a deterministic way
87
87
  const compareChunksWithGraph = compareChunks(chunkGraph);
88
- const orderedChunks = Array.from(chunks).sort(compareChunksWithGraph);
88
+ /** @type {Chunk[]} */
89
+ const orderedChunks = [...chunks].sort(compareChunksWithGraph);
89
90
 
90
91
  // create a lazy sorted data structure to keep all combinations
91
92
  // this is large. Size = chunks * (chunks - 1) / 2
@@ -296,4 +297,5 @@ class LimitChunkCountPlugin {
296
297
  });
297
298
  }
298
299
  }
300
+
299
301
  module.exports = LimitChunkCountPlugin;
@@ -7,9 +7,9 @@
7
7
 
8
8
  const { UsageState } = require("../ExportsInfo");
9
9
  const {
10
- numberToIdentifier,
10
+ NUMBER_OF_IDENTIFIER_CONTINUATION_CHARS,
11
11
  NUMBER_OF_IDENTIFIER_START_CHARS,
12
- NUMBER_OF_IDENTIFIER_CONTINUATION_CHARS
12
+ numberToIdentifier
13
13
  } = require("../Template");
14
14
  const { assignDeterministicIds } = require("../ids/IdHelpers");
15
15
  const { compareSelect, compareStringsNumeric } = require("../util/comparators");
@@ -23,8 +23,9 @@ const { compareSelect, compareStringsNumeric } = require("../util/comparators");
23
23
  * @returns {boolean} mangle is possible
24
24
  */
25
25
  const canMangle = exportsInfo => {
26
- if (exportsInfo.otherExportsInfo.getUsed(undefined) !== UsageState.Unused)
26
+ if (exportsInfo.otherExportsInfo.getUsed(undefined) !== UsageState.Unused) {
27
27
  return false;
28
+ }
28
29
  let hasSomethingToMangle = false;
29
30
  for (const exportInfo of exportsInfo.exports) {
30
31
  if (exportInfo.canMangle === true) {
@@ -13,7 +13,7 @@ const { runtimeEqual } = require("../util/runtime");
13
13
  /** @typedef {import("../Compiler")} Compiler */
14
14
 
15
15
  const validate = createSchemaValidation(
16
- require("../../schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js"),
16
+ require("../../schemas/plugins/optimize/MergeDuplicateChunksPlugin.check"),
17
17
  () =>
18
18
  require("../../schemas/plugins/optimize/MergeDuplicateChunksPlugin.json"),
19
19
  {
@@ -22,6 +22,8 @@ const validate = createSchemaValidation(
22
22
  }
23
23
  );
24
24
 
25
+ const PLUGIN_NAME = "MergeDuplicateChunksPlugin";
26
+
25
27
  class MergeDuplicateChunksPlugin {
26
28
  /**
27
29
  * @param {MergeDuplicateChunksPluginOptions} options options object
@@ -36,100 +38,97 @@ class MergeDuplicateChunksPlugin {
36
38
  * @returns {void}
37
39
  */
38
40
  apply(compiler) {
39
- compiler.hooks.compilation.tap(
40
- "MergeDuplicateChunksPlugin",
41
- compilation => {
42
- compilation.hooks.optimizeChunks.tap(
43
- {
44
- name: "MergeDuplicateChunksPlugin",
45
- stage: this.options.stage
46
- },
47
- chunks => {
48
- const { chunkGraph, moduleGraph } = compilation;
41
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
42
+ compilation.hooks.optimizeChunks.tap(
43
+ {
44
+ name: PLUGIN_NAME,
45
+ stage: this.options.stage
46
+ },
47
+ chunks => {
48
+ const { chunkGraph, moduleGraph } = compilation;
49
49
 
50
- // remember already tested chunks for performance
51
- const notDuplicates = new Set();
50
+ // remember already tested chunks for performance
51
+ const notDuplicates = new Set();
52
52
 
53
- // for each chunk
54
- for (const chunk of chunks) {
55
- // track a Set of all chunk that could be duplicates
56
- let possibleDuplicates;
57
- for (const module of chunkGraph.getChunkModulesIterable(chunk)) {
58
- if (possibleDuplicates === undefined) {
59
- // when possibleDuplicates is not yet set,
60
- // create a new Set from chunks of the current module
61
- // including only chunks with the same number of modules
62
- for (const dup of chunkGraph.getModuleChunksIterable(
63
- module
64
- )) {
65
- if (
66
- dup !== chunk &&
67
- chunkGraph.getNumberOfChunkModules(chunk) ===
68
- chunkGraph.getNumberOfChunkModules(dup) &&
69
- !notDuplicates.has(dup)
70
- ) {
71
- // delay allocating the new Set until here, reduce memory pressure
72
- if (possibleDuplicates === undefined) {
73
- possibleDuplicates = new Set();
74
- }
75
- possibleDuplicates.add(dup);
53
+ // for each chunk
54
+ for (const chunk of chunks) {
55
+ // track a Set of all chunk that could be duplicates
56
+ let possibleDuplicates;
57
+ for (const module of chunkGraph.getChunkModulesIterable(chunk)) {
58
+ if (possibleDuplicates === undefined) {
59
+ // when possibleDuplicates is not yet set,
60
+ // create a new Set from chunks of the current module
61
+ // including only chunks with the same number of modules
62
+ for (const dup of chunkGraph.getModuleChunksIterable(module)) {
63
+ if (
64
+ dup !== chunk &&
65
+ chunkGraph.getNumberOfChunkModules(chunk) ===
66
+ chunkGraph.getNumberOfChunkModules(dup) &&
67
+ !notDuplicates.has(dup)
68
+ ) {
69
+ // delay allocating the new Set until here, reduce memory pressure
70
+ if (possibleDuplicates === undefined) {
71
+ possibleDuplicates = new Set();
76
72
  }
73
+ possibleDuplicates.add(dup);
77
74
  }
78
- // when no chunk is possible we can break here
79
- if (possibleDuplicates === undefined) break;
80
- } else {
81
- // validate existing possible duplicates
82
- for (const dup of possibleDuplicates) {
83
- // remove possible duplicate when module is not contained
84
- if (!chunkGraph.isModuleInChunk(module, dup)) {
85
- possibleDuplicates.delete(dup);
86
- }
75
+ }
76
+ // when no chunk is possible we can break here
77
+ if (possibleDuplicates === undefined) break;
78
+ } else {
79
+ // validate existing possible duplicates
80
+ for (const dup of possibleDuplicates) {
81
+ // remove possible duplicate when module is not contained
82
+ if (!chunkGraph.isModuleInChunk(module, dup)) {
83
+ possibleDuplicates.delete(dup);
87
84
  }
88
- // when all chunks has been removed we can break here
89
- if (possibleDuplicates.size === 0) break;
90
85
  }
86
+ // when all chunks has been removed we can break here
87
+ if (possibleDuplicates.size === 0) break;
91
88
  }
89
+ }
92
90
 
93
- // when we found duplicates
94
- if (
95
- possibleDuplicates !== undefined &&
96
- possibleDuplicates.size > 0
97
- ) {
98
- outer: for (const otherChunk of possibleDuplicates) {
99
- if (otherChunk.hasRuntime() !== chunk.hasRuntime()) continue;
100
- if (chunkGraph.getNumberOfEntryModules(chunk) > 0) continue;
101
- if (chunkGraph.getNumberOfEntryModules(otherChunk) > 0)
102
- continue;
103
- if (!runtimeEqual(chunk.runtime, otherChunk.runtime)) {
104
- for (const module of chunkGraph.getChunkModulesIterable(
105
- chunk
106
- )) {
107
- const exportsInfo = moduleGraph.getExportsInfo(module);
108
- if (
109
- !exportsInfo.isEquallyUsed(
110
- chunk.runtime,
111
- otherChunk.runtime
112
- )
113
- ) {
114
- continue outer;
115
- }
91
+ // when we found duplicates
92
+ if (
93
+ possibleDuplicates !== undefined &&
94
+ possibleDuplicates.size > 0
95
+ ) {
96
+ outer: for (const otherChunk of possibleDuplicates) {
97
+ if (otherChunk.hasRuntime() !== chunk.hasRuntime()) continue;
98
+ if (chunkGraph.getNumberOfEntryModules(chunk) > 0) continue;
99
+ if (chunkGraph.getNumberOfEntryModules(otherChunk) > 0) {
100
+ continue;
101
+ }
102
+ if (!runtimeEqual(chunk.runtime, otherChunk.runtime)) {
103
+ for (const module of chunkGraph.getChunkModulesIterable(
104
+ chunk
105
+ )) {
106
+ const exportsInfo = moduleGraph.getExportsInfo(module);
107
+ if (
108
+ !exportsInfo.isEquallyUsed(
109
+ chunk.runtime,
110
+ otherChunk.runtime
111
+ )
112
+ ) {
113
+ continue outer;
116
114
  }
117
115
  }
118
- // merge them
119
- if (chunkGraph.canChunksBeIntegrated(chunk, otherChunk)) {
120
- chunkGraph.integrateChunks(chunk, otherChunk);
121
- compilation.chunks.delete(otherChunk);
122
- }
116
+ }
117
+ // merge them
118
+ if (chunkGraph.canChunksBeIntegrated(chunk, otherChunk)) {
119
+ chunkGraph.integrateChunks(chunk, otherChunk);
120
+ compilation.chunks.delete(otherChunk);
123
121
  }
124
122
  }
125
-
126
- // don't check already processed chunks twice
127
- notDuplicates.add(chunk);
128
123
  }
124
+
125
+ // don't check already processed chunks twice
126
+ notDuplicates.add(chunk);
129
127
  }
130
- );
131
- }
132
- );
128
+ }
129
+ );
130
+ });
133
131
  }
134
132
  }
133
+
135
134
  module.exports = MergeDuplicateChunksPlugin;