|
6 | 6 |
|
7 | 7 | const util = require("util"); |
8 | 8 | const SortableSet = require("./util/SortableSet"); |
| 9 | +const intersect = require("./util/SetHelpers").intersect; |
9 | 10 | const GraphHelpers = require("./GraphHelpers"); |
10 | 11 | let debugId = 1000; |
11 | 12 | const ERR_CHUNK_ENTRY = "Chunk.entry was removed. Use hasRuntime()"; |
@@ -170,8 +171,8 @@ class Chunk { |
170 | 171 | if (aItem.done) return 0; |
171 | 172 | const aModuleIdentifier = aItem.value.identifier(); |
172 | 173 | const bModuleIdentifier = bItem.value.identifier(); |
173 | | - if (aModuleIdentifier > bModuleIdentifier) return -1; |
174 | | - if (aModuleIdentifier < bModuleIdentifier) return 1; |
| 174 | + if (aModuleIdentifier < bModuleIdentifier) return -1; |
| 175 | + if (aModuleIdentifier > bModuleIdentifier) return 1; |
175 | 176 | } |
176 | 177 | } |
177 | 178 |
|
@@ -321,12 +322,15 @@ class Chunk { |
321 | 322 | } |
322 | 323 |
|
323 | 324 | getAllAsyncChunks() { |
324 | | - const initialChunks = new Set(); |
325 | | - const queue = new Set(this.groupsIterable); |
| 325 | + const queue = new Set(); |
326 | 326 | const chunks = new Set(); |
327 | 327 |
|
328 | | - for (const chunkGroup of queue) { |
329 | | - for (const chunk of chunkGroup.chunks) initialChunks.add(chunk); |
| 328 | + const initialChunks = intersect( |
| 329 | + Array.from(this.groupsIterable, g => new Set(g.chunks)) |
| 330 | + ); |
| 331 | + |
| 332 | + for (const chunkGroup of this.groupsIterable) { |
| 333 | + for (const child of chunkGroup.childrenIterable) queue.add(child); |
330 | 334 | } |
331 | 335 |
|
332 | 336 | for (const chunkGroup of queue) { |
@@ -361,6 +365,62 @@ class Chunk { |
361 | 365 | }; |
362 | 366 | } |
363 | 367 |
|
| 368 | + getChildIdsByOrders() { |
| 369 | + const lists = new Map(); |
| 370 | + for (const group of this.groupsIterable) { |
| 371 | + if (group.chunks[group.chunks.length - 1] === this) { |
| 372 | + for (const childGroup of group.childrenIterable) { |
| 373 | + // TODO webpack 5 remove this check for options |
| 374 | + if (typeof childGroup.options === "object") { |
| 375 | + for (const key of Object.keys(childGroup.options)) { |
| 376 | + if (key.endsWith("Order")) { |
| 377 | + const name = key.substr(0, key.length - "Order".length); |
| 378 | + let list = lists.get(name); |
| 379 | + if (list === undefined) lists.set(name, (list = [])); |
| 380 | + list.push({ |
| 381 | + order: childGroup.options[key], |
| 382 | + group: childGroup |
| 383 | + }); |
| 384 | + } |
| 385 | + } |
| 386 | + } |
| 387 | + } |
| 388 | + } |
| 389 | + } |
| 390 | + const result = Object.create(null); |
| 391 | + for (const [name, list] of lists) { |
| 392 | + list.sort((a, b) => { |
| 393 | + const cmp = b.order - a.order; |
| 394 | + if (cmp !== 0) return cmp; |
| 395 | + // TOOD webpack 5 remove this check of compareTo |
| 396 | + if (a.group.compareTo) return a.group.compareTo(b.group); |
| 397 | + return 0; |
| 398 | + }); |
| 399 | + result[name] = Array.from( |
| 400 | + list.reduce((set, item) => { |
| 401 | + for (const chunk of item.group.chunks) set.add(chunk.id); |
| 402 | + return set; |
| 403 | + }, new Set()) |
| 404 | + ); |
| 405 | + } |
| 406 | + return result; |
| 407 | + } |
| 408 | + |
| 409 | + getChildIdsByOrdersMap() { |
| 410 | + const chunkMaps = Object.create(null); |
| 411 | + |
| 412 | + for (const chunk of this.getAllAsyncChunks()) { |
| 413 | + const data = chunk.getChildIdsByOrders(); |
| 414 | + for (const key of Object.keys(data)) { |
| 415 | + let chunkMap = chunkMaps[key]; |
| 416 | + if (chunkMap === undefined) |
| 417 | + chunkMaps[key] = chunkMap = Object.create(null); |
| 418 | + chunkMap[chunk.id] = data[key]; |
| 419 | + } |
| 420 | + } |
| 421 | + return chunkMaps; |
| 422 | + } |
| 423 | + |
364 | 424 | getChunkModuleMaps(filterFn) { |
365 | 425 | const chunkModuleIdMap = Object.create(null); |
366 | 426 | const chunkModuleHashMap = Object.create(null); |
|
0 commit comments