@useavalon/avalon 0.1.5 → 0.1.7

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 (39) hide show
  1. package/package.json +31 -58
  2. package/src/build/prop-extractors/index.ts +11 -11
  3. package/src/build/prop-extractors/lit.ts +1 -1
  4. package/src/build/prop-extractors/qwik.ts +2 -2
  5. package/src/build/prop-extractors/solid.ts +1 -1
  6. package/src/build/prop-extractors/svelte.ts +1 -1
  7. package/src/schemas/routing.ts +2 -2
  8. package/src/vite-plugin/nitro-integration.ts +1 -1
  9. package/src/vite-plugin/plugin.ts +20 -16
  10. package/src/build/README.md +0 -310
  11. package/src/client/tests/css-hmr-handler.test.ts +0 -360
  12. package/src/client/tests/framework-adapter.test.ts +0 -519
  13. package/src/client/tests/hmr-coordinator.test.ts +0 -176
  14. package/src/client/tests/hydration-option-parsing.test.ts +0 -107
  15. package/src/client/tests/lit-adapter.test.ts +0 -427
  16. package/src/client/tests/preact-adapter.test.ts +0 -353
  17. package/src/client/tests/qwik-adapter.test.ts +0 -343
  18. package/src/client/tests/react-adapter.test.ts +0 -317
  19. package/src/client/tests/solid-adapter.test.ts +0 -396
  20. package/src/client/tests/svelte-adapter.test.ts +0 -387
  21. package/src/client/tests/vue-adapter.test.ts +0 -407
  22. package/src/components/tests/component-analyzer.test.ts +0 -96
  23. package/src/components/tests/component-detection.test.ts +0 -347
  24. package/src/components/tests/persistent-islands.test.ts +0 -398
  25. package/src/core/components/tests/enhanced-framework-detector.test.ts +0 -577
  26. package/src/core/components/tests/framework-registry.test.ts +0 -465
  27. package/src/core/integrations/README.md +0 -282
  28. package/src/core/layout/tests/enhanced-layout-resolver.test.ts +0 -477
  29. package/src/core/layout/tests/layout-cache-optimization.test.ts +0 -149
  30. package/src/core/layout/tests/layout-composer.test.ts +0 -486
  31. package/src/core/layout/tests/layout-data-loader.test.ts +0 -443
  32. package/src/core/layout/tests/layout-discovery.test.ts +0 -253
  33. package/src/core/layout/tests/layout-matcher.test.ts +0 -480
  34. package/src/core/modules/tests/framework-module-resolver.test.ts +0 -263
  35. package/src/core/modules/tests/module-resolution-integration.test.ts +0 -117
  36. package/src/islands/discovery/tests/island-discovery.test.ts +0 -881
  37. package/src/middleware/__tests__/discovery.test.ts +0 -107
  38. package/src/types/tests/layout-types.test.ts +0 -197
  39. package/src/vite-plugin/tests/image-optimization.test.ts +0 -54
