Skip to content

Commit 67df3eb

Browse files
committed
fix: only support taobao check and inline registry when using npm
close #789
1 parent 46166fb commit 67df3eb

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ program
3939
.option('-p, --preset <presetName>', 'Skip prompts and use saved preset')
4040
.option('-d, --default', 'Skip prompts and use default preset')
4141
.option('-i, --inlinePreset <json>', 'Skip prompts and use inline JSON string as preset')
42-
.option('-r, --registry <url>', 'Use specified NPM registry when installing dependencies')
43-
.option('-m, --packageManager <command>', 'Use specified NPM client when installing dependencies')
42+
.option('-m, --packageManager <command>', 'Use specified npm client when installing dependencies')
43+
.option('-r, --registry <url>', 'Use specified npm registry when installing dependencies (only for npm)')
4444
.option('-f, --force', 'Overwrite target directory if it exists')
4545
.action((name, cmd) => {
4646
require('../lib/create')(name, cleanArgs(cmd))

packages/@vue/cli/lib/util/installDeps.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const ping = url => new Promise((resolve, reject) => {
2929

3030
let checked
3131
let result
32-
const shouldUseTaobao = async (command) => {
32+
const shouldUseTaobao = async () => {
3333
// ensure this only gets called once.
3434
if (checked) return result
3535
checked = true
@@ -46,8 +46,8 @@ const shouldUseTaobao = async (command) => {
4646
return val
4747
}
4848

49-
const userCurrent = (await execa(command, ['config', 'get', 'registry'])).stdout
50-
const defaultRegistry = registries[command]
49+
const userCurrent = (await execa(`npm`, ['config', 'get', 'registry'])).stdout
50+
const defaultRegistry = registries.npm
5151
if (userCurrent !== defaultRegistry) {
5252
// user has configured custom regsitry, respect that
5353
return save(false)
@@ -67,7 +67,7 @@ const shouldUseTaobao = async (command) => {
6767
name: 'useTaobaoRegistry',
6868
type: 'confirm',
6969
message: chalk.yellow(
70-
` Your connection to the the default ${command} registry seems to be slow.\n` +
70+
` Your connection to the the default npm registry seems to be slow.\n` +
7171
` Use ${chalk.cyan(registries.taobao)} for faster installation?`
7272
)
7373
}])
@@ -102,20 +102,27 @@ module.exports = async function installDeps (targetDir, command, cliRegistry) {
102102
} else if (command === 'yarn') {
103103
// do nothing
104104
} else {
105-
throw new Error(`unknown package manager: ${command}`)
105+
throw new Error(`Unknown package manager: ${command}`)
106+
}
107+
108+
if (command === 'yarn' && cliRegistry) {
109+
throw new Error(
110+
`Inline registry is not supported when using yarn. ` +
111+
`Please run \`yarn config set registry ${cliRegistry}\` before running @vue/cli.`
112+
)
106113
}
107114

108115
const altRegistry = (
109116
cliRegistry || (
110-
(await shouldUseTaobao(command))
117+
(command === 'npm' && await shouldUseTaobao())
111118
? registries.taobao
112119
: null
113120
)
114121
)
115122

116123
if (altRegistry) {
117124
args.push(`--registry=${altRegistry}`)
118-
if (command === 'npm' && altRegistry === registries.taobao) {
125+
if (altRegistry === registries.taobao) {
119126
args.push(`--disturl=${taobaoDistURL}`)
120127
}
121128
}

0 commit comments

Comments
 (0)