From 5f1314427c4054545ba5c2cfa0f1555f6de421b2 Mon Sep 17 00:00:00 2001 From: Lauri Nevala Date: Tue, 24 Nov 2020 11:35:00 +0200 Subject: [PATCH] Check if extension is enabled in store unless it is bundled Signed-off-by: Lauri Nevala --- src/extensions/extension-discovery.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/extensions/extension-discovery.ts b/src/extensions/extension-discovery.ts index bb1d1db420..a6a0879c8d 100644 --- a/src/extensions/extension-discovery.ts +++ b/src/extensions/extension-discovery.ts @@ -6,6 +6,7 @@ import path from "path"; import { getBundledExtensions } from "../common/utils/app-version"; import logger from "../main/logger"; import { extensionInstaller, PackageJson } from "./extension-installer"; +import { extensionsStore } from "./extensions-store"; import type { LensExtensionId, LensExtensionManifest } from "./lens-extension"; export interface InstalledExtension { @@ -91,7 +92,7 @@ export class ExtensionDiscovery { init() { this.watchExtensions(); } - + /** * Watches for added/removed local extensions. * Dependencies are installed automatically after an extension folder is copied. @@ -213,24 +214,31 @@ export class ExtensionDiscovery { } } - protected async getByManifest(manifestPath: string, { isBundled = false, isEnabled = isBundled }: { + protected async getByManifest(manifestPath: string, { isBundled = false }: { isBundled?: boolean; - isEnabled?: boolean; } = {}): Promise { let manifestJson: LensExtensionManifest; + let isEnabled: boolean; try { // check manifest file for existence fs.accessSync(manifestPath, fs.constants.F_OK); manifestJson = __non_webpack_require__(manifestPath); + const installedManifestPath = path.join(this.nodeModulesPath, manifestJson.name, "package.json"); this.packagesJson.dependencies[manifestJson.name] = path.dirname(manifestPath); + if (!isBundled) { + isEnabled = extensionsStore.isEnabled(installedManifestPath); + } else { + isEnabled = true; + } + return { - manifestPath: path.join(this.nodeModulesPath, manifestJson.name, "package.json"), + manifestPath: installedManifestPath, manifest: manifestJson, isBundled, - isEnabled, + isEnabled }; } catch (error) { logger.error(`${logModule}: can't install extension at ${manifestPath}: ${error}`, { manifestJson }); @@ -316,13 +324,12 @@ export class ExtensionDiscovery { /** * Loads extension from absolute path, updates this.packagesJson to include it and returns the extension. */ - async loadExtensionFromPath(absPath: string, { isBundled = false, isEnabled = isBundled }: { + async loadExtensionFromPath(absPath: string, { isBundled = false }: { isBundled?: boolean; - isEnabled?: boolean; } = {}): Promise { const manifestPath = path.resolve(absPath, manifestFilename); - return this.getByManifest(manifestPath, { isBundled, isEnabled }); + return this.getByManifest(manifestPath, { isBundled }); } }