From bc7ad069d36a86c475684ff127019e0a5e1530c4 Mon Sep 17 00:00:00 2001 From: William Barlow Date: Wed, 19 Jan 2022 15:50:21 +0800 Subject: [PATCH] fix: use npm_config_user_agent, which is more reliable Ref https://github.com/facebook/create-react-app/pull/11322#issuecomment-906621551 --- index.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index cc2614d..4097b02 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(