mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
chore: Extract legacy global di into separate package
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
1c23162b58
commit
576373b16b
17
package-lock.json
generated
17
package-lock.json
generated
@ -3954,6 +3954,10 @@
|
||||
"resolved": "packages/technical-features/application/legacy-extensions",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/@k8slens/legacy-global-di": {
|
||||
"resolved": "packages/legacy-global-di",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/@k8slens/list-layout": {
|
||||
"resolved": "packages/list-layout",
|
||||
"link": true
|
||||
@ -35970,6 +35974,7 @@
|
||||
"@k8slens/event-emitter": "^1.0.0-alpha.1",
|
||||
"@k8slens/kubectl-versions": "^1.0.0-alpha.0",
|
||||
"@k8slens/legacy-extensions": "^1.0.0-alpha.0",
|
||||
"@k8slens/legacy-global-di": "^1.0.0-alpha.0",
|
||||
"@k8slens/messaging": "^1.0.0-alpha.1",
|
||||
"@k8slens/messaging-for-main": "^1.0.0-alpha.1",
|
||||
"@k8slens/messaging-for-renderer": "^1.0.0-alpha.1",
|
||||
@ -36772,6 +36777,18 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"packages/legacy-global-di": {
|
||||
"version": "1.0.0-alpha.0",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@k8slens/eslint-config": "^6.5.0-alpha.2",
|
||||
"@k8slens/jest": "^6.5.0-alpha.4",
|
||||
"@k8slens/typescript": "^6.5.0-alpha.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@ogre-tools/injectable": "^15.1.2"
|
||||
}
|
||||
},
|
||||
"packages/list-layout": {
|
||||
"name": "@k8slens/list-layout",
|
||||
"version": "1.0.0-alpha.1",
|
||||
|
||||
@ -322,6 +322,7 @@
|
||||
"@k8slens/cluster-settings": "^6.5.0-alpha.1",
|
||||
"@k8slens/kubectl-versions": "^1.0.0-alpha.0",
|
||||
"@k8slens/legacy-extensions": "^1.0.0-alpha.0",
|
||||
"@k8slens/legacy-global-di": "^1.0.0-alpha.0",
|
||||
"@k8slens/messaging": "^1.0.0-alpha.1",
|
||||
"@k8slens/messaging-for-main": "^1.0.0-alpha.1",
|
||||
"@k8slens/messaging-for-renderer": "^1.0.0-alpha.1",
|
||||
|
||||
@ -9,7 +9,7 @@ import { broadcastMessage } from "../ipc";
|
||||
import type { CatalogEntityConstructor, CatalogEntitySpec } from "../catalog/catalog-entity";
|
||||
import { IpcRendererNavigationEvents } from "../ipc/navigation-events";
|
||||
import KubeClusterCategoryIcon from "./icons/kubernetes.svg";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
import { requestClusterActivationInjectionToken, requestClusterDeactivationInjectionToken } from "../../features/cluster/activation/common/request-token";
|
||||
|
||||
export interface KubernetesClusterPrometheusMetrics {
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getEnvironmentSpecificLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import { getEnvironmentSpecificLegacyGlobalDiForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
import removeWeblinkInjectable from "../../features/weblinks/common/remove.injectable";
|
||||
import type { CatalogEntityContextMenuContext, CatalogEntityMetadata, CatalogEntityStatus } from "../catalog";
|
||||
import { CatalogCategory, CatalogEntity, categoryVersion } from "../catalog/catalog-entity";
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
import { ipcMain, ipcRenderer, webContents } from "electron";
|
||||
import { toJS } from "../utils/toJS";
|
||||
import type { Disposer } from "@k8slens/utilities";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
import ipcRendererInjectable from "../../renderer/utils/channel/ipc-renderer.injectable";
|
||||
import loggerInjectable from "../logger.injectable";
|
||||
import ipcMainInjectionToken from "./ipc-main-injection-token";
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
import customResourcesRouteInjectable from "../../front-end-routing/routes/cluster/custom-resources/custom-resources/custom-resources-route.injectable";
|
||||
import { buildURL } from "@k8slens/utilities";
|
||||
import type { BaseKubeObjectCondition, ClusterScopedMetadata } from "../kube-object";
|
||||
|
||||
@ -30,7 +30,7 @@ import requestKubeObjectPatchInjectable from "./endpoints/resource-applier.api/r
|
||||
import { apiKubeInjectionToken } from "./api-kube";
|
||||
import requestKubeObjectCreationInjectable from "./endpoints/resource-applier.api/request-update.injectable";
|
||||
import { dump } from "js-yaml";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
import autoBind from "auto-bind";
|
||||
|
||||
export type KubeJsonApiDataFor<K> = K extends KubeObject<infer Metadata, infer Status, infer Spec>
|
||||
@ -443,7 +443,7 @@ export interface RawKubeObject<
|
||||
metadata: Metadata;
|
||||
status?: Status;
|
||||
spec?: Spec;
|
||||
managedFields?: any;
|
||||
[otherFields: string]: unknown;
|
||||
}
|
||||
|
||||
export class KubeObject<
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
import hb from "handlebars";
|
||||
import type { KubernetesCluster } from "../catalog-entities";
|
||||
import yaml from "js-yaml";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
import productNameInjectable from "../vars/product-name.injectable";
|
||||
import type { AsyncResult } from "@k8slens/utilities";
|
||||
import type { Logger } from "../logger";
|
||||
|
||||
@ -1,20 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getLegacyGlobalDiForExtensionApi } from "./legacy-global-di-for-extension-api";
|
||||
import type { Inject } from "@ogre-tools/injectable";
|
||||
|
||||
export const asLegacyGlobalFunctionForExtensionApi = ((
|
||||
injectableKey,
|
||||
instantiationParameter,
|
||||
) =>
|
||||
(...args: any[]) => {
|
||||
const injected = getLegacyGlobalDiForExtensionApi().inject(
|
||||
injectableKey,
|
||||
instantiationParameter,
|
||||
) as unknown as (...args: any[]) => any;
|
||||
|
||||
return injected(...args);
|
||||
}) as Inject;
|
||||
@ -1,81 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type {
|
||||
DiContainer,
|
||||
Injectable } from "@ogre-tools/injectable";
|
||||
import {
|
||||
createContainer,
|
||||
getInjectable,
|
||||
} from "@ogre-tools/injectable";
|
||||
import { setLegacyGlobalDiForExtensionApi } from "./legacy-global-di-for-extension-api";
|
||||
import { asLegacyGlobalObjectForExtensionApiWithModifications } from "./as-legacy-global-object-for-extension-api-with-modifications";
|
||||
|
||||
describe("asLegacyGlobalObjectForExtensionApiWithModifications", () => {
|
||||
describe("given legacy global object", () => {
|
||||
let di: DiContainer;
|
||||
let someInjectable: Injectable<{ someProperty: string }, unknown, void>;
|
||||
let actual: { someProperty: string } & {
|
||||
someModificationProperty: string;
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
di = createContainer("irrelevant");
|
||||
|
||||
jest.spyOn(di, "inject");
|
||||
|
||||
setLegacyGlobalDiForExtensionApi(di, "renderer");
|
||||
|
||||
someInjectable = getInjectable({
|
||||
id: "some-injectable",
|
||||
instantiate: () => ({
|
||||
someProperty: "some-property-value",
|
||||
}),
|
||||
});
|
||||
|
||||
di.register(someInjectable);
|
||||
|
||||
actual = asLegacyGlobalObjectForExtensionApiWithModifications(
|
||||
someInjectable,
|
||||
{ someModificationProperty: "some-modification-value" },
|
||||
);
|
||||
});
|
||||
|
||||
it("when not accessed, does not inject yet", () => {
|
||||
expect(di.inject).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe("when a property of global is accessed, ", () => {
|
||||
let actualPropertyValue: string;
|
||||
|
||||
beforeEach(() => {
|
||||
actualPropertyValue = actual.someProperty;
|
||||
});
|
||||
|
||||
it("injects the injectable for global", () => {
|
||||
expect(di.inject).toHaveBeenCalledWith(someInjectable, undefined);
|
||||
});
|
||||
|
||||
it("global has property of injectable", () => {
|
||||
expect(actualPropertyValue).toBe("some-property-value");
|
||||
});
|
||||
});
|
||||
|
||||
describe("when a property of modification is accessed, ", () => {
|
||||
let actualModificationValue: string;
|
||||
|
||||
beforeEach(() => {
|
||||
actualModificationValue = actual.someModificationProperty;
|
||||
});
|
||||
|
||||
it("injects the injectable for global", () => {
|
||||
expect(di.inject).toHaveBeenCalledWith(someInjectable, undefined);
|
||||
});
|
||||
|
||||
it("global has property of modification", () => {
|
||||
expect(actualModificationValue).toBe("some-modification-value");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -1,22 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { asLegacyGlobalForExtensionApi } from "./as-legacy-global-object-for-extension-api";
|
||||
import type { Injectable } from "@ogre-tools/injectable";
|
||||
|
||||
/**
|
||||
* @deprecated use asLegacyGlobalForExtensionApi instead, and use proper implementations instead of "modifications".
|
||||
*/
|
||||
export const asLegacyGlobalObjectForExtensionApiWithModifications = <
|
||||
InjectableInstance extends InjectionTokenInstance & object,
|
||||
InjectionTokenInstance,
|
||||
ModificationObject extends object,
|
||||
>(
|
||||
injectable: Injectable<InjectableInstance, InjectionTokenInstance, void>,
|
||||
modificationObject: ModificationObject,
|
||||
) =>
|
||||
Object.assign(
|
||||
asLegacyGlobalForExtensionApi(injectable),
|
||||
modificationObject,
|
||||
);
|
||||
@ -1,46 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { Inject } from "@ogre-tools/injectable";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "./legacy-global-di-for-extension-api";
|
||||
|
||||
export const asLegacyGlobalForExtensionApi = ((
|
||||
injectable,
|
||||
instantiationParameter,
|
||||
) =>
|
||||
new Proxy(
|
||||
{},
|
||||
|
||||
{
|
||||
apply(target: any, thisArg, argArray) {
|
||||
const fn = getLegacyGlobalDiForExtensionApi().inject(
|
||||
injectable,
|
||||
instantiationParameter,
|
||||
) as unknown as (...args: any[]) => any;
|
||||
|
||||
return fn(...argArray);
|
||||
},
|
||||
|
||||
get(target, propertyName) {
|
||||
if (propertyName === "$$typeof") {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const instance: any = getLegacyGlobalDiForExtensionApi().inject(
|
||||
injectable,
|
||||
instantiationParameter,
|
||||
);
|
||||
|
||||
const propertyValue = instance[propertyName] ?? target[propertyName];
|
||||
|
||||
if (typeof propertyValue === "function") {
|
||||
return function (...args: any[]) {
|
||||
return propertyValue.apply(instance, args);
|
||||
};
|
||||
}
|
||||
|
||||
return propertyValue;
|
||||
},
|
||||
},
|
||||
)) as Inject;
|
||||
@ -1,42 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { Injectable } from "@ogre-tools/injectable";
|
||||
import { asLegacyGlobalForExtensionApi } from "./as-legacy-global-object-for-extension-api";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "./legacy-global-di-for-extension-api";
|
||||
import loggerInjectable from "../../common/logger.injectable";
|
||||
|
||||
export interface LegacySingleton<T> {
|
||||
createInstance(): T;
|
||||
getInstance(): T;
|
||||
resetInstance(): void;
|
||||
}
|
||||
|
||||
export function asLegacyGlobalSingletonForExtensionApi<Instance>(injectable: Injectable<Instance, unknown, void>): LegacySingleton<Instance>;
|
||||
export function asLegacyGlobalSingletonForExtensionApi<Instance, InstantiationParameter>(injectable: Injectable<Instance, unknown, InstantiationParameter>, param: InstantiationParameter): LegacySingleton<Instance>;
|
||||
|
||||
export function asLegacyGlobalSingletonForExtensionApi<Instance, InstantiationParameter>(
|
||||
injectable: Injectable<Instance, unknown, InstantiationParameter>,
|
||||
instantiationParameter?: InstantiationParameter,
|
||||
): LegacySingleton<Instance> {
|
||||
const instance = asLegacyGlobalForExtensionApi(
|
||||
injectable as never,
|
||||
instantiationParameter,
|
||||
) as Instance;
|
||||
|
||||
return {
|
||||
createInstance: () => instance,
|
||||
|
||||
getInstance: () => instance,
|
||||
|
||||
resetInstance: () => {
|
||||
const di = getLegacyGlobalDiForExtensionApi();
|
||||
const logger = di.inject(loggerInjectable);
|
||||
|
||||
logger.warn(
|
||||
`resetInstance() for a legacy global singleton of "${injectable.id}" does nothing.`,
|
||||
);
|
||||
},
|
||||
};
|
||||
}
|
||||
@ -7,7 +7,7 @@ import * as path from "path";
|
||||
import type { LensExtension } from "./lens-extension";
|
||||
import type { StaticThis } from "../common/utils/singleton";
|
||||
import { getOrInsertWith } from "@k8slens/utilities";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "./as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
import type { PersistentStorage, PersistentStorageParams } from "../common/persistent-storage/create.injectable";
|
||||
import createPersistentStorageInjectable from "../common/persistent-storage/create.injectable";
|
||||
import directoryForUserDataInjectable from "../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
|
||||
@ -8,9 +8,8 @@ import isLinuxInjectable from "../../common/vars/is-linux.injectable";
|
||||
import isMacInjectable from "../../common/vars/is-mac.injectable";
|
||||
import isSnapPackageInjectable from "../../common/vars/is-snap-package.injectable";
|
||||
import isWindowsInjectable from "../../common/vars/is-windows.injectable";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import { getLegacyGlobalDiForExtensionApi, asLegacyGlobalForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
import { issuesTrackerUrl } from "../../common/vars";
|
||||
import { asLegacyGlobalForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
|
||||
import enabledExtensionsInjectable from "../../features/extensions/enabled/common/enabled-extensions.injectable";
|
||||
import userPreferencesStateInjectable from "../../features/user-preferences/common/state.injectable";
|
||||
import { lensBuildEnvironmentInjectionToken } from "@k8slens/application";
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
import type { KubernetesClusterCategory } from "../../common/catalog-entities/kubernetes-cluster";
|
||||
import kubernetesClusterCategoryInjectable from "../../common/catalog/categories/kubernetes-cluster.injectable";
|
||||
import { asLegacyGlobalForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
|
||||
import { asLegacyGlobalForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
|
||||
export {
|
||||
KubernetesCluster,
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import appEventBusInjectable from "../../common/app-event-bus/app-event-bus.injectable";
|
||||
import { asLegacyGlobalForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
|
||||
import { asLegacyGlobalForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
import type { AppEvent } from "../../common/app-event-bus/event-bus";
|
||||
import type { EventEmitter, EventEmitterCallback, EventEmitterOptions } from "@k8slens/event-emitter";
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import loggerInjectable from "../../common/logger.injectable";
|
||||
import { asLegacyGlobalForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
|
||||
import { asLegacyGlobalForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
|
||||
// APIs
|
||||
export { App } from "./app";
|
||||
|
||||
@ -12,8 +12,7 @@ import createKubeApiForClusterInjectable from "../../common/k8s-api/create-kube-
|
||||
import createKubeApiForRemoteClusterInjectable from "../../common/k8s-api/create-kube-api-for-remote-cluster.injectable";
|
||||
import createResourceStackInjectable from "../../common/k8s/create-resource-stack.injectable";
|
||||
import type { ResourceApplyingStack } from "../../common/k8s/resource-stack";
|
||||
import { asLegacyGlobalFunctionForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-function-for-extension-api";
|
||||
import { asLegacyGlobalForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
|
||||
import { asLegacyGlobalFunctionForExtensionApi, asLegacyGlobalForExtensionApi, getLegacyGlobalDiForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
import type { KubernetesCluster } from "./catalog";
|
||||
import type { KubeApiDataFrom, KubeObjectStoreOptions } from "../../common/k8s-api/kube-object.store";
|
||||
import { KubeObjectStore as InternalKubeObjectStore } from "../../common/k8s-api/kube-object.store";
|
||||
@ -23,7 +22,6 @@ import { KubeApi as InternalKubeApi } from "../../common/k8s-api/kube-api";
|
||||
import clusterFrameContextForNamespacedResourcesInjectable from "../../renderer/cluster-frame-context/for-namespaced-resources.injectable";
|
||||
import type { ClusterContext } from "../../renderer/cluster-frame-context/cluster-frame-context";
|
||||
import loggerInjectable from "../../common/logger.injectable";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import maybeKubeApiInjectable from "../../common/k8s-api/maybe-kube-api.injectable";
|
||||
import { DeploymentApi as InternalDeploymentApi, IngressApi as InternalIngressApi, NodeApi, PersistentVolumeClaimApi, PodApi } from "../../common/k8s-api/endpoints";
|
||||
import { storesAndApisCanBeCreatedInjectionToken } from "../../common/k8s-api/stores-apis-can-be-created.token";
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { asLegacyGlobalFunctionForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-function-for-extension-api";
|
||||
import { asLegacyGlobalFunctionForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
import { resolveSystemProxyInjectionToken } from "../../common/utils/resolve-system-proxy/resolve-system-proxy-injection-token";
|
||||
|
||||
/**
|
||||
|
||||
@ -5,8 +5,7 @@
|
||||
|
||||
import openLinkInBrowserInjectable from "../../common/utils/open-link-in-browser.injectable";
|
||||
import { buildVersionInitializable } from "../../features/vars/build-version/common/token";
|
||||
import { asLegacyGlobalFunctionForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-function-for-extension-api";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import { asLegacyGlobalFunctionForExtensionApi, getLegacyGlobalDiForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
|
||||
export { Singleton } from "../../common/utils/singleton";
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ import type { Disposer } from "@k8slens/utilities";
|
||||
import { once } from "lodash";
|
||||
import { ipcMainHandle } from "../../common/ipc";
|
||||
import type { Logger } from "../common-api";
|
||||
import { getEnvironmentSpecificLegacyGlobalDiForExtensionApi } from "../as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import { getEnvironmentSpecificLegacyGlobalDiForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
import loggerInjectable from "../../common/logger.injectable";
|
||||
|
||||
interface Dependencies {
|
||||
|
||||
@ -11,7 +11,7 @@ import { isObservableArray } from "mobx";
|
||||
import type { MenuRegistration } from "../features/application-menu/main/menu-registration";
|
||||
import type { TrayMenuRegistration } from "../main/tray/tray-menu-registration";
|
||||
import type { ShellEnvModifier } from "../main/shell-session/shell-env-modifier/shell-env-modifier-registration";
|
||||
import { getEnvironmentSpecificLegacyGlobalDiForExtensionApi } from "./as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import { getEnvironmentSpecificLegacyGlobalDiForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
import type { InstalledExtension } from "./common-api";
|
||||
import type { CatalogEntityRegistry } from "../main/catalog";
|
||||
import type { NavigateForExtension } from "../main/start-main-application/lens-window/navigate-for-extension.injectable";
|
||||
|
||||
@ -36,7 +36,7 @@ import type { NavigateToRoute } from "../common/front-end-routing/navigate-to-ro
|
||||
import type { Route } from "../common/front-end-routing/front-end-route-injection-token";
|
||||
import type { GetExtensionPageParameters } from "../renderer/routes/get-extension-page-parameters.injectable";
|
||||
import type { InstalledExtension } from "./common-api";
|
||||
import { getEnvironmentSpecificLegacyGlobalDiForExtensionApi } from "./as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import { getEnvironmentSpecificLegacyGlobalDiForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
import catalogCategoryRegistryInjectable from "../common/catalog/category-registry.injectable";
|
||||
import catalogEntityRegistryInjectable from "../renderer/api/catalog/entity/registry.injectable";
|
||||
import loggerInjectable from "../common/logger.injectable";
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import type { CatalogEntity } from "../../common/catalog";
|
||||
import { asLegacyGlobalForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
|
||||
import { asLegacyGlobalForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
import catalogCategoryRegistryInjectable from "../../common/catalog/category-registry.injectable";
|
||||
import catalogEntityRegistryInjectable from "../../main/catalog/entity-registry.injectable";
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getEnvironmentSpecificLegacyGlobalDiForExtensionApi } from "../as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import { getEnvironmentSpecificLegacyGlobalDiForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
import navigateInjectable from "../../main/start-main-application/lens-window/navigate.injectable";
|
||||
|
||||
export function navigate(url: string) {
|
||||
|
||||
@ -8,7 +8,7 @@ import type { CatalogCategory, CatalogEntity } from "../../common/catalog";
|
||||
import type { CatalogEntityOnBeforeRun } from "../../renderer/api/catalog/entity/registry";
|
||||
import type { Disposer } from "@k8slens/utilities";
|
||||
import catalogCategoryRegistryInjectable from "../../common/catalog/category-registry.injectable";
|
||||
import { asLegacyGlobalForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
|
||||
import { asLegacyGlobalForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
import catalogEntityRegistryInjectable from "../../renderer/api/catalog/entity/registry.injectable";
|
||||
import activeKubernetesClusterInjectable from "../../renderer/cluster-frame-context/active-kubernetes-cluster.injectable";
|
||||
|
||||
|
||||
@ -2,10 +2,9 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { asLegacyGlobalFunctionForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-function-for-extension-api";
|
||||
import { asLegacyGlobalFunctionForExtensionApi, asLegacyGlobalForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
import createTerminalTabInjectable from "../../renderer/components/dock/terminal/create-terminal-tab.injectable";
|
||||
import terminalStoreInjectable from "../../renderer/components/dock/terminal/store.injectable";
|
||||
import { asLegacyGlobalForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
|
||||
import logTabStoreInjectable from "../../renderer/components/dock/logs/tab-store.injectable";
|
||||
|
||||
import commandOverlayInjectable from "../../renderer/components/command-palette/command-overlay.injectable";
|
||||
@ -13,7 +12,6 @@ import createPodLogsTabInjectable from "../../renderer/components/dock/logs/crea
|
||||
import createWorkloadLogsTabInjectable from "../../renderer/components/dock/logs/create-workload-logs-tab.injectable";
|
||||
import sendCommandInjectable from "../../renderer/components/dock/terminal/send-command.injectable";
|
||||
import renameTabInjectable from "../../renderer/components/dock/dock/rename-tab.injectable";
|
||||
import { asLegacyGlobalObjectForExtensionApiWithModifications } from "../as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api-with-modifications";
|
||||
import { ConfirmDialog as _ConfirmDialog } from "../../renderer/components/confirm-dialog";
|
||||
import type { ConfirmDialogBooleanParams, ConfirmDialogParams, ConfirmDialogProps } from "../../renderer/components/confirm-dialog";
|
||||
import openConfirmDialogInjectable from "../../renderer/components/confirm-dialog/open.injectable";
|
||||
@ -131,8 +129,8 @@ export * from "../../renderer/components/status-brick";
|
||||
|
||||
export const createTerminalTab = asLegacyGlobalFunctionForExtensionApi(createTerminalTabInjectable);
|
||||
|
||||
export const terminalStore = asLegacyGlobalObjectForExtensionApiWithModifications(
|
||||
terminalStoreInjectable,
|
||||
export const terminalStore = Object.assign(
|
||||
asLegacyGlobalForExtensionApi(terminalStoreInjectable),
|
||||
{
|
||||
sendCommand: asLegacyGlobalFunctionForExtensionApi(sendCommandInjectable),
|
||||
},
|
||||
@ -141,8 +139,8 @@ export const terminalStore = asLegacyGlobalObjectForExtensionApiWithModification
|
||||
const renameTab = asLegacyGlobalFunctionForExtensionApi(renameTabInjectable);
|
||||
const podStore = asLegacyGlobalForExtensionApi(podStoreInjectable);
|
||||
|
||||
export const logTabStore = asLegacyGlobalObjectForExtensionApiWithModifications(
|
||||
logTabStoreInjectable,
|
||||
export const logTabStore = Object.assign(
|
||||
asLegacyGlobalForExtensionApi(logTabStoreInjectable),
|
||||
{
|
||||
createPodTab: asLegacyGlobalFunctionForExtensionApi(createPodLogsTabInjectable),
|
||||
createWorkloadTab: asLegacyGlobalFunctionForExtensionApi(createWorkloadLogsTabInjectable),
|
||||
|
||||
@ -4,11 +4,10 @@
|
||||
*/
|
||||
import type { KubeResource } from "../../common/rbac";
|
||||
import { apiResourceRecord } from "../../common/rbac";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import { getLegacyGlobalDiForExtensionApi, asLegacyGlobalForExtensionApi, asLegacyGlobalFunctionForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
import clusterRoleBindingApiInjectable from "../../common/k8s-api/endpoints/cluster-role-binding.api.injectable";
|
||||
import clusterRoleApiInjectable from "../../common/k8s-api/endpoints/cluster-role.api.injectable";
|
||||
import serviceAccountApiInjectable from "../../common/k8s-api/endpoints/service-account.api.injectable";
|
||||
import { asLegacyGlobalForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
|
||||
import roleApiInjectable from "../../common/k8s-api/endpoints/role.api.injectable";
|
||||
import podApiInjectable from "../../common/k8s-api/endpoints/pod.api.injectable";
|
||||
import daemonSetApiInjectable from "../../common/k8s-api/endpoints/daemon-set.api.injectable";
|
||||
@ -38,7 +37,6 @@ import kubeEventApiInjectable from "../../common/k8s-api/endpoints/events.api.in
|
||||
import roleBindingApiInjectable from "../../common/k8s-api/endpoints/role-binding.api.injectable";
|
||||
import customResourceDefinitionApiInjectable from "../../common/k8s-api/endpoints/custom-resource-definition.api.injectable";
|
||||
import { shouldShowResourceInjectionToken } from "../../features/cluster/showing-kube-resources/common/allowed-resources-injection-token";
|
||||
import { asLegacyGlobalFunctionForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-function-for-extension-api";
|
||||
import requestMetricsInjectable from "../../common/k8s-api/endpoints/metrics.api/request-metrics.injectable";
|
||||
|
||||
export function isAllowedResource(resources: KubeResource | KubeResource[]) {
|
||||
|
||||
@ -11,7 +11,7 @@ import showDetailsInjectable from "../../renderer/components/kube-detail-params/
|
||||
import createPageParamInjectable from "../../renderer/navigation/create-page-param.injectable";
|
||||
import isActiveRouteInjectable from "../../renderer/navigation/is-route-active.injectable";
|
||||
import navigateInjectable from "../../renderer/navigation/navigate.injectable";
|
||||
import { asLegacyGlobalFunctionForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-function-for-extension-api";
|
||||
import { asLegacyGlobalFunctionForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
|
||||
export type { PageParamInit, PageParam } from "../../renderer/navigation/page-param";
|
||||
export type { URLParams } from "@k8slens/utilities";
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
import activeThemeInjectable from "../../renderer/themes/active.injectable";
|
||||
import type { LensTheme } from "../../renderer/themes/lens-theme";
|
||||
import { asLegacyGlobalForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
|
||||
import { asLegacyGlobalForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
|
||||
export const activeTheme = asLegacyGlobalForExtensionApi(activeThemeInjectable);
|
||||
|
||||
|
||||
@ -24,7 +24,7 @@ import waitUntilBundledExtensionsAreLoadedInjectable from "./start-main-applicat
|
||||
import initializeClusterManagerInjectable from "./cluster/initialize-manager.injectable";
|
||||
import type { GlobalOverride } from "@k8slens/test-utils";
|
||||
import { getOverrideFsWithFakes } from "../test-utils/override-fs-with-fakes";
|
||||
import { setLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import { setLegacyGlobalDiForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
|
||||
import { registerFeature } from "@k8slens/feature-core";
|
||||
import { messagingFeature, testUtils as messagingTestUtils } from "@k8slens/messaging";
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
*/
|
||||
|
||||
// @experimental
|
||||
export type { Environments } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
export { registerLensCore } from "./register-lens-core";
|
||||
export { nodeEnvInjectionToken } from "../common/vars/node-env-injection-token";
|
||||
|
||||
|
||||
@ -5,11 +5,8 @@
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import { autoRegister } from "@ogre-tools/injectable-extension-for-auto-registration";
|
||||
import { runInAction } from "mobx";
|
||||
import type {
|
||||
Environments } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import {
|
||||
setLegacyGlobalDiForExtensionApi,
|
||||
} from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import type { Environments } from "@k8slens/legacy-global-di";
|
||||
import { setLegacyGlobalDiForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
|
||||
export function registerLensCore(di: DiContainer, environment: Environments) {
|
||||
setLegacyGlobalDiForExtensionApi(di, environment);
|
||||
|
||||
@ -10,7 +10,7 @@ import { observer } from "mobx-react";
|
||||
import type { IClassName } from "@k8slens/utilities";
|
||||
import { cssNames } from "@k8slens/utilities";
|
||||
import { CloseButton } from "./close-button";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
import navigateToCatalogInjectable from "../../../common/front-end-routing/routes/catalog/navigate-to-catalog.injectable";
|
||||
import { observableHistoryInjectionToken } from "@k8slens/routing";
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ import startTopbarStateSyncInjectable from "./components/layout/top-bar/start-st
|
||||
import watchHistoryStateInjectable from "./remote-helpers/watch-history-state.injectable";
|
||||
import legacyOnChannelListenInjectable from "./ipc/legacy-channel-listen.injectable";
|
||||
import type { GlobalOverride } from "@k8slens/test-utils";
|
||||
import { setLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import { setLegacyGlobalDiForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
|
||||
import { registerInjectableReact } from "@ogre-tools/injectable-react";
|
||||
import { registerFeature } from "@k8slens/feature-core";
|
||||
|
||||
@ -9,7 +9,7 @@ import { windowActionHandleChannel, windowLocationChangedChannel, windowOpenAppM
|
||||
import { extensionDiscoveryStateChannel, extensionLoaderFromMainChannel } from "../../common/ipc/extension-handling";
|
||||
import type { InstalledExtension, LensExtensionId } from "@k8slens/legacy-extensions";
|
||||
import type { Location } from "history";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
import ipcRendererInjectable from "../utils/channel/ipc-renderer.injectable";
|
||||
import { toJS } from "../../common/utils";
|
||||
|
||||
|
||||
@ -8,7 +8,6 @@ import ReactDOM from "react-dom";
|
||||
import setStatusBarStatusInjectable from "./components/status-bar/set-status-bar-status.injectable";
|
||||
|
||||
// @experimental
|
||||
export type { Environments } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
export { nodeEnvInjectionToken } from "../common/vars/node-env-injection-token";
|
||||
export { registerLensCore } from "./register-lens-core";
|
||||
export {
|
||||
|
||||
@ -6,12 +6,8 @@
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import { autoRegister } from "@ogre-tools/injectable-extension-for-auto-registration";
|
||||
import { runInAction } from "mobx";
|
||||
import type {
|
||||
Environments,
|
||||
} from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import {
|
||||
setLegacyGlobalDiForExtensionApi,
|
||||
} from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import type { Environments } from "@k8slens/legacy-global-di";
|
||||
import { setLegacyGlobalDiForExtensionApi } from "@k8slens/legacy-global-di";
|
||||
|
||||
export function registerLensCore(di: DiContainer, environment: Environments) {
|
||||
setLegacyGlobalDiForExtensionApi(di, environment);
|
||||
|
||||
6
packages/legacy-global-di/.eslintrc.js
Normal file
6
packages/legacy-global-di/.eslintrc.js
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
extends: "@k8slens/eslint-config/eslint",
|
||||
parserOptions: {
|
||||
project: "./tsconfig.json",
|
||||
},
|
||||
};
|
||||
1
packages/legacy-global-di/.prettierrc
Normal file
1
packages/legacy-global-di/.prettierrc
Normal file
@ -0,0 +1 @@
|
||||
"@k8slens/eslint-config/prettier"
|
||||
8
packages/legacy-global-di/index.ts
Normal file
8
packages/legacy-global-di/index.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
export * from "./src/as-global-function";
|
||||
export * from "./src/as-global-object";
|
||||
export * from "./src/global-di";
|
||||
1
packages/legacy-global-di/jest.config.js
Normal file
1
packages/legacy-global-di/jest.config.js
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require("@k8slens/jest").monorepoPackageConfig(__dirname).configForReact;
|
||||
41
packages/legacy-global-di/package.json
Normal file
41
packages/legacy-global-di/package.json
Normal file
@ -0,0 +1,41 @@
|
||||
{
|
||||
"name": "@k8slens/legacy-global-di",
|
||||
"private": false,
|
||||
"version": "1.0.0-alpha.0",
|
||||
"description": "Injection tokens for implementing metrics for Lens",
|
||||
"type": "commonjs",
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"registry": "https://registry.npmjs.org/"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/lensapp/lens.git"
|
||||
},
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"author": {
|
||||
"name": "OpenLens Authors",
|
||||
"email": "info@k8slens.dev"
|
||||
},
|
||||
"license": "MIT",
|
||||
"homepage": "https://github.com/lensapp/lens",
|
||||
"scripts": {
|
||||
"build": "webpack",
|
||||
"clean": "rimraf dist/",
|
||||
"test": "jest --coverage --runInBand",
|
||||
"lint": "lens-lint",
|
||||
"lint:fix": "lens-lint --fix"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@ogre-tools/injectable": "^15.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@k8slens/eslint-config": "^6.5.0-alpha.2",
|
||||
"@k8slens/jest": "^6.5.0-alpha.4",
|
||||
"@k8slens/typescript": "^6.5.0-alpha.2"
|
||||
}
|
||||
}
|
||||
16
packages/legacy-global-di/src/as-global-function.ts
Normal file
16
packages/legacy-global-di/src/as-global-function.ts
Normal file
@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getLegacyGlobalDiForExtensionApi } from "./global-di";
|
||||
import type { Inject } from "@ogre-tools/injectable";
|
||||
|
||||
export const asLegacyGlobalFunctionForExtensionApi = ((injectableKey, instantiationParameter) =>
|
||||
(...args: unknown[]) => {
|
||||
const injected = getLegacyGlobalDiForExtensionApi().inject(injectableKey, instantiationParameter) as unknown as (
|
||||
...args: unknown[]
|
||||
) => unknown;
|
||||
|
||||
return injected(...args);
|
||||
}) as Inject;
|
||||
42
packages/legacy-global-di/src/as-global-object.ts
Normal file
42
packages/legacy-global-di/src/as-global-object.ts
Normal file
@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { Inject } from "@ogre-tools/injectable";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "./global-di";
|
||||
|
||||
export const asLegacyGlobalForExtensionApi = ((injectable, instantiationParameter) =>
|
||||
new Proxy(
|
||||
{},
|
||||
|
||||
{
|
||||
apply(target: unknown, thisArg, argArray: unknown[]) {
|
||||
const fn = getLegacyGlobalDiForExtensionApi().inject(injectable, instantiationParameter) as unknown as (
|
||||
...args: unknown[]
|
||||
) => unknown;
|
||||
|
||||
return fn(...argArray);
|
||||
},
|
||||
|
||||
get(target: Record<string | symbol, unknown>, propertyName) {
|
||||
if (propertyName === "$$typeof") {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const instance = getLegacyGlobalDiForExtensionApi().inject(injectable, instantiationParameter) as Record<
|
||||
string | symbol,
|
||||
unknown
|
||||
>;
|
||||
|
||||
const propertyValue = instance[propertyName] ?? target[propertyName];
|
||||
|
||||
if (typeof propertyValue === "function") {
|
||||
return function (...args: unknown[]) {
|
||||
return propertyValue.apply(instance, args) as unknown;
|
||||
};
|
||||
}
|
||||
|
||||
return propertyValue;
|
||||
},
|
||||
},
|
||||
)) as Inject;
|
||||
4
packages/legacy-global-di/tsconfig.json
Normal file
4
packages/legacy-global-di/tsconfig.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "@k8slens/typescript/config/base.json",
|
||||
"include": ["**/*.ts"]
|
||||
}
|
||||
1
packages/legacy-global-di/webpack.config.js
Normal file
1
packages/legacy-global-di/webpack.config.js
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require("@k8slens/webpack").configForReact;
|
||||
Loading…
Reference in New Issue
Block a user