fix(iOS): fallback to old path when dynamic resolve fails (#46432)

Summary:
This PR is a follow-up after https://github.com/facebook/react-native/issues/46181 this change makes sure that if the `require.resolve` fails we still fall back to the old behavior.

The `require.resolve` was failing for local builds of OOT platforms (because in OOT platforms mono repo `react-native` is renamed to `react-native-platform-name`)

## Changelog:

[IOS] [FIXED] - Fallback to old resolve mechanism when node require fails to resolve react native path

Pull Request resolved: https://github.com/facebook/react-native/pull/46432

Test Plan: CI Green

Reviewed By: christophpurrer

Differential Revision: D62577183

Pulled By: cipolleschi

fbshipit-source-id: d62d9c2a5eee3546a81d2aad52b7f73763315b18
This commit is contained in:
Oskar Kwaśniewski
2024-09-13 09:44:19 -07:00
committed by Facebook GitHub Bot
parent 11a2ab1cc5
commit 3cbaddbc16
@@ -6,12 +6,17 @@
require "json"
require_relative "./hermes-utils.rb"
react_native_path = File.dirname(Pod::Executable.execute_command('node', ['-p',
'require.resolve(
"react-native",
begin
react_native_path = File.dirname(Pod::Executable.execute_command('node', ['-p',
'require.resolve(
"react-native",
{paths: [process.argv[1]]},
)', __dir__]).strip
)
)', __dir__]).strip
)
rescue => e
# Fallback to the parent directory if the above command fails (e.g when building locally in OOT Platform)
react_native_path = File.join(__dir__, "..", "..")
end
# package.json
package = JSON.parse(File.read(File.join(react_native_path, "package.json")))