Skip to content

Commit b366f77

Browse files
committed
tree-wide: fix version comparison
We were using satisfies in a few places where we should have just been using a comparison operator.
1 parent 2523101 commit b366f77

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

src/ble/sagas.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import { firmwareVersion } from '@pybricks/firmware';
1010
import { Task, buffers, eventChannel } from 'redux-saga';
11-
import { satisfies } from 'semver';
11+
import { lt, satisfies } from 'semver';
1212
import {
1313
call,
1414
cancel,
@@ -223,9 +223,9 @@ function* handleBleConnectPybricks(): Generator {
223223

224224
// notify user if old firmware
225225
if (
226-
satisfies(
226+
lt(
227227
pythonVersionToSemver(firmwareRevision),
228-
`<${pythonVersionToSemver(firmwareVersion)}`,
228+
pythonVersionToSemver(firmwareVersion),
229229
)
230230
) {
231231
yield* put(alertsShowAlert('ble', 'oldFirmware'));

src/hub/reducers.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,7 @@ const preferredFileFormat: Reducer<FileFormat | null> = (state = null, action) =
193193
if (blePybricksServiceDidNotReceiveHubCapabilities.matches(action)) {
194194
// HACK: there is not a good way to get the supported MPY ABI version
195195
// from a running hub, so we use heuristics on the firmware version.
196-
if (
197-
semver.satisfies(
198-
pythonVersionToSemver(action.firmwareVersion),
199-
'>=3.2.0-beta.2',
200-
)
201-
) {
196+
if (semver.lte(pythonVersionToSemver(action.firmwareVersion), '3.2.0-beta.2')) {
202197
return FileFormat.Mpy6;
203198
}
204199

src/utils/version.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: MIT
2-
// Copyright (c) 2021 The Pybricks Authors
2+
// Copyright (c) 2021-2022 The Pybricks Authors
33

4+
import { lt } from 'semver';
45
import { pythonVersionToSemver } from './version';
56

67
describe('pythonVersionToSemver', () => {
@@ -14,6 +15,16 @@ describe('pythonVersionToSemver', () => {
1415
expect(pythonVersionToSemver(version)).toBe(expected);
1516
});
1617

18+
test.each([
19+
['v1.0.0a1', 'v1.0.0b1'],
20+
['v1.0.0b1', 'v1.0.0c1'],
21+
['v1.0.0c1', 'v1.0.0'],
22+
])('%s < %s', (first, second) => {
23+
expect(
24+
lt(pythonVersionToSemver(first), pythonVersionToSemver(second)),
25+
).toBeTruthy();
26+
});
27+
1728
test('invalid version', () => {
1829
expect(() => pythonVersionToSemver('not a version')).toThrow();
1930
});

0 commit comments

Comments
 (0)