Skip to content
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

fix: should tolerate cli version check error #4741

Merged
merged 2 commits into from Oct 22, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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