Sitelet https://github.com/yarnpkg/yarn/pull/7070
Skip to content

fix: handle npm prefix config environment variables - #7070

Merged
arcanis merged 6 commits into
yarnpkg:masterfrom
NicholasBoll:fix/env-variables
Mar 5, 2019
Merged

arcanis merged 6 commits into
yarnpkg:masterfrom
NicholasBoll:fix/env-variables

Conversation

@NicholasBoll

Copy link
Copy Markdown
Contributor

Fixes #4682

Summary

Passing npm_config_ environment variables changed all underscores (_) to dashes (-) which isn't correct behavior for special config variables (_auth, _authToken, _username and _password). An additional check was added to base-registry.js to filter out these config keys from this processing.

Test plan

yarn test - all tests passed except two tests that have nothing with my change - they are integration tests (I assume my environment isn't set up correctly for these to pass? Maybe CI will verify?)

key = key.replace(/__/g, '.');

// replace underscores with dashes
key = key.replace(/_/g, '-');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you instead add it in a more generic way that supports __?

For example: key.replace(/([^_])_/g, '$1-')

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea. We're probably assuming any key starting with an underscore needs to stay an underscore, but that's probably always true

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arcanis Are the changes satisfactory?

test('correctly escapes environment config variables', () => {
const testCwd = '.';
const {mockRequestManager, mockRegistries, mockReporter} = createMocks();
const npmRegistry = new NpmRegistry(testCwd, mockRegistries, mockRequestManager, mockReporter, true, []);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had trouble figuring out where these tests should go. mergeEnv is an instance method that requires a whole mocked registry to test.

Simplifying this test would involve refactoring the mergeEnv method to use a utility method, but I decided to reduce the changes to the code and instead have a more complicated test

@arcanis

arcanis commented Mar 5, 2019

Copy link
Copy Markdown
Member

Yep! Thanks 😃

@arcanis
arcanis merged commit b66549d into yarnpkg:master Mar 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants