diff --git a/src/ble/sagas.ts b/src/ble/sagas.ts index b22c3363..e5aa87e8 100644 --- a/src/ble/sagas.ts +++ b/src/ble/sagas.ts @@ -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')); diff --git a/src/hub/reducers.ts b/src/hub/reducers.ts index 583482ab..ec219b4c 100644 --- a/src/hub/reducers.ts +++ b/src/hub/reducers.ts @@ -193,12 +193,7 @@ const preferredFileFormat: Reducer = (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; } diff --git a/src/utils/version.test.ts b/src/utils/version.test.ts index 1757f301..f5f62bef 100644 --- a/src/utils/version.test.ts +++ b/src/utils/version.test.ts @@ -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(); });