From: Haoqun Jiang Date: Wed, 19 Jan 2022 07:50:21 +0000 (+0800) Subject: fix: use npm_config_user_agent, which is more reliable X-Git-Tag: v3.1.0~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=27374f00df87bf881f6adba5b33f2792e2463a27;p=thirdparty%2Fvuejs%2Fcreate-vue.git fix: use npm_config_user_agent, which is more reliable Ref https://github.com/facebook/create-react-app/pull/11322#issuecomment-906621551 --- diff --git a/index.js b/index.js index cc2614d5..4097b021 100755 --- a/index.js +++ b/index.js @@ -358,12 +358,8 @@ async function init() { // Supported package managers: pnpm > yarn > npm // Note: until is resolved, // it is not possible to tell if the command is called by `pnpm init`. - const packageManagerBinary = path.basename(process.env.npm_execpath || '') - const packageManager = /pnpm/.test(packageManagerBinary) - ? 'pnpm' - : /yarn/.test(packageManagerBinary) - ? 'yarn' - : 'npm' + const userAgent = process.env.npm_config_user_agent ?? '' + const packageManager = /pnpm/.test(userAgent) ? 'pnpm' : /yarn/.test(userAgent) ? 'yarn' : 'npm' // README generation fs.writeFileSync(