Skip to content

Commit

Permalink
Fix path to node in .xcode.env.local (#43333)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #43333

This change fixes #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
  • Loading branch information
cipolleschi authored and Titozzz committed Jul 22, 2024
1 parent 1f80687 commit f996422
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/react-native/scripts/cocoapods/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,18 @@ def self.create_xcode_env_if_missing(file_manager: File)
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
Expand Down

1 comment on commit f996422

@kashkashio
Copy link

@kashkashio kashkashio commented on f996422 Jul 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to use that piece of code but for some reason i kept getting this alias
/private/var/folders/79/pkg907593gd3cc_7tb8p7hj80000gn/T/xfs-d4afa4c8/node

And it seems that the code isnt supporting a fall back so the file will be never made.

It happens when I use yarn to call pod install, if I use NPM or do directly pod install in the terminal, it finds the right path!

Please sign in to comment.