Skip to content

Commit

Permalink
fix(bundler): fix unstable sorting for shim modules
Browse files Browse the repository at this point in the history
Previous sorting algorithm mixed alphabetical order and shim order, it could lead to rock-paper-scissor situation (means it could choose to honour alphabetical order above shim order). The new sorting takes two steps, first it sorts alphabetically, then sorts shims. This ensure we only breaks alphabetical order, not shim order.

fixes #955
  • Loading branch information
3cp committed Nov 14, 2018
1 parent 9d4bbbe commit c702325
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/build/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ exports.Bundle = class {
// Sort files by moduleId and deps to be sure they will always be
// concatenated in the same order, so revision hash won't change.
let bundleFiles = this.getBundledFiles()
.sort((a, b) => {
// alphabetical sorting based on moduleId
if (a.moduleId > b.moduleId) return 1;
if (b.moduleId > a.moduleId) return -1;
return 0;
})
.sort((a, b) => {
// for shim with deps, make sure they are in proper order
if (a.dependencyInclusion && b.dependencyInclusion) {
Expand All @@ -170,10 +176,6 @@ exports.Bundle = class {
// b must be after a
if (bDeps && bDeps.indexOf(aPackageName) !== -1) return -1;
}

// normal sorting based on moduleId
if (a.moduleId > b.moduleId) return 1;
if (b.moduleId > a.moduleId) return -1;
return 0;
});

Expand Down

0 comments on commit c702325

Please sign in to comment.