Преглед изворни кода

fix(generate): make openapi output deterministic by formatting in-place (#23228)

Kit Langton пре 4 месеци
родитељ
комит
3573019916
1 измењених фајлова са 13 додато и 1 уклоњено
  1. 13 1
      packages/opencode/src/cli/cmd/generate.ts

+ 13 - 1
packages/opencode/src/cli/cmd/generate.ts

@@ -25,7 +25,19 @@ export const GenerateCommand = {
         ]
       }
     }
-    const json = JSON.stringify(specs, null, 2)
+    const raw = JSON.stringify(specs, null, 2)
+
+    // Format through prettier so output is byte-identical to committed file
+    // regardless of whether ./script/format.ts runs afterward.
+    const prettier = await import("prettier")
+    const babel = await import("prettier/plugins/babel")
+    const estree = await import("prettier/plugins/estree")
+    const format = prettier.format ?? prettier.default?.format
+    const json = await format(raw, {
+      parser: "json",
+      plugins: [babel.default ?? babel, estree.default ?? estree],
+      printWidth: 120,
+    })
 
     // Wait for stdout to finish writing before process.exit() is called
     await new Promise<void>((resolve, reject) => {