|
5 | 5 | import { Command } from "commander"; |
6 | 6 | import { writeHuman, writeJson } from "../io.js"; |
7 | 7 | import { EXIT } from "../contract/exitCodes.js"; |
8 | | -import { createRequire } from "node:module"; |
9 | | -import { getAlphaIntent } from "../contract/intents"; |
10 | | -import { ok } from "../contract/envelope"; |
| 8 | +import { fileURLToPath } from "url"; |
| 9 | +import { dirname, join } from "path"; |
| 10 | +import { readFileSync, existsSync } from "fs"; |
| 11 | +import { getAlphaIntent } from "../contract/intents.js"; |
| 12 | +import { ok } from "../contract/envelope.js"; |
11 | 13 |
|
12 | 14 | type GlobalOpts = { json?: boolean } |
13 | 15 |
|
14 | | -const require = createRequire(import.meta.url); |
15 | | -const pkg = require("../../package.json") as { name: string; version: string }; |
| 16 | +// Resolve package.json from current file location (works for both tsx and compiled) |
| 17 | +const __filename = fileURLToPath(import.meta.url); |
| 18 | +const __dirname = dirname(__filename); |
| 19 | + |
| 20 | +// Try source location first (tsx), then compiled location |
| 21 | +let pkgPath = join(__dirname, "../../package.json"); |
| 22 | +if (!existsSync(pkgPath)) { |
| 23 | + pkgPath = join(__dirname, "../../../package.json"); |
| 24 | +} |
| 25 | + |
| 26 | +const pkg = JSON.parse(readFileSync(pkgPath, "utf-8")) as { name: string; version: string }; |
16 | 27 |
|
17 | 28 | export function versionCommand(): Command { |
18 | 29 | return new Command("version") |
|
0 commit comments