Allow changing the project path in react-native-xcode.sh #23273
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
When using react-native inside a monorepo with yarn workspaces the react-native installation can get hoisted and the assumption that the project is located in the folder where node_modules is is no longer true.
Solution
To handle this case I added an option to pass the path of the project root.
For example when using yarn workspace we can use something like this in the xcode scripts:
Assumes the following folder structure
/packages/myapp
/node_modules/react-native
Alternatives
It could be possible to change the default to
$PWD/..
since pwd is where the xcode project is located but then it would break if the native project structure is not the one we assume. To avoid the breaking change I decided to just keep the existing behaviour and allow changing the path withPROJECT_ROOT
.Changelog
[ios] [added] - Allow changing the project path in react-native-xcode.sh
Test Plan
Tested in a project that setting PROJECT_ROOT env overrides the default project root config and that not setting the variable keeps the same behaviour as before.