Skip to content

fix: fix latest version check when current version is a prerelease #4295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@vue/cli/lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
17 changes: 13 additions & 4 deletions packages/@vue/cli/lib/util/getVersions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@ 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)

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
}

Expand All @@ -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
Expand Down