Resolve GA issues
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/push/deploy Pipeline was successful

This commit is contained in:
2026-02-08 00:36:38 -03:00
parent 3130661e65
commit ebc7ebc229
6 changed files with 73 additions and 15 deletions

View File

@@ -6,23 +6,57 @@
* Usage: node scripts/critical-css.mjs [buildDir]
* buildDir: path to build output (default: "build"). Use from repo root.
*/
import { readFileSync, writeFileSync } from 'node:fs';
import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
import { homedir, platform } from 'node:os';
import { join } from 'node:path';
import { cwd } from 'node:process';
const buildDir = join(cwd(), process.argv[2] || 'build');
const htmlPath = join(buildDir, 'index.html');
// critical/penthouse use a nested puppeteer; point it at our installed Chrome
try {
const puppeteer = await import('puppeteer');
const executablePath = puppeteer.default?.executablePath?.();
if (executablePath) {
process.env.PUPPETEER_EXECUTABLE_PATH = executablePath;
// critical/penthouse use a nested puppeteer; point at an installed Chrome/Chromium.
// Only set PUPPETEER_EXECUTABLE_PATH if the path exists. Prefer Playwright's Chromium
// on arm64 so we use the native binary (Puppeteer's default can be x86 on ARM hosts e.g. OrbStack).
function getPlaywrightChromePath() {
const cacheBase =
process.env.PLAYWRIGHT_BROWSERS_PATH || join(homedir(), '.cache', 'ms-playwright');
if (!existsSync(cacheBase)) return null;
const dirs = readdirSync(cacheBase, { withFileTypes: true });
for (const d of dirs) {
if (!d.isDirectory() || !d.name.startsWith('chromium-')) continue;
const sub = join(cacheBase, d.name);
const rel =
platform() === 'win32'
? 'chrome-win\\chrome.exe'
: platform() === 'darwin'
? 'chrome-mac/Chromium.app/Contents/MacOS/Chromium'
: 'chrome-linux/chrome';
const candidate = join(sub, rel);
if (existsSync(candidate)) return candidate;
}
} catch {
// no top-level puppeteer or no executable; rely on env or default
return null;
}
async function resolveChromePath() {
const isArm64 = process.arch === 'arm64';
if (isArm64) {
const pw = getPlaywrightChromePath();
if (pw) return pw;
}
try {
const puppeteer = await import('puppeteer');
const path = puppeteer.default?.executablePath?.();
if (path && existsSync(path)) return path;
} catch {
// ignore
}
if (!isArm64) {
const pw = getPlaywrightChromePath();
if (pw) return pw;
}
return null;
}
const chromePath = await resolveChromePath();
if (chromePath) process.env.PUPPETEER_EXECUTABLE_PATH = chromePath;
try {
const { generate } = await import('critical');
@@ -45,9 +79,16 @@ try {
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
console.error('Critical CSS step failed:', msg);
if (msg.includes('Browser is not downloaded')) {
if (
msg.includes('Browser is not downloaded') ||
msg.includes('did not find any executable') ||
msg.includes('Could not find Chrome')
) {
console.error('Install Chromium first: pnpm run critical-css:install');
console.error('Or run "pnpm run build" without critical CSS.');
console.error(
'(Dev container: Playwright Chromium is also used if present in ~/.cache/ms-playwright.)',
);
console.error('Or run "pnpm run build" (without critical CSS) for a working build.');
}
process.exit(1);
}

View File

@@ -1,5 +1,6 @@
/**
* Post-build: minify JS and CSS under build/assets (files copied from static/).
* Includes static/assets/js/*.js (e.g. ga-init.js, bootstrap.js) and assets/*.css.
* Usage: node scripts/minify-static-assets.mjs [buildDir]
*/
import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';