node.jsamazon-web-servicesaws-codeartifact.npmrc

How to run AWS codeartifact login and keep default registry


I run this commande in a package.json file (scripts > preinstall) or (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)

{
  "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:

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:

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

Solution

  • add --namespace @my-npm at the end of commande line

    This parameter added change only the scope @my-npm:registry=... in .npmrc file.