Skip to content

Commit 044f5b3

Browse files
committed
refactor: use a version map to determine the newest dependency versions
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 1ae223d#diff-ac5fc3f8b11df9fc948b8e5aa52a074e the background version check might never get executed since rc.12)
1 parent 5d49d57 commit 044f5b3

File tree

6 files changed

+59
-33
lines changed

6 files changed

+59
-33
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ dist
77
temp
88
.vuerc
99
.version
10+
.versions

packages/@vue/cli/lib/Creator.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ module.exports = class Creator extends EventEmitter {
119119
}
120120
pkg.devDependencies[dep] = (
121121
preset.plugins[dep].version ||
122-
(/^@vue/.test(dep) ? `^${latest}` : `latest`)
122+
((/^@vue/.test(dep) && latest[dep]) ? `^${latest[dep]}` : `latest`)
123123
)
124124
})
125125
// write package.json

packages/@vue/cli/lib/util/clearConsole.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ const { clearConsole } = require('@vue/cli-shared-utils')
66
exports.generateTitle = async function (checkUpdate) {
77
const { current, latest } = await getVersions()
88

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

1111
if (process.env.VUE_CLI_TEST) {
1212
title += ' ' + chalk.blue.bold('TEST')
1313
}
1414
if (process.env.VUE_CLI_DEBUG) {
1515
title += ' ' + chalk.magenta.bold('DEBUG')
1616
}
17-
if (checkUpdate && semver.gt(latest, current)) {
17+
if (checkUpdate && semver.gt(latest['@vue/cli'], current['@vue/cli'])) {
1818
if (process.env.VUE_CLI_API_MODE) {
1919
title += chalk.green(` 🌟️ Update available: ${latest}`)
2020
} else {
2121
title += chalk.green(`
22-
┌────────────────────${`─`.repeat(latest.length)}──┐
23-
│ Update available: ${latest}
24-
└────────────────────${`─`.repeat(latest.length)}──┘`)
22+
┌────────────────────${`─`.repeat(latest['@vue/cli'].length)}──┐
23+
│ Update available: ${latest['@vue/cli']}
24+
└────────────────────${`─`.repeat(latest['@vue/cli'].length)}──┘`)
2525
}
2626
}
2727

+23-26
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const fs = require('fs-extra')
22
const path = require('path')
3-
const semver = require('semver')
4-
const fsCachePath = path.resolve(__dirname, '.version')
3+
const fsCachePath = path.resolve(__dirname, '.versions')
54

65
let sessionCached
76

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

1312
let latest
14-
const local = require(`../../package.json`).version
13+
const local = require('vue-cli-version-marker').devDependencies
1514
if (process.env.VUE_CLI_TEST || process.env.VUE_CLI_DEBUG) {
1615
return (sessionCached = {
1716
current: local,
1817
latest: local
1918
})
2019
}
2120

22-
if (fs.existsSync(fsCachePath)) {
23-
const cached = await fs.readFile(fsCachePath, 'utf-8')
24-
const lastChecked = (await fs.stat(fsCachePath)).mtimeMs
25-
const daysPassed = (Date.now() - lastChecked) / (60 * 60 * 1000 * 24)
26-
if (daysPassed > 1) {
27-
// if we haven't check for a new version in a day, wait for the check
28-
// before proceeding
29-
latest = await getAndCacheLatestVersion(cached)
30-
} else {
31-
// Otherwise, do a check in the background. If the result was updated,
32-
// it will be used for the next 24 hours.
33-
getAndCacheLatestVersion(cached)
34-
latest = cached
35-
}
36-
} else {
21+
if (!fs.existsSync(fsCachePath)) {
3722
// if the cache file doesn't exist, this is likely a fresh install
38-
// so no need to check
39-
latest = local
23+
// then create a cache file with the bundled version map
24+
await fs.writeFile(fsCachePath, JSON.stringify(local))
25+
}
26+
27+
const cached = JSON.parse(await fs.readFile(fsCachePath, 'utf-8'))
28+
const lastChecked = (await fs.stat(fsCachePath)).mtimeMs
29+
const daysPassed = (Date.now() - lastChecked) / (60 * 60 * 1000 * 24)
30+
if (daysPassed > 1) {
31+
// if we haven't check for a new version in a day, wait for the check
32+
// before proceeding
33+
latest = await getAndCacheLatestVersions(cached)
34+
} else {
35+
// Otherwise, do a check in the background. If the result was updated,
36+
// it will be used for the next 24 hours.
37+
getAndCacheLatestVersions(cached)
38+
latest = cached
4039
}
4140

4241
return (sessionCached = {
@@ -47,15 +46,13 @@ module.exports = async function getVersions () {
4746

4847
// fetch the latest version and save it on disk
4948
// so that it is available immediately next time
50-
async function getAndCacheLatestVersion (cached) {
49+
async function getAndCacheLatestVersions (cached) {
5150
const getPackageVersion = require('./getPackageVersion')
5251
const res = await getPackageVersion('vue-cli-version-marker', 'latest')
5352
if (res.statusCode === 200) {
54-
const { version } = res.body
55-
if (semver.valid(version) && version !== cached) {
56-
await fs.writeFile(fsCachePath, version)
57-
return version
58-
}
53+
const versions = res.body.devDependencies
54+
await fs.writeFile(fsCachePath, JSON.stringify(versions))
55+
return versions
5956
}
6057
return cached
6158
}

packages/@vue/cli/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"shortid": "^2.2.11",
5454
"slash": "^2.0.0",
5555
"validate-npm-package-name": "^3.0.0",
56+
"vue-cli-version-marker": "^3.1.0",
5657
"yaml-front-matter": "^3.4.1"
5758
},
5859
"engines": {

packages/vue-cli-version-marker/package.json

+28-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,32 @@
33
"version": "3.1.0",
44
"description": "version marker for @vue/cli",
55
"author": "Evan You",
6-
"license": "MIT"
6+
"license": "MIT",
7+
"main": "package.json",
8+
"devDependencies": {
9+
"@vue/babel-preset-app": "3.1.1",
10+
"@vue/cli-init": "3.1.1",
11+
"@vue/cli-overlay": "3.1.0",
12+
"@vue/cli-plugin-babel": "3.1.1",
13+
"@vue/cli-plugin-e2e-cypress": "3.1.1",
14+
"@vue/cli-plugin-e2e-nightwatch": "3.1.1",
15+
"@vue/cli-plugin-eslint": "3.1.4",
16+
"@vue/cli-plugin-pwa": "3.1.1",
17+
"@vue/cli-plugin-typescript": "3.1.1",
18+
"@vue/cli-plugin-unit-jest": "3.1.1",
19+
"@vue/cli-plugin-unit-mocha": "3.1.1",
20+
"@vue/cli-service-global": "3.1.2",
21+
"@vue/cli-service": "3.1.3",
22+
"@vue/cli-shared-utils": "3.1.1",
23+
"@vue/cli-test-utils": "3.1.1",
24+
"@vue/cli-ui-addon-webpack": "3.1.1",
25+
"@vue/cli-ui-addon-widgets": "3.1.1",
26+
"@vue/cli-ui": "3.1.1",
27+
"@vue/cli-upgrade": "3.1.1",
28+
"@vue/cli": "3.1.1",
29+
"@vue/eslint-config-airbnb": "4.0.0",
30+
"@vue/eslint-config-prettier": "4.0.0",
31+
"@vue/eslint-config-standard": "4.0.0",
32+
"@vue/eslint-config-typescript": "3.1.1"
33+
}
734
}

0 commit comments

Comments
 (0)