From c7023255c73547d984812997f5abd6c6cf785478 Mon Sep 17 00:00:00 2001 From: Chunpeng Huo Date: Thu, 15 Nov 2018 08:17:09 +1100 Subject: [PATCH] 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 --- lib/build/bundle.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/build/bundle.js b/lib/build/bundle.js index e094e5d9a..1c0156e29 100644 --- a/lib/build/bundle.js +++ b/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; });