library
Prebuilt pebble components: drop-in custom elements, no compiler needed
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runAucun
0Étoiles
0Forks
2Issues
| 1 | /** |
| 2 | * Release-size table: the floor (an empty component, everything a bundle pays |
| 3 | * before its first feature) and each package's prebuilt bundle. Prints JSON |
| 4 | * for test/size.test.ts; the README quotes it. |
| 5 | * |
| 6 | * bun run scripts/sizes.ts # human-readable table |
| 7 | * bun run scripts/sizes.ts --json # machine-readable |
| 8 | * |
| 9 | * Always run in its own process: inside `bun test`, Bun.build reuses the test |
| 10 | * runtime's CommonJS resolutions and inflates every number. |
| 11 | */ |
| 12 | import { brotliCompressSync, gzipSync } from "node:zlib"; |
| 13 | import { discoverPackages, writeEntryShim } from "./packages"; |
| 14 | import { buildRelease } from "./release"; |
| 15 | |
| 16 | const DIR = `${import.meta.dir}/../.size-fixtures`; |
| 17 | |
| 18 | /** The floor: an empty component through the consumer compiler, pebble bundled in. */ |
| 19 | const FLOOR = `import { define } from "@pebble/pebble"; define("x-a", {}, () => <span>hi</span>);`; |
| 20 | |
| 21 | async function measure(entry: string) { |
| 22 | const code = await buildRelease(entry); |
| 23 | return { gz: gzipSync(code).byteLength, br: brotliCompressSync(code).byteLength }; |
| 24 | } |
| 25 | |
| 26 | const floorFile = `${DIR}/floor.tsx`; |
| 27 | await Bun.write(floorFile, FLOOR); |
| 28 | const floor = await measure(floorFile); |
| 29 | |
| 30 | const packages: Record<string, { gz: number; br: number; delta: number }> = {}; |
| 31 | for (const pkg of await discoverPackages()) { |
| 32 | const row = await measure(await writeEntryShim(pkg)); |
| 33 | packages[pkg.name] = { ...row, delta: row.gz - floor.gz }; |
| 34 | } |
| 35 | |
| 36 | const report = { floor, packages }; |
| 37 | if (process.argv.includes("--json")) { |
| 38 | console.log(JSON.stringify(report)); |
| 39 | } else { |
| 40 | console.log("component gz br Δ over floor"); |
| 41 | console.log("floor (empty component)".padEnd(26), String(floor.gz).padStart(5), String(floor.br).padStart(6)); |
| 42 | for (const [name, r] of Object.entries(packages)) { |
| 43 | console.log(name.padEnd(26), String(r.gz).padStart(5), String(r.br).padStart(6), String(r.delta).padStart(8)); |
| 44 | } |
| 45 | } |