Commit 33641f0
Summary:
> [!NOTE]
> This is a bit of a speculative fix that's based on trying to get a bare project with `react-native-macos` to link directly against it in an isolated installation, which makes passing `path` set to `require.resolve('react-native-macos/package.json')` more convenient than constructing a relative path first.
The `path` argument in `react_native_pods.rb` is not resolved but instead later joined using `File.join(relative_path_from_current, path)`. This doesn't actually resolve the path, meaning, if `path` is absolute it's appended to this first relative path.
Instead, we should use `Pathname#join` and join the path to the pathname, guaranteeing it to be absolute, then construct relative paths (for the prefix) using `relative_path_from` against 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:
> [!] Invalid Podfile file: Couldn't find the React Native package.json file at ./Users/phil/git/expo/expo-pnpm/packages/expo/package.json.
Since absolute paths are unambiguous the change should be safe.
## Changelog:
[IOS][Fixed] - Allow absolute react-native paths to be passed to `use_react_native!` in project podfiles
Pull Request resolved: #54948
Test Plan:
This can be replicated by replacing `path` in the `use_react_native` call with an absolute resolution and running `pod install` after, for example:
```rb
use_react_native!(
:path => File.dirname(`node --print "require.resolve('react-native/package.json')"`),
:hermes_enabled => podfile_properties['expo.jsEngine'] == nil || podfile_properties['expo.jsEngine'] == 'hermes',
# An absolute path to your application root.
:app_path => "#{Pod::Config.instance.installation_root}/..",
)
```
Usually, the `path` argument gets resolved from the react-native-config via `config[:reactNativePath]`. However, this makes the implicit assumption that `use_native_modules!` has already converted this to a relative path.
Reviewed By: cortinico, vzaidman
Differential Revision: D90261384
Pulled By: cipolleschi
fbshipit-source-id: fb7482a2f5adb8452a1c300d7a26b22129e4171a
1 parent 3b46755 commit 33641f0
1 file changed
Lines changed: 5 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
78 | 81 | | |
79 | 82 | | |
80 | 83 | | |
81 | | - | |
| 84 | + | |
82 | 85 | | |
83 | 86 | | |
84 | 87 | | |
| |||
107 | 110 | | |
108 | 111 | | |
109 | 112 | | |
110 | | - | |
111 | | - | |
| 113 | + | |
112 | 114 | | |
113 | 115 | | |
114 | 116 | | |
115 | 117 | | |
116 | 118 | | |
117 | 119 | | |
118 | | - | |
119 | | - | |
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
| |||
0 commit comments