()
| 17 | const MODULE_DIR = import.meta.dirname; |
| 18 | |
| 19 | export function getHostPackageJsonPath(): string { |
| 20 | // Walk upwards from this file's directory until a `package.json` shows up, |
| 21 | // so both dev (`tsx src/main.ts` — this file in `src/cli/`, pkg 2 levels |
| 22 | // up) and prod (`node dist/main.mjs` — this code bundled into `dist/`, |
| 23 | // pkg 1 level up) resolve correctly. |
| 24 | let dir = MODULE_DIR; |
| 25 | for (let i = 0; i < 6; i++) { |
| 26 | const candidate = resolve(dir, 'package.json'); |
| 27 | if (existsSync(candidate)) { |
| 28 | return candidate; |
| 29 | } |
| 30 | const parent = dirname(dir); |
| 31 | if (parent === dir) break; |
| 32 | dir = parent; |
| 33 | } |
| 34 | throw new Error(`Could not locate package.json near ${MODULE_DIR}`); |
| 35 | } |
| 36 | |
| 37 | export function getHostPackageRoot(): string { |
| 38 | return dirname(getHostPackageJsonPath()); |
no test coverage detected