File tree 1 file changed +26
-3
lines changed
1 file changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -254,14 +254,23 @@ async function init() {
254
254
255
255
write ( 'package.json' , JSON . stringify ( pkg , null , 2 ) )
256
256
257
- const pkgManager = / y a r n / . test ( process . env . npm_execpath ) ? 'yarn' : 'npm'
257
+ const pkgInfo = pkgFromUserAgent ( process . env . npm_config_user_agent )
258
+ const pkgManager = pkgInfo ? pkgInfo . name : 'npm'
258
259
259
260
console . log ( `\nDone. Now run:\n` )
260
261
if ( root !== cwd ) {
261
262
console . log ( ` cd ${ path . relative ( cwd , root ) } ` )
262
263
}
263
- console . log ( ` ${ pkgManager === 'yarn' ? `yarn` : `npm install` } ` )
264
- console . log ( ` ${ pkgManager === 'yarn' ? `yarn dev` : `npm run dev` } ` )
264
+ switch ( pkgManager ) {
265
+ case 'yarn' :
266
+ console . log ( ' yarn' )
267
+ console . log ( ' yarn dev' )
268
+ break
269
+ default :
270
+ console . log ( ` ${ pkgManager } install` )
271
+ console . log ( ` ${ pkgManager } run dev` )
272
+ break
273
+ }
265
274
console . log ( )
266
275
}
267
276
@@ -318,6 +327,20 @@ function emptyDir(dir) {
318
327
}
319
328
}
320
329
330
+ /**
331
+ * @param {string | undefined } userAgent process.env.npm_config_user_agent
332
+ * @returns object | undefined
333
+ */
334
+ function pkgFromUserAgent ( userAgent ) {
335
+ if ( ! userAgent ) return undefined
336
+ const pkgSpec = userAgent . split ( ' ' ) [ 0 ]
337
+ const pkgSpecArr = pkgSpec . split ( '/' )
338
+ return {
339
+ name : pkgSpecArr [ 0 ] ,
340
+ version : pkgSpecArr [ 1 ]
341
+ }
342
+ }
343
+
321
344
init ( ) . catch ( ( e ) => {
322
345
console . error ( e )
323
346
} )
You can’t perform that action at this time.
0 commit comments