use semver for version comparsion (#3042)

close  #3041
close #3043

---------

Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com>
This commit is contained in:
6543 2023-12-30 23:28:43 +01:00 committed by GitHub
parent 9c066c237a
commit 38cf248e41
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 3 deletions

View file

@ -27,6 +27,7 @@
"node-emoji": "^2.0.0",
"pinia": "^2.1.4",
"prismjs": "^1.29.0",
"semver": "^7.5.4",
"vue": "^3.3.4",
"vue-i18n": "^9.2.2",
"vue-router": "^4.2.2"
@ -37,6 +38,7 @@
"@types/node": "^20.0.0",
"@types/node-emoji": "^1.8.2",
"@types/prismjs": "^1.26.0",
"@types/semver": "^7.5.6",
"@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0",
"@vitejs/plugin-vue": "^5.0.0",

View file

@ -38,6 +38,9 @@ dependencies:
prismjs:
specifier: ^1.29.0
version: 1.29.0
semver:
specifier: ^7.5.4
version: 7.5.4
vue:
specifier: ^3.3.4
version: 3.3.10(typescript@5.3.3)
@ -64,6 +67,9 @@ devDependencies:
'@types/prismjs':
specifier: ^1.26.0
version: 1.26.3
'@types/semver':
specifier: ^7.5.6
version: 7.5.6
'@typescript-eslint/eslint-plugin':
specifier: ^6.8.0
version: 6.13.2(@typescript-eslint/parser@6.13.2)(eslint@8.55.0)(typescript@5.3.3)

View file

@ -1,3 +1,5 @@
import semverCoerce from 'semver/functions/coerce';
import semverGt from 'semver/functions/gt';
import { onMounted, ref } from 'vue';
import useAuthentication from './useAuthentication';
@ -39,6 +41,7 @@ export function useVersion() {
const config = useConfig();
const current = config.version as string;
const currentSemver = semverCoerce(current);
const usesNext = current.startsWith('next');
const { user } = useAuthentication();
@ -72,9 +75,9 @@ export function useVersion() {
if (usesNext) {
latest = versionInfo.next;
} else if (current.includes('rc')) {
latest = versionInfo.rc.replace(/^v/, '');
latest = versionInfo.rc;
} else {
latest = versionInfo.latest.replace(/^v/, '');
latest = versionInfo.latest;
}
}
@ -82,7 +85,7 @@ export function useVersion() {
latest,
current,
currentShort: usesNext ? 'next' : current,
needsUpdate: latest !== undefined && latest !== current,
needsUpdate: latest !== undefined && currentSemver !== null && semverGt(latest, currentSemver),
usesNext,
};
});