source files #

Every analyzed file informs types, but only source files are documented, each as one ModuleJson: the files discovery finds that sit under the source paths (default src/lib) and match no exclude pattern. This page covers how files are found and scoped; the options are the same across the Vite plugin, the CLI (as flags), and the JS API.

Discovery
#

The discovery option picks how files are found:

  • 'auto' (default): from package.json exports, falling back to globs when there are none
  • 'exports': from exports only, throwing when they're missing or name no source files
  • 'glob': every module file under the source paths

Exports discovery maps each dist entry back to its source: a .js to the .ts, .tsx, .js, or .jsx beside it, in that order, and an .mjs to an .mts or .mjs. Wildcard entries ("./*.js") expand, and null entries ("./internal/*": null) block subpaths with Node's matching rules.

Modules are .svelte, .ts, .mts, .tsx, .js, .mjs, and .jsx files. Discovery also finds .css and .json files, which document as modules with no declarations. .cjs, .cts, and declaration files aren't analyzed.

include globs replace discovery (they collapse 'auto' to glob, and combining them with 'exports' throws). Each pattern's static base joins the source paths, so the files it finds are documented; a pattern with no base (**/*.ts) makes the whole project source.

Excluding files
#

exclude applies at discovery and analysis alike, so an excluded file is never documented however it was found. The default is ['**/*.{test,spec}.{ts,mts,tsx,js,mjs,jsx}', '**/internal/**']. An array replaces it, and a callback extends it:

exclude: (defaults) => [...defaults, '**/*.gen.ts']

The CLI's --exclude always replaces the defaults. Beneath any exclude, node_modules and dot-directories below a source path are never source; dist and build are ordinary names.

src/lib/internal/ holds modules that ship for public modules to import but aren't documented, usually paired with an "./internal/*": null exports entry. They still inform types, and in dev an edit to one re-analyzes the modules that use it. A public re-export of an internal symbol documents in full at the re-export. To document them anyway, drop the pattern: exclude: (defaults) => defaults.filter((p) => p !== '**/internal/**').

Source paths
#

sourceOptions.sourcePaths (CLI: --source-dir, repeatable) lists the source directories, and sourceRoot (--source-root) is the base of ModuleJson.path, by default the single source path or the common prefix of several. Pass '.' for project-relative paths.

import {createSourceOptions} from 'svelte-docinfo'; const sourceOptions = createSourceOptions(process.cwd(), { sourcePaths: ['packages/a/src', 'packages/b/src'], });

Paths and patterns are relative to the project root. Absolute ones inside it are accepted, and anything outside it throws when the options are created. '/src/lib' is a filesystem path, not shorthand for 'src/lib'.

tsconfig
#

Analysis runs with your project's compiler options, from tsconfig.json found at or above the project root (the tsconfig option, or --tsconfig, names another). The file and its whole extends chain must load, so a SvelteKit project needs svelte-kit sync first. tsconfig: false (--no-tsconfig) analyzes without one, under strict built-in options (DEFAULT_COMPILER_OPTIONS), and compilerOptions merge over either, key by key.

allowJs is always on, so JS modules document under any tsconfig (see JS and JSDoc).

Every file the tsconfig includes loads, which makes a cold start scale with the project. rootFileNames narrows that to the analyzed files and what they import; an ambient type declared in a file nothing imports then resolves to any, unless you keep the declaration files with the declarationFileRoots preset (see RootFileNames).