* Gets child ids by orders. * @param {ChunkGraph} chunkGraph the chunk graph * @param {ChunkFilterPredicate=} filterFn function used to filter chunks * @returns {Record<string, ChunkId[]>} a record object of names to lists of child ids(?)
(chunkGraph, filterFn)
| 793 | * @returns {Record<string, ChunkId[]>} a record object of names to lists of child ids(?) |
| 794 | */ |
| 795 | getChildIdsByOrders(chunkGraph, filterFn) { |
| 796 | /** @type {Map<string, { order: number, group: ChunkGroup }[]>} */ |
| 797 | const lists = new Map(); |
| 798 | for (const group of this.groupsIterable) { |
| 799 | if (group.chunks[group.chunks.length - 1] === this) { |
| 800 | for (const childGroup of group.childrenIterable) { |
| 801 | const edgeOptions = group.getChildOrderOptions( |
| 802 | childGroup, |
| 803 | chunkGraph |
| 804 | ); |
| 805 | for (const key of Object.keys(edgeOptions)) { |
| 806 | const name = key.slice(0, key.length - "Order".length); |
| 807 | let list = lists.get(name); |
| 808 | if (list === undefined) { |
| 809 | list = []; |
| 810 | lists.set(name, list); |
| 811 | } |
| 812 | list.push({ |
| 813 | order: edgeOptions[key], |
| 814 | group: childGroup |
| 815 | }); |
| 816 | } |
| 817 | } |
| 818 | } |
| 819 | } |
| 820 | /** @type {Record<string, ChunkId[]>} */ |
| 821 | const result = Object.create(null); |
| 822 | for (const [name, list] of lists) { |
| 823 | list.sort((a, b) => { |
| 824 | const cmp = b.order - a.order; |
| 825 | if (cmp !== 0) return cmp; |
| 826 | return a.group.compareTo(chunkGraph, b.group); |
| 827 | }); |
| 828 | /** @type {Set<ChunkId>} */ |
| 829 | const chunkIdSet = new Set(); |
| 830 | for (const item of list) { |
| 831 | for (const chunk of item.group.chunks) { |
| 832 | if (filterFn && !filterFn(chunk, chunkGraph)) continue; |
| 833 | chunkIdSet.add(/** @type {ChunkId} */ (chunk.id)); |
| 834 | } |
| 835 | } |
| 836 | if (chunkIdSet.size > 0) { |
| 837 | result[name] = [...chunkIdSet]; |
| 838 | } |
| 839 | } |
| 840 | return result; |
| 841 | } |
| 842 | |
| 843 | /** |
| 844 | * Gets children of type in order. |
no test coverage detected