Yarn re-load or pass new config after 'preinstall'
Asked Answered
D

2

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?

Derward answered 10/2, 2022 at 16:50 Comment(1)
related: github.com/yarnpkg/yarn/issues/8821Highjack
H
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"

Headwork answered 14/3, 2023 at 22:17 Comment(0)
I
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.

Inflict answered 16/9, 2022 at 6:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.