Skip to content

Commit a79130c

Browse files
authored
fix: refine upgrade error handling; improve the output (#232)
* fix: refine upgrade error handling * moar refinements to the output
1 parent b572a9c commit a79130c

File tree

2 files changed

+47
-39
lines changed

2 files changed

+47
-39
lines changed

packages/cli/src/commands/upgrade/__tests__/upgrade.test.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ test('fetches empty patch and installs deps', async () => {
112112
expect(flushOutput()).toMatchInlineSnapshot(`
113113
"info Fetching diff between v0.57.8 and v0.58.4...
114114
info Diff has no changes to apply, proceeding further
115-
warn Continuing after failure. Most of the files are upgraded but you will need to deal with some conflicts manually
116-
info Installing [email protected] and its peer dependencies...
115+
info Installing \\"[email protected]\\" and its peer dependencies...
117116
$ execa npm info [email protected] peerDependencies --json
118117
119118
$ execa git add package.json
@@ -135,7 +134,8 @@ $ execa git apply --check tmp-upgrade-rn.patch --exclude=package.json -p2 --3way
135134
info Applying diff...
136135
$ execa git apply tmp-upgrade-rn.patch --exclude=package.json -p2 --3way
137136
[fs] unlink tmp-upgrade-rn.patch
138-
info Installing [email protected] and its peer dependencies...
137+
$ execa git status -s
138+
info Installing \\"[email protected]\\" and its peer dependencies...
139139
$ execa npm info [email protected] peerDependencies --json
140140
141141
$ execa git add package.json
@@ -186,19 +186,13 @@ info Applying diff (excluding: package.json, .flowconfig)...
186186
$ execa git apply tmp-upgrade-rn.patch --exclude=package.json --exclude=.flowconfig -p2 --3way
187187
error: .flowconfig: does not exist in index
188188
error Automatically applying diff failed
189-
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
190-
info You may find release notes helpful: https://github.com/facebook/react-native/releases/tag/v0.58.4
191189
[fs] unlink tmp-upgrade-rn.patch
192-
warn Continuing after failure. Most of the files are upgraded but you will need to deal with some conflicts manually
193-
info Installing [email protected] and its peer dependencies...
194-
$ execa npm info [email protected] peerDependencies --json
195-
196-
$ execa git add package.json
197-
$ execa git add yarn.lock
198-
$ execa git add package-lock.json
199-
info Running \\"git status\\" to check what changed...
200-
$ execa git status
190+
$ execa git status -s
191+
error Patch failed to apply for unknown reason. Please fall back to manual way of upgrading
201192
$ execa git remote remove tmp-rn-diff-purge
202-
warn Please run \\"git diff\\" to review the conflicts and resolve them"
193+
info You may find these resources helpful:
194+
• Release notes: https://github.com/facebook/react-native/releases/tag/v0.58.4
195+
• Comparison between versions: https://github.com/react-native-community/rn-diff-purge/compare/version/0.57.8..version/0.58.4
196+
• Git diff: https://github.com/react-native-community/rn-diff-purge/compare/version/0.57.8..version/0.58.4.diff"
203197
`);
204198
});

packages/cli/src/commands/upgrade/upgrade.js

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,9 @@ const getVersionToUpgradeTo = async (argv, currentVersion, projectDir) => {
104104
return newVersion;
105105
};
106106

107-
const installDeps = async (newVersion, projectDir, patchSuccess) => {
108-
if (!patchSuccess) {
109-
logger.warn(
110-
'Continuing after failure. Most of the files are upgraded but you will need to deal with some conflicts manually',
111-
);
112-
}
107+
const installDeps = async (newVersion, projectDir) => {
113108
logger.info(
114-
`Installing react-native@${newVersion} and its peer dependencies...`,
109+
`Installing "react-native@${newVersion}" and its peer dependencies...`,
115110
);
116111
const peerDeps = await getRNPeerDeps(newVersion);
117112
const pm = new PackageManager({projectDir});
@@ -170,12 +165,6 @@ const applyPatch = async (
170165
logger.log(`${chalk.dim(error.stderr.trim())}`);
171166
}
172167
logger.error('Automatically applying diff failed');
173-
logger.info(
174-
`Here's the diff we tried to apply: ${rnDiffPurgeUrl}/compare/version/${currentVersion}...version/${newVersion}`,
175-
);
176-
logger.info(
177-
`You may find release notes helpful: https://github.com/facebook/react-native/releases/tag/v${newVersion}`,
178-
);
179168
return false;
180169
}
181170
return true;
@@ -188,8 +177,7 @@ async function upgrade(argv: Array<string>, ctx: ContextT, args: FlagsT) {
188177
if (args.legacy) {
189178
return legacyUpgrade.func(argv, ctx);
190179
}
191-
const rnDiffGitAddress =
192-
'https://github.com/react-native-community/rn-diff-purge.git';
180+
const rnDiffGitAddress = `${rnDiffPurgeUrl}.git`;
193181
const tmpRemote = 'tmp-rn-diff-purge';
194182
const tmpPatchFile = 'tmp-upgrade-rn.patch';
195183
const projectDir = ctx.root;
@@ -229,9 +217,6 @@ async function upgrade(argv: Array<string>, ctx: ContextT, args: FlagsT) {
229217
await execa('git', ['remote', 'add', tmpRemote, rnDiffGitAddress]);
230218
await execa('git', ['fetch', '--no-tags', tmpRemote]);
231219
patchSuccess = await applyPatch(currentVersion, newVersion, tmpPatchFile);
232-
if (!patchSuccess) {
233-
return;
234-
}
235220
} catch (error) {
236221
throw new Error(error.stderr || error);
237222
} finally {
@@ -240,15 +225,44 @@ async function upgrade(argv: Array<string>, ctx: ContextT, args: FlagsT) {
240225
} catch (e) {
241226
// ignore
242227
}
243-
await installDeps(newVersion, projectDir, patchSuccess);
244-
logger.info('Running "git status" to check what changed...');
245-
await execa('git', ['status'], {stdio: 'inherit'});
228+
const {stdout} = await execa('git', ['status', '-s']);
229+
if (!patchSuccess) {
230+
if (stdout) {
231+
logger.warn(
232+
'Continuing after failure. Most of the files are upgraded but you will need to deal with some conflicts manually',
233+
);
234+
await installDeps(newVersion, projectDir);
235+
logger.info('Running "git status" to check what changed...');
236+
await execa('git', ['status'], {stdio: 'inherit'});
237+
} else {
238+
logger.error(
239+
'Patch failed to apply for unknown reason. Please fall back to manual way of upgrading',
240+
);
241+
}
242+
} else {
243+
await installDeps(newVersion, projectDir);
244+
logger.info('Running "git status" to check what changed...');
245+
await execa('git', ['status'], {stdio: 'inherit'});
246+
}
246247
await execa('git', ['remote', 'remove', tmpRemote]);
247248

248249
if (!patchSuccess) {
249-
logger.warn(
250-
'Please run "git diff" to review the conflicts and resolve them',
251-
);
250+
if (stdout) {
251+
logger.warn(
252+
'Please run "git diff" to review the conflicts and resolve them',
253+
);
254+
}
255+
logger.info(`You may find these resources helpful:
256+
• Release notes: ${chalk.underline.dim(
257+
`https://github.com/facebook/react-native/releases/tag/v${newVersion}`,
258+
)}
259+
• Comparison between versions: ${chalk.underline.dim(
260+
`${rnDiffPurgeUrl}/compare/version/${currentVersion}..version/${newVersion}`,
261+
)}
262+
• Git diff: ${chalk.underline.dim(
263+
`${rnDiffPurgeUrl}/compare/version/${currentVersion}..version/${newVersion}.diff`,
264+
)}`);
265+
252266
throw new Error(
253267
'Upgrade failed. Please see the messages above for details',
254268
);

0 commit comments

Comments
 (0)