/ni

💡 Use the right package manager by rust

Primary LanguageHTMLMIT LicenseMIT

n

💡 Inspired by ni

Choose the correct command prefix (npm, yarn, pnpm) based on the packageManager configuration in your package.json.

Why

Why do we need to do this when we already have ni 🤔️ ?

Because ni runs on the Node environment, which means that when we switch between different versions of Node using tools like fnm and nvm, we always need to globally install ni, which is not elegant.

We hope to have a tool similar to ni, but it does not depend on the Node environment, so that we can better collaborate with fnm and nvm.

Differences from ni

Our philosophy is somewhat different from ni. We are strict and require you to declare packageManager in package.json.

Installation

Using a script (macOS/Linux)

curl -fsSL https://raw.githubusercontent.com/sheinsight/ni/main/install.sh | bash

Use case

install

# Ready ✅
n i
# npm install
# yarn install
# pnpm install
# Ready ✅
n ci
# npm ci
# yarn install --frozen-lockfile (Yarn 1)
# pnpm install --frozen-lockfile

add

# Ready ✅
n add react
# npm add react
# yarn add react
# pnpm add react
# Ready ✅
n add react -D
# npm add --save-dev react
# yarn add --save-dev react
# pnpm add --save-dev react
# Ready ✅
n add react -S
# npm add --save react
# yarn add --save react
# pnpm add --save react
# Ready ✅
n add react -O
# npm add --save-optional react
# yarn add --save-optional react
# pnpm add --save-optional react
# Ready ✅
n add -g eslint

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

run

# Ready ✅
n r dev
# npm run dev
# yarn run dev
# pnpm run dev
# Ready ✅
n r dev --port=3000
# npm run dev -- --port=3000
# yarn run dev --port=3000
# pnpm run dev --port=3000
# Ready ❌
n r
# interactively select the script to run
# supports https://www.npmjs.com/package/npm-scripts-info convention

npx

# Ready ✅
n dlx tsx
# npx vitest
# yarn dlx vitest
# pnpm dlx vitest

upgrade

# Ready ✅
n u
# npm upgrade
# yarn upgrade (Yarn 1)
# pnpm update

uninstall

# Ready ✅
n un
# npm uninstall webpack
# yarn remove webpack
# pnpm remove webpack
# Ready ✅
n un -g silent

# npm uninstall -g silent
# yarn global remove silent
# pnpm remove -g silent
# Ready ✅
n set-cache /root
# npm config set cache /root
# yarn config set cache-folder /root
# pnpm config set store-dir /root