analyze.ts

One-shot analysis wrappers — analyze and analyzeFromFiles.

Both wrap a single-use AnalysisSession: `createSession → 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 session.ts for the persistent session API @see 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<{ modules: { path: string; declarations: ({ kind: "function"; parameters: { name: string; type: string; optional: boolean; rest: boolean; description?: string | undefined; defaultValue?: string | undefined; propertyDescriptions?: Record<...> | undefined; }[]; ... 17 more ...; sourceLine?: number | undefined; } | ... 7 more ... | { ...; })[]; ... 7 more ...; moduleComment?: string | undefined; }[]; diagnostics: ({ ...; } | ... 12 more ... | { ...; })[]; }> 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<{ modules: { path: string; declarations: ({ kind: "function"; parameters: { name: string; type: string; optional: boolean; rest: boolean; description?: string | undefined; defaultValue?: string | undefined; propertyDescriptions?: Record<...> | undefined; }[]; ... 17 more ...; sourceLine?: number | undefined;...

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

throws

  • Error - if `sourceOptions` validation fails or `tsconfig.json` is

analyzeFromFiles
#

analyze.ts view source

also exported from index.ts

(options: AnalyzeFromFilesOptions): Promise<{ modules: { path: string; declarations: ({ kind: "function"; parameters: { name: string; type: string; optional: boolean; rest: boolean; description?: string | undefined; defaultValue?: string | undefined; propertyDescriptions?: Record<...> | undefined; }[]; ... 17 more ...; sourceLine?: number | undefined; } | ... 7 more ... | { ...; })[]; ... 7 more ...; moduleComment?: string | undefined; }[]; diagnostics: ({ ...; } | ... 12 more ... | { ...; })[]; }> 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. DiscoverydiscoverSourceFiles (exports-first, glob fallback)
  2. Ingest — push discovered files into a single-use session
  3. Analysissession.query()

options

returns

Promise<{ modules: { path: string; declarations: ({ kind: "function"; parameters: { name: string; type: string; optional: boolean; rest: boolean; description?: string | undefined; defaultValue?: string | undefined; propertyDescriptions?: Record<...> | undefined; }[]; ... 17 more ...; sourceLine?: number | undefined;...

analyzed modules + concatenated ingest, discovery, and query diagnostics

throws

  • Error - if `sourceOptions` validation fails or `tsconfig.json` is missing

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 Partial<SourceOptionsDefaults>

onDuplicates?

Behavior when duplicate declaration names are found across modules.

type OnDuplicates

log?

Optional logger for status and diagnostic messages.

type AnalysisLog

include?

Glob patterns to include (relative to projectRoot).

Filters glob-based discovery. Providing include under the default discovery: 'auto' collapses the chain to glob immediately; combining with discovery: 'exports' throws.

When omitted, the glob fallback derives an include from sourceOptions.sourcePaths via deriveIncludePatterns, so custom sourcePaths (e.g., ['packages/foo']) survive the fallback instead of silently defaulting to src/lib.

type Array<string>

exclude?

Glob patterns to exclude — fully replaces sourceOptions.exclude (no merge).

type Array<string>

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'

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).

type ReadonlyArray<SourceFileInfo>

sourceOptions

Module source options for path extraction and source filtering.

type ModuleSourceOptions

onDuplicates?

Behavior when duplicate declaration names are found across modules.

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

Depends on
#

Imported by
#