diff --git a/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb b/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb index 690145b6144..4e4aa2ef4e6 100644 --- a/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb +++ b/packages/react-native/scripts/cocoapods/__tests__/utils-test.rb @@ -560,24 +560,28 @@ class UtilsTests < Test::Unit::TestCase # =================================== # # Test - Prepare React Native Project # # =================================== # - def test_createXcodeEnvIfMissing_whenItIsPresent_doNothing + def test_createXcodeEnvIfMissing_whenTheyArePresent_doNothing # Arrange FileMock.mocked_existing_files("/.xcode.env") + FileMock.mocked_existing_files("/.xcode.env.local") # Act ReactNativePodsUtils.create_xcode_env_if_missing(file_manager: FileMock) # Assert - assert_equal(FileMock.exist_invocation_params, ["/.xcode.env"]) + assert_equal(FileMock.exist_invocation_params, ["/.xcode.env", "/.xcode.env.local"]) assert_equal($collected_commands, []) end - def test_createXcodeEnvIfMissing_whenItIsNotPresent_createsIt + def test_createXcodeEnvIfMissing_whenTheyAreNotPresent_createsThem # Arrange # Act ReactNativePodsUtils.create_xcode_env_if_missing(file_manager: FileMock) # Assert - assert_equal(FileMock.exist_invocation_params, ["/.xcode.env"]) - assert_equal($collected_commands, ["echo 'export NODE_BINARY=$(command -v node)' > /.xcode.env"]) + assert_equal(FileMock.exist_invocation_params, ["/.xcode.env", "/.xcode.env.local"]) + assert_equal($collected_commands[0], "echo 'export NODE_BINARY=$(command -v node)' > /.xcode.env") + + assert_true($collected_commands[1].start_with? "echo 'export NODE_BINARY=") + assert_true($collected_commands[1].end_with? "' > /.xcode.env.local") end # ============================ # diff --git a/packages/react-native/scripts/cocoapods/utils.rb b/packages/react-native/scripts/cocoapods/utils.rb index 2f66018339b..e26f0cf1b2a 100644 --- a/packages/react-native/scripts/cocoapods/utils.rb +++ b/packages/react-native/scripts/cocoapods/utils.rb @@ -186,11 +186,15 @@ class ReactNativePodsUtils def self.create_xcode_env_if_missing(file_manager: File) relative_path = Pod::Config.instance.installation_root.relative_path_from(Pathname.pwd) file_path = file_manager.join(relative_path, '.xcode.env') - if file_manager.exist?(file_path) - return + + if !file_manager.exist?(file_path) + system("echo 'export NODE_BINARY=$(command -v node)' > #{file_path}") end - system("echo 'export NODE_BINARY=$(command -v node)' > #{file_path}") + if !file_manager.exist?("#{file_path}.local") + node_binary = `command -v node` + system("echo 'export NODE_BINARY=#{node_binary}' > #{file_path}.local") + end end # It examines the target_definition property and sets the appropriate value for