Skip to content

Commit 4745468

Browse files
emilyoramjwulf
authored andcommitted
fix: harden README code injection
- Upgrade snippet markers to descriptive format showing source file and regions - Move 5 un-injected examples into compilable snippets in examples/readme.ts - Add exempt markers for blocks using external deps (cockatiel, fp-ts, pino, winston, loglevel) - Detect un-injected TS/JS code blocks during sync - Add CI step for README snippet checking - Build scripts now use --check mode (fail on drift) Closes #87
1 parent e8fc7e0 commit 4745468

File tree

5 files changed

+292
-68
lines changed

5 files changed

+292
-68
lines changed

.github/copilot-instructions.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ NODE`
122122
- the generator version (`@hey-api/openapi-ts`)
123123
- and open an issue upstream or pin a known-good generator version.
124124

125+
## Pre-push checklist
126+
127+
Before pushing any commits, **always** run `npm run build:local` (or `npm run build` if the upstream spec may have changed). This:
128+
129+
1. Regenerates `src/gen/` from the bundled spec
130+
2. Syncs README code snippets from `examples/readme.ts` (fails if out of sync)
131+
3. Runs all unit tests
132+
4. Produces the `dist/` output
133+
134+
If the build modifies any files (e.g. README snippet drift, generated code changes), commit those changes before pushing.
135+
125136
## README Code Examples
126137

127138
Code blocks in `README.md` are **injected from compilable example files** — do not edit them inline.
@@ -133,14 +144,17 @@ Code blocks in `README.md` are **injected from compilable example files** — do
133144
### How it works
134145

135146
1. Wrap code in `examples/readme.ts` with `//#region RegionName` / `//#endregion RegionName` tags.
136-
2. In `README.md`, place `<!-- snippet:RegionName -->` immediately before the fenced code block.
147+
2. In `README.md`, place a snippet marker immediately before the fenced code block:
148+
- New format: `<!-- snippet-source: examples/readme.ts | regions: RegionName -->`
149+
- Legacy format `<!-- snippet:RegionName -->` is auto-migrated on sync.
137150
3. Run `tsx scripts/sync-readme-snippets.ts` to update README.
138-
4. Composite regions: `<!-- snippet:A+B -->` concatenates regions A and B separated by a blank line.
151+
4. Composite regions: `regions: A+B` concatenates regions A and B separated by a blank line.
152+
5. Blocks using external deps or pseudo-code that can't be type-checked: mark with `<!-- snippet-exempt: reason -->`.
139153

140154
### Adding or updating a README example
141155

142156
1. Add/edit the region-tagged code in `examples/readme.ts`.
143-
2. Add/verify the `<!-- snippet:RegionName -->` marker in `README.md`.
157+
2. Add/verify the `<!-- snippet-source: ... -->` marker in `README.md`.
144158
3. Run `tsx scripts/sync-readme-snippets.ts` to sync.
145159

146160
**Never edit a snippet-marked code block directly in README.md** — it will be overwritten on the next sync.

0 commit comments

Comments
 (0)