#!/usr/bin/env node import { execFile } from "node:child_process"; import { promisify } from "node:util"; const execFileAsync = promisify(execFile); const cwd = process.cwd(); async function compileRuntime() { try { await execFileAsync("npm", ["run", "compile", "--silent"], { cwd, maxBuffer: 10 * 1024 * 1024, }); } catch (error) { const code = typeof error === "object" && error !== null && "code" in error ? String(error.code) : "unknown"; throw new Error(`runtime compilation failed with exit code ${code}`); } } async function generatedRuntimeDrift() { const [{ stdout: changed }, { stdout: untracked }] = await Promise.all([ execFileAsync("git", ["diff", "--name-status", "--", "dist/src"], { cwd }), execFileAsync( "git", ["ls-files", "--others", "--exclude-standard", "--", "dist/src"], { cwd }, ), ]); return [changed.trim(), untracked.trim()].filter(Boolean).join("\n"); } async function verify() { await compileRuntime(); const drift = await generatedRuntimeDrift(); if (drift !== "") { throw new Error(`generated runtime drift detected in dist/src:\n${drift}`); } process.stdout.write("Generated runtime is fresh.\n"); } verify().catch((error) => { const message = error instanceof Error ? error.message : String(error); process.stderr.write(`Generated-runtime verification failed: ${message}\n`); process.exitCode = 1; });