UNPKG

922 BJavaScriptView Raw
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const Entrypoint = require("../Entrypoint");
9
10/** @typedef {import("../Chunk")} Chunk */
11
12/**
13 * @param {Entrypoint} entrypoint a chunk group
14 * @param {Chunk} excludedChunk1 current chunk which is excluded
15 * @param {Chunk} excludedChunk2 runtime chunk which is excluded
16 * @returns {Set<Chunk>} chunks
17 */
18const getAllChunks = (entrypoint, excludedChunk1, excludedChunk2) => {
19 const queue = new Set([entrypoint]);
20 const chunks = new Set();
21 for (const entrypoint of queue) {
22 for (const chunk of entrypoint.chunks) {
23 if (chunk === excludedChunk1) continue;
24 if (chunk === excludedChunk2) continue;
25 chunks.add(chunk);
26 }
27 for (const parent of entrypoint.parentsIterable) {
28 if (parent instanceof Entrypoint) queue.add(parent);
29 }
30 }
31 return chunks;
32};
33exports.getAllChunks = getAllChunks;