Skip to content

Commit

Permalink
fix: use npm_config_user_agent, which is more reliable
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamBarlow0216 committed Jan 19, 2022
1 parent 1c1ae4f commit bc7ad06
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit bc7ad06

Please sign in to comment.