index.js 935 B

123456789101112131415161718192021222324252627
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. const path_1 = __importDefault(require("path"));
  7. const find_up_1 = __importDefault(require("find-up"));
  8. exports.default = toplevel;
  9. /**
  10. * Find the next git root
  11. */
  12. async 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. */
  22. async function searchDotGit(cwd) {
  23. const foundFile = await (0, find_up_1.default)('.git', { cwd, type: 'file' });
  24. const foundDir = await (0, find_up_1.default)('.git', { cwd, type: 'directory' });
  25. return foundFile || foundDir;
  26. }
  27. //# sourceMappingURL=index.js.map