* List files using ripgrep
({
rgPath,
dir,
matchDirs,
}: {
rgPath: string
dir: string
matchDirs: boolean
})
| 232 | * List files using ripgrep |
| 233 | */ |
| 234 | async function listFilesWithRipgrep({ |
| 235 | rgPath, |
| 236 | dir, |
| 237 | matchDirs, |
| 238 | }: { |
| 239 | rgPath: string |
| 240 | dir: string |
| 241 | matchDirs: boolean |
| 242 | }): Promise<string[]> { |
| 243 | // Use rg --files to list all files (respects .gitignore by default) |
| 244 | // Exclude .git directory explicitly since --hidden includes it but .gitignore doesn't exclude it |
| 245 | const result = await execCmd(rgPath, ["--files", "--hidden", "--glob", "!.git"], dir) |
| 246 | if (!result.success) { |
| 247 | logger.warn("[Files:listFilesWithRipgrep] Failed:", result.stderr) |
| 248 | return [] |
| 249 | } |
| 250 | |
| 251 | let files = result.stdout |
| 252 | .split("\n") |
| 253 | .map((f) => f.trim()) |
| 254 | .filter((f) => f.length > 0) |
| 255 | |
| 256 | if (matchDirs) { |
| 257 | // Extract unique directory paths |
| 258 | const dirs = new Set<string>() |
| 259 | for (const file of files) { |
| 260 | let dirPath = path.dirname(file) |
| 261 | while (dirPath && dirPath !== ".") { |
| 262 | dirs.add(dirPath) |
| 263 | dirPath = path.dirname(dirPath) |
| 264 | } |
| 265 | } |
| 266 | return Array.from(dirs).sort() |
| 267 | } |
| 268 | |
| 269 | return files |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * List files using filesystem walk (fallback) |
no test coverage detected