@@ -8,6 +8,7 @@ import process from 'node:process'
88import { fileURLToPath } from 'node:url'
99import { blue , bold , cyan , dim , green , yellow } from 'ansis'
1010import minimist from 'minimist'
11+ import { detect } from 'package-manager-detector/detect'
1112import path from 'pathe'
1213import prompts from 'prompts'
1314import { x } from 'tinyexec'
@@ -95,21 +96,7 @@ async function init() {
9596
9697 console . log ( green ( ' Done.\n' ) )
9798
98- function getPkgManager ( ) {
99- const pm = [ ]
100- if ( typeof Deno !== 'undefined' )
101- pm . push ( 'deno' )
102- if ( typeof Bun !== 'undefined' )
103- pm . push ( 'bun' )
104- const userAgent = process . env . npm_config_user_agent || ''
105- const execPath = process . env . npm_execpath || ''
106- if ( execPath . includes ( 'pnpm' ) || userAgent . includes ( 'pnpm' ) )
107- pm . push ( 'pnpm' )
108- if ( execPath . includes ( 'yarn' ) || userAgent . includes ( 'yarn' ) )
109- pm . push ( 'yarn' )
110- return pm . length === 1 ? pm [ 0 ] : null
111- }
112- const pkgManager = getPkgManager ( )
99+ const pkgManager = await detect ( ) . catch ( ( ) => undefined ) ?? 'npm'
113100
114101 /**
115102 * @type {{ yes: boolean } }
@@ -122,19 +109,12 @@ async function init() {
122109 } )
123110
124111 if ( yes ) {
125- const agent = pkgManager || ( await prompts ( {
126- name : 'agent' ,
127- type : 'select' ,
128- message : 'Choose the package manager' ,
129- choices : [ 'npm' , 'yarn' , 'pnpm' , 'bun' , 'deno' ] . map ( i => ( { value : i , title : i } ) ) ,
130- } ) . agent )
131-
132- if ( ! agent )
112+ if ( ! pkgManager )
133113 return
134114
135- writeReadme ( agent )
136- await x ( agent , [ 'install' ] , { nodeOptions : { stdio : 'inherit' , cwd : root } } )
137- await x ( agent , [ 'run' , 'dev' ] , { nodeOptions : { stdio : 'inherit' , cwd : root } } )
115+ writeReadme ( pkgManager )
116+ await x ( pkgManager , [ 'install' ] , { nodeOptions : { stdio : 'inherit' , cwd : root } } )
117+ await x ( pkgManager , [ 'run' , 'dev' ] , { nodeOptions : { stdio : 'inherit' , cwd : root } } )
138118 }
139119 else {
140120 writeReadme ( pkgManager )
0 commit comments