Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can npm be used AWS CodeArtifact for private packages, while all npm.org is used with public packages?

The docs read a bit like the developer is supposed to give over all "package registry duties" to AWS CodeArtifact. But I want to continue using npm.org for some packages.

Given a javascript app that uses private and public packages, can I setup npm/AWS so:

  • privately scoped packages (my code) are pulled from AWS CodeArtifact, and
  • publically scoped packages (e.g. lodash) are pulled npm.org?
like image 961
Ashley Coolman Avatar asked Oct 12 '25 00:10

Ashley Coolman


1 Answers

There is way to explicitly set two npm registries, therefore achieving what you want. Instead of using aws codeartifact login --tool npm --repository my-repo --domain my-domain to login into aws you should use a more granular approach use the following commands:

# 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). In this way you will be able to have you fetch your packages from the sources you want.

like image 166
sebassebas1313 Avatar answered Oct 15 '25 18:10

sebassebas1313