Skip to content

Commit aac0389

Browse files
committed
Sort by debug id and id
1 parent 7ca1297 commit aac0389

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

‎lib/Compilation.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ class Compilation extends Tapable {
10131013

10141014
const modules = this.modules;
10151015
for(let indexModule = 0; indexModule < modules.length; indexModule++) {
1016-
modules[indexModule].sortItems();
1016+
modules[indexModule].sortItems(false);
10171017
}
10181018

10191019
const chunks = this.chunks;
@@ -1027,7 +1027,7 @@ class Compilation extends Tapable {
10271027

10281028
const modules = this.modules;
10291029
for(let indexModule = 0; indexModule < modules.length; indexModule++) {
1030-
modules[indexModule].sortItems();
1030+
modules[indexModule].sortItems(true);
10311031
}
10321032

10331033
const chunks = this.chunks;

‎lib/Module.js‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ function byId(a, b) {
2020
return a.id - b.id;
2121
}
2222

23+
function byDebugId(a, b) {
24+
return a.debugId - b.debugId;
25+
}
26+
2327
let debugId = 1000;
2428

2529
class Module extends DependenciesBlock {
@@ -39,6 +43,7 @@ class Module extends DependenciesBlock {
3943
this.providedExports = null;
4044
this._chunks = new Set();
4145
this._chunksIsSorted = true;
46+
this._chunksIsSortedByDebugId = true;
4247
this._chunksDebugIdent = undefined;
4348
this.warnings = [];
4449
this.dependenciesWarnings = [];
@@ -60,7 +65,7 @@ class Module extends DependenciesBlock {
6065
this.providedExports = null;
6166
this._chunks.clear();
6267
this._chunksDebugIdent = undefined;
63-
this._chunksIsSorted = false;
68+
this._chunksIsSorted = this._chunksIsSortedByDebugId = false;
6469
super.disconnect();
6570
}
6671

@@ -72,14 +77,14 @@ class Module extends DependenciesBlock {
7277
this.depth = null;
7378
this._chunks.clear();
7479
this._chunksDebugIdent = undefined;
75-
this._chunksIsSorted = false;
80+
this._chunksIsSorted = this._chunksIsSortedByDebugId = false;
7681
super.unseal();
7782
}
7883

7984
addChunk(chunk) {
8085
this._chunks.add(chunk);
8186
this._chunksDebugIdent = undefined;
82-
this._chunksIsSorted = false;
87+
this._chunksIsSorted = this._chunksIsSortedByDebugId = false;
8388
}
8489

8590
removeChunk(chunk) {
@@ -97,7 +102,7 @@ class Module extends DependenciesBlock {
97102

98103
getChunkIdsIdent() {
99104
if(this._chunksDebugIdent !== undefined) return this._chunksDebugIdent;
100-
this._ensureChunksSorted();
105+
this._ensureChunksSortedByDebugId();
101106
const chunks = this._chunks;
102107
const list = [];
103108
for(let chunk of chunks) {
@@ -135,9 +140,17 @@ class Module extends DependenciesBlock {
135140
_ensureChunksSorted() {
136141
if(this._chunksIsSorted) return;
137142
this._chunks = new Set(Array.from(this._chunks).sort(byId));
143+
this._chunksIsSortedByDebugId = false;
138144
this._chunksIsSorted = true;
139145
}
140146

147+
_ensureChunksSortedByDebugId() {
148+
if(this._chunksIsSortedByDebugId) return;
149+
this._chunks = new Set(Array.from(this._chunks).sort(byDebugId));
150+
this._chunksIsSorted = false;
151+
this._chunksIsSortedByDebugId = true;
152+
}
153+
141154
addReason(module, dependency) {
142155
this.reasons.push(new ModuleReason(module, dependency));
143156
}
@@ -211,9 +224,10 @@ class Module extends DependenciesBlock {
211224
super.updateHash(hash);
212225
}
213226

214-
sortItems() {
227+
sortItems(sortChunks) {
215228
super.sortItems();
216-
this._ensureChunksSorted();
229+
if(sortChunks)
230+
this._ensureChunksSorted();
217231
this.reasons.sort((a, b) => byId(a.module, b.module));
218232
}
219233

0 commit comments

Comments
 (0)