From 9e50d76416730b4e5c87856787d29f0bf6a2ed70 Mon Sep 17 00:00:00 2001 From: Kit Langton Date: Sun, 23 Aug 2026 17:34:47 -0400 Subject: [PATCH] fix(codegen): write prettier-stable schema snapshot (#43985) --- packages/core/script/migration.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/core/script/migration.ts b/packages/core/script/migration.ts index 4f6f4270efc..582f9abbc8d 100644 --- a/packages/core/script/migration.ts +++ b/packages/core/script/migration.ts @@ -48,7 +48,7 @@ async function generate() { renderMigration(name, await Bun.file(path.join(incremental, name, "migration.sql")).text()), ), ) - await fs.copyFile(path.join(incremental, name, "snapshot.json"), snapshot) + await Bun.write(snapshot, await formatJson(await Bun.file(path.join(incremental, name, "snapshot.json")).text())) } await fs.mkdir(full) @@ -192,6 +192,19 @@ async function formatTypescript(input: string) { }) } +// Drizzle emits every array multi-line; format the snapshot so regeneration +// diffs stay minimal against the prettier-styled checked-in copy. +async function formatJson(input: string) { + const prettier = await import("prettier") + const babel = await import("prettier/plugins/babel") + const estree = await import("prettier/plugins/estree") + return prettier.format(input, { + parser: "json", + plugins: [babel.default, estree.default], + printWidth: 120, + }) +} + function renderRegistry(names: string[]) { return `import type { DatabaseMigration } from "./migration.js" ${names.map((name, index) => `import m${index.toString().padStart(2, "0")} from "./migration/${name}.js"`).join("\n")}