UNPKG

5.12 kBMarkdownView Raw
1# nnrm
2
3English Docs | [中文文档](./README.zh-CN.md)
4
5[![npm](https://img.shields.io/npm/v/nnrm)](https://www.npmjs.com/package/nnrm)
6![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/yunyoujun/nnrm)
7[![node-current](https://img.shields.io/node/v/nnrm)](https://nodejs.dev/)
8![npm](https://img.shields.io/npm/dt/nnrm)
9![Libraries.io dependency status for latest release](https://img.shields.io/librariesio/release/npm/nnrm)
10![Snyk Vulnerabilities for npm scoped package](https://img.shields.io/snyk/vulnerabilities/npm/nnrm)
11
12> nnrm = new nrm
13
14新的 npm 源管理器。
15
16相比 [nrm](https://github.com/Pana/nrm) 使用了更小的依赖。
17
18> [由来](https://www.yunyoujun.cn/posts/nnrm-new-nrm/)
19
20## 安装
21
22```sh
23# install
24npm install -g nnrm
25yarn global add nnrm
26pnpm add -g nnrm
27```
28
29## 使用
30
31以下命令是用来切换对应的包管理工具的源。
32
33- `nnrm` & `nrm`: npm
34- `nyrm` & `yrm`: yarn(v1-v3)
35- `prm`: pnpm
36
37```sh
38nnrm ls
39# nrm ls
40# yrm ls
41# prm ls
42
43nnrm use taobao
44# nrm use taobao
45# yrm use taobao
46# prm use taobao
47
48# 设置本地的 `.npmrc`
49nrm use taobao -l
50
51nnrm test
52# nrm test
53# yrm test
54# prm test
55```
56
57- `nnrm -h`: 显示帮助信息
58
59```bash
60Usage:
61 $ nrm <command> [options]
62
63Commands:
64 ls List all the registries
65 use [registry] Change registry
66 test Show response time for all registries
67 add <registry> <url> [home] Add a custom registry
68 remove <registry> Remove a custom registry
69
70Options:
71 -h, --help Display this message
72 -v, --version Display version number
73```
74
75```bash
76Usage:
77 $ nrm use [registry]
78
79Options:
80 -l, --local set '.npmrc' for local
81```
82
83### 添加/删除自定义源
84
85```sh
86# 添加自定义源
87nnrm add example https://xxx.com
88```
89
90```sh
91# 移除自定义源
92nrm remove example
93```
94
95它将会被记录在你的 `~/.nnrm/registries.json`
96
97### 默认源
98
99- npm -------- <https://registry.npmjs.org/>
100- yarn ------- <https://registry.yarnpkg.com/>
101- taobao ----- <https://registry.npmmirror.com/> (淘宝已将 `npm.taobao.org` 重定向至 `npmmirror.com`
102- tencent ---- <https://mirrors.cloud.tencent.com/npm/>
103- npmMirror -- <https://skimdb.npmjs.com/registry/>
104- github ----- <https://npm.pkg.github.com/>
105
106## Features
107
108nnrm 相比 nrm 的改进之处:
109
110- 支持 yarn(v1-v3) (yarn 与 npm 的 registry 是互相独立的,`pnpm` 则与 npm 相同)
111 - `yarn(v3)` 的配置字段使用 `npmRegistryServer` 替代了 `registry`
112- 极小的依赖
113 - 使用 `node-fetch` (289B) 替代 `request` (184.8KB) 进行测速 [node-fetch vs axios vs request | npmtrends](https://www.npmtrends.com/node-fetch-vs-axios-vs-request)
114 - 使用 `execa` (8.4KB) 替代 `npm` (455.4KB) 通过终端而非 node API 实现切换 [execa vs npm | npmtrends](https://www.npmtrends.com/execa-vs-npm)
115 - 使用 `cac` (3.6KB) 替代 `commander` (6.8KB) 实现简单的终端 [cac vs commander | npmtrends](https://www.npmtrends.com/minimist-vs-commander-vs-cac)
116- 异步地显示源测速结果
117- 彩色的输出结果
118- 每次修改后自动显示 registry 列表,并标记当前 registry
119
120## FAQ
121
122### 为什么要写新的 nrm?
123
124nrm 依赖了已经弃用的 `request` 和包体较大的 `npm`,以及其他一些依赖。
125
126所以在没有切换镜像源时,安装 nrm 是一件很慢的事情。
127
128### 为什么使用 cac?
129
130> [minimist vs commander vs cac | npm trends](https://www.npmtrends.com/minimist-vs-commander-vs-cac)
131
132[minimist](https://github.com/substack/minimist) 仅仅 1.3 KB,但它只是一个参数解析工具。
133
134我们需要一个可以自动生成帮助信息的工具。
135
136[commander](https://github.com/tj/commander.js) 和 [cac](https://github.com/cacjs/cac) 可以做到。
137
138cac(3.6KB) 相比 commander(6.8KB) 更小。~~并且它的名字取自我喜爱的动漫人物 C.C.~~
139
140### 为什么使用 node-fetch?
141
142> [node-fetch vs axios vs request](https://www.npmtrends.com/node-fetch-vs-axios-vs-request)
143
144[node-fetch](https://github.com/node-fetch/node-fetch) 大小仅仅 289B!
145
146[axios](https://github.com/axios/axios)(4.6KB) 很棒,但是 `node-fetch` 更小。
147
148[request](https://github.com/request/request)(184.8KB) 已经被弃用了,而且它是如此的大。
149
150### 为什么使用 [execa](https://github.com/sindresorhus/execa)?
151
152> [execa vs shelljs](https://www.npmtrends.com/execa-vs-shelljs)
153
154[execa](https://github.com/sindresorhus/execa) 大小仅仅 8.4KB。
155
156安装 [npm](https://www.npmjs.com/package/npm) 包来使用 `npm.config.set('registry', 'xxx')` 的代价是十分昂贵的。
157
158我们只需要执行本地的命令: `npm config set registry xxx`
159
160### Windows 报错?
161
162如果您是 Windows 用户,您可能需要确保你使用 `bash` 等类 UNIX 通用命令行(而非 CMD)。
163
164## 参考
165
166- [npm-config | npm Docs](https://docs.npmjs.com/cli/v7/commands/npm-config)
167
168## [赞助者](https://sponsors.yunyoujun.cn)
169
170<p align="center">
171 <a href="https://sponsors.yunyoujun.cn">
172 <img src='https://cdn.jsdelivr.net/gh/YunYouJun/sponsors/public/sponsors.svg'/>
173 </a>
174</p>