Add sync-snippets script for type-checked examples
#1487
+1,367
−164
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.
JSDoc
@examplecode blocks were previously inlined and not type-checked, meaning they could silently drift from the actual API. This adds ascripts/sync-snippets.tsscript (pnpm sync:snippets) that extracts code from co-located.examples.tsfiles — using//#regionmarkers — and syncs them into JSDoc@examplefences and markdown files.The script supports a
--checkmode (wired intolint:all) to catch drift in CI. Code fences use asource="./file.examples.ts#regionName"attribute to reference their source of truth.The
sync-snippets.tsscript is mostly copied from https://github.com/modelcontextprotocol/ext-apps/blob/main/scripts/sync-snippets.ts, which has been working well for us.Note that the script is configured to run as part of
pnpm run lint:allandpnpm run lint:fix:all. The idea being that syncing code snippets is akin to applying linter / formatting rules. Is that acceptable?