Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/serialize-node-materials.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@design-intelligence/ghost": patch
---

serializeNode preserves the materials frontmatter field instead of dropping it.
5 changes: 3 additions & 2 deletions packages/ghost/src/ghost-core/node/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import type { GhostNodeDocument, GhostNodeFrontmatter } from "./types.js";

/**
* Serialize a node back to its `---\n<yaml>\n---\n<body>` markdown form. Keys
* are emitted in a stable order (description) so round-trips and diffs are
* deterministic. Identity and kind are not serialized — they come from the
* are emitted in a stable order (description, materials) so round-trips and
* diffs are deterministic. Identity and kind are not serialized — they come from the
* node's file path and optional filename prefix. Undefined fields are omitted; a node
* with no frontmatter fields emits an empty block.
*/
export function serializeNode(node: GhostNodeDocument): string {
const fm = node.frontmatter;
const ordered: Record<string, unknown> = {};
if (fm.description !== undefined) ordered.description = fm.description;
if (fm.materials !== undefined) ordered.materials = fm.materials;

// An empty frontmatter object stringifies to "{}"; emit a bare block instead.
const yaml =
Expand Down
17 changes: 17 additions & 0 deletions packages/ghost/test/ghost-core/node-schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ describe("ghost.node/v1 schema", () => {
expect(reparsed.node?.body).toBe(original.body);
});

it("round-trips materials frontmatter through serialize/parse", () => {
const original: GhostNodeDocument = {
frontmatter: {
description: "Checkout trust signals.",
materials: [
"src/components/checkout/**",
"https://example.com/logo.svg",
],
},
body: "Near payment, reduce felt risk.",
};
const reparsed = parseNode(serializeNode(original));
expect(reparsed.report.errors).toBe(0);
expect(reparsed.node?.frontmatter).toEqual(original.frontmatter);
expect(reparsed.node?.body).toBe(original.body);
});

it("round-trips an empty-frontmatter node", () => {
const original: GhostNodeDocument = {
frontmatter: {},
Expand Down
Loading