Skip to content

Commit

Permalink
Fix module id conflict on a case insensitive OS
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
yesmeck committed Jan 4, 2020
1 parent 7158c06 commit 4abdd4e
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/utils/renderNamePattern.ts
Expand Up @@ -31,12 +31,15 @@ export function renderNamePattern(
}

export function makeUnique(name: string, existingNames: Record<string, any>) {
if (name in existingNames === false) return name;

const ext = extname(name);
name = name.substr(0, name.length - ext.length);
let uniqueName,
uniqueIndex = 1;
while (existingNames[(uniqueName = name + ++uniqueIndex + ext)]);
return uniqueName;
for (const existingName of Object.keys(existingNames)) {
if (name.toLowerCase() === existingName.toLowerCase()) {
const ext = extname(name);
name = name.substr(0, name.length - ext.length);
let uniqueName,
uniqueIndex = 1;
while (existingNames[(uniqueName = name + ++uniqueIndex + ext)]);
return uniqueName;
}
}
return name;
}

0 comments on commit 4abdd4e

Please sign in to comment.