mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Restructure to monorepo (#6907)
* wip: restructure to monorepo Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * refactor create-release-pr to a package Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * build fixes Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * github workflow fixes Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix typo Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * add webpack-env types to core Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix github workflows Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * refactor/fix integration tests Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * lint fix Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * yarn run dev Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * eslint settings for vscode Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * move templates to right package Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * open-lens build fixes Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * integration test fix Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix nx task dependencies Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * use bash shell for unit tests in test workflow Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix test:unit for windows Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix win-ca webpack error in open-lens Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix win-ca webpack error in open-lens Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix build:app on windows Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * remove ELECTRON_BUILDER_EXTRA_ARGS Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * sync src/ from master Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * remove Makefile from core Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
1 parent
0066ca4ea2
commit
2657df2293
3321 files changed
+28699
-11447
No files matched your search
@@ -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 type { SendToViewArgs } from "../../main/start-main-application/lens-window/application-window/create-lens-window.injectable";
|
||||
import { overrideMessagingFromMainToWindow } from "./override-messaging-from-main-to-window";
|
||||
import { overrideMessagingFromWindowToMain } from "./override-messaging-from-window-to-main";
|
||||
import { overrideRequestingFromWindowToMain } from "./override-requesting-from-window-to-main";
|
||||
|
||||
export interface OverrideChannels {
|
||||
overrideForWindow: (windowDi: DiContainer, windowId: string) => void;
|
||||
sendToWindow: (windowId: string, args: SendToViewArgs) => void;
|
||||
}
|
||||
|
||||
export const overrideChannels = (mainDi: DiContainer): OverrideChannels => {
|
||||
const { overrideEnlistForWindow, sendToWindow } = overrideMessagingFromMainToWindow();
|
||||
const overrideMessagingFromWindowToForWindow = overrideMessagingFromWindowToMain(mainDi);
|
||||
const overrideRequestingFromWindowToMainForWindow = overrideRequestingFromWindowToMain(mainDi);
|
||||
|
||||
return {
|
||||
overrideForWindow: (windowDi, windowId) => {
|
||||
overrideEnlistForWindow(windowDi, windowId);
|
||||
overrideMessagingFromWindowToForWindow(windowDi);
|
||||
overrideRequestingFromWindowToMainForWindow(windowDi);
|
||||
},
|
||||
sendToWindow,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { MessageChannelListener } from "../../common/utils/channel/message-channel-listener-injection-token";
|
||||
import enlistMessageChannelListenerInjectableInRenderer from "../../renderer/utils/channel/channel-listeners/enlist-message-channel-listener.injectable";
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import { getOrInsert, getOrInsertSet } from "../../common/utils";
|
||||
import type { SendToViewArgs } from "../../main/start-main-application/lens-window/application-window/create-lens-window.injectable";
|
||||
import { deserialize, serialize } from "v8";
|
||||
|
||||
type ListenerSet = Set<MessageChannelListener<any>>;
|
||||
type WindowListenerMap = Map<string, ListenerSet>;
|
||||
type ListenerFakeMap = Map<string, WindowListenerMap>;
|
||||
|
||||
export interface OverriddenWindowMessaging {
|
||||
sendToWindow(windowId: string, args: SendToViewArgs): void;
|
||||
overrideEnlistForWindow(windowDi: DiContainer, windowId: string): void;
|
||||
}
|
||||
|
||||
export const overrideMessagingFromMainToWindow = (): OverriddenWindowMessaging => {
|
||||
const messageChannelListenerFakesForRenderer: ListenerFakeMap = new Map();
|
||||
|
||||
const getWindowListeners = (channelId: string, windowId: string) => {
|
||||
const channelListeners = getOrInsert<string, WindowListenerMap>(
|
||||
messageChannelListenerFakesForRenderer,
|
||||
channelId,
|
||||
new Map(),
|
||||
);
|
||||
|
||||
return getOrInsertSet(channelListeners, windowId);
|
||||
};
|
||||
|
||||
return {
|
||||
overrideEnlistForWindow: (windowDi, windowId) => {
|
||||
windowDi.override(
|
||||
enlistMessageChannelListenerInjectableInRenderer,
|
||||
|
||||
() => (listener) => {
|
||||
const windowListeners = getWindowListeners(
|
||||
listener.channel.id,
|
||||
windowId,
|
||||
);
|
||||
|
||||
windowListeners.add(listener);
|
||||
|
||||
return () => {
|
||||
windowListeners.delete(listener);
|
||||
};
|
||||
},
|
||||
);
|
||||
},
|
||||
sendToWindow: (windowId, { channel, data, frameInfo }) => {
|
||||
try {
|
||||
data = deserialize(serialize(data));
|
||||
} catch (error) {
|
||||
throw new Error(`Tried to send a message to channel "${channel}" that is not compatible with StructuredClone: ${error}`);
|
||||
}
|
||||
|
||||
const windowListeners = getWindowListeners(channel, windowId);
|
||||
|
||||
if (frameInfo) {
|
||||
throw new Error(
|
||||
`Tried to send message to frame "${frameInfo.frameId}" in process "${frameInfo.processId}" using channel "${channel}" which isn't supported yet.`,
|
||||
);
|
||||
}
|
||||
|
||||
if (windowListeners.size === 0) {
|
||||
throw new Error(
|
||||
`Tried to send message to channel "${channel}" but there where no listeners. Current channels with listeners: "${[
|
||||
...messageChannelListenerFakesForRenderer.keys(),
|
||||
].join('", "')}"`,
|
||||
);
|
||||
}
|
||||
|
||||
windowListeners.forEach((listener) => listener.handler(data));
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* 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 { deserialize, serialize } from "v8";
|
||||
import type { MessageChannel, MessageChannelListener } from "../../common/utils/channel/message-channel-listener-injection-token";
|
||||
import enlistMessageChannelListenerInjectableInMain from "../../main/utils/channel/channel-listeners/enlist-message-channel-listener.injectable";
|
||||
import { getOrInsertSet } from "../../renderer/utils";
|
||||
import sendToMainInjectable from "../../renderer/utils/channel/send-to-main.injectable";
|
||||
|
||||
export const overrideMessagingFromWindowToMain = (mainDi: DiContainer) => {
|
||||
const messageChannelListenerFakesForMain = new Map<
|
||||
string,
|
||||
Set<MessageChannelListener<MessageChannel<unknown>>>
|
||||
>();
|
||||
|
||||
mainDi.override(
|
||||
enlistMessageChannelListenerInjectableInMain,
|
||||
|
||||
() => (listener) => {
|
||||
const listeners = getOrInsertSet(messageChannelListenerFakesForMain, listener.channel.id);
|
||||
|
||||
listeners.add(listener);
|
||||
|
||||
return () => {
|
||||
listeners.delete(listener);
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
return (windowDi: DiContainer) => {
|
||||
windowDi.override(sendToMainInjectable, () => (channelId, message) => {
|
||||
const listeners = messageChannelListenerFakesForMain.get(channelId);
|
||||
|
||||
if (!listeners || listeners.size === 0) {
|
||||
throw new Error(
|
||||
`Tried to send message to channel "${channelId}" but there where no listeners. Current channels with listeners: "${[
|
||||
...messageChannelListenerFakesForMain.keys(),
|
||||
].join('", "')}"`,
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
message = deserialize(serialize(message));
|
||||
} catch (error) {
|
||||
throw new Error(`Tried to send a message to channel "${channelId}" that is not compatible with StructuredClone: ${error}`);
|
||||
}
|
||||
|
||||
listeners.forEach((listener) => listener.handler(message));
|
||||
});
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* 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 { deserialize, serialize } from "v8";
|
||||
import type { RequestChannel } from "../../common/utils/channel/request-channel-listener-injection-token";
|
||||
import type { RequestFromChannel } from "../../common/utils/channel/request-from-channel-injection-token";
|
||||
import enlistRequestChannelListenerInjectableInMain from "../../main/utils/channel/channel-listeners/enlist-request-channel-listener.injectable";
|
||||
import type { RequestChannelListener } from "../../main/utils/channel/channel-listeners/listener-tokens";
|
||||
import requestFromChannelInjectable from "../../renderer/utils/channel/request-from-channel.injectable";
|
||||
|
||||
export const overrideRequestingFromWindowToMain = (mainDi: DiContainer) => {
|
||||
const requestChannelListenerFakesForMain = new Map<
|
||||
string,
|
||||
RequestChannelListener<RequestChannel<unknown, unknown>>
|
||||
>();
|
||||
|
||||
mainDi.override(
|
||||
enlistRequestChannelListenerInjectableInMain,
|
||||
|
||||
() => (listener) => {
|
||||
if (requestChannelListenerFakesForMain.has(listener.channel.id)) {
|
||||
throw new Error(
|
||||
`Tried to enlist listener for channel "${listener.channel.id}", but it was already enlisted`,
|
||||
);
|
||||
}
|
||||
|
||||
requestChannelListenerFakesForMain.set(listener.channel.id, listener);
|
||||
|
||||
return () => {
|
||||
requestChannelListenerFakesForMain.delete(listener.channel.id);
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
return (windowDi: DiContainer) => {
|
||||
windowDi.override(
|
||||
requestFromChannelInjectable,
|
||||
|
||||
() => (async (channel, request) => {
|
||||
const requestListener = requestChannelListenerFakesForMain.get(channel.id);
|
||||
|
||||
if (!requestListener) {
|
||||
throw new Error(
|
||||
`Tried to get value from channel "${channel.id}", but no listeners were registered`,
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
request = deserialize(serialize(request));
|
||||
} catch (error) {
|
||||
throw new Error(`Tried to request from channel "${channel.id}" with data that is not compatible with StructuredClone: ${error}`);
|
||||
}
|
||||
|
||||
return requestListener.handler(request);
|
||||
}) as RequestFromChannel,
|
||||
);
|
||||
};
|
||||
};
|
||||
@@ -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 { Response, Headers as NodeFetchHeaders } from "node-fetch";
|
||||
import { PassThrough } from "stream";
|
||||
|
||||
export const createMockResponseFromString = (url: string, data: string, statusCode = 200) => {
|
||||
const res: jest.Mocked<Response> = {
|
||||
buffer: jest.fn(async () => { throw new Error("buffer() is not supported"); }),
|
||||
clone: jest.fn(() => res),
|
||||
arrayBuffer: jest.fn(async () => { throw new Error("arrayBuffer() is not supported"); }),
|
||||
blob: jest.fn(async () => { throw new Error("blob() is not supported"); }),
|
||||
body: new PassThrough(),
|
||||
bodyUsed: false,
|
||||
headers: new Headers() as NodeFetchHeaders,
|
||||
json: jest.fn(async () => JSON.parse(await res.text())),
|
||||
ok: 200 <= statusCode && statusCode < 300,
|
||||
redirected: 300 <= statusCode && statusCode < 400,
|
||||
size: data.length,
|
||||
status: statusCode,
|
||||
statusText: "some-text",
|
||||
text: jest.fn(async () => data),
|
||||
type: "basic",
|
||||
url,
|
||||
formData: jest.fn(async () => { throw new Error("formData() is not supported"); }),
|
||||
};
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
export const createMockResponseFromStream = (url: string, stream: NodeJS.ReadableStream, statusCode = 200) => {
|
||||
const res: jest.Mocked<Response> = {
|
||||
buffer: jest.fn(async () => { throw new Error("buffer() is not supported"); }),
|
||||
clone: jest.fn(() => res),
|
||||
arrayBuffer: jest.fn(async () => { throw new Error("arrayBuffer() is not supported"); }),
|
||||
blob: jest.fn(async () => { throw new Error("blob() is not supported"); }),
|
||||
body: stream,
|
||||
bodyUsed: false,
|
||||
headers: new Headers() as NodeFetchHeaders,
|
||||
json: jest.fn(async () => JSON.parse(await res.text())),
|
||||
ok: 200 <= statusCode && statusCode < 300,
|
||||
redirected: 300 <= statusCode && statusCode < 400,
|
||||
size: 10,
|
||||
status: statusCode,
|
||||
statusText: "some-text",
|
||||
text: jest.fn(() => {
|
||||
const chunks: Buffer[] = [];
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
stream.on("data", (chunk) => chunks.push(Buffer.from(chunk)));
|
||||
stream.on("error", (err) => reject(err));
|
||||
stream.on("end", () => resolve(Buffer.concat(chunks).toString("utf8")));
|
||||
});
|
||||
}),
|
||||
type: "basic",
|
||||
url,
|
||||
formData: jest.fn(async () => { throw new Error("formData() is not supported"); }),
|
||||
};
|
||||
|
||||
return res;
|
||||
};
|
||||
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* 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 fsInjectable from "../common/fs/fs.injectable";
|
||||
import { createFsFromVolume, Volume } from "memfs";
|
||||
import type {
|
||||
ensureDirSync as ensureDirSyncImpl,
|
||||
readJsonSync as readJsonSyncImpl,
|
||||
writeJsonSync as writeJsonSyncImpl,
|
||||
} from "fs-extra";
|
||||
|
||||
export const getOverrideFsWithFakes = () => {
|
||||
const root = createFsFromVolume(Volume.fromJSON({}));
|
||||
|
||||
const readJsonSync = ((file, opts) => {
|
||||
const options = typeof opts === "string"
|
||||
? {
|
||||
encoding: opts,
|
||||
}
|
||||
: opts;
|
||||
const value = root.readFileSync(file, options as any) as string;
|
||||
|
||||
return JSON.parse(value, options?.reviver);
|
||||
}) as typeof readJsonSyncImpl;
|
||||
const writeJsonSync = ((file, object, opts) => {
|
||||
const options = typeof opts === "string"
|
||||
? {
|
||||
encoding: opts,
|
||||
}
|
||||
: opts;
|
||||
|
||||
root.writeFileSync(file, JSON.stringify(object, options?.replacer, options?.spaces), options as any);
|
||||
}) as typeof writeJsonSyncImpl;
|
||||
const ensureDirSync = ((path, opts) => {
|
||||
const mode = typeof opts === "number"
|
||||
? opts
|
||||
: opts?.mode;
|
||||
|
||||
root.mkdirpSync(path, mode);
|
||||
}) as typeof ensureDirSyncImpl;
|
||||
|
||||
return (di: DiContainer) => {
|
||||
di.override(fsInjectable, () => ({
|
||||
pathExists: async (path) => root.existsSync(path),
|
||||
pathExistsSync: root.existsSync,
|
||||
readFile: root.promises.readFile as any,
|
||||
readFileSync: root.readFileSync as any,
|
||||
readJson: async (file, opts) => readJsonSync(file, opts),
|
||||
readJsonSync,
|
||||
writeFile: root.promises.writeFile as any,
|
||||
writeFileSync: root.writeFileSync as any,
|
||||
writeJson: async (file, obj, opts) => writeJsonSync(file, obj, opts as any),
|
||||
writeJsonSync,
|
||||
readdir: root.promises.readdir as any,
|
||||
lstat: root.promises.lstat as any,
|
||||
rm: root.promises.rm,
|
||||
access: root.promises.access,
|
||||
copy: async (src, dest) => { throw new Error(`Tried to copy '${src}' to '${dest}'. Copying is not yet supported`); },
|
||||
ensureDir: async (path, opts) => ensureDirSync(path, opts),
|
||||
ensureDirSync,
|
||||
createReadStream: root.createReadStream as any,
|
||||
stat: root.promises.stat as any,
|
||||
}));
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Conditionally run a test
|
||||
*/
|
||||
export function itIf(condition: boolean) {
|
||||
return condition ? it : it.skip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Conditionally run a block of tests
|
||||
*/
|
||||
export function describeIf(condition: boolean) {
|
||||
return condition ? describe : describe.skip;
|
||||
}
|
||||
Reference in new issue
Block a user