Skip to content

Commit

Permalink
Fix module id conflict on a case insensitive OS (#3317)
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 authored and lukastaegert committed Jan 8, 2020
1 parent b99758b commit 35e127c
Show file tree
Hide file tree
Showing 19 changed files with 139 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/utils/renderNamePattern.ts
Expand Up @@ -31,12 +31,13 @@ export function renderNamePattern(
}

export function makeUnique(name: string, existingNames: Record<string, any>) {
if (name in existingNames === false) return name;
const existingNamesLowercase = new Set(Object.keys(existingNames).map(key => key.toLowerCase()));
if (!existingNamesLowercase.has(name.toLocaleLowerCase())) return name;

const ext = extname(name);
name = name.substr(0, name.length - ext.length);
let uniqueName,
uniqueIndex = 1;
while (existingNames[(uniqueName = name + ++uniqueIndex + ext)]);
while (existingNamesLowercase.has((uniqueName = name + ++uniqueIndex + ext).toLowerCase()));
return uniqueName;
}
@@ -0,0 +1,21 @@
module.exports = {
description: 'Preserve modules id case sensitive',
options: {
input: 'main.js',
preserveModules: true,
plugins: [
{
resolveId(id) {
if (id.toLowerCase().includes('one')) {
return id;
}
},
load(id) {
if (id.toLowerCase().includes('one')) {
return `export default '${id.replace('\0', '')}'`;
}
}
}
]
}
};
@@ -0,0 +1,7 @@
define(function () { 'use strict';

var c = 'One1.js';

return c;

});
@@ -0,0 +1,7 @@
define(function () { 'use strict';

var b = 'One.js';

return b;

});
@@ -0,0 +1,7 @@
define(function () { 'use strict';

var a = 'one.js';

return a;

});
@@ -0,0 +1,5 @@
define(['./_virtual/_one', './_virtual/_One2', './_virtual/_One1'], function (_one, _One, _One1) { 'use strict';

window.APP = { a: _one, b: _One, c: _One1 };

});
@@ -0,0 +1,5 @@
'use strict';

var c = 'One1.js';

module.exports = c;
@@ -0,0 +1,5 @@
'use strict';

var b = 'One.js';

module.exports = b;
@@ -0,0 +1,5 @@
'use strict';

var a = 'one.js';

module.exports = a;
@@ -0,0 +1,7 @@
'use strict';

var _one = require('./_virtual/_one.js');
var _One = require('./_virtual/_One2.js');
var _One1 = require('./_virtual/_One1.js');

window.APP = { a: _one, b: _One, c: _One1 };
@@ -0,0 +1,3 @@
var c = 'One1.js';

export default c;
@@ -0,0 +1,3 @@
var b = 'One.js';

export default b;
@@ -0,0 +1,3 @@
var a = 'one.js';

export default a;
@@ -0,0 +1,5 @@
import a from './_virtual/_one.js';
import b from './_virtual/_One2.js';
import c from './_virtual/_One1.js';

window.APP = { a, b, c };
@@ -0,0 +1,10 @@
System.register([], function (exports) {
'use strict';
return {
execute: function () {

var c = exports('default', 'One1.js');

}
};
});
@@ -0,0 +1,10 @@
System.register([], function (exports) {
'use strict';
return {
execute: function () {

var b = exports('default', 'One.js');

}
};
});
@@ -0,0 +1,10 @@
System.register([], function (exports) {
'use strict';
return {
execute: function () {

var a = exports('default', 'one.js');

}
};
});
@@ -0,0 +1,18 @@
System.register(['./_virtual/_one.js', './_virtual/_One2.js', './_virtual/_One1.js'], function () {
'use strict';
var a, b, c;
return {
setters: [function (module) {
a = module.default;
}, function (module) {
b = module.default;
}, function (module) {
c = module.default;
}],
execute: function () {

window.APP = { a, b, c };

}
};
});
@@ -0,0 +1,5 @@
import a from '\0one.js';
import b from '\0One.js';
import c from '\0One1.js';

window.APP = { a, b, c };

0 comments on commit 35e127c

Please sign in to comment.