* Walk filesystem to find config files * * @param dir - Directory to walk * @param files - Accumulator for found files * @param depth - Current depth (for limiting recursion) * @returns Array of absolute paths to config files
(dir: string, files: string[] = [], depth = 0)
| 136 | * @returns Array of absolute paths to config files |
| 137 | */ |
| 138 | async function walkForConfigFiles(dir: string, files: string[] = [], depth = 0): Promise<string[]> { |
| 139 | // Limit depth to avoid runaway recursion |
| 140 | if (depth > 10) return files |
| 141 | |
| 142 | try { |
| 143 | const entries = await fs.readdir(dir, { withFileTypes: true }) |
| 144 | |
| 145 | for (const entry of entries) { |
| 146 | if (CONFIG_FILENAMES_SET.has(entry.name) && entry.isFile()) { |
| 147 | files.push(path.join(dir, entry.name)) |
| 148 | } else if (entry.isDirectory() && !IGNORE_DIRS.has(entry.name) && !entry.name.startsWith(".")) { |
| 149 | await walkForConfigFiles(path.join(dir, entry.name), files, depth + 1) |
| 150 | } |
| 151 | } |
| 152 | } catch { |
| 153 | // Ignore permission errors etc |
| 154 | } |
| 155 | |
| 156 | return files |
| 157 | } |
no test coverage detected