From 47f1709a3c85a31013a3c4e5e131e722cc4cc39f Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Fri, 27 Mar 2026 18:18:08 +0000 Subject: [PATCH] Add basic metadata analysis script --- package.json | 2 +- pr-checks/bundle-metadata.ts | 31 +++++++++++++++++++++++++++++++ pr-checks/config.ts | 3 +++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100755 pr-checks/bundle-metadata.ts diff --git a/package.json b/package.json index e4a80d1bd..b76677e46 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "description": "CodeQL action", "scripts": { "_build_comment": "echo 'Run the full build so we typecheck the project and can reuse the transpiled files in npm test'", - "build": "./scripts/check-node-modules.sh && npm run transpile && node build.mjs", + "build": "./scripts/check-node-modules.sh && npm run transpile && node build.mjs && npx tsx ./pr-checks/bundle-metadata.ts", "lint": "eslint --report-unused-disable-directives --max-warnings=0 .", "lint-ci": "SARIF_ESLINT_IGNORE_SUPPRESSED=true eslint --report-unused-disable-directives --max-warnings=0 . --format @microsoft/eslint-formatter-sarif --output-file=eslint.sarif", "lint-fix": "eslint --report-unused-disable-directives --max-warnings=0 . --fix", diff --git a/pr-checks/bundle-metadata.ts b/pr-checks/bundle-metadata.ts new file mode 100755 index 000000000..1e7585536 --- /dev/null +++ b/pr-checks/bundle-metadata.ts @@ -0,0 +1,31 @@ +#!/usr/bin/env npx tsx + +import * as fs from "node:fs/promises"; + +import { BUNDLE_METADATA_FILE } from "./config"; + +interface Output { + bytes: number; +} + +interface Metadata { + outputs: Output[]; +} + +async function main() { + const fileContents = await fs.readFile(BUNDLE_METADATA_FILE); + const metadata = JSON.parse(String(fileContents)) as Metadata; + + for (const [outputFile, outputData] of Object.entries( + metadata.outputs, + ).reverse()) { + console.info( + `${outputFile}: ${(outputData.bytes / (1024 * 1024)).toFixed(2)}MB`, + ); + } +} + +// Only call `main` if this script was run directly. +if (require.main === module) { + void main(); +} diff --git a/pr-checks/config.ts b/pr-checks/config.ts index 7f2826d59..253843f22 100644 --- a/pr-checks/config.ts +++ b/pr-checks/config.ts @@ -8,3 +8,6 @@ export const PR_CHECKS_DIR = __dirname; /** The path of the file configuring which checks shouldn't be required. */ export const PR_CHECK_EXCLUDED_FILE = path.join(PR_CHECKS_DIR, "excluded.yml"); + +/** The path to the esbuild metadata file. */ +export const BUNDLE_METADATA_FILE = path.join(PR_CHECKS_DIR, "..", "meta.json");