aiwg
Version:
Deployment tool and support utility for AI context. Copies agents, skills, commands, rules, and behaviors into the paths each AI platform reads (Claude Code, Codex, Copilot, Cursor, Warp, OpenClaw, and 6 more) so one source of truth works across 10 platfo
40 lines • 1.4 kB
JavaScript
/**
* Shared helper: walk up from a starting directory to find AIWG's package root
* (the directory containing the package.json with name === 'aiwg').
*
* Required because the compiled layout (dist/src/<area>/<file>.js) and the
* source layout (src/<area>/<file>.ts) are different depths from the package
* root, so fixed `../../` walks break in one of the two modes. Walking up to
* the `aiwg` package.json works in both.
*
* @issue #1261
*/
import { existsSync, readFileSync } from 'fs';
import { dirname, join } from 'path';
/**
* Walk up from `startDir` looking for a `package.json` with `name === 'aiwg'`.
* Returns the directory containing that package.json, or `null` if not found
* within `maxDepth` levels.
*/
export function findPackageRoot(startDir, maxDepth = 10) {
let dir = startDir;
for (let i = 0; i < maxDepth; i++) {
const pkgPath = join(dir, 'package.json');
if (existsSync(pkgPath)) {
try {
const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
if (pkg.name === 'aiwg')
return dir;
}
catch {
/* malformed package.json — keep walking */
}
}
const parent = dirname(dir);
if (parent === dir)
break;
dir = parent;
}
return null;
}
//# sourceMappingURL=find-package-root.js.map