1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

fix is-compatible-extension.test.ts types

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-05-13 11:57:47 -04:00
parent a27c092c40
commit fac1ce9678
2 changed files with 13 additions and 11 deletions

View File

@ -102,6 +102,12 @@ describe("Extension/App versions compatibility check", () => {
})(getExtensionManifestMock({
lensEngine: ">=2.0",
}))).toThrow(/Invalid format/i);
expect(() => isCompatibleExtension({
appSemVer: semverCoerce("1.0.0"),
})(getExtensionManifestMock({
lensEngine: ">=2.0 <3.0",
}))).toThrow(/Invalid format/i);
});
it("'*' cannot be used for any version matching (at least in the prefix)", () => {

View File

@ -2,7 +2,6 @@
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import assert from "assert";
import semver, { type SemVer } from "semver";
import type { LensExtensionManifest } from "../../lens-extension";
@ -14,12 +13,9 @@ export const isCompatibleExtension = ({ appSemVer }: Dependencies): ((manifest:
return (manifest: LensExtensionManifest): boolean => {
const appVersion = appSemVer.raw.split("-")[0]; // drop prerelease version if any, e.g. "-alpha.0"
const manifestLensEngine = manifest.engines.lens;
const lensEngine = semver.coerce(manifestLensEngine, {
loose: true,
includePrerelease: false,
});
const validVersion = manifestLensEngine.match(/^[\^0-9]\d*\.\d+\b/); // must start from ^ or number
if (!lensEngine) {
if (!validVersion) {
const errorInfo = [
`Invalid format for "manifest.engines.lens"="${manifestLensEngine}"`,
`Range versions can only be specified starting with '^'.`,
@ -29,11 +25,11 @@ export const isCompatibleExtension = ({ appSemVer }: Dependencies): ((manifest:
throw new Error(errorInfo);
}
const { major: extMajor, minor: extMinor } = lensEngine;
const supportedRange = `^${extMajor}.${extMinor}`;
const supportedVersionsByExtension = semver.validRange(supportedRange);
assert(supportedVersionsByExtension, `${supportedRange} should always be a valid semver range`);
const { major: extMajor, minor: extMinor } = semver.coerce(manifestLensEngine, {
loose: true,
includePrerelease: false,
}) as semver.SemVer;
const supportedVersionsByExtension = semver.validRange(`^${extMajor}.${extMinor}`) as string;
return semver.satisfies(appVersion, supportedVersionsByExtension, {
loose: true,