@rnm/pm
Version:
Unified Package Manager for Node.js
119 lines (84 loc) âĒ 5.31 kB
Markdown
# ðĶ PM
[](https://github.com/rnmjs/pm/blob/main/LICENSE)
[](https://www.npmjs.com/package/@rnm/pm)
[](https://www.npmjs.com/package/@rnm/pm)
[](https://packagephobia.com/result?p=@rnm/pm)
[]()
[](https://github.com/rnmjs/pm?tab=readme-ov-file#contributing)
A unified package manager for Node.js that supports `npm`, `yarn`, and `pnpm`. This human-friendly Corepack wrapper lets you forget about `npm`, `yarn`, and `pnpm` â just use the `pm` command for everything.
## Highlights
- **ðĶ All-in-One**: Supports npm, yarn, and pnpm without extra installations.
- **ðŊ Auto Detect**: Automatically detects the correct package manager.
- **âŽïļ Auto Fallback**: Automatically falls back to npm if no package manager is detected.
- **ð Version Management**: Automatically switches to the proper version of the detected package manager.
- **âĄïļ Zero Configuration**: No configuration required. Just install it globally and start using it.
- **ð Global Safety**: Does not modify or override existing global package managers by default.
- **ðŠķ Lightweight**: Tiny codebase (~ 400 lines).
## Installation
```bash
npm install -g @rnm/pm
```
## Usage
### Inside Projects
When inside a project directory, `pm` and `px` are aliases for `npm`/`yarn`/`pnpm` and `npx`/`yarnpkg`/`pnpx` respectively. The choice depends on the project's configuration. Falls back to `npm` and `npx` if no specific package manager is detected.
Configure `packageManager` or `devEngines.packageManager` in `package.json`:
```json
{
"packageManager": "pnpm@10.0.0",
"devEngines": {
"packageManager": {
"name": "pnpm",
"version": "10.0.0"
}
}
}
```
Commands work exactly like the underlying package manager:
```bash
# pm = smart alias for npm/yarn/pnpm
pm install # â npm/yarn/pnpm install
pm run build # â npm/yarn/pnpm run build
pm --help # â npm/yarn/pnpm --help
pm --version # â npm/yarn/pnpm --version
# px = smart alias for npx/yarnpkg/pnpx
px create-react-app my-app --template typescript # â npx/yarnpkg/pnpx create-react-app my-app --template typescript
px tsx --watch src/index.ts # â npx/yarnpkg/pnpx tsx --watch src/index.ts
```
### Outside Projects
When outside project directories, `pm` and `px` are aliases for `npm` and `npx`. These are typically used for global operations.
```bash
# pm = alias for npm
pm install -g typescript@latest # â npm install -g typescript@latest
pm list -g --depth=0 # â npm list -g --depth=0
# px = alias for npx
px create-react-app my-app --template next # â npx create-react-app my-app --template next
px degit user/repo my-app # â npx degit user/repo my-app
```
## Advanced Usage
The `pm-util` command provides additional utilities for advanced use cases.
#### Enable Shim Commands
Use `pm-util enable-shim` to create symbolic links that replace the native package manager commands with `@rnm/pm` equivalents:
```bash
# Enable shims for all package managers (npm, yarn, pnpm, npx, yarnpkg, pnpx)
pm-util enable-shim
# Enable shims for specific package managers only
pm-util enable-shim npm yarn
pm-util enable-shim pnpm
```
This command creates symbolic links in your global installation directory, so when you run `npm`, `yarn`, or `pnpm`, they will automatically use the `@rnm/pm` detection logic.
**â ïļ Warning**: This will override your existing global package manager commands. Use with caution and ensure you understand the implications.
## Differences from Corepack
1. **Field Detection**: `@rnm/pm` detects `packageManager`, `devEngines`, and `engines` fields in `package.json`, while Corepack only supports `packageManager` and `devEngines`.
2. **Lock File Detection**: `@rnm/pm` automatically detects lock files (`package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`) to determine the package manager, while Corepack does not.
3. **Version Range Support**: `@rnm/pm` supports version ranges (e.g., `^10.0.0`) in `packageManager` and `devEngines.packageManager.version` fields, while Corepack only accepts specific versions.
4. **Environment Variables**: `@rnm/pm` ignores `COREPACK_*` environment variables for non-configurable behavior, while Corepack respects them.
5. **Configuration Files**: `@rnm/pm` ignores `.corepack.env` files, while Corepack reads them for configuration.
6. **Registry Configuration**: `@rnm/pm` uses `npm config get registry` for package installation, while Corepack uses the `COREPACK_NPM_REGISTRY` environment variable.
7. **Transparency Features**: `@rnm/pm` does not provide transparency features, unlike Corepack. See Corepack's [config.json](https://github.com/nodejs/corepack/blob/main/config.json) for details.
## Migration from Corepack
1. Install `@rnm/pm` globally using `npm install -g @rnm/pm`.
2. Replace `npm`, `yarn`, and `pnpm` with `pm` in your projects.
## Show your support
Give a âïļ if this project helped you!
## License
MIT