iterate.com / kernel

git clone https://git.iterate.com/repos/kernel

kernel / core / lib / bin / iterate.jsmain at 949894f

#!/usr/bin/env node

// THE BIN RUNS ITS OWN PACKAGE, AND NO OTHER. It never looks at the working folder for another
// iterate CLI: git runs `iterate git-credential` in git's own working folder, and a service starts
// `iterate daemon` wherever it likes, so a command must answer the same in every folder. (Until
// 28 Nov 2026 it handed every command to a CLI found above the working folder, and git's helper
// answered "unknown command 'git-credential'" in a checkout with an older CLI.) To run a checkout's
// CLI, run that checkout's bin: `pnpm exec iterate` there, or `node <checkout>/core/lib/bin/iterate.js`.
import { existsSync } from "node:fs";
import { dirname, join } from "node:path";
import process from "node:process";
import { fileURLToPath } from "node:url";

const pkgRoot = dirname(dirname(fileURLToPath(import.meta.url)));

// A checkout has the source and runs it; the published package has only the build.
// ITERATE_FORCE_BUILT_PACKAGE=1 runs a checkout's build: a test of the published artifact.
const srcPath = join(pkgRoot, "src/cli/cli.ts");
const distPath = join(pkgRoot, "dist/cli.mjs");
const forceBuiltPackage = process.env.ITERATE_FORCE_BUILT_PACKAGE === "1";
const { runCli } = await import(!forceBuiltPackage && existsSync(srcPath) ? srcPath : distPath);
await runCli();