You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

@antfu/ni

Package Overview
Dependencies
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@antfu/ni

Use the right package manager


Version published
Weekly downloads
335K
Maintainers
1
Created
Weekly downloads
 

Package description

What is @antfu/ni?

@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.

What are @antfu/ni's main functionalities?

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

Other packages similar to @antfu/ni

Readme

Source

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 --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 - 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

nx - execute

nx vitest

# (not available for bun)
# npx vitest
# yarn dlx vitest
# pnpm dlx vitest

nu - upgrade

nu

# (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 - uninstall

nun webpack

# npm uninstall webpack
# yarn remove webpack
# pnpm remove webpack
# bun remove webpack
nun -g eslint

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

nci - clean install

nci

# 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 alias

na

# npm
# yarn
# pnpm
# bun
na run foo

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

Change Directory

ni -C packages/foo vite
nr -C playground dev

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"

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) {
  $profileEntry | Out-File $profile -Append -Force
}

FAQs

Package last updated on 29 Sep 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc