• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

node.js - 如何在 .npmrc 中为范围注册表设置 _auth?

[复制链接]
菜鸟教程小白 发表于 2022-8-3 04:06:25 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我想知道如何配置 .npmrc文件,以便我可以拥有一个默认注册表和一个不同范围的带有身份验证的注册表。

我将 Nexus 用于私有(private)存储库,但我不确定如何为范围注册表设置身份验证,只有默认注册表。

例如我的 ~/.npmrc文件是:

registry=https://registry.npmjs.org/
@test-scope:registry=http://nexus:8081/nexus/content/repositories/npm-test/
[email protected]
_auth="…"

如果我这样做 npm publish对于范围为 test-scope 的包, 我收到身份验证错误。

AFAIK,_auth仅适用于 registry=...部分。有没有办法为 @test-scope:registry=... 指定认证 key ?部分?

谢谢,



Best Answer-推荐答案


因此,在对 NPM 源代码进行一些挖掘之后,发现有一种方法可以做到这一点。

我的解决方案如下:

registry=https://registry.npmjs.org/
@test-scope:registry=http://nexus:8081/nexus/content/repositories/npm-test/
//nexus:8081/nexus/content/repositories/npm-test/:username=admin
//nexus:8081/nexus/content/repositories/npm-test/:_password=YWRtaW4xMjM=
email=…

说明:

范围@test-scope指定具有范围的包应发布到与默认值不同的注册表 registry=执行 npm publish 时命令。

//nexus:8081/... 开头的两行用于为 username 指定作用域存储库的凭据和 _password哪里_password是来自之前使用的 _auth 的 base64 编码密码组件证书。

使用这种方法,只会从私有(private)注册表发布和安装范围内的包,而所有其他包将从默认注册表安装。

编辑:

除此之外,密码可以指定为环境变量,这样它就不会以明文形式存储在文件中。

例如:
registry=https://registry.npmjs.org/
@test-scope:registry=http://nexus:8081/nexus/content/repositories/npm-test/
//nexus:8081/nexus/content/repositories/npm-test/:username=admin
//nexus:8081/nexus/content/repositories/npm-test/:_password=${BASE64_PASSWORD}
email=…

此外,当使用 Nexus 时,email=必须指定行。

关于node.js - 如何在 .npmrc 中为范围注册表设置 _auth?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49404870/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap