diff --git a/packages/cli/src/commands/upgrade/__tests__/upgrade.test.js b/packages/cli/src/commands/upgrade/__tests__/upgrade.test.js index fbd09d97c..2730bb013 100644 --- a/packages/cli/src/commands/upgrade/__tests__/upgrade.test.js +++ b/packages/cli/src/commands/upgrade/__tests__/upgrade.test.js @@ -112,8 +112,7 @@ test('fetches empty patch and installs deps', async () => { expect(flushOutput()).toMatchInlineSnapshot(` "info Fetching diff between v0.57.8 and v0.58.4... info Diff has no changes to apply, proceeding further -warn Continuing after failure. Most of the files are upgraded but you will need to deal with some conflicts manually -info Installing react-native@0.58.4 and its peer dependencies... +info Installing \\"react-native@0.58.4\\" and its peer dependencies... $ execa npm info react-native@0.58.4 peerDependencies --json $ yarn add react-native@0.58.4 react@16.6.3 $ execa git add package.json @@ -135,7 +134,8 @@ $ execa git apply --check tmp-upgrade-rn.patch --exclude=package.json -p2 --3way info Applying diff... $ execa git apply tmp-upgrade-rn.patch --exclude=package.json -p2 --3way [fs] unlink tmp-upgrade-rn.patch -info Installing react-native@0.58.4 and its peer dependencies... +$ execa git status -s +info Installing \\"react-native@0.58.4\\" and its peer dependencies... $ execa npm info react-native@0.58.4 peerDependencies --json $ yarn add react-native@0.58.4 react@16.6.3 $ execa git add package.json @@ -186,19 +186,13 @@ info Applying diff (excluding: package.json, .flowconfig)... $ execa git apply tmp-upgrade-rn.patch --exclude=package.json --exclude=.flowconfig -p2 --3way error: .flowconfig: does not exist in index error Automatically applying diff failed -info Here's the diff we tried to apply: https://github.com/react-native-community/rn-diff-purge/compare/version/0.57.8...version/0.58.4 -info You may find release notes helpful: https://github.com/facebook/react-native/releases/tag/v0.58.4 [fs] unlink tmp-upgrade-rn.patch -warn Continuing after failure. Most of the files are upgraded but you will need to deal with some conflicts manually -info Installing react-native@0.58.4 and its peer dependencies... -$ execa npm info react-native@0.58.4 peerDependencies --json -$ yarn add react-native@0.58.4 react@16.6.3 -$ execa git add package.json -$ execa git add yarn.lock -$ execa git add package-lock.json -info Running \\"git status\\" to check what changed... -$ execa git status +$ execa git status -s +error Patch failed to apply for unknown reason. Please fall back to manual way of upgrading $ execa git remote remove tmp-rn-diff-purge -warn Please run \\"git diff\\" to review the conflicts and resolve them" +info You may find these resources helpful: +• Release notes: https://github.com/facebook/react-native/releases/tag/v0.58.4 +• Comparison between versions: https://github.com/react-native-community/rn-diff-purge/compare/version/0.57.8..version/0.58.4 +• Git diff: https://github.com/react-native-community/rn-diff-purge/compare/version/0.57.8..version/0.58.4.diff" `); }); diff --git a/packages/cli/src/commands/upgrade/upgrade.js b/packages/cli/src/commands/upgrade/upgrade.js index c22720b3d..d49a1f31b 100644 --- a/packages/cli/src/commands/upgrade/upgrade.js +++ b/packages/cli/src/commands/upgrade/upgrade.js @@ -104,14 +104,9 @@ const getVersionToUpgradeTo = async (argv, currentVersion, projectDir) => { return newVersion; }; -const installDeps = async (newVersion, projectDir, patchSuccess) => { - if (!patchSuccess) { - logger.warn( - 'Continuing after failure. Most of the files are upgraded but you will need to deal with some conflicts manually', - ); - } +const installDeps = async (newVersion, projectDir) => { logger.info( - `Installing react-native@${newVersion} and its peer dependencies...`, + `Installing "react-native@${newVersion}" and its peer dependencies...`, ); const peerDeps = await getRNPeerDeps(newVersion); const pm = new PackageManager({projectDir}); @@ -170,12 +165,6 @@ const applyPatch = async ( logger.log(`${chalk.dim(error.stderr.trim())}`); } logger.error('Automatically applying diff failed'); - logger.info( - `Here's the diff we tried to apply: ${rnDiffPurgeUrl}/compare/version/${currentVersion}...version/${newVersion}`, - ); - logger.info( - `You may find release notes helpful: https://github.com/facebook/react-native/releases/tag/v${newVersion}`, - ); return false; } return true; @@ -188,8 +177,7 @@ async function upgrade(argv: Array, ctx: ContextT, args: FlagsT) { if (args.legacy) { return legacyUpgrade.func(argv, ctx); } - const rnDiffGitAddress = - 'https://github.com/react-native-community/rn-diff-purge.git'; + const rnDiffGitAddress = `${rnDiffPurgeUrl}.git`; const tmpRemote = 'tmp-rn-diff-purge'; const tmpPatchFile = 'tmp-upgrade-rn.patch'; const projectDir = ctx.root; @@ -229,9 +217,6 @@ async function upgrade(argv: Array, ctx: ContextT, args: FlagsT) { await execa('git', ['remote', 'add', tmpRemote, rnDiffGitAddress]); await execa('git', ['fetch', '--no-tags', tmpRemote]); patchSuccess = await applyPatch(currentVersion, newVersion, tmpPatchFile); - if (!patchSuccess) { - return; - } } catch (error) { throw new Error(error.stderr || error); } finally { @@ -240,15 +225,44 @@ async function upgrade(argv: Array, ctx: ContextT, args: FlagsT) { } catch (e) { // ignore } - await installDeps(newVersion, projectDir, patchSuccess); - logger.info('Running "git status" to check what changed...'); - await execa('git', ['status'], {stdio: 'inherit'}); + const {stdout} = await execa('git', ['status', '-s']); + if (!patchSuccess) { + if (stdout) { + logger.warn( + 'Continuing after failure. Most of the files are upgraded but you will need to deal with some conflicts manually', + ); + await installDeps(newVersion, projectDir); + logger.info('Running "git status" to check what changed...'); + await execa('git', ['status'], {stdio: 'inherit'}); + } else { + logger.error( + 'Patch failed to apply for unknown reason. Please fall back to manual way of upgrading', + ); + } + } else { + await installDeps(newVersion, projectDir); + logger.info('Running "git status" to check what changed...'); + await execa('git', ['status'], {stdio: 'inherit'}); + } await execa('git', ['remote', 'remove', tmpRemote]); if (!patchSuccess) { - logger.warn( - 'Please run "git diff" to review the conflicts and resolve them', - ); + if (stdout) { + logger.warn( + 'Please run "git diff" to review the conflicts and resolve them', + ); + } + logger.info(`You may find these resources helpful: +• Release notes: ${chalk.underline.dim( + `https://github.com/facebook/react-native/releases/tag/v${newVersion}`, + )} +• Comparison between versions: ${chalk.underline.dim( + `${rnDiffPurgeUrl}/compare/version/${currentVersion}..version/${newVersion}`, + )} +• Git diff: ${chalk.underline.dim( + `${rnDiffPurgeUrl}/compare/version/${currentVersion}..version/${newVersion}.diff`, + )}`); + throw new Error( 'Upgrade failed. Please see the messages above for details', );