API index and search · Build metadata
Source snapshot
packages/cli/src/platform.ts
1// Single source of truth for mapping the *running* Node platform to the per-platform package that2// carries the prebuilt Rindle binaries (`rindle`, `rindled`, `rindle-replicator`, and the local3// `rindle-dev-edge`) for it. Those4// packages (`@rindle/cli-<key>`) are generated at release time by `scripts/build-npm-packages.mjs`5// from dist's (cargo-dist) release archives, and declared as optionalDependencies of this umbrella6// package — so npm/pnpm install only the one whose `os`/`cpu` match the host. All binaries ship7// **co-located** in that one package's `bin/`, which is required: the `rindle` CLI's `rindle up`8// finds every component as a sibling of its own executable (rindle-cli §7.1) so it can supervise9// the local topology. This module and the generator MUST agree on the `<key>`10// scheme; it is defined here and mirrored in the generator.1112export type Libc = "gnu" | "musl";1314/** A native binary shipped by the Rindle development toolchain. */15export type Binary = "rindle" | "rindled" | "rindle-replicator" | "rindle-dev-edge";1617/**18 * The package-name suffix identifying a build target for the current (or given) host:19 * `darwin-{arm64,x64}`, `linux-{x64,arm64}-{gnu,musl}`, `win32-x64-msvc`. Throws20 * `UnsupportedPlatformError` for a host we don't publish binaries for.21 */22export function platformKey(23 platform: NodeJS.Platform = process.platform,24 arch: string = process.arch,25 libc: Libc = detectLibc(platform),26): string {27 switch (platform) {28 case "darwin":29 return `darwin-${arch}`;30 case "linux":31 return `linux-${arch}-${libc}`;32 // `win32` is deliberately absent, and must stay in step with `"rindle".targets` in33 // package.json: we publish no Windows binaries, so returning a key here would only trade this34 // actionable error for a MODULE_NOT_FOUND on a package that was never published. Restoring35 // Windows means re-adding the target there AND a `case "win32"` here — see36 // follow-ups/windows-hctree.md.37 default:38 throw new UnsupportedPlatformError(platform, arch);39 }40}4142/** The npm package name carrying the binaries for `key` (default: the current host's key). */43export function platformPackageName(key: string = platformKey()): string {44 return `@rindle/cli-${key}`;45}4647/** The on-disk filename of `bin` inside a platform package (`rindle` / `rindled.exe`). */48export function binaryName(bin: Binary, platform: NodeJS.Platform = process.platform): string {49 return platform === "win32" ? `${bin}.exe` : bin;50}5152export class UnsupportedPlatformError extends Error {53 constructor(platform: string, arch: string) {54 super(55 `@rindle/cli ships no prebuilt Rindle binaries for ${platform}-${arch}` +56 (platform === "win32"57 ? ". Rindle's storage engine is Linux-only, so there is no native Windows build. Run the " +58 "toolchain under WSL2 and keep the database on the WSL filesystem (~/), NOT under " +59 "/mnt/c — the Windows drive mount cannot back a memory-mapped database. Your app and " +60 "browser can stay on Windows: WSL2 forwards localhost."61 : ""),62 );63 this.name = "UnsupportedPlatformError";64 }65}6667// glibc vs musl: Node reports the runtime glibc version in its process report on glibc systems;68// its absence on linux implies musl. We publish both `-gnu` and `-musl` Linux packages, so this69// picks the right one (and avoids a `detect-libc` dependency — the launcher stays dep-free).70function detectLibc(platform: NodeJS.Platform): Libc {71 if (platform !== "linux") return "gnu";72 try {73 const report = process.report?.getReport() as74 | { header?: { glibcVersionRuntime?: string } }75 | undefined;76 return report?.header?.glibcVersionRuntime ? "gnu" : "musl";77 } catch {78 return "gnu";79 }80}81