@heroor/npmm
v0.2.0
Published
An npm / pnpm / yarn / bun command alias. Run `n <args>` or `npmm <args>`, and npmm will detect the package manager for the current project, then forward all arguments to that command.
Readme
npmm
An npm / pnpm / yarn / bun command alias. Run n <args> or npmm <args>, and npmm will detect the package manager for the current project, then forward all arguments to that command.
Features
- Supports
npm,pnpm,yarn, andbun - Provides both
nandnpmmcommand aliases - Prefers the
packageManagerfield inpackage.json - Falls back to lockfile detection when
packageManageris not set - Searches upward from the current directory, which works well in monorepo subdirectories
- Prompts for a package manager when multiple lockfiles are found
Installation
npm install -g @heroor/npmmYou can also install it globally with your preferred package manager:
pnpm add -g @heroor/npmm
yarn global add @heroor/npmm
bun install --global @heroor/npmmThe
ncommand name may conflict with other tools. If you already have anotherncommand installed, usenpmminstead.
Usage
Replace your package manager command with n inside a project:
n install
n run dev
n run build
n add react
n remove lodashYou can also use the full command name:
npmm install
npmm run devnpmm prints the command it is about to run, for example:
pnpm installThen it starts the detected package manager and forwards the original arguments.
Package Manager Detection
npmm starts from the current working directory and walks up parent directories until it finds the nearest package.json or supported lockfile.
Detection priority:
- If
package.jsonhas apackageManagerfield, npmm uses that manager. - If lockfiles point to exactly one package manager, npmm uses that manager.
- If lockfiles point to multiple package managers in an interactive terminal, npmm prompts you to choose one.
- If no project signal is found, npmm defaults to
npm.
Supported lockfiles:
| Package manager | Lockfile |
| --------------- | ------------------- |
| npm | package-lock.json |
| pnpm | pnpm-lock.yaml |
| yarn | yarn.lock |
| bun | bun.lock, bun.lockb |
For stable CI and script usage, declare the package manager in package.json:
{
"packageManager": "[email protected]"
}Non-Interactive Environments
If a project has lockfiles for multiple package managers and no packageManager field, npmm fails in non-interactive environments. Add packageManager to package.json to make CI, pre-commit hooks, and scripts deterministic.
Bun Support
Bun is supported as a package manager when a project declares packageManager: "bun@...", has bun.lock, or has the legacy bun.lockb lockfile.
npmm forwards commands to bun without translating arguments. Command and flag compatibility follows Bun's CLI behavior, so n run dev becomes bun run dev and runs through Bun.
Development
pnpm install
pnpm test
pnpm run dev
pnpm run typecheck
pnpm run buildSource files live in src/, and build output is written to dist/. The prepack script runs the build before publishing.
License
MIT
