Check if your code is running as an npm, yarn, pnpm, or bun script
npm install is-npmimport {isPackageManager, isNpm, isYarn, isPnpm, isBun} from 'is-npm';
console.table({isPackageManager, isNpm, isYarn, isPnpm, isBun});$ node foo.js
# ┌──────────────────┬────────┐
# │ (index) │ Values │
# ├──────────────────┼────────┤
# │ isPackageManager │ false │
# │ isNpm │ false │
# │ isYarn │ false │
# │ isPnpm │ false │
# │ isBun │ false │
# └──────────────────┴────────┘
$ npm run foo
# ┌──────────────────┬────────┐
# │ (index) │ Values │
# ├──────────────────┼────────┤
# │ isPackageManager │ true │
# │ isNpm │ true │
# │ isYarn │ false │
# │ isPnpm │ false │
# │ isBun │ false │
# └──────────────────┴────────┘
$ yarn run foo
# ┌──────────────────┬────────┐
# │ (index) │ Values │
# ├──────────────────┼────────┤
# │ isPackageManager │ true │
# │ isNpm │ false │
# │ isYarn │ true │
# │ isPnpm │ false │
# │ isBun │ false │
# └──────────────────┴────────┘
$ pnpm run foo
# ┌──────────────────┬────────┐
# │ (index) │ Values │
# ├──────────────────┼────────┤
# │ isPackageManager │ true │
# │ isNpm │ false │
# │ isYarn │ false │
# │ isPnpm │ true │
# │ isBun │ false │
# └──────────────────┴────────┘
$ bun run foo
# ┌──────────────────┬────────┐
# │ (index) │ Values │
# ├──────────────────┼────────┤
# │ isPackageManager │ true │
# │ isNpm │ false │
# │ isYarn │ false │
# │ isPnpm │ false │
# │ isBun │ true │
# └──────────────────┴────────┘Check if your code is running as an npm script.
Check if your code is running as a yarn script.
Check if your code is running as a pnpm script.
Check if your code is running as a bun script.
Check if your code is running as a package manager script (npm, yarn, pnpm, or bun).
Check if your code is running as an npm or yarn script.
Use isPackageManager instead for detecting any package manager.
- is-npm-cli - CLI for this module