35 lines
1.4 KiB
JavaScript
35 lines
1.4 KiB
JavaScript
#!/usr/bin/env node
|
|
import { loadQuixosLock } from "./loader.js";
|
|
import { parseQuixosLockDocument } from "./parser.js";
|
|
import { readFile, stat } from "node:fs/promises";
|
|
|
|
// A trusted fetcher can inspect the root's declared platform pin without
|
|
// following authored import paths or evaluating Nix. The input is a fetched
|
|
// Git blob, not a filesystem tree provided by an author.
|
|
if (process.argv[2] === "--platform-only") {
|
|
const filename = process.argv[3];
|
|
if (process.argv.length !== 4 || !filename || (await stat(filename)).size > 1024 * 1024)
|
|
throw Error("INVALID_PLATFORM_SOURCE_LOCK");
|
|
const result = parseQuixosLockDocument(await readFile(filename, "utf8"));
|
|
if (!result.ok || result.document.kind !== "root") throw Error("INVALID_PLATFORM_SOURCE_LOCK");
|
|
console.log(JSON.stringify({ repository: result.document.quixos.repository, commit: result.document.quixos.commit }));
|
|
process.exit(0);
|
|
}
|
|
|
|
const fileName = process.argv[2];
|
|
if (!fileName || process.argv.length !== 3) {
|
|
console.error("Usage: quixos-lock-check <quixos.lock>");
|
|
process.exit(2);
|
|
}
|
|
|
|
const result = await loadQuixosLock(fileName);
|
|
if (!result.ok) {
|
|
for (const diagnostic of result.diagnostics) {
|
|
console.error(
|
|
`${diagnostic.fileName}:${diagnostic.line}:${diagnostic.column + 1}: ${diagnostic.phase}/${diagnostic.code}: ${diagnostic.message}`,
|
|
);
|
|
}
|
|
process.exit(1);
|
|
}
|
|
console.log(JSON.stringify(result.lock, null, 2));
|