ni
npm i
in a yarn project, again? F**k!
ni - use the right package manager
npm i -g @antfu/ni
npm · yarn · pnpm · bun
ni
- install
ni
ni vite
ni @types/node -D
ni --frozen
ni -g eslint
nr
- run
nr dev --port=3000
nr
nr -
nlx
- download & execute
nlx vitest
nu
- upgrade
nu
nu -i
nun
- uninstall
nun webpack
nun -g silent
nci
- clean install
nci
if the corresponding node manager is not present, this command will install it globally along the way.
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
export NI_CONFIG_FILE="$HOME/.config/ni/nirc"
How?
ni assumes that you work with lockfiles (and you should)
Before it runs, it will detect your yarn.lock
/ pnpm-lock.yaml
/ package-lock.json
/ bun.lockb
to know current package manager (or packageManager
field in your packages.json if specified), and runs the corresponding commands.
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
and nix
is no longer available
We renamed nx
/nix
to nlx
to avoid conflicts with the other existing tools - nx and nix. You can always alias them back on your shell configuration file (.zshrc
, .bashrc
, etc).
alias nx="nlx"
alias nix="nlx"