Skip to content

Commit 47f1709

Browse files
committed
Add basic metadata analysis script
1 parent b1981a5 commit 47f1709

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"description": "CodeQL action",
66
"scripts": {
77
"_build_comment": "echo 'Run the full build so we typecheck the project and can reuse the transpiled files in npm test'",
8-
"build": "./scripts/check-node-modules.sh && npm run transpile && node build.mjs",
8+
"build": "./scripts/check-node-modules.sh && npm run transpile && node build.mjs && npx tsx ./pr-checks/bundle-metadata.ts",
99
"lint": "eslint --report-unused-disable-directives --max-warnings=0 .",
1010
"lint-ci": "SARIF_ESLINT_IGNORE_SUPPRESSED=true eslint --report-unused-disable-directives --max-warnings=0 . --format @microsoft/eslint-formatter-sarif --output-file=eslint.sarif",
1111
"lint-fix": "eslint --report-unused-disable-directives --max-warnings=0 . --fix",

pr-checks/bundle-metadata.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env npx tsx
2+
3+
import * as fs from "node:fs/promises";
4+
5+
import { BUNDLE_METADATA_FILE } from "./config";
6+
7+
interface Output {
8+
bytes: number;
9+
}
10+
11+
interface Metadata {
12+
outputs: Output[];
13+
}
14+
15+
async function main() {
16+
const fileContents = await fs.readFile(BUNDLE_METADATA_FILE);
17+
const metadata = JSON.parse(String(fileContents)) as Metadata;
18+
19+
for (const [outputFile, outputData] of Object.entries(
20+
metadata.outputs,
21+
).reverse()) {
22+
console.info(
23+
`${outputFile}: ${(outputData.bytes / (1024 * 1024)).toFixed(2)}MB`,
24+
);
25+
}
26+
}
27+
28+
// Only call `main` if this script was run directly.
29+
if (require.main === module) {
30+
void main();
31+
}

pr-checks/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ export const PR_CHECKS_DIR = __dirname;
88

99
/** The path of the file configuring which checks shouldn't be required. */
1010
export const PR_CHECK_EXCLUDED_FILE = path.join(PR_CHECKS_DIR, "excluded.yml");
11+
12+
/** The path to the esbuild metadata file. */
13+
export const BUNDLE_METADATA_FILE = path.join(PR_CHECKS_DIR, "..", "meta.json");

0 commit comments

Comments
 (0)