Skip to content

Commit 22b9600

Browse files
fix(create-app): default manual setup to npm (#2703)
Co-authored-by: Anthony Fu <github@antfu.me>
1 parent 1877b30 commit 22b9600

4 files changed

Lines changed: 14 additions & 26 deletions

File tree

packages/create-app/index.mjs

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import process from 'node:process'
88
import { fileURLToPath } from 'node:url'
99
import { blue, bold, cyan, dim, green, yellow } from 'ansis'
1010
import minimist from 'minimist'
11+
import { detect } from 'package-manager-detector/detect'
1112
import path from 'pathe'
1213
import prompts from 'prompts'
1314
import { 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)

packages/create-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"dependencies": {
3131
"ansis": "catalog:prod",
3232
"minimist": "catalog:prod",
33+
"package-manager-detector": "catalog:prod",
3334
"pathe": "catalog:prod",
3435
"prompts": "catalog:prod",
3536
"tinyexec": "catalog:prod"

pnpm-lock.yaml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ catalogs:
157157
mlly: ^1.8.2
158158
obug: ^2.1.4
159159
open: ^11.0.0
160+
package-manager-detector: ^1.8.0
160161
pathe: ^2.0.3
161162
pdf-lib: ^1.17.1
162163
picomatch: ^4.0.5

0 commit comments

Comments
 (0)