Skip to content

Commit b0f6ed8

Browse files
authored
feat: support for --registry option in vue add & vue invoke commands (#2698)
closes #1868
1 parent 78c7c12 commit b0f6ed8

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

packages/@vue/cli/bin/vue.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ program
6767
program
6868
.command('add <plugin> [pluginOptions]')
6969
.description('install a plugin and invoke its generator in an already created project')
70+
.option('--registry <url>', 'Use specified npm registry when installing dependencies (only for npm)')
7071
.allowUnknownOption()
7172
.action((plugin) => {
7273
require('../lib/add')(plugin, minimist(process.argv.slice(3)))
@@ -75,6 +76,7 @@ program
7576
program
7677
.command('invoke <plugin> [pluginOptions]')
7778
.description('invoke the generator of a plugin in an already created project')
79+
.option('--registry <url>', 'Use specified npm registry when installing dependencies (only for npm)')
7880
.allowUnknownOption()
7981
.action((plugin) => {
8082
require('../lib/invoke')(plugin, minimist(process.argv.slice(3)))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ async function add (pluginName, options = {}, context = process.cwd()) {
2727
log()
2828

2929
const packageManager = loadOptions().packageManager || (hasProjectYarn(context) ? 'yarn' : 'npm')
30-
await installPackage(context, packageManager, null, packageName)
30+
await installPackage(context, packageManager, options.registry, packageName)
3131

3232
log(`${chalk.green('✔')} Successfully installed plugin: ${chalk.cyan(packageName)}`)
3333
log()

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,11 @@ async function invoke (pluginName, options = {}, context = process.cwd()) {
8181
throw new Error(`Plugin ${id} does not have a generator.`)
8282
}
8383

84-
// resolve options if no command line options are passed, and the plugin
85-
// contains a prompt module.
86-
if (!Object.keys(options).length) {
84+
// resolve options if no command line options (other than --registry) are passed,
85+
// and the plugin contains a prompt module.
86+
// eslint-disable-next-line prefer-const
87+
let { registry, ...pluginOptions } = options
88+
if (!Object.keys(pluginOptions).length) {
8789
let pluginPrompts = loadModule(`${id}/prompts`, context)
8890
if (pluginPrompts) {
8991
if (typeof pluginPrompts === 'function') {
@@ -92,14 +94,17 @@ async function invoke (pluginName, options = {}, context = process.cwd()) {
9294
if (typeof pluginPrompts.getPrompts === 'function') {
9395
pluginPrompts = pluginPrompts.getPrompts(pkg)
9496
}
95-
options = await inquirer.prompt(pluginPrompts)
97+
pluginOptions = await inquirer.prompt(pluginPrompts)
9698
}
9799
}
98100

99101
const plugin = {
100102
id,
101103
apply: pluginGenerator,
102-
options
104+
options: {
105+
registry,
106+
...pluginOptions
107+
}
103108
}
104109

105110
await runGenerator(context, plugin, pkg)
@@ -134,7 +139,7 @@ async function runGenerator (context, plugin, pkg = getPkg(context)) {
134139
log()
135140
const packageManager =
136141
loadOptions().packageManager || (hasProjectYarn(context) ? 'yarn' : 'npm')
137-
await installDeps(context, packageManager)
142+
await installDeps(context, packageManager, plugin.options.registry)
138143
}
139144

140145
if (createCompleteCbs.length) {

0 commit comments

Comments
 (0)