ni
npm i in a yarn project, again? F**k!
ni - use the right package manager
npm i -g @antfu/ni
Homebrew (macOS)
brew install ni
npm · yarn · pnpm · bun · deno
ni - install
ni
ni vite
ni @types/node -D
ni -P
ni --frozen
ni -g eslint
ni -i
nr - run
nr dev --port=3000
nr
nr -p
nr -p dev
nr -
nr --completion-bash >> ~/.bashrc
mkdir -p ~/.zim/custom/ni-completions
nr --completion-zsh > ~/.zim/custom/ni-completions/_ni
echo "zmodule $HOME/.zim/custom/ni-completions --fpath ." >> ~/.zimrc
zimfw install
nlx - download & execute
nlx vitest
nup - upgrade
nup
nup -i
nun - uninstall
nun webpack
nun
nun -m
nun -g silent
nci - clean install
nci
nd - dedupe dependencies
nd
na - agent alias
na
na run foo
Global Flags
ni vite ?
ni -C packages/foo vite
nr -C playground dev
ni -v
ni -h
Config
defaultAgent=npm
globalAgent=npm
runAgent=node
useSfw=true
export NI_CONFIG_FILE="$HOME/.config/ni/nirc"
export NI_DEFAULT_AGENT="npm"
export NI_GLOBAL_AGENT="npm"
export NI_USE_SFW="true"
# for Windows
# custom configuration file path in PowerShell accessible within the `$profile` path
$Env:NI_CONFIG_FILE = 'C:\to\your\config\location'
Automatic installation
Before executing any command (ni, nr, nlx, etc.), ni detects your active package manager.
If the corresponding package manager (npm, yarn, pnpm, bun, or deno) is not installed, it will install it globally before running the command.
Integrations
asdf
You can also install ni via the 3rd-party asdf-plugin maintained by CanRau
asdf plugin add ni https://github.com/CanRau/asdf-ni.git
asdf install ni latest
asdf global ni latest
How?
ni assumes that you work with lock-files (and you should).
Before ni runs the command, it detects your yarn.lock / pnpm-lock.yaml / package-lock.json / bun.lock / bun.lockb / deno.json / deno.jsonc to know the current package manager (or packageManager field in your packages.json if specified) using the package-manager-detector package and then runs the corresponding package-manager-detector command.
Trouble shooting
Conflicts with PowerShell
PowerShell comes with a built-in alias ni for the New-Item cmdlet. To remove the alias in your current PowerShell session in favor of this package, use the following command:
'Remove-Item Alias:ni -Force -ErrorAction Ignore'
If you want to persist the changes, you can add them to your PowerShell profile. The profile path is accessible within the $profile variable. The ps1 profile file can normally be found at
- PowerShell 5 (Windows PowerShell):
C:\Users\USERNAME\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
- PowerShell 7:
C:\Users\USERNAME\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
- VSCode:
C:\Users\USERNAME\Documents\PowerShell\Microsoft.VSCode_profile.ps1
You can use the following script to remove the alias at shell start by adding the above command to your profile:
if (-not (Test-Path $profile)) {
New-Item -ItemType File -Path (Split-Path $profile) -Force -Name (Split-Path $profile -Leaf)
}
$profileEntry = 'Remove-Item Alias:ni -Force -ErrorAction Ignore'
$profileContent = Get-Content $profile
if ($profileContent -notcontains $profileEntry) {
("`n" + $profileEntry) | Out-File $profile -Append -Force -Encoding UTF8
}
nx, nix and nu are no longer available
We renamed nx/nix and nu to nlx and nup to avoid conflicts with the other existing tools - nx, nix and nushell. You can always alias them back on your shell configuration file (.zshrc, .bashrc, etc).
alias nx="nlx"
alias nix="nlx"
alias nu="nup"