mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Remove last vestiges of isTestEnv and the is* globals
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
120e8ba0c1
commit
84a9569412
@ -6,21 +6,6 @@
|
||||
// App's common configuration for any process (main, renderer, build pipeline, etc.)
|
||||
import type { ThemeId } from "../renderer/themes/lens-theme";
|
||||
|
||||
/**
|
||||
* @deprecated Switch to using isTestEnvInjectable
|
||||
*/
|
||||
export const isTestEnv = !!process.env.JEST_WORKER_ID;
|
||||
|
||||
/**
|
||||
* @deprecated Switch to using isProductionInjectable
|
||||
*/
|
||||
export const isProduction = process.env.NODE_ENV === "production";
|
||||
|
||||
/**
|
||||
* @deprecated Switch to using isDevelopmentInjectable
|
||||
*/
|
||||
export const isDevelopment = !isTestEnv && !isProduction;
|
||||
|
||||
export const publicPath = "/build/" as string;
|
||||
export const defaultThemeId: ThemeId = "lens-dark";
|
||||
export const defaultFontSize = 12;
|
||||
|
||||
@ -4,17 +4,10 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import isProductionInjectable from "./is-production.injectable";
|
||||
import isTestEnvInjectable from "./is-test-env.injectable";
|
||||
|
||||
const isDevelopmentInjectable = getInjectable({
|
||||
id: "is-development",
|
||||
|
||||
instantiate: (di) => {
|
||||
const isProduction = di.inject(isProductionInjectable);
|
||||
const isTestEnv = di.inject(isTestEnvInjectable);
|
||||
|
||||
return !isTestEnv && !isProduction;
|
||||
},
|
||||
instantiate: (di) => !di.inject(isProductionInjectable),
|
||||
});
|
||||
|
||||
export default isDevelopmentInjectable;
|
||||
|
||||
@ -1,18 +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 environmentVariablesInjectable from "../utils/environment-variables.injectable";
|
||||
|
||||
const isTestEnvInjectable = getInjectable({
|
||||
id: "is-test-env",
|
||||
|
||||
instantiate: (di) => {
|
||||
const { JEST_WORKER_ID: jestWorkerId } = di.inject(environmentVariablesInjectable);
|
||||
|
||||
return !!jestWorkerId;
|
||||
},
|
||||
});
|
||||
|
||||
export default isTestEnvInjectable;
|
||||
22
src/renderer/api/default-websocket-api-params.injectable.ts
Normal file
22
src/renderer/api/default-websocket-api-params.injectable.ts
Normal file
@ -0,0 +1,22 @@
|
||||
/**
|
||||
* 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 type { TerminalMessage } from "../../common/terminal/channels";
|
||||
import { TerminalChannels } from "../../common/terminal/channels";
|
||||
import isDevelopmentInjectable from "../../common/vars/is-development.injectable";
|
||||
|
||||
export type DefaultWebsocketApiParams = ReturnType<typeof defaultWebsocketApiParamsInjectable.instantiate>;
|
||||
|
||||
const defaultWebsocketApiParamsInjectable = getInjectable({
|
||||
id: "default-websocket-api-params",
|
||||
instantiate: (di) => ({
|
||||
logging: di.inject(isDevelopmentInjectable),
|
||||
reconnectDelay: 10,
|
||||
flushOnOpen: true,
|
||||
pingMessage: JSON.stringify({ type: TerminalChannels.PING } as TerminalMessage),
|
||||
}),
|
||||
});
|
||||
|
||||
export default defaultWebsocketApiParamsInjectable;
|
||||
@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { WebSocketEvents } from "./websocket-api";
|
||||
import type { WebSocketApiDependencies, WebSocketEvents } from "./websocket-api";
|
||||
import { WebSocketApi } from "./websocket-api";
|
||||
import isEqual from "lodash/isEqual";
|
||||
import url from "url";
|
||||
@ -36,7 +36,7 @@ export interface TerminalEvents extends WebSocketEvents {
|
||||
connected: () => void;
|
||||
}
|
||||
|
||||
export interface TerminalApiDependencies {
|
||||
export interface TerminalApiDependencies extends WebSocketApiDependencies {
|
||||
readonly hostedClusterId: string;
|
||||
readonly logger: Logger;
|
||||
}
|
||||
@ -47,7 +47,7 @@ export class TerminalApi extends WebSocketApi<TerminalEvents> {
|
||||
@observable public isReady = false;
|
||||
|
||||
constructor(protected readonly dependencies: TerminalApiDependencies, protected readonly query: TerminalApiQuery) {
|
||||
super({
|
||||
super(dependencies, {
|
||||
flushOnOpen: false,
|
||||
pingInterval: 30,
|
||||
});
|
||||
|
||||
@ -7,9 +7,8 @@ import { observable, makeObservable } from "mobx";
|
||||
import EventEmitter from "events";
|
||||
import type TypedEventEmitter from "typed-emitter";
|
||||
import type { Arguments } from "typed-emitter";
|
||||
import { isDevelopment } from "../../common/vars";
|
||||
import type { Defaulted } from "../utils";
|
||||
import { TerminalChannels, type TerminalMessage } from "../../common/terminal/channels";
|
||||
import type { DefaultWebsocketApiParams } from "./default-websocket-api-params.injectable";
|
||||
|
||||
interface WebsocketApiParams {
|
||||
/**
|
||||
@ -64,27 +63,24 @@ export interface WebSocketEvents {
|
||||
close: () => void;
|
||||
}
|
||||
|
||||
export interface WebSocketApiDependencies {
|
||||
readonly defaultParams: DefaultWebsocketApiParams;
|
||||
}
|
||||
|
||||
export class WebSocketApi<Events extends WebSocketEvents> extends (EventEmitter as { new<T>(): TypedEventEmitter<T> })<Events> {
|
||||
protected socket: WebSocket | null = null;
|
||||
protected pendingCommands: string[] = [];
|
||||
protected reconnectTimer?: number;
|
||||
protected pingTimer?: number;
|
||||
protected params: Defaulted<WebsocketApiParams, keyof typeof WebSocketApi["defaultParams"]>;
|
||||
protected params: Defaulted<WebsocketApiParams, keyof DefaultWebsocketApiParams>;
|
||||
|
||||
@observable readyState = WebSocketApiState.PENDING;
|
||||
|
||||
private static readonly defaultParams = {
|
||||
logging: isDevelopment,
|
||||
reconnectDelay: 10,
|
||||
flushOnOpen: true,
|
||||
pingMessage: JSON.stringify({ type: TerminalChannels.PING } as TerminalMessage),
|
||||
};
|
||||
|
||||
constructor(params: WebsocketApiParams) {
|
||||
constructor(protected readonly dependencies: WebSocketApiDependencies, params: WebsocketApiParams) {
|
||||
super();
|
||||
makeObservable(this);
|
||||
this.params = {
|
||||
...WebSocketApi.defaultParams,
|
||||
...this.dependencies.defaultParams,
|
||||
...params,
|
||||
};
|
||||
const { pingInterval } = this.params;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user