Skip to content

Commit 3e73de1

Browse files
ci: tolerate clean attw malformed JSON reports PIE-605
Keep ATTW exit status as the publish-readiness gate when CI emits an unparsable JSON report despite a clean check. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 741a069 commit 3e73de1

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

scripts/check-attw.mjs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,35 @@ const getWorkspaceDirs = () => {
3939
const runAttw = (dir) => {
4040
const cmd = "bunx attw --pack --ignore-rules cjs-resolves-to-esm --format json -- .";
4141
try {
42-
return execSync(cmd, {
42+
const stdout = execSync(cmd, {
4343
cwd: dir,
4444
stdio: "pipe",
4545
encoding: "utf8",
4646
maxBuffer: 256 * 1024 * 1024,
4747
});
48+
return { failed: false, stdout };
4849
} catch (error) {
4950
const stdout = error.stdout?.toString?.() ?? "";
5051
if (!stdout.trim()) {
5152
const stderr = error.stderr?.toString?.() ?? "";
5253
throw new Error([stderr, error.message].filter(Boolean).join("\n"));
5354
}
54-
return stdout;
55+
return { failed: true, stdout };
56+
}
57+
};
58+
59+
const parseAttwReport = ({ stdout, failed }, packageName) => {
60+
try {
61+
return JSON.parse(stdout);
62+
} catch (error) {
63+
if (failed) {
64+
throw error;
65+
}
66+
67+
console.warn(
68+
`[check-attw] ${packageName}: ATTW exited cleanly but emitted malformed JSON; treating the clean exit status as authoritative.`,
69+
);
70+
return { problems: {} };
5571
}
5672
};
5773

@@ -110,8 +126,7 @@ const run = () => {
110126
}
111127
checked += 1;
112128
try {
113-
const raw = runAttw(dir);
114-
const report = JSON.parse(raw);
129+
const report = parseAttwReport(runAttw(dir), pkg.name);
115130
const problems = flattenProblems(report.problems);
116131
const actionable = problems.filter(
117132
(problem) => !shouldSuppressProblem(problem, pkg.name),

0 commit comments

Comments
 (0)