Fix use_react_native to support absolute paths
Summary:
While setting up a monorepo that required a custom react-native path location (react-native-macos in my case) I was getting the following error when running pod install
That's because build_codegen and checkAndGenerateEmptyThirdPartyProvider functions don't check if the given react_native_path is absolute or relative.
This PR fixes this problem by checking if react_native_path starts with /
Changelog:
[IOS] [FIXED] - Fix use_react_native to support custom react native absolute paths
Test Plan:
Modify rn-tester/Podfile to use an absolute path when calling use_react_native
E.g.
rn_path = File.dirname(`node --print "require.resolve('react-native/package.json')"`)
use_react_native!(
path: rn_path,
...
)
then run pod install
| Platform | Engine | Arch | Size (bytes) | Diff |
|---|---|---|---|---|
| android | hermes | arm64-v8a | 8,739,360 | -5,061 |
| android | hermes | armeabi-v7a | 8,050,513 | -6,114 |
| android | hermes | x86 | 9,229,736 | -5,812 |
| android | hermes | x86_64 | 9,081,581 | -4,797 |
| android | jsc | arm64-v8a | 9,302,721 | -4,544 |
| android | jsc | armeabi-v7a | 8,491,196 | -5,611 |
| android | jsc | x86 | 9,363,975 | -5,306 |
| android | jsc | x86_64 | 9,619,912 | -4,292 |
Base commit: 4540668c1598075f7ae46449bcbcbb70f69fcd8a Branch: main
Hi @cipolleschi, thanks for the feedback, I've just pushed a commit updating the code to use the basePath function along with a new test case on codegen-test.rb ensuring that absolute paths work
Hi @cipolleschi, is there something else that needs to be done here?
No, sorry... I've been caught up in the release of RC.4 and had little time to followup with the PRs. Importing it now.
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.
Could we use something like File.expand_path instead of rolling this ourselves?
/rebase
Hi @cipolleschi, sorry for the delay on this, it seems that these changes to use system APIs kinda break all tests involving paths, what should we do about it? Should I update the tests or should we revert to using the original implementation? I'm afraid that using system APIs could break something else as it affected a bunch of tests
So... the problem with these tests is that they are using a Mock for Pathname that can be found here: https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/cocoapods/tests/test_utils/PathnameMock.rb
So, we have two options:
- enhance the PathnameMock to support
absolute - we revert to the original version
In theory, using system API should be the right way to go. I'd say that we can timebox that to 1 hr, for example, to try and fix the tests. If we can't let's revert and I'll try that out myself once it landed. How do you feel about this?
@cipolleschi merged this pull request in facebook/react-native@835f62c189a76cf05a444f35d0215f51e1e155d8.
Oops, sorry for taking so long I this, I had this on my todo list for a while but couldn't get to work on that yet 😅
no problem! with the approaching of the end of the half I ended up with some free time on my hands and I was clearing up my queue of open things. It took actually very little effort! ;)
Anyway, thank you for carrying on most of the work! :D