mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-31 17:32:51 +08:00
fix: Plugin install fails when preview sdk is installed (#985)
This commit is contained in:
parent
0bf6455153
commit
8d8600b442
17
bin/templates/cordova/lib/android_sdk.js
vendored
17
bin/templates/cordova/lib/android_sdk.js
vendored
@ -29,17 +29,14 @@ var suffix_number_regex = /(\d+)$/;
|
|||||||
// the number at the end, the more recent the target, the closer to the
|
// the number at the end, the more recent the target, the closer to the
|
||||||
// start of the array.
|
// start of the array.
|
||||||
function sort_by_largest_numerical_suffix (a, b) {
|
function sort_by_largest_numerical_suffix (a, b) {
|
||||||
var suffix_a = a.match(suffix_number_regex);
|
let suffix_a = a.match(suffix_number_regex);
|
||||||
var suffix_b = b.match(suffix_number_regex);
|
let suffix_b = b.match(suffix_number_regex);
|
||||||
if (suffix_a && suffix_b) {
|
// If no number is detected (eg: preview version like android-R),
|
||||||
// If the two targets being compared have suffixes, return less than
|
// designate a suffix of 0 so it gets moved to the end
|
||||||
// zero, or greater than zero, based on which suffix is larger.
|
suffix_a = suffix_a || ['0', '0'];
|
||||||
|
suffix_b = suffix_b || ['0', '0'];
|
||||||
|
// Return < zero, or > zero, based on which suffix is larger.
|
||||||
return (parseInt(suffix_a[1]) > parseInt(suffix_b[1]) ? -1 : 1);
|
return (parseInt(suffix_a[1]) > parseInt(suffix_b[1]) ? -1 : 1);
|
||||||
} else {
|
|
||||||
// If no suffix numbers were detected, leave the order as-is between
|
|
||||||
// elements a and b.
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.print_newest_available_sdk_target = function () {
|
module.exports.print_newest_available_sdk_target = function () {
|
||||||
|
@ -33,14 +33,21 @@ describe('android_sdk', () => {
|
|||||||
|
|
||||||
describe('sort_by_largest_numerical_suffix', () => {
|
describe('sort_by_largest_numerical_suffix', () => {
|
||||||
it('should return the newest version first', () => {
|
it('should return the newest version first', () => {
|
||||||
const ids = ['android-24', 'android-19', 'android-27', 'android-23'];
|
const ids = ['android-P', 'android-24', 'android-19', 'android-27', 'android-23'];
|
||||||
const sortedIds = ['android-27', 'android-24', 'android-23', 'android-19'];
|
const sortedIds = ['android-27', 'android-24', 'android-23', 'android-19', 'android-P'];
|
||||||
expect(ids.sort(android_sdk.__get__('sort_by_largest_numerical_suffix'))).toEqual(sortedIds);
|
expect(ids.sort(android_sdk.__get__('sort_by_largest_numerical_suffix'))).toEqual(sortedIds);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return 0 (no sort) if one of the versions has no number', () => {
|
describe('should return release version over preview versions', () => {
|
||||||
|
it('Test #001', () => {
|
||||||
const ids = ['android-27', 'android-P'];
|
const ids = ['android-27', 'android-P'];
|
||||||
expect(android_sdk.__get__('sort_by_largest_numerical_suffix')(ids[0], ids[1])).toBe(0);
|
expect(android_sdk.__get__('sort_by_largest_numerical_suffix')(ids[0], ids[1])).toBe(-1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Test #002', () => {
|
||||||
|
const ids = ['android-P', 'android-27'];
|
||||||
|
expect(android_sdk.__get__('sort_by_largest_numerical_suffix')(ids[0], ids[1])).toBe(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user