Limit search depth in path corrector (#14869)

This commit is contained in:
Tommaso Sciortino
2025-12-09 20:08:39 -08:00
committed by GitHub
parent ee6556cbd2
commit 1954f45c19
7 changed files with 213 additions and 76 deletions
@@ -5,8 +5,6 @@
*/
import fs from 'node:fs/promises';
import * as path from 'node:path';
import { globSync } from 'glob';
/**
* Interface for file system operations that may be delegated to different implementations
@@ -27,15 +25,6 @@ export interface FileSystemService {
* @param content - The content to write
*/
writeTextFile(filePath: string, content: string): Promise<void>;
/**
* Finds files with a given name within specified search paths.
*
* @param fileName - The name of the file to find.
* @param searchPaths - An array of directory paths to search within.
* @returns An array of absolute paths to the found files.
*/
findFiles(fileName: string, searchPaths: readonly string[]): string[];
}
/**
@@ -49,14 +38,4 @@ export class StandardFileSystemService implements FileSystemService {
async writeTextFile(filePath: string, content: string): Promise<void> {
await fs.writeFile(filePath, content, 'utf-8');
}
findFiles(fileName: string, searchPaths: readonly string[]): string[] {
return searchPaths.flatMap((searchPath) => {
const pattern = path.posix.join(searchPath, '**', fileName);
return globSync(pattern, {
nodir: true,
absolute: true,
});
});
}
}