From 3cbaddbc164b9dc326b2a7ddc0b35ce885bc7d9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Kwas=CC=81niewski?= Date: Fri, 13 Sep 2024 09:44:19 -0700 Subject: [PATCH] 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 --- .../sdks/hermes-engine/hermes-engine.podspec | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/react-native/sdks/hermes-engine/hermes-engine.podspec b/packages/react-native/sdks/hermes-engine/hermes-engine.podspec index 787b55c3fc8..9fe7d73fbc3 100644 --- a/packages/react-native/sdks/hermes-engine/hermes-engine.podspec +++ b/packages/react-native/sdks/hermes-engine/hermes-engine.podspec @@ -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")))