@fuzdev/fuz_ui 0.194.0 → 0.195.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/DeclarationDetail.svelte +139 -64
  2. package/dist/DeclarationDetail.svelte.d.ts +9 -0
  3. package/dist/DeclarationDetail.svelte.d.ts.map +1 -1
  4. package/dist/LibraryDetail.svelte +14 -10
  5. package/dist/LibraryDetail.svelte.d.ts +7 -0
  6. package/dist/LibraryDetail.svelte.d.ts.map +1 -1
  7. package/dist/declaration.svelte.d.ts +233 -25
  8. package/dist/declaration.svelte.d.ts.map +1 -1
  9. package/dist/declaration.svelte.js +71 -23
  10. package/dist/library.svelte.js +1 -1
  11. package/dist/library_gen.d.ts +24 -17
  12. package/dist/library_gen.d.ts.map +1 -1
  13. package/dist/library_gen.js +52 -32
  14. package/dist/library_output.d.ts +5 -4
  15. package/dist/library_output.d.ts.map +1 -1
  16. package/dist/library_output.js +11 -8
  17. package/dist/module.svelte.d.ts +21 -7
  18. package/dist/module.svelte.d.ts.map +1 -1
  19. package/dist/module.svelte.js +26 -11
  20. package/dist/tsdoc_mdz.d.ts +6 -1
  21. package/dist/tsdoc_mdz.d.ts.map +1 -1
  22. package/dist/tsdoc_mdz.js +23 -2
  23. package/package.json +10 -8
  24. package/src/lib/declaration.svelte.ts +90 -35
  25. package/src/lib/library.svelte.ts +1 -1
  26. package/src/lib/library_gen.ts +65 -42
  27. package/src/lib/library_output.ts +11 -8
  28. package/src/lib/module.svelte.ts +29 -16
  29. package/src/lib/tsdoc_mdz.ts +25 -2
  30. package/dist/analysis_context.d.ts +0 -199
  31. package/dist/analysis_context.d.ts.map +0 -1
  32. package/dist/analysis_context.js +0 -138
  33. package/dist/library_analysis.d.ts +0 -112
  34. package/dist/library_analysis.d.ts.map +0 -1
  35. package/dist/library_analysis.js +0 -106
  36. package/dist/library_generate.d.ts +0 -94
  37. package/dist/library_generate.d.ts.map +0 -1
  38. package/dist/library_generate.js +0 -147
  39. package/dist/library_pipeline.d.ts +0 -113
  40. package/dist/library_pipeline.d.ts.map +0 -1
  41. package/dist/library_pipeline.js +0 -160
  42. package/dist/module_helpers.d.ts +0 -334
  43. package/dist/module_helpers.d.ts.map +0 -1
  44. package/dist/module_helpers.js +0 -317
  45. package/dist/svelte_helpers.d.ts +0 -92
  46. package/dist/svelte_helpers.d.ts.map +0 -1
  47. package/dist/svelte_helpers.js +0 -367
  48. package/dist/ts_helpers.d.ts +0 -181
  49. package/dist/ts_helpers.d.ts.map +0 -1
  50. package/dist/ts_helpers.js +0 -674
  51. package/dist/tsdoc_helpers.d.ts +0 -119
  52. package/dist/tsdoc_helpers.d.ts.map +0 -1
  53. package/dist/tsdoc_helpers.js +0 -207
  54. package/src/lib/analysis_context.ts +0 -254
  55. package/src/lib/library_analysis.ts +0 -168
  56. package/src/lib/library_generate.ts +0 -215
  57. package/src/lib/library_pipeline.ts +0 -221
  58. package/src/lib/module_helpers.ts +0 -501
  59. package/src/lib/svelte_helpers.ts +0 -539
  60. package/src/lib/ts_helpers.ts +0 -862
  61. package/src/lib/tsdoc_helpers.ts +0 -246
