fix(ci): make bundle budget check resilient to missing dist artifacts
This commit is contained in:
@@ -66,7 +66,9 @@ jobs:
|
||||
|
||||
- name: Check browser bundle budgets
|
||||
working-directory: packages/browser
|
||||
run: pnpm run check:bundle-budget
|
||||
run: |
|
||||
[ -f dist/browser-extension/background.js ] || node src/build.js
|
||||
pnpm run check:bundle-budget
|
||||
|
||||
- name: Run Playwright E2E tests
|
||||
working-directory: packages/browser
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { execSync } from 'node:child_process';
|
||||
|
||||
const root = path.resolve(path.dirname(new URL(import.meta.url).pathname), '..');
|
||||
|
||||
@@ -13,9 +14,33 @@ const budgets = {
|
||||
|
||||
let failed = false;
|
||||
|
||||
function resolveBundlePath(relPath) {
|
||||
const direct = path.join(root, relPath);
|
||||
if (fs.existsSync(direct)) return direct;
|
||||
|
||||
const baseName = path.basename(relPath);
|
||||
const chromeFallback = path.join(root, 'dist/browser-extension/chrome', baseName);
|
||||
if (fs.existsSync(chromeFallback)) return chromeFallback;
|
||||
|
||||
const firefoxFallback = path.join(root, 'dist/browser-extension/firefox', baseName);
|
||||
if (fs.existsSync(firefoxFallback)) return firefoxFallback;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function ensureBuildArtifacts() {
|
||||
const hasAnyArtifacts = Object.keys(budgets).some((relPath) => !!resolveBundlePath(relPath));
|
||||
if (hasAnyArtifacts) return;
|
||||
|
||||
console.log('No bundle artifacts found; running build once before budget check...');
|
||||
execSync('node src/build.js', { cwd: root, stdio: 'inherit' });
|
||||
}
|
||||
|
||||
ensureBuildArtifacts();
|
||||
|
||||
for (const [relPath, maxBytes] of Object.entries(budgets)) {
|
||||
const filePath = path.join(root, relPath);
|
||||
if (!fs.existsSync(filePath)) {
|
||||
const filePath = resolveBundlePath(relPath);
|
||||
if (!filePath) {
|
||||
console.error(`Missing bundle for budget check: ${relPath}`);
|
||||
failed = true;
|
||||
continue;
|
||||
@@ -25,7 +50,8 @@ for (const [relPath, maxBytes] of Object.entries(budgets)) {
|
||||
const kb = (size / 1024).toFixed(1);
|
||||
const limitKb = (maxBytes / 1024).toFixed(1);
|
||||
const status = size <= maxBytes ? 'OK' : 'OVER';
|
||||
console.log(`${status} ${relPath} ${kb}KB / ${limitKb}KB`);
|
||||
const displayPath = path.relative(root, filePath);
|
||||
console.log(`${status} ${relPath} [${displayPath}] ${kb}KB / ${limitKb}KB`);
|
||||
if (size > maxBytes) {
|
||||
failed = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user