diff --git a/src/actions/upgrade-action.ts b/src/actions/upgrade-action.ts index baf207d..19d882a 100644 --- a/src/actions/upgrade-action.ts +++ b/src/actions/upgrade-action.ts @@ -4,7 +4,7 @@ import fs from 'node:fs'; import {getBetaVersion} from '@helpers/beta'; import {getCanaryVersion} from '@helpers/canary'; -import {checkIllegalComponents, getConditionData} from '@helpers/check'; +import {checkIllegalComponents, getConditionLatestVersion} from '@helpers/check'; import {detect} from '@helpers/detect'; import {exec} from '@helpers/exec'; import {Logger} from '@helpers/logger'; @@ -44,6 +44,7 @@ function extraCompareVersions( const compareResult = compareVersions(version, latestVersion); // Beta version is greater than latest version if beta is true + // compareResult(2.1.0, 2.1.0-beta.0) = 1 // Example: 2.1.0 < 2.1.0-beta.0 return beta && compareResult === 1 && !version.includes('beta') ? false @@ -100,10 +101,9 @@ export async function upgradeAction(components: string[], options: UpgradeAction // If have the main nextui then add if (isNextUIAll) { const version = transformPeerVersion(allDependencies[NEXT_UI]); - const conditionData = getConditionData(store.beta, store.canary); - const latestVersion = conditionData?.version ?? store.latestVersion; + const latestVersion = getConditionLatestVersion(store.beta, store.canary); const nextuiData = { - isLatest: extraCompareVersions(latestVersion, version, store.beta, store.canary), + isLatest: extraCompareVersions(version, latestVersion, store.beta, store.canary), latestVersion, package: NEXT_UI, version diff --git a/src/helpers/check.ts b/src/helpers/check.ts index 5f744fb..1a69c83 100644 --- a/src/helpers/check.ts +++ b/src/helpers/check.ts @@ -118,6 +118,10 @@ export function getConditionData(beta: boolean, canary: boolean) { : null; } +export function getConditionLatestVersion(beta: boolean, canary: boolean) { + return beta ? store.betaVersion : canary ? store.canaryVersion : store.latestVersion; +} + /** * Check if the required content is installed * @example return result and missing required [false, '@nextui-org/react', 'framer-motion'] diff --git a/src/helpers/upgrade.ts b/src/helpers/upgrade.ts index 4c2594b..0b7b17f 100644 --- a/src/helpers/upgrade.ts +++ b/src/helpers/upgrade.ts @@ -9,6 +9,7 @@ import {type Dependencies, compareVersions, getLatestVersion} from 'src/scripts/ import {getBetaVersion} from './beta'; import {getCanaryVersion} from './canary'; +import {getConditionLatestVersion} from './check'; import {Logger} from './logger'; import {colorMatchRegex, outputBox} from './output-info'; import { @@ -269,7 +270,7 @@ export async function getAllOutputData( }; } - const latestVersion = store.latestVersion; + const latestVersion = getConditionLatestVersion(store.beta, store.canary); const {currentVersion, versionMode} = getVersionAndMode(allDependencies, NEXT_UI); const colorVersion = getColorVersion(currentVersion, latestVersion); diff --git a/src/scripts/helpers.ts b/src/scripts/helpers.ts index 7e4f41e..d94e55c 100644 --- a/src/scripts/helpers.ts +++ b/src/scripts/helpers.ts @@ -72,9 +72,11 @@ export async function updateComponents(options?: UpdateComponentsOptions) { const currentVersion = components.version; const betaVersion = components.betaVersion; const canaryVersion = components.canaryVersion; - const latestVersion = await getStore('latestVersion'); - const latestBetaVersion = await getStore('betaVersion'); - const latestCanaryVersion = await getStore('canaryVersion'); + const [latestVersion, latestBetaVersion, latestCanaryVersion] = await Promise.all([ + getStore('latestVersion'), + getStore('betaVersion'), + getStore('canaryVersion') + ]); if ( compareVersions(currentVersion, latestVersion) === -1 ||