|
1 | 1 | import { readdirSync, readFileSync, realpathSync, statSync } from "node:fs"; |
2 | | -import { readdir } from "node:fs/promises"; |
| 2 | +import { glob } from "node:fs/promises"; |
3 | 3 | import { homedir } from "node:os"; |
4 | 4 | import * as path from "node:path"; |
5 | 5 |
|
@@ -146,33 +146,21 @@ export async function findFiles( |
146 | 146 |
|
147 | 147 | const matchPath = normalizedPattern.includes(path.sep); |
148 | 148 | const results: string[] = []; |
149 | | - const pending = [root]; |
150 | 149 |
|
151 | 150 | signal?.throwIfAborted(); |
152 | | - while (pending.length > 0) { |
| 151 | + for await (const entry of glob("**/@(*|.*)", { |
| 152 | + cwd: root, |
| 153 | + withFileTypes: true, |
| 154 | + exclude: (entry) => entry.isDirectory() && SKIPPED_SEARCH_DIRS.has(entry.name), |
| 155 | + })) { |
153 | 156 | signal?.throwIfAborted(); |
154 | | - const current = pending.pop()!; |
155 | | - let entries; |
156 | | - try { |
157 | | - entries = await readdir(current, { withFileTypes: true }); |
158 | | - } catch { |
159 | | - continue; |
160 | | - } |
| 157 | + if (!entry.isFile()) continue; |
161 | 158 |
|
162 | | - for (const entry of entries) { |
163 | | - signal?.throwIfAborted(); |
164 | | - const fullPath = path.join(current, entry.name); |
165 | | - if (entry.isDirectory()) { |
166 | | - if (!SKIPPED_SEARCH_DIRS.has(entry.name)) pending.push(fullPath); |
167 | | - continue; |
168 | | - } |
169 | | - if (!entry.isFile()) continue; |
170 | | - |
171 | | - const candidate = matchPath ? path.relative(root, fullPath) : entry.name; |
172 | | - if (!path.matchesGlob(candidate, normalizedPattern)) continue; |
173 | | - results.push(fullPath); |
174 | | - if (results.length >= maxResults) return results; |
175 | | - } |
| 159 | + const fullPath = path.join(entry.parentPath, entry.name); |
| 160 | + const candidate = matchPath ? path.relative(root, fullPath) : entry.name; |
| 161 | + if (!path.matchesGlob(candidate, normalizedPattern)) continue; |
| 162 | + results.push(fullPath); |
| 163 | + if (results.length >= maxResults) return results; |
176 | 164 | } |
177 | 165 |
|
178 | 166 | return results; |
|
0 commit comments