webpack 5.99.6 → 5.99.8

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 (219) hide show
  1. package/lib/AutomaticPrefetchPlugin.js +21 -22
  2. package/lib/BannerPlugin.js +31 -35
  3. package/lib/CleanPlugin.js +5 -3
  4. package/lib/Compilation.js +21 -15
  5. package/lib/Compiler.js +2 -1
  6. package/lib/ContextExclusionPlugin.js +4 -2
  7. package/lib/ContextModule.js +1 -1
  8. package/lib/ContextModuleFactory.js +1 -2
  9. package/lib/ContextReplacementPlugin.js +7 -4
  10. package/lib/DefinePlugin.js +2 -2
  11. package/lib/DelegatedModule.js +18 -8
  12. package/lib/DelegatedModuleFactoryPlugin.js +9 -7
  13. package/lib/DelegatedPlugin.js +4 -2
  14. package/lib/DllEntryPlugin.js +4 -2
  15. package/lib/DllPlugin.js +5 -3
  16. package/lib/DllReferencePlugin.js +56 -60
  17. package/lib/DynamicEntryPlugin.js +4 -2
  18. package/lib/EntryOptionPlugin.js +3 -1
  19. package/lib/EntryPlugin.js +4 -2
  20. package/lib/EnvironmentPlugin.js +4 -2
  21. package/lib/EvalDevToolModulePlugin.js +9 -7
  22. package/lib/EvalSourceMapDevToolPlugin.js +138 -139
  23. package/lib/ExportsInfo.js +35 -16
  24. package/lib/ExternalModule.js +6 -5
  25. package/lib/ExternalsPlugin.js +3 -1
  26. package/lib/FileSystemInfo.js +2 -2
  27. package/lib/FlagDependencyExportsPlugin.js +2 -1
  28. package/lib/IgnorePlugin.js +6 -4
  29. package/lib/IgnoreWarningsPlugin.js +4 -2
  30. package/lib/LibManifestPlugin.js +5 -6
  31. package/lib/LoaderOptionsPlugin.js +4 -2
  32. package/lib/LoaderTargetPlugin.js +4 -2
  33. package/lib/Module.js +19 -12
  34. package/lib/ModuleFilenameHelpers.js +8 -4
  35. package/lib/ModuleInfoHeaderPlugin.js +11 -12
  36. package/lib/MultiCompiler.js +5 -3
  37. package/lib/NoEmitOnErrorsPlugin.js +5 -3
  38. package/lib/NormalModule.js +13 -8
  39. package/lib/NormalModuleReplacementPlugin.js +33 -36
  40. package/lib/PlatformPlugin.js +3 -1
  41. package/lib/PrefetchPlugin.js +4 -2
  42. package/lib/ProgressPlugin.js +23 -26
  43. package/lib/RecordIdsPlugin.js +72 -102
  44. package/lib/RuntimePlugin.js +34 -32
  45. package/lib/SourceMapDevToolPlugin.js +9 -8
  46. package/lib/WarnCaseSensitiveModulesPlugin.js +36 -37
  47. package/lib/WarnNoModeSetPlugin.js +3 -1
  48. package/lib/WatchIgnorePlugin.js +3 -1
  49. package/lib/WebpackError.js +11 -3
  50. package/lib/WebpackOptionsApply.js +6 -7
  51. package/lib/asset/AssetGenerator.js +2 -2
  52. package/lib/async-modules/InferAsyncModulesPlugin.js +25 -26
  53. package/lib/cache/IdleFileCachePlugin.js +11 -12
  54. package/lib/cache/MemoryWithGcCachePlugin.js +7 -5
  55. package/lib/cache/ResolverCachePlugin.js +8 -6
  56. package/lib/cli.js +5 -1
  57. package/lib/config/defaults.js +10 -6
  58. package/lib/config/normalization.js +14 -8
  59. package/lib/container/ContainerReferencePlugin.js +24 -26
  60. package/lib/container/ModuleFederationPlugin.js +2 -1
  61. package/lib/css/CssGenerator.js +1 -1
  62. package/lib/css/CssModulesPlugin.js +8 -6
  63. package/lib/debug/ProfilingPlugin.js +18 -21
  64. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -1
  65. package/lib/dependencies/ContextElementDependency.js +1 -1
  66. package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
  67. package/lib/dependencies/HarmonyDetectionParserPlugin.js +9 -15
  68. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -15
  69. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +4 -2
  70. package/lib/dependencies/LoaderPlugin.js +5 -3
  71. package/lib/dependencies/RequireContextDependencyParserPlugin.js +46 -46
  72. package/lib/dependencies/RequireContextPlugin.js +2 -1
  73. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +94 -100
  74. package/lib/dependencies/WorkerPlugin.js +2 -2
  75. package/lib/esm/ModuleChunkLoadingPlugin.js +72 -73
  76. package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
  77. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +0 -2
  78. package/lib/hmr/LazyCompilationPlugin.js +17 -18
  79. package/lib/ids/ChunkModuleIdRangePlugin.js +6 -6
  80. package/lib/ids/DeterministicModuleIdsPlugin.js +47 -48
  81. package/lib/ids/HashedModuleIdsPlugin.js +4 -2
  82. package/lib/ids/NamedChunkIdsPlugin.js +4 -2
  83. package/lib/ids/NamedModuleIdsPlugin.js +4 -2
  84. package/lib/ids/NaturalChunkIdsPlugin.js +4 -2
  85. package/lib/ids/NaturalModuleIdsPlugin.js +4 -2
  86. package/lib/ids/OccurrenceChunkIdsPlugin.js +4 -2
  87. package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -2
  88. package/lib/index.js +11 -0
  89. package/lib/javascript/JavascriptModulesPlugin.js +2 -2
  90. package/lib/javascript/JavascriptParser.js +634 -656
  91. package/lib/json/JsonModulesPlugin.js +4 -4
  92. package/lib/library/AbstractLibraryPlugin.js +1 -1
  93. package/lib/library/ModuleLibraryPlugin.js +60 -42
  94. package/lib/node/CommonJsChunkLoadingPlugin.js +69 -73
  95. package/lib/node/NodeEnvironmentPlugin.js +3 -1
  96. package/lib/node/nodeConsole.js +3 -2
  97. package/lib/optimize/AggressiveSplittingPlugin.js +224 -232
  98. package/lib/optimize/ConcatenatedModule.js +15 -16
  99. package/lib/optimize/FlagIncludedChunksPlugin.js +92 -97
  100. package/lib/optimize/LimitChunkCountPlugin.js +4 -2
  101. package/lib/optimize/MangleExportsPlugin.js +15 -16
  102. package/lib/optimize/MinChunkSizePlugin.js +4 -2
  103. package/lib/optimize/ModuleConcatenationPlugin.js +6 -4
  104. package/lib/optimize/RealContentHashPlugin.js +4 -2
  105. package/lib/optimize/RemoveEmptyChunksPlugin.js +5 -3
  106. package/lib/optimize/RemoveParentModulesPlugin.js +4 -2
  107. package/lib/optimize/RuntimeChunkPlugin.js +21 -23
  108. package/lib/optimize/SideEffectsFlagPlugin.js +9 -6
  109. package/lib/optimize/SplitChunksPlugin.js +9 -7
  110. package/lib/performance/SizeLimitsPlugin.js +3 -1
  111. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +61 -62
  112. package/lib/rules/BasicEffectRulePlugin.js +1 -2
  113. package/lib/rules/ObjectMatcherRulePlugin.js +2 -1
  114. package/lib/rules/RuleSetCompiler.js +19 -5
  115. package/lib/rules/UseEffectRulePlugin.js +4 -6
  116. package/lib/runtime/StartupChunkDependenciesPlugin.js +39 -42
  117. package/lib/schemes/DataUriPlugin.js +5 -3
  118. package/lib/schemes/FileUriPlugin.js +5 -3
  119. package/lib/schemes/HttpUriPlugin.js +186 -188
  120. package/lib/serialization/AggregateErrorSerializer.js +42 -0
  121. package/lib/serialization/ErrorObjectSerializer.js +7 -2
  122. package/lib/serialization/ObjectMiddleware.js +13 -0
  123. package/lib/sharing/ProvideSharedPlugin.js +6 -4
  124. package/lib/stats/DefaultStatsFactoryPlugin.js +89 -33
  125. package/lib/stats/DefaultStatsPresetPlugin.js +25 -20
  126. package/lib/stats/DefaultStatsPrinterPlugin.js +306 -341
  127. package/lib/util/concatenate.js +4 -2
  128. package/lib/util/createHash.js +3 -3
  129. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +55 -57
  130. package/lib/web/JsonpChunkLoadingPlugin.js +73 -74
  131. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +77 -78
  132. package/package.json +35 -30
  133. package/schemas/WebpackOptions.check.d.ts +1 -1
  134. package/schemas/WebpackOptions.check.js +2 -2
  135. package/schemas/WebpackOptions.json +267 -26
  136. package/schemas/plugins/BannerPlugin.check.d.ts +1 -1
  137. package/schemas/plugins/BannerPlugin.check.js +1 -1
  138. package/schemas/plugins/DllPlugin.check.d.ts +1 -1
  139. package/schemas/plugins/DllPlugin.check.js +1 -1
  140. package/schemas/plugins/DllReferencePlugin.check.d.ts +1 -1
  141. package/schemas/plugins/DllReferencePlugin.check.js +1 -1
  142. package/schemas/plugins/HashedModuleIdsPlugin.check.d.ts +1 -1
  143. package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
  144. package/schemas/plugins/IgnorePlugin.check.d.ts +1 -1
  145. package/schemas/plugins/IgnorePlugin.check.js +1 -1
  146. package/schemas/plugins/LoaderOptionsPlugin.check.d.ts +1 -1
  147. package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
  148. package/schemas/plugins/ProgressPlugin.check.d.ts +1 -1
  149. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  150. package/schemas/plugins/SourceMapDevToolPlugin.check.d.ts +1 -1
  151. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  152. package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
  153. package/schemas/plugins/WatchIgnorePlugin.check.d.ts +1 -1
  154. package/schemas/plugins/WatchIgnorePlugin.check.js +1 -1
  155. package/schemas/plugins/asset/AssetGeneratorOptions.check.d.ts +1 -1
  156. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  157. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.d.ts +1 -1
  158. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +1 -1
  159. package/schemas/plugins/asset/AssetParserOptions.check.d.ts +1 -1
  160. package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
  161. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.d.ts +1 -1
  162. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  163. package/schemas/plugins/container/ContainerPlugin.check.d.ts +1 -1
  164. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  165. package/schemas/plugins/container/ContainerReferencePlugin.check.d.ts +1 -1
  166. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  167. package/schemas/plugins/container/ExternalsType.check.d.ts +1 -1
  168. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  169. package/schemas/plugins/container/ModuleFederationPlugin.check.d.ts +1 -1
  170. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  171. package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +1 -1
  172. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
  173. package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +1 -1
  174. package/schemas/plugins/css/CssAutoParserOptions.check.js +1 -1
  175. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +1 -1
  176. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  177. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +1 -1
  178. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  179. package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +1 -1
  180. package/schemas/plugins/css/CssGlobalParserOptions.check.js +1 -1
  181. package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +1 -1
  182. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  183. package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +1 -1
  184. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  185. package/schemas/plugins/css/CssParserOptions.check.d.ts +1 -1
  186. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  187. package/schemas/plugins/debug/ProfilingPlugin.check.d.ts +1 -1
  188. package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
  189. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.d.ts +1 -1
  190. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +1 -1
  191. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.d.ts +1 -1
  192. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +1 -1
  193. package/schemas/plugins/json/JsonModulesPluginGenerator.check.d.ts +7 -0
  194. package/schemas/plugins/{JsonModulesPluginGenerator.check.js → json/JsonModulesPluginGenerator.check.js} +1 -1
  195. package/schemas/plugins/json/JsonModulesPluginGenerator.json +3 -0
  196. package/schemas/plugins/json/JsonModulesPluginParser.check.d.ts +7 -0
  197. package/schemas/plugins/{JsonModulesPluginParser.check.js → json/JsonModulesPluginParser.check.js} +1 -1
  198. package/schemas/plugins/json/JsonModulesPluginParser.json +3 -0
  199. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.d.ts +1 -1
  200. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
  201. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.d.ts +1 -1
  202. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
  203. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.d.ts +1 -1
  204. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +1 -1
  205. package/schemas/plugins/optimize/MinChunkSizePlugin.check.d.ts +1 -1
  206. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
  207. package/schemas/plugins/schemes/HttpUriPlugin.check.d.ts +1 -1
  208. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  209. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.d.ts +1 -1
  210. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +1 -1
  211. package/schemas/plugins/sharing/ProvideSharedPlugin.check.d.ts +1 -1
  212. package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +1 -1
  213. package/schemas/plugins/sharing/SharePlugin.check.d.ts +1 -1
  214. package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
  215. package/types.d.ts +587 -207
  216. package/schemas/plugins/JsonModulesPluginGenerator.check.d.ts +0 -7
  217. package/schemas/plugins/JsonModulesPluginGenerator.json +0 -11
  218. package/schemas/plugins/JsonModulesPluginParser.check.d.ts +0 -7
  219. package/schemas/plugins/JsonModulesPluginParser.json +0 -16
