versacompiler 2.0.7 → 2.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/compiler/compile.js +26 -2332
  2. package/dist/compiler/error-reporter.js +38 -467
  3. package/dist/compiler/linter.js +1 -72
  4. package/dist/compiler/minify.js +1 -229
  5. package/dist/compiler/module-resolution-optimizer.js +1 -821
  6. package/dist/compiler/parser.js +1 -203
  7. package/dist/compiler/performance-monitor.js +56 -192
  8. package/dist/compiler/tailwindcss.js +1 -39
  9. package/dist/compiler/transform-optimizer.js +1 -392
  10. package/dist/compiler/transformTStoJS.js +1 -16
  11. package/dist/compiler/transforms.js +1 -550
  12. package/dist/compiler/typescript-compiler.js +2 -172
  13. package/dist/compiler/typescript-error-parser.js +10 -281
  14. package/dist/compiler/typescript-manager.js +2 -273
  15. package/dist/compiler/typescript-sync-validator.js +31 -295
  16. package/dist/compiler/typescript-worker-pool.js +1 -842
  17. package/dist/compiler/typescript-worker-thread.cjs +41 -466
  18. package/dist/compiler/typescript-worker.js +1 -339
  19. package/dist/compiler/vuejs.js +37 -392
  20. package/dist/hrm/VueHRM.js +1 -353
  21. package/dist/hrm/errorScreen.js +1 -83
  22. package/dist/hrm/getInstanciaVue.js +1 -313
  23. package/dist/hrm/initHRM.js +1 -141
  24. package/dist/main.js +7 -347
  25. package/dist/servicios/browserSync.js +5 -501
  26. package/dist/servicios/file-watcher.js +4 -379
  27. package/dist/servicios/logger.js +3 -63
  28. package/dist/servicios/readConfig.js +105 -430
  29. package/dist/utils/excluded-modules.js +1 -36
  30. package/dist/utils/module-resolver.js +1 -466
  31. package/dist/utils/promptUser.js +2 -48
  32. package/dist/utils/proxyValidator.js +1 -68
  33. package/dist/utils/resolve-bin.js +1 -48
  34. package/dist/utils/utils.js +1 -21
  35. package/dist/utils/vue-types-setup.js +241 -435
  36. package/dist/wrappers/eslint-node.js +1 -145
  37. package/dist/wrappers/oxlint-node.js +1 -120
  38. package/dist/wrappers/tailwind-node.js +1 -92
  39. package/package.json +36 -35
