Skip to content

Conversation

@thymikee
Copy link
Member

@thymikee thymikee commented Feb 14, 2020

Summary:

See #406 (comment) for explanation what happens.

This PR makes use of a fact, that CLI is available under https://github.com/facebook/react-native/blob/master/cli.js, which works regardless of package manager hoisting strategy. It doesn't make us closer to PnP support because we're making assumption we have react-native in the node_modules tree without declaring a dependency, but we can fix that later.

Fixes #406

Test Plan:

CLI is properly resolved under npm.

@thymikee
Copy link
Member Author

Cocoapods tests are failing, because there's no react-native in our deps.


cli_resolve_script = "console.log(require('@react-native-community/cli').bin);"
# Resolving the path the RN CLI. The `@react-native-community/cli` module may not be there for certain package managers, so we fall back to resolving it through `react-native` package, that's always present in RN projects
cli_resolve_script = "try {console.log(require('@react-native-community/cli').bin);} catch (e) {console.log(require('react-native/cli').bin);}"
Copy link
Member Author

Choose a reason for hiding this comment

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

cc @alloy in reality this try/catch is only necessary for testing environment. Do you think it's better to leave this or somehow detect we're in "test" environment and change path accordingly? (usually a bad idea in my experience)

Copy link
Member

Choose a reason for hiding this comment

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

Might be better to mock execute_command instead?

@thymikee thymikee merged commit 55eb34b into master Feb 14, 2020
@thymikee thymikee deleted the fix/cli-resolve branch February 14, 2020 12:04
thymikee added a commit that referenced this pull request Feb 14, 2020
* fix: resolve CLI through react-native to avoid hoisting issues

* fix tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot find module '@react-native-community/cli'

3 participants