mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-01-17 12:50:04 -06:00
refactor: use env variables to set registry for package managers (#5110)
also fixes compatibility with Yarn 2
This commit is contained in:
@@ -131,11 +131,13 @@ class PackageManager {
|
||||
return this._registry
|
||||
}
|
||||
|
||||
async addRegistryToArgs (args) {
|
||||
async setRegistryEnvs () {
|
||||
const registry = await this.getRegistry()
|
||||
args.push(`--registry=${registry}`)
|
||||
|
||||
return args
|
||||
process.env.npm_config_registry = registry
|
||||
process.env.YARN_NPM_REGISTRY_SERVER = registry
|
||||
|
||||
this.setBinaryMirrors()
|
||||
}
|
||||
|
||||
// set mirror urls for users in china
|
||||
@@ -224,20 +226,28 @@ class PackageManager {
|
||||
}
|
||||
}
|
||||
|
||||
async runCommand (args) {
|
||||
await this.setRegistryEnvs()
|
||||
await executeCommand(this.bin, args, this.context)
|
||||
}
|
||||
|
||||
async install () {
|
||||
await this.setBinaryMirrors()
|
||||
const args = await this.addRegistryToArgs(PACKAGE_MANAGER_CONFIG[this.bin].install)
|
||||
return executeCommand(this.bin, args, this.context)
|
||||
return this.runCommand([PACKAGE_MANAGER_CONFIG[this.bin].install])
|
||||
}
|
||||
|
||||
async add (packageName, isDev = true) {
|
||||
await this.setBinaryMirrors()
|
||||
const args = await this.addRegistryToArgs([
|
||||
return this.runCommand([
|
||||
...PACKAGE_MANAGER_CONFIG[this.bin].add,
|
||||
packageName,
|
||||
...(isDev ? ['-D'] : [])
|
||||
])
|
||||
return executeCommand(this.bin, args, this.context)
|
||||
}
|
||||
|
||||
async remove (packageName) {
|
||||
return this.runCommand([
|
||||
...PACKAGE_MANAGER_CONFIG[this.bin].remove,
|
||||
packageName
|
||||
])
|
||||
}
|
||||
|
||||
async upgrade (packageName) {
|
||||
@@ -254,20 +264,10 @@ class PackageManager {
|
||||
return
|
||||
}
|
||||
|
||||
await this.setBinaryMirrors()
|
||||
const args = await this.addRegistryToArgs([
|
||||
return this.runCommand([
|
||||
...PACKAGE_MANAGER_CONFIG[this.bin].add,
|
||||
packageName
|
||||
])
|
||||
return executeCommand(this.bin, args, this.context)
|
||||
}
|
||||
|
||||
async remove (packageName) {
|
||||
const args = [
|
||||
...PACKAGE_MANAGER_CONFIG[this.bin].remove,
|
||||
packageName
|
||||
]
|
||||
return executeCommand(this.bin, args, this.context)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user