@launchql/env
Version:
LaunchQL environment management
28 lines (27 loc) • 942 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.walkUp = void 0;
const fs_1 = require("fs");
const path_1 = require("path");
/**
* Recursively walks up directories to find a specific file (sync version).
* @param startDir - Starting directory.
* @param filename - The target file to search for.
* @returns The directory path containing the file.
*/
const walkUp = (startDir, filename) => {
let currentDir = (0, path_1.resolve)(startDir);
while (currentDir) {
const targetPath = (0, path_1.resolve)(currentDir, filename);
if ((0, fs_1.existsSync)(targetPath)) {
return currentDir;
}
const parentDir = (0, path_1.dirname)(currentDir);
if (parentDir === currentDir) {
break;
}
currentDir = parentDir;
}
throw new Error(`File "${filename}" not found in any parent directories.`);
};
exports.walkUp = walkUp;
;