@useavalon/avalon 0.1.11 → 0.1.13

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 (141) hide show
  1. package/README.md +54 -54
  2. package/mod.ts +302 -302
  3. package/package.json +49 -26
  4. package/src/build/integration-bundler-plugin.ts +116 -116
  5. package/src/build/integration-config.ts +168 -168
  6. package/src/build/integration-detection-plugin.ts +117 -117
  7. package/src/build/integration-resolver-plugin.ts +90 -90
  8. package/src/build/island-manifest.ts +269 -269
  9. package/src/build/island-types-generator.ts +476 -476
  10. package/src/build/mdx-island-transform.ts +464 -464
  11. package/src/build/mdx-plugin.ts +98 -98
  12. package/src/build/page-island-transform.ts +598 -598
  13. package/src/build/prop-extractors/index.ts +21 -21
  14. package/src/build/prop-extractors/lit.ts +140 -140
  15. package/src/build/prop-extractors/qwik.ts +16 -16
  16. package/src/build/prop-extractors/solid.ts +125 -125
  17. package/src/build/prop-extractors/svelte.ts +194 -194
  18. package/src/build/prop-extractors/vue.ts +111 -111
  19. package/src/build/sidecar-file-manager.ts +104 -104
  20. package/src/build/sidecar-renderer.ts +30 -30
  21. package/src/client/adapters/index.ts +21 -13
  22. package/src/client/components.ts +35 -35
  23. package/src/client/css-hmr-handler.ts +344 -344
  24. package/src/client/framework-adapter.ts +462 -462
  25. package/src/client/hmr-coordinator.ts +396 -396
  26. package/src/client/hmr-error-overlay.js +533 -533
  27. package/src/client/main.js +824 -816
  28. package/src/client/types/framework-runtime.d.ts +68 -68
  29. package/src/client/types/vite-hmr.d.ts +46 -46
  30. package/src/client/types/vite-virtual-modules.d.ts +70 -60
  31. package/src/components/Image.tsx +123 -123
  32. package/src/components/IslandErrorBoundary.tsx +145 -145
  33. package/src/components/LayoutDataErrorBoundary.tsx +141 -141
  34. package/src/components/LayoutErrorBoundary.tsx +127 -127
  35. package/src/components/PersistentIsland.tsx +52 -52
  36. package/src/components/StreamingErrorBoundary.tsx +233 -233
  37. package/src/components/StreamingLayout.tsx +538 -538
  38. package/src/core/components/component-analyzer.ts +192 -192
  39. package/src/core/components/component-detection.ts +508 -508
  40. package/src/core/components/enhanced-framework-detector.ts +500 -500
  41. package/src/core/components/framework-registry.ts +563 -563
  42. package/src/core/content/mdx-processor.ts +46 -46
  43. package/src/core/integrations/index.ts +19 -19
  44. package/src/core/integrations/loader.ts +125 -125
  45. package/src/core/integrations/registry.ts +175 -175
  46. package/src/core/islands/island-persistence.ts +325 -325
  47. package/src/core/islands/island-state-serializer.ts +258 -258
  48. package/src/core/islands/persistent-island-context.tsx +80 -80
  49. package/src/core/islands/use-persistent-state.ts +68 -68
  50. package/src/core/layout/enhanced-layout-resolver.ts +322 -322
  51. package/src/core/layout/layout-cache-manager.ts +485 -485
  52. package/src/core/layout/layout-composer.ts +357 -357
  53. package/src/core/layout/layout-data-loader.ts +516 -516
  54. package/src/core/layout/layout-discovery.ts +243 -243
  55. package/src/core/layout/layout-matcher.ts +299 -299
  56. package/src/core/layout/layout-types.ts +110 -110
  57. package/src/core/modules/framework-module-resolver.ts +273 -273
  58. package/src/islands/component-analysis.ts +213 -213
  59. package/src/islands/css-utils.ts +565 -565
  60. package/src/islands/discovery/index.ts +80 -80
  61. package/src/islands/discovery/registry.ts +340 -340
  62. package/src/islands/discovery/resolver.ts +477 -477
  63. package/src/islands/discovery/scanner.ts +386 -386
  64. package/src/islands/discovery/types.ts +117 -117
  65. package/src/islands/discovery/validator.ts +544 -544
  66. package/src/islands/discovery/watcher.ts +368 -368
  67. package/src/islands/framework-detection.ts +428 -428
  68. package/src/islands/integration-loader.ts +490 -490
  69. package/src/islands/island.tsx +565 -565
  70. package/src/islands/render-cache.ts +550 -550
  71. package/src/islands/types.ts +80 -80
  72. package/src/islands/universal-css-collector.ts +157 -157
  73. package/src/islands/universal-head-collector.ts +137 -137
  74. package/src/layout-system.d.ts +592 -592
  75. package/src/layout-system.ts +218 -218
  76. package/src/middleware/discovery.ts +268 -268
  77. package/src/middleware/executor.ts +315 -315
  78. package/src/middleware/index.ts +76 -76
  79. package/src/middleware/types.ts +99 -99
  80. package/src/nitro/build-config.ts +575 -575
  81. package/src/nitro/config.ts +483 -483
  82. package/src/nitro/error-handler.ts +636 -636
  83. package/src/nitro/index.ts +173 -173
  84. package/src/nitro/island-manifest.ts +584 -584
  85. package/src/nitro/middleware-adapter.ts +260 -260
  86. package/src/nitro/renderer.ts +1471 -1471
  87. package/src/nitro/route-discovery.ts +439 -439
  88. package/src/nitro/types.ts +321 -321
  89. package/src/render/collect-css.ts +198 -198
  90. package/src/render/error-pages.ts +79 -79
  91. package/src/render/isolated-ssr-renderer.ts +654 -654
  92. package/src/render/ssr.ts +1030 -1030
  93. package/src/schemas/api.ts +30 -30
  94. package/src/schemas/core.ts +64 -64
  95. package/src/schemas/index.ts +212 -212
  96. package/src/schemas/layout.ts +279 -279
  97. package/src/schemas/routing/index.ts +38 -38
  98. package/src/schemas/routing.ts +376 -376
  99. package/src/types/as-island.ts +20 -20
  100. package/src/types/image.d.ts +106 -106
  101. package/src/types/index.d.ts +22 -22
  102. package/src/types/island-jsx.d.ts +33 -33
  103. package/src/types/island-prop.d.ts +20 -20
  104. package/src/types/layout.ts +285 -285
  105. package/src/types/mdx.d.ts +6 -6
  106. package/src/types/routing.ts +555 -555
  107. package/src/types/types.ts +5 -5
  108. package/src/types/urlpattern.d.ts +49 -49
  109. package/src/types/vite-env.d.ts +11 -11
  110. package/src/utils/dev-logger.ts +299 -299
  111. package/src/utils/fs.ts +151 -151
  112. package/src/vite-plugin/auto-discover.ts +551 -551
  113. package/src/vite-plugin/config.ts +266 -266
  114. package/src/vite-plugin/errors.ts +127 -127
  115. package/src/vite-plugin/image-optimization.ts +156 -156
  116. package/src/vite-plugin/integration-activator.ts +126 -126
  117. package/src/vite-plugin/island-sidecar-plugin.ts +176 -176
  118. package/src/vite-plugin/module-discovery.ts +189 -189
  119. package/src/vite-plugin/nitro-integration.ts +1354 -1354
  120. package/src/vite-plugin/plugin.ts +403 -409
  121. package/src/vite-plugin/types.ts +327 -327
  122. package/src/vite-plugin/validation.ts +228 -228
  123. package/src/client/adapters/index.js +0 -12
  124. package/src/client/adapters/lit-adapter.js +0 -467
  125. package/src/client/adapters/lit-adapter.ts +0 -654
  126. package/src/client/adapters/preact-adapter.js +0 -223
  127. package/src/client/adapters/preact-adapter.ts +0 -331
  128. package/src/client/adapters/qwik-adapter.js +0 -259
  129. package/src/client/adapters/qwik-adapter.ts +0 -345
  130. package/src/client/adapters/react-adapter.js +0 -220
  131. package/src/client/adapters/react-adapter.ts +0 -353
  132. package/src/client/adapters/solid-adapter.js +0 -295
  133. package/src/client/adapters/solid-adapter.ts +0 -451
  134. package/src/client/adapters/svelte-adapter.js +0 -368
  135. package/src/client/adapters/svelte-adapter.ts +0 -524
  136. package/src/client/adapters/vue-adapter.js +0 -278
  137. package/src/client/adapters/vue-adapter.ts +0 -467
  138. package/src/client/components.js +0 -23
  139. package/src/client/css-hmr-handler.js +0 -263
  140. package/src/client/framework-adapter.js +0 -283
  141. package/src/client/hmr-coordinator.js +0 -274
