diff --git a/.changeset/curly-lions-cheer.md b/.changeset/curly-lions-cheer.md new file mode 100644 index 0000000..7f9a267 --- /dev/null +++ b/.changeset/curly-lions-cheer.md @@ -0,0 +1,5 @@ +--- +"@neuledge/context": patch +--- + +Ignore non-string `title`/`description` frontmatter values when parsing docs. Previously a frontmatter field that parsed to a non-string (e.g. an object) propagated into the document title and broke package building with "Too few parameter values were provided". Such values now fall back to the derived title instead of crashing the build. diff --git a/packages/context/src/build.test.ts b/packages/context/src/build.test.ts index a0f7841..2e8cb9f 100644 --- a/packages/context/src/build.test.ts +++ b/packages/context/src/build.test.ts @@ -27,6 +27,27 @@ Install the package. expect(result.frontmatter.description).toBe("Learn how to get started"); }); + it("ignores non-string frontmatter title (malformed YAML)", () => { + // Svelte 5's docs use unquoted titles like `{let/const ...}` that YAML + // parses into an object, which must not leak into docTitle (it would break + // SQLite parameter binding with "Too few parameter values were provided"). + const source = `--- +title: {let/const ...} +--- + +## Declaration tags + +Some content about declaration tags. +`; + + const result = parseMarkdown(source, "docs/declaration-tags.md"); + + expect(result.frontmatter.title).toBeUndefined(); + // docTitle falls back to the filename-derived title + expect(typeof result.sections[0]?.docTitle).toBe("string"); + expect(result.sections[0]?.docTitle).toBe("declaration-tags"); + }); + it("chunks content by h2 sections", () => { const source = `--- title: Routing diff --git a/packages/context/src/build.ts b/packages/context/src/build.ts index 1651c44..96fceee 100644 --- a/packages/context/src/build.ts +++ b/packages/context/src/build.ts @@ -141,7 +141,15 @@ function extractFrontmatter(tree: Root): DocFrontmatter { if (!yamlNode) return {}; try { - return parseYaml(yamlNode.value) as DocFrontmatter; + // Validate types rather than blindly casting: malformed frontmatter can + // parse title/description into non-strings (e.g. a bare value the YAML + // parser reads as a map), which later breaks SQLite parameter binding. + const data = parseYaml(yamlNode.value) as Record | null; + return { + title: typeof data?.title === "string" ? data.title : undefined, + description: + typeof data?.description === "string" ? data.description : undefined, + }; } catch { return {}; }