| 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 Entrypoint = require("../Entrypoint");
|
|---|
| 9 |
|
|---|
| 10 | /** @typedef {import("../Chunk")} Chunk */
|
|---|
| 11 |
|
|---|
| 12 | /**
|
|---|
| 13 | * Returns chunks.
|
|---|
| 14 | * @param {Entrypoint} entrypoint a chunk group
|
|---|
| 15 | * @param {(Chunk | null)=} excludedChunk1 current chunk which is excluded
|
|---|
| 16 | * @param {(Chunk | null)=} excludedChunk2 runtime chunk which is excluded
|
|---|
| 17 | * @returns {Set<Chunk>} chunks
|
|---|
| 18 | */
|
|---|
| 19 | const getAllChunks = (entrypoint, excludedChunk1, excludedChunk2) => {
|
|---|
| 20 | /** @type {Set<Entrypoint>} */
|
|---|
| 21 | const queue = new Set([entrypoint]);
|
|---|
| 22 | /** @type {Set<Entrypoint>} */
|
|---|
| 23 | const groups = new Set();
|
|---|
| 24 | for (const group of queue) {
|
|---|
| 25 | if (group !== entrypoint) {
|
|---|
| 26 | groups.add(group);
|
|---|
| 27 | }
|
|---|
| 28 | for (const parent of group.parentsIterable) {
|
|---|
| 29 | if (parent instanceof Entrypoint) queue.add(parent);
|
|---|
| 30 | }
|
|---|
| 31 | }
|
|---|
| 32 | groups.add(entrypoint);
|
|---|
| 33 |
|
|---|
| 34 | /** @type {Set<Chunk>} */
|
|---|
| 35 | const chunks = new Set();
|
|---|
| 36 | for (const group of groups) {
|
|---|
| 37 | for (const chunk of group.chunks) {
|
|---|
| 38 | if (chunk === excludedChunk1) continue;
|
|---|
| 39 | if (chunk === excludedChunk2) continue;
|
|---|
| 40 | chunks.add(chunk);
|
|---|
| 41 | }
|
|---|
| 42 | }
|
|---|
| 43 | return chunks;
|
|---|
| 44 | };
|
|---|
| 45 |
|
|---|
| 46 | module.exports.getAllChunks = getAllChunks;
|
|---|