diff --git a/scripts/bundle-budget.mjs b/scripts/bundle-budget.mjs index e1ba0ddc..e7523f29 100644 --- a/scripts/bundle-budget.mjs +++ b/scripts/bundle-budget.mjs @@ -3,7 +3,16 @@ import { readFileSync } from 'node:fs'; import { resolve } from 'node:path'; import { pathToFileURL } from 'node:url'; -export const INITIAL_VIEW_GZIP_BUDGET = 256_000; +// #352: the budget guards the CLASS of regression — tens of kilobytes from +// an accidentally imported dependency or an eagerly bundled dictionary — +// not every byte. v1.69.0-beta.1 shipped at 255 993 B gzip against a +// 256 000 B ceiling: seven bytes of headroom turned the gate into a +// lottery where the unlucky LAST commit goes red, not the one that grew +// the bundle (5740324b was exactly that). The ceiling therefore keeps a +// deliberate ~10% allowance over the measured fact; the fact and headroom +// are printed on every run so the trend is visible long before the wall. +// Measured fact at calibration (v1.69.0-beta.1): 255 993 B gzip. +export const INITIAL_VIEW_GZIP_BUDGET = 282_000; export function assertBundleBudget(manifest, budget = INITIAL_VIEW_GZIP_BUDGET) { if (manifest?.schema !== 1 || !Array.isArray(manifest.files)) { @@ -41,9 +50,25 @@ if (import.meta.url === pathToFileURL(process.argv[1] || '').href) { try { const manifest = JSON.parse(readFileSync(resolve('dist/houseplan-assets.json'), 'utf8')); const result = assertBundleBudget(manifest); - console.log(`initial View: ${result.initialViewGzipBytes} B gzip`); - console.log(`lazy editor: ${result.lazyEditorGzipBytes} B gzip`); - console.log(`lazy locale: ${result.lazyLocaleGzipBytes} B gzip`); + const headroom = INITIAL_VIEW_GZIP_BUDGET - result.initialViewGzipBytes; + const lines = [ + `initial View: ${result.initialViewGzipBytes} B gzip` + + ` (budget ${INITIAL_VIEW_GZIP_BUDGET} B, headroom ${headroom} B)`, + `lazy editor: ${result.lazyEditorGzipBytes} B gzip`, + `lazy locale: ${result.lazyLocaleGzipBytes} B gzip`, + ]; + for (const line of lines) console.log(line); + // #352: the trend belongs where humans look — the run summary. + if (process.env.GITHUB_STEP_SUMMARY) { + const { appendFileSync } = await import('node:fs'); + appendFileSync(process.env.GITHUB_STEP_SUMMARY, [ + '### Бюджет бандла', + `| граф | gzip | бюджет | запас |`, + `|---|---|---|---|`, + `| initial View | ${result.initialViewGzipBytes} B | ${INITIAL_VIEW_GZIP_BUDGET} B | ${headroom} B |`, + '', + ].join('\n')); + } } catch (error) { console.error(error instanceof Error ? error.message : String(error)); process.exit(1);