/** * earth-now.co * Author: Simon-Pierre Boucher * Contact: contact@spboucher.ai * File: packages/widget/scripts/check-size.mjs * Purpose: Build gate — fail the widget build if dist/widget.js exceeds the 15 KB gzip budget */ import { readFileSync } from "node:fs"; import { gzipSync } from "node:zlib"; const LIMIT_BYTES = 15 * 1024; const bundlePath = new URL("../dist/widget.js", import.meta.url); let raw; try { raw = readFileSync(bundlePath); } catch { console.error("✗ check-size: dist/widget.js not found — run the esbuild step first"); process.exit(1); } const gzipped = gzipSync(raw, { level: 9 }).length; console.log( `widget.js: ${raw.length} B raw, ${gzipped} B gzip (budget ${LIMIT_BYTES} B gzip)`, ); if (gzipped > LIMIT_BYTES) { console.error( `✗ widget.js is ${gzipped - LIMIT_BYTES} B over the 15 KB gzip budget — trim it before shipping`, ); process.exit(1); } console.log("✓ widget.js is within the 15 KB gzip budget");