-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix use_react_native to support absolute paths #37545
Fix use_react_native to support absolute paths #37545
Conversation
Base commit: 4540668 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @gabrieldonadel! Thank you so much for the contribution.
I added a suggestion to improve readability and maintainability.
Also, there should be some tests in __tests__/codegen-test.rb
: it would be great to duplicate one of those tests with an absolute path, so we make sure not to break this in the future!
Thank you so much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @gabrieldonadel! Thank you so much for the contribution.
I added a suggestion to improve readability and maintainability.
Also, there should be some tests in __tests__/codegen-test.rb
: it would be great to duplicate one of those tests with an absolute path, so we make sure not to break this in the future!
Thank you so much.
Hi @cipolleschi, thanks for the feedback, I've just pushed a commit updating the code to use the |
3dffd62
to
4ffdb48
Compare
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 |
@@ -108,3 +108,11 @@ def run_codegen!( | |||
codegen_utils.generate_react_codegen_podspec!(react_codegen_spec, codegen_output_dir) | |||
end | |||
end | |||
|
|||
def basePath(react_native_path, relative_installation_root) | |||
if react_native_path.start_with?("/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if react_native_path.start_with?("/") | |
if Pathname.new(react_native_path).absolute |
This suggestion also need a require 'pathname'
after the license.
(See here for reference)
@@ -11,8 +11,8 @@ | |||
# - dir_manager: a class that implements the `Dir` interface. Defaults to `Dir`, the Dependency can be injected for testing purposes. | |||
# @throws an error if it could not find the codegen folder. | |||
def build_codegen!(react_native_path, relative_installation_root, dir_manager: Dir) | |||
codegen_repo_path = "#{relative_installation_root}/#{react_native_path}/../react-native-codegen"; | |||
codegen_npm_path = "#{relative_installation_root}/#{react_native_path}/../@react-native/codegen"; | |||
codegen_repo_path = "#{basePath(react_native_path, relative_installation_root)}/../react-native-codegen"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following up with @NickGerleman suggestion, probably it is better to use some system APIs...
codegen_repo_path = "#{basePath(react_native_path, relative_installation_root)}/../react-native-codegen"; | |
codegen_repo_path = File.join(basePath(react_native_path, relative_installation_root), "..", "react-native-codegen") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing this seems to break some codegen tests, I'll try to investigate what's going on latter today
if react_native_path.start_with?("/") | ||
react_native_path | ||
else | ||
"#{relative_installation_root.to_s}/#{react_native_path}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"#{relative_installation_root.to_s}/#{react_native_path}" | |
File.join(relative_installation_root.to_s, react_native_path)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following @NickGerleman right suggestion, I left some comments to improve the codebase! :D
Thank you both for the review and the effort!
4099265
to
7594dde
Compare
/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:
In theory, using system API should be the right way to go. |
@cipolleschi merged this pull request in 835f62c. |
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 |
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
andcheckAndGenerateEmptyThirdPartyProvider
functions don't check if the givenreact_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 pathsTest Plan:
Modify rn-tester/Podfile to use an absolute path when calling
use_react_native
E.g.
then run
pod install