Skip to content

fix: allow specifying plugin version when calling vue add #5497

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

Merged
merged 1 commit into from
May 19, 2020
Merged
Changes from all commits
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
19 changes: 14 additions & 5 deletions packages/@vue/cli/lib/add.js
Original file line number Diff line number Diff line change
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