Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/skarab42/detect-package-manager
Detects which package manager (bun, pnpm, yarn, npm) is used.
https://github.com/skarab42/detect-package-manager
bun lock-file lockfile npm package-manager packagemanager pnpm version yarn
Last synced: about 2 months ago
JSON representation
Detects which package manager (bun, pnpm, yarn, npm) is used.
- Host: GitHub
- URL: https://github.com/skarab42/detect-package-manager
- Owner: skarab42
- License: mit
- Created: 2022-08-05T13:30:16.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-07T01:55:39.000Z (about 1 year ago)
- Last Synced: 2024-05-21T11:29:15.469Z (7 months ago)
- Topics: bun, lock-file, lockfile, npm, package-manager, packagemanager, pnpm, version, yarn
- Language: TypeScript
- Homepage: https://npmjs.com/package/@skarab/detect-package-manager
- Size: 314 KB
- Stars: 13
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @skarab/detect-package-manager
Detects which package manager (bun, pnpm, yarn, npm) is used based on the current working directory.
## Features
- Support `packageManager` field in `package.json`.
- Detect PM agent version from lock file name, format or version.
- No dependency, fully typed and well tested!_TODO_
- Resolve external lock file such as `lockfile-directory` in `.npmrc` (PR welcome).
## Installation
```bash
pnpm add @skarab/detect-package-manager
```## Usage
Detect the PM agent from the current working directory.
```ts
import { detectAgent } from '@skarab/detect-package-manager';const agent = await detectAgent();
console.log(agent); // { name: 'pnpm', version: '7.6.0' }
```Detect the PM agent from a provided directory.
```ts
import { detectAgent } from '@skarab/detect-package-manager';const agent = await detectAgent('path/to/yarn/project');
console.log(agent); // { name: 'yarn', version: '1.22.17' }
```Detect all installed and [known](#known-agents) agents.
```ts
import { detectInstalledAgents } from '@skarab/detect-package-manager';const agents = await api.detectInstalledAgents();
console.log(agents.has('pnpm')); // true
// agents === Map(3) {
// 'pnpm' => { name: 'pnpm', version: '7.6.0' },
// 'yarn' => { name: 'yarn', version: '1.22.17' },
// 'npm' => { name: 'npm', version: '8.13.2' }
// }
```## Known agents
- [bun](https://bun.sh/) Bun is a fast all-in-one JavaScript runtime.
- [pnpm](https://pnpm.io/) Fast, disk space efficient package manager.
- [yarn](https://yarnpkg.com/) Yarn is a package manager that doubles down as project manager.
- [npm](https://www.npmjs.com/package/npm) A JavaScript package manager.## Related
- [detect-package-manager](https://github.com/egoist/detect-package-manager) Detect which package manager you're using (yarn or pnpm or npm)
- [preferred-pm](https://github.com/zkochan/packages/tree/main/preferred-pm) Returns the preferred package manager of a project
- [@antfu/ni](https://github.com/antfu/ni) Use the right package manager---
Scaffolded with [@skarab/skaffold](https://www.npmjs.com/package/@skarab/skaffold)