Skip to content

Commit aee9e17

Browse files
authored
fix: allow specifying plugin version when calling vue add (#5497)
fixes #4700
1 parent 8b01c9e commit aee9e17

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

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

+14-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const {
1717
} = require('@vue/cli-shared-utils')
1818
const confirmIfGitDirty = require('./util/confirmIfGitDirty')
1919

20-
async function add (pluginName, options = {}, context = process.cwd()) {
20+
async function add (pluginToAdd, options = {}, context = process.cwd()) {
2121
if (!(await confirmIfGitDirty(context))) {
2222
return
2323
}
@@ -26,24 +26,33 @@ async function add (pluginName, options = {}, context = process.cwd()) {
2626
const servicePkg = loadModule('@vue/cli-service/package.json', context)
2727
if (servicePkg && semver.satisfies(servicePkg.version, '3.x')) {
2828
// special internal "plugins"
29-
if (/^(@vue\/)?router$/.test(pluginName)) {
29+
if (/^(@vue\/)?router$/.test(pluginToAdd)) {
3030
return addRouter(context)
3131
}
32-
if (/^(@vue\/)?vuex$/.test(pluginName)) {
32+
if (/^(@vue\/)?vuex$/.test(pluginToAdd)) {
3333
return addVuex(context)
3434
}
3535
}
3636

37+
const pluginRe = /^(@?[^@]+)(?:@(.+))?$/
38+
const [
39+
// eslint-disable-next-line
40+
_skip,
41+
pluginName,
42+
pluginVersion
43+
] = pluginToAdd.match(pluginRe)
3744
const packageName = resolvePluginId(pluginName)
3845

3946
log()
4047
log(`📦 Installing ${chalk.cyan(packageName)}...`)
4148
log()
4249

4350
const pm = new PackageManager({ context })
44-
const { latestMinor } = await getVersions()
4551

46-
if (isOfficialPlugin(packageName)) {
52+
if (pluginVersion) {
53+
await pm.add(`${packageName}@${pluginVersion}`)
54+
} else if (isOfficialPlugin(packageName)) {
55+
const { latestMinor } = await getVersions()
4756
await pm.add(`${packageName}@~${latestMinor}`)
4857
} else {
4958
await pm.add(packageName, { tilde: true })

0 commit comments

Comments
 (0)