Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions packages/react-native/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ const deprecated = () => {
);
};

function findCommunityCli(startDir = process.cwd()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is process.cwd() in this context? It seems fragile to assume that's where the dependency is declared.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's where the react-native command is being executed from, which should be project root. I am not familiar with use cases where it's being executed elsewhere.

// In monorepos, we cannot make any assumptions on where
// `@react-native-community/cli` gets installed. The safest way to find it
// (barring adding an optional peer dependency) is to start from the project
// root.
//
// Note that we're assuming that the current working directory is the project
// root. This is also what `@react-native-community/cli` assumes (see
// https://github.com/react-native-community/cli/blob/14.x/packages/cli-tools/src/findProjectRoot.ts).
const options = { paths: [startDir] };
const rncli = require.resolve('@react-native-community/cli', options);
return require(rncli);
}

function isMissingCliDependency(error) {
return (
error.code === 'MODULE_NOT_FOUND' &&
Expand Down Expand Up @@ -217,7 +231,7 @@ async function main() {
}

try {
return require('@react-native-community/cli').run(name);
return findCommunityCli().run(name);
} catch (e) {
if (isMissingCliDependency(e)) {
warnWithExplicitDependency();
Expand All @@ -231,7 +245,7 @@ if (require.main === module) {
main();
} else {
try {
cli = require('@react-native-community/cli');
cli = findCommunityCli();
} catch (e) {
// We silence @react-native-community/cli missing as it is no
// longer a dependency
Expand Down
Loading