@fuzdev/fuz_ui 0.194.0 → 0.195.1

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,147 +0,0 @@
1
- /**
2
- * Generic library metadata generation.
3
- *
4
- * This module provides build-tool agnostic library generation. It takes source files
5
- * and package metadata, analyzes them, and produces structured metadata with:
6
- * - JSDoc/TSDoc comments with full tag support
7
- * - Full type signatures
8
- * - Source code locations
9
- * - Parameter information with descriptions and defaults
10
- * - Return value documentation
11
- * - Usage examples
12
- * - Dependency graphs
13
- * - Svelte component props
14
- *
15
- * For Gro integration, see `library_gen.ts` which wraps this with Gro's `Gen` interface.
16
- *
17
- * @see `@fuzdev/fuz_util/source_json.js` for type definitions
18
- * @see `library_analysis.ts` for the unified analysis entry point
19
- * @see `library_pipeline.ts` for pipeline helpers
20
- * @see `library_output.ts` for JSON/TS file generation
21
- *
22
- * @module
23
- */
24
- import { ts_create_program } from './ts_helpers.js';
25
- import {} from './module_helpers.js';
26
- import { library_analyze_module } from './library_analysis.js';
27
- import { library_sort_modules, library_find_duplicates, library_merge_re_exports, } from './library_pipeline.js';
28
- import { library_generate_output } from './library_output.js';
29
- import { AnalysisContext, format_diagnostic } from './analysis_context.js';
30
- /**
31
- * Strict duplicate handler that throws on any duplicate declaration names.
32
- *
33
- * Use this callback with `library_generate({ on_duplicates: library_throw_on_duplicates })`
34
- * to enforce a flat namespace where all declaration names must be unique.
35
- *
36
- * @throws Error if any duplicate declaration names are found
37
- */
38
- export const library_throw_on_duplicates = (duplicates, log) => {
39
- if (duplicates.size === 0)
40
- return;
41
- log.error('Duplicate declaration names detected in flat namespace:');
42
- for (const [name, occurrences] of duplicates) {
43
- log.error(` "${name}" found in:`);
44
- for (const { declaration, module } of occurrences) {
45
- const line_info = declaration.source_line !== undefined ? `:${declaration.source_line}` : '';
46
- log.error(` - ${module}${line_info} (${declaration.kind})`);
47
- }
48
- }
49
- throw new Error(`Found ${duplicates.size} duplicate declaration name${duplicates.size === 1 ? '' : 's'} across modules. ` +
50
- 'The flat namespace requires unique names. To resolve: ' +
51
- '(1) rename one of the conflicting declarations, or ' +
52
- '(2) add /** @nodocs */ to exclude from documentation.');
53
- };
54
- /**
55
- * Generate library metadata from source files.
56
- *
57
- * This is the main entry point for library generation. It analyzes source files,
58
- * extracts metadata, and produces both structured data and file contents.
59
- *
60
- * @example
61
- * ```ts
62
- * const result = library_generate({
63
- * source_files,
64
- * package_json: {name: '@my/lib', version: '1.0.0'},
65
- * source_options: module_create_source_options(process.cwd()),
66
- * });
67
- *
68
- * await writeFile('library.json', result.json_content);
69
- * await writeFile('library.ts', result.ts_content);
70
- * ```
71
- */
72
- export const library_generate = (input) => {
73
- const { source_files, package_json, source_options, on_duplicates, log } = input;
74
- // Create or use provided TypeScript program
75
- const program = input.program ?? ts_create_program(undefined, log).program;
76
- // Create analysis context for collecting diagnostics
77
- const ctx = new AnalysisContext();
78
- // Collect modules
79
- const modules = [];
80
- // Build source_json with array-based modules
81
- // Phase 1: Analyze all modules and collect re-exports
82
- const source_json = {
83
- name: package_json.name,
84
- version: package_json.version || '',
85
- modules,
86
- };
87
- // Collect re-exports for phase 2 merging
88
- // See library_merge_re_exports for the two-phase resolution strategy
89
- const collected_re_exports = [];
90
- for (const source_file of source_files) {
91
- // Use unified analyzer that dispatches based on file type
92
- const result = library_analyze_module(source_file, program, source_options, ctx, log);
93
- if (!result)
94
- continue;
95
- // Build ModuleJson, filtering out @nodocs declarations
96
- const module = {
97
- path: result.path,
98
- declarations: result.declarations.filter((d) => !d.nodocs).map((d) => d.declaration),
99
- };
100
- if (result.module_comment)
101
- module.module_comment = result.module_comment;
102
- if (result.dependencies.length > 0)
103
- module.dependencies = result.dependencies;
104
- if (result.dependents.length > 0)
105
- module.dependents = result.dependents;
106
- if (result.star_exports.length > 0)
107
- module.star_exports = result.star_exports;
108
- modules.push(module);
109
- // Collect re-exports for phase 2 merging
110
- for (const re_export of result.re_exports) {
111
- collected_re_exports.push({ re_exporting_module: result.path, re_export });
112
- }
113
- }
114
- // Phase 2: Build also_exported_from arrays from re-export data
115
- library_merge_re_exports(source_json, collected_re_exports);
116
- // Sort modules alphabetically for deterministic output and cleaner diffs
117
- source_json.modules = library_sort_modules(modules);
118
- // Check for duplicate declaration names and invoke callback if provided
119
- if (on_duplicates) {
120
- const duplicates = library_find_duplicates(source_json);
121
- if (duplicates.size > 0) {
122
- // Use provided logger or a minimal fallback
123
- const error_log = log ?? { error: (...args) => console.error(...args) }; // eslint-disable-line no-console
124
- on_duplicates(duplicates, error_log);
125
- }
126
- }
127
- // Report any analysis diagnostics
128
- if (ctx.diagnostics.length > 0 && log) {
129
- const errors = ctx.errors();
130
- const warnings = ctx.warnings();
131
- const format_options = { strip_base: source_options.project_root };
132
- if (errors.length > 0) {
133
- log.error(`Analysis completed with ${errors.length} error(s):`);
134
- for (const diagnostic of errors) {
135
- log.error(` ${format_diagnostic(diagnostic, format_options)}`);
136
- }
137
- }
138
- if (warnings.length > 0) {
139
- log.warn(`Analysis completed with ${warnings.length} warning(s):`);
140
- for (const diagnostic of warnings) {
141
- log.warn(` ${format_diagnostic(diagnostic, format_options)}`);
142
- }
143
- }
144
- }
145
- const { json_content, ts_content } = library_generate_output(package_json, source_json);
146
- return { source_json, json_content, ts_content };
147
- };
@@ -1,113 +0,0 @@
1
- /**
2
- * Library metadata generation pipeline.
3
- *
4
- * These functions handle collection, validation, and transformation of library metadata
5
- * during the generation pipeline.
6
- *
7
- * Pipeline stages:
8
- * 1. **Collection** - `library_collect_source_files` gathers and filters source files
9
- * 2. **Analysis** - `library_analyze_module` (in `library_analysis.ts`) extracts metadata
10
- * 3. **Validation** - `library_find_duplicates` checks flat namespace constraints
11
- * 4. **Transformation** - `library_merge_re_exports` resolves re-export relationships
12
- * 5. **Output** - `library_sort_modules` prepares deterministic output
13
- *
14
- * @see `library_generate.ts` for the main generation entry point
15
- * @see `library_analysis.ts` for module-level analysis
16
- * @see `library_output.ts` for output file generation (JSON/TS wrapper)
17
- * @see `library_gen.ts` for Gro-specific integration
18
- *
19
- * @module
20
- */
21
- import type { Logger } from '@fuzdev/fuz_util/log.js';
22
- import type { DeclarationJson, ModuleJson, SourceJson } from '@fuzdev/fuz_util/source_json.js';
23
- import type { ReExportInfo } from './library_analysis.js';
24
- import { type SourceFileInfo, type ModuleSourceOptions } from './module_helpers.js';
25
- /**
26
- * A duplicate declaration with its full metadata and module path.
27
- */
28
- export interface DuplicateInfo {
29
- /** The full declaration metadata. */
30
- declaration: DeclarationJson;
31
- /** Module path where this declaration is defined. */
32
- module: string;
33
- }
34
- /**
35
- * Find duplicate declaration names across modules.
36
- *
37
- * Returns a Map of declaration names to their full metadata (only includes duplicates).
38
- * Callers can decide how to handle duplicates (throw, warn, ignore).
39
- *
40
- * @example
41
- * ```ts
42
- * const duplicates = library_find_duplicates(source_json);
43
- * if (duplicates.size > 0) {
44
- * for (const [name, occurrences] of duplicates) {
45
- * console.error(`"${name}" found in:`);
46
- * for (const {declaration, module} of occurrences) {
47
- * console.error(` - ${module}:${declaration.source_line} (${declaration.kind})`);
48
- * }
49
- * }
50
- * throw new Error(`Found ${duplicates.size} duplicate declaration names`);
51
- * }
52
- * ```
53
- */
54
- export declare const library_find_duplicates: (source_json: SourceJson) => Map<string, Array<DuplicateInfo>>;
55
- /**
56
- * Sort modules alphabetically by path for deterministic output and cleaner diffs.
57
- */
58
- export declare const library_sort_modules: (modules: Array<ModuleJson>) => Array<ModuleJson>;
59
- /**
60
- * A collected re-export with its source module context.
61
- *
62
- * Used during the two-phase re-export resolution:
63
- * 1. Phase 1: Collect re-exports from each module during analysis
64
- * 2. Phase 2: Group by original module and merge into `also_exported_from`
65
- */
66
- export interface CollectedReExport {
67
- /** The module that re-exports the declaration. */
68
- re_exporting_module: string;
69
- /** The re-export info (name and original module). */
70
- re_export: ReExportInfo;
71
- }
72
- /**
73
- * Build `also_exported_from` arrays from collected re-export data.
74
- *
75
- * This function resolves the two-phase re-export problem:
76
- *
77
- * **Problem**: When module A re-exports from module B, we discover this while
78
- * analyzing A, but need to update B's declarations. However, B may already be
79
- * processed or may be processed later.
80
- *
81
- * **Solution**: Collect all re-exports in phase 1, then merge them in phase 2
82
- * after all modules are analyzed.
83
- *
84
- * @example
85
- * ```ts
86
- * // helpers.ts exports: foo, bar
87
- * // index.ts does: export {foo, bar} from './helpers.js'
88
- * //
89
- * // After processing:
90
- * // - helpers.ts foo declaration gets: also_exported_from: ['index.ts']
91
- * // - helpers.ts bar declaration gets: also_exported_from: ['index.ts']
92
- * ```
93
- *
94
- * @param source_json - the source JSON with all modules (will be mutated)
95
- * @param collected_re_exports - array of re-exports collected during phase 1
96
- * @mutates source_json - adds `also_exported_from` to declarations
97
- */
98
- export declare const library_merge_re_exports: (source_json: SourceJson, collected_re_exports: Array<CollectedReExport>) => void;
99
- /**
100
- * Collect and filter source files.
101
- *
102
- * Returns source files for TypeScript/JS files and Svelte components, excluding test files.
103
- * Returns an empty array with a warning if no source files are found.
104
- *
105
- * File types are determined by `options.get_analyzer`. By default, `.ts`, `.js`, and `.svelte`
106
- * files are supported. Customize `get_analyzer` to support additional file types like `.svx`.
107
- *
108
- * @param files - iterable of source file info (from Gro filer, file system, or other source)
109
- * @param options - module source options for filtering
110
- * @param log - optional logger for status messages
111
- */
112
- export declare const library_collect_source_files: (files: Iterable<SourceFileInfo>, options: ModuleSourceOptions, log?: Logger) => Array<SourceFileInfo>;
113
- //# sourceMappingURL=library_pipeline.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"library_pipeline.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/library_pipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,EAAC,eAAe,EAAE,UAAU,EAAE,UAAU,EAAC,MAAM,iCAAiC,CAAC;AAE7F,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,uBAAuB,CAAC;AACxD,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,mBAAmB,EAIxB,MAAM,qBAAqB,CAAC;AAE7B;;GAEG;AACH,MAAM,WAAW,aAAa;IAC7B,qCAAqC;IACrC,WAAW,EAAE,eAAe,CAAC;IAC7B,qDAAqD;IACrD,MAAM,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,uBAAuB,GACnC,aAAa,UAAU,KACrB,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,aAAa,CAAC,CA0BlC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,GAAI,SAAS,KAAK,CAAC,UAAU,CAAC,KAAG,KAAK,CAAC,UAAU,CAEjF,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB;IACjC,kDAAkD;IAClD,mBAAmB,EAAE,MAAM,CAAC;IAC5B,qDAAqD;IACrD,SAAS,EAAE,YAAY,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,wBAAwB,GACpC,aAAa,UAAU,EACvB,sBAAsB,KAAK,CAAC,iBAAiB,CAAC,KAC5C,IAgCF,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,4BAA4B,GACxC,OAAO,QAAQ,CAAC,cAAc,CAAC,EAC/B,SAAS,mBAAmB,EAC5B,MAAM,MAAM,KACV,KAAK,CAAC,cAAc,CA0BtB,CAAC"}
@@ -1,160 +0,0 @@
1
- /**
2
- * Library metadata generation pipeline.
3
- *
4
- * These functions handle collection, validation, and transformation of library metadata
5
- * during the generation pipeline.
6
- *
7
- * Pipeline stages:
8
- * 1. **Collection** - `library_collect_source_files` gathers and filters source files
9
- * 2. **Analysis** - `library_analyze_module` (in `library_analysis.ts`) extracts metadata
10
- * 3. **Validation** - `library_find_duplicates` checks flat namespace constraints
11
- * 4. **Transformation** - `library_merge_re_exports` resolves re-export relationships
12
- * 5. **Output** - `library_sort_modules` prepares deterministic output
13
- *
14
- * @see `library_generate.ts` for the main generation entry point
15
- * @see `library_analysis.ts` for module-level analysis
16
- * @see `library_output.ts` for output file generation (JSON/TS wrapper)
17
- * @see `library_gen.ts` for Gro-specific integration
18
- *
19
- * @module
20
- */
21
- import { module_is_source, module_validate_source_options, module_get_source_root, } from './module_helpers.js';
22
- /**
23
- * Find duplicate declaration names across modules.
24
- *
25
- * Returns a Map of declaration names to their full metadata (only includes duplicates).
26
- * Callers can decide how to handle duplicates (throw, warn, ignore).
27
- *
28
- * @example
29
- * ```ts
30
- * const duplicates = library_find_duplicates(source_json);
31
- * if (duplicates.size > 0) {
32
- * for (const [name, occurrences] of duplicates) {
33
- * console.error(`"${name}" found in:`);
34
- * for (const {declaration, module} of occurrences) {
35
- * console.error(` - ${module}:${declaration.source_line} (${declaration.kind})`);
36
- * }
37
- * }
38
- * throw new Error(`Found ${duplicates.size} duplicate declaration names`);
39
- * }
40
- * ```
41
- */
42
- export const library_find_duplicates = (source_json) => {
43
- const all_occurrences = new Map();
44
- // Collect all declaration names and their full metadata
45
- for (const mod of source_json.modules ?? []) {
46
- for (const declaration of mod.declarations ?? []) {
47
- const name = declaration.name;
48
- if (!all_occurrences.has(name)) {
49
- all_occurrences.set(name, []);
50
- }
51
- all_occurrences.get(name).push({
52
- declaration,
53
- module: mod.path,
54
- });
55
- }
56
- }
57
- // Filter to only duplicates
58
- const duplicates = new Map();
59
- for (const [name, occurrences] of all_occurrences) {
60
- if (occurrences.length > 1) {
61
- duplicates.set(name, occurrences);
62
- }
63
- }
64
- return duplicates;
65
- };
66
- /**
67
- * Sort modules alphabetically by path for deterministic output and cleaner diffs.
68
- */
69
- export const library_sort_modules = (modules) => {
70
- return modules.slice().sort((a, b) => a.path.localeCompare(b.path));
71
- };
72
- /**
73
- * Build `also_exported_from` arrays from collected re-export data.
74
- *
75
- * This function resolves the two-phase re-export problem:
76
- *
77
- * **Problem**: When module A re-exports from module B, we discover this while
78
- * analyzing A, but need to update B's declarations. However, B may already be
79
- * processed or may be processed later.
80
- *
81
- * **Solution**: Collect all re-exports in phase 1, then merge them in phase 2
82
- * after all modules are analyzed.
83
- *
84
- * @example
85
- * ```ts
86
- * // helpers.ts exports: foo, bar
87
- * // index.ts does: export {foo, bar} from './helpers.js'
88
- * //
89
- * // After processing:
90
- * // - helpers.ts foo declaration gets: also_exported_from: ['index.ts']
91
- * // - helpers.ts bar declaration gets: also_exported_from: ['index.ts']
92
- * ```
93
- *
94
- * @param source_json - the source JSON with all modules (will be mutated)
95
- * @param collected_re_exports - array of re-exports collected during phase 1
96
- * @mutates source_json - adds `also_exported_from` to declarations
97
- */
98
- export const library_merge_re_exports = (source_json, collected_re_exports) => {
99
- // Group re-exports by original module and declaration name
100
- // Structure: Map<original_module_path, Map<declaration_name, Array<re_exporting_module_path>>>
101
- const re_export_map = new Map();
102
- for (const { re_exporting_module, re_export } of collected_re_exports) {
103
- const { name, original_module } = re_export;
104
- if (!re_export_map.has(original_module)) {
105
- re_export_map.set(original_module, new Map());
106
- }
107
- const module_map = re_export_map.get(original_module);
108
- if (!module_map.has(name)) {
109
- module_map.set(name, []);
110
- }
111
- module_map.get(name).push(re_exporting_module);
112
- }
113
- // Merge into original declarations
114
- for (const mod of source_json.modules ?? []) {
115
- const module_re_exports = re_export_map.get(mod.path);
116
- if (!module_re_exports)
117
- continue;
118
- for (const declaration of mod.declarations ?? []) {
119
- const re_exporters = module_re_exports.get(declaration.name);
120
- if (re_exporters?.length) {
121
- // Sort for deterministic output
122
- declaration.also_exported_from = re_exporters.sort();
123
- }
124
- }
125
- }
126
- };
127
- /**
128
- * Collect and filter source files.
129
- *
130
- * Returns source files for TypeScript/JS files and Svelte components, excluding test files.
131
- * Returns an empty array with a warning if no source files are found.
132
- *
133
- * File types are determined by `options.get_analyzer`. By default, `.ts`, `.js`, and `.svelte`
134
- * files are supported. Customize `get_analyzer` to support additional file types like `.svx`.
135
- *
136
- * @param files - iterable of source file info (from Gro filer, file system, or other source)
137
- * @param options - module source options for filtering
138
- * @param log - optional logger for status messages
139
- */
140
- export const library_collect_source_files = (files, options, log) => {
141
- // Validate options early to fail fast on misconfiguration
142
- module_validate_source_options(options);
143
- const all_files = Array.from(files);
144
- log?.info(`received ${all_files.length} files total`);
145
- const source_files = [];
146
- for (const file of all_files) {
147
- if (module_is_source(file.id, options)) {
148
- source_files.push(file);
149
- }
150
- }
151
- log?.info(`found ${source_files.length} source files to analyze`);
152
- if (source_files.length === 0) {
153
- const effective_root = module_get_source_root(options);
154
- log?.warn(`No source files found in ${effective_root} - generating empty library metadata`);
155
- return [];
156
- }
157
- // Sort for deterministic output (stable alphabetical module ordering)
158
- source_files.sort((a, b) => a.id.localeCompare(b.id));
159
- return source_files;
160
- };