From 89c8bb54d366f7cb6e1a1ac52e56e07864716ae8 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Mon, 19 Dec 2022 09:03:41 -0500 Subject: [PATCH] Switch bundled extension declarations to injection token Signed-off-by: Sebastian Malton --- package.json | 3 +-- .../extension-discovery/bundled-extension-path.ts | 10 ++++++++++ .../extension-discovery.injectable.ts | 4 ++-- .../extension-discovery/extension-discovery.ts | 11 ++++------- 4 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 src/extensions/extension-discovery/bundled-extension-path.ts diff --git a/package.json b/package.json index 99fdec1759..e79087bd34 100644 --- a/package.json +++ b/package.json @@ -58,8 +58,7 @@ "bundledHelmVersion": "3.7.2", "sentryDsn": "", "contentSecurityPolicy": "script-src 'unsafe-eval' 'self'; frame-src http://*.localhost:*/; img-src * data:", - "welcomeRoute": "/welcome", - "extensions": [] + "welcomeRoute": "/welcome" }, "engines": { "node": ">=16 <17" diff --git a/src/extensions/extension-discovery/bundled-extension-path.ts b/src/extensions/extension-discovery/bundled-extension-path.ts new file mode 100644 index 0000000000..a2977feb6f --- /dev/null +++ b/src/extensions/extension-discovery/bundled-extension-path.ts @@ -0,0 +1,10 @@ +/** + * Copyright (c) OpenLens Authors. All rights reserved. + * Licensed under MIT License. See LICENSE in root directory for more information. + */ + +import { getInjectionToken } from "@ogre-tools/injectable"; + +export const bundledExtensionPathInjectionToken = getInjectionToken({ + id: "bundled-extension-path", +}); diff --git a/src/extensions/extension-discovery/extension-discovery.injectable.ts b/src/extensions/extension-discovery/extension-discovery.injectable.ts index 971850c585..37ef8590bf 100644 --- a/src/extensions/extension-discovery/extension-discovery.injectable.ts +++ b/src/extensions/extension-discovery/extension-discovery.injectable.ts @@ -27,8 +27,8 @@ import getRelativePathInjectable from "../../common/path/get-relative-path.injec import joinPathsInjectable from "../../common/path/join-paths.injectable"; import removePathInjectable from "../../common/fs/remove.injectable"; import homeDirectoryPathInjectable from "../../common/os/home-directory-path.injectable"; -import applicationInformationInjectable from "../../common/vars/application-information.injectable"; import lensResourcesDirInjectable from "../../common/vars/lens-resources-dir.injectable"; +import { bundledExtensionPathInjectionToken } from "./bundled-extension-path"; const extensionDiscoveryInjectable = getInjectable({ id: "extension-discovery", @@ -58,7 +58,7 @@ const extensionDiscoveryInjectable = getInjectable({ getRelativePath: di.inject(getRelativePathInjectable), joinPaths: di.inject(joinPathsInjectable), homeDirectoryPath: di.inject(homeDirectoryPathInjectable), - applicationInformation: di.inject(applicationInformationInjectable), + bundledExtensionPaths: di.injectMany(bundledExtensionPathInjectionToken), }), }); diff --git a/src/extensions/extension-discovery/extension-discovery.ts b/src/extensions/extension-discovery/extension-discovery.ts index 1d14c427d0..dc17a51e0c 100644 --- a/src/extensions/extension-discovery/extension-discovery.ts +++ b/src/extensions/extension-discovery/extension-discovery.ts @@ -30,7 +30,6 @@ import type { GetDirnameOfPath } from "../../common/path/get-dirname.injectable" import type { GetRelativePath } from "../../common/path/get-relative-path.injectable"; import type { RemovePath } from "../../common/fs/remove.injectable"; import type TypedEventEmitter from "typed-emitter"; -import type { ApplicationInformation } from "../../common/vars/application-information.injectable"; interface Dependencies { readonly extensionLoader: ExtensionLoader; @@ -42,7 +41,7 @@ interface Dependencies { readonly isProduction: boolean; readonly fileSystemSeparator: string; readonly homeDirectoryPath: string; - readonly applicationInformation: ApplicationInformation; + readonly bundledExtensionPaths: string[]; isCompatibleExtension: (manifest: LensExtensionManifest) => boolean; installExtension: (name: string) => Promise; readJsonFile: ReadJson; @@ -393,14 +392,12 @@ export class ExtensionDiscovery { async loadBundledExtensions(): Promise { const extensions: InstalledExtension[] = []; - const extensionNames = this.dependencies.applicationInformation.config.extensions || []; - for (const dirName of extensionNames) { - const absPath = this.dependencies.joinPaths(__dirname, "..", "..", "node_modules", dirName); - const extension = await this.loadExtensionFromFolder(absPath, { isBundled: true }); + for (const bundledExtensionPath of this.dependencies.bundledExtensionPaths) { + const extension = await this.loadExtensionFromFolder(bundledExtensionPath, { isBundled: true }); if (!extension) { - throw new Error(`Couldn't load bundled extension: ${dirName}`); + throw new Error(`Couldn't load bundled extension: ${bundledExtensionPath}`); } extensions.push(extension);