From 2485f8d88ce3300c82ad3ff58ae4d4906686409d Mon Sep 17 00:00:00 2001 From: jinzelin Date: Wed, 27 May 2026 15:03:47 +0800 Subject: [PATCH] fix(schema): preserve YAML formatting when forking a schema Use yaml's Document API (parseDocument + doc.set) instead of round -tripping through parseSchema/stringifyYaml so block scalars, comments and key order in the source schema.yaml survive the fork --- src/commands/schema.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/commands/schema.ts b/src/commands/schema.ts index 7f8d0b788..04e3d4eb2 100644 --- a/src/commands/schema.ts +++ b/src/commands/schema.ts @@ -2,7 +2,7 @@ import { Command } from 'commander'; import * as fs from 'node:fs'; import * as path from 'node:path'; import ora from 'ora'; -import { stringify as stringifyYaml } from 'yaml'; +import { stringify as stringifyYaml, parseDocument } from 'yaml'; import { getSchemaDir, getProjectSchemasDir, @@ -625,10 +625,10 @@ export function registerSchemaCommand(program: Command): void { // Update name in schema.yaml const destSchemaPath = path.join(destinationDir, 'schema.yaml'); const schemaContent = fs.readFileSync(destSchemaPath, 'utf-8'); - const schema = parseSchema(schemaContent); - schema.name = destinationName; - fs.writeFileSync(destSchemaPath, stringifyYaml(schema)); + const doc = parseDocument(schemaContent); + doc.set('name', destinationName); + fs.writeFileSync(destSchemaPath, doc.toString()); if (spinner) spinner.succeed(`Forked '${source}' to '${destinationName}'`);