This commit is contained in:
Michael Telatynski 2025-01-28 11:27:53 +00:00
parent 5bc85e8ae4
commit e71f9e327e
6 changed files with 17 additions and 14 deletions

View File

@ -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",

View File

@ -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
}

View File

@ -37,7 +37,7 @@ const moduleExportSignature: Record<keyof ModuleExport, Type> = {
type Type = "function" | "string" | "number" | "boolean" | "object";
export function isInterface<T>(obj: any, keys: Record<keyof T, Type>): obj is T {
export function isInterface<T>(obj: unknown, keys: Record<keyof T, Type>): 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<T>(obj: any, keys: Record<keyof T, Type>): 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) &&

View File

@ -77,12 +77,12 @@ export interface Media {
downloadSource(): Promise<Response>;
}
export interface MediaContructable {
new (prepared: { mxc: string; thumbnail?: any; file?: any }): Media;
export interface MediaContructable<Thumbnail, File> {
new (prepared: { mxc: string; thumbnail?: Thumbnail; file?: File }): Media;
}
export interface MediaCustomisations<Content, Client> {
readonly Media: MediaContructable;
export interface MediaCustomisations<Content, Client, Thumbnail, File> {
readonly Media: MediaContructable<Thumbnail, File>;
mediaFromContent(content: Content, client?: Client): Media;
mediaFromMxc(mxc?: string, client?: Client): Media;
}
@ -166,7 +166,7 @@ export interface LegacyCustomisationsApiExtension {
/**
* @deprecated
*/
readonly _registerLegacyChatExportCustomisations: LegacyCustomisations<ChatExportCustomisations<any, any>>;
readonly _registerLegacyChatExportCustomisations: LegacyCustomisations<ChatExportCustomisations<never, never>>;
/**
* @deprecated
*/
@ -182,11 +182,11 @@ export interface LegacyCustomisationsApiExtension {
/**
* @deprecated
*/
readonly _registerLegacyMediaCustomisations: LegacyCustomisations<MediaCustomisations<any, any>>;
readonly _registerLegacyMediaCustomisations: LegacyCustomisations<MediaCustomisations<never, never, never, never>>;
/**
* @deprecated
*/
readonly _registerLegacyRoomListCustomisations: LegacyCustomisations<RoomListCustomisations<any>>;
readonly _registerLegacyRoomListCustomisations: LegacyCustomisations<RoomListCustomisations<never>>;
/**
* @deprecated
*/
@ -195,7 +195,7 @@ export interface LegacyCustomisationsApiExtension {
* @deprecated
*/
readonly _registerLegacyWidgetPermissionsCustomisations: LegacyCustomisations<
WidgetPermissionsCustomisations<any, any>
WidgetPermissionsCustomisations<never, never>
>;
/**
* @deprecated

View File

@ -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

View File

@ -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;