Skip to content

Commit 738386e

Browse files
committed
fix(create-vite): distinguish pnpm pkgManager
1 parent eb39853 commit 738386e

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

packages/create-vite/index.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,17 @@ async function init() {
254254

255255
write('package.json', JSON.stringify(pkg, null, 2))
256256

257-
const pkgManager = /yarn/.test(process.env.npm_execpath) ? 'yarn' : 'npm'
257+
const pkgManager =
258+
pmFromUserAgent(process.env.npm_config_user_agent)?.name || 'npm'
258259

259260
console.log(`\nDone. Now run:\n`)
260261
if (root !== cwd) {
261262
console.log(` cd ${path.relative(cwd, root)}`)
262263
}
263-
console.log(` ${pkgManager === 'yarn' ? `yarn` : `npm install`}`)
264-
console.log(` ${pkgManager === 'yarn' ? `yarn dev` : `npm run dev`}`)
264+
console.log(` ${pkgManager === 'yarn' ? `yarn` : `${pkgManager} install`}`)
265+
console.log(
266+
` ${pkgManager === 'yarn' ? `yarn dev` : `${pkgManager} run dev`}`
267+
)
265268
console.log()
266269
}
267270

@@ -318,6 +321,20 @@ function emptyDir(dir) {
318321
}
319322
}
320323

324+
/**
325+
* @param {string | undefined} userAgent process.env.npm_config_user_agent
326+
* @returns object | undefined
327+
*/
328+
function pmFromUserAgent(userAgent) {
329+
if (!userAgent) return undefined
330+
const pmSpec = userAgent.split(' ')[0]
331+
const pmSpecArr = pmSpec.split('/')
332+
return {
333+
name: pmSpecArr[0],
334+
version: pmSpecArr[1]
335+
}
336+
}
337+
321338
init().catch((e) => {
322339
console.error(e)
323340
})

0 commit comments

Comments
 (0)