mirror of
https://github.com/millionco/react-doctor.git
synced 2026-09-14 20:00:24 +08:00
938008119a
* feat(report): add versioned JSON v3 metadata Expose deterministic diagnostic identities and exact scan completeness while preserving v1 and v2 decoding. * fix(report): make v3 identities and coverage exact Keep workspace diagnostics distinct and align JSON completeness, telemetry verdicts, and fallback output with the versioned report contract.
51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
import * as fs from "node:fs";
|
|
|
|
const reportPath = process.argv[2];
|
|
const status = Number(process.argv[3] ?? "1");
|
|
|
|
if (!reportPath) {
|
|
process.exit(0);
|
|
}
|
|
|
|
const fallbackReport = {
|
|
schemaVersion: 3,
|
|
version: "unknown",
|
|
ok: false,
|
|
directory: process.cwd(),
|
|
mode: "full",
|
|
diff: null,
|
|
projects: [],
|
|
diagnostics: [],
|
|
summary: {
|
|
errorCount: 0,
|
|
warningCount: 0,
|
|
affectedFileCount: 0,
|
|
totalDiagnosticCount: 0,
|
|
score: null,
|
|
scoreLabel: null,
|
|
},
|
|
elapsedMilliseconds: 0,
|
|
error: {
|
|
name: "ReactDoctorActionError",
|
|
message: `react-doctor exited with status ${Number.isFinite(status) ? status : 1} before producing a JSON report.`,
|
|
chain: [],
|
|
},
|
|
};
|
|
|
|
// Known JsonReport schema versions remain valid CLI output; only an
|
|
// unparseable or unrecognized payload is treated as a failed scan.
|
|
const KNOWN_SCHEMA_VERSIONS = new Set([1, 2, 3]);
|
|
|
|
try {
|
|
const raw = fs.readFileSync(reportPath, "utf8").trim();
|
|
const parsed = JSON.parse(raw);
|
|
if (parsed && KNOWN_SCHEMA_VERSIONS.has(parsed.schemaVersion) && typeof parsed.ok === "boolean") {
|
|
process.exit(0);
|
|
}
|
|
} catch {
|
|
// Fall through to the fallback report.
|
|
}
|
|
|
|
fs.writeFileSync(reportPath, `${JSON.stringify(fallbackReport)}\n`);
|
|
process.exit(1);
|