mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-05-05 19:39:11 -05:00
fix: should tolerate cli version check error (#4741)
* fix: should tolerate cli version check error * fix: add the error message after the DEBUG indicator
This commit is contained in:
@@ -26,8 +26,7 @@ async function getInstallationCommand () {
|
||||
}
|
||||
|
||||
exports.generateTitle = async function (checkUpdate) {
|
||||
const { current, latest } = await getVersions()
|
||||
|
||||
const { current, latest, error } = await getVersions()
|
||||
let title = chalk.bold.blue(`Vue CLI v${current}`)
|
||||
|
||||
if (process.env.VUE_CLI_TEST) {
|
||||
@@ -36,7 +35,12 @@ exports.generateTitle = async function (checkUpdate) {
|
||||
if (process.env.VUE_CLI_DEBUG) {
|
||||
title += ' ' + chalk.magenta.bold('DEBUG')
|
||||
}
|
||||
if (checkUpdate && semver.gt(latest, current)) {
|
||||
|
||||
if (error) {
|
||||
title += '\n' + chalk.red('Failed to check for updates')
|
||||
}
|
||||
|
||||
if (checkUpdate && !error && semver.gt(latest, current)) {
|
||||
if (process.env.VUE_CLI_API_MODE) {
|
||||
title += chalk.green(` 🌟️ New version available: ${latest}`)
|
||||
} else {
|
||||
|
||||
@@ -26,20 +26,28 @@ module.exports = async function getVersions () {
|
||||
const cached = latestVersion
|
||||
const daysPassed = (Date.now() - lastChecked) / (60 * 60 * 1000 * 24)
|
||||
|
||||
let error
|
||||
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, includePrerelease)
|
||||
try {
|
||||
latest = await getAndCacheLatestVersion(cached, includePrerelease)
|
||||
} catch (e) {
|
||||
latest = cached
|
||||
error = e
|
||||
}
|
||||
} else {
|
||||
// Otherwise, do a check in the background. If the result was updated,
|
||||
// it will be used for the next 24 hours.
|
||||
getAndCacheLatestVersion(cached, includePrerelease)
|
||||
// don't throw to interrupt the user if the background check failed
|
||||
getAndCacheLatestVersion(cached, includePrerelease).catch(() => {})
|
||||
latest = cached
|
||||
}
|
||||
|
||||
return (sessionCached = {
|
||||
current: local,
|
||||
latest
|
||||
latest,
|
||||
error
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user