Skip to content

Commit c390ec3

Browse files
authored
Tidy up modules (#29089)
Signed-off-by: Michael Telatynski <[email protected]>
1 parent 3c22e5d commit c390ec3

File tree

7 files changed

+23
-12
lines changed

7 files changed

+23
-12
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ test/end-to-end-tests/lib/
77
src/component-index.js
88
# Auto-generated file
99
src/modules.ts
10+
src/modules.js

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ electron/pub
2626
/coverage
2727
# Auto-generated file
2828
/src/modules.ts
29+
/src/modules.js
2930
/build_config.yaml
3031
/book
3132
/index.html

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ electron/pub
1717
/coverage
1818
# Auto-generated file
1919
/src/modules.ts
20+
/src/modules.js
2021
/src/i18n/strings
2122
/build_config.yaml
2223
# Raises an error because it contains a template var breaking the script tag

module_system/installer.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ const MODULES_TS_HEADER = `
2323
* You are not a salmon.
2424
*/
2525
26-
import { RuntimeModule } from "@matrix-org/react-sdk-module-api/lib/RuntimeModule";
2726
`;
2827
const MODULES_TS_DEFINITIONS = `
29-
export const INSTALLED_MODULES: RuntimeModule[] = [];
28+
export const INSTALLED_MODULES = [];
3029
`;
3130

3231
export function installer(config: BuildConfig): void {
@@ -78,8 +77,8 @@ export function installer(config: BuildConfig): void {
7877
return; // hit the finally{} block before exiting
7978
}
8079

81-
// If we reach here, everything seems fine. Write modules.ts and log some output
82-
// Note: we compile modules.ts in two parts for developer friendliness if they
80+
// If we reach here, everything seems fine. Write modules.js and log some output
81+
// Note: we compile modules.js in two parts for developer friendliness if they
8382
// happen to look at it.
8483
console.log("The following modules have been installed: ", installedModules);
8584
let modulesTsHeader = MODULES_TS_HEADER;
@@ -193,5 +192,5 @@ function isModuleVersionCompatible(ourApiVersion: string, moduleApiVersion: stri
193192
}
194193

195194
function writeModulesTs(content: string): void {
196-
fs.writeFileSync("./src/modules.ts", content, "utf-8");
195+
fs.writeFileSync("./src/modules.js", content, "utf-8");
197196
}

src/modules.d.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
Copyright 2025 New Vector Ltd.
3+
4+
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
5+
Please see LICENSE files in the repository root for full details.
6+
*/
7+
8+
import { ModuleApi, RuntimeModule } from "@matrix-org/react-sdk-module-api";
9+
10+
declare module "./modules.js" {
11+
export type RuntimeModuleConstructor = { new (api: ModuleApi): RuntimeModule };
12+
export const INSTALLED_MODULES: RuntimeModuleConstructor[];
13+
}

src/stores/widgets/StopGapWidgetDriver.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ import { navigateToPermalink } from "../../utils/permalinks/navigator";
6565
import { SdkContextClass } from "../../contexts/SDKContext";
6666
import { ModuleRunner } from "../../modules/ModuleRunner";
6767
import SettingsStore from "../../settings/SettingsStore";
68-
import { Media } from "../../customisations/Media";
68+
import { mediaFromMxc } from "../../customisations/Media";
6969

7070
// TODO: Purge this from the universe
7171

@@ -684,7 +684,7 @@ export class StopGapWidgetDriver extends WidgetDriver {
684684
*/
685685
public async downloadFile(contentUri: string): Promise<{ file: XMLHttpRequestBodyInit }> {
686686
const client = MatrixClientPeg.safeGet();
687-
const media = new Media({ mxc: contentUri }, client);
687+
const media = mediaFromMxc(contentUri, client);
688688
const response = await media.downloadSource();
689689
const blob = await response.blob();
690690
return { file: blob };

src/vector/init.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,8 @@ export async function showIncompatibleBrowser(onAccept: () => void): Promise<voi
125125
}
126126

127127
export async function loadModules(): Promise<void> {
128-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
129-
// @ts-ignore - this path is created at runtime and therefore won't exist at typecheck time
130-
const { INSTALLED_MODULES } = await import("../modules");
128+
const { INSTALLED_MODULES } = await import("../modules.js");
131129
for (const InstalledModule of INSTALLED_MODULES) {
132-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
133-
// @ts-ignore - we know the constructor exists even if TypeScript can't be convinced of that
134130
ModuleRunner.instance.registerModule((api) => new InstalledModule(api));
135131
}
136132
}

0 commit comments

Comments
 (0)