findProjectRoot.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = findProjectRoot;
  6. function _findUp() {
  7. const data = _interopRequireDefault(require("find-up"));
  8. _findUp = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. function _path() {
  14. const data = _interopRequireDefault(require("path"));
  15. _path = function () {
  16. return data;
  17. };
  18. return data;
  19. }
  20. function _cliTools() {
  21. const data = require("@react-native-community/cli-tools");
  22. _cliTools = function () {
  23. return data;
  24. };
  25. return data;
  26. }
  27. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  28. /**
  29. * Finds project root by looking for a closest `package.json`.
  30. */
  31. function findProjectRoot(cwd = process.cwd()) {
  32. const packageLocation = _findUp().default.sync('package.json', {
  33. cwd
  34. });
  35. /**
  36. * It is possible that `package.json` doesn't exist
  37. * in the tree. In that case, we want to throw an error.
  38. *
  39. * When executing via `npx`, this will never happen as `npm`
  40. * requires that file to be present in order to run.
  41. */
  42. if (!packageLocation) {
  43. throw new (_cliTools().CLIError)(`
  44. We couldn't find a package.json in your project.
  45. Are you sure you are running it inside a React Native project?
  46. `);
  47. }
  48. return _path().default.dirname(packageLocation);
  49. }
  50. //# sourceMappingURL=findProjectRoot.js.map