From b0f6ed82187ecb2e953bf970ba84beaf9a349270 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Mon, 29 Oct 2018 00:07:15 +0800 Subject: [PATCH] feat: support for `--registry` option in `vue add` & `vue invoke` commands (#2698) closes #1868 --- packages/@vue/cli/bin/vue.js | 2 ++ packages/@vue/cli/lib/add.js | 2 +- packages/@vue/cli/lib/invoke.js | 17 +++++++++++------ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/@vue/cli/bin/vue.js b/packages/@vue/cli/bin/vue.js index ee78bc257..6ee000686 100755 --- a/packages/@vue/cli/bin/vue.js +++ b/packages/@vue/cli/bin/vue.js @@ -67,6 +67,7 @@ program program .command('add [pluginOptions]') .description('install a plugin and invoke its generator in an already created project') + .option('--registry ', 'Use specified npm registry when installing dependencies (only for npm)') .allowUnknownOption() .action((plugin) => { require('../lib/add')(plugin, minimist(process.argv.slice(3))) @@ -75,6 +76,7 @@ program program .command('invoke [pluginOptions]') .description('invoke the generator of a plugin in an already created project') + .option('--registry ', 'Use specified npm registry when installing dependencies (only for npm)') .allowUnknownOption() .action((plugin) => { require('../lib/invoke')(plugin, minimist(process.argv.slice(3))) diff --git a/packages/@vue/cli/lib/add.js b/packages/@vue/cli/lib/add.js index dff23f3ea..a4e231664 100644 --- a/packages/@vue/cli/lib/add.js +++ b/packages/@vue/cli/lib/add.js @@ -27,7 +27,7 @@ async function add (pluginName, options = {}, context = process.cwd()) { log() const packageManager = loadOptions().packageManager || (hasProjectYarn(context) ? 'yarn' : 'npm') - await installPackage(context, packageManager, null, packageName) + await installPackage(context, packageManager, options.registry, packageName) log(`${chalk.green('✔')} Successfully installed plugin: ${chalk.cyan(packageName)}`) log() diff --git a/packages/@vue/cli/lib/invoke.js b/packages/@vue/cli/lib/invoke.js index d1b4c0dcd..6dd67b490 100644 --- a/packages/@vue/cli/lib/invoke.js +++ b/packages/@vue/cli/lib/invoke.js @@ -81,9 +81,11 @@ async function invoke (pluginName, options = {}, context = process.cwd()) { throw new Error(`Plugin ${id} does not have a generator.`) } - // resolve options if no command line options are passed, and the plugin - // contains a prompt module. - if (!Object.keys(options).length) { + // resolve options if no command line options (other than --registry) are passed, + // and the plugin contains a prompt module. + // eslint-disable-next-line prefer-const + let { registry, ...pluginOptions } = options + if (!Object.keys(pluginOptions).length) { let pluginPrompts = loadModule(`${id}/prompts`, context) if (pluginPrompts) { if (typeof pluginPrompts === 'function') { @@ -92,14 +94,17 @@ async function invoke (pluginName, options = {}, context = process.cwd()) { if (typeof pluginPrompts.getPrompts === 'function') { pluginPrompts = pluginPrompts.getPrompts(pkg) } - options = await inquirer.prompt(pluginPrompts) + pluginOptions = await inquirer.prompt(pluginPrompts) } } const plugin = { id, apply: pluginGenerator, - options + options: { + registry, + ...pluginOptions + } } await runGenerator(context, plugin, pkg) @@ -134,7 +139,7 @@ async function runGenerator (context, plugin, pkg = getPkg(context)) { log() const packageManager = loadOptions().packageManager || (hasProjectYarn(context) ? 'yarn' : 'npm') - await installDeps(context, packageManager) + await installDeps(context, packageManager, plugin.options.registry) } if (createCompleteCbs.length) {