LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

ni

Uses the right package manager automatically

TLDR

Install all dependencies for the current project
$ ni
copy
Add a package (dev dependency)
$ ni [package-name] -D
copy
Add a package globally
$ ni -g [package-name]
copy
Clean install from lockfile (equivalent to npm ci / pnpm install --frozen-lockfile)
$ nci
copy
Run a script, passing arguments through
$ nr [script] [args...]
copy
Execute a package without installing (npx / pnpm dlx equivalent)
$ nlx [package] [args...]
copy
Uninstall a package
$ nun [package-name]
copy
Upgrade dependencies interactively
$ nup -i
copy

SYNOPSIS

ni [options] [packages...]nr [script] [args...]nlx package [args...]nun package...nup [options]ncina args...

DESCRIPTION

ni is a small command-line utility by Anthony Fu that dispatches package-manager commands to whichever package manager the current project uses: npm, yarn, pnpm, bun, or deno. The package manager is detected by looking at the lockfile in the project root (package-lock.json, yarn.lock, pnpm-lock.yaml, bun.lock, bun.lockb, deno.json) or the packageManager field of package.json.Users type the same short commands regardless of project. ni installs dependencies, nr runs scripts, nlx executes a one-off package, nun removes packages, nup upgrades them, nci performs a clean install, and na passes arbitrary arguments straight through to the detected agent.Interactive menus are available when fzf is on the PATH: nr without arguments lists scripts, ni -i picks packages, and nr - reruns the previous script.

PARAMETERS

-D

Add as a development dependency (maps to --save-dev / -D).
-P
Production-only install (prunes dev dependencies).
-g
Operate on globally installed packages.
-i
Interactive mode (select packages or scripts via fzf).
--frozen
Install with a frozen lockfile (no updates).
-C DIR
Run as if invoked from directory DIR.
?
Show the translated command for the detected agent without running it.
-v, --version
Print the ni version.
-h, --help
Display help.

CONFIGURATION

User configuration lives in ~/.nirc:

$ defaultAgent=npm
globalAgent=npm
copy
- defaultAgent selects the package manager when no lockfile is detected (set to prompt to be asked interactively).- globalAgent selects the manager used for global installs.Environment variables NI_DEFAULT_AGENT, NI_GLOBAL_AGENT, NI_CONFIG_FILE, and NI_AUTO_INSTALL override these settings per shell.

CAVEATS

On Windows PowerShell, the built-in ni alias for New-Item collides with this tool; remove it with Remove-Item Alias:ni -Force before using. A few legacy aliases have been renamed to avoid conflicts with other tools: nx/nix are now nlx, and nu is now nup. Because ni relies on lockfile detection, projects without any lockfile fall back to the defaultAgent.

HISTORY

Created by Anthony Fu (antfu) and first published to npm in 2021 under @antfu/ni. It was moved to the antfu-collective organization on GitHub and is distributed through npm (@antfu/ni) and Homebrew (brew install ni). The project is written in TypeScript.

SEE ALSO

npm(1), yarn(1), pnpm(1), bun(1), deno(1)

Copied to clipboard
Kai