[Fix] correctly resolve dir paths when file with the same name exists#124
Merged
ljharb merged 1 commit intobrowserify:masterfrom Apr 19, 2017
kamilogorek:same-names
Merged
[Fix] correctly resolve dir paths when file with the same name exists#124ljharb merged 1 commit intobrowserify:masterfrom kamilogorek:same-names
ljharb merged 1 commit intobrowserify:masterfrom
kamilogorek:same-names
Conversation
ljharb
requested changes
Apr 19, 2017
Member
ljharb
left a comment
There was a problem hiding this comment.
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 += '/'; |
Member
There was a problem hiding this comment.
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 += '/'; |
| var dir = path.join(__dirname, 'resolver'); | ||
|
|
||
| t.equal( | ||
| resolve.sync('./foo/', { basedir: path.join(dir, 'same_names') }), |
Member
There was a problem hiding this comment.
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) { |
Member
There was a problem hiding this comment.
could we also add a test for ./foo, to ensure that resolves to foo.js?
Contributor
Author
|
@ljharb updated all 4 requests :) |
ljharb
added a commit
that referenced
this pull request
Apr 20, 2017
- [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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.