Skip to content

Commit

Permalink
refactor: use a version map to determine the newest dependency versions
Browse files Browse the repository at this point in the history
Now that lerna independent mode is used to release new versions, we can
no longer ensure the core service/plugin versions are in sync with
@vue/cli itself. So `vue-cli-version-marker` is now used to store the
latest version map of core packages.

In order to automate this process, all the core cli packages are listed
as `devDependencies` of `vue-cli-version-marker`. This will cause a
cyclic dependency warning in lerna bootstrap, and that warning can be
safely ignored because these are just `devDependencies` which won't
affect end users.

Another gotcha is that the version of `vue-cli-version-marker` will be
bumped each time we do a release. This may break the remote version
check logic before rc.12 (due to
vuejs@1ae223d#diff-ac5fc3f8b11df9fc948b8e5aa52a074e
the background version check might never get executed since rc.12)
  • Loading branch information
haoqunjiang committed Nov 12, 2018
1 parent 5d49d57 commit 044f5b3
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ dist
temp
.vuerc
.version
.versions
2 changes: 1 addition & 1 deletion packages/@vue/cli/lib/Creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ module.exports = class Creator extends EventEmitter {
}
pkg.devDependencies[dep] = (
preset.plugins[dep].version ||
(/^@vue/.test(dep) ? `^${latest}` : `latest`)
((/^@vue/.test(dep) && latest[dep]) ? `^${latest[dep]}` : `latest`)
)
})
// write package.json
Expand Down
10 changes: 5 additions & 5 deletions packages/@vue/cli/lib/util/clearConsole.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ const { clearConsole } = require('@vue/cli-shared-utils')
exports.generateTitle = async function (checkUpdate) {
const { current, latest } = await getVersions()

let title = chalk.bold.blue(`Vue CLI v${current}`)
let title = chalk.bold.blue(`Vue CLI v${current['@vue/cli']}`)

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 && semver.gt(latest['@vue/cli'], current['@vue/cli'])) {
if (process.env.VUE_CLI_API_MODE) {
title += chalk.green(` 🌟️ Update available: ${latest}`)
} else {
title += chalk.green(`
┌────────────────────${`─`.repeat(latest.length)}──┐
│ Update available: ${latest}
└────────────────────${`─`.repeat(latest.length)}──┘`)
┌────────────────────${`─`.repeat(latest['@vue/cli'].length)}──┐
│ Update available: ${latest['@vue/cli']}
└────────────────────${`─`.repeat(latest['@vue/cli'].length)}──┘`)
}
}

Expand Down
49 changes: 23 additions & 26 deletions packages/@vue/cli/lib/util/getVersions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const fs = require('fs-extra')
const path = require('path')
const semver = require('semver')
const fsCachePath = path.resolve(__dirname, '.version')
const fsCachePath = path.resolve(__dirname, '.versions')

let sessionCached

Expand All @@ -11,32 +10,32 @@ module.exports = async function getVersions () {
}

let latest
const local = require(`../../package.json`).version
const local = require('vue-cli-version-marker').devDependencies
if (process.env.VUE_CLI_TEST || process.env.VUE_CLI_DEBUG) {
return (sessionCached = {
current: local,
latest: local
})
}

if (fs.existsSync(fsCachePath)) {
const cached = await fs.readFile(fsCachePath, 'utf-8')
const lastChecked = (await fs.stat(fsCachePath)).mtimeMs
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)
} else {
// Otherwise, do a check in the background. If the result was updated,
// it will be used for the next 24 hours.
getAndCacheLatestVersion(cached)
latest = cached
}
} else {
if (!fs.existsSync(fsCachePath)) {
// if the cache file doesn't exist, this is likely a fresh install
// so no need to check
latest = local
// then create a cache file with the bundled version map
await fs.writeFile(fsCachePath, JSON.stringify(local))
}

const cached = JSON.parse(await fs.readFile(fsCachePath, 'utf-8'))
const lastChecked = (await fs.stat(fsCachePath)).mtimeMs
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 getAndCacheLatestVersions(cached)
} else {
// Otherwise, do a check in the background. If the result was updated,
// it will be used for the next 24 hours.
getAndCacheLatestVersions(cached)
latest = cached
}

return (sessionCached = {
Expand All @@ -47,15 +46,13 @@ 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) {
async function getAndCacheLatestVersions (cached) {
const getPackageVersion = require('./getPackageVersion')
const res = await getPackageVersion('vue-cli-version-marker', 'latest')
if (res.statusCode === 200) {
const { version } = res.body
if (semver.valid(version) && version !== cached) {
await fs.writeFile(fsCachePath, version)
return version
}
const versions = res.body.devDependencies
await fs.writeFile(fsCachePath, JSON.stringify(versions))
return versions
}
return cached
}
1 change: 1 addition & 0 deletions packages/@vue/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"shortid": "^2.2.11",
"slash": "^2.0.0",
"validate-npm-package-name": "^3.0.0",
"vue-cli-version-marker": "^3.1.0",
"yaml-front-matter": "^3.4.1"
},
"engines": {
Expand Down
29 changes: 28 additions & 1 deletion packages/vue-cli-version-marker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,32 @@
"version": "3.1.0",
"description": "version marker for @vue/cli",
"author": "Evan You",
"license": "MIT"
"license": "MIT",
"main": "package.json",
"devDependencies": {
"@vue/babel-preset-app": "3.1.1",
"@vue/cli-init": "3.1.1",
"@vue/cli-overlay": "3.1.0",
"@vue/cli-plugin-babel": "3.1.1",
"@vue/cli-plugin-e2e-cypress": "3.1.1",
"@vue/cli-plugin-e2e-nightwatch": "3.1.1",
"@vue/cli-plugin-eslint": "3.1.4",
"@vue/cli-plugin-pwa": "3.1.1",
"@vue/cli-plugin-typescript": "3.1.1",
"@vue/cli-plugin-unit-jest": "3.1.1",
"@vue/cli-plugin-unit-mocha": "3.1.1",
"@vue/cli-service-global": "3.1.2",
"@vue/cli-service": "3.1.3",
"@vue/cli-shared-utils": "3.1.1",
"@vue/cli-test-utils": "3.1.1",
"@vue/cli-ui-addon-webpack": "3.1.1",
"@vue/cli-ui-addon-widgets": "3.1.1",
"@vue/cli-ui": "3.1.1",
"@vue/cli-upgrade": "3.1.1",
"@vue/cli": "3.1.1",
"@vue/eslint-config-airbnb": "4.0.0",
"@vue/eslint-config-prettier": "4.0.0",
"@vue/eslint-config-standard": "4.0.0",
"@vue/eslint-config-typescript": "3.1.1"
}
}

0 comments on commit 044f5b3

Please sign in to comment.