mirror of https://github.com/openclaw/openclaw.git
Build: ship Matrix crypto WASM pkg
This commit is contained in:
parent
82f04ced27
commit
1769d76e81
|
|
@ -0,0 +1,34 @@
|
|||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { removePathIfExists } from "./runtime-postbuild-shared.mjs";
|
||||
|
||||
/**
|
||||
* @param {{
|
||||
* cwd?: string;
|
||||
* repoRoot?: string;
|
||||
* }} [params]
|
||||
*/
|
||||
export function copyMatrixCryptoWasmPkg(params = {}) {
|
||||
const repoRoot = params.cwd ?? params.repoRoot ?? process.cwd();
|
||||
const sourcePkgDir = path.join(
|
||||
repoRoot,
|
||||
"node_modules",
|
||||
"@matrix-org",
|
||||
"matrix-sdk-crypto-wasm",
|
||||
"pkg",
|
||||
);
|
||||
const targetPkgDir = path.join(repoRoot, "dist", "pkg");
|
||||
|
||||
removePathIfExists(targetPkgDir);
|
||||
if (!fs.existsSync(sourcePkgDir)) {
|
||||
return;
|
||||
}
|
||||
|
||||
fs.mkdirSync(path.dirname(targetPkgDir), { recursive: true });
|
||||
fs.cpSync(sourcePkgDir, targetPkgDir, { force: true, recursive: true });
|
||||
}
|
||||
|
||||
if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) {
|
||||
copyMatrixCryptoWasmPkg();
|
||||
}
|
||||
|
|
@ -28,6 +28,7 @@ const requiredPathGroups = [
|
|||
"dist/build-info.json",
|
||||
"dist/channel-catalog.json",
|
||||
"dist/control-ui/index.html",
|
||||
"dist/pkg/matrix_sdk_crypto_wasm_bg.wasm",
|
||||
];
|
||||
const forbiddenPrefixes = ["dist-runtime/", "dist/OpenClaw.app/"];
|
||||
// 2026.3.12 ballooned to ~213.6 MiB unpacked and correlated with low-memory
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { pathToFileURL } from "node:url";
|
||||
import { copyBundledPluginMetadata } from "./copy-bundled-plugin-metadata.mjs";
|
||||
import { copyMatrixCryptoWasmPkg } from "./copy-matrix-crypto-wasm-pkg.mjs";
|
||||
import { copyPluginSdkRootAlias } from "./copy-plugin-sdk-root-alias.mjs";
|
||||
import { stageBundledPluginRuntimeDeps } from "./stage-bundled-plugin-runtime-deps.mjs";
|
||||
import { stageBundledPluginRuntime } from "./stage-bundled-plugin-runtime.mjs";
|
||||
|
|
@ -8,6 +9,7 @@ import { writeOfficialChannelCatalog } from "./write-official-channel-catalog.mj
|
|||
export function runRuntimePostBuild(params = {}) {
|
||||
copyPluginSdkRootAlias(params);
|
||||
copyBundledPluginMetadata(params);
|
||||
copyMatrixCryptoWasmPkg(params);
|
||||
writeOfficialChannelCatalog(params);
|
||||
stageBundledPluginRuntimeDeps(params);
|
||||
stageBundledPluginRuntime(params);
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ function makePackResult(filename: string, unpackedSize: number) {
|
|||
|
||||
const requiredPluginSdkPackPaths = [...listPluginSdkDistArtifacts(), "dist/plugin-sdk/compat.js"];
|
||||
const requiredBundledPluginPackPaths = listBundledPluginPackArtifacts();
|
||||
const requiredMatrixCryptoWasmPackPaths = ["dist/pkg/matrix_sdk_crypto_wasm_bg.wasm"];
|
||||
|
||||
describe("collectAppcastSparkleVersionErrors", () => {
|
||||
it("accepts legacy 9-digit calver builds before lane-floor cutover", () => {
|
||||
|
|
@ -138,6 +139,7 @@ describe("collectMissingPackPaths", () => {
|
|||
expect.arrayContaining([
|
||||
"dist/channel-catalog.json",
|
||||
"dist/control-ui/index.html",
|
||||
"dist/pkg/matrix_sdk_crypto_wasm_bg.wasm",
|
||||
bundledDistPluginFile("matrix", "helper-api.js"),
|
||||
bundledDistPluginFile("matrix", "runtime-api.js"),
|
||||
bundledDistPluginFile("matrix", "thread-bindings-runtime.js"),
|
||||
|
|
@ -158,6 +160,7 @@ describe("collectMissingPackPaths", () => {
|
|||
"dist/entry.js",
|
||||
"dist/control-ui/index.html",
|
||||
...requiredBundledPluginPackPaths,
|
||||
...requiredMatrixCryptoWasmPackPaths,
|
||||
...requiredPluginSdkPackPaths,
|
||||
"dist/plugin-sdk/root-alias.cjs",
|
||||
"dist/build-info.json",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { copyMatrixCryptoWasmPkg } from "../../scripts/copy-matrix-crypto-wasm-pkg.mjs";
|
||||
|
||||
function createRepoFixture() {
|
||||
return fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-matrix-wasm-pkg-"));
|
||||
}
|
||||
|
||||
describe("copyMatrixCryptoWasmPkg", () => {
|
||||
it("stages the matrix crypto wasm package into dist/pkg", () => {
|
||||
const repoRoot = createRepoFixture();
|
||||
const sourcePkgDir = path.join(
|
||||
repoRoot,
|
||||
"node_modules",
|
||||
"@matrix-org",
|
||||
"matrix-sdk-crypto-wasm",
|
||||
"pkg",
|
||||
);
|
||||
fs.mkdirSync(sourcePkgDir, { recursive: true });
|
||||
fs.writeFileSync(path.join(sourcePkgDir, "matrix_sdk_crypto_wasm_bg.wasm"), "wasm\n", "utf8");
|
||||
fs.writeFileSync(path.join(sourcePkgDir, "matrix_sdk_crypto_wasm_bg.js"), "js\n", "utf8");
|
||||
|
||||
copyMatrixCryptoWasmPkg({ cwd: repoRoot });
|
||||
|
||||
expect(
|
||||
fs.readFileSync(path.join(repoRoot, "dist", "pkg", "matrix_sdk_crypto_wasm_bg.wasm"), "utf8"),
|
||||
).toBe("wasm\n");
|
||||
expect(
|
||||
fs.readFileSync(path.join(repoRoot, "dist", "pkg", "matrix_sdk_crypto_wasm_bg.js"), "utf8"),
|
||||
).toBe("js\n");
|
||||
});
|
||||
|
||||
it("removes stale dist/pkg output when the source package is unavailable", () => {
|
||||
const repoRoot = createRepoFixture();
|
||||
const staleTargetDir = path.join(repoRoot, "dist", "pkg");
|
||||
fs.mkdirSync(staleTargetDir, { recursive: true });
|
||||
fs.writeFileSync(path.join(staleTargetDir, "stale.txt"), "stale\n", "utf8");
|
||||
|
||||
copyMatrixCryptoWasmPkg({ cwd: repoRoot });
|
||||
|
||||
expect(fs.existsSync(staleTargetDir)).toBe(false);
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue