Skip to content

Commit 71647bf

Browse files
kittentjzel
andauthored
fix(pods): Fix invalid react-native/../react-native resolution for aliases (#9592)
## Description Related: software-mansion/react-native-gesture-handler#4232 (same fix for `react-native-gesture-handler`) The pod scripts attempt 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: Tomasz Żelawski <tzelawski@gmail.com>
1 parent 831b317 commit 71647bf

2 files changed

Lines changed: 16 additions & 16 deletions

File tree

packages/react-native-reanimated/scripts/reanimated_utils.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module ReanimatedUtils
22
module_function
33

4-
def try_to_parse_react_native_package_json(node_modules_dir)
5-
react_native_package_json_path = File.join(node_modules_dir, 'react-native/package.json')
4+
def try_to_parse_react_native_package_json(react_native_dir)
5+
react_native_package_json_path = File.join(react_native_dir, 'package.json')
66
if !File.exist?(react_native_package_json_path)
77
return nil
88
end
@@ -13,17 +13,17 @@ def find_config()
1313
result = {
1414
:is_reanimated_example_app => nil,
1515
:react_native_version => nil,
16-
:react_native_node_modules_dir => nil,
16+
:react_native_dir => nil,
1717
:react_native_common_dir => nil,
1818
}
1919

20-
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')"`), '..')
21-
react_native_json = try_to_parse_react_native_package_json(react_native_node_modules_dir)
20+
react_native_dir = File.dirname(`cd "#{Pod::Config.instance.installation_root.to_s}" && node --print "require.resolve('react-native/package.json')"`)
21+
react_native_json = try_to_parse_react_native_package_json(react_native_dir)
2222

2323
if react_native_json == nil
2424
# user configuration, just in case
2525
node_modules_dir = ENV["REACT_NATIVE_NODE_MODULES_DIR"]
26-
react_native_json = try_to_parse_react_native_package_json(node_modules_dir)
26+
react_native_json = try_to_parse_react_native_package_json(File.join(node_modules_dir, 'react-native'))
2727
end
2828

2929
if react_native_json == nil
@@ -38,10 +38,10 @@ def find_config()
3838

3939
result[:is_reanimated_example_app] = ENV["IS_REANIMATED_EXAMPLE_APP"] != nil
4040
result[:react_native_version] = react_native_json['version']
41-
result[:react_native_node_modules_dir] = File.expand_path(react_native_node_modules_dir)
41+
result[:react_native_dir] = File.expand_path(react_native_dir)
4242

4343
pods_root = Pod::Config.instance.project_pods_root
44-
react_native_common_dir_absolute = File.join(react_native_node_modules_dir, 'react-native', 'ReactCommon')
44+
react_native_common_dir_absolute = File.join(react_native_dir, 'ReactCommon')
4545
react_native_common_dir_relative = Pathname.new(react_native_common_dir_absolute).relative_path_from(pods_root).to_s
4646
result[:react_native_common_dir] = react_native_common_dir_relative
4747

packages/react-native-worklets/scripts/worklets_utils.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module WorkletsUtils
22
module_function
33

4-
def try_to_parse_react_native_package_json(node_modules_dir)
5-
react_native_package_json_path = File.join(node_modules_dir, 'react-native/package.json')
4+
def try_to_parse_react_native_package_json(react_native_dir)
5+
react_native_package_json_path = File.join(react_native_dir, 'package.json')
66
if !File.exist?(react_native_package_json_path)
77
return nil
88
end
@@ -15,17 +15,17 @@ def find_config()
1515
:fetch_preview_flag => nil,
1616
:is_reanimated_example_app => nil,
1717
:react_native_version => nil,
18-
:react_native_node_modules_dir => nil,
18+
:react_native_dir => nil,
1919
:react_native_common_dir => nil,
2020
}
2121

22-
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')"`), '..')
23-
react_native_json = try_to_parse_react_native_package_json(react_native_node_modules_dir)
22+
react_native_dir = File.dirname(`cd "#{Pod::Config.instance.installation_root.to_s}" && node --print "require.resolve('react-native/package.json')"`)
23+
react_native_json = try_to_parse_react_native_package_json(react_native_dir)
2424

2525
if react_native_json == nil
2626
# user configuration, just in case
2727
node_modules_dir = ENV["REACT_NATIVE_NODE_MODULES_DIR"]
28-
react_native_json = try_to_parse_react_native_package_json(node_modules_dir)
28+
react_native_json = try_to_parse_react_native_package_json(File.join(node_modules_dir, 'react-native'))
2929
end
3030

3131
if react_native_json == nil
@@ -34,10 +34,10 @@ def find_config()
3434

3535
result[:is_reanimated_example_app] = ENV["IS_REANIMATED_EXAMPLE_APP"] != nil
3636
result[:react_native_version] = react_native_json['version']
37-
result[:react_native_node_modules_dir] = File.expand_path(react_native_node_modules_dir)
37+
result[:react_native_dir] = File.expand_path(react_native_dir)
3838

3939
pods_root = Pod::Config.instance.project_pods_root
40-
react_native_common_dir_absolute = File.join(react_native_node_modules_dir, 'react-native', 'ReactCommon')
40+
react_native_common_dir_absolute = File.join(react_native_dir, 'ReactCommon')
4141
react_native_common_dir_relative = Pathname.new(react_native_common_dir_absolute).relative_path_from(pods_root).to_s
4242
result[:react_native_common_dir] = react_native_common_dir_relative
4343

0 commit comments

Comments
 (0)