19 lines
1.0 KiB
JavaScript
19 lines
1.0 KiB
JavaScript
import fs from "node:fs";
|
|
import { fileURLToPath } from "node:url";
|
|
import ts from "typescript";
|
|
|
|
// Evaluate the same policy used by WebModuleRouter; do not duplicate its rules.
|
|
const source = fs.readFileSync(new URL("../src/native-source-policy.ts", import.meta.url), "utf8");
|
|
const compiled = ts.transpileModule(source, {
|
|
compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.ES2022 },
|
|
}).outputText;
|
|
const { nativeSourceDecision } = await import(`data:text/javascript;base64,${Buffer.from(compiled).toString("base64")}`);
|
|
const input = JSON.parse(fs.readFileSync(process.argv[2] ?? 0, "utf8"));
|
|
const blocked = {};
|
|
for (const row of input.records ?? []) {
|
|
if (row.implementationStatus !== "routed" || row.route?.transport === "ui-container") continue;
|
|
const decision = nativeSourceDecision(row.route?.module ?? row.module, row.route?.command ?? row.command);
|
|
if (decision) blocked[row.id] = decision;
|
|
}
|
|
console.log(JSON.stringify({ policy: fileURLToPath(new URL("../src/native-source-policy.ts", import.meta.url)), blocked }));
|