@@ -52,6 +52,8 @@ const isNotAEntryModule = (chunkGraph, chunk) => module =>
52
52
  /** @type {WeakSet<Chunk>} */
53
53
  const recordedChunks = new WeakSet();
54
54
 
55
+ const PLUGIN_NAME = "AggressiveSplittingPlugin";
56
+
55
57
  class AggressiveSplittingPlugin {
56
58
  /**
57
59
  * @param {AggressiveSplittingPluginOptions=} options options object
@@ -88,261 +90,251 @@ class AggressiveSplittingPlugin {
88
90
  * @returns {void}
89
91
  */
90
92
  apply(compiler) {
91
- compiler.hooks.thisCompilation.tap(
92
- "AggressiveSplittingPlugin",
93
- compilation => {
94
- let needAdditionalSeal = false;
95
- /** @typedef {{ id?: NonNullable<Chunk["id"]>, hash?: NonNullable<Chunk["hash"]>, modules: Module[], size: number }} SplitData */
96
- /** @type {SplitData[]} */
97
- let newSplits;
98
- /** @type {Set<Chunk>} */
99
- let fromAggressiveSplittingSet;
100
- /** @type {Map<Chunk, SplitData>} */
101
- let chunkSplitDataMap;
102
- compilation.hooks.optimize.tap("AggressiveSplittingPlugin", () => {
103
- newSplits = [];
104
- fromAggressiveSplittingSet = new Set();
105
- chunkSplitDataMap = new Map();
106
- });
107
- compilation.hooks.optimizeChunks.tap(
108
- {
109
- name: "AggressiveSplittingPlugin",
110
- stage: STAGE_ADVANCED
111
- },
112
- chunks => {
113
- const chunkGraph = compilation.chunkGraph;
114
- // Precompute stuff
115
- const nameToModuleMap = new Map();
116
- const moduleToNameMap = new Map();
117
- const makePathsRelative =
118
- identifierUtils.makePathsRelative.bindContextCache(
119
- compiler.context,
120
- compiler.root
121
- );
122
- for (const m of compilation.modules) {
123
- const name = makePathsRelative(m.identifier());
124
- nameToModuleMap.set(name, m);
125
- moduleToNameMap.set(m, name);
126
- }
93
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
94
+ let needAdditionalSeal = false;
95
+ /** @typedef {{ id?: NonNullable<Chunk["id"]>, hash?: NonNullable<Chunk["hash"]>, modules: Module[], size: number }} SplitData */
96
+ /** @type {SplitData[]} */
97
+ let newSplits;
98
+ /** @type {Set<Chunk>} */
99
+ let fromAggressiveSplittingSet;
100
+ /** @type {Map<Chunk, SplitData>} */
101
+ let chunkSplitDataMap;
102
+ compilation.hooks.optimize.tap(PLUGIN_NAME, () => {
103
+ newSplits = [];
104
+ fromAggressiveSplittingSet = new Set();
105
+ chunkSplitDataMap = new Map();
106
+ });
107
+ compilation.hooks.optimizeChunks.tap(
108
+ {
109
+ name: PLUGIN_NAME,
110
+ stage: STAGE_ADVANCED
111
+ },
112
+ chunks => {
113
+ const chunkGraph = compilation.chunkGraph;
114
+ // Precompute stuff
115
+ const nameToModuleMap = new Map();
116
+ const moduleToNameMap = new Map();
117
+ const makePathsRelative =
118
+ identifierUtils.makePathsRelative.bindContextCache(
119
+ compiler.context,
120
+ compiler.root
121
+ );
122
+ for (const m of compilation.modules) {
123
+ const name = makePathsRelative(m.identifier());
124
+ nameToModuleMap.set(name, m);
125
+ moduleToNameMap.set(m, name);
126
+ }
127
+
128
+ // Check used chunk ids
129
+ const usedIds = new Set();
130
+ for (const chunk of chunks) {
131
+ usedIds.add(chunk.id);
132
+ }
133
+
134
+ const recordedSplits =
135
+ (compilation.records && compilation.records.aggressiveSplits) || [];
136
+ const usedSplits = newSplits
137
+ ? recordedSplits.concat(newSplits)
138
+ : recordedSplits;
127
139
 
128
- // Check used chunk ids
129
- const usedIds = new Set();
130
- for (const chunk of chunks) {
131
- usedIds.add(chunk.id);
140
+ const minSize = /** @type {number} */ (this.options.minSize);
141
+ const maxSize = /** @type {number} */ (this.options.maxSize);
142
+
143
+ /**
144
+ * @param {SplitData} splitData split data
145
+ * @returns {boolean} true when applied, otherwise false
146
+ */
147
+ const applySplit = splitData => {
148
+ // Cannot split if id is already taken
149
+ if (splitData.id !== undefined && usedIds.has(splitData.id)) {
150
+ return false;
132
151
  }
133
152
 
134
- const recordedSplits =
135
- (compilation.records && compilation.records.aggressiveSplits) ||
136
- [];
137
- const usedSplits = newSplits
138
- ? recordedSplits.concat(newSplits)
139
- : recordedSplits;
140
-
141
- const minSize = /** @type {number} */ (this.options.minSize);
142
- const maxSize = /** @type {number} */ (this.options.maxSize);
143
-
144
- /**
145
- * @param {SplitData} splitData split data
146
- * @returns {boolean} true when applied, otherwise false
147
- */
148
- const applySplit = splitData => {
149
- // Cannot split if id is already taken
150
- if (splitData.id !== undefined && usedIds.has(splitData.id)) {
151
- return false;
152
- }
153
+ // Get module objects from names
154
+ const selectedModules = splitData.modules.map(name =>
155
+ nameToModuleMap.get(name)
156
+ );
153
157
 
154
- // Get module objects from names
155
- const selectedModules = splitData.modules.map(name =>
156
- nameToModuleMap.get(name)
157
- );
158
-
159
- // Does the modules exist at all?
160
- if (!selectedModules.every(Boolean)) return false;
161
-
162
- // Check if size matches (faster than waiting for hash)
163
- let size = 0;
164
- for (const m of selectedModules) size += m.size();
165
- if (size !== splitData.size) return false;
166
-
167
- // get chunks with all modules
168
- const selectedChunks = intersect(
169
- selectedModules.map(
170
- m => new Set(chunkGraph.getModuleChunksIterable(m))
171
- )
172
- );
173
-
174
- // No relevant chunks found
175
- if (selectedChunks.size === 0) return false;
176
-
177
- // The found chunk is already the split or similar
178
- if (
179
- selectedChunks.size === 1 &&
180
- chunkGraph.getNumberOfChunkModules(
181
- Array.from(selectedChunks)[0]
182
- ) === selectedModules.length
183
- ) {
184
- const chunk = Array.from(selectedChunks)[0];
185
- if (fromAggressiveSplittingSet.has(chunk)) return false;
186
- fromAggressiveSplittingSet.add(chunk);
187
- chunkSplitDataMap.set(chunk, splitData);
188
- return true;
189
- }
158
+ // Does the modules exist at all?
159
+ if (!selectedModules.every(Boolean)) return false;
190
160
 
191
- // split the chunk into two parts
192
- const newChunk = compilation.addChunk();
193
- newChunk.chunkReason = "aggressive splitted";
194
- for (const chunk of selectedChunks) {
195
- for (const module of selectedModules) {
196
- moveModuleBetween(chunkGraph, chunk, newChunk)(module);
197
- }
198
- chunk.split(newChunk);
199
- chunk.name = /** @type {TODO} */ (null);
200
- }
201
- fromAggressiveSplittingSet.add(newChunk);
202
- chunkSplitDataMap.set(newChunk, splitData);
161
+ // Check if size matches (faster than waiting for hash)
162
+ let size = 0;
163
+ for (const m of selectedModules) size += m.size();
164
+ if (size !== splitData.size) return false;
203
165
 
204
- if (splitData.id !== null && splitData.id !== undefined) {
205
- newChunk.id = splitData.id;
206
- newChunk.ids = [splitData.id];
207
- }
208
- return true;
209
- };
166
+ // get chunks with all modules
167
+ const selectedChunks = intersect(
168
+ selectedModules.map(
169
+ m => new Set(chunkGraph.getModuleChunksIterable(m))
170
+ )
171
+ );
172
+
173
+ // No relevant chunks found
174
+ if (selectedChunks.size === 0) return false;
210
175
 
211
- // try to restore to recorded splitting
212
- let changed = false;
213
- for (let j = 0; j < usedSplits.length; j++) {
214
- const splitData = usedSplits[j];
215
- if (applySplit(splitData)) changed = true;
176
+ // The found chunk is already the split or similar
177
+ if (
178
+ selectedChunks.size === 1 &&
179
+ chunkGraph.getNumberOfChunkModules(
180
+ Array.from(selectedChunks)[0]
181
+ ) === selectedModules.length
182
+ ) {
183
+ const chunk = Array.from(selectedChunks)[0];
184
+ if (fromAggressiveSplittingSet.has(chunk)) return false;
185
+ fromAggressiveSplittingSet.add(chunk);
186
+ chunkSplitDataMap.set(chunk, splitData);
187
+ return true;
216
188
  }
217
189
 
218
- // for any chunk which isn't splitted yet, split it and create a new entry
219
- // start with the biggest chunk
220
- const cmpFn = compareChunks(chunkGraph);
221
- const sortedChunks = Array.from(chunks).sort((a, b) => {
222
- const diff1 =
223
- chunkGraph.getChunkModulesSize(b) -
224
- chunkGraph.getChunkModulesSize(a);
225
- if (diff1) return diff1;
226
- const diff2 =
227
- chunkGraph.getNumberOfChunkModules(a) -
228
- chunkGraph.getNumberOfChunkModules(b);
229
- if (diff2) return diff2;
230
- return cmpFn(a, b);
231
- });
232
- for (const chunk of sortedChunks) {
233
- if (fromAggressiveSplittingSet.has(chunk)) continue;
234
- const size = chunkGraph.getChunkModulesSize(chunk);
235
- if (
236
- size > maxSize &&
237
- chunkGraph.getNumberOfChunkModules(chunk) > 1
238
- ) {
239
- const modules = chunkGraph
240
- .getOrderedChunkModules(chunk, compareModulesByIdentifier)
241
- .filter(isNotAEntryModule(chunkGraph, chunk));
242
- const selectedModules = [];
243
- let selectedModulesSize = 0;
244
- for (let k = 0; k < modules.length; k++) {
245
- const module = modules[k];
246
- const newSize = selectedModulesSize + module.size();
247
- if (newSize > maxSize && selectedModulesSize >= minSize) {
248
- break;
249
- }
250
- selectedModulesSize = newSize;
251
- selectedModules.push(module);
252
- }
253
- if (selectedModules.length === 0) continue;
254
- /** @type {SplitData} */
255
- const splitData = {
256
- modules: selectedModules
257
- .map(m => moduleToNameMap.get(m))
258
- .sort(),
259
- size: selectedModulesSize
260
- };
261
-
262
- if (applySplit(splitData)) {
263
- newSplits = (newSplits || []).concat(splitData);
264
- changed = true;
265
- }
190
+ // split the chunk into two parts
191
+ const newChunk = compilation.addChunk();
192
+ newChunk.chunkReason = "aggressive splitted";
193
+ for (const chunk of selectedChunks) {
194
+ for (const module of selectedModules) {
195
+ moveModuleBetween(chunkGraph, chunk, newChunk)(module);
266
196
  }
197
+ chunk.split(newChunk);
198
+ chunk.name = null;
267
199
  }
268
- if (changed) return true;
269
- }
270
- );
271
- compilation.hooks.recordHash.tap(
272
- "AggressiveSplittingPlugin",
273
- records => {
274
- // 4. save made splittings to records
275
- const allSplits = new Set();
276
- /** @type {Set<SplitData>} */
277
- const invalidSplits = new Set();
278
-
279
- // Check if some splittings are invalid
280
- // We remove invalid splittings and try again
281
- for (const chunk of compilation.chunks) {
282
- const splitData = chunkSplitDataMap.get(chunk);
283
- if (
284
- splitData !== undefined &&
285
- splitData.hash &&
286
- chunk.hash !== splitData.hash
287
- ) {
288
- // Split was successful, but hash doesn't equal
289
- // We can throw away the split since it's useless now
290
- invalidSplits.add(splitData);
291
- }
200
+ fromAggressiveSplittingSet.add(newChunk);
201
+ chunkSplitDataMap.set(newChunk, splitData);
202
+
203
+ if (splitData.id !== null && splitData.id !== undefined) {
204
+ newChunk.id = splitData.id;
205
+ newChunk.ids = [splitData.id];
292
206
  }
207
+ return true;
208
+ };
209
+
210
+ // try to restore to recorded splitting
211
+ let changed = false;
212
+ for (let j = 0; j < usedSplits.length; j++) {
213
+ const splitData = usedSplits[j];
214
+ if (applySplit(splitData)) changed = true;
215
+ }
293
216
 
294
- if (invalidSplits.size > 0) {
295
- records.aggressiveSplits =
296
- /** @type {SplitData[]} */
297
- (records.aggressiveSplits).filter(
298
- splitData => !invalidSplits.has(splitData)
299
- );
300
- needAdditionalSeal = true;
301
- } else {
302
- // set hash and id values on all (new) splittings
303
- for (const chunk of compilation.chunks) {
304
- const splitData = chunkSplitDataMap.get(chunk);
305
- if (splitData !== undefined) {
306
- splitData.hash =
307
- /** @type {NonNullable<Chunk["hash"]>} */
308
- (chunk.hash);
309
- splitData.id =
310
- /** @type {NonNullable<Chunk["id"]>} */
311
- (chunk.id);
312
- allSplits.add(splitData);
313
- // set flag for stats
314
- recordedChunks.add(chunk);
217
+ // for any chunk which isn't splitted yet, split it and create a new entry
218
+ // start with the biggest chunk
219
+ const cmpFn = compareChunks(chunkGraph);
220
+ const sortedChunks = Array.from(chunks).sort((a, b) => {
221
+ const diff1 =
222
+ chunkGraph.getChunkModulesSize(b) -
223
+ chunkGraph.getChunkModulesSize(a);
224
+ if (diff1) return diff1;
225
+ const diff2 =
226
+ chunkGraph.getNumberOfChunkModules(a) -
227
+ chunkGraph.getNumberOfChunkModules(b);
228
+ if (diff2) return diff2;
229
+ return cmpFn(a, b);
230
+ });
231
+ for (const chunk of sortedChunks) {
232
+ if (fromAggressiveSplittingSet.has(chunk)) continue;
233
+ const size = chunkGraph.getChunkModulesSize(chunk);
234
+ if (
235
+ size > maxSize &&
236
+ chunkGraph.getNumberOfChunkModules(chunk) > 1
237
+ ) {
238
+ const modules = chunkGraph
239
+ .getOrderedChunkModules(chunk, compareModulesByIdentifier)
240
+ .filter(isNotAEntryModule(chunkGraph, chunk));
241
+ const selectedModules = [];
242
+ let selectedModulesSize = 0;
243
+ for (let k = 0; k < modules.length; k++) {
244
+ const module = modules[k];
245
+ const newSize = selectedModulesSize + module.size();
246
+ if (newSize > maxSize && selectedModulesSize >= minSize) {
247
+ break;
315
248
  }
249
+ selectedModulesSize = newSize;
250
+ selectedModules.push(module);
316
251
  }
252
+ if (selectedModules.length === 0) continue;
253
+ /** @type {SplitData} */
254
+ const splitData = {
255
+ modules: selectedModules
256
+ .map(m => moduleToNameMap.get(m))
257
+ .sort(),
258
+ size: selectedModulesSize
259
+ };
317
260
 
318
- // Also add all unused historical splits (after the used ones)
319
- // They can still be used in some future compilation
320
- const recordedSplits =
321
- compilation.records && compilation.records.aggressiveSplits;
322
- if (recordedSplits) {
323
- for (const splitData of recordedSplits) {
324
- if (!invalidSplits.has(splitData)) allSplits.add(splitData);
325
- }
261
+ if (applySplit(splitData)) {
262
+ newSplits = (newSplits || []).concat(splitData);
263
+ changed = true;
326
264
  }
265
+ }
266
+ }
267
+ if (changed) return true;
268
+ }
269
+ );
270
+ compilation.hooks.recordHash.tap(PLUGIN_NAME, records => {
271
+ // 4. save made splittings to records
272
+ const allSplits = new Set();
273
+ /** @type {Set<SplitData>} */
274
+ const invalidSplits = new Set();
327
275
 
328
- // record all splits
329
- records.aggressiveSplits = Array.from(allSplits);
276
+ // Check if some splittings are invalid
277
+ // We remove invalid splittings and try again
278
+ for (const chunk of compilation.chunks) {
279
+ const splitData = chunkSplitDataMap.get(chunk);
280
+ if (
281
+ splitData !== undefined &&
282
+ splitData.hash &&
283
+ chunk.hash !== splitData.hash
284
+ ) {
285
+ // Split was successful, but hash doesn't equal
286
+ // We can throw away the split since it's useless now
287
+ invalidSplits.add(splitData);
288
+ }
289
+ }
330
290
 
331
- needAdditionalSeal = false;
291
+ if (invalidSplits.size > 0) {
292
+ records.aggressiveSplits =
293
+ /** @type {SplitData[]} */
294
+ (records.aggressiveSplits).filter(
295
+ splitData => !invalidSplits.has(splitData)
296
+ );
297
+ needAdditionalSeal = true;
298
+ } else {
299
+ // set hash and id values on all (new) splittings
300
+ for (const chunk of compilation.chunks) {
301
+ const splitData = chunkSplitDataMap.get(chunk);
302
+ if (splitData !== undefined) {
303
+ splitData.hash =
304
+ /** @type {NonNullable<Chunk["hash"]>} */
305
+ (chunk.hash);
306
+ splitData.id =
307
+ /** @type {NonNullable<Chunk["id"]>} */
308
+ (chunk.id);
309
+ allSplits.add(splitData);
310
+ // set flag for stats
311
+ recordedChunks.add(chunk);
332
312
  }
333
313
  }
334
- );
335
- compilation.hooks.needAdditionalSeal.tap(
336
- "AggressiveSplittingPlugin",
337
- () => {
338
- if (needAdditionalSeal) {
339
- needAdditionalSeal = false;
340
- return true;
314
+
315
+ // Also add all unused historical splits (after the used ones)
316
+ // They can still be used in some future compilation
317
+ const recordedSplits =
318
+ compilation.records && compilation.records.aggressiveSplits;
319
+ if (recordedSplits) {
320
+ for (const splitData of recordedSplits) {
321
+ if (!invalidSplits.has(splitData)) allSplits.add(splitData);
341
322
  }
342
323
  }
343
- );
344
- }
345
- );
324
+
325
+ // record all splits
326
+ records.aggressiveSplits = Array.from(allSplits);
327
+
328
+ needAdditionalSeal = false;
329
+ }
330
+ });
331
+ compilation.hooks.needAdditionalSeal.tap(PLUGIN_NAME, () => {
332
+ if (needAdditionalSeal) {
333
+ needAdditionalSeal = false;
334
+ return true;
335
+ }
336
+ });
337
+ });
346
338
  }
347
339
  }
348
340
  module.exports = AggressiveSplittingPlugin;
@@ -84,6 +84,7 @@ const {
84
84
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
85
85
  /** @typedef {import("../util/Hash")} Hash */
86
86
  /** @typedef {typeof import("../util/Hash")} HashConstructor */
87
+ /** @typedef {import("../util/concatenate").ScopeInfo} ScopeInfo */
87
88
  /** @typedef {import("../util/concatenate").UsedNames} UsedNames */
88
89
  /** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
89
90
  /** @typedef {import("../util/identifier").AssociatedObjectForCache} AssociatedObjectForCache */
@@ -1138,13 +1139,8 @@ class ConcatenatedModule extends Module {
1138
1139
  const topLevelDeclarations = new Set();
1139
1140
 
1140
1141
  // List of additional names in scope for module references
1141
- /** @type {Map<string, { usedNames: UsedNames, alreadyCheckedScopes: Set<TODO> }>} */
1142
+ /** @type {Map<string, ScopeInfo>} */
1142
1143
  const usedNamesInScopeInfo = new Map();
1143
- /**
1144
- * @param {string} module module identifier
1145
- * @param {string} id export id
1146
- * @returns {{ usedNames: UsedNames, alreadyCheckedScopes: Set<TODO> }} info
1147
- */
1148
1144
 
1149
1145
  // Set of already checked scopes
1150
1146
  const ignoredScopes = new Set();
@@ -1163,7 +1159,7 @@ class ConcatenatedModule extends Module {
1163
1159
  const superClassCache = new WeakMap();
1164
1160
  /**
1165
1161
  * @param {Scope} scope scope
1166
- * @returns {TODO} result
1162
+ * @returns {{ range: Range, variables: Variable[] }[]} result
1167
1163
  */
1168
1164
  const getSuperClassExpressions = scope => {
1169
1165
  const cacheEntry = superClassCache.get(scope);
@@ -1178,7 +1174,7 @@ class ConcatenatedModule extends Module {
1178
1174
  block.superClass
1179
1175
  ) {
1180
1176
  superClassExpressions.push({
1181
- range: block.superClass.range,
1177
+ range: /** @type {Range} */ (block.superClass.range),
1182
1178
  variables: childScope.variables
1183
1179
  });
1184
1180
  }
@@ -1428,9 +1424,9 @@ class ConcatenatedModule extends Module {
1428
1424
  /** @type {Set<string>} */
1429
1425
  const unusedExports = new Set();
1430
1426
 
1431
- const rootInfo = /** @type {ConcatenatedModuleInfo} */ (
1432
- moduleToInfoMap.get(this.rootModule)
1433
- );
1427
+ const rootInfo =
1428
+ /** @type {ConcatenatedModuleInfo} */
1429
+ (moduleToInfoMap.get(this.rootModule));
1434
1430
  const strictHarmonyModule =
1435
1431
  /** @type {BuildMeta} */
1436
1432
  (rootInfo.module.buildMeta).strictHarmonyModule;
@@ -1632,7 +1628,8 @@ ${defineGetters}`
1632
1628
  );
1633
1629
  runtimeRequirements.add(RuntimeGlobals.require);
1634
1630
  const { runtimeCondition } =
1635
- /** @type {ExternalModuleInfo | ReferenceToModuleInfo} */ (rawInfo);
1631
+ /** @type {ExternalModuleInfo | ReferenceToModuleInfo} */
1632
+ (rawInfo);
1636
1633
  const condition = runtimeTemplate.runtimeConditionExpression({
1637
1634
  chunkGraph,
1638
1635
  runtimeCondition,
@@ -1730,9 +1727,9 @@ ${defineGetters}`
1730
1727
  codeGenerationResults,
1731
1728
  sourceTypes: JS_TYPES
1732
1729
  });
1733
- const source = /** @type {Source} */ (
1734
- codeGenResult.sources.get("javascript")
1735
- );
1730
+ const source =
1731
+ /** @type {Source} */
1732
+ (codeGenResult.sources.get("javascript"));
1736
1733
  const data = codeGenResult.data;
1737
1734
  const chunkInitFragments = data && data.get("chunkInitFragments");
1738
1735
  const code = source.source().toString();
@@ -1742,7 +1739,9 @@ ${defineGetters}`
1742
1739
  sourceType: "module"
1743
1740
  });
1744
1741
  } catch (_err) {
1745
- const err = /** @type {TODO} */ (_err);
1742
+ const err =
1743
+ /** @type {Error & { loc?: { line: number, column: number } }} */
1744
+ (_err);
1746
1745
  if (
1747
1746
  err.loc &&
1748
1747
  typeof err.loc === "object" &&