mirror of
https://github.com/Zakkaus/doona.git
synced 2026-12-06 08:02:04 +00:00
check:size --json writes each budget's worst entry and its largest parts. The check job keeps that file as the size-report artifact on every run, main's included, and writes the table to the run summary. report.yml runs after Check from the default branch's code, reads the artifact, compares it with main's measurement for the pull request's base commit (else the newest one main has, labelled as such) and keeps one comment per pull request up to date. CONTRIBUTING.md now says the limits are fixed ceilings and raising one is a separate decision.
29 lines
1.7 KiB
JavaScript
29 lines
1.7 KiB
JavaScript
import {readdir, readFile, writeFile} from 'node:fs/promises';
|
|
import {parseArgs} from 'node:util';
|
|
import {gzipSync} from 'node:zlib';
|
|
import {checkLimits, evaluate, measure, report, totals} from './size-budget.mjs';
|
|
import {summarize} from './size-report.mjs';
|
|
|
|
// --json <path> also writes the measurement for the size report; --commit and --base name the commit measured and main's commit under it.
|
|
const {values: options} = parseArgs({options: {json: {type: 'string'}, commit: {type: 'string'}, base: {type: 'string'}}});
|
|
|
|
const {sizeBudget} = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf8'));
|
|
checkLimits(sizeBudget);
|
|
const dist = new URL('../dist/', import.meta.url);
|
|
const sizes = new Map();
|
|
const files = (await readdir(new URL('assets/', dist))).filter(file => /\.(js|css)$/.test(file));
|
|
if (!files.some(file => file.endsWith('.js'))) throw new Error('No JS assets; run pnpm build first.');
|
|
for (const file of files) sizes.set(`assets/${file}`, gzipSync(await readFile(new URL(`assets/${file}`, dist))).length);
|
|
const manifest = JSON.parse(await readFile(new URL('.vite/manifest.json', dist), 'utf8'));
|
|
const size = file => {
|
|
if (!sizes.has(file)) throw new Error(`Missing built asset: ${file}`);
|
|
return sizes.get(file);
|
|
};
|
|
|
|
const results = evaluate(measure(manifest, size), sizeBudget);
|
|
for (const result of results) console.log(report(result));
|
|
const total = totals(sizes);
|
|
console.log(`total (information only): js ${total.js} bytes gzip, css ${total.css} bytes gzip, ${sizes.size} files`);
|
|
if (options.json) await writeFile(options.json, `${JSON.stringify(summarize(results, total, options), null, 2)}\n`);
|
|
if (results.some(({ok}) => !ok)) process.exitCode = 1;
|