CLI #

Run in a project with TypeScript or Svelte source and a tsconfig.json at or above its root (or pass --no-tsconfig). The CLI runs analyzeFromFiles once and prints the JSON to stdout.

Basic usage
#

npx svelte-docinfo # analyze the current directory npx svelte-docinfo ./packages/my-lib # analyze a specific directory npx svelte-docinfo -o output.json # write to a file instead npx svelte-docinfo --pretty # pretty-print the JSON output

It documents the files package.json exports point to, falling back to everything under src/lib; source files covers the flags that change that.

Output is compact: empty arrays and false flags are omitted, so treat absent as empty, or parse with parseAnalyzeResult. It pairs well with jq:

npx svelte-docinfo | jq '.modules | length' # count modules npx svelte-docinfo | jq -r '.modules[].declarations[].name' # list all exported names

JSON goes to stdout and messages go to stderr, so > and | capture clean JSON. -q silences info messages; warnings and errors still print.

Options
#

FlagDescription
[project-root]project root directory (default: cwd)
-i, --include <pattern>include pattern (repeatable). Replaces exports discovery and widens the source scope (see below); incompatible with --discovery exports
-e, --exclude <pattern>exclude glob, applied at discovery and analysis (repeatable). Replaces the defaults **/*.{test,spec}.{ts,mts,tsx,js,mjs,jsx}, **/internal/** entirely
-o, --output <file>output file (default: stdout; - also means stdout, so -o "$OUT" works when $OUT=-)
--discovery <mode>auto | exports | glob (default: auto: exports first, glob fallback). exports fails when package.json exports is missing or resolves to no files
--dist-dir <dir>dist directory for exports discovery (default: dist)
--source-dir <dir>source directory, relative to the project root or absolute inside it (default: src/lib). Repeatable; also sets the default include glob
--source-root <dir>base of output module paths (default: single source dir or longest common prefix; . for project-relative)
--only <pattern>glob filter on output module paths (repeatable). The full project is still analyzed, so re-exports and dependents stay correct; diagnostics aren't filtered
--no-resolve-dependenciesdisable dependency resolution (dependencies/dependents stay empty)
--tsconfig <path>path to the tsconfig, relative to the project root and searched upward from it (default: tsconfig.json)
--no-tsconfiganalyze without a tsconfig, using built-in strict compiler options
--prettypretty-print JSON output (default: compact)
-q, --quietsuppress info messages on stderr (warnings and errors still print)
--on-duplicates <mode>opt-in check that names are unique across modules, for packages with a flat export namespace: diagnostic | warn | throw (default: off)
-V, --versionshow version number
-h, --helpshow help

--include, --exclude, --source-dir, and the discovery and tsconfig flags work as source files describes. --exclude always replaces the defaults; there's no form that extends them.

Exit codes: 0 success, 1 analysis errors, 2 CLI errors (an unknown flag, a missing or invalid option value) or a thrown analysis error (a missing or unloadable tsconfig.json, strict exports discovery failing).

To use the data in a SvelteKit or Vite app, see the Vite plugin; from code, the JS API.