Files
suaveplan/packages/devtools/tooling/javy-cli-linux-x64/src/index.ts
2026-05-27 23:29:53 +01:00

38 lines
1.5 KiB
TypeScript

import { existsSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
/**
* Absolute filesystem path to the bundled Javy binary for this
* platform. `@suaveplan/wasm-compiler-javy` calls this to locate the
* binary it spawns via `child_process.spawnSync` — the postinstall
* script places the binary at this exact path after verifying its
* SHA-256.
*
* Throws if the binary is missing (the postinstall step failed or was
* skipped via `JAVY_SKIP_DOWNLOAD=1` without a follow-up seed). The
* caller is expected to surface this as a structured error.
*/
export function getJavyBinary(): string {
const here = dirname(fileURLToPath(import.meta.url));
// dist/index.js → ../bin/<name>
const candidate = join(here, "..", "bin", "javy");
if (!existsSync(candidate)) {
// src/index.ts → ../bin/<name> (when running from src under bun)
const fallback = join(here, "..", "bin", "javy");
if (existsSync(fallback)) return fallback;
throw new Error(
"@suaveplan/javy-cli-linux-x64: binary not found at " +
candidate +
" — did postinstall run? (set JAVY_SKIP_DOWNLOAD=1 only with a manual seed)"
);
}
return candidate;
}
/** Platform triple this wrapper serves. */
export const JAVY_PLATFORM = "linux-x64" as const;
/** Pinned Javy upstream version this wrapper installs. */
export const JAVY_VERSION = "v8.1.1" as const;