Giter Site home page Giter Site logo

ni's Introduction

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

nlx - download & execute

nlx vitest

# npx vitest
# yarn dlx vitest
# pnpm dlx vitest
# bunx 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 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 --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
}

nx and nix is no longer available

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

alias nx="nlx"
# or
alias nix="nlx"

ni's People

Contributors

antfu avatar privatenumber avatar sxzz avatar hannoeru avatar eggsy avatar zeko369 avatar itpropro avatar kirklin avatar adaex avatar smallnine9 avatar cawa-93 avatar amir20 avatar antongolub avatar liby avatar morrislaptop avatar ouduidui avatar posva avatar flower-f avatar fritx avatar jordienr avatar joaosamouco avatar kidonng avatar muxiu1997 avatar nico-bachner avatar wobsoriano avatar simon-he95 avatar thelastzombie avatar vltansky avatar wladpaiva avatar wxh16144 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.