Skip to content

Commit

Permalink
rename arg and add in better comment
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholas-codecov committed Dec 3, 2024
1 parent 3600d3e commit 0ddd647
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ export interface ProcessChunksArgs {
}

export const processChunks = ({ chunks, chunkIdMap }: ProcessChunksArgs) => {
const chunkMap = new Map<PropertyKey, StatsChunk>();

// need to collect all possible chunk ids beforehand so we can use them to
// collect the dynamic imports
// need a reference of all chunks by their id so we can use it to collect
// the dynamic imports from the children chunks without having to search
// through the entire list of chunks every time
const referenceChunkMapById = new Map<PropertyKey, StatsChunk>();
chunks.forEach((chunk) => {
if (chunk.id) {
chunkMap.set(chunk.id.toString(), chunk);
referenceChunkMapById.set(chunk.id.toString(), chunk);
}
});

Expand All @@ -25,7 +25,7 @@ export const processChunks = ({ chunks, chunkIdMap }: ProcessChunksArgs) => {
const dynamicImports: string[] = [];
chunk.children?.forEach((child) => {
const childIdString = child.toString();
const childChunk = chunkMap.get(childIdString);
const childChunk = referenceChunkMapById.get(childIdString);

if (!childChunk || !childChunk.files) {
red(`Child chunk ${childIdString} not found in chunkMap`);
Expand Down

0 comments on commit 0ddd647

Please sign in to comment.