From 128b05d4d46344a511398f654865c133c6e36514 Mon Sep 17 00:00:00 2001
From: Sebastian Malton
Date: Wed, 5 Apr 2023 10:17:21 -0400
Subject: [PATCH 01/16] feat: Allow built versions to specify an environment
(#7495)
* feat: Allow built versions to specify an environment
- This should be hard coded at build time
Signed-off-by: Sebastian Malton
* chore: Add default value to open-lens
Signed-off-by: Sebastian Malton
* chore: Add --no-bail to test script invocations
Signed-off-by: Sebastian Malton
* chore: Add tests for coverage of new code
Signed-off-by: Sebastian Malton
---------
Signed-off-by: Sebastian Malton
---
package.json | 4 ++--
.../core/src/extensions/common-api/app.ts | 6 +++++
.../common/build-environment.injectable.ts | 14 ++++++++++++
.../application/agnostic/index.ts | 2 ++
.../agnostic/src/environment-token.test.ts | 22 +++++++++++++++++++
.../agnostic/src/environment-token.ts | 9 ++++++++
6 files changed, 55 insertions(+), 2 deletions(-)
create mode 100644 packages/open-lens/src/common/build-environment.injectable.ts
create mode 100644 packages/technical-features/application/agnostic/src/environment-token.test.ts
create mode 100644 packages/technical-features/application/agnostic/src/environment-token.ts
diff --git a/package.json b/package.json
index 016cb3464c..3bbf863063 100644
--- a/package.json
+++ b/package.json
@@ -25,9 +25,9 @@
"lint:fix": "lerna run lint:fix --stream",
"mkdocs:serve-local": "docker build -t mkdocs-serve-local:latest mkdocs/ && docker run --rm -it -p 8000:8000 -v ${PWD}:/docs mkdocs-serve-local:latest",
"mkdocs:verify": "docker build -t mkdocs-serve-local:latest mkdocs/ && docker run --rm -v ${PWD}:/docs mkdocs-serve-local:latest build --strict",
- "test:unit": "lerna run --stream test:unit",
+ "test:unit": "lerna run --stream test:unit --no-bail",
"test:unit:watch": "jest --watch",
- "test:integration": "lerna run --stream test:integration",
+ "test:integration": "lerna run --stream test:integration --no-bail",
"bump-version": "lerna version --no-git-tag-version --no-push",
"precreate-release-pr": "cd packages/release-tool && npm run build",
"create-release-pr": "node packages/release-tool/dist/index.js"
diff --git a/packages/core/src/extensions/common-api/app.ts b/packages/core/src/extensions/common-api/app.ts
index 9e0c84f4e0..a7b33c35cc 100644
--- a/packages/core/src/extensions/common-api/app.ts
+++ b/packages/core/src/extensions/common-api/app.ts
@@ -14,6 +14,7 @@ import { buildVersionInjectionToken } from "../../common/vars/build-semantic-ver
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";
const userStore = asLegacyGlobalForExtensionApi(userPreferencesStateInjectable);
const enabledExtensions = asLegacyGlobalForExtensionApi(enabledExtensionsInjectable);
@@ -53,6 +54,11 @@ export const App = {
return di.inject(isLinuxInjectable);
},
+ get lensBuildEnvironment() {
+ const di = getLegacyGlobalDiForExtensionApi();
+
+ return di.inject(lensBuildEnvironmentInjectionToken);
+ },
/**
* @deprecated This value is now `""` and is left here for backwards compatibility.
*/
diff --git a/packages/open-lens/src/common/build-environment.injectable.ts b/packages/open-lens/src/common/build-environment.injectable.ts
new file mode 100644
index 0000000000..790b4e3fcb
--- /dev/null
+++ b/packages/open-lens/src/common/build-environment.injectable.ts
@@ -0,0 +1,14 @@
+/**
+ * Copyright (c) OpenLens Authors. All rights reserved.
+ * Licensed under MIT License. See LICENSE in root directory for more information.
+ */
+import { lensBuildEnvironmentInjectionToken } from "@k8slens/application";
+import { getInjectable } from "@ogre-tools/injectable";
+
+const lensBuildEnvironmentInjectable = getInjectable({
+ id: "lens-build-environment",
+ instantiate: () => "unknown",
+ injectionToken: lensBuildEnvironmentInjectionToken,
+});
+
+export default lensBuildEnvironmentInjectable;
diff --git a/packages/technical-features/application/agnostic/index.ts b/packages/technical-features/application/agnostic/index.ts
index 2e5595a816..fd8c0b4800 100644
--- a/packages/technical-features/application/agnostic/index.ts
+++ b/packages/technical-features/application/agnostic/index.ts
@@ -7,3 +7,5 @@ export { startApplicationInjectionToken } from "./src/start-application/start-ap
export { applicationInformationToken } from "./src/application-information-token.no-coverage";
export type { ApplicationInformation } from "./src/application-information-token.no-coverage";
+
+export { lensBuildEnvironmentInjectionToken } from "./src/environment-token";
diff --git a/packages/technical-features/application/agnostic/src/environment-token.test.ts b/packages/technical-features/application/agnostic/src/environment-token.test.ts
new file mode 100644
index 0000000000..bece4e0ac7
--- /dev/null
+++ b/packages/technical-features/application/agnostic/src/environment-token.test.ts
@@ -0,0 +1,22 @@
+import { createContainer, DiContainer, getInjectable } from "@ogre-tools/injectable";
+import { lensBuildEnvironmentInjectionToken } from "./environment-token";
+
+describe("environment-token coverage tests", () => {
+ let di: DiContainer;
+
+ beforeEach(() => {
+ di = createContainer("irrelevant");
+ });
+
+ it("should be able to specify a build environment", () => {
+ di.register(
+ getInjectable({
+ id: "some-id",
+ instantiate: () => "some-value",
+ injectionToken: lensBuildEnvironmentInjectionToken,
+ }),
+ );
+
+ expect(di.inject(lensBuildEnvironmentInjectionToken)).toBe("some-value");
+ });
+});
diff --git a/packages/technical-features/application/agnostic/src/environment-token.ts b/packages/technical-features/application/agnostic/src/environment-token.ts
new file mode 100644
index 0000000000..111c45d526
--- /dev/null
+++ b/packages/technical-features/application/agnostic/src/environment-token.ts
@@ -0,0 +1,9 @@
+/**
+ * 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 lensBuildEnvironmentInjectionToken = getInjectionToken({
+ id: "lens-build-environment-token",
+});
From 351f9d492f6e52e9e97d17d71e2bbdbbde4ea2db Mon Sep 17 00:00:00 2001
From: Sebastian Malton
Date: Wed, 5 Apr 2023 10:17:35 -0400
Subject: [PATCH 02/16] fix: Referencing apiManager should not throw (#7468)
Signed-off-by: Sebastian Malton
---
.../k8s-api/__tests__/api-manager.test.ts | 14 +++++++++
.../common/k8s-api/api-manager/api-manager.ts | 4 +--
.../k8s-api/api-manager/manager.injectable.ts | 29 +++++++++++--------
3 files changed, 33 insertions(+), 14 deletions(-)
diff --git a/packages/core/src/common/k8s-api/__tests__/api-manager.test.ts b/packages/core/src/common/k8s-api/__tests__/api-manager.test.ts
index ce117d9475..0490f446fe 100644
--- a/packages/core/src/common/k8s-api/__tests__/api-manager.test.ts
+++ b/packages/core/src/common/k8s-api/__tests__/api-manager.test.ts
@@ -206,3 +206,17 @@ describe("ApiManager", () => {
});
});
});
+
+describe("ApiManger without storesAndApisCanBeCreated", () => {
+ let di: DiContainer;
+
+ beforeEach(() => {
+ di = getDiForUnitTesting();
+
+ di.override(storesAndApisCanBeCreatedInjectable, () => false);
+ });
+
+ it("should not throw when creating apiManager", () => {
+ di.inject(apiManagerInjectable);
+ });
+});
diff --git a/packages/core/src/common/k8s-api/api-manager/api-manager.ts b/packages/core/src/common/k8s-api/api-manager/api-manager.ts
index 6b60ba8e7a..23574822ed 100644
--- a/packages/core/src/common/k8s-api/api-manager/api-manager.ts
+++ b/packages/core/src/common/k8s-api/api-manager/api-manager.ts
@@ -25,7 +25,7 @@ export type KubeObjectStoreFrom = Api extends KubeApi) => boolean;
-interface Dependencies {
+export interface ApiManagerDependencies {
readonly apis: IComputedValue;
readonly crdApis: IComputedValue;
readonly stores: IComputedValue;
@@ -38,7 +38,7 @@ export class ApiManager {
private readonly defaultCrdStores = observable.map();
private readonly apis = observable.map();
- constructor(private readonly dependencies: Dependencies) {
+ constructor(private readonly dependencies: ApiManagerDependencies) {
// NOTE: this is done to preserve the old behaviour of an API being discoverable using all previous apiBases
autorun(() => {
const apis = iter.chain(this.dependencies.apis.get().values())
diff --git a/packages/core/src/common/k8s-api/api-manager/manager.injectable.ts b/packages/core/src/common/k8s-api/api-manager/manager.injectable.ts
index 2ffd41a296..6caca127f5 100644
--- a/packages/core/src/common/k8s-api/api-manager/manager.injectable.ts
+++ b/packages/core/src/common/k8s-api/api-manager/manager.injectable.ts
@@ -18,18 +18,23 @@ const apiManagerInjectable = getInjectable({
const computedInjectMany = di.inject(computedInjectManyInjectable);
const storesAndApisCanBeCreated = di.inject(storesAndApisCanBeCreatedInjectionToken);
- return new ApiManager({
- apis: storesAndApisCanBeCreated
- ? computedInjectMany(kubeApiInjectionToken)
- : computed(() => []),
- stores: storesAndApisCanBeCreated
- ? computedInjectMany(kubeObjectStoreInjectionToken)
- : computed(() => []),
- crdApis: storesAndApisCanBeCreated
- ? computedInjectMany(customResourceDefinitionApiInjectionToken)
- : computed(() => []),
- createCustomResourceStore: di.inject(createCustomResourceStoreInjectable),
- });
+ return new ApiManager((
+ storesAndApisCanBeCreated
+ ? {
+ apis: computedInjectMany(kubeApiInjectionToken),
+ stores: computedInjectMany(kubeObjectStoreInjectionToken),
+ crdApis: computedInjectMany(customResourceDefinitionApiInjectionToken),
+ createCustomResourceStore: di.inject(createCustomResourceStoreInjectable),
+ }
+ : {
+ apis: computed(() => []),
+ stores: computed(() => []),
+ crdApis: computed(() => []),
+ createCustomResourceStore: () => {
+ throw new Error("Tried to create a KubeObjectStore for a CustomResource in a disallowed environment");
+ },
+ }
+ ));
},
});
From 058494bc73aeef9a4d527fc0d93ca24c48a7ee50 Mon Sep 17 00:00:00 2001
From: Sebastian Malton
Date: Wed, 5 Apr 2023 10:21:38 -0400
Subject: [PATCH 03/16] Introduce clearer boundry between extensions (#7164)
- Bundled extensions are always enabled, and are always compatible
- Have bundled extensions be loaded asyncronously to support
typescript dynamic import (which is typed) as opposed to require
Signed-off-by: Sebastian Malton
---
.../src/common/protocol-handler/router.ts | 2 +-
.../__tests__/extension-loader.test.ts | 4 +-
.../extension-discovery.ts | 36 +--
.../create-extension-instance.token.ts | 7 +-
.../extension-loader/extension-loader.ts | 109 ++++-----
.../core/src/extensions/lens-extension.ts | 7 +-
...gation-using-application-menu.test.ts.snap | 2 +-
.../enabled/common/is-enabled.injectable.ts | 9 +-
.../create-extension-instance.injectable.ts | 2 +-
.../protocol-handler/__test__/router.test.ts | 34 +--
.../lens-protocol-router-main.ts | 28 +--
.../flag-renderer-as-loaded.injectable.ts | 2 +-
.../flag-renderer-as-not-loaded.injectable.ts | 2 +-
.../attempt-install.injectable.tsx | 2 +-
.../unpack-extension.injectable.tsx | 2 +-
.../disable-extension.injectable.ts | 27 +++
.../disable-extension.injectable.ts | 18 --
.../disable-extension/disable-extension.ts | 20 --
.../enable-extension.injectable.ts | 27 +++
.../enable-extension.injectable.ts | 18 --
.../enable-extension/enable-extension.ts | 20 --
.../components/+extensions/extensions.tsx | 156 ++++--------
.../components/+extensions/install.tsx | 153 ++++++------
.../+extensions/installed-extensions.tsx | 223 +++++++++---------
.../uninstall-extension.injectable.tsx | 4 +-
.../user-extensions.injectable.ts | 2 +-
.../create-extension-instance.injectable.ts | 2 +-
.../src/bundled-extension.ts | 10 +-
.../legacy-extensions/src/lens-extension.ts | 62 +++--
29 files changed, 440 insertions(+), 550 deletions(-)
create mode 100644 packages/core/src/renderer/components/+extensions/disable-extension.injectable.ts
delete mode 100644 packages/core/src/renderer/components/+extensions/disable-extension/disable-extension.injectable.ts
delete mode 100644 packages/core/src/renderer/components/+extensions/disable-extension/disable-extension.ts
create mode 100644 packages/core/src/renderer/components/+extensions/enable-extension.injectable.ts
delete mode 100644 packages/core/src/renderer/components/+extensions/enable-extension/enable-extension.injectable.ts
delete mode 100644 packages/core/src/renderer/components/+extensions/enable-extension/enable-extension.ts
diff --git a/packages/core/src/common/protocol-handler/router.ts b/packages/core/src/common/protocol-handler/router.ts
index 7a48dbb343..2147e932e2 100644
--- a/packages/core/src/common/protocol-handler/router.ts
+++ b/packages/core/src/common/protocol-handler/router.ts
@@ -209,7 +209,7 @@ export abstract class LensProtocolRouter {
return name;
}
- if (!this.dependencies.isExtensionEnabled(extension)) {
+ if (!extension.isBundled && !this.dependencies.isExtensionEnabled(extension.id)) {
this.dependencies.logger.info(`${LensProtocolRouter.LoggingPrefix}: Extension ${name} matched, but not enabled`);
return name;
diff --git a/packages/core/src/extensions/__tests__/extension-loader.test.ts b/packages/core/src/extensions/__tests__/extension-loader.test.ts
index 9be0507f6d..51a43dfeff 100644
--- a/packages/core/src/extensions/__tests__/extension-loader.test.ts
+++ b/packages/core/src/extensions/__tests__/extension-loader.test.ts
@@ -113,13 +113,13 @@ describe("ExtensionLoader", () => {
});
it("renderer updates extension after ipc broadcast", async () => {
- expect(extensionLoader.userExtensions).toEqual(new Map());
+ expect(extensionLoader.userExtensions.get()).toEqual(new Map());
await extensionLoader.init();
await delay(10);
// Assert the extensions after the extension broadcast event
- expect(extensionLoader.userExtensions).toEqual(
+ expect(extensionLoader.userExtensions.get()).toEqual(
new Map([
["manifest/path", {
absolutePath: "/test/1",
diff --git a/packages/core/src/extensions/extension-discovery/extension-discovery.ts b/packages/core/src/extensions/extension-discovery/extension-discovery.ts
index 7a39fa7467..f097af9731 100644
--- a/packages/core/src/extensions/extension-discovery/extension-discovery.ts
+++ b/packages/core/src/extensions/extension-discovery/extension-discovery.ts
@@ -10,7 +10,7 @@ import { broadcastMessage, ipcMainHandle, ipcRendererOn } from "../../common/ipc
import { toJS } from "../../common/utils";
import { isErrnoException } from "@k8slens/utilities";
import type { ExtensionLoader } from "../extension-loader";
-import type { InstalledExtension, LensExtensionId, LensExtensionManifest } from "@k8slens/legacy-extensions";
+import type { InstalledExtension, LensExtensionId, LensExtensionManifest, ExternalInstalledExtension } from "@k8slens/legacy-extensions";
import type { ExtensionInstallationStateStore } from "../extension-installation-state-store/extension-installation-state-store";
import { extensionDiscoveryStateChannel } from "../../common/ipc/extension-handling";
import { requestInitialExtensionDiscovery } from "../../renderer/ipc";
@@ -73,10 +73,6 @@ interface ExtensionDiscoveryChannelMessage {
*/
const isDirectoryLike = (lstat: Stats) => lstat.isDirectory() || lstat.isSymbolicLink();
-interface LoadFromFolderOptions {
- isBundled?: boolean;
-}
-
interface ExtensionDiscoveryEvents {
add: (ext: InstalledExtension) => void;
remove: (extId: LensExtensionId) => void;
@@ -271,7 +267,7 @@ export class ExtensionDiscovery {
* @param extensionId The ID of the extension to uninstall.
*/
async uninstallExtension(extensionId: LensExtensionId): Promise {
- const extension = this.extensions.get(extensionId) ?? this.dependencies.extensionLoader.getExtension(extensionId);
+ const extension = this.extensions.get(extensionId) ?? this.dependencies.extensionLoader.getExtensionById(extensionId);
if (!extension) {
return void this.dependencies.logger.warn(`${logModule} could not uninstall extension, not found`, { id: extensionId });
@@ -330,24 +326,26 @@ export class ExtensionDiscovery {
* Returns InstalledExtension from path to package.json file.
* Also updates this.packagesJson.
*/
- protected async getByManifest(manifestPath: string, { isBundled = false } = {}): Promise {
+ protected async loadExtensionFromFolder(folderPath: string): Promise {
+ const manifestPath = this.dependencies.joinPaths(folderPath, manifestFilename);
+
try {
const manifest = await this.dependencies.readJsonFile(manifestPath) as unknown as LensExtensionManifest;
- const id = isBundled ? manifestPath : this.getInstalledManifestPath(manifest.name);
- const isEnabled = this.dependencies.isExtensionEnabled({ id, isBundled });
+ const id = this.getInstalledManifestPath(manifest.name);
+ const isEnabled = this.dependencies.isExtensionEnabled(id);
const extensionDir = this.dependencies.getDirnameOfPath(manifestPath);
const npmPackage = this.dependencies.joinPaths(extensionDir, `${manifest.name}-${manifest.version}.tgz`);
const absolutePath = this.dependencies.isProduction && await this.dependencies.pathExists(npmPackage)
? npmPackage
: extensionDir;
- const isCompatible = isBundled || this.dependencies.isCompatibleExtension(manifest);
+ const isCompatible = this.dependencies.isCompatibleExtension(manifest);
return {
id,
absolutePath,
manifestPath: id,
manifest,
- isBundled,
+ isBundled: false,
isEnabled,
isCompatible,
};
@@ -363,14 +361,14 @@ export class ExtensionDiscovery {
}
}
- async ensureExtensions(): Promise
,
+ );
runInAction(() => {
- this.editingResource.firstDraft = currentValue;
+ this.editingResource.firstDraft = yaml.dump(currentVersion);
+ this.editingResource.resource = selfLink;
});
- return result.response.toString();
+ // NOTE: This is required for `saveAndClose` to work correctly
+ return [];
};
}
diff --git a/packages/core/src/renderer/components/dock/edit-resource/view.tsx b/packages/core/src/renderer/components/dock/edit-resource/view.tsx
index 0465f80c93..107728e81d 100644
--- a/packages/core/src/renderer/components/dock/edit-resource/view.tsx
+++ b/packages/core/src/renderer/components/dock/edit-resource/view.tsx
@@ -56,12 +56,14 @@ const NonInjectedEditResource = observer(({
Namespace:
- )} />
+ )}
+ />
+ onError={model.configuration.error.onChange}
+ />
>
)
}
diff --git a/packages/core/src/renderer/components/kube-object-details/kube-object-detail-items/implementations/horizontal-pod-autoscaler-detail-item.injectable.ts b/packages/core/src/renderer/components/kube-object-details/kube-object-detail-items/implementations/horizontal-pod-autoscaler-detail-item.injectable.ts
index 8fe4b7da38..449feac7ea 100644
--- a/packages/core/src/renderer/components/kube-object-details/kube-object-detail-items/implementations/horizontal-pod-autoscaler-detail-item.injectable.ts
+++ b/packages/core/src/renderer/components/kube-object-details/kube-object-detail-items/implementations/horizontal-pod-autoscaler-detail-item.injectable.ts
@@ -4,7 +4,7 @@
*/
import { getInjectable } from "@ogre-tools/injectable";
import { kubeObjectDetailItemInjectionToken } from "../kube-object-detail-item-injection-token";
-import { HpaDetails } from "../../../+config-horizontal-pod-autoscalers";
+import { HorizontalPodAutoscalerDetails } from "../../../+config-horizontal-pod-autoscalers";
import { computed } from "mobx";
import { kubeObjectMatchesToKindAndApiVersion } from "../kube-object-matches-to-kind-and-api-version";
import currentKubeObjectInDetailsInjectable from "../../current-kube-object-in-details.injectable";
@@ -16,7 +16,7 @@ const horizontalPodAutoscalerDetailItemInjectable = getInjectable({
const kubeObject = di.inject(currentKubeObjectInDetailsInjectable);
return {
- Component: HpaDetails,
+ Component: HorizontalPodAutoscalerDetails,
enabled: computed(() => isHorizontalPodAutoscaler(kubeObject.value.get()?.object)),
orderNumber: 10,
};
diff --git a/packages/core/src/renderer/components/monaco-editor/monaco-editor.tsx b/packages/core/src/renderer/components/monaco-editor/monaco-editor.tsx
index 7e36639c41..592d288e13 100644
--- a/packages/core/src/renderer/components/monaco-editor/monaco-editor.tsx
+++ b/packages/core/src/renderer/components/monaco-editor/monaco-editor.tsx
@@ -246,12 +246,10 @@ class NonInjectedMonacoEditor extends React.Component this.model, this.onModelChange),
- reaction(() => this.theme, theme => {
- if (theme) {
- editor.setTheme(theme);
- }
+ reaction(() => this.theme, editor.setTheme),
+ reaction(() => this.props.value, value => this.setValue(value), {
+ fireImmediately: true,
}),
- reaction(() => this.props.value, value => this.setValue(value)),
reaction(() => this.options, opts => this.editor.updateOptions(opts)),
() => onDidLayoutChangeDisposer.dispose(),
diff --git a/packages/infrastructure/eslint-config/prettier-config.json b/packages/infrastructure/eslint-config/prettier-config.json
index c9f2606a59..7c1cbfc0a5 100644
--- a/packages/infrastructure/eslint-config/prettier-config.json
+++ b/packages/infrastructure/eslint-config/prettier-config.json
@@ -1,5 +1,5 @@
{
- "printWidth": 100,
+ "printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"semi": true,
diff --git a/packages/technical-features/application/agnostic/src/start-application/start-application.injectable.ts b/packages/technical-features/application/agnostic/src/start-application/start-application.injectable.ts
index 87f6d1f7db..ea2f4f8a5b 100644
--- a/packages/technical-features/application/agnostic/src/start-application/start-application.injectable.ts
+++ b/packages/technical-features/application/agnostic/src/start-application/start-application.injectable.ts
@@ -13,9 +13,7 @@ const startApplicationInjectable = getInjectable({
instantiate: (di): StartApplication => {
const runManyAsync = runManyFor(di);
- const beforeApplicationIsLoading = runManyAsync(
- timeSlots.beforeApplicationIsLoadingInjectionToken,
- );
+ const beforeApplicationIsLoading = runManyAsync(timeSlots.beforeApplicationIsLoadingInjectionToken);
const onLoadOfApplication = runManyAsync(timeSlots.onLoadOfApplicationInjectionToken);
const afterApplicationIsLoaded = runManyAsync(timeSlots.afterApplicationIsLoadedInjectionToken);
diff --git a/packages/technical-features/application/electron-main/src/start-application/start-electron-application.injectable.ts b/packages/technical-features/application/electron-main/src/start-application/start-electron-application.injectable.ts
index 495f75ec27..bd17d85991 100644
--- a/packages/technical-features/application/electron-main/src/start-application/start-electron-application.injectable.ts
+++ b/packages/technical-features/application/electron-main/src/start-application/start-electron-application.injectable.ts
@@ -1,9 +1,4 @@
-import {
- DiContainer,
- getInjectable,
- instantiationDecoratorToken,
- lifecycleEnum,
-} from "@ogre-tools/injectable";
+import { DiContainer, getInjectable, instantiationDecoratorToken, lifecycleEnum } from "@ogre-tools/injectable";
import { startApplicationInjectionToken } from "@k8slens/application";
import whenAppIsReadyInjectable from "./when-app-is-ready.injectable";
import { beforeAnythingInjectionToken, beforeElectronIsReadyInjectionToken } from "./time-slots";
diff --git a/packages/technical-features/application/electron-main/src/starting-of-electron-main-application.test.ts b/packages/technical-features/application/electron-main/src/starting-of-electron-main-application.test.ts
index d64cec3bc5..ec4ae1a836 100644
--- a/packages/technical-features/application/electron-main/src/starting-of-electron-main-application.test.ts
+++ b/packages/technical-features/application/electron-main/src/starting-of-electron-main-application.test.ts
@@ -1,10 +1,7 @@
import { createContainer, DiContainer, getInjectable } from "@ogre-tools/injectable";
import { registerFeature } from "@k8slens/feature-core";
import { applicationFeatureForElectronMain } from "./feature";
-import {
- beforeApplicationIsLoadingInjectionToken,
- startApplicationInjectionToken,
-} from "@k8slens/application";
+import { beforeApplicationIsLoadingInjectionToken, startApplicationInjectionToken } from "@k8slens/application";
import asyncFn, { AsyncFnMock } from "@async-fn/jest";
import whenAppIsReadyInjectable from "./start-application/when-app-is-ready.injectable";
import * as timeSlots from "./start-application/time-slots";
diff --git a/packages/technical-features/feature-core/src/deregister-feature.ts b/packages/technical-features/feature-core/src/deregister-feature.ts
index 4476120ab7..8bd08e9077 100644
--- a/packages/technical-features/feature-core/src/deregister-feature.ts
+++ b/packages/technical-features/feature-core/src/deregister-feature.ts
@@ -2,9 +2,7 @@ import type { DiContainer } from "@ogre-tools/injectable";
import type { Feature } from "./feature";
import { featureContextMapInjectable } from "./feature-context-map-injectable";
-const getDependingFeaturesFor = (
- featureContextMap: Map }>,
-) => {
+const getDependingFeaturesFor = (featureContextMap: Map }>) => {
const getDependingFeaturesForRecursion = (feature: Feature, atRoot = true): string[] => {
const context = featureContextMap.get(feature);
@@ -36,11 +34,9 @@ const deregisterFeatureRecursed = (di: DiContainer, feature: Feature, dependedBy
const dependingFeatures = getDependingFeatures(feature);
if (!dependedBy && dependingFeatures.length) {
- throw new Error(
- `Tried to deregister Feature "${
- feature.id
- }", but it is the dependency of Features "${dependingFeatures.join(", ")}"`,
- );
+ const names = dependingFeatures.join(", ");
+
+ throw new Error(`Tried to deregister Feature "${feature.id}", but it is the dependency of Features "${names}"`);
}
if (dependedBy) {
diff --git a/packages/technical-features/feature-core/src/feature-dependencies.test.ts b/packages/technical-features/feature-core/src/feature-dependencies.test.ts
index 8ddf6e11b8..8fb69fe33f 100644
--- a/packages/technical-features/feature-core/src/feature-dependencies.test.ts
+++ b/packages/technical-features/feature-core/src/feature-dependencies.test.ts
@@ -59,9 +59,7 @@ describe("feature-dependencies", () => {
expect(() => {
deregisterFeature(di, someDependencyFeature);
- }).toThrow(
- 'Tried to deregister feature "some-dependency-feature", but it was not registered.',
- );
+ }).toThrow('Tried to deregister feature "some-dependency-feature", but it was not registered.');
});
it("given the parent Feature is deregistered, when injecting an injectable from the dependency Feature, throws", () => {
@@ -104,9 +102,7 @@ describe("feature-dependencies", () => {
it("when the first Feature is deregistered, throws", () => {
expect(() => {
deregisterFeature(di, someFeature1);
- }).toThrow(
- 'Tried to deregister Feature "some-feature-1", but it is the dependency of Features "some-feature-2"',
- );
+ }).toThrow('Tried to deregister Feature "some-feature-1", but it is the dependency of Features "some-feature-2"');
});
it("given the second Feature is deregistered, when injecting an injectable from the first Feature, still does so", () => {
@@ -180,9 +176,7 @@ describe("feature-dependencies", () => {
expect(() => {
di.inject(someInjectableInDependencyFeature);
- }).toThrow(
- 'Tried to inject non-registered injectable "irrelevant" -> "some-injectable-in-dependency-feature".',
- );
+ }).toThrow('Tried to inject non-registered injectable "irrelevant" -> "some-injectable-in-dependency-feature".');
});
});
@@ -256,9 +250,7 @@ describe("feature-dependencies", () => {
expect(() => {
di.inject(someInjectableInDependencyFeature);
- }).toThrow(
- 'Tried to inject non-registered injectable "irrelevant" -> "some-injectable-in-dependency-feature".',
- );
+ }).toThrow('Tried to inject non-registered injectable "irrelevant" -> "some-injectable-in-dependency-feature".');
});
});
});
diff --git a/packages/technical-features/feature-core/src/register-feature.ts b/packages/technical-features/feature-core/src/register-feature.ts
index f02b050002..535a93bf18 100644
--- a/packages/technical-features/feature-core/src/register-feature.ts
+++ b/packages/technical-features/feature-core/src/register-feature.ts
@@ -1,10 +1,7 @@
import type { DiContainer } from "@ogre-tools/injectable";
import { getInjectable } from "@ogre-tools/injectable";
import type { Feature } from "./feature";
-import {
- featureContextMapInjectable,
- featureContextMapInjectionToken,
-} from "./feature-context-map-injectable";
+import { featureContextMapInjectable, featureContextMapInjectionToken } from "./feature-context-map-injectable";
const createFeatureContext = (feature: Feature, di: DiContainer) => {
const featureContextInjectable = getInjectable({
@@ -58,10 +55,9 @@ const registerFeatureRecursed = (di: DiContainer, feature: Feature, dependedBy?:
if (dependedBy) {
const oldNumberOfDependents = featureContext.dependedBy.get(dependedBy) || 0;
+ const newNumberOfDependents = oldNumberOfDependents + 1;
- const newNumberOfDependants = oldNumberOfDependents + 1;
-
- featureContext.dependedBy.set(dependedBy, newNumberOfDependants);
+ featureContext.dependedBy.set(dependedBy, newNumberOfDependents);
}
if (!existingFeatureContext) {
diff --git a/packages/technical-features/messaging/agnostic/src/features/actual/index.ts b/packages/technical-features/messaging/agnostic/src/features/actual/index.ts
index f85542c954..f0acf5ee1c 100644
--- a/packages/technical-features/messaging/agnostic/src/features/actual/index.ts
+++ b/packages/technical-features/messaging/agnostic/src/features/actual/index.ts
@@ -21,15 +21,9 @@ export {
getMessageChannelListenerInjectable,
} from "./message/message-channel-listener-injection-token";
-export type {
- RequestChannel,
- RequestChannelHandler,
-} from "./request/request-channel-listener-injection-token";
+export type { RequestChannel, RequestChannelHandler } from "./request/request-channel-listener-injection-token";
-export type {
- RequestFromChannel,
- ChannelRequester,
-} from "./request/request-from-channel-injection-token";
+export type { RequestFromChannel, ChannelRequester } from "./request/request-from-channel-injection-token";
export type { EnlistMessageChannelListener } from "./message/enlist-message-channel-listener-injection-token";
export { enlistMessageChannelListenerInjectionToken } from "./message/enlist-message-channel-listener-injection-token";
diff --git a/packages/technical-features/messaging/agnostic/src/features/actual/listening-of-channels/listening-of-channels.injectable.ts b/packages/technical-features/messaging/agnostic/src/features/actual/listening-of-channels/listening-of-channels.injectable.ts
index 9040939f06..6d65621f12 100644
--- a/packages/technical-features/messaging/agnostic/src/features/actual/listening-of-channels/listening-of-channels.injectable.ts
+++ b/packages/technical-features/messaging/agnostic/src/features/actual/listening-of-channels/listening-of-channels.injectable.ts
@@ -21,9 +21,7 @@ export const listeningOfChannelsInjectionToken = getInjectionToken | RequestChannel },
->(
+const listening = | RequestChannel }>(
channelListeners: IComputedValue,
enlistChannelListener: (listener: T) => () => void,
getId: (listener: T) => string,
@@ -33,9 +31,7 @@ const listening = <
const reactionDisposer = reaction(
() => channelListeners.get(),
(newValues, oldValues = []) => {
- const addedListeners = newValues.filter(
- (newValue) => !oldValues.some((oldValue) => oldValue.id === newValue.id),
- );
+ const addedListeners = newValues.filter((newValue) => !oldValues.some((oldValue) => oldValue.id === newValue.id));
const removedListeners = oldValues.filter(
(oldValue) => !newValues.some((newValue) => newValue.id === oldValue.id),
@@ -45,9 +41,7 @@ const listening = <
const id = getId(listener);
if (listenerDisposers.has(id)) {
- throw new Error(
- `Tried to add listener for channel "${listener.channel.id}" but listener already exists.`,
- );
+ throw new Error(`Tried to add listener for channel "${listener.channel.id}" but listener already exists.`);
}
const disposer = enlistChannelListener(listener);
diff --git a/packages/technical-features/messaging/agnostic/src/features/actual/message/enlist-message-channel-listener-injection-token.ts b/packages/technical-features/messaging/agnostic/src/features/actual/message/enlist-message-channel-listener-injection-token.ts
index 1bb114ca09..19f4b32df6 100644
--- a/packages/technical-features/messaging/agnostic/src/features/actual/message/enlist-message-channel-listener-injection-token.ts
+++ b/packages/technical-features/messaging/agnostic/src/features/actual/message/enlist-message-channel-listener-injection-token.ts
@@ -1,16 +1,10 @@
import type { Disposer } from "@k8slens/utilities";
import { getInjectionToken } from "@ogre-tools/injectable";
-import type {
- MessageChannel,
- MessageChannelListener,
-} from "./message-channel-listener-injection-token";
+import type { MessageChannel, MessageChannelListener } from "./message-channel-listener-injection-token";
-export type EnlistMessageChannelListener = (
- listener: MessageChannelListener>,
-) => Disposer;
+export type EnlistMessageChannelListener = (listener: MessageChannelListener>) => Disposer;
-export const enlistMessageChannelListenerInjectionToken =
- getInjectionToken({
- id: "listening-to-a-message-channel",
- });
+export const enlistMessageChannelListenerInjectionToken = getInjectionToken({
+ id: "listening-to-a-message-channel",
+});
diff --git a/packages/technical-features/messaging/agnostic/src/features/actual/message/message-channel-listener-injection-token.ts b/packages/technical-features/messaging/agnostic/src/features/actual/message/message-channel-listener-injection-token.ts
index 0558bf6598..0e2ee20a64 100644
--- a/packages/technical-features/messaging/agnostic/src/features/actual/message/message-channel-listener-injection-token.ts
+++ b/packages/technical-features/messaging/agnostic/src/features/actual/message/message-channel-listener-injection-token.ts
@@ -18,9 +18,7 @@ export interface MessageChannelListener {
handler: MessageChannelHandler;
}
-export const messageChannelListenerInjectionToken = getInjectionToken<
- MessageChannelListener>
->({
+export const messageChannelListenerInjectionToken = getInjectionToken>>({
id: "message-channel-listener",
});
@@ -31,10 +29,7 @@ export interface GetMessageChannelListenerInfo,
- Message,
->(
+export const getMessageChannelListenerInjectable = , Message>(
info: GetMessageChannelListenerInfo,
) =>
getInjectable({
diff --git a/packages/technical-features/messaging/agnostic/src/features/actual/request/enlist-request-channel-listener-injection-token.ts b/packages/technical-features/messaging/agnostic/src/features/actual/request/enlist-request-channel-listener-injection-token.ts
index 7f2a04a78d..8f2d6c2c81 100644
--- a/packages/technical-features/messaging/agnostic/src/features/actual/request/enlist-request-channel-listener-injection-token.ts
+++ b/packages/technical-features/messaging/agnostic/src/features/actual/request/enlist-request-channel-listener-injection-token.ts
@@ -1,16 +1,12 @@
import type { Disposer } from "@k8slens/utilities/index";
import { getInjectionToken } from "@ogre-tools/injectable";
-import type {
- RequestChannel,
- RequestChannelListener,
-} from "./request-channel-listener-injection-token";
+import type { RequestChannel, RequestChannelListener } from "./request-channel-listener-injection-token";
export type EnlistRequestChannelListener = (
listener: RequestChannelListener>,
) => Disposer;
-export const enlistRequestChannelListenerInjectionToken =
- getInjectionToken({
- id: "listening-to-a-request-channel",
- });
+export const enlistRequestChannelListenerInjectionToken = getInjectionToken({
+ id: "listening-to-a-request-channel",
+});
diff --git a/packages/technical-features/messaging/agnostic/src/features/actual/request/get-request-channel.ts b/packages/technical-features/messaging/agnostic/src/features/actual/request/get-request-channel.ts
index c0ee40bcf4..e89f8a8d0e 100644
--- a/packages/technical-features/messaging/agnostic/src/features/actual/request/get-request-channel.ts
+++ b/packages/technical-features/messaging/agnostic/src/features/actual/request/get-request-channel.ts
@@ -1,7 +1,5 @@
import type { RequestChannel } from "./request-channel-listener-injection-token";
-export const getRequestChannel = (
- id: string,
-): RequestChannel => ({
+export const getRequestChannel = (id: string): RequestChannel => ({
id,
});
diff --git a/packages/technical-features/messaging/agnostic/src/features/actual/request/request-channel-listener-injection-token.ts b/packages/technical-features/messaging/agnostic/src/features/actual/request/request-channel-listener-injection-token.ts
index 2ec76ff546..4491b14fe1 100644
--- a/packages/technical-features/messaging/agnostic/src/features/actual/request/request-channel-listener-injection-token.ts
+++ b/packages/technical-features/messaging/agnostic/src/features/actual/request/request-channel-listener-injection-token.ts
@@ -7,10 +7,7 @@ export interface RequestChannel {
_responseSignature?: Response;
}
-export type RequestChannelHandler = Channel extends RequestChannel<
- infer Request,
- infer Response
->
+export type RequestChannelHandler = Channel extends RequestChannel
? (req: Request) => Promise | Response
: never;
diff --git a/packages/technical-features/messaging/agnostic/src/features/actual/request/request-from-channel-injection-token.ts b/packages/technical-features/messaging/agnostic/src/features/actual/request/request-from-channel-injection-token.ts
index 194091b588..f15dc97614 100644
--- a/packages/technical-features/messaging/agnostic/src/features/actual/request/request-from-channel-injection-token.ts
+++ b/packages/technical-features/messaging/agnostic/src/features/actual/request/request-from-channel-injection-token.ts
@@ -2,17 +2,11 @@ import { getInjectionToken } from "@ogre-tools/injectable";
import type { RequestChannel } from "./request-channel-listener-injection-token";
export interface RequestFromChannel {
- (
- channel: RequestChannel,
- request: Request,
- ): Promise;
+ (channel: RequestChannel, request: Request): Promise;
(channel: RequestChannel): Promise;
}
-export type ChannelRequester = Channel extends RequestChannel<
- infer Request,
- infer Response
->
+export type ChannelRequester = Channel extends RequestChannel
? (req: Request) => Promise>
: never;
diff --git a/packages/technical-features/messaging/agnostic/src/listening-of-requests.test.ts b/packages/technical-features/messaging/agnostic/src/listening-of-requests.test.ts
index e708c983c8..6432ac1376 100644
--- a/packages/technical-features/messaging/agnostic/src/listening-of-requests.test.ts
+++ b/packages/technical-features/messaging/agnostic/src/listening-of-requests.test.ts
@@ -121,9 +121,7 @@ describe("listening-of-requests", () => {
runInAction(() => {
di.register(someConflictingListenerInjectable);
});
- }).toThrow(
- 'Tried to add listener for channel "some-channel-id" but listener already exists.',
- );
+ }).toThrow('Tried to add listener for channel "some-channel-id" but listener already exists.');
});
describe("when another listener gets registered", () => {
diff --git a/packages/technical-features/messaging/computed-channel/index.ts b/packages/technical-features/messaging/computed-channel/index.ts
index dd72ecf71b..ba98df8cca 100644
--- a/packages/technical-features/messaging/computed-channel/index.ts
+++ b/packages/technical-features/messaging/computed-channel/index.ts
@@ -3,7 +3,4 @@ export {
computedChannelObserverInjectionToken,
} from "./src/computed-channel/computed-channel.injectable";
-export type {
- ChannelObserver,
- ComputedChannelFactory,
-} from "./src/computed-channel/computed-channel.injectable";
+export type { ChannelObserver, ComputedChannelFactory } from "./src/computed-channel/computed-channel.injectable";
diff --git a/packages/technical-features/messaging/computed-channel/src/computed-channel/computed-channel.injectable.ts b/packages/technical-features/messaging/computed-channel/src/computed-channel/computed-channel.injectable.ts
index b652a0c795..99d5d18fec 100644
--- a/packages/technical-features/messaging/computed-channel/src/computed-channel/computed-channel.injectable.ts
+++ b/packages/technical-features/messaging/computed-channel/src/computed-channel/computed-channel.injectable.ts
@@ -1,23 +1,13 @@
import { getInjectable, getInjectionToken } from "@ogre-tools/injectable";
-import {
- computed,
- IComputedValue,
- observable,
- onBecomeObserved,
- onBecomeUnobserved,
- runInAction,
-} from "mobx";
+import { computed, IComputedValue, observable, onBecomeObserved, onBecomeUnobserved, runInAction } from "mobx";
import type { MessageChannel } from "@k8slens/messaging";
import { getMessageChannelListenerInjectable } from "@k8slens/messaging";
import { sendMessageToChannelInjectionToken } from "@k8slens/messaging";
import { computedChannelAdministrationChannel } from "./computed-channel-administration-channel.injectable";
-export type ComputedChannelFactory = (
- channel: MessageChannel,
- pendingValue: T,
-) => IComputedValue;
+export type ComputedChannelFactory = (channel: MessageChannel, pendingValue: T) => IComputedValue;
export const computedChannelInjectionToken = getInjectionToken({
id: "computed-channel-injection-token",
diff --git a/packages/technical-features/messaging/computed-channel/src/computed-channel/computed-channel.test.tsx b/packages/technical-features/messaging/computed-channel/src/computed-channel/computed-channel.test.tsx
index 6bea2ca76d..abab064191 100644
--- a/packages/technical-features/messaging/computed-channel/src/computed-channel/computed-channel.test.tsx
+++ b/packages/technical-features/messaging/computed-channel/src/computed-channel/computed-channel.test.tsx
@@ -3,23 +3,13 @@ import { act } from "@testing-library/react";
import { createContainer, DiContainer, getInjectable } from "@ogre-tools/injectable";
import { getMessageBridgeFake, MessageBridgeFake } from "@k8slens/messaging-fake-bridge";
import { startApplicationInjectionToken } from "@k8slens/application";
-import {
- computed,
- IComputedValue,
- IObservableValue,
- observable,
- reaction,
- runInAction,
-} from "mobx";
+import { computed, IComputedValue, IObservableValue, observable, reaction, runInAction } from "mobx";
import type { MessageChannel } from "@k8slens/messaging";
import { getMessageChannelListenerInjectable } from "@k8slens/messaging";
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
import { registerFeature } from "@k8slens/feature-core";
import { testUtils } from "@k8slens/messaging";
-import {
- computedChannelInjectionToken,
- computedChannelObserverInjectionToken,
-} from "./computed-channel.injectable";
+import { computedChannelInjectionToken, computedChannelObserverInjectionToken } from "./computed-channel.injectable";
import { runWithThrownMobxReactions, renderFor } from "@k8slens/test-utils";
import { observer } from "mobx-react";
import {
@@ -36,9 +26,7 @@ const TestComponent = observer(({ someComputed }: { someComputed: IComputedValue
));
[{ scenarioIsAsync: true }, { scenarioIsAsync: false }].forEach(({ scenarioIsAsync }) =>
- describe(`computed-channel, given running message bridge fake as ${
- scenarioIsAsync ? "async" : "sync"
- }`, () => {
+ describe(`computed-channel, given running message bridge fake as ${scenarioIsAsync ? "async" : "sync"}`, () => {
describe("given multiple dis and a message channel and a channel observer and application has started", () => {
let di1: DiContainer;
let di2: DiContainer;
@@ -87,10 +75,7 @@ const TestComponent = observer(({ someComputed }: { someComputed: IComputedValue
messageBridgeFake.setAsync(scenarioIsAsync);
messageBridgeFake.involve(di1, di2);
- await Promise.all([
- di1.inject(startApplicationInjectionToken)(),
- di2.inject(startApplicationInjectionToken)(),
- ]);
+ await Promise.all([di1.inject(startApplicationInjectionToken)(), di2.inject(startApplicationInjectionToken)()]);
});
describe("given a channel observer and matching computed channel for the channel in di-2", () => {
@@ -175,9 +160,7 @@ const TestComponent = observer(({ someComputed }: { someComputed: IComputedValue
expect(observedValue).toBe("some-pending-value");
});
- const scenarioName = scenarioIsAsync
- ? "when admin messages are propagated"
- : "immediately";
+ const scenarioName = scenarioIsAsync ? "when admin messages are propagated" : "immediately";
// eslint-disable-next-line jest/valid-title
describe(scenarioName, () => {
@@ -196,9 +179,7 @@ const TestComponent = observer(({ someComputed }: { someComputed: IComputedValue
});
});
- const scenarioName = scenarioIsAsync
- ? "when returning value-messages propagate"
- : "immediately";
+ const scenarioName = scenarioIsAsync ? "when returning value-messages propagate" : "immediately";
// eslint-disable-next-line jest/valid-title
describe(scenarioName, () => {
@@ -227,9 +208,7 @@ const TestComponent = observer(({ someComputed }: { someComputed: IComputedValue
});
});
- const scenarioName = scenarioIsAsync
- ? "when value-messages propagate"
- : "immediately";
+ const scenarioName = scenarioIsAsync ? "when value-messages propagate" : "immediately";
// eslint-disable-next-line jest/valid-title
describe(scenarioName, () => {
@@ -258,9 +237,7 @@ const TestComponent = observer(({ someComputed }: { someComputed: IComputedValue
stopObserving();
});
- const scenarioName = scenarioIsAsync
- ? "when admin-messages propagate"
- : "immediately";
+ const scenarioName = scenarioIsAsync ? "when admin-messages propagate" : "immediately";
// eslint-disable-next-line jest/valid-title
describe(scenarioName, () => {
@@ -317,9 +294,7 @@ const TestComponent = observer(({ someComputed }: { someComputed: IComputedValue
expect(observedValue).toBe("some-pending-value");
});
- const scenarioName = scenarioIsAsync
- ? "when admin messages propagate"
- : "immediately";
+ const scenarioName = scenarioIsAsync ? "when admin messages propagate" : "immediately";
// eslint-disable-next-line jest/valid-title
describe(scenarioName, () => {
@@ -345,9 +320,7 @@ const TestComponent = observer(({ someComputed }: { someComputed: IComputedValue
expect(observedValue).toBe("some-pending-value");
});
- const scenarioTitle = scenarioIsAsync
- ? "when value-messages propagate back"
- : "immediately";
+ const scenarioTitle = scenarioIsAsync ? "when value-messages propagate back" : "immediately";
// eslint-disable-next-line jest/valid-title
describe(scenarioTitle, () => {
@@ -466,9 +439,7 @@ const TestComponent = observer(({ someComputed }: { someComputed: IComputedValue
expect(nonReactiveValue).toBe("some-initial-value");
});
- const scenarioName = scenarioIsAsync
- ? "when messages would be propagated"
- : "immediately";
+ const scenarioName = scenarioIsAsync ? "when messages would be propagated" : "immediately";
// eslint-disable-next-line jest/valid-title
describe(scenarioName, () => {
diff --git a/packages/technical-features/messaging/electron/main/src/channel-listeners/enlist-message-channel-listener.test.ts b/packages/technical-features/messaging/electron/main/src/channel-listeners/enlist-message-channel-listener.test.ts
index c4385246cd..898efdf3f1 100644
--- a/packages/technical-features/messaging/electron/main/src/channel-listeners/enlist-message-channel-listener.test.ts
+++ b/packages/technical-features/messaging/electron/main/src/channel-listeners/enlist-message-channel-listener.test.ts
@@ -1,9 +1,6 @@
import ipcMainInjectable from "../ipc-main/ipc-main.injectable";
import type { IpcMain, IpcMainEvent } from "electron";
-import {
- EnlistMessageChannelListener,
- enlistMessageChannelListenerInjectionToken,
-} from "@k8slens/messaging";
+import { EnlistMessageChannelListener, enlistMessageChannelListenerInjectionToken } from "@k8slens/messaging";
import { createContainer } from "@ogre-tools/injectable";
import { registerFeature } from "@k8slens/feature-core";
import { messagingFeatureForMain } from "../feature";
diff --git a/packages/technical-features/messaging/electron/main/src/request-from-channel/request-from-channel.injectable.ts b/packages/technical-features/messaging/electron/main/src/request-from-channel/request-from-channel.injectable.ts
index 220daf9fc7..94ce8c89be 100644
--- a/packages/technical-features/messaging/electron/main/src/request-from-channel/request-from-channel.injectable.ts
+++ b/packages/technical-features/messaging/electron/main/src/request-from-channel/request-from-channel.injectable.ts
@@ -1,19 +1,13 @@
/* c8 ignore start */
import { getInjectable } from "@ogre-tools/injectable";
-import {
- RequestChannel,
- RequestFromChannel,
- requestFromChannelInjectionToken,
-} from "@k8slens/messaging";
+import { RequestChannel, RequestFromChannel, requestFromChannelInjectionToken } from "@k8slens/messaging";
const requestFromChannelInjectable = getInjectable({
id: "request-from-channel",
instantiate: () =>
((channel: RequestChannel) => {
- throw new Error(
- `Tried to request from channel "${channel.id}" but requesting in "main" it's not supported yet`,
- );
+ throw new Error(`Tried to request from channel "${channel.id}" but requesting in "main" it's not supported yet`);
}) as unknown as RequestFromChannel,
injectionToken: requestFromChannelInjectionToken,
diff --git a/packages/technical-features/messaging/electron/main/src/send-message-to-channel/allow-communication-listener.injectable.ts b/packages/technical-features/messaging/electron/main/src/send-message-to-channel/allow-communication-listener.injectable.ts
index af74d7a810..7b80adabc0 100644
--- a/packages/technical-features/messaging/electron/main/src/send-message-to-channel/allow-communication-listener.injectable.ts
+++ b/packages/technical-features/messaging/electron/main/src/send-message-to-channel/allow-communication-listener.injectable.ts
@@ -1,9 +1,7 @@
import { getMessageChannel, getMessageChannelListenerInjectable } from "@k8slens/messaging";
import frameIdsInjectable from "./frameIds.injectable";
-const frameCommunicationAdminChannel = getMessageChannel(
- "frame-communication-admin-channel",
-);
+const frameCommunicationAdminChannel = getMessageChannel("frame-communication-admin-channel");
const allowCommunicationListenerInjectable = getMessageChannelListenerInjectable({
id: "allow-communication",
diff --git a/packages/technical-features/messaging/electron/renderer/src/allow-communication-to-iframe.injectable.ts b/packages/technical-features/messaging/electron/renderer/src/allow-communication-to-iframe.injectable.ts
index 59abe7f931..fe8928caca 100644
--- a/packages/technical-features/messaging/electron/renderer/src/allow-communication-to-iframe.injectable.ts
+++ b/packages/technical-features/messaging/electron/renderer/src/allow-communication-to-iframe.injectable.ts
@@ -2,9 +2,7 @@ import { getInjectable } from "@ogre-tools/injectable";
import { onLoadOfApplicationInjectionToken } from "@k8slens/application";
import { getMessageChannel, sendMessageToChannelInjectionToken } from "@k8slens/messaging";
-export const frameCommunicationAdminChannel = getMessageChannel(
- "frame-communication-admin-channel",
-);
+export const frameCommunicationAdminChannel = getMessageChannel("frame-communication-admin-channel");
const allowCommunicationToIframeInjectable = getInjectable({
id: "allow-communication-to-iframe-injectable",
diff --git a/packages/technical-features/messaging/electron/renderer/src/listening-of-messages/enlist-message-channel-listener.test.ts b/packages/technical-features/messaging/electron/renderer/src/listening-of-messages/enlist-message-channel-listener.test.ts
index dc89c7b3e7..a325821b91 100644
--- a/packages/technical-features/messaging/electron/renderer/src/listening-of-messages/enlist-message-channel-listener.test.ts
+++ b/packages/technical-features/messaging/electron/renderer/src/listening-of-messages/enlist-message-channel-listener.test.ts
@@ -1,9 +1,6 @@
import type { IpcRendererEvent, IpcRenderer } from "electron";
import ipcRendererInjectable from "../ipc/ipc-renderer.injectable";
-import {
- EnlistMessageChannelListener,
- enlistMessageChannelListenerInjectionToken,
-} from "@k8slens/messaging";
+import { EnlistMessageChannelListener, enlistMessageChannelListenerInjectionToken } from "@k8slens/messaging";
import { createContainer } from "@ogre-tools/injectable";
import { registerFeature } from "@k8slens/feature-core";
import { messagingFeatureForRenderer } from "../feature";
diff --git a/packages/technical-features/messaging/message-bridge-fake/src/get-message-bridge-fake/get-message-bridge-fake.test.ts b/packages/technical-features/messaging/message-bridge-fake/src/get-message-bridge-fake/get-message-bridge-fake.test.ts
index e91109df10..a3a3c86ad3 100644
--- a/packages/technical-features/messaging/message-bridge-fake/src/get-message-bridge-fake/get-message-bridge-fake.test.ts
+++ b/packages/technical-features/messaging/message-bridge-fake/src/get-message-bridge-fake/get-message-bridge-fake.test.ts
@@ -32,9 +32,7 @@ const someRequestChannelWithoutListeners: SomeRequestChannel = {
};
[{ scenarioIsAsync: true }, { scenarioIsAsync: false }].forEach(({ scenarioIsAsync }) =>
- describe(`get-message-bridge-fake, given running as ${
- scenarioIsAsync ? "async" : "sync"
- }`, () => {
+ describe(`get-message-bridge-fake, given running as ${scenarioIsAsync ? "async" : "sync"}`, () => {
let messageBridgeFake: any;
beforeEach(() => {
@@ -135,9 +133,7 @@ const someRequestChannelWithoutListeners: SomeRequestChannel = {
describe("given a message is sent in di-1", () => {
beforeEach(() => {
- const sendMessageToChannelFromDi1 = someDi1.inject(
- sendMessageToChannelInjectionToken,
- );
+ const sendMessageToChannelFromDi1 = someDi1.inject(sendMessageToChannelInjectionToken);
sendMessageToChannelFromDi1(someMessageChannel, "some-message");
});
@@ -161,13 +157,10 @@ const someRequestChannelWithoutListeners: SomeRequestChannel = {
});
it("the response gets handled in di-1", () => {
- expect(someHandler1MockInDi1).toHaveBeenCalledWith(
- "some-response-to: some-message",
- {
- frameId: 42,
- processId: 42,
- },
- );
+ expect(someHandler1MockInDi1).toHaveBeenCalledWith("some-response-to: some-message", {
+ frameId: 42,
+ processId: 42,
+ });
});
scenarioIsAsync &&
@@ -191,13 +184,10 @@ const someRequestChannelWithoutListeners: SomeRequestChannel = {
});
it("the response gets handled in di-1", () => {
- expect(someHandler1MockInDi1).toHaveBeenCalledWith(
- "some-response-to: some-message",
- {
- frameId: 42,
- processId: 42,
- },
- );
+ expect(someHandler1MockInDi1).toHaveBeenCalledWith("some-response-to: some-message", {
+ frameId: 42,
+ processId: 42,
+ });
});
});
});
@@ -375,9 +365,7 @@ const someRequestChannelWithoutListeners: SomeRequestChannel = {
const requestFromChannelFromDi2 = someDi2.inject(requestFromChannelInjectionToken);
- return expect(() =>
- requestFromChannelFromDi2(someRequestChannel, "irrelevant"),
- ).rejects.toThrow(
+ return expect(() => requestFromChannelFromDi2(someRequestChannel, "irrelevant")).rejects.toThrow(
'Tried to make a request but multiple listeners were discovered for channel "some-request-channel" in multiple DIs.',
);
});
@@ -385,9 +373,7 @@ const someRequestChannelWithoutListeners: SomeRequestChannel = {
it("when requesting from channel without listener, throws", () => {
const requestFromChannel = someDi1.inject(requestFromChannelInjectionToken);
- return expect(() =>
- requestFromChannel(someRequestChannelWithoutListeners, "irrelevant"),
- ).rejects.toThrow(
+ return expect(() => requestFromChannel(someRequestChannelWithoutListeners, "irrelevant")).rejects.toThrow(
'Tried to make a request but no listeners for channel "some-request-channel-without-listeners" was discovered in any DIs',
);
});
diff --git a/packages/technical-features/messaging/message-bridge-fake/src/get-message-bridge-fake/get-message-bridge-fake.ts b/packages/technical-features/messaging/message-bridge-fake/src/get-message-bridge-fake/get-message-bridge-fake.ts
index 8feb31dcd2..3e7efea5f9 100644
--- a/packages/technical-features/messaging/message-bridge-fake/src/get-message-bridge-fake/get-message-bridge-fake.ts
+++ b/packages/technical-features/messaging/message-bridge-fake/src/get-message-bridge-fake/get-message-bridge-fake.ts
@@ -22,7 +22,7 @@ import asyncFn, { AsyncFnMock } from "@async-fn/jest";
export type MessageBridgeFake = {
involve: (...dis: DiContainer[]) => void;
messagePropagation: () => Promise;
- messagePropagationRecursive: (callback: any) => any;
+ messagePropagationRecursive: (callback: () => any) => any;
setAsync: (value: boolean) => void;
};
@@ -167,9 +167,7 @@ export const getMessageBridgeFake = (): MessageBridgeFake => {
await Promise.all(oldMessages.map((x) => wrapper(x.resolve)));
};
- const messagePropagationRecursive = async (
- wrapper: (callback: any) => any = (callback) => callback(),
- ) => {
+ const messagePropagationRecursive = async (wrapper = (callback: () => any) => callback()) => {
while (messagePropagationBuffer.size) {
await messagePropagation(wrapper);
}
diff --git a/packages/technical-features/react-application/src/react-application/react-application.tsx b/packages/technical-features/react-application/src/react-application/react-application.tsx
index 933d0ad389..982a49a3c1 100644
--- a/packages/technical-features/react-application/src/react-application/react-application.tsx
+++ b/packages/technical-features/react-application/src/react-application/react-application.tsx
@@ -27,9 +27,7 @@ const render = (components: ReactApplicationHigherOrderComponent[]) => {
export const ReactApplication = observer(({ di }: ReactApplicationProps) => {
const computedInjectMany = di.inject(computedInjectManyInjectable);
- const higherOrderComponents = computedInjectMany(
- reactApplicationHigherOrderComponentInjectionToken,
- );
+ const higherOrderComponents = computedInjectMany(reactApplicationHigherOrderComponentInjectionToken);
const Components = [...higherOrderComponents.get(), ReactApplicationContent];
diff --git a/packages/utility-features/react-testing-library-discovery/index.ts b/packages/utility-features/react-testing-library-discovery/index.ts
index 109c6af90f..92e817512c 100644
--- a/packages/utility-features/react-testing-library-discovery/index.ts
+++ b/packages/utility-features/react-testing-library-discovery/index.ts
@@ -5,9 +5,4 @@ export type {
QuerySingleElement,
} from "./src/discovery-of-html-elements";
-export {
- discoverFor,
- getSingleElement,
- queryAllElements,
- querySingleElement,
-} from "./src/discovery-of-html-elements";
+export { discoverFor, getSingleElement, queryAllElements, querySingleElement } from "./src/discovery-of-html-elements";
diff --git a/packages/utility-features/react-testing-library-discovery/src/discovery-of-html-elements.ts b/packages/utility-features/react-testing-library-discovery/src/discovery-of-html-elements.ts
index 0df7d9202d..0722c74732 100644
--- a/packages/utility-features/react-testing-library-discovery/src/discovery-of-html-elements.ts
+++ b/packages/utility-features/react-testing-library-discovery/src/discovery-of-html-elements.ts
@@ -26,8 +26,7 @@ export interface Discover {
getSingleElement: GetSingleElement;
}
-const getBaseElement = (source: DiscoverySourceTypes) =>
- "baseElement" in source ? source.baseElement : source;
+const getBaseElement = (source: DiscoverySourceTypes) => ("baseElement" in source ? source.baseElement : source);
export function querySingleElement(getSource: () => DiscoverySourceTypes): QuerySingleElement {
return (attributeName, attributeValue) => {
@@ -35,9 +34,7 @@ export function querySingleElement(getSource: () => DiscoverySourceTypes): Query
const dataAttribute = `data-${attributeName}-test`;
- const selector = attributeValue
- ? `[${dataAttribute}="${attributeValue}"]`
- : `[${dataAttribute}]`;
+ const selector = attributeValue ? `[${dataAttribute}="${attributeValue}"]` : `[${dataAttribute}]`;
const discovered = getBaseElement(source).querySelector(selector);
@@ -78,10 +75,7 @@ export function getSingleElement(getSource: () => DiscoverySourceTypes): GetSing
return (attributeName, attributeValue) => {
const dataAttribute = `data-${attributeName}-test`;
- const { discovered, ...nestedDiscover } = querySingleElement(getSource)(
- attributeName,
- attributeValue,
- );
+ const { discovered, ...nestedDiscover } = querySingleElement(getSource)(attributeName, attributeValue);
if (!discovered) {
// eslint-disable-next-line xss/no-mixed-html
@@ -97,18 +91,14 @@ export function getSingleElement(getSource: () => DiscoverySourceTypes): GetSing
);
}
- throw new Error(
- `Couldn't find HTML-element with attribute "${dataAttribute}"\n\nHTML is:\n\n${html}`,
- );
+ throw new Error(`Couldn't find HTML-element with attribute "${dataAttribute}"\n\nHTML is:\n\n${html}`);
}
const click = () => {
if ("click" in discovered && typeof discovered.click === "function") {
discovered.click();
} else {
- throw new Error(
- `Tried to click something that was not clickable:\n\n${prettyDom(discovered)}`,
- );
+ throw new Error(`Tried to click something that was not clickable:\n\n${prettyDom(discovered)}`);
}
};
From a3716baaf07d31e7f80ac5a52d3999f16b9ef67c Mon Sep 17 00:00:00 2001
From: Janne Savolainen
Date: Wed, 5 Apr 2023 16:34:32 +0300
Subject: [PATCH 05/16] Stop file system watchers on application quit to
prevent exit code !== 0 (#7504)
* fix: Dispose the kubeconfig watcher when application quits
Signed-off-by: Janne Savolainen
* fix: Dispose the extension watcher when application quits
Signed-off-by: Janne Savolainen
---------
Signed-off-by: Janne Savolainen
---
.../extension-discovery.ts | 12 +++++++--
...-watching-extensions-on-quit.injectable.ts | 27 +++++++++++++++++++
.../kubeconfig-sync/manager.ts | 12 +++++++--
3 files changed, 47 insertions(+), 4 deletions(-)
create mode 100644 packages/core/src/extensions/extension-discovery/stop-watching-extensions-on-quit.injectable.ts
diff --git a/packages/core/src/extensions/extension-discovery/extension-discovery.ts b/packages/core/src/extensions/extension-discovery/extension-discovery.ts
index f097af9731..107a61f886 100644
--- a/packages/core/src/extensions/extension-discovery/extension-discovery.ts
+++ b/packages/core/src/extensions/extension-discovery/extension-discovery.ts
@@ -17,7 +17,7 @@ import { requestInitialExtensionDiscovery } from "../../renderer/ipc";
import type { ReadJson } from "../../common/fs/read-json-file.injectable";
import type { Logger } from "../../common/logger";
import type { PathExists } from "../../common/fs/path-exists.injectable";
-import type { Watch } from "../../common/fs/watch/watch.injectable";
+import type { Watch, Watcher } from "../../common/fs/watch/watch.injectable";
import type { Stats } from "fs";
import type { LStat } from "../../common/fs/lstat.injectable";
import type { ReadDirectory } from "../../common/fs/read-directory.injectable";
@@ -149,6 +149,8 @@ export class ExtensionDiscovery {
});
}
+ private _watch: Watcher|undefined;
+
/**
* Watches for added/removed local extensions.
* Dependencies are installed automatically after an extension folder is copied.
@@ -159,7 +161,7 @@ export class ExtensionDiscovery {
// Wait until .load() has been called and has been resolved
await this.whenLoaded;
- this.dependencies.watch(this.localFolderPath, {
+ this._watch = this.dependencies.watch(this.localFolderPath, {
// For adding and removing symlinks to work, the depth has to be 1.
depth: 1,
ignoreInitial: true,
@@ -179,6 +181,12 @@ export class ExtensionDiscovery {
.on("unlink", this.handleWatchUnlinkEvent);
}
+ async stopWatchingExtensions() {
+ this.dependencies.logger.info(`${logModule} stopping the watch for extensions`);
+
+ await this._watch?.close();
+ }
+
handleWatchFileAdd = async (manifestPath: string): Promise => {
// e.g. "foo/package.json"
const relativePath = this.dependencies.getRelativePath(this.localFolderPath, manifestPath);
diff --git a/packages/core/src/extensions/extension-discovery/stop-watching-extensions-on-quit.injectable.ts b/packages/core/src/extensions/extension-discovery/stop-watching-extensions-on-quit.injectable.ts
new file mode 100644
index 0000000000..2644612d54
--- /dev/null
+++ b/packages/core/src/extensions/extension-discovery/stop-watching-extensions-on-quit.injectable.ts
@@ -0,0 +1,27 @@
+/**
+ * Copyright (c) OpenLens Authors. All rights reserved.
+ * Licensed under MIT License. See LICENSE in root directory for more information.
+ */
+import { getInjectable } from "@ogre-tools/injectable";
+import { beforeQuitOfBackEndInjectionToken } from "../../main/start-main-application/runnable-tokens/before-quit-of-back-end-injection-token";
+import extensionDiscoveryInjectable from "./extension-discovery.injectable";
+
+const stopWatchingExtensionsOnQuitInjectable = getInjectable({
+ id: "stop-watching-extensions-on-quit",
+
+ instantiate: (di) => {
+ const extensionDiscovery = di.inject(extensionDiscoveryInjectable);
+
+ return {
+ id: "stop-watching-extensions-on-quit",
+
+ run: async () => {
+ await extensionDiscovery.stopWatchingExtensions();
+ },
+ };
+ },
+
+ injectionToken: beforeQuitOfBackEndInjectionToken,
+});
+
+export default stopWatchingExtensionsOnQuitInjectable;
diff --git a/packages/core/src/main/catalog-sources/kubeconfig-sync/manager.ts b/packages/core/src/main/catalog-sources/kubeconfig-sync/manager.ts
index c7b53d8973..cecf52e4c1 100644
--- a/packages/core/src/main/catalog-sources/kubeconfig-sync/manager.ts
+++ b/packages/core/src/main/catalog-sources/kubeconfig-sync/manager.ts
@@ -98,11 +98,19 @@ export class KubeconfigSyncManager {
@action
protected stopOldSync(filePath: string): void {
- if (!this.sources.delete(filePath)) {
- // already stopped
+ const source = this.sources.get(filePath);
+
+ // already stopped
+ if (!source) {
return this.dependencies.logger.debug(`no syncing file/folder to stop`, { filePath });
}
+ const [, disposer] = source;
+
+ disposer();
+
+ this.sources.delete(filePath);
+
this.dependencies.logger.info(`stopping sync of file/folder`, { filePath });
this.dependencies.logger.debug(`${this.sources.size} files/folders watched`, { files: Array.from(this.sources.keys()) });
}
From 87453b2f145bd3659ff8752d20362fc8eb76b492 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Wed, 5 Apr 2023 01:57:57 +0000
Subject: [PATCH 06/16] Bump joi from 17.8.4 to 17.9.1
Bumps [joi](https://github.com/hapijs/joi) from 17.8.4 to 17.9.1.
- [Release notes](https://github.com/hapijs/joi/releases)
- [Commits](https://github.com/hapijs/joi/compare/v17.8.4...v17.9.1)
---
updated-dependencies:
- dependency-name: joi
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot]
---
package-lock.json | 8 ++++----
packages/core/package.json | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/package-lock.json b/package-lock.json
index 44103eb6c9..086db76798 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -23322,9 +23322,9 @@
}
},
"node_modules/joi": {
- "version": "17.8.4",
- "resolved": "https://registry.npmjs.org/joi/-/joi-17.8.4.tgz",
- "integrity": "sha512-jjdRHb5WtL+KgSHvOULQEPPv4kcl+ixd1ybOFQq3rWLgEEqc03QMmilodL0GVJE14U/SQDXkUhQUSZANGDH/AA==",
+ "version": "17.9.1",
+ "resolved": "https://registry.npmjs.org/joi/-/joi-17.9.1.tgz",
+ "integrity": "sha512-FariIi9j6QODKATGBrEX7HZcja8Bsh3rfdGYy/Sb65sGlZWK/QWesU1ghk7aJWDj95knjXlQfSmzFSPPkLVsfw==",
"dependencies": {
"@hapi/hoek": "^9.0.0",
"@hapi/topo": "^5.0.0",
@@ -38175,7 +38175,7 @@
"hpagent": "^1.2.0",
"http-proxy": "^1.18.1",
"immer": "^9.0.19",
- "joi": "^17.7.1",
+ "joi": "^17.9.1",
"js-yaml": "^4.1.0",
"lodash": "^4.17.15",
"marked": "^4.2.12",
diff --git a/packages/core/package.json b/packages/core/package.json
index 5ac43c7007..6c378aadd3 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -142,7 +142,7 @@
"hpagent": "^1.2.0",
"http-proxy": "^1.18.1",
"immer": "^9.0.19",
- "joi": "^17.7.1",
+ "joi": "^17.9.1",
"js-yaml": "^4.1.0",
"lodash": "^4.17.15",
"marked": "^4.2.12",
From 15d38293197855073dd30a40c4c2a9e5d3ae65e4 Mon Sep 17 00:00:00 2001
From: Sebastian Malton
Date: Wed, 5 Apr 2023 13:48:07 -0400
Subject: [PATCH 07/16] Fix cherry-pick of #7504
Signed-off-by: Sebastian Malton
---
...p-watching-extensions-on-quit.injectable.ts | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/packages/core/src/extensions/extension-discovery/stop-watching-extensions-on-quit.injectable.ts b/packages/core/src/extensions/extension-discovery/stop-watching-extensions-on-quit.injectable.ts
index 2644612d54..a8e6eafb9e 100644
--- a/packages/core/src/extensions/extension-discovery/stop-watching-extensions-on-quit.injectable.ts
+++ b/packages/core/src/extensions/extension-discovery/stop-watching-extensions-on-quit.injectable.ts
@@ -3,23 +3,19 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
-import { beforeQuitOfBackEndInjectionToken } from "../../main/start-main-application/runnable-tokens/before-quit-of-back-end-injection-token";
+import { beforeQuitOfBackEndInjectionToken } from "../../main/start-main-application/runnable-tokens/phases";
import extensionDiscoveryInjectable from "./extension-discovery.injectable";
const stopWatchingExtensionsOnQuitInjectable = getInjectable({
id: "stop-watching-extensions-on-quit",
- instantiate: (di) => {
- const extensionDiscovery = di.inject(extensionDiscoveryInjectable);
+ instantiate: (di) => ({
+ run: async () => {
+ const extensionDiscovery = di.inject(extensionDiscoveryInjectable);
- return {
- id: "stop-watching-extensions-on-quit",
-
- run: async () => {
- await extensionDiscovery.stopWatchingExtensions();
- },
- };
- },
+ await extensionDiscovery.stopWatchingExtensions();
+ },
+ }),
injectionToken: beforeQuitOfBackEndInjectionToken,
});
From 630928d6ba577bb84011b312eacf4ba9b6c65bbf Mon Sep 17 00:00:00 2001
From: Sebastian Malton
Date: Wed, 5 Apr 2023 14:25:02 -0400
Subject: [PATCH 08/16] chore: fix spelling
Signed-off-by: Sebastian Malton
---
.../main/request-system-cas.injectable.win32.ts | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.win32.ts b/packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.win32.ts
index 9e5d5d8caf..161b333677 100644
--- a/packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.win32.ts
+++ b/packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.win32.ts
@@ -23,7 +23,7 @@ const pemEncoding = (hexEncodedCert: String) => {
const requestSystemCAsInjectable = getInjectable({
id: "request-system-cas",
instantiate: (di) => {
- const wincaRootsExePath: string = __non_webpack_require__.resolve("win-ca/lib/roots.exe");
+ const winCARootsExePath: string = __non_webpack_require__.resolve("win-ca/lib/roots.exe");
const execFile = di.inject(execFileInjectable);
const logger = di.inject(loggerInjectable);
@@ -32,12 +32,12 @@ const requestSystemCAsInjectable = getInjectable({
* This needs to be done manually because for some reason calling the api from "win-ca"
* directly fails to load "child_process" correctly on renderer
*/
- const result = await execFile(wincaRootsExePath, {
+ const result = await execFile(winCARootsExePath, {
maxBuffer: 128 * 1024 * 1024, // 128 MiB
});
if (!result.callWasSuccessful) {
- logger.warn(`[INJECT-CAS]: Error retreiving CAs`, result.error);
+ logger.warn(`[INJECT-CAS]: Error retrieving CAs`, result.error);
return [];
}
From 9b0318b493fe2e49a34b8a4cb3d0bef1600759b8 Mon Sep 17 00:00:00 2001
From: Sebastian Malton
Date: Wed, 5 Apr 2023 14:37:34 -0400
Subject: [PATCH 09/16] fix: remove platform specific injectable file names
- Causes issues due to a single platform being used to build the library
Signed-off-by: Sebastian Malton
---
packages/core/src/jest.setup.ts | 4 ++--
packages/core/webpack/main.ts | 4 ++--
packages/core/webpack/renderer.ts | 5 ++---
packages/open-lens/webpack/main.ts | 4 ++--
packages/open-lens/webpack/renderer.ts | 4 ++--
5 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/packages/core/src/jest.setup.ts b/packages/core/src/jest.setup.ts
index 4e9b86ba22..bfc5d42cb7 100644
--- a/packages/core/src/jest.setup.ts
+++ b/packages/core/src/jest.setup.ts
@@ -70,10 +70,10 @@ const getInjectables = (environment: "renderer" | "main", filePathGlob: string)
global.injectablePaths = {
renderer: {
globalOverridePaths: getInjectables("renderer", "*.global-override-for-injectable.{ts,tsx}"),
- paths: getInjectables("renderer", "*.{injectable,injectable.testing-env}.{ts,tsx}"),
+ paths: getInjectables("renderer", "*.injectable.{ts,tsx}"),
},
main: {
globalOverridePaths: getInjectables("main", "*.global-override-for-injectable.{ts,tsx}"),
- paths: getInjectables("main", "*.{injectable,injectable.testing-env}.{ts,tsx}"),
+ paths: getInjectables("main", "*.injectable.{ts,tsx}"),
},
};
diff --git a/packages/core/webpack/main.ts b/packages/core/webpack/main.ts
index 2460ac3c8d..9a73fb3a0b 100755
--- a/packages/core/webpack/main.ts
+++ b/packages/core/webpack/main.ts
@@ -67,8 +67,8 @@ const webpackLensMain = (): webpack.Configuration => {
},
plugins: [
new DefinePlugin({
- CONTEXT_MATCHER_FOR_NON_FEATURES: `/\\.injectable(\\.${platform})?\\.tsx?$/`,
- CONTEXT_MATCHER_FOR_FEATURES: `/\\/(main|common)\\/.+\\.injectable(\\.${platform})?\\.tsx?$/`,
+ CONTEXT_MATCHER_FOR_NON_FEATURES: `/\\.injectable\\.tsx?$/`,
+ CONTEXT_MATCHER_FOR_FEATURES: `/\\/(main|common)\\/.+\\.injectable\\.tsx?$/`,
}),
new ForkTsCheckerPlugin({
typescript: {
diff --git a/packages/core/webpack/renderer.ts b/packages/core/webpack/renderer.ts
index 3b133f8f50..a64fc2d3c3 100755
--- a/packages/core/webpack/renderer.ts
+++ b/packages/core/webpack/renderer.ts
@@ -12,7 +12,6 @@ import type { WebpackPluginInstance } from "webpack";
import { optimize, DefinePlugin } from "webpack";
import nodeExternals from "webpack-node-externals";
import { isDevelopment, buildDir, sassCommonVars } from "./vars";
-import { platform } from "process";
export function webpackLensRenderer(): webpack.Configuration {
return {
@@ -84,8 +83,8 @@ export function webpackLensRenderer(): webpack.Configuration {
plugins: [
new DefinePlugin({
- CONTEXT_MATCHER_FOR_NON_FEATURES: `/\\.injectable(\\.${platform})?\\.tsx?$/`,
- CONTEXT_MATCHER_FOR_FEATURES: `/\\/(renderer|common)\\/.+\\.injectable(\\.${platform})?\\.tsx?$/`,
+ CONTEXT_MATCHER_FOR_NON_FEATURES: `/\\.injectable\\.tsx?$/`,
+ CONTEXT_MATCHER_FOR_FEATURES: `/\\/(renderer|common)\\/.+\\.injectable\\.tsx?$/`,
}),
new ForkTsCheckerPlugin({}),
diff --git a/packages/open-lens/webpack/main.ts b/packages/open-lens/webpack/main.ts
index a94f45a794..277fc1b785 100644
--- a/packages/open-lens/webpack/main.ts
+++ b/packages/open-lens/webpack/main.ts
@@ -50,8 +50,8 @@ const main: webpack.Configuration = ({
},
plugins: [
new DefinePlugin({
- CONTEXT_MATCHER_FOR_NON_FEATURES: `/\\.injectable(\\.${platform})?\\.tsx?$/`,
- CONTEXT_MATCHER_FOR_FEATURES: `/\\/(renderer|common)\\/.+\\.injectable(\\.${platform})?\\.tsx?$/`,
+ CONTEXT_MATCHER_FOR_NON_FEATURES: `/\\.injectable\\.tsx?$/`,
+ CONTEXT_MATCHER_FOR_FEATURES: `/\\/(renderer|common)\\/.+\\.injectable\\.tsx?$/`,
}),
],
});
diff --git a/packages/open-lens/webpack/renderer.ts b/packages/open-lens/webpack/renderer.ts
index e46487c6de..a17511db30 100644
--- a/packages/open-lens/webpack/renderer.ts
+++ b/packages/open-lens/webpack/renderer.ts
@@ -81,8 +81,8 @@
plugins: [
new DefinePlugin({
- CONTEXT_MATCHER_FOR_NON_FEATURES: `/\\.injectable(\\.${platform})?\\.tsx?$/`,
- CONTEXT_MATCHER_FOR_FEATURES: `/\\/(renderer|common)\\/.+\\.injectable(\\.${platform})?\\.tsx?$/`,
+ CONTEXT_MATCHER_FOR_NON_FEATURES: `/\\.injectable\\.tsx?$/`,
+ CONTEXT_MATCHER_FOR_FEATURES: `/\\/(renderer|common)\\/.+\\.injectable\\.tsx?$/`,
}),
new ForkTsCheckerPlugin(),
From 0bc3d9f8b23a452fe92d7d6b4a525a67b048ea8b Mon Sep 17 00:00:00 2001
From: Sebastian Malton
Date: Wed, 5 Apr 2023 14:38:22 -0400
Subject: [PATCH 10/16] feat: Introduce PlatformSpecific as a new wrapper type
for injectables
Signed-off-by: Sebastian Malton
---
packages/utility-features/utilities/index.ts | 1 +
.../src/platform-specific-version.ts | 20 +++++++++++++++++++
2 files changed, 21 insertions(+)
create mode 100644 packages/utility-features/utilities/src/platform-specific-version.ts
diff --git a/packages/utility-features/utilities/index.ts b/packages/utility-features/utilities/index.ts
index dc8eacdfdd..b9e2b176b8 100644
--- a/packages/utility-features/utilities/index.ts
+++ b/packages/utility-features/utilities/index.ts
@@ -29,6 +29,7 @@ export * from "./src/noop";
export * from "./src/object";
export * from "./src/observable-crate";
export * from "./src/on-keyboard-shortcut";
+export * from "./src/platform-specific-version"
export * from "./src/prevDefault";
export * from "./src/readableStream";
export * from "./src/readonly";
diff --git a/packages/utility-features/utilities/src/platform-specific-version.ts b/packages/utility-features/utilities/src/platform-specific-version.ts
new file mode 100644
index 0000000000..adbc9971cc
--- /dev/null
+++ b/packages/utility-features/utilities/src/platform-specific-version.ts
@@ -0,0 +1,20 @@
+/**
+ * Copyright (c) OpenLens Authors. All rights reserved.
+ * Licensed under MIT License. See LICENSE in root directory for more information.
+ */
+
+export interface PlatformSpecific {
+ instantiate: () => T;
+ readonly platform: NodeJS.Platform | "";
+}
+
+export const getPlatformSpecificFor = (targetPlatform: NodeJS.Platform, id: string) => (specificImplementations: PlatformSpecific[]): T => {
+ const impl = specificImplementations.find(impl => impl.platform === targetPlatform)
+ ?? specificImplementations.find(impl => impl.platform === "");
+
+ if (!impl) {
+ throw new Error(`No platform specific implementation of "${id}" found`);
+ }
+
+ return impl.instantiate();
+}
From 75a1b0a983115343de0aaf7d3404222093d8ee9b Mon Sep 17 00:00:00 2001
From: Sebastian Malton
Date: Wed, 5 Apr 2023 15:00:36 -0400
Subject: [PATCH 11/16] chore: move PlatformSpecific back to core
- This is needed in 6.4 and this will make that transition easier
Signed-off-by: Sebastian Malton
---
.../platform-specific-version.injectable.ts | 35 +++++++++++++++++++
packages/utility-features/utilities/index.ts | 1 -
.../src/platform-specific-version.ts | 20 -----------
3 files changed, 35 insertions(+), 21 deletions(-)
create mode 100644 packages/core/src/common/utils/platform-specific-version.injectable.ts
delete mode 100644 packages/utility-features/utilities/src/platform-specific-version.ts
diff --git a/packages/core/src/common/utils/platform-specific-version.injectable.ts b/packages/core/src/common/utils/platform-specific-version.injectable.ts
new file mode 100644
index 0000000000..71f611216d
--- /dev/null
+++ b/packages/core/src/common/utils/platform-specific-version.injectable.ts
@@ -0,0 +1,35 @@
+/**
+ * Copyright (c) OpenLens Authors. All rights reserved.
+ * Licensed under MIT License. See LICENSE in root directory for more information.
+ */
+
+import type { DiContainerForInjection, InjectionToken } from "@ogre-tools/injectable";
+import { getInjectable } from "@ogre-tools/injectable";
+import platformInjectable from "../vars/platform.injectable";
+
+export interface PlatformSpecific {
+ instantiate: () => T;
+ readonly platform: NodeJS.Platform;
+}
+
+const platformSpecificVersionInjectable = getInjectable({
+ id: "platform-specific-version",
+ instantiate: (di: DiContainerForInjection) => {
+ const targetPlatform = di.inject(platformInjectable);
+
+ return (token: InjectionToken, void>) => {
+ const impls = di.injectMany(token);
+
+ const impl = impls.find(impl => impl.platform === targetPlatform);
+
+ if (!impl) {
+ throw new Error(`No platform specific implementation of "${token.id}" found`);
+ }
+
+ return impl.instantiate();
+ };
+ },
+});
+
+export default platformSpecificVersionInjectable;
+
diff --git a/packages/utility-features/utilities/index.ts b/packages/utility-features/utilities/index.ts
index b9e2b176b8..dc8eacdfdd 100644
--- a/packages/utility-features/utilities/index.ts
+++ b/packages/utility-features/utilities/index.ts
@@ -29,7 +29,6 @@ export * from "./src/noop";
export * from "./src/object";
export * from "./src/observable-crate";
export * from "./src/on-keyboard-shortcut";
-export * from "./src/platform-specific-version"
export * from "./src/prevDefault";
export * from "./src/readableStream";
export * from "./src/readonly";
diff --git a/packages/utility-features/utilities/src/platform-specific-version.ts b/packages/utility-features/utilities/src/platform-specific-version.ts
deleted file mode 100644
index adbc9971cc..0000000000
--- a/packages/utility-features/utilities/src/platform-specific-version.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-/**
- * Copyright (c) OpenLens Authors. All rights reserved.
- * Licensed under MIT License. See LICENSE in root directory for more information.
- */
-
-export interface PlatformSpecific {
- instantiate: () => T;
- readonly platform: NodeJS.Platform | "";
-}
-
-export const getPlatformSpecificFor = (targetPlatform: NodeJS.Platform, id: string) => (specificImplementations: PlatformSpecific[]): T => {
- const impl = specificImplementations.find(impl => impl.platform === targetPlatform)
- ?? specificImplementations.find(impl => impl.platform === "");
-
- if (!impl) {
- throw new Error(`No platform specific implementation of "${id}" found`);
- }
-
- return impl.instantiate();
-}
From 5fc32c0b27dd73537ee931e4ba790c36b19782c3 Mon Sep 17 00:00:00 2001
From: Sebastian Malton
Date: Wed, 5 Apr 2023 15:00:58 -0400
Subject: [PATCH 12/16] chore: convert request-system-cas to use
PlatformSpecific
Signed-off-by: Sebastian Malton
---
.../common/request-system-cas-token.ts | 5 +-
.../darwin-request-system-cas.injectable.ts | 60 +++++++++++++++++++
.../linux-request-system-cas.injectable.ts | 17 ++++++
...stem-cas.global-override-for-injectable.ts | 9 +++
.../request-system-cas.injectable.darwin.ts | 57 ------------------
...quest-system-cas.injectable.testing-env.ts | 14 -----
...ux.ts => request-system-cas.injectable.ts} | 6 +-
.../request-system-cas.injectable.win32.ts | 56 -----------------
.../win32-request-system-cas.injectable.ts | 59 ++++++++++++++++++
9 files changed, 152 insertions(+), 131 deletions(-)
create mode 100644 packages/core/src/features/certificate-authorities/main/darwin-request-system-cas.injectable.ts
create mode 100644 packages/core/src/features/certificate-authorities/main/linux-request-system-cas.injectable.ts
create mode 100644 packages/core/src/features/certificate-authorities/main/request-system-cas.global-override-for-injectable.ts
delete mode 100644 packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.darwin.ts
delete mode 100644 packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.testing-env.ts
rename packages/core/src/features/certificate-authorities/main/{request-system-cas.injectable.linux.ts => request-system-cas.injectable.ts} (50%)
delete mode 100644 packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.win32.ts
create mode 100644 packages/core/src/features/certificate-authorities/main/win32-request-system-cas.injectable.ts
diff --git a/packages/core/src/features/certificate-authorities/common/request-system-cas-token.ts b/packages/core/src/features/certificate-authorities/common/request-system-cas-token.ts
index c69b0bd8b0..8e79d44e59 100644
--- a/packages/core/src/features/certificate-authorities/common/request-system-cas-token.ts
+++ b/packages/core/src/features/certificate-authorities/common/request-system-cas-token.ts
@@ -4,7 +4,10 @@
*/
import { getInjectionToken } from "@ogre-tools/injectable";
+import type { PlatformSpecific } from "../../../common/utils/platform-specific-version.injectable";
-export const requestSystemCAsInjectionToken = getInjectionToken<() => Promise>({
+export type RequestSystemCAs = () => Promise;
+
+export const platformSpecificRequestSystemCAsInjectionToken = getInjectionToken>({
id: "request-system-cas-token",
});
diff --git a/packages/core/src/features/certificate-authorities/main/darwin-request-system-cas.injectable.ts b/packages/core/src/features/certificate-authorities/main/darwin-request-system-cas.injectable.ts
new file mode 100644
index 0000000000..9a798123e7
--- /dev/null
+++ b/packages/core/src/features/certificate-authorities/main/darwin-request-system-cas.injectable.ts
@@ -0,0 +1,60 @@
+/**
+ * Copyright (c) OpenLens Authors. All rights reserved.
+ * Licensed under MIT License. See LICENSE in root directory for more information.
+ */
+import { getInjectable } from "@ogre-tools/injectable";
+import execFileInjectable from "../../../common/fs/exec-file.injectable";
+import loggerInjectable from "../../../common/logger.injectable";
+import type { AsyncResult } from "@k8slens/utilities";
+import { platformSpecificRequestSystemCAsInjectionToken } from "../common/request-system-cas-token";
+
+// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Cheatsheet#other_assertions
+const certSplitPattern = /(?=-----BEGIN\sCERTIFICATE-----)/g;
+
+const darwinRequestSystemCAsInjectable = getInjectable({
+ id: "darwin-request-system-cas",
+ instantiate: (di) => ({
+ platform: "darwin" as const,
+ instantiate: () => {
+ const execFile = di.inject(execFileInjectable);
+ const logger = di.inject(loggerInjectable);
+
+ const execSecurity = async (...args: string[]): AsyncResult => {
+ const result = await execFile("/usr/bin/security", args);
+
+ if (!result.callWasSuccessful) {
+ return {
+ callWasSuccessful: false,
+ error: result.error.stderr || result.error.message,
+ };
+ }
+
+ return {
+ callWasSuccessful: true,
+ response: result.response.split(certSplitPattern),
+ };
+ };
+
+ return async () => {
+ const [trustedResult, rootCAResult] = await Promise.all([
+ execSecurity("find-certificate", "-a", "-p"),
+ execSecurity("find-certificate", "-a", "-p", "/System/Library/Keychains/SystemRootCertificates.keychain"),
+ ]);
+
+ if (!trustedResult.callWasSuccessful) {
+ logger.warn(`[INJECT-CAS]: Error retrieving trusted CAs: ${trustedResult.error}`);
+ } else if (!rootCAResult.callWasSuccessful) {
+ logger.warn(`[INJECT-CAS]: Error retrieving root CAs: ${rootCAResult.error}`);
+ } else {
+ return [...new Set([...trustedResult.response, ...rootCAResult.response])];
+ }
+
+ return [];
+ };
+ },
+ }),
+ causesSideEffects: true,
+ injectionToken: platformSpecificRequestSystemCAsInjectionToken,
+});
+
+export default darwinRequestSystemCAsInjectable;
diff --git a/packages/core/src/features/certificate-authorities/main/linux-request-system-cas.injectable.ts b/packages/core/src/features/certificate-authorities/main/linux-request-system-cas.injectable.ts
new file mode 100644
index 0000000000..520830fdf8
--- /dev/null
+++ b/packages/core/src/features/certificate-authorities/main/linux-request-system-cas.injectable.ts
@@ -0,0 +1,17 @@
+/**
+ * Copyright (c) OpenLens Authors. All rights reserved.
+ * Licensed under MIT License. See LICENSE in root directory for more information.
+ */
+import { getInjectable } from "@ogre-tools/injectable";
+import { platformSpecificRequestSystemCAsInjectionToken } from "../common/request-system-cas-token";
+
+const linuxRequestSystemCAsInjectable = getInjectable({
+ id: "linux-request-system-cas",
+ instantiate: () => ({
+ platform: "linux" as const,
+ instantiate: () => async () => [],
+ }),
+ injectionToken: platformSpecificRequestSystemCAsInjectionToken,
+});
+
+export default linuxRequestSystemCAsInjectable;
diff --git a/packages/core/src/features/certificate-authorities/main/request-system-cas.global-override-for-injectable.ts b/packages/core/src/features/certificate-authorities/main/request-system-cas.global-override-for-injectable.ts
new file mode 100644
index 0000000000..670f150b81
--- /dev/null
+++ b/packages/core/src/features/certificate-authorities/main/request-system-cas.global-override-for-injectable.ts
@@ -0,0 +1,9 @@
+/**
+ * Copyright (c) OpenLens Authors. All rights reserved.
+ * Licensed under MIT License. See LICENSE in root directory for more information.
+ */
+
+import { getGlobalOverride } from "@k8slens/test-utils";
+import requestSystemCAsInjectable from "./request-system-cas.injectable";
+
+export default getGlobalOverride(requestSystemCAsInjectable, () => async () => []);
diff --git a/packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.darwin.ts b/packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.darwin.ts
deleted file mode 100644
index 66c24a1235..0000000000
--- a/packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.darwin.ts
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * Copyright (c) OpenLens Authors. All rights reserved.
- * Licensed under MIT License. See LICENSE in root directory for more information.
- */
-import { getInjectable } from "@ogre-tools/injectable";
-import execFileInjectable from "../../../common/fs/exec-file.injectable";
-import loggerInjectable from "../../../common/logger.injectable";
-import type { AsyncResult } from "@k8slens/utilities";
-import { requestSystemCAsInjectionToken } from "../common/request-system-cas-token";
-
-// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Cheatsheet#other_assertions
-const certSplitPattern = /(?=-----BEGIN\sCERTIFICATE-----)/g;
-
-const requestSystemCAsInjectable = getInjectable({
- id: "request-system-cas",
- instantiate: (di) => {
- const execFile = di.inject(execFileInjectable);
- const logger = di.inject(loggerInjectable);
-
- const execSecurity = async (...args: string[]): AsyncResult => {
- const result = await execFile("/usr/bin/security", args);
-
- if (!result.callWasSuccessful) {
- return {
- callWasSuccessful: false,
- error: result.error.stderr || result.error.message,
- };
- }
-
- return {
- callWasSuccessful: true,
- response: result.response.split(certSplitPattern),
- };
- };
-
- return async () => {
- const [trustedResult, rootCAResult] = await Promise.all([
- execSecurity("find-certificate", "-a", "-p"),
- execSecurity("find-certificate", "-a", "-p", "/System/Library/Keychains/SystemRootCertificates.keychain"),
- ]);
-
- if (!trustedResult.callWasSuccessful) {
- logger.warn(`[INJECT-CAS]: Error retreiving trusted CAs: ${trustedResult.error}`);
- } else if (!rootCAResult.callWasSuccessful) {
- logger.warn(`[INJECT-CAS]: Error retreiving root CAs: ${rootCAResult.error}`);
- } else {
- return [...new Set([...trustedResult.response, ...rootCAResult.response])];
- }
-
- return [];
- };
- },
- causesSideEffects: true,
- injectionToken: requestSystemCAsInjectionToken,
-});
-
-export default requestSystemCAsInjectable;
diff --git a/packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.testing-env.ts b/packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.testing-env.ts
deleted file mode 100644
index cffd0d172a..0000000000
--- a/packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.testing-env.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-/**
- * Copyright (c) OpenLens Authors. All rights reserved.
- * Licensed under MIT License. See LICENSE in root directory for more information.
- */
-import { getInjectable } from "@ogre-tools/injectable";
-import { requestSystemCAsInjectionToken } from "../common/request-system-cas-token";
-
-const requestSystemCAsInjectable = getInjectable({
- id: "request-system-cas",
- instantiate: () => async () => [],
- injectionToken: requestSystemCAsInjectionToken,
-});
-
-export default requestSystemCAsInjectable;
diff --git a/packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.linux.ts b/packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.ts
similarity index 50%
rename from packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.linux.ts
rename to packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.ts
index cffd0d172a..e0c4c2fd47 100644
--- a/packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.linux.ts
+++ b/packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.ts
@@ -3,12 +3,12 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
-import { requestSystemCAsInjectionToken } from "../common/request-system-cas-token";
+import platformSpecificVersionInjectable from "../../../common/utils/platform-specific-version.injectable";
+import { platformSpecificRequestSystemCAsInjectionToken } from "../common/request-system-cas-token";
const requestSystemCAsInjectable = getInjectable({
id: "request-system-cas",
- instantiate: () => async () => [],
- injectionToken: requestSystemCAsInjectionToken,
+ instantiate: (di) => di.inject(platformSpecificVersionInjectable)(platformSpecificRequestSystemCAsInjectionToken),
});
export default requestSystemCAsInjectable;
diff --git a/packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.win32.ts b/packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.win32.ts
deleted file mode 100644
index 161b333677..0000000000
--- a/packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.win32.ts
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * Copyright (c) OpenLens Authors. All rights reserved.
- * Licensed under MIT License. See LICENSE in root directory for more information.
- */
-import { getInjectable } from "@ogre-tools/injectable";
-import execFileInjectable from "../../../common/fs/exec-file.injectable";
-import loggerInjectable from "../../../common/logger.injectable";
-import { requestSystemCAsInjectionToken } from "../common/request-system-cas-token";
-
-const pemEncoding = (hexEncodedCert: String) => {
- const certData = Buffer.from(hexEncodedCert, "hex").toString("base64");
- const lines = ["-----BEGIN CERTIFICATE-----"];
-
- for (let i = 0; i < certData.length; i += 64) {
- lines.push(certData.substring(i, i + 64));
- }
-
- lines.push("-----END CERTIFICATE-----", "");
-
- return lines.join("\r\n");
-};
-
-const requestSystemCAsInjectable = getInjectable({
- id: "request-system-cas",
- instantiate: (di) => {
- const winCARootsExePath: string = __non_webpack_require__.resolve("win-ca/lib/roots.exe");
- const execFile = di.inject(execFileInjectable);
- const logger = di.inject(loggerInjectable);
-
- return async () => {
- /**
- * This needs to be done manually because for some reason calling the api from "win-ca"
- * directly fails to load "child_process" correctly on renderer
- */
- const result = await execFile(winCARootsExePath, {
- maxBuffer: 128 * 1024 * 1024, // 128 MiB
- });
-
- if (!result.callWasSuccessful) {
- logger.warn(`[INJECT-CAS]: Error retrieving CAs`, result.error);
-
- return [];
- }
-
- return result
- .response
- .split("\r\n")
- .filter(Boolean)
- .map(pemEncoding);
- };
- },
- causesSideEffects: true,
- injectionToken: requestSystemCAsInjectionToken,
-});
-
-export default requestSystemCAsInjectable;
diff --git a/packages/core/src/features/certificate-authorities/main/win32-request-system-cas.injectable.ts b/packages/core/src/features/certificate-authorities/main/win32-request-system-cas.injectable.ts
new file mode 100644
index 0000000000..2c4cc6f906
--- /dev/null
+++ b/packages/core/src/features/certificate-authorities/main/win32-request-system-cas.injectable.ts
@@ -0,0 +1,59 @@
+/**
+ * Copyright (c) OpenLens Authors. All rights reserved.
+ * Licensed under MIT License. See LICENSE in root directory for more information.
+ */
+import { getInjectable } from "@ogre-tools/injectable";
+import execFileInjectable from "../../../common/fs/exec-file.injectable";
+import loggerInjectable from "../../../common/logger.injectable";
+import { platformSpecificRequestSystemCAsInjectionToken } from "../common/request-system-cas-token";
+
+const pemEncoding = (hexEncodedCert: String) => {
+ const certData = Buffer.from(hexEncodedCert, "hex").toString("base64");
+ const lines = ["-----BEGIN CERTIFICATE-----"];
+
+ for (let i = 0; i < certData.length; i += 64) {
+ lines.push(certData.substring(i, i + 64));
+ }
+
+ lines.push("-----END CERTIFICATE-----", "");
+
+ return lines.join("\r\n");
+};
+
+const win32RequestSystemCAsInjectable = getInjectable({
+ id: "win32-request-system-cas",
+ instantiate: (di) => ({
+ platform: "win32" as const,
+ instantiate: () => {
+ const winCARootsExePath: string = __non_webpack_require__.resolve("win-ca/lib/roots.exe");
+ const execFile = di.inject(execFileInjectable);
+ const logger = di.inject(loggerInjectable);
+
+ return async () => {
+ /**
+ * This needs to be done manually because for some reason calling the api from "win-ca"
+ * directly fails to load "child_process" correctly on renderer
+ */
+ const result = await execFile(winCARootsExePath, {
+ maxBuffer: 128 * 1024 * 1024, // 128 MiB
+ });
+
+ if (!result.callWasSuccessful) {
+ logger.warn(`[INJECT-CAS]: Error retrieving CAs`, result.error);
+
+ return [];
+ }
+
+ return result
+ .response
+ .split("\r\n")
+ .filter(Boolean)
+ .map(pemEncoding);
+ };
+ },
+ }),
+ causesSideEffects: true,
+ injectionToken: platformSpecificRequestSystemCAsInjectionToken,
+});
+
+export default win32RequestSystemCAsInjectable;
From 3c8839151c39ea4145b59ca0aa559986ef56780e Mon Sep 17 00:00:00 2001
From: Sebastian Malton
Date: Wed, 5 Apr 2023 15:05:36 -0400
Subject: [PATCH 13/16] chore: move test-env specific versions to own folder
Signed-off-by: Sebastian Malton
---
packages/core/src/jest.setup.ts | 2 +-
.../application-information-fake.injectable.ts} | 4 +---
.../node-env.injectable.ts} | 8 ++++----
3 files changed, 6 insertions(+), 8 deletions(-)
rename packages/core/src/{common/vars/application-information-fake.injectable.testing-env.ts => test-env/application-information-fake.injectable.ts} (87%)
rename packages/core/src/{common/vars/node-env.injectable.testing-env.ts => test-env/node-env.injectable.ts} (59%)
diff --git a/packages/core/src/jest.setup.ts b/packages/core/src/jest.setup.ts
index bfc5d42cb7..96a4b816d4 100644
--- a/packages/core/src/jest.setup.ts
+++ b/packages/core/src/jest.setup.ts
@@ -58,7 +58,7 @@ jest.mock("./renderer/components/tooltip/withTooltip");
jest.mock("monaco-editor");
const getInjectables = (environment: "renderer" | "main", filePathGlob: string) => [
- ...glob.sync(`./{common,extensions,${environment}}/**/${filePathGlob}`, {
+ ...glob.sync(`./{common,extensions,${environment},test-env}/**/${filePathGlob}`, {
cwd: __dirname,
}),
diff --git a/packages/core/src/common/vars/application-information-fake.injectable.testing-env.ts b/packages/core/src/test-env/application-information-fake.injectable.ts
similarity index 87%
rename from packages/core/src/common/vars/application-information-fake.injectable.testing-env.ts
rename to packages/core/src/test-env/application-information-fake.injectable.ts
index 1fd988b817..c5d9bfa8d2 100644
--- a/packages/core/src/common/vars/application-information-fake.injectable.testing-env.ts
+++ b/packages/core/src/test-env/application-information-fake.injectable.ts
@@ -18,9 +18,7 @@ export const applicationInformationFakeInjectable = getInjectable({
bundledKubectlVersion: "1.23.3",
bundledHelmVersion: "3.7.2",
sentryDsn: "",
- contentSecurityPolicy:
- "script-src 'unsafe-eval' 'self'; frame-src http://*.localhost:*/; img-src * data:",
-
+ contentSecurityPolicy: "script-src 'unsafe-eval' 'self'; frame-src http://*.localhost:*/; img-src * data:",
welcomeRoute: "/welcome",
copyright: "some-copyright-information",
description: "some-descriptive-text",
diff --git a/packages/core/src/common/vars/node-env.injectable.testing-env.ts b/packages/core/src/test-env/node-env.injectable.ts
similarity index 59%
rename from packages/core/src/common/vars/node-env.injectable.testing-env.ts
rename to packages/core/src/test-env/node-env.injectable.ts
index 20d041330f..b08639d94c 100644
--- a/packages/core/src/common/vars/node-env.injectable.testing-env.ts
+++ b/packages/core/src/test-env/node-env.injectable.ts
@@ -3,12 +3,12 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
-import { nodeEnvInjectionToken } from "./node-env-injection-token";
+import { nodeEnvInjectionToken } from "../main/library";
-const nodeEnvFakeInjectable = getInjectable({
- id: "node-env-fake",
+const nodeEnvForTestingEnvInjectable = getInjectable({
+ id: "node-env-for-testing-env",
instantiate: () => "production",
injectionToken: nodeEnvInjectionToken,
});
-export default nodeEnvFakeInjectable;
+export default nodeEnvForTestingEnvInjectable;
From 477ad3caa43d5710f2abc4b1bbd88584ee42cff9 Mon Sep 17 00:00:00 2001
From: Sebastian Malton
Date: Wed, 5 Apr 2023 15:13:18 -0400
Subject: [PATCH 14/16] chore: fix lint for main webpack
Signed-off-by: Sebastian Malton
---
packages/core/webpack/main.ts | 1 -
1 file changed, 1 deletion(-)
diff --git a/packages/core/webpack/main.ts b/packages/core/webpack/main.ts
index 9a73fb3a0b..3e8c3ed4d7 100755
--- a/packages/core/webpack/main.ts
+++ b/packages/core/webpack/main.ts
@@ -10,7 +10,6 @@ import ForkTsCheckerPlugin from "fork-ts-checker-webpack-plugin";
import { iconsAndImagesWebpackRules } from "./renderer";
import { DefinePlugin } from "webpack";
import { buildDir, isDevelopment } from "./vars";
-import { platform } from "process";
const webpackLensMain = (): webpack.Configuration => {
return {
From c0ebe605c4d36c0d98454e25565818f75ffb1b69 Mon Sep 17 00:00:00 2001
From: Sebastian Malton
Date: Wed, 5 Apr 2023 15:31:37 -0400
Subject: [PATCH 15/16] fix: Fix tests by recreating non-specific injection
token
Signed-off-by: Sebastian Malton
---
.../common/request-system-cas-token.ts | 4 ++++
.../main/request-system-cas.injectable.ts | 3 ++-
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/packages/core/src/features/certificate-authorities/common/request-system-cas-token.ts b/packages/core/src/features/certificate-authorities/common/request-system-cas-token.ts
index 8e79d44e59..5c5f17ff64 100644
--- a/packages/core/src/features/certificate-authorities/common/request-system-cas-token.ts
+++ b/packages/core/src/features/certificate-authorities/common/request-system-cas-token.ts
@@ -9,5 +9,9 @@ import type { PlatformSpecific } from "../../../common/utils/platform-specific-v
export type RequestSystemCAs = () => Promise;
export const platformSpecificRequestSystemCAsInjectionToken = getInjectionToken>({
+ id: "platform-specific-request-system-cas-token",
+});
+
+export const requestSystemCAsInjectionToken = getInjectionToken({
id: "request-system-cas-token",
});
diff --git a/packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.ts b/packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.ts
index e0c4c2fd47..814bbdbde6 100644
--- a/packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.ts
+++ b/packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.ts
@@ -4,11 +4,12 @@
*/
import { getInjectable } from "@ogre-tools/injectable";
import platformSpecificVersionInjectable from "../../../common/utils/platform-specific-version.injectable";
-import { platformSpecificRequestSystemCAsInjectionToken } from "../common/request-system-cas-token";
+import { platformSpecificRequestSystemCAsInjectionToken, requestSystemCAsInjectionToken } from "../common/request-system-cas-token";
const requestSystemCAsInjectable = getInjectable({
id: "request-system-cas",
instantiate: (di) => di.inject(platformSpecificVersionInjectable)(platformSpecificRequestSystemCAsInjectionToken),
+ injectionToken: requestSystemCAsInjectionToken,
});
export default requestSystemCAsInjectable;
From 5db8fc134231dc8bb7fae3d84edab3ad7dcd3e45 Mon Sep 17 00:00:00 2001
From: Sebastian Malton
Date: Wed, 5 Apr 2023 15:33:49 -0400
Subject: [PATCH 16/16] chore: Remove explicit throw when finding
platformSpecificVersion
Signed-off-by: Sebastian Malton
---
.../platform-specific-version.injectable.ts | 16 +++++-----------
.../main/request-system-cas.injectable.ts | 7 ++++++-
2 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/packages/core/src/common/utils/platform-specific-version.injectable.ts b/packages/core/src/common/utils/platform-specific-version.injectable.ts
index 71f611216d..79abad6a49 100644
--- a/packages/core/src/common/utils/platform-specific-version.injectable.ts
+++ b/packages/core/src/common/utils/platform-specific-version.injectable.ts
@@ -17,17 +17,11 @@ const platformSpecificVersionInjectable = getInjectable({
instantiate: (di: DiContainerForInjection) => {
const targetPlatform = di.inject(platformInjectable);
- return (token: InjectionToken, void>) => {
- const impls = di.injectMany(token);
-
- const impl = impls.find(impl => impl.platform === targetPlatform);
-
- if (!impl) {
- throw new Error(`No platform specific implementation of "${token.id}" found`);
- }
-
- return impl.instantiate();
- };
+ return (token: InjectionToken, void>) => (
+ di.injectMany(token)
+ .find(impl => impl.platform === targetPlatform)
+ ?.instantiate()
+ );
},
});
diff --git a/packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.ts b/packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.ts
index 814bbdbde6..f17f538529 100644
--- a/packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.ts
+++ b/packages/core/src/features/certificate-authorities/main/request-system-cas.injectable.ts
@@ -8,7 +8,12 @@ import { platformSpecificRequestSystemCAsInjectionToken, requestSystemCAsInjecti
const requestSystemCAsInjectable = getInjectable({
id: "request-system-cas",
- instantiate: (di) => di.inject(platformSpecificVersionInjectable)(platformSpecificRequestSystemCAsInjectionToken),
+ instantiate: (di) => {
+ const platformSpecificVersion = di.inject(platformSpecificVersionInjectable);
+ const platformSpecificRequestSystemCAs = platformSpecificVersion(platformSpecificRequestSystemCAsInjectionToken);
+
+ return platformSpecificRequestSystemCAs ?? (async () => []);
+ },
injectionToken: requestSystemCAsInjectionToken,
});