Skip to content

Commit c8c0362

Browse files
simkathymikee
authored andcommitted
fix: run pod repo update after installing CocoaPods (#513)
* fix: run `pod repo update` after installing CocoaPods (#487) Added `pod repo update` command call after CocoaPods installation to avoid issues with pod command being unable to find specification for dependency. Added loader to CocoaPods installation step for consistency with other steps of init and better DX, removed logger info after 30s timeout because of redundancy with loader. Changed loader method before prompt for CocoaPods installation from `stop` to `info` for better prompt visibility. * always show installing pods step * add notice back * minor loader refactor * fix false positive for pod command being available * use pod --version for smaller output
1 parent 558fad2 commit c8c0362

File tree

5 files changed

+48
-33
lines changed

5 files changed

+48
-33
lines changed

packages/cli/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"@react-native-community/cli-platform-ios": "^2.2.0",
2929
"@react-native-community/cli-tools": "^2.0.2",
3030
"chalk": "^1.1.1",
31-
"command-exists": "^1.2.8",
3231
"commander": "^2.19.0",
3332
"compression": "^1.7.1",
3433
"connect": "^3.6.5",

packages/cli/src/commands/init/init.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ async function installDependencies({
154154
npm?: boolean,
155155
loader: typeof Ora,
156156
}) {
157-
loader.start('Installing all required dependencies');
157+
loader.start('Installing dependencies');
158158

159159
await PackageManager.installAll({
160160
preferYarn: !npm,

packages/cli/src/tools/installPods.js

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ import execa from 'execa';
44
import chalk from 'chalk';
55
import Ora from 'ora';
66
import inquirer from 'inquirer';
7-
import commandExists from 'command-exists';
87
import {logger} from '@react-native-community/cli-tools';
9-
10-
const COCOAPODS_INSTALLATION_TIMEOUT = 30000;
8+
import {NoopLoader} from './loader';
119

1210
async function installPods({
1311
projectName,
@@ -16,6 +14,7 @@ async function installPods({
1614
projectName: string,
1715
loader?: typeof Ora,
1816
}) {
17+
loader = loader || new NoopLoader();
1918
try {
2019
if (!fs.existsSync('ios')) {
2120
return;
@@ -30,11 +29,12 @@ async function installPods({
3029
}
3130

3231
try {
33-
await commandExists('pod');
32+
// Check if "pod" is available and usable. It happens that there are
33+
// multiple versions of "pod" command and even though it's there, it exits
34+
// with a failure
35+
await execa('pod', ['--version']);
3436
} catch (e) {
35-
if (loader) {
36-
loader.stop();
37-
}
37+
loader.info();
3838

3939
const {shouldInstallCocoaPods} = await inquirer.prompt([
4040
{
@@ -49,20 +49,23 @@ async function installPods({
4949
]);
5050

5151
if (shouldInstallCocoaPods) {
52-
// Show a helpful notice when installation takes more than usually
53-
const cocoaPodsInstallationTimeMessage = setTimeout(
54-
() =>
55-
logger.info('Installing CocoaPods, this may take a few minutes'),
56-
COCOAPODS_INSTALLATION_TIMEOUT,
57-
);
52+
loader.start('Installing CocoaPods');
53+
5854
try {
5955
// First attempt to install `cocoapods`
60-
await execa('gem', ['install', 'cocoapods']);
56+
await execa('gem', ['install', 'cocoapods', '--no-document']);
57+
loader.succeed();
6158
} catch (_error) {
6259
try {
6360
// If that doesn't work then try with sudo
64-
await execa('sudo', ['gem', 'install', 'cocoapods']);
61+
await execa('sudo', [
62+
'gem',
63+
'install',
64+
'cocoapods',
65+
'--no-document',
66+
]);
6567
} catch (error) {
68+
loader.fail();
6669
logger.log(error.stderr);
6770

6871
throw new Error(
@@ -71,19 +74,36 @@ async function installPods({
7174
)}`,
7275
);
7376
}
74-
} finally {
75-
clearTimeout(cocoaPodsInstallationTimeMessage);
7677
}
7778

78-
// This only shows when `CocoaPods` is automatically installed,
79-
// if it's already installed then we just show the `Installing dependencies` step
80-
if (loader) {
81-
loader.start('Installing CocoaPods dependencies');
79+
try {
80+
loader.start(
81+
`Updating CocoaPods repositories ${chalk.dim(
82+
'(this make take a few minutes)',
83+
)}`,
84+
);
85+
await execa('pod', ['repo', 'update']);
86+
} catch (error) {
87+
// "pod" command outputs errors to stdout (at least some of them)
88+
logger.log(error.stderr || error.stdout);
89+
loader.fail();
90+
91+
throw new Error(
92+
`Failed to update CocoaPods repositories for iOS project.\nPlease try again manually: "pod repo update".\nCocoaPods documentation: ${chalk.dim.underline(
93+
'https://cocoapods.org/',
94+
)}`,
95+
);
8296
}
8397
}
8498
}
8599

86100
try {
101+
loader.succeed();
102+
loader.start(
103+
`Installing CocoaPods dependencies ${chalk.dim(
104+
'(this make take a few minutes)',
105+
)}`,
106+
);
87107
await execa('pod', ['install']);
88108
} catch (error) {
89109
// "pod" command outputs errors to stdout (at least some of them)

packages/cli/src/tools/loader.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
import Ora from 'ora';
33
import logger from './logger';
44

5-
class OraMock {
5+
class OraNoop {
66
succeed() {}
77
fail() {}
8-
start() {}
8+
start(message?: string) {}
9+
info(message?: string) {}
910
}
1011

11-
function getLoader(): typeof Ora {
12-
return logger.isVerbose() ? OraMock : Ora;
12+
export function getLoader(): typeof Ora {
13+
return logger.isVerbose() ? OraNoop : Ora;
1314
}
1415

15-
export {getLoader};
16+
export const NoopLoader = OraNoop;

yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2948,11 +2948,6 @@ combined-stream@^1.0.6, combined-stream@~1.0.6:
29482948
dependencies:
29492949
delayed-stream "~1.0.0"
29502950

2951-
command-exists@^1.2.8:
2952-
version "1.2.8"
2953-
resolved "https://registry.yarnpkg.com/command-exists/-/command-exists-1.2.8.tgz#715acefdd1223b9c9b37110a149c6392c2852291"
2954-
integrity sha512-PM54PkseWbiiD/mMsbvW351/u+dafwTJ0ye2qB60G1aGQP9j3xK2gmMDc+R34L3nDtx4qMCitXT75mkbkGJDLw==
2955-
29562951
commander@^2.19.0, commander@~2.19.0:
29572952
version "2.19.0"
29582953
resolved "https://registry.yarnpkg.com/commander/-/commander-2.19.0.tgz#f6198aa84e5b83c46054b94ddedbfed5ee9ff12a"

0 commit comments

Comments
 (0)