Skip to content

Commit

Permalink
refactor: use env variables to set registry for package managers (#5110)
Browse files Browse the repository at this point in the history
also fixes compatibility with Yarn 2
  • Loading branch information
sodatea committed Jan 27, 2020
1 parent be06858 commit b049e99
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions packages/@vue/cli/lib/util/ProjectPackageManager.js
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
}
}

Expand Down

0 comments on commit b049e99

Please sign in to comment.