Giter VIP home page Giter VIP 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

<a href='https://docs.npmjs.com/cli/v6/comm // 获取用户设置的配置文件路径 const customRcPath = process.env.NI_CONFIG_FILE

// 获取当前操作系统的用户目录 const home = process.platform === 'win const yarn = { // 安装yarn代理 'agent': 'yarn {0}', // 运行yarn命令 'run': 'yarn run {0}', // 安装yarn命令 'install': 'yarn install {0}', // 锁定yarn安装 'frozen': 'yarn install --frozen-lockfile', // 全局安装yarn 'global': 'yarn global add {0}', // 添加yarn 'add': 'yarn add {0}', // 升级yarn 'upgrade': 'yarn upgrade {0}', // 交互式升级yarn 'upgrade-interactive': 'yarn upgrade-interactive {0}', // 执行npx命令 'execute': 'npx {0}', // 卸载yarn 'uninstall': 'yarn remove {0}', // 全局卸载yarn 'global_uninstall': 'yarn global remove {0}', } -D

pnpm add -D @types/node

bun add -d @types/node


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

# npm upgrade
# yarn upgrade (Yarn 1)
# yarn up (Yarn Berry)
# pnpm update
# bun 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

Global Flags

# ?               | Print the command execution depends on the agent
ni vite ?

# -C              | Change directory before running the command
ni -C packages/foo vite
nr -C playground dev

# -v, --version   | Show version number
ni -v

# -h, --help      | Show help
ni -h

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"
# for Windows

# custom configuration file path in PowerShell accessible within the `$profile` path
$Env:NI_CONFIG_FILE = 'C:\to\your\config\location'

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) {
  ("`n" + $profileEntry) | Out-File $profile -Append -Force -Encoding UTF8
}

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

adaex avatar amir20 avatar antfu avatar antongolub avatar cawa-93 avatar colinhacks avatar dimava avatar dunqing avatar eggsy avatar flower-f avatar frankfang avatar fritx avatar ghengeveld avatar hannoeru avatar hawtinzeng avatar itpropro avatar jatindotdev avatar joaosamouco avatar jordienr avatar juckz avatar kirklin avatar liby avatar morrislaptop avatar ouduidui avatar posva avatar privatenumber avatar smallnine9 avatar smallteddy avatar sxzz avatar zeko369 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.