UNPKG

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