AnalyzerType Analyzer type for source files.
- 'typescript' - TypeScript/JS files analyzed via TypeScript Compiler API
- 'svelte' - Svelte components analyzed via svelte2tsx + TypeScript Compiler API
Module path and metadata helpers.
Provides utilities for working with source module paths, file types, and import relationships in the package generation system.
All functions are prefixed with module_ for clarity.
19 declarations
AnalyzerType Analyzer type for source files.
- 'typescript' - TypeScript/JS files analyzed via TypeScript Compiler API
- 'svelte' - Svelte components analyzed via svelte2tsx + TypeScript Compiler API
(project_root: string, overrides?: Partial<ModuleSourcePartial> | undefined): ModuleSourceOptions Create complete source options from project root and optional overrides.
project_rootAbsolute path to project root (typically process.cwd())
stringoverrides?Optional overrides for default options
Partial<ModuleSourcePartial> | undefinedModuleSourceOptions // Standard SvelteKit library
const options = module_create_source_options(process.cwd());// Multiple source directories
const options = module_create_source_options(process.cwd(), {
source_paths: ['src/lib', 'src/routes'],
source_root: 'src',
});// Custom exclusions
const options = module_create_source_options(process.cwd(), {
exclude_patterns: [/\.test\.ts$/, /\.internal\.ts$/],
});(source_file: SourceFileInfo, options: ModuleSourceOptions): { dependencies: string[]; dependents: string[]; } Extract dependencies and dependents for a module from source file info.
Filters to only include source modules (excludes external packages, node_modules, tests). Returns sorted arrays of module paths (relative to source_root) for deterministic output.
source_fileThe source file info to extract dependencies from
optionsModule source options for filtering and path extraction
{ dependencies: string[]; dependents: string[]; } (source_id: string, options: ModuleSourceOptions): string Extract module path relative to source root from absolute source ID.
Uses proper path semantics: strips project_root/source_root/ prefix.
source_idAbsolute path to the source file
stringoptionsModule source options for path extraction
string const options = module_create_source_options('/home/user/project');
module_extract_path('/home/user/project/src/lib/foo.ts', options) // => 'foo.ts'
module_extract_path('/home/user/project/src/lib/nested/bar.svelte', options) // => 'nested/bar.svelte'const options = module_create_source_options('/home/user/project', {
source_paths: ['src/lib', 'src/routes'],
source_root: 'src',
});
module_extract_path('/home/user/project/src/lib/foo.ts', options) // => 'lib/foo.ts'
module_extract_path('/home/user/project/src/routes/page.svelte', options) // => 'routes/page.svelte'(path: string): AnalyzerType | null Default analyzer resolver based on file extension.
- .svelte → 'svelte'
- .ts, .js → 'typescript'
- Other extensions → null (skip)
pathstringAnalyzerType | null (module_path: string): string Extract component name from a Svelte module path.
module_pathstringstring module_get_component_name('Alert.svelte') // => 'Alert'
module_get_component_name('components/Button.svelte') // => 'Button'(module_path: string): string Convert module path to module key format (with ./ prefix).
module_pathstringstring module_get_key('foo.ts') // => './foo.ts'(options: ModuleSourceOptions): string Get the effective source_root from options.
Returns source_root if provided, otherwise returns source_paths[0] for single-path configs.
optionsstring Error - if source_root is required but not provided (multiple source_paths)(path: string): boolean pathstringboolean (path: string): boolean pathstringboolean (path: string, options: ModuleSourceOptions): boolean Check if a path is an analyzable source file.
Combines all filtering: exclusion patterns, source directory paths, and analyzer availability. This is the single check for whether a file should be included in library analysis.
Uses proper path semantics with startsWith matching against
project_root/source_path/. No heuristics needed - nested directories
are correctly excluded by the prefix check.
pathFull absolute path to check
stringoptionsModule source options for filtering
boolean True if the path is an analyzable source file
const options = module_create_source_options('/home/user/project');
module_is_source('/home/user/project/src/lib/foo.ts', options) // => true
module_is_source('/home/user/project/src/lib/foo.test.ts', options) // => false (excluded)
module_is_source('/home/user/project/src/fixtures/mini/src/lib/bar.ts', options) // => false (wrong prefix)(path: string): boolean pathstringboolean (path: string): boolean pathstringboolean (path: string): boolean Check if a path is a TypeScript or JS file.
Includes both .ts and .js files since JS files are valid in TS projects.
Excludes .d.ts declaration files - use a custom get_analyzer to include them.
pathstringboolean ModuleSourcePartial Default partial options for standard SvelteKit library structure.
Does not include project_root - use module_create_source_options() to create
complete options with your project root.
(options: ModuleSourceOptions): void Validate ModuleSourceOptions format and consistency.
Checks:
1. project_root is an absolute path (starts with /)
2. source_paths entries don't have leading/trailing slashes
3. source_root (if provided) doesn't have leading/trailing slashes
4. Multiple source_paths require explicit source_root
5. source_root is a prefix of all source_paths
optionsvoid Error - if validation fails// Valid - single source path (source_root auto-derived)
module_validate_source_options({
project_root: '/home/user/project',
source_paths: ['src/lib'],
...
});// Valid - multiple source paths with explicit source_root
module_validate_source_options({
project_root: '/home/user/project',
source_paths: ['src/lib', 'src/routes'],
source_root: 'src',
...
});// Invalid - multiple source paths without source_root
module_validate_source_options({
project_root: '/home/user/project',
source_paths: ['src/lib', 'src/routes'], // throws
...
});ModuleSourceOptions Configuration for module source detection and path extraction.
Uses proper path semantics with project_root as the base for all path operations.
Paths are matched using startsWith rather than substring search, which correctly
handles nested directories without special heuristics.
const options = module_create_source_options(process.cwd(), {
source_paths: ['src/lib', 'src/routes'],
source_root: 'src',
});project_rootAbsolute path to the project root directory.
All source_paths are relative to this. Typically process.cwd() when
running from the project root via Gro, Vite, or other build tools.
stringsource_pathsSource directory paths to include, relative to project_root.
Paths should not have leading or trailing slashes - they are added internally for correct matching.
Array<string>source_rootSource root for extracting relative module paths, relative to project_root.
When omitted:
- Single source_path: defaults to that path
- Multiple source_paths: required (no auto-derivation)
stringexclude_patternsPatterns to exclude (matched against full path).
Array<RegExp>get_analyzerDetermine which analyzer to use for a file path.
Called for files in source directories. Return 'typescript', 'svelte',
or null to skip the file. This is the single source of truth for which
files are analyzable and how to analyze them.
(path: string) => AnalyzerType | nullModuleSourcePartial Partial source options without project_root.
Use with module_create_source_options to build complete options.
SourceFileInfo File information for source analysis.
Can be constructed from Gro's Disknode or from plain file system access. This abstraction enables non-Gro usage while keeping Gro support via adapter.
Note: content is required to keep analysis functions pure (no hidden I/O).
Callers are responsible for reading file content before analysis.
idAbsolute path to the file.
stringcontentFile content (required - analysis functions don't read from disk).
stringdependenciesAbsolute file paths of modules this file imports (optional). Only include resolved local imports, not node_modules. Order should be declaration order in source for deterministic output.
ReadonlyArray<string>dependentsAbsolute file paths of modules that import this file (optional). Only include resolved local imports, not node_modules.
ReadonlyArray<string>