Skip to content

Commit 27374f0

Browse files
committed
fix: use npm_config_user_agent, which is more reliable
Ref facebook/create-react-app#11322 (comment)
1 parent bee0fe3 commit 27374f0

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

index.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,8 @@ async function init() {
358358
// Supported package managers: pnpm > yarn > npm
359359
// Note: until <https://github.com/pnpm/pnpm/issues/3505> is resolved,
360360
// it is not possible to tell if the command is called by `pnpm init`.
361-
const packageManagerBinary = path.basename(process.env.npm_execpath || '')
362-
const packageManager = /pnpm/.test(packageManagerBinary)
363-
? 'pnpm'
364-
: /yarn/.test(packageManagerBinary)
365-
? 'yarn'
366-
: 'npm'
361+
const userAgent = process.env.npm_config_user_agent ?? ''
362+
const packageManager = /pnpm/.test(userAgent) ? 'pnpm' : /yarn/.test(userAgent) ? 'yarn' : 'npm'
367363

368364
// README generation
369365
fs.writeFileSync(

0 commit comments

Comments
 (0)