Skip to content

Commit

Permalink
checkForFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
sowtame committed Oct 6, 2023
1 parent 742698e commit eab0ac2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
6 changes: 3 additions & 3 deletions webpack-subresource-integrity/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
allChunksInChunkIterable,
allChunksInPrimaryChunkIterable,
sriHashVariableReference,
wmfSharedChunk,
checkForFiles,
} from "./util";
import { createDAGfromGraph } from "./scc";
import { RuntimeModule, Template, Chunk } from "webpack";
Expand Down Expand Up @@ -53,13 +53,13 @@ function buildTopologicallySortedChunkGraph(

// Chunks should have *all* chunks, not simply entry chunks
for (const vertex of chunks) {
if (wmfSharedChunk(vertex) || addIfNotExist(vertices, vertex)) {
if (checkForFiles(vertex) || addIfNotExist(vertices, vertex)) {
continue;
}

edges.set(vertex, new Set<Chunk>());
for (const childChunk of allChunksInChunkIterable(vertex)) {
if (!wmfSharedChunk(childChunk)) {
if (!checkForFiles(childChunk)) {
edges.get(vertex)?.add(childChunk);
}
}
Expand Down
8 changes: 3 additions & 5 deletions webpack-subresource-integrity/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,8 @@ export function addIfNotExist<T>(set: Set<T>, item: T): boolean {
set.add(item);
return false;
}
export function wmfSharedChunk(chunk: Chunk): boolean {
return Boolean(
chunk.chunkReason?.includes("split chunk (cache group: default)")
);
export function checkForFiles(chunk: Chunk): boolean {
return chunk.files?.size === 0;
}

export function findChunks(chunk: Chunk): Set<Chunk> {
Expand All @@ -104,7 +102,7 @@ export function findChunks(chunk: Chunk): Set<Chunk> {
group.childrenIterable.forEach(recurseGroup);
}

if (wmfSharedChunk(childChunk) || addIfNotExist(allChunks, childChunk)) {
if (checkForFiles(childChunk) || addIfNotExist(allChunks, childChunk)) {
return;
}
Array.from(childChunk.groupsIterable).forEach(recurseGroup);
Expand Down

0 comments on commit eab0ac2

Please sign in to comment.