Detalhes do pacote

is-npm

sindresorhus34.2mMIT6.1.0

Check if your code is running as an npm script

npm, yarn, pnpm, bun

readme (leia-me)

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