Skip to content

Commit b049e99

Browse files
authored
refactor: use env variables to set registry for package managers (#5110)
also fixes compatibility with Yarn 2
1 parent be06858 commit b049e99

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,13 @@ class PackageManager {
131131
return this._registry
132132
}
133133

134-
async addRegistryToArgs (args) {
134+
async setRegistryEnvs () {
135135
const registry = await this.getRegistry()
136-
args.push(`--registry=${registry}`)
137136

138-
return args
137+
process.env.npm_config_registry = registry
138+
process.env.YARN_NPM_REGISTRY_SERVER = registry
139+
140+
this.setBinaryMirrors()
139141
}
140142

141143
// set mirror urls for users in china
@@ -224,20 +226,28 @@ class PackageManager {
224226
}
225227
}
226228

229+
async runCommand (args) {
230+
await this.setRegistryEnvs()
231+
await executeCommand(this.bin, args, this.context)
232+
}
233+
227234
async install () {
228-
await this.setBinaryMirrors()
229-
const args = await this.addRegistryToArgs(PACKAGE_MANAGER_CONFIG[this.bin].install)
230-
return executeCommand(this.bin, args, this.context)
235+
return this.runCommand([PACKAGE_MANAGER_CONFIG[this.bin].install])
231236
}
232237

233238
async add (packageName, isDev = true) {
234-
await this.setBinaryMirrors()
235-
const args = await this.addRegistryToArgs([
239+
return this.runCommand([
236240
...PACKAGE_MANAGER_CONFIG[this.bin].add,
237241
packageName,
238242
...(isDev ? ['-D'] : [])
239243
])
240-
return executeCommand(this.bin, args, this.context)
244+
}
245+
246+
async remove (packageName) {
247+
return this.runCommand([
248+
...PACKAGE_MANAGER_CONFIG[this.bin].remove,
249+
packageName
250+
])
241251
}
242252

243253
async upgrade (packageName) {
@@ -254,20 +264,10 @@ class PackageManager {
254264
return
255265
}
256266

257-
await this.setBinaryMirrors()
258-
const args = await this.addRegistryToArgs([
267+
return this.runCommand([
259268
...PACKAGE_MANAGER_CONFIG[this.bin].add,
260269
packageName
261270
])
262-
return executeCommand(this.bin, args, this.context)
263-
}
264-
265-
async remove (packageName) {
266-
const args = [
267-
...PACKAGE_MANAGER_CONFIG[this.bin].remove,
268-
packageName
269-
]
270-
return executeCommand(this.bin, args, this.context)
271271
}
272272
}
273273

0 commit comments

Comments
 (0)