fix: bind performance evidence to production resources
This commit is contained in:
@@ -10,10 +10,13 @@ import {
|
||||
classifyArtifact,
|
||||
evaluateBudgetTotals,
|
||||
evaluateMediaAssetBudget,
|
||||
evaluateRuntimeBudgetEvidence,
|
||||
validateRuntimeBudgetTraceReport,
|
||||
} from './lib/bundle-budgets.mjs';
|
||||
|
||||
const root = resolve(process.argv[2] ?? 'dist');
|
||||
const runtimeTraceIndex = process.argv.indexOf('--runtime-trace');
|
||||
const runtimeTracePath = runtimeTraceIndex === -1 ? null : process.argv[runtimeTraceIndex + 1];
|
||||
if (runtimeTraceIndex !== -1 && runtimeTracePath === undefined) throw new Error('--runtime-trace requires one explicit drive-trace JSON path.');
|
||||
if (!(await stat(root)).isDirectory()) throw new Error('Bundle budget target must be a directory.');
|
||||
|
||||
const listFiles = async (directory) => {
|
||||
@@ -38,7 +41,6 @@ const readJson = async (path, label) => {
|
||||
|
||||
const manifest = await readJson(resolve('content/public/asset-manifest.json'), 'Public asset manifest');
|
||||
const content = await readJson(resolve('content/public/portfolio-content.json'), 'Portfolio content');
|
||||
const runtimeEvidence = await readJson(resolve('config/performance-budget-evidence.json'), 'Runtime budget evidence');
|
||||
if (!Array.isArray(manifest?.assets)) throw new Error('Public asset manifest is invalid.');
|
||||
|
||||
const assetClassById = new Map();
|
||||
@@ -118,13 +120,17 @@ const entrySource = await readFile(resolve(root, entry.path), 'utf8');
|
||||
if (!/import\([^)]*environment-/u.test(entrySource)) throw new Error('The live scene is not separated behind a dynamic import.');
|
||||
if (/WebGLRenderer|WebGLProgram|ShaderMaterial/u.test(entrySource)) throw new Error('Three.js/live-scene code leaked into the reduced-motion initial chunk.');
|
||||
|
||||
const runtime = evaluateRuntimeBudgetEvidence(runtimeEvidence);
|
||||
const violations = [...evaluateBudgetTotals(totals).violations, ...mediaViolations, ...runtime.violations];
|
||||
let runtime = null;
|
||||
if (runtimeTracePath !== null) {
|
||||
const trace = await readJson(resolve(runtimeTracePath), 'Runtime drive trace');
|
||||
runtime = validateRuntimeBudgetTraceReport(trace);
|
||||
}
|
||||
const violations = [...evaluateBudgetTotals(totals).violations, ...mediaViolations, ...(runtime?.violations ?? [])];
|
||||
const report = {
|
||||
schema: 'portfolio-bundle-budget/v1',
|
||||
compression: 'brotli-quality-11-or-raw-already-compressed',
|
||||
totals,
|
||||
runtime: { peakRequests: runtimeEvidence.peakRequests, tiers: runtime.tiers },
|
||||
runtime: runtime === null ? { status: 'pending-production-path-trace' } : { status: 'verified-production-path-trace', tier: runtime.tier },
|
||||
records: records.sort((left, right) => left.path.localeCompare(right.path)),
|
||||
violations,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user