跳到正文

nyprm

🔀 npm、pnpm、yarn、bun、deno 的镜像管理工具

类别技术栈
语言TypeScript
CLIcommander
构建tsdown
测试Vitest
规范oxlint、oxfmt

安装#

sh
npm install -g nyprm --registry=https://registry.npmmirror.com/

需要 Node.js 22.13 及以上版本。nyprm 直接修改各包管理器的配置文件,不需要事先安装它们。

使用说明#

text
Usage: nyprm [options] [command]
Registry manager for npm, pnpm, yarn, bun and deno
Options:  -V, --version             output the version number  -h, --help                display help for command
Commands:  ls|list                   list preset registries  current [options]         show the registry set in each config file  use [options] <registry>  switch to a preset registry or any registry URL  reset [options]           remove the registry setting to use the defaults  test                      measure the response time of preset registries  help [command]            display help for command
sh
nyprm use npmmirror                  # 预设:npm、npmmirror、tencent、huaweinyprm use https://npm.example.com/   # 任意镜像地址nyprm use npmmirror --local          # 只改当前项目nyprm currentnyprm reset

配置文件#

文件读取方写入时机
~/.npmrcnpm、pnpm、bun、deno、yarn 1总是写入
~/.yarnrc.ymlyarn 2+总是写入
~/.yarnrcyarn 1仅当文件里已设置 registry
~/.bunfig.tomlbun仅当 [install] 里已设置 registry

加上 --local 时改的是当前目录下的同名文件(bun 为不带点的 bunfig.toml),.yarnrc.yml 只在 yarn 2+ 项目里写入。

  • 只修改 registry 那一行,auth token、scope 镜像等其他配置原样保留。
  • 每次修改前,会把原文件备份为同目录下的 <文件名>.nyprm.bak。
  • 支持 NPM_CONFIG_USERCONFIG 和 XDG_CONFIG_HOME。
  • pnpm 读取 registry 时 ~/.npmrc 优先于它自己的 auth.ini,所以写 ~/.npmrc 就够了。

开发#

sh
pnpm installpnpm buildpnpm testpnpm lintpnpm formatpnpm typecheck

发版#

sh
pnpm release

bumpp 会升级版本号、提交、打 tag 并推送。tag 会触发 release workflow,通过 trusted publishing 把包提交到 npm 等待审核(自动附带 provenance),并用 changelogithub 创建 GitHub Release。维护者在 npmjs.com 包页面的 Staged Packages 标签中用 2FA 批准后(或执行 npm stage approve <stage-id>),新版本才会正式发布。

使用许可#

MIT © tlyboy