Skip to content

Commit 9f16238

Browse files
authored
Merge pull request webpack#7749 from webpack/bugfix/sort-reasons
fix sorting of reasons
2 parents 9fd6af8 + dcd6442 commit 9f16238

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

lib/Stats.js

Lines changed: 19 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,23 @@ 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 = compareId(a.module.id, b.module.id);
532+
if (cmp) return cmp;
533+
}
534+
if (a.dependency && !b.dependency) return -1;
535+
if (!a.dependency && b.dependency) return 1;
536+
if (a.dependency && b.dependency) {
537+
const cmp = compareLocations(a.dependency.loc, b.dependency.loc);
538+
if (cmp) return cmp;
539+
if (a.dependency.type < b.dependency.type) return -1;
540+
if (a.dependency.type > b.dependency.type) return 1;
541+
}
542+
return 0;
543+
})
526544
.map(reason => {
527545
const obj = {
528546
moduleId: reason.module ? reason.module.id : null,
@@ -548,8 +566,7 @@ class Stats {
548566
}
549567
}
550568
return obj;
551-
})
552-
.sort(compareId);
569+
});
553570
}
554571
if (showUsedExports) {
555572
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)