[英]How to run AWS codeartifact login and keep default repository
I run this commande in a package.json file ( scripts
> preinstall
) or ( scripts
> prepare
):我在 package.json 文件(
scripts
> preinstall
)或( scripts
> prepare
)中运行此命令:
aws codeartifact login --tool npm --repository my-repo --domain my-domain --domain-owner <123456789> --profile <me>
full file: ( <123456789>
and <me>
is modified for stackoverflow)完整文件: (
<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"
}
}
My .npmrc
file before aws codeartifact login..
commande:在
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/
My .npmrc
file is modified:我的
.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....
but I need keep this:但我需要保留这个:
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....
add --namespace @my-npm
at the end of commande line在命令行末尾添加
--namespace @my-npm
This parameter added change only the scope @my-npm:registry=...
in .npmrc
file.此参数添加仅更改
.npmrc
文件中的 scope @my-npm:registry=...
A solution I've been using for this matter is instead of using aws codeartifact login --tool npm --repository my-repo --domain my-domain
to login into aws I use a more granular approach using the following commands:我一直在使用的解决方案不是使用
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
These commands are a deconstruction of aws codeartifact login --tool npm --repository my-repo --domain my-domain
( more info ), with the difference that instead of setting a general registry
at your .npmrc
file (used to set configurations for your npm) will set a scoped registry ( more info ).这些命令是
aws codeartifact login --tool npm --repository my-repo --domain my-domain
( 更多信息)的解构,不同之处在于不是在您的.npmrc
文件中设置通用registry
(用于设置配置为您的 npm)将设置一个范围注册表( 更多信息)。 In this way you will be able to have you fetch your packages from the sources you want.通过这种方式,您将能够从您想要的来源获取您的包。 Applying this to the
package.json
you can insert those commands the value of co:login
or even isolate the commands in a script and call these script as the value.将此应用于
package.json
您可以将这些命令插入co:login
的值,甚至将这些命令隔离在脚本中并将这些脚本作为值调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.