import { existsSync } from 'fs';
import { join, dirname, sep } from 'path';
const foundFileCache = new Map();
export default function findFileInCurrentPath(fileName) {
    const currentWorkingDirectory = process.cwd();
    const cacheKey = `${currentWorkingDirectory}::${fileName}`;
    if (foundFileCache.has(cacheKey)) {
        return foundFileCache.get(cacheKey);
    }
    let currentPath = currentWorkingDirectory;
    while (currentPath !== sep && !existsSync(join(currentPath, fileName))) {
        currentPath = dirname(currentPath);
    }
    const foundPath = currentPath !== sep ? join(currentPath, fileName) : undefined;
    foundFileCache.set(cacheKey, foundPath);
    return foundPath;
}
export function clearFoundFileCache() {
    foundFileCache.clear();
}
