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 1 commit
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
Next Next commit
fix: should tolerate cli version check error
  • Loading branch information
haoqunjiang committed Oct 22, 2019
commit b40503fc45ee2fadfa19315c8b8e8e9770521b68
10 changes: 7 additions & 3 deletions packages/@vue/cli/lib/util/clearConsole.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@ 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 (error) {
title += '\n' + chalk.red('Failed to check for updates')
}

if (process.env.VUE_CLI_TEST) {
title += ' ' + chalk.blue.bold('TEST')
}
if (process.env.VUE_CLI_DEBUG) {
title += ' ' + chalk.magenta.bold('DEBUG')
}
if (checkUpdate && semver.gt(latest, current)) {

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
Original file line number Diff line number Diff line change
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