haperone_local-image-compress/scripts/verify-root-ts.js
haperone 3355a902aa fix: bind timers to their owning windows
fix: make cache unload replay authoritative
2026-06-15 21:23:29 +02:00

56 lines
1.9 KiB
JavaScript

"use strict";
const fs = require("fs");
const path = require("path");
const crypto = require("crypto");
const { resolveRepositoryLayout } = require("./repository-layout");
const { repositoryRoot, sourceRoot: root } = resolveRepositoryLayout();
const generatedPath = path.join(root, "dist-ts", "main.js");
const rootMainPath = path.join(repositoryRoot, "main.js");
function sha256(buffer) {
return crypto.createHash("sha256").update(buffer).digest("hex").toUpperCase();
}
function firstDifferenceOffset(a, b) {
const length = Math.min(a.length, b.length);
for (let i = 0; i < length; i += 1) {
if (a[i] !== b[i]) return i;
}
return a.length === b.length ? -1 : length;
}
function readRequired(file) {
if (!fs.existsSync(file)) {
throw new Error(`File not found: ${file}`);
}
return fs.readFileSync(file);
}
const generated = readRequired(generatedPath);
const rootMain = readRequired(rootMainPath);
const generatedHash = sha256(generated);
const rootMainHash = sha256(rootMain);
if (generated.length === rootMain.length && generatedHash === rootMainHash) {
console.log(`Verified root main.js matches dist-ts/main.js (${generated.length} bytes, SHA-256 ${generatedHash})`);
process.exit(0);
}
console.error("Root TS verification failed.");
console.error(`Generated SHA-256: ${generatedHash}`);
console.error(`Root main SHA-256: ${rootMainHash}`);
console.error(`Generated size: ${generated.length}`);
console.error(`Root main size: ${rootMain.length}`);
const offset = firstDifferenceOffset(generated, rootMain);
if (offset >= 0) {
const generatedByte = offset < generated.length ? `0x${generated[offset].toString(16).padStart(2, "0")}` : "<EOF>";
const rootByte = offset < rootMain.length ? `0x${rootMain[offset].toString(16).padStart(2, "0")}` : "<EOF>";
console.error(`First differing byte offset: ${offset}`);
console.error(`Generated byte: ${generatedByte}`);
console.error(`Root byte: ${rootByte}`);
}
process.exit(1);