1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>

Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
This commit is contained in:
Iku-turso 2022-11-23 15:37:10 +02:00
parent 6b4e3f1e51
commit 51675f8e09
20 changed files with 113 additions and 69 deletions

View File

@ -218,11 +218,12 @@
"@hapi/subtext": "^7.0.4", "@hapi/subtext": "^7.0.4",
"@kubernetes/client-node": "^0.17.1", "@kubernetes/client-node": "^0.17.1",
"@material-ui/styles": "^4.11.5", "@material-ui/styles": "^4.11.5",
"@ogre-tools/fp": "^12.0.1", "@ogre-tools/fp": "^14.0.3",
"@ogre-tools/injectable": "^12.0.1", "@ogre-tools/injectable": "^14.0.3",
"@ogre-tools/injectable-extension-for-auto-registration": "^12.0.1", "@ogre-tools/injectable-extension-for-auto-registration": "^14.0.3",
"@ogre-tools/injectable-extension-for-mobx": "^12.0.1", "@ogre-tools/injectable-extension-for-mobx": "^14.0.3",
"@ogre-tools/injectable-react": "^12.0.1", "@ogre-tools/injectable-react": "^14.0.3",
"@ogre-tools/mobx-utils": "^14.0.3",
"@sentry/electron": "^3.0.8", "@sentry/electron": "^3.0.8",
"@sentry/integrations": "^6.19.3", "@sentry/integrations": "^6.19.3",
"@side/jest-runtime": "^1.0.1", "@side/jest-runtime": "^1.0.1",
@ -291,7 +292,13 @@
"winston-console-format": "^1.0.8", "winston-console-format": "^1.0.8",
"winston-transport-browserconsole": "^1.0.5", "winston-transport-browserconsole": "^1.0.5",
"ws": "^8.11.0", "ws": "^8.11.0",
"xterm-link-provider": "^1.3.1" "xterm-link-provider": "^1.3.1",
"@lensapp/cluster": "^0.1.5",
"@lensapp/feature-core": "^0.1.6",
"@lensapp/fs": "^0.2.0",
"@lensapp/logging": "^0.1.5",
"@lensapp/shell": "^0.1.6",
"@lensapp/utils": "^0.2.4"
}, },
"devDependencies": { "devDependencies": {
"@async-fn/jest": "1.6.4", "@async-fn/jest": "1.6.4",

View File

@ -8,7 +8,7 @@ import fsInjectable from "./fs.injectable";
export type DeleteFile = (filePath: string) => Promise<void>; export type DeleteFile = (filePath: string) => Promise<void>;
const deleteFileInjectable = getInjectable({ const deleteFileInjectable = getInjectable({
id: "delete-file", id: "delete-file-1",
instantiate: (di): DeleteFile => di.inject(fsInjectable).unlink, instantiate: (di): DeleteFile => di.inject(fsInjectable).unlink,
}); });

View File

@ -6,7 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable";
import fse from "fs-extra"; import fse from "fs-extra";
const fsInjectable = getInjectable({ const fsInjectable = getInjectable({
id: "fs", id: "fs-1",
instantiate: () => fse, instantiate: () => fse,
causesSideEffects: true, causesSideEffects: true,
}); });

View File

@ -8,7 +8,7 @@ import fsInjectable from "./fs.injectable";
export type PathExists = (path: string) => Promise<boolean>; export type PathExists = (path: string) => Promise<boolean>;
const pathExistsInjectable = getInjectable({ const pathExistsInjectable = getInjectable({
id: "path-exists", id: "path-exists-1",
instantiate: (di): PathExists => di.inject(fsInjectable).pathExists, instantiate: (di): PathExists => di.inject(fsInjectable).pathExists,
}); });

View File

@ -8,7 +8,7 @@ import fsInjectable from "./fs.injectable";
export type ReadFile = (filePath: string) => Promise<string>; export type ReadFile = (filePath: string) => Promise<string>;
const readFileInjectable = getInjectable({ const readFileInjectable = getInjectable({
id: "read-file", id: "read-file-1",
instantiate: (di): ReadFile => { instantiate: (di): ReadFile => {
const { readFile } = di.inject(fsInjectable); const { readFile } = di.inject(fsInjectable);

View File

@ -9,7 +9,7 @@ import fsInjectable from "./fs.injectable";
export type ReadJson = (filePath: string) => Promise<JsonValue>; export type ReadJson = (filePath: string) => Promise<JsonValue>;
const readJsonFileInjectable = getInjectable({ const readJsonFileInjectable = getInjectable({
id: "read-json-file", id: "read-json-file-1",
instantiate: (di): ReadJson => di.inject(fsInjectable).readJson, instantiate: (di): ReadJson => di.inject(fsInjectable).readJson,
}); });

View File

@ -9,7 +9,7 @@ import yaml from "js-yaml";
export type ReadYamlFile = (filePath: string) => Promise<unknown>; export type ReadYamlFile = (filePath: string) => Promise<unknown>;
const readYamlFileInjectable = getInjectable({ const readYamlFileInjectable = getInjectable({
id: "read-yaml-file", id: "read-yaml-file-1",
instantiate: (di): ReadYamlFile => { instantiate: (di): ReadYamlFile => {
const readFile = di.inject(readFileInjectable); const readFile = di.inject(readFileInjectable);

View File

@ -10,7 +10,7 @@ import fsInjectable from "./fs.injectable";
export type WriteFile = (filePath: string, content: string | Buffer, opts?: WriteFileOptions) => Promise<void>; export type WriteFile = (filePath: string, content: string | Buffer, opts?: WriteFileOptions) => Promise<void>;
const writeFileInjectable = getInjectable({ const writeFileInjectable = getInjectable({
id: "write-file", id: "write-file-1",
instantiate: (di): WriteFile => { instantiate: (di): WriteFile => {
const { writeFile, ensureDir } = di.inject(fsInjectable); const { writeFile, ensureDir } = di.inject(fsInjectable);

View File

@ -10,7 +10,7 @@ import fsInjectable from "./fs.injectable";
export type WriteJson = (filePath: string, contents: JsonValue) => Promise<void>; export type WriteJson = (filePath: string, contents: JsonValue) => Promise<void>;
const writeJsonFileInjectable = getInjectable({ const writeJsonFileInjectable = getInjectable({
id: "write-json-file", id: "write-json-file-1",
instantiate: (di): WriteJson => { instantiate: (di): WriteJson => {
const { writeJson, ensureDir } = di.inject(fsInjectable); const { writeJson, ensureDir } = di.inject(fsInjectable);

View File

@ -8,7 +8,7 @@ import path from "path";
export type GetDirnameOfPath = (path: string) => string; export type GetDirnameOfPath = (path: string) => string;
const getDirnameOfPathInjectable = getInjectable({ const getDirnameOfPathInjectable = getInjectable({
id: "get-dirname-of-path", id: "get-dirname-of-path-1",
instantiate: (): GetDirnameOfPath => path.dirname, instantiate: (): GetDirnameOfPath => path.dirname,
causesSideEffects: true, causesSideEffects: true,
}); });

View File

@ -208,7 +208,7 @@ describe("channel", () => {
handler: () => () => "some-other-value", handler: () => () => "some-other-value",
}); });
testChannelListenerInMain2Injectable.id += "2"; // testChannelListenerInMain2Injectable.id += "2";
applicationBuilder.beforeApplicationStart((mainDi) => { applicationBuilder.beforeApplicationStart((mainDi) => {
runInAction(() => { runInAction(() => {

View File

@ -4,17 +4,17 @@
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import { computed } from "mobx"; import { computed } from "mobx";
import type { ClusterDto } from "./clusters.injectable";
import clustersInjectable from "./clusters.injectable";
import catalogEntityForClusterInjectable from "./catalog-entity-for-cluster.injectable"; import catalogEntityForClusterInjectable from "./catalog-entity-for-cluster.injectable";
import type { Cluster } from "@lensapp/cluster";
import { clustersInjectionToken } from "@lensapp/cluster";
const catalogEntitiesInjectable = getInjectable({ const catalogEntitiesInjectable = getInjectable({
id: "catalog-entities", id: "catalog-entities",
instantiate: (di) => { instantiate: (di) => {
const clusters = di.inject(clustersInjectable); const clusters = di.inject(clustersInjectionToken);
const getCatalogEntity = (cluster: ClusterDto) => const getCatalogEntity = (cluster: Cluster) =>
di.inject(catalogEntityForClusterInjectable, cluster); di.inject(catalogEntityForClusterInjectable, cluster);
return computed(() => clusters.get().map(getCatalogEntity)); return computed(() => clusters.get().map(getCatalogEntity));

View File

@ -2,14 +2,17 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { Cluster } from "@lensapp/cluster";
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable"; import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import { KubernetesCluster, LensKubernetesClusterStatus } from "../../../common/catalog-entities"; import {
import type { ClusterDto } from "./clusters.injectable"; KubernetesCluster,
LensKubernetesClusterStatus,
} from "../../../common/catalog-entities";
const catalogEntityForClusterInjectable = getInjectable({ const catalogEntityForClusterInjectable = getInjectable({
id: "catalog-entity-for-cluster", id: "catalog-entity-for-cluster",
instantiate: (di, cluster: ClusterDto) => instantiate: (di, cluster: Cluster) =>
new KubernetesCluster({ new KubernetesCluster({
metadata: { metadata: {
uid: cluster.id, uid: cluster.id,
@ -31,7 +34,7 @@ const catalogEntityForClusterInjectable = getInjectable({
}), }),
lifecycle: lifecycleEnum.keyedSingleton({ lifecycle: lifecycleEnum.keyedSingleton({
getInstanceKey: (di, cluster: ClusterDto) => cluster.id, getInstanceKey: (di, cluster: Cluster) => cluster.id,
}), }),
}); });

View File

@ -1,21 +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 { computedInjectManyInjectable } from "@ogre-tools/injectable-extension-for-mobx";
import { computed } from "mobx";
import { clusterInjectionToken } from "@lensapp/catalog";
const clustersInjectable = getInjectable({
id: "clusters",
instantiate: (di) => {
const computedInjectMany = di.inject(computedInjectManyInjectable);
const clusters = computedInjectMany(clusterInjectionToken);
return computed(() => clusters.get());
},
});
export default clustersInjectable;

View File

@ -5,12 +5,15 @@
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import hasCategoryForEntityInjectable from "../../common/catalog/has-category-for-entity.injectable"; import hasCategoryForEntityInjectable from "../../common/catalog/has-category-for-entity.injectable";
import { CatalogEntityRegistry } from "./entity-registry"; import { CatalogEntityRegistry } from "./entity-registry";
import catalogEntitiesInjectable
from "./catalog-entities-from-features/catalog-entities.injectable";
const catalogEntityRegistryInjectable = getInjectable({ const catalogEntityRegistryInjectable = getInjectable({
id: "catalog-entity-registry", id: "catalog-entity-registry",
instantiate: (di) => new CatalogEntityRegistry({ instantiate: (di) => new CatalogEntityRegistry({
hasCategoryForEntity: di.inject(hasCategoryForEntityInjectable), hasCategoryForEntity: di.inject(hasCategoryForEntityInjectable),
decoupledCatalogEntities: di.inject(catalogEntitiesInjectable),
}), }),
}); });

View File

@ -18,7 +18,10 @@ export const getDi = () => {
autoRegister({ autoRegister({
di, di,
requireContexts: [
targetModule: module,
getRequireContexts: () => [
require.context("./", true, /\.injectable\.(ts|tsx)$/), require.context("./", true, /\.injectable\.(ts|tsx)$/),
require.context("../extensions", true, /\.injectable\.(ts|tsx)$/), require.context("../extensions", true, /\.injectable\.(ts|tsx)$/),
require.context("../common", true, /\.injectable\.(ts|tsx)$/), require.context("../common", true, /\.injectable\.(ts|tsx)$/),

View File

@ -3,8 +3,18 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { registerFeature } from "@lensapp/feature-core";
import clusterFeature from "@lensapp/cluster";
import fsFeature from "@lensapp/fs";
import loggingFeature from "@lensapp/logging";
import shellFeature from "@lensapp/shell";
import type { DiContainer } from "@ogre-tools/injectable"; import type { DiContainer } from "@ogre-tools/injectable";
import { action } from "mobx"; import { action } from "mobx";
export default action((di: DiContainer) => {}); export default action((di: DiContainer) => {
registerFeature(di, clusterFeature);
registerFeature(di, fsFeature);
registerFeature(di, loggingFeature);
registerFeature(di, shellFeature);
});

View File

@ -19,7 +19,10 @@ export const getDi = () => {
autoRegister({ autoRegister({
di, di,
requireContexts: [
targetModule: module,
getRequireContexts: () => [
require.context("./", true, /\.injectable\.(ts|tsx)$/), require.context("./", true, /\.injectable\.(ts|tsx)$/),
require.context("../common", true, /\.injectable\.(ts|tsx)$/), require.context("../common", true, /\.injectable\.(ts|tsx)$/),
require.context("../extensions", true, /\.injectable\.(ts|tsx)$/), require.context("../extensions", true, /\.injectable\.(ts|tsx)$/),

View File

@ -3,7 +3,8 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { DiContainer } from "@ogre-tools/injectable";
import { action } from "mobx"; import { action } from "mobx";
export default action(() => {}); export default action((di: DiContainer) => {});

View File

@ -1101,6 +1101,36 @@
resolved "https://registry.yarnpkg.com/@leichtgewicht/ip-codec/-/ip-codec-2.0.4.tgz#b2ac626d6cb9c8718ab459166d4bb405b8ffa78b" resolved "https://registry.yarnpkg.com/@leichtgewicht/ip-codec/-/ip-codec-2.0.4.tgz#b2ac626d6cb9c8718ab459166d4bb405b8ffa78b"
integrity sha512-Hcv+nVC0kZnQ3tD9GVu5xSMR4VVYOteQIr/hwFPVEvPdlXqgGEuRjiheChHgdM+JyqdgNcmzZOX/tnl0JOiI7A== integrity sha512-Hcv+nVC0kZnQ3tD9GVu5xSMR4VVYOteQIr/hwFPVEvPdlXqgGEuRjiheChHgdM+JyqdgNcmzZOX/tnl0JOiI7A==
"@lensapp/cluster@^0.1.5":
version "0.1.5"
resolved "http://localhost:53093/@lensapp%2fcluster/-/cluster-0.1.5.tgz#81b7a6cb1a32bf0ef5a388cee53bac40077adf51"
integrity sha512-PDM8NBgvugQTOqQEk2/9XRW98Yup9+eqhbAv9mrMetfDnYnadS2UJQXU9uOTo8bZDjgSNCJFyijqWH8KJBXQcw==
"@lensapp/feature-core@^0.1.6":
version "0.1.6"
resolved "http://localhost:53093/@lensapp%2ffeature-core/-/feature-core-0.1.6.tgz#7f59954c7108c2357a3fccd675707702f0e1e28b"
integrity sha512-c7Iq9E/M0V9uTrJvwHXUWaWJs2ndNML3zzT51+hyTV5oBbKFYlS+82b9jiETVPTGy52r5ttJwLEKfvfVIzadag==
"@lensapp/fs@^0.2.0":
version "0.2.0"
resolved "http://localhost:53093/@lensapp%2ffs/-/fs-0.2.0.tgz#b22f669d4dd6a20a9365cf7d75262801c6baefba"
integrity sha512-ToQc89BkYDF7Ca4yUl24frYYYfJ3BFRiVpmlvmIpLQvoGe1FbHesq3JcaAmuMMOv2DmxvNdJ/yN/5BBEwkOnPQ==
"@lensapp/logging@^0.1.5":
version "0.1.5"
resolved "http://localhost:53093/@lensapp%2flogging/-/logging-0.1.5.tgz#51f24447252745f394a0f1230b7473ee3cb13d39"
integrity sha512-CIKEVaYMdwkYbPkJpaNwlgwq76t9XKJqAuSg7UDqzUEd4abnXu/vsojfeNWIRVc5ZlXsegZYBKKQQ4dlivb3/Q==
"@lensapp/shell@^0.1.6":
version "0.1.6"
resolved "http://localhost:53093/@lensapp%2fshell/-/shell-0.1.6.tgz#574ae450c8e75c16d12a79e1ffcf0ef5733ad7e8"
integrity sha512-BrIvBrrOpAdaGLisI8kjet4ez9eq/b6dkOD5jV1ep+z1wIWjsJv8BDC1obIUQ1jb2V5N1ACofwt3SdlNyNVYMQ==
"@lensapp/utils@^0.2.4":
version "0.2.4"
resolved "http://localhost:53093/@lensapp%2futils/-/utils-0.2.4.tgz#aab4ad66d0c0d467080b29ed4216a6b81ca27d67"
integrity sha512-vfYiLC98vFhbJD4kDMILebOapqOXaM35mR72MHkBdbP8nYeDej62fC6YW6sAO41G5mJpLELvVQy8Xix9XHxwQQ==
"@malept/cross-spawn-promise@^1.1.0": "@malept/cross-spawn-promise@^1.1.0":
version "1.1.1" version "1.1.1"
resolved "https://registry.yarnpkg.com/@malept/cross-spawn-promise/-/cross-spawn-promise-1.1.1.tgz#504af200af6b98e198bce768bc1730c6936ae01d" resolved "https://registry.yarnpkg.com/@malept/cross-spawn-promise/-/cross-spawn-promise-1.1.1.tgz#504af200af6b98e198bce768bc1730c6936ae01d"
@ -1409,30 +1439,35 @@
read-package-json-fast "^2.0.3" read-package-json-fast "^2.0.3"
which "^2.0.2" which "^2.0.2"
"@ogre-tools/fp@^12.0.1": "@ogre-tools/fp@^14.0.3":
version "12.0.1" version "14.0.3"
resolved "https://registry.yarnpkg.com/@ogre-tools/fp/-/fp-12.0.1.tgz#1f932c8c4cc04075f92ab5ca564db158ac1514d4" resolved "https://registry.yarnpkg.com/@ogre-tools/fp/-/fp-14.0.3.tgz#e8e1279b6f40685d0f4b1699dfd6e5c81e9f305b"
integrity sha512-BzMhkI4wPnuI+hXJDbtHUXQn/uBjJLx3W0oDaIFV+lLpkneUU0oW9D5uZFHNOouzCgf67/tnmUC6Ohevbr7/VA== integrity sha512-6FwUnuw5n4/ICtXTcUadgNJlLJv+iCfUD4UE+8yrVyyXg+LXX3K2GdSxI9sivoA/3xIEoUyPkXcSOAEUIDXWsA==
"@ogre-tools/injectable-extension-for-auto-registration@^12.0.1": "@ogre-tools/injectable-extension-for-auto-registration@^14.0.3":
version "12.0.1" version "14.0.3"
resolved "https://registry.yarnpkg.com/@ogre-tools/injectable-extension-for-auto-registration/-/injectable-extension-for-auto-registration-12.0.1.tgz#878f73b5408b12193664f4920289905eacb4c1cc" resolved "https://registry.yarnpkg.com/@ogre-tools/injectable-extension-for-auto-registration/-/injectable-extension-for-auto-registration-14.0.3.tgz#492c43e01b7d1efcdcb10bd0c844ef636f8b5788"
integrity sha512-itKcxEJ/J8SKGD/Wwj0UYOA+/nqwnrwanhikY6qhlibj8guujX77Iip7vMBzJFc2nIrRaQRcpNV2eXe+tjQUdg== integrity sha512-2wXDIxO//DOBw+N68JLumrK/3zaryYfS70AFkKCf/FI17qsgkfd2OrMh2TEdXhnGwoPiIelRRGaLYWiFcxl8nw==
"@ogre-tools/injectable-extension-for-mobx@^12.0.1": "@ogre-tools/injectable-extension-for-mobx@^14.0.3":
version "12.0.1" version "14.0.3"
resolved "https://registry.yarnpkg.com/@ogre-tools/injectable-extension-for-mobx/-/injectable-extension-for-mobx-12.0.1.tgz#1e9de8caba076d7cebda4177a5ab763594b08b28" resolved "https://registry.yarnpkg.com/@ogre-tools/injectable-extension-for-mobx/-/injectable-extension-for-mobx-14.0.3.tgz#11f5becc6d5e15e75bbbac31e994501e0f683536"
integrity sha512-M1penOpZfO3/rJMb6WN4IL86p9Lx9tOMCipiNkAyitNLGWfeDPG279JlCs9E3Uw8R9nkFPiw8Je2SLnwnM9o+A== integrity sha512-VOFXxC4ZH3+WfK5sizjT0SEmnmK48bai6VkKKj1BsHkywpLFaYLQrA4yr6DvvxtWuP8q/Zr7u8rb+JkW68cdyQ==
"@ogre-tools/injectable-react@^12.0.1": "@ogre-tools/injectable-react@^14.0.3":
version "12.0.1" version "14.0.3"
resolved "https://registry.yarnpkg.com/@ogre-tools/injectable-react/-/injectable-react-12.0.1.tgz#07a43f25bd78db37cb2c00bc0c06e0a69394f519" resolved "https://registry.yarnpkg.com/@ogre-tools/injectable-react/-/injectable-react-14.0.3.tgz#005679b9b727ee9249cc327272fe933329eda5d9"
integrity sha512-LAOh/EHKqk/pQcBRZUAz0VcJwgBeIPxHwlV/Apw0aEBBoMuYLsLZh47rES8sMYMV6N5x7oVfkjMscujY0DCgaQ== integrity sha512-y0c8gb8uO9AUWKILXItE0ZqqMmJcXDh3+2j+fXJT5SDcnV7TIVgYuwXd+mh78i0SaoL74/YiX+HNujne/wnIUA==
"@ogre-tools/injectable@^12.0.1": "@ogre-tools/injectable@^14.0.3":
version "12.0.1" version "14.0.3"
resolved "https://registry.yarnpkg.com/@ogre-tools/injectable/-/injectable-12.0.1.tgz#53f9981f7f165da4277857b8338cc4097d357ad2" resolved "https://registry.yarnpkg.com/@ogre-tools/injectable/-/injectable-14.0.3.tgz#3d2b188fce6d87e8195093d555b34d788a436c5e"
integrity sha512-uOx8STN2wSc9hknDSTGqViyR89Vwg7rGacwrVNchgyo48/QJsmZZz6cd1Aw3nT4vr7ekjTc2lh0Rz6zGIv47hg== integrity sha512-qytN1CWITWW7qa6a4gWSTgAo1MV2M1nDSh+SX0xDE7w5lvDpKj6cT3zxNbGX4J1s++SdiCsAK7HHuX3IaeBaow==
"@ogre-tools/mobx-utils@^14.0.3":
version "14.0.3"
resolved "https://registry.yarnpkg.com/@ogre-tools/mobx-utils/-/mobx-utils-14.0.3.tgz#8a83f13c00df18d4bab4489029b3e0b519eb0634"
integrity sha512-7Mwqap03vfgHfxLTy2hRRoMi2uepuUOb+zbGqg6kSK7Mdpwu4UXkMEOgQnEQFsiTPhxvbUBdUPS8Uc6HFlP9NA==
"@pmmmwh/react-refresh-webpack-plugin@^0.5.8": "@pmmmwh/react-refresh-webpack-plugin@^0.5.8":
version "0.5.8" version "0.5.8"