Skip to content

Commit 4e0952a

Browse files
committed
Output largest inputs
1 parent 47f1709 commit 4e0952a

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

pr-checks/bundle-metadata.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,41 @@ import * as fs from "node:fs/promises";
44

55
import { BUNDLE_METADATA_FILE } from "./config";
66

7+
interface InputInfo {
8+
bytesInOutput: number;
9+
}
10+
11+
type Inputs = Record<string, InputInfo>;
12+
713
interface Output {
814
bytes: number;
15+
inputs: Inputs;
916
}
1017

1118
interface Metadata {
1219
outputs: Output[];
1320
}
1421

22+
function toMB(bytes: number): string {
23+
return `${(bytes / (1024 * 1024)).toFixed(2)}MB`;
24+
}
25+
1526
async function main() {
1627
const fileContents = await fs.readFile(BUNDLE_METADATA_FILE);
1728
const metadata = JSON.parse(String(fileContents)) as Metadata;
1829

1930
for (const [outputFile, outputData] of Object.entries(
2031
metadata.outputs,
2132
).reverse()) {
22-
console.info(
23-
`${outputFile}: ${(outputData.bytes / (1024 * 1024)).toFixed(2)}MB`,
24-
);
33+
console.info(`${outputFile}: ${toMB(outputData.bytes)}`);
34+
35+
for (const [inputName, inputData] of Object.entries(outputData.inputs)) {
36+
// Ignore any inputs that make up less than 5% of the output.
37+
const percentage = (inputData.bytesInOutput / outputData.bytes) * 100.0;
38+
if (percentage < 5.0) continue;
39+
40+
console.info(` ${inputName}: ${toMB(inputData.bytesInOutput)}`);
41+
}
2542
}
2643
}
2744

0 commit comments

Comments
 (0)