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
24 changes: 9 additions & 15 deletions packages/cli/src/commands/upgrade/__tests__/upgrade.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected] and its peer dependencies...
info Installing \\"[email protected]\\" and its peer dependencies...
$ execa npm info [email protected] peerDependencies --json
$ yarn add [email protected] [email protected]
$ execa git add package.json
Expand All @@ -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 [email protected] and its peer dependencies...
$ execa git status -s
info Installing \\"[email protected]\\" and its peer dependencies...
$ execa npm info [email protected] peerDependencies --json
$ yarn add [email protected] [email protected]
$ execa git add package.json
Expand Down Expand Up @@ -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 [email protected] and its peer dependencies...
$ execa npm info [email protected] peerDependencies --json
$ yarn add [email protected] [email protected]
$ 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"
`);
});
62 changes: 38 additions & 24 deletions packages/cli/src/commands/upgrade/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down Expand Up @@ -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;
Expand All @@ -188,8 +177,7 @@ async function upgrade(argv: Array<string>, 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;
Expand Down Expand Up @@ -229,9 +217,6 @@ async function upgrade(argv: Array<string>, 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 {
Expand All @@ -240,15 +225,44 @@ async function upgrade(argv: Array<string>, 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',
);
Expand Down