Skip to content

Commit a485103

Browse files
committed
Fix regession in Compilation.sortModules
This reverts the accidental change introduced in webpack#6203 which sorted modules by `id` instead of `index`. See also: webpack#7194
1 parent 645400a commit a485103

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

lib/Compilation.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ function byId(a, b) {
3232
return 0;
3333
}
3434

35+
const byIndex = (a, b) => {
36+
if(a.index < b.index) return -1;
37+
if(a.index > b.index) return 1;
38+
return 0;
39+
};
40+
3541
function iterationBlockVariable(variables, fn) {
3642
for(let indexVariable = 0; indexVariable < variables.length; indexVariable++) {
3743
const varDep = variables[indexVariable].dependencies;
@@ -682,7 +688,7 @@ class Compilation extends Tapable {
682688
}
683689

684690
sortModules(modules) {
685-
modules.sort(byId);
691+
modules.sort(byIndex);
686692
}
687693

688694
reportDependencyErrorsAndWarnings(module, blocks) {

test/Compilation.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* globals describe, it */
2+
"use strict";
3+
4+
const should = require("should");
5+
const sinon = require("sinon");
6+
7+
const Compilation = require("../lib/Compilation");
8+
9+
describe("Compilation", () => {
10+
describe('sortModules', () => {
11+
it('should sort modules by index', () => {
12+
let modules = [
13+
{index: 5},
14+
{index: 4},
15+
{index: 8},
16+
{index: 1},
17+
];
18+
19+
Compilation.prototype.sortModules(modules);
20+
modules.should.match([
21+
{index: 1},
22+
{index: 4},
23+
{index: 5},
24+
{index: 8},
25+
]);
26+
});
27+
});
28+
});

0 commit comments

Comments
 (0)