files.ts

File system helpers — file loading and glob discovery.

Composable primitives for analyzeFromFiles / discoverSourceFiles. For most use cases prefer those higher-level entry points.

Build tools that want to drive resolve outside the session can construct an ImportResolver directly and pass it to createAnalysisSession.

@see analyzeFromFiles for the high-level disk-discovery wrapper @see discoverSourceFiles for exports-first discovery with glob fallback

Declarations
#

4 declarations

view source

deriveIncludePatterns
#

files.ts view source

(sourcePaths: readonly string[]): string[]

Build an include pattern array from source paths.

Each path becomes a <path>/**\/*.{ts,js,svelte,css,json} glob. Used by discoverSourceFiles to derive a default include from sourceOptions.sourcePaths when no explicit pattern is supplied — keeps the glob fallback consistent with custom sourcePaths instead of silently defaulting to src/lib.

sourcePaths

type readonly string[]

returns

string[]

examples

deriveIncludePatterns(['packages/foo', 'packages/bar']) // => ['packages/foo/**\/*.{ts,js,svelte,css,json}', 'packages/bar/**\/*.{ts,js,svelte,css,json}']

globFiles
#

files.ts view source

(options: GlobFilesOptions): Promise<SourceFileInfo[]>

Discover source files via glob patterns.

options

glob configuration

returns

Promise<SourceFileInfo[]>

array of source files with content loaded

throws

  • Error - if any matched file cannot be read — `Promise.all` rejects on the first read failure

examples

const files = await globFiles({ projectRoot: process.cwd(), include: deriveIncludePatterns(['src/lib']), exclude: DEFAULT_SOURCE_OPTIONS.exclude, });

GlobFilesOptions
#

files.ts view source

GlobFilesOptions

Options for globFiles.

projectRoot

Absolute path to project root.

type string

include

Glob patterns to include (relative to projectRoot).

type Array<string>

exclude

Optional glob patterns to exclude.

type Array<string>

loadFile
#

files.ts view source

(path: string, projectRoot: string): Promise<SourceFileInfo>

Load a single source file from disk.

Accepts either relative or absolute paths. Relative paths are resolved against projectRoot.

path

file path (relative to projectRoot or absolute)

type string

projectRoot

absolute path to project root

type string

returns

Promise<SourceFileInfo>

source file info with content loaded

throws

  • Error - if the file cannot be read (e.g., missing or permission denied)

examples

const file = await loadFile('src/lib/math.ts', process.cwd()); // {id: '/abs/path/to/src/lib/math.ts', content: '...'}

Depends on
#

Imported by
#