From 1fa9f35077bf04daacaedaf61060547449a048f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Tue, 19 Dec 2023 11:31:46 +0100 Subject: [PATCH] Introduce a reusable `resolve_node_module` function --- .../react-native/scripts/react_native_pods.rb | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/react-native/scripts/react_native_pods.rb b/packages/react-native/scripts/react_native_pods.rb index 1f6591eb1e361b..156435bc43330f 100644 --- a/packages/react-native/scripts/react_native_pods.rb +++ b/packages/react-native/scripts/react_native_pods.rb @@ -24,17 +24,16 @@ $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 resolves a path using the node_modules resolution algorithm +# Using this will allow for different packager and workspace setups. +def resolve_node_module(request, from) + code = "require.resolve(process.argv[1], { paths: [process.argv[2]] })" + return Pod::Executable.execute_command('node', ['-p', code, request, from], true).strip +end +# `@react-native-community/cli-platform-ios/native_modules` defines use_native_modules. +# This is reliant on `@react-native-community/cli-platform-ios` being a direct dependency of `react-native`. +require resolve_node_module("@react-native-community/cli-platform-ios/native_modules.rb", __dir__) def min_ios_version_supported return Helpers::Constants.min_ios_version_supported