-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Allow token replacement of .npmrc configuration with env vars #1207
Conversation
We use this to inject our NPM token into the nvmrc file, so we can avoid checking in the token, and also avoid having to deal with global npm configuration on machines. |
Thanks for the PR @darthtrevino I will review |
Sweet, thank you sir! |
@@ -36,6 +36,24 @@ function getGlobalPrefix(): string { | |||
} | |||
} | |||
|
|||
function envReplace(f: string): string { |
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.
Should be more descriptive variable here than f
.
Word, thanks @wyze; in the last couple of commits I split out the envReplace function into a separate module in |
Any chance to get this in the next release? Would love to see this as it is annoying me in my project :) |
@@ -118,6 +119,9 @@ export default class NpmRegistry extends Registry { | |||
|
|||
for (const [, loc, file] of await this.getPossibleConfigLocations('.npmrc')) { | |||
const config = ini.parse(file); | |||
Object.keys(config).forEach((key: string) => { |
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.
Use for...in
here please.
import assert from 'assert'; | ||
|
||
describe('environment variable replacement', () => { | ||
|
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.
Remove empty newline.
return value; | ||
} | ||
|
||
const envExpr = /(\\*)\$\{([^}]+)\}/g; |
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.
Put this at the top level and capitalise it as ENV_EXPR
.
|
Does this PR also include the ability to replace any env variable? NPM, e.g., does not replace env vars in keys like this:
So ${ARTIFACTORY_REGISTRY} is replaced in a value expression but not in a key expression, which is quite odd. |
@maybeec Nope, this change acts the same way that NPM does. It performs token replacement in value expressions |
@darthtrevino maybe not in near future: npm/npm#14513 But might be also in a separate PR by another guy if this is merged here. As you prefer. |
@maybeec When NPM changes, I'll gladly implement it here (provided this PR actually makes it in) |
@kittens The changes you requested have been implemented and the CI looks good now. |
Does this PR require further work/changes? Would love to see it merged... |
¯_(ツ)_/¯ - I've addressed the review issues; it's up to the yarn team now |
💃 |
Summary
NPM allows for clients to inject environment variables into .npmrc configuration files. e.g.
This commit allows yarn to understand .npmrc files using this feature.
Test plan
yarn config list
to view injected variablesFixes #1206