Skip to content

chore: make docgen examples pass under @effect/docgen 0.5 and 4.x - #97

Merged
thomasfosterau merged 1 commit into
trunkfrom
issue-62-docgen-explicit-assert
Oct 14, 2026
Merged

thomasfosterau merged 1 commit into
trunkfrom
issue-62-docgen-explicit-assert

Conversation

@thomasfosterau

@thomasfosterau thomasfosterau commented Oct 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

Part of #62. This gets trunk ready for Dependabot #88 (effect 4.0.4, @effect/docgen 0.5.2 → 4.0.4), so #88 goes green once it is rebased onto trunk. The PR stays on docgen 0.5.2 and passes under both versions. #88 itself is not touched.

Root cause of #88's red "Verify documentation examples (docgen)" step (Cannot find name 'assert' at lines 24 and 31 of the generated validateRegistry example). Docgen 0.5.2's addAssertImport prepends import * as assert from 'assert' to any example whose text contains assert. (the bin.cjs of npm pack @effect/docgen@0.5.2). Docgen 4.0.4's Core.ts has no such injection.

Changes:

  • packages/pulpit/src/registry.ts: the validateRegistry example now does import { throws } from "node:assert" and calls throws(…). It has to be a named import. A namespace import * as assert from "node:assert" fails under 0.5.2 with TS2300: Duplicate identifier 'assert', because it collides with the injected import (tested). With the named import, the example never contains assert., so 0.5.2 injects nothing, and 4.x has the import it needs.
  • packages/pulpit/docgen.json: adds "runExamples": true. Docgen 0.5.2 always executed examples after type-checking them. Docgen 4.0.4 only type-checks them unless runExamples is set (Config.Boolean("runExamples") defaults to false; its log says "Skipping running examples"). Without this setting, chore: Bump the effect group across 1 directory with 3 updates #88 would go green but would quietly stop executing examples. 0.5.2 ignores the key and always runs examples (verified in review: "runExamples": false still executes them), so nothing changes on trunk. Until chore: Bump the effect group across 1 directory with 3 updates #88 lands, editors may flag the key against 0.5.2's schema.json (additionalProperties: false); docgen itself accepts it.
  • AGENTS.md: the @example bullet no longer says assert.… gets node:assert imported for you. It now says to import assertion functions by name and explains why.

Left for after #88 merges (owner decision on #62: follow-ups go in a separate PR), filed as #96:

  • remove "@effect/docgen>typescript": "6" from peerDependencyRules, and its comment. On chore: Bump the effect group across 1 directory with 3 updates #88 + this PR with the entry removed, pnpm install left the lockfile unchanged, and a clean pnpm install --frozen-lockfile printed no peer warning. 4.0.4's typescript >=5.8.2 <7.0.0 peer accepts the TS6 alias.
  • reword the @effect/docgen catalog comment. 4.x parses with ts-morph + tsconfck and no longer uses a bundled TypeScript 5.5.
  • update the AGENTS.md docgen bullet to describe 4.x only. That means dropping the 0.5 assert-injection half, "TypeScript 5.5 bundled in its own bin", and "docgen rewrites to src/". 4.x does no rewriting: the package name resolves through its own exports, which point at src/.

Verification

On this branch (trunk + this PR, @effect/docgen 0.5.2), clean tree (rm -rf node_modules packages/*/node_modules tests/*/node_modules && pnpm install --frozen-lockfile):

  1. vp check: pass (0 errors; 46 warnings, all already on trunk)
  2. vp run check: pass
  3. vp run -r test:unit: pass
  4. vp run -r build: pass
  5. vp run -r docgen: pass (type-checks and runs the example)
  6. pnpm audit --audit-level high: pass (1 moderate, below the threshold)
  7. fallow audit --base origin/trunk: pass ("No issues in 3 changed files")
  8. fallow audit --format json --quiet --explain --gate-marker agent: verdict pass

On #88's head (8fc4f55, docgen 4.0.4) with this PR cherry-picked on top (local only, not pushed): vp check, vp run check, vp run -r test:unit, vp run -r build, vp run -r docgen ("Typechecking examples..." → "Running examples..." → "✓ Docs generation succeeded!") and pnpm audit --audit-level high all pass.

Negative controls:

Changeset

  • none needed, because this changes tooling config, docs and the text of one JSDoc @example; the published package's behaviour is unchanged

Notes

🤖 Generated with Claude Code

https://claude.ai/code/session_01MbvVf1RHTwKCbEw9dyn3Aa


Generated by Claude Code


Generated by Claude Code

Import `throws` from node:assert by name in the validateRegistry example
instead of relying on docgen 0.5's injected `assert` namespace, which
docgen 4.x no longer adds (the "Cannot find name 'assert'" failure on
the effect-group bump). A named import compiles under both: 0.5 only
injects when an example contains `assert.`, and a namespace import of
our own would collide with that injection.

Set `runExamples: true` in docgen.json: 0.5 always executed examples,
4.x only type-checks them unless asked to run.

Part of #62

Claude-Session: https://claude.ai/code/session_01MbvVf1RHTwKCbEw9dyn3Aa
Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants