Permalink
Browse files

fix(bundler): fix unstable sorting for shim modules

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...
huochunpeng committed Nov 14, 2018
1 parent 9d4bbbe commit c7023255c73547d984812997f5abd6c6cf785478
Showing with 6 additions and 4 deletions.
  1. +6 −4 lib/build/bundle.js
@@ -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) {
@@ -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;
});

0 comments on commit c702325

Please sign in to comment.