MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / getHostPackageJsonPath

Function getHostPackageJsonPath

apps/kimi-code/src/cli/version.ts:19–35  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

17const MODULE_DIR = import.meta.dirname;
18
19export 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
37export function getHostPackageRoot(): string {
38 return dirname(getHostPackageJsonPath());

Callers 3

version.test.tsFile · 0.90
getHostPackageRootFunction · 0.85
getVersionFunction · 0.85

Calls 1

resolveFunction · 0.50

Tested by

no test coverage detected