-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
Resolve directory to the real path before using as base for resolve #7
Conversation
index.js
Outdated
@@ -11,7 +12,15 @@ const resolveFrom = (fromDir, moduleId, silent) => { | |||
throw new TypeError(`Expected \`moduleId\` to be of type \`string\`, got \`${typeof moduleId}\``); | |||
} | |||
|
|||
fromDir = path.resolve(fromDir); | |||
try { | |||
fromDir = resolveLinkTarget.sync(fromDir); |
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.
Why not just fs.realpathSync()
?
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.
Indeed. Updated
index.js
Outdated
try { | ||
fromDir = fs.realpathSync(fromDir); | ||
} catch (err) { | ||
if (err.code !== 'EINVAL') { |
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.
Not really sure why you're just throwing on EINVAL
. Any error should be thrown.
You also have to correctly handle the silent
argument. See line 32.
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.
you're right, EINVAL
was needed only when used with the resolve-link-target
lib. All should be thrown when using fs.realpathSync
. Also added tests for silent.
Thanks for the quick review. If anything else, I'll fix tomorrow. morning.
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.
@sindresorhus, after thinking about this more, I am not so sure we have to throw any error. Right now it works if the fromDir
does not exist in the filesystem. resolve seems to behave the same. So maybe we just need to use path.resolve
on fromDir
and then ignore ENOENT
errors of realpathSync
. What do you think?
LGTM 👍 |
Sorry, forgot about this. I'm gonna do a major bump just in case it affects something. |
Close #6