mirror of
https://github.com/status-im/react-native.git
synced 2025-01-12 18:44:25 +00:00
Fix the parse error when specifying an unknown version.
Summary: **Motivation** When running `react-native-git-upgrade` with an unknown version, the error message isn't very helpful **Test Plan** - Publish the `master` branch to Sinopia - Run `react-native-git-upgrade 0.666.0` inside a RN project - Error message is `SyntaxError: Unexpected end of JSON input` - Publish this branch to Sinopia - Run `react-native-git-upgrade 0.666.0` inside a RN project - Error message should be `Error: The specified version of React Native 0.666.0 doesn't exist. Re-run the react-native-git-upgrade command with an existing version, for example: "react-native-git-upgrade 0.38.0", or without arguments to upgrade to the latest: "react-native-git-upgrade".` Closes https://github.com/facebook/react-native/pull/11264 Differential Revision: D4265553 Pulled By: mkonicek fbshipit-source-id: 8597eb09cc3397bfa6d2205a9b3bb30acfad530f
This commit is contained in:
parent
f917c073aa
commit
53178b48d1
12
react-native-git-upgrade/checks.js
vendored
12
react-native-git-upgrade/checks.js
vendored
@ -54,21 +54,9 @@ function checkGitAvailable() {
|
||||
}
|
||||
}
|
||||
|
||||
function checkNewVersionValid(newVersion, requestedVersion) {
|
||||
if (!semver.valid(newVersion) && requestedVersion) {
|
||||
throw new Error(
|
||||
'The specified version of React Native ' + requestedVersion + ' doesn\'t exist.\n' +
|
||||
'Re-run the react-native-git-upgrade command with an existing version,\n' +
|
||||
'for example: "react-native-git-upgrade 0.38.0",\n' +
|
||||
'or without arguments to upgrade to the latest: "react-native-git-upgrade".'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
checkDeclaredVersion,
|
||||
checkMatchingVersions,
|
||||
checkReactPeerDependency,
|
||||
checkGitAvailable,
|
||||
checkNewVersionValid,
|
||||
};
|
||||
|
29
react-native-git-upgrade/cliEntry.js
vendored
29
react-native-git-upgrade/cliEntry.js
vendored
@ -10,6 +10,7 @@
|
||||
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const assert = require('assert');
|
||||
const path = require('path');
|
||||
const shell = require('shelljs');
|
||||
const Promise = require('promise');
|
||||
@ -25,7 +26,6 @@ const {
|
||||
checkMatchingVersions,
|
||||
checkReactPeerDependency,
|
||||
checkGitAvailable,
|
||||
checkNewVersionValid
|
||||
} = require('./checks');
|
||||
|
||||
log.heading = 'git-upgrade';
|
||||
@ -96,6 +96,25 @@ function readPackageFiles(useYarn) {
|
||||
}
|
||||
}
|
||||
|
||||
function parseInformationJsonOutput(jsonOutput, requestedVersion) {
|
||||
try {
|
||||
const output = JSON.parse(jsonOutput);
|
||||
const newVersion = output.version;
|
||||
const newReactVersionRange = output['peerDependencies.react'];
|
||||
|
||||
assert(semver.valid(newVersion));
|
||||
|
||||
return {newVersion, newReactVersionRange}
|
||||
} catch (err) {
|
||||
throw new Error(
|
||||
'The specified version of React Native ' + requestedVersion + ' doesn\'t exist.\n' +
|
||||
'Re-run the react-native-git-upgrade command with an existing version,\n' +
|
||||
'for example: "react-native-git-upgrade 0.38.0",\n' +
|
||||
'or without arguments to upgrade to the latest: "react-native-git-upgrade".'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function setupWorkingDir(tmpDir) {
|
||||
return new Promise((resolve, reject) => {
|
||||
@ -240,15 +259,11 @@ async function run(requestedVersion, cliArgs) {
|
||||
|
||||
log.info('Get information from NPM registry');
|
||||
const viewCommand = 'npm view react-native@' + (requestedVersion || 'latest') + ' peerDependencies.react version --json';
|
||||
const viewOutput = await exec(viewCommand, verbose).then(JSON.parse);
|
||||
const newVersion = viewOutput.version;
|
||||
const newReactVersionRange = viewOutput['peerDependencies.react'];
|
||||
const jsonOutput = await exec(viewCommand, verbose);
|
||||
const {newVersion, newReactVersionRange} = parseInformationJsonOutput(jsonOutput, requestedVersion);
|
||||
// Print which versions we're upgrading to
|
||||
log.info('Upgrading to React Native ' + newVersion + (newReactVersionRange ? ', React ' + newReactVersionRange : ''));
|
||||
|
||||
log.info('Check new version');
|
||||
checkNewVersionValid(newVersion, requestedVersion);
|
||||
|
||||
log.info('Setup temporary working directory');
|
||||
await setupWorkingDir(tmpDir);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user