Repo of the Day
antfu-collective/ni
Published: Oct 13, 2021
Open repository ↗Use the right package manager depending on what lock file is present
Summary
ni is a small TypeScript CLI, published as @antfu/ni under the MIT license, that detects which JavaScript package manager a project uses and runs the matching install, run, upgrade, uninstall, or dedupe command for you. Instead of remembering whether a repo wants npm, yarn, pnpm, bun, deno, nub, or aube, you run one short command and it picks the right one based on the lockfile or the packageManager field in package.json.
What it is useful for
It removes the mental overhead of switching package managers across projects. When you clone a pnpm-lock.yaml repo after working in a package-lock.json one all day, you do not have to retype commands or guess which installer the team uses. It also normalizes less common workflows like pnpm update -i or yarn dedupe under one consistent interface (nup -i, nd), so you do not have to look up the right flag for each tool. For monorepos using pnpm, Yarn Berry, or Bun catalogs, ni automatically writes catalog: references into package.json instead of pinning a version, which keeps version upgrades centralized in the workspace config.
How engineers can use it
Install it globally and use the subcommands in place of the package manager's own commands:
npm i -g @antfu/ni
ni # install (detects lockfile)
ni vite # add a dependency
ni -D @types/node # add as devDependency
ni --frozen # ci-style install from lockfile
nr dev # run a script from package.json
nlx vitest # download and run a one-off binary
nup # upgrade dependencies
nun webpack # uninstall a package
nci # clean install
nd # dedupe
Add ? after any command (for example ni vite ?) to print which underlying command would run, without executing it. Configuration lives in ~/.nirc or environment variables such as NI_DEFAULT_AGENT, NI_GLOBAL_AGENT, and NI_CATALOG, which can be set to false to disable catalog mode or existing to only reuse packages already declared in a catalog. On Windows PowerShell, the built-in ni alias for New-Item shadows this tool, and the README documents how to remove the alias from your profile.
The README also notes that earlier commands nx, nix, and nu were renamed to nlx and nup to avoid clashing with nx, nix, and nushell, and suggests shell aliases if you prefer the old names.