npm registry 切换机
安装
- npm
- yarn
- pnpm
npm install nry --save
yarn add nry
pnpm add nry --save
使用
执行能力可能根据当前执行的包管理器有关,
- 使用
npm
时使用npx
调用执行 - 使用
yarn
时使用yarn dlx
调用执行 - 使用
pnpm
时使用pnpm dlx
调用执行
调用子项 | 缩写项 | 释义 |
---|---|---|
-- nry | -- | 切换 registry 源 |
-- nry add | -- nry a | 添加自定义 registry 源 |
-- nry delete | -- nry del | 删除 registry 源 |
-- nry edit | -- nry ed | 修改 registry 源 |
-- nry list | -- nry ls | 展示 registry 源 |
-- nry manage | -- nry mg | 管理 registry 源显隐 |
-- nry reset | -- nry re | 重置 registry 源 |
相应的,对应的包管理器调用执行仅用于设置本包管理器的 registry
。
示例
- npm
- yarn
- pnpm
# 简单使用
npx nry
# 简单使用
yarn dlx nry
# 简单使用
pnpm dlx nry
其效果为:
▶︎ 请选择想使用的新的 npm registry
● 官方
◦ tao bao
◦ 腾讯(当前使用)
◦ 中科大
◦ yarn
https://registry.npmjs.org
可使用键盘上下键切换项,使用 Enter
键选择要选择新 npm registry。
添加自定义项
可使用 子命令 add
添加自定义 npm registry。
- npm
- yarn
- pnpm
# 长命令使用
npx nry add
# 使用缩写
npx nry a
# 长命令使用
yarn dlx nry add
# 使用缩写
yarn dlx nry a
# 长命令使用
pnpm dlx nry add
# 使用缩写
pnpm dlx nry a
执行效果
# 先问询输入自定义 npm registry 网址
▶︎ 请输入自定义的 npm 的源地址: https://registry.npmjs.org
# 再询问输入自定义的 npm registry 别名
▶︎ 请输入自定义的 npm 的别名: 任意别名
# 展示添加的结果
当前的 npm registry 列表为
┌────────────────────────────────────┬───────────┬──────────┐
│ npm registry │ 别名 │ 当前可见 │
├────────────────────────────────────┼───────────┼──────────┤
│ * https://registry.npmjs.org │ * 官方 │ ✅ │
├────────────────────────────────────┼───────────┼──────────┤
│ https://taobao.com │ tao bao │ ✅ │
├────────────────────────────────────┼───────────┼──────────┤
│ https://mirrors.tencent.com/npm │ 腾讯 │ ✅ │
├────────────────────────────────────┼───────────┼──────────┤
│ https://npmreg.proxy.ustclug.org │ 中科大 │ ✅ │
├────────────────────────────────────┼───────────┼──────────┤
│ https://registry.yarnpkg.com │ yarn │ ✅ │
├────────────────────────────────────┼───────────┼──────────┤
│ https://earthnut.dev │ earthnut│ ✅ │
└────────────────────────────────────┴───────────┴──────────┘
注:当前可见状态仅影响 npx nry 选择项
# 添加新项后问询是否新添加或退出
▶︎ 添加完成,是否持续添加: 退出 继续添加
本来考虑是否在添加后直接配置新添加项为当前项,思之再三,专命令专用该命令仅添加新的 npm registry,添加后并不设置该值为当前值。
删除项
删除项,除了当前使用项,其他项均可以被删除,不限于自定义的项。
- npm
- yarn
- pnpm
# 长命令使用
npx nry delete
# 使用缩写
npx nry d
# 长命令使用
yarn dlx nry delete
# 使用缩写
yarn dlx nry d
# 长命令使用
pnpm dlx nry delete
# 使用缩写
pnpm dlx nry d
效果:
# 先展示交互选项,当前使用项不可被选中
▶︎ 请选择要删除的项
⊗ 官方(当前使用)
◦ tao bao
◦ 腾讯
◦ 中科大
● yarn
◦ earthnut
https://registry.yarnpkg.com
# 删除后展示
删除项后的列表为:
┌────────────────────────────────────┬───────────┬──────────┐
│ npm registry │ 别名 │ 当前可见 │
├────────────────────────────────────┼───────────┼──────────┤
│ * https://registry.npmjs.org │ * 官方 │ ✅ │
├────────────────────────────────────┼───────────┼──────────┤
│ https://taobao.com │ tao bao │ ✅ │
├────────────────────────────────────┼───────────┼──────────┤
│ https://mirrors.tencent.com/npm │ 腾讯 │ ✅ │
├────────────────────────────────────┼───────────┼──────────┤
│ https://npmreg.proxy.ustclug.org │ 中科大 │ ✅ │
├────────────────────────────────────┼───────────┼──────────┤
│ https://lmssee.com │ lmssee │ ✅ │
└────────────────────────────────────┴───────────┴──────────┘
注:当前可见状态仅影响 npx nry 选择项
# 问询是否进行再次删除或直接退出
▶︎ 是否继续删除其他项: 退出 继续删除
# 若是选择了继续删除,则重复上述步骤
编辑项
编辑已有项,但不切换项,仅作 npm registry 的值更改
- npm
- yarn
- pnpm
# 长命令使用
npx nry edit
# 使用缩写
npx nry ed
# 长命令使用
yarn dlx nry edit
# 使用缩写
yarn dlx nry ed
# 长命令使用
pnpm dlx nry edit
# 使用缩写
pnpm dlx nry ed
效果在展示:
# 先展示交互选择需要更改的项
▶︎ 请选择你想要修改的项
● 官方(当前使用)
◦ tao bao
◦ 腾讯
◦ 中科大
◦ yarn
◦ earthnut
https://registry.npmjs.org
# 然后在选择后更改 npm registry 值,直接回车,默认不更改
▶︎ 请更改为新的 npm registry 值: https://earthnut.dev
# 接着更改选择项的 npm registry 的别名 ,默认不更改
▶︎ 请更改为新的 npm registry 别名: earthnut
# 展示效果并问询是否依旧继续修改或退出
更改后的列表为:
┌────────────────────────────────────┬─────────────┬──────────┐
│ npm registry │ 别名 │ 当前可见 │
├────────────────────────────────────┼─────────────┼──────────┤
│ * https://registry.npmjs.org │ * 官方 │ ✅ │
├────────────────────────────────────┼─────────────┼──────────┤
│ https://taobao.com │ tao bao │ ✅ │
├────────────────────────────────────┼─────────────┼──────────┤
│ https://mirrors.tencent.com/npm │ 腾讯 │ ✅ │
├────────────────────────────────────┼─────────────┼──────────┤
│ https://npmreg.proxy.ustclug.org │ 中科大 │ ✅ │
├────────────────────────────────────┼─────────────┼──────────┤
│ https://earthnut.dev │ earthtnut │ ✅ │
└────────────────────────────────────┴─────────────┴──────────┘
注:当前可见状态仅影响 npx nry 选择项
▶︎ 是否继续修改其他项: 退出 继续修改
展示当前项状态
- npm
- yarn
- pnpm
# 长命令使用
npx nry list
# 使用缩写
npx nry ls
# 长命令使用
yarn dlx nry list
# 使用缩写
yarn dlx nry ls
# 长命令使用
pnpm dlx nry list
# 使用缩写
pnpm dlx nry ls
效果展示:
┌────────────────────────────────────┬─────────────┬──────────┐
│ npm registry │ 别名 │ 当前可见 │
├────────────────────────────────────┼─────────────┼──────────┤
│ * https://registry.npmjs.org │ * 官方 │ ✅ │
├────────────────────────────────────┼─────────────┼──────────┤
│ https://taobao.com │ tao bao │ ✅ │
├────────────────────────────────────┼─────────────┼──────────┤
│ https://mirrors.tencent.com/npm │ 腾讯 │ ❌ │
├────────────────────────────────────┼─────────────┼──────────┤
│ https://npmreg.proxy.ustclug.org │ 中科大 │ ✅ │
├────────────────────────────────────┼─────────────┼──────────┤
│ https://earthnut.dev │ earthnut │ ❌ │
└────────────────────────────────────┴─────────────┴──────────┘
注:当前可见状态仅影响 npx nry 选择项
管理所有项的显隐
使用 a-command 的多选,所以可以使用ctrl + A
全选,使用 ctrl + Z
全不选,使用 ctrl + R
全反选。而与删除命令类似,不作用于当前使用项。
- npm
- yarn
- pnpm
# 长命令使用
npx nry manage
# 使用缩写
npx nry mg
# 长命令使用
yarn dlx nry manage
# 使用缩写
yarn dlx nry mg
# 长命令使用
pnpm dlx nry manage
# 使用缩写
pnpm dlx nry mg
效果展示:
# 使用上下键切换焦点项,使用空格或左右键切换状态
▶︎ 请使用键盘选择,请使用 Enter 键进行选择
▣ 官方
■ tao bao
□ 腾讯
■ 中科大
□ earthnut
https://registry.npmmirror.com
# 按下 enter 键后保存状态
┌────────────────────────────────────┬─────────────┬──────────┐
│ npm registry │ 别名 │ 当前可见 │
├────────────────────────────────────┼─────────────┼──────────┤
│ * https://registry.npmjs.org │ * 官方 │ ✅ │
├────────────────────────────────────┼─────────────┼──────────┤
│ https://taobao.com │ tao bao │ ✅ │
├────────────────────────────────────┼─────────────┼──────────┤
│ https://mirrors.tencent.com/npm │ 腾讯 │ ✅ │
├────────────────────────────────────┼─────────────┼──────────┤
│ https://npmreg.proxy.ustclug.org │ 中科大 │ ✅ │
├────────────────────────────────────┼─────────────┼──────────┤
│ https://earthnut.dev │ earthnut │ ❌ │
└────────────────────────────────────┴─────────────┴──────────┘
注:当前可见状态仅影响 npx nry 选择项
重置所有当前值
有时候,将值改的乱七八糟,就需要恢复原有,但这么操作将丢失所有的自定义的项。
- npm
- yarn
- pnpm
# 长命令使用
npx nry reset
# 使用缩写
npx nry rs
# 长命令使用
yarn dlx nry reset
# 使用缩写
yarn dlx nry rs
# 长命令使用
pnpm dlx nry reset
# 使用缩写
pnpm dlx nry rs
效果展示
# 重置前再次询问
▶︎ 请确认是否执行覆盖原数据,该操作无法复原: 退出 重置
# 选择重置
写入成功
┌────────────────────────────────────┬──────────┬──────────┐
│ npm registry │ 别名 │ 当前可见 │
├────────────────────────────────────┼──────────┼──────────┤
│ * https://registry.npmjs.org │ * 官方 │ ✅ │
├────────────────────────────────────┼──────────┼──────────┤
│ https://registry.npmmirror.com │ 淘宝 │ ✅ │
├────────────────────────────────────┼──────────┼──────────┤
│ https://mirrors.tencent.com/npm │ 腾讯 │ ✅ │
├────────────────────────────────────┼──────────┼──────────┤
│ https://npmreg.proxy.ustclug.org │ 中科大 │ ✅ │
├────────────────────────────────────┼──────────┼──────────┤
│ https://registry.yarnpkg.com │ yarn │ ✅ │
└────────────────────────────────────┴──────────┴──────────┘
注:当前可见状态仅影响 npx nry 选择项