Files
faunosteo/scripts/browser/lib/app-build.mjs
T
bchanot 4439fd2420 test(tests): R4.1e browser harness and TS baselines (Chromium, Firefox, WebKit)
Playwright harness under scripts/browser: 127.0.0.1 server with the DEPLOY
CSP, export and import baselines of the TypeScript engine under a 4 GiB RSS
watchdog (not a guaranteed memory limit), O9 browser columns in
inflate.browsers.json (26 rows agree with Node in all three engines).
Results of 2026-10-18 committed; the O9 Node test no longer expects browser
columns in inflate.json.
2026-10-18 15:05:28 +02:00

50 lines
1.6 KiB
JavaScript

import { execFileSync } from 'node:child_process'
import { existsSync, readdirSync, statSync } from 'node:fs'
import { join } from 'node:path'
import { DIST_DIR, REPO_ROOT } from './paths.mjs'
/**
* The harness measures a production build that embeds the reference sheet.
* It never builds by itself: the build command is printed instead, so a run
* always names the build it measured (mtime, chunk sizes, HEAD).
*/
export const BUILD_COMMAND =
'SHEET_BUNDLE=draft corepack pnpm --filter @faunosteo/app build'
// A build without the sheet (SHEET_BUNDLE=none) leaves a 40-byte stub chunk.
const MIN_SHEET_CHUNK_BYTES = 10_000
function assetSize(pattern) {
const assets = join(DIST_DIR, 'assets')
const name = readdirSync(assets).find((file) => pattern.test(file))
return name ? { name, bytes: statSync(join(assets, name)).size } : null
}
function headCommit() {
try {
const args = ['-C', REPO_ROOT, 'rev-parse', '--short', 'HEAD']
return execFileSync('git', args, { encoding: 'utf8' }).trim()
} catch {
return null
}
}
export function checkBuild() {
const index = join(DIST_DIR, 'index.html')
if (!existsSync(index)) {
throw new Error(`no build in apps/app/dist: run ${BUILD_COMMAND}`)
}
const sheet = assetSize(/^_virtual_faunosteo-sheet-.*\.js$/)
if (!sheet || sheet.bytes < MIN_SHEET_CHUNK_BYTES) {
throw new Error(`the build carries no sheet: run ${BUILD_COMMAND}`)
}
return {
distDir: 'apps/app/dist',
builtAt: statSync(index).mtime.toISOString(),
sheetChunk: sheet,
entryChunk: assetSize(/^index-.*\.js$/),
wasm: assetSize(/\.wasm$/),
headCommit: headCommit(),
}
}