fix(matrix): load crypto-nodejs via createRequire to fix __dirname in ESM (#54566)

Merged via squash.

Prepared head SHA: 61d99628f9
Co-authored-by: joelnishanth <140015627+joelnishanth@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
OfflynAI 2026-03-28 16:43:44 -05:00 committed by GitHub
parent 2022dfd0a1
commit cb00d44ae4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 35 additions and 1 deletions

View File

@ -127,6 +127,7 @@ Docs: https://docs.openclaw.ai
- Daemon/status: surface immediate gateway close reasons from lightweight probes and prefer those concrete auth or pairing failures over generic timeouts in `openclaw daemon status`. (#56282) Thanks @mbelinky.
- Agents/failover: classify HTTP 410 errors as retryable timeouts by default while still preserving explicit session-expired, billing, and auth signals from the payload. (#55201) thanks @nikus-pan.
- Agents/subagents: restore completion announce delivery for extension channels like BlueBubbles. (#56348)
- Plugins/Matrix: load bundled `@matrix-org/matrix-sdk-crypto-nodejs` through `createRequire(...)` so E2EE media send and receive keep the package-local native binding lookup working in packaged ESM builds. (#54566) thanks @joelnishanth.
## 2026.3.24

View File

@ -0,0 +1,27 @@
import path from "node:path";
import { fileURLToPath } from "node:url";
import { build } from "esbuild";
import { describe, expect, it } from "vitest";
const sdkDir = path.dirname(fileURLToPath(import.meta.url));
const cryptoNodeRuntimePath = path.join(sdkDir, "crypto-node.runtime.ts");
describe("crypto-node runtime bundling", () => {
it("keeps the native Matrix crypto package behind a runtime require boundary", async () => {
const result = await build({
entryPoints: [cryptoNodeRuntimePath],
bundle: true,
external: ["@matrix-org/matrix-sdk-crypto-nodejs"],
format: "esm",
platform: "node",
write: false,
});
const bundled = result.outputFiles.at(0)?.text ?? "";
expect(bundled).toContain('from "node:module"');
expect(bundled).toContain("createRequire(import.meta.url)");
expect(bundled).toMatch(/require\d*\("@matrix-org\/matrix-sdk-crypto-nodejs"\)/);
expect(bundled).not.toContain('from "@matrix-org/matrix-sdk-crypto-nodejs"');
});
});

View File

@ -1,3 +1,9 @@
import { Attachment, EncryptedAttachment } from "@matrix-org/matrix-sdk-crypto-nodejs";
import { createRequire } from "node:module";
// Load via createRequire so the CJS package gets __dirname (its index.js
// uses __dirname to locate platform-specific native .node bindings).
const require = createRequire(import.meta.url);
const { Attachment, EncryptedAttachment } =
require("@matrix-org/matrix-sdk-crypto-nodejs") as typeof import("@matrix-org/matrix-sdk-crypto-nodejs");
export { Attachment, EncryptedAttachment };