-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Support recursive environment variable fallback in .yarnrc.yml #7005
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
Conversation
d33fa4d to
2fd4ea3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
You can also nest this syntax, for example
${PRIMARY:-${SECONDARY:-fallback}}, which first checks PRIMARY, then SECONDARY, and finally falls back to fallback.
pvcresin
commented
Dec 9, 2025
@arcanis I would like to hear your opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only works if the variable is the last thing in the fallback, so ${A:-${B}x} would fail
As there is no balancing groups in regex in JS, there are just 2 ways to properly support nested variables as far as I can see:
- Do multiple passes to replace variables from the deepest-nested one, like how
dotenv-expanddoes it - Actually write a PDA-like parser
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@clemyan Thank you for pointing out the case I hadn't considered.
I have modified the algorithm to support it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The \${...} syntax isn't really meant to be "escape everything inside", but rather "this brace has no special meaning. It's just that without nested substitution the two end up being equivalent.
Now that I have had some time to dive a little deeper I think the PDA approach would be superior and I'd like to have more robust syntax. Do you mind if I take your tests and take over the implementation? I can probably whip something up in a couple of days
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@clemyan I apologize for my shallow understanding. Please take care of the rest of the implementation.
2fd4ea3 to
ee0bf63
Compare
Uh oh!
There was an error while loading. Please reload this page.
What's the problem this PR addresses?
Support
${PRIMARY_VAR:-${SECONDARY_VAR:-fallback-value}}.This would bring Yarn's configuration behavior closer to standard shell (Bash/Zsh) parity.
I really need this feature right now.
Resolves #6998
How did you fix it?
Added an implementation to recursively look for environment variables.
Checklist