Detect package managers automatically (
npm
,yarn
,bun
andpnpm
).
detect-pm comes from https://github.com/antfu/install-pkg/blob/main/src/detect.ts. The author is antfu who is my super idol.
$ npm i detect-pm
$ yarn add detect-pm
$ pnpm add detect-pm
Support ES module and CommonJS:
import { detectPackageManager } from 'detect-pm'
// or
// const { detectPackageManager } = require('detect-pm')
detectPackageManager().then(pm => {
console.log(pm) // one of npm, yarn, pnpm or bun if detect, else null
})