Skip to content

feat(docs): invoke docs({ plugins }) - #164

Merged
captjt merged 2 commits into
mainfrom
feat/docs-plugins-hook
Sep 25, 2026
Merged

captjt merged 2 commits into
mainfrom
feat/docs-plugins-hook

Conversation

@captjt

@captjt captjt commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

What

@eqtylab/docs 0.4.0 declares a plugins option and exports the DocsPlugin / DocsPluginContext types, but nothing ever calls a plugin's setup. A consumer that passes plugins: [...] gets a build that silently registers nothing. This wires the hook up.

Why

We hit this while moving the Guardian docs (eqtylab/governance-platform-docs) onto the framework. Its API reference is written as a DocsPlugin, and the only way to run it today is a small adapter that calls setup from an ordinary Astro integration. That works, but an option that is accepted and ignored is a trap for the next consumer, and the extension point is the right home for generated sections that the framework does not ship itself (changelogs, CLI references, and so on).

This is independent of the native OpenAPI work in #158 → #160, which takes the content-collection route rather than the plugin hook; the two merge cleanly (checked with git merge-tree against feat/mic-73-openapi-pages). Once that chain lands, Guardian will drop its own plugin in favour of the built-in pages, and this hook remains for everything else.

Changes

  • src/internal/run-plugins.ts (new): validates plugins entries, runs each setup in order inside astro:config:setup with the raw hook params as ctx.astro, and collects contributions. Runs after the framework has planned its own routes and before the runtime payload is sealed.
  • addNavGroup groups are appended to sidebar.extra, so they reach the runtime through the existing config virtual module.
  • addMdxComponents now takes module specifiers (Record<string, string>), served through a new virtual:eqty-docs/plugin-components module that mdx-components.ts spreads in last. A component object cannot cross into the runtime, which loads from node_modules, so passing one fails with a message naming the plugin and the component. This narrows the previously unknown-typed map; nothing could have used it before.
  • Types injected for the new virtual module; README gains a "Plugins" section; CHANGELOG has an Unreleased entry.

Verification

  • 5 new tests in tests/plugins.test.ts (ordering, replacement, error paths, virtual-module source); pnpm --filter @eqtylab/docs test passes all 108 docs tests. Lint, format check and pnpm --filter @eqtylab/docs build pass.
  • End to end: packed this branch, installed it into the Guardian docs checkout, and built that site with docs({ plugins: [openApiPlugin(...)] }) instead of the adapter. The plugin logged as registered through the hook and the build emitted the same 241 pages, including all 143 operation pages with correct sidebar state.

🤖 Generated with Claude Code

0.4.0 declared the `plugins` option and the `DocsPlugin` type but never
called a plugin's `setup`, so a consumer generating a section (an OpenAPI
reference, say) had to run it from `integrations` instead.

`setup` now runs inside `astro:config:setup`, after the framework has planned
its own routes and before the runtime payload is sealed. `addNavGroup` groups
land in `sidebar.extra`; `addMdxComponents` entries are module specifiers,
served through a new `virtual:eqty-docs/plugin-components` module that the
route-level component map spreads in last. A component cannot be passed as an
object, because the runtime loads from node_modules and imports what the
virtual module names; passing one fails with a message naming the plugin, as
does a malformed `plugins` entry.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@captjt
captjt requested review from Shrinks99 and matthewmr-eqty and removed request for matthewmr-eqty September 24, 2026 20:38
@captjt captjt self-assigned this Sep 24, 2026

@matthewmr-eqty matthewmr-eqty left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, glad the plugins actually run now. I haven't run my OpenAPI pages against the Guardian specs yet, so looking forward to comparing the two.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@captjt
captjt merged commit 0082b29 into main Sep 25, 2026
1 check passed
@captjt
captjt deleted the feat/docs-plugins-hook branch September 25, 2026 12:48
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