使用用户身份验证令牌覆盖 npm 项目身份验证令牌? [英] Override npm project auth token with user auth token?

查看:103
本文介绍了使用用户身份验证令牌覆盖 npm 项目身份验证令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含 $PROJECT/.npmrc 的项目,该项目有一个授权令牌,授予对项目所需的 proviat 存储库的只读访问权限:

I've got a project that includes a $PROJECT/.npmrc that has an auth token granting read-only access to the proviat repos required by the project:

$ cat .npmrc
//registry.npmjs.org/:_authToken={read-only-token}

如何使用我的用户令牌覆盖该令牌以便我可以发布包?

How can I override that token with my user token so I can publish packages?

$ cat ~/.npmrc
//registry.npmjs.org/:_authToken={my-token}

文档说明 配置文件将按优先级顺序"加载,其中项目配置具有最高优先级,并且似乎没有任何方法可以覆盖它:

The documentation states that config files will be loaded in "priority order", where the project configuration has the highest priority, and there doesn't seem to be any way to override this:

$ cd my-project/
$ npm whoami
project-readonly-user
$ cd ~
$ npm whoami
wolever

我知道可以定义一个 NPM_TOKEN 环境变量:

I know that it's possible to define an NPM_TOKEN environment variable:

//registry.npmjs.org/:_authToken=${NPM_TOKEN}

但这意味着项目的每个用户都需要定义 NPM_TOKEN 环境变量,这是不可取的(即,因为这意味着每个用户 - 包括只读用户 - 都需要在他们可以使用项目之前定义一个 NPM_TOKEN 环境变量).

But this means that every user of the project will need to define the NPM_TOKEN environment variable, which is undesirable (ie, because it means that every user - including read-only users - will need to define an NPM_TOKEN environment variable before they can use the project).

推荐答案

刚刚找到解决方案.

编辑您的 .npmrc 文件:

//registry.npmjs.org/:_authToken=${NPM_TOKEN}

每次要发布时(powershell):

Every time you want to publish(powershell):

$env:NPM_TOKEN="the-token"
npm publish --access public --registry https://registry.npmjs.org

这篇关于使用用户身份验证令牌覆盖 npm 项目身份验证令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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