@@ -1,347 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import {
3
- analyzeComponent,
4
- detectFramework,
5
- hasScriptSection,
6
- hasHydrateFunction,
7
- shouldHydrateComponent,
8
- createComponentMetadata,
9
- extractVueScript,
10
- extractSvelteScript,
11
- extractSolidScript,
12
- type ComponentAnalysis,
13
- } from '../../core/components/component-detection.ts';
14
-
15
- // Test data - sample component contents
16
- const sampleComponents = {
17
- vueWithScript: `
18
- <template>
19
- <div>{{ count }}</div>
20
- <button @click="increment">+</button>
21
- </template>
22
-
23
- <script setup>
24
- import { ref } from 'vue'
25
- const count = ref(0)
26
- const increment = () => count.value++
27
-
28
- // Hydrate function
29
- export function hydrate() {
30
- console.log('Hydrating Vue component')
31
- }
32
- </script>
33
- `,
34
-
35
- vueWithoutScript: `
36
- <template>
37
- <div>
38
- <h1>Static Content</h1>
39
- <p>This is a static Vue component</p>
40
- </div>
41
- </template>
42
- `,
43
-
44
- svelteWithScript: `
45
- <script>
46
- import { onMount } from 'svelte';
47
- let count = 0;
48
-
49
- function increment() {
50
- count += 1;
51
- }
52
-
53
- onMount(() => {
54
- console.log('Component mounted');
55
- });
56
-
57
- export function hydrate() {
58
- console.log('Hydrating Svelte component');
59
- }
60
- </script>
61
-
62
- <div>
63
- <p>Count: {count}</p>
64
- <button on:click={increment}>+</button>
65
- </div>
66
- `,
67
-
68
- svelteWithoutScript: `
69
- <div>
70
- <h1>Static Svelte Component</h1>
71
- <p>No JavaScript here</p>
72
- </div>
73
- `,
74
-
75
- solidWithHydrate: `
76
- import { createSignal } from 'solid-js';
77
-
78
- export default function Counter() {
79
- const [count, setCount] = createSignal(0);
80
-
81
- const increment = () => setCount(count() + 1);
82
-
83
- return (
84
- <div>
85
- <p>Count: {count()}</p>
86
- <button onClick={increment}>+</button>
87
- </div>
88
- );
89
- }
90
-
91
- export function hydrate() {
92
- console.log('Hydrating Solid component');
93
- }
94
- `,
95
-
96
- solidWithoutHydrate: `
97
- export default function StaticComponent() {
98
- return (
99
- <div>
100
- <h1>Static Solid Component</h1>
101
- <p>No hydration needed</p>
102
- </div>
103
- );
104
- }
105
- `,
106
- };
107
-
108
- describe('Framework Detection', () => {
109
- it('should detect Vue framework from file extension', () => {
110
- const framework = detectFramework('Component.vue', sampleComponents.vueWithScript);
111
- expect(framework).toEqual('vue');
112
- });
113
-
114
- it('should detect Svelte framework from file extension', () => {
115
- const framework = detectFramework('Component.svelte', sampleComponents.svelteWithScript);
116
- expect(framework).toEqual('svelte');
117
- });
118
-
119
- it('should detect Solid framework from file extension', () => {
120
- const framework = detectFramework('Component.tsx', sampleComponents.solidWithHydrate);
121
- expect(framework).toEqual('solid');
122
- });
123
-
124
- it('should detect framework from content when extension is ambiguous', () => {
125
- const vueFramework = detectFramework('Component.js', 'import { ref } from "vue"');
126
- expect(vueFramework).toEqual('vue');
127
-
128
- const svelteFramework = detectFramework('Component.js', 'import { onMount } from "svelte"');
129
- expect(svelteFramework).toEqual('svelte');
130
-
131
- const solidFramework = detectFramework('Component.js', 'import { createSignal } from "solid-js"');
132
- expect(solidFramework).toEqual('solid');
133
- });
134
-
135
- it('should return unknown for unrecognized patterns', () => {
136
- const framework = detectFramework('Component.js', 'console.log("hello")');
137
- expect(framework).toEqual('unknown');
138
- });
139
- });
140
-
141
- describe('Script Section Detection', () => {
142
- it('should detect Vue script sections', () => {
143
- expect(hasScriptSection(sampleComponents.vueWithScript, 'vue')).toEqual(true);
144
- expect(hasScriptSection(sampleComponents.vueWithoutScript, 'vue')).toEqual(false);
145
- });
146
-
147
- it('should detect Svelte script sections', () => {
148
- expect(hasScriptSection(sampleComponents.svelteWithScript, 'svelte')).toEqual(true);
149
- expect(hasScriptSection(sampleComponents.svelteWithoutScript, 'svelte')).toEqual(false);
150
- });
151
-
152
- it('should detect Solid script content', () => {
153
- expect(hasScriptSection(sampleComponents.solidWithHydrate, 'solid')).toEqual(true);
154
- expect(hasScriptSection('<div>Static HTML</div>', 'solid')).toEqual(false);
155
- });
156
- });
157
-
158
- describe('Hydrate Function Detection', () => {
159
- it('should detect Vue hydrate functions', () => {
160
- expect(hasHydrateFunction(sampleComponents.vueWithScript, 'vue')).toEqual(true);
161
- expect(hasHydrateFunction(sampleComponents.vueWithoutScript, 'vue')).toEqual(false);
162
- });
163
-
164
- it('should detect Svelte hydrate functions', () => {
165
- expect(hasHydrateFunction(sampleComponents.svelteWithScript, 'svelte')).toEqual(true);
166
- expect(hasHydrateFunction(sampleComponents.svelteWithoutScript, 'svelte')).toEqual(false);
167
- });
168
-
169
- it('should detect Solid hydrate functions', () => {
170
- expect(hasHydrateFunction(sampleComponents.solidWithHydrate, 'solid')).toEqual(true);
171
- expect(hasHydrateFunction(sampleComponents.solidWithoutHydrate, 'solid')).toEqual(false);
172
- });
173
-
174
- it('should detect explicit hydration patterns', () => {
175
- expect(hasHydrateFunction('export function hydrate() {}', 'vue')).toEqual(true);
176
- expect(hasHydrateFunction('import { hydrate } from "svelte"; hydrate()', 'svelte')).toEqual(true);
177
- expect(hasHydrateFunction('import { hydrate } from "solid-js/web"; hydrate()', 'solid')).toEqual(true);
178
- expect(hasHydrateFunction('createApp().mount()', 'vue')).toEqual(true);
179
- });
180
-
181
- it('should not detect non-hydration patterns', () => {
182
- expect(hasHydrateFunction('function mount() {}', 'vue')).toEqual(false);
183
- expect(hasHydrateFunction('onMount(() => {})', 'svelte')).toEqual(false);
184
- expect(hasHydrateFunction('createSignal(0)', 'solid')).toEqual(false);
185
- });
186
- });
187
-
188
- describe('Script Content Extraction', () => {
189
- it('should extract Vue script content', () => {
190
- const script = extractVueScript(sampleComponents.vueWithScript);
191
- expect(script).toBeDefined();
192
- expect(script.includes('const count = ref(0)')).toEqual(true);
193
- expect(script.includes('export function hydrate')).toEqual(true);
194
- });
195
-
196
- it('should extract Svelte script content', () => {
197
- const script = extractSvelteScript(sampleComponents.svelteWithScript);
198
- expect(script).toBeDefined();
199
- expect(script.includes('let count = 0')).toEqual(true);
200
- expect(script.includes('export function hydrate')).toEqual(true);
201
- });
202
-
203
- it('should extract Solid script content', () => {
204
- const script = extractSolidScript(sampleComponents.solidWithHydrate);
205
- expect(script).toBeDefined();
206
- expect(script.includes('createSignal')).toEqual(true);
207
- expect(script.includes('export function hydrate')).toEqual(true);
208
- });
209
-
210
- it('should return empty string for components without scripts', () => {
211
- expect(extractVueScript(sampleComponents.vueWithoutScript)).toEqual('');
212
- expect(extractSvelteScript(sampleComponents.svelteWithoutScript)).toEqual('');
213
- });
214
- });
215
-
216
- describe('Component Analysis', () => {
217
- it('should analyze Vue component with script and hydrate function', () => {
218
- const analysis = analyzeComponent('Component.vue', sampleComponents.vueWithScript);
219
- expect(analysis.framework).toEqual('vue');
220
- expect(analysis.hasScript).toEqual(true);
221
- expect(analysis.hasHydrateFunction).toEqual(true);
222
- expect(analysis.recommendedStrategy).toEqual('hydrate');
223
- });
224
-
225
- it('should analyze Vue component without script', () => {
226
- const analysis = analyzeComponent('Component.vue', sampleComponents.vueWithoutScript);
227
- expect(analysis.framework).toEqual('vue');
228
- expect(analysis.hasScript).toEqual(false);
229
- expect(analysis.hasHydrateFunction).toEqual(false);
230
- expect(analysis.recommendedStrategy).toEqual('ssr-only');
231
- });
232
-
233
- it('should analyze Svelte component with script and hydrate function', () => {
234
- const analysis = analyzeComponent('Component.svelte', sampleComponents.svelteWithScript);
235
- expect(analysis.framework).toEqual('svelte');
236
- expect(analysis.hasScript).toEqual(true);
237
- expect(analysis.hasHydrateFunction).toEqual(true);
238
- expect(analysis.recommendedStrategy).toEqual('hydrate');
239
- });
240
-
241
- it('should analyze Solid component with hydrate function', () => {
242
- const analysis = analyzeComponent('Component.tsx', sampleComponents.solidWithHydrate);
243
- expect(analysis.framework).toEqual('solid');
244
- expect(analysis.hasScript).toEqual(true);
245
- expect(analysis.hasHydrateFunction).toEqual(true);
246
- expect(analysis.recommendedStrategy).toEqual('hydrate');
247
- });
248
- });
249
-
250
- describe('Hydration Decision Logic', () => {
251
- it('should recommend SSR-only for components without scripts', () => {
252
- const analysis: ComponentAnalysis = {
253
- hasScript: false,
254
- hasHydrateFunction: false,
255
- framework: 'vue',
256
- recommendedStrategy: 'ssr-only',
257
- };
258
-
259
- const result = shouldHydrateComponent(analysis);
260
- expect(result.shouldHydrate).toEqual(false);
261
- expect(result.reason).toEqual('No script section detected, using SSR-only rendering');
262
- });
263
-
264
- it('should recommend hydration for components with hydrate functions', () => {
265
- const analysis: ComponentAnalysis = {
266
- hasScript: true,
267
- hasHydrateFunction: true,
268
- framework: 'vue',
269
- recommendedStrategy: 'hydrate',
270
- };
271
-
272
- const result = shouldHydrateComponent(analysis);
273
- expect(result.shouldHydrate).toEqual(true);
274
- expect(result.reason).toEqual('Vue component with script section - uses Vue integration system');
275
- });
276
-
277
- it('should respect forceSSROnly option', () => {
278
- const analysis: ComponentAnalysis = {
279
- hasScript: true,
280
- hasHydrateFunction: true,
281
- framework: 'vue',
282
- recommendedStrategy: 'hydrate',
283
- };
284
-
285
- const result = shouldHydrateComponent(analysis, { forceSSROnly: true });
286
- expect(result.shouldHydrate).toEqual(false);
287
- expect(result.reason).toEqual('Explicitly configured for SSR-only rendering');
288
- });
289
-
290
- it('should handle components with scripts but no hydrate functions', () => {
291
- const analysis: ComponentAnalysis = {
292
- hasScript: true,
293
- hasHydrateFunction: false,
294
- framework: 'vue',
295
- recommendedStrategy: 'ssr-only',
296
- };
297
-
298
- const result = shouldHydrateComponent(analysis);
299
- // Known frameworks with script sections always hydrate per shouldHydrateComponent logic
300
- expect(result.shouldHydrate).toEqual(true);
301
- expect(result.reason).toEqual('Vue component with script section - uses Vue integration system');
302
- });
303
- });
304
-
305
- describe('Component Metadata Creation', () => {
306
- it('should create metadata with high confidence for clear cases', () => {
307
- const analysis: ComponentAnalysis = {
308
- hasScript: true,
309
- hasHydrateFunction: true,
310
- framework: 'vue',
311
- recommendedStrategy: 'hydrate',
312
- };
313
-
314
- const metadata = createComponentMetadata('Component.vue', sampleComponents.vueWithScript, analysis);
315
- expect(metadata.framework).toEqual('vue');
316
- expect(metadata.hasScript).toEqual(true);
317
- expect(metadata.hasHydrateFunction).toEqual(true);
318
- expect(metadata.renderStrategy).toEqual('hydrate');
319
- expect(metadata.detectionConfidence).toEqual('high');
320
- });
321
-
322
- it('should create metadata with high confidence for SSR-only components', () => {
323
- const analysis: ComponentAnalysis = {
324
- hasScript: false,
325
- hasHydrateFunction: false,
326
- framework: 'vue',
327
- recommendedStrategy: 'ssr-only',
328
- };
329
-
330
- const metadata = createComponentMetadata('Component.vue', sampleComponents.vueWithoutScript, analysis);
331
- expect(metadata.renderStrategy).toEqual('ssr-only');
332
- expect(metadata.detectionConfidence).toEqual('high');
333
- });
334
-
335
- it('should create metadata with low confidence for unknown frameworks', () => {
336
- const analysis: ComponentAnalysis = {
337
- hasScript: true,
338
- hasHydrateFunction: false,
339
- framework: 'unknown',
340
- recommendedStrategy: 'hydrate',
341
- };
342
-
343
- const metadata = createComponentMetadata('Component.js', 'some content', analysis);
344
- expect(metadata.framework).toEqual('vue'); // Default fallback
345
- expect(metadata.detectionConfidence).toEqual('low');
346
- });
347
- });