cli #

Run in a project with TypeScript or Svelte source and a tsconfig.json at or above its root. The CLI prints JSON describing the 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

Files are discovered from package.json exports, falling back to glob. -i supplies explicit patterns, --discovery glob skips exports, and --discovery exports fails when exports is missing or resolves to no files.

--source-dir sets the source directory (default src/lib, repeatable for monorepos). --source-root sets the base of output module paths (default: the single source dir, or the longest common prefix of several).

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 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.ts, **/*.spec.ts, **/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)
--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

--include patterns widen the source scope: each pattern's static base joins the source dirs, and module paths become relative to the widened root. A pattern with no base (**/*.ts, a root file) makes the whole project root source and logs an info line.

Regardless of --exclude, 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 discovery also skips subpaths blocked by null exports entries ("./internal/*": null), using Node's best-match rules.

Absolute paths and patterns inside the project root are accepted; ones outside it are an error.

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

For SvelteKit and Vite projects where the analysis feeds into your app bundle, see the Vite plugin.