mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-01-23 15:49:08 -06:00
chore: merge dev
This commit is contained in:
@@ -54,7 +54,7 @@ modifications must be webpcak 4 compatible. Drop support
|
||||
for webpack plugins that do not work with v4 or above.
|
||||
* dll option has been removed.
|
||||
* the "vueLoader" option has been removed. To modify vue-loader
|
||||
options, use chainWebpack then `config.module.rule(vue).use(vue-loader).tap()`.
|
||||
options, use chainWebpack then `config.module.rule('vue').use('vue-loader').tap()`.
|
||||
vue-loader has been upgraded to v15 and expects different options from v14.
|
||||
* To include a dependency for Babel transpilation, tapping
|
||||
babel-loader and adding .include() will no longer work. Use the new
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
const { request } = require('@vue/cli-shared-utils')
|
||||
|
||||
module.exports = async function getPackageVersion (id, range = '') {
|
||||
const options = require('../options').loadOptions()
|
||||
const registry = options.useTaobaoRegistry
|
||||
const registry = (await require('./shouldUseTaobao')())
|
||||
? `https://registry.npm.taobao.org`
|
||||
: `https://registry.npmjs.org`
|
||||
|
||||
|
||||
@@ -2,17 +2,11 @@ const EventEmitter = require('events')
|
||||
const chalk = require('chalk')
|
||||
const execa = require('execa')
|
||||
const readline = require('readline')
|
||||
const inquirer = require('inquirer')
|
||||
const { loadOptions, saveOptions } = require('../options')
|
||||
const { request, pauseSpinner, resumeSpinner } = require('@vue/cli-shared-utils')
|
||||
const registries = require('./registries')
|
||||
const shouldUseTaobao = require('./shouldUseTaobao')
|
||||
|
||||
const debug = require('debug')('vue-cli:install')
|
||||
|
||||
const registries = {
|
||||
npm: 'https://registry.npmjs.org',
|
||||
yarn: 'https://registry.yarnpkg.com',
|
||||
taobao: 'https://registry.npm.taobao.org'
|
||||
}
|
||||
const taobaoDistURL = 'https://npm.taobao.org/dist'
|
||||
|
||||
class InstallProgress extends EventEmitter {
|
||||
@@ -46,64 +40,6 @@ class InstallProgress extends EventEmitter {
|
||||
|
||||
const progress = exports.progress = new InstallProgress()
|
||||
|
||||
async function ping (registry) {
|
||||
await request.get(`${registry}/vue-cli-version-marker/latest`)
|
||||
return registry
|
||||
}
|
||||
|
||||
function removeSlash (url) {
|
||||
return url.replace(/\/$/, '')
|
||||
}
|
||||
|
||||
let checked
|
||||
let result
|
||||
async function shouldUseTaobao () {
|
||||
// ensure this only gets called once.
|
||||
if (checked) return result
|
||||
checked = true
|
||||
|
||||
// previously saved preference
|
||||
const saved = loadOptions().useTaobaoRegistry
|
||||
if (typeof saved === 'boolean') {
|
||||
return (result = saved)
|
||||
}
|
||||
|
||||
const save = val => {
|
||||
result = val
|
||||
saveOptions({ useTaobaoRegistry: val })
|
||||
return val
|
||||
}
|
||||
|
||||
const userCurrent = (await execa(`npm`, ['config', 'get', 'registry'])).stdout
|
||||
const defaultRegistry = registries.npm
|
||||
if (removeSlash(userCurrent) !== removeSlash(defaultRegistry)) {
|
||||
// user has configured custom regsitry, respect that
|
||||
return save(false)
|
||||
}
|
||||
const faster = await Promise.race([
|
||||
ping(defaultRegistry),
|
||||
ping(registries.taobao)
|
||||
])
|
||||
|
||||
if (faster !== registries.taobao) {
|
||||
// default is already faster
|
||||
return save(false)
|
||||
}
|
||||
|
||||
// ask and save preference
|
||||
pauseSpinner()
|
||||
const { useTaobaoRegistry } = await inquirer.prompt([{
|
||||
name: 'useTaobaoRegistry',
|
||||
type: 'confirm',
|
||||
message: chalk.yellow(
|
||||
` Your connection to the the default npm registry seems to be slow.\n` +
|
||||
` Use ${chalk.cyan(registries.taobao)} for faster installation?`
|
||||
)
|
||||
}])
|
||||
resumeSpinner()
|
||||
return save(useTaobaoRegistry)
|
||||
}
|
||||
|
||||
function toStartOfLine (stream) {
|
||||
if (!chalk.supportsColor) {
|
||||
stream.write('\r')
|
||||
|
||||
7
packages/@vue/cli/lib/util/registries.js
Normal file
7
packages/@vue/cli/lib/util/registries.js
Normal file
@@ -0,0 +1,7 @@
|
||||
const registries = {
|
||||
npm: 'https://registry.npmjs.org',
|
||||
yarn: 'https://registry.yarnpkg.com',
|
||||
taobao: 'https://registry.npm.taobao.org'
|
||||
}
|
||||
|
||||
module.exports = registries
|
||||
69
packages/@vue/cli/lib/util/shouldUseTaobao.js
Normal file
69
packages/@vue/cli/lib/util/shouldUseTaobao.js
Normal file
@@ -0,0 +1,69 @@
|
||||
const chalk = require('chalk')
|
||||
const execa = require('execa')
|
||||
const request = require('./request')
|
||||
const inquirer = require('inquirer')
|
||||
const registries = require('./registries')
|
||||
const { loadOptions, saveOptions } = require('../options')
|
||||
|
||||
async function ping (registry) {
|
||||
await request.get(`${registry}/vue-cli-version-marker/latest`)
|
||||
return registry
|
||||
}
|
||||
|
||||
function removeSlash (url) {
|
||||
return url.replace(/\/$/, '')
|
||||
}
|
||||
|
||||
let checked
|
||||
let result
|
||||
|
||||
module.exports = async function shouldUseTaobao () {
|
||||
// ensure this only gets called once.
|
||||
if (checked) return result
|
||||
checked = true
|
||||
|
||||
// previously saved preference
|
||||
const saved = loadOptions().useTaobaoRegistry
|
||||
if (typeof saved === 'boolean') {
|
||||
return (result = saved)
|
||||
}
|
||||
|
||||
const save = val => {
|
||||
result = val
|
||||
saveOptions({ useTaobaoRegistry: val })
|
||||
return val
|
||||
}
|
||||
|
||||
const userCurrent = (await execa(`npm`, ['config', 'get', 'registry'])).stdout
|
||||
const defaultRegistry = registries.npm
|
||||
if (removeSlash(userCurrent) !== removeSlash(defaultRegistry)) {
|
||||
// user has configured custom regsitry, respect that
|
||||
return save(false)
|
||||
}
|
||||
const faster = await Promise.race([
|
||||
ping(defaultRegistry),
|
||||
ping(registries.taobao)
|
||||
])
|
||||
|
||||
if (faster !== registries.taobao) {
|
||||
// default is already faster
|
||||
return save(false)
|
||||
}
|
||||
|
||||
if (process.env.VUE_CLI_API_MODE) {
|
||||
return save(true)
|
||||
}
|
||||
|
||||
// ask and save preference
|
||||
const { useTaobaoRegistry } = await inquirer.prompt([
|
||||
{
|
||||
name: 'useTaobaoRegistry',
|
||||
type: 'confirm',
|
||||
message: chalk.yellow(
|
||||
` Your connection to the the default npm registry seems to be slow.\n` +
|
||||
` Use ${chalk.cyan(registries.taobao)} for faster installation?`
|
||||
)
|
||||
}
|
||||
])
|
||||
return save(useTaobaoRegistry)
|
||||
}
|
||||
Reference in New Issue
Block a user