library_gen_helpers.ts

Declarations
#

Build-time helpers for library metadata generation.

These functions handle Gro-specific concerns like file collection and dependency graph extraction. Core analysis logic has been extracted to reusable helpers:

- ts_helpers.ts - ts_analyze_module_exports - svelte_helpers.ts - svelte_analyze_file - module_helpers.ts - path utilities and source detection

Design philosophy: Fail fast with clear errors rather than silently producing invalid metadata. All validation errors halt the build immediately with actionable messages.

@see library_gen.ts for the main generation task @see @ryanatkn/belt/source_json.js for type definitions @see ts_helpers.ts for reusable TypeScript analysis @see svelte_helpers.ts for reusable Svelte component analysis

8 declarations

view source

library_gen_analyze_svelte_file
#

library_gen_helpers.ts view source

(disknode: Disknode, module_path: string, checker: TypeChecker): { [x: string]: unknown; path: string; declarations?: { [x: string]: unknown; name: string; kind: "function" | ... 6 more ... | "css"; ... 19 more ...; alias_of?: { ...; } | undefined; }[] | undefined; module_comment?: string | undefined; dependencies?: string[] | undefined; dependents?: string[] | undefined; }

Analyze a Svelte component file and extract metadata.

Uses svelte_analyze_file for core analysis, then adds Gro-specific dependency information from the disknode.

disknode

type Disknode

module_path

type string

checker

type TypeChecker

returns

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

library_gen_analyze_typescript_file
#

library_gen_helpers.ts view source

(disknode: Disknode, source_file: SourceFile, module_path: string, checker: TypeChecker): TsFileAnalysis

Analyze a TypeScript file and extract all declarations.

Uses ts_analyze_module_exports for core analysis, then adds Gro-specific dependency information from the disknode.

Returns both the module metadata and re-export information for post-processing.

disknode

type Disknode

source_file

type SourceFile

module_path

type string

checker

type TypeChecker

returns

TsFileAnalysis

library_gen_collect_source_files
#

library_gen_helpers.ts view source

(files: Map<PathId, Disknode>, log: Logger): Disknode[]

Collect and filter source files from filer.

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

files

type Map<PathId, Disknode>

log

type Logger

returns

Disknode[]

library_gen_extract_dependencies
#

library_gen_helpers.ts view source

(disknode: Disknode): { dependencies: string[]; dependents: string[]; }

Extract dependencies and dependents for a module from the filer's dependency graph.

Filters to only include source modules from src/lib (excludes external packages, node_modules, tests). Returns sorted arrays of module paths (relative to src/lib) for deterministic output.

disknode

type Disknode

returns

{ dependencies: string[]; dependents: string[]; }

library_gen_generate_ts
#

library_gen_helpers.ts view source

(package_json: { [x: string]: unknown; name: string; version: string; private?: boolean | undefined; public?: boolean | undefined; description?: string | undefined; motto?: string | undefined; glyph?: string | undefined; ... 24 more ...; exports?: string | ... 2 more ... | undefined; }, source_json: { ...; }): string

Generate the library.ts file content with library_json export. Parses at generation time so runtime only needs the pre-computed result.

package_json

type { [x: string]: unknown; name: string; version: string; private?: boolean | undefined; public?: boolean | undefined; description?: string | undefined; motto?: string | undefined; glyph?: string | undefined; ... 24 more ...; exports?: string | ... 2 more ... | undefined; }

source_json

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

returns

string

library_gen_sort_modules
#

library_gen_helpers.ts view source

(modules: { [x: string]: unknown; path: string; declarations?: { [x: string]: unknown; name: string; kind: "function" | "type" | "json" | "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; }[]): { ...; }[]

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" | "type" | "json" | "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" | "type" | "json" | "variable" | "class" | "constructor" | "component" | "css"; doc_comment?: string | undefined; ... 18 more ...; alias_of?: { ...; } | undefined; }[] | undefined; module_comment?: string | un...

library_gen_validate_no_duplicates
#

library_gen_helpers.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" | "type" | "json" | "variable" | "class" | "constructor" | "component" | "css"; ... 19 more ...; alias_of?: { ...; } | undefined; }[] | undefined; module_comment?: string | undefined; dependencies?: string[] | undefined; dependents?: string[] | undefined; }[] | undefined; }, log: Logger): void

Validates that no declaration names are duplicated across modules. The flat namespace is intentional - duplicates should fail fast.

source_json

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

log

type Logger

returns

void

throws

  • Error - if duplicate declaration names are found

TsFileAnalysis
#

library_gen_helpers.ts view source

TsFileAnalysis

Result of analyzing a TypeScript file. Includes both the module metadata and re-export information for post-processing.

module

Module metadata for inclusion in source_json.

type ModuleJson

re_exports

Re-exports from this module for building also_exported_from.

type Array<ReExportInfo>

Depends on
#

Imported by
#