@antfu/ni
TypeScript icon, indicating that this package has built-in type declarations

0.23.1 • Public • Published

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

# npm install
# yarn install
# pnpm install
# bun install
ni vite

# npm i vite
# yarn add vite
# pnpm add vite
# bun add vite
ni @types/node -D

# npm i @types/node -D
# yarn add @types/node -D
# pnpm add -D @types/node
# bun add -d @types/node
ni --frozen

# npm ci
# yarn install --frozen-lockfile (Yarn 1)
# yarn install --immutable (Yarn Berry)
# pnpm install --frozen-lockfile
# bun install --frozen-lockfile
ni -g eslint

# npm i -g eslint
# yarn global add eslint (Yarn 1)
# pnpm add -g eslint
# bun add -g eslint

# this uses default agent, regardless your current working directory
ni -i

# interactively select the dependency to install
# search for packages by name

nr - run

nr dev --port=3000

# npm run dev -- --port=3000
# yarn run dev --port=3000
# pnpm run dev --port=3000
# bun run dev --port=3000
nr

# interactively select the script to run
# supports https://www.npmjs.com/package/npm-scripts-info convention
nr -

# rerun the last command

nlx - download & execute

nlx vitest

# npx vitest
# yarn dlx vitest
# pnpm dlx vitest
# bunx vitest

nu - upgrade

nu

# npm upgrade
# yarn upgrade (Yarn 1)
# yarn up (Yarn Berry)
# pnpm update
# bun update
nu -i

# (not available for npm & bun)
# yarn upgrade-interactive (Yarn 1)
# yarn up -i (Yarn Berry)
# pnpm update -i

nun - uninstall

nun webpack

# npm uninstall webpack
# yarn remove webpack
# pnpm remove webpack
# bun remove webpack
nun

# interactively select
# the dependency to remove
nun -m

# interactive select,
# but with multiple dependencies
nun -g silent

# npm uninstall -g silent
# yarn global remove silent
# pnpm remove -g silent
# bun remove -g silent

nci - clean install

nci

# npm ci
# yarn install --frozen-lockfile
# pnpm install --frozen-lockfile
# bun install --frozen-lockfile

if the corresponding node manager is not present, this command will install it globally along the way.


na - agent alias

na

# npm
# yarn
# pnpm
# bun
na run foo

# npm run foo
# yarn run foo
# pnpm run foo
# bun run foo

Global Flags

# ?               | Print the command execution depends on the agent
ni vite ?

# -C              | Change directory before running the command
ni -C packages/foo vite
nr -C playground dev

# -v, --version   | Show version number
ni -v

# -h, --help      | Show help
ni -h

Config

; ~/.nirc

; fallback when no lock found
defaultAgent=npm # default "prompt"

; for global installs
globalAgent=npm
# ~/.bashrc

# custom configuration file path
export NI_CONFIG_FILE="$HOME/.config/ni/nirc"

# environment variables have higher priority than config file if presented
export NI_DEFAULT_AGENT="npm" # default "prompt"
export NI_GLOBAL_AGENT="npm"
# for Windows

# custom configuration file path in PowerShell accessible within the `$profile` path
$Env:NI_CONFIG_FILE = 'C:\to\your\config\location'

Integrations

asdf

You can also install ni via the 3rd-party asdf-plugin maintained by CanRau

# first add the plugin
asdf plugin add ni https://github.com/CanRau/asdf-ni.git

# then install the latest version
asdf install ni latest

# and make it globally available
asdf global ni latest

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"
# or
alias nix="nlx"

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.23.111,626latest

Version History

VersionDownloads (Last 7 Days)Published
0.23.111,626
0.23.050,930
0.22.42,773
0.22.32
0.22.21
0.22.11,381
0.22.0169
0.21.12154,149
0.21.119
0.21.10113
0.21.9176
0.21.896,756
0.21.71
0.21.6836
0.21.56,778
0.21.495,175
0.21.3112
0.21.215
0.21.12
0.21.0121
0.20.028,993
0.19.0269
0.18.8387
0.18.61
0.18.54
0.18.31
0.18.21
0.18.059
0.17.245
0.17.10
0.17.01
0.16.377
0.16.22
0.16.11
0.15.00
0.14.02
0.13.25
0.13.11
0.13.01
0.12.01
0.11.10
0.11.02
0.10.20
0.10.11
0.10.00
0.9.33
0.9.21
0.9.02
0.8.10
0.8.01
0.7.034
0.6.11
0.6.00
0.5.92
0.5.81
0.5.71
0.5.61
0.5.50
0.5.40
0.5.31
0.5.21
0.5.12
0.5.01
0.4.10
0.4.00
0.3.01
0.2.31
0.2.21
0.2.10
0.2.01
0.1.40
0.1.30
0.1.21
0.1.10
0.1.00
0.0.11

Package Sidebar

Install

npm i @antfu/ni

Weekly Downloads

451,037

Version

0.23.1

License

MIT

Unpacked Size

376 kB

Total Files

56

Last publish

Collaborators

  • antfu