diff --git a/packages/cli/src/commands/init/init.js b/packages/cli/src/commands/init/init.js index 35099c883..c1eda4ace 100644 --- a/packages/cli/src/commands/init/init.js +++ b/packages/cli/src/commands/init/init.js @@ -162,7 +162,7 @@ async function installDependencies({ }); if (process.platform === 'darwin') { - await installPods({projectName, loader}); + await installPods({projectName, loader, shouldUpdatePods: false}); } loader.succeed(); diff --git a/packages/cli/src/commands/upgrade/__tests__/upgrade.test.js b/packages/cli/src/commands/upgrade/__tests__/upgrade.test.js index af689b03e..c4ad3379e 100644 --- a/packages/cli/src/commands/upgrade/__tests__/upgrade.test.js +++ b/packages/cli/src/commands/upgrade/__tests__/upgrade.test.js @@ -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(() => { @@ -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); @@ -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, @@ -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" @@ -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 diff --git a/packages/cli/src/commands/upgrade/upgrade.js b/packages/cli/src/commands/upgrade/upgrade.js index b20b788e9..3ace9cf60 100644 --- a/packages/cli/src/commands/upgrade/upgrade.js +++ b/packages/cli/src/commands/upgrade/upgrade.js @@ -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 = { @@ -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, @@ -265,6 +293,10 @@ async function upgrade(argv: Array, 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, @@ -285,6 +317,8 @@ async function upgrade(argv: Array, 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`, ); @@ -319,6 +353,7 @@ async function upgrade(argv: Array, 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'}); } @@ -328,6 +363,11 @@ async function upgrade(argv: Array, 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}`, diff --git a/packages/cli/src/tools/installPods.js b/packages/cli/src/tools/installPods.js index 159fb8370..6327ba29c 100644 --- a/packages/cli/src/tools/installPods.js +++ b/packages/cli/src/tools/installPods.js @@ -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 { @@ -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(