| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- #!/usr/bin/env node
- import { execFile } from "node:child_process";
- import { promisify } from "node:util";
- const execFileAsync = promisify(execFile);
- const cwd = process.cwd();
- const runtimePaths = ["dist/cli.js", "dist/config.js"];
- 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", "--", ...runtimePaths], { cwd }),
- execFileAsync(
- "git",
- ["ls-files", "--others", "--exclude-standard", "--", ...runtimePaths],
- { 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:\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;
- });
|