UNPKG

925 BJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6const path_1 = __importDefault(require("path"));
7const find_up_1 = __importDefault(require("find-up"));
8exports.default = toplevel;
9/**
10 * Find the next git root
11 */
12async function toplevel(cwd) {
13 const found = await searchDotGit(cwd);
14 if (typeof found !== 'string') {
15 return found;
16 }
17 return path_1.default.join(found, '..');
18}
19/**
20 * Search .git, the '.git' can be a file(submodule), also can be a directory(normal)
21 */
22async function searchDotGit(cwd) {
23 const foundFile = await find_up_1.default('.git', { cwd, type: 'file' });
24 const foundDir = await find_up_1.default('.git', { cwd, type: 'directory' });
25 return foundFile || foundDir;
26}
27//# sourceMappingURL=index.js.map
\No newline at end of file