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.
- package/dist/compiler/compile.js +26 -2332
- package/dist/compiler/error-reporter.js +38 -467
- package/dist/compiler/linter.js +1 -72
- package/dist/compiler/minify.js +1 -229
- package/dist/compiler/module-resolution-optimizer.js +1 -821
- package/dist/compiler/parser.js +1 -203
- package/dist/compiler/performance-monitor.js +56 -192
- package/dist/compiler/tailwindcss.js +1 -39
- package/dist/compiler/transform-optimizer.js +1 -392
- package/dist/compiler/transformTStoJS.js +1 -16
- package/dist/compiler/transforms.js +1 -550
- package/dist/compiler/typescript-compiler.js +2 -172
- package/dist/compiler/typescript-error-parser.js +10 -281
- package/dist/compiler/typescript-manager.js +2 -273
- package/dist/compiler/typescript-sync-validator.js +31 -295
- package/dist/compiler/typescript-worker-pool.js +1 -842
- package/dist/compiler/typescript-worker-thread.cjs +41 -466
- package/dist/compiler/typescript-worker.js +1 -339
- package/dist/compiler/vuejs.js +37 -392
- package/dist/hrm/VueHRM.js +1 -353
- package/dist/hrm/errorScreen.js +1 -83
- package/dist/hrm/getInstanciaVue.js +1 -313
- package/dist/hrm/initHRM.js +1 -141
- package/dist/main.js +7 -347
- package/dist/servicios/browserSync.js +5 -501
- package/dist/servicios/file-watcher.js +4 -379
- package/dist/servicios/logger.js +3 -63
- package/dist/servicios/readConfig.js +105 -430
- package/dist/utils/excluded-modules.js +1 -36
- package/dist/utils/module-resolver.js +1 -466
- package/dist/utils/promptUser.js +2 -48
- package/dist/utils/proxyValidator.js +1 -68
- package/dist/utils/resolve-bin.js +1 -48
- package/dist/utils/utils.js +1 -21
- package/dist/utils/vue-types-setup.js +241 -435
- package/dist/wrappers/eslint-node.js +1 -145
- package/dist/wrappers/oxlint-node.js +1 -120
- package/dist/wrappers/tailwind-node.js +1 -92
- package/package.json +36 -35
package/dist/compiler/vuejs.js
CHANGED
|
@@ -1,392 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
const cacheKey = `${fileName}:${contentHash}`;
|
|
39
|
-
// Verificar cache
|
|
40
|
-
const cached = this.cache.get(cacheKey);
|
|
41
|
-
if (cached && Date.now() - cached.timestamp < this.CACHE_TTL) {
|
|
42
|
-
return {
|
|
43
|
-
injectedData: cached.injectedCode,
|
|
44
|
-
cached: true,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
// Generar nueva inyección HMR
|
|
48
|
-
const vueImportPattern = /import\s*\{[^}]*\bref\b[^}]*\}\s*from\s*['"]vue['"]/;
|
|
49
|
-
const hasRefImport = vueImportPattern.test(originalData);
|
|
50
|
-
const varContent = `
|
|
51
|
-
${hasRefImport ? '' : 'import { ref } from "/node_modules/vue/dist/vue.esm-browser.js";'}
|
|
52
|
-
const versaComponentKey = ref(0);
|
|
53
|
-
`;
|
|
54
|
-
let injectedData;
|
|
55
|
-
const ifExistScript = originalData.includes('<script');
|
|
56
|
-
if (!ifExistScript) {
|
|
57
|
-
injectedData =
|
|
58
|
-
`<script setup lang="ts">${varContent}</script>/n` +
|
|
59
|
-
originalData;
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
injectedData = originalData.replace(/(<script.*?>)/, `$1${varContent}`);
|
|
63
|
-
}
|
|
64
|
-
// Inyectar :key en el template
|
|
65
|
-
injectedData = injectedData.replace(/(<template[^>]*>[\s\S]*?)(<(\w+)([^>]*?))(\/?>)/, (match, p1, p2, p3, p4, p5) => {
|
|
66
|
-
if (p4.includes(':key=') || p4.includes('key=')) {
|
|
67
|
-
return match;
|
|
68
|
-
}
|
|
69
|
-
const isSelfClosing = p5 === '/>';
|
|
70
|
-
if (isSelfClosing) {
|
|
71
|
-
return `${p1}<${p3}${p4} :key="versaComponentKey" />`;
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
return `${p1}<${p3}${p4} :key="versaComponentKey">`;
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
// Cachear resultado
|
|
78
|
-
this.cache.set(cacheKey, {
|
|
79
|
-
contentHash,
|
|
80
|
-
injectedCode: injectedData,
|
|
81
|
-
hasRefImport,
|
|
82
|
-
timestamp: Date.now(),
|
|
83
|
-
});
|
|
84
|
-
// Limpiar cache si es necesario
|
|
85
|
-
this.evictIfNeeded();
|
|
86
|
-
return {
|
|
87
|
-
injectedData,
|
|
88
|
-
cached: false,
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Limpia entradas de cache cuando se excede el límite
|
|
93
|
-
*/
|
|
94
|
-
evictIfNeeded() {
|
|
95
|
-
if (this.cache.size <= this.MAX_CACHE_SIZE)
|
|
96
|
-
return;
|
|
97
|
-
const entries = Array.from(this.cache.entries());
|
|
98
|
-
entries.sort((a, b) => a[1].timestamp - b[1].timestamp);
|
|
99
|
-
// Eliminar las entradas más antiguas
|
|
100
|
-
const toDelete = entries.slice(0, entries.length - this.MAX_CACHE_SIZE);
|
|
101
|
-
toDelete.forEach(([key]) => this.cache.delete(key));
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Limpia entradas expiradas
|
|
105
|
-
*/
|
|
106
|
-
cleanExpired() {
|
|
107
|
-
const now = Date.now();
|
|
108
|
-
for (const [key, entry] of this.cache.entries()) {
|
|
109
|
-
if (now - entry.timestamp > this.CACHE_TTL) {
|
|
110
|
-
this.cache.delete(key);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Obtiene estadísticas del cache
|
|
116
|
-
*/
|
|
117
|
-
getStats() {
|
|
118
|
-
return {
|
|
119
|
-
size: this.cache.size,
|
|
120
|
-
maxSize: this.MAX_CACHE_SIZE,
|
|
121
|
-
ttl: this.CACHE_TTL,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Limpia todo el cache
|
|
126
|
-
*/
|
|
127
|
-
clear() {
|
|
128
|
-
this.cache.clear();
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
// Instancia global del cache HMR
|
|
132
|
-
const hmrInjectionCache = VueHMRInjectionCache.getInstance();
|
|
133
|
-
const getComponentsVueMap = async (ast) => {
|
|
134
|
-
let components = [];
|
|
135
|
-
const importsStatic = ast?.module?.staticImports;
|
|
136
|
-
if (importsStatic) {
|
|
137
|
-
const vueImports = importsStatic.filter((item) => item.moduleRequest.value.endsWith('.vue'));
|
|
138
|
-
components = vueImports.map((item) => {
|
|
139
|
-
return item.entries.map((entry) => entry.localName.value);
|
|
140
|
-
});
|
|
141
|
-
components = components.flat();
|
|
142
|
-
}
|
|
143
|
-
return components;
|
|
144
|
-
};
|
|
145
|
-
/**
|
|
146
|
-
* Precompila un componente Vue.
|
|
147
|
-
* @param {string} data - El código del componente Vue.
|
|
148
|
-
* @param {string} source - La fuente del componente Vue.
|
|
149
|
-
* @returns {Promise<Object>} - Un objeto con el código precompilado o un error.
|
|
150
|
-
*/
|
|
151
|
-
export const preCompileVue = async (data, source, isProd = false) => {
|
|
152
|
-
try {
|
|
153
|
-
const fileName = path.basename(source).replace('.vue', '');
|
|
154
|
-
if (!data || data.trim().length === 0) {
|
|
155
|
-
return {
|
|
156
|
-
error: null,
|
|
157
|
-
data: 'export default {};',
|
|
158
|
-
lang: 'js',
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
if (!isProd) {
|
|
162
|
-
const { injectedData } = hmrInjectionCache.getOrGenerateHMRInjection(data, fileName);
|
|
163
|
-
data = injectedData;
|
|
164
|
-
}
|
|
165
|
-
const { descriptor, errors } = vueCompiler.parse(data, {
|
|
166
|
-
filename: fileName,
|
|
167
|
-
sourceMap: !isProd,
|
|
168
|
-
sourceRoot: path.dirname(source),
|
|
169
|
-
});
|
|
170
|
-
if (errors.length) {
|
|
171
|
-
throw new Error(`Error al analizar el componente Vue ${source}:\n${errors.map((e) => e.message).join('\n')}`);
|
|
172
|
-
}
|
|
173
|
-
const id = Math.random().toString(36).slice(2, 12);
|
|
174
|
-
const scopeId = descriptor.styles.some((s) => s.scoped)
|
|
175
|
-
? `data-v-${id}`
|
|
176
|
-
: null;
|
|
177
|
-
// --- 1. Compilación del Script ---
|
|
178
|
-
let scriptContent;
|
|
179
|
-
let scriptLang = 'js';
|
|
180
|
-
let scriptBindings;
|
|
181
|
-
let scriptType;
|
|
182
|
-
if (descriptor.script || descriptor.scriptSetup) {
|
|
183
|
-
scriptType = descriptor.script ? 'script' : 'scriptSetup';
|
|
184
|
-
const scriptToCompile = descriptor.script || descriptor.scriptSetup;
|
|
185
|
-
const scriptCompileOptions = {
|
|
186
|
-
id,
|
|
187
|
-
isProd,
|
|
188
|
-
sourceMap: !isProd,
|
|
189
|
-
inlineTemplate: false, // Siempre compilar por separado para tener control
|
|
190
|
-
propsDestructure: true,
|
|
191
|
-
templateOptions: {
|
|
192
|
-
compilerOptions: {
|
|
193
|
-
mode: 'module',
|
|
194
|
-
scopeId,
|
|
195
|
-
prefixIdentifiers: true,
|
|
196
|
-
hoistStatic: isProd,
|
|
197
|
-
cacheHandlers: isProd,
|
|
198
|
-
nodeTransforms: [],
|
|
199
|
-
directiveTransforms: {},
|
|
200
|
-
},
|
|
201
|
-
transformAssetUrls: true,
|
|
202
|
-
},
|
|
203
|
-
customElement: false,
|
|
204
|
-
};
|
|
205
|
-
const compiledScriptResult = vueCompiler.compileScript(descriptor, scriptCompileOptions);
|
|
206
|
-
scriptContent = compiledScriptResult.content;
|
|
207
|
-
scriptLang =
|
|
208
|
-
scriptToCompile.lang?.toLowerCase() === 'ts' ||
|
|
209
|
-
scriptToCompile.lang?.toLowerCase() === 'typescript'
|
|
210
|
-
? 'ts'
|
|
211
|
-
: 'js';
|
|
212
|
-
scriptBindings = compiledScriptResult.bindings;
|
|
213
|
-
}
|
|
214
|
-
else {
|
|
215
|
-
scriptContent = 'export default {};';
|
|
216
|
-
scriptLang = 'js';
|
|
217
|
-
}
|
|
218
|
-
const ast = await parser(`temp.${scriptLang}`, scriptContent, scriptLang);
|
|
219
|
-
if (ast?.errors.length > 0) {
|
|
220
|
-
throw new Error(`Error al analizar el script del componente Vue ${source}:\n${ast.errors
|
|
221
|
-
.map((e) => e.message)
|
|
222
|
-
.join('\n')}`);
|
|
223
|
-
}
|
|
224
|
-
const components = await getComponentsVueMap(ast);
|
|
225
|
-
if (scriptBindings) {
|
|
226
|
-
Object.keys(scriptBindings).forEach(key => {
|
|
227
|
-
if (components.includes(key)) {
|
|
228
|
-
delete scriptBindings[key];
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
} // --- 2. Compilación de la Plantilla (CORREGIDA) ---
|
|
232
|
-
let templateCode = '';
|
|
233
|
-
if (descriptor.template) {
|
|
234
|
-
const templateCompileOptions = {
|
|
235
|
-
source: descriptor.template.content,
|
|
236
|
-
filename: `${fileName}.vue`,
|
|
237
|
-
id,
|
|
238
|
-
scoped: !!scopeId,
|
|
239
|
-
slotted: descriptor.slotted,
|
|
240
|
-
isProd,
|
|
241
|
-
compilerOptions: {
|
|
242
|
-
scopeId,
|
|
243
|
-
mode: 'module',
|
|
244
|
-
bindingMetadata: scriptBindings,
|
|
245
|
-
prefixIdentifiers: true,
|
|
246
|
-
hoistStatic: isProd,
|
|
247
|
-
cacheHandlers: isProd,
|
|
248
|
-
runtimeGlobalName: 'Vue',
|
|
249
|
-
runtimeModuleName: '/node_modules/vue/dist/vue.esm-browser.js',
|
|
250
|
-
whitespace: 'condense',
|
|
251
|
-
ssr: false,
|
|
252
|
-
nodeTransforms: [],
|
|
253
|
-
directiveTransforms: {},
|
|
254
|
-
},
|
|
255
|
-
};
|
|
256
|
-
const compiledTemplateResult = vueCompiler.compileTemplate(templateCompileOptions);
|
|
257
|
-
if (compiledTemplateResult.errors?.length > 0) {
|
|
258
|
-
logger.error('Template compilation errors:', compiledTemplateResult.errors);
|
|
259
|
-
}
|
|
260
|
-
templateCode = compiledTemplateResult.code;
|
|
261
|
-
}
|
|
262
|
-
else {
|
|
263
|
-
const chalkInstance = await loadChalk();
|
|
264
|
-
logger.warn(chalkInstance.yellow(`Advertencia: El componente Vue ${source} no tiene una sección de plantilla.`));
|
|
265
|
-
}
|
|
266
|
-
const finalCompiledScript = {
|
|
267
|
-
content: scriptContent,
|
|
268
|
-
lang: scriptLang,
|
|
269
|
-
type: scriptType,
|
|
270
|
-
};
|
|
271
|
-
const finalCompiledTemplate = {
|
|
272
|
-
code: templateCode,
|
|
273
|
-
};
|
|
274
|
-
let customBlocks = '';
|
|
275
|
-
if (descriptor.customBlocks.length > 0) {
|
|
276
|
-
customBlocks =
|
|
277
|
-
descriptor.customBlocks[0]?.content.slice(0, -1) ?? '';
|
|
278
|
-
}
|
|
279
|
-
// Compile styles
|
|
280
|
-
const compiledStyles = descriptor.styles.map((style) => {
|
|
281
|
-
const lang = style.lang?.toLowerCase();
|
|
282
|
-
let currentPreprocessLang = undefined;
|
|
283
|
-
if (lang === 'scss' ||
|
|
284
|
-
lang === 'sass' ||
|
|
285
|
-
lang === 'less' ||
|
|
286
|
-
lang === 'styl' ||
|
|
287
|
-
lang === 'stylus') {
|
|
288
|
-
currentPreprocessLang = lang;
|
|
289
|
-
}
|
|
290
|
-
return vueCompiler.compileStyle({
|
|
291
|
-
id,
|
|
292
|
-
source: style.content,
|
|
293
|
-
scoped: style.scoped,
|
|
294
|
-
preprocessLang: currentPreprocessLang,
|
|
295
|
-
isProd,
|
|
296
|
-
trim: true,
|
|
297
|
-
filename: `${fileName}.vue`,
|
|
298
|
-
});
|
|
299
|
-
});
|
|
300
|
-
const insertStyles = compiledStyles.length
|
|
301
|
-
? `(function(){
|
|
302
|
-
let styleTag = document.createElement('style');
|
|
303
|
-
styleTag.setAttribute('data-v-${id}', '');
|
|
304
|
-
styleTag.innerHTML = \`${compiledStyles.map((s) => s.code).join('\n')}\`;
|
|
305
|
-
document.head.appendChild(styleTag);
|
|
306
|
-
})();`
|
|
307
|
-
: '';
|
|
308
|
-
let output = `
|
|
309
|
-
${insertStyles}
|
|
310
|
-
${finalCompiledScript.content}
|
|
311
|
-
${finalCompiledTemplate.code}
|
|
312
|
-
`; // Sanitizar el nombre del archivo para crear un nombre de variable JavaScript válido
|
|
313
|
-
const sanitizedFileName = fileName.replace(/[^a-zA-Z0-9_$]/g, '').replace(/^[0-9]/, '_$&') ||
|
|
314
|
-
'component';
|
|
315
|
-
const componentName = `${sanitizedFileName}_component`; // Verificar si ya existe una propiedad 'name' en el output
|
|
316
|
-
const hasNameProperty = /name\s*:\s*['"`]/.test(output);
|
|
317
|
-
// Verificar si ya existe una propiedad 'components' en el output
|
|
318
|
-
const hasComponentsProperty = /components\s*:\s*\{/.test(output);
|
|
319
|
-
const exportComponent = `
|
|
320
|
-
__file: '${source}',
|
|
321
|
-
__name: '${fileName}',
|
|
322
|
-
${hasNameProperty ? '' : `name: '${fileName}',`}
|
|
323
|
-
${hasComponentsProperty
|
|
324
|
-
? ''
|
|
325
|
-
: `components: {
|
|
326
|
-
${components.map(comp => `${comp}`).join(',\n ')}
|
|
327
|
-
},`}
|
|
328
|
-
`;
|
|
329
|
-
// MEJORAR: Manejo más robusto de export default
|
|
330
|
-
if (output.includes('export default {')) {
|
|
331
|
-
output = output.replace('export default {', `const ${componentName} = {
|
|
332
|
-
\n${exportComponent}
|
|
333
|
-
`);
|
|
334
|
-
}
|
|
335
|
-
else if (output.includes('export default defineComponent({')) {
|
|
336
|
-
output = output.replace('export default defineComponent({', `const ${componentName} = defineComponent({
|
|
337
|
-
\n${exportComponent}
|
|
338
|
-
`);
|
|
339
|
-
}
|
|
340
|
-
else if (output.includes('const default = /*@__PURE__*/_defineComponent({')) {
|
|
341
|
-
output = output.replace('const default = /*@__PURE__*/_defineComponent({', `const ${componentName} = /*@__PURE__*/_defineComponent({
|
|
342
|
-
\n${exportComponent}
|
|
343
|
-
`);
|
|
344
|
-
}
|
|
345
|
-
else if (output.includes('export default /*@__PURE__*/_defineComponent({')) {
|
|
346
|
-
output = output.replace('export default /*@__PURE__*/_defineComponent({', `const ${componentName} = /*@__PURE__*/_defineComponent({
|
|
347
|
-
\n${exportComponent}
|
|
348
|
-
`);
|
|
349
|
-
}
|
|
350
|
-
// MEJORAR: Manejo más robusto de render function
|
|
351
|
-
if (output.includes('export function render')) {
|
|
352
|
-
output = output.replace('export function render', `function render_${componentName}`);
|
|
353
|
-
}
|
|
354
|
-
// AÑADIR: Verificar si render fue generado correctamente
|
|
355
|
-
const hasRenderFunction = output.includes(`render_${componentName}`) ||
|
|
356
|
-
output.includes('function render(');
|
|
357
|
-
if (!hasRenderFunction && descriptor.template) {
|
|
358
|
-
logger.warn('Warning: No render function found in compiled output');
|
|
359
|
-
}
|
|
360
|
-
const finishComponent = `
|
|
361
|
-
${hasRenderFunction ? `${componentName}.render = render_${componentName};` : ''}
|
|
362
|
-
${scopeId ? `${componentName}.__scopeId = '${scopeId}';` : ''}
|
|
363
|
-
${customBlocks}
|
|
364
|
-
|
|
365
|
-
export default ${componentName}; `;
|
|
366
|
-
output = `${output}\n${finishComponent}`;
|
|
367
|
-
return {
|
|
368
|
-
lang: finalCompiledScript.lang,
|
|
369
|
-
error: null,
|
|
370
|
-
data: output,
|
|
371
|
-
};
|
|
372
|
-
}
|
|
373
|
-
catch (error) {
|
|
374
|
-
logger.error('Vue compilation error:', error);
|
|
375
|
-
return {
|
|
376
|
-
lang: null,
|
|
377
|
-
error: error instanceof Error ? error : new Error(String(error)),
|
|
378
|
-
data: null,
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
};
|
|
382
|
-
// ✨ NUEVA FUNCIÓN: Exportar funcionalidades del cache HMR para uso externo
|
|
383
|
-
export const getVueHMRCacheStats = () => {
|
|
384
|
-
return hmrInjectionCache.getStats();
|
|
385
|
-
};
|
|
386
|
-
export const clearVueHMRCache = () => {
|
|
387
|
-
hmrInjectionCache.clear();
|
|
388
|
-
};
|
|
389
|
-
export const cleanExpiredVueHMRCache = () => {
|
|
390
|
-
hmrInjectionCache.cleanExpired();
|
|
391
|
-
};
|
|
392
|
-
//# sourceMappingURL=vuejs.js.map
|
|
1
|
+
import{createHash as e}from"node:crypto";import t from"node:path";import*as n from"vue/compiler-sfc";const r=n;import{logger as i}from"../servicios/logger.js";import{parser as a}from"./parser.js";let o;async function s(){return o||=(await import(`chalk`)).default,o}class c{static instance;cache=new Map;MAX_CACHE_SIZE=100;CACHE_TTL=300*1e3;static getInstance(){return c.instance||=new c,c.instance}generateContentHash(t){return e(`md5`).update(t).digest(`hex`)}getOrGenerateHMRInjection(e,t){let n=this.generateContentHash(e),r=`${t}:${n}`,i=this.cache.get(r);if(i&&Date.now()-i.timestamp<this.CACHE_TTL)return{injectedData:i.injectedCode,cached:!0};let a=/import\s*\{[^}]*\bref\b[^}]*\}\s*from\s*['"]vue['"]/,o=a.test(e),s=`
|
|
2
|
+
${o?``:`import { ref } from "/node_modules/vue/dist/vue.esm-browser.js";`}
|
|
3
|
+
const versaComponentKey = ref(0);
|
|
4
|
+
`,c,l=e.includes(`<script`);return c=l?e.replace(/(<script.*?>)/,`$1${s}`):`<script setup lang="ts">${s}<\/script>/n`+e,c=c.replace(/(<template[^>]*>[\s\S]*?)(<(\w+)([^>]*?))(\/?>)/,(e,t,n,r,i,a)=>{if(i.includes(`:key=`)||i.includes(`key=`))return e;let o=a===`/>`;return o?`${t}<${r}${i} :key="versaComponentKey" />`:`${t}<${r}${i} :key="versaComponentKey">`}),this.cache.set(r,{contentHash:n,injectedCode:c,hasRefImport:o,timestamp:Date.now()}),this.evictIfNeeded(),{injectedData:c,cached:!1}}evictIfNeeded(){if(this.cache.size<=this.MAX_CACHE_SIZE)return;let e=Array.from(this.cache.entries());e.sort((e,t)=>e[1].timestamp-t[1].timestamp);let t=e.slice(0,e.length-this.MAX_CACHE_SIZE);t.forEach(([e])=>this.cache.delete(e))}cleanExpired(){let e=Date.now();for(let[t,n]of this.cache.entries())e-n.timestamp>this.CACHE_TTL&&this.cache.delete(t)}getStats(){return{size:this.cache.size,maxSize:this.MAX_CACHE_SIZE,ttl:this.CACHE_TTL}}clear(){this.cache.clear()}}const l=c.getInstance(),u=async e=>{let t=[],n=e?.module?.staticImports;if(n){let e=n.filter(e=>e.moduleRequest.value.endsWith(`.vue`));t=e.map(e=>e.entries.map(e=>e.localName.value)),t=t.flat()}return t};export const preCompileVue=async(e,n,o=!1)=>{try{let c=t.basename(n).replace(`.vue`,``);if(!e||e.trim().length===0)return{error:null,data:`export default {};`,lang:`js`};if(!o){let{injectedData:t}=l.getOrGenerateHMRInjection(e,c);e=t}let{descriptor:d,errors:f}=r.parse(e,{filename:c,sourceMap:!o,sourceRoot:t.dirname(n)});if(f.length)throw Error(`Error al analizar el componente Vue ${n}:\n${f.map(e=>e.message).join(`
|
|
5
|
+
`)}`);let p=Math.random().toString(36).slice(2,12),m=d.styles.some(e=>e.scoped)?`data-v-${p}`:null,h,g=`js`,_,v;if(d.script||d.scriptSetup){v=d.script?`script`:`scriptSetup`;let e=d.script||d.scriptSetup,t={id:p,isProd:o,sourceMap:!o,inlineTemplate:!1,propsDestructure:!0,templateOptions:{compilerOptions:{mode:`module`,scopeId:m,prefixIdentifiers:!0,hoistStatic:o,cacheHandlers:o,nodeTransforms:[],directiveTransforms:{}},transformAssetUrls:!0},customElement:!1},n=r.compileScript(d,t);h=n.content,g=e.lang?.toLowerCase()===`ts`||e.lang?.toLowerCase()===`typescript`?`ts`:`js`,_=n.bindings}else h=`export default {};`,g=`js`;let y=await a(`temp.${g}`,h,g);if(y?.errors.length>0)throw Error(`Error al analizar el script del componente Vue ${n}:\n${y.errors.map(e=>e.message).join(`
|
|
6
|
+
`)}`);let b=await u(y);_&&Object.keys(_).forEach(e=>{b.includes(e)&&delete _[e]});let x=``;if(d.template){let e={source:d.template.content,filename:`${c}.vue`,id:p,scoped:!!m,slotted:d.slotted,isProd:o,compilerOptions:{scopeId:m,mode:`module`,bindingMetadata:_,prefixIdentifiers:!0,hoistStatic:o,cacheHandlers:o,runtimeGlobalName:`Vue`,runtimeModuleName:`/node_modules/vue/dist/vue.esm-browser.js`,whitespace:`condense`,ssr:!1,nodeTransforms:[],directiveTransforms:{}}},t=r.compileTemplate(e);t.errors?.length>0&&i.error(`Template compilation errors:`,t.errors),x=t.code}else{let e=await s();i.warn(e.yellow(`Advertencia: El componente Vue ${n} no tiene una sección de plantilla.`))}let S={content:h,lang:g,type:v},C={code:x},w=``;d.customBlocks.length>0&&(w=d.customBlocks[0]?.content.slice(0,-1)??``);let T=d.styles.map(e=>{let t=e.lang?.toLowerCase(),n;return(t===`scss`||t===`sass`||t===`less`||t===`styl`||t===`stylus`)&&(n=t),r.compileStyle({id:p,source:e.content,scoped:e.scoped,preprocessLang:n,isProd:o,trim:!0,filename:`${c}.vue`})}),E=T.length?`(function(){
|
|
7
|
+
let styleTag = document.createElement('style');
|
|
8
|
+
styleTag.setAttribute('data-v-${p}', '');
|
|
9
|
+
styleTag.innerHTML = \`${T.map(e=>e.code).join(`
|
|
10
|
+
`)}\`;
|
|
11
|
+
document.head.appendChild(styleTag);
|
|
12
|
+
})();`:``,D=`
|
|
13
|
+
${E}
|
|
14
|
+
${S.content}
|
|
15
|
+
${C.code}
|
|
16
|
+
`,O=c.replace(/[^a-zA-Z0-9_$]/g,``).replace(/^[0-9]/,`_$&`)||`component`,k=`${O}_component`,A=/name\s*:\s*['"`]/.test(D),j=/components\s*:\s*\{/.test(D),M=`
|
|
17
|
+
__file: '${n}',
|
|
18
|
+
__name: '${c}',
|
|
19
|
+
${A?``:`name: '${c}',`}
|
|
20
|
+
${j?``:`components: {
|
|
21
|
+
${b.map(e=>`${e}`).join(`,
|
|
22
|
+
`)}
|
|
23
|
+
},`}
|
|
24
|
+
`;D.includes(`export default {`)?D=D.replace(`export default {`,`const ${k} = {
|
|
25
|
+
\n${M}
|
|
26
|
+
`):D.includes(`export default defineComponent({`)?D=D.replace(`export default defineComponent({`,`const ${k} = defineComponent({
|
|
27
|
+
\n${M}
|
|
28
|
+
`):D.includes(`const default = /*@__PURE__*/_defineComponent({`)?D=D.replace(`const default = /*@__PURE__*/_defineComponent({`,`const ${k} = /*@__PURE__*/_defineComponent({
|
|
29
|
+
\n${M}
|
|
30
|
+
`):D.includes(`export default /*@__PURE__*/_defineComponent({`)&&(D=D.replace(`export default /*@__PURE__*/_defineComponent({`,`const ${k} = /*@__PURE__*/_defineComponent({
|
|
31
|
+
\n${M}
|
|
32
|
+
`)),D.includes(`export function render`)&&(D=D.replace(`export function render`,`function render_${k}`));let N=D.includes(`render_${k}`)||D.includes(`function render(`);!N&&d.template&&i.warn(`Warning: No render function found in compiled output`);let P=`
|
|
33
|
+
${N?`${k}.render = render_${k};`:``}
|
|
34
|
+
${m?`${k}.__scopeId = '${m}';`:``}
|
|
35
|
+
${w}
|
|
36
|
+
|
|
37
|
+
export default ${k}; `;return D=`${D}\n${P}`,{lang:S.lang,error:null,data:D}}catch(e){return i.error(`Vue compilation error:`,e),{lang:null,error:e instanceof Error?e:Error(String(e)),data:null}}};export const getVueHMRCacheStats=()=>l.getStats();export const clearVueHMRCache=()=>{l.clear()};export const cleanExpiredVueHMRCache=()=>{l.cleanExpired()};
|