import { readFileSync } from "node:fs"; import { join } from "node:path"; /** * The installed package version, read from the package manifest once per run. * The path is one level deeper than cli.ts's original — this module lives in * src/commands/ — but resolves to the same omp/package.json. */ function packageVersion(): string { const parsed = JSON.parse( readFileSync(join(import.meta.dir, "..", "..", "package.json"), "utf8"), ) as { version?: unknown; }; if (typeof parsed.version !== "string" || parsed.version.length === 0) { throw new Error("installed package.json has no version"); } return parsed.version; } /** * `--version`, `-V` and `version`: print the installed package version. * * Moved out of cli.ts's switch by the per-verb module split (#462); only the * case wrapper and the imports changed from the original body. */ export async function versionCommand(): Promise { process.stdout.write(`${packageVersion()}\n`); }