npm.io
6.1.0 • Published 11 months ago

is-npm

Licence
MIT
Version
6.1.0
Deps
0
Size
8 kB
Vulns
0
Weekly
0
Stars
66
Better alternativeUse process.env.npm_config_user_agent?.startsWith("npm")Consider using a lighter alternative

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.

Keywords