Skip to content

Commit 43b79c0

Browse files
fix(scripts): format refreshed specs with biome to avoid noise PRs (#209)
Run JSON.stringify output through `biome format --stdin-file-path` so refreshed specs match the checked-in formatting (short arrays inlined per biome.json line width). Without this, the weekly refresh workflow opened PRs whose entire diff was formatting churn even when upstream content was unchanged. Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 3e0c18a commit 43b79c0

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

scripts/refresh-specs.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,22 @@ const SERVICE_SPECS: ServiceSpec[] = [
6868
},
6969
];
7070

71+
async function formatJson(content: string, filePath: string): Promise<string> {
72+
const proc = Bun.spawn(['bunx', 'biome', 'format', `--stdin-file-path=${filePath}`], {
73+
stdin: 'pipe',
74+
stdout: 'pipe',
75+
stderr: 'pipe',
76+
});
77+
proc.stdin.write(content);
78+
await proc.stdin.end();
79+
const [stdout, exitCode] = await Promise.all([new Response(proc.stdout).text(), proc.exited]);
80+
if (exitCode !== 0) {
81+
const stderr = await new Response(proc.stderr).text();
82+
throw new Error(`biome format failed for ${filePath}: ${stderr}`);
83+
}
84+
return stdout;
85+
}
86+
7187
async function fetchSpec(service: ServiceSpec) {
7288
const source = process.env[service.envVar] || service.defaultUrl;
7389
if (!source) {
@@ -98,7 +114,7 @@ async function fetchSpec(service: ServiceSpec) {
98114
const raw = await response.text();
99115
const parsed =
100116
source.endsWith('.yaml') || source.endsWith('.yml') ? YAML.parse(raw) : JSON.parse(raw);
101-
const next = `${JSON.stringify(parsed, null, 2)}\n`;
117+
const next = await formatJson(`${JSON.stringify(parsed, null, 2)}\n`, service.outputPath);
102118
const current = existsSync(service.outputPath) ? readFileSync(service.outputPath, 'utf-8') : null;
103119
const changed = current !== next;
104120

0 commit comments

Comments
 (0)