library_pipeline.ts

Library metadata generation pipeline.

These functions handle collection, validation, and transformation of library metadata during the generation pipeline.

Pipeline stages: 1. Collection - library_collect_source_files gathers and filters source files 2. Analysis - library_analyze_module (in library_analysis.ts) extracts metadata 3. Validation - library_find_duplicates checks flat namespace constraints 4. Transformation - library_merge_re_exports resolves re-export relationships 5. Output - library_sort_modules prepares deterministic output

@see library_generate.ts for the main generation entry point @see library_analysis.ts for module-level analysis @see library_output.ts for output file generation (JSON/TS wrapper) @see library_gen.ts for Gro-specific integration

Declarations
#

6 declarations

view source

CollectedReExport
#

library_pipeline.ts view source

CollectedReExport

A collected re-export with its source module context.

Used during the two-phase re-export resolution: 1. Phase 1: Collect re-exports from each module during analysis 2. Phase 2: Group by original module and merge into also_exported_from

re_exporting_module

The module that re-exports the declaration.

type string

re_export

The re-export info (name and original module).

DuplicateInfo
#

library_pipeline.ts view source

DuplicateInfo

A duplicate declaration with its full metadata and module path.

declaration

The full declaration metadata.

type DeclarationJson

module

Module path where this declaration is defined.

type string

library_collect_source_files
#

library_pipeline.ts view source

(files: Iterable<SourceFileInfo>, options: ModuleSourceOptions, log?: Logger | undefined): SourceFileInfo[]

Collect and filter source files.

Returns source files for TypeScript/JS files and Svelte components, excluding test files. Returns an empty array with a warning if no source files are found.

File types are determined by options.get_analyzer. By default, .ts, .js, and .svelte files are supported. Customize get_analyzer to support additional file types like .svx.

files

Iterable of source file info (from Gro filer, file system, or other source)

type Iterable<SourceFileInfo>

options

Module source options for filtering

log?

Optional logger for status messages

type Logger | undefined
optional

returns

SourceFileInfo[]

library_find_duplicates
#

library_pipeline.ts view source

(source_json: { [x: string]: unknown; name: string; version: string; modules?: { [x: string]: unknown; path: string; declarations?: { [x: string]: unknown; name: string; kind: "function" | "json" | "type" | "variable" | "class" | "constructor" | "component" | "css"; ... 19 more ...; alias_of?: { ...; } | undefined; }[] | undefined; module_comment?: string | undefined; dependencies?: string[] | undefined; dependents?: string[] | undefined; star_exports?: string[] | undefined; }[] | undefined; }): Map<...>

Find duplicate declaration names across modules.

Returns a Map of declaration names to their full metadata (only includes duplicates). Callers can decide how to handle duplicates (throw, warn, ignore).

source_json

type { [x: string]: unknown; name: string; version: string; modules?: { [x: string]: unknown; path: string; declarations?: { [x: string]: unknown; name: string; kind: "function" | "json" | "type" | "variable" | "class" | "constructor" | "component" | "css"; ... 19 more ...; alias_of?: { ...; } | undefined; }[] | undefine...

returns

Map<string, DuplicateInfo[]>

examples

Example 1

library_merge_re_exports
#

library_pipeline.ts view source

(source_json: { [x: string]: unknown; name: string; version: string; modules?: { [x: string]: unknown; path: string; declarations?: { [x: string]: unknown; name: string; kind: "function" | "json" | "type" | "variable" | "class" | "constructor" | "component" | "css"; ... 19 more ...; alias_of?: { ...; } | undefined; }[] | undefined; module_comment?: string | undefined; dependencies?: string[] | undefined; dependents?: string[] | undefined; star_exports?: string[] | undefined; }[] | undefined; }, collected_re_exports: CollectedReExport[]): void

Build also_exported_from arrays from collected re-export data.

This function resolves the two-phase re-export problem:

Problem: When module A re-exports from module B, we discover this while analyzing A, but need to update B's declarations. However, B may already be processed or may be processed later.

Solution: Collect all re-exports in phase 1, then merge them in phase 2 after all modules are analyzed.

source_json

The source JSON with all modules (will be mutated)

type { [x: string]: unknown; name: string; version: string; modules?: { [x: string]: unknown; path: string; declarations?: { [x: string]: unknown; name: string; kind: "function" | "json" | "type" | "variable" | "class" | "constructor" | "component" | "css"; ... 19 more ...; alias_of?: { ...; } | undefined; }[] | undefine...

collected_re_exports

Array of re-exports collected during phase 1

type CollectedReExport[]

returns

void

examples

Example 1

library_sort_modules
#

library_pipeline.ts view source

(modules: { [x: string]: unknown; path: string; declarations?: { [x: string]: unknown; name: string; kind: "function" | "json" | "type" | "variable" | "class" | "constructor" | "component" | "css"; doc_comment?: string | undefined; ... 18 more ...; alias_of?: { ...; } | undefined; }[] | undefined; module_comment?: string | undefined; dependencies?: string[] | undefined; dependents?: string[] | undefined; star_exports?: string[] | undefined; }[]): { ...; }[]

Sort modules alphabetically by path for deterministic output and cleaner diffs.

modules

type { [x: string]: unknown; path: string; declarations?: { [x: string]: unknown; name: string; kind: "function" | "json" | "type" | "variable" | "class" | "constructor" | "component" | "css"; doc_comment?: string | undefined; ... 18 more ...; alias_of?: { ...; } | undefined; }[] | undefined; module_comment?: string | un...

returns

{ [x: string]: unknown; path: string; declarations?: { [x: string]: unknown; name: string; kind: "function" | "json" | "type" | "variable" | "class" | "constructor" | "component" | "css"; doc_comment?: string | undefined; ... 18 more ...; alias_of?: { ...; } | undefined; }[] | undefined; module_comment?: string | un...

Depends on
#

Imported by
#