(startDir: string)
| 14 | * @internal |
| 15 | */ |
| 16 | export function findEnvrcDirectory(startDir: string): string | null { |
| 17 | let currentDir = path.resolve(startDir) |
| 18 | const root = path.parse(currentDir).root |
| 19 | |
| 20 | while (currentDir !== root) { |
| 21 | // Read directory entries once and check for both .envrc and .git |
| 22 | let entries: string[] |
| 23 | try { |
| 24 | entries = fs.readdirSync(currentDir) |
| 25 | } catch { |
| 26 | // Directory not readable - stop searching |
| 27 | break |
| 28 | } |
| 29 | |
| 30 | const hasEnvrc = entries.includes('.envrc') |
| 31 | const hasGit = entries.includes('.git') |
| 32 | |
| 33 | if (hasEnvrc) { |
| 34 | return currentDir |
| 35 | } |
| 36 | |
| 37 | // If this is a git root and no .envrc found, stop searching |
| 38 | if (hasGit) { |
| 39 | break |
| 40 | } |
| 41 | |
| 42 | const parentDir = path.dirname(currentDir) |
| 43 | if (parentDir === currentDir) break |
| 44 | currentDir = parentDir |
| 45 | } |
| 46 | |
| 47 | return null |
| 48 | } |
| 49 | |
| 50 | /** @internal */ |
| 51 | export function isDirenvAvailable(): boolean { |
no test coverage detected