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 svelte2tsx and the TypeScript compiler API to resolve types, track exports, and extract semantic details. The npm package has a Vite plugin, CLI, and programmatic API.

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, mainly the API reference, with fuz_ui components.

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

This is an early release. There are gaps to fill and design choices still open, but Svelte 5 coverage seems good and it's used in production websites. Please open issues for bugs, and discussions for everything else!

AI disclosure: the code and docs beyond the intro were written by Claude Code with uneven human guidance.

Install
#

Published as svelte-docinfo to npm:

npm install svelte-docinfo -D

Usage
#

The tool's main function is outputting JSON, and there are several integration paths, in rough order from most opinionated to most flexible:

For SvelteKit and Vite projects, the Vite plugin is the recommended path. It runs the analysis at build time and serves the result as a virtual module with HMR:

import {modules} from 'virtual:svelte-docinfo';

Run the CLI to inspect a project from the command line:

# Analyze the current project and print JSON to stdout npx svelte-docinfo # Analyze a specific directory and write to a file npx svelte-docinfo ./packages/my-lib -o docs/library.json

For standalone use or custom build tools, two functions cover most cases. analyzeFromFiles handles file discovery automatically:

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

If your build tool already has file contents in memory, use analyze directly to skip file discovery. See the build tools guide for the full integration surface:

import {analyze, createSourceOptions} from 'svelte-docinfo'; const {modules} = await analyze({ sourceFiles: [{id: '/path/to/file.ts', content: '...'}], sourceOptions: createSourceOptions('/project'), });

For long-lived consumers (Vite plugin, LSP-style tools) that re-analyze the same source set repeatedly, createAnalysisSession returns a persistent handle backed by a TypeScript LanguageService. Parsed ASTs and svelte2tsx output are reused across calls. The one-shot analyze and analyzeFromFiles are thin wrappers over single-use sessions. See the session guide for the full incremental API.

See the API reference for all exported functions and types.

Not supported
#

A few constructs are silently skipped: standalone namespace Foo {} declarations (namespace re-exports are supported), decorators, and per-parameter doc fields beyond @param descriptions. ParameterJson deliberately doesn't carry @example/@deprecated/@since/@see/@throws. Per the TSDoc spec, those tags are scoped to the function symbol and live on the parent declaration.

Key features
#

  • full type resolution: infers complex types without manual annotations, including generics, imported types, and inferred return types, with source locations for every declaration
  • TSDoc/JSDoc parsing: extracts standard tags (@param, @returns, @example, @deprecated, etc.) plus @nodocs to exclude from docs and @mutates to flag side effects
  • Svelte 5 components: analyzes components via svelte2tsx, extracting prop types, defaults, bindability, snippet parameters, children detection, and exported template snippets
  • Svelte 5 reactivity runes: detects $state, $state.raw, $derived, and $derived.by on variables and class fields and exposes them via the reactivity field. Detection is syntactic, so the same patterns can be captured in any analyzed file
  • re-export tracking: alsoExportedFrom arrays, aliasOf for renames, default-slot entries named "default", and export * from patterns
  • dependency graphs: tracks imports between modules and computes dependents
  • function overloads: captures all public overload signatures with per-overload JSDoc
  • build-tool agnostic: works with any source: file system, build pipeline, or in-memory
  • diagnostic collection: accumulates warnings and errors without halting, so you can report problems in batch

Compared to sveld
#

svelte-docinfo is largely inspired by sveld, 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 without requiring @type annotations. It also analyzes TypeScript modules, not just .svelte files.

svelte-docinfo additionally tracks re-exports across modules, computes dependency graphs, and records source locations. It does not currently support Svelte 4 features like legacy slots, dispatched events, or the context API. Svelte 5 replaces most of these with snippets and callback props.