react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Fix use_react_native to support absolute paths

Open gabrieldonadel opened this issue 2 years ago • 7 comments

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

image

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

gabrieldonadel avatar May 24 '23 03:05 gabrieldonadel

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

analysis-bot avatar May 24 '23 03:05 analysis-bot

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

gabrieldonadel avatar May 24 '23 12:05 gabrieldonadel

Hi @cipolleschi, is there something else that needs to be done here?

gabrieldonadel avatar May 26 '23 11:05 gabrieldonadel

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 avatar May 29 '23 14:05 cipolleschi

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar May 30 '23 14:05 facebook-github-bot

Could we use something like File.expand_path instead of rolling this ourselves?

NickGerleman avatar May 30 '23 17:05 NickGerleman

/rebase

cipolleschi avatar Jun 14 '23 15:06 cipolleschi

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

gabrieldonadel avatar Jun 16 '23 15:06 gabrieldonadel

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:

  1. enhance the PathnameMock to support absolute
  2. 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 avatar Jun 19 '23 15:06 cipolleschi

@cipolleschi merged this pull request in facebook/react-native@835f62c189a76cf05a444f35d0215f51e1e155d8.

facebook-github-bot avatar Jun 30 '23 11:06 facebook-github-bot

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 😅

gabrieldonadel avatar Jun 30 '23 11:06 gabrieldonadel

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

cipolleschi avatar Jun 30 '23 15:06 cipolleschi