@@ -1,229 +1 @@
1
- import { createHash } from 'node:crypto';
2
- import { minify } from 'oxc-minify';
3
- class MinificationCache {
4
- static instance;
5
- cache = new Map();
6
- MAX_CACHE_SIZE = 100; // Máximo archivos minificados en cache
7
- MAX_CACHE_MEMORY = 20 * 1024 * 1024; // 20MB límite
8
- CACHE_TTL = 30 * 60 * 1000; // 30 minutos
9
- currentMemoryUsage = 0;
10
- // Métricas
11
- cacheHits = 0;
12
- cacheMisses = 0;
13
- totalMinifications = 0;
14
- totalOriginalSize = 0;
15
- totalMinifiedSize = 0;
16
- static getInstance() {
17
- if (!MinificationCache.instance) {
18
- MinificationCache.instance = new MinificationCache();
19
- }
20
- return MinificationCache.instance;
21
- }
22
- /**
23
- * Genera un hash del contenido y opciones de minificación
24
- */
25
- generateCacheKey(data, options) {
26
- const content = `${data}||${JSON.stringify(options)}`;
27
- return createHash('sha256').update(content).digest('hex');
28
- }
29
- /**
30
- * Obtiene resultado de minificación desde cache o lo genera
31
- */
32
- async getOrMinify(data, filename, options) {
33
- this.totalMinifications++;
34
- const cacheKey = this.generateCacheKey(data, options);
35
- // Verificar cache
36
- const cached = this.cache.get(cacheKey);
37
- if (cached && Date.now() - cached.timestamp < this.CACHE_TTL) {
38
- // Actualizar timestamp de uso (LRU)
39
- cached.timestamp = Date.now();
40
- this.cacheHits++;
41
- return {
42
- code: cached.minifiedCode,
43
- error: null,
44
- cached: true,
45
- };
46
- }
47
- // Cache miss - minificar código
48
- this.cacheMisses++;
49
- const originalSize = data.length;
50
- try {
51
- const result = await minify(filename, data, options);
52
- // Si el código de entrada no estaba vacío pero el resultado sí,
53
- // probablemente hay un error de sintaxis
54
- if (data.trim() && !result.code.trim()) {
55
- const error = new Error(`Minification failed: likely syntax error in ${filename}`);
56
- return { code: '', error, cached: false };
57
- }
58
- const minifiedSize = result.code.length;
59
- // Cachear resultado exitoso
60
- this.addToCache(cacheKey, {
61
- contentHash: cacheKey,
62
- options,
63
- minifiedCode: result.code,
64
- timestamp: Date.now(),
65
- originalSize,
66
- minifiedSize,
67
- });
68
- // Actualizar métricas globales
69
- this.totalOriginalSize += originalSize;
70
- this.totalMinifiedSize += minifiedSize;
71
- return {
72
- code: result.code,
73
- error: null,
74
- cached: false,
75
- };
76
- }
77
- catch (error) {
78
- return {
79
- error: error instanceof Error ? error : new Error(String(error)),
80
- code: '',
81
- cached: false,
82
- };
83
- }
84
- }
85
- /**
86
- * Añade resultado al cache con gestión de memoria
87
- */
88
- addToCache(cacheKey, entry) {
89
- try {
90
- const entrySize = entry.originalSize + entry.minifiedSize;
91
- // Aplicar políticas de eviction si es necesario
92
- this.evictIfNeeded(entrySize);
93
- this.cache.set(cacheKey, entry);
94
- this.currentMemoryUsage += entrySize;
95
- }
96
- catch (error) {
97
- console.warn('[MinificationCache] Error cacheando minificación:', error);
98
- }
99
- }
100
- /**
101
- * Aplica políticas de eviction LRU si es necesario
102
- */
103
- evictIfNeeded(newEntrySize) {
104
- // Verificar límite de entradas
105
- while (this.cache.size >= this.MAX_CACHE_SIZE) {
106
- this.evictLRU();
107
- }
108
- // Verificar límite de memoria
109
- while (this.currentMemoryUsage + newEntrySize > this.MAX_CACHE_MEMORY &&
110
- this.cache.size > 0) {
111
- this.evictLRU();
112
- }
113
- }
114
- /**
115
- * Elimina la entrada menos recientemente usada
116
- */
117
- evictLRU() {
118
- let oldestKey = '';
119
- let oldestTime = Infinity;
120
- for (const [key, entry] of this.cache) {
121
- if (entry.timestamp < oldestTime) {
122
- oldestTime = entry.timestamp;
123
- oldestKey = key;
124
- }
125
- }
126
- if (oldestKey) {
127
- const entry = this.cache.get(oldestKey);
128
- if (entry) {
129
- this.currentMemoryUsage -=
130
- entry.originalSize + entry.minifiedSize;
131
- this.cache.delete(oldestKey);
132
- }
133
- }
134
- }
135
- /**
136
- * Limpia entradas expiradas
137
- */
138
- cleanExpired() {
139
- const now = Date.now();
140
- for (const [key, entry] of this.cache.entries()) {
141
- if (now - entry.timestamp > this.CACHE_TTL) {
142
- this.currentMemoryUsage -=
143
- entry.originalSize + entry.minifiedSize;
144
- this.cache.delete(key);
145
- }
146
- }
147
- }
148
- /**
149
- * Obtiene estadísticas del cache
150
- */
151
- getStats() {
152
- const hitRate = this.totalMinifications > 0
153
- ? Math.round((this.cacheHits / this.totalMinifications) * 100)
154
- : 0;
155
- const avgCompressionRatio = this.totalOriginalSize > 0
156
- ? Math.round(((this.totalOriginalSize - this.totalMinifiedSize) /
157
- this.totalOriginalSize) *
158
- 100)
159
- : 0;
160
- return {
161
- cacheHits: this.cacheHits,
162
- cacheMisses: this.cacheMisses,
163
- hitRate,
164
- totalMinifications: this.totalMinifications,
165
- cacheSize: this.cache.size,
166
- maxCacheSize: this.MAX_CACHE_SIZE,
167
- memoryUsage: this.currentMemoryUsage,
168
- maxMemoryUsage: this.MAX_CACHE_MEMORY,
169
- totalOriginalSize: this.totalOriginalSize,
170
- totalMinifiedSize: this.totalMinifiedSize,
171
- avgCompressionRatio,
172
- };
173
- }
174
- /**
175
- * Limpia todo el cache
176
- */
177
- clear() {
178
- this.cache.clear();
179
- this.currentMemoryUsage = 0;
180
- this.cacheHits = 0;
181
- this.cacheMisses = 0;
182
- this.totalMinifications = 0;
183
- this.totalOriginalSize = 0;
184
- this.totalMinifiedSize = 0;
185
- }
186
- }
187
- // Instancia global del cache de minificación
188
- const minificationCache = MinificationCache.getInstance();
189
- /**
190
- * Minifica el codigo JavaScript usando opciones especificas.
191
- *
192
- * @param {string} data - The JavaScript code to be minified.
193
- * @param {string} filename - The name of the file containing the JavaScript code.
194
- * @param {boolean} isProd - Indica si está en modo producción.
195
- * @returns {Promise<Object>} The result of the minification process.
196
- */
197
- export const minifyJS = async (data, filename, isProd = true) => {
198
- try {
199
- const options = {
200
- compress: {
201
- target: 'es2020',
202
- },
203
- mangle: {
204
- toplevel: true,
205
- debug: !isProd,
206
- },
207
- codegen: {
208
- removeWhitespace: true,
209
- },
210
- sourcemap: !isProd,
211
- };
212
- const result = await minificationCache.getOrMinify(data, filename, options);
213
- return { code: result.code, error: result.error };
214
- }
215
- catch (error) {
216
- return { error, code: '' };
217
- }
218
- };
219
- // ✨ NUEVAS FUNCIONES: Exportar funcionalidades del cache de minificación para uso externo
220
- export const getMinificationCacheStats = () => {
221
- return minificationCache.getStats();
222
- };
223
- export const clearMinificationCache = () => {
224
- minificationCache.clear();
225
- };
226
- export const cleanExpiredMinificationCache = () => {
227
- minificationCache.cleanExpired();
228
- };
229
- //# sourceMappingURL=minify.js.map
1
+ import{createHash as e}from"node:crypto";import{minify as t}from"oxc-minify";class n{static instance;cache=new Map;MAX_CACHE_SIZE=100;MAX_CACHE_MEMORY=20*1024*1024;CACHE_TTL=1800*1e3;currentMemoryUsage=0;cacheHits=0;cacheMisses=0;totalMinifications=0;totalOriginalSize=0;totalMinifiedSize=0;static getInstance(){return n.instance||=new n,n.instance}generateCacheKey(t,n){let r=`${t}||${JSON.stringify(n)}`;return e(`sha256`).update(r).digest(`hex`)}async getOrMinify(e,n,r){this.totalMinifications++;let i=this.generateCacheKey(e,r),a=this.cache.get(i);if(a&&Date.now()-a.timestamp<this.CACHE_TTL)return a.timestamp=Date.now(),this.cacheHits++,{code:a.minifiedCode,error:null,cached:!0};this.cacheMisses++;let o=e.length;try{let a=await t(n,e,r);if(e.trim()&&!a.code.trim()){let e=Error(`Minification failed: likely syntax error in ${n}`);return{code:``,error:e,cached:!1}}let s=a.code.length;return this.addToCache(i,{contentHash:i,options:r,minifiedCode:a.code,timestamp:Date.now(),originalSize:o,minifiedSize:s}),this.totalOriginalSize+=o,this.totalMinifiedSize+=s,{code:a.code,error:null,cached:!1}}catch(e){return{error:e instanceof Error?e:Error(String(e)),code:``,cached:!1}}}addToCache(e,t){try{let n=t.originalSize+t.minifiedSize;this.evictIfNeeded(n),this.cache.set(e,t),this.currentMemoryUsage+=n}catch(e){console.warn(`[MinificationCache] Error cacheando minificación:`,e)}}evictIfNeeded(e){for(;this.cache.size>=this.MAX_CACHE_SIZE;)this.evictLRU();for(;this.currentMemoryUsage+e>this.MAX_CACHE_MEMORY&&this.cache.size>0;)this.evictLRU()}evictLRU(){let e=``,t=1/0;for(let[n,r]of this.cache)r.timestamp<t&&(t=r.timestamp,e=n);if(e){let t=this.cache.get(e);t&&(this.currentMemoryUsage-=t.originalSize+t.minifiedSize,this.cache.delete(e))}}cleanExpired(){let e=Date.now();for(let[t,n]of this.cache.entries())e-n.timestamp>this.CACHE_TTL&&(this.currentMemoryUsage-=n.originalSize+n.minifiedSize,this.cache.delete(t))}getStats(){let e=this.totalMinifications>0?Math.round(this.cacheHits/this.totalMinifications*100):0,t=this.totalOriginalSize>0?Math.round((this.totalOriginalSize-this.totalMinifiedSize)/this.totalOriginalSize*100):0;return{cacheHits:this.cacheHits,cacheMisses:this.cacheMisses,hitRate:e,totalMinifications:this.totalMinifications,cacheSize:this.cache.size,maxCacheSize:this.MAX_CACHE_SIZE,memoryUsage:this.currentMemoryUsage,maxMemoryUsage:this.MAX_CACHE_MEMORY,totalOriginalSize:this.totalOriginalSize,totalMinifiedSize:this.totalMinifiedSize,avgCompressionRatio:t}}clear(){this.cache.clear(),this.currentMemoryUsage=0,this.cacheHits=0,this.cacheMisses=0,this.totalMinifications=0,this.totalOriginalSize=0,this.totalMinifiedSize=0}}const r=n.getInstance();export const minifyJS=async(e,t,n=!0)=>{try{let i={compress:{target:`es2020`},mangle:{toplevel:!0,debug:!n},codegen:{removeWhitespace:!0},sourcemap:!n},a=await r.getOrMinify(e,t,i);return{code:a.code,error:a.error}}catch(e){return{error:e,code:``}}};export const getMinificationCacheStats=()=>r.getStats();export const clearMinificationCache=()=>{r.clear()};export const cleanExpiredMinificationCache=()=>{r.cleanExpired()};