Skip to content

Commit

Permalink
Merge pull request #7749 from webpack/bugfix/sort-reasons
Browse files Browse the repository at this point in the history
fix sorting of reasons
  • Loading branch information
sokra committed Jul 20, 2018
2 parents 9fd6af8 + dcd6442 commit 9f16238
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
21 changes: 19 additions & 2 deletions lib/Stats.js
Expand Up @@ -8,6 +8,7 @@ const RequestShortener = require("./RequestShortener");
const SizeFormatHelpers = require("./SizeFormatHelpers");
const formatLocation = require("./formatLocation");
const identifierUtils = require("./util/identifier");
const compareLocations = require("./compareLocations");

const optionsOrFallback = (...args) => {
let optionValues = [];
Expand Down Expand Up @@ -523,6 +524,23 @@ class Stats {
}
if (showReasons) {
obj.reasons = module.reasons
.sort((a, b) => {
if (a.module && !b.module) return -1;
if (!a.module && b.module) return 1;
if (a.module && b.module) {
const cmp = compareId(a.module.id, b.module.id);
if (cmp) return cmp;
}
if (a.dependency && !b.dependency) return -1;
if (!a.dependency && b.dependency) return 1;
if (a.dependency && b.dependency) {
const cmp = compareLocations(a.dependency.loc, b.dependency.loc);
if (cmp) return cmp;
if (a.dependency.type < b.dependency.type) return -1;
if (a.dependency.type > b.dependency.type) return 1;
}
return 0;
})
.map(reason => {
const obj = {
moduleId: reason.module ? reason.module.id : null,
Expand All @@ -548,8 +566,7 @@ class Stats {
}
}
return obj;
})
.sort(compareId);
});
}
if (showUsedExports) {
if (module.used === true) {
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/StatsTestCases.test.js.snap
Expand Up @@ -560,8 +560,8 @@ chunk {2} 2.bundle.js 60 bytes <{1}> [rendered]
chunk {main} bundle.js (main) 73 bytes >{0}< >{1}< [entry] [rendered]
> ./index main
[./a.js] 22 bytes {main} [built]
cjs require ./a [./index.js] 1:0-14
cjs require ./a [./e.js] 1:0-14
cjs require ./a [./index.js] 1:0-14
[./index.js] Xms -> factory:Xms building:Xms = Xms
[./index.js] 51 bytes {main} [built]
single entry ./index main
Expand Down

0 comments on commit 9f16238

Please sign in to comment.