Skip to content

Commit

Permalink
fix: upgrade command version
Browse files Browse the repository at this point in the history
  • Loading branch information
winchesHe committed Dec 5, 2024
1 parent 9234f72 commit f41230a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/actions/upgrade-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions src/scripts/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down

0 comments on commit f41230a

Please sign in to comment.