@@ -1,334 +0,0 @@
1
- /**
2
- * Module path and metadata helpers.
3
- *
4
- * Provides utilities for working with source module paths, file types,
5
- * and import relationships in the package generation system.
6
- *
7
- * All functions are prefixed with `module_` for clarity.
8
- *
9
- * @module
10
- */
11
- /**
12
- * Analyzer type for source files.
13
- *
14
- * - `'typescript'` - TypeScript/JS files analyzed via TypeScript Compiler API
15
- * - `'svelte'` - Svelte components analyzed via svelte2tsx + TypeScript Compiler API
16
- */
17
- export type AnalyzerType = 'typescript' | 'svelte';
18
- /**
19
- * File information for source analysis.
20
- *
21
- * Can be constructed from Gro's `Disknode` or from plain file system access.
22
- * This abstraction enables non-Gro usage while keeping Gro support via adapter.
23
- *
24
- * Note: `content` is required to keep analysis functions pure (no hidden I/O).
25
- * Callers are responsible for reading file content before analysis.
26
- */
27
- export interface SourceFileInfo {
28
- /** Absolute path to the file. */
29
- id: string;
30
- /** File content (required - analysis functions don't read from disk). */
31
- content: string;
32
- /**
33
- * Absolute file paths of modules this file imports (optional).
34
- * Only include resolved local imports, not node_modules.
35
- * Order should be declaration order in source for deterministic output.
36
- */
37
- dependencies?: ReadonlyArray<string>;
38
- /**
39
- * Absolute file paths of modules that import this file (optional).
40
- * Only include resolved local imports, not node_modules.
41
- */
42
- dependents?: ReadonlyArray<string>;
43
- }
44
- /**
45
- * Configuration for module source detection and path extraction.
46
- *
47
- * Uses proper path semantics with `project_root` as the base for all path operations.
48
- * Paths are matched using `startsWith` rather than substring search, which correctly
49
- * handles nested directories without special heuristics.
50
- *
51
- * @example
52
- * ```ts
53
- * const options = module_create_source_options(process.cwd(), {
54
- * source_paths: ['src/lib', 'src/routes'],
55
- * source_root: 'src',
56
- * });
57
- * ```
58
- */
59
- export interface ModuleSourceOptions {
60
- /**
61
- * Absolute path to the project root directory.
62
- *
63
- * All `source_paths` are relative to this. Typically `process.cwd()` when
64
- * running from the project root via Gro, Vite, or other build tools.
65
- *
66
- * @example
67
- * ```ts
68
- * '/home/user/my-project'
69
- * ```
70
- */
71
- project_root: string;
72
- /**
73
- * Source directory paths to include, relative to `project_root`.
74
- *
75
- * Paths should not have leading or trailing slashes - they are added
76
- * internally for correct matching.
77
- *
78
- * @example
79
- * ```ts
80
- * ['src/lib'] // single source directory
81
- * ```
82
- * @example
83
- * ```ts
84
- * ['src/lib', 'src/routes'] // multiple directories
85
- * ```
86
- */
87
- source_paths: Array<string>;
88
- /**
89
- * Source root for extracting relative module paths, relative to `project_root`.
90
- *
91
- * When omitted:
92
- * - Single `source_path`: defaults to that path
93
- * - Multiple `source_paths`: required (no auto-derivation)
94
- *
95
- * @example
96
- * ```ts
97
- * 'src/lib' // module paths like 'foo.ts', 'utils/bar.ts'
98
- * ```
99
- * @example
100
- * ```ts
101
- * 'src' // module paths like 'lib/foo.ts', 'routes/page.svelte'
102
- * ```
103
- */
104
- source_root?: string;
105
- /** Patterns to exclude (matched against full path). */
106
- exclude_patterns: Array<RegExp>;
107
- /**
108
- * Determine which analyzer to use for a file path.
109
- *
110
- * Called for files in source directories. Return `'typescript'`, `'svelte'`,
111
- * or `null` to skip the file. This is the single source of truth for which
112
- * files are analyzable and how to analyze them.
113
- *
114
- * @default Uses file extension: `.svelte` → svelte, `.ts`/`.js` → typescript
115
- *
116
- * @example
117
- * ```ts
118
- * // Add MDsveX support
119
- * get_analyzer: (path) => {
120
- * if (path.endsWith('.svelte') || path.endsWith('.svx')) return 'svelte';
121
- * if (path.endsWith('.ts') || path.endsWith('.js')) return 'typescript';
122
- * return null;
123
- * }
124
- * ```
125
- *
126
- * @example
127
- * ```ts
128
- * // Include .d.ts files
129
- * get_analyzer: (path) => {
130
- * if (path.endsWith('.svelte')) return 'svelte';
131
- * if (path.endsWith('.ts') || path.endsWith('.d.ts') || path.endsWith('.js')) return 'typescript';
132
- * return null;
133
- * }
134
- * ```
135
- */
136
- get_analyzer: (path: string) => AnalyzerType | null;
137
- }
138
- /**
139
- * Default analyzer resolver based on file extension.
140
- *
141
- * - `.svelte` → `'svelte'`
142
- * - `.ts`, `.js` → `'typescript'`
143
- * - Other extensions → `null` (skip)
144
- */
145
- export declare const module_get_analyzer_default: (path: string) => AnalyzerType | null;
146
- /**
147
- * Partial source options without `project_root`.
148
- *
149
- * Use with `module_create_source_options` to build complete options.
150
- */
151
- export type ModuleSourcePartial = Omit<ModuleSourceOptions, 'project_root'>;
152
- /**
153
- * Default partial options for standard SvelteKit library structure.
154
- *
155
- * Does not include `project_root` - use `module_create_source_options()` to create
156
- * complete options with your project root.
157
- */
158
- export declare const MODULE_SOURCE_PARTIAL: ModuleSourcePartial;
159
- /**
160
- * Create complete source options from project root and optional overrides.
161
- *
162
- * @param project_root - absolute path to project root (typically `process.cwd()`)
163
- * @param overrides - optional overrides for default options
164
- *
165
- * @example
166
- * ```ts
167
- * // Standard SvelteKit library
168
- * const options = module_create_source_options(process.cwd());
169
- * ```
170
- *
171
- * @example
172
- * ```ts
173
- * // Multiple source directories
174
- * const options = module_create_source_options(process.cwd(), {
175
- * source_paths: ['src/lib', 'src/routes'],
176
- * source_root: 'src',
177
- * });
178
- * ```
179
- *
180
- * @example
181
- * ```ts
182
- * // Custom exclusions
183
- * const options = module_create_source_options(process.cwd(), {
184
- * exclude_patterns: [/\.test\.ts$/, /\.internal\.ts$/],
185
- * });
186
- * ```
187
- */
188
- export declare const module_create_source_options: (project_root: string, overrides?: Partial<ModuleSourcePartial>) => ModuleSourceOptions;
189
- /**
190
- * Validate `ModuleSourceOptions` format and consistency.
191
- *
192
- * Checks:
193
- * 1. `project_root` is an absolute path (starts with `/`)
194
- * 2. `source_paths` entries don't have leading/trailing slashes
195
- * 3. `source_root` (if provided) doesn't have leading/trailing slashes
196
- * 4. Multiple `source_paths` require explicit `source_root`
197
- * 5. `source_root` is a prefix of all `source_paths`
198
- *
199
- * @throws Error if validation fails
200
- *
201
- * @example
202
- * ```ts
203
- * // Valid - single source path (source_root auto-derived)
204
- * module_validate_source_options({
205
- * project_root: '/home/user/project',
206
- * source_paths: ['src/lib'],
207
- * ...
208
- * });
209
- * ```
210
- *
211
- * @example
212
- * ```ts
213
- * // Valid - multiple source paths with explicit source_root
214
- * module_validate_source_options({
215
- * project_root: '/home/user/project',
216
- * source_paths: ['src/lib', 'src/routes'],
217
- * source_root: 'src',
218
- * ...
219
- * });
220
- * ```
221
- *
222
- * @example
223
- * ```ts
224
- * // Invalid - multiple source paths without source_root
225
- * module_validate_source_options({
226
- * project_root: '/home/user/project',
227
- * source_paths: ['src/lib', 'src/routes'], // throws
228
- * ...
229
- * });
230
- * ```
231
- */
232
- export declare const module_validate_source_options: (options: ModuleSourceOptions) => void;
233
- /**
234
- * Get the effective source_root from options.
235
- *
236
- * Returns `source_root` if provided, otherwise returns `source_paths[0]` for single-path configs.
237
- *
238
- * @throws Error if `source_root` is required but not provided (multiple `source_paths`)
239
- */
240
- export declare const module_get_source_root: (options: ModuleSourceOptions) => string;
241
- /**
242
- * Extract module path relative to source root from absolute source ID.
243
- *
244
- * Uses proper path semantics: strips `project_root/source_root/` prefix.
245
- *
246
- * @param source_id - absolute path to the source file
247
- * @param options - module source options for path extraction
248
- *
249
- * @example
250
- * ```ts
251
- * const options = module_create_source_options('/home/user/project');
252
- * module_extract_path('/home/user/project/src/lib/foo.ts', options) // => 'foo.ts'
253
- * module_extract_path('/home/user/project/src/lib/nested/bar.svelte', options) // => 'nested/bar.svelte'
254
- * ```
255
- *
256
- * @example
257
- * ```ts
258
- * const options = module_create_source_options('/home/user/project', {
259
- * source_paths: ['src/lib', 'src/routes'],
260
- * source_root: 'src',
261
- * });
262
- * module_extract_path('/home/user/project/src/lib/foo.ts', options) // => 'lib/foo.ts'
263
- * module_extract_path('/home/user/project/src/routes/page.svelte', options) // => 'routes/page.svelte'
264
- * ```
265
- */
266
- export declare const module_extract_path: (source_id: string, options: ModuleSourceOptions) => string;
267
- /**
268
- * Extract component name from a Svelte module path.
269
- *
270
- * @example
271
- * ```ts
272
- * module_get_component_name('Alert.svelte') // => 'Alert'
273
- * module_get_component_name('components/Button.svelte') // => 'Button'
274
- * ```
275
- */
276
- export declare const module_get_component_name: (module_path: string) => string;
277
- /**
278
- * Convert module path to module key format (with ./ prefix).
279
- *
280
- * @example
281
- * ```ts
282
- * module_get_key('foo.ts') // => './foo.ts'
283
- * ```
284
- */
285
- export declare const module_get_key: (module_path: string) => string;
286
- /**
287
- * Check if a path is a TypeScript or JS file.
288
- *
289
- * Includes both `.ts` and `.js` files since JS files are valid in TS projects.
290
- * Excludes `.d.ts` declaration files - use a custom `get_analyzer` to include them.
291
- */
292
- export declare const module_is_typescript: (path: string) => boolean;
293
- export declare const module_is_svelte: (path: string) => boolean;
294
- export declare const module_is_css: (path: string) => boolean;
295
- export declare const module_is_json: (path: string) => boolean;
296
- export declare const module_is_test: (path: string) => boolean;
297
- /**
298
- * Check if a path is an analyzable source file.
299
- *
300
- * Combines all filtering: exclusion patterns, source directory paths,
301
- * and analyzer availability. This is the single check for whether a
302
- * file should be included in library analysis.
303
- *
304
- * Uses proper path semantics with `startsWith` matching against
305
- * `project_root/source_path/`. No heuristics needed - nested directories
306
- * are correctly excluded by the prefix check.
307
- *
308
- * @param path - full absolute path to check
309
- * @param options - module source options for filtering
310
- * @returns true if the path is an analyzable source file
311
- *
312
- * @example
313
- * ```ts
314
- * const options = module_create_source_options('/home/user/project');
315
- * module_is_source('/home/user/project/src/lib/foo.ts', options) // => true
316
- * module_is_source('/home/user/project/src/lib/foo.test.ts', options) // => false (excluded)
317
- * module_is_source('/home/user/project/src/fixtures/mini/src/lib/bar.ts', options) // => false (wrong prefix)
318
- * ```
319
- */
320
- export declare const module_is_source: (path: string, options: ModuleSourceOptions) => boolean;
321
- /**
322
- * Extract dependencies and dependents for a module from source file info.
323
- *
324
- * Filters to only include source modules (excludes external packages, node_modules, tests).
325
- * Returns sorted arrays of module paths (relative to source_root) for deterministic output.
326
- *
327
- * @param source_file - the source file info to extract dependencies from
328
- * @param options - module source options for filtering and path extraction
329
- */
330
- export declare const module_extract_dependencies: (source_file: SourceFileInfo, options: ModuleSourceOptions) => {
331
- dependencies: Array<string>;
332
- dependents: Array<string>;
333
- };
334
- //# sourceMappingURL=module_helpers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"module_helpers.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/module_helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,YAAY,GAAG,QAAQ,CAAC;AAEnD;;;;;;;;GAQG;AACH,MAAM,WAAW,cAAc;IAC9B,iCAAiC;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,yEAAyE;IACzE,OAAO,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,YAAY,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACrC;;;OAGG;IACH,UAAU,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CACnC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,mBAAmB;IACnC;;;;;;;;;;OAUG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;;;;;;;;;;;;;OAcG;IACH,YAAY,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5B;;;;;;;;;;;;;;;OAeG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uDAAuD;IACvD,gBAAgB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAChC;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,YAAY,GAAG,IAAI,CAAC;CACpD;AAED;;;;;;GAMG;AACH,eAAO,MAAM,2BAA2B,GAAI,MAAM,MAAM,KAAG,YAAY,GAAG,IAIzE,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,IAAI,CAAC,mBAAmB,EAAE,cAAc,CAAC,CAAC;AAE5E;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,EAAE,mBAInC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,4BAA4B,GACxC,cAAc,MAAM,EACpB,YAAY,OAAO,CAAC,mBAAmB,CAAC,KACtC,mBAID,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,eAAO,MAAM,8BAA8B,GAAI,SAAS,mBAAmB,KAAG,IAqE7E,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,GAAI,SAAS,mBAAmB,KAAG,MAWrE,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,mBAAmB,GAAI,WAAW,MAAM,EAAE,SAAS,mBAAmB,KAAG,MAUrF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,yBAAyB,GAAI,aAAa,MAAM,KAAG,MACN,CAAC;AAE3D;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,GAAI,aAAa,MAAM,KAAG,MAA4B,CAAC;AAElF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAAI,MAAM,MAAM,KAAG,OACsB,CAAC;AAE3E,eAAO,MAAM,gBAAgB,GAAI,MAAM,MAAM,KAAG,OAAmC,CAAC;AAEpF,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,KAAG,OAAgC,CAAC;AAE9E,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,KAAG,OAAiC,CAAC;AAEhF,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,KAAG,OAAoC,CAAC;AAEnF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,MAAM,EAAE,SAAS,mBAAmB,KAAG,OAe7E,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,2BAA2B,GACvC,aAAa,cAAc,EAC3B,SAAS,mBAAmB,KAC1B;IAAC,YAAY,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAAC,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;CA2BzD,CAAC"}
@@ -1,317 +0,0 @@
1
- /**
2
- * Module path and metadata helpers.
3
- *
4
- * Provides utilities for working with source module paths, file types,
5
- * and import relationships in the package generation system.
6
- *
7
- * All functions are prefixed with `module_` for clarity.
8
- *
9
- * @module
10
- */
11
- /**
12
- * Default analyzer resolver based on file extension.
13
- *
14
- * - `.svelte` → `'svelte'`
15
- * - `.ts`, `.js` → `'typescript'`
16
- * - Other extensions → `null` (skip)
17
- */
18
- export const module_get_analyzer_default = (path) => {
19
- if (module_is_svelte(path))
20
- return 'svelte';
21
- if (module_is_typescript(path))
22
- return 'typescript';
23
- return null;
24
- };
25
- /**
26
- * Default partial options for standard SvelteKit library structure.
27
- *
28
- * Does not include `project_root` - use `module_create_source_options()` to create
29
- * complete options with your project root.
30
- */
31
- export const MODULE_SOURCE_PARTIAL = {
32
- source_paths: ['src/lib'],
33
- exclude_patterns: [/\.test\.ts$/],
34
- get_analyzer: module_get_analyzer_default,
35
- };
36
- /**
37
- * Create complete source options from project root and optional overrides.
38
- *
39
- * @param project_root - absolute path to project root (typically `process.cwd()`)
40
- * @param overrides - optional overrides for default options
41
- *
42
- * @example
43
- * ```ts
44
- * // Standard SvelteKit library
45
- * const options = module_create_source_options(process.cwd());
46
- * ```
47
- *
48
- * @example
49
- * ```ts
50
- * // Multiple source directories
51
- * const options = module_create_source_options(process.cwd(), {
52
- * source_paths: ['src/lib', 'src/routes'],
53
- * source_root: 'src',
54
- * });
55
- * ```
56
- *
57
- * @example
58
- * ```ts
59
- * // Custom exclusions
60
- * const options = module_create_source_options(process.cwd(), {
61
- * exclude_patterns: [/\.test\.ts$/, /\.internal\.ts$/],
62
- * });
63
- * ```
64
- */
65
- export const module_create_source_options = (project_root, overrides) => ({
66
- project_root,
67
- ...MODULE_SOURCE_PARTIAL,
68
- ...overrides,
69
- });
70
- /**
71
- * Validate `ModuleSourceOptions` format and consistency.
72
- *
73
- * Checks:
74
- * 1. `project_root` is an absolute path (starts with `/`)
75
- * 2. `source_paths` entries don't have leading/trailing slashes
76
- * 3. `source_root` (if provided) doesn't have leading/trailing slashes
77
- * 4. Multiple `source_paths` require explicit `source_root`
78
- * 5. `source_root` is a prefix of all `source_paths`
79
- *
80
- * @throws Error if validation fails
81
- *
82
- * @example
83
- * ```ts
84
- * // Valid - single source path (source_root auto-derived)
85
- * module_validate_source_options({
86
- * project_root: '/home/user/project',
87
- * source_paths: ['src/lib'],
88
- * ...
89
- * });
90
- * ```
91
- *
92
- * @example
93
- * ```ts
94
- * // Valid - multiple source paths with explicit source_root
95
- * module_validate_source_options({
96
- * project_root: '/home/user/project',
97
- * source_paths: ['src/lib', 'src/routes'],
98
- * source_root: 'src',
99
- * ...
100
- * });
101
- * ```
102
- *
103
- * @example
104
- * ```ts
105
- * // Invalid - multiple source paths without source_root
106
- * module_validate_source_options({
107
- * project_root: '/home/user/project',
108
- * source_paths: ['src/lib', 'src/routes'], // throws
109
- * ...
110
- * });
111
- * ```
112
- */
113
- export const module_validate_source_options = (options) => {
114
- const { project_root, source_paths, source_root } = options;
115
- // Validate project_root is absolute
116
- if (!project_root.startsWith('/')) {
117
- throw new Error(`project_root must be an absolute path (start with "/"): "${project_root}"`);
118
- }
119
- // Validate project_root doesn't have trailing slash (we add it internally)
120
- if (project_root.endsWith('/')) {
121
- throw new Error(`project_root should not have trailing slash: "${project_root}". ` +
122
- `Trailing slashes are added internally for correct matching.`);
123
- }
124
- // Validate source_paths
125
- if (source_paths.length === 0) {
126
- throw new Error('source_paths must have at least one entry');
127
- }
128
- for (const source_path of source_paths) {
129
- if (source_path.startsWith('/')) {
130
- throw new Error(`source_paths entry should not start with "/": "${source_path}". ` +
131
- `Paths are relative to project_root.`);
132
- }
133
- if (source_path.endsWith('/')) {
134
- throw new Error(`source_paths entry should not end with "/": "${source_path}". ` +
135
- `Trailing slashes are added internally for correct matching.`);
136
- }
137
- }
138
- // Validate source_root if provided
139
- if (source_root !== undefined) {
140
- if (source_root.startsWith('/')) {
141
- throw new Error(`source_root should not start with "/": "${source_root}". ` +
142
- `Paths are relative to project_root.`);
143
- }
144
- if (source_root.endsWith('/')) {
145
- throw new Error(`source_root should not end with "/": "${source_root}". ` +
146
- `Trailing slashes are added internally for correct matching.`);
147
- }
148
- // Validate each source_path starts with source_root
149
- for (const source_path of source_paths) {
150
- // source_path should equal source_root or start with source_root/
151
- if (source_path !== source_root && !source_path.startsWith(source_root + '/')) {
152
- throw new Error(`source_paths entry "${source_path}" must start with source_root "${source_root}". ` +
153
- `module_extract_path uses source_root to compute module paths.`);
154
- }
155
- }
156
- }
157
- else if (source_paths.length > 1) {
158
- // Multiple source_paths without source_root - error
159
- throw new Error(`source_root is required when source_paths has multiple entries. ` +
160
- `Got source_paths: [${source_paths.map((p) => `"${p}"`).join(', ')}]. ` +
161
- `Provide source_root to specify the common prefix for module path extraction.`);
162
- }
163
- };
164
- /**
165
- * Get the effective source_root from options.
166
- *
167
- * Returns `source_root` if provided, otherwise returns `source_paths[0]` for single-path configs.
168
- *
169
- * @throws Error if `source_root` is required but not provided (multiple `source_paths`)
170
- */
171
- export const module_get_source_root = (options) => {
172
- if (options.source_root !== undefined) {
173
- return options.source_root;
174
- }
175
- if (options.source_paths.length === 1) {
176
- return options.source_paths[0];
177
- }
178
- throw new Error(`source_root is required when source_paths has multiple entries. ` +
179
- `Got source_paths: [${options.source_paths.map((p) => `"${p}"`).join(', ')}].`);
180
- };
181
- /**
182
- * Extract module path relative to source root from absolute source ID.
183
- *
184
- * Uses proper path semantics: strips `project_root/source_root/` prefix.
185
- *
186
- * @param source_id - absolute path to the source file
187
- * @param options - module source options for path extraction
188
- *
189
- * @example
190
- * ```ts
191
- * const options = module_create_source_options('/home/user/project');
192
- * module_extract_path('/home/user/project/src/lib/foo.ts', options) // => 'foo.ts'
193
- * module_extract_path('/home/user/project/src/lib/nested/bar.svelte', options) // => 'nested/bar.svelte'
194
- * ```
195
- *
196
- * @example
197
- * ```ts
198
- * const options = module_create_source_options('/home/user/project', {
199
- * source_paths: ['src/lib', 'src/routes'],
200
- * source_root: 'src',
201
- * });
202
- * module_extract_path('/home/user/project/src/lib/foo.ts', options) // => 'lib/foo.ts'
203
- * module_extract_path('/home/user/project/src/routes/page.svelte', options) // => 'routes/page.svelte'
204
- * ```
205
- */
206
- export const module_extract_path = (source_id, options) => {
207
- const effective_root = module_get_source_root(options);
208
- // Build the full prefix: project_root + '/' + source_root + '/'
209
- const prefix = options.project_root + '/' + effective_root + '/';
210
- if (source_id.startsWith(prefix)) {
211
- return source_id.slice(prefix.length);
212
- }
213
- // Fallback: return full path if prefix doesn't match (shouldn't happen with valid inputs)
214
- return source_id;
215
- };
216
- /**
217
- * Extract component name from a Svelte module path.
218
- *
219
- * @example
220
- * ```ts
221
- * module_get_component_name('Alert.svelte') // => 'Alert'
222
- * module_get_component_name('components/Button.svelte') // => 'Button'
223
- * ```
224
- */
225
- export const module_get_component_name = (module_path) => module_path.replace(/^.*\//, '').replace(/\.svelte$/, '');
226
- /**
227
- * Convert module path to module key format (with ./ prefix).
228
- *
229
- * @example
230
- * ```ts
231
- * module_get_key('foo.ts') // => './foo.ts'
232
- * ```
233
- */
234
- export const module_get_key = (module_path) => `./${module_path}`;
235
- /**
236
- * Check if a path is a TypeScript or JS file.
237
- *
238
- * Includes both `.ts` and `.js` files since JS files are valid in TS projects.
239
- * Excludes `.d.ts` declaration files - use a custom `get_analyzer` to include them.
240
- */
241
- export const module_is_typescript = (path) => (path.endsWith('.ts') && !path.endsWith('.d.ts')) || path.endsWith('.js');
242
- export const module_is_svelte = (path) => path.endsWith('.svelte');
243
- export const module_is_css = (path) => path.endsWith('.css');
244
- export const module_is_json = (path) => path.endsWith('.json');
245
- export const module_is_test = (path) => path.endsWith('.test.ts');
246
- /**
247
- * Check if a path is an analyzable source file.
248
- *
249
- * Combines all filtering: exclusion patterns, source directory paths,
250
- * and analyzer availability. This is the single check for whether a
251
- * file should be included in library analysis.
252
- *
253
- * Uses proper path semantics with `startsWith` matching against
254
- * `project_root/source_path/`. No heuristics needed - nested directories
255
- * are correctly excluded by the prefix check.
256
- *
257
- * @param path - full absolute path to check
258
- * @param options - module source options for filtering
259
- * @returns true if the path is an analyzable source file
260
- *
261
- * @example
262
- * ```ts
263
- * const options = module_create_source_options('/home/user/project');
264
- * module_is_source('/home/user/project/src/lib/foo.ts', options) // => true
265
- * module_is_source('/home/user/project/src/lib/foo.test.ts', options) // => false (excluded)
266
- * module_is_source('/home/user/project/src/fixtures/mini/src/lib/bar.ts', options) // => false (wrong prefix)
267
- * ```
268
- */
269
- export const module_is_source = (path, options) => {
270
- // Check exclusion patterns first (fast regex check)
271
- const is_excluded = options.exclude_patterns.some((pattern) => pattern.test(path));
272
- if (is_excluded)
273
- return false;
274
- // Check if path starts with project_root/source_path/
275
- // Using startsWith with trailing slash ensures correct directory matching
276
- const in_source_dir = options.source_paths.some((source_path) => {
277
- const full_prefix = options.project_root + '/' + source_path + '/';
278
- return path.startsWith(full_prefix);
279
- });
280
- if (!in_source_dir)
281
- return false;
282
- // Check if file type is analyzable
283
- return options.get_analyzer(path) !== null;
284
- };
285
- /**
286
- * Extract dependencies and dependents for a module from source file info.
287
- *
288
- * Filters to only include source modules (excludes external packages, node_modules, tests).
289
- * Returns sorted arrays of module paths (relative to source_root) for deterministic output.
290
- *
291
- * @param source_file - the source file info to extract dependencies from
292
- * @param options - module source options for filtering and path extraction
293
- */
294
- export const module_extract_dependencies = (source_file, options) => {
295
- const dependencies = [];
296
- const dependents = [];
297
- // Extract dependencies (files this module imports) if provided
298
- if (source_file.dependencies) {
299
- for (const dep_id of source_file.dependencies) {
300
- if (module_is_source(dep_id, options)) {
301
- dependencies.push(module_extract_path(dep_id, options));
302
- }
303
- }
304
- }
305
- // Extract dependents (files that import this module) if provided
306
- if (source_file.dependents) {
307
- for (const dependent_id of source_file.dependents) {
308
- if (module_is_source(dependent_id, options)) {
309
- dependents.push(module_extract_path(dependent_id, options));
310
- }
311
- }
312
- }
313
- // Sort for deterministic output
314
- dependencies.sort();
315
- dependents.sort();
316
- return { dependencies, dependents };
317
- };