mirror of https://github.com/webpack/webpack.git
fixes #11026
This commit is contained in:
parent
eac7d290ca
commit
ab01c0628e
|
|
@ -44,20 +44,30 @@ const similarity = (a, b) => {
|
|||
/**
|
||||
* @param {string} a key
|
||||
* @param {string} b key
|
||||
* @param {Set<string>} usedNames set of already used names
|
||||
* @returns {string} the common part and a single char for the difference
|
||||
*/
|
||||
const getName = (a, b) => {
|
||||
const getName = (a, b, usedNames) => {
|
||||
const l = Math.min(a.length, b.length);
|
||||
let r = "";
|
||||
for (let i = 0; i < l; i++) {
|
||||
const ca = a.charAt(i);
|
||||
const cb = b.charAt(i);
|
||||
r += ca;
|
||||
if (ca === cb) {
|
||||
continue;
|
||||
let i = 0;
|
||||
while (i < l) {
|
||||
if (a.charCodeAt(i) !== b.charCodeAt(i)) {
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
return r;
|
||||
i++;
|
||||
}
|
||||
while (i < l) {
|
||||
const name = a.slice(0, i);
|
||||
const lowerName = name.toLowerCase();
|
||||
if (!usedNames.has(lowerName)) {
|
||||
usedNames.add(lowerName);
|
||||
return name;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
// names always contain a hash, so this is always unique
|
||||
// we don't need to check usedNames nor add it
|
||||
return a;
|
||||
};
|
||||
|
||||
|
|
@ -391,12 +401,17 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
|
|||
});
|
||||
|
||||
// give every group a name
|
||||
const usedNames = new Set();
|
||||
for (let i = 0; i < result.length; i++) {
|
||||
const group = result[i];
|
||||
const first = group.nodes[0];
|
||||
const last = group.nodes[group.nodes.length - 1];
|
||||
let name = getName(first.key, last.key);
|
||||
group.key = name;
|
||||
if (group.nodes.length === 1) {
|
||||
group.key = group.nodes[0].key;
|
||||
} else {
|
||||
const first = group.nodes[0];
|
||||
const last = group.nodes[group.nodes.length - 1];
|
||||
const name = getName(first.key, last.key, usedNames);
|
||||
group.key = name;
|
||||
}
|
||||
}
|
||||
|
||||
// return the results
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
import a from "./file-a1";
|
||||
import b from "./file-b1";
|
||||
import A from "./file-A2";
|
||||
import B from "./file-B2";
|
||||
export default "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" +
|
||||
a +
|
||||
b +
|
||||
A +
|
||||
B;
|
||||
|
|
@ -0,0 +1 @@
|
|||
export default "A2222222222222222222222";
|
||||
|
|
@ -0,0 +1 @@
|
|||
export default "B2222222222222222222222";
|
||||
|
|
@ -0,0 +1 @@
|
|||
export default "a1111111111111111111111";
|
||||
|
|
@ -0,0 +1 @@
|
|||
export default "b1111111111111111111111";
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
it("should ignore case insenstive chars when generating maxSize filenames", () =>
|
||||
import(/* webpackChunkName: "chunk" */ "./chunk").then(
|
||||
({ default: value }) => {
|
||||
expect(value).toContain("a111");
|
||||
expect(value).toContain("b111");
|
||||
expect(value).toContain("A222");
|
||||
expect(value).toContain("B222");
|
||||
expect(value).toContain("cccc");
|
||||
}
|
||||
));
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
module.exports = {
|
||||
findBundle: function (i, options) {
|
||||
return ["main.js"];
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
/** @type {import("../../../../").Configuration} */
|
||||
module.exports = {
|
||||
output: {
|
||||
filename: "[name].js"
|
||||
},
|
||||
optimization: {
|
||||
chunkIds: "named",
|
||||
splitChunks: {
|
||||
hidePathInfo: false,
|
||||
minSize: 50,
|
||||
maxSize: 100
|
||||
}
|
||||
}
|
||||
};
|
||||
Loading…
Reference in New Issue