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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 };