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
NazariiTomei committed Jan 19, 2022
1 parent 5a36c26 commit 9b173da
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 9b173da

Please sign in to comment.