mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 09:36:27 +00:00
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:
+3
-3
@@ -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
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user