| 49 | } |
| 50 | |
| 51 | async function walkRecursive( |
| 52 | dir: string, |
| 53 | rootDir: string, |
| 54 | ig: Ignore, |
| 55 | depth: number, |
| 56 | maxDepth: number, |
| 57 | results: FileEntry[], |
| 58 | ): Promise<void> { |
| 59 | if (maxDepth > 0 && depth > maxDepth) return; |
| 60 | |
| 61 | const entries = await readdir(dir, { withFileTypes: true }).catch(() => []); |
| 62 | for (const entry of entries) { |
| 63 | if (ALWAYS_IGNORE.has(entry.name) || entry.name.startsWith(".")) continue; |
| 64 | |
| 65 | const fullPath = join(dir, entry.name); |
| 66 | const relPath = relative(rootDir, fullPath).replace(/\\/g, "/"); |
| 67 | if (ig.ignores(relPath)) continue; |
| 68 | |
| 69 | const isDir = entry.isDirectory(); |
| 70 | results.push({ path: fullPath, relativePath: relPath, isDirectory: isDir, depth }); |
| 71 | |
| 72 | if (isDir) await walkRecursive(fullPath, rootDir, ig, depth + 1, maxDepth, results); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | export async function walkDirectory(options: WalkOptions): Promise<FileEntry[]> { |
| 77 | const rootDir = resolve(options.rootDir); |