mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Remove all usages of legacy global logger
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
1456e1e597
commit
ade0775061
107 files changed
+852
-606
No files matched your search
@@ -11,8 +11,10 @@ import { Util } from "./utils";
|
||||
import * as Catalog from "./catalog";
|
||||
import * as Types from "./types";
|
||||
import * as Proxy from "./proxy";
|
||||
import loggerInjectable from "../../common/logger.injectable";
|
||||
import { asLegacyGlobalForExtensionApi } from "../as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
|
||||
|
||||
import logger from "../../common/logger";
|
||||
const logger = asLegacyGlobalForExtensionApi(loggerInjectable);
|
||||
|
||||
export {
|
||||
App,
|
||||
|
||||
@@ -21,6 +21,8 @@ import type { KubeJsonApiDataFor, KubeObject } from "../../common/k8s-api/kube-o
|
||||
import type { KubeApi } 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";
|
||||
|
||||
export const apiManager = asLegacyGlobalForExtensionApi(apiManagerInjectable);
|
||||
export const forCluster = asLegacyGlobalFunctionForExtensionApi(createKubeApiForClusterInjectable);
|
||||
@@ -104,9 +106,12 @@ export abstract class KubeObjectStore<
|
||||
*/
|
||||
constructor();
|
||||
constructor(api?: A, opts?: KubeObjectStoreOptions) {
|
||||
const di = getLegacyGlobalDiForExtensionApi();
|
||||
|
||||
super(
|
||||
{
|
||||
context: asLegacyGlobalForExtensionApi(clusterFrameContextForNamespacedResourcesInjectable),
|
||||
context: di.inject(clusterFrameContextForNamespacedResourcesInjectable),
|
||||
logger: di.inject(loggerInjectable),
|
||||
},
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
api!,
|
||||
|
||||
+4
-1
@@ -3,11 +3,14 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import loggerInjectable from "../../common/logger.injectable";
|
||||
import { ExtensionInstallationStateStore } from "./extension-installation-state-store";
|
||||
|
||||
const extensionInstallationStateStoreInjectable = getInjectable({
|
||||
id: "extension-installation-state-store",
|
||||
instantiate: () => new ExtensionInstallationStateStore(),
|
||||
instantiate: (di) => new ExtensionInstallationStateStore({
|
||||
logger: di.inject(loggerInjectable),
|
||||
}),
|
||||
});
|
||||
|
||||
export default extensionInstallationStateStoreInjectable;
|
||||
+33
-30
@@ -4,12 +4,12 @@
|
||||
*/
|
||||
|
||||
import { action, computed, observable } from "mobx";
|
||||
import logger from "../../main/logger";
|
||||
import { disposer } from "../../renderer/utils";
|
||||
import type { ExtendableDisposer } from "../../renderer/utils";
|
||||
import * as uuid from "uuid";
|
||||
import { broadcastMessage } from "../../common/ipc";
|
||||
import { ipcRenderer } from "electron";
|
||||
import type { Logger } from "../../common/logger";
|
||||
|
||||
export enum ExtensionInstallationState {
|
||||
INSTALLING = "installing",
|
||||
@@ -17,26 +17,29 @@ export enum ExtensionInstallationState {
|
||||
IDLE = "idle",
|
||||
}
|
||||
|
||||
interface Dependencies {
|
||||
readonly logger: Logger;
|
||||
}
|
||||
|
||||
const Prefix = "[ExtensionInstallationStore]";
|
||||
|
||||
const installingFromMainChannel = "extension-installation-state-store:install";
|
||||
const clearInstallingFromMainChannel = "extension-installation-state-store:clear-install";
|
||||
|
||||
export class ExtensionInstallationStateStore {
|
||||
private InstallingFromMainChannel =
|
||||
"extension-installation-state-store:install";
|
||||
private readonly preInstallIds = observable.set<string>();
|
||||
private readonly uninstallingExtensions = observable.set<string>();
|
||||
private readonly installingExtensions = observable.set<string>();
|
||||
|
||||
private ClearInstallingFromMainChannel =
|
||||
"extension-installation-state-store:clear-install";
|
||||
|
||||
private PreInstallIds = observable.set<string>();
|
||||
private UninstallingExtensions = observable.set<string>();
|
||||
private InstallingExtensions = observable.set<string>();
|
||||
constructor(private readonly dependencies: Dependencies) {}
|
||||
|
||||
bindIpcListeners = () => {
|
||||
ipcRenderer
|
||||
.on(this.InstallingFromMainChannel, (event, extId) => {
|
||||
.on(installingFromMainChannel, (event, extId) => {
|
||||
this.setInstalling(extId);
|
||||
})
|
||||
|
||||
.on(this.ClearInstallingFromMainChannel, (event, extId) => {
|
||||
.on(clearInstallingFromMainChannel, (event, extId) => {
|
||||
this.clearInstalling(extId);
|
||||
});
|
||||
};
|
||||
@@ -47,7 +50,7 @@ export class ExtensionInstallationStateStore {
|
||||
* @throws if state is not IDLE
|
||||
*/
|
||||
@action setInstalling = (extId: string): void => {
|
||||
logger.debug(`${Prefix}: trying to set ${extId} as installing`);
|
||||
this.dependencies.logger.debug(`${Prefix}: trying to set ${extId} as installing`);
|
||||
|
||||
const curState = this.getInstallationState(extId);
|
||||
|
||||
@@ -57,7 +60,7 @@ export class ExtensionInstallationStateStore {
|
||||
);
|
||||
}
|
||||
|
||||
this.InstallingExtensions.add(extId);
|
||||
this.installingExtensions.add(extId);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -65,7 +68,7 @@ export class ExtensionInstallationStateStore {
|
||||
* @param extId the ID of the extension
|
||||
*/
|
||||
setInstallingFromMain = (extId: string): void => {
|
||||
broadcastMessage(this.InstallingFromMainChannel, extId);
|
||||
broadcastMessage(installingFromMainChannel, extId);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -73,7 +76,7 @@ export class ExtensionInstallationStateStore {
|
||||
* @param extId the ID of the extension
|
||||
*/
|
||||
clearInstallingFromMain = (extId: string): void => {
|
||||
broadcastMessage(this.ClearInstallingFromMainChannel, extId);
|
||||
broadcastMessage(clearInstallingFromMainChannel, extId);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -85,14 +88,14 @@ export class ExtensionInstallationStateStore {
|
||||
@action startPreInstall = (): ExtendableDisposer => {
|
||||
const preInstallStepId = uuid.v4();
|
||||
|
||||
logger.debug(
|
||||
this.dependencies.logger.debug(
|
||||
`${Prefix}: starting a new preinstall phase: ${preInstallStepId}`,
|
||||
);
|
||||
this.PreInstallIds.add(preInstallStepId);
|
||||
this.preInstallIds.add(preInstallStepId);
|
||||
|
||||
return disposer(() => {
|
||||
this.PreInstallIds.delete(preInstallStepId);
|
||||
logger.debug(`${Prefix}: ending a preinstall phase: ${preInstallStepId}`);
|
||||
this.preInstallIds.delete(preInstallStepId);
|
||||
this.dependencies.logger.debug(`${Prefix}: ending a preinstall phase: ${preInstallStepId}`);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -102,7 +105,7 @@ export class ExtensionInstallationStateStore {
|
||||
* @throws if state is not IDLE
|
||||
*/
|
||||
@action setUninstalling = (extId: string): void => {
|
||||
logger.debug(`${Prefix}: trying to set ${extId} as uninstalling`);
|
||||
this.dependencies.logger.debug(`${Prefix}: trying to set ${extId} as uninstalling`);
|
||||
|
||||
const curState = this.getInstallationState(extId);
|
||||
|
||||
@@ -112,7 +115,7 @@ export class ExtensionInstallationStateStore {
|
||||
);
|
||||
}
|
||||
|
||||
this.UninstallingExtensions.add(extId);
|
||||
this.uninstallingExtensions.add(extId);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -121,13 +124,13 @@ export class ExtensionInstallationStateStore {
|
||||
* @throws if state is not INSTALLING
|
||||
*/
|
||||
@action clearInstalling = (extId: string): void => {
|
||||
logger.debug(`${Prefix}: trying to clear ${extId} as installing`);
|
||||
this.dependencies.logger.debug(`${Prefix}: trying to clear ${extId} as installing`);
|
||||
|
||||
const curState = this.getInstallationState(extId);
|
||||
|
||||
switch (curState) {
|
||||
case ExtensionInstallationState.INSTALLING:
|
||||
return void this.InstallingExtensions.delete(extId);
|
||||
return void this.installingExtensions.delete(extId);
|
||||
default:
|
||||
throw new Error(
|
||||
`${Prefix}: cannot clear INSTALLING state for ${extId}, it is currently ${curState}`,
|
||||
@@ -141,13 +144,13 @@ export class ExtensionInstallationStateStore {
|
||||
* @throws if state is not UNINSTALLING
|
||||
*/
|
||||
@action clearUninstalling = (extId: string): void => {
|
||||
logger.debug(`${Prefix}: trying to clear ${extId} as uninstalling`);
|
||||
this.dependencies.logger.debug(`${Prefix}: trying to clear ${extId} as uninstalling`);
|
||||
|
||||
const curState = this.getInstallationState(extId);
|
||||
|
||||
switch (curState) {
|
||||
case ExtensionInstallationState.UNINSTALLING:
|
||||
return void this.UninstallingExtensions.delete(extId);
|
||||
return void this.uninstallingExtensions.delete(extId);
|
||||
default:
|
||||
throw new Error(
|
||||
`${Prefix}: cannot clear UNINSTALLING state for ${extId}, it is currently ${curState}`,
|
||||
@@ -160,11 +163,11 @@ export class ExtensionInstallationStateStore {
|
||||
* @param extId The ID of the extension
|
||||
*/
|
||||
getInstallationState = (extId: string): ExtensionInstallationState => {
|
||||
if (this.InstallingExtensions.has(extId)) {
|
||||
if (this.installingExtensions.has(extId)) {
|
||||
return ExtensionInstallationState.INSTALLING;
|
||||
}
|
||||
|
||||
if (this.UninstallingExtensions.has(extId)) {
|
||||
if (this.uninstallingExtensions.has(extId)) {
|
||||
return ExtensionInstallationState.UNINSTALLING;
|
||||
}
|
||||
|
||||
@@ -197,14 +200,14 @@ export class ExtensionInstallationStateStore {
|
||||
* The current number of extensions installing
|
||||
*/
|
||||
@computed get installing(): number {
|
||||
return this.InstallingExtensions.size;
|
||||
return this.installingExtensions.size;
|
||||
}
|
||||
|
||||
/**
|
||||
* The current number of extensions uninstalling
|
||||
*/
|
||||
get uninstalling(): number {
|
||||
return this.UninstallingExtensions.size;
|
||||
return this.uninstallingExtensions.size;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -225,7 +228,7 @@ export class ExtensionInstallationStateStore {
|
||||
* The current number of extensions preinstalling
|
||||
*/
|
||||
get preinstalling(): number {
|
||||
return this.PreInstallIds.size;
|
||||
return this.preInstallIds.size;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import pathToNpmCliInjectable from "../../common/app-paths/path-to-npm-cli.injectable";
|
||||
import loggerInjectable from "../../common/logger.injectable";
|
||||
import { ExtensionInstaller } from "./extension-installer";
|
||||
import extensionPackageRootDirectoryInjectable from "./extension-package-root-directory/extension-package-root-directory.injectable";
|
||||
|
||||
@@ -11,6 +13,8 @@ const extensionInstallerInjectable = getInjectable({
|
||||
|
||||
instantiate: (di) => new ExtensionInstaller({
|
||||
extensionPackageRootDirectory: di.inject(extensionPackageRootDirectoryInjectable),
|
||||
logger: di.inject(loggerInjectable),
|
||||
pathToNpmCli: di.inject(pathToNpmCliInjectable),
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@@ -5,12 +5,14 @@
|
||||
|
||||
import AwaitLock from "await-lock";
|
||||
import child_process from "child_process";
|
||||
import logger from "../../main/logger";
|
||||
import type { Logger } from "../../common/logger";
|
||||
|
||||
const logModule = "[EXTENSION-INSTALLER]";
|
||||
|
||||
interface Dependencies {
|
||||
extensionPackageRootDirectory: string;
|
||||
readonly extensionPackageRootDirectory: string;
|
||||
readonly logger: Logger;
|
||||
readonly pathToNpmCli: string;
|
||||
}
|
||||
|
||||
const baseNpmInstallArgs = [
|
||||
@@ -27,13 +29,9 @@ const baseNpmInstallArgs = [
|
||||
* Installs dependencies for extensions
|
||||
*/
|
||||
export class ExtensionInstaller {
|
||||
private installLock = new AwaitLock();
|
||||
private readonly installLock = new AwaitLock();
|
||||
|
||||
constructor(private dependencies: Dependencies) {}
|
||||
|
||||
get npmPath() {
|
||||
return __non_webpack_require__.resolve("npm");
|
||||
}
|
||||
constructor(private readonly dependencies: Dependencies) {}
|
||||
|
||||
/**
|
||||
* Install single package using npm
|
||||
@@ -43,9 +41,9 @@ export class ExtensionInstaller {
|
||||
await this.installLock.acquireAsync();
|
||||
|
||||
try {
|
||||
logger.info(`${logModule} installing package from ${name} to ${this.dependencies.extensionPackageRootDirectory}`);
|
||||
this.dependencies.logger.info(`${logModule} installing package from ${name} to ${this.dependencies.extensionPackageRootDirectory}`);
|
||||
await this.npm(...baseNpmInstallArgs, name);
|
||||
logger.info(`${logModule} package ${name} installed to ${this.dependencies.extensionPackageRootDirectory}`);
|
||||
this.dependencies.logger.info(`${logModule} package ${name} installed to ${this.dependencies.extensionPackageRootDirectory}`);
|
||||
} finally {
|
||||
this.installLock.release();
|
||||
}
|
||||
@@ -53,7 +51,7 @@ export class ExtensionInstaller {
|
||||
|
||||
private npm(...args: string[]): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = child_process.fork(this.npmPath, args, {
|
||||
const child = child_process.fork(this.dependencies.pathToNpmCli, args, {
|
||||
cwd: this.dependencies.extensionPackageRootDirectory,
|
||||
silent: true,
|
||||
env: {},
|
||||
|
||||
@@ -4,12 +4,11 @@
|
||||
*/
|
||||
import { ipcMain } from "electron";
|
||||
import { IpcPrefix, IpcRegistrar } from "./ipc-registrar";
|
||||
import { Disposers } from "../lens-extension";
|
||||
import { Disposers, lensExtensionDependencies } from "../lens-extension";
|
||||
import type { LensMainExtension } from "../lens-main-extension";
|
||||
import type { Disposer } from "../../common/utils";
|
||||
import { once } from "lodash";
|
||||
import { ipcMainHandle } from "../../common/ipc";
|
||||
import logger from "../../main/logger";
|
||||
|
||||
export abstract class IpcMain extends IpcRegistrar {
|
||||
constructor(extension: LensMainExtension) {
|
||||
@@ -28,12 +27,12 @@ export abstract class IpcMain extends IpcRegistrar {
|
||||
listen(channel: string, listener: (event: Electron.IpcRendererEvent, ...args: any[]) => any): Disposer {
|
||||
const prefixedChannel = `extensions@${this[IpcPrefix]}:${channel}`;
|
||||
const cleanup = once(() => {
|
||||
logger.info(`[IPC-RENDERER]: removing extension listener`, { channel, extension: { name: this.extension.name, version: this.extension.version }});
|
||||
this.extension[lensExtensionDependencies].logger.info(`[IPC-RENDERER]: removing extension listener`, { channel, extension: { name: this.extension.name, version: this.extension.version }});
|
||||
|
||||
return ipcMain.removeListener(prefixedChannel, listener);
|
||||
});
|
||||
|
||||
logger.info(`[IPC-RENDERER]: adding extension listener`, { channel, extension: { name: this.extension.name, version: this.extension.version }});
|
||||
this.extension[lensExtensionDependencies].logger.info(`[IPC-RENDERER]: adding extension listener`, { channel, extension: { name: this.extension.name, version: this.extension.version }});
|
||||
ipcMain.addListener(prefixedChannel, listener);
|
||||
this.extension[Disposers].push(cleanup);
|
||||
|
||||
@@ -48,10 +47,10 @@ export abstract class IpcMain extends IpcRegistrar {
|
||||
handle(channel: string, handler: (event: Electron.IpcMainInvokeEvent, ...args: any[]) => any): void {
|
||||
const prefixedChannel = `extensions@${this[IpcPrefix]}:${channel}`;
|
||||
|
||||
logger.info(`[IPC-RENDERER]: adding extension handler`, { channel, extension: { name: this.extension.name, version: this.extension.version }});
|
||||
this.extension[lensExtensionDependencies].logger.info(`[IPC-RENDERER]: adding extension handler`, { channel, extension: { name: this.extension.name, version: this.extension.version }});
|
||||
ipcMainHandle(prefixedChannel, handler);
|
||||
this.extension[Disposers].push(() => {
|
||||
logger.info(`[IPC-RENDERER]: removing extension handler`, { channel, extension: { name: this.extension.name, version: this.extension.version }});
|
||||
this.extension[lensExtensionDependencies].logger.info(`[IPC-RENDERER]: removing extension handler`, { channel, extension: { name: this.extension.name, version: this.extension.version }});
|
||||
|
||||
return ipcMain.removeHandler(prefixedChannel);
|
||||
});
|
||||
|
||||
@@ -12,7 +12,7 @@ export const IpcPrefix = Symbol();
|
||||
export abstract class IpcRegistrar extends Singleton {
|
||||
readonly [IpcPrefix]: string;
|
||||
|
||||
constructor(protected extension: LensExtension) {
|
||||
constructor(protected readonly extension: LensExtension) {
|
||||
super();
|
||||
this[IpcPrefix] = createHash("sha256").update(extension.id).digest("hex");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user