Yarn re-load or pass new config after 'preinstall'

Viewed 166

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?

1 Answers

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.

Related