如何为.npmrc中的作用域注册表设置_auth? [英] How to set _auth for a scoped registry in .npmrc?

查看:954
本文介绍了如何为.npmrc中的作用域注册表设置_auth?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何配置.npmrc文件,以便可以拥有默认注册表和具有身份验证功能的其他作用域注册表.

我将Nexus用于私有存储库,并且我不确定如何为范围内的注册表(仅默认注册表)设置身份验证.

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

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

如果对范围为test-scope的程序包执行npm publish,则会收到身份验证错误.

AFAIK,_auth仅适用于registry=...部分.是否可以为@test-scope:registry=...部分指定身份验证密钥?

谢谢

解决方案

因此,在仔细研究了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指定执行npm publish命令时,应将具有范围的软件包发布到与默认registry=不同的注册表中.

//nexus:8081/...开头的两行用于为username_password指定范围存储库的凭据,其中_password是先前使用的_auth凭据的base64编码密码组件. /p>

使用这种方法,将仅从私有注册表中发布和安装范围内的软件包,而从默认注册表中安装所有其他软件包.

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

例如:

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=行.

I am wondering how to configure the .npmrc file so that I can have a default registry and a different scoped registry with authentication.

I am using Nexus for the private repository and I am not sure how to set authentication for the scoped registry, only the default registry.

For example my ~/.npmrc file is:

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

If I do npm publish for a package scoped to test-scope, I get an authentication error.

AFAIK, the _auth only applies to the registry=... section. Is there a way of specifying an auth key for the @test-scope:registry=... section?

Thanks,

解决方案

So, after some digging through the NPM source code, it turns out there is a way to do this.

My solution is below:

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=…

Explanation:

The scope @test-scope specifies that packages with the scope should be published to a different registry than the default registry= when executing the npm publish command.

The two lines starting with //nexus:8081/... are used to specify the credentials to the scoped repository for both username and _password where _password is the base64 encoded password component from the previously used _auth credentials.

Using this approach, only scoped packages will be published and installed from the private registry and all other packages will be installed from the default registry.

Edit:

Additional to this, the password can be specified as an environment variable so that it is not stored in plaintext in the file.

For example:

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=…

Also, when using Nexus, the email= line must be specified.

这篇关于如何为.npmrc中的作用域注册表设置_auth?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