/** * Release-size table: the floor (an empty component, everything a bundle pays * before its first feature) and each package's prebuilt bundle. Prints JSON * for test/size.test.ts; the README quotes it. * * bun run scripts/sizes.ts # human-readable table * bun run scripts/sizes.ts --json # machine-readable * * Always run in its own process: inside `bun test`, Bun.build reuses the test * runtime's CommonJS resolutions and inflates every number. */ import { brotliCompressSync, gzipSync } from "node:zlib"; import { discoverPackages, writeEntryShim } from "./packages"; import { buildRelease } from "./release"; const DIR = `${import.meta.dir}/../.size-fixtures`; /** The floor: an empty component through the consumer compiler, pebble bundled in. */ const FLOOR = `import { define } from "@pebble/pebble"; define("x-a", {}, () => hi);`; async function measure(entry: string) { const code = await buildRelease(entry); return { gz: gzipSync(code).byteLength, br: brotliCompressSync(code).byteLength }; } const floorFile = `${DIR}/floor.tsx`; await Bun.write(floorFile, FLOOR); const floor = await measure(floorFile); const packages: Record = {}; for (const pkg of await discoverPackages()) { const row = await measure(await writeEntryShim(pkg)); packages[pkg.name] = { ...row, delta: row.gz - floor.gz }; } const report = { floor, packages }; if (process.argv.includes("--json")) { console.log(JSON.stringify(report)); } else { console.log("component gz br Δ over floor"); console.log("floor (empty component)".padEnd(26), String(floor.gz).padStart(5), String(floor.br).padStart(6)); for (const [name, r] of Object.entries(packages)) { console.log(name.padEnd(26), String(r.gz).padStart(5), String(r.br).padStart(6), String(r.delta).padStart(8)); } }