mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Switch bundled extension declarations to injection token
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
8db81a4731
commit
89c8bb54d3
@ -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"
|
||||
|
||||
10
src/extensions/extension-discovery/bundled-extension-path.ts
Normal file
10
src/extensions/extension-discovery/bundled-extension-path.ts
Normal file
@ -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<string>({
|
||||
id: "bundled-extension-path",
|
||||
});
|
||||
@ -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),
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@ -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<void>;
|
||||
readJsonFile: ReadJson;
|
||||
@ -393,14 +392,12 @@ export class ExtensionDiscovery {
|
||||
|
||||
async loadBundledExtensions(): Promise<InstalledExtension[]> {
|
||||
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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user