Repository navigation
refactor: replace gray-matter with an in-house frontmatter splitter - #3947
Merged
Merged
Conversation
gray-matter 4.0.3 has not been published since 2023-07 and needed a local pnpm patch to drop its eval-based JavaScript engine, a patch that never reaches installed copies of rulesync. Frontmatter is now split in src/utils/frontmatter.ts with the same grammar gray-matter used (BOM, `----` rule, fence language, first `\n---` closes the block, one line break dropped after it), and the YAML is still parsed and dumped with js-yaml 4, now a direct dependency under the `js-yaml-v4` alias, so every file reads and writes exactly as before. js-yaml 5 is stricter (it rejects a flow list whose closing `]` sits at column 0) and drops v4's timestamp/merge/binary tags, so it is not used for frontmatter. Removes gray-matter and its transitive deps (section-matter, strip-bom-string, extend-shallow, is-extendable, kind-of), the gray-matter patch and its js-yaml override. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
…n the split block - Replace gray-matter's `/^\s*#[^\n]+/gm` blank-block check with a line-by-line test; its `\s*` spans line breaks and backtracked quadratically (about 10 s on 65k blank lines). - Apply the raw size guard to the block splitFrontmatter returns, so a whitespace-only fence language or a file with no line break can no longer hand the parser more than MAX_FRONTMATTER_RAW_CHARS. - Pin the js-yaml 4 folding of long unbreakable values, an unclosed language fence and a null block with tests. - Correct comments: gray-matter ran on js-yaml 4 only in this repository and the release binaries, and the factorydroid strip keeps skill metadata out of the check body rather than out of its frontmatter. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
…mments Also relax the linear-time assertion to 3 s to keep it stable on loaded CI. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
Owner
Author
|
@dyoshikawa Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces
gray-matterwith a small in-house frontmatter splitter insrc/utils/frontmatter.ts.Why:
gray-matter4.0.3 was last published in 2023-07.eval()-based JavaScript engine. pnpm patches and overrides only apply inside this repository, so installed copies of rulesync ran unpatched gray-matter on js-yaml 3. The language check and the engine override infrontmatter.tswere what actually protected users.section-matter,strip-bom-string,extend-shallow,is-extendableandkind-of.What changed
parseFrontmattersplits the file using gray-matter's grammar. The rules:----line is a horizontal rule, not a fence;\n---closes the block;stringifyFrontmatterwrites---\n<yaml>\n---\nfollowed by the body with a trailing newline. An empty mapping writes the body alone, as gray-matter did.js-yaml-v4(npm:[email protected], still maintained, already in the lockfile through secretlint). Minimal typings are insrc/types/js-yaml-v4.d.ts. TheavoidBlockScalarspath keeps using js-yaml 5, as it did before. js-yaml 5 is not used for frontmatter parsing because:]sits at column 0 (covered by an existing Trae test) fails withdeficient indentation.timestamp,mergeandbinarytags;/^\s*#[^\n]+/gmbacktracked quadratically (about 10 s on 65k blank lines). It is now a line-by-line check. The one known difference: a lone\rnow ends a comment line, as it does in YAML.patches/[email protected], thegray-matter>js-yamloverride and thepatchedDependenciesentry.trae-rule.ts,factorydroid-check.tsandcontent-equivalence.tsthat referred to gray-matter now refer toparseFrontmatter.Verification
pnpm cicheckpasses: 17266 tests, with lint, typecheck, cspell and secretlint clean.main, with gray-matter installed) against the new one:.md/.mdcfile in the repository and innode_modules(986 files) plus about 35 edge cases (BOM, CRLF,---yaml,----, unclosed fences,!!binary,!!set, merge keys, complex keys, dates, a column-0], octal);<<,!!binary, complex keys).gray-mattermodule mock.Note for npm users
Installed rulesync previously parsed frontmatter with js-yaml 3, because the repository's override does not ship. It now uses js-yaml 4 everywhere, matching what the repository and the release binaries already used. The only difference observed between the two versions is how octal-looking scalars are read:
012and0o12.🤖 Generated with Claude Code
https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4