https://github.com/jackw/pm-detect
https://github.com/jackw/pm-detect
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/jackw/pm-detect
- Owner: jackw
- License: mit
- Created: 2025-08-04T10:51:09.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-08-04T12:12:13.000Z (10 months ago)
- Last Synced: 2025-08-04T13:09:00.728Z (10 months ago)
- Language: TypeScript
- Size: 41 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Package Manager Detect
[](#contributors-)
This package includes a bin which can be used to detect the current node package manager a node project uses and it's associated commands.
## Usage
No need to install, can be run via node exec commands such as:
```
npx pm-detect
```
The above command will log the following JSON blob to stdout (if the project uses NPM):
```json
{
"name": "npm",
"install": "npm install",
"frozen-install": "npm ci",
"global-install": "npm install -g",
"run": "npm run",
"exec": "npx"
}
```
The structure of the output is always the same regardless of package manager (`NPM`, `yarn`, `PNPM`). It is only the values of the object that change.
## Command Line Options
The `pm-detect` CLI supports the following options:
### `--working-dir `
Specifies the working directory to detect the package manager in. If not provided, the current working directory is used.
```bash
npx pm-detect --working-dir /path/to/project
```
> [!NOTE]
> If no package manager is detected in the working directory the cli will traverse up the directory tree until it finds one. This should prove useful in monorepos where a workspace might be passed as the current working directory.
### `--strategies `
Specifies a comma-separated list of detection strategies to use. Available strategies are:
- `packageJson` - Detect from package.json's packageManager field (recommended)
- `lockFile` - Detect from lock file presence (package-lock.json, yarn.lock, pnpm-lock.yaml)
- `userAgent` - Detect from npm_config_user_agent environment variable
```bash
# Use only package.json detection
npx pm-detect --strategies packageJson
# Use multiple strategies in a specific order
npx pm-detect --strategies packageJson,lockFile,userAgent
```
### `--help`
Shows the help message with all available options.
```bash
npx pm-detect --help
```
### `--version`
Shows the current version of the CLI tool.
```bash
npx pm-detect --version
```
## Examples
```bash
# Basic usage - detects package manager in current directory
npx pm-detect
# Detect in a specific directory
npx pm-detect --working-dir /path/to/project
# Use only lock file detection strategy
npx pm-detect --strategies lockFile
# Combine options
npx pm-detect --working-dir /path/to/project --strategies packageJson,lockFile
```
## Thanks
This project is based heavily on the following npm packages. Many thanks to their authors.
- [package-manager-detector](https://www.npmjs.com/package/package-manager-detector)
- [detect-package-manager](https://www.npmjs.com/package/detect-package-manager)
## Contributors ✨
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
## Security
This package is published using NPMs provenence feature that asserts a given release is tied to a specific commit.