analyze.ts

One-shot analysis wrappers — analyze and analyzeFromFiles.

Both wrap a single-use AnalysisSession: `createAnalysisSession → setFiles → query → dispose`. Incremental consumers (Vite plugin, LSP) should use createAnalysisSession directly so parsed ASTs and svelte2tsx output survive between calls.

  • analyzeFromFiles — high-level: file discovery from disk + dependency resolution + analysis. Recommended for CLI / build-time generation.
  • analyze — mid-level: caller supplies SourceFileInfo[]. For build-tool integrations that own discovery but don't run incrementally.

see also

  • ``session.ts`` for the persistent session API

  • ``analyze-core.ts`` for the two-phase orchestrator

view source

Declarations
#

4 declarations

analyze
#

analyze.ts view source

also exported from index.ts

(options: AnalyzeOptions): Promise<AnalyzeResultJson> import {analyze} from 'svelte-docinfo/analyze.js';

Analyze library source files and extract metadata (one-shot).

Wraps a single-use AnalysisSession. For repeated analyses of the same source set (e.g., a Vite plugin reacting to file edits), use createAnalysisSession directly.

options

returns

Promise<AnalyzeResultJson>

analyzed modules (sorted alphabetically) + concatenated ingest + query diagnostics

throws

  • Error - if `sourceOptions` validation fails or the tsconfig is missing or can't be loaded (see `loadTsconfig`; `tsconfig: false` skips it). Also propagates `onDuplicates: 'throw'` errors.

analyzeFromFiles
#

analyze.ts view source

also exported from index.ts

(options: AnalyzeFromFilesOptions): Promise<AnalyzeResultJson> import {analyzeFromFiles} from 'svelte-docinfo/analyze.js';

Analyze a library from files on disk with automatic file discovery.

Recommended high-level API for one-shot use (CLI, build-time generation):

  1. Discovery — discoverSourceFiles (exports-first, glob fallback)
  2. Ingest — push discovered files into a single-use session
  3. Analysis — session.query()

options

returns

Promise<AnalyzeResultJson>

analyzed modules + concatenated ingest, discovery, and query diagnostics

throws

  • Error - on invalid or contradictory options, a missing or unloadable `tsconfig.json` (see `loadTsconfig`), failed strict `'exports'` discovery, or a collision under `onDuplicates: 'throw'`

AnalyzeFromFilesOptions
#

analyze.ts view source

also exported from index.ts

AnalyzeFromFilesOptions import type {AnalyzeFromFilesOptions} from 'svelte-docinfo/analyze.js';

Options for analyzeFromFiles.

see also

  • ``AnalyzeOptions`` for the build-tool-integration API where you supply sourceFiles and a fully-formed sourceOptions: ModuleSourceOptions directly.

projectRoot

Absolute path to project root directory.

type string

sourceOptions?

Partial overrides for default source options (SvelteKit src/lib layout).

type SourceOptionsOverrides

onDuplicates?

Opt-in check that declaration names are unique across modules (see OnDuplicates).

type OnDuplicates

log?

Optional logger for status and diagnostic messages.

type AnalysisLog

include?

Glob patterns to include, relative to projectRoot. Collapses discovery: 'auto' to glob (combining with 'exports' throws), and each pattern's static base widens sourceOptions.sourcePaths so the matched files emit modules (see createSourceOptionsWithInclude).

type string[]

exclude?

Glob patterns to exclude — supersedes sourceOptions.exclude whole (no merge; the callback form still receives the built-in defaults). An array replaces the defaults, a callback extends them — see ExcludeOption.

type ExcludeOption

resolveDependencies?

Whether to resolve import dependencies (default true).

When false, the session uses a no-op resolver that always returns null, so ModuleJson.dependencies / dependents stay empty. analyzeFromFiles's discovery layer does not pre-populate SourceFileInfo.dependencies, so the session's pre-resolved fast path isn't reachable through this API — to exercise it, drive analyze or createAnalysisSession directly with files whose dependencies field is already filled in by your build tool.

type boolean

default `true`

resolveImport?

Optional custom import resolver — a bare ResolveImportFn or a token-paired ImportResolver (see ResolveImport). One-shot use doesn't benefit from a stable cache identity, so the bare function form is the natural choice here; for long-lived consumers (Vite plugin, LSP) construct an ImportResolver with a stable identity and pass it via createAnalysisSession so cache hits survive across calls.

Cannot be combined with resolveDependencies: false — resolution is then off, so the resolver would never be consulted; passing both throws.

type ResolveImport

discovery?

Discovery strategy for source files.

type Discovery

default 'auto'

distDir?

Dist directory name for exports-based discovery.

type string

default 'dist'

tsconfig?

Path to the tsconfig, relative to the project root, or false to analyze without one (see LoadTsconfigOptions.tsconfig).

type string | false

default 'tsconfig.json'

compilerOptions?

Compiler options merged over the tsconfig's (see LoadTsconfigOptions.compilerOptions).

type CompilerOptions

rootFileNames?

Root files for the program in place of the tsconfig's (see RootFileNames).

type RootFileNames

default the tsconfig's roots

AnalyzeOptions
#

analyze.ts view source

also exported from index.ts

AnalyzeOptions import type {AnalyzeOptions} from 'svelte-docinfo/analyze.js';

Options for analyze.

Requires pre-loaded SourceFileInfo arrays — use analyzeFromFiles for automatic file discovery and loading from disk, or createAnalysisSession for incremental use.

sourceFiles

Source files to analyze (must have content loaded). Files outside sourceOptions.sourcePaths or matching exclude emit no module — they still feed the checker as in-memory content, so passing extra files (unsaved buffers, virtual-only helpers) shapes type resolution without polluting the output.

type readonly SourceFileInfo[]

sourceOptions

Module source options for path extraction and source filtering.

type ModuleSourceOptions

onDuplicates?

Opt-in check that declaration names are unique across modules (see OnDuplicates).

type OnDuplicates

log?

Optional logger for status and diagnostic messages.

type AnalysisLog

resolveImport?

Optional custom import resolver for the session default — a bare ResolveImportFn or a token-paired ImportResolver (see ResolveImport). For one-shot analyze() the session is single-use, so a bare function is the natural form; pass an ImportResolver with a stable identity only if you have a reason to control the cache scope.

type ResolveImport

tsconfig?

Path to the tsconfig, relative to the project root, or false to analyze without one (see LoadTsconfigOptions.tsconfig).

type string | false

default 'tsconfig.json'

compilerOptions?

Compiler options merged over the tsconfig's (see LoadTsconfigOptions.compilerOptions).

type CompilerOptions

rootFileNames?

Root files for the program in place of the tsconfig's (see RootFileNames).

type RootFileNames

default the tsconfig's roots

Depends on
#

Imported by
#