1 | # nnrm
|
2 |
|
3 | English 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
|
24 | npm install -g nnrm
|
25 | yarn global add nnrm
|
26 | pnpm add -g nnrm
|
27 | ```
|
28 |
|
29 | ## 使用
|
30 |
|
31 | 以下命令是用来切换对应的包管理工具的源。
|
32 |
|
33 | - `nnrm` & `nrm`: npm
|
34 | - `nyrm` & `yrm`: yarn
|
35 | - `prm`: pnpm
|
36 |
|
37 | ```sh
|
38 | nnrm ls
|
39 | # nrm ls
|
40 | # yrm ls
|
41 | # prm ls
|
42 |
|
43 | nnrm use taobao
|
44 | # nrm use taobao
|
45 | # yrm use taobao
|
46 | # prm use taobao
|
47 |
|
48 | # 设置本地的 `.npmrc`
|
49 | nrm use taobao -l
|
50 |
|
51 | nnrm test
|
52 | # nrm test
|
53 | # yrm test
|
54 | # prm test
|
55 | ```
|
56 |
|
57 | - `nnrm -h`: 显示帮助信息
|
58 |
|
59 | ```bash
|
60 | Usage:
|
61 | $ nrm <command> [options]
|
62 |
|
63 | Commands:
|
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 |
|
70 | Options:
|
71 | -h, --help Display this message
|
72 | -v, --version Display version number
|
73 | ```
|
74 |
|
75 | ```bash
|
76 | Usage:
|
77 | $ nrm use [registry]
|
78 |
|
79 | Options:
|
80 | -l, --local set '.npmrc' for local
|
81 | ```
|
82 |
|
83 | ### 添加/删除自定义源
|
84 |
|
85 | ```sh
|
86 | # 添加自定义源
|
87 | nnrm add example https://xxx.com
|
88 | ```
|
89 |
|
90 | ```sh
|
91 | # 移除自定义源
|
92 | nrm 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 |
|
108 | nnrm 相比 nrm 的改进之处:
|
109 |
|
110 | - 支持 yarn (yarn 与 npm 的 registry 是互相独立的,`pnpm` 则与 npm 相同)
|
111 | - 极小的依赖
|
112 | - 使用 `node-fetch` (289B) 替代 `request` (184.8KB) 进行测速 [node-fetch vs axios vs request | npmtrends](https://www.npmtrends.com/node-fetch-vs-axios-vs-request)
|
113 | - 使用 `execa` (8.4KB) 替代 `npm` (455.4KB) 通过终端而非 node API 实现切换 [execa vs npm | npmtrends](https://www.npmtrends.com/execa-vs-npm)
|
114 | - 使用 `cac` (3.6KB) 替代 `commander` (6.8KB) 实现简单的终端 [cac vs commander | npmtrends](https://www.npmtrends.com/minimist-vs-commander-vs-cac)
|
115 | - 异步地显示源测速结果
|
116 | - 彩色的输出结果
|
117 | - 每次修改后自动显示 registry 列表,并标记当前 registry
|
118 |
|
119 | ## FAQ
|
120 |
|
121 | ### 为什么要写新的 nrm?
|
122 |
|
123 | nrm 依赖了已经弃用的 `request` 和包体较大的 `npm`,以及其他一些依赖。
|
124 |
|
125 | 所以在没有切换镜像源时,安装 nrm 是一件很慢的事情。
|
126 |
|
127 | ### 为什么使用 cac?
|
128 |
|
129 | > [minimist vs commander vs cac | npm trends](https://www.npmtrends.com/minimist-vs-commander-vs-cac)
|
130 |
|
131 | [minimist](https://github.com/substack/minimist) 仅仅 1.3 KB,但它只是一个参数解析工具。
|
132 |
|
133 | 我们需要一个可以自动生成帮助信息的工具。
|
134 |
|
135 | [commander](https://github.com/tj/commander.js) 和 [cac](https://github.com/cacjs/cac) 可以做到。
|
136 |
|
137 | cac(3.6KB) 相比 commander(6.8KB) 更小。~~并且它的名字取自我喜爱的动漫人物 C.C.~~
|
138 |
|
139 | ### 为什么使用 node-fetch?
|
140 |
|
141 | > [node-fetch vs axios vs request](https://www.npmtrends.com/node-fetch-vs-axios-vs-request)
|
142 |
|
143 | [node-fetch](https://github.com/node-fetch/node-fetch) 大小仅仅 289B!
|
144 |
|
145 | [axios](https://github.com/axios/axios)(4.6KB) 很棒,但是 `node-fetch` 更小。
|
146 |
|
147 | [request](https://github.com/request/request)(184.8KB) 已经被弃用了,而且它是如此的大。
|
148 |
|
149 | ### 为什么使用 [execa](https://github.com/sindresorhus/execa)?
|
150 |
|
151 | > [execa vs shelljs](https://www.npmtrends.com/execa-vs-shelljs)
|
152 |
|
153 | [execa](https://github.com/sindresorhus/execa) 大小仅仅 8.4KB。
|
154 |
|
155 | 安装 [npm](https://www.npmjs.com/package/npm) 包来使用 `npm.config.set('registry', 'xxx')` 的代价是十分昂贵的。
|
156 |
|
157 | 我们只需要执行本地的命令: `npm config set registry xxx`。
|
158 |
|
159 | ### Windows 报错?
|
160 |
|
161 | 如果您是 Windows 用户,您可能需要确保你使用 `bash` 等类 UNIX 通用命令行(而非 CMD)。
|
162 |
|
163 | ## 参考
|
164 |
|
165 | - [npm-config | npm Docs](https://docs.npmjs.com/cli/v7/commands/npm-config)
|