{"id":13440479,"url":"https://github.com/antfu-collective/ni","last_synced_at":"2026-03-06T12:01:41.750Z","repository":{"id":37426311,"uuid":"310226997","full_name":"antfu-collective/ni","owner":"antfu-collective","description":"💡 Use the right package manager","archived":false,"fork":false,"pushed_at":"2026-01-14T05:36:49.000Z","size":1083,"stargazers_count":8062,"open_issues_count":29,"forks_count":258,"subscribers_count":17,"default_branch":"main","last_synced_at":"2026-02-24T15:36:30.782Z","etag":null,"topics":["cli","npm","package-manager","pnpm","yarn"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/antfu-collective.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["antfu"]}},"created_at":"2020-11-05T07:56:23.000Z","updated_at":"2026-02-24T07:03:37.000Z","dependencies_parsed_at":"2024-02-09T02:10:33.131Z","dependency_job_id":"452de0a8-a31b-40e8-a7a8-fdfbb2534828","html_url":"https://github.com/antfu-collective/ni","commit_stats":{"total_commits":292,"total_committers":67,"mean_commits":4.358208955223881,"dds":0.3047945205479452,"last_synced_commit":"df87e8407f9cf409d5d5e7d785fa4ed354ab5025"},"previous_names":["antfu-collective/ni","antfu/ni"],"tags_count":104,"template":false,"template_full_name":null,"purl":"pkg:github/antfu-collective/ni","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antfu-collective%2Fni","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antfu-collective%2Fni/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antfu-collective%2Fni/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antfu-collective%2Fni/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/antfu-collective","download_url":"https://codeload.github.com/antfu-collective/ni/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antfu-collective%2Fni/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29987726,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-01T22:42:38.399Z","status":"ssl_error","status_checked_at":"2026-03-01T22:41:51.863Z","response_time":124,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","npm","package-manager","pnpm","yarn"],"created_at":"2024-07-31T03:01:23.131Z","updated_at":"2026-03-06T12:01:41.711Z","avatar_url":"https://github.com/antfu-collective.png","language":"TypeScript","funding_links":["https://github.com/sponsors/antfu"],"categories":["HarmonyOS","TypeScript","cli","前端"],"sub_categories":["Windows Manager","文本处理"],"readme":"# ni\n\n~~*`npm i` in a yarn project, again? F\\*\\*k!*~~\n\n**ni** - use the right package manager\n\n\u003cbr\u003e\n\n```\nnpm i -g @antfu/ni\n```\n\n### Homebrew (macOS, Linux)\n\n```\nbrew install ni\n```\n\n\u003ca href='https://docs.npmjs.com/cli/v6/commands/npm'\u003enpm\u003c/a\u003e · \u003ca href='https://yarnpkg.com'\u003eyarn\u003c/a\u003e · \u003ca href='https://pnpm.io/'\u003epnpm\u003c/a\u003e · \u003ca href='https://bun.sh/'\u003ebun\u003c/a\u003e · \u003ca href='https://deno.land/'\u003edeno\u003c/a\u003e\n\n\u003cbr\u003e\n\n### `ni` - install\n\n```bash\nni\n\n# npm install\n# yarn install\n# pnpm install\n# bun install\n# deno install\n```\n\n```bash\nni vite\n\n# npm i vite\n# yarn add vite\n# pnpm add vite\n# bun add vite\n# deno add vite\n```\n\n```bash\nni @types/node -D\n\n# npm i @types/node -D\n# yarn add @types/node -D\n# pnpm add -D @types/node\n# bun add -d @types/node\n# deno add -D @types/node\n```\n\n```bash\nni -P\n\n# npm i --omit=dev\n# yarn install --production\n# pnpm i --production\n# bun install --production\n# (deno not supported)\n```\n\n```bash\nni --frozen\n\n# npm ci\n# yarn install --frozen-lockfile (Yarn 1)\n# yarn install --immutable (Yarn Berry)\n# pnpm install --frozen-lockfile\n# bun install --frozen-lockfile\n# deno install --frozen\n```\n\n```bash\nni -g eslint\n\n# npm i -g eslint\n# yarn global add eslint (Yarn 1)\n# pnpm add -g eslint\n# bun add -g eslint\n# deno install eslint\n\n# this uses default agent, regardless your current working directory\n```\n\n```bash\nni -i\n\n# interactively select the dependency to install\n# search for packages by name\n```\n\n\u003cbr\u003e\n\n### `nr` - run\n\n```bash\nnr dev --port=3000\n\n# npm run dev -- --port=3000\n# yarn run dev --port=3000\n# pnpm run dev --port=3000\n# bun run dev --port=3000\n# deno task dev --port=3000\n```\n\n```bash\nnr\n\n# interactively select the script to run\n# supports https://www.npmjs.com/package/npm-scripts-info convention\n```\n\n```bash\nnr -p\nnr -p dev\n\n# interactively select the package and script to run\n# supports https://www.npmjs.com/package/npm-scripts-info convention\n```\n\n```bash\nnr -\n\n# rerun the last command\n```\n\n```bash\n# Add completion script for bash\nnr --completion-bash \u003e\u003e ~/.bashrc\n\n# Add completion script for zsh\n# For zim:fw\nmkdir -p ~/.zim/custom/ni-completions\nnr --completion-zsh \u003e ~/.zim/custom/ni-completions/_ni\necho \"zmodule $HOME/.zim/custom/ni-completions --fpath .\" \u003e\u003e ~/.zimrc\nzimfw install\n\n# Add completion script for fish\nmkdir -p ~/.config/fish/completions\nnr --completion-fish \u003e ~/.config/fish/completions/nr.fish\n```\n\n\u003cbr\u003e\n\n### `nlx` - download \u0026 execute\n\n```bash\nnlx vitest\n\n# npx vitest\n# yarn dlx vitest\n# pnpm dlx vitest\n# bunx vitest\n# deno run npm:vitest\n```\n\n\u003cbr\u003e\n\n### `nup` - upgrade\n\n```bash\nnup\n\n# npm upgrade\n# yarn upgrade (Yarn 1)\n# yarn up (Yarn Berry)\n# pnpm update\n# bun update\n# deno upgrade\n```\n\n```bash\nnup -i\n\n# (not available for npm)\n# yarn upgrade-interactive (Yarn 1)\n# yarn up -i (Yarn Berry)\n# pnpm update -i\n# bun update -i\n# deno outdated -u -i\n```\n\n\u003cbr\u003e\n\n### `nun` - uninstall\n\n```bash\nnun webpack\n\n# npm uninstall webpack\n# yarn remove webpack\n# pnpm remove webpack\n# bun remove webpack\n# deno remove webpack\n```\n\n```bash\nnun\n\n# interactively multi-select\n# the dependencies to remove\n```\n\n```bash\nnun -g silent\n\n# npm uninstall -g silent\n# yarn global remove silent\n# pnpm remove -g silent\n# bun remove -g silent\n# deno uninstall -g silent\n```\n\n\u003cbr\u003e\n\n### `nci` - clean install\n\n```bash\nnci\n\n# npm ci\n# yarn install --frozen-lockfile\n# pnpm install --frozen-lockfile\n# bun install --frozen-lockfile\n# deno cache --reload\n```\n\n\u003cbr\u003e\n\n### `nd` - dedupe dependencies\n\n```bash\nnd\n\n# npm dedupe\n# yarn dedupe\n# pnpm dedupe\n```\n\n\u003cbr\u003e\n\n### `na` - agent alias\n\n```bash\nna\n\n# npm\n# yarn\n# pnpm\n# bun\n# deno\n```\n\n```bash\nna run foo\n\n# npm run foo\n# yarn run foo\n# pnpm run foo\n# bun run foo\n# deno task foo\n```\n\n\u003cbr\u003e\n\n### Global Flags\n\n```bash\n# ?               | Print the command execution depends on the agent\nni vite ?\n\n# -C              | Change directory before running the command\nni -C packages/foo vite\nnr -C playground dev\n\n# -v, --version   | Show version number\nni -v\n\n# -h, --help      | Show help\nni -h\n```\n\n\u003cbr\u003e\n\n### Config\n\n```ini\n; ~/.nirc\n\n; fallback when no lock found\ndefaultAgent=npm # default \"prompt\"\n\n; for global installs\nglobalAgent=npm\n\n; use node --run instead of package manager run command (requires Node.js 22+)\nrunAgent=node\n\n; prefix commands with sfw\nuseSfw=true\n```\n\n```bash\n# ~/.bashrc\n\n# custom configuration file path\nexport NI_CONFIG_FILE=\"$HOME/.config/ni/nirc\"\n\n# environment variables have higher priority than config file if presented\nexport NI_DEFAULT_AGENT=\"npm\" # default \"prompt\"\nexport NI_GLOBAL_AGENT=\"npm\"\nexport NI_USE_SFW=\"true\"\n```\n\n```ps\n# for Windows\n\n# custom configuration file path in PowerShell accessible within the `$profile` path\n$Env:NI_CONFIG_FILE = 'C:\\to\\your\\config\\location'\n```\n\n\u003cbr\u003e\n\n### Automatic installation\n\nYou can set `NI_AUTO_INSTALL=true` to enable automatic installation.\n\nIf the corresponding package manager (**npm**, **yarn**, **pnpm**, **bun**, or **deno**) is not installed, it will install it globally before running the command.\n\n### Integrations\n\n#### asdf\n\nYou can also install ni via the [3rd-party asdf-plugin](https://github.com/CanRau/asdf-ni.git) maintained by [CanRau](https://github.com/CanRau)\n\n```bash\n# first add the plugin\nasdf plugin add ni https://github.com/CanRau/asdf-ni.git\n\n# then install the latest version\nasdf install ni latest\n\n# and make it globally available\nasdf global ni latest\n```\n\n### How?\n\n**ni** assumes that you work with lock-files (and you should).\n\nBefore `ni` runs the command, it detects your `yarn.lock` / `pnpm-lock.yaml` / `package-lock.json` / `bun.lock` / `bun.lockb` / `deno.json` / `deno.jsonc` to know the current package manager (or `packageManager` field in your packages.json if specified) using the [package-manager-detector](https://github.com/antfu-collective/package-manager-detector) package and then runs the corresponding [package-manager-detector command](https://github.com/antfu-collective/package-manager-detector/blob/main/src/commands.ts).\n\n### Trouble shooting\n\n#### Conflicts with PowerShell\n\nPowerShell 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:\n\n```PowerShell\n'Remove-Item Alias:ni -Force -ErrorAction Ignore'\n```\n\nIf 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\n\n- PowerShell 5 (Windows PowerShell): `C:\\Users\\USERNAME\\Documents\\WindowsPowerShell\\Microsoft.PowerShell_profile.ps1`\n- PowerShell 7: `C:\\Users\\USERNAME\\Documents\\PowerShell\\Microsoft.PowerShell_profile.ps1`\n- VSCode: `C:\\Users\\USERNAME\\Documents\\PowerShell\\Microsoft.VSCode_profile.ps1`\n\nYou can use the following script to remove the alias at shell start by adding the above command to your profile:\n\n```PowerShell\nif (-not (Test-Path $profile)) {\n  New-Item -ItemType File -Path (Split-Path $profile) -Force -Name (Split-Path $profile -Leaf)\n}\n\n$profileEntry = 'Remove-Item Alias:ni -Force -ErrorAction Ignore'\n$profileContent = Get-Content $profile\nif ($profileContent -notcontains $profileEntry) {\n  (\"`n\" + $profileEntry) | Out-File $profile -Append -Force -Encoding UTF8\n}\n```\n\n#### `nx`, `nix` and `nu` are no longer available\n\nWe renamed `nx`/`nix` and `nu` to `nlx` and `nup` to avoid conflicts with the other existing tools - [nx](https://nx.dev/), [nix](https://nixos.org/) and [nushell](https://www.nushell.sh/). You can always alias them back on your shell configuration file (`.zshrc`, `.bashrc`, etc).\n\n```bash\nalias nx=\"nlx\"\n# or\nalias nix=\"nlx\"\n# or\nalias nu=\"nup\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantfu-collective%2Fni","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantfu-collective%2Fni","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantfu-collective%2Fni/lists"}