mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Initial support for validating extension engines.lens version (#2884)
This commit is contained in:
1 parent
d6e72ddc1c
commit
3847a91758
12 files changed
+70
-43
No files matched your search
@@ -93,6 +93,7 @@ describe("ExtensionDiscovery", () => {
|
||||
id: path.normalize("node_modules/my-extension/package.json"),
|
||||
isBundled: false,
|
||||
isEnabled: false,
|
||||
isCompatible: false,
|
||||
manifest: {
|
||||
name: "my-extension",
|
||||
},
|
||||
|
||||
@@ -38,7 +38,8 @@ describe("lens extension", () => {
|
||||
absolutePath: "/absolute/fake/",
|
||||
manifestPath: "/this/is/fake/package.json",
|
||||
isBundled: false,
|
||||
isEnabled: true
|
||||
isEnabled: true,
|
||||
isCompatible: true
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -30,10 +30,13 @@ import { broadcastMessage, handleRequest, requestMain, subscribeToBroadcast } fr
|
||||
import { Singleton, toJS } from "../common/utils";
|
||||
import logger from "../main/logger";
|
||||
import { ExtensionInstallationStateStore } from "../renderer/components/+extensions/extension-install.store";
|
||||
import { extensionInstaller, PackageJson } from "./extension-installer";
|
||||
import { extensionInstaller } from "./extension-installer";
|
||||
import { ExtensionsStore } from "./extensions-store";
|
||||
import { ExtensionLoader } from "./extension-loader";
|
||||
import type { LensExtensionId, LensExtensionManifest } from "./lens-extension";
|
||||
import type { PackageJson } from "type-fest";
|
||||
import semver from "semver";
|
||||
import { appSemVer } from "../common/vars";
|
||||
import { isProduction } from "../common/vars";
|
||||
|
||||
export interface InstalledExtension {
|
||||
@@ -48,6 +51,7 @@ export interface InstalledExtension {
|
||||
// Absolute to the symlinked package.json file
|
||||
readonly manifestPath: string;
|
||||
readonly isBundled: boolean; // defined in project root's package.json
|
||||
readonly isCompatible: boolean;
|
||||
isEnabled: boolean;
|
||||
}
|
||||
|
||||
@@ -349,12 +353,17 @@ export class ExtensionDiscovery extends Singleton {
|
||||
*/
|
||||
protected async getByManifest(manifestPath: string, { isBundled = false } = {}): Promise<InstalledExtension | null> {
|
||||
try {
|
||||
const manifest = await fse.readJson(manifestPath);
|
||||
const manifest = await fse.readJson(manifestPath) as LensExtensionManifest;
|
||||
const installedManifestPath = this.getInstalledManifestPath(manifest.name);
|
||||
const isEnabled = isBundled || ExtensionsStore.getInstance().isEnabled(installedManifestPath);
|
||||
const extensionDir = path.dirname(manifestPath);
|
||||
const npmPackage = path.join(extensionDir, `${manifest.name}-${manifest.version}.tgz`);
|
||||
const absolutePath = (isProduction && await fse.pathExists(npmPackage)) ? npmPackage : extensionDir;
|
||||
let isCompatible = isBundled;
|
||||
|
||||
if (manifest.engines?.lens) {
|
||||
isCompatible = semver.satisfies(appSemVer, manifest.engines.lens);
|
||||
}
|
||||
|
||||
return {
|
||||
id: installedManifestPath,
|
||||
@@ -362,7 +371,8 @@ export class ExtensionDiscovery extends Singleton {
|
||||
manifestPath: installedManifestPath,
|
||||
manifest,
|
||||
isBundled,
|
||||
isEnabled
|
||||
isEnabled,
|
||||
isCompatible
|
||||
};
|
||||
} catch (error) {
|
||||
if (error.code === "ENOTDIR") {
|
||||
|
||||
@@ -25,17 +25,10 @@ import fs from "fs-extra";
|
||||
import path from "path";
|
||||
import logger from "../main/logger";
|
||||
import { extensionPackagesRoot } from "./extension-loader";
|
||||
import type { PackageJson } from "type-fest";
|
||||
|
||||
const logModule = "[EXTENSION-INSTALLER]";
|
||||
|
||||
type Dependencies = {
|
||||
[name: string]: string;
|
||||
};
|
||||
|
||||
// Type for the package.json file that is written by ExtensionInstaller
|
||||
export type PackageJson = {
|
||||
dependencies: Dependencies;
|
||||
};
|
||||
|
||||
/**
|
||||
* Installs dependencies for extensions
|
||||
|
||||
@@ -301,7 +301,7 @@ export class ExtensionLoader extends Singleton {
|
||||
for (const [extId, extension] of installedExtensions) {
|
||||
const alreadyInit = this.instances.has(extId);
|
||||
|
||||
if (extension.isEnabled && !alreadyInit) {
|
||||
if (extension.isCompatible && extension.isEnabled && !alreadyInit) {
|
||||
try {
|
||||
const LensExtensionClass = this.requireExtension(extension);
|
||||
|
||||
|
||||
@@ -24,18 +24,17 @@ import { action, observable, makeObservable } from "mobx";
|
||||
import { FilesystemProvisionerStore } from "../main/extension-filesystem";
|
||||
import logger from "../main/logger";
|
||||
import type { ProtocolHandlerRegistration } from "./registries";
|
||||
import type { PackageJson } from "type-fest";
|
||||
import { Disposer, disposer } from "../common/utils";
|
||||
|
||||
export type LensExtensionId = string; // path to manifest (package.json)
|
||||
export type LensExtensionConstructor = new (...args: ConstructorParameters<typeof LensExtension>) => LensExtension;
|
||||
|
||||
export interface LensExtensionManifest {
|
||||
export interface LensExtensionManifest extends PackageJson {
|
||||
name: string;
|
||||
version: string;
|
||||
description?: string;
|
||||
main?: string; // path to %ext/dist/main.js
|
||||
renderer?: string; // path to %ext/dist/renderer.js
|
||||
lens?: object; // fixme: add more required fields for validation
|
||||
}
|
||||
|
||||
export const Disposers = Symbol();
|
||||
@@ -91,7 +90,7 @@ export class LensExtension {
|
||||
try {
|
||||
await this.onActivate();
|
||||
this.isEnabled = true;
|
||||
|
||||
|
||||
this[Disposers].push(...await register(this));
|
||||
logger.info(`[EXTENSION]: enabled ${this.name}@${this.version}`);
|
||||
} catch (error) {
|
||||
|
||||
@@ -40,7 +40,8 @@ describe("getPageUrl", () => {
|
||||
absolutePath: "/absolute/fake/",
|
||||
manifestPath: "/this/is/fake/package.json",
|
||||
isBundled: false,
|
||||
isEnabled: true
|
||||
isEnabled: true,
|
||||
isCompatible: true
|
||||
});
|
||||
globalPageRegistry.add({
|
||||
id: "page-with-params",
|
||||
@@ -107,7 +108,8 @@ describe("globalPageRegistry", () => {
|
||||
absolutePath: "/absolute/fake/",
|
||||
manifestPath: "/this/is/fake/package.json",
|
||||
isBundled: false,
|
||||
isEnabled: true
|
||||
isEnabled: true,
|
||||
isCompatible: true
|
||||
});
|
||||
globalPageRegistry.add([
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user