vike
Version:
The Framework *You* Control - Next.js & Nuxt alternative for unprecedented flexibility and dependability.
31 lines (30 loc) • 1.28 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 path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("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 = path_1.default.posix.join(dir, `./${filename}`);
if (fs_1.default.existsSync(configFilePath)) {
(0, path_js_1.assertPosixPath)(configFilePath);
return configFilePath;
}
}
const dirPrevious = dir;
dir = path_1.default.posix.dirname(dir);
if (dir === dirPrevious) {
return null;
}
}
}