@zylaris/compiler 1.0.1 → 1.0.2
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/index.d.ts +26 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +153 -67
- package/dist/index.js.map +1 -1
- package/dist/jit.d.ts +61 -14
- package/dist/jit.d.ts.map +1 -1
- package/dist/jit.js +210 -94
- package/dist/jit.js.map +1 -1
- package/package.json +1 -1
- package/dist/compile-worker.d.ts +0 -2
- package/dist/compile-worker.d.ts.map +0 -1
- package/dist/compile-worker.js +0 -49
- package/dist/compile-worker.js.map +0 -1
- package/dist/lazy-compile.d.ts +0 -28
- package/dist/lazy-compile.d.ts.map +0 -1
- package/dist/lazy-compile.js +0 -171
- package/dist/lazy-compile.js.map +0 -1
- package/dist/parallel-jit.d.ts +0 -61
- package/dist/parallel-jit.d.ts.map +0 -1
- package/dist/parallel-jit.js +0 -223
- package/dist/parallel-jit.js.map +0 -1
package/dist/jit.js
CHANGED
|
@@ -1,138 +1,254 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* JIT Compiler for Development
|
|
3
|
+
* Ultra-fast compilation with LRU caching and batch operations
|
|
4
|
+
*/
|
|
3
5
|
import { transform as esbuildTransform } from 'esbuild';
|
|
4
6
|
import { createHash } from 'crypto';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
import { performance } from 'perf_hooks';
|
|
8
|
+
// LRU Cache implementation with size limits
|
|
9
|
+
class JITCache {
|
|
10
|
+
cache = new Map();
|
|
11
|
+
maxSize;
|
|
12
|
+
maxEntries;
|
|
13
|
+
defaultTimeout;
|
|
14
|
+
stats = { hits: 0, misses: 0 };
|
|
15
|
+
constructor(options = {}) {
|
|
16
|
+
this.maxSize = (options.maxSizeMB || 50) * 1024 * 1024;
|
|
17
|
+
this.maxEntries = options.maxEntries || 1000;
|
|
18
|
+
this.defaultTimeout = options.defaultTimeoutMs || 5 * 60 * 1000; // 5 min
|
|
19
|
+
}
|
|
20
|
+
get(key, timeout) {
|
|
21
|
+
const entry = this.cache.get(key);
|
|
22
|
+
if (!entry) {
|
|
23
|
+
this.stats.misses++;
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
// Check expiration
|
|
27
|
+
const isExpired = Date.now() - entry.timestamp > (timeout || this.defaultTimeout);
|
|
28
|
+
if (isExpired) {
|
|
29
|
+
this.cache.delete(key);
|
|
30
|
+
this.stats.misses++;
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
// Update stats and move to end (LRU)
|
|
34
|
+
entry.hits++;
|
|
35
|
+
this.stats.hits++;
|
|
36
|
+
this.cache.delete(key);
|
|
37
|
+
this.cache.set(key, entry);
|
|
38
|
+
return entry;
|
|
39
|
+
}
|
|
40
|
+
set(key, entry) {
|
|
41
|
+
const size = entry.code.length + entry.map.length;
|
|
42
|
+
// Evict old entries if needed
|
|
43
|
+
while (this.shouldEvict(size)) {
|
|
44
|
+
const firstKey = this.cache.keys().next().value;
|
|
45
|
+
if (firstKey) {
|
|
46
|
+
this.cache.delete(firstKey);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
this.cache.set(key, {
|
|
53
|
+
...entry,
|
|
54
|
+
size,
|
|
55
|
+
timestamp: Date.now(),
|
|
56
|
+
hits: 0,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
shouldEvict(newSize) {
|
|
60
|
+
if (this.cache.size === 0)
|
|
61
|
+
return false;
|
|
62
|
+
let totalSize = newSize;
|
|
63
|
+
for (const entry of this.cache.values()) {
|
|
64
|
+
totalSize += entry.size;
|
|
65
|
+
}
|
|
66
|
+
return this.cache.size >= this.maxEntries || totalSize > this.maxSize;
|
|
67
|
+
}
|
|
68
|
+
invalidate(filename) {
|
|
69
|
+
let count = 0;
|
|
70
|
+
for (const key of this.cache.keys()) {
|
|
71
|
+
if (key.includes(filename)) {
|
|
72
|
+
this.cache.delete(key);
|
|
73
|
+
count++;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return count;
|
|
77
|
+
}
|
|
78
|
+
invalidatePattern(pattern) {
|
|
79
|
+
let count = 0;
|
|
80
|
+
for (const key of this.cache.keys()) {
|
|
81
|
+
if (pattern.test(key)) {
|
|
82
|
+
this.cache.delete(key);
|
|
83
|
+
count++;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return count;
|
|
87
|
+
}
|
|
88
|
+
clear() {
|
|
89
|
+
this.cache.clear();
|
|
90
|
+
this.stats.hits = 0;
|
|
91
|
+
this.stats.misses = 0;
|
|
92
|
+
}
|
|
93
|
+
getStats() {
|
|
94
|
+
const total = this.stats.hits + this.stats.misses;
|
|
95
|
+
return {
|
|
96
|
+
hits: this.stats.hits,
|
|
97
|
+
misses: this.stats.misses,
|
|
98
|
+
hitRate: total > 0 ? this.stats.hits / total : 0,
|
|
99
|
+
size: Array.from(this.cache.values()).reduce((sum, e) => sum + e.size, 0),
|
|
100
|
+
entries: this.cache.size,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// Global cache instance
|
|
105
|
+
const jitCache = new JITCache({ maxSizeMB: 100, maxEntries: 2000 });
|
|
8
106
|
// Default options
|
|
9
107
|
const defaultOptions = {
|
|
10
108
|
target: 'es2022',
|
|
11
109
|
jsx: 'transform',
|
|
12
110
|
jsxImportSource: 'zylaris',
|
|
13
111
|
sourceMap: true,
|
|
14
|
-
cacheTimeout: 5 * 60 * 1000,
|
|
112
|
+
cacheTimeout: 5 * 60 * 1000,
|
|
15
113
|
};
|
|
16
|
-
|
|
17
|
-
* Generate cache key from content and options
|
|
18
|
-
*/
|
|
114
|
+
// Generate cache key
|
|
19
115
|
function generateCacheKey(source, filename, options) {
|
|
20
|
-
|
|
21
|
-
|
|
116
|
+
return createHash('md5')
|
|
117
|
+
.update(`${source.length}::${filename}::${JSON.stringify(options)}`)
|
|
118
|
+
.digest('hex');
|
|
22
119
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
120
|
+
// Extract dependencies for selective invalidation
|
|
121
|
+
// @ts-expect-error - Will be used for selective cache invalidation
|
|
122
|
+
function extractDependencies(source) {
|
|
123
|
+
const deps = new Set();
|
|
124
|
+
// Match import statements
|
|
125
|
+
const importRegex = /import\s+(?:(?:type\s+)?{[^}]*}|[^'"]*)\s*from\s*['"]([^'"]+)['"]|import\s*['"]([^'"]+)['"]/g;
|
|
126
|
+
let match;
|
|
127
|
+
while ((match = importRegex.exec(source)) !== null) {
|
|
128
|
+
const dep = match[1] || match[2];
|
|
129
|
+
if (dep && (dep.startsWith('./') || dep.startsWith('../'))) {
|
|
130
|
+
deps.add(dep);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return deps;
|
|
29
134
|
}
|
|
30
135
|
/**
|
|
31
|
-
* JIT Compile
|
|
32
|
-
* Uses esbuild for maximum speed with in-memory caching
|
|
136
|
+
* JIT Compile with caching
|
|
33
137
|
*/
|
|
34
138
|
export async function jitCompile(source, filename, options = {}) {
|
|
139
|
+
const startTime = performance.now();
|
|
35
140
|
const opts = { ...defaultOptions, ...options };
|
|
36
141
|
const cacheKey = generateCacheKey(source, filename, opts);
|
|
37
|
-
// Check cache
|
|
38
|
-
const cached =
|
|
39
|
-
if (cached
|
|
40
|
-
return {
|
|
142
|
+
// Check cache
|
|
143
|
+
const cached = jitCache.get(cacheKey, opts.cacheTimeout);
|
|
144
|
+
if (cached) {
|
|
145
|
+
return {
|
|
146
|
+
code: cached.code,
|
|
147
|
+
map: cached.map,
|
|
148
|
+
fromCache: true,
|
|
149
|
+
duration: performance.now() - startTime,
|
|
150
|
+
};
|
|
41
151
|
}
|
|
42
|
-
// Determine loader
|
|
43
|
-
const ext = filename.split('.').pop()?.toLowerCase();
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
152
|
+
// Determine loader
|
|
153
|
+
const ext = filename.split('.').pop()?.toLowerCase() || '';
|
|
154
|
+
const loader = ext === 'tsx' ? 'tsx' : ext === 'jsx' ? 'jsx' : 'ts';
|
|
155
|
+
// Compile with esbuild
|
|
156
|
+
try {
|
|
157
|
+
const result = await esbuildTransform(source, {
|
|
158
|
+
loader,
|
|
159
|
+
target: opts.target,
|
|
160
|
+
format: 'esm',
|
|
161
|
+
platform: 'neutral',
|
|
162
|
+
jsx: opts.jsx === 'transform' ? 'automatic' : 'preserve',
|
|
163
|
+
jsxImportSource: opts.jsxImportSource,
|
|
164
|
+
sourcemap: opts.sourceMap ? 'inline' : false,
|
|
165
|
+
sourcesContent: false,
|
|
166
|
+
minifyWhitespace: false,
|
|
167
|
+
minifyIdentifiers: false,
|
|
168
|
+
minifySyntax: false,
|
|
169
|
+
keepNames: true,
|
|
170
|
+
treeShaking: false, // Skip for speed in dev
|
|
171
|
+
define: {
|
|
172
|
+
'import.meta.env.DEV': 'true',
|
|
173
|
+
'import.meta.env.PROD': 'false',
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
const output = {
|
|
177
|
+
code: result.code,
|
|
178
|
+
map: result.map || '',
|
|
179
|
+
fromCache: false,
|
|
180
|
+
duration: performance.now() - startTime,
|
|
181
|
+
};
|
|
182
|
+
// Cache the result
|
|
183
|
+
jitCache.set(cacheKey, {
|
|
184
|
+
code: output.code,
|
|
185
|
+
map: output.map,
|
|
186
|
+
size: output.code.length + output.map.length,
|
|
187
|
+
});
|
|
188
|
+
return output;
|
|
47
189
|
}
|
|
48
|
-
|
|
49
|
-
|
|
190
|
+
catch (error) {
|
|
191
|
+
throw new Error(`JIT compile failed for ${filename}: ${error}`);
|
|
50
192
|
}
|
|
51
|
-
// Compile with esbuild (faster than SWC for single-file transforms)
|
|
52
|
-
const result = await esbuildTransform(source, {
|
|
53
|
-
loader,
|
|
54
|
-
target: opts.target,
|
|
55
|
-
format: 'esm',
|
|
56
|
-
platform: 'neutral',
|
|
57
|
-
jsx: opts.jsx === 'transform' ? 'automatic' : 'preserve',
|
|
58
|
-
jsxImportSource: opts.jsxImportSource,
|
|
59
|
-
sourcemap: opts.sourceMap ? 'inline' : false,
|
|
60
|
-
sourcesContent: false,
|
|
61
|
-
// Development optimizations
|
|
62
|
-
minifyWhitespace: false,
|
|
63
|
-
minifyIdentifiers: false,
|
|
64
|
-
minifySyntax: false,
|
|
65
|
-
// Keep names for debugging
|
|
66
|
-
keepNames: true,
|
|
67
|
-
// Fastest tree shaking
|
|
68
|
-
treeShaking: true,
|
|
69
|
-
// Preserve import.meta
|
|
70
|
-
define: {
|
|
71
|
-
'import.meta.env.DEV': 'true',
|
|
72
|
-
'import.meta.env.PROD': 'false',
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
const output = {
|
|
76
|
-
code: result.code,
|
|
77
|
-
map: result.map || '',
|
|
78
|
-
};
|
|
79
|
-
// Store in cache
|
|
80
|
-
moduleCache.set(cacheKey, {
|
|
81
|
-
code: output.code,
|
|
82
|
-
map: output.map,
|
|
83
|
-
timestamp: Date.now(),
|
|
84
|
-
dependencies: extractDependencies(source),
|
|
85
|
-
});
|
|
86
|
-
return output;
|
|
87
193
|
}
|
|
88
194
|
/**
|
|
89
|
-
*
|
|
195
|
+
* Batch compile multiple files
|
|
90
196
|
*/
|
|
91
|
-
function
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
197
|
+
export async function jitCompileBatch(files, options = {}) {
|
|
198
|
+
// Process in chunks to avoid overwhelming the event loop
|
|
199
|
+
const CONCURRENCY = 8;
|
|
200
|
+
const results = [];
|
|
201
|
+
for (let i = 0; i < files.length; i += CONCURRENCY) {
|
|
202
|
+
const chunk = files.slice(i, i + CONCURRENCY);
|
|
203
|
+
const chunkResults = await Promise.all(chunk.map(async ({ source, filename }) => {
|
|
204
|
+
const result = await jitCompile(source, filename, options);
|
|
205
|
+
return { ...result, filename };
|
|
206
|
+
}));
|
|
207
|
+
results.push(...chunkResults);
|
|
97
208
|
}
|
|
98
|
-
return
|
|
209
|
+
return results;
|
|
99
210
|
}
|
|
100
211
|
/**
|
|
101
|
-
* Invalidate cache
|
|
212
|
+
* Invalidate cache by filename
|
|
102
213
|
*/
|
|
103
214
|
export function invalidateCache(filename) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
215
|
+
return jitCache.invalidate(filename);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Invalidate cache by pattern
|
|
219
|
+
*/
|
|
220
|
+
export function invalidateCachePattern(pattern) {
|
|
221
|
+
return jitCache.invalidatePattern(pattern);
|
|
110
222
|
}
|
|
111
223
|
/**
|
|
112
224
|
* Clear all cache
|
|
113
225
|
*/
|
|
114
226
|
export function clearCache() {
|
|
115
|
-
|
|
116
|
-
fileTimestamps.clear();
|
|
227
|
+
jitCache.clear();
|
|
117
228
|
}
|
|
118
229
|
/**
|
|
119
230
|
* Get cache stats
|
|
120
231
|
*/
|
|
121
232
|
export function getCacheStats() {
|
|
122
|
-
return
|
|
123
|
-
size: moduleCache.size,
|
|
124
|
-
entries: moduleCache.size,
|
|
125
|
-
hitRate: 0, // Would need to track hits/misses
|
|
126
|
-
};
|
|
233
|
+
return jitCache.getStats();
|
|
127
234
|
}
|
|
128
235
|
/**
|
|
129
|
-
*
|
|
236
|
+
* Warmup cache with commonly used files
|
|
130
237
|
*/
|
|
131
238
|
export async function warmupCache(files, options) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
})
|
|
239
|
+
let compiled = 0;
|
|
240
|
+
let errors = 0;
|
|
241
|
+
await Promise.all(files.map(async ({ source, filename }) => {
|
|
242
|
+
try {
|
|
243
|
+
await jitCompile(source, filename, options);
|
|
244
|
+
compiled++;
|
|
245
|
+
}
|
|
246
|
+
catch {
|
|
247
|
+
errors++;
|
|
248
|
+
}
|
|
249
|
+
}));
|
|
250
|
+
return { compiled, errors };
|
|
135
251
|
}
|
|
136
|
-
// Export for
|
|
137
|
-
export {
|
|
252
|
+
// Export cache for advanced usage
|
|
253
|
+
export { jitCache };
|
|
138
254
|
//# sourceMappingURL=jit.js.map
|
package/dist/jit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jit.js","sourceRoot":"","sources":["../src/jit.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"jit.js","sourceRoot":"","sources":["../src/jit.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,IAAI,gBAAgB,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AA0BzC,4CAA4C;AAC5C,MAAM,QAAQ;IACJ,KAAK,GAAG,IAAI,GAAG,EAAyB,CAAC;IACzC,OAAO,CAAS;IAChB,UAAU,CAAS;IACnB,cAAc,CAAS;IACvB,KAAK,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;IAEvC,YAAY,UAAkF,EAAE;QAC9F,IAAI,CAAC,OAAO,GAAG,CAAC,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;QACvD,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,IAAI,CAAC;QAC7C,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,gBAAgB,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,QAAQ;IAC3E,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,OAAgB;QAC/B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAElC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,IAAI,CAAC,KAAK,CA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MAAM,UAAU,sBAAsB,CAAC,OAAe;IACpD,OAAO,QAAQ,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;AAC7C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU;IACxB,QAAQ,CAAC,KAAK,EAAE,CAAC;AACnB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,QAAQ,CAAC,QAAQ,EAAE,CAAC;AAC7B,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,KAAkD,EAClD,OAAoB;IAEpB,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,IAAI,MAAM,GAAG,CAAC,CAAC;IAEf,MAAM,OAAO,CAAC,GAAG,CACf,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE;QACvC,IAAI,CAAC;YACH,MAAM,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;YAC5C,QAAQ,EAAE,CAAC;QACb,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,EAAE,CAAC;QACX,CAAC;IACH,CAAC,CAAC,CACH,CAAC;IAEF,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAC9B,CAAC;AAED,kCAAkC;AAClC,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
package/package.json
CHANGED
package/dist/compile-worker.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compile-worker.d.ts","sourceRoot":"","sources":["../src/compile-worker.ts"],"names":[],"mappings":""}
|
package/dist/compile-worker.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
// Worker Thread for Parallel Compilation
|
|
2
|
-
import { parentPort } from 'worker_threads';
|
|
3
|
-
import { transform as esbuildTransform } from 'esbuild';
|
|
4
|
-
parentPort?.on('message', async (task) => {
|
|
5
|
-
const startTime = performance.now();
|
|
6
|
-
try {
|
|
7
|
-
const ext = task.filename.split('.').pop()?.toLowerCase();
|
|
8
|
-
let loader = 'ts';
|
|
9
|
-
if (ext === 'tsx')
|
|
10
|
-
loader = 'tsx';
|
|
11
|
-
else if (ext === 'jsx')
|
|
12
|
-
loader = 'jsx';
|
|
13
|
-
else if (ext === 'js')
|
|
14
|
-
loader = 'js';
|
|
15
|
-
const result = await esbuildTransform(task.source, {
|
|
16
|
-
loader,
|
|
17
|
-
target: task.options.target || 'es2022',
|
|
18
|
-
format: 'esm',
|
|
19
|
-
platform: 'neutral',
|
|
20
|
-
jsx: 'automatic',
|
|
21
|
-
jsxImportSource: 'zylaris',
|
|
22
|
-
sourcemap: task.options.sourceMap ? 'inline' : false,
|
|
23
|
-
sourcesContent: false,
|
|
24
|
-
minifyWhitespace: false,
|
|
25
|
-
minifyIdentifiers: false,
|
|
26
|
-
minifySyntax: false,
|
|
27
|
-
keepNames: true,
|
|
28
|
-
treeShaking: true,
|
|
29
|
-
});
|
|
30
|
-
const compileResult = {
|
|
31
|
-
id: task.id,
|
|
32
|
-
code: result.code,
|
|
33
|
-
map: result.map || '',
|
|
34
|
-
compileTime: performance.now() - startTime,
|
|
35
|
-
};
|
|
36
|
-
parentPort?.postMessage(compileResult);
|
|
37
|
-
}
|
|
38
|
-
catch (error) {
|
|
39
|
-
const errorResult = {
|
|
40
|
-
id: task.id,
|
|
41
|
-
code: '',
|
|
42
|
-
map: '',
|
|
43
|
-
error: error instanceof Error ? error.message : String(error),
|
|
44
|
-
compileTime: performance.now() - startTime,
|
|
45
|
-
};
|
|
46
|
-
parentPort?.postMessage(errorResult);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
//# sourceMappingURL=compile-worker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compile-worker.js","sourceRoot":"","sources":["../src/compile-worker.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;A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AE,GAAG,SAAS;SAC3C,CAAC;QAEF,UAAU,EAAE,WAAW,CAAC,aAAa,CAAC,CAAC;IACzC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,WAAW,GAAkB;YACjC,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,IAAI,EAAE,EAAE;YACR,GAAG,EAAE,EAAE;YACP,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;YAC7D,WAAW,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,SAAS;SAC3C,CAAC;QAEF,UAAU,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC;IACvC,CAAC;AACH,CAAC,CAAC,CAAC"}
|
package/dist/lazy-compile.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
interface LazyCompileOptions {
|
|
2
|
-
root: string;
|
|
3
|
-
entryPoints: string[];
|
|
4
|
-
onCompile: (filename: string, code: string) => void;
|
|
5
|
-
}
|
|
6
|
-
declare class ModuleGraph {
|
|
7
|
-
private modules;
|
|
8
|
-
private onCompile;
|
|
9
|
-
private compileQueue;
|
|
10
|
-
private processing;
|
|
11
|
-
constructor(options: LazyCompileOptions);
|
|
12
|
-
private addModule;
|
|
13
|
-
private generateId;
|
|
14
|
-
requestModule(filename: string): Promise<void>;
|
|
15
|
-
private processQueue;
|
|
16
|
-
private compileModule;
|
|
17
|
-
private extractDependencies;
|
|
18
|
-
private transformCode;
|
|
19
|
-
getCompilationOrder(): string[];
|
|
20
|
-
invalidate(filename: string): string[];
|
|
21
|
-
getStats(): {
|
|
22
|
-
total: number;
|
|
23
|
-
compiled: number;
|
|
24
|
-
pending: number;
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
export { ModuleGraph as LazyModuleGraph };
|
|
28
|
-
//# sourceMappingURL=lazy-compile.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lazy-compile.d.ts","sourceRoot":"","sources":["../src/lazy-compile.ts"],"names":[],"mappings":"AAMA,UAAU,kBAAkB;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACrD;AAaD,cAAM,WAAW;IACf,OAAO,CAAC,OAAO,CAAiC;IAChD,OAAO,CAAC,SAAS,CAA2C;IAC5D,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,UAAU,CAAS;gBAEf,OAAO,EAAE,kBAAkB;IASvC,OAAO,CAAC,SAAS;IAcjB,OAAO,CAAC,UAAU;IAKZ,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAatC,YAAY;YAWZ,aAAa;IAqC3B,OAAO,CAAC,mBAAmB;YA4Bb,aAAa;IAO3B,mBAAmB,IAAI,MAAM,EAAE;IAyB/B,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE;IAyBtC,QAAQ;;;;;CAeT;AAGD,OAAO,EAAE,WAAW,IAAI,eAAe,EAAE,CAAC"}
|
package/dist/lazy-compile.js
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
// Lazy Compilation - Only compile what's needed
|
|
2
|
-
// Speeds up initial dev server startup dramatically
|
|
3
|
-
import fs from 'fs/promises';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
// Module Graph for tracking dependencies
|
|
6
|
-
class ModuleGraph {
|
|
7
|
-
modules = new Map();
|
|
8
|
-
onCompile;
|
|
9
|
-
compileQueue = [];
|
|
10
|
-
processing = false;
|
|
11
|
-
constructor(options) {
|
|
12
|
-
this.onCompile = options.onCompile;
|
|
13
|
-
// Initialize entry points
|
|
14
|
-
for (const entry of options.entryPoints) {
|
|
15
|
-
this.addModule(entry);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
addModule(filename) {
|
|
19
|
-
if (!this.modules.has(filename)) {
|
|
20
|
-
this.modules.set(filename, {
|
|
21
|
-
id: this.generateId(filename),
|
|
22
|
-
filename,
|
|
23
|
-
dependencies: new Set(),
|
|
24
|
-
dependents: new Set(),
|
|
25
|
-
compiled: false,
|
|
26
|
-
compiling: false,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
return this.modules.get(filename);
|
|
30
|
-
}
|
|
31
|
-
generateId(filename) {
|
|
32
|
-
return Buffer.from(filename).toString('base64').replace(/[^a-zA-Z0-9]/g, '');
|
|
33
|
-
}
|
|
34
|
-
// Mark module as requested (lazy compile)
|
|
35
|
-
async requestModule(filename) {
|
|
36
|
-
const module = this.addModule(filename);
|
|
37
|
-
if (module.compiled || module.compiling)
|
|
38
|
-
return;
|
|
39
|
-
module.compiling = true;
|
|
40
|
-
this.compileQueue.push(filename);
|
|
41
|
-
if (!this.processing) {
|
|
42
|
-
this.processQueue();
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
async processQueue() {
|
|
46
|
-
this.processing = true;
|
|
47
|
-
while (this.compileQueue.length > 0) {
|
|
48
|
-
const filename = this.compileQueue.shift();
|
|
49
|
-
await this.compileModule(filename);
|
|
50
|
-
}
|
|
51
|
-
this.processing = false;
|
|
52
|
-
}
|
|
53
|
-
async compileModule(filename) {
|
|
54
|
-
const module = this.modules.get(filename);
|
|
55
|
-
if (!module || module.compiled)
|
|
56
|
-
return;
|
|
57
|
-
try {
|
|
58
|
-
// Read source
|
|
59
|
-
const source = await fs.readFile(filename, 'utf-8');
|
|
60
|
-
// Extract dependencies
|
|
61
|
-
const deps = this.extractDependencies(source, filename);
|
|
62
|
-
// Update dependency graph
|
|
63
|
-
for (const dep of deps) {
|
|
64
|
-
module.dependencies.add(dep);
|
|
65
|
-
const depModule = this.addModule(dep);
|
|
66
|
-
depModule.dependents.add(filename);
|
|
67
|
-
// Queue dependency for compilation
|
|
68
|
-
if (!depModule.compiled && !depModule.compiling) {
|
|
69
|
-
this.compileQueue.push(dep);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
// Compile (in real implementation, use JIT compiler)
|
|
73
|
-
const code = await this.transformCode(source, filename);
|
|
74
|
-
module.compiled = true;
|
|
75
|
-
module.compiling = false;
|
|
76
|
-
// Notify
|
|
77
|
-
this.onCompile(filename, code);
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
module.error = String(error);
|
|
81
|
-
module.compiling = false;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
extractDependencies(source, filename) {
|
|
85
|
-
const deps = [];
|
|
86
|
-
const basedir = path.dirname(filename);
|
|
87
|
-
// Match ES6 imports
|
|
88
|
-
const importRegex = /import\s+(?:{[^}]*}|[^'"]*)\s*from\s*['"]([^'"]+)['"]|import\s*['"]([^'"]+)['"]/g;
|
|
89
|
-
let match;
|
|
90
|
-
while ((match = importRegex.exec(source)) !== null) {
|
|
91
|
-
const importPath = match[1] || match[2];
|
|
92
|
-
// Resolve relative paths
|
|
93
|
-
if (importPath.startsWith('.')) {
|
|
94
|
-
const resolved = path.resolve(basedir, importPath);
|
|
95
|
-
// Try extensions
|
|
96
|
-
const extensions = ['.tsx', '.ts', '.jsx', '.js'];
|
|
97
|
-
for (const ext of extensions) {
|
|
98
|
-
const fullPath = resolved + ext;
|
|
99
|
-
deps.push(fullPath);
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return deps;
|
|
105
|
-
}
|
|
106
|
-
async transformCode(source, filename) {
|
|
107
|
-
// In real implementation, call JIT compiler here
|
|
108
|
-
// For now, return a placeholder
|
|
109
|
-
return `/* compiled: ${filename} */\n${source}`;
|
|
110
|
-
}
|
|
111
|
-
// Get compilation order (for pre-compilation)
|
|
112
|
-
getCompilationOrder() {
|
|
113
|
-
const visited = new Set();
|
|
114
|
-
const order = [];
|
|
115
|
-
const visit = (filename) => {
|
|
116
|
-
if (visited.has(filename))
|
|
117
|
-
return;
|
|
118
|
-
visited.add(filename);
|
|
119
|
-
const module = this.modules.get(filename);
|
|
120
|
-
if (module) {
|
|
121
|
-
for (const dep of module.dependencies) {
|
|
122
|
-
visit(dep);
|
|
123
|
-
}
|
|
124
|
-
order.push(filename);
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
for (const [filename] of this.modules) {
|
|
128
|
-
visit(filename);
|
|
129
|
-
}
|
|
130
|
-
return order;
|
|
131
|
-
}
|
|
132
|
-
// Invalidate module and dependents
|
|
133
|
-
invalidate(filename) {
|
|
134
|
-
const module = this.modules.get(filename);
|
|
135
|
-
if (!module)
|
|
136
|
-
return [];
|
|
137
|
-
const toInvalidate = new Set();
|
|
138
|
-
const queue = [filename];
|
|
139
|
-
while (queue.length > 0) {
|
|
140
|
-
const current = queue.shift();
|
|
141
|
-
const mod = this.modules.get(current);
|
|
142
|
-
if (mod && !toInvalidate.has(current)) {
|
|
143
|
-
toInvalidate.add(current);
|
|
144
|
-
mod.compiled = false;
|
|
145
|
-
// Add dependents
|
|
146
|
-
for (const dep of mod.dependents) {
|
|
147
|
-
queue.push(dep);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
return Array.from(toInvalidate);
|
|
152
|
-
}
|
|
153
|
-
getStats() {
|
|
154
|
-
let compiled = 0;
|
|
155
|
-
let pending = 0;
|
|
156
|
-
for (const mod of this.modules.values()) {
|
|
157
|
-
if (mod.compiled)
|
|
158
|
-
compiled++;
|
|
159
|
-
if (mod.compiling)
|
|
160
|
-
pending++;
|
|
161
|
-
}
|
|
162
|
-
return {
|
|
163
|
-
total: this.modules.size,
|
|
164
|
-
compiled,
|
|
165
|
-
pending,
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
// Export for use in dev server
|
|
170
|
-
export { ModuleGraph as LazyModuleGraph };
|
|
171
|
-
//# sourceMappingURL=lazy-compile.js.map
|