tree-wide: fix version comparison

We were using satisfies in a few places where we should have just been
using a comparison operator.
This commit is contained in:
David Lechner
2022-12-20 15:39:26 -06:00
parent 25231012f6
commit b366f777ca
3 changed files with 16 additions and 10 deletions
+3 -3
View File
@@ -8,7 +8,7 @@
import { firmwareVersion } from '@pybricks/firmware';
import { Task, buffers, eventChannel } from 'redux-saga';
import { satisfies } from 'semver';
import { lt, satisfies } from 'semver';
import {
call,
cancel,
@@ -223,9 +223,9 @@ function* handleBleConnectPybricks(): Generator {
// notify user if old firmware
if (
satisfies(
lt(
pythonVersionToSemver(firmwareRevision),
`<${pythonVersionToSemver(firmwareVersion)}`,
pythonVersionToSemver(firmwareVersion),
)
) {
yield* put(alertsShowAlert('ble', 'oldFirmware'));
+1 -6
View File
@@ -193,12 +193,7 @@ const preferredFileFormat: Reducer<FileFormat | null> = (state = null, action) =
if (blePybricksServiceDidNotReceiveHubCapabilities.matches(action)) {
// HACK: there is not a good way to get the supported MPY ABI version
// from a running hub, so we use heuristics on the firmware version.
if (
semver.satisfies(
pythonVersionToSemver(action.firmwareVersion),
'>=3.2.0-beta.2',
)
) {
if (semver.lte(pythonVersionToSemver(action.firmwareVersion), '3.2.0-beta.2')) {
return FileFormat.Mpy6;
}
+12 -1
View File
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2021 The Pybricks Authors
// Copyright (c) 2021-2022 The Pybricks Authors
import { lt } from 'semver';
import { pythonVersionToSemver } from './version';
describe('pythonVersionToSemver', () => {
@@ -14,6 +15,16 @@ describe('pythonVersionToSemver', () => {
expect(pythonVersionToSemver(version)).toBe(expected);
});
test.each([
['v1.0.0a1', 'v1.0.0b1'],
['v1.0.0b1', 'v1.0.0c1'],
['v1.0.0c1', 'v1.0.0'],
])('%s < %s', (first, second) => {
expect(
lt(pythonVersionToSemver(first), pythonVersionToSemver(second)),
).toBeTruthy();
});
test('invalid version', () => {
expect(() => pythonVersionToSemver('not a version')).toThrow();
});