From 8408b8bc96db15e265ca65fce7875ee65dcfdcec Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Thu, 18 Jul 2024 03:35:50 -0700 Subject: [PATCH] Fix path to node in .xcode.env.local (#43333) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43333 This change fixes https://github.com/facebook/react-native/issues/43285. Basically, when using a `yarn` alias to install pods, yarn creates a copy of the `node` and `yarn` executables and the `command -v node` command will return the path to that executable. ## Changelog [iOS][Fixed] - Do not use temporary node when creating the .xcode.env.local Reviewed By: dmytrorykun Differential Revision: D54542774 fbshipit-source-id: 3ab0d0bb441988026feff9d5390dcfd10869a1b5 --- packages/react-native/scripts/cocoapods/utils.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/react-native/scripts/cocoapods/utils.rb b/packages/react-native/scripts/cocoapods/utils.rb index 7db8dacfd3b..42452fb25dd 100644 --- a/packages/react-native/scripts/cocoapods/utils.rb +++ b/packages/react-native/scripts/cocoapods/utils.rb @@ -233,7 +233,18 @@ class ReactNativePodsUtils end if !file_manager.exist?("#{file_path}.local") - node_binary = `command -v node` + # When installing pods with a yarn alias, yarn creates a fake yarn and node executables + # in a temporary folder. + # Using `type -a` we are able to retrieve all the paths of an executable and we can + # exclude the temporary ones. + # see https://github.com/facebook/react-native/issues/43285 for more info + node_binary = `type -a node`.split("\n").map { |path| + path.gsub!("node is ", "") + }.select { |b| + return !b.start_with?("/var") + } + + node_binary = node_binary[0] system("echo 'export NODE_BINARY=#{node_binary}' > #{file_path}.local") end end