Skip to content

Commit e1a0ffe

Browse files
committed
fix: use pod installed by bundler if possible
1 parent 8492fde commit e1a0ffe

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

packages/cli-config-apple/src/tools/installPods.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
runSudo,
1111
} from '@react-native-community/cli-tools';
1212
import runBundleInstall from './runBundleInstall';
13+
import {execaPod} from './pods';
1314

1415
interface PodInstallOptions {
1516
skipBundleInstall?: boolean;
@@ -31,7 +32,7 @@ async function runPodInstall(loader: Ora, options: RunPodInstallOptions) {
3132
)} ${chalk.dim('(this may take a few minutes)')}`,
3233
);
3334

34-
await execa('bundle', ['exec', 'pod', 'install'], {
35+
await execaPod(['install'], {
3536
env: {
3637
RCT_NEW_ARCH_ENABLED: options?.newArchEnabled ? '1' : '0',
3738
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) {
7778
'(this may take a few minutes)',
7879
)}`,
7980
);
80-
await execa('pod', ['repo', 'update']);
81+
await execaPod(['repo', 'update']);
8182
} catch (error) {
8283
// "pod" command outputs errors to stdout (at least some of them)
8384
logger.log((error as any).stderr || (error as any).stdout);
@@ -151,7 +152,7 @@ async function installPods(loader?: Ora, options?: PodInstallOptions) {
151152
// Check if "pod" is available and usable. It happens that there are
152153
// multiple versions of "pod" command and even though it's there, it exits
153154
// with a failure
154-
await execa('pod', ['--version']);
155+
await execaPod(['--version']);
155156
} catch (e) {
156157
loader.info();
157158
await installCocoaPods(loader);

packages/cli-config-apple/src/tools/pods.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from '@react-native-community/cli-types';
1515
import {ApplePlatform} from '../types';
1616
import runCodegen from './runCodegen';
17+
import execa from 'execa';
1718

1819
interface ResolvePodsOptions {
1920
forceInstall?: boolean;
@@ -214,3 +215,23 @@ export default async function resolvePods(
214215
}
215216
}
216217
}
218+
219+
export async function execaPod(args: string[], options?: execa.Options) {
220+
let podType: 'system' | 'bundle' = 'system';
221+
try {
222+
await execa('bundle', ['exec', 'pod', '--version'], options);
223+
podType = 'bundle';
224+
} catch (bundledPodError) {
225+
try {
226+
await execa('pod', ['--version'], options);
227+
podType = 'system';
228+
} catch (systemPodError) {
229+
throw new Error('cocoapods not installed');
230+
}
231+
}
232+
233+
if (podType === 'bundle') {
234+
return execa('bundle', ['exec', 'pod', ...args], options);
235+
}
236+
return execa('pod', args, options);
237+
}

0 commit comments

Comments
 (0)