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:
Jari Kolehmainen authored and GitHub committed 2023-01-24 10:46:26 -08:00
1 parent 0066ca4ea2
commit 2657df2293
3321 files changed
+28699 -11447

No files matched your search

@@ -0,0 +1,20 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getLegacyGlobalDiForExtensionApi } from "./legacy-global-di-for-extension-api";
import type { Inject } from "@ogre-tools/injectable";
export const asLegacyGlobalFunctionForExtensionApi = ((
injectableKey,
instantiationParameter,
) =>
(...args: any[]) => {
const injected = getLegacyGlobalDiForExtensionApi().inject(
injectableKey,
instantiationParameter,
) as unknown as (...args: any[]) => any;
return injected(...args);
}) as Inject;
@@ -0,0 +1,81 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type {
DiContainer,
Injectable } from "@ogre-tools/injectable";
import {
createContainer,
getInjectable,
} from "@ogre-tools/injectable";
import { Environments, setLegacyGlobalDiForExtensionApi } from "./legacy-global-di-for-extension-api";
import { asLegacyGlobalObjectForExtensionApiWithModifications } from "./as-legacy-global-object-for-extension-api-with-modifications";
describe("asLegacyGlobalObjectForExtensionApiWithModifications", () => {
describe("given legacy global object", () => {
let di: DiContainer;
let someInjectable: Injectable<{ someProperty: string }, unknown, void>;
let actual: { someProperty: string } & {
someModificationProperty: string;
};
beforeEach(() => {
di = createContainer("irrelevant");
jest.spyOn(di, "inject");
setLegacyGlobalDiForExtensionApi(di, Environments.renderer);
someInjectable = getInjectable({
id: "some-injectable",
instantiate: () => ({
someProperty: "some-property-value",
}),
});
di.register(someInjectable);
actual = asLegacyGlobalObjectForExtensionApiWithModifications(
someInjectable,
{ someModificationProperty: "some-modification-value" },
);
});
it("when not accessed, does not inject yet", () => {
expect(di.inject).not.toHaveBeenCalled();
});
describe("when a property of global is accessed, ", () => {
let actualPropertyValue: string;
beforeEach(() => {
actualPropertyValue = actual.someProperty;
});
it("injects the injectable for global", () => {
expect(di.inject).toHaveBeenCalledWith(someInjectable, undefined);
});
it("global has property of injectable", () => {
expect(actualPropertyValue).toBe("some-property-value");
});
});
describe("when a property of modification is accessed, ", () => {
let actualModificationValue: string;
beforeEach(() => {
actualModificationValue = actual.someModificationProperty;
});
it("injects the injectable for global", () => {
expect(di.inject).toHaveBeenCalledWith(someInjectable, undefined);
});
it("global has property of modification", () => {
expect(actualModificationValue).toBe("some-modification-value");
});
});
});
});
@@ -0,0 +1,22 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { asLegacyGlobalForExtensionApi } from "./as-legacy-global-object-for-extension-api";
import type { Injectable } from "@ogre-tools/injectable";
/**
* @deprecated use asLegacyGlobalForExtensionApi instead, and use proper implementations instead of "modifications".
*/
export const asLegacyGlobalObjectForExtensionApiWithModifications = <
InjectableInstance extends InjectionTokenInstance & object,
InjectionTokenInstance,
ModificationObject extends object,
>(
injectable: Injectable<InjectableInstance, InjectionTokenInstance, void>,
modificationObject: ModificationObject,
) =>
Object.assign(
asLegacyGlobalForExtensionApi(injectable),
modificationObject,
);
@@ -0,0 +1,46 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { Inject } from "@ogre-tools/injectable";
import { getLegacyGlobalDiForExtensionApi } from "./legacy-global-di-for-extension-api";
export const asLegacyGlobalForExtensionApi = ((
injectable,
instantiationParameter,
) =>
new Proxy(
{},
{
apply(target: any, thisArg, argArray) {
const fn = getLegacyGlobalDiForExtensionApi().inject(
injectable,
instantiationParameter,
) as unknown as (...args: any[]) => any;
return fn(...argArray);
},
get(target, propertyName) {
if (propertyName === "$$typeof") {
return undefined;
}
const instance: any = getLegacyGlobalDiForExtensionApi().inject(
injectable,
instantiationParameter,
);
const propertyValue = instance[propertyName] ?? target[propertyName];
if (typeof propertyValue === "function") {
return function (...args: any[]) {
return propertyValue.apply(instance, args);
};
}
return propertyValue;
},
},
)) as Inject;
@@ -0,0 +1,42 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { Injectable } from "@ogre-tools/injectable";
import { asLegacyGlobalForExtensionApi } from "./as-legacy-global-object-for-extension-api";
import { getLegacyGlobalDiForExtensionApi } from "./legacy-global-di-for-extension-api";
import loggerInjectable from "../../common/logger.injectable";
export interface LegacySingleton<T> {
createInstance(): T;
getInstance(): T;
resetInstance(): void;
}
export function asLegacyGlobalSingletonForExtensionApi<Instance>(injectable: Injectable<Instance, unknown, void>): LegacySingleton<Instance>;
export function asLegacyGlobalSingletonForExtensionApi<Instance, InstantiationParameter>(injectable: Injectable<Instance, unknown, InstantiationParameter>, param: InstantiationParameter): LegacySingleton<Instance>;
export function asLegacyGlobalSingletonForExtensionApi<Instance, InstantiationParameter>(
injectable: Injectable<Instance, unknown, InstantiationParameter>,
instantiationParameter?: InstantiationParameter,
): LegacySingleton<Instance> {
const instance = asLegacyGlobalForExtensionApi(
injectable as never,
instantiationParameter,
) as Instance;
return {
createInstance: () => instance,
getInstance: () => instance,
resetInstance: () => {
const di = getLegacyGlobalDiForExtensionApi();
const logger = di.inject(loggerInjectable);
logger.warn(
`resetInstance() for a legacy global singleton of "${injectable.id}" does nothing.`,
);
},
};
}
@@ -0,0 +1,43 @@
/**
* 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";
const legacyGlobalDis = new Map<Environments, DiContainer>();
export enum Environments {
renderer,
main,
}
export const setLegacyGlobalDiForExtensionApi = (
di: DiContainer,
environment: Environments,
) => {
legacyGlobalDis.set(environment, di);
};
export const getLegacyGlobalDiForExtensionApi = () => {
if (legacyGlobalDis.size > 1) {
throw new Error("Tried to get DI container using legacy globals where there is multiple containers available.");
}
const [di] = [...legacyGlobalDis.values()];
if (!di) {
throw new Error("Tried to get DI container using legacy globals where there is no containers available.");
}
return di;
};
export function getEnvironmentSpecificLegacyGlobalDiForExtensionApi(environment: Environments) {
const di = legacyGlobalDis.get(environment);
if (!di) {
throw new Error("Tried to get DI container using legacy globals in environment which doesn't exist");
}
return di;
}