简介
nnrm 即 new nrm。
GitHub: github.com/YunYouJun/n…
nnrm - 一个极简的 npm/yarn registry 切换管理器 | V2EX
一个简单的 npm/yarn registry (镜像源)切换工具
Why new nrm - nnrm?
首先,我赞成重复造轮子是不好的行为。
nrm 的确使得切换更加方便,譬如我们可以简单地使用 nrm use taobao 的方式切换镜像。
但是在切换镜像前,安装 nrm 本身也是一件很慢的事情,nrm 依赖了已 deprecated 的且包体较大的 request,npm 包,以及一些其他依赖。
而我自身至今使用过的实际只有 nrm ls 与 nrm use 命令而已。(偶尔可能尝试一下 nrm test 进行测速)。当然它现在也支持了自定义源的操作。
此外因为经常需要在不同的机器上操作,所以我希望它足够简洁,安装迅速,并且我不想总是看到依赖的包已 deprecated 的提示(强迫症?)。这便是它诞生的原因。
nnrm
English Docs | 中文文档
nnrm = new nrm
新的 npm 源管理器。
相比 nrm 使用了更小的依赖。
安装
# install
npm install -g nnrm
yarn global add nnrm
pnpm add -g nnrm
使用
以下命令是用来切换对应的包管理工具的源。
nnrm&nrm: npmnyrm&yrm: yarnprm: pnpm
nnrm ls
# nrm ls
# yrm ls
# prm ls
nnrm use taobao
# nrm use taobao
# yrm use taobao
# prm use taobao
# 设置本地的 `.npmrc`
nrm use taobao -l
nnrm test
# nrm test
# yrm test
# prm test
nnrm -h: 显示帮助信息
Usage:
$ nrm <command> [options]
Commands:
ls List all the registries
use [registry] Change registry
test Show response time for all registries
add <registry> <url> [home] Add a custom registry
remove <registry> Remove a custom registry
Options:
-h, --help Display this message
-v, --version Display version number
Usage:
$ nrm use [registry]
Options:
-l, --local set '.npmrc' for local
添加/删除自定义源
# 添加自定义源
nnrm add example https://xxx.com
# 移除自定义源
nrm remove example
它将会被记录在你的 ~/.nnrm/registries.json。
默认源
- npm -------- registry.npmjs.org/
- yarn ------- registry.yarnpkg.com/
- taobao ----- registry.npmmirror.com/ (淘宝已将
npm.taobao.org重定向至npmmirror.com) - tencent ---- mirrors.cloud.tencent.com/npm/
- npmMirror -- skimdb.npmjs.com/registry/
- github ----- npm.pkg.github.com/
Features
nnrm 相比 nrm 的改进之处:
- 支持 yarn (yarn 与 npm 的 registry 是互相独立的,
pnpm则与 npm 相同) - 极小的依赖
- 使用
node-fetch(289B) 替代request(184.8KB) 进行测速 node-fetch vs axios vs request | npmtrends - 使用
execa(8.4KB) 替代npm(455.4KB) 通过终端而非 node API 实现切换 execa vs npm | npmtrends - 使用
cac(3.6KB) 替代commander(6.8KB) 实现简单的终端 cac vs commander | npmtrends
- 使用
- 异步地显示源测速结果
- 彩色的输出结果
- 每次修改后自动显示 registry 列表,并标记当前 registry
FAQ
为什么要写新的 nrm?
nrm 依赖了已经弃用的 request 和包体较大的 npm,以及其他一些依赖。
所以在没有切换镜像源时,安装 nrm 是一件很慢的事情。
为什么使用 cac?
minimist 仅仅 1.3 KB,但它只是一个参数解析工具。
我们需要一个可以自动生成帮助信息的工具。
cac(3.6KB) 相比 commander(6.8KB) 更小。并且它的名字取自我喜爱的动漫人物 C.C.
为什么使用 node-fetch?
node-fetch 大小仅仅 289B!
axios(4.6KB) 很棒,但是 node-fetch 更小。
request(184.8KB) 已经被弃用了,而且它是如此的大。
为什么使用 execa?
execa 大小仅仅 8.4KB。
安装 npm 包来使用 npm.config.set('registry', 'xxx') 的代价是十分昂贵的。
我们只需要执行本地的命令: npm config set registry xxx。
Windows 报错?
如果您是 Windows 用户,您可能需要确保你使用 bash 等类 UNIX 通用命令行(而非 CMD)。