将.npmrc配置为使用NPM_TOKEN发布到公共存储库

qhhrdooz  于 2022-11-14  发布在  其他
关注(0)|答案(1)|浏览(958)

我已经创建了一个公共的npm存储库:https://www.npmjs.com/package/point-cloud-visualiser
我正在尝试从codebuild中运行npm publish。我已经生成了一个令牌并将其保存在AWS secrets manager中。我成功地将secret拉入buildspec中。但是我不确定如何配置.npmrc文件,使其使用令牌,并且不告诉我登录。
当前我的.npmrc如下所示:

@point-cloud-visualiser:registry=https://www.npmjs.com/package/point-cloud-visualiser
//point-cloud-visualiser/:_authToken=${NPM_TOKEN}

我的buildspec.yml看起来像这样:

version: 0.2

env:
  secrets-manager:
    NPM_TOKEN: "npm-token:npm-token"

phases:
  install:
    commands:
      - npm install
  build:
    commands:
      - npm run build
      - npm publish

但是,当它在npm publish上失败时,会出现以下错误:

npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in to https://registry.npmjs.org/
npm ERR! need auth You need to authorize this machine using `npm adduser`

我还尝试删除.npmrc文件并在buildspec.yml中使用以下代码:

version: 0.2

env:
  secrets-manager:
    NPM_TOKEN: "npm-token:npm-token"

phases:
  install:
    commands:
      - npm install
  build:
    commands:
      - npm run build
      - npm config set registry 'https://www.npmjs.com/package/point-cloud-visualiser'
      - npm config set '//npmjs.com/package/point-cloud-visualiser/:always-auth' 'true'
      - npm config set '//npmjs.com/package/point-cloud-visualiser/:_authToken' '${NPM_TOKEN}'
      - npm publish

但是这种方法给出了和上面一样的结果。我做错了什么?谢谢!

3xiyfsfu

3xiyfsfu1#

以下构建规范已成功运行:

version: 0.2

env:
  secrets-manager:
    NPM_TOKEN: "npm-token:npm-token"

phases:
  install:
    commands:
      - npm install
  build:
    commands:
      - npm run build
      - echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
      - echo "//registry.npmjs.org/:always-auth=true" >> ~/.npmrc
      - npm publish

相关问题