fix: bundle qr renderer in relay
This commit is contained in:
@@ -251,6 +251,9 @@ if [[ "${SKIP_GATEWAY_PACKAGE:-0}" != "1" ]]; then
|
|||||||
fi
|
fi
|
||||||
rm -rf "$RELAY_BUILD_DIR"
|
rm -rf "$RELAY_BUILD_DIR"
|
||||||
|
|
||||||
|
echo "🧪 Smoke testing bundled relay QR modules"
|
||||||
|
CLAWDBOT_SMOKE_QR=1 "$RELAY_OUT" >/dev/null
|
||||||
|
|
||||||
echo "🎨 Copying gateway A2UI host assets"
|
echo "🎨 Copying gateway A2UI host assets"
|
||||||
rm -rf "$RELAY_DIR/a2ui"
|
rm -rf "$RELAY_DIR/a2ui"
|
||||||
cp -R "$ROOT_DIR/src/canvas-host/a2ui" "$RELAY_DIR/a2ui"
|
cp -R "$ROOT_DIR/src/canvas-host/a2ui" "$RELAY_DIR/a2ui"
|
||||||
|
|||||||
@@ -32,6 +32,13 @@ async function main() {
|
|||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (process.env.CLAWDBOT_SMOKE_QR === "1") {
|
||||||
|
const { renderQrPngBase64 } = await import("../web/qr-image.js");
|
||||||
|
await renderQrPngBase64("clawdbot-smoke");
|
||||||
|
console.log("smoke: qr ok");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await patchBunLongForProtobuf();
|
await patchBunLongForProtobuf();
|
||||||
|
|
||||||
const { loadDotEnv } = await import("../infra/dotenv.js");
|
const { loadDotEnv } = await import("../infra/dotenv.js");
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
import { readFile } from "node:fs/promises";
|
||||||
|
import { resolve } from "node:path";
|
||||||
|
|
||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
import { renderQrPngBase64 } from "./qr-image.js";
|
import { renderQrPngBase64 } from "./qr-image.js";
|
||||||
@@ -8,4 +11,11 @@ describe("renderQrPngBase64", () => {
|
|||||||
const buf = Buffer.from(b64, "base64");
|
const buf = Buffer.from(b64, "base64");
|
||||||
expect(buf.subarray(0, 8).toString("hex")).toBe("89504e470d0a1a0a");
|
expect(buf.subarray(0, 8).toString("hex")).toBe("89504e470d0a1a0a");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("avoids dynamic require of qrcode-terminal vendor modules", async () => {
|
||||||
|
const sourcePath = resolve(process.cwd(), "src/web/qr-image.ts");
|
||||||
|
const source = await readFile(sourcePath, "utf-8");
|
||||||
|
expect(source).not.toContain("createRequire(");
|
||||||
|
expect(source).not.toContain('require("qrcode-terminal/vendor/QRCode")');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { createRequire } from "node:module";
|
|
||||||
import { deflateSync } from "node:zlib";
|
import { deflateSync } from "node:zlib";
|
||||||
|
import QRCodeModule from "qrcode-terminal/vendor/QRCode";
|
||||||
|
import QRErrorCorrectLevelModule from "qrcode-terminal/vendor/QRCode/QRErrorCorrectLevel";
|
||||||
|
|
||||||
type QRCodeConstructor = new (
|
type QRCodeConstructor = new (
|
||||||
typeNumber: number,
|
typeNumber: number,
|
||||||
@@ -11,13 +12,8 @@ type QRCodeConstructor = new (
|
|||||||
isDark: (row: number, col: number) => boolean;
|
isDark: (row: number, col: number) => boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const require = createRequire(import.meta.url);
|
const QRCode = QRCodeModule as unknown as QRCodeConstructor;
|
||||||
const QRCode = require("qrcode-terminal/vendor/QRCode") as QRCodeConstructor;
|
const QRErrorCorrectLevel = QRErrorCorrectLevelModule as Record<string, unknown>;
|
||||||
const QRErrorCorrectLevel =
|
|
||||||
require("qrcode-terminal/vendor/QRCode/QRErrorCorrectLevel") as Record<
|
|
||||||
string,
|
|
||||||
unknown
|
|
||||||
>;
|
|
||||||
|
|
||||||
function createQrMatrix(input: string) {
|
function createQrMatrix(input: string) {
|
||||||
const qr = new QRCode(-1, QRErrorCorrectLevel.L);
|
const qr = new QRCode(-1, QRErrorCorrectLevel.L);
|
||||||
|
|||||||
Reference in New Issue
Block a user