mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-01-15 03:40:48 -06:00
fix: fix latest version check when current version is a prerelease (#4295)
This commit is contained in:
@@ -20,7 +20,7 @@ const presetSchema = createSchema(joi => joi.object().keys({
|
||||
}))
|
||||
|
||||
const schema = createSchema(joi => joi.object().keys({
|
||||
latestVersion: joi.string().regex(/^\d+\.\d+\.\d+$/),
|
||||
latestVersion: joi.string().regex(/^\d+\.\d+\.\d+(-(alpha|beta|rc)\.\d+)?$/),
|
||||
lastChecked: joi.date().timestamp(),
|
||||
packageManager: joi.string().only(['yarn', 'npm', 'pnpm']),
|
||||
useTaobaoRegistry: joi.boolean(),
|
||||
|
||||
@@ -19,6 +19,9 @@ module.exports = async function getVersions () {
|
||||
})
|
||||
}
|
||||
|
||||
// should also check for prerelease versions if the current one is a prerelease
|
||||
const includePrerelease = !!semver.prerelease(local)
|
||||
|
||||
const { latestVersion = local, lastChecked = 0 } = loadOptions()
|
||||
const cached = latestVersion
|
||||
const daysPassed = (Date.now() - lastChecked) / (60 * 60 * 1000 * 24)
|
||||
@@ -26,11 +29,11 @@ module.exports = async function getVersions () {
|
||||
if (daysPassed > 1) {
|
||||
// if we haven't check for a new version in a day, wait for the check
|
||||
// before proceeding
|
||||
latest = await getAndCacheLatestVersion(cached)
|
||||
latest = await getAndCacheLatestVersion(cached, includePrerelease)
|
||||
} else {
|
||||
// Otherwise, do a check in the background. If the result was updated,
|
||||
// it will be used for the next 24 hours.
|
||||
getAndCacheLatestVersion(cached)
|
||||
getAndCacheLatestVersion(cached, includePrerelease)
|
||||
latest = cached
|
||||
}
|
||||
|
||||
@@ -42,8 +45,14 @@ module.exports = async function getVersions () {
|
||||
|
||||
// fetch the latest version and save it on disk
|
||||
// so that it is available immediately next time
|
||||
async function getAndCacheLatestVersion (cached) {
|
||||
const version = await pm.getRemoteVersion('vue-cli-version-marker', 'latest')
|
||||
async function getAndCacheLatestVersion (cached, includePrerelease) {
|
||||
let version = await pm.getRemoteVersion('vue-cli-version-marker', 'latest')
|
||||
|
||||
if (includePrerelease) {
|
||||
const next = await pm.getRemoteVersion('vue-cli-version-marker', 'next')
|
||||
version = semver.gt(next, version) ? next : version
|
||||
}
|
||||
|
||||
if (semver.valid(version) && version !== cached) {
|
||||
saveOptions({ latestVersion: version, lastChecked: Date.now() })
|
||||
return version
|
||||
|
||||
Reference in New Issue
Block a user