UNPKG

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