@@ -8,6 +8,7 @@ const RequestShortener = require("./RequestShortener");
8
8
const SizeFormatHelpers = require ( "./SizeFormatHelpers" ) ;
9
9
const formatLocation = require ( "./formatLocation" ) ;
10
10
const identifierUtils = require ( "./util/identifier" ) ;
11
+ const compareLocations = require ( "./compareLocations" ) ;
11
12
12
13
const optionsOrFallback = ( ...args ) => {
13
14
let optionValues = [ ] ;
@@ -523,6 +524,24 @@ class Stats {
523
524
}
524
525
if ( showReasons ) {
525
526
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
+ } )
526
545
. map ( reason => {
527
546
const obj = {
528
547
moduleId : reason . module ? reason . module . id : null ,
@@ -548,8 +567,7 @@ class Stats {
548
567
}
549
568
}
550
569
return obj ;
551
- } )
552
- . sort ( compareId ) ;
570
+ } ) ;
553
571
}
554
572
if ( showUsedExports ) {
555
573
if ( module . used === true ) {
0 commit comments