-
Notifications
You must be signed in to change notification settings - Fork 91
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
fix: stop duplicating names on case-insensitive file systems #192
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* A unique set of paths. Case insensitive on win32 | ||
*/ | ||
class PathSet extends Set { | ||
constructor () { | ||
super() | ||
this._win32 = process.platform === 'win32' | ||
} | ||
|
||
add (value) { | ||
if (this._win32) { | ||
value = value.toLowerCase() | ||
} | ||
super.add(value) | ||
return this | ||
} | ||
|
||
has (value) { | ||
if (this._win32) { | ||
value = value.toLowerCase() | ||
} | ||
return super.has(value) | ||
} | ||
} | ||
|
||
module.exports = PathSet |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ | ||
"result": [ | ||
{ | ||
"scriptId": "51", | ||
"url": "file:///TEST_CWD/test/fixtures/all/vanilla/MAIN.js", | ||
"functions": [ | ||
{ | ||
"functionName": "", | ||
"ranges": [ | ||
{ | ||
"startOffset": 0, | ||
"endOffset": 111, | ||
"count": 1 | ||
} | ||
], | ||
"isBlockCoverage": true | ||
} | ||
] | ||
}, | ||
{ | ||
"scriptId": "52", | ||
"url": "file:///TEST_CWD/test/fixtures/all/vanilla/LOADED.js", | ||
"functions": [ | ||
{ | ||
"functionName": "", | ||
"ranges": [ | ||
{ | ||
"startOffset": 0, | ||
"endOffset": 309, | ||
"count": 1 | ||
} | ||
], | ||
"isBlockCoverage": true | ||
}, | ||
{ | ||
"functionName": "getString", | ||
"ranges": [ | ||
{ | ||
"startOffset": 17, | ||
"endOffset": 309, | ||
"count": 3 | ||
}, | ||
{ | ||
"startOffset": 89, | ||
"endOffset": 117, | ||
"count": 0 | ||
}, | ||
{ | ||
"startOffset": 140, | ||
"endOffset": 169, | ||
"count": 1 | ||
}, | ||
{ | ||
"startOffset": 169, | ||
"endOffset": 267, | ||
"count": 2 | ||
}, | ||
{ | ||
"startOffset": 190, | ||
"endOffset": 267, | ||
"count": 1 | ||
}, | ||
{ | ||
"startOffset": 272, | ||
"endOffset": 306, | ||
"count": 0 | ||
} | ||
], | ||
"isBlockCoverage": true | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* global describe, it */ | ||
const PathSet = require('../lib/path-set') | ||
const assert = require('assert') | ||
describe('path-set', () => { | ||
it('should have only one entry when adding strings with different cases on win32', () => { | ||
const pathSet = new PathSet() | ||
pathSet._win32 = true | ||
const file = 'foo.js' | ||
pathSet.add(file) | ||
pathSet.add(file.toUpperCase()) | ||
assert.strictEqual(pathSet.size, 1) | ||
}) | ||
|
||
it('should have multiple entries when adding strings with different cases on non-win32', () => { | ||
const pathSet = new PathSet() | ||
pathSet._win32 = false | ||
const file = 'foo.js' | ||
pathSet.add(file) | ||
pathSet.add(file.toUpperCase()) | ||
assert.strictEqual(pathSet.size, 2) | ||
}) | ||
|
||
it('has should return true for different cases on win32', () => { | ||
const pathSet = new PathSet() | ||
pathSet._win32 = true | ||
const file = 'foo.js' | ||
pathSet.add(file) | ||
assert(pathSet.has(file.toUpperCase())) | ||
}) | ||
|
||
it('has should NOT return true for different cases non-win32', () => { | ||
const pathSet = new PathSet() | ||
pathSet._win32 = false | ||
const file = 'foo.js' | ||
pathSet.add(file) | ||
assert(!pathSet.has(file.toUpperCase())) | ||
}) | ||
}) |
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.
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.
My concern is that I think Windows can have case sensitivity enabled? see this article.
I wonder if we could find a way to feature detect case sensitivity, rather than basing it on Windows?
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.
Oh I didn't know that. Will review. Thanks!
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.
I looked into that for jest and didn't find a nice way (suggested solutions was writing a file and reading it with different casing, but it had some caveats).
If you do find a nice way, please publish it as a separate module and we can use it in Jest as well 😀
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.
@SimenB did you publish a module for the approach used by Jest? otherwise I'd be happy to pull together a module that at least exposes the hack.
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.
No, we gave up and just check for
platform === 'win32'
😞 So please put together a module! Would be cool if Node itself could expose something...