mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-24 22:23:34 +00:00
fix(codegen): write prettier-stable schema snapshot (#43985)
This commit is contained in:
parent
771c0f5850
commit
9e50d76416
1 changed files with 14 additions and 1 deletions
|
|
@ -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")}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue