Rindle

API index and search · Build metadata

Source snapshot

packages/cli/src/index.ts

Source revision 05d0bf2c2e56 · build details
Source revision: 05d0bf2c2e56.
TypeScript input SHA-256: aabe6cfcc4172b870d5e272142958e9ea8d8784c2aa23133156e5a7ee633318e
Generated 2026-09-04T23:58:25.590Z with TypeScript 6.0.3. Public TypeScript checks and declaration emit passed. Package runtime tests are separate.
1// @rindle/cli — the Rindle CLI and supervised local-fleet components as prebuilt npm binaries.2//3// `rindled` is the *network front* of the engine: the `rindle-server` crate — the SQLite-backed4// `rindle-replica` live-query engine plus the public subscription/lease plane. `rindle` is the CLI5// that inspects and manages a deployed daemon (`rindle status`/`migrate`/…) and, for local dev,6// scaffolds and supervises one (`rindle init` / `rindle dev` / `rindle up`). Where7// `@rindle/replica` is a napi8// addon that embeds the engine *in-process*, this package ships the standalone executables,9// prebuilt per platform by dist (cargo-dist), **co-located** so `rindle dev` finds every component10// beside it. This module resolves the right binary for the host; the `rindle` bin (dist/cli.js)11// execs the CLI. `rindle dev` owns the normal app lifecycle, `rindle up` runs only the fleet, and12// `spawnRindled()` embeds a follower in another supervisor (it is not exposed as its own bin).13import { spawn, type ChildProcess, type SpawnOptions } from "node:child_process";14import { existsSync } from "node:fs";15import { createRequire } from "node:module";16import { dirname, join } from "node:path";1718import {19  binaryName,20  platformKey,21  platformPackageName,22  UnsupportedPlatformError,23  type Binary,24} from "./platform.ts";2526export {27  binaryName,28  platformKey,29  platformPackageName,30  UnsupportedPlatformError,31} from "./platform.ts";32export type { Binary, Libc } from "./platform.ts";3334const require = createRequire(import.meta.url);3536/**37 * Absolute path to a native Rindle toolchain binary for the current platform.38 *39 * Resolution order:40 *  1. The binary's explicit `*_BINARY_PATH` override.41 *  2. `RINDLE_BIN_DIR` — a directory holding the co-located toolchain. Point it at42 *     `target/release` after building the four binary crates and one env var lights up the fleet.43 *  3. The matching `@rindle/cli-<key>` optional dependency that npm/pnpm installed.44 *45 * Throws `UnsupportedPlatformError` for an un-targeted host, or a descriptive Error if the46 * platform package isn't installed (e.g. installed with `--no-optional`, or on a host the last47 * publish didn't target) and no override is set.48 */49export function binaryPath(bin: Binary): string {50  const explicitName: Record<Binary, string> = {51    rindle: "RINDLE_BINARY_PATH",52    rindled: "RINDLED_BINARY_PATH",53    "rindle-replicator": "RINDLE_REPLICATOR_BINARY_PATH",54    "rindle-dev-edge": "RINDLE_DEV_EDGE_BINARY_PATH",55  };56  const explicit = process.env[explicitName[bin]];57  if (explicit) {58    if (!existsSync(explicit)) {59      throw new Error(`${explicitName[bin]} points at a missing file: ${explicit}`);60    }61    return explicit;62  }6364  const file = binaryName(bin);65  const binDir = process.env.RINDLE_BIN_DIR;66  if (binDir) {67    const candidate = join(binDir, file);68    if (existsSync(candidate)) return candidate;69    // Fall through to the installed package — `RINDLE_BIN_DIR` may legitimately hold only one bin.70  }7172  const key = platformKey(); // throws UnsupportedPlatformError for un-targeted hosts73  const pkg = platformPackageName(key);74  let manifest: string;75  try {76    manifest = require.resolve(`${pkg}/package.json`);77  } catch {78    throw new Error(79      `${pkg} is not installed — the prebuilt Rindle binaries for "${key}" are missing.\n` +80        `They ship as an optional dependency of @rindle/cli; reinstall without --no-optional, ` +81        `or set RINDLE_BIN_DIR to a directory of locally built binaries.`,82    );83  }84  return join(dirname(manifest), "bin", file);85}8687/** Absolute path to the `rindle` CLI binary for the current platform. See {@link binaryPath}. */88export function rindleBinaryPath(): string {89  return binaryPath("rindle");90}9192/** Absolute path to the `rindled` daemon binary for the current platform. See {@link binaryPath}. */93export function rindledBinaryPath(): string {94  return binaryPath("rindled");95}9697/** Spawn `bin` with `args`, inheriting stdio by default. A thin wrapper over `child_process.spawn`. */98export function spawnBinary(bin: Binary, args: string[] = [], options: SpawnOptions = {}): ChildProcess {99  return spawn(binaryPath(bin), args, { stdio: "inherit", ...options });100}101102/** Spawn the `rindle` CLI with `args`. See {@link spawnBinary}. */103export function spawnRindle(args: string[] = [], options: SpawnOptions = {}): ChildProcess {104  return spawnBinary("rindle", args, options);105}106107/** Spawn the `rindled` daemon with `args`, for embedding it in a Node supervisor. See {@link spawnBinary}. */108export function spawnRindled(args: string[] = [], options: SpawnOptions = {}): ChildProcess {109  return spawnBinary("rindled", args, options);110}111