Skip to content

Commit c4fed82

Browse files
ci: fall back to text attw report PIE-605
Use ATTW text output as the fallback gate when CI emits malformed JSON for large package reports. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 3e73de1 commit c4fed82

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

scripts/check-attw.mjs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ const getWorkspaceDirs = () => {
3636
return [...dirs].filter((dir) => existsSync(path.join(dir, "package.json")));
3737
};
3838

39-
const runAttw = (dir) => {
40-
const cmd = "bunx attw --pack --ignore-rules cjs-resolves-to-esm --format json -- .";
39+
const runCommand = (cmd, dir) => {
4140
try {
4241
const stdout = execSync(cmd, {
4342
cwd: dir,
@@ -56,16 +55,26 @@ const runAttw = (dir) => {
5655
}
5756
};
5857

59-
const parseAttwReport = ({ stdout, failed }, packageName) => {
58+
const runAttw = (dir) =>
59+
runCommand(
60+
"bunx attw --pack --ignore-rules cjs-resolves-to-esm --format json -- .",
61+
dir,
62+
);
63+
64+
const runAttwText = (dir) =>
65+
runCommand("bunx attw --pack --ignore-rules cjs-resolves-to-esm -- .", dir);
66+
67+
const parseAttwReport = ({ stdout, failed }, packageName, dir) => {
6068
try {
6169
return JSON.parse(stdout);
6270
} catch (error) {
63-
if (failed) {
64-
throw error;
71+
const textReport = runAttwText(dir);
72+
if (textReport.failed) {
73+
throw new Error(textReport.stdout || error.message);
6574
}
6675

6776
console.warn(
68-
`[check-attw] ${packageName}: ATTW exited cleanly but emitted malformed JSON; treating the clean exit status as authoritative.`,
77+
`[check-attw] ${packageName}: ATTW JSON report was malformed; text-mode ATTW exited cleanly, treating that as authoritative.`,
6978
);
7079
return { problems: {} };
7180
}
@@ -126,7 +135,7 @@ const run = () => {
126135
}
127136
checked += 1;
128137
try {
129-
const report = parseAttwReport(runAttw(dir), pkg.name);
138+
const report = parseAttwReport(runAttw(dir), pkg.name, dir);
130139
const problems = flattenProblems(report.problems);
131140
const actionable = problems.filter(
132141
(problem) => !shouldSuppressProblem(problem, pkg.name),

0 commit comments

Comments
 (0)