Skip to content
/ n Public

Extended fork of @antfu/ni — "use the right package manager"

License

Notifications You must be signed in to change notification settings

nberlette/n

Repository files navigation

@brlt/n

An extended fork of @antfu/ni - "use the right package manager"

Open in Gitpod Open in Stackblitz Open in CodeSandbox


pnpm  ·  yarn  ·  npm


pnpm add -g @brlt/n
yarn global add @brlt/n
npm i -g @brlt/n

Bin Links: na, nb, nci, nd, ne, nh, ni, nl, no, np, nr, nt, nu, nun, nv


This package expands upon the original ni package created by Anthony Fu, adding several new commands.

My primary motivation has been laziness, leading to more shorthand aliases to functions often used in my workflows. There are also commands that have been renamed to resolve binary naming conflicts. For example, I had some trouble with Nx workspaces for monorepo projects, since nx was occupied. So nx was renamed to ne.

You may or may not find these useful.

Disclaimer: This is very much a work in progress. I haven't had time to add any tests for the updated commands yet, and I'm sure some of them are partially (maybe even completely) broken. Please create an Issue (or multiple issues) or a Discussion, with any kind of criticism or comments you have. I could really use your help!


How does it work?

ni assumes that you work with lockfiles (and you should). See the list of commands.

Before it runs, it will detect your yarn.lock / pnpm-lock.yaml / package-lock.json to know current package manager (or packageManager field in your packages.json), and runs the corresponding commands.


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"




New Commands (unique to this fork)

As the description states, this is an extended fork of the parent project, @antfu/ni, which means it comes with several new additions to it's list of features.

Note: in the examples below, {npm,yarn,pnpm} indicates "either pnpm, yarn, or npm". {npm,pnpm} means "npm and pnpm", and so on.

nb - bin

nb
# {npm,yarn,pnpm} bin
nb -g

# npm bin --global
# yarn global bin
# pnpm -g bin

nd - diff

nd 
# {npm,yarn,pnpm} diff

nh - help

nh
# {npm,yarn,pnpm} help 

nh [topic]
# {npm,yarn,pnpm} help [topic]

Example

nh version

# {npm,yarn,pnpm} help version

nl - link

nl next

# {npm,yarn,pnpm} link next

no - outdated

no
# {npm,yarn,pnpm} outdated
no [...options]
# {npm,yarn,pnpm} outdated [...options]

Examples

no --long
# {npm,yarn,pnpm} outdated --long
no --global
# {npm,pnpm} outdated --global
# yarn global outdated

np - publish

np
# {npm,yarn,pnpm} publish
np [<tarball>|<dir>] [--tag <tag>] [--access <public|restricted>] [options]

# {npm,yarn,pnpm} publish [...arguments]

Example

np --registry=https://npm.pkg.github.com

# {npm,yarn,pnpm} publish --registry=https://npm.pkg.github.com

nt - test

Execute a package's test script, if it exists.

nt
# {npm,yarn,pnpm} test

nv - version

Without any arguments, returns a list of versions for all local dependencies.
Provided arguments, modifies (or "bumps") a package's version number according to semver guidelines.

nv
# {npm,yarn,pnpm} version
nv [arguments]
# {npm,yarn,pnpm}

Example

nv patch
# {npm,yarn,pnpm} version patch




Renamed Commands

I've made the decision to change a couple of names of existing commands, to help resolve naming conflicts I've encountered with other projects (like Nx by @nrwl).


nx ne - execute

Renamed to ne to eliminate conflict with Nx monorepo tool

ne jest

# npx jest
# {pnpm,yarn} dlx jest




Existing Commands - inherited from @antfu/ni


ni - install

Usage

ni [package] [options]
# {npm,yarn,pnpm} install [package] [options]

Examples

ni axios
ni @types/node -D

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

Options

--frozen
ni --frozen # or nci

# npm ci
# {pnpm,yarn} install --frozen-lockfile
-g, --global
ni -g iroiro

# npm i -g iroiro
# yarn global add iroiro
# pnpm add -g iroiro

# this uses default agent, regardless your current working directory
-C: run command in a different directory
ni -C packages/foo vite
nr -C playground dev

nci - clean install

nci

# npm ci
# {pnpm,yarn} install --frozen-lockfile

If the corresponding node manager is not present, this command will install it globally.


nr - run

Usage

nr [script] [options]

# {pnpm,yarn} <script> [options]
# npm run <script> [options
Interactively select a script to run
nr

Supports https://www.npmjs.com/package/npm-scripts-info convention

Re-run the last command
nr -
nr dev --port=3000

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

na - agent alias

na
# {npm,yarn,pnpm}

nu - upgrade

nu

# pnpm update
# <npm|yarn> upgrade

Examples

nu -i # interactive update

# (currently not available for npm)
# yarn upgrade-interactive
# pnpm update -i

nun - uninstall

nun axios

# npm uninstall axios
# yarn remove axios
# pnpm remove axios
nun @types/node -D

# npm uninstall @types/node -D
# yarn remove @types/node -D
# pnpm remove -D @types/node
nun -g eslint

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