[ios] Resolve use_react_native!(path) param in reacft_native_pods.rb from Pathname.pwd
#54948
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:
Note
This is a bit of a speculative fix that's based on trying to get a bare project with
react-native-macosto link directly against it in an isolated installation, which makes passingpathset torequire.resolve('react-native-macos/package.json')more convenient than constructing a relative path first.The
pathargument inreact_native_pods.rbis not resolved but instead later joined usingFile.join(relative_path_from_current, path). This doesn't actually resolve the path, meaning, ifpathis absolute it's appended to this first relative path.Instead, we should use
Pathname#joinand join the path to the pathname, guaranteeing it to be absolute, then construct relative paths (for the prefix) usingrelative_path_fromagainst the installation root.If we don't do this, the absolute path gets treated as a relative path (e.g.
./Users), which leads to errors such as:Since absolute paths are unambiguous the change should be safe.
Changelog:
[IOS] Allow absolute react-native paths to be passed to
use_react_native!in project podfilesTest Plan:
This can be replicated by replacing
pathin theuse_react_nativecall with an absolute resolution and runningpod installafter, for example:Usually, the
pathargument gets resolved from the react-native-config viaconfig[:reactNativePath]. However, this makes the implicit assumption thatuse_native_modules!has already converted this to a relative path.