mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Clean up versioning and packageJson uses (#6196)
This commit is contained in:
1 parent
cfe35ded90
commit
67ac1692b2
116 files changed
+1154
-644
No files matched your search
@@ -18,13 +18,13 @@ import { createClusterInjectionToken } from "../cluster/create-cluster-injection
|
||||
import directoryForUserDataInjectable from "../app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
import { getDiForUnitTesting } from "../../main/getDiForUnitTesting";
|
||||
import getConfigurationFileModelInjectable from "../get-configuration-file-model/get-configuration-file-model.injectable";
|
||||
import appVersionInjectable from "../vars/app-version.injectable";
|
||||
import assert from "assert";
|
||||
import directoryForTempInjectable from "../app-paths/directory-for-temp/directory-for-temp.injectable";
|
||||
import kubectlBinaryNameInjectable from "../../main/kubectl/binary-name.injectable";
|
||||
import kubectlDownloadingNormalizedArchInjectable from "../../main/kubectl/normalized-arch.injectable";
|
||||
import normalizedPlatformInjectable from "../vars/normalized-platform.injectable";
|
||||
import fsInjectable from "../fs/fs.injectable";
|
||||
import storeMigrationVersionInjectable from "../vars/store-migration-version.injectable";
|
||||
|
||||
console = new Console(stdout, stderr);
|
||||
|
||||
@@ -372,7 +372,7 @@ users:
|
||||
|
||||
mockFs(mockOpts);
|
||||
|
||||
mainDi.override(appVersionInjectable, () => "3.6.0");
|
||||
mainDi.override(storeMigrationVersionInjectable, () => "3.6.0");
|
||||
|
||||
createCluster = mainDi.inject(createClusterInjectionToken);
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import mockFs from "mock-fs";
|
||||
import type { CatalogEntity, CatalogEntityData, CatalogEntityKindData } from "../catalog";
|
||||
import { getDiForUnitTesting } from "../../main/getDiForUnitTesting";
|
||||
import getConfigurationFileModelInjectable from "../get-configuration-file-model/get-configuration-file-model.injectable";
|
||||
import appVersionInjectable from "../vars/app-version.injectable";
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import hotbarStoreInjectable from "../hotbars/store.injectable";
|
||||
import type { HotbarStore } from "../hotbars/store";
|
||||
@@ -19,6 +18,7 @@ import catalogCatalogEntityInjectable from "../catalog-entities/general-catalog-
|
||||
import loggerInjectable from "../logger.injectable";
|
||||
import type { Logger } from "../logger";
|
||||
import directoryForUserDataInjectable from "../app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
import storeMigrationVersionInjectable from "../vars/store-migration-version.injectable";
|
||||
|
||||
function getMockCatalogEntity(data: Partial<CatalogEntityData> & CatalogEntityKindData): CatalogEntity {
|
||||
return {
|
||||
@@ -348,7 +348,7 @@ describe("HotbarStore", () => {
|
||||
|
||||
mockFs(configurationToBeMigrated);
|
||||
|
||||
di.override(appVersionInjectable, () => "5.0.0-beta.10");
|
||||
di.override(storeMigrationVersionInjectable, () => "5.0.0-beta.10");
|
||||
|
||||
hotbarStore = di.inject(hotbarStoreInjectable);
|
||||
|
||||
|
||||
@@ -23,8 +23,6 @@ jest.mock("electron", () => ({
|
||||
|
||||
import type { UserStore } from "../user-store";
|
||||
import { Console } from "console";
|
||||
import { SemVer } from "semver";
|
||||
import electron from "electron";
|
||||
import { stdout, stderr } from "process";
|
||||
import userStoreInjectable from "../user-store/user-store.injectable";
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
@@ -34,7 +32,7 @@ import { defaultThemeId } from "../vars";
|
||||
import writeFileInjectable from "../fs/write-file.injectable";
|
||||
import { getDiForUnitTesting } from "../../main/getDiForUnitTesting";
|
||||
import getConfigurationFileModelInjectable from "../get-configuration-file-model/get-configuration-file-model.injectable";
|
||||
import appVersionInjectable from "../vars/app-version.injectable";
|
||||
import storeMigrationVersionInjectable from "../vars/store-migration-version.injectable";
|
||||
|
||||
console = new Console(stdout, stderr);
|
||||
|
||||
@@ -86,13 +84,6 @@ describe("user store tests", () => {
|
||||
userStore.resetTheme();
|
||||
expect(userStore.colorTheme).toBe(defaultThemeId);
|
||||
});
|
||||
|
||||
it("correctly calculates if the last seen version is an old release", () => {
|
||||
expect(userStore.isNewVersion).toBe(true);
|
||||
|
||||
userStore.lastSeenAppVersion = (new SemVer(electron.app.getVersion())).inc("major").format();
|
||||
expect(userStore.isNewVersion).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("migrations", () => {
|
||||
@@ -125,7 +116,7 @@ describe("user store tests", () => {
|
||||
},
|
||||
});
|
||||
|
||||
di.override(appVersionInjectable, () => "10.0.0");
|
||||
di.override(storeMigrationVersionInjectable, () => "10.0.0");
|
||||
|
||||
userStore = di.inject(userStoreInjectable);
|
||||
});
|
||||
|
||||
@@ -7,7 +7,6 @@ import { appPathsInjectionToken } from "./app-path-injection-token";
|
||||
import getElectronAppPathInjectable from "../../main/app-paths/get-electron-app-path/get-electron-app-path.injectable";
|
||||
import type { PathName } from "./app-path-names";
|
||||
import setElectronAppPathInjectable from "../../main/app-paths/set-electron-app-path/set-electron-app-path.injectable";
|
||||
import appNameInjectable from "../../main/app-paths/app-name/app-name.injectable";
|
||||
import directoryForIntegrationTestingInjectable from "../../main/app-paths/directory-for-integration-testing/directory-for-integration-testing.injectable";
|
||||
import type { ApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
|
||||
import { getApplicationBuilder } from "../../renderer/components/test-utils/get-application-builder";
|
||||
@@ -53,8 +52,6 @@ describe("app-paths", () => {
|
||||
defaultAppPathsStub[key] = path;
|
||||
},
|
||||
);
|
||||
|
||||
mainDi.override(appNameInjectable, () => "some-app-name");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -88,7 +85,7 @@ describe("app-paths", () => {
|
||||
recent: "some-recent",
|
||||
temp: "some-temp",
|
||||
videos: "some-videos",
|
||||
userData: "some-app-data/some-app-name",
|
||||
userData: "some-app-data/some-product-name",
|
||||
});
|
||||
});
|
||||
|
||||
@@ -111,7 +108,7 @@ describe("app-paths", () => {
|
||||
recent: "some-recent",
|
||||
temp: "some-temp",
|
||||
videos: "some-videos",
|
||||
userData: "some-app-data/some-app-name",
|
||||
userData: "some-app-data/some-product-name",
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -137,7 +134,7 @@ describe("app-paths", () => {
|
||||
|
||||
expect({ appData, userData }).toEqual({
|
||||
appData: "some-integration-testing-app-data",
|
||||
userData: `some-integration-testing-app-data/some-app-name`,
|
||||
userData: `some-integration-testing-app-data/some-product-name`,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -146,7 +143,7 @@ describe("app-paths", () => {
|
||||
|
||||
expect({ appData, userData }).toEqual({
|
||||
appData: "some-integration-testing-app-data",
|
||||
userData: "some-integration-testing-app-data/some-app-name",
|
||||
userData: "some-integration-testing-app-data/some-product-name",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+3
-3
@@ -2,13 +2,13 @@
|
||||
* 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 { createInitializableState } from "../../initializable-state/create";
|
||||
import releaseChannelInjectable from "../../vars/release-channel.injectable";
|
||||
import { updateChannels } from "../update-channels";
|
||||
|
||||
const defaultUpdateChannelInjectable = getInjectable({
|
||||
const defaultUpdateChannelInjectable = createInitializableState({
|
||||
id: "default-update-channel",
|
||||
instantiate: (di) => updateChannels[di.inject(releaseChannelInjectable)],
|
||||
init: (di) => updateChannels[di.inject(releaseChannelInjectable)],
|
||||
});
|
||||
|
||||
export default defaultUpdateChannelInjectable;
|
||||
+5
-5
@@ -5,13 +5,13 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { IComputedValue } from "mobx";
|
||||
import { action, computed, observable } from "mobx";
|
||||
import type { UpdateChannel, UpdateChannelId } from "../update-channels";
|
||||
import type { UpdateChannel, ReleaseChannel } from "../update-channels";
|
||||
import { updateChannels } from "../update-channels";
|
||||
import defaultUpdateChannelInjectable from "./default-update-channel.injectable";
|
||||
|
||||
export interface SelectedUpdateChannel {
|
||||
value: IComputedValue<UpdateChannel>;
|
||||
setValue: (channelId?: UpdateChannelId) => void;
|
||||
setValue: (channelId?: ReleaseChannel) => void;
|
||||
}
|
||||
|
||||
const selectedUpdateChannelInjectable = getInjectable({
|
||||
@@ -19,16 +19,16 @@ const selectedUpdateChannelInjectable = getInjectable({
|
||||
|
||||
instantiate: (di): SelectedUpdateChannel => {
|
||||
const defaultUpdateChannel = di.inject(defaultUpdateChannelInjectable);
|
||||
const state = observable.box(defaultUpdateChannel);
|
||||
const state = observable.box<UpdateChannel>();
|
||||
|
||||
return {
|
||||
value: computed(() => state.get()),
|
||||
value: computed(() => state.get() ?? defaultUpdateChannel.get()),
|
||||
|
||||
setValue: action((channelId) => {
|
||||
const targetUpdateChannel =
|
||||
channelId && updateChannels[channelId]
|
||||
? updateChannels[channelId]
|
||||
: defaultUpdateChannel;
|
||||
: defaultUpdateChannel.get();
|
||||
|
||||
state.set(targetUpdateChannel);
|
||||
}),
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
|
||||
export type UpdateChannelId = "alpha" | "beta" | "latest";
|
||||
export type ReleaseChannel = "alpha" | "beta" | "latest";
|
||||
|
||||
const latestChannel: UpdateChannel = {
|
||||
id: "latest",
|
||||
@@ -31,7 +31,7 @@ export const updateChannels = {
|
||||
};
|
||||
|
||||
export interface UpdateChannel {
|
||||
readonly id: UpdateChannelId;
|
||||
readonly id: ReleaseChannel;
|
||||
readonly label: string;
|
||||
readonly moreStableUpdateChannel: UpdateChannel | null;
|
||||
}
|
||||
@@ -19,7 +19,7 @@ import { kebabCase } from "lodash";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import directoryForUserDataInjectable from "./app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
import getConfigurationFileModelInjectable from "./get-configuration-file-model/get-configuration-file-model.injectable";
|
||||
import appVersionInjectable from "./vars/app-version.injectable";
|
||||
import storeMigrationVersionInjectable from "./vars/store-migration-version.injectable";
|
||||
|
||||
export interface BaseStoreParams<T> extends ConfOptions<T> {
|
||||
syncOptions?: {
|
||||
@@ -60,7 +60,7 @@ export abstract class BaseStore<T extends object> extends Singleton {
|
||||
|
||||
this.storeConfig = getConfigurationFileModel({
|
||||
projectName: "lens",
|
||||
projectVersion: di.inject(appVersionInjectable),
|
||||
projectVersion: di.inject(storeMigrationVersionInjectable),
|
||||
cwd: this.cwd(),
|
||||
...this.params,
|
||||
});
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import type { CatalogEntityContextMenuContext, CatalogEntityMetadata, CatalogEntityStatus } from "../catalog";
|
||||
import { CatalogCategory, CatalogEntity, categoryVersion } from "../catalog/catalog-entity";
|
||||
import { productName } from "../vars";
|
||||
import productNameInjectable from "../vars/product-name.injectable";
|
||||
import { WeblinkStore } from "../weblink-store";
|
||||
|
||||
export type WebLinkStatusPhase = "available" | "unavailable";
|
||||
@@ -30,6 +31,9 @@ export class WebLink extends CatalogEntity<CatalogEntityMetadata, WebLinkStatus,
|
||||
}
|
||||
|
||||
onContextMenuOpen(context: CatalogEntityContextMenuContext) {
|
||||
const di = getLegacyGlobalDiForExtensionApi();
|
||||
const productName = di.inject(productNameInjectable);
|
||||
|
||||
if (this.metadata.source === "local") {
|
||||
context.menuItems.push({
|
||||
title: "Delete",
|
||||
|
||||
+9
@@ -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 "../test-utils/get-global-override";
|
||||
import initializeSentryReportingWithInjectable from "./initialize-sentry-reporting.injectable";
|
||||
|
||||
export default getGlobalOverride(initializeSentryReportingWithInjectable, () => () => {});
|
||||
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* 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 { ElectronMainOptions } from "@sentry/electron/main";
|
||||
import type { BrowserOptions } from "@sentry/electron/renderer";
|
||||
import isProductionInjectable from "../vars/is-production.injectable";
|
||||
import sentryDataSourceNameInjectable from "../vars/sentry-dsn-url.injectable";
|
||||
import { Dedupe, Offline } from "@sentry/integrations";
|
||||
import { inspect } from "util";
|
||||
import userStoreInjectable from "../user-store/user-store.injectable";
|
||||
|
||||
export type InitializeSentryReportingWith = (initSentry: (opts: BrowserOptions | ElectronMainOptions) => void) => void;
|
||||
|
||||
const mapProcessName = (type: "browser" | "renderer" | "worker") => type === "browser" ? "main" : type;
|
||||
|
||||
const initializeSentryReportingWithInjectable = getInjectable({
|
||||
id: "initialize-sentry-reporting-with",
|
||||
instantiate: (di): InitializeSentryReportingWith => {
|
||||
const sentryDataSourceName = di.inject(sentryDataSourceNameInjectable);
|
||||
const isProduction = di.inject(isProductionInjectable);
|
||||
|
||||
if (!sentryDataSourceName) {
|
||||
return () => {};
|
||||
}
|
||||
|
||||
return (initSentry) => initSentry({
|
||||
beforeSend: (event) => {
|
||||
// TODO: remove loading from userStoreInjectable so that this can be moved out
|
||||
const userStore = di.inject(userStoreInjectable);
|
||||
|
||||
if (userStore.allowErrorReporting) {
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Directly write to stdout so that no other integrations capture this and create an infinite loop
|
||||
*/
|
||||
process.stdout.write(`🔒 [SENTRY-BEFORE-SEND-HOOK]: Sentry event is caught but not sent to server.`);
|
||||
process.stdout.write("🔒 [SENTRY-BEFORE-SEND-HOOK]: === START OF SENTRY EVENT ===");
|
||||
process.stdout.write(inspect(event, false, null, true));
|
||||
process.stdout.write("🔒 [SENTRY-BEFORE-SEND-HOOK]: === END OF SENTRY EVENT ===");
|
||||
|
||||
// if return null, the event won't be sent
|
||||
// ref https://github.com/getsentry/sentry-javascript/issues/2039
|
||||
return null;
|
||||
},
|
||||
dsn: sentryDataSourceName,
|
||||
integrations: [
|
||||
new Dedupe(),
|
||||
new Offline(),
|
||||
],
|
||||
initialScope: {
|
||||
tags: {
|
||||
"process": mapProcessName(process.type),
|
||||
},
|
||||
},
|
||||
environment: isProduction ? "production" : "development",
|
||||
});
|
||||
},
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default initializeSentryReportingWithInjectable;
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getGlobalOverride } from "../../../test-utils/get-global-override";
|
||||
import welcomeRouteConfig from "./welcome-route-config.injectable";
|
||||
|
||||
export default getGlobalOverride(welcomeRouteConfig, () => "/welcome");
|
||||
@@ -3,16 +3,12 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import packageJsonInjectable from "../../../vars/package-json.injectable";
|
||||
import applicationInformationInjectable from "../../../vars/application-information.injectable";
|
||||
|
||||
const welcomeRouteConfigInjectable = getInjectable({
|
||||
id: "welcome-route-config",
|
||||
|
||||
instantiate: (di) => {
|
||||
const packageJson = di.inject(packageJsonInjectable);
|
||||
|
||||
return packageJson.config.welcomeRoute;
|
||||
},
|
||||
instantiate: (di) => di.inject(applicationInformationInjectable).config.welcomeRoute,
|
||||
});
|
||||
|
||||
export default welcomeRouteConfigInjectable;
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { AsyncFnMock } from "@async-fn/jest";
|
||||
import asyncFn from "@async-fn/jest";
|
||||
import type { DiContainer, Injectable } from "@ogre-tools/injectable";
|
||||
import { runInAction } from "mobx";
|
||||
import { getDiForUnitTesting } from "../../main/getDiForUnitTesting";
|
||||
import type { InitializableState } from "./create";
|
||||
import { createInitializableState } from "./create";
|
||||
|
||||
describe("InitializableState tests", () => {
|
||||
let di: DiContainer;
|
||||
|
||||
beforeEach(() => {
|
||||
di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
});
|
||||
|
||||
describe("when created", () => {
|
||||
let stateInjectable: Injectable<InitializableState<number>, unknown, void>;
|
||||
let initMock: AsyncFnMock<() => number>;
|
||||
|
||||
beforeEach(() => {
|
||||
initMock = asyncFn();
|
||||
stateInjectable = createInitializableState({
|
||||
id: "my-state",
|
||||
init: initMock,
|
||||
});
|
||||
|
||||
runInAction(() => {
|
||||
di.register(stateInjectable);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when injected", () => {
|
||||
let state: InitializableState<number>;
|
||||
|
||||
beforeEach(() => {
|
||||
state = di.inject(stateInjectable);
|
||||
});
|
||||
|
||||
it("when get is called, throw", () => {
|
||||
expect(() => state.get()).toThrowError("InitializableState(my-state) has not been initialized yet");
|
||||
});
|
||||
|
||||
describe("when init is called", () => {
|
||||
beforeEach(() => {
|
||||
state.init();
|
||||
});
|
||||
|
||||
it("should call provided initialization function", () => {
|
||||
expect(initMock).toBeCalled();
|
||||
});
|
||||
|
||||
it("when get is called, throw", () => {
|
||||
expect(() => state.get()).toThrowError("InitializableState(my-state) has not finished initializing");
|
||||
});
|
||||
|
||||
describe("when initialization resolves", () => {
|
||||
beforeEach(async () => {
|
||||
await initMock.resolve(42);
|
||||
});
|
||||
|
||||
it("when get is called, returns value", () => {
|
||||
expect(state.get()).toBe(42);
|
||||
});
|
||||
|
||||
it("when init is called again, throws", async () => {
|
||||
await expect(() => state.init()).rejects.toThrow("Cannot initialize InitializableState(my-state) more than once");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { DiContainerForInjection, Injectable, InjectionToken } from "@ogre-tools/injectable";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
|
||||
export interface CreateInitializableStateArgs<T> {
|
||||
id: string;
|
||||
init: (di: DiContainerForInjection) => Promise<T> | T;
|
||||
injectionToken?: InjectionToken<InitializableState<T>, void>;
|
||||
}
|
||||
|
||||
export interface InitializableState<T> {
|
||||
get: () => T;
|
||||
init: () => Promise<void>;
|
||||
}
|
||||
|
||||
type InitializableStateValue<T> =
|
||||
| { set: false }
|
||||
| { set: true; value: T } ;
|
||||
|
||||
export function createInitializableState<T>(args: CreateInitializableStateArgs<T>): Injectable<InitializableState<T>, unknown, void> {
|
||||
const { id, init, injectionToken } = args;
|
||||
|
||||
return getInjectable({
|
||||
id,
|
||||
instantiate: (di) => {
|
||||
let box: InitializableStateValue<T> = {
|
||||
set: false,
|
||||
};
|
||||
let initCalled = false;
|
||||
|
||||
return {
|
||||
init: async () => {
|
||||
if (initCalled) {
|
||||
throw new Error(`Cannot initialize InitializableState(${id}) more than once`);
|
||||
}
|
||||
|
||||
initCalled = true;
|
||||
box = {
|
||||
set: true,
|
||||
value: await init(di),
|
||||
};
|
||||
},
|
||||
get: () => {
|
||||
if (!initCalled) {
|
||||
throw new Error(`InitializableState(${id}) has not been initialized yet`);
|
||||
}
|
||||
|
||||
if (box.set === false) {
|
||||
throw new Error(`InitializableState(${id}) has not finished initializing`);
|
||||
}
|
||||
|
||||
return box.value;
|
||||
},
|
||||
};
|
||||
},
|
||||
injectionToken,
|
||||
});
|
||||
}
|
||||
@@ -11,8 +11,9 @@ import logger from "../../main/logger";
|
||||
import { app } from "electron";
|
||||
import { ClusterStore } from "../cluster-store/cluster-store";
|
||||
import yaml from "js-yaml";
|
||||
import { productName } from "../vars";
|
||||
import { requestKubectlApplyAll, requestKubectlDeleteAll } from "../../renderer/ipc";
|
||||
import { getLegacyGlobalDiForExtensionApi } from "../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import productNameInjectable from "../vars/product-name.injectable";
|
||||
|
||||
export class ResourceStack {
|
||||
constructor(protected cluster: KubernetesCluster, protected name: string) {}
|
||||
@@ -97,6 +98,8 @@ export class ResourceStack {
|
||||
|
||||
protected async renderTemplates(folderPath: string, templateContext: any): Promise<string[]> {
|
||||
const resources: string[] = [];
|
||||
const di = getLegacyGlobalDiForExtensionApi();
|
||||
const productName = di.inject(productNameInjectable);
|
||||
|
||||
logger.info(`[RESOURCE-STACK]: render templates from ${folderPath}`);
|
||||
const files = await fse.readdir(folderPath);
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { Dedupe, Offline } from "@sentry/integrations";
|
||||
import { sentryDsn, isProduction } from "./vars";
|
||||
import { UserStore } from "./user-store";
|
||||
import { inspect } from "util";
|
||||
import type { BrowserOptions } from "@sentry/electron/renderer";
|
||||
import type { ElectronMainOptions } from "@sentry/electron/main";
|
||||
|
||||
/**
|
||||
* "Translate" 'browser' to 'main' as Lens developer more familiar with the term 'main'
|
||||
*/
|
||||
function mapProcessName(processType: string) {
|
||||
if (processType === "browser") {
|
||||
return "main";
|
||||
}
|
||||
|
||||
return processType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize Sentry for the current process so to send errors for debugging.
|
||||
*/
|
||||
export function initializeSentryReporting(init: (opts: BrowserOptions | ElectronMainOptions) => void) {
|
||||
const processName = mapProcessName(process.type);
|
||||
|
||||
if (!sentryDsn) {
|
||||
return; // do nothing if not configured to avoid uncaught error in dev mode
|
||||
}
|
||||
|
||||
init({
|
||||
beforeSend: (event) => {
|
||||
// default to false, in case instance of UserStore is not created (yet)
|
||||
const allowErrorReporting = UserStore.getInstance(false)?.allowErrorReporting ?? false;
|
||||
|
||||
if (allowErrorReporting) {
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Directly write to stdout so that no other integrations capture this and create an infinite loop
|
||||
*/
|
||||
process.stdout.write(`🔒 [SENTRY-BEFORE-SEND-HOOK]: allowErrorReporting: ${allowErrorReporting}. Sentry event is caught but not sent to server.`);
|
||||
process.stdout.write("🔒 [SENTRY-BEFORE-SEND-HOOK]: === START OF SENTRY EVENT ===");
|
||||
process.stdout.write(inspect(event, false, null, true));
|
||||
process.stdout.write("🔒 [SENTRY-BEFORE-SEND-HOOK]: === END OF SENTRY EVENT ===");
|
||||
|
||||
// if return null, the event won't be sent
|
||||
// ref https://github.com/getsentry/sentry-javascript/issues/2039
|
||||
return null;
|
||||
},
|
||||
dsn: sentryDsn,
|
||||
integrations: [
|
||||
new Dedupe(),
|
||||
new Offline(),
|
||||
],
|
||||
initialScope: {
|
||||
tags: {
|
||||
"process": processName,
|
||||
},
|
||||
},
|
||||
environment: isProduction ? "production" : "development",
|
||||
});
|
||||
}
|
||||
@@ -4,19 +4,16 @@
|
||||
*/
|
||||
|
||||
import { app } from "electron";
|
||||
import semver from "semver";
|
||||
import { action, computed, observable, reaction, makeObservable, isObservableArray, isObservableSet, isObservableMap } from "mobx";
|
||||
import { BaseStore } from "../base-store";
|
||||
import migrations from "../../migrations/user-store";
|
||||
import { getAppVersion } from "../utils/app-version";
|
||||
import { kubeConfigDefaultPath } from "../kube-helpers";
|
||||
import { appEventBus } from "../app-event-bus/event-bus";
|
||||
import { getOrInsertSet, toggle, toJS, object } from "../../renderer/utils";
|
||||
import { DESCRIPTORS } from "./preferences-helpers";
|
||||
import type { UserPreferencesModel, StoreType } from "./preferences-helpers";
|
||||
import logger from "../../main/logger";
|
||||
import type { SelectedUpdateChannel } from "../application-update/selected-update-channel/selected-update-channel.injectable";
|
||||
import type { UpdateChannelId } from "../application-update/update-channels";
|
||||
import type { ReleaseChannel } from "../application-update/update-channels";
|
||||
|
||||
export interface UserStoreModel {
|
||||
lastSeenAppVersion: string;
|
||||
@@ -24,7 +21,7 @@ export interface UserStoreModel {
|
||||
}
|
||||
|
||||
interface Dependencies {
|
||||
selectedUpdateChannel: SelectedUpdateChannel;
|
||||
readonly selectedUpdateChannel: SelectedUpdateChannel;
|
||||
}
|
||||
|
||||
export class UserStore extends BaseStore<UserStoreModel> /* implements UserStoreFlatModel (when strict null is enabled) */ {
|
||||
@@ -98,10 +95,6 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
|
||||
*/
|
||||
@observable syncKubeconfigEntries!: StoreType<typeof DESCRIPTORS["syncKubeconfigEntries"]>;
|
||||
|
||||
@computed get isNewVersion() {
|
||||
return semver.gt(getAppVersion(), this.lastSeenAppVersion);
|
||||
}
|
||||
|
||||
@computed get resolvedShell(): string | undefined {
|
||||
return this.shell || process.env.SHELL || process.env.PTYSHELL;
|
||||
}
|
||||
@@ -151,12 +144,6 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
|
||||
this.colorTheme = DESCRIPTORS.colorTheme.fromStore(undefined);
|
||||
}
|
||||
|
||||
@action
|
||||
saveLastSeenAppVersion() {
|
||||
appEventBus.emit({ name: "app", action: "whats-new-seen" });
|
||||
this.lastSeenAppVersion = getAppVersion();
|
||||
}
|
||||
|
||||
@action
|
||||
protected fromStore({ lastSeenAppVersion, preferences }: Partial<UserStoreModel> = {}) {
|
||||
logger.debug("UserStore.fromStore()", { lastSeenAppVersion, preferences });
|
||||
@@ -180,7 +167,7 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
|
||||
|
||||
// TODO: Switch to action-based saving instead saving stores by reaction
|
||||
if (preferences?.updateChannel) {
|
||||
this.dependencies.selectedUpdateChannel.setValue(preferences?.updateChannel as UpdateChannelId);
|
||||
this.dependencies.selectedUpdateChannel.setValue(preferences?.updateChannel as ReleaseChannel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,15 +4,6 @@
|
||||
*/
|
||||
|
||||
import requestPromise from "request-promise-native";
|
||||
import packageInfo from "../../../package.json";
|
||||
|
||||
export function getAppVersion(): string {
|
||||
return packageInfo.version;
|
||||
}
|
||||
|
||||
export function getBundledKubectlVersion(): string {
|
||||
return packageInfo.config.bundledKubectlVersion;
|
||||
}
|
||||
|
||||
export async function getAppVersionFromProxyServer(proxyPort: number): Promise<string> {
|
||||
const response = await requestPromise({
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
// App's common configuration for any process (main, renderer, build pipeline, etc.)
|
||||
import path from "path";
|
||||
import packageInfo from "../../package.json";
|
||||
import type { ThemeId } from "../renderer/themes/store";
|
||||
import { lazyInitialized } from "./utils/lazy-initialized";
|
||||
|
||||
@@ -25,7 +24,6 @@ export const isWindows = process.platform === "win32";
|
||||
export const isLinux = process.platform === "linux";
|
||||
|
||||
export const isDebugging = ["true", "1", "yes", "y", "on"].includes((process.env.DEBUG ?? "").toLowerCase());
|
||||
export const isSnap = !!process.env.SNAP;
|
||||
|
||||
/**
|
||||
* @deprecated Switch to using isTestEnvInjectable
|
||||
@@ -42,13 +40,6 @@ export const isProduction = process.env.NODE_ENV === "production";
|
||||
*/
|
||||
export const isDevelopment = !isTestEnv && !isProduction;
|
||||
|
||||
export const productName = packageInfo.productName;
|
||||
|
||||
/**
|
||||
* @deprecated Switch to using appNameInjectable
|
||||
*/
|
||||
export const appName = `${packageInfo.productName}${isDevelopment ? "Dev" : ""}`;
|
||||
|
||||
export const publicPath = "/build/" as string;
|
||||
export const defaultThemeId: ThemeId = "lens-dark";
|
||||
export const defaultFontSize = 12;
|
||||
@@ -139,6 +130,3 @@ export const lensBlogWeblinkId = "lens-blog-link";
|
||||
export const kubernetesDocumentationWeblinkId = "kubernetes-documentation-link";
|
||||
|
||||
export const docsUrl = "https://docs.k8slens.dev/main" as string;
|
||||
|
||||
export const sentryDsn = packageInfo.config?.sentryDsn ?? "";
|
||||
export const contentSecurityPolicy = packageInfo.config?.contentSecurityPolicy ?? "";
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* 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 isDevelopmentInjectable from "./is-development.injectable";
|
||||
import productNameInjectable from "./product-name.injectable";
|
||||
|
||||
const appNameInjectable = getInjectable({
|
||||
id: "app-name",
|
||||
|
||||
instantiate: (di) => {
|
||||
const isDevelopment = di.inject(isDevelopmentInjectable);
|
||||
const productName = di.inject(productNameInjectable);
|
||||
|
||||
return `${productName}${isDevelopment ? "Dev" : ""}`;
|
||||
},
|
||||
});
|
||||
|
||||
export default appNameInjectable;
|
||||
@@ -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 { SemVer } from "semver";
|
||||
import appVersionInjectable from "./app-version.injectable";
|
||||
|
||||
const appSemanticVersionInjectable = getInjectable({
|
||||
id: "app-semantic-version",
|
||||
instantiate: (di) => new SemVer(di.inject(appVersionInjectable)),
|
||||
});
|
||||
|
||||
export default appSemanticVersionInjectable;
|
||||
@@ -1,13 +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 packageJsonInjectable from "./package-json.injectable";
|
||||
|
||||
const appVersionInjectable = getInjectable({
|
||||
id: "app-version",
|
||||
instantiate: (di) => di.inject(packageJsonInjectable).version,
|
||||
});
|
||||
|
||||
export default appVersionInjectable;
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* 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 applicationInformationInjectable from "./application-information.injectable";
|
||||
|
||||
const applicationCopyrightInjectable = getInjectable({
|
||||
id: "application-copyright",
|
||||
instantiate: (di) => di.inject(applicationInformationInjectable).copyright,
|
||||
});
|
||||
|
||||
export default applicationCopyrightInjectable;
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* 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 applicationInformationInjectable from "./application-information.injectable";
|
||||
|
||||
const applicationDescriptionInjectable = getInjectable({
|
||||
id: "application-description",
|
||||
instantiate: (di) => di.inject(applicationInformationInjectable).description,
|
||||
});
|
||||
|
||||
export default applicationDescriptionInjectable;
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* 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";
|
||||
|
||||
export default getGlobalOverride(applicationInformationInjectable, () => ({
|
||||
productName: "some-product-name",
|
||||
version: "6.0.0",
|
||||
build: {},
|
||||
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",
|
||||
}));
|
||||
@@ -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 packageJson from "../../../package.json";
|
||||
|
||||
export type ApplicationInformation = Pick<typeof packageJson, "version" | "config" | "productName" | "copyright" | "description"> & {
|
||||
build: Partial<typeof packageJson["build"]>;
|
||||
};
|
||||
|
||||
const applicationInformationInjectable = getInjectable({
|
||||
id: "application-information",
|
||||
instantiate: (): ApplicationInformation => {
|
||||
const { version, config, productName, build, copyright, description } = packageJson;
|
||||
|
||||
return { version, config, productName, build, copyright, description };
|
||||
},
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default applicationInformationInjectable;
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* 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 { SemVer } from "semver";
|
||||
import type { InitializableState } from "../initializable-state/create";
|
||||
import { createInitializableState } from "../initializable-state/create";
|
||||
import type { RequestChannel } from "../utils/channel/request-channel-injection-token";
|
||||
|
||||
export const buildVersionInjectionToken = getInjectionToken<InitializableState<string>>({
|
||||
id: "build-version-token",
|
||||
});
|
||||
|
||||
export const buildVersionChannel: RequestChannel<void, string> = {
|
||||
id: "build-version",
|
||||
};
|
||||
|
||||
const buildSemanticVersionInjectable = createInitializableState({
|
||||
id: "build-semantic-version",
|
||||
init: (di) => {
|
||||
const buildVersion = di.inject(buildVersionInjectionToken);
|
||||
|
||||
return new SemVer(buildVersion.get());
|
||||
},
|
||||
});
|
||||
|
||||
export default buildSemanticVersionInjectable;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* 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 applicationInformationInjectable from "./application-information.injectable";
|
||||
|
||||
const bundledKubectlVersionInjectable = getInjectable({
|
||||
id: "bundled-kubectl-version",
|
||||
instantiate: (di) => di.inject(applicationInformationInjectable).config.bundledKubectlVersion,
|
||||
});
|
||||
|
||||
export default bundledKubectlVersionInjectable;
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* 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 applicationInformationInjectable from "./application-information.injectable";
|
||||
|
||||
const contentSecurityPolicyInjectable = getInjectable({
|
||||
id: "content-security-policy",
|
||||
instantiate: (di) => di.inject(applicationInformationInjectable).config.contentSecurityPolicy,
|
||||
});
|
||||
|
||||
export default contentSecurityPolicyInjectable;
|
||||
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* 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 { SemVer } from "semver";
|
||||
import applicationInformationInjectable from "./application-information.injectable";
|
||||
|
||||
const extensionApiVersionInjectable = getInjectable({
|
||||
id: "extension-api-version",
|
||||
instantiate: (di) => {
|
||||
const { major, minor, patch } = new SemVer(di.inject(applicationInformationInjectable).version);
|
||||
|
||||
return `${major}.${minor}.${patch}`;
|
||||
},
|
||||
});
|
||||
|
||||
export default extensionApiVersionInjectable;
|
||||
@@ -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 "../test-utils/get-global-override";
|
||||
import isSnapPackageInjectable from "./is-snap-package.injectable";
|
||||
|
||||
export default getGlobalOverride(isSnapPackageInjectable, () => false);
|
||||
+4
-5
@@ -3,12 +3,11 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import packageJson from "../../../package.json";
|
||||
|
||||
const packageJsonInjectable = getInjectable({
|
||||
id: "package-json",
|
||||
instantiate: () => packageJson,
|
||||
const isSnapPackageInjectable = getInjectable({
|
||||
id: "is-snap",
|
||||
instantiate: () => Boolean(process.env.SNAP),
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default packageJsonInjectable;
|
||||
export default isSnapPackageInjectable;
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* 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 applicationInformationInjectable from "./application-information.injectable";
|
||||
|
||||
const productNameInjectable = getInjectable({
|
||||
id: "product-name",
|
||||
instantiate: (di) => di.inject(applicationInformationInjectable).productName,
|
||||
});
|
||||
|
||||
export default productNameInjectable;
|
||||
@@ -3,14 +3,14 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { UpdateChannelId } from "../application-update/update-channels";
|
||||
import appSemanticVersionInjectable from "./app-semantic-version.injectable";
|
||||
import type { ReleaseChannel } from "../application-update/update-channels";
|
||||
import buildSemanticVersionInjectable from "./build-semantic-version.injectable";
|
||||
|
||||
const releaseChannelInjectable = getInjectable({
|
||||
id: "release-channel",
|
||||
instantiate: (di): UpdateChannelId => {
|
||||
const appSemanticVersion = di.inject(appSemanticVersionInjectable);
|
||||
const currentReleaseChannel = appSemanticVersion.prerelease[0];
|
||||
instantiate: (di): ReleaseChannel => {
|
||||
const buildSemanticVersion = di.inject(buildSemanticVersionInjectable);
|
||||
const currentReleaseChannel = buildSemanticVersion.get().prerelease[0];
|
||||
|
||||
switch (currentReleaseChannel) {
|
||||
case "latest":
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* 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 applicationInformationInjectable from "./application-information.injectable";
|
||||
|
||||
const sentryDataSourceNameInjectable = getInjectable({
|
||||
id: "sentry-data-source-name",
|
||||
instantiate: (di) => di.inject(applicationInformationInjectable).config.sentryDsn,
|
||||
});
|
||||
|
||||
export default sentryDataSourceNameInjectable;
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* 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 applicationInformationInjectable from "./application-information.injectable";
|
||||
|
||||
const storeMigrationVersionInjectable = getInjectable({
|
||||
id: "store-migration-version",
|
||||
instantiate: (di) => di.inject(applicationInformationInjectable).version,
|
||||
});
|
||||
|
||||
export default storeMigrationVersionInjectable;
|
||||
Reference in new issue
Block a user