versacompiler 2.4.1 → 2.6.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 +722 -722
- package/dist/compiler/compile-worker-pool.js +108 -0
- package/dist/compiler/compile-worker-thread.cjs +72 -0
- package/dist/compiler/compile.js +177 -18
- package/dist/compiler/error-reporter.js +12 -0
- package/dist/compiler/integrity-validator.js +13 -1
- package/dist/compiler/linter.js +12 -0
- package/dist/compiler/minify.js +12 -0
- package/dist/compiler/minifyTemplate.js +12 -0
- package/dist/compiler/module-resolution-optimizer.js +35 -20
- package/dist/compiler/parser.js +12 -0
- package/dist/compiler/performance-monitor.js +73 -61
- package/dist/compiler/pipeline/build-pipeline.js +139 -0
- package/dist/compiler/pipeline/core-plugins.js +230 -0
- package/dist/compiler/pipeline/module-graph.js +75 -0
- package/dist/compiler/pipeline/plugin-driver.js +99 -0
- package/dist/compiler/pipeline/types.js +14 -0
- package/dist/compiler/tailwindcss.js +12 -0
- package/dist/compiler/transform-optimizer.js +12 -0
- package/dist/compiler/transformTStoJS.js +38 -5
- package/dist/compiler/transforms.js +234 -16
- package/dist/compiler/typescript-compiler.js +12 -0
- package/dist/compiler/typescript-error-parser.js +12 -0
- package/dist/compiler/typescript-manager.js +15 -1
- package/dist/compiler/typescript-sync-validator.js +45 -31
- package/dist/compiler/typescript-worker-pool.js +12 -0
- package/dist/compiler/typescript-worker-thread.cjs +482 -475
- package/dist/compiler/typescript-worker.js +12 -0
- package/dist/compiler/vuejs.js +73 -47
- package/dist/config.js +14 -0
- package/dist/hrm/VueHRM.js +484 -359
- package/dist/hrm/errorScreen.js +95 -83
- package/dist/hrm/getInstanciaVue.js +325 -313
- package/dist/hrm/initHRM.js +736 -586
- package/dist/hrm/versaHMR.js +317 -0
- package/dist/main.js +23 -3
- package/dist/servicios/browserSync.js +127 -6
- package/dist/servicios/file-watcher.js +139 -8
- package/dist/servicios/logger.js +12 -0
- package/dist/servicios/readConfig.js +141 -54
- package/dist/servicios/versacompile.config.types.js +14 -0
- package/dist/utils/excluded-modules.js +12 -0
- package/dist/utils/module-resolver.js +86 -40
- package/dist/utils/promptUser.js +12 -0
- package/dist/utils/proxyValidator.js +12 -0
- package/dist/utils/resolve-bin.js +12 -0
- package/dist/utils/utils.js +12 -0
- package/dist/utils/vue-types-setup.js +260 -248
- package/dist/wrappers/eslint-node.js +15 -1
- package/dist/wrappers/oxlint-node.js +15 -1
- package/dist/wrappers/tailwind-node.js +12 -0
- package/package.json +74 -54
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
/* VersaCompiler HMR shim [dev] */
|
|
2
|
+
if (typeof window !== 'undefined' && window.__versaHMR) {
|
|
3
|
+
(() => {
|
|
4
|
+
const _id = new URL(import.meta.url).pathname;
|
|
5
|
+
import.meta.hot = {
|
|
6
|
+
accept(cb) { window.__versaHMR.accept(_id, typeof cb === 'function' ? cb : () => {}); },
|
|
7
|
+
invalidate() { window.__versaHMR._invalidate?.(_id); },
|
|
8
|
+
dispose(cb) { window.__versaHMR._onDispose?.(_id, cb); },
|
|
9
|
+
get data() { return window.__versaHMR._getHotData?.(_id) ?? {}; },
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
}
|
|
1
13
|
/**
|
|
2
14
|
* TypeScript Worker Manager - Gestiona workers dedicados para type checking asíncrono
|
|
3
15
|
* Implementa el patrón Singleton para reutilizar workers entre compilaciones
|
package/dist/compiler/vuejs.js
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
/* VersaCompiler HMR shim [dev] */
|
|
2
|
+
if (typeof window !== 'undefined' && window.__versaHMR) {
|
|
3
|
+
(() => {
|
|
4
|
+
const _id = new URL(import.meta.url).pathname;
|
|
5
|
+
import.meta.hot = {
|
|
6
|
+
accept(cb) { window.__versaHMR.accept(_id, typeof cb === 'function' ? cb : () => {}); },
|
|
7
|
+
invalidate() { window.__versaHMR._invalidate?.(_id); },
|
|
8
|
+
dispose(cb) { window.__versaHMR._onDispose?.(_id, cb); },
|
|
9
|
+
get data() { return window.__versaHMR._getHotData?.(_id) ?? {}; },
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
}
|
|
1
13
|
import { createHash } from 'node:crypto';
|
|
2
14
|
import path from 'node:path';
|
|
3
15
|
import * as vCompiler from 'vue/compiler-sfc';
|
|
@@ -49,9 +61,9 @@ class VueHMRInjectionCache {
|
|
|
49
61
|
const hasRefImport = vueImportPattern.test(originalData);
|
|
50
62
|
// ✨ FIX: Construir el import dinámicamente para evitar que el compilador lo transforme
|
|
51
63
|
const vueRefImport = ['import', '{ ref }', 'from', '"vue"'].join(' ') + ';';
|
|
52
|
-
const varContent = `
|
|
53
|
-
${hasRefImport ? '' : vueRefImport}
|
|
54
|
-
const versaComponentKey = ref(0);
|
|
64
|
+
const varContent = `
|
|
65
|
+
${hasRefImport ? '' : vueRefImport}
|
|
66
|
+
const versaComponentKey = ref(0);
|
|
55
67
|
`;
|
|
56
68
|
let injectedData;
|
|
57
69
|
const ifExistScript = originalData.includes('<script');
|
|
@@ -63,19 +75,30 @@ class VueHMRInjectionCache {
|
|
|
63
75
|
else {
|
|
64
76
|
injectedData = originalData.replace(/(<script.*?>)/, `$1${varContent}`);
|
|
65
77
|
}
|
|
66
|
-
// Inyectar :key en el template
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
// Inyectar :key en el primer elemento hijo del template.
|
|
79
|
+
// Dos pasos para evitar backtracking catastrófico (ReDoS) que ocurría con
|
|
80
|
+
// el pattern combinado /(<template[^>]*>[\s\S]*?)(<(\w+)([^>]*?))(\/?>)/
|
|
81
|
+
const templateTagMatch = /(<template[^>]*>)/.exec(injectedData);
|
|
82
|
+
if (templateTagMatch) {
|
|
83
|
+
const templateEnd = templateTagMatch.index + templateTagMatch[0].length;
|
|
84
|
+
const afterTemplate = injectedData.slice(templateEnd);
|
|
85
|
+
// Buscar el primer tag de elemento (ignora espacios/comentarios) justo después del <template>
|
|
86
|
+
const firstChildMatch = /^(\s*)(<(\w+)([^>]*?)(\/?>))/.exec(afterTemplate);
|
|
87
|
+
if (firstChildMatch) {
|
|
88
|
+
const [, whitespace = '', fullTag = '', tagName, attrs = '', closing,] = firstChildMatch;
|
|
89
|
+
if (!attrs.includes(':key=') && !attrs.includes('key=')) {
|
|
90
|
+
const isSelfClosing = closing === '/>';
|
|
91
|
+
const newTag = isSelfClosing
|
|
92
|
+
? `<${tagName}${attrs} :key="versaComponentKey" />`
|
|
93
|
+
: `<${tagName}${attrs} :key="versaComponentKey">`;
|
|
94
|
+
injectedData =
|
|
95
|
+
injectedData.slice(0, templateEnd) +
|
|
96
|
+
whitespace +
|
|
97
|
+
newTag +
|
|
98
|
+
afterTemplate.slice(whitespace.length + fullTag.length);
|
|
99
|
+
}
|
|
77
100
|
}
|
|
78
|
-
}
|
|
101
|
+
}
|
|
79
102
|
// Cachear resultado
|
|
80
103
|
this.cache.set(cacheKey, {
|
|
81
104
|
contentHash,
|
|
@@ -167,8 +190,6 @@ export const preCompileVue = async (data, source, isProd = false) => {
|
|
|
167
190
|
scriptInfo: undefined,
|
|
168
191
|
};
|
|
169
192
|
}
|
|
170
|
-
// Guardar el código original antes de inyectar HMR
|
|
171
|
-
const originalData = data;
|
|
172
193
|
if (!isProd) {
|
|
173
194
|
const { injectedData } = hmrInjectionCache.getOrGenerateHMRInjection(data, fileName);
|
|
174
195
|
data = injectedData;
|
|
@@ -312,18 +333,22 @@ export const preCompileVue = async (data, source, isProd = false) => {
|
|
|
312
333
|
filename: `${fileName}.vue`,
|
|
313
334
|
});
|
|
314
335
|
});
|
|
336
|
+
// data-versa-hmr-component permite a VueHRM.js eliminar style tags
|
|
337
|
+
// de ciclos HMR anteriores para evitar acumulación de estilos duplicados.
|
|
338
|
+
const sanitizedForAttr = fileName.replace(/[^a-zA-Z0-9_-]/g, '');
|
|
315
339
|
const insertStyles = compiledStyles.length
|
|
316
|
-
? `(function(){
|
|
317
|
-
let styleTag = document.createElement('style');
|
|
318
|
-
styleTag.setAttribute('data-v-${id}', '');
|
|
319
|
-
styleTag.
|
|
320
|
-
|
|
340
|
+
? `(function(){
|
|
341
|
+
let styleTag = document.createElement('style');
|
|
342
|
+
styleTag.setAttribute('data-v-${id}', '');
|
|
343
|
+
styleTag.setAttribute('data-versa-hmr-component', '${sanitizedForAttr}');
|
|
344
|
+
styleTag.innerHTML = \`${compiledStyles.map((s) => s.code).join('\n')}\`;
|
|
345
|
+
document.head.appendChild(styleTag);
|
|
321
346
|
})();`
|
|
322
347
|
: '';
|
|
323
|
-
let output = `
|
|
324
|
-
${insertStyles}
|
|
325
|
-
${finalCompiledScript.content}
|
|
326
|
-
${finalCompiledTemplate.code}
|
|
348
|
+
let output = `
|
|
349
|
+
${insertStyles}
|
|
350
|
+
${finalCompiledScript.content}
|
|
351
|
+
${finalCompiledTemplate.code}
|
|
327
352
|
`; // Sanitizar el nombre del archivo para crear un nombre de variable JavaScript válido
|
|
328
353
|
const sanitizedFileName = fileName.replace(/[^a-zA-Z0-9_$]/g, '').replace(/^[0-9]/, '_$&') ||
|
|
329
354
|
'component';
|
|
@@ -331,35 +356,35 @@ export const preCompileVue = async (data, source, isProd = false) => {
|
|
|
331
356
|
const hasNameProperty = /name\s*:\s*['"`]/.test(output);
|
|
332
357
|
// Verificar si ya existe una propiedad 'components' en el output
|
|
333
358
|
const hasComponentsProperty = /components\s*:\s*\{/.test(output);
|
|
334
|
-
const exportComponent = `
|
|
335
|
-
__file: '${source}',
|
|
336
|
-
__name: '${fileName}',
|
|
337
|
-
${hasNameProperty ? '' : `name: '${fileName}',`}
|
|
359
|
+
const exportComponent = `
|
|
360
|
+
__file: '${source}',
|
|
361
|
+
__name: '${fileName}',
|
|
362
|
+
${hasNameProperty ? '' : `name: '${fileName}',`}
|
|
338
363
|
${hasComponentsProperty
|
|
339
364
|
? ''
|
|
340
|
-
: `components: {
|
|
341
|
-
${components.map(comp => `${comp}`).join(',\n ')}
|
|
342
|
-
},`}
|
|
365
|
+
: `components: {
|
|
366
|
+
${components.map(comp => `${comp}`).join(',\n ')}
|
|
367
|
+
},`}
|
|
343
368
|
`;
|
|
344
369
|
// MEJORAR: Manejo más robusto de export default
|
|
345
370
|
if (output.includes('export default {')) {
|
|
346
|
-
output = output.replace('export default {', `const ${componentName} = {
|
|
347
|
-
\n${exportComponent}
|
|
371
|
+
output = output.replace('export default {', `const ${componentName} = {
|
|
372
|
+
\n${exportComponent}
|
|
348
373
|
`);
|
|
349
374
|
}
|
|
350
375
|
else if (output.includes('export default defineComponent({')) {
|
|
351
|
-
output = output.replace('export default defineComponent({', `const ${componentName} = defineComponent({
|
|
352
|
-
\n${exportComponent}
|
|
376
|
+
output = output.replace('export default defineComponent({', `const ${componentName} = defineComponent({
|
|
377
|
+
\n${exportComponent}
|
|
353
378
|
`);
|
|
354
379
|
}
|
|
355
380
|
else if (output.includes('const default = /*@__PURE__*/_defineComponent({')) {
|
|
356
|
-
output = output.replace('const default = /*@__PURE__*/_defineComponent({', `const ${componentName} = /*@__PURE__*/_defineComponent({
|
|
357
|
-
\n${exportComponent}
|
|
381
|
+
output = output.replace('const default = /*@__PURE__*/_defineComponent({', `const ${componentName} = /*@__PURE__*/_defineComponent({
|
|
382
|
+
\n${exportComponent}
|
|
358
383
|
`);
|
|
359
384
|
}
|
|
360
385
|
else if (output.includes('export default /*@__PURE__*/_defineComponent({')) {
|
|
361
|
-
output = output.replace('export default /*@__PURE__*/_defineComponent({', `const ${componentName} = /*@__PURE__*/_defineComponent({
|
|
362
|
-
\n${exportComponent}
|
|
386
|
+
output = output.replace('export default /*@__PURE__*/_defineComponent({', `const ${componentName} = /*@__PURE__*/_defineComponent({
|
|
387
|
+
\n${exportComponent}
|
|
363
388
|
`);
|
|
364
389
|
}
|
|
365
390
|
// MEJORAR: Manejo más robusto de render function
|
|
@@ -372,14 +397,16 @@ export const preCompileVue = async (data, source, isProd = false) => {
|
|
|
372
397
|
if (!hasRenderFunction && descriptor.template) {
|
|
373
398
|
logger.warn('Warning: No render function found in compiled output');
|
|
374
399
|
}
|
|
375
|
-
const finishComponent = `
|
|
376
|
-
${hasRenderFunction ? `${componentName}.render = render_${componentName};` : ''}
|
|
377
|
-
${scopeId ? `${componentName}.__scopeId = '${scopeId}';` : ''}
|
|
378
|
-
${customBlocks}
|
|
379
|
-
|
|
400
|
+
const finishComponent = `
|
|
401
|
+
${hasRenderFunction ? `${componentName}.render = render_${componentName};` : ''}
|
|
402
|
+
${scopeId ? `${componentName}.__scopeId = '${scopeId}';` : ''}
|
|
403
|
+
${customBlocks}
|
|
404
|
+
|
|
380
405
|
export default ${componentName}; `;
|
|
381
406
|
output = `${output}\n${finishComponent}`;
|
|
382
407
|
// 🚀 OPTIMIZACIÓN CRÍTICA: Evitar crear scriptInfo si no hay script
|
|
408
|
+
// originalData NO se incluye en scriptInfo para evitar retener la cadena completa
|
|
409
|
+
// del .vue en memoria. Se pasa por separado como sourceCode en parseTypeScriptErrors.
|
|
383
410
|
const result = {
|
|
384
411
|
lang: finalCompiledScript.lang,
|
|
385
412
|
error: null,
|
|
@@ -391,7 +418,6 @@ export const preCompileVue = async (data, source, isProd = false) => {
|
|
|
391
418
|
startLine: (descriptor.script || descriptor.scriptSetup).loc?.start
|
|
392
419
|
.line || 1,
|
|
393
420
|
content: (descriptor.script || descriptor.scriptSetup).content,
|
|
394
|
-
originalData: originalData, // String directa, no closure
|
|
395
421
|
};
|
|
396
422
|
}
|
|
397
423
|
return result;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/* VersaCompiler HMR shim [dev] */
|
|
2
|
+
if (typeof window !== 'undefined' && window.__versaHMR) {
|
|
3
|
+
(() => {
|
|
4
|
+
const _id = new URL(import.meta.url).pathname;
|
|
5
|
+
import.meta.hot = {
|
|
6
|
+
accept(cb) { window.__versaHMR.accept(_id, typeof cb === 'function' ? cb : () => {}); },
|
|
7
|
+
invalidate() { window.__versaHMR._invalidate?.(_id); },
|
|
8
|
+
dispose(cb) { window.__versaHMR._onDispose?.(_id, cb); },
|
|
9
|
+
get data() { return window.__versaHMR._getHotData?.(_id) ?? {}; },
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
}
|
|
13
|
+
export { defineConfig, } from './servicios/versacompile.config.types';
|
|
14
|
+
//# sourceMappingURL=config.js.map
|