![](/img/trans.png)
[英]npm login still required despite AWS CodeArtifact login configuration
[英]How to run AWS codeartifact login and keep default repository
我在 package.json 文件( scripts
> preinstall
)或( scripts
> prepare
)中運行此命令:
aws codeartifact login --tool npm --repository my-repo --domain my-domain --domain-owner <123456789> --profile <me>
完整文件: ( <123456789>
和<me>
已針對 stackoverflow 進行了修改)
{
"name": "my-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"preinstall": "npm run co:login",
"co:login": "aws codeartifact login --tool npm --repository my-repo --domain my-domain --domain-owner <123456789> --profile <me>",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"uuid": "^3.3.2",
"@my-npm/my-common": "1.0.0"
}
}
在aws codeartifact login..
之前我的.npmrc
文件..命令:
registry=https://registry.npmjs.org
@my-npm:registry=https://my-domain-<123456789>.d.codeartifact.eu-west-1.amazonaws.com/npm/-repo/
我的.npmrc
文件被修改:
registry=https://my-domain-<123456789>.d.codeartifact.eu-west-1.amazonaws.com/npm/-repo/
@my-npm:registry=https://my-domain-<123456789>.d.codeartifact.eu-west-1.amazonaws.com/npm/-repo/
//my-domain-<123456789>.d.codeartifact.eu-west-1.amazonaws.com/npm/my-repo/:always-auth=true
//my-domain-<123456789>.d.codeartifact.eu-west-1.amazonaws.com/npm/my-repo/:_authToken=eyJ2ZXIiOjEsIml....
但我需要保留這個:
registry=https://registry.npmjs.org
@my-npm:registry=https://my-domain-<123456789>.d.codeartifact.eu-west-1.amazonaws.com/npm/-repo/
//my-domain-<123456789>.d.codeartifact.eu-west-1.amazonaws.com/npm/my-repo/:always-auth=true
//my-domain-<123456789>.d.codeartifact.eu-west-1.amazonaws.com/npm/my-repo/:_authToken=eyJ2ZXIiOjEsIml....
在命令行末尾添加--namespace @my-npm
此參數添加僅更改.npmrc
文件中的 scope @my-npm:registry=...
我一直在使用的解決方案不是使用aws codeartifact login --tool npm --repository my-repo --domain my-domain
登錄到 aws 我使用以下命令使用更精細的方法:
# get endpoint
endpoint = aws codeartifact get-repository-endpoint --domain my_domain --domain-owner 111122223333 --repository my_repo --format npm
# set a scoped registry
npm config set registry endpoint --scope=@my-package
# get token
token = aws codeartifact get-authorization-token --domain my_domain --domain-owner 111122223333 --repository my_repo
# set token
npm config set //my_domain-111122223333.d.codeartifact.region.amazonaws.com/npm/my_repo/:_authToken=token
# always truth
npm config set //my_domain-111122223333.d.codeartifact.region.amazonaws.com/npm/my_repo/:always-auth=true
這些命令是aws codeartifact login --tool npm --repository my-repo --domain my-domain
( 更多信息)的解構,不同之處在於不是在您的.npmrc
文件中設置通用registry
(用於設置配置為您的 npm)將設置一個范圍注冊表( 更多信息)。 通過這種方式,您將能夠從您想要的來源獲取您的包。 將此應用於package.json
您可以將這些命令插入co:login
的值,甚至將這些命令隔離在腳本中並將這些腳本作為值調用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.