@node-kit/which-pm
Version:
A simple utility to get which package manager used in the project
116 lines (78 loc) • 3 kB
Markdown
<div style="text-align: center;" align="center">
A simple utility to get which package manager used in the project
[![NPM version][npm-image]][npm-url]
[![Codacy Badge][codacy-image]][codacy-url]
[![Test coverage][codecov-image]][codecov-url]
[![npm download][download-image]][download-url]
[![License][license-image]][license-url]
[![Sonar][sonar-image]][sonar-url]
</div>
```bash
$ pnpm install -D @node-kit/which-pm
$ yarn add -D @node-kit/which-pm
$ npm install -D @node-kit/which-pm
```
use `@node-kit/which-pm` in terminal
```bash
npx which-pm
```
use import
```js
import { whichPM, whichPMSync } from '@node-kit/which-pm'
whichPM()
// or
whichPMSync()
```
use require
```js
const { whichPM, whichPMSync } = require('@node-kit/which-pm')
whichPM()
// or
whichPMSync()
```
- Usage: `whichPM([cwd, withVersion])` & `whichPMSync([cwd, withVersion])`
- Parameters:
<div class="table-prop">
| Param | Description | Type | Optional value | Required | Default value |
| ----------- | ------------------- | --------- | -------------- | -------- | ------------- |
| cwd | running path | `string` | - | `false` | - |
| withVersion | return with version | `boolean` | - | `false` | `true` |
</div>
- Types:
```ts
declare function whichPM(cwd?: string, withVersion?: boolean): Promise<string | null>
declare function whichPMSync(cwd?: string, withVersion?: boolean): string | null
```
- Demos:
1. simple use
```ts
import { whichPM, whichPMSync } from '@node-kit/which-pm'
whichPM().then(path => {
console.log('The package manager is: ', path) // pnpm@7.26.1 | null
})
console.log('The package manager is: ', whichPMSync()) // pnpm@7.26.1 | null
```
Please open an issue [here](https://github.com/saqqdy/node-kit/issues).
[](LICENSE)
[]: https://img.shields.io/npm/v/@node-kit/which-pm.svg?style=flat-square
[]: https://npmjs.org/package/@node-kit/which-pm
[]: https://app.codacy.com/project/badge/Grade/f70d4880e4ad4f40aa970eb9ee9d0696
[]: https://www.codacy.com/gh/saqqdy/@node-kit/which-pm/dashboard?utm_source=github.com&utm_medium=referral&utm_content=saqqdy/@node-kit/which-pm&utm_campaign=Badge_Grade
[]: https://img.shields.io/codecov/c/github/saqqdy/@node-kit/which-pm.svg?style=flat-square
[]: https://codecov.io/github/saqqdy/@node-kit/which-pm?branch=master
[]: https://img.shields.io/npm/dm/@node-kit/which-pm.svg?style=flat-square
[]: https://npmjs.org/package/@node-kit/which-pm
[]: https://img.shields.io/badge/License-MIT-blue.svg
[]: LICENSE
[]: https://sonarcloud.io/api/project_badges/quality_gate?project=saqqdy_node-kit
[]: https://sonarcloud.io/dashboard?id=saqqdy_node-kit