-
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
Replace user-home
with os.homedir
.
#2635
Conversation
I think user-home wraps os.homedir and has some important edge case handling. |
So the only edge case would be |
Lol, indeed it is https://github.com/sindresorhus/user-home/blob/master/index.js. |
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 that.
Just a minor refactoring please.
src/registries/npm-registry.js
Outdated
@@ -12,7 +12,7 @@ import {addSuffix, removePrefix} from '../util/misc'; | |||
import isRequestToRegistry from './is-request-to-registry.js'; | |||
|
|||
const defaults = require('defaults'); | |||
const userHome = require('user-home'); | |||
const userHome = require('os').homedir(); |
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.
Considering that constants.js has custom edge case handling to homedir, can you extract that part into an internal module in src/util
?
I think that edge case handling may cause some issues
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.
Would you like me to use that internal module for all uses of os.homedir
? What would you like me to name that module?
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.
Yeah, I think we should use one homedir definition everywhere.
Use your best judgement and lowercase letters, something with words user, home and dir maybe :)
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.
Being up at 4 AM to fix PR's is the highlight of my day, so I wouldn't bank on my best judgement.
It needs access to isRootUser
(which is exported) and getUid
(which is not). Would you like me to make getUid
an export of src/constants.js
, or move both to src/util
?
Tested failing because |
Thanks, @wtgtybhertgeghgtwtg. |
This should be safe to merge, all the other tests pass. |
* Replace `user-home` with `os.homedir`. * Replace `os.homedir` with `user-home-dir`. * Fix use `require('user-home-dir').default`.
* Replace `user-home` with `os.homedir`. * Replace `os.homedir` with `user-home-dir`. * Fix use `require('user-home-dir').default`.
* Replace `user-home` with `os.homedir`. * Replace `os.homedir` with `user-home-dir`. * Fix use `require('user-home-dir').default`.
# This is the 1st commit message: add warning from issue yarnpkg#2495 # This is the commit message yarnpkg#2: fix comments of Deniel15 # This is the commit message yarnpkg#3: remove spaces # This is the commit message yarnpkg#4: fix spaces # This is the commit message yarnpkg#5: Drop `diff`. (yarnpkg#2592) # This is the commit message yarnpkg#6: Remove empty lines # This is the commit message yarnpkg#7: Replace `user-home` with `os.homedir`. (yarnpkg#2635) * Replace `user-home` with `os.homedir`. * Replace `os.homedir` with `user-home-dir`. * Fix use `require('user-home-dir').default`. # This is the commit message yarnpkg#8: add space that were removed
fix comments of Deniel15 remove spaces fix spaces Drop `diff`. (yarnpkg#2592) Remove empty lines Replace `user-home` with `os.homedir`. (yarnpkg#2635) * Replace `user-home` with `os.homedir`. * Replace `os.homedir` with `user-home-dir`. * Fix use `require('user-home-dir').default`. add space that were removed marge with master
# This is the 1st commit message: add warning from issue yarnpkg#2495 # This is the commit message yarnpkg#2: fix comments of Deniel15 # This is the commit message yarnpkg#3: remove spaces # This is the commit message yarnpkg#4: fix spaces # This is the commit message yarnpkg#5: Drop `diff`. (yarnpkg#2592) # This is the commit message yarnpkg#6: Remove empty lines # This is the commit message yarnpkg#7: Replace `user-home` with `os.homedir`. (yarnpkg#2635) * Replace `user-home` with `os.homedir`. * Replace `os.homedir` with `user-home-dir`. * Fix use `require('user-home-dir').default`. # This is the commit message yarnpkg#8: add space that were removed
add warning from issue yarnpkg#2495 fix comments of Deniel15 remove spaces fix spaces Drop `diff`. (yarnpkg#2592) Remove empty lines Replace `user-home` with `os.homedir`. (yarnpkg#2635) * Replace `user-home` with `os.homedir`. * Replace `os.homedir` with `user-home-dir`. * Fix use `require('user-home-dir').default`. add space that were removed
@@ -0,0 +1,9 @@ | |||
/* @flow */ | |||
const path = require('path'); | |||
const {ROOT_USER} = require('../constants'); |
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.
ROOT_USER
is undefined at this point due to the cyclic dependency.
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.
Good catch, that may explain #2807.
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.
@connesc would you send a PR then?
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.
Sure: #2855 😉
Summary
Replaces
user-home
withos.homedir
. Proposed to close #2596.Test plan
Refactors internals. Nothing should change.