8

I'm trying to utilize a private repo using AWS CodeArtifact. The instructions there mention executing a aws-cli npm login command. This login command grabs a token from AWS and places it in the users .npmrc.

I had tried to put this login function in a preinstall script in the projects package.json but the problem is that .npmrc is only modified in this step and not reloaded when proceeding to the yarn install task.

Is there any way to load this token into yarn while keeping the login / install process seamless?

nlloyd
  • 1,966
  • 2
  • 15
  • 18

2 Answers2

3

Similar to the other answer, but a bit simpler, I added this as my preinstall script

Where the code to login is in the preinstall.js file. Could use the AWS CLI command too.

"preinstall": "node preinstall.js && yarn install --ignore-scripts && yarn postinstall && exit 0"

ciaran
  • 31
  • 2
1

I had a similar problem with gcloud. I managed to hack it by adding a yarn preinstall hook to package.json

    "preinstall": "yarn install --ignore-scripts; kill -9 $(ps | grep 'yarn.js install' | awk 'NR==1' | awk '{print $1}')"

It's always not necessary to also kill the yarn install either. Your "second" install would just get a cache hit and it will be fast.

You can also add /bin/bash -c ' if [[ -n ${ENV_VARIABLE:-} ]]; then blabla; fi' to make the command only run in the environment you want.

Paku
  • 455
  • 1
  • 4
  • 15