Files
regex-tools/scripts/verify-engine-assets.mjs

35 lines
1.1 KiB
JavaScript

import { lstat, readFile, readdir } from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const engineDirectory = path.join(root, "dist", "engines");
const details = await lstat(engineDirectory);
if (details.isSymbolicLink() || !details.isDirectory()) {
throw new Error("dist/engines must be a real directory.");
}
const entries = (await readdir(engineDirectory, { withFileTypes: true })).sort(
(left, right) =>
left.name < right.name ? -1 : left.name > right.name ? 1 : 0,
);
if (
entries.length !== 1 ||
!entries[0]?.isFile() ||
entries[0].name !== "README.md"
) {
throw new Error(
"Regex Tools 0.1.0 must not ship an undeclared external engine pack.",
);
}
const notice = await readFile(path.join(engineDirectory, "README.md"), "utf8");
if (
!notice.includes("native `RegExp`") ||
!notice.includes("no external engine")
) {
throw new Error("The engine asset notice does not describe this release.");
}
console.log("Verified ECMAScript-only engine assets (no WebAssembly pack).");