From cf62b885ee980560ab28c7becef3dc3f0943d698 Mon Sep 17 00:00:00 2001 From: buschco Date: Tue, 3 Jun 2025 13:19:55 +0200 Subject: [PATCH 1/2] fix: use pod installed by bundler if possible --- .../cli-config-apple/src/tools/installPods.ts | 7 ++++--- packages/cli-config-apple/src/tools/pods.ts | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/packages/cli-config-apple/src/tools/installPods.ts b/packages/cli-config-apple/src/tools/installPods.ts index 2d4c5acb4..31bd280d1 100644 --- a/packages/cli-config-apple/src/tools/installPods.ts +++ b/packages/cli-config-apple/src/tools/installPods.ts @@ -10,6 +10,7 @@ import { runSudo, } from '@react-native-community/cli-tools'; import runBundleInstall from './runBundleInstall'; +import {execaPod} from './pods'; interface PodInstallOptions { skipBundleInstall?: boolean; @@ -31,7 +32,7 @@ async function runPodInstall(loader: Ora, options: RunPodInstallOptions) { )} ${chalk.dim('(this may take a few minutes)')}`, ); - await execa('bundle', ['exec', 'pod', 'install'], { + await execaPod(['install'], { env: { RCT_NEW_ARCH_ENABLED: options?.newArchEnabled ? '1' : '0', RCT_IGNORE_PODS_DEPRECATION: '1', // From React Native 0.79 onwards, users shouldn't install CocoaPods manually. @@ -77,7 +78,7 @@ async function runPodUpdate(loader: Ora) { '(this may take a few minutes)', )}`, ); - await execa('pod', ['repo', 'update']); + await execaPod(['repo', 'update']); } catch (error) { // "pod" command outputs errors to stdout (at least some of them) logger.log((error as any).stderr || (error as any).stdout); @@ -151,7 +152,7 @@ async function installPods(loader?: Ora, options?: PodInstallOptions) { // Check if "pod" is available and usable. It happens that there are // multiple versions of "pod" command and even though it's there, it exits // with a failure - await execa('pod', ['--version']); + await execaPod(['--version']); } catch (e) { loader.info(); await installCocoaPods(loader); diff --git a/packages/cli-config-apple/src/tools/pods.ts b/packages/cli-config-apple/src/tools/pods.ts index 715012ef7..7ac61de01 100644 --- a/packages/cli-config-apple/src/tools/pods.ts +++ b/packages/cli-config-apple/src/tools/pods.ts @@ -14,6 +14,7 @@ import { } from '@react-native-community/cli-types'; import {ApplePlatform} from '../types'; import runCodegen from './runCodegen'; +import execa from 'execa'; interface ResolvePodsOptions { forceInstall?: boolean; @@ -215,3 +216,23 @@ export default async function resolvePods( } } } + +export async function execaPod(args: string[], options?: execa.Options) { + let podType: 'system' | 'bundle' = 'system'; + try { + await execa('bundle', ['exec', 'pod', '--version'], options); + podType = 'bundle'; + } catch (bundledPodError) { + try { + await execa('pod', ['--version'], options); + podType = 'system'; + } catch (systemPodError) { + throw new Error('cocoapods not installed'); + } + } + + if (podType === 'bundle') { + return execa('bundle', ['exec', 'pod', ...args], options); + } + return execa('pod', args, options); +} From d85ce6c5224120473cbd17a0e91af40b1ec3845c Mon Sep 17 00:00:00 2001 From: buschco Date: Sun, 27 Jul 2025 12:03:56 +0200 Subject: [PATCH 2/2] also try bundle install --- packages/cli-config-apple/src/tools/pods.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/cli-config-apple/src/tools/pods.ts b/packages/cli-config-apple/src/tools/pods.ts index 7ac61de01..49b53de97 100644 --- a/packages/cli-config-apple/src/tools/pods.ts +++ b/packages/cli-config-apple/src/tools/pods.ts @@ -219,15 +219,25 @@ export default async function resolvePods( export async function execaPod(args: string[], options?: execa.Options) { let podType: 'system' | 'bundle' = 'system'; + try { + // try bundle pod first await execa('bundle', ['exec', 'pod', '--version'], options); podType = 'bundle'; - } catch (bundledPodError) { + } catch (bundlePodError) { + // try to install bundle pod try { - await execa('pod', ['--version'], options); - podType = 'system'; - } catch (systemPodError) { - throw new Error('cocoapods not installed'); + await execa('bundle', ['install']); + await execa('bundle', ['exec', 'pod', '--version'], options); + podType = 'bundle'; + } catch (bundleInstallError) { + // fall back to system pod + try { + await execa('pod', ['--version'], options); + podType = 'system'; + } catch (systemPodError) { + throw new Error('cocoapods not installed'); + } } }