Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Support env variables in yarnrc #1146

Closed
1 of 2 tasks
7rulnik opened this issue Apr 2, 2020 · 5 comments
Closed
1 of 2 tasks

[Feature] Support env variables in yarnrc #1146

7rulnik opened this issue Apr 2, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@7rulnik
Copy link
Contributor

7rulnik commented Apr 2, 2020

  • I'd be willing to implement this feature
  • This feature can already be implemented through a plugin

Describe the user story

yarn v1 supports env variables in yarnrc/npmrc:

//registry.npmjs.org/:_authToken=${COMPANY_NPM_TOKEN}

but v2 doesn't support it in .yarnrc.yml

Describe the solution you'd like

It would be nice to support env variables like in other tools/libraries (for example docker compose)

@7rulnik 7rulnik added the enhancement New feature or request label Apr 2, 2020
@DaneTheory
Copy link

You can inject runtime environment variables, including variables already defined within the active shell, by rerouting the yarnPath defined in .yarnrc.yml to a custom path containing a .js file which instantiates a valid Yarn v2 release in the form of a child_process. At that point, declaring custom process.env values is straight-forward. Though it does feel a bit hacky. Check out @yarkPkg Berry's repo and you can see they do exactly that. However, I imagine best practices would be to utilize the pnpapi lifecycle as according to the docs.

@paul-soporan
Copy link
Member

A quick but not that convenient solution, until we add support for setting complex values (Arrays and Objects) through environment variables (e.g. YARN_NPM_REGISTRIES), would be to use yarn config set --json (It's a very new feature, so you have to use yarn set version from sources to get the latest Yarn version from master):

yarn config set --json npmRegistries '{ "//registry.npmjs.org": { "npmAuthToken": "'"${COMPANY_NPM_TOKEN}"'" } }'

Note that this command modifies your .yarnrc.yml file (so make sure you don't commit it) and it also displays the modified value, so make sure to hide its output on CI if your logs are public.

@njradford
Copy link

njradford commented May 6, 2020

I'm getting around this on CI by setting YARN_NPM_AUTH_TOKEN as an ENV var https://yarnpkg.com/configuration/yarnrc

@7rulnik
Copy link
Contributor Author

7rulnik commented May 6, 2020

@njradford yeah, I am doing the same thing right now.

@paul-soporan @arcanis what do you think if we will traverse config here and replace all ${SOME_ENV} by real env from process.env?

function parseViaJsYaml(source: string) {

If you don't mind I can send a PR

@arcanis
Copy link
Member

arcanis commented Jun 1, 2020

Fixed in #1341 💫

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants