-
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
Read config from ~/.yarnrc #5812
Conversation
@@ -298,8 +298,7 @@ export default class NpmRegistry extends Registry { | |||
} | |||
|
|||
for (const scope of [this.getScope(packageIdent), '']) { | |||
const registry = | |||
this.getScopedOption(scope, 'registry') || this.registries.yarn.getScopedOption(scope, 'registry'); |
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.
YarnRegistry.getScopedOption
does not exist.
7f44bca
to
ced8487
Compare
@arcanis @rally25rs @imsnif can you take a look? @otaku thanks a lot for the fix! Do you think you can add tests for the fix? |
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.
Hey @otaku - thanks a lot for this patch! I left one comment. To elaborate: if I understand correctly, we could achieve the same effect by implementing YarnRegistry.getScopedOption
and leaving the registry assignment in the for loop as is. Or am I missing something? What do you think?
Also, a test case for this would definitely be great.
Other than that, looks like an important fix. I feel like I've encountered this issue in the past and had to dance around it without looking too much into it. :)
Would be happy to merge. Good find!
src/registries/npm-registry.js
Outdated
} | ||
} | ||
|
||
return val; |
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.
Do you think it will be possible to swap this for an implementation of YarnRegistry.getScopedOption
?
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.
I believe that would turn into endless recursion.
NpmRegistry.getScopedOption
would loop through all registries looking for getScopedOption
and call it, however if it doesn't exist in that registry, it in turn would do the same thing. It could be possible by passing optional arguments to not recurse... but I don't know if that's worth the complexity.
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.
Sorry, I'll clarify my meaning. How aboutif we implement YarnRegistry.getScopedOption
as something like:
getScopedOption(scope: string, option: string): mixed {
return this.getOption(scope + (scope ? ':' : '') + option);
}
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.
YarnRegistry
is an extension of NpmRegistry
so getScopedOption
is the same function as this one.
I could look into moving all the logic into BaseRegistry
and remove them from both YarnRegistry
and NpmRegistry
if that's the desired goal?
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.
I think we can start by adding a test for this and then playing around to see what works best. It'll be much easier that way. Makes sense?
I've added a simple test case against two scoped registries. Let me know if there's any more changes needed. I originally attempted to modify all test cases to run with I don't understand in which scenarios All the test cases appear to be for |
Alternatively, instead of I've modified This is a slightly cleaner implementation as it moves everything into Tests are passing as well. Check it out here: otaku/yarn@master...otaku:registry-fix2 Let me know if I should merge these changes into this PR. Also, to attempt to answer your first question / concern: yarn/src/fetchers/tarball-fetcher.js Line 151 in ec8cea0
registry is set to npm . It directly calls NpmRegistry.request bypassing YarnRegistry entirely. It never actually tries to get the configuration option from YarnRegistry config anywhere.
|
Hey @otaku - first: thanks for all the rapid work on this! I reverted your As for tests - there indeed don't seem to be unit tests for |
Just want to mention that the |
Fixed the test case. I had it running against |
@otaku - let me know if you want a hand fixing those tests. |
All good to go now! The recursive getOption broke everything. |
Hey @otaku - thanks again for your work on this. The issue I find with this implementation (and please correct me if I missed something) is that it causes I feel it would be much better, maintainability-wise and usability-wise to wait for the bigger refactor @arcanis talked about above. Where we can decide how the two config files are merged exactly and write it out explicitly. Barring that, I think a temporary solution that would simplify rather than add complexity is addressing this issue: #3683 |
@imsnif You're not wrong. It's actually confusing even trying to follow the code. Currently, you have Currently in
|
Hey @otaku - great! So, let's get things rolling. Since we're changing the behaviour of the config files (what we call fixing a bug might be called "creating a bug" by someone else) - I wouldn't want to do it more than we absolutely have to. So ideally, I'd want to do it just once. I think the desired precedence for config files is:
IMO, this can be achieved as mentioned here: #3683 by extracting the *I'm ignoring the aliases right now for simplicity. |
Do note that if we go this way, I think we'll need to add quite a lot of new test cases that will articulate this behaviour - because as far as I saw this is hardly tested right now. |
Hey, @otaku - do you feel like picking this up? |
I currently do not have time due to work @imsnif |
Thanks for your work and effort up until now @otaku! |
Was this added/fixed in some other PR? I would like to use it =) |
This would be useful to me too, was it ever merged? |
Same here. I find the combination of It's literally impossible to configure yarn to talk to an internal private registry (including authentication and over SSL) simply by reading the docs. I have no clue what information goes where, all i know is that information configured in I cannot possibly know which of these configuration tidbits ( Help. |
The system is completely overhauled in the v2. Yarn will only read |
Given the following:
I expect to be able to be able to access the private packages on the registry.
I believe this relates to #3932 as well as a few others.
Explanation:
YarnRegistry
extendsNpmRegistry
howeverNpmRegistry.getScopedOption
does not try to read fromYarnRegistry.config
so it is unable to find//registry.npmjs.org/:_authToken
resulting in errors.