From e71f9e327ee24b7e8e5b020c222a068138e969fe Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 28 Jan 2025 11:27:53 +0000 Subject: [PATCH] Iterate --- packages/element-web-module-api/package.json | 3 +-- .../src/@types/global.d.ts | 1 + packages/element-web-module-api/src/api.ts | 4 ++-- .../src/legacy-customisations.ts | 16 ++++++++-------- .../element-web-module-api/src/legacy-modules.ts | 2 ++ packages/element-web-module-api/src/loader.ts | 5 +++-- 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/packages/element-web-module-api/package.json b/packages/element-web-module-api/package.json index 2e01680e89..d817ca4936 100644 --- a/packages/element-web-module-api/package.json +++ b/packages/element-web-module-api/package.json @@ -15,8 +15,7 @@ } }, "scripts": { - "lint:ts": "tsc --noEmit", - "lint:js": "eslint --max-warnings 0 src" + "lint:ts": "tsc --noEmit" }, "devDependencies": { "@types/node": "^22.10.7", diff --git a/packages/element-web-module-api/src/@types/global.d.ts b/packages/element-web-module-api/src/@types/global.d.ts index 07eea17458..82ae781eb5 100644 --- a/packages/element-web-module-api/src/@types/global.d.ts +++ b/packages/element-web-module-api/src/@types/global.d.ts @@ -6,6 +6,7 @@ Please see LICENSE files in the repository root for full details. */ declare global { + // eslint-disable-next-line no-var var __VERSION__: string; // injected by vite } diff --git a/packages/element-web-module-api/src/api.ts b/packages/element-web-module-api/src/api.ts index f38b8e643c..5d01f31b62 100644 --- a/packages/element-web-module-api/src/api.ts +++ b/packages/element-web-module-api/src/api.ts @@ -37,7 +37,7 @@ const moduleExportSignature: Record = { type Type = "function" | "string" | "number" | "boolean" | "object"; -export function isInterface(obj: any, keys: Record): obj is T { +export function isInterface(obj: unknown, keys: Record): obj is T { if (obj === null || typeof obj !== "object") return false; for (const key in keys) { if (typeof obj[key] !== keys[key]) return false; @@ -45,7 +45,7 @@ export function isInterface(obj: any, keys: Record): obj is T return true; } -export function isModule(module: any): module is ModuleExport { +export function isModule(module: unknown): module is ModuleExport { return ( isInterface(module, moduleExportSignature) && isInterface(module.default, moduleFactorySignature) && diff --git a/packages/element-web-module-api/src/legacy-customisations.ts b/packages/element-web-module-api/src/legacy-customisations.ts index e3ac489cf7..753f8ff107 100644 --- a/packages/element-web-module-api/src/legacy-customisations.ts +++ b/packages/element-web-module-api/src/legacy-customisations.ts @@ -77,12 +77,12 @@ export interface Media { downloadSource(): Promise; } -export interface MediaContructable { - new (prepared: { mxc: string; thumbnail?: any; file?: any }): Media; +export interface MediaContructable { + new (prepared: { mxc: string; thumbnail?: Thumbnail; file?: File }): Media; } -export interface MediaCustomisations { - readonly Media: MediaContructable; +export interface MediaCustomisations { + readonly Media: MediaContructable; mediaFromContent(content: Content, client?: Client): Media; mediaFromMxc(mxc?: string, client?: Client): Media; } @@ -166,7 +166,7 @@ export interface LegacyCustomisationsApiExtension { /** * @deprecated */ - readonly _registerLegacyChatExportCustomisations: LegacyCustomisations>; + readonly _registerLegacyChatExportCustomisations: LegacyCustomisations>; /** * @deprecated */ @@ -182,11 +182,11 @@ export interface LegacyCustomisationsApiExtension { /** * @deprecated */ - readonly _registerLegacyMediaCustomisations: LegacyCustomisations>; + readonly _registerLegacyMediaCustomisations: LegacyCustomisations>; /** * @deprecated */ - readonly _registerLegacyRoomListCustomisations: LegacyCustomisations>; + readonly _registerLegacyRoomListCustomisations: LegacyCustomisations>; /** * @deprecated */ @@ -195,7 +195,7 @@ export interface LegacyCustomisationsApiExtension { * @deprecated */ readonly _registerLegacyWidgetPermissionsCustomisations: LegacyCustomisations< - WidgetPermissionsCustomisations + WidgetPermissionsCustomisations >; /** * @deprecated diff --git a/packages/element-web-module-api/src/legacy-modules.ts b/packages/element-web-module-api/src/legacy-modules.ts index 30a5755f21..8e7cc82ca8 100644 --- a/packages/element-web-module-api/src/legacy-modules.ts +++ b/packages/element-web-module-api/src/legacy-modules.ts @@ -5,11 +5,13 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial Please see LICENSE files in the repository root for full details. */ +// eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore -- optional interface, will gracefully degrade to `any` if `react-sdk-module-api` isn't installed import type { ModuleApi, RuntimeModule } from "@matrix-org/react-sdk-module-api"; export type RuntimeModuleConstructor = new (api: ModuleApi) => RuntimeModule; +/* eslint-disable @typescript-eslint/naming-convention */ export interface LegacyModuleApiExtension { /** * Register a legacy module based on @matrix-org/react-sdk-module-api diff --git a/packages/element-web-module-api/src/loader.ts b/packages/element-web-module-api/src/loader.ts index 6cc04d5aec..8f19cbb627 100644 --- a/packages/element-web-module-api/src/loader.ts +++ b/packages/element-web-module-api/src/loader.ts @@ -10,7 +10,7 @@ import { satisfies } from "semver"; import { Api, isModule, Module, ModuleExport } from "./api"; export class ModuleIncompatibleError extends Error { - constructor(pluginVersion: string) { + public constructor(pluginVersion: string) { super(`Plugin version ${pluginVersion} is incompatible with engine version ${__VERSION__}`); } } @@ -30,7 +30,8 @@ export class ModuleLoader { if (!satisfies(__VERSION__, moduleExport.default.moduleApiVersion)) { throw new ModuleIncompatibleError(moduleExport.default.moduleApiVersion); } - this.#modules.push(new moduleExport.default(this.api)); + const { default: Module } = moduleExport; + this.#modules.push(new Module(this.api)); } #started = false;