Skip to content

Commit e80d494

Browse files
committed
fix sorting of reasons
1 parent 9fd6af8 commit e80d494

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

lib/Stats.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const RequestShortener = require("./RequestShortener");
88
const SizeFormatHelpers = require("./SizeFormatHelpers");
99
const formatLocation = require("./formatLocation");
1010
const identifierUtils = require("./util/identifier");
11+
const compareLocations = require("./compareLocations");
1112

1213
const optionsOrFallback = (...args) => {
1314
let optionValues = [];
@@ -523,6 +524,24 @@ class Stats {
523524
}
524525
if (showReasons) {
525526
obj.reasons = module.reasons
527+
.sort((a, b) => {
528+
if (a.module && !b.module) return -1;
529+
if (!a.module && b.module) return 1;
530+
if (a.module && b.module) {
531+
//const cmp = a.module.index - b.module.index;
532+
const cmp = compareId(a.module.id, b.module.id);
533+
if (cmp) return cmp;
534+
}
535+
if (a.dependency && !b.dependency) return -1;
536+
if (!a.dependency && b.dependency) return 1;
537+
if (a.dependency && b.dependency) {
538+
const cmp = compareLocations(a.dependency.loc, b.dependency.loc);
539+
if (cmp) return cmp;
540+
if (a.dependency.type < b.dependency.type) return -1;
541+
if (a.dependency.type > b.dependency.type) return 1;
542+
}
543+
return 0;
544+
})
526545
.map(reason => {
527546
const obj = {
528547
moduleId: reason.module ? reason.module.id : null,
@@ -548,8 +567,7 @@ class Stats {
548567
}
549568
}
550569
return obj;
551-
})
552-
.sort(compareId);
570+
});
553571
}
554572
if (showUsedExports) {
555573
if (module.used === true) {

test/__snapshots__/StatsTestCases.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,8 @@ chunk {2} 2.bundle.js 60 bytes <{1}> [rendered]
560560
chunk {main} bundle.js (main) 73 bytes >{0}< >{1}< [entry] [rendered]
561561
> ./index main
562562
[./a.js] 22 bytes {main} [built]
563-
cjs require ./a [./index.js] 1:0-14
564563
cjs require ./a [./e.js] 1:0-14
564+
cjs require ./a [./index.js] 1:0-14
565565
[./index.js] Xms -> factory:Xms building:Xms = Xms
566566
[./index.js] 51 bytes {main} [built]
567567
single entry ./index main

0 commit comments

Comments
 (0)