From d50df4dd1219ce93cb145f55c666aff290de450d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 14 Mar 2019 00:55:45 +0100 Subject: [PATCH 1/2] fix: refine upgrade error handling --- .../upgrade/__tests__/upgrade.test.js | 21 +++----- packages/cli/src/commands/upgrade/upgrade.js | 48 +++++++++++-------- 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/packages/cli/src/commands/upgrade/__tests__/upgrade.test.js b/packages/cli/src/commands/upgrade/__tests__/upgrade.test.js index fbd09d97c..660439249 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,7 @@ $ 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... +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 +185,11 @@ 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 +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 [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 using links above $ execa git remote remove tmp-rn-diff-purge -warn Please run \\"git diff\\" to review the conflicts and resolve them" +warn Please run \\"git diff\\" to review the conflicts and resolve them. You may find release notes helpful: https://github.com/facebook/react-native/releases/tag/v0.58.4" `); }); diff --git a/packages/cli/src/commands/upgrade/upgrade.js b/packages/cli/src/commands/upgrade/upgrade.js index c22720b3d..38d65799c 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}); @@ -171,10 +166,9 @@ const applyPatch = async ( } 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}`, + `Here's the diff we tried to apply: ${chalk.underline.dim( + `${rnDiffPurgeUrl}/compare/version/${currentVersion}...version/${newVersion}`, + )}`, ); return false; } @@ -188,8 +182,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 +222,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,14 +230,32 @@ 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'}); + if (!patchSuccess) { + const {stdout} = await execa('git', ['status', '-s']); + 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 using links above', + ); + } + } 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', + `Please run "git diff" to review the conflicts and resolve them. You may find release notes helpful: ${chalk.underline.dim( + `https://github.com/facebook/react-native/releases/tag/v${newVersion}`, + )}`, ); throw new Error( 'Upgrade failed. Please see the messages above for details', From 47b71b20f07d42efd1096b614c5231251ab185a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 14 Mar 2019 10:15:29 +0100 Subject: [PATCH 2/2] moar refinements --- .../upgrade/__tests__/upgrade.test.js | 9 ++++-- packages/cli/src/commands/upgrade/upgrade.js | 30 +++++++++++-------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/packages/cli/src/commands/upgrade/__tests__/upgrade.test.js b/packages/cli/src/commands/upgrade/__tests__/upgrade.test.js index 660439249..2730bb013 100644 --- a/packages/cli/src/commands/upgrade/__tests__/upgrade.test.js +++ b/packages/cli/src/commands/upgrade/__tests__/upgrade.test.js @@ -134,6 +134,7 @@ $ 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 +$ 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 @@ -185,11 +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 [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 using links above +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. You may find release notes helpful: https://github.com/facebook/react-native/releases/tag/v0.58.4" +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 38d65799c..d49a1f31b 100644 --- a/packages/cli/src/commands/upgrade/upgrade.js +++ b/packages/cli/src/commands/upgrade/upgrade.js @@ -165,11 +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: ${chalk.underline.dim( - `${rnDiffPurgeUrl}/compare/version/${currentVersion}...version/${newVersion}`, - )}`, - ); return false; } return true; @@ -230,8 +225,8 @@ async function upgrade(argv: Array, ctx: ContextT, args: FlagsT) { } catch (e) { // ignore } + const {stdout} = await execa('git', ['status', '-s']); if (!patchSuccess) { - const {stdout} = await execa('git', ['status', '-s']); if (stdout) { logger.warn( 'Continuing after failure. Most of the files are upgraded but you will need to deal with some conflicts manually', @@ -241,7 +236,7 @@ async function upgrade(argv: Array, ctx: ContextT, args: FlagsT) { await execa('git', ['status'], {stdio: 'inherit'}); } else { logger.error( - 'Patch failed to apply for unknown reason. Please fall back to manual way of upgrading using links above', + 'Patch failed to apply for unknown reason. Please fall back to manual way of upgrading', ); } } else { @@ -252,11 +247,22 @@ async function upgrade(argv: Array, ctx: ContextT, args: FlagsT) { await execa('git', ['remote', 'remove', tmpRemote]); if (!patchSuccess) { - logger.warn( - `Please run "git diff" to review the conflicts and resolve them. You may find release notes helpful: ${chalk.underline.dim( - `https://github.com/facebook/react-native/releases/tag/v${newVersion}`, - )}`, - ); + 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', );