| 7 | |
| 8 | /** Find the monorepo root by walking up from cwd looking for .bumpy/ */ |
| 9 | export async function findRoot(startDir: string = process.cwd()): Promise<string> { |
| 10 | let dir = resolve(startDir); |
| 11 | while (true) { |
| 12 | if (await exists(resolve(dir, BUMPY_DIR))) return dir; |
| 13 | // Also check for package.json with workspaces as a fallback |
| 14 | if (await exists(resolve(dir, 'package.json'))) { |
| 15 | try { |
| 16 | const pkg = await readJson<Record<string, unknown>>(resolve(dir, 'package.json')); |
| 17 | if (pkg.workspaces) return dir; |
| 18 | } catch { |
| 19 | // ignore |
| 20 | } |
| 21 | } |
| 22 | const parent = resolve(dir, '..'); |
| 23 | if (parent === dir) break; // reached filesystem root |
| 24 | dir = parent; |
| 25 | } |
| 26 | // Default to cwd if nothing found |
| 27 | return resolve(startDir); |
| 28 | } |
| 29 | |
| 30 | /** Load the root bumpy config, merging with defaults */ |
| 31 | export async function loadConfig(rootDir: string): Promise<BumpyConfig> { |