@@ -1,563 +1,563 @@
1
- /**
2
- * Framework Registry and Configuration System
3
- *
4
- * This module provides a centralized registry for framework configurations,
5
- * validation utilities, and management of framework-specific detection patterns.
6
- */
7
-
8
- import type { FrameworkConfig } from './enhanced-framework-detector.ts';
9
-
10
- export interface FrameworkRegistryConfig {
11
- enableValidation: boolean;
12
- allowCustomFrameworks: boolean;
13
- defaultFramework: string;
14
- }
15
-
16
- export interface FrameworkValidationResult {
17
- isValid: boolean;
18
- errors: string[];
19
- warnings: string[];
20
- }
21
-
22
- /**
23
- * Centralized framework registry with validation and management
24
- */
25
- export class FrameworkRegistry {
26
- private readonly frameworks: Map<string, FrameworkConfig>;
27
- private readonly config: FrameworkRegistryConfig;
28
-
29
- constructor(config: Partial<FrameworkRegistryConfig> = {}) {
30
- this.frameworks = new Map();
31
- this.config = {
32
- enableValidation: true,
33
- allowCustomFrameworks: true,
34
- defaultFramework: 'unknown',
35
- ...config,
36
- };
37
-
38
- // Initialize with default frameworks
39
- this.initializeDefaultFrameworks();
40
- }
41
-
42
- /**
43
- * Registers a new framework configuration
44
- */
45
- registerFramework(name: string, config: FrameworkConfig): FrameworkValidationResult {
46
- const validation = this.validateFrameworkConfig(config);
47
-
48
- if (this.config.enableValidation && !validation.isValid) {
49
- return validation;
50
- }
51
-
52
- if (!this.config.allowCustomFrameworks && !this.isDefaultFramework(name)) {
53
- return {
54
- isValid: false,
55
- errors: [`Custom framework '${name}' not allowed`],
56
- warnings: [],
57
- };
58
- }
59
-
60
- this.frameworks.set(name, { ...config });
61
-
62
- return {
63
- isValid: true,
64
- errors: [],
65
- warnings: validation.warnings,
66
- };
67
- }
68
-
69
- /**
70
- * Gets a framework configuration by name
71
- */
72
- getFramework(name: string): FrameworkConfig | undefined {
73
- return this.frameworks.get(name);
74
- }
75
-
76
- /**
77
- * Gets all registered frameworks
78
- */
79
- getAllFrameworks(): Map<string, FrameworkConfig> {
80
- return new Map(this.frameworks);
81
- }
82
-
83
- /**
84
- * Gets framework names that support a specific file extension
85
- */
86
- getFrameworksByExtension(extension: string): string[] {
87
- const frameworks: string[] = [];
88
-
89
- for (const [name, config] of this.frameworks) {
90
- if (config.fileExtensions.includes(extension)) {
91
- frameworks.push(name);
92
- }
93
- }
94
-
95
- return frameworks;
96
- }
97
-
98
- /**
99
- * Gets frameworks that use a specific JSX import source
100
- */
101
- getFrameworksByJSXImportSource(importSource: string): string[] {
102
- const frameworks: string[] = [];
103
-
104
- for (const [name, config] of this.frameworks) {
105
- if (config.jsxImportSources.includes(importSource)) {
106
- frameworks.push(name);
107
- }
108
- }
109
-
110
- return frameworks;
111
- }
112
-
113
- /**
114
- * Removes a framework from the registry
115
- */
116
- unregisterFramework(name: string): boolean {
117
- if (this.isDefaultFramework(name)) {
118
- return false; // Cannot remove default frameworks
119
- }
120
-
121
- return this.frameworks.delete(name);
122
- }
123
-
124
- /**
125
- * Updates an existing framework configuration
126
- */
127
- updateFramework(name: string, updates: Partial<FrameworkConfig>): FrameworkValidationResult {
128
- const existing = this.frameworks.get(name);
129
- if (!existing) {
130
- return {
131
- isValid: false,
132
- errors: [`Framework '${name}' not found`],
133
- warnings: [],
134
- };
135
- }
136
-
137
- const updated = { ...existing, ...updates };
138
- const validation = this.validateFrameworkConfig(updated);
139
-
140
- if (this.config.enableValidation && !validation.isValid) {
141
- return validation;
142
- }
143
-
144
- this.frameworks.set(name, updated);
145
-
146
- return {
147
- isValid: true,
148
- errors: [],
149
- warnings: validation.warnings,
150
- };
151
- }
152
-
153
- /**
154
- * Validates a framework configuration
155
- */
156
- validateFrameworkConfig(config: FrameworkConfig): FrameworkValidationResult {
157
- const errors: string[] = [];
158
- const warnings: string[] = [];
159
-
160
- this.validateRequiredFields(config, errors, warnings);
161
- this.validateDetectionPatterns(config, errors, warnings);
162
- this.validateCrossFrameworkConflicts(config, warnings);
163
-
164
- return { isValid: errors.length === 0, errors, warnings };
165
- }
166
-
167
- /** Validate required top-level fields on a framework config */
168
- private validateRequiredFields(config: FrameworkConfig, errors: string[], warnings: string[]): void {
169
- if (!config.name || config.name.trim() === '') {
170
- errors.push('Framework name is required and cannot be empty');
171
- }
172
-
173
- if (!config.fileExtensions || config.fileExtensions.length === 0) {
174
- errors.push('At least one file extension is required');
175
- } else {
176
- for (const ext of config.fileExtensions) {
177
- if (!ext.startsWith('.')) {
178
- errors.push(`File extension '${ext}' must start with a dot`);
179
- }
180
- }
181
- }
182
-
183
- if (!config.jsxImportSources || config.jsxImportSources.length === 0) {
184
- warnings.push('No JSX import sources defined - detection may be less accurate');
185
- }
186
-
187
- if (!config.ssrModules || config.ssrModules.length === 0) {
188
- errors.push('At least one SSR module is required');
189
- }
190
-
191
- if (!config.hydrationModules || config.hydrationModules.length === 0) {
192
- errors.push('At least one hydration module is required');
193
- }
194
- }
195
-
196
- /** Validate the detectionPatterns sub-object */
197
- private validateDetectionPatterns(config: FrameworkConfig, errors: string[], warnings: string[]): void {
198
- if (!config.detectionPatterns) {
199
- errors.push('Detection patterns are required');
200
- return;
201
- }
202
-
203
- if (!config.detectionPatterns.imports || config.detectionPatterns.imports.length === 0) {
204
- errors.push('At least one import pattern is required for detection');
205
- }
206
- if (!config.detectionPatterns.content || config.detectionPatterns.content.length === 0) {
207
- warnings.push('No content patterns defined - detection may be less accurate');
208
- }
209
- if (!config.detectionPatterns.jsxPragmas || config.detectionPatterns.jsxPragmas.length === 0) {
210
- warnings.push('No JSX pragmas defined - detection may be less accurate');
211
- }
212
- }
213
-
214
- /**
215
- * Checks for potential conflicts with other registered frameworks
216
- */
217
- private validateCrossFrameworkConflicts(config: FrameworkConfig, warnings: string[]): void {
218
- // Skip validation if config is incomplete
219
- if (!config.fileExtensions || !config.jsxImportSources) {
220
- return;
221
- }
222
-
223
- for (const [existingName, existingConfig] of this.frameworks) {
224
- if (existingName === config.name) continue;
225
-
226
- // Check for overlapping file extensions
227
- if (existingConfig.fileExtensions) {
228
- const overlappingExtensions = config.fileExtensions.filter(ext => existingConfig.fileExtensions.includes(ext));
229
-
230
- if (overlappingExtensions.length > 0) {
231
- warnings.push(`File extensions ${overlappingExtensions.join(', ')} overlap with framework '${existingName}'`);
232
- }
233
- }
234
-
235
- // Check for overlapping JSX import sources
236
- if (existingConfig.jsxImportSources) {
237
- const overlappingImportSources = config.jsxImportSources.filter(source =>
238
- existingConfig.jsxImportSources.includes(source)
239
- );
240
-
241
- if (overlappingImportSources.length > 0) {
242
- warnings.push(
243
- `JSX import sources ${overlappingImportSources.join(', ')} overlap with framework '${existingName}'`
244
- );
245
- }
246
- }
247
- }
248
- }
249
-
250
- /**
251
- * Checks if a framework is a default framework
252
- */
253
- private isDefaultFramework(name: string): boolean {
254
- return ['preact', 'solid', 'vue', 'svelte', 'react', 'lit', 'qwik'].includes(name);
255
- }
256
-
257
- /**
258
- * Initializes the registry with default framework configurations
259
- */
260
- private initializeDefaultFrameworks(): void {
261
- const defaultFrameworks = this.getDefaultFrameworkConfigs();
262
-
263
- for (const [name, config] of Object.entries(defaultFrameworks)) {
264
- this.frameworks.set(name, config);
265
- }
266
- }
267
-
268
- /**
269
- * Gets default framework configurations
270
- */
271
- private getDefaultFrameworkConfigs(): Record<string, FrameworkConfig> {
272
- return {
273
- preact: {
274
- name: 'preact',
275
- fileExtensions: ['.tsx', '.jsx'],
276
- jsxImportSources: ['preact'],
277
- ssrModules: ['preact-render-to-string'],
278
- hydrationModules: ['preact'],
279
- detectionPatterns: {
280
- imports: [/^preact$/, /^preact\//, /preact-render-to-string/],
281
- content: [
282
- /\buseState\b/,
283
- /\buseEffect\b/,
284
- /\buseCallback\b/,
285
- /\buseMemo\b/,
286
- /\buseRef\b/,
287
- /\buseContext\b/,
288
- /\buseReducer\b/,
289
- /from\s+['"]preact['"]/,
290
- /import\s+.*\s+from\s+['"]preact['"]/,
291
- ],
292
- jsxPragmas: ['@jsxImportSource preact'],
293
- },
294
- },
295
- solid: {
296
- name: 'solid',
297
- fileExtensions: ['.tsx', '.jsx'],
298
- jsxImportSources: ['solid-js'],
299
- ssrModules: ['solid-js/web'],
300
- hydrationModules: ['solid-js/web'],
301
- detectionPatterns: {
302
- imports: [/^solid-js$/, /^solid-js\//, /solid-js\/web/, /solid-js\/store/],
303
- content: [
304
- /\bcreateSignal\b/,
305
- /\bcreateEffect\b/,
306
- /\bcreateMemo\b/,
307
- /\bcreateResource\b/,
308
- /\bcreateStore\b/,
309
- /\bonMount\b/,
310
- /\bonCleanup\b/,
311
- /\bShow\b/,
312
- /\bFor\b/,
313
- /from\s+['"]solid-js['"]/,
314
- /import\s+.*\s+from\s+['"]solid-js['"]/,
315
- ],
316
- jsxPragmas: ['@jsxImportSource solid-js'],
317
- },
318
- },
319
- vue: {
320
- name: 'vue',
321
- fileExtensions: ['.vue'],
322
- jsxImportSources: ['vue'],
323
- ssrModules: ['vue/server-renderer'],
324
- hydrationModules: ['vue'],
325
- detectionPatterns: {
326
- imports: [/^vue$/, /^@vue\//, /vue\/server-renderer/, /vue\/composition-api/],
327
- content: [
328
- /<template>/,
329
- /<script>/,
330
- /<style>/,
331
- /\bref\b/,
332
- /\breactive\b/,
333
- /\bcomputed\b/,
334
- /\bwatchEffect\b/,
335
- /\bwatch\b/,
336
- /\bonMounted\b/,
337
- /\bonUnmounted\b/,
338
- /from\s+['"]vue['"]/,
339
- /import\s+.*\s+from\s+['"]vue['"]/,
340
- ],
341
- jsxPragmas: ['@jsxImportSource vue'],
342
- },
343
- },
344
- svelte: {
345
- name: 'svelte',
346
- fileExtensions: ['.svelte'],
347
- jsxImportSources: ['svelte'],
348
- ssrModules: ['svelte/server'],
349
- hydrationModules: ['svelte'],
350
- detectionPatterns: {
351
- imports: [/^svelte$/, /^svelte\//, /svelte\/store/, /svelte\/motion/, /svelte\/transition/],
352
- content: [
353
- /<script>/,
354
- /<style>/,
355
- /\$:/,
356
- /\bonMount\b/,
357
- /\bafterUpdate\b/,
358
- /\bbeforeUpdate\b/,
359
- /\bonDestroy\b/,
360
- /\btick\b/,
361
- /from\s+['"]svelte['"]/,
362
- /import\s+.*\s+from\s+['"]svelte['"]/,
363
- ],
364
- jsxPragmas: ['@jsxImportSource svelte'],
365
- },
366
- },
367
- react: {
368
- name: 'react',
369
- fileExtensions: ['.jsx', '.tsx'],
370
- jsxImportSources: ['react'],
371
- ssrModules: ['react-dom/server'],
372
- hydrationModules: ['react-dom/client'],
373
- detectionPatterns: {
374
- imports: [
375
- /^react$/,
376
- /^react\//,
377
- /^react-dom$/,
378
- /^react-dom\//,
379
- /from\s+['"]react['"]/,
380
- /from\s+['"]react\/[^'"]+['"]/,
381
- /from\s+['"]react-dom['"]/,
382
- ],
383
- content: [
384
- /\buseState\b/,
385
- /\buseEffect\b/,
386
- /\buseContext\b/,
387
- /\buseReducer\b/,
388
- /\buseCallback\b/,
389
- /\buseMemo\b/,
390
- /\buseRef\b/,
391
- /\buseTransition\b/,
392
- /\buseDeferredValue\b/,
393
- /\buseId\b/,
394
- /\buseImperativeHandle\b/,
395
- /\buseLayoutEffect\b/,
396
- /["']use client["']/,
397
- /["']use server["']/,
398
- /from\s+['"]react['"]/,
399
- /import\s+.*\s+from\s+['"]react['"]/,
400
- ],
401
- jsxPragmas: ['@jsxImportSource react'],
402
- },
403
- },
404
- lit: {
405
- name: 'lit',
406
- fileExtensions: ['.ts', '.js'],
407
- jsxImportSources: ['lit'],
408
- ssrModules: ['@lit-labs/ssr'],
409
- hydrationModules: ['lit'],
410
- detectionPatterns: {
411
- imports: [
412
- /^lit$/,
413
- /^lit\//,
414
- /^@lit\//,
415
- /^@lit-labs\/ssr/,
416
- /from\s+['"]lit['"]/,
417
- /from\s+['"]lit\/[^'"]+['"]/,
418
- /from\s+['"]@lit\/[^'"]+['"]/,
419
- ],
420
- content: [
421
- /\bLitElement\b/,
422
- /\bcustomElement\b/,
423
- /@customElement/,
424
- /@property/,
425
- /@state/,
426
- /@query/,
427
- /@queryAll/,
428
- /\bhtml`/,
429
- /\bcss`/,
430
- /extends\s+LitElement/,
431
- /from\s+['"]lit['"]/,
432
- /import\s+.*\s+from\s+['"]lit['"]/,
433
- ],
434
- jsxPragmas: ['@jsxImportSource lit'],
435
- },
436
- },
437
- qwik: {
438
- name: 'qwik',
439
- fileExtensions: ['.tsx', '.jsx'],
440
- jsxImportSources: ['@builder.io/qwik'],
441
- ssrModules: ['@builder.io/qwik/server'],
442
- hydrationModules: ['@builder.io/qwik'],
443
- detectionPatterns: {
444
- imports: [
445
- /^@builder\.io\/qwik$/,
446
- /^@builder\.io\/qwik\//,
447
- /from\s+['"]@builder\.io\/qwik['"]/,
448
- /from\s+['"]@builder\.io\/qwik\/[^'"]+['"]/,
449
- ],
450
- content: [
451
- /\bcomponent\$/,
452
- /\buseSignal\b/,
453
- /\buseStore\b/,
454
- /\buseTask\$/,
455
- /\buseVisibleTask\$/,
456
- /\buseResource\$/,
457
- /\buseContext\b/,
458
- /\$\(\s*\(/,
459
- /from\s+['"]@builder\.io\/qwik['"]/,
460
- /import\s+.*\s+from\s+['"]@builder\.io\/qwik['"]/,
461
- ],
462
- jsxPragmas: ['@jsxImportSource @builder.io/qwik'],
463
- },
464
- },
465
- };
466
- }
467
-
468
- /**
469
- * Exports the current registry configuration
470
- */
471
- exportConfig(): Record<string, FrameworkConfig> {
472
- const config: Record<string, FrameworkConfig> = {};
473
-
474
- for (const [name, frameworkConfig] of this.frameworks) {
475
- config[name] = { ...frameworkConfig };
476
- }
477
-
478
- return config;
479
- }
480
-
481
- /**
482
- * Imports a registry configuration
483
- */
484
- importConfig(config: Record<string, FrameworkConfig>): FrameworkValidationResult[] {
485
- const results: FrameworkValidationResult[] = [];
486
-
487
- for (const [name, frameworkConfig] of Object.entries(config)) {
488
- const result = this.registerFramework(name, frameworkConfig);
489
- results.push(result);
490
- }
491
-
492
- return results;
493
- }
494
-
495
- /**
496
- * Resets the registry to default frameworks only
497
- */
498
- reset(): void {
499
- this.frameworks.clear();
500
- this.initializeDefaultFrameworks();
501
- }
502
-
503
- /**
504
- * Gets registry statistics
505
- */
506
- getStats(): {
507
- totalFrameworks: number;
508
- defaultFrameworks: number;
509
- customFrameworks: number;
510
- supportedExtensions: string[];
511
- } {
512
- const defaultFrameworkNames = new Set(['preact', 'solid', 'vue', 'svelte', 'react', 'lit', 'qwik']);
513
- const defaultCount = Array.from(this.frameworks.keys()).filter(name => defaultFrameworkNames.has(name)).length;
514
-
515
- const allExtensions = new Set<string>();
516
- for (const config of this.frameworks.values()) {
517
- config.fileExtensions.forEach(ext => allExtensions.add(ext));
518
- }
519
-
520
- return {
521
- totalFrameworks: this.frameworks.size,
522
- defaultFrameworks: defaultCount,
523
- customFrameworks: this.frameworks.size - defaultCount,
524
- supportedExtensions: Array.from(allExtensions).sort((a, b) => a.localeCompare(b)),
525
- };
526
- }
527
- }
528
-
529
- /**
530
- * Default framework registry instance
531
- */
532
- export const defaultFrameworkRegistry = new FrameworkRegistry();
533
-
534
- /**
535
- * Utility function to create a framework configuration
536
- */
537
- export function createFrameworkConfig(
538
- name: string,
539
- options: {
540
- fileExtensions: string[];
541
- jsxImportSources?: string[];
542
- ssrModules: string[];
543
- hydrationModules: string[];
544
- importPatterns: (string | RegExp)[];
545
- contentPatterns?: (string | RegExp)[];
546
- jsxPragmas?: string[];
547
- }
548
- ): FrameworkConfig {
549
- return {
550
- name,
551
- fileExtensions: options.fileExtensions,
552
- jsxImportSources: options.jsxImportSources || [],
553
- ssrModules: options.ssrModules,
554
- hydrationModules: options.hydrationModules,
555
- detectionPatterns: {
556
- imports: options.importPatterns.map(pattern => (typeof pattern === 'string' ? new RegExp(pattern) : pattern)),
557
- content: (options.contentPatterns || []).map(pattern =>
558
- typeof pattern === 'string' ? new RegExp(pattern) : pattern
559
- ),
560
- jsxPragmas: options.jsxPragmas || [],
561
- },
562
- };
563
- }
1
+ /**
2
+ * Framework Registry and Configuration System
3
+ *
4
+ * This module provides a centralized registry for framework configurations,
5
+ * validation utilities, and management of framework-specific detection patterns.
6
+ */
7
+
8
+ import type { FrameworkConfig } from './enhanced-framework-detector.ts';
9
+
10
+ export interface FrameworkRegistryConfig {
11
+ enableValidation: boolean;
12
+ allowCustomFrameworks: boolean;
13
+ defaultFramework: string;
14
+ }
15
+
16
+ export interface FrameworkValidationResult {
17
+ isValid: boolean;
18
+ errors: string[];
19
+ warnings: string[];
20
+ }
21
+
22
+ /**
23
+ * Centralized framework registry with validation and management
24
+ */
25
+ export class FrameworkRegistry {
26
+ private readonly frameworks: Map<string, FrameworkConfig>;
27
+ private readonly config: FrameworkRegistryConfig;
28
+
29
+ constructor(config: Partial<FrameworkRegistryConfig> = {}) {
30
+ this.frameworks = new Map();
31
+ this.config = {
32
+ enableValidation: true,
33
+ allowCustomFrameworks: true,
34
+ defaultFramework: 'unknown',
35
+ ...config,
36
+ };
37
+
38
+ // Initialize with default frameworks
39
+ this.initializeDefaultFrameworks();
40
+ }
41
+
42
+ /**
43
+ * Registers a new framework configuration
44
+ */
45
+ registerFramework(name: string, config: FrameworkConfig): FrameworkValidationResult {
46
+ const validation = this.validateFrameworkConfig(config);
47
+
48
+ if (this.config.enableValidation && !validation.isValid) {
49
+ return validation;
50
+ }
51
+
52
+ if (!this.config.allowCustomFrameworks && !this.isDefaultFramework(name)) {
53
+ return {
54
+ isValid: false,
55
+ errors: [`Custom framework '${name}' not allowed`],
56
+ warnings: [],
57
+ };
58
+ }
59
+
60
+ this.frameworks.set(name, { ...config });
61
+
62
+ return {
63
+ isValid: true,
64
+ errors: [],
65
+ warnings: validation.warnings,
66
+ };
67
+ }
68
+
69
+ /**
70
+ * Gets a framework configuration by name
71
+ */
72
+ getFramework(name: string): FrameworkConfig | undefined {
73
+ return this.frameworks.get(name);
74
+ }
75
+
76
+ /**
77
+ * Gets all registered frameworks
78
+ */
79
+ getAllFrameworks(): Map<string, FrameworkConfig> {
80
+ return new Map(this.frameworks);
81
+ }
82
+
83
+ /**
84
+ * Gets framework names that support a specific file extension
85
+ */
86
+ getFrameworksByExtension(extension: string): string[] {
87
+ const frameworks: string[] = [];
88
+
89
+ for (const [name, config] of this.frameworks) {
90
+ if (config.fileExtensions.includes(extension)) {
91
+ frameworks.push(name);
92
+ }
93
+ }
94
+
95
+ return frameworks;
96
+ }
97
+
98
+ /**
99
+ * Gets frameworks that use a specific JSX import source
100
+ */
101
+ getFrameworksByJSXImportSource(importSource: string): string[] {
102
+ const frameworks: string[] = [];
103
+
104
+ for (const [name, config] of this.frameworks) {
105
+ if (config.jsxImportSources.includes(importSource)) {
106
+ frameworks.push(name);
107
+ }
108
+ }
109
+
110
+ return frameworks;
111
+ }
112
+
113
+ /**
114
+ * Removes a framework from the registry
115
+ */
116
+ unregisterFramework(name: string): boolean {
117
+ if (this.isDefaultFramework(name)) {
118
+ return false; // Cannot remove default frameworks
119
+ }
120
+
121
+ return this.frameworks.delete(name);
122
+ }
123
+
124
+ /**
125
+ * Updates an existing framework configuration
126
+ */
127
+ updateFramework(name: string, updates: Partial<FrameworkConfig>): FrameworkValidationResult {
128
+ const existing = this.frameworks.get(name);
129
+ if (!existing) {
130
+ return {
131
+ isValid: false,
132
+ errors: [`Framework '${name}' not found`],
133
+ warnings: [],
134
+ };
135
+ }
136
+
137
+ const updated = { ...existing, ...updates };
138
+ const validation = this.validateFrameworkConfig(updated);
139
+
140
+ if (this.config.enableValidation && !validation.isValid) {
141
+ return validation;
142
+ }
143
+
144
+ this.frameworks.set(name, updated);
145
+
146
+ return {
147
+ isValid: true,
148
+ errors: [],
149
+ warnings: validation.warnings,
150
+ };
151
+ }
152
+
153
+ /**
154
+ * Validates a framework configuration
155
+ */
156
+ validateFrameworkConfig(config: FrameworkConfig): FrameworkValidationResult {
157
+ const errors: string[] = [];
158
+ const warnings: string[] = [];
159
+
160
+ this.validateRequiredFields(config, errors, warnings);
161
+ this.validateDetectionPatterns(config, errors, warnings);
162
+ this.validateCrossFrameworkConflicts(config, warnings);
163
+
164
+ return { isValid: errors.length === 0, errors, warnings };
165
+ }
166
+
167
+ /** Validate required top-level fields on a framework config */
168
+ private validateRequiredFields(config: FrameworkConfig, errors: string[], warnings: string[]): void {
169
+ if (!config.name || config.name.trim() === '') {
170
+ errors.push('Framework name is required and cannot be empty');
171
+ }
172
+
173
+ if (!config.fileExtensions || config.fileExtensions.length === 0) {
174
+ errors.push('At least one file extension is required');
175
+ } else {
176
+ for (const ext of config.fileExtensions) {
177
+ if (!ext.startsWith('.')) {
178
+ errors.push(`File extension '${ext}' must start with a dot`);
179
+ }
180
+ }
181
+ }
182
+
183
+ if (!config.jsxImportSources || config.jsxImportSources.length === 0) {
184
+ warnings.push('No JSX import sources defined - detection may be less accurate');
185
+ }
186
+
187
+ if (!config.ssrModules || config.ssrModules.length === 0) {
188
+ errors.push('At least one SSR module is required');
189
+ }
190
+
191
+ if (!config.hydrationModules || config.hydrationModules.length === 0) {
192
+ errors.push('At least one hydration module is required');
193
+ }
194
+ }
195
+
196
+ /** Validate the detectionPatterns sub-object */
197
+ private validateDetectionPatterns(config: FrameworkConfig, errors: string[], warnings: string[]): void {
198
+ if (!config.detectionPatterns) {
199
+ errors.push('Detection patterns are required');
200
+ return;
201
+ }
202
+
203
+ if (!config.detectionPatterns.imports || config.detectionPatterns.imports.length === 0) {
204
+ errors.push('At least one import pattern is required for detection');
205
+ }
206
+ if (!config.detectionPatterns.content || config.detectionPatterns.content.length === 0) {
207
+ warnings.push('No content patterns defined - detection may be less accurate');
208
+ }
209
+ if (!config.detectionPatterns.jsxPragmas || config.detectionPatterns.jsxPragmas.length === 0) {
210
+ warnings.push('No JSX pragmas defined - detection may be less accurate');
211
+ }
212
+ }
213
+
214
+ /**
215
+ * Checks for potential conflicts with other registered frameworks
216
+ */
217
+ private validateCrossFrameworkConflicts(config: FrameworkConfig, warnings: string[]): void {
218
+ // Skip validation if config is incomplete
219
+ if (!config.fileExtensions || !config.jsxImportSources) {
220
+ return;
221
+ }
222
+
223
+ for (const [existingName, existingConfig] of this.frameworks) {
224
+ if (existingName === config.name) continue;
225
+
226
+ // Check for overlapping file extensions
227
+ if (existingConfig.fileExtensions) {
228
+ const overlappingExtensions = config.fileExtensions.filter(ext => existingConfig.fileExtensions.includes(ext));
229
+
230
+ if (overlappingExtensions.length > 0) {
231
+ warnings.push(`File extensions ${overlappingExtensions.join(', ')} overlap with framework '${existingName}'`);
232
+ }
233
+ }
234
+
235
+ // Check for overlapping JSX import sources
236
+ if (existingConfig.jsxImportSources) {
237
+ const overlappingImportSources = config.jsxImportSources.filter(source =>
238
+ existingConfig.jsxImportSources.includes(source)
239
+ );
240
+
241
+ if (overlappingImportSources.length > 0) {
242
+ warnings.push(
243
+ `JSX import sources ${overlappingImportSources.join(', ')} overlap with framework '${existingName}'`
244
+ );
245
+ }
246
+ }
247
+ }
248
+ }
249
+
250
+ /**
251
+ * Checks if a framework is a default framework
252
+ */
253
+ private isDefaultFramework(name: string): boolean {
254
+ return ['preact', 'solid', 'vue', 'svelte', 'react', 'lit', 'qwik'].includes(name);
255
+ }
256
+
257
+ /**
258
+ * Initializes the registry with default framework configurations
259
+ */
260
+ private initializeDefaultFrameworks(): void {
261
+ const defaultFrameworks = this.getDefaultFrameworkConfigs();
262
+
263
+ for (const [name, config] of Object.entries(defaultFrameworks)) {
264
+ this.frameworks.set(name, config);
265
+ }
266
+ }
267
+
268
+ /**
269
+ * Gets default framework configurations
270
+ */
271
+ private getDefaultFrameworkConfigs(): Record<string, FrameworkConfig> {
272
+ return {
273
+ preact: {
274
+ name: 'preact',
275
+ fileExtensions: ['.tsx', '.jsx'],
276
+ jsxImportSources: ['preact'],
277
+ ssrModules: ['preact-render-to-string'],
278
+ hydrationModules: ['preact'],
279
+ detectionPatterns: {
280
+ imports: [/^preact$/, /^preact\//, /preact-render-to-string/],
281
+ content: [
282
+ /\buseState\b/,
283
+ /\buseEffect\b/,
284
+ /\buseCallback\b/,
285
+ /\buseMemo\b/,
286
+ /\buseRef\b/,
287
+ /\buseContext\b/,
288
+ /\buseReducer\b/,
289
+ /from\s+['"]preact['"]/,
290
+ /import\s+.*\s+from\s+['"]preact['"]/,
291
+ ],
292
+ jsxPragmas: ['@jsxImportSource preact'],
293
+ },
294
+ },
295
+ solid: {
296
+ name: 'solid',
297
+ fileExtensions: ['.tsx', '.jsx'],
298
+ jsxImportSources: ['solid-js'],
299
+ ssrModules: ['solid-js/web'],
300
+ hydrationModules: ['solid-js/web'],
301
+ detectionPatterns: {
302
+ imports: [/^solid-js$/, /^solid-js\//, /solid-js\/web/, /solid-js\/store/],
303
+ content: [
304
+ /\bcreateSignal\b/,
305
+ /\bcreateEffect\b/,
306
+ /\bcreateMemo\b/,
307
+ /\bcreateResource\b/,
308
+ /\bcreateStore\b/,
309
+ /\bonMount\b/,
310
+ /\bonCleanup\b/,
311
+ /\bShow\b/,
312
+ /\bFor\b/,
313
+ /from\s+['"]solid-js['"]/,
314
+ /import\s+.*\s+from\s+['"]solid-js['"]/,
315
+ ],
316
+ jsxPragmas: ['@jsxImportSource solid-js'],
317
+ },
318
+ },
319
+ vue: {
320
+ name: 'vue',
321
+ fileExtensions: ['.vue'],
322
+ jsxImportSources: ['vue'],
323
+ ssrModules: ['vue/server-renderer'],
324
+ hydrationModules: ['vue'],
325
+ detectionPatterns: {
326
+ imports: [/^vue$/, /^@vue\//, /vue\/server-renderer/, /vue\/composition-api/],
327
+ content: [
328
+ /<template>/,
329
+ /<script>/,
330
+ /<style>/,
331
+ /\bref\b/,
332
+ /\breactive\b/,
333
+ /\bcomputed\b/,
334
+ /\bwatchEffect\b/,
335
+ /\bwatch\b/,
336
+ /\bonMounted\b/,
337
+ /\bonUnmounted\b/,
338
+ /from\s+['"]vue['"]/,
339
+ /import\s+.*\s+from\s+['"]vue['"]/,
340
+ ],
341
+ jsxPragmas: ['@jsxImportSource vue'],
342
+ },
343
+ },
344
+ svelte: {
345
+ name: 'svelte',
346
+ fileExtensions: ['.svelte'],
347
+ jsxImportSources: ['svelte'],
348
+ ssrModules: ['svelte/server'],
349
+ hydrationModules: ['svelte'],
350
+ detectionPatterns: {
351
+ imports: [/^svelte$/, /^svelte\//, /svelte\/store/, /svelte\/motion/, /svelte\/transition/],
352
+ content: [
353
+ /<script>/,
354
+ /<style>/,
355
+ /\$:/,
356
+ /\bonMount\b/,
357
+ /\bafterUpdate\b/,
358
+ /\bbeforeUpdate\b/,
359
+ /\bonDestroy\b/,
360
+ /\btick\b/,
361
+ /from\s+['"]svelte['"]/,
362
+ /import\s+.*\s+from\s+['"]svelte['"]/,
363
+ ],
364
+ jsxPragmas: ['@jsxImportSource svelte'],
365
+ },
366
+ },
367
+ react: {
368
+ name: 'react',
369
+ fileExtensions: ['.jsx', '.tsx'],
370
+ jsxImportSources: ['react'],
371
+ ssrModules: ['react-dom/server'],
372
+ hydrationModules: ['react-dom/client'],
373
+ detectionPatterns: {
374
+ imports: [
375
+ /^react$/,
376
+ /^react\//,
377
+ /^react-dom$/,
378
+ /^react-dom\//,
379
+ /from\s+['"]react['"]/,
380
+ /from\s+['"]react\/[^'"]+['"]/,
381
+ /from\s+['"]react-dom['"]/,
382
+ ],
383
+ content: [
384
+ /\buseState\b/,
385
+ /\buseEffect\b/,
386
+ /\buseContext\b/,
387
+ /\buseReducer\b/,
388
+ /\buseCallback\b/,
389
+ /\buseMemo\b/,
390
+ /\buseRef\b/,
391
+ /\buseTransition\b/,
392
+ /\buseDeferredValue\b/,
393
+ /\buseId\b/,
394
+ /\buseImperativeHandle\b/,
395
+ /\buseLayoutEffect\b/,
396
+ /["']use client["']/,
397
+ /["']use server["']/,
398
+ /from\s+['"]react['"]/,
399
+ /import\s+.*\s+from\s+['"]react['"]/,
400
+ ],
401
+ jsxPragmas: ['@jsxImportSource react'],
402
+ },
403
+ },
404
+ lit: {
405
+ name: 'lit',
406
+ fileExtensions: ['.ts', '.js'],
407
+ jsxImportSources: ['lit'],
408
+ ssrModules: ['@lit-labs/ssr'],
409
+ hydrationModules: ['lit'],
410
+ detectionPatterns: {
411
+ imports: [
412
+ /^lit$/,
413
+ /^lit\//,
414
+ /^@lit\//,
415
+ /^@lit-labs\/ssr/,
416
+ /from\s+['"]lit['"]/,
417
+ /from\s+['"]lit\/[^'"]+['"]/,
418
+ /from\s+['"]@lit\/[^'"]+['"]/,
419
+ ],
420
+ content: [
421
+ /\bLitElement\b/,
422
+ /\bcustomElement\b/,
423
+ /@customElement/,
424
+ /@property/,
425
+ /@state/,
426
+ /@query/,
427
+ /@queryAll/,
428
+ /\bhtml`/,
429
+ /\bcss`/,
430
+ /extends\s+LitElement/,
431
+ /from\s+['"]lit['"]/,
432
+ /import\s+.*\s+from\s+['"]lit['"]/,
433
+ ],
434
+ jsxPragmas: ['@jsxImportSource lit'],
435
+ },
436
+ },
437
+ qwik: {
438
+ name: 'qwik',
439
+ fileExtensions: ['.tsx', '.jsx'],
440
+ jsxImportSources: ['@builder.io/qwik'],
441
+ ssrModules: ['@builder.io/qwik/server'],
442
+ hydrationModules: ['@builder.io/qwik'],
443
+ detectionPatterns: {
444
+ imports: [
445
+ /^@builder\.io\/qwik$/,
446
+ /^@builder\.io\/qwik\//,
447
+ /from\s+['"]@builder\.io\/qwik['"]/,
448
+ /from\s+['"]@builder\.io\/qwik\/[^'"]+['"]/,
449
+ ],
450
+ content: [
451
+ /\bcomponent\$/,
452
+ /\buseSignal\b/,
453
+ /\buseStore\b/,
454
+ /\buseTask\$/,
455
+ /\buseVisibleTask\$/,
456
+ /\buseResource\$/,
457
+ /\buseContext\b/,
458
+ /\$\(\s*\(/,
459
+ /from\s+['"]@builder\.io\/qwik['"]/,
460
+ /import\s+.*\s+from\s+['"]@builder\.io\/qwik['"]/,
461
+ ],
462
+ jsxPragmas: ['@jsxImportSource @builder.io/qwik'],
463
+ },
464
+ },
465
+ };
466
+ }
467
+
468
+ /**
469
+ * Exports the current registry configuration
470
+ */
471
+ exportConfig(): Record<string, FrameworkConfig> {
472
+ const config: Record<string, FrameworkConfig> = {};
473
+
474
+ for (const [name, frameworkConfig] of this.frameworks) {
475
+ config[name] = { ...frameworkConfig };
476
+ }
477
+
478
+ return config;
479
+ }
480
+
481
+ /**
482
+ * Imports a registry configuration
483
+ */
484
+ importConfig(config: Record<string, FrameworkConfig>): FrameworkValidationResult[] {
485
+ const results: FrameworkValidationResult[] = [];
486
+
487
+ for (const [name, frameworkConfig] of Object.entries(config)) {
488
+ const result = this.registerFramework(name, frameworkConfig);
489
+ results.push(result);
490
+ }
491
+
492
+ return results;
493
+ }
494
+
495
+ /**
496
+ * Resets the registry to default frameworks only
497
+ */
498
+ reset(): void {
499
+ this.frameworks.clear();
500
+ this.initializeDefaultFrameworks();
501
+ }
502
+
503
+ /**
504
+ * Gets registry statistics
505
+ */
506
+ getStats(): {
507
+ totalFrameworks: number;
508
+ defaultFrameworks: number;
509
+ customFrameworks: number;
510
+ supportedExtensions: string[];
511
+ } {
512
+ const defaultFrameworkNames = new Set(['preact', 'solid', 'vue', 'svelte', 'react', 'lit', 'qwik']);
513
+ const defaultCount = Array.from(this.frameworks.keys()).filter(name => defaultFrameworkNames.has(name)).length;
514
+
515
+ const allExtensions = new Set<string>();
516
+ for (const config of this.frameworks.values()) {
517
+ config.fileExtensions.forEach(ext => allExtensions.add(ext));
518
+ }
519
+
520
+ return {
521
+ totalFrameworks: this.frameworks.size,
522
+ defaultFrameworks: defaultCount,
523
+ customFrameworks: this.frameworks.size - defaultCount,
524
+ supportedExtensions: Array.from(allExtensions).sort((a, b) => a.localeCompare(b)),
525
+ };
526
+ }
527
+ }
528
+
529
+ /**
530
+ * Default framework registry instance
531
+ */
532
+ export const defaultFrameworkRegistry = new FrameworkRegistry();
533
+
534
+ /**
535
+ * Utility function to create a framework configuration
536
+ */
537
+ export function createFrameworkConfig(
538
+ name: string,
539
+ options: {
540
+ fileExtensions: string[];
541
+ jsxImportSources?: string[];
542
+ ssrModules: string[];
543
+ hydrationModules: string[];
544
+ importPatterns: (string | RegExp)[];
545
+ contentPatterns?: (string | RegExp)[];
546
+ jsxPragmas?: string[];
547
+ }
548
+ ): FrameworkConfig {
549
+ return {
550
+ name,
551
+ fileExtensions: options.fileExtensions,
552
+ jsxImportSources: options.jsxImportSources || [],
553
+ ssrModules: options.ssrModules,
554
+ hydrationModules: options.hydrationModules,
555
+ detectionPatterns: {
556
+ imports: options.importPatterns.map(pattern => (typeof pattern === 'string' ? new RegExp(pattern) : pattern)),
557
+ content: (options.contentPatterns || []).map(pattern =>
558
+ typeof pattern === 'string' ? new RegExp(pattern) : pattern
559
+ ),
560
+ jsxPragmas: options.jsxPragmas || [],
561
+ },
562
+ };
563
+ }