mirror of
https://github.com/status-im/react-native.git
synced 2025-01-14 11:34:23 +00:00
More accurate check for latest version
Summary: When testing `react-native-git-upgrade` locally I noticed a warning: A more recent version of "react-native-git-upgrade" has been found: Current: 0.1.0 Latest: 0.0.1 See https://www.npmjs.com/package/react-native-git-upgrade This won't happen to a lot of people but better fix the warning. Also, if the check for updates fails, don't crash - the check for updates is not critical to the tool working. Also, slightly updated one error message. **Test plan (required)** Installed `react-native-git-upgrade` locally, ran it inside an app folder (RN 0.29). Didn't see the wrong "more recent version" warning anymore. Tried making `checkForUpdates` fail by adding some dummy code: `semver.foo()`. Saw a warning but the process continued: git-upgrade WARN Check for latest version failed semver.foo is not a function Saw a more descriptive error message: git-upgrade ERR! Error: react-native version in "package.json" (0.29.0) doesn't match the installed version in "node_mod Closes https://github.com/facebook/react-native/pull/11188 Differential Revision: D4244002 Pulled By: bestander fbshipit-source-id: 772044750a933663cb516201d09e2873462cca4a
This commit is contained in:
parent
f1a5233fd2
commit
b20b20656a
4
react-native-git-upgrade/checks.js
vendored
4
react-native-git-upgrade/checks.js
vendored
@ -22,8 +22,8 @@ function checkDeclaredVersion(declaredVersion) {
|
|||||||
function checkMatchingVersions(currentVersion, declaredVersion) {
|
function checkMatchingVersions(currentVersion, declaredVersion) {
|
||||||
if (!semver.satisfies(currentVersion, declaredVersion)) {
|
if (!semver.satisfies(currentVersion, declaredVersion)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'react-native version in "package.json" doesn\'t match ' +
|
'react-native version in "package.json" (' + declaredVersion + ') doesn\'t match ' +
|
||||||
'the installed version in "node_modules".\n' +
|
'the installed version in "node_modules" (' + currentVersion + ').\n' +
|
||||||
'Try running "npm install" to fix this.'
|
'Try running "npm install" to fix this.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
35
react-native-git-upgrade/cliEntry.js
vendored
35
react-native-git-upgrade/cliEntry.js
vendored
@ -156,6 +156,28 @@ function runYeomanGenerators(generatorDir, appName, verbose) {
|
|||||||
return new Promise((resolve) => env.run(generatorArgs, {upgrade: true, force: true}, resolve));
|
return new Promise((resolve) => env.run(generatorArgs, {upgrade: true, force: true}, resolve));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If there's a newer version of react-native-git-upgrade in npm, suggest to the user to upgrade.
|
||||||
|
*/
|
||||||
|
async function checkForUpdates() {
|
||||||
|
try {
|
||||||
|
log.info('Check for react-native-git-upgrade updates');
|
||||||
|
const lastGitUpgradeVersion = await exec('npm view react-native-git-upgrade@latest version');
|
||||||
|
const current = require('./package').version;
|
||||||
|
const latest = semver.clean(lastGitUpgradeVersion);
|
||||||
|
if (semver.gt(latest, current)) {
|
||||||
|
log.warn(
|
||||||
|
'A more recent version of "react-native-git-upgrade" has been found.\n' +
|
||||||
|
`Current: ${current}\n` +
|
||||||
|
`Latest: ${latest}\n` +
|
||||||
|
'Please run "npm install -g react-native-git-upgrade"'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
log.warn('Check for latest version failed', err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function run(requiredVersion, cliArgs) {
|
async function run(requiredVersion, cliArgs) {
|
||||||
const context = {
|
const context = {
|
||||||
tmpDir: path.resolve(os.tmpdir(), 'react-native-git-upgrade'),
|
tmpDir: path.resolve(os.tmpdir(), 'react-native-git-upgrade'),
|
||||||
@ -165,18 +187,7 @@ async function run(requiredVersion, cliArgs) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
log.info('Check for react-native-git-upgrade updates');
|
await checkForUpdates();
|
||||||
const lastGitUpgradeVersion = await exec('npm view react-native-git-upgrade@latest version');
|
|
||||||
const current = require('./package').version;
|
|
||||||
const latest = semver.clean(lastGitUpgradeVersion);
|
|
||||||
if (current !== latest) {
|
|
||||||
log.warn(
|
|
||||||
'A more recent version of "react-native-git-upgrade" has been found.\n' +
|
|
||||||
`Current: ${current}\n` +
|
|
||||||
`Latest: ${latest}\n` +
|
|
||||||
'Please run "npm install -g react-native-git-upgrade"'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info('Read package.json files');
|
log.info('Read package.json files');
|
||||||
const {rnPak, pak} = readPackageFiles();
|
const {rnPak, pak} = readPackageFiles();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user