Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli/src/commands/init/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ async function installDependencies({
});

if (process.platform === 'darwin') {
await installPods({projectName, loader});
await installPods({projectName, loader, shouldUpdatePods: false});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we have an option to enable this for template configs - there's an issue with any custom templates that use pod specs where the template will fail to init because it could not find the pod specs (because a repo update is required)

See: invertase/react-native-firebase#2351

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

installPods checks if the template has a Podfile, so it's gonna work in your template as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strangely, this did not work for a react-native-firebase v6 user just now, in that they had stale cocoapods repo while the react-native-firebase v6 starter template was looking for some pretty recent pods, and pod install failed because pod update needed to run. A manual run of pod update for the user resolved it so I think somewhere in here is the root cause but I'm not sure what the interaction is.

I believe this is the template Podfile: https://github.com/invertase/react-native-firebase/blob/master/packages/template/project/ios/Podfile

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they're able to provide a repro, can you ask them to create a new issue about it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got a repro and logged it up here #752

}

loader.succeed();
Expand Down
9 changes: 8 additions & 1 deletion packages/cli/src/commands/upgrade/__tests__/upgrade.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ beforeEach(() => {
fs.unlinkSync = jest.fn((...args) => mockPushLog('[fs] unlink', args));
logs = [];
(execa: any).mockImplementation(mockExecaDefault);
Object.defineProperty(process, 'platform', {
value: 'darwin',
});
});

