]> git.ipfire.org Git - thirdparty/vuejs/create-vue.git/commitdiff
fix: use npm_config_user_agent, which is more reliable
authorHaoqun Jiang <haoqunjiang@gmail.com>
Wed, 19 Jan 2022 07:50:21 +0000 (15:50 +0800)
committerHaoqun Jiang <haoqunjiang@gmail.com>
Wed, 19 Jan 2022 07:50:21 +0000 (15:50 +0800)
Ref https://github.com/facebook/create-react-app/pull/11322#issuecomment-906621551

index.js

index cc2614d58b48eba7b1a3034e38e7d8163cf51ef1..4097b021b3dc5789672b5d8eb949026fa9b40e01 100755 (executable)
--- a/index.js
+++ b/index.js
@@ -358,12 +358,8 @@ async function init() {
   // Supported package managers: pnpm > yarn > npm
   // Note: until <https://github.com/pnpm/pnpm/issues/3505> 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(