Skip to content

Commit

Permalink
fix: allow specifying plugin version when calling vue add (#5497)
Browse files Browse the repository at this point in the history
fixes #4700
  • Loading branch information
sodatea committed May 19, 2020
1 parent 8b01c9e commit aee9e17
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions packages/@vue/cli/lib/add.js
Expand Up @@ -17,7 +17,7 @@ const {
} = require('@vue/cli-shared-utils')
const confirmIfGitDirty = require('./util/confirmIfGitDirty')

async function add (pluginName, options = {}, context = process.cwd()) {
async function add (pluginToAdd, options = {}, context = process.cwd()) {
if (!(await confirmIfGitDirty(context))) {
return
}
Expand All @@ -26,24 +26,33 @@ async function add (pluginName, options = {}, context = process.cwd()) {
const servicePkg = loadModule('@vue/cli-service/package.json', context)
if (servicePkg && semver.satisfies(servicePkg.version, '3.x')) {
// special internal "plugins"
if (/^(@vue\/)?router$/.test(pluginName)) {
if (/^(@vue\/)?router$/.test(pluginToAdd)) {
return addRouter(context)
}
if (/^(@vue\/)?vuex$/.test(pluginName)) {
if (/^(@vue\/)?vuex$/.test(pluginToAdd)) {
return addVuex(context)
}
}

const pluginRe = /^(@?[^@]+)(?:@(.+))?$/
const [
// eslint-disable-next-line
_skip,
pluginName,
pluginVersion
] = pluginToAdd.match(pluginRe)
const packageName = resolvePluginId(pluginName)

log()
log(`📦 Installing ${chalk.cyan(packageName)}...`)
log()

const pm = new PackageManager({ context })
const { latestMinor } = await getVersions()

if (isOfficialPlugin(packageName)) {
if (pluginVersion) {
await pm.add(`${packageName}@${pluginVersion}`)
} else if (isOfficialPlugin(packageName)) {
const { latestMinor } = await getVersions()
await pm.add(`${packageName}@~${latestMinor}`)
} else {
await pm.add(packageName, { tilde: true })
Expand Down

0 comments on commit aee9e17

Please sign in to comment.