Skip to content
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

Global Config at ${PREFIX}/etc/{nmp,yarn}rc #3958

Merged
merged 3 commits into from
Jul 20, 2017
Merged

Conversation

Parakleta
Copy link
Contributor

This searches for the global RC files at ${PREFIX}/etc/{npm,yarn}rc, whereas previously it looked in ${PREFIX}/.{npm,yarn}rc. By code inspection it looks like the NPM code does the same thing on both windows and posix, but the documentation for windows suggests it might not use the /etc path component. I haven't verified behaviour on windows.

Resolves #1931.

This searches for the global `rc` files at `${PREFIX}/etc/{npm,yarn}rc`, whereas previously it looked in `${PREFIX}/.{npm,yarn}rc`.  By code inspection it looks like the NPM code does the same thing on windows and posix, but the documentation suggests it doesn't use the `/etc` path component.  I haven't verified behaviour on windows.
@@ -130,7 +130,7 @@ export default class NpmRegistry extends Registry {
const possibles = [
[false, path.join(this.cwd, filename)],
[true, this.config.userconfig || path.join(userHome, filename)],
[false, path.join(getGlobalPrefix(), filename)],
[false, path.join(getGlobalPrefix(), 'etc', filename.slice(1))],
Copy link
Member

Choose a reason for hiding this comment

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

Please add a comment about the .slice(1) part above this line. Or even better, add example paths as comments:

./.npmrc
~/.npmrc
$PREFIX/etc/npmrc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually to be properly correct it should probably take the RC name without the leading . and prefix it, rather than slicing it off. If we're going to do this properly I can try and take a look tomorrow at filling it out a bit.

I don't know anything about the Windows install of this or NPM though, so someone else will need to check that aspect of it.

Copy link
Member

Choose a reason for hiding this comment

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

That sound great :) Your change seems okay on Windows too since it seems in-line with what NPM documents and it doesn't break AppVeyor builds.

@BYK
Copy link
Member

BYK commented Jul 19, 2017

Thanks a lot for the patch by the way! :)

Moved the leading `.` from the config filename to be added by the location searcher.  The alternative is to strip the leading `.` to create the global name, but that feels clumsy.  This should also make it easier to make portable if the leading `.` is not used for hidden config files on other platforms.

Added some comments explaining the path transformations.
Leading `.` is added now by `getPossibleConfigLocations` method.
@Parakleta
Copy link
Contributor Author

I think this structure is cleaner, and I added some comments.

@Parakleta
Copy link
Contributor Author

I just noticed similar path searching behaviour in https://github.com/yarnpkg/yarn/blob/master/src/util/rc.js but I'm not sure where this code fits in. It does miss the ${prefix}/etc version and looks in /etc instead which is probably not correct. Not sure why there are multiple RC search algorithms.

@BYK
Copy link
Member

BYK commented Jul 20, 2017

I just noticed similar path searching behaviour in https://github.com/yarnpkg/yarn/blob/master/src/util/rc.js but I'm not sure where this code fits in. It does miss the ${prefix}/etc version and looks in /etc instead which is probably not correct. Not sure why there are multiple RC search algorithms.

Oh, that's quite concerning actually. Let me check that.

@BYK
Copy link
Member

BYK commented Jul 20, 2017

@Parakleta I'll go ahead and merge your fix since it fixes an immediate problem. That said findRc method is only used in one place and its logic should be fixed too. I'd argue we should use it here too if possible.

Would you be interested in taking a stab at it as a follow-up?

PS:

const home = isWin ? process.env.USERPROFILE : process.env.HOME;

line should actually be

const home = process.env.HOME || process.env.USERPROFILE;

Sicne you can have a HOME environment variable on Windows too :)

@BYK BYK merged commit fa0fb69 into yarnpkg:master Jul 20, 2017
@Parakleta
Copy link
Contributor Author

I think consolidating findRc is going to require refactoring and that's a bit much for me, I'll leave that for someone who understands the structure and direction of the project.

@BYK
Copy link
Member

BYK commented Jul 21, 2017

@Parakleta It's actually only used in two places so it shouldn't be too complicated. If you don't have time, that's okay but if you don't wanna try just because you think you'd get drowned we're here to help ;)

chrmoritz pushed a commit to chrmoritz/yarn that referenced this pull request Jul 31, 2017
**Summary**

This searches for the global `rc` files at `${PREFIX}/etc/{npm,yarn}rc`, whereas previously it looked in `${PREFIX}/.{npm,yarn}rc`.  By code inspection it looks like the NPM code does the same thing on windows and posix, but the documentation suggests it doesn't use the `/etc` path component.

**Test plan**

N/A
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