refactor(matrix): simplify dependency availability check

This commit is contained in:
Ayaan Zaidi
2026-05-12 14:47:51 +05:30
parent 760501fc38
commit 0792223a87
2 changed files with 11 additions and 20 deletions
+1 -5
View File
@@ -173,12 +173,8 @@ describe("ensureMatrixSdkInstalled", () => {
throw new Error("Cannot find module");
});
await expect(ensureMatrixSdkInstalled({ resolveFn })).rejects.toThrow(
/matrix-js-sdk.*@matrix-org\/matrix-sdk-crypto-nodejs.*@matrix-org\/matrix-sdk-crypto-wasm/s,
/Matrix plugin dependencies are missing: matrix-js-sdk, @matrix-org\/matrix-sdk-crypto-nodejs, @matrix-org\/matrix-sdk-crypto-wasm\. Repair this plugin with `openclaw plugins update matrix` or run `openclaw doctor --fix`\./,
);
await expect(ensureMatrixSdkInstalled({ resolveFn })).rejects.toThrow(
/openclaw plugins update matrix/,
);
await expect(ensureMatrixSdkInstalled({ resolveFn })).rejects.toThrow(/openclaw doctor --fix/);
});
it("lists only the packages that fail to resolve", async () => {
+10 -15
View File
@@ -26,19 +26,15 @@ type MatrixCryptoRuntimeDeps = {
};
function resolveMissingMatrixPackages(resolveFn?: (id: string) => string): string[] {
try {
const resolve = resolveFn ?? defaultResolveFn;
return REQUIRED_MATRIX_PACKAGES.filter((pkg) => {
try {
resolve(pkg);
return false;
} catch {
return true;
}
});
} catch {
return [...REQUIRED_MATRIX_PACKAGES];
}
const resolve = resolveFn ?? defaultResolveFn;
return REQUIRED_MATRIX_PACKAGES.filter((pkg) => {
try {
resolve(pkg);
return false;
} catch {
return true;
}
});
}
export function isMatrixSdkAvailable(): boolean {
@@ -46,9 +42,8 @@ export function isMatrixSdkAvailable(): boolean {
}
function buildMatrixDepsMissingMessage(missing: string[]): string {
const packages = missing.length > 0 ? missing.join(", ") : REQUIRED_MATRIX_PACKAGES.join(", ");
return [
`Matrix plugin dependencies are missing: ${packages}.`,
`Matrix plugin dependencies are missing: ${missing.join(", ")}.`,
"Repair this plugin with `openclaw plugins update matrix` or run `openclaw doctor --fix`.",
].join(" ");
}