Wil*_*ich 20 authentication nexus node.js npm npm-publish
我想知道如何配置.npmrc文件,以便我可以拥有默认注册表和具有身份验证的不同范围注册表.
我使用Nexus作为私有存储库,我不知道如何为作用域注册表设置身份验证,只有默认注册表.
例如我的~/.npmrc文件是:
registry=https://registry.npmjs.org/
@test-scope:registry=http://nexus:8081/nexus/content/repositories/npm-test/
email=test@user.com
_auth="…"
Run Code Online (Sandbox Code Playgroud)
如果我npm publish为一个作用域的包test-scope,我收到一个身份验证错误.
AFAIK,_auth唯一适用于该registry=...部分.有没有办法为该@test-scope:registry=...部分指定auth密钥?
谢谢,
Wil*_*ich 23
因此,经过一些挖掘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=…
Run Code Online (Sandbox Code Playgroud)
说明:
范围@test-scope指定registry=在执行npm publish命令时,应将具有范围的包发布到与缺省值不同的注册表.
开始与两行//nexus:8081/...用于指定的凭据两者的范围的信息库username和_password其中_password从先前使用的base64编码密码部件_auth凭据.
使用此方法,将仅从私有注册表发布和安装作用域包,并且将从默认注册表安装所有其他包.
编辑:
除此之外,可以将密码指定为环境变量,以使其不以明文形式存储在文件中.
例如:
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=…
Run Code Online (Sandbox Code Playgroud)
此外,使用Nexus时,email=必须指定行.
出于某种奇怪的原因,在使用范围包时_auth会调用它_authToken.如果您使用此功能,则无需将纯文本密码存储在您的.npmrc
registry=https://registry.npmjs.org/
@test-scope:registry=http://nexus:8081/nexus/content/repositories/npm-test/
//nexus:8081/nexus/content/repositories/npm-test/:_authToken=...
email=…
Run Code Online (Sandbox Code Playgroud)
运行以下命令,将@company-scope替换为范围,将company-registry替换为您的公司\xe2\x80\x99s npm Enterprise 注册表的名称:
\nnpm login --scope=@company-scope --registry=https://registry.company-registry.npme.io/\nRun Code Online (Sandbox Code Playgroud)\n此信息可在 npm文档中找到。
\n| 归档时间: |
|
| 查看次数: |
9545 次 |
| 最近记录: |