ChunkHelpers.js 942 B

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