introduction #

svelte-docinfo extracts JSON describing the exports of TypeScript and Svelte modules for open-ended use cases like docs, code search, and dev tools. It uses the TypeScript compiler API and svelte2tsx to resolve types, track exports+imports, and extract semantic details.

svelte-docinfo is largely inspired by sveld, but uses the TypeScript compiler API instead of AST-only inspection, and also analyzes TypeScript modules. See the comparison below.

The library is mostly complete for Svelte 5 and used in production websites, but you may find gaps and flaws -- please open issues for bugs, and discussions for everything else!

Dependencies are minimal and the tool's scope is limited to data, not presentation. These docs were made using the data produced by svelte-docinfo, like the architecture and API reference, with fuz_ui components.

AI disclosure: the code and docs beyond the intro were mostly written by Claude Code with uneven human guidance. The first release took 5 months of intermittent work and ~500 manual commits to extract its initial implementation from fuz_ui, which was more limited, lacking the fancy TS compiler usage, and grew slowly over years without AI assistance.

Install
#

npm i -D svelte-docinfo

Peer dependencies: svelte 5+, svelte2tsx, and typescript 5.9+ or 6, plus vite 6+ for the Vite plugin.

Three ways to use it
#

All three run the same analysis and produce the same data, AnalyzeResultJson: {modules, diagnostics}.

Vite plugin
#

For SvelteKit and Vite projects, the Vite plugin analyzes at build time and serves the result as a virtual module that stays current in dev:

// vite.config.ts import {defineConfig} from 'vite'; import {sveltekit} from '@sveltejs/kit/vite'; import svelteDocinfo from 'svelte-docinfo/vite.js'; export default defineConfig({plugins: [sveltekit(), svelteDocinfo()]}); // anywhere in your app import {modules} from 'virtual:svelte-docinfo';

CLI
#

The CLI inspects a project, writes a JSON file, or feeds a shell pipeline:

npx svelte-docinfo --pretty -o library.json

JS API
#

The JS API serves scripts and build tools: analyzeFromFiles finds the files itself, analyze takes contents you already have, and createAnalysisSession re-analyzes incrementally.

import {analyzeFromFiles} from 'svelte-docinfo'; const {modules, diagnostics} = await analyzeFromFiles({projectRoot: process.cwd()});

By default all three document the source files your package.json exports point to, falling back to everything under src/lib; see source files. The output format reference shows the JSON.

What it extracts
#

  • every export of every documented module, with the checker's types (generics, imported and inferred types, no annotations needed), docs, and source lines
  • TSDoc and JSDoc tags, plus @nodocs to leave a declaration out and @mutates for side effects
  • structured types: typeInfo trees beside the flat type strings, recovering alias names TypeScript drops (z.infer, v.InferOutput)
  • Svelte 5 components: props with types, defaults, and bindability, snippet and callback parameters, generics, children, exported snippets, and runes ($state, $derived) in any file
  • component styling: the CSS custom properties a component's styles read, plus those documented with @cssprop
  • JS modules documented like their TS twins, from JSDoc types, @typedefs, @templates, and @overloads
  • re-exports and the import graph between modules
  • diagnostics collected without halting, for doc problems like misplaced tags and stale @params

Limitations
#

  • Svelte 4 named slots, slot props, and events aren't modeled, nor context (setContext); a request would bump context's priority. Legacy export let components document their props.
  • Standalone namespace Foo {} declarations document as a bare variable (export * as ns works), and decorators aren't modeled.
  • CommonJS isn't modeled (see CommonJS).

Compared to sveld
#

sveld is a Svelte component documentation generator that walks the AST and infers types from JSDoc annotations and literal values. svelte-docinfo instead uses the TypeScript compiler API (via svelte2tsx) as its source of truth, so it resolves imported types, generics, and complex inferred types in TypeScript components without @type annotations. It also analyzes TypeScript modules, not just .svelte files, tracks re-exports across modules, computes dependency graphs, and records source locations.