afterEach(() => {
Expand Down Expand Up @@ -174,6 +177,7 @@ test('fetches empty patch and installs deps', async () => {
$ execa git add package.json
$ execa git add yarn.lock
$ execa git add package-lock.json
info Installing CocoaPods dependencies (this may take a few minutes)
success Upgraded React Native to v0.58.4 🎉. Now you can review and commit the changes"
`);
}, 60000);
Expand Down Expand Up @@ -205,10 +209,11 @@ test('fetches regular patch, adds remote, applies patch, installs deps, removes
$ execa git add package.json
$ execa git add yarn.lock
$ execa git add package-lock.json
info Installing CocoaPods dependencies (this may take a few minutes)
info Running \\"git status\\" to check what changed...
$ execa git status
success Upgraded React Native to v0.58.4 🎉. Now you can review and commit the changes"
`);
`);
expect(
snapshotDiff(samplePatch, (fs.writeFileSync: any).mock.calls[0][1], {
contextLines: 1,
Expand Down Expand Up @@ -237,6 +242,7 @@ test('fetches regular patch, adds remote, applies patch, installs deps, removes
$ execa git add package.json
$ execa git add yarn.lock
$ execa git add package-lock.json
info Installing CocoaPods dependencies (this may take a few minutes)
info Running \\"git status\\" to check what changed...
$ execa git status
success Upgraded React Native to v0.58.4 🎉. Now you can review and commit the changes"
Expand Down Expand Up @@ -290,6 +296,7 @@ test('cleans up if patching fails,', async () => {
[fs] unlink tmp-upgrade-rn.patch
$ execa git status -s
error Patch failed to apply for unknown reason. Please fall back to manual way of upgrading
warn After resolving conflicts don't forget to run \\"pod install\\" inside \\"ios\\" directory
info You may find these resources helpful:
• Release notes: https://github.com/facebook/react-native/releases/tag/v0.58.4
• Manual Upgrade Helper: https://react-native-community.github.io/upgrade-helper/?from=0.57.8&to=0.58.4
Expand Down
40 changes: 40 additions & 0 deletions packages/cli/src/commands/upgrade/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import execa from 'execa';
import type {ConfigT} from 'types';
import {logger, CLIError, fetch} from '@react-native-community/cli-tools';
import * as PackageManager from '../../tools/packageManager';
import installPods from '../../tools/installPods';
import legacyUpgrade from './legacyUpgrade';

type FlagsT = {
Expand Down Expand Up @@ -163,6 +164,33 @@ const installDeps = async (newVersion, projectDir) => {
}
};

const installCocoaPodsDeps = async (projectDir, thirdPartyIOSDeps) => {
if (process.platform === 'darwin') {
try {
logger.info(
`Installing CocoaPods dependencies ${chalk.dim(
'(this may take a few minutes)',
)}`,
);
await installPods({
projectName: projectDir.split('/').pop(),
shouldUpdatePods: thirdPartyIOSDeps.length > 0,
});
} catch (error) {
if (error.stderr) {
logger.debug(
`"pod install" or "pod repo update" failed. Error output:\n${
error.stderr
}`,
);
}
logger.error(
'Installation of CocoaPods dependencies failed. Try to install them manually by running "pod install" in "ios" directory after finishing upgrade',
);
}
}
};

const applyPatch = async (
currentVersion: string,
newVersion: string,
Expand Down Expand Up @@ -265,6 +293,10 @@ async function upgrade(argv: Array<string>, ctx: ConfigT, args: FlagsT) {
projectDir,
'node_modules/react-native/package.json',
));
const thirdPartyIOSDeps = Object.values(ctx.dependencies).filter(
// $FlowFixMe
dependency => dependency.platforms.ios,
);

const newVersion = await getVersionToUpgradeTo(
argv,
Expand All @@ -285,6 +317,8 @@ async function upgrade(argv: Array<string>, ctx: ConfigT, args: FlagsT) {
if (patch === '') {
logger.info('Diff has no changes to apply, proceeding further');
await installDeps(newVersion, projectDir);
await installCocoaPodsDeps(projectDir, thirdPartyIOSDeps);

logger.success(
`Upgraded React Native to v${newVersion} 🎉. Now you can review and commit the changes`,
);
Expand Down Expand Up @@ -319,6 +353,7 @@ async function upgrade(argv: Array<string>, ctx: ConfigT, args: FlagsT) {
}
} else {
await installDeps(newVersion, projectDir);
await installCocoaPodsDeps(projectDir, thirdPartyIOSDeps);
logger.info('Running "git status" to check what changed...');
await execa('git', ['status'], {stdio: 'inherit'});
}
Expand All @@ -328,6 +363,11 @@ async function upgrade(argv: Array<string>, ctx: ConfigT, args: FlagsT) {
'Please run "git diff" to review the conflicts and resolve them',
);
}
if (process.platform === 'darwin') {
logger.warn(
'After resolving conflicts don\'t forget to run "pod install" inside "ios" directory',
);
}
logger.info(`You may find these resources helpful:
• Release notes: ${chalk.underline.dim(
`https://github.com/facebook/react-native/releases/tag/v${newVersion}`,
Expand Down
46 changes: 28 additions & 18 deletions packages/cli/src/tools/installPods.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,35 @@ import inquirer from 'inquirer';
import {logger} from '@react-native-community/cli-tools';
import {NoopLoader} from './loader';

async function updatePods(loader: typeof Ora) {
try {
loader.start(
`Updating CocoaPods repositories ${chalk.dim(
'(this may take a few minutes)',
)}`,
);
await execa('pod', ['repo', 'update']);
} catch (error) {
// "pod" command outputs errors to stdout (at least some of them)
logger.log(error.stderr || error.stdout);
loader.fail();

throw new Error(
`Failed to update CocoaPods repositories for iOS project.\nPlease try again manually: "pod repo update".\nCocoaPods documentation: ${chalk.dim.underline(
'https://cocoapods.org/',
)}`,
);
}
}

async function installPods({
projectName,
loader,
shouldUpdatePods,
}: {
projectName: string,
loader?: typeof Ora,
shouldUpdatePods: boolean,
}) {
loader = loader || new NoopLoader();
try {
Expand Down Expand Up @@ -77,27 +100,14 @@ async function installPods({
}
}

try {
loader.start(
`Updating CocoaPods repositories ${chalk.dim(
'(this may take a few minutes)',
)}`,
);
await execa('pod', ['repo', 'update']);
} catch (error) {
// "pod" command outputs errors to stdout (at least some of them)
logger.log(error.stderr || error.stdout);
loader.fail();

throw new Error(
`Failed to update CocoaPods repositories for iOS project.\nPlease try again manually: "pod repo update".\nCocoaPods documentation: ${chalk.dim.underline(
'https://cocoapods.org/',
)}`,
);
}
await updatePods(loader);
}
}

if (shouldUpdatePods) {
await updatePods(loader);
}

try {
loader.succeed();
loader.start(
Expand Down