Skip to content

Commit 9a9f8b4

Browse files
kittenm-bert
andauthored
fix(pods): Fix invalid react-native/../react-native resolution for aliases (#4232)
## Description Related: software-mansion/react-native-reanimated#9592 (same fix for `react-native-reanimated` and `react-native-worklets`) The pod script attempts to resolve `react-native/package.json` to get to the `version` and perform a version check. It however performs a redundant `react-native/../react-native` resolution i.e. it essentially performs `path.dirname(require.resolve('react-native/package.json'))` (correct), but then joins this with `${dir}/..`, then re-joins this with `react-native`. Re-entering the `react-native` directory can be invalid in case of symlinks in the `node_modules` structure. The easiest way to reproduce an issue is to use react-native-tvos's pattern of aliasing `"react-native": "npm:react-native-tvos@x.x.x"`. With isolated dependencies this will point a symlink at a directory that's named `react-native-tvos` and not `react-native`. The also applies to local `link:` dependency specifiers. Essentially, the directory name `react-native` is unnecessarily enforced. This would lead to a cryptic `file: no implicit conversion of nil into String.` error ## Test plan - Existing `pod install` in working projects should continue passing unchanged - https://github.com/kitten/douglowder--with-monorepo-tv-test/tree/init-pnpm - `pnpm i` then in `apps/tv` run `pnpm prebuild` (which runs `pod install`) --------- Co-authored-by: Michał Bert <63123542+m-bert@users.noreply.github.com>
1 parent f417709 commit 9a9f8b4

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

packages/react-native-gesture-handler/RNGestureHandler.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ is_gh_example_app = ENV["GH_EXAMPLE_APP_NAME"] != nil
55

66
compilation_metadata_dir = "CompilationDatabase"
77
compilation_metadata_generation_flag = is_gh_example_app ? '-gen-cdb-fragment-path ' + compilation_metadata_dir : ''
8-
version_flag = "-DREACT_NATIVE_MINOR_VERSION=#{get_react_native_minor_version()}"
8+
version_flag = "-DREACT_NATIVE_MINOR_VERSION=#{rngh_get_react_native_minor_version()}"
99

1010
Pod::Spec.new do |s|
1111
# NPM package specification

packages/react-native-gesture-handler/scripts/gesture_handler_utils.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
def try_to_parse_react_native_package_json(node_modules_dir)
2-
react_native_package_json_path = File.join(node_modules_dir, 'react-native/package.json')
1+
def rngh_try_to_parse_react_native_package_json(react_native_dir)
2+
react_native_package_json_path = File.join(react_native_dir, 'package.json')
33

44
if !File.exist?(react_native_package_json_path)
55
return nil
@@ -8,13 +8,13 @@ def try_to_parse_react_native_package_json(node_modules_dir)
88
return JSON.parse(File.read(react_native_package_json_path))
99
end
1010

11-
def get_react_native_minor_version()
12-
react_native_node_modules_dir = File.join(File.dirname(`cd "#{Pod::Config.instance.installation_root.to_s}" && node --print "require.resolve('react-native/package.json')"`), '..')
13-
react_native_json = try_to_parse_react_native_package_json(react_native_node_modules_dir)
11+
def rngh_get_react_native_minor_version()
12+
react_native_dir = File.dirname(`cd "#{Pod::Config.instance.installation_root.to_s}" && node --print "require.resolve('react-native/package.json')"`)
13+
react_native_json = rngh_try_to_parse_react_native_package_json(react_native_dir)
1414

1515
if react_native_json == nil
1616
node_modules_dir = ENV["REACT_NATIVE_NODE_MODULES_DIR"]
17-
react_native_json = try_to_parse_react_native_package_json(node_modules_dir)
17+
react_native_json = rngh_try_to_parse_react_native_package_json(File.join(node_modules_dir, 'react-native'))
1818
end
1919

2020
if react_native_json == nil

0 commit comments

Comments
 (0)