-
-
Notifications
You must be signed in to change notification settings - Fork 191
[Fix] correctly resolve dir paths when file with the same name exists #124
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
Conversation
ljharb
left a comment
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, this seems like a great fix!
lib/async.js
Outdated
| if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/.test(x)) { | ||
| var res = path.resolve(y, x); | ||
| if (x === '..') res += '/'; | ||
| if (x === '..' || x[x.length - 1] === '/') res += '/'; |
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.
indexing into strings doesn't work in IE 6-8 (it crashes pretty hard) - i'd prefer to use .slice(-1) or .charAt(x.length - 1) here.
lib/sync.js
Outdated
| if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/.test(x)) { | ||
| var res = path.resolve(y, x); | ||
| if (x === '..') res += '/'; | ||
| if (x === '..' || x[x.length - 1] === '/') res += '/'; |
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.
also here
| var dir = path.join(__dirname, 'resolver'); | ||
|
|
||
| t.equal( | ||
| resolve.sync('./foo/', { basedir: path.join(dir, 'same_names') }), |
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 we also add a test for ./foo, to ensure that that ends up with foo.js?
|
|
||
| var dir = path.join(__dirname, 'resolver'); | ||
|
|
||
| resolve('./foo/', { basedir: path.join(dir, 'same_names') }, function (err, res, pkg) { |
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 we also add a test for ./foo, to ensure that resolves to foo.js?
|
@ljharb updated all 4 requests :) |
ljharb
left a comment
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!
- [Fix] `sync`: ensure that the path is a string, explicitly - [Fix] correctly resolve dir paths when file with the same name exists (#124) - [Fix] error code MODULE_NOT_FOUND instead of ENOTDIR (#121) - [Dev Deps] update `eslint` - [Tests] improve failure scenarios - [Tests] [eslint] add `npm run lint` - [Tests] up to `node` `v7.9`, `v6.10`, `v4.8`; comment out OSX builds - [Tests] node 0.6 can’t support an npm that understands scoped packages
The current behavior is not in line with node's implementation.
It affects both, sync and async methods and I fixed both of them.
Related Jest issue with more details jestjs/jest#3199
Fixes #51. Closes #53.