mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Allow to import app as a library (#6722)
* unify build fs layout Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * use currentApp path for static files Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * lint fix Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * allow to import open-lens Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * allow to customize both main & renderer Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix compile-library script Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * remove bundled extensions Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * similar interface for both main & renderer Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * use startApp on both sides Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix startApp import Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix startApp import Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * Fix injection cycle (somehow) Signed-off-by: Sebastian Malton <sebastian@malton.name> * use cwd in download_binaries Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * introduce applicationInformationToken Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * register applicationInformationInjectable in main & renderer Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * allow to define bundled extensions via appStart Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * compile node-fetch automatically via prepare Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * define peerDependencies Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * webpack fixes Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * rename application-information-token.injectable.ts -> application-information-token.ts Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * monaco-editor as externals Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * refactor application-information Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * introduce bundledExtensionInjectionToken Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * mark library exports as experimental Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * move extension npm package files & add release automation Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * add missing build files to package Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix bad merge conflict resolve Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix package.json name Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * allow to set mode via startApp Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * revert unnecessary changes Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * webpack: fix extensionOutDir Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * remove unnecessary peerDependencies Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * introduce nodeEnvInjectionToken Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * remove NODE_ENV from environmentVariablesInjectable Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix jest modulePathIgnorePatterns Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix duplicate injectable registration Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix build executableName Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> Signed-off-by: Sebastian Malton <sebastian@malton.name> Co-authored-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
ba908c860d
commit
97551bb7f0
57 files changed
+712
-263
No files matched your search
@@ -3,12 +3,12 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import applicationInformationInjectable from "../../../vars/application-information.injectable";
|
||||
import applicationInformationToken from "../../../vars/application-information-token";
|
||||
|
||||
const welcomeRouteConfigInjectable = getInjectable({
|
||||
id: "welcome-route-config",
|
||||
|
||||
instantiate: (di) => di.inject(applicationInformationInjectable).config.welcomeRoute,
|
||||
instantiate: (di) => di.inject(applicationInformationToken).config.welcomeRoute,
|
||||
});
|
||||
|
||||
export default welcomeRouteConfigInjectable;
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import applicationInformationToken from "./vars/application-information-token";
|
||||
import type { ApplicationInformation } from "./vars/application-information-token";
|
||||
import { bundledExtensionInjectionToken } from "../extensions/extension-discovery/bundled-extension-token";
|
||||
|
||||
// @experimental
|
||||
export {
|
||||
applicationInformationToken,
|
||||
ApplicationInformation,
|
||||
bundledExtensionInjectionToken,
|
||||
};
|
||||
@@ -8,15 +8,11 @@ const environmentVariablesInjectable = getInjectable({
|
||||
id: "environment-variables",
|
||||
|
||||
instantiate: () => {
|
||||
// IMPORTANT: The syntax needs to be exactly this in order to make environment variable values
|
||||
// hard-coded at compile-time by Webpack.
|
||||
const NODE_ENV = process.env.NODE_ENV;
|
||||
const JEST_WORKER_ID = process.env.JEST_WORKER_ID;
|
||||
const CICD = process.env.CICD;
|
||||
|
||||
return {
|
||||
// Compile-time environment variables
|
||||
NODE_ENV,
|
||||
JEST_WORKER_ID,
|
||||
CICD,
|
||||
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import applicationInformationInjectable from "./application-information.injectable";
|
||||
import applicationInformationToken from "./application-information-token";
|
||||
|
||||
const applicationCopyrightInjectable = getInjectable({
|
||||
id: "application-copyright",
|
||||
instantiate: (di) => di.inject(applicationInformationInjectable).copyright,
|
||||
instantiate: (di) => di.inject(applicationInformationToken).copyright,
|
||||
});
|
||||
|
||||
export default applicationCopyrightInjectable;
|
||||
@@ -3,11 +3,11 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import applicationInformationInjectable from "./application-information.injectable";
|
||||
import applicationInformationToken from "./application-information-token";
|
||||
|
||||
const applicationDescriptionInjectable = getInjectable({
|
||||
id: "application-description",
|
||||
instantiate: (di) => di.inject(applicationInformationInjectable).description,
|
||||
instantiate: (di) => di.inject(applicationInformationToken).description,
|
||||
});
|
||||
|
||||
export default applicationDescriptionInjectable;
|
||||
+3
-5
@@ -4,14 +4,12 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import packageJson from "../../../package.json";
|
||||
|
||||
export type ApplicationInformation = Pick<typeof packageJson, "version" | "config" | "productName" | "copyright" | "description" | "name"> & {
|
||||
build: Partial<typeof packageJson["build"]> & { publish?: unknown[] };
|
||||
};
|
||||
import applicationInformationToken from "../../common/vars/application-information-token";
|
||||
|
||||
const applicationInformationInjectable = getInjectable({
|
||||
id: "application-information",
|
||||
instantiate: (): ApplicationInformation => {
|
||||
injectionToken: applicationInformationToken,
|
||||
instantiate: () => {
|
||||
const { version, config, productName, build, copyright, description, name } = packageJson;
|
||||
|
||||
return { version, config, productName, build, copyright, description, name };
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* 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";
|
||||
import type packageJson from "../../../package.json";
|
||||
|
||||
export type ApplicationInformation = Pick<typeof packageJson, "version" | "config" | "productName" | "copyright" | "description" | "name"> & {
|
||||
build: Partial<typeof packageJson["build"]> & { publish?: unknown[] };
|
||||
};
|
||||
|
||||
const applicationInformationToken = getInjectionToken<ApplicationInformation>({
|
||||
id: "application-information-token",
|
||||
});
|
||||
|
||||
export default applicationInformationToken;
|
||||
@@ -3,11 +3,11 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import applicationInformationInjectable from "./application-information.injectable";
|
||||
import applicationInformationToken from "./application-information-token";
|
||||
|
||||
const bundledKubectlVersionInjectable = getInjectable({
|
||||
id: "bundled-kubectl-version",
|
||||
instantiate: (di) => di.inject(applicationInformationInjectable).config.bundledKubectlVersion,
|
||||
instantiate: (di) => di.inject(applicationInformationToken).config.bundledKubectlVersion,
|
||||
});
|
||||
|
||||
export default bundledKubectlVersionInjectable;
|
||||
@@ -3,11 +3,11 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import applicationInformationInjectable from "./application-information.injectable";
|
||||
import applicationInformationToken from "./application-information-token";
|
||||
|
||||
const contentSecurityPolicyInjectable = getInjectable({
|
||||
id: "content-security-policy",
|
||||
instantiate: (di) => di.inject(applicationInformationInjectable).config.contentSecurityPolicy,
|
||||
instantiate: (di) => di.inject(applicationInformationToken).config.contentSecurityPolicy,
|
||||
});
|
||||
|
||||
export default contentSecurityPolicyInjectable;
|
||||
@@ -4,12 +4,12 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { SemVer } from "semver";
|
||||
import applicationInformationInjectable from "./application-information.injectable";
|
||||
import applicationInformationToken from "./application-information-token";
|
||||
|
||||
const extensionApiVersionInjectable = getInjectable({
|
||||
id: "extension-api-version",
|
||||
instantiate: (di) => {
|
||||
const { major, minor, patch } = new SemVer(di.inject(applicationInformationInjectable).version);
|
||||
const { major, minor, patch } = new SemVer(di.inject(applicationInformationToken).version);
|
||||
|
||||
return `${major}.${minor}.${patch}`;
|
||||
},
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import environmentVariablesInjectable from "../utils/environment-variables.injectable";
|
||||
import nodeEnvInjectionToken from "./node-env-injection-token";
|
||||
|
||||
const isProductionInjectable = getInjectable({
|
||||
id: "is-production",
|
||||
|
||||
instantiate: (di) => {
|
||||
const { NODE_ENV: nodeEnv } = di.inject(environmentVariablesInjectable);
|
||||
const nodeEnv = di.inject(nodeEnvInjectionToken);
|
||||
|
||||
return nodeEnv === "production";
|
||||
},
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* 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";
|
||||
|
||||
const nodeEnvInjectionToken = getInjectionToken<string | undefined>({
|
||||
id: "node-env-injection-token",
|
||||
});
|
||||
|
||||
export default nodeEnvInjectionToken;
|
||||
@@ -3,11 +3,11 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import applicationInformationInjectable from "./application-information.injectable";
|
||||
import applicationInformationToken from "./application-information-token";
|
||||
|
||||
const productNameInjectable = getInjectable({
|
||||
id: "product-name",
|
||||
instantiate: (di) => di.inject(applicationInformationInjectable).productName,
|
||||
instantiate: (di) => di.inject(applicationInformationToken).productName,
|
||||
});
|
||||
|
||||
export default productNameInjectable;
|
||||
@@ -3,11 +3,11 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import applicationInformationInjectable from "./application-information.injectable";
|
||||
import applicationInformationToken from "./application-information-token";
|
||||
|
||||
const sentryDataSourceNameInjectable = getInjectable({
|
||||
id: "sentry-data-source-name",
|
||||
instantiate: (di) => di.inject(applicationInformationInjectable).config.sentryDsn,
|
||||
instantiate: (di) => di.inject(applicationInformationToken).config.sentryDsn,
|
||||
});
|
||||
|
||||
export default sentryDataSourceNameInjectable;
|
||||
@@ -5,5 +5,4 @@
|
||||
import { getGlobalOverride } from "../test-utils/get-global-override";
|
||||
import staticFilesDirectoryInjectable from "./static-files-directory.injectable";
|
||||
|
||||
|
||||
export default getGlobalOverride(staticFilesDirectoryInjectable, () => "/some-static-directory");
|
||||
@@ -3,11 +3,11 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import applicationInformationInjectable from "./application-information.injectable";
|
||||
import applicationInformationToken from "./application-information-token";
|
||||
|
||||
const storeMigrationVersionInjectable = getInjectable({
|
||||
id: "store-migration-version",
|
||||
instantiate: (di) => di.inject(applicationInformationInjectable).version,
|
||||
instantiate: (di) => di.inject(applicationInformationToken).version,
|
||||
});
|
||||
|
||||
export default storeMigrationVersionInjectable;
|
||||
@@ -404,7 +404,7 @@ export class ExtensionLoader {
|
||||
const extAbsolutePath = this.dependencies.joinPaths(this.dependencies.getDirnameOfPath(extension.manifestPath), extRelativePath);
|
||||
|
||||
try {
|
||||
return __non_webpack_require__(extAbsolutePath).default;
|
||||
return require(/* webpackIgnore: true */ extAbsolutePath).default;
|
||||
} catch (error) {
|
||||
const message = (error instanceof Error ? error.stack : undefined) || error;
|
||||
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
dist/
|
||||
__mocks__/
|
||||
@@ -1,31 +0,0 @@
|
||||
{
|
||||
"name": "@k8slens/extensions",
|
||||
"productName": "OpenLens extensions",
|
||||
"description": "OpenLens - Open Source Kubernetes IDE: extensions",
|
||||
"version": "6.0.0",
|
||||
"copyright": "© 2022 OpenLens Authors",
|
||||
"license": "MIT",
|
||||
"main": "dist/src/extensions/extension-api.js",
|
||||
"types": "dist/src/extensions/extension-api.d.ts",
|
||||
"files": [
|
||||
"dist/**/*.ts",
|
||||
"__mocks__/*.ts",
|
||||
"dist/**/*.js"
|
||||
],
|
||||
"author": {
|
||||
"name": "OpenLens Authors"
|
||||
},
|
||||
"dependencies": {
|
||||
"@material-ui/core": "^4.12.3",
|
||||
"@types/node": "^16.11.58",
|
||||
"@types/react": "^17.0.45",
|
||||
"@types/react-dom": "^17.0.16",
|
||||
"@types/react-router": "^5.1.18",
|
||||
"@types/react-router-dom": "^5.3.3",
|
||||
"conf": "^7.0.1",
|
||||
"mobx": "^6.5.0",
|
||||
"mobx-react": "^7.3.0",
|
||||
"react-select": "^5.3.2",
|
||||
"typed-emitter": "^1.3.1"
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -3,11 +3,11 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import applicationInformationInjectable from "../../../../../common/vars/application-information.injectable";
|
||||
import applicationInformationToken from "../../../../../common/vars/application-information-token";
|
||||
|
||||
const publishIsConfiguredInjectable = getInjectable({
|
||||
id: "publish-is-configured",
|
||||
instantiate: (di) => Boolean(di.inject(applicationInformationInjectable).build.publish?.length),
|
||||
instantiate: (di) => Boolean(di.inject(applicationInformationToken).build.publish?.length),
|
||||
});
|
||||
|
||||
export default publishIsConfiguredInjectable;
|
||||
@@ -6,7 +6,7 @@
|
||||
// Fix embedded kubeconfig paths under snap config
|
||||
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import applicationInformationInjectable from "../../../common/vars/application-information.injectable";
|
||||
import applicationInformationToken from "../../../common/vars/application-information-token";
|
||||
import { clusterStoreMigrationInjectionToken } from "../../../common/cluster-store/migration-token";
|
||||
import loggerInjectable from "../../../common/logger.injectable";
|
||||
import isSnapPackageInjectable from "../../../common/vars/is-snap-package.injectable";
|
||||
@@ -16,7 +16,7 @@ import pathExistsSyncInjectable from "../../../common/fs/path-exists-sync.inject
|
||||
const clusterStoreSnapMigrationInjectable = getInjectable({
|
||||
id: "cluster-store-snap-migration",
|
||||
instantiate: (di) => {
|
||||
const { version } = di.inject(applicationInformationInjectable);
|
||||
const { version } = di.inject(applicationInformationToken);
|
||||
const logger = di.inject(loggerInjectable);
|
||||
const isSnapPackage = di.inject(isSnapPackageInjectable);
|
||||
const pathExistsSync = di.inject(pathExistsSyncInjectable);
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { runInAction } from "mobx";
|
||||
import nodeEnvInjectionToken from "../common/vars/node-env-injection-token";
|
||||
import { registerInjectables } from "./register-injectables";
|
||||
import startMainApplicationInjectable from "./start-main-application/start-main-application.injectable";
|
||||
|
||||
interface AppConfig {
|
||||
di: DiContainer;
|
||||
mode: string;
|
||||
}
|
||||
|
||||
export function createApp(conf: AppConfig) {
|
||||
const { di, mode } = conf;
|
||||
|
||||
runInAction(() => {
|
||||
di.register(getInjectable({
|
||||
id: "node-env",
|
||||
instantiate: () => mode,
|
||||
injectionToken: nodeEnvInjectionToken,
|
||||
}));
|
||||
|
||||
registerInjectables(di);
|
||||
});
|
||||
|
||||
const startMainApplication = di.inject(startMainApplicationInjectable);
|
||||
|
||||
return {
|
||||
start: () => startMainApplication(),
|
||||
};
|
||||
}
|
||||
+3
-1
@@ -3,6 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import nodeEnvInjectionToken from "../../../common/vars/node-env-injection-token";
|
||||
import loggerInjectable from "../../../common/logger.injectable";
|
||||
import { onLoadOfApplicationInjectionToken } from "../../start-main-application/runnable-tokens/on-load-of-application-injection-token";
|
||||
|
||||
@@ -11,11 +12,12 @@ const setupDeveloperToolsInDevelopmentEnvironmentInjectable = getInjectable({
|
||||
|
||||
instantiate: (di) => {
|
||||
const logger = di.inject(loggerInjectable);
|
||||
const nodeEnv = di.inject(nodeEnvInjectionToken);
|
||||
|
||||
return {
|
||||
id: "setup-developer-tools-in-development-environment",
|
||||
run: () => {
|
||||
if (process.env.NODE_ENV !== "development") {
|
||||
if (nodeEnv !== "development") {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import * as Mobx from "mobx";
|
||||
import { spawn } from "node-pty";
|
||||
import * as LensExtensionsCommonApi from "../extensions/common-api";
|
||||
import * as LensExtensionsMainApi from "../extensions/main-api";
|
||||
|
||||
|
||||
/**
|
||||
* Exports for virtual package "@k8slens/extensions" for main-process.
|
||||
* All exporting names available in global runtime scope:
|
||||
* e.g. global.Mobx, global.LensExtensions
|
||||
*/
|
||||
const LensExtensions = {
|
||||
Common: LensExtensionsCommonApi,
|
||||
Main: LensExtensionsMainApi,
|
||||
};
|
||||
|
||||
const Pty = {
|
||||
spawn,
|
||||
};
|
||||
|
||||
export { Mobx, LensExtensions, Pty };
|
||||
+2
-16
@@ -3,28 +3,14 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { createContainer } from "@ogre-tools/injectable";
|
||||
import { autoRegister } from "@ogre-tools/injectable-extension-for-auto-registration";
|
||||
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
|
||||
import { runInAction } from "mobx";
|
||||
import { Environments, setLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import applicationInformationInjectable from "../common/vars/application-information-injectable";
|
||||
|
||||
export const getDi = () => {
|
||||
const di = createContainer("main");
|
||||
|
||||
setLegacyGlobalDiForExtensionApi(di, Environments.main);
|
||||
|
||||
runInAction(() => {
|
||||
registerMobX(di);
|
||||
|
||||
autoRegister({
|
||||
di,
|
||||
requireContexts: [
|
||||
require.context("./", true, CONTEXT_MATCHER_FOR_NON_FEATURES),
|
||||
require.context("../extensions", true, CONTEXT_MATCHER_FOR_NON_FEATURES),
|
||||
require.context("../common", true, CONTEXT_MATCHER_FOR_NON_FEATURES),
|
||||
require.context("../features", true, CONTEXT_MATCHER_FOR_FEATURES),
|
||||
],
|
||||
});
|
||||
di.register(applicationInformationInjectable);
|
||||
});
|
||||
|
||||
return di;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import { kebabCase, noop, chunk } from "lodash/fp";
|
||||
import type { DiContainer, Injectable } from "@ogre-tools/injectable";
|
||||
import { createContainer, isInjectable } from "@ogre-tools/injectable";
|
||||
import { createContainer, isInjectable, getInjectable } from "@ogre-tools/injectable";
|
||||
import { Environments, setLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import writeJsonFileInjectable from "../common/fs/write-json-file.injectable";
|
||||
import readJsonFileInjectable from "../common/fs/read-json-file.injectable";
|
||||
@@ -71,6 +71,8 @@ import kubectlDownloadingNormalizedArchInjectable from "./kubectl/normalized-arc
|
||||
import initializeClusterManagerInjectable from "./cluster/initialize-manager.injectable";
|
||||
import addKubeconfigSyncAsEntitySourceInjectable from "./start-main-application/runnables/kube-config-sync/add-source.injectable";
|
||||
import type { GlobalOverride } from "../common/test-utils/get-global-override";
|
||||
import applicationInformationInjectable from "../common/vars/application-information-injectable";
|
||||
import nodeEnvInjectionToken from "../common/vars/node-env-injection-token";
|
||||
|
||||
export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {}) {
|
||||
const {
|
||||
@@ -79,6 +81,12 @@ export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {})
|
||||
|
||||
const di = createContainer("main");
|
||||
|
||||
di.register(getInjectable({
|
||||
id: "node-env",
|
||||
instantiate: () => "test",
|
||||
injectionToken: nodeEnvInjectionToken,
|
||||
}));
|
||||
|
||||
setLegacyGlobalDiForExtensionApi(di, Environments.main);
|
||||
|
||||
di.preventSideEffects();
|
||||
@@ -93,6 +101,7 @@ export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {})
|
||||
|
||||
runInAction(() => {
|
||||
registerMobX(di);
|
||||
di.register(applicationInformationInjectable);
|
||||
|
||||
chunk(100)(injectables).forEach(chunkInjectables => {
|
||||
di.register(...chunkInjectables);
|
||||
|
||||
+10
-29
@@ -5,38 +5,19 @@
|
||||
|
||||
// Main process
|
||||
|
||||
import * as Mobx from "mobx";
|
||||
import { spawn } from "node-pty";
|
||||
import process from "process";
|
||||
import * as LensExtensionsCommonApi from "../extensions/common-api";
|
||||
import * as LensExtensionsMainApi from "../extensions/main-api";
|
||||
import { getDi } from "./getDi";
|
||||
import startMainApplicationInjectable from "./start-main-application/start-main-application.injectable";
|
||||
import { Mobx, LensExtensions, Pty } from "./extension-api";
|
||||
import { createApp } from "./create-app";
|
||||
|
||||
const di = getDi();
|
||||
const startMainApplication = di.inject(startMainApplicationInjectable);
|
||||
const app = createApp({
|
||||
di,
|
||||
mode: process.env.NODE_ENV || "development",
|
||||
});
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await startMainApplication();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
}
|
||||
})();
|
||||
|
||||
/**
|
||||
* Exports for virtual package "@k8slens/extensions" for main-process.
|
||||
* All exporting names available in global runtime scope:
|
||||
* e.g. global.Mobx, global.LensExtensions
|
||||
*/
|
||||
const LensExtensions = {
|
||||
Common: LensExtensionsCommonApi,
|
||||
Main: LensExtensionsMainApi,
|
||||
};
|
||||
|
||||
const Pty = {
|
||||
spawn,
|
||||
};
|
||||
app.start().catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
export { Mobx, LensExtensions, Pty };
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { afterApplicationIsLoadedInjectionToken } from "./start-main-application/runnable-tokens/after-application-is-loaded-injection-token";
|
||||
import { beforeApplicationIsLoadingInjectionToken } from "./start-main-application/runnable-tokens/before-application-is-loading-injection-token";
|
||||
import { beforeElectronIsReadyInjectionToken } from "./start-main-application/runnable-tokens/before-electron-is-ready-injection-token";
|
||||
import { onLoadOfApplicationInjectionToken } from "./start-main-application/runnable-tokens/on-load-of-application-injection-token";
|
||||
import * as extensionApi from "./extension-api";
|
||||
import { createApp } from "./create-app";
|
||||
|
||||
// @experimental
|
||||
export {
|
||||
createApp,
|
||||
extensionApi,
|
||||
afterApplicationIsLoadedInjectionToken,
|
||||
beforeApplicationIsLoadingInjectionToken,
|
||||
beforeElectronIsReadyInjectionToken,
|
||||
onLoadOfApplicationInjectionToken,
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import { autoRegister } from "@ogre-tools/injectable-extension-for-auto-registration";
|
||||
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
|
||||
import { runInAction } from "mobx";
|
||||
import { Environments, setLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
|
||||
export function registerInjectables(di: DiContainer) {
|
||||
setLegacyGlobalDiForExtensionApi(di, Environments.main);
|
||||
|
||||
runInAction(() => {
|
||||
registerMobX(di);
|
||||
|
||||
autoRegister({
|
||||
di,
|
||||
requireContexts: [
|
||||
require.context("./", true, CONTEXT_MATCHER_FOR_NON_FEATURES),
|
||||
require.context("../extensions", true, CONTEXT_MATCHER_FOR_NON_FEATURES),
|
||||
require.context("../common", true, CONTEXT_MATCHER_FOR_NON_FEATURES),
|
||||
require.context("../features", true, CONTEXT_MATCHER_FOR_FEATURES),
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
return di;
|
||||
}
|
||||
@@ -6,19 +6,17 @@ import { getInjectable } from "@ogre-tools/injectable";
|
||||
import httpProxy from "http-proxy";
|
||||
import { webpackDevServerPort } from "../../../../webpack/vars";
|
||||
import { publicPath } from "../../../common/vars";
|
||||
import appNameInjectable from "../../../common/vars/app-name.injectable";
|
||||
import type { LensApiRequest, RouteResponse } from "../../router/route";
|
||||
|
||||
const devStaticFileRouteHandlerInjectable = getInjectable({
|
||||
id: "dev-static-file-route-handler",
|
||||
instantiate: (di) => {
|
||||
instantiate: () => {
|
||||
const proxy = httpProxy.createProxy();
|
||||
const appName = di.inject(appNameInjectable);
|
||||
const proxyTarget = `http://127.0.0.1:${webpackDevServerPort}`;
|
||||
|
||||
return async ({ raw: { req, res }}: LensApiRequest<"/{path*}">): Promise<RouteResponse<Buffer>> => {
|
||||
if (req.url === "/" || !req.url) {
|
||||
req.url = `${publicPath}/${appName}.html`;
|
||||
req.url = `${publicPath}/index.html`;
|
||||
} else if (!req.url.startsWith("/build/")) {
|
||||
return { statusCode: 404 };
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import { getInjectable } from "@ogre-tools/injectable";
|
||||
import readFileBufferInjectable from "../../../common/fs/read-file-buffer.injectable";
|
||||
import joinPathsInjectable from "../../../common/path/join-paths.injectable";
|
||||
import staticFilesDirectoryInjectable from "../../../common/vars/static-files-directory.injectable";
|
||||
import appNameInjectable from "../../../common/vars/app-name.injectable";
|
||||
import type { LensApiRequest } from "../../router/route";
|
||||
import path from "path";
|
||||
import type { SupportedFileExtension } from "../../router/router-content-types";
|
||||
@@ -20,7 +19,6 @@ const prodStaticFileRouteHandlerInjectable = getInjectable({
|
||||
const readFileBuffer = di.inject(readFileBufferInjectable);
|
||||
const joinPaths = di.inject(joinPathsInjectable);
|
||||
const staticFilesDirectory = di.inject(staticFilesDirectoryInjectable);
|
||||
const appName = di.inject(appNameInjectable);
|
||||
const logger = di.inject(loggerInjectable);
|
||||
|
||||
return async ({ params }: LensApiRequest<"/{path*}">) => {
|
||||
@@ -49,7 +47,7 @@ const prodStaticFileRouteHandlerInjectable = getInjectable({
|
||||
return { statusCode: 404 };
|
||||
}
|
||||
|
||||
filePath = `${publicPath}/${appName}.html`;
|
||||
filePath = `${publicPath}/index.html`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -12,7 +12,7 @@ import openLinkInBrowserInjectable from "../../../../common/utils/open-link-in-b
|
||||
import getAbsolutePathInjectable from "../../../../common/path/get-absolute-path.injectable";
|
||||
import lensResourcesDirInjectable from "../../../../common/vars/lens-resources-dir.injectable";
|
||||
import isLinuxInjectable from "../../../../common/vars/is-linux.injectable";
|
||||
import applicationInformationInjectable from "../../../../common/vars/application-information.injectable";
|
||||
import applicationInformationToken from "../../../../common/vars/application-information-token";
|
||||
import pathExistsSyncInjectable from "../../../../common/fs/path-exists-sync.injectable";
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ const createElectronWindowInjectable = getInjectable({
|
||||
const getAbsolutePath = di.inject(getAbsolutePathInjectable);
|
||||
const lensResourcesDir = di.inject(lensResourcesDirInjectable);
|
||||
const isLinux = di.inject(isLinuxInjectable);
|
||||
const applicationInformation = di.inject(applicationInformationInjectable);
|
||||
const applicationInformation = di.inject(applicationInformationToken);
|
||||
const pathExistsSync = di.inject(pathExistsSyncInjectable);
|
||||
|
||||
return (configuration) => {
|
||||
|
||||
+3
-4
@@ -3,14 +3,14 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getGlobalOverride } from "../test-utils/get-global-override";
|
||||
import applicationInformationInjectable from "./application-information.injectable";
|
||||
import { getGlobalOverride } from "../../common/test-utils/get-global-override";
|
||||
import applicationInformationInjectable from "../../common/vars/application-information-injectable";
|
||||
|
||||
export default getGlobalOverride(applicationInformationInjectable, () => ({
|
||||
name: "some-product-name",
|
||||
productName: "some-product-name",
|
||||
version: "6.0.0",
|
||||
build: {},
|
||||
build: {} as any,
|
||||
config: {
|
||||
k8sProxyVersion: "0.2.1",
|
||||
bundledKubectlVersion: "1.23.3",
|
||||
@@ -18,7 +18,6 @@ export default getGlobalOverride(applicationInformationInjectable, () => ({
|
||||
sentryDsn: "",
|
||||
contentSecurityPolicy: "script-src 'unsafe-eval' 'self'; frame-src http://*.localhost:*/; img-src * data:",
|
||||
welcomeRoute: "/welcome",
|
||||
extensions: [],
|
||||
},
|
||||
copyright: "some-copyright-information",
|
||||
description: "some-descriptive-text",
|
||||
@@ -7,13 +7,13 @@ import { docsUrl, slackUrl } from "../../../common/vars";
|
||||
import type { WeblinkData } from "../../../common/weblinks-store/weblink-store";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { weblinkStoreMigrationInjectionToken } from "../../../common/weblinks-store/migration-token";
|
||||
import applicationInformationInjectable from "../../../common/vars/application-information.injectable";
|
||||
import applicationInformationToken from "../../../common/vars/application-information-token";
|
||||
import { lensDocumentationWeblinkId, lensSlackWeblinkId } from "../links";
|
||||
|
||||
const currentVersionWeblinkStoreMigrationInjectable = getInjectable({
|
||||
id: "current-version-weblink-store-migration",
|
||||
instantiate: (di) => {
|
||||
const { version } = di.inject(applicationInformationInjectable);
|
||||
const { version } = di.inject(applicationInformationToken);
|
||||
|
||||
return {
|
||||
version, // Run always after upgrade
|
||||
|
||||
@@ -6,15 +6,8 @@
|
||||
import "./components/app.scss";
|
||||
|
||||
import React from "react";
|
||||
import ReactDOM, { render, unmountComponentAtNode } from "react-dom";
|
||||
import * as Mobx from "mobx";
|
||||
import * as MobxReact from "mobx-react";
|
||||
import * as ReactRouter from "react-router";
|
||||
import * as ReactRouterDom from "react-router-dom";
|
||||
import * as LensExtensionsCommonApi from "../extensions/common-api";
|
||||
import * as LensExtensionsRendererApi from "../extensions/renderer-api";
|
||||
import { render, unmountComponentAtNode } from "react-dom";
|
||||
import { DefaultProps } from "./mui-base-theme";
|
||||
import { getDi } from "./getDi";
|
||||
import { DiContextProvider } from "@ogre-tools/injectable-react";
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import extensionLoaderInjectable from "../extensions/extension-loader/extension-loader.injectable";
|
||||
@@ -80,28 +73,3 @@ export async function bootstrap(di: DiContainer) {
|
||||
rootElem,
|
||||
);
|
||||
}
|
||||
|
||||
const di = getDi();
|
||||
|
||||
// run
|
||||
bootstrap(di);
|
||||
|
||||
/**
|
||||
* Exports for virtual package "@k8slens/extensions" for renderer-process.
|
||||
* All exporting names available in global runtime scope:
|
||||
* e.g. Devtools -> Console -> window.LensExtensions (renderer)
|
||||
*/
|
||||
const LensExtensions = {
|
||||
Common: LensExtensionsCommonApi,
|
||||
Renderer: LensExtensionsRendererApi,
|
||||
};
|
||||
|
||||
export {
|
||||
React,
|
||||
ReactDOM,
|
||||
ReactRouter,
|
||||
ReactRouterDom,
|
||||
Mobx,
|
||||
MobxReact,
|
||||
LensExtensions,
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import "./components/app.scss";
|
||||
|
||||
import { bootstrap } from "./bootstrap";
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import nodeEnvInjectionToken from "../common/vars/node-env-injection-token";
|
||||
import { runInAction } from "mobx";
|
||||
import { registerInjectables } from "./register-injectables";
|
||||
|
||||
interface AppConfig {
|
||||
di: DiContainer;
|
||||
mode: string;
|
||||
}
|
||||
|
||||
export function createApp(conf: AppConfig) {
|
||||
const { di, mode } = conf;
|
||||
|
||||
runInAction(() => {
|
||||
di.register(getInjectable({
|
||||
id: "node-env",
|
||||
instantiate: () => mode,
|
||||
injectionToken: nodeEnvInjectionToken,
|
||||
}));
|
||||
registerInjectables(di);
|
||||
});
|
||||
|
||||
return {
|
||||
start: () => bootstrap(di),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import * as Mobx from "mobx";
|
||||
import * as MobxReact from "mobx-react";
|
||||
import * as ReactRouter from "react-router";
|
||||
import * as ReactRouterDom from "react-router-dom";
|
||||
import * as LensExtensionsCommonApi from "../extensions/common-api";
|
||||
import * as LensExtensionsRendererApi from "../extensions/renderer-api";
|
||||
|
||||
/**
|
||||
* Exports for virtual package "@k8slens/extensions" for renderer-process.
|
||||
* All exporting names available in global runtime scope:
|
||||
* e.g. Devtools -> Console -> window.LensExtensions (renderer)
|
||||
*/
|
||||
const LensExtensions = {
|
||||
Common: LensExtensionsCommonApi,
|
||||
Renderer: LensExtensionsRendererApi,
|
||||
};
|
||||
|
||||
export {
|
||||
React,
|
||||
ReactDOM,
|
||||
ReactRouter,
|
||||
ReactRouterDom,
|
||||
Mobx,
|
||||
MobxReact,
|
||||
LensExtensions,
|
||||
};
|
||||
+46
-35
@@ -9,51 +9,62 @@ import { MainLayout } from "../../components/layout/main-layout";
|
||||
import { Sidebar } from "../../components/layout/sidebar";
|
||||
import { Dock } from "../../components/dock";
|
||||
import styles from "./cluster-frame.module.css";
|
||||
import type { IComputedValue } from "mobx";
|
||||
import { computed } from "mobx";
|
||||
import currentRouteComponentInjectable from "../../routes/current-route-component.injectable";
|
||||
import { Redirect } from "react-router";
|
||||
import startUrlInjectable from "./start-url.injectable";
|
||||
import currentPathInjectable from "../../routes/current-path.injectable";
|
||||
import { observer } from "mobx-react";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
|
||||
interface Dependencies {
|
||||
currentRouteComponent: IComputedValue<React.ElementType<any> | undefined>;
|
||||
startUrl: IComputedValue<string>;
|
||||
currentPath: IComputedValue<string>;
|
||||
}
|
||||
|
||||
const NonInjectedClusterFrameLayout = observer((props: Dependencies) => {
|
||||
const Component = props.currentRouteComponent.get();
|
||||
const starting = props.startUrl.get();
|
||||
const current = props.currentPath.get();
|
||||
|
||||
return (
|
||||
<MainLayout sidebar={<Sidebar />} footer={<Dock />}>
|
||||
{Component ? (
|
||||
<Component />
|
||||
) : // NOTE: this check is to prevent an infinite loop
|
||||
starting !== current ? (
|
||||
<Redirect to={starting} />
|
||||
) : (
|
||||
<div className={styles.centering}>
|
||||
<div className="error">
|
||||
An error has occured. No route can be found matching the
|
||||
current route, which is also the starting route.
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</MainLayout>
|
||||
);
|
||||
});
|
||||
|
||||
const ClusterFrameLayout = withInjectables<Dependencies>(NonInjectedClusterFrameLayout, {
|
||||
getProps: (di, props) => ({
|
||||
...props,
|
||||
currentRouteComponent: di.inject(currentRouteComponentInjectable),
|
||||
startUrl: di.inject(startUrlInjectable),
|
||||
currentPath: di.inject(currentPathInjectable),
|
||||
}),
|
||||
});
|
||||
|
||||
const clusterFrameLayoutChildComponentInjectable = getInjectable({
|
||||
id: "cluster-frame-layout-child-component",
|
||||
|
||||
instantiate: (di) => {
|
||||
const currentRouteComponent = di.inject(currentRouteComponentInjectable);
|
||||
const startUrl = di.inject(startUrlInjectable);
|
||||
const currentPath = di.inject(currentPathInjectable);
|
||||
|
||||
return {
|
||||
id: "cluster-frame-layout",
|
||||
|
||||
shouldRender: computed(() => true),
|
||||
|
||||
Component: observer(() => {
|
||||
const Component = currentRouteComponent.get();
|
||||
const starting = startUrl.get();
|
||||
const current = currentPath.get();
|
||||
|
||||
return (
|
||||
<MainLayout sidebar={<Sidebar />} footer={<Dock />}>
|
||||
{Component ? (
|
||||
<Component />
|
||||
) : // NOTE: this check is to prevent an infinite loop
|
||||
starting !== current ? (
|
||||
<Redirect to={startUrl.get()} />
|
||||
) : (
|
||||
<div className={styles.centering}>
|
||||
<div className="error">
|
||||
An error has occured. No route can be found matching the
|
||||
current route, which is also the starting route.
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</MainLayout>
|
||||
);
|
||||
}),
|
||||
};
|
||||
},
|
||||
instantiate: () => ({
|
||||
id: "cluster-frame-layout",
|
||||
shouldRender: computed(() => true),
|
||||
Component: ClusterFrameLayout,
|
||||
}),
|
||||
|
||||
injectionToken: clusterFrameChildComponentInjectionToken,
|
||||
});
|
||||
|
||||
+2
-16
@@ -4,28 +4,14 @@
|
||||
*/
|
||||
|
||||
import { createContainer } from "@ogre-tools/injectable";
|
||||
import { autoRegister } from "@ogre-tools/injectable-extension-for-auto-registration";
|
||||
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
|
||||
import { runInAction } from "mobx";
|
||||
import { Environments, setLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import applicationInformationInjectable from "../common/vars/application-information-injectable";
|
||||
|
||||
export const getDi = () => {
|
||||
const di = createContainer("renderer");
|
||||
|
||||
setLegacyGlobalDiForExtensionApi(di, Environments.renderer);
|
||||
|
||||
runInAction(() => {
|
||||
registerMobX(di);
|
||||
|
||||
autoRegister({
|
||||
di,
|
||||
requireContexts: [
|
||||
require.context("./", true, CONTEXT_MATCHER_FOR_NON_FEATURES),
|
||||
require.context("../common", true, CONTEXT_MATCHER_FOR_NON_FEATURES),
|
||||
require.context("../extensions", true, CONTEXT_MATCHER_FOR_NON_FEATURES),
|
||||
require.context("../features", true, CONTEXT_MATCHER_FOR_FEATURES),
|
||||
],
|
||||
});
|
||||
di.register(applicationInformationInjectable);
|
||||
});
|
||||
|
||||
return di;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import { noop, chunk } from "lodash/fp";
|
||||
import type { DiContainer, Injectable } from "@ogre-tools/injectable";
|
||||
import { createContainer, isInjectable } from "@ogre-tools/injectable";
|
||||
import { createContainer, isInjectable, getInjectable } from "@ogre-tools/injectable";
|
||||
import { Environments, setLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import requestFromChannelInjectable from "./utils/channel/request-from-channel.injectable";
|
||||
import loggerInjectable from "../common/logger.injectable";
|
||||
@@ -41,6 +41,8 @@ import legacyOnChannelListenInjectable from "./ipc/legacy-channel-listen.injecta
|
||||
import storageSaveDelayInjectable from "./utils/create-storage/storage-save-delay.injectable";
|
||||
import environmentVariablesInjectable from "../common/utils/environment-variables.injectable";
|
||||
import type { GlobalOverride } from "../common/test-utils/get-global-override";
|
||||
import applicationInformationInjectable from "../common/vars/application-information-injectable";
|
||||
import nodeEnvInjectionToken from "../common/vars/node-env-injection-token";
|
||||
|
||||
export const getDiForUnitTesting = (
|
||||
opts: { doGeneralOverrides?: boolean } = {},
|
||||
@@ -49,6 +51,12 @@ export const getDiForUnitTesting = (
|
||||
|
||||
const di = createContainer("renderer");
|
||||
|
||||
di.register(getInjectable({
|
||||
id: "node-env",
|
||||
instantiate: () => "test",
|
||||
injectionToken: nodeEnvInjectionToken,
|
||||
}));
|
||||
|
||||
di.preventSideEffects();
|
||||
|
||||
setLegacyGlobalDiForExtensionApi(di, Environments.renderer);
|
||||
@@ -63,7 +71,8 @@ export const getDiForUnitTesting = (
|
||||
|
||||
runInAction(() => {
|
||||
registerMobX(di);
|
||||
|
||||
di.register(applicationInformationInjectable);
|
||||
|
||||
chunk(100)(injectables).forEach((chunkInjectables) => {
|
||||
di.register(...chunkInjectables);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import "./components/app.scss";
|
||||
|
||||
import { getDi } from "./getDi";
|
||||
import {
|
||||
React, ReactDOM, ReactRouter,
|
||||
ReactRouterDom, Mobx, MobxReact, LensExtensions,
|
||||
} from "./extension-api";
|
||||
import { createApp } from "./create-app";
|
||||
|
||||
const di = getDi();
|
||||
const app = createApp({
|
||||
di,
|
||||
mode: process.env.NODE_ENV || "development",
|
||||
});
|
||||
|
||||
// run
|
||||
app.start();
|
||||
|
||||
export {
|
||||
React,
|
||||
ReactDOM,
|
||||
ReactRouter,
|
||||
ReactRouterDom,
|
||||
Mobx,
|
||||
MobxReact,
|
||||
LensExtensions,
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import "./components/app.scss";
|
||||
|
||||
import * as extensionApi from "./extension-api";
|
||||
import { createApp } from "./create-app";
|
||||
|
||||
// @experimental
|
||||
export {
|
||||
createApp,
|
||||
extensionApi,
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import { autoRegister } from "@ogre-tools/injectable-extension-for-auto-registration";
|
||||
import { registerMobX } from "@ogre-tools/injectable-extension-for-mobx";
|
||||
import { runInAction } from "mobx";
|
||||
import { Environments, setLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
|
||||
export function registerInjectables(di: DiContainer) {
|
||||
setLegacyGlobalDiForExtensionApi(di, Environments.renderer);
|
||||
|
||||
runInAction(() => {
|
||||
registerMobX(di);
|
||||
|
||||
autoRegister({
|
||||
di,
|
||||
requireContexts: [
|
||||
require.context("./", true, CONTEXT_MATCHER_FOR_NON_FEATURES),
|
||||
require.context("../common", true, CONTEXT_MATCHER_FOR_NON_FEATURES),
|
||||
require.context("../extensions", true, CONTEXT_MATCHER_FOR_NON_FEATURES),
|
||||
require.context("../features", true, CONTEXT_MATCHER_FOR_FEATURES),
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
return di;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getGlobalOverride } from "../../common/test-utils/get-global-override";
|
||||
import applicationInformationInjectable from "../../common/vars/application-information-injectable";
|
||||
|
||||
export default getGlobalOverride(applicationInformationInjectable, () => ({
|
||||
name: "some-product-name",
|
||||
productName: "some-product-name",
|
||||
version: "6.0.0",
|
||||
build: {} as any,
|
||||
config: {
|
||||
k8sProxyVersion: "0.2.1",
|
||||
bundledKubectlVersion: "1.23.3",
|
||||
bundledHelmVersion: "3.7.2",
|
||||
sentryDsn: "",
|
||||
contentSecurityPolicy: "script-src 'unsafe-eval' 'self'; frame-src http://*.localhost:*/; img-src * data:",
|
||||
welcomeRoute: "/welcome",
|
||||
},
|
||||
copyright: "some-copyright-information",
|
||||
description: "some-descriptive-text",
|
||||
}));
|
||||
Reference in new issue
Block a user