( files: string[], start: number, end: number, out: Set<string>, )
| 418 | } |
| 419 | |
| 420 | function collectDirectoryNames( |
| 421 | files: string[], |
| 422 | start: number, |
| 423 | end: number, |
| 424 | out: Set<string>, |
| 425 | ): void { |
| 426 | for (let i = start; i < end; i++) { |
| 427 | let currentDir = path.dirname(files[i]!) |
| 428 | // Early exit if we've already processed this directory and all its parents. |
| 429 | // Root detection: path.dirname returns its input at the root (fixed point), |
| 430 | // so we stop when dirname stops changing. Checking this before add() keeps |
| 431 | // the root out of the result set (matching the old path.parse().root guard). |
| 432 | // This avoids path.parse() which allocates a 5-field object per file. |
| 433 | while (currentDir !== '.' && !out.has(currentDir)) { |
| 434 | const parent = path.dirname(currentDir) |
| 435 | if (parent === currentDir) break |
| 436 | out.add(currentDir) |
| 437 | currentDir = parent |
| 438 | } |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | /** |
| 443 | * Gets additional files from Claude config directories |
no test coverage detected