@@ -11,6 +11,29 @@ const taobaoDistURL = 'https://npm.taobao.org/dist'
11
11
12
12
const supportPackageManagerList = [ 'npm' , 'yarn' , 'pnpm' ]
13
13
14
+ const packageManagerConfig = {
15
+ npm : {
16
+ installDeps : [ 'install' , '--loglevel' , 'error' ] ,
17
+ installPackage : [ 'install' , '--loglevel' , 'error' ] ,
18
+ uninstallPackage : [ 'uninstall' , '--loglevel' , 'error' ] ,
19
+ updatePackage : [ 'update' , '--loglevel' , 'error' ]
20
+ } ,
21
+
22
+ pnpm : {
23
+ installDeps : [ 'install' , '--loglevel' , 'error' , '--shamefully-flatten' ] ,
24
+ installPackage : [ 'install' , '--loglevel' , 'error' ] ,
25
+ uninstallPackage : [ 'uninstall' , '--loglevel' , 'error' ] ,
26
+ updatePackage : [ 'update' , '--loglevel' , 'error' ]
27
+ } ,
28
+
29
+ yarn : {
30
+ installDeps : [ ] ,
31
+ installPackage : [ 'add' ] ,
32
+ uninstallPackage : [ 'remove' ] ,
33
+ updatePackage : [ 'upgrade' ]
34
+ }
35
+ }
36
+
14
37
class InstallProgress extends EventEmitter {
15
38
constructor ( ) {
16
39
super ( )
@@ -174,17 +197,7 @@ function executeCommand (command, args, targetDir) {
174
197
exports . installDeps = async function installDeps ( targetDir , command , cliRegistry ) {
175
198
checkPackageManagerIsSupported ( command )
176
199
177
- const args = [ ]
178
-
179
- if ( command === 'npm' || command === 'pnpm' ) {
180
- args . push ( 'install' , '--loglevel' , 'error' )
181
- } else if ( command === 'yarn' ) {
182
- // do nothing
183
- }
184
-
185
- if ( command === 'pnpm' ) {
186
- args . push ( '--shamefully-flatten' )
187
- }
200
+ const args = packageManagerConfig [ command ] . installDeps ;
188
201
189
202
await addRegistryToArgs ( command , args , cliRegistry )
190
203
@@ -197,13 +210,7 @@ exports.installDeps = async function installDeps (targetDir, command, cliRegistr
197
210
exports . installPackage = async function ( targetDir , command , cliRegistry , packageName , dev = true ) {
198
211
checkPackageManagerIsSupported ( command )
199
212
200
- const args = [ ]
201
-
202
- if ( command === 'npm' || command === 'pnpm' ) {
203
- args . push ( 'install' , '--loglevel' , 'error' )
204
- } else if ( command === 'yarn' ) {
205
- args . push ( 'add' )
206
- }
213
+ const args = packageManagerConfig [ command ] . installPackage ;
207
214
208
215
if ( dev ) args . push ( '-D' )
209
216
@@ -220,13 +227,7 @@ exports.installPackage = async function (targetDir, command, cliRegistry, packag
220
227
exports . uninstallPackage = async function ( targetDir , command , cliRegistry , packageName ) {
221
228
checkPackageManagerIsSupported ( command )
222
229
223
- const args = [ ]
224
-
225
- if ( command === 'npm' || command === 'pnpm' ) {
226
- args . push ( 'uninstall' , '--loglevel' , 'error' )
227
- } else if ( command === 'yarn' ) {
228
- args . push ( 'remove' )
229
- }
230
+ const args = packageManagerConfig [ command ] . uninstallPackage ;
230
231
231
232
await addRegistryToArgs ( command , args , cliRegistry )
232
233
@@ -241,13 +242,7 @@ exports.uninstallPackage = async function (targetDir, command, cliRegistry, pack
241
242
exports . updatePackage = async function ( targetDir , command , cliRegistry , packageName ) {
242
243
checkPackageManagerIsSupported ( command )
243
244
244
- const args = [ ]
245
-
246
- if ( command === 'npm' || command === 'pnpm' ) {
247
- args . push ( 'update' , '--loglevel' , 'error' )
248
- } else if ( command === 'yarn' ) {
249
- args . push ( 'upgrade' )
250
- }
245
+ const args = packageManagerConfig [ command ] . updatePackage ;
251
246
252
247
await addRegistryToArgs ( command , args , cliRegistry )
253
248
0 commit comments