ChunkHelpers.js 1.2 KB

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