mirror of
https://github.com/apache/cordova-android.git
synced 2025-03-13 14:41:03 +08:00
Consistent order from ProjectBuilder.apkSorter (#779)
This function used to give a different order depending on the behavior of Array.prototype.sort(), which led to a test failure on Node.js 12 (see apache/cordova-android#767). This update gives a consistent sort order, regardless of the JavaScript engine implementation, now succeeds on Node.js versions 6, 8, 10, and 12. Resolves #767 For reference: - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
This commit is contained in:
parent
989b4cc913
commit
acad24d62a
@ -301,21 +301,22 @@ class ProjectBuilder {
|
|||||||
module.exports = ProjectBuilder;
|
module.exports = ProjectBuilder;
|
||||||
|
|
||||||
function apkSorter (fileA, fileB) {
|
function apkSorter (fileA, fileB) {
|
||||||
// De-prioritize arch specific builds
|
const archSpecificRE = /-x86|-arm/;
|
||||||
var archSpecificRE = /-x86|-arm/;
|
|
||||||
if (archSpecificRE.exec(fileA)) {
|
|
||||||
return 1;
|
|
||||||
} else if (archSpecificRE.exec(fileB)) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// De-prioritize unsigned builds
|
const unsignedRE = /-unsigned/;
|
||||||
var unsignedRE = /-unsigned/;
|
|
||||||
if (unsignedRE.exec(fileA)) {
|
// De-prioritize arch-specific builds & unsigned builds
|
||||||
return 1;
|
const lower = (fileName) => {
|
||||||
} else if (unsignedRE.exec(fileB)) {
|
return archSpecificRE.exec(fileName)
|
||||||
return -1;
|
? -2
|
||||||
}
|
: unsignedRE.exec(fileName)
|
||||||
|
? -1
|
||||||
|
: 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
const lowerDiff = lower(fileB) - lower(fileA);
|
||||||
|
|
||||||
|
if (lowerDiff !== 0) return lowerDiff;
|
||||||
|
|
||||||
var timeDiff = fs.statSync(fileB).mtime - fs.statSync(fileA).mtime;
|
var timeDiff = fs.statSync(fileB).mtime - fs.statSync(fileA).mtime;
|
||||||
return timeDiff === 0 ? fileA.length - fileB.length : timeDiff;
|
return timeDiff === 0 ? fileA.length - fileB.length : timeDiff;
|
||||||
|
@ -248,7 +248,7 @@ describe('ProjectBuilder', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const expectedResult = ['app-release.apk', 'app-debug.apk', 'app-release-unsigned.apk',
|
const expectedResult = ['app-release.apk', 'app-debug.apk', 'app-release-unsigned.apk',
|
||||||
'app-release-arm.apk', 'app-debug-arm.apk', 'app-release-x86.apk', 'app-debug-x86.apk'];
|
'app-release-arm.apk', 'app-release-x86.apk', 'app-debug-x86.apk', 'app-debug-arm.apk'];
|
||||||
|
|
||||||
const fsSpy = jasmine.createSpyObj('fs', ['statSync']);
|
const fsSpy = jasmine.createSpyObj('fs', ['statSync']);
|
||||||
fsSpy.statSync.and.callFake(filename => {
|
fsSpy.statSync.and.callFake(filename => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user