-
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
Use Object.assign
over defaults
.
#2687
Conversation
Travis failing because |
@@ -139,7 +138,7 @@ export default class NpmRegistry extends Registry { | |||
await fs.mkdirp(mirrorLoc); | |||
} | |||
|
|||
defaults(this.config, config); | |||
this.config = Object.assign({}, config, this.config); |
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 understand that defaults mutates the object instead of creating a copy.
Would it be a problem when passing a particular property across modules?
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.
It might if you're sharing a config object between registries and relying on outside mutations.
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.
Could you check if this is the case for the options added here?
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 don't think it is. this.config
is initialized as an empty object when a registry is constructed, and its values are loaded from a .ini or a lockfile.
The only case I came come up with is if you have something like
const yarnReg = new YarnRegistry();
await yarnReg.loadConfig();
const config = yarnReg.config.
await yarnReg.loadConfig();
// config and yarnReg.config will be different and may have different values if the lockfile has been edited between `yarReg.loadConfig` calls.
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.
Thanks for looking into this, @wtgtybhertgeghgtwtg
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.
Thank you for merging.
Try rebasing to fix CI test |
Summary
Drops the
defaults
package and usesObject.assign
. Whileis a little less obvious than
I thought it might be worth making a PR.
Test plan
Since it's an internal, no tests have been added that strictly test this.