cli #
Run in any directory with TypeScript or Svelte source files. Prints JSON describing your project's exports 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 Discovery defaults to package.json exports, falling back to glob. -i forces explicit patterns; --discovery glob skips exports; --discovery exports is strict (fails when exports is missing).
--source-dir sets the source directory (default src/lib,
repeatable for monorepos) and seeds the implicit include glob. --source-root controls module-path stripping in the output (defaults to the
single --source-dir or their longest common prefix).
Compact JSON 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; info, warnings, and errors go to stderr, so the terminal interleaves
them, but > and | capture clean JSON. -q/--quiet silences info; warnings and errors still print.
Options #
| Flag | Description |
|---|---|
[project-root] | project root directory (default: cwd) |
-i, --include <pattern> | include pattern (repeatable, replaces exports discovery, widens the source scope — see the note below) |
-e, --exclude <pattern> | exclude glob, applied at discovery and analysis (repeatable; fully replaces the
defaults **/*.test.ts, **/*.spec.ts, **/internal/** — no merge; the always-on baseline below applies beneath) |
-o, --output <file> | output file (default: stdout; pass - for explicit stdout, so -o "$OUT" works when $OUT=-) |
--discovery <mode> | auto | exports | glob (default: auto: exports first, glob fallback). exports is strict and fails
when package.json exports is missing. |
--dist-dir <dir> | dist directory for exports discovery (default: dist) |
--source-dir <dir> | source directory, relative to project root or absolute inside it (default: src/lib). Repeatable for monorepos; also seeds the implicit include glob. |
--source-root <dir> | source root for module-path stripping (default: single source-dir or longest common prefix) |
--on-duplicates <mode> | dispatch on duplicate declaration names: throw | warn (default: emit duplicate_declaration diagnostic, no dispatch) |
--only <pattern> | glob filter applied to module paths in output (repeatable). Full project is still analyzed (re-exports/dependents stay correct); diagnostics aren't filtered |
--no-resolve-dependencies | disable dependency resolution |
--pretty | pretty-print JSON output (default: compact) |
-q, --quiet | suppress info messages on stderr (warnings and errors still print) |
-V, --version | show version number |
Explicit --include patterns widen the source scope: each pattern's static base
joins the source paths, so module paths become relative to the widened root, and a pattern
with no base (**/*.ts, a literal root file) scopes the whole project root as
source and logs an info line. Beneath any --exclude, an always-on baseline
applies: node_modules and dot-directories below a source dir are never source.
The default excludes cover tests and the src/lib/internal/ convention (**/internal/**); exports-based discovery additionally honors null-target exports keys ("./internal/*": null) with Node's
best-match resolution, so blocked subpaths are never discovered. Absolute paths and patterns
inside the project root are accepted (relativized); out-of-root ones fail loudly instead of
silently emitting nothing.
Exit codes: 0 success, 1 analysis errors, 2 CLI errors.
For SvelteKit and Vite projects where the analysis feeds into your app bundle, see the Vite plugin.