Skip to content

Commit e65fde9

Browse files
authored
fix: use pod installed by bundler if possible (#2669)
* fix: use pod installed by bundler if possible * also try bundle install
1 parent 5316cb7 commit e65fde9

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-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.
@@ -86,7 +87,7 @@ async function runPodUpdate(loader: Ora) {
8687
'(this may take a few minutes)',
8788
)}`,
8889
);
89-
await execa('pod', ['repo', 'update']);
90+
await execaPod(['repo', 'update']);
9091
} catch (error) {
9192
// "pod" command outputs errors to stdout (at least some of them)
9293
logger.log((error as any).stderr || (error as any).stdout);
@@ -160,7 +161,7 @@ async function installPods(loader?: Ora, options?: PodInstallOptions) {
160161
// Check if "pod" is available and usable. It happens that there are
161162
// multiple versions of "pod" command and even though it's there, it exits
162163
// with a failure
163-
await execa('pod', ['--version']);
164+
await execaPod(['--version']);
164165
} catch (e) {
165166
loader.info();
166167
await installCocoaPods(loader);

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

Lines changed: 31 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;
@@ -215,3 +216,33 @@ export default async function resolvePods(
215216
}
216217
}
217218
}
219+
220+
export async function execaPod(args: string[], options?: execa.Options) {
221+
let podType: 'system' | 'bundle' = 'system';
222+
223+
try {
224+
// try bundle pod first
225+
await execa('bundle', ['exec', 'pod', '--version'], options);
226+
podType = 'bundle';
227+
} catch (bundlePodError) {
228+
// try to install bundle pod
229+
try {
230+
await execa('bundle', ['install']);
231+
await execa('bundle', ['exec', 'pod', '--version'], options);
232+
podType = 'bundle';
233+
} catch (bundleInstallError) {
234+
// fall back to system pod
235+
try {
236+
await execa('pod', ['--version'], options);
237+
podType = 'system';
238+
} catch (systemPodError) {
239+
throw new Error('cocoapods not installed');
240+
}
241+
}
242+
}
243+
244+
if (podType === 'bundle') {
245+
return execa('bundle', ['exec', 'pod', ...args], options);
246+
}
247+
return execa('pod', args, options);
248+
}

0 commit comments

Comments
 (0)