Skip to content

Commit 84fd347

Browse files
authored
fix(codegen): write prettier-stable generated manifests (#41343)
1 parent e8f215b commit 84fd347

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

packages/httpapi-codegen/src/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,15 @@ export function write(
13161316
}).pipe(Effect.flatMap((content) => fs.writeFileString(join(directory, file.path), content))),
13171317
{ concurrency: 8, discard: true },
13181318
)
1319-
yield* fs.writeFileString(manifest, JSON.stringify(output.files.map((file) => file.path).sort(), null, 2) + "\n")
1319+
// Format the manifest with the same prettier settings as the repo-wide
1320+
// format pass, so `check:generated` stays clean after the generate bot
1321+
// reformats the tree.
1322+
const manifestJson = JSON.stringify(output.files.map((file) => file.path).sort())
1323+
const manifestContent = yield* Effect.tryPromise({
1324+
try: () => format(manifestJson, { filepath: manifest, parser: "json", printWidth: 120 }),
1325+
catch: (error) => new GenerationError({ reason: `Failed to format ${manifest}: ${String(error)}` }),
1326+
})
1327+
yield* fs.writeFileString(manifest, manifestContent)
13201328
})
13211329
}
13221330

packages/httpapi-codegen/test/write.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe("HttpApiCodegen.write", () => {
1616

1717
expect(writes).toEqual([
1818
{ path: "/generated/session.ts", content: "export const session = {}\n" },
19-
{ path: "/generated/.httpapi-codegen.json", content: '[\n "session.ts"\n]\n' },
19+
{ path: "/generated/.httpapi-codegen.json", content: '["session.ts"]\n' },
2020
])
2121
}).pipe(
2222
Effect.provideService(

0 commit comments

Comments
 (0)