(root: string, options: { includeDirs?: boolean; showHidden?: boolean } = {})
| 70 | } |
| 71 | |
| 72 | async function walk(root: string, options: { includeDirs?: boolean; showHidden?: boolean } = {}): Promise<Array<{ relativePath: string; fullPath: string; isDir: boolean }>> { |
| 73 | const result: Array<{ relativePath: string; fullPath: string; isDir: boolean }> = [] |
| 74 | const queue = [root] |
| 75 | |
| 76 | while (queue.length > 0 && result.length < MAX_WALK_ENTRIES) { |
| 77 | const dir = queue.shift()! |
| 78 | let entries: Array<{ name: string; isDirectory(): boolean }> |
| 79 | try { |
| 80 | entries = await fs.readdir(dir, { withFileTypes: true }) |
| 81 | } catch { |
| 82 | continue |
| 83 | } |
| 84 | |
| 85 | for (const entry of entries) { |
| 86 | if (!options.showHidden && entry.name.startsWith(".")) continue |
| 87 | const fullPath = path.join(dir, entry.name) |
| 88 | const relativePath = path.relative(root, fullPath) |
| 89 | const isDir = entry.isDirectory() |
| 90 | if (isDir && SKIP_DIRS.has(entry.name)) continue |
| 91 | if (!isDir || options.includeDirs) result.push({ relativePath, fullPath, isDir }) |
| 92 | if (isDir) queue.push(fullPath) |
| 93 | if (result.length >= MAX_WALK_ENTRIES) break |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | return result |
| 98 | } |
| 99 | |
| 100 | function rankMatch(pathname: string, query: string): number { |
| 101 | if (!query) return 0 |
no test coverage detected