Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

💡 Use the right package manager

License

NotificationsYou must be signed in to change notification settings

antfu-collective/ni

Repository files navigation

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 -P# npm i --omit=dev# yarn install --production# pnpm i --production# bun install --production
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
nr --completion>>~/.bashrc# add completion script to your shell (only bash supported for now)

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 agentni vite?# -C              | Change directory before running the commandni -C packages/foo vitenr -C playground dev# -v, --version   | Show version numberni -v# -h, --help      | Show helpni -h

Config

; ~/.nirc; fallback when no lock founddefaultAgent=npm# default "prompt"; for global installsglobalAgent=npm
# ~/.bashrc# custom configuration file pathexport NI_CONFIG_FILE="$HOME/.config/ni/nirc"# environment variables have higher priority than config file if presentedexport NI_DEFAULT_AGENT="npm"# default "prompt"export NI_GLOBAL_AGENT="npm"
#forWindows#customconfigurationfilepathinPowerShellaccessiblewithinthe`$profile`path$Env:NI_CONFIG_FILE='C:\to\your\config\location'

Integrations

asdf

You can also install ni via the3rd-party asdf-plugin maintained byCanRau

# first add the pluginasdf plugin add ni https://github.com/CanRau/asdf-ni.git# then install the latest versionasdf install ni latest# and make it globally availableasdf global ni latest

How?

ni assumes that you work with lock-files (and you should).

Beforeni runs the command, it detects youryarn.lock /pnpm-lock.yaml /package-lock.json /bun.lock /bun.lockb to know the current package manager (orpackageManager field in your packages.json if specified) using thepackage-manager-detector package and then runs the correspondingpackage-manager-detector command.

Trouble shooting

Conflicts with PowerShell

PowerShell comes with a built-in aliasni for theNew-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$profileif ($profileContent-notcontains$profileEntry) {  ("`n"+$profileEntry)|Out-File$profile-Append-Force-Encoding UTF8}

nx andnix is no longer available

We renamednx/nix tonlx to avoid conflicts with the other existing tools -nx andnix. You can always alias them back on your shell configuration file (.zshrc,.bashrc, etc).

alias nx="nlx"# oralias nix="nlx"

[8]ページ先頭

©2009-2025 Movatter.jp