mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-06-05 19:56:34 +00:00
ATL-428: Fixed the semver ordering for installable
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
parent
781747fe80
commit
acbb7d32b2
@ -1,3 +1,4 @@
|
||||
import * as semver from 'semver';
|
||||
import { naturalCompare } from './../utils';
|
||||
import { ArduinoComponent } from './arduino-component';
|
||||
|
||||
@ -18,6 +19,11 @@ export namespace Installable {
|
||||
/**
|
||||
* Most recent version comes first, then the previous versions. (`1.8.1`, `1.6.3`, `1.6.2`, `1.6.1` and so on.)
|
||||
*/
|
||||
export const COMPARATOR = (left: Version, right: Version) => naturalCompare(right, left);
|
||||
export const COMPARATOR = (left: Version, right: Version) => {
|
||||
if (semver.valid(left) && semver.valid(right)) {
|
||||
return semver.compare(left, right);
|
||||
}
|
||||
return naturalCompare(left, right);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -375,7 +375,7 @@ export class BoardsServiceImpl implements BoardsService, Disposable {
|
||||
const pkg = packages.get(id);
|
||||
if (pkg) {
|
||||
pkg.availableVersions.push(platform.getLatest());
|
||||
pkg.availableVersions.sort(Installable.Version.COMPARATOR);
|
||||
pkg.availableVersions.sort(Installable.Version.COMPARATOR).reverse();
|
||||
} else {
|
||||
packages.set(id, toPackage(platform));
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ export class LibraryServiceImpl implements LibraryService {
|
||||
.slice(0, 50)
|
||||
.map(item => {
|
||||
// TODO: This seems to contain only the latest item instead of all of the items.
|
||||
const availableVersions = item.getReleasesMap().getEntryList().map(([key, _]) => key).sort(Installable.Version.COMPARATOR);
|
||||
const availableVersions = item.getReleasesMap().getEntryList().map(([key, _]) => key).sort(Installable.Version.COMPARATOR).reverse();
|
||||
let installedVersion: string | undefined;
|
||||
const installed = installedLibsIdx.get(item.getName());
|
||||
if (installed) {
|
||||
|
38
arduino-ide-extension/src/test/common/installable.test.ts
Normal file
38
arduino-ide-extension/src/test/common/installable.test.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import { expect } from 'chai';
|
||||
import { Installable } from '../../common/protocol/installable';
|
||||
|
||||
describe('installable', () => {
|
||||
|
||||
describe('compare', () => {
|
||||
|
||||
const testMe = Installable.Version.COMPARATOR;
|
||||
|
||||
([
|
||||
['1.8.1', '1.8.1', 0],
|
||||
['1.8.1', '1.6.1', 1],
|
||||
['1.6.1', '1.8.1', -1],
|
||||
['1.6.1', '1.6.3', -1],
|
||||
['5.1.1', '5.1.0', 1],
|
||||
['5.1.0', '5.1.0-beta.1', 1],
|
||||
['5.1.0-beta.1', '5.1.0', -1],
|
||||
['5.1.0-beta.2', '5.1.0-beta.1', 1],
|
||||
['5.1.0-beta.1', '5.1.0-beta.2', -1],
|
||||
['5.1.0-beta.1', '5.1.1', -1],
|
||||
['1.1.0', '1.1.0-a', 1],
|
||||
['1.1.0-a', '1.1.0', -1],
|
||||
['COM1', 'COM2', -1],
|
||||
['COM1', 'COM10', -1],
|
||||
['COM10', 'COM1', 1],
|
||||
['COM10', 'COM2', 1],
|
||||
['COM2', 'COM10', -1],
|
||||
['COM10', 'COM10', 0],
|
||||
] as Array<[string, string, number]>).forEach(([left, right, expectation]) => {
|
||||
it(`'${left}' should be ${expectation === 0 ? 'equal to' : expectation < 0 ? 'less than' : 'greater than'} '${right}'`, () => {
|
||||
const actual = testMe(left, right);
|
||||
expect(actual).to.be.equal(expectation);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user