Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(create-vite): distinguish pnpm pkgManager #4220

Merged
merged 9 commits into from
Jul 30, 2021
23 changes: 20 additions & 3 deletions packages/create-vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,17 @@ async function init() {

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

const pkgManager = /yarn/.test(process.env.npm_execpath) ? 'yarn' : 'npm'
const pkgManager =
pmFromUserAgent(process.env.npm_config_user_agent)?.name || 'npm'
d2FuZ3h1ZG9uZw marked this conversation as resolved.
Show resolved Hide resolved

console.log(`\nDone. Now run:\n`)
if (root !== cwd) {
console.log(` cd ${path.relative(cwd, root)}`)
}
console.log(` ${pkgManager === 'yarn' ? `yarn` : `npm install`}`)
console.log(` ${pkgManager === 'yarn' ? `yarn dev` : `npm run dev`}`)
console.log(` ${pkgManager === 'yarn' ? `yarn` : `${pkgManager} install`}`)
console.log(
` ${pkgManager === 'yarn' ? `yarn dev` : `${pkgManager} run dev`}`
)
d2FuZ3h1ZG9uZw marked this conversation as resolved.
Show resolved Hide resolved
console.log()
}

Expand Down Expand Up @@ -318,6 +321,20 @@ function emptyDir(dir) {
}
}

/**
* @param {string | undefined} userAgent process.env.npm_config_user_agent
* @returns object | undefined
*/
function pmFromUserAgent(userAgent) {
if (!userAgent) return undefined
const pmSpec = userAgent.split(' ')[0]
const pmSpecArr = pmSpec.split('/')
return {
name: pmSpecArr[0],
version: pmSpecArr[1]
}
}

init().catch((e) => {
console.error(e)
})