From 489d9f6c624aa0b3e2607cd70e46adbb2ea7162d Mon Sep 17 00:00:00 2001 From: Tommy Nguyen <4123478+tido64@users.noreply.github.com> Date: Mon, 1 Apr 2024 12:37:05 -0700 Subject: [PATCH] fix: version checker not considering nightlies (#43712) Summary: Fix version checker not considering nightlies: ``` WARNING: You should run npx react-native@latest to ensure you're always using the most current version of the CLI. NPX has cached version (0.74.0-nightly-20240214-b8ad91732) != current release (0.73.6) ``` ## Changelog: [GENERAL] [FIXED] - Fix version checker not considering nightlies Pull Request resolved: https://github.com/facebook/react-native/pull/43712 Test Plan: On a recent nightly version, run any cli command. Reviewed By: rshest Differential Revision: D55525055 Pulled By: zeyap fbshipit-source-id: 6dd08e30e542d9ddd191bf95c968a26c0cc14e4e --- packages/react-native/cli.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/react-native/cli.js b/packages/react-native/cli.js index 53c7e47df57..459213d4c51 100755 --- a/packages/react-native/cli.js +++ b/packages/react-native/cli.js @@ -56,6 +56,11 @@ async function getLatestVersion(registryHost = DEFAULT_REGISTRY_HOST) { }); } +function parseVersion(version) { + const [major, minor = 0, patch = 0] = version.split('-')[0].split('.'); + return major * 1000000 + minor * 1000 + patch; +} + /** * Warn when users are using `npx react-native init`, to raise awareness of the changes from RFC 0759. * @@ -129,7 +134,7 @@ async function main() { if (isNpxRuntime && !process.env.SKIP && currentVersion !== HEAD) { try { const latest = await getLatestVersion(); - if (latest !== currentVersion) { + if (parseVersion(latest) > parseVersion(currentVersion)) { const msg = ` ${chalk.bold.yellow('WARNING:')} You should run ${chalk.white.bold( 'npx react-native@latest',