Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
@antfu/ni is a command-line tool that provides a unified interface for package managers like npm, yarn, and pnpm. It simplifies the process of managing dependencies by automatically detecting the package manager used in a project and running the appropriate commands.
Install Dependencies
The `ni` command installs dependencies in the current project. It automatically detects the package manager used (npm, yarn, or pnpm) and runs the corresponding install command.
ni
Add a Dependency
The `ni <package>` command adds a new dependency to the project. It detects the package manager and runs the appropriate command to add the specified package.
ni axios
Remove a Dependency
The `nr <package>` command removes a dependency from the project. It detects the package manager and runs the appropriate command to remove the specified package.
nr axios
Upgrade Dependencies
The `nu` command upgrades all dependencies in the project. It detects the package manager and runs the appropriate command to upgrade the dependencies.
nu
Run Scripts
The `ni run <script>` command runs a script defined in the project's package.json file. It detects the package manager and runs the appropriate command to execute the script.
ni run build
npm is the default package manager for Node.js. It provides a wide range of commands for managing dependencies, running scripts, and more. Unlike @antfu/ni, npm does not automatically detect other package managers.
Yarn is a fast, reliable, and secure dependency management tool. It offers similar functionalities to npm but with a focus on speed and reliability. Yarn does not provide a unified interface for other package managers like @antfu/ni.
pnpm is a fast, disk space-efficient package manager. It uses a unique symlink-based approach to manage dependencies. Like npm and yarn, pnpm does not offer a unified interface for other package managers.
npm i
in a yarn project, again? F**k!
ni - use the right package manager
npm i -g @antfu/ni
ni
- installni
# 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 --no-save
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
nr
- runnr 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
nx
- executenx vitest
# (not available for bun)
# npx vitest
# yarn dlx vitest
# pnpm dlx vitest
nu
- upgradenu
# (not available for bun)
# npm upgrade
# yarn upgrade (Yarn 1)
# yarn up (Yarn Berry)
# pnpm update
nu -i
# (not available for npm & bun)
# yarn upgrade-interactive (Yarn 1)
# yarn up -i (Yarn Berry)
# pnpm update -i
nun
- uninstallnun webpack
# npm uninstall webpack
# yarn remove webpack
# pnpm remove webpack
# bun remove webpack
nun -g silent
# npm uninstall -g silent
# yarn global remove silent
# pnpm remove -g silent
# bun remove -g silent
nci
- clean installnci
# npm ci
# yarn install --frozen-lockfile
# pnpm install --frozen-lockfile
# bun install --no-save
if the corresponding node manager is not present, this command will install it globally along the way.
na
- agent aliasna
# npm
# yarn
# pnpm
# bun
na run foo
# npm run foo
# yarn run foo
# pnpm run foo
# bun run foo
ni -C packages/foo vite
nr -C playground dev
; ~/.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"
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.
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
C:\Users\USERNAME\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
C:\Users\USERNAME\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
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) {
$profileEntry | Out-File $profile -Append -Force
}
FAQs
Use the right package manager
The npm package @antfu/ni receives a total of 339,669 weekly downloads. As such, @antfu/ni popularity was classified as popular.
We found that @antfu/ni demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.