diff --git a/react-native-git-upgrade/checks.js b/react-native-git-upgrade/checks.js index 35177a12f..6856ce6a4 100644 --- a/react-native-git-upgrade/checks.js +++ b/react-native-git-upgrade/checks.js @@ -22,8 +22,8 @@ function checkDeclaredVersion(declaredVersion) { function checkMatchingVersions(currentVersion, declaredVersion) { if (!semver.satisfies(currentVersion, declaredVersion)) { throw new Error( - 'react-native version in "package.json" doesn\'t match ' + - 'the installed version in "node_modules".\n' + + 'react-native version in "package.json" (' + declaredVersion + ') doesn\'t match ' + + 'the installed version in "node_modules" (' + currentVersion + ').\n' + 'Try running "npm install" to fix this.' ); } diff --git a/react-native-git-upgrade/cliEntry.js b/react-native-git-upgrade/cliEntry.js index 1a0bcae25..2cca0e7a7 100644 --- a/react-native-git-upgrade/cliEntry.js +++ b/react-native-git-upgrade/cliEntry.js @@ -156,6 +156,28 @@ function runYeomanGenerators(generatorDir, appName, verbose) { 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) { const context = { tmpDir: path.resolve(os.tmpdir(), 'react-native-git-upgrade'), @@ -165,18 +187,7 @@ async function run(requiredVersion, cliArgs) { }; 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 (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"' - ); - } + await checkForUpdates(); log.info('Read package.json files'); const {rnPak, pak} = readPackageFiles();