Skip to content
Myr

version.ts

This file

Path

apps/cli/src/version.ts

26 lines · 1.2 KiB · TypeScript

Last changed by

Merge build/1104 into mainoscabrielbefore adoption82cc398

History of this file

Take it

Merge build/1104 into mainoscabrielbefore adoption82cc398

lines 1–26why, one step back
1/**
2 * The CLI's version, as its build stamped it: what `--version` prints and3 * what the stdio MCP server says it is.4 *5 * `build.ts` stamps it with a define (`versionDefine`) that both bundlers6 * apply: tsdown for the npm build, `bun build --compile` for each binary.7 * Each replaces `import.meta.env.CLI_BUILD_VERSION` with the version as a8 * string literal at build time. The form is chosen because both bundlers9 * replace it, it needs no `typeof` guard on an undeclared global and no10 * `process.env` read, and a run no build stamped (vitest, `bun11 * src/bin.ts`) leaves it undefined, so it reads as `0.0.0`, the release's12 * own word for unreleased (`scripts/lib/release.ts`' `UNRELEASED`). Bun13 * reads `import.meta.env` from the process env, so an unbuilt run under14 * Bun with `CLI_BUILD_VERSION` set reports that instead; a built one never15 * looks.16 */1718declare global {19 interface ImportMeta {20 /** What a bundler's define replaces; unbuilt, Vite's or Bun's env. */21 readonly env: { readonly CLI_BUILD_VERSION?: string };22 }23}2425/** The CLI's version as its build stamped it; `0.0.0` in a run no build stamped. */26export const cliVersion: string = import.meta.env.CLI_BUILD_VERSION ?? "0.0.0";