Using yarn (recommended)
tip
We highly recommend using yarn 2+
as your package manager.
Besides the benefit of yarn over npm of better deterministic builds across different systems,
It supports moving dependencies inside the project folder.
Once you acquire the packages either using the token or by visiting the AWS code repository, you further would be able to keep the packages in the repository itself and install them without any external connection required.
Already using yarn
2+?
Follow steps 3-5 in the next section.
Migrating to yarn
info
This guide is for npm compatible yarn upgrade. Yarn also supports a zero install mode which would also work.
1. Enable yarn
note
If you already have yarn installed, you can skip this step
If you have node
>= 16.10 installed, all you need to do is:
corepack enable
Check if it is availabe now by
yarn -v
If you don't have corepack
available, you can install it with:
npm i -g corepack
2. Install the latest yarn in your project
cd into your project folder
yarn set version stable
3. Update your newly created yarnrc.yml
file
yarnPath: .yarn/releases/yarn-3.1.1.cjs
nodeLinker: node-modules
npmScopes:
neev:
npmAuthToken: ${CODEARTIFACT_AUTH_TOKEN-''}
npmAlwaysAuth: true
npmRegistryServer: "https://neev-529730085565.d.codeartifact.eu-west-2.amazonaws.com/npm/npm/"
4. Update your .gitignore
file
.pnp.*
.yarn/*
!.yarn/cache
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
Make sure that the .yarn/cache/
folder is committed to your repository.
5. Get your CodeArtifact auth token
- macOS or Linux
- Powershell
export CODEARTIFACT_AUTH_TOKEN=`aws codeartifact get-authorization-token --domain neev --domain-owner 529730085565 --query authorizationToken --output text --region eu-west-2`
$env:CODEARTIFACT_AUTH_TOKEN = aws codeartifact get-authorization-token --domain neev --domain-owner 529730085565 --query authorizationToken --output text --region eu-west-2
More details on getting the authorization token.
tip
If you get "An error occurred (ResourceNotFoundException) when calling the GetAuthorizationToken operation: Domain not found. Domain 'neev' owned by account '529730085565' does not exist."
Then make sure the aws cli has been set with an account in the o-akodnm2nsf
org id. (ECS org).
caution
The token is valid for 12 hours by default. You'll need to call this command again to get a new token.
6. Run install
This will install all the dependencies in your project with yarn.
yarn install
7. Remove your package-lock.json
That file will not be needed anymore.
8. Done 🎉
Try installing a package
yarn add @neev/logger
Once the dependencies are installed, your project should be able install all the dependencies completely offline now.