refactor(matrix): simplify dependency availability check · openclaw/openclaw@0792223
obviyus
·
2026-05-12
·
via Recent Commits to openclaw:main
File tree
extensions/matrix/src/matrix
| Original file line number | Diff line number | Diff line change |
|---|
@@ -173,12 +173,8 @@ describe("ensureMatrixSdkInstalled", () => {
|
173 | 173 | throw new Error("Cannot find module"); |
174 | 174 | }); |
175 | 175 | await expect(ensureMatrixSdkInstalled({ resolveFn })).rejects.toThrow( |
176 | | -/matrix-js-sdk.*@matrix-org\/matrix-sdk-crypto-nodejs.*@matrix-org\/matrix-sdk-crypto-wasm/s, |
| 176 | +/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`\./, |
177 | 177 | ); |
178 | | -await expect(ensureMatrixSdkInstalled({ resolveFn })).rejects.toThrow( |
179 | | -/openclaw plugins update matrix/, |
180 | | -); |
181 | | -await expect(ensureMatrixSdkInstalled({ resolveFn })).rejects.toThrow(/openclaw doctor --fix/); |
182 | 178 | }); |
183 | 179 | |
184 | 180 | it("lists only the packages that fail to resolve", async () => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -26,29 +26,24 @@ type MatrixCryptoRuntimeDeps = {
|
26 | 26 | }; |
27 | 27 | |
28 | 28 | function resolveMissingMatrixPackages(resolveFn?: (id: string) => string): string[] { |
29 | | -try { |
30 | | -const resolve = resolveFn ?? defaultResolveFn; |
31 | | -return REQUIRED_MATRIX_PACKAGES.filter((pkg) => { |
32 | | -try { |
33 | | -resolve(pkg); |
34 | | -return false; |
35 | | -} catch { |
36 | | -return true; |
37 | | -} |
38 | | -}); |
39 | | -} catch { |
40 | | -return [...REQUIRED_MATRIX_PACKAGES]; |
41 | | -} |
| 29 | +const resolve = resolveFn ?? defaultResolveFn; |
| 30 | +return REQUIRED_MATRIX_PACKAGES.filter((pkg) => { |
| 31 | +try { |
| 32 | +resolve(pkg); |
| 33 | +return false; |
| 34 | +} catch { |
| 35 | +return true; |
| 36 | +} |
| 37 | +}); |
42 | 38 | } |
43 | 39 | |
44 | 40 | export function isMatrixSdkAvailable(): boolean { |
45 | 41 | return resolveMissingMatrixPackages().length === 0; |
46 | 42 | } |
47 | 43 | |
48 | 44 | function buildMatrixDepsMissingMessage(missing: string[]): string { |
49 | | -const packages = missing.length > 0 ? missing.join(", ") : REQUIRED_MATRIX_PACKAGES.join(", "); |
50 | 45 | return [ |
51 | | -`Matrix plugin dependencies are missing: ${packages}.`, |
| 46 | +`Matrix plugin dependencies are missing: ${missing.join(", ")}.`, |
52 | 47 | "Repair this plugin with `openclaw plugins update matrix` or run `openclaw doctor --fix`.", |
53 | 48 | ].join(" "); |
54 | 49 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。