Skip to content
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 module id conflict on a case insensitive OS #3317

Merged
merged 1 commit into from Jan 8, 2020

Conversation

yesmeck
Copy link
Contributor

@yesmeck yesmeck commented Jan 3, 2020

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

Description

Suppose we have to files named date.js and Date.js, makeUnique treats these two files are different currently. But on a case insensitive OS, they are the same file. This commit try to fix the
problem.

@yesmeck
Copy link
Contributor Author

yesmeck commented Jan 3, 2020

I think this commit also fixes #3139

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would need to check but I am not sure you can do it that way as existingNames is also the bundle object in some cases. Changing the names here could have far reaching consequences and could also be considered a breaking change as suddenly, all names on the bundle object would be lowercase. My guess is that some part of the code assumes that a chunk is on the bundle object under its original name. Not yet sure about a better approach, though.

@codecov
Copy link

codecov bot commented Jan 4, 2020

Codecov Report

Merging #3317 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3317      +/-   ##
==========================================
+ Coverage   93.17%   93.18%   +<.01%     
==========================================
  Files         172      172              
  Lines        6041     6042       +1     
  Branches     1801     1801              
==========================================
+ Hits         5629     5630       +1     
  Misses        221      221              
  Partials      191      191
Impacted Files Coverage Δ
src/utils/renderNamePattern.ts 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b99758b...290de04. Read the comment docs.

@yesmeck
Copy link
Contributor Author

yesmeck commented Jan 4, 2020

@lukastaegert I submit another approach which won't change names in existingNames, now CI is passed.

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment. Also it is mandatory for this fix to move forward to have tests that demonstrate the problem that is solved and also how potential edge-cases are handled if there are relevant ones.

For this feature, a test from the chunking-form category would be easy to set up.

name = name.substr(0, name.length - ext.length);
let uniqueName,
uniqueIndex = 1;
while (existingNames[(uniqueName = name + ++uniqueIndex + ext)]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are files Date.js and Date1.js, a file named date.js would be renamed date1.js and thus conflict with the other name because you are not being case-insensitive here. For a quick fix, instead of iterating over the existing names you could create a Set a-priori to reference against:

const existingNamesLowercase = new Set(Object.keys(existingNames).map(key => key.toLowerCase()));
if (!existingNamesLowercase.has(name) return name;
...
while (existingNamesLowercase.has((uniqueName = name + ++uniqueIndex + ext).toLowerCase());

@yesmeck yesmeck force-pushed the fix-module-name branch 3 times, most recently from 4422141 to 1a4b1f0 Compare January 8, 2020 06:17
Suppose we have to files named `date.js` and `Date.js`, `makeUnique`
treats these two files are different currently. But on a case
insensitive OS, they are the same file. The commit try to fix the
problem.
@yesmeck
Copy link
Contributor Author

yesmeck commented Jan 8, 2020

@lukastaegert Updated and test included.

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants