bertui 1.2.9 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -242
- package/TYPES_PATCH.md +17 -0
- package/bin/bertui.js +2 -7
- package/package.json +32 -98
- package/src/config.ts +4 -0
- package/src/index.ts +32 -0
- package/src/optional.ts +49 -0
- package/src/router.ts +3 -0
- package/tsconfig.json +29 -0
- package/LICENSE +0 -21
- package/index.js +0 -103
- package/src/analyzer/index.js +0 -370
- package/src/build/compiler/file-transpiler.js +0 -216
- package/src/build/compiler/index.js +0 -31
- package/src/build/compiler/route-discoverer.js +0 -49
- package/src/build/compiler/router-generator.js +0 -105
- package/src/build/css-builder.js +0 -81
- package/src/build/generators/html-generator.js +0 -263
- package/src/build/generators/robots-generator.js +0 -58
- package/src/build/generators/sitemap-generator.js +0 -63
- package/src/build/image-optimizer.js +0 -137
- package/src/build/processors/asset-processor.js +0 -19
- package/src/build/processors/css-builder.js +0 -142
- package/src/build/server-island-validator.js +0 -67
- package/src/build/ssr-renderer.js +0 -64
- package/src/build.js +0 -273
- package/src/cli.js +0 -131
- package/src/client/compiler.js +0 -522
- package/src/client/fast-refresh.js +0 -72
- package/src/client/hmr-runtime.js +0 -59
- package/src/compiler/index.js +0 -25
- package/src/compiler/router-generator-pure.js +0 -104
- package/src/compiler/transform.js +0 -149
- package/src/config/defaultConfig.js +0 -37
- package/src/config/index.js +0 -2
- package/src/config/loadConfig.js +0 -64
- package/src/config/og-image.png +0 -0
- package/src/css/index.js +0 -46
- package/src/css/processor.js +0 -172
- package/src/dev.js +0 -68
- package/src/hydration/index.js +0 -151
- package/src/image-optimizer/index.js +0 -103
- package/src/images/index.js +0 -102
- package/src/images/processor.js +0 -169
- package/src/layouts/index.js +0 -165
- package/src/loading/index.js +0 -210
- package/src/logger/logger.js +0 -320
- package/src/logger/notes.md +0 -20
- package/src/middleware/index.js +0 -182
- package/src/router/Router.js +0 -150
- package/src/router/SSRRouter.js +0 -156
- package/src/router/index.js +0 -3
- package/src/scaffolder/index.js +0 -310
- package/src/serve.js +0 -193
- package/src/server/dev-handler.js +0 -195
- package/src/server/dev-server-utils.js +0 -406
- package/src/server/dev-server.js +0 -15
- package/src/server/hmr-handler.js +0 -148
- package/src/server/index.js +0 -3
- package/src/server/notes.md +0 -1
- package/src/server/request-handler.js +0 -36
- package/src/server-islands/extractor.js +0 -198
- package/src/server-islands/index.js +0 -59
- package/src/styles/bertui.css +0 -210
- package/src/utils/cache.js +0 -297
- package/src/utils/env.js +0 -87
- package/src/utils/importhow.js +0 -52
- package/src/utils/index.js +0 -11
- package/src/utils/meta-extractor.js +0 -127
- package/types/bin/bertui.d.ts +0 -3
- package/types/bin/bertui.d.ts.map +0 -1
- package/types/error-overlay.d.ts +0 -2
- package/types/error-overlay.d.ts.map +0 -1
- package/types/index.d.ts +0 -26
- package/types/index.d.ts.map +0 -1
- package/types/scripts/fix-wasm-exports.d.ts +0 -2
- package/types/scripts/fix-wasm-exports.d.ts.map +0 -1
- package/types/src/analyzer/index.d.ts +0 -8
- package/types/src/analyzer/index.d.ts.map +0 -1
- package/types/src/build/compiler/file-transpiler.d.ts +0 -5
- package/types/src/build/compiler/file-transpiler.d.ts.map +0 -1
- package/types/src/build/compiler/index.d.ts +0 -12
- package/types/src/build/compiler/index.d.ts.map +0 -1
- package/types/src/build/compiler/route-discoverer.d.ts +0 -2
- package/types/src/build/compiler/route-discoverer.d.ts.map +0 -1
- package/types/src/build/compiler/router-generator.d.ts +0 -2
- package/types/src/build/compiler/router-generator.d.ts.map +0 -1
- package/types/src/build/css-builder.d.ts +0 -18
- package/types/src/build/css-builder.d.ts.map +0 -1
- package/types/src/build/generators/html-generator.d.ts +0 -2
- package/types/src/build/generators/html-generator.d.ts.map +0 -1
- package/types/src/build/generators/robots-generator.d.ts +0 -11
- package/types/src/build/generators/robots-generator.d.ts.map +0 -1
- package/types/src/build/generators/sitemap-generator.d.ts +0 -5
- package/types/src/build/generators/sitemap-generator.d.ts.map +0 -1
- package/types/src/build/image-optimizer.d.ts +0 -11
- package/types/src/build/image-optimizer.d.ts.map +0 -1
- package/types/src/build/processors/asset-processor.d.ts +0 -2
- package/types/src/build/processors/asset-processor.d.ts.map +0 -1
- package/types/src/build/processors/css-builder.d.ts +0 -2
- package/types/src/build/processors/css-builder.d.ts.map +0 -1
- package/types/src/build/server-island-validator.d.ts +0 -27
- package/types/src/build/server-island-validator.d.ts.map +0 -1
- package/types/src/build.d.ts +0 -5
- package/types/src/build.d.ts.map +0 -1
- package/types/src/cli.d.ts +0 -2
- package/types/src/cli.d.ts.map +0 -1
- package/types/src/client/compiler.d.ts +0 -16
- package/types/src/client/compiler.d.ts.map +0 -1
- package/types/src/client/fast-refresh.d.ts +0 -3
- package/types/src/client/fast-refresh.d.ts.map +0 -1
- package/types/src/client/hmr-runtime.d.ts +0 -4
- package/types/src/client/hmr-runtime.d.ts.map +0 -1
- package/types/src/compiler/index.d.ts +0 -8
- package/types/src/compiler/index.d.ts.map +0 -1
- package/types/src/compiler/router-generator-pure.d.ts +0 -2
- package/types/src/compiler/router-generator-pure.d.ts.map +0 -1
- package/types/src/compiler/transform.d.ts +0 -36
- package/types/src/compiler/transform.d.ts.map +0 -1
- package/types/src/config/defaultConfig.d.ts +0 -26
- package/types/src/config/defaultConfig.d.ts.map +0 -1
- package/types/src/config/index.d.ts +0 -3
- package/types/src/config/index.d.ts.map +0 -1
- package/types/src/config/loadConfig.d.ts +0 -2
- package/types/src/config/loadConfig.d.ts.map +0 -1
- package/types/src/css/index.d.ts +0 -6
- package/types/src/css/index.d.ts.map +0 -1
- package/types/src/css/processor.d.ts +0 -23
- package/types/src/css/processor.d.ts.map +0 -1
- package/types/src/dev.d.ts +0 -2
- package/types/src/dev.d.ts.map +0 -1
- package/types/src/hydration/index.d.ts +0 -33
- package/types/src/hydration/index.d.ts.map +0 -1
- package/types/src/image-optimizer/index.d.ts +0 -24
- package/types/src/image-optimizer/index.d.ts.map +0 -1
- package/types/src/images/index.d.ts +0 -12
- package/types/src/images/index.d.ts.map +0 -1
- package/types/src/images/processor.d.ts +0 -30
- package/types/src/images/processor.d.ts.map +0 -1
- package/types/src/layouts/index.d.ts +0 -28
- package/types/src/layouts/index.d.ts.map +0 -1
- package/types/src/loading/index.d.ts +0 -28
- package/types/src/loading/index.d.ts.map +0 -1
- package/types/src/logger/logger.d.ts +0 -30
- package/types/src/logger/logger.d.ts.map +0 -1
- package/types/src/middleware/index.d.ts +0 -61
- package/types/src/middleware/index.d.ts.map +0 -1
- package/types/src/router/Router.d.ts +0 -16
- package/types/src/router/Router.d.ts.map +0 -1
- package/types/src/router/SSRRouter.d.ts +0 -20
- package/types/src/router/SSRRouter.d.ts.map +0 -1
- package/types/src/router/index.d.ts +0 -3
- package/types/src/router/index.d.ts.map +0 -1
- package/types/src/scaffolder/index.d.ts +0 -14
- package/types/src/scaffolder/index.d.ts.map +0 -1
- package/types/src/serve.d.ts +0 -3
- package/types/src/serve.d.ts.map +0 -1
- package/types/src/server/dev-handler.d.ts +0 -13
- package/types/src/server/dev-handler.d.ts.map +0 -1
- package/types/src/server/dev-server-utils.d.ts +0 -6
- package/types/src/server/dev-server-utils.d.ts.map +0 -1
- package/types/src/server/dev-server.d.ts +0 -18
- package/types/src/server/dev-server.d.ts.map +0 -1
- package/types/src/server/hmr-handler.d.ts +0 -19
- package/types/src/server/hmr-handler.d.ts.map +0 -1
- package/types/src/server/index.d.ts +0 -4
- package/types/src/server/index.d.ts.map +0 -1
- package/types/src/server/request-handler.d.ts +0 -19
- package/types/src/server/request-handler.d.ts.map +0 -1
- package/types/src/server-islands/extractor.d.ts +0 -16
- package/types/src/server-islands/extractor.d.ts.map +0 -1
- package/types/src/server-islands/index.d.ts +0 -3
- package/types/src/server-islands/index.d.ts.map +0 -1
- package/types/src/utils/cache.d.ts +0 -52
- package/types/src/utils/cache.d.ts.map +0 -1
- package/types/src/utils/env.d.ts +0 -20
- package/types/src/utils/env.d.ts.map +0 -1
- package/types/src/utils/importhow.d.ts +0 -15
- package/types/src/utils/importhow.d.ts.map +0 -1
- package/types/src/utils/index.d.ts +0 -3
- package/types/src/utils/index.d.ts.map +0 -1
- package/types/src/utils/meta-extractor.d.ts +0 -13
- package/types/src/utils/meta-extractor.d.ts.map +0 -1
package/src/utils/cache.js
DELETED
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
// bertui/src/utils/cache.js - ULTRA FAST CACHING (Microsecond precision)
|
|
2
|
-
import { createHash } from 'crypto';
|
|
3
|
-
import logger from '../logger/logger.js';
|
|
4
|
-
|
|
5
|
-
export class BertuiCache {
|
|
6
|
-
constructor(options = {}) {
|
|
7
|
-
this.maxSize = options.maxSize || 5000;
|
|
8
|
-
this.ttl = options.ttl || 30000; // 30 seconds default
|
|
9
|
-
this.stats = { hits: 0, misses: 0, sets: 0, evictions: 0 };
|
|
10
|
-
|
|
11
|
-
// Main cache store
|
|
12
|
-
this.store = new Map();
|
|
13
|
-
|
|
14
|
-
// File content cache with timestamps
|
|
15
|
-
this.fileCache = new Map();
|
|
16
|
-
this.fileTimestamps = new Map();
|
|
17
|
-
|
|
18
|
-
// Compiled code cache (keyed by content hash)
|
|
19
|
-
this.codeCache = new Map();
|
|
20
|
-
|
|
21
|
-
// CSS processing cache
|
|
22
|
-
this.cssCache = new Map();
|
|
23
|
-
|
|
24
|
-
// Image optimization cache
|
|
25
|
-
this.imageCache = new Map();
|
|
26
|
-
|
|
27
|
-
// Weak reference cache for DOM objects (if in browser)
|
|
28
|
-
if (typeof WeakRef !== 'undefined') {
|
|
29
|
-
this.weakCache = new Map();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Start periodic cleanup
|
|
33
|
-
this.cleanupInterval = setInterval(() => this.cleanup(), 60000);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// ULTRA FAST GET with microsecond timing
|
|
37
|
-
get(key, options = {}) {
|
|
38
|
-
const start = process.hrtime.bigint();
|
|
39
|
-
|
|
40
|
-
const item = this.store.get(key);
|
|
41
|
-
if (!item) {
|
|
42
|
-
this.stats.misses++;
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Check TTL
|
|
47
|
-
const ttl = options.ttl || item.ttl || this.ttl;
|
|
48
|
-
if (Date.now() - item.timestamp > ttl) {
|
|
49
|
-
this.store.delete(key);
|
|
50
|
-
this.stats.misses++;
|
|
51
|
-
this.stats.evictions++;
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
this.stats.hits++;
|
|
56
|
-
|
|
57
|
-
// Update access time for LRU
|
|
58
|
-
item.lastAccessed = Date.now();
|
|
59
|
-
|
|
60
|
-
if (options.logSpeed) {
|
|
61
|
-
const end = process.hrtime.bigint();
|
|
62
|
-
const duration = Number(end - start) / 1000; // Microseconds
|
|
63
|
-
logger.debug(`⚡ Cache hit: ${duration.toFixed(3)}µs for ${key.substring(0, 30)}...`);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return item.value;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
set(key, value, options = {}) {
|
|
70
|
-
// Generate hash for large values to save memory
|
|
71
|
-
const valueHash = typeof value === 'string' && value.length > 10000
|
|
72
|
-
? createHash('md5').update(value).digest('hex')
|
|
73
|
-
: null;
|
|
74
|
-
|
|
75
|
-
this.store.set(key, {
|
|
76
|
-
value: valueHash ? { __hash: valueHash, __original: null } : value,
|
|
77
|
-
valueHash,
|
|
78
|
-
timestamp: Date.now(),
|
|
79
|
-
lastAccessed: Date.now(),
|
|
80
|
-
ttl: options.ttl || this.ttl,
|
|
81
|
-
size: this.getSize(value)
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
this.stats.sets++;
|
|
85
|
-
|
|
86
|
-
// Store original separately if hashed
|
|
87
|
-
if (valueHash) {
|
|
88
|
-
this.codeCache.set(valueHash, value);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// LRU cleanup if needed
|
|
92
|
-
if (this.store.size > this.maxSize) {
|
|
93
|
-
this.evictLRU();
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// FILE CACHE: Zero-copy file reading with mtime validation
|
|
98
|
-
async getFile(filePath, options = {}) {
|
|
99
|
-
const cacheKey = `file:${filePath}`;
|
|
100
|
-
|
|
101
|
-
try {
|
|
102
|
-
const file = Bun.file(filePath);
|
|
103
|
-
const exists = await file.exists();
|
|
104
|
-
if (!exists) return null;
|
|
105
|
-
|
|
106
|
-
const stats = await file.stat();
|
|
107
|
-
const mtimeMs = stats.mtimeMs;
|
|
108
|
-
|
|
109
|
-
// Check cache
|
|
110
|
-
const cached = this.fileCache.get(cacheKey);
|
|
111
|
-
const cachedTime = this.fileTimestamps.get(cacheKey);
|
|
112
|
-
|
|
113
|
-
if (cached && cachedTime === mtimeMs) {
|
|
114
|
-
if (options.logSpeed) {
|
|
115
|
-
logger.debug(`📄 File cache hit: ${filePath.split('/').pop()}`);
|
|
116
|
-
}
|
|
117
|
-
return cached;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Read file (single operation)
|
|
121
|
-
const start = process.hrtime.bigint();
|
|
122
|
-
const content = await file.arrayBuffer();
|
|
123
|
-
const buffer = Buffer.from(content);
|
|
124
|
-
const end = process.hrtime.bigint();
|
|
125
|
-
|
|
126
|
-
// Store in cache
|
|
127
|
-
this.fileCache.set(cacheKey, buffer);
|
|
128
|
-
this.fileTimestamps.set(cacheKey, mtimeMs);
|
|
129
|
-
|
|
130
|
-
if (options.logSpeed) {
|
|
131
|
-
const duration = Number(end - start) / 1000;
|
|
132
|
-
logger.debug(`📄 File read: ${duration.toFixed(3)}µs - ${filePath.split('/').pop()}`);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return buffer;
|
|
136
|
-
|
|
137
|
-
} catch (error) {
|
|
138
|
-
logger.error(`File cache error: ${filePath} - ${error.message}`);
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// CODE TRANSFORMATION CACHE
|
|
144
|
-
getTransformed(sourceCode, options = {}) {
|
|
145
|
-
const hash = createHash('md5')
|
|
146
|
-
.update(sourceCode)
|
|
147
|
-
.update(JSON.stringify(options))
|
|
148
|
-
.digest('hex');
|
|
149
|
-
|
|
150
|
-
const cacheKey = `transform:${hash}`;
|
|
151
|
-
return this.get(cacheKey, options);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
setTransformed(sourceCode, result, options = {}) {
|
|
155
|
-
const hash = createHash('md5')
|
|
156
|
-
.update(sourceCode)
|
|
157
|
-
.update(JSON.stringify(options))
|
|
158
|
-
.digest('hex');
|
|
159
|
-
|
|
160
|
-
const cacheKey = `transform:${hash}`;
|
|
161
|
-
this.set(cacheKey, result, options);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// CSS PROCESSING CACHE
|
|
165
|
-
getCSS(css, options = {}) {
|
|
166
|
-
const hash = createHash('md5')
|
|
167
|
-
.update(css)
|
|
168
|
-
.update(JSON.stringify(options))
|
|
169
|
-
.digest('hex');
|
|
170
|
-
|
|
171
|
-
return this.cssCache.get(hash);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
setCSS(css, result, options = {}) {
|
|
175
|
-
const hash = createHash('md5')
|
|
176
|
-
.update(css)
|
|
177
|
-
.update(JSON.stringify(options))
|
|
178
|
-
.digest('hex');
|
|
179
|
-
|
|
180
|
-
this.cssCache.set(hash, result);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// BATCH OPERATIONS
|
|
184
|
-
mget(keys) {
|
|
185
|
-
const results = [];
|
|
186
|
-
for (const key of keys) {
|
|
187
|
-
results.push(this.get(key));
|
|
188
|
-
}
|
|
189
|
-
return results;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
mset(entries) {
|
|
193
|
-
for (const [key, value] of entries) {
|
|
194
|
-
this.set(key, value);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// STATS with microsecond precision
|
|
199
|
-
getStats() {
|
|
200
|
-
const total = this.stats.hits + this.stats.misses;
|
|
201
|
-
const hitRate = total > 0 ? (this.stats.hits / total * 100).toFixed(2) : 0;
|
|
202
|
-
|
|
203
|
-
// Memory usage
|
|
204
|
-
const memUsage = process.memoryUsage();
|
|
205
|
-
|
|
206
|
-
return {
|
|
207
|
-
hits: this.stats.hits,
|
|
208
|
-
misses: this.stats.misses,
|
|
209
|
-
sets: this.stats.sets,
|
|
210
|
-
evictions: this.stats.evictions,
|
|
211
|
-
hitRate: `${hitRate}%`,
|
|
212
|
-
size: this.store.size,
|
|
213
|
-
fileCacheSize: this.fileCache.size,
|
|
214
|
-
codeCacheSize: this.codeCache.size,
|
|
215
|
-
cssCacheSize: this.cssCache.size,
|
|
216
|
-
imageCacheSize: this.imageCache.size,
|
|
217
|
-
memory: {
|
|
218
|
-
heapUsed: `${(memUsage.heapUsed / 1024 / 1024).toFixed(2)} MB`,
|
|
219
|
-
heapTotal: `${(memUsage.heapTotal / 1024 / 1024).toFixed(2)} MB`,
|
|
220
|
-
rss: `${(memUsage.rss / 1024 / 1024).toFixed(2)} MB`
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// PRIVATE METHODS
|
|
226
|
-
getSize(value) {
|
|
227
|
-
if (typeof value === 'string') return value.length;
|
|
228
|
-
if (Buffer.isBuffer(value)) return value.length;
|
|
229
|
-
if (typeof value === 'object') return JSON.stringify(value).length;
|
|
230
|
-
return 0;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
evictLRU() {
|
|
234
|
-
const entries = Array.from(this.store.entries());
|
|
235
|
-
entries.sort((a, b) => a[1].lastAccessed - b[1].lastAccessed);
|
|
236
|
-
|
|
237
|
-
const removeCount = Math.floor(this.maxSize * 0.2); // Remove 20%
|
|
238
|
-
for (let i = 0; i < removeCount && i < entries.length; i++) {
|
|
239
|
-
this.store.delete(entries[i][0]);
|
|
240
|
-
this.stats.evictions++;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
cleanup() {
|
|
245
|
-
const now = Date.now();
|
|
246
|
-
let evicted = 0;
|
|
247
|
-
|
|
248
|
-
for (const [key, item] of this.store.entries()) {
|
|
249
|
-
if (now - item.timestamp > item.ttl) {
|
|
250
|
-
this.store.delete(key);
|
|
251
|
-
evicted++;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
if (evicted > 0) {
|
|
256
|
-
logger.debug(`🧹 Cache cleanup: removed ${evicted} expired items`);
|
|
257
|
-
this.stats.evictions += evicted;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
dispose() {
|
|
262
|
-
if (this.cleanupInterval) {
|
|
263
|
-
clearInterval(this.cleanupInterval);
|
|
264
|
-
}
|
|
265
|
-
this.store.clear();
|
|
266
|
-
this.fileCache.clear();
|
|
267
|
-
this.fileTimestamps.clear();
|
|
268
|
-
this.codeCache.clear();
|
|
269
|
-
this.cssCache.clear();
|
|
270
|
-
this.imageCache.clear();
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// Singleton instance
|
|
275
|
-
export const globalCache = new BertuiCache();
|
|
276
|
-
|
|
277
|
-
// Decorator for automatic caching of async functions
|
|
278
|
-
export function cached(options = {}) {
|
|
279
|
-
return function(target, propertyKey, descriptor) {
|
|
280
|
-
const originalMethod = descriptor.value;
|
|
281
|
-
|
|
282
|
-
descriptor.value = async function(...args) {
|
|
283
|
-
const cacheKey = `${propertyKey}:${JSON.stringify(args)}`;
|
|
284
|
-
const cached = globalCache.get(cacheKey, options);
|
|
285
|
-
|
|
286
|
-
if (cached !== null) {
|
|
287
|
-
return cached;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
const result = await originalMethod.apply(this, args);
|
|
291
|
-
globalCache.set(cacheKey, result, options);
|
|
292
|
-
return result;
|
|
293
|
-
};
|
|
294
|
-
|
|
295
|
-
return descriptor;
|
|
296
|
-
};
|
|
297
|
-
}
|
package/src/utils/env.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
// bertui/src/utils/env.js - COMPLETE FIXED VERSION
|
|
2
|
-
import { join } from 'path';
|
|
3
|
-
import { existsSync, readFileSync } from 'fs';
|
|
4
|
-
import logger from '../logger/logger.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Load environment variables from .env file
|
|
8
|
-
* @param {string} root - Project root directory
|
|
9
|
-
* @returns {Object} Environment variables
|
|
10
|
-
*/
|
|
11
|
-
export function loadEnvVariables(root) {
|
|
12
|
-
const envPath = join(root, '.env');
|
|
13
|
-
const envVars = {};
|
|
14
|
-
|
|
15
|
-
if (existsSync(envPath)) {
|
|
16
|
-
try {
|
|
17
|
-
// ✅ FIXED: Use Node.js readFileSync instead of Bun.file().text()
|
|
18
|
-
const envContent = readFileSync(envPath, 'utf-8');
|
|
19
|
-
const lines = envContent.split('\n');
|
|
20
|
-
|
|
21
|
-
for (const line of lines) {
|
|
22
|
-
// Skip empty lines and comments
|
|
23
|
-
if (!line.trim() || line.trim().startsWith('#')) continue;
|
|
24
|
-
|
|
25
|
-
// Parse KEY=VALUE
|
|
26
|
-
const match = line.match(/^([^=]+)=(.*)$/);
|
|
27
|
-
if (match) {
|
|
28
|
-
const key = match[1].trim();
|
|
29
|
-
let value = match[2].trim();
|
|
30
|
-
|
|
31
|
-
// Remove quotes if present
|
|
32
|
-
if ((value.startsWith('"') && value.endsWith('"')) ||
|
|
33
|
-
(value.startsWith("'") && value.endsWith("'"))) {
|
|
34
|
-
value = value.slice(1, -1);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
envVars[key] = value;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (Object.keys(envVars).length > 0) {
|
|
42
|
-
logger.debug(`Loaded ${Object.keys(envVars).length} environment variables from .env`);
|
|
43
|
-
}
|
|
44
|
-
} catch (error) {
|
|
45
|
-
logger.warn(`Failed to load .env: ${error.message}`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return envVars;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Generate JavaScript code to expose environment variables
|
|
54
|
-
* @param {Object} envVars - Environment variables object
|
|
55
|
-
* @returns {string} JavaScript code
|
|
56
|
-
*/
|
|
57
|
-
export function generateEnvCode(envVars) {
|
|
58
|
-
const exports = Object.entries(envVars)
|
|
59
|
-
.map(([key, value]) => `export const ${key} = ${JSON.stringify(value)};`)
|
|
60
|
-
.join('\n');
|
|
61
|
-
|
|
62
|
-
return `// Auto-generated environment variables
|
|
63
|
-
// Do not edit this file manually
|
|
64
|
-
|
|
65
|
-
${exports}
|
|
66
|
-
|
|
67
|
-
// Access via: import { VAR_NAME } from './env.js'
|
|
68
|
-
`;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Replace process.env references in code
|
|
73
|
-
* @param {string} code - Source code
|
|
74
|
-
* @param {Object} envVars - Environment variables
|
|
75
|
-
* @returns {string} Code with replaced env vars
|
|
76
|
-
*/
|
|
77
|
-
export function replaceEnvInCode(code, envVars) {
|
|
78
|
-
let modified = code;
|
|
79
|
-
|
|
80
|
-
for (const [key, value] of Object.entries(envVars)) {
|
|
81
|
-
// Replace process.env.KEY with actual value
|
|
82
|
-
const regex = new RegExp(`process\\.env\\.${key}\\b`, 'g');
|
|
83
|
-
modified = modified.replace(regex, JSON.stringify(value));
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return modified;
|
|
87
|
-
}
|
package/src/utils/importhow.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
// bertui/src/utils/importhow.js
|
|
2
|
-
import { join, relative, dirname } from 'path';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @param {Object} importhow - { alias: relPath } from bertui.config.js
|
|
6
|
-
* @param {string} projectRoot - absolute project root
|
|
7
|
-
* @param {string} compiledDir - if set, aliases resolve to compiledDir/<alias>
|
|
8
|
-
* pass .bertui/compiled in dev mode
|
|
9
|
-
* leave null in build mode (uses raw source paths)
|
|
10
|
-
*/
|
|
11
|
-
export function buildAliasMap(importhow = {}, projectRoot, compiledDir = null) {
|
|
12
|
-
const map = new Map();
|
|
13
|
-
for (const [alias, relPath] of Object.entries(importhow)) {
|
|
14
|
-
const abs = compiledDir
|
|
15
|
-
? join(compiledDir, alias) // dev: .bertui/compiled/amani
|
|
16
|
-
: join(projectRoot, relPath); // build: /project/src/components
|
|
17
|
-
map.set(alias, abs);
|
|
18
|
-
}
|
|
19
|
-
return map;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Rewrite alias import specifiers in compiled code.
|
|
24
|
-
* 'amani/button' → '../components/button.js'
|
|
25
|
-
*/
|
|
26
|
-
export function rewriteAliasImports(code, currentFile, aliasMap) {
|
|
27
|
-
if (!aliasMap || aliasMap.size === 0) return code;
|
|
28
|
-
|
|
29
|
-
const currentDir = dirname(currentFile);
|
|
30
|
-
const importRe = /(?:import|export)(?:\s+[\w*{},\s]+\s+from)?\s+['"]([^'"]+)['"]/g;
|
|
31
|
-
|
|
32
|
-
return code.replace(importRe, (match, specifier) => {
|
|
33
|
-
const slashIdx = specifier.indexOf('/');
|
|
34
|
-
const alias = slashIdx === -1 ? specifier : specifier.slice(0, slashIdx);
|
|
35
|
-
const rest = slashIdx === -1 ? '' : specifier.slice(slashIdx);
|
|
36
|
-
|
|
37
|
-
const absBase = aliasMap.get(alias);
|
|
38
|
-
if (!absBase) return match;
|
|
39
|
-
|
|
40
|
-
let rel = relative(currentDir, absBase + rest).replace(/\\/g, '/');
|
|
41
|
-
if (!rel.startsWith('.')) rel = './' + rel;
|
|
42
|
-
if (rest && !/\.\w+$/.test(rest)) rel += '.js';
|
|
43
|
-
|
|
44
|
-
return match.replace(`'${specifier}'`, `'${rel}'`).replace(`"${specifier}"`, `"${rel}"`);
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function getAliasDirs(aliasMap) {
|
|
49
|
-
const dirs = new Set();
|
|
50
|
-
for (const absPath of aliasMap.values()) dirs.add(absPath);
|
|
51
|
-
return dirs;
|
|
52
|
-
}
|
package/src/utils/index.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
// bertui/src/utils/meta-extractor.js
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Extract meta information from page component source code
|
|
5
|
-
* @param {string} sourceCode - Component source code
|
|
6
|
-
* @returns {Object} Extracted meta information
|
|
7
|
-
*/
|
|
8
|
-
export function extractMetaFromSource(sourceCode) {
|
|
9
|
-
const meta = {};
|
|
10
|
-
|
|
11
|
-
// Extract title
|
|
12
|
-
const titleMatch = sourceCode.match(/export\s+const\s+title\s*=\s*['"]([^'"]+)['"]/);
|
|
13
|
-
if (titleMatch) {
|
|
14
|
-
meta.title = titleMatch[1];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// Extract description
|
|
18
|
-
const descMatch = sourceCode.match(/export\s+const\s+description\s*=\s*['"]([^'"]+)['"]/);
|
|
19
|
-
if (descMatch) {
|
|
20
|
-
meta.description = descMatch[1];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Extract keywords
|
|
24
|
-
const keywordsMatch = sourceCode.match(/export\s+const\s+keywords\s*=\s*['"]([^'"]+)['"]/);
|
|
25
|
-
if (keywordsMatch) {
|
|
26
|
-
meta.keywords = keywordsMatch[1];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Extract author
|
|
30
|
-
const authorMatch = sourceCode.match(/export\s+const\s+author\s*=\s*['"]([^'"]+)['"]/);
|
|
31
|
-
if (authorMatch) {
|
|
32
|
-
meta.author = authorMatch[1];
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Extract og:title
|
|
36
|
-
const ogTitleMatch = sourceCode.match(/export\s+const\s+ogTitle\s*=\s*['"]([^'"]+)['"]/);
|
|
37
|
-
if (ogTitleMatch) {
|
|
38
|
-
meta.ogTitle = ogTitleMatch[1];
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Extract og:description
|
|
42
|
-
const ogDescMatch = sourceCode.match(/export\s+const\s+ogDescription\s*=\s*['"]([^'"]+)['"]/);
|
|
43
|
-
if (ogDescMatch) {
|
|
44
|
-
meta.ogDescription = ogDescMatch[1];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Extract og:image
|
|
48
|
-
const ogImageMatch = sourceCode.match(/export\s+const\s+ogImage\s*=\s*['"]([^'"]+)['"]/);
|
|
49
|
-
if (ogImageMatch) {
|
|
50
|
-
meta.ogImage = ogImageMatch[1];
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Extract language
|
|
54
|
-
const langMatch = sourceCode.match(/export\s+const\s+lang\s*=\s*['"]([^'"]+)['"]/);
|
|
55
|
-
if (langMatch) {
|
|
56
|
-
meta.lang = langMatch[1];
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Extract theme color
|
|
60
|
-
const themeMatch = sourceCode.match(/export\s+const\s+themeColor\s*=\s*['"]([^'"]+)['"]/);
|
|
61
|
-
if (themeMatch) {
|
|
62
|
-
meta.themeColor = themeMatch[1];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return meta;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Generate HTML meta tags from meta object
|
|
70
|
-
* @param {Object} meta - Meta information object
|
|
71
|
-
* @returns {string} HTML meta tags
|
|
72
|
-
*/
|
|
73
|
-
export function generateMetaTags(meta) {
|
|
74
|
-
const tags = [];
|
|
75
|
-
|
|
76
|
-
if (meta.title) {
|
|
77
|
-
tags.push(`<title>${escapeHtml(meta.title)}</title>`);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (meta.description) {
|
|
81
|
-
tags.push(`<meta name="description" content="${escapeHtml(meta.description)}">`);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (meta.keywords) {
|
|
85
|
-
tags.push(`<meta name="keywords" content="${escapeHtml(meta.keywords)}">`);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (meta.author) {
|
|
89
|
-
tags.push(`<meta name="author" content="${escapeHtml(meta.author)}">`);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (meta.themeColor) {
|
|
93
|
-
tags.push(`<meta name="theme-color" content="${escapeHtml(meta.themeColor)}">`);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Open Graph tags
|
|
97
|
-
if (meta.ogTitle) {
|
|
98
|
-
tags.push(`<meta property="og:title" content="${escapeHtml(meta.ogTitle)}">`);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (meta.ogDescription) {
|
|
102
|
-
tags.push(`<meta property="og:description" content="${escapeHtml(meta.ogDescription)}">`);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (meta.ogImage) {
|
|
106
|
-
tags.push(`<meta property="og:image" content="${escapeHtml(meta.ogImage)}">`);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return tags.join('\n ');
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Escape HTML special characters
|
|
114
|
-
* @param {string} text - Text to escape
|
|
115
|
-
* @returns {string} Escaped text
|
|
116
|
-
*/
|
|
117
|
-
function escapeHtml(text) {
|
|
118
|
-
const map = {
|
|
119
|
-
'&': '&',
|
|
120
|
-
'<': '<',
|
|
121
|
-
'>': '>',
|
|
122
|
-
'"': '"',
|
|
123
|
-
"'": '''
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
return String(text).replace(/[&<>"']/g, m => map[m]);
|
|
127
|
-
}
|
package/types/bin/bertui.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bertui.d.ts","sourceRoot":"","sources":["../../bin/bertui.js"],"names":[],"mappings":""}
|
package/types/error-overlay.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"error-overlay.d.ts","sourceRoot":"","sources":["../error-overlay.js"],"names":[],"mappings":""}
|
package/types/index.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export { compileForBuild } from "./src/build/compiler/index.js";
|
|
2
|
-
export { discoverRoutes } from "./src/build/compiler/route-discoverer.js";
|
|
3
|
-
export { hmr } from "./src/client/hmr-runtime.js";
|
|
4
|
-
export { buildProduction } from "./src/build.js";
|
|
5
|
-
export { optimizeImages } from "./src/build/image-optimizer.js";
|
|
6
|
-
export { SSRRouter } from "./src/router/SSRRouter.js";
|
|
7
|
-
export { default as logger } from "./src/logger/logger.js";
|
|
8
|
-
export { program } from "./src/cli.js";
|
|
9
|
-
export { analyzeBuild } from "./src/analyzer/index.js";
|
|
10
|
-
export { createDevHandler } from "./src/server/dev-handler.js";
|
|
11
|
-
export { startDevServer } from "./src/server/dev-server.js";
|
|
12
|
-
export const version: "1.2.2";
|
|
13
|
-
export { compileProject, compileFile } from "./src/client/compiler.js";
|
|
14
|
-
export { optimizeImage, optimizeImagesBatch, hasWasm, version as optimizerVersion } from "./src/image-optimizer/index.js";
|
|
15
|
-
export { Router, Link, useRouter } from "./src/router/index.js";
|
|
16
|
-
export { loadConfig, defaultConfig } from "./src/config/index.js";
|
|
17
|
-
export { MiddlewareManager, loadMiddleware, runMiddleware, MiddlewareContext } from "./src/middleware/index.js";
|
|
18
|
-
export { discoverLayouts, compileLayouts, matchLayout, generateLayoutWrapper, injectLayoutsIntoRouter } from "./src/layouts/index.js";
|
|
19
|
-
export { discoverLoadingComponents, compileLoadingComponents, generateLoadingAwareRouter, getLoadingScript, DEFAULT_LOADING_HTML } from "./src/loading/index.js";
|
|
20
|
-
export { needsHydration, getInteractiveFeatures, analyzeRoutes, generatePartialHydrationCode, logHydrationReport } from "./src/hydration/index.js";
|
|
21
|
-
export { scaffold, parseCreateArgs } from "./src/scaffolder/index.js";
|
|
22
|
-
export { minifyCSS, combineCSS } from "./src/css/processor.js";
|
|
23
|
-
export { copyImagesSync, isImageFile } from "./src/images/index.js";
|
|
24
|
-
export { extractStaticHTML, isServerIsland, validateServerIsland } from "./src/server-islands/index.js";
|
|
25
|
-
export { buildAliasMap, rewriteAliasImports, getAliasDirs } from "./src/utils/importhow.js";
|
|
26
|
-
//# sourceMappingURL=index.d.ts.map
|
package/types/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.js"],"names":[],"mappings":";;;;;;;;;;;AAsGA,sBAAuB,OAAO,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fix-wasm-exports.d.ts","sourceRoot":"","sources":["../../scripts/fix-wasm-exports.js"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/analyzer/index.js"],"names":[],"mappings":"AAOA;;GAEG;AACH;;;UA8BC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file-transpiler.d.ts","sourceRoot":"","sources":["../../../../src/build/compiler/file-transpiler.js"],"names":[],"mappings":"AAOA;;GAEG;AACH,0HA4BC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param {string} root
|
|
3
|
-
* @param {string} buildDir
|
|
4
|
-
* @param {Object} envVars
|
|
5
|
-
* @param {Object} config - full bertui config (includes importhow)
|
|
6
|
-
*/
|
|
7
|
-
export function compileForBuild(root: string, buildDir: string, envVars: Object, config?: Object): Promise<{
|
|
8
|
-
routes: any[];
|
|
9
|
-
serverIslands: any[];
|
|
10
|
-
clientRoutes: any[];
|
|
11
|
-
}>;
|
|
12
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/build/compiler/index.js"],"names":[],"mappings":"AAQA;;;;;GAKG;AACH,sCALW,MAAM,YACN,MAAM,WACN,MAAM,WACN,MAAM;;;;GAwChB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"route-discoverer.d.ts","sourceRoot":"","sources":["../../../../src/build/compiler/route-discoverer.js"],"names":[],"mappings":"AAIA,8DA4CC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"router-generator.d.ts","sourceRoot":"","sources":["../../../../src/build/compiler/router-generator.js"],"names":[],"mappings":"AAGA,+EAoGC"}
|