Skip to content

Commit

Permalink
Support PNPM and workspace setups with pod install (#36485)
Browse files Browse the repository at this point in the history
Summary:
With Metro symlink support coming soon, users will expect isolated `node_modules` resolution and hoisted `react-native` to work. Currently, we make some fragile assumptions in Ruby scripts about the location of `node_modules` packages - in particular `react-native` and `react-native-community/cli-platform-ios`.

This change invokes `node` to resolve those paths, which should allow these scripts to work in any Node JS-compliant setup.

There's a small (sub-second) performance penalty involved in invoking node, but two of these in the context of `pod install` seems reasonable. Also, these scripts [already invoke `node`](https://github.com/react-native-community/cli/blob/fb78fe8ea2fabe8e6d43f5042ecbb92e8e484e12/packages/cli-platform-ios/native_modules.rb#L26), so this isn't an additional dependency or point of failure.

*This is probably the first Ruby I've written in >10 years, review suggestions welcome!*

Changelog:
[iOS][Added] - Support workspace and isolated setups with `pod install`

Pull Request resolved: #36485

Test Plan: `pod install` succeeds on a PNPM workspace setup where `react-native-community/cli` was not at the path previously expected by this script.

Reviewed By: cipolleschi

Differential Revision: D44097440

Pulled By: robhogan

fbshipit-source-id: 8300144888d8da019451b3f792b30eabc3a568cf
  • Loading branch information
robhogan authored and facebook-github-bot committed Mar 20, 2023
1 parent b9c64f3 commit 0eff8d6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
11 changes: 11 additions & 0 deletions packages/react-native/scripts/react_native_pods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@

$START_TIME = Time.now.to_i

# `@react-native-community/cli-platform-ios/native_modules` defines
# use_native_modules. We use node to resolve its path to allow for
# different packager and workspace setups. This is reliant on
# `@react-native-community/cli-platform-ios` being a direct dependency
# of `react-native`.
require Pod::Executable.execute_command('node', ['-p',
'require.resolve(
"@react-native-community/cli-platform-ios/native_modules.rb",
{paths: [process.argv[1]]},
)', __dir__]).strip

# This function returns the min iOS version supported by React Native
# By using this function, you won't have to manually change your Podfile
# when we change the minimum version supported by the framework.
Expand Down
9 changes: 7 additions & 2 deletions packages/react-native/template/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
# Resolve react_native_pods.rb with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p',
'require.resolve(
"react-native/scripts/react_native_pods.rb",
{paths: [process.argv[1]]},
)', __dir__]).strip

platform :ios, min_ios_version_supported
prepare_react_native_project!
Expand Down Expand Up @@ -50,6 +54,7 @@ target 'HelloWorld' do
# https://github.com/facebook/react-native/blob/main/scripts/react_native_pods.rb#L197-L202
react_native_post_install(
installer,
config[:reactNativePath],
:mac_catalyst_enabled => false
)
__apply_Xcode_12_5_M1_post_install_workaround(installer)
Expand Down

0 comments on commit 0eff8d6

Please sign in to comment.