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 1ca5693af..a4710389e 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; @@ -214,3 +215,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); +}