@useavalon/avalon 0.1.13 → 0.1.14
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.
- package/dist/mod.js +1 -0
- package/dist/src/build/integration-bundler-plugin.js +1 -0
- package/dist/src/build/integration-config.js +1 -0
- package/dist/src/build/integration-detection-plugin.js +1 -0
- package/dist/src/build/integration-resolver-plugin.js +1 -0
- package/dist/src/build/island-manifest.js +1 -0
- package/dist/src/build/island-types-generator.js +5 -0
- package/dist/src/build/mdx-island-transform.js +2 -0
- package/dist/src/build/mdx-plugin.js +1 -0
- package/dist/src/build/page-island-transform.js +3 -0
- package/dist/src/build/prop-extractors/index.js +1 -0
- package/dist/src/build/prop-extractors/lit.js +1 -0
- package/dist/src/build/prop-extractors/qwik.js +1 -0
- package/dist/src/build/prop-extractors/solid.js +1 -0
- package/dist/src/build/prop-extractors/svelte.js +1 -0
- package/dist/src/build/prop-extractors/vue.js +1 -0
- package/dist/src/build/sidecar-file-manager.js +1 -0
- package/dist/src/build/sidecar-renderer.js +6 -0
- package/dist/src/client/adapters/index.js +1 -0
- package/dist/src/client/components.js +1 -0
- package/dist/src/client/css-hmr-handler.js +1 -0
- package/dist/src/client/framework-adapter.js +13 -0
- package/dist/src/client/hmr-coordinator.js +1 -0
- package/dist/src/client/hmr-error-overlay.js +214 -0
- package/dist/src/client/main.js +39 -0
- package/dist/src/components/Image.js +1 -0
- package/dist/src/components/IslandErrorBoundary.js +1 -0
- package/dist/src/components/LayoutDataErrorBoundary.js +1 -0
- package/dist/src/components/LayoutErrorBoundary.js +1 -0
- package/dist/src/components/PersistentIsland.js +1 -0
- package/dist/src/components/StreamingErrorBoundary.js +1 -0
- package/dist/src/components/StreamingLayout.js +29 -0
- package/dist/src/core/components/component-analyzer.js +1 -0
- package/dist/src/core/components/component-detection.js +5 -0
- package/dist/src/core/components/enhanced-framework-detector.js +1 -0
- package/dist/src/core/components/framework-registry.js +1 -0
- package/dist/src/core/content/mdx-processor.js +1 -0
- package/dist/src/core/integrations/index.js +1 -0
- package/dist/src/core/integrations/loader.js +1 -0
- package/dist/src/core/integrations/registry.js +1 -0
- package/dist/src/core/islands/island-persistence.js +1 -0
- package/dist/src/core/islands/island-state-serializer.js +1 -0
- package/dist/src/core/islands/persistent-island-context.js +1 -0
- package/dist/src/core/islands/use-persistent-state.js +1 -0
- package/dist/src/core/layout/enhanced-layout-resolver.js +1 -0
- package/dist/src/core/layout/layout-cache-manager.js +1 -0
- package/dist/src/core/layout/layout-composer.js +1 -0
- package/dist/src/core/layout/layout-data-loader.js +1 -0
- package/dist/src/core/layout/layout-discovery.js +1 -0
- package/dist/src/core/layout/layout-matcher.js +1 -0
- package/dist/src/core/layout/layout-types.js +1 -0
- package/dist/src/core/modules/framework-module-resolver.js +1 -0
- package/dist/src/islands/component-analysis.js +1 -0
- package/dist/src/islands/css-utils.js +17 -0
- package/dist/src/islands/discovery/index.js +1 -0
- package/dist/src/islands/discovery/registry.js +1 -0
- package/dist/src/islands/discovery/resolver.js +2 -0
- package/dist/src/islands/discovery/scanner.js +1 -0
- package/dist/src/islands/discovery/types.js +1 -0
- package/dist/src/islands/discovery/validator.js +18 -0
- package/dist/src/islands/discovery/watcher.js +1 -0
- package/dist/src/islands/framework-detection.js +1 -0
- package/dist/src/islands/integration-loader.js +1 -0
- package/dist/src/islands/island.js +1 -0
- package/dist/src/islands/render-cache.js +1 -0
- package/dist/src/islands/types.js +1 -0
- package/dist/src/islands/universal-css-collector.js +5 -0
- package/dist/src/islands/universal-head-collector.js +2 -0
- package/dist/src/layout-system.js +1 -0
- package/dist/src/middleware/discovery.js +1 -0
- package/dist/src/middleware/executor.js +1 -0
- package/dist/src/middleware/index.js +1 -0
- package/dist/src/middleware/types.js +1 -0
- package/dist/src/nitro/build-config.js +1 -0
- package/dist/src/nitro/config.js +1 -0
- package/dist/src/nitro/error-handler.js +198 -0
- package/dist/src/nitro/index.js +1 -0
- package/dist/src/nitro/island-manifest.js +2 -0
- package/dist/src/nitro/middleware-adapter.js +1 -0
- package/dist/src/nitro/renderer.js +183 -0
- package/dist/src/nitro/route-discovery.js +1 -0
- package/dist/src/nitro/types.js +1 -0
- package/dist/src/render/collect-css.js +3 -0
- package/dist/src/render/error-pages.js +48 -0
- package/dist/src/render/isolated-ssr-renderer.js +1 -0
- package/dist/src/render/ssr.js +90 -0
- package/dist/src/schemas/api.js +1 -0
- package/dist/src/schemas/core.js +1 -0
- package/dist/src/schemas/index.js +1 -0
- package/dist/src/schemas/layout.js +1 -0
- package/dist/src/schemas/routing/index.js +1 -0
- package/dist/src/schemas/routing.js +1 -0
- package/dist/src/types/as-island.js +1 -0
- package/dist/src/types/layout.js +1 -0
- package/dist/src/types/routing.js +1 -0
- package/dist/src/types/types.js +1 -0
- package/dist/src/utils/dev-logger.js +12 -0
- package/dist/src/utils/fs.js +1 -0
- package/dist/src/vite-plugin/auto-discover.js +1 -0
- package/dist/src/vite-plugin/config.js +1 -0
- package/dist/src/vite-plugin/errors.js +1 -0
- package/dist/src/vite-plugin/image-optimization.js +45 -0
- package/dist/src/vite-plugin/integration-activator.js +1 -0
- package/dist/src/vite-plugin/island-sidecar-plugin.js +1 -0
- package/dist/src/vite-plugin/module-discovery.js +1 -0
- package/dist/src/vite-plugin/nitro-integration.js +42 -0
- package/dist/src/vite-plugin/plugin.js +1 -0
- package/dist/src/vite-plugin/types.js +1 -0
- package/dist/src/vite-plugin/validation.js +2 -0
- package/package.json +14 -20
- package/mod.ts +0 -302
- package/src/build/integration-bundler-plugin.ts +0 -116
- package/src/build/integration-config.ts +0 -168
- package/src/build/integration-detection-plugin.ts +0 -117
- package/src/build/integration-resolver-plugin.ts +0 -90
- package/src/build/island-manifest.ts +0 -269
- package/src/build/island-types-generator.ts +0 -476
- package/src/build/mdx-island-transform.ts +0 -464
- package/src/build/mdx-plugin.ts +0 -98
- package/src/build/page-island-transform.ts +0 -598
- package/src/build/prop-extractors/index.ts +0 -21
- package/src/build/prop-extractors/lit.ts +0 -140
- package/src/build/prop-extractors/qwik.ts +0 -16
- package/src/build/prop-extractors/solid.ts +0 -125
- package/src/build/prop-extractors/svelte.ts +0 -194
- package/src/build/prop-extractors/vue.ts +0 -111
- package/src/build/sidecar-file-manager.ts +0 -104
- package/src/build/sidecar-renderer.ts +0 -30
- package/src/client/adapters/index.ts +0 -21
- package/src/client/components.ts +0 -35
- package/src/client/css-hmr-handler.ts +0 -344
- package/src/client/framework-adapter.ts +0 -462
- package/src/client/hmr-coordinator.ts +0 -396
- package/src/client/hmr-error-overlay.js +0 -533
- package/src/client/main.js +0 -824
- package/src/components/Image.tsx +0 -123
- package/src/components/IslandErrorBoundary.tsx +0 -145
- package/src/components/LayoutDataErrorBoundary.tsx +0 -141
- package/src/components/LayoutErrorBoundary.tsx +0 -127
- package/src/components/PersistentIsland.tsx +0 -52
- package/src/components/StreamingErrorBoundary.tsx +0 -233
- package/src/components/StreamingLayout.tsx +0 -538
- package/src/core/components/component-analyzer.ts +0 -192
- package/src/core/components/component-detection.ts +0 -508
- package/src/core/components/enhanced-framework-detector.ts +0 -500
- package/src/core/components/framework-registry.ts +0 -563
- package/src/core/content/mdx-processor.ts +0 -46
- package/src/core/integrations/index.ts +0 -19
- package/src/core/integrations/loader.ts +0 -125
- package/src/core/integrations/registry.ts +0 -175
- package/src/core/islands/island-persistence.ts +0 -325
- package/src/core/islands/island-state-serializer.ts +0 -258
- package/src/core/islands/persistent-island-context.tsx +0 -80
- package/src/core/islands/use-persistent-state.ts +0 -68
- package/src/core/layout/enhanced-layout-resolver.ts +0 -322
- package/src/core/layout/layout-cache-manager.ts +0 -485
- package/src/core/layout/layout-composer.ts +0 -357
- package/src/core/layout/layout-data-loader.ts +0 -516
- package/src/core/layout/layout-discovery.ts +0 -243
- package/src/core/layout/layout-matcher.ts +0 -299
- package/src/core/layout/layout-types.ts +0 -110
- package/src/core/modules/framework-module-resolver.ts +0 -273
- package/src/islands/component-analysis.ts +0 -213
- package/src/islands/css-utils.ts +0 -565
- package/src/islands/discovery/index.ts +0 -80
- package/src/islands/discovery/registry.ts +0 -340
- package/src/islands/discovery/resolver.ts +0 -477
- package/src/islands/discovery/scanner.ts +0 -386
- package/src/islands/discovery/types.ts +0 -117
- package/src/islands/discovery/validator.ts +0 -544
- package/src/islands/discovery/watcher.ts +0 -368
- package/src/islands/framework-detection.ts +0 -428
- package/src/islands/integration-loader.ts +0 -490
- package/src/islands/island.tsx +0 -565
- package/src/islands/render-cache.ts +0 -550
- package/src/islands/types.ts +0 -80
- package/src/islands/universal-css-collector.ts +0 -157
- package/src/islands/universal-head-collector.ts +0 -137
- package/src/layout-system.ts +0 -218
- package/src/middleware/discovery.ts +0 -268
- package/src/middleware/executor.ts +0 -315
- package/src/middleware/index.ts +0 -76
- package/src/middleware/types.ts +0 -99
- package/src/nitro/build-config.ts +0 -576
- package/src/nitro/config.ts +0 -483
- package/src/nitro/error-handler.ts +0 -636
- package/src/nitro/index.ts +0 -173
- package/src/nitro/island-manifest.ts +0 -584
- package/src/nitro/middleware-adapter.ts +0 -260
- package/src/nitro/renderer.ts +0 -1471
- package/src/nitro/route-discovery.ts +0 -439
- package/src/nitro/types.ts +0 -321
- package/src/render/collect-css.ts +0 -198
- package/src/render/error-pages.ts +0 -79
- package/src/render/isolated-ssr-renderer.ts +0 -654
- package/src/render/ssr.ts +0 -1030
- package/src/schemas/api.ts +0 -30
- package/src/schemas/core.ts +0 -64
- package/src/schemas/index.ts +0 -212
- package/src/schemas/layout.ts +0 -279
- package/src/schemas/routing/index.ts +0 -38
- package/src/schemas/routing.ts +0 -376
- package/src/types/as-island.ts +0 -20
- package/src/types/layout.ts +0 -285
- package/src/types/routing.ts +0 -555
- package/src/types/types.ts +0 -5
- package/src/utils/dev-logger.ts +0 -299
- package/src/utils/fs.ts +0 -151
- package/src/vite-plugin/auto-discover.ts +0 -551
- package/src/vite-plugin/config.ts +0 -266
- package/src/vite-plugin/errors.ts +0 -127
- package/src/vite-plugin/image-optimization.ts +0 -156
- package/src/vite-plugin/integration-activator.ts +0 -126
- package/src/vite-plugin/island-sidecar-plugin.ts +0 -176
- package/src/vite-plugin/module-discovery.ts +0 -189
- package/src/vite-plugin/nitro-integration.ts +0 -1354
- package/src/vite-plugin/plugin.ts +0 -403
- package/src/vite-plugin/types.ts +0 -327
- package/src/vite-plugin/validation.ts +0 -228
- /package/{src → dist/src}/client/types/framework-runtime.d.ts +0 -0
- /package/{src → dist/src}/client/types/vite-hmr.d.ts +0 -0
- /package/{src → dist/src}/client/types/vite-virtual-modules.d.ts +0 -0
- /package/{src → dist/src}/layout-system.d.ts +0 -0
- /package/{src → dist/src}/types/image.d.ts +0 -0
- /package/{src → dist/src}/types/index.d.ts +0 -0
- /package/{src → dist/src}/types/island-jsx.d.ts +0 -0
- /package/{src → dist/src}/types/island-prop.d.ts +0 -0
- /package/{src → dist/src}/types/mdx.d.ts +0 -0
- /package/{src → dist/src}/types/urlpattern.d.ts +0 -0
- /package/{src → dist/src}/types/vite-env.d.ts +0 -0
|
@@ -1,550 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Island Render Cache Module
|
|
3
|
-
*
|
|
4
|
-
* Provides caching for expensive operations in the island rendering pipeline:
|
|
5
|
-
* - Component analysis results
|
|
6
|
-
* - Resolved paths
|
|
7
|
-
* - Framework detection results
|
|
8
|
-
*
|
|
9
|
-
* This module helps optimize island rendering by avoiding repeated file I/O
|
|
10
|
-
* and analysis operations for the same components.
|
|
11
|
-
*
|
|
12
|
-
* @module render-cache
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import type { AnalysisReport } from "../core/components/component-analyzer.ts";
|
|
16
|
-
import type { Framework } from "./types.ts";
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Cache entry for component analysis results
|
|
20
|
-
*/
|
|
21
|
-
export interface AnalysisCacheEntry {
|
|
22
|
-
/** The analysis result */
|
|
23
|
-
result: AnalysisReport;
|
|
24
|
-
/** Timestamp when the entry was cached */
|
|
25
|
-
timestamp: number;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Cache entry for resolved paths
|
|
30
|
-
*/
|
|
31
|
-
export interface PathCacheEntry {
|
|
32
|
-
/** The resolved path */
|
|
33
|
-
resolved: string;
|
|
34
|
-
/** Timestamp when the entry was cached */
|
|
35
|
-
timestamp: number;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Cache entry for framework detection results
|
|
40
|
-
*/
|
|
41
|
-
export interface FrameworkCacheEntry {
|
|
42
|
-
/** The detected framework */
|
|
43
|
-
framework: Framework;
|
|
44
|
-
/** Timestamp when the entry was cached */
|
|
45
|
-
timestamp: number;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Configuration options for the island render cache
|
|
50
|
-
*/
|
|
51
|
-
export interface CacheConfig {
|
|
52
|
-
/** TTL for analysis cache entries in milliseconds (default: 60000ms = 1 minute) */
|
|
53
|
-
analysisTTL: number;
|
|
54
|
-
/** TTL for path cache entries in milliseconds (default: 60000ms = 1 minute) */
|
|
55
|
-
pathTTL: number;
|
|
56
|
-
/** TTL for framework cache entries in milliseconds (default: 60000ms = 1 minute) */
|
|
57
|
-
frameworkTTL: number;
|
|
58
|
-
/** Maximum number of entries per cache (default: 1000) */
|
|
59
|
-
maxEntries: number;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Cache statistics for monitoring and debugging
|
|
64
|
-
*/
|
|
65
|
-
export interface CacheStats {
|
|
66
|
-
/** Number of analysis cache entries */
|
|
67
|
-
analysisSize: number;
|
|
68
|
-
/** Number of path cache entries */
|
|
69
|
-
pathsSize: number;
|
|
70
|
-
/** Number of framework cache entries */
|
|
71
|
-
frameworksSize: number;
|
|
72
|
-
/** Number of cache hits for analysis */
|
|
73
|
-
analysisHits: number;
|
|
74
|
-
/** Number of cache misses for analysis */
|
|
75
|
-
analysisMisses: number;
|
|
76
|
-
/** Number of cache hits for paths */
|
|
77
|
-
pathHits: number;
|
|
78
|
-
/** Number of cache misses for paths */
|
|
79
|
-
pathMisses: number;
|
|
80
|
-
/** Number of cache hits for frameworks */
|
|
81
|
-
frameworkHits: number;
|
|
82
|
-
/** Number of cache misses for frameworks */
|
|
83
|
-
frameworkMisses: number;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Island Render Cache interface
|
|
88
|
-
* Centralized cache for all expensive operations in island rendering
|
|
89
|
-
*/
|
|
90
|
-
export interface IslandRenderCache {
|
|
91
|
-
/** Analysis results by component path */
|
|
92
|
-
analysis: Map<string, AnalysisCacheEntry>;
|
|
93
|
-
/** Resolved paths by source path */
|
|
94
|
-
paths: Map<string, PathCacheEntry>;
|
|
95
|
-
/** Framework detection results by source path */
|
|
96
|
-
frameworks: Map<string, FrameworkCacheEntry>;
|
|
97
|
-
/** Cache configuration */
|
|
98
|
-
config: CacheConfig;
|
|
99
|
-
/** Cache statistics */
|
|
100
|
-
stats: CacheStats;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Default cache configuration
|
|
105
|
-
*/
|
|
106
|
-
const DEFAULT_CONFIG: CacheConfig = {
|
|
107
|
-
analysisTTL: 60000, // 1 minute
|
|
108
|
-
pathTTL: 60000, // 1 minute
|
|
109
|
-
frameworkTTL: 60000, // 1 minute
|
|
110
|
-
maxEntries: 1000,
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Initial cache statistics
|
|
115
|
-
*/
|
|
116
|
-
const INITIAL_STATS: CacheStats = {
|
|
117
|
-
analysisSize: 0,
|
|
118
|
-
pathsSize: 0,
|
|
119
|
-
frameworksSize: 0,
|
|
120
|
-
analysisHits: 0,
|
|
121
|
-
analysisMisses: 0,
|
|
122
|
-
pathHits: 0,
|
|
123
|
-
pathMisses: 0,
|
|
124
|
-
frameworkHits: 0,
|
|
125
|
-
frameworkMisses: 0,
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Global cache instance
|
|
130
|
-
*/
|
|
131
|
-
const islandCache: IslandRenderCache = {
|
|
132
|
-
analysis: new Map(),
|
|
133
|
-
paths: new Map(),
|
|
134
|
-
frameworks: new Map(),
|
|
135
|
-
config: { ...DEFAULT_CONFIG },
|
|
136
|
-
stats: { ...INITIAL_STATS },
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Check if we're in development mode
|
|
141
|
-
*/
|
|
142
|
-
function isDev(): boolean {
|
|
143
|
-
try {
|
|
144
|
-
return process.env.NODE_ENV !== "production";
|
|
145
|
-
} catch {
|
|
146
|
-
return true; // Default to dev mode if we can't check
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function isVerbose(): boolean {
|
|
151
|
-
try {
|
|
152
|
-
return process.env.AVALON_VERBOSE === "1";
|
|
153
|
-
} catch {
|
|
154
|
-
return false;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Check if a cache entry is expired
|
|
160
|
-
*/
|
|
161
|
-
function isExpired(timestamp: number, ttl: number): boolean {
|
|
162
|
-
return Date.now() - timestamp > ttl;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Enforce max entries limit by removing oldest entries
|
|
167
|
-
*/
|
|
168
|
-
function enforceMaxEntries<T>(cache: Map<string, T & { timestamp: number }>, maxEntries: number): void {
|
|
169
|
-
if (cache.size <= maxEntries) return;
|
|
170
|
-
|
|
171
|
-
// Sort entries by timestamp and remove oldest
|
|
172
|
-
const entries = Array.from(cache.entries())
|
|
173
|
-
.sort((a, b) => a[1].timestamp - b[1].timestamp);
|
|
174
|
-
|
|
175
|
-
const toRemove = entries.slice(0, cache.size - maxEntries);
|
|
176
|
-
for (const [key] of toRemove) {
|
|
177
|
-
cache.delete(key);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// ============================================================================
|
|
182
|
-
// Analysis Cache Functions
|
|
183
|
-
// ============================================================================
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Get cached analysis result for a component path
|
|
187
|
-
*
|
|
188
|
-
* @param src - The component source path
|
|
189
|
-
* @returns The cached analysis result or null if not found/expired
|
|
190
|
-
*/
|
|
191
|
-
export function getCachedAnalysis(src: string): AnalysisReport | null {
|
|
192
|
-
const cached = islandCache.analysis.get(src);
|
|
193
|
-
|
|
194
|
-
if (cached) {
|
|
195
|
-
if (!isExpired(cached.timestamp, islandCache.config.analysisTTL)) {
|
|
196
|
-
islandCache.stats.analysisHits++;
|
|
197
|
-
return cached.result;
|
|
198
|
-
}
|
|
199
|
-
// Expired, remove from cache
|
|
200
|
-
islandCache.analysis.delete(src);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
islandCache.stats.analysisMisses++;
|
|
204
|
-
return null;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Store analysis result in cache
|
|
209
|
-
*
|
|
210
|
-
* @param src - The component source path
|
|
211
|
-
* @param result - The analysis result to cache
|
|
212
|
-
*/
|
|
213
|
-
export function setCachedAnalysis(src: string, result: AnalysisReport): void {
|
|
214
|
-
islandCache.analysis.set(src, {
|
|
215
|
-
result,
|
|
216
|
-
timestamp: Date.now(),
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
islandCache.stats.analysisSize = islandCache.analysis.size;
|
|
220
|
-
enforceMaxEntries(islandCache.analysis, islandCache.config.maxEntries);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// ============================================================================
|
|
224
|
-
// Path Cache Functions
|
|
225
|
-
// ============================================================================
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Get cached resolved path for a source path
|
|
229
|
-
*
|
|
230
|
-
* @param src - The source path
|
|
231
|
-
* @returns The cached resolved path or null if not found/expired
|
|
232
|
-
*/
|
|
233
|
-
export function getCachedPath(src: string): string | null {
|
|
234
|
-
const cached = islandCache.paths.get(src);
|
|
235
|
-
|
|
236
|
-
if (cached) {
|
|
237
|
-
if (!isExpired(cached.timestamp, islandCache.config.pathTTL)) {
|
|
238
|
-
islandCache.stats.pathHits++;
|
|
239
|
-
return cached.resolved;
|
|
240
|
-
}
|
|
241
|
-
// Expired, remove from cache
|
|
242
|
-
islandCache.paths.delete(src);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
islandCache.stats.pathMisses++;
|
|
246
|
-
return null;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Store resolved path in cache
|
|
251
|
-
*
|
|
252
|
-
* @param src - The source path
|
|
253
|
-
* @param resolved - The resolved path to cache
|
|
254
|
-
*/
|
|
255
|
-
export function setCachedPath(src: string, resolved: string): void {
|
|
256
|
-
islandCache.paths.set(src, {
|
|
257
|
-
resolved,
|
|
258
|
-
timestamp: Date.now(),
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
islandCache.stats.pathsSize = islandCache.paths.size;
|
|
262
|
-
enforceMaxEntries(islandCache.paths, islandCache.config.maxEntries);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// ============================================================================
|
|
266
|
-
// Framework Cache Functions
|
|
267
|
-
// ============================================================================
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Get cached framework detection result for a source path
|
|
271
|
-
*
|
|
272
|
-
* @param src - The source path
|
|
273
|
-
* @returns The cached framework or null if not found/expired
|
|
274
|
-
*/
|
|
275
|
-
export function getCachedFramework(src: string): Framework | null {
|
|
276
|
-
const cached = islandCache.frameworks.get(src);
|
|
277
|
-
|
|
278
|
-
if (cached) {
|
|
279
|
-
if (!isExpired(cached.timestamp, islandCache.config.frameworkTTL)) {
|
|
280
|
-
islandCache.stats.frameworkHits++;
|
|
281
|
-
return cached.framework;
|
|
282
|
-
}
|
|
283
|
-
// Expired, remove from cache
|
|
284
|
-
islandCache.frameworks.delete(src);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
islandCache.stats.frameworkMisses++;
|
|
288
|
-
return null;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* Store framework detection result in cache
|
|
293
|
-
*
|
|
294
|
-
* @param src - The source path
|
|
295
|
-
* @param framework - The detected framework to cache
|
|
296
|
-
*/
|
|
297
|
-
export function setCachedFramework(src: string, framework: Framework): void {
|
|
298
|
-
islandCache.frameworks.set(src, {
|
|
299
|
-
framework,
|
|
300
|
-
timestamp: Date.now(),
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
islandCache.stats.frameworksSize = islandCache.frameworks.size;
|
|
304
|
-
enforceMaxEntries(islandCache.frameworks, islandCache.config.maxEntries);
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
// ============================================================================
|
|
308
|
-
// Cache Management Functions
|
|
309
|
-
// ============================================================================
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
* Clear all caches
|
|
313
|
-
* Useful for testing or when file structure changes
|
|
314
|
-
*/
|
|
315
|
-
export function clearCache(): void {
|
|
316
|
-
islandCache.analysis.clear();
|
|
317
|
-
islandCache.paths.clear();
|
|
318
|
-
islandCache.frameworks.clear();
|
|
319
|
-
|
|
320
|
-
// Reset stats
|
|
321
|
-
islandCache.stats = { ...INITIAL_STATS };
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* Clear cache for a specific component path
|
|
326
|
-
* Useful for HMR when a specific file changes
|
|
327
|
-
*
|
|
328
|
-
* @param src - The component source path to invalidate
|
|
329
|
-
*/
|
|
330
|
-
export function invalidateCacheForPath(src: string): void {
|
|
331
|
-
islandCache.analysis.delete(src);
|
|
332
|
-
islandCache.paths.delete(src);
|
|
333
|
-
islandCache.frameworks.delete(src);
|
|
334
|
-
|
|
335
|
-
// Update sizes
|
|
336
|
-
islandCache.stats.analysisSize = islandCache.analysis.size;
|
|
337
|
-
islandCache.stats.pathsSize = islandCache.paths.size;
|
|
338
|
-
islandCache.stats.frameworksSize = islandCache.frameworks.size;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* Configure cache settings
|
|
343
|
-
*
|
|
344
|
-
* @param config - Partial configuration to merge with defaults
|
|
345
|
-
*/
|
|
346
|
-
export function configureCache(config: Partial<CacheConfig>): void {
|
|
347
|
-
islandCache.config = {
|
|
348
|
-
...islandCache.config,
|
|
349
|
-
...config,
|
|
350
|
-
};
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
/**
|
|
354
|
-
* Get current cache configuration
|
|
355
|
-
*
|
|
356
|
-
* @returns The current cache configuration
|
|
357
|
-
*/
|
|
358
|
-
export function getCacheConfig(): CacheConfig {
|
|
359
|
-
return { ...islandCache.config };
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
/**
|
|
363
|
-
* Get cache statistics for monitoring and debugging
|
|
364
|
-
* Only logs in development mode
|
|
365
|
-
*
|
|
366
|
-
* @returns Current cache statistics
|
|
367
|
-
*/
|
|
368
|
-
export function getCacheStats(): CacheStats {
|
|
369
|
-
return {
|
|
370
|
-
analysisSize: islandCache.analysis.size,
|
|
371
|
-
pathsSize: islandCache.paths.size,
|
|
372
|
-
frameworksSize: islandCache.frameworks.size,
|
|
373
|
-
analysisHits: islandCache.stats.analysisHits,
|
|
374
|
-
analysisMisses: islandCache.stats.analysisMisses,
|
|
375
|
-
pathHits: islandCache.stats.pathHits,
|
|
376
|
-
pathMisses: islandCache.stats.pathMisses,
|
|
377
|
-
frameworkHits: islandCache.stats.frameworkHits,
|
|
378
|
-
frameworkMisses: islandCache.stats.frameworkMisses,
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* Log cache statistics to console (dev mode only)
|
|
384
|
-
* Useful for debugging and performance monitoring
|
|
385
|
-
*/
|
|
386
|
-
export function logCacheStats(): void {
|
|
387
|
-
if (!isDev() || !isVerbose()) return;
|
|
388
|
-
|
|
389
|
-
const stats = getCacheStats();
|
|
390
|
-
const totalHits = stats.analysisHits + stats.pathHits + stats.frameworkHits;
|
|
391
|
-
const totalMisses = stats.analysisMisses + stats.pathMisses + stats.frameworkMisses;
|
|
392
|
-
const hitRate = totalHits + totalMisses > 0
|
|
393
|
-
? ((totalHits / (totalHits + totalMisses)) * 100).toFixed(1)
|
|
394
|
-
: "0.0";
|
|
395
|
-
|
|
396
|
-
console.log("📊 Island Render Cache Stats:");
|
|
397
|
-
console.log(` Analysis: ${stats.analysisSize} entries (${stats.analysisHits} hits / ${stats.analysisMisses} misses)`);
|
|
398
|
-
console.log(` Paths: ${stats.pathsSize} entries (${stats.pathHits} hits / ${stats.pathMisses} misses)`);
|
|
399
|
-
console.log(` Frameworks: ${stats.frameworksSize} entries (${stats.frameworkHits} hits / ${stats.frameworkMisses} misses)`);
|
|
400
|
-
console.log(` Overall hit rate: ${hitRate}%`);
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
/**
|
|
404
|
-
* Get the raw cache instance (for testing purposes only)
|
|
405
|
-
* @internal
|
|
406
|
-
*/
|
|
407
|
-
export function _getCache(): IslandRenderCache {
|
|
408
|
-
return islandCache;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
// ============================================================================
|
|
412
|
-
// File Watcher Integration Functions
|
|
413
|
-
// ============================================================================
|
|
414
|
-
|
|
415
|
-
/**
|
|
416
|
-
* Normalize a file path for cache key matching
|
|
417
|
-
* Handles various path formats from Vite file watcher
|
|
418
|
-
*
|
|
419
|
-
* @param filePath - The file path to normalize
|
|
420
|
-
* @returns Normalized path for cache key matching
|
|
421
|
-
*/
|
|
422
|
-
function normalizePathForCache(filePath: string): string {
|
|
423
|
-
return filePath
|
|
424
|
-
.replace(/\\/g, '/') // Normalize Windows paths
|
|
425
|
-
.replace(/^\//, '') // Remove leading slash
|
|
426
|
-
.replace(/\?.*$/, '') // Remove query strings
|
|
427
|
-
.replace(/#.*$/, ''); // Remove hash fragments
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
/**
|
|
431
|
-
* Check if a file path matches any cached entry
|
|
432
|
-
* Uses partial matching to handle different path formats
|
|
433
|
-
*
|
|
434
|
-
* @param filePath - The file path to check
|
|
435
|
-
* @param cacheKey - The cache key to match against
|
|
436
|
-
* @returns True if the paths match
|
|
437
|
-
*/
|
|
438
|
-
function pathMatchesCacheKey(filePath: string, cacheKey: string): boolean {
|
|
439
|
-
const normalizedFile = normalizePathForCache(filePath);
|
|
440
|
-
const normalizedKey = normalizePathForCache(cacheKey);
|
|
441
|
-
|
|
442
|
-
// Exact match
|
|
443
|
-
if (normalizedFile === normalizedKey) return true;
|
|
444
|
-
|
|
445
|
-
// Partial match (file path ends with cache key or vice versa)
|
|
446
|
-
if (normalizedFile.endsWith(normalizedKey) || normalizedKey.endsWith(normalizedFile)) return true;
|
|
447
|
-
|
|
448
|
-
// Filename match (for cases where full paths differ)
|
|
449
|
-
const fileName = normalizedFile.split('/').pop();
|
|
450
|
-
const keyFileName = normalizedKey.split('/').pop();
|
|
451
|
-
if (fileName && keyFileName && fileName === keyFileName) return true;
|
|
452
|
-
|
|
453
|
-
return false;
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
/**
|
|
457
|
-
* Invalidate cache entries for a specific file path
|
|
458
|
-
* Called when a component file changes during development
|
|
459
|
-
*
|
|
460
|
-
* @param filePath - The path of the changed file
|
|
461
|
-
* @returns Number of cache entries invalidated
|
|
462
|
-
*/
|
|
463
|
-
export function invalidateCacheForFile(filePath: string): number {
|
|
464
|
-
let invalidatedCount = 0;
|
|
465
|
-
|
|
466
|
-
// Find and remove matching entries from analysis cache
|
|
467
|
-
for (const key of islandCache.analysis.keys()) {
|
|
468
|
-
if (pathMatchesCacheKey(filePath, key)) {
|
|
469
|
-
islandCache.analysis.delete(key);
|
|
470
|
-
invalidatedCount++;
|
|
471
|
-
if (isVerbose()) {
|
|
472
|
-
console.log(`🗑️ [Cache] Invalidated analysis cache for: ${key}`);
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
// Find and remove matching entries from paths cache
|
|
478
|
-
for (const key of islandCache.paths.keys()) {
|
|
479
|
-
if (pathMatchesCacheKey(filePath, key)) {
|
|
480
|
-
islandCache.paths.delete(key);
|
|
481
|
-
invalidatedCount++;
|
|
482
|
-
if (isVerbose()) {
|
|
483
|
-
console.log(`🗑️ [Cache] Invalidated path cache for: ${key}`);
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
// Find and remove matching entries from frameworks cache
|
|
489
|
-
for (const key of islandCache.frameworks.keys()) {
|
|
490
|
-
if (pathMatchesCacheKey(filePath, key)) {
|
|
491
|
-
islandCache.frameworks.delete(key);
|
|
492
|
-
invalidatedCount++;
|
|
493
|
-
if (isVerbose()) {
|
|
494
|
-
console.log(`🗑️ [Cache] Invalidated framework cache for: ${key}`);
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
// Update stats
|
|
500
|
-
islandCache.stats.analysisSize = islandCache.analysis.size;
|
|
501
|
-
islandCache.stats.pathsSize = islandCache.paths.size;
|
|
502
|
-
islandCache.stats.frameworksSize = islandCache.frameworks.size;
|
|
503
|
-
|
|
504
|
-
return invalidatedCount;
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
/**
|
|
508
|
-
* Check if a file path is an island component file
|
|
509
|
-
* Used to determine if cache invalidation is needed
|
|
510
|
-
*
|
|
511
|
-
* @param filePath - The file path to check
|
|
512
|
-
* @returns True if the file is an island component
|
|
513
|
-
*/
|
|
514
|
-
export function isIslandComponentFile(filePath: string): boolean {
|
|
515
|
-
const normalized = normalizePathForCache(filePath);
|
|
516
|
-
|
|
517
|
-
// Check if it's in an islands directory
|
|
518
|
-
if (normalized.includes('/islands/') || normalized.includes('\\islands\\')) {
|
|
519
|
-
return true;
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
// Check for common component file extensions
|
|
523
|
-
const componentExtensions = ['.tsx', '.jsx', '.vue', '.svelte', '.solid.tsx', '.lit.ts'];
|
|
524
|
-
return componentExtensions.some(ext => normalized.endsWith(ext));
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
/**
|
|
528
|
-
* Clear all caches when file structure changes significantly
|
|
529
|
-
* Called when files are added or removed
|
|
530
|
-
*/
|
|
531
|
-
export function clearPathCacheOnStructureChange(): void {
|
|
532
|
-
islandCache.paths.clear();
|
|
533
|
-
islandCache.stats.pathsSize = 0;
|
|
534
|
-
|
|
535
|
-
if (isVerbose()) {
|
|
536
|
-
console.log('🗑️ [Cache] Cleared path cache due to file structure change');
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
/**
|
|
541
|
-
* Alias for clearCache - provides a more descriptive name for external use
|
|
542
|
-
* Clears all island render caches
|
|
543
|
-
*/
|
|
544
|
-
export function clearIslandCache(): void {
|
|
545
|
-
clearCache();
|
|
546
|
-
|
|
547
|
-
if (isVerbose()) {
|
|
548
|
-
console.log('🗑️ [Cache] Cleared all island render caches');
|
|
549
|
-
}
|
|
550
|
-
}
|
package/src/islands/types.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import type { JSX } from "preact";
|
|
2
|
-
import type { AnalyzerOptions } from "../core/components/component-analyzer.ts";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Framework type for island components
|
|
6
|
-
* Represents the supported UI frameworks for island architecture
|
|
7
|
-
*/
|
|
8
|
-
export type Framework =
|
|
9
|
-
| "solid"
|
|
10
|
-
| "vue"
|
|
11
|
-
| "svelte"
|
|
12
|
-
| "preact"
|
|
13
|
-
| "react"
|
|
14
|
-
| "lit"
|
|
15
|
-
| "qwik"
|
|
16
|
-
| "unknown";
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Props for the Island component
|
|
20
|
-
* Defines the configuration for rendering an interactive island component
|
|
21
|
-
*/
|
|
22
|
-
export interface IslandProps {
|
|
23
|
-
/** Path to the island component (e.g., "/islands/Counter.tsx") */
|
|
24
|
-
src: string;
|
|
25
|
-
/** Hydration condition */
|
|
26
|
-
condition?:
|
|
27
|
-
| "on:visible"
|
|
28
|
-
| "on:interaction"
|
|
29
|
-
| "on:idle"
|
|
30
|
-
| "on:client"
|
|
31
|
-
| `media:${string}`;
|
|
32
|
-
/** Props to pass to the island component */
|
|
33
|
-
props?: Record<string, unknown>;
|
|
34
|
-
/** Children to render inside the island (for SSR) */
|
|
35
|
-
children?: JSX.Element | JSX.Element[] | string;
|
|
36
|
-
/** Whether to render server-side (default: true unless condition is 'on:client') */
|
|
37
|
-
ssr?: boolean;
|
|
38
|
-
/** Framework hint for client hydration */
|
|
39
|
-
framework?: "solid" | "vue" | "preact" | "react" | "svelte" | "lit" | "qwik";
|
|
40
|
-
/** Force SSR-only rendering without hydration */
|
|
41
|
-
ssrOnly?: boolean;
|
|
42
|
-
/** Component render options for intelligent detection */
|
|
43
|
-
renderOptions?: AnalyzerOptions;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Parameters for framework-specific render functions
|
|
48
|
-
* Used by all framework renderers to maintain consistent interface
|
|
49
|
-
*/
|
|
50
|
-
export interface RenderParams {
|
|
51
|
-
/** Path to the island component */
|
|
52
|
-
src: string;
|
|
53
|
-
/** Hydration condition */
|
|
54
|
-
condition: IslandProps["condition"];
|
|
55
|
-
/** Props to pass to the component */
|
|
56
|
-
props: Record<string, unknown>;
|
|
57
|
-
/** Whether to render server-side */
|
|
58
|
-
ssr: boolean;
|
|
59
|
-
/** Component render options for intelligent detection */
|
|
60
|
-
renderOptions?: AnalyzerOptions;
|
|
61
|
-
/** Force SSR-only rendering without hydration */
|
|
62
|
-
ssrOnly?: boolean;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Entry in the Svelte SSR CSS collection
|
|
67
|
-
* Tracks CSS for Svelte components during server-side rendering
|
|
68
|
-
*/
|
|
69
|
-
export interface SvelteSSRCSSEntry {
|
|
70
|
-
/** The CSS content */
|
|
71
|
-
css: string;
|
|
72
|
-
/** Unique scope identifier for the component */
|
|
73
|
-
scopeId: string;
|
|
74
|
-
/** Source path of the component */
|
|
75
|
-
src: string;
|
|
76
|
-
/** Whether this is global CSS */
|
|
77
|
-
isGlobal: boolean;
|
|
78
|
-
/** Timestamp when the CSS was added */
|
|
79
|
-
timestamp: number;
|
|
80
|
-
}
|