vike
Version:
The Framework *You* Control - Next.js & Nuxt alternative for unprecedented flexibility and dependability.
31 lines (30 loc) • 1.32 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.findFile = findFile;
const node_path_1 = __importDefault(require("node:path"));
const node_fs_1 = __importDefault(require("node:fs"));
const isArray_js_1 = require("./isArray.js");
const path_js_1 = require("./path.js");
// We need to be able to crawl the filesystem, regardless of Vike's `$ git ls-files` command call, because we need to fallback if the user didn't setup Git (e.g. we cannot remove the tinyglobby fallback).
function findFile(arg, cwd) {
(0, path_js_1.assertPosixPath)(cwd);
const filenames = (0, isArray_js_1.isArray)(arg) ? arg : [arg];
let dir = cwd;
while (true) {
for (const filename of filenames) {
const configFilePath = node_path_1.default.posix.join(dir, `./${filename}`);
if (node_fs_1.default.existsSync(configFilePath)) {
(0, path_js_1.assertPosixPath)(configFilePath);
return configFilePath;
}
}
const dirPrevious = dir;
dir = node_path_1.default.posix.dirname(dir);
if (dir === dirPrevious) {
return null;
}
}
}