@@ -9,6 +9,8 @@ const debug = require('debug')('vue-cli:install')
9
9
10
10
const taobaoDistURL = 'https://npm.taobao.org/dist'
11
11
12
+ const supportPackageManagerList = [ 'npm' , 'yarn' ]
13
+
12
14
class InstallProgress extends EventEmitter {
13
15
constructor ( ) {
14
16
super ( )
@@ -48,6 +50,12 @@ function toStartOfLine (stream) {
48
50
readline . cursorTo ( stream , 0 )
49
51
}
50
52
53
+ function checkPackageManagerIsSupported ( command ) {
54
+ if ( supportPackageManagerList . indexOf ( command ) === - 1 ) {
55
+ throw new Error ( `Unknown package manager: ${ command } ` )
56
+ }
57
+ }
58
+
51
59
function renderProgressBar ( curr , total ) {
52
60
const ratio = Math . min ( Math . max ( curr / total , 0 ) , 1 )
53
61
const bar = ` ${ curr } /${ total } `
@@ -164,13 +172,14 @@ function executeCommand (command, args, targetDir) {
164
172
}
165
173
166
174
exports . installDeps = async function installDeps ( targetDir , command , cliRegistry ) {
175
+ checkPackageManagerIsSupported ( command )
176
+
167
177
const args = [ ]
178
+
168
179
if ( command === 'npm' ) {
169
180
args . push ( 'install' , '--loglevel' , 'error' )
170
181
} else if ( command === 'yarn' ) {
171
182
// do nothing
172
- } else {
173
- throw new Error ( `Unknown package manager: ${ command } ` )
174
183
}
175
184
176
185
await addRegistryToArgs ( command , args , cliRegistry )
@@ -182,13 +191,14 @@ exports.installDeps = async function installDeps (targetDir, command, cliRegistr
182
191
}
183
192
184
193
exports . installPackage = async function ( targetDir , command , cliRegistry , packageName , dev = true ) {
194
+ checkPackageManagerIsSupported ( command )
195
+
185
196
const args = [ ]
197
+
186
198
if ( command === 'npm' ) {
187
199
args . push ( 'install' , '--loglevel' , 'error' )
188
200
} else if ( command === 'yarn' ) {
189
201
args . push ( 'add' )
190
- } else {
191
- throw new Error ( `Unknown package manager: ${ command } ` )
192
202
}
193
203
194
204
if ( dev ) args . push ( '-D' )
@@ -204,13 +214,14 @@ exports.installPackage = async function (targetDir, command, cliRegistry, packag
204
214
}
205
215
206
216
exports . uninstallPackage = async function ( targetDir , command , cliRegistry , packageName ) {
217
+ checkPackageManagerIsSupported ( command )
218
+
207
219
const args = [ ]
220
+
208
221
if ( command === 'npm' ) {
209
222
args . push ( 'uninstall' , '--loglevel' , 'error' )
210
223
} else if ( command === 'yarn' ) {
211
224
args . push ( 'remove' )
212
- } else {
213
- throw new Error ( `Unknown package manager: ${ command } ` )
214
225
}
215
226
216
227
await addRegistryToArgs ( command , args , cliRegistry )
@@ -224,13 +235,14 @@ exports.uninstallPackage = async function (targetDir, command, cliRegistry, pack
224
235
}
225
236
226
237
exports . updatePackage = async function ( targetDir , command , cliRegistry , packageName ) {
238
+ checkPackageManagerIsSupported ( command )
239
+
227
240
const args = [ ]
241
+
228
242
if ( command === 'npm' ) {
229
243
args . push ( 'update' , '--loglevel' , 'error' )
230
244
} else if ( command === 'yarn' ) {
231
245
args . push ( 'upgrade' )
232
- } else {
233
- throw new Error ( `Unknown package manager: ${ command } ` )
234
246
}
235
247
236
248
await addRegistryToArgs ( command , args , cliRegistry )
0 commit comments