Skip to content

Commit

Permalink
fix: should tolerate cli version check error (#4741)
Browse files Browse the repository at this point in the history
* fix: should tolerate cli version check error

* fix: add the error message after the DEBUG indicator
  • Loading branch information
sodatea committed Oct 22, 2019
1 parent 31df36d commit 964fad5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
10 changes: 7 additions & 3 deletions packages/@vue/cli/lib/util/clearConsole.js
Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down
14 changes: 11 additions & 3 deletions packages/@vue/cli/lib/util/getVersions.js
Expand Up @@ -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
})
}

Expand Down

0 comments on commit 964fad5

Please sign in to comment.