is-npm
Check if your code is running as an npm script
Last updated a year ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install is-npm 
SYNC missed versions from official npm registry.

is-npm

Check if your code is running as an npm, yarn, pnpm, or bun script

Install

npm install is-npm

Usage

import {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   │
# └──────────────────┴────────┘

API

isNpm

Check if your code is running as an npm script.

isYarn

Check if your code is running as a yarn script.

isPnpm

Check if your code is running as a pnpm script.

isBun

Check if your code is running as a bun script.

isPackageManager

Check if your code is running as a package manager script (npm, yarn, pnpm, or bun).

isNpmOrYarn (deprecated)

Check if your code is running as an npm or yarn script.

Use isPackageManager instead for detecting any package manager.

Related

Current Tags

  • 6.1.0                                ...           latest (a year ago)

7 Versions

  • 6.1.0                                ...           a year ago
  • 6.0.0                                ...           5 years ago
  • 5.0.0                                ...           7 years ago
  • 4.0.0                                ...           7 years ago
  • 3.0.0                                ...           8 years ago
  • 2.0.0                                ...           9 years ago
  • 1.0.0                                ...           12 years ago
Maintainers (1)
Downloads
Total 29
Today 0
This Week 3
This Month 19
Last Day 2
Last Week 5
Last Month 3
Dependencies (0)
None
Dev Dependencies (3)

© 2010 - cnpmjs.org x YWFE | Home | YWFE