Skip to content

Commit e966db9

Browse files
committed
feat: shouldUseTaobao done
1 parent 81164ff commit e966db9

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

.vscode/settings.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
{
2-
"search.followSymlinks": false
2+
"search.followSymlinks": false,
3+
"files.exclude": {
4+
"**/bower_components": true,
5+
"**/node_modules": true
6+
}
37
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ module.exports = class Creator extends EventEmitter {
7373
preset = await this.resolvePreset(cliOptions.preset, cliOptions.clone)
7474
} else if (cliOptions.default) {
7575
// vue create foo --default
76-
preset = defaults.presets.default
77-
} else if (cliOptions.inlinePreset) {
76+
preset = defaults.presets.default // 使用默认预设选项
77+
} else if (cliOptions.inlinePreset) { // 使用内联的 JSON 字符串预设选项
7878
// vue create foo --inlinePreset {...}
7979
try {
8080
preset = JSON.parse(cliOptions.inlinePreset)

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports = async function shouldUseTaobao (command = 'npm') {
2323
checked = true
2424

2525
// previously saved preference
26-
const saved = loadOptions().useTaobaoRegistry
26+
const saved = loadOptions().useTaobaoRegistry // ~/.vuerc 中 useTaobaoRegistry 字段
2727
if (typeof saved === 'boolean') {
2828
return (result = saved)
2929
}
@@ -34,7 +34,7 @@ module.exports = async function shouldUseTaobao (command = 'npm') {
3434
return val
3535
}
3636

37-
const userCurrent = (await execa(command, ['config', 'get', 'registry'])).stdout
37+
const userCurrent = (await execa(command, ['config', 'get', 'registry'])).stdout // npm config get registry 获取用户是否设置了
3838
const defaultRegistry = registries[command]
3939

4040
if (removeSlash(userCurrent) !== removeSlash(defaultRegistry)) {
@@ -44,6 +44,7 @@ module.exports = async function shouldUseTaobao (command = 'npm') {
4444

4545
let faster
4646
try {
47+
// Promise.race 哪个结果获取的快就返回哪个
4748
faster = await Promise.race([
4849
ping(defaultRegistry),
4950
ping(registries.taobao)

0 commit comments

Comments
 (0)