versacompiler 2.0.7 → 2.1.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.
Files changed (40) hide show
  1. package/dist/compiler/compile.js +25 -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/minifyTemplate.js +1 -0
  6. package/dist/compiler/module-resolution-optimizer.js +1 -821
  7. package/dist/compiler/parser.js +1 -203
  8. package/dist/compiler/performance-monitor.js +56 -192
  9. package/dist/compiler/tailwindcss.js +1 -39
  10. package/dist/compiler/transform-optimizer.js +1 -392
  11. package/dist/compiler/transformTStoJS.js +1 -16
  12. package/dist/compiler/transforms.js +1 -550
  13. package/dist/compiler/typescript-compiler.js +2 -172
  14. package/dist/compiler/typescript-error-parser.js +10 -281
  15. package/dist/compiler/typescript-manager.js +2 -273
  16. package/dist/compiler/typescript-sync-validator.js +31 -295
  17. package/dist/compiler/typescript-worker-pool.js +1 -842
  18. package/dist/compiler/typescript-worker-thread.cjs +22 -466
  19. package/dist/compiler/typescript-worker.js +1 -339
  20. package/dist/compiler/vuejs.js +37 -392
  21. package/dist/hrm/VueHRM.js +1 -353
  22. package/dist/hrm/errorScreen.js +1 -83
  23. package/dist/hrm/getInstanciaVue.js +1 -313
  24. package/dist/hrm/initHRM.js +1 -141
  25. package/dist/main.js +7 -347
  26. package/dist/servicios/browserSync.js +2 -503
  27. package/dist/servicios/file-watcher.js +4 -379
  28. package/dist/servicios/logger.js +3 -63
  29. package/dist/servicios/readConfig.js +53 -430
  30. package/dist/utils/excluded-modules.js +1 -36
  31. package/dist/utils/module-resolver.js +1 -466
  32. package/dist/utils/promptUser.js +2 -48
  33. package/dist/utils/proxyValidator.js +1 -68
  34. package/dist/utils/resolve-bin.js +1 -48
  35. package/dist/utils/utils.js +1 -21
  36. package/dist/utils/vue-types-setup.js +241 -435
  37. package/dist/wrappers/eslint-node.js +3 -1
  38. package/dist/wrappers/oxlint-node.js +1 -120
  39. package/dist/wrappers/tailwind-node.js +1 -92
  40. package/package.json +103 -108
@@ -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 i}from"oxc-minify";import{minifyTemplate as a}from"./minifyTemplate.js";import{removehtmlOfTemplateString as o}from"./transforms.js";class s{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 s.instance||(s.instance=new s),s.instance}generateCacheKey(i,a){let o=`${i}||${JSON.stringify(a)}`;return e(`sha256`).update(o).digest(`hex`)}async getOrMinify(e,a,o){this.totalMinifications++;let s=this.generateCacheKey(e,o),c=this.cache.get(s);if(c&&Date.now()-c.timestamp<this.CACHE_TTL)return c.timestamp=Date.now(),this.cacheHits++,{code:c.minifiedCode,error:null,cached:!0};this.cacheMisses++;let l=e.length;try{let c=await i(a,e,o);if(e.trim()&&!c.code.trim())return{code:``,error:Error(`Minification failed: likely syntax error in ${a}`),cached:!1};let u=c.code.length;return this.addToCache(s,{contentHash:s,options:o,minifiedCode:c.code,timestamp:Date.now(),originalSize:l,minifiedSize:u}),this.totalOriginalSize+=l,this.totalMinifiedSize+=u,{code:c.code,error:null,cached:!1}}catch(e){return{error:e instanceof Error?e:Error(String(e)),code:``,cached:!1}}}addToCache(e,i){try{let a=i.originalSize+i.minifiedSize;this.evictIfNeeded(a),this.cache.set(e,i),this.currentMemoryUsage+=a}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=``,i=1/0;for(let[a,o]of this.cache)o.timestamp<i&&(i=o.timestamp,e=a);if(e){let i=this.cache.get(e);i&&(this.currentMemoryUsage-=i.originalSize+i.minifiedSize,this.cache.delete(e))}}cleanExpired(){let e=Date.now();for(let[i,a]of this.cache.entries())e-a.timestamp>this.CACHE_TTL&&(this.currentMemoryUsage-=a.originalSize+a.minifiedSize,this.cache.delete(i))}getStats(){let e=this.totalMinifications>0?Math.round(this.cacheHits/this.totalMinifications*100):0,i=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:i}}clear(){this.cache.clear(),this.currentMemoryUsage=0,this.cacheHits=0,this.cacheMisses=0,this.totalMinifications=0,this.totalOriginalSize=0,this.totalMinifiedSize=0}}const c=s.getInstance();export const minifyJS=async(e,i,a=!0)=>{try{let o={compress:{target:`es2020`},mangle:{toplevel:!0,debug:!a},codegen:{removeWhitespace:!0},sourcemap:!a},s=await c.getOrMinify(e,i,o);return{code:s.code,error:s.error}}catch(e){return{error:e,code:``}}};export const getMinificationCacheStats=()=>c.getStats();export const clearMinificationCache=()=>{c.clear()};export const cleanExpiredMinificationCache=()=>{c.cleanExpired()};export const minifyWithTemplates=async(e,i,s=!0)=>{try{let c=a(e,i);if(c.error&&!c.code){let e=c.error instanceof Error?c.error.message:String(c.error);return{code:``,error:Error(`Template minification failed: ${e}`)}}let u=await minifyJS(c.code,i,s);return u.code=await o(u.code),u}catch(e){return{error:e instanceof Error?e:Error(String(e)),code:``}}};
@@ -0,0 +1 @@
1
+ import{minifyHTMLLiterals as e}from"/node_modules/minify-html-literals/index.js";const t={caseSensitive:!0,keepClosingSlash:!0,collapseWhitespace:!0,removeComments:!0,minifyCSS:!0,minifyJS:!0,conservativeCollapse:!1,preserveLineBreaks:!1,removeAttributeQuotes:!1,removeEmptyAttributes:!1,removeRedundantAttributes:!1,removeScriptTypeAttributes:!0,removeStyleLinkTypeAttributes:!0,useShortDoctype:!0},n=e=>{try{return e.replace(/=`([^`]+)`/g,(e,t)=>t.includes(`{`)&&t.includes(`}`)?`=html\`${t.replace(/\/\*[\s\S]*?\*\//g,``).replace(/\s+/g,` `).replace(/\s*{\s*/g,`{`).replace(/\s*}\s*/g,`}`).replace(/\s*:\s*/g,`:`).replace(/\s*;\s*/g,`;`).replace(/;\s*}/g,`}`).replace(/,\s*/g,`,`).trim()}\``:e)}catch(t){return console.warn(`[MinifyTemplate] Error minificando CSS:`,t),e}},r=(r,i)=>{try{let a=n(r);return{code:e(a,{fileName:i,...t})?.code||a,error:null}}catch(e){return console.warn(`[MinifyTemplate] Error minificando plantilla ${i}:`,e),{code:r,error:e}}};export{t as defaultMinifyOptions,r as minifyTemplate};