@@ -131,11 +131,13 @@ class PackageManager {
131
131
return this . _registry
132
132
}
133
133
134
- async addRegistryToArgs ( args ) {
134
+ async setRegistryEnvs ( ) {
135
135
const registry = await this . getRegistry ( )
136
- args . push ( `--registry=${ registry } ` )
137
136
138
- return args
137
+ process . env . npm_config_registry = registry
138
+ process . env . YARN_NPM_REGISTRY_SERVER = registry
139
+
140
+ this . setBinaryMirrors ( )
139
141
}
140
142
141
143
// set mirror urls for users in china
@@ -224,20 +226,28 @@ class PackageManager {
224
226
}
225
227
}
226
228
229
+ async runCommand ( args ) {
230
+ await this . setRegistryEnvs ( )
231
+ await executeCommand ( this . bin , args , this . context )
232
+ }
233
+
227
234
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 ] )
231
236
}
232
237
233
238
async add ( packageName , isDev = true ) {
234
- await this . setBinaryMirrors ( )
235
- const args = await this . addRegistryToArgs ( [
239
+ return this . runCommand ( [
236
240
...PACKAGE_MANAGER_CONFIG [ this . bin ] . add ,
237
241
packageName ,
238
242
...( isDev ? [ '-D' ] : [ ] )
239
243
] )
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
+ ] )
241
251
}
242
252
243
253
async upgrade ( packageName ) {
@@ -254,20 +264,10 @@ class PackageManager {
254
264
return
255
265
}
256
266
257
- await this . setBinaryMirrors ( )
258
- const args = await this . addRegistryToArgs ( [
267
+ return this . runCommand ( [
259
268
...PACKAGE_MANAGER_CONFIG [ this . bin ] . add ,
260
269
packageName
261
270
] )
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 )
271
271
}
272
272
}
273
273
0 commit comments