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
This commit is contained in:
Riccardo Cipolleschi
2024-07-18 03:35:50 -07:00
committed by Facebook GitHub Bot
parent 9504e864bc
commit 8408b8bc96
@@ -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