Skip to content

Commit

Permalink
fix: only support taobao check and inline registry when using npm
Browse files Browse the repository at this point in the history
close #789
  • Loading branch information
yyx990803 committed Feb 6, 2018
1 parent 46166fb commit 67df3eb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/@vue/cli/bin/vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ program
.option('-p, --preset <presetName>', 'Skip prompts and use saved preset')
.option('-d, --default', 'Skip prompts and use default preset')
.option('-i, --inlinePreset <json>', 'Skip prompts and use inline JSON string as preset')
.option('-r, --registry <url>', 'Use specified NPM registry when installing dependencies')
.option('-m, --packageManager <command>', 'Use specified NPM client when installing dependencies')
.option('-m, --packageManager <command>', 'Use specified npm client when installing dependencies')
.option('-r, --registry <url>', 'Use specified npm registry when installing dependencies (only for npm)')
.option('-f, --force', 'Overwrite target directory if it exists')
.action((name, cmd) => {
require('../lib/create')(name, cleanArgs(cmd))
Expand Down
21 changes: 14 additions & 7 deletions packages/@vue/cli/lib/util/installDeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const ping = url => new Promise((resolve, reject) => {

let checked
let result
const shouldUseTaobao = async (command) => {
const shouldUseTaobao = async () => {
// ensure this only gets called once.
if (checked) return result
checked = true
Expand All @@ -46,8 +46,8 @@ const shouldUseTaobao = async (command) => {
return val
}

const userCurrent = (await execa(command, ['config', 'get', 'registry'])).stdout
const defaultRegistry = registries[command]
const userCurrent = (await execa(`npm`, ['config', 'get', 'registry'])).stdout
const defaultRegistry = registries.npm
if (userCurrent !== defaultRegistry) {
// user has configured custom regsitry, respect that
return save(false)
Expand All @@ -67,7 +67,7 @@ const shouldUseTaobao = async (command) => {
name: 'useTaobaoRegistry',
type: 'confirm',
message: chalk.yellow(
` Your connection to the the default ${command} registry seems to be slow.\n` +
` Your connection to the the default npm registry seems to be slow.\n` +
` Use ${chalk.cyan(registries.taobao)} for faster installation?`
)
}])
Expand Down Expand Up @@ -102,20 +102,27 @@ module.exports = async function installDeps (targetDir, command, cliRegistry) {
} else if (command === 'yarn') {
// do nothing
} else {
throw new Error(`unknown package manager: ${command}`)
throw new Error(`Unknown package manager: ${command}`)
}

if (command === 'yarn' && cliRegistry) {
throw new Error(
`Inline registry is not supported when using yarn. ` +
`Please run \`yarn config set registry ${cliRegistry}\` before running @vue/cli.`
)
}

const altRegistry = (
cliRegistry || (
(await shouldUseTaobao(command))
(command === 'npm' && await shouldUseTaobao())
? registries.taobao
: null
)
)

if (altRegistry) {
args.push(`--registry=${altRegistry}`)
if (command === 'npm' && altRegistry === registries.taobao) {
if (altRegistry === registries.taobao) {
args.push(`--disturl=${taobaoDistURL}`)
}
}
Expand Down

0 comments on commit 67df3eb

Please sign in to comment.