mirror of
https://github.com/lensapp/lens.git
synced 2024-11-10 10:36:25 +03:00
Change engines.lens signature to only respect minimums (#5290)
Co-authored-by: Jim Ehrismann <40840436+jim-docker@users.noreply.github.com>
This commit is contained in:
parent
b1df407715
commit
74b4a752eb
@ -39,7 +39,8 @@ utils.describeIf(minikubeReady(TEST_NAMESPACE))("Minikube based tests", () => {
|
||||
await frame.waitForSelector(`.Menu >> text="Remove"`);
|
||||
});
|
||||
|
||||
it("opens cluster settings by clicking link in no-metrics area", async () => {
|
||||
// FIXME: failed locally since metrics might already exist, cc @aleksfront
|
||||
it.skip("opens cluster settings by clicking link in no-metrics area", async () => {
|
||||
await frame.locator("text=Open cluster settings >> nth=0").click();
|
||||
await window.waitForSelector(`[data-testid="metrics-header"]`);
|
||||
});
|
||||
|
@ -1,128 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { rawIsCompatibleExtension } from "../extension-compatibility";
|
||||
import { Console } from "console";
|
||||
import { stdout, stderr } from "process";
|
||||
import type { LensExtensionManifest } from "../lens-extension";
|
||||
import { SemVer } from "semver";
|
||||
|
||||
console = new Console(stdout, stderr);
|
||||
|
||||
describe("extension compatibility", () => {
|
||||
describe("appSemVer with no prerelease tag", () => {
|
||||
const isCompatibleExtension = rawIsCompatibleExtension(new SemVer("5.0.3"));
|
||||
|
||||
it("has no extension comparator", () => {
|
||||
const manifest = { name: "extensionName", version: "0.0.1" };
|
||||
|
||||
expect(isCompatibleExtension(manifest)).toBe(false);
|
||||
});
|
||||
|
||||
it.each([
|
||||
{
|
||||
comparator: "",
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
comparator: "bad comparator",
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
comparator: "^4.0.0",
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
comparator: "^5.0.0",
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
comparator: "^6.0.0",
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
comparator: "^4.0.0-alpha.1",
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
comparator: "^5.0.0-alpha.1",
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
comparator: "^6.0.0-alpha.1",
|
||||
expected: false,
|
||||
},
|
||||
])("extension comparator test: %p", ({ comparator, expected }) => {
|
||||
const manifest: LensExtensionManifest = { name: "extensionName", version: "0.0.1", engines: { lens: comparator }};
|
||||
|
||||
expect(isCompatibleExtension(manifest)).toBe(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe("appSemVer with prerelease tag", () => {
|
||||
const isCompatibleExtension = rawIsCompatibleExtension(new SemVer("5.0.3-beta.3"));
|
||||
|
||||
it("^5.1.0 should work when lens' version is 5.1.0-latest.123456789", () => {
|
||||
const comparer = rawIsCompatibleExtension(new SemVer("5.1.0-latest.123456789"));
|
||||
|
||||
expect(comparer({ name: "extensionName", version: "0.0.1", engines: { lens: "^5.1.0" }})).toBe(true);
|
||||
});
|
||||
|
||||
it("^5.1.0 should not when lens' version is 5.1.0-beta.1.123456789", () => {
|
||||
const comparer = rawIsCompatibleExtension(new SemVer("5.1.0-beta.123456789"));
|
||||
|
||||
expect(comparer({ name: "extensionName", version: "0.0.1", engines: { lens: "^5.1.0" }})).toBe(false);
|
||||
});
|
||||
|
||||
it("^5.1.0 should not when lens' version is 5.1.0-alpha.1.123456789", () => {
|
||||
const comparer = rawIsCompatibleExtension(new SemVer("5.1.0-alpha.123456789"));
|
||||
|
||||
expect(comparer({ name: "extensionName", version: "0.0.1", engines: { lens: "^5.1.0" }})).toBe(false);
|
||||
});
|
||||
|
||||
it("has no extension comparator", () => {
|
||||
const manifest = { name: "extensionName", version: "0.0.1" };
|
||||
|
||||
expect(isCompatibleExtension(manifest)).toBe(false);
|
||||
});
|
||||
|
||||
it.each([
|
||||
{
|
||||
comparator: "",
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
comparator: "bad comparator",
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
comparator: "^4.0.0",
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
comparator: "^5.0.0",
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
comparator: "^6.0.0",
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
comparator: "^4.0.0-alpha.1",
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
comparator: "^5.0.0-alpha.1",
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
comparator: "^6.0.0-alpha.1",
|
||||
expected: false,
|
||||
},
|
||||
])("extension comparator test: %p", ({ comparator, expected }) => {
|
||||
expect(isCompatibleExtension({ name: "extensionName", version: "0.0.1", engines: { lens: comparator }})).toBe(expected);
|
||||
});
|
||||
});
|
||||
});
|
121
src/extensions/__tests__/is-compatible-extension.test.ts
Normal file
121
src/extensions/__tests__/is-compatible-extension.test.ts
Normal file
@ -0,0 +1,121 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import semver from "semver";
|
||||
import {
|
||||
isCompatibleExtension,
|
||||
} from "../extension-discovery/is-compatible-extension/is-compatible-extension";
|
||||
import type { LensExtensionManifest } from "../lens-extension";
|
||||
|
||||
describe("Extension/App versions compatibility check", () => {
|
||||
it("is compatible with exact version matching", () => {
|
||||
expect(isCompatibleExtension({
|
||||
appSemVer: semver.coerce("5.5.0"),
|
||||
})(getExtensionManifestMock({
|
||||
lensEngine: "5.5.0",
|
||||
}))).toBeTruthy();
|
||||
});
|
||||
|
||||
it("is compatible with upper %PATCH versions of base app", () => {
|
||||
expect(isCompatibleExtension({
|
||||
appSemVer: semver.coerce("5.5.5"),
|
||||
})(getExtensionManifestMock({
|
||||
lensEngine: "5.5.0",
|
||||
}))).toBeTruthy();
|
||||
});
|
||||
|
||||
it("is compatible with upper %MINOR version of base app", () => {
|
||||
expect(isCompatibleExtension({
|
||||
appSemVer: semver.coerce("5.6.0"),
|
||||
})(getExtensionManifestMock({
|
||||
lensEngine: "5.5.0",
|
||||
}))).toBeTruthy();
|
||||
|
||||
expect(isCompatibleExtension({
|
||||
appSemVer: semver.coerce("5.5.0-alpha.0"),
|
||||
})(getExtensionManifestMock({
|
||||
lensEngine: "^5.5.0",
|
||||
}))).toBeTruthy();
|
||||
|
||||
expect(isCompatibleExtension({
|
||||
appSemVer: semver.coerce("5.5"),
|
||||
})(getExtensionManifestMock({
|
||||
lensEngine: "^5.6.0",
|
||||
}))).toBeFalsy();
|
||||
});
|
||||
|
||||
it("is not compatible with upper %MAJOR version of base app", () => {
|
||||
expect(isCompatibleExtension({
|
||||
appSemVer: semver.coerce("5.5.0"), // current lens-version
|
||||
})(getExtensionManifestMock({
|
||||
lensEngine: "6.0.0",
|
||||
}))).toBeFalsy(); // extension with lens@6.0 is not compatible with app@5.5
|
||||
|
||||
expect(isCompatibleExtension({
|
||||
appSemVer: semver.coerce("6.0.0"), // current lens-version
|
||||
})(getExtensionManifestMock({
|
||||
lensEngine: "5.5.0",
|
||||
}))).toBeFalsy(); // extension with lens@5.5 is not compatible with app@6.0
|
||||
});
|
||||
|
||||
it("is compatible with lensEngine with prerelease", () => {
|
||||
expect(isCompatibleExtension({
|
||||
appSemVer: semver.parse("5.5.0-alpha.0"),
|
||||
})(getExtensionManifestMock({
|
||||
lensEngine: "^5.4.0-alpha.0",
|
||||
}))).toBeTruthy();
|
||||
});
|
||||
|
||||
describe("supported formats for manifest.engines.lens", () => {
|
||||
it("short version format for engines.lens", () => {
|
||||
expect(isCompatibleExtension({
|
||||
appSemVer: semver.coerce("5.5.0"),
|
||||
})(getExtensionManifestMock({
|
||||
lensEngine: "5.5",
|
||||
}))).toBeTruthy();
|
||||
});
|
||||
|
||||
it("validates version and throws if incorrect format", () => {
|
||||
expect(() => isCompatibleExtension({
|
||||
appSemVer: semver.coerce("1.0.0"),
|
||||
})(getExtensionManifestMock({
|
||||
lensEngine: "1.0",
|
||||
}))).not.toThrow();
|
||||
|
||||
expect(() => isCompatibleExtension({
|
||||
appSemVer: semver.coerce("1.0.0"),
|
||||
})(getExtensionManifestMock({
|
||||
lensEngine: "^1.0",
|
||||
}))).not.toThrow();
|
||||
|
||||
expect(() => isCompatibleExtension({
|
||||
appSemVer: semver.coerce("1.0.0"),
|
||||
})(getExtensionManifestMock({
|
||||
lensEngine: ">=2.0",
|
||||
}))).toThrow(/Invalid format/i);
|
||||
});
|
||||
|
||||
it("'*' cannot be used for any version matching (at least in the prefix)", () => {
|
||||
expect(() => isCompatibleExtension({
|
||||
appSemVer: semver.coerce("1.0.0"),
|
||||
})(getExtensionManifestMock({
|
||||
lensEngine: "*",
|
||||
}))).toThrowError(/Invalid format/i);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function getExtensionManifestMock(
|
||||
{
|
||||
lensEngine = "1.0",
|
||||
} = {}): LensExtensionManifest {
|
||||
return {
|
||||
name: "some-extension",
|
||||
version: "1.0",
|
||||
engines: {
|
||||
lens: lensEngine,
|
||||
},
|
||||
};
|
||||
}
|
@ -17,6 +17,7 @@ describe("lens extension", () => {
|
||||
manifest: {
|
||||
name: "foo-bar",
|
||||
version: "0.1.1",
|
||||
engines: { lens: "^5.5.0" },
|
||||
},
|
||||
id: "/this/is/fake/package.json",
|
||||
absolutePath: "/absolute/fake/",
|
||||
|
@ -1,49 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import semver, { SemVer } from "semver";
|
||||
import { appSemVer, isProduction } from "../common/vars";
|
||||
import type { LensExtensionManifest } from "./lens-extension";
|
||||
|
||||
export function rawIsCompatibleExtension(version: SemVer): (manifest: LensExtensionManifest) => boolean {
|
||||
const { major, minor, patch, prerelease: oldPrelease } = version;
|
||||
let prerelease = "";
|
||||
|
||||
if (oldPrelease.length > 0) {
|
||||
const [first] = oldPrelease;
|
||||
|
||||
if (first === "alpha" || first === "beta" || first === "rc") {
|
||||
/**
|
||||
* Strip the build IDs and "latest" prerelease tag as that is not really
|
||||
* a part of API version
|
||||
*/
|
||||
prerelease = `-${oldPrelease.slice(0, 2).join(".")}`;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* We unfortunately have to format as string because the constructor only
|
||||
* takes an instance or a string.
|
||||
*/
|
||||
const strippedVersion = new SemVer(`${major}.${minor}.${patch}${prerelease}`, { includePrerelease: true });
|
||||
|
||||
return (manifest: LensExtensionManifest): boolean => {
|
||||
if (manifest.engines?.lens) {
|
||||
/**
|
||||
* include Lens's prerelease tag in the matching so the extension's
|
||||
* compatibility is not limited by it
|
||||
*/
|
||||
return semver.satisfies(strippedVersion, manifest.engines.lens, { includePrerelease: true });
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
export const isCompatibleExtension = rawIsCompatibleExtension(appSemVer);
|
||||
|
||||
export function isCompatibleBundledExtension(manifest: LensExtensionManifest): boolean {
|
||||
return !isProduction || manifest.version === appSemVer.raw;
|
||||
}
|
@ -74,6 +74,9 @@ describe("ExtensionDiscovery", () => {
|
||||
return {
|
||||
name: "my-extension",
|
||||
version: "1.0.0",
|
||||
engines: {
|
||||
lens: "5.0.0",
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
@ -104,10 +107,13 @@ describe("ExtensionDiscovery", () => {
|
||||
id: path.normalize("some-directory-for-user-data/node_modules/my-extension/package.json"),
|
||||
isBundled: false,
|
||||
isEnabled: false,
|
||||
isCompatible: false,
|
||||
isCompatible: true,
|
||||
manifest: {
|
||||
name: "my-extension",
|
||||
version: "1.0.0",
|
||||
engines: {
|
||||
lens: "5.0.0",
|
||||
},
|
||||
},
|
||||
manifestPath: path.normalize("some-directory-for-user-data/node_modules/my-extension/package.json"),
|
||||
});
|
||||
|
@ -2,51 +2,38 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import semver, { SemVer } from "semver";
|
||||
import semver, { type SemVer } from "semver";
|
||||
import type { LensExtensionManifest } from "../../lens-extension";
|
||||
|
||||
interface Dependencies {
|
||||
appSemVer: SemVer;
|
||||
}
|
||||
|
||||
export const isCompatibleExtension = ({
|
||||
appSemVer,
|
||||
}: Dependencies): ((manifest: LensExtensionManifest) => boolean) => {
|
||||
const { major, minor, patch, prerelease: oldPrelease } = appSemVer;
|
||||
let prerelease = "";
|
||||
|
||||
if (oldPrelease.length > 0) {
|
||||
const [first] = oldPrelease;
|
||||
|
||||
if (first === "alpha" || first === "beta" || first === "rc") {
|
||||
/**
|
||||
* Strip the build IDs and "latest" prerelease tag as that is not really
|
||||
* a part of API version
|
||||
*/
|
||||
prerelease = `-${oldPrelease.slice(0, 2).join(".")}`;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* We unfortunately have to format as string because the constructor only
|
||||
* takes an instance or a string.
|
||||
*/
|
||||
const strippedVersion = new SemVer(
|
||||
`${major}.${minor}.${patch}${prerelease}`,
|
||||
{ includePrerelease: true },
|
||||
);
|
||||
|
||||
export const isCompatibleExtension = ({ appSemVer }: Dependencies): ((manifest: LensExtensionManifest) => boolean) => {
|
||||
return (manifest: LensExtensionManifest): boolean => {
|
||||
if (manifest.engines?.lens) {
|
||||
/**
|
||||
* include Lens's prerelease tag in the matching so the extension's
|
||||
* compatibility is not limited by it
|
||||
*/
|
||||
return semver.satisfies(strippedVersion, manifest.engines.lens, {
|
||||
includePrerelease: true,
|
||||
});
|
||||
const appVersion = appSemVer.raw.split("-")[0]; // drop prerelease version if any, e.g. "-alpha.0"
|
||||
const manifestLensEngine = manifest.engines.lens;
|
||||
const validVersion = manifestLensEngine.match(/^[\^0-9]\d*\.\d+\b/); // must start from ^ or number
|
||||
|
||||
if (!validVersion) {
|
||||
const errorInfo = [
|
||||
`Invalid format for "manifest.engines.lens"="${manifestLensEngine}"`,
|
||||
`Range versions can only be specified starting with '^'.`,
|
||||
`Otherwise it's recommended to use plain %MAJOR.%MINOR to match with supported Lens version.`,
|
||||
].join("\n");
|
||||
|
||||
throw new Error(errorInfo);
|
||||
}
|
||||
|
||||
return false;
|
||||
const { major: extMajor, minor: extMinor } = semver.coerce(manifestLensEngine, {
|
||||
loose: true,
|
||||
includePrerelease: false,
|
||||
});
|
||||
const supportedVersionsByExtension: string = semver.validRange(`^${extMajor}.${extMinor}`);
|
||||
|
||||
return semver.satisfies(appVersion, supportedVersionsByExtension, {
|
||||
loose: true,
|
||||
includePrerelease: false,
|
||||
});
|
||||
};
|
||||
};
|
||||
|
@ -4,17 +4,14 @@
|
||||
*/
|
||||
|
||||
import type { InstalledExtension } from "./extension-discovery/extension-discovery";
|
||||
import { action, observable, makeObservable, computed } from "mobx";
|
||||
import { action, computed, makeObservable, observable } from "mobx";
|
||||
import logger from "../main/logger";
|
||||
import type { ProtocolHandlerRegistration } from "./registries";
|
||||
import type { PackageJson } from "type-fest";
|
||||
import type { Disposer } from "../common/utils";
|
||||
import { disposer } from "../common/utils";
|
||||
import type {
|
||||
LensExtensionDependencies } from "./lens-extension-set-dependencies";
|
||||
import {
|
||||
setLensExtensionDependencies,
|
||||
} from "./lens-extension-set-dependencies";
|
||||
import type { LensExtensionDependencies } from "./lens-extension-set-dependencies";
|
||||
import { setLensExtensionDependencies } from "./lens-extension-set-dependencies";
|
||||
|
||||
export type LensExtensionId = string; // path to manifest (package.json)
|
||||
export type LensExtensionConstructor = new (...args: ConstructorParameters<typeof LensExtension>) => LensExtension;
|
||||
@ -24,6 +21,15 @@ export interface LensExtensionManifest extends PackageJson {
|
||||
version: string;
|
||||
main?: string; // path to %ext/dist/main.js
|
||||
renderer?: string; // path to %ext/dist/renderer.js
|
||||
/**
|
||||
* Supported Lens version engine by extension could be defined in `manifest.engines.lens`
|
||||
* Only MAJOR.MINOR version is taken in consideration.
|
||||
*/
|
||||
engines: {
|
||||
lens: string; // "semver"-package format
|
||||
npm?: string;
|
||||
node?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export const Disposers = Symbol();
|
||||
|
@ -109,7 +109,7 @@ class SomeTestExtension extends LensMainExtension {
|
||||
isBundled: false,
|
||||
isCompatible: false,
|
||||
isEnabled: false,
|
||||
manifest: { name: id, version: "some-version" },
|
||||
manifest: { name: id, version: "some-version", engines: { lens: "^5.5.0" }},
|
||||
manifestPath: "irrelevant",
|
||||
});
|
||||
|
||||
|
@ -87,6 +87,7 @@ describe("protocol router tests", () => {
|
||||
manifest: {
|
||||
name: "@mirantis/minikube",
|
||||
version: "0.1.1",
|
||||
engines: { lens: "^5.5.0" },
|
||||
},
|
||||
isBundled: false,
|
||||
isEnabled: true,
|
||||
@ -162,6 +163,7 @@ describe("protocol router tests", () => {
|
||||
manifest: {
|
||||
name: "@foobar/icecream",
|
||||
version: "0.1.1",
|
||||
engines: { lens: "^5.5.0" },
|
||||
},
|
||||
isBundled: false,
|
||||
isEnabled: true,
|
||||
@ -203,6 +205,7 @@ describe("protocol router tests", () => {
|
||||
manifest: {
|
||||
name: "@foobar/icecream",
|
||||
version: "0.1.1",
|
||||
engines: { lens: "^5.5.0" },
|
||||
},
|
||||
isBundled: false,
|
||||
isEnabled: true,
|
||||
@ -228,6 +231,7 @@ describe("protocol router tests", () => {
|
||||
manifest: {
|
||||
name: "icecream",
|
||||
version: "0.1.1",
|
||||
engines: { lens: "^5.5.0" },
|
||||
},
|
||||
isBundled: false,
|
||||
isEnabled: true,
|
||||
|
@ -113,7 +113,7 @@ class SomeTestExtension extends LensMainExtension {
|
||||
isBundled: false,
|
||||
isCompatible: false,
|
||||
isEnabled: false,
|
||||
manifest: { name: id, version: "some-version" },
|
||||
manifest: { name: id, version: "some-version", engines: { lens: "^5.5.0" }},
|
||||
manifestPath: "irrelevant",
|
||||
});
|
||||
|
||||
|
@ -77,6 +77,7 @@ describe("Extensions", () => {
|
||||
manifest: {
|
||||
name: "test",
|
||||
version: "1.2.3",
|
||||
engines: { lens: "^5.5.0" },
|
||||
},
|
||||
absolutePath: "/absolute/path",
|
||||
manifestPath: "/symlinked/path/package.json",
|
||||
|
@ -102,7 +102,7 @@ class TestExtension extends LensRendererExtension {
|
||||
isBundled: false,
|
||||
isCompatible: false,
|
||||
isEnabled: false,
|
||||
manifest: { name: id, version: "some-version" },
|
||||
manifest: { name: id, version: "some-version", engines: { lens: "^5.5.0" }},
|
||||
manifestPath: "irrelevant",
|
||||
});
|
||||
|
||||
|
@ -42,7 +42,7 @@ class SomeTestExtension extends LensRendererExtension {
|
||||
isBundled: false,
|
||||
isCompatible: false,
|
||||
isEnabled: false,
|
||||
manifest: { name: "some-id", version: "some-version" },
|
||||
manifest: { name: "some-id", version: "some-version", engines: { lens: "^5.5.0" }},
|
||||
manifestPath: "irrelevant",
|
||||
});
|
||||
|
||||
|
@ -255,7 +255,7 @@ class SomeTestExtension extends LensRendererExtension {
|
||||
isBundled: false,
|
||||
isCompatible: false,
|
||||
isEnabled: false,
|
||||
manifest: { name: "some-id", version: "some-version" },
|
||||
manifest: { name: "some-id", version: "some-version", engines: { lens: "^5.5.0" }},
|
||||
manifestPath: "irrelevant",
|
||||
});
|
||||
|
||||
|
@ -26,7 +26,7 @@ class SomeTestExtension extends LensRendererExtension {
|
||||
isBundled: false,
|
||||
isCompatible: false,
|
||||
isEnabled: false,
|
||||
manifest: { name: "some-id", version: "some-version" },
|
||||
manifest: { name: "some-id", version: "some-version", engines: { lens: "^5.5.0" }},
|
||||
manifestPath: "irrelevant",
|
||||
});
|
||||
|
||||
|
@ -13,7 +13,7 @@ export const getRendererExtensionFake = ({ id, ...rest }: Partial<LensRendererEx
|
||||
isBundled: false,
|
||||
isCompatible: false,
|
||||
isEnabled: false,
|
||||
manifest: { name: id, version: "some-version" },
|
||||
manifest: { name: id, version: "some-version", engines: { lens: "^5.5.0" }},
|
||||
manifestPath: "irrelevant",
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user