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,353 +1 @@
1
- /**
2
- * @typedef {Object} TreeNode
3
- * @property {string} name - Nombre del componente
4
- * @property {Object} instancia - Instancia del componente Vue
5
- * @property {TreeNode[]} children - Nodos hijos
6
- * @property {TreeNode|null} parent - Nodo padre
7
- * @property {boolean} isRoot - Si es el nodo raíz
8
- * @property {string} [from] - Origen del nodo
9
- */
10
-
11
- /**
12
- * @typedef {Object} VNode
13
- * @property {Object} [type] - Tipo del VNode
14
- * @property {Object} [component] - Componente asociado
15
- * @property {VNode[]} [children] - VNodes hijos
16
- * @property {VNode[]} [dynamicChildren] - VNodes dinámicos
17
- * @property {Object} [suspense] - Objeto suspense
18
- */
19
-
20
- /**
21
- * @typedef {Object} ComponentInstance
22
- * @property {Object} type - Tipo del componente
23
- * @property {string} [type.name] - Nombre del tipo
24
- * @property {string} [type.__name] - Nombre alternativo del tipo
25
- * @property {Object} [components] - Componentes registrados
26
- * @property {VNode} subTree - Subárbol del componente
27
- * @property {Object} [proxy] - Proxy del componente
28
- * @property {Function} [proxy.$forceUpdate] - Función de actualización forzada
29
- * @property {Function} [update] - Función de actualización
30
- * @property {Object} [ctx] - Contexto del componente
31
- * @property {Object} [ctx._] - Contexto interno del componente
32
- * @property {Object} [ctx._.setupState] - Estado del setup del componente
33
- * @property {number} [ctx._.setupState.versaComponentKey] - Clave del componente para HMR
34
- */
35
-
36
- /**
37
- * @typedef {Object} ComponentInfo
38
- * @property {string} normalizedPath - Ruta normalizada del componente
39
- * @property {string} nameFile - Nombre del archivo del componente
40
- */
41
-
42
- /**
43
- * @typedef {Object} VueApp
44
- * @property {ComponentInstance} _instance - Instancia principal de la aplicación
45
- */
46
-
47
- /**
48
- * Busca nodos en el árbol por nombre de instancia
49
- * @param {TreeNode} tree - Árbol de componentes
50
- * @param {string} instance - Nombre de la instancia a buscar
51
- * @returns {TreeNode[]} Array de nodos encontrados
52
- */
53
- function findNodeByInstance(tree, instance) {
54
- const matches = [];
55
- /**
56
- * @param {TreeNode} node - Nodo a buscar recursivamente
57
- */
58
- function searchRecursively(node) {
59
- if (node.name === instance) {
60
- matches.push(node);
61
- }
62
- for (const child of node.children) {
63
- searchRecursively(child);
64
- }
65
- }
66
-
67
- searchRecursively(tree);
68
- return matches;
69
- }
70
- /**
71
- * Obtiene el camino desde un nodo hasta la raíz
72
- * @param {TreeNode} node - Nodo inicial
73
- * @returns {TreeNode[]} Camino desde el nodo hasta la raíz
74
- */
75
- function getPathToRoot(node) {
76
- const path = [];
77
- while (node) {
78
- path.push(node);
79
- node = node.parent;
80
- }
81
- return path; // Ordenado desde hijo hasta raíz
82
- }
83
-
84
- /**
85
- * Encuentra componentes recursivamente dentro de un VNode
86
- * @param {VNode} vnode - VNode a explorar
87
- * @param {TreeNode} parentTreeNode - Nodo padre en el árbol
88
- */
89
- function recursivelyFindComponentsInVNode(vnode, parentTreeNode) {
90
- if (!vnode || typeof vnode !== 'object') {
91
- return;
92
- }
93
- if (vnode?.type.name === 'Suspense') {
94
- const childComponentInstance = vnode?.suspense.activeBranch;
95
- const childTreeNode = {
96
- name: vnode?.type.name,
97
- instancia: childComponentInstance,
98
- children: [],
99
- parent: parentTreeNode,
100
- isRoot: false,
101
- };
102
- parentTreeNode.children.push(childTreeNode);
103
- recursivelyFindComponentsInVNode(childComponentInstance, childTreeNode);
104
- } else if (vnode.component) {
105
- const childComponentInstance = vnode.component;
106
-
107
- let componentName = 'Anonymous';
108
- if (childComponentInstance.type) {
109
- if (childComponentInstance.type.name) {
110
- componentName = childComponentInstance.type.name;
111
- } else if (childComponentInstance.type.__name) {
112
- componentName = childComponentInstance.type.__name;
113
- } else if (typeof childComponentInstance.type === 'function') {
114
- const funcName = childComponentInstance.type.name;
115
- if (funcName && funcName !== 'Anonymous function') {
116
- componentName = funcName;
117
- }
118
- // Heurísticas para componentes comunes de Vue
119
- const typeStr = childComponentInstance.type.toString();
120
- if (typeStr.includes('BaseTransition')) {
121
- componentName = 'Transition';
122
- } else if (typeStr.includes('KeepAlive')) {
123
- componentName = 'KeepAlive';
124
- } else if (typeStr.includes('Suspense')) {
125
- componentName = 'Suspense';
126
- }
127
- }
128
- }
129
-
130
- const childTreeNode = {
131
- name: componentName,
132
- instancia: childComponentInstance,
133
- children: [],
134
- parent: parentTreeNode,
135
- isRoot: false,
136
- };
137
- parentTreeNode.children.push(childTreeNode);
138
- traverseComponentInstance(childComponentInstance, childTreeNode);
139
- } else {
140
- const childrenToExplore = vnode.children || vnode.dynamicChildren;
141
- if (Array.isArray(childrenToExplore)) {
142
- childrenToExplore.forEach(childVNode => {
143
- recursivelyFindComponentsInVNode(childVNode, parentTreeNode);
144
- });
145
- }
146
- }
147
- }
148
-
149
- /**
150
- * Recorre una instancia de componente y construye el árbol
151
- * @param {ComponentInstance} componentInstance - Instancia del componente
152
- * @param {TreeNode} currentTreeNode - Nodo actual del árbol
153
- */
154
- function traverseComponentInstance(componentInstance, currentTreeNode) {
155
- const subTreeVNode = componentInstance.subTree;
156
-
157
- if (!subTreeVNode) {
158
- return;
159
- }
160
-
161
- recursivelyFindComponentsInVNode(subTreeVNode, currentTreeNode);
162
- }
163
-
164
- /**
165
- * Construye el árbol de componentes desde una instancia raíz
166
- * @param {ComponentInstance} componentRootInstance - Instancia raíz del componente
167
- * @returns {TreeNode|null} Árbol de componentes o null si falla
168
- */
169
- export const buildComponentTree = componentRootInstance => {
170
- if (!componentRootInstance || !componentRootInstance.type) {
171
- console.warn(
172
- 'No se pudo construir el árbol de componentes: instancia inválida',
173
- );
174
- return null;
175
- }
176
- const tree = {
177
- name:
178
- componentRootInstance.type?.name ||
179
- componentRootInstance.type?.__name ||
180
- 'Anonymous',
181
- instancia: componentRootInstance,
182
- children: [],
183
- parent: null,
184
- isRoot: true,
185
- from: 'root',
186
- };
187
- traverseComponentInstance(componentRootInstance, tree);
188
-
189
- return tree;
190
- };
191
-
192
- /**
193
- * Intenta forzar la actualización de una instancia de componente
194
- * @param {ComponentInstance} instance - Instancia del componente a actualizar
195
- * @returns {boolean} True si la actualización fue exitosa, false en caso contrario
196
- */
197
- function tryForceUpdate(instance) {
198
- if (!instance) {
199
- return false;
200
- }
201
- if (instance.proxy && typeof instance.proxy.$forceUpdate === 'function') {
202
- instance.proxy.$forceUpdate();
203
- if (typeof instance.update === 'function') {
204
- instance.update();
205
- }
206
- // buscar una variable en el componente que se llame versaComponentKey y sumarle 1
207
- if (instance.ctx?._.setupState?.versaComponentKey !== undefined) {
208
- instance.ctx._.setupState.versaComponentKey++;
209
- }
210
- return true;
211
- }
212
- if (typeof instance.update === 'function') {
213
- if (instance.ctx?._.setupState?.versaComponentKey !== undefined) {
214
- instance.ctx._.setupState.versaComponentKey++;
215
- }
216
- instance.update();
217
- return true;
218
- }
219
- return false;
220
- }
221
-
222
- /**
223
- * Intenta actualizar un componente en el camino del árbol
224
- * @param {TreeNode[]} path - Camino de nodos desde el componente hasta la raíz
225
- * @param {Object} newComponent - Nuevo componente a usar
226
- * @param {string} componentName - Nombre del componente
227
- * @param {VueApp} App - Aplicación Vue
228
- * @returns {boolean} True si la actualización fue exitosa
229
- */
230
- function tryUpdateComponentPath(path, newComponent, componentName, App) {
231
- if (!path || !newComponent || !componentName || !App) {
232
- console.error('❌ Parámetros inválidos para tryUpdateComponentPath');
233
- return false;
234
- }
235
-
236
- // Recorrer el path desde el padre hacia la raíz (saltando el primer elemento que es el propio componente)
237
- for (let i = 1; i < path.length; i++) {
238
- const parent = path[i];
239
-
240
- if (parent.isRoot || parent.name === 'KeepAlive') {
241
- window.location.reload();
242
- return true;
243
- }
244
-
245
- if (!parent || !parent.instancia) {
246
- console.error('❌ Nodo padre no válido en el camino:', parent);
247
- continue; // Continúa con el siguiente padre en lugar de fallar
248
- }
249
-
250
- // Actualizar la instancia del componente
251
- const componentsDefinition =
252
- parent.instancia?.type?.components || parent.instancia?.components;
253
-
254
- if (componentsDefinition && componentsDefinition[componentName]) {
255
- componentsDefinition[componentName] = newComponent;
256
-
257
- // Forzar actualización de la instancia padre
258
- return (
259
- tryForceUpdate(parent.instancia) ||
260
- tryForceUpdate(parent.instancia.proxy)
261
- );
262
- }
263
- }
264
-
265
- return false;
266
- }
267
-
268
- /**
269
- * Recarga un componente Vue con Hot Module Replacement
270
- * @param {VueApp} App - Aplicación Vue principal
271
- * @param {ComponentInfo} Component - Información del componente a recargar
272
- * @returns {Promise<boolean>} Promise que resuelve a true si la recarga fue exitosa
273
- */
274
- export async function reloadComponent(App, Component) {
275
- try {
276
- const { normalizedPath: relativePath, nameFile: componentName } =
277
- Component;
278
- if (!App || !App._instance) {
279
- console.error('❌ App o App._instance no están definidos');
280
- return false;
281
- }
282
-
283
- if (!relativePath) {
284
- console.error('❌ No se proporcionó relativePath');
285
- return false;
286
- }
287
-
288
- const baseUrl = window.location.href;
289
- const newBaseUrl = new URL(baseUrl);
290
- const urlOrigin = `${newBaseUrl.origin}/${relativePath}`;
291
- const timestamp = Date.now();
292
- const moduleUrl = `${urlOrigin}?t=${timestamp}`;
293
-
294
- const module = await import(moduleUrl);
295
-
296
- if (!module.default) {
297
- console.error('❌ El módulo importado no tiene export default');
298
- return false;
299
- }
300
-
301
- const componentTree = buildComponentTree(App._instance);
302
- if (!componentTree) {
303
- console.error('❌ No se pudo construir el árbol de componentes');
304
- return false;
305
- }
306
-
307
- const targetNodes = findNodeByInstance(componentTree, componentName);
308
- if (!targetNodes) {
309
- console.warn(
310
- '⚠️ No se encontró el nodo objetivo para:',
311
- componentName,
312
- );
313
-
314
- return false;
315
- }
316
-
317
- console.log(
318
- `🔍 Se encontraron ${targetNodes.length} instancias del componente ${componentName}`,
319
- );
320
-
321
- let successfulUpdates = 0; // Procesar TODAS las instancias encontradas
322
- for (let i = 0; i < targetNodes.length; i++) {
323
- const node = targetNodes[i];
324
- if (node) {
325
- const path = getPathToRoot(node);
326
- const updateResult = await tryUpdateComponentPath(
327
- path,
328
- module.default,
329
- componentName,
330
- App,
331
- );
332
-
333
- if (updateResult) {
334
- successfulUpdates++;
335
- } else {
336
- console.error(
337
- `❌ No se pudo actualizar la instancia ${i + 1}`,
338
- );
339
- }
340
- }
341
- }
342
-
343
- const hasSuccessfulUpdate = successfulUpdates > 0;
344
- console.log(
345
- `\n📊 Resultado final: ${successfulUpdates}/${targetNodes.length} instancias actualizadas`,
346
- );
347
-
348
- return hasSuccessfulUpdate;
349
- } catch (error) {
350
- console.error('❌ Error en reloadComponent:', error);
351
- return false;
352
- }
353
- }
1
+ import{obtenerInstanciaVue as e}from"./getInstanciaVue.js";function t(e,t){let n=[];function r(e){e.name===t&&n.push(e);for(let t of e.children)r(t)}return r(e),n}function n(e){let t=[];for(;e;)t.push(e),e=e.parent;return t}function r(e,t){if(!(!e||typeof e!=`object`))if(e?.type.name===`Suspense`){let n=e?.suspense.activeBranch,i={name:e?.type.name,instancia:n,children:[],parent:t,isRoot:!1};t.children.push(i),r(n,i)}else if(e.component){let n=e.component,r=`Anonymous`;if(n.type){if(n.type.name)r=n.type.name;else if(n.type.__name)r=n.type.__name;else if(typeof n.type==`function`){let e=n.type.name;e&&e!==`Anonymous function`&&(r=e);let t=n.type.toString();t.includes(`BaseTransition`)?r=`Transition`:t.includes(`KeepAlive`)?r=`KeepAlive`:t.includes(`Suspense`)&&(r=`Suspense`)}}let a={name:r,instancia:n,children:[],parent:t,isRoot:!1};t.children.push(a),i(n,a)}else{let n=e.children||e.dynamicChildren;Array.isArray(n)&&n.forEach(e=>{r(e,t)})}}function i(e,t){let n=e.subTree;n&&r(n,t)}export const buildComponentTree=e=>{if(!e||!e.type)return console.warn(`No se pudo construir el árbol de componentes: instancia inválida`),null;let t={name:e.type?.name||e.type?.__name||`Anonymous`,instancia:e,children:[],parent:null,isRoot:!0,from:`root`};return i(e,t),t};function o(e){return e?e.proxy&&typeof e.proxy.$forceUpdate==`function`?(e.proxy.$forceUpdate(),typeof e.update==`function`&&e.update(),e.ctx?._.setupState?.versaComponentKey!==void 0&&e.ctx._.setupState.versaComponentKey++,!0):typeof e.update==`function`?(e.ctx?._.setupState?.versaComponentKey!==void 0&&e.ctx._.setupState.versaComponentKey++,e.update(),!0):!1:!1}function s(e,t,n,r){if(!e||!t||!n||!r)return console.error(`❌ Parámetros inválidos para tryUpdateComponentPath`),!1;for(let r=1;r<e.length;r++){let i=e[r];if(i.isRoot||i.name===`KeepAlive`)return window.location.reload(),!0;if(!i||!i.instancia){console.error(`❌ Nodo padre no válido en el camino:`,i);continue}let a=i.instancia?.type?.components||i.instancia?.components;if(a&&a[n])return a[n]=t,o(i.instancia)||o(i.instancia.proxy)}return!1}export async function reloadComponent(r,i){try{let{normalizedPath:o,nameFile:c}=i;if(!r||!r._instance){let t=await e();if(!t)return console.error(`❌ No se pudo obtener la instancia de Vue`),!1;r=t}if(!o)return console.error(`❌ No se proporcionó relativePath`),!1;let l=window.location.href,u=new URL(l),d=`${u.origin}/${o}`,f=Date.now(),p=`${d}?t=${f}`,m=await import(p);if(!m.default)return console.error(`❌ El módulo importado no tiene export default`),!1;let h=buildComponentTree(r._instance);if(!h)return console.error(`❌ No se pudo construir el árbol de componentes`),!1;let g=t(h,c);if(!g)return console.warn(`⚠️ No se encontró el nodo objetivo para:`,c),!1;console.log(`🔍 Se encontraron ${g.length} instancias del componente ${c}`);let _=0;for(let e=0;e<g.length;e++){let t=g[e];if(t){let i=n(t),a=await s(i,m.default,c,r);a?_++:console.error(`❌ No se pudo actualizar la instancia ${e+1}`)}}let v=_>0;return console.log(`\n📊 Resultado final: ${_}/${g.length} instancias actualizadas`),v}catch(e){return console.error(`❌ Error en reloadComponent:`,e),!1}}
@@ -1,83 +1 @@
1
- /**
2
- * Variable global que mantiene la referencia al overlay de error actual
3
- * @type {HTMLElement|null}
4
- */
5
- let errorOverlay;
6
-
7
- /**
8
- * Oculta y remueve el overlay de error actual del DOM
9
- * @returns {void}
10
- */
11
- export function hideErrorOverlay() {
12
- const existingOverlay = document.getElementById('versa-hmr-error-overlay');
13
- if (existingOverlay) {
14
- existingOverlay.remove();
15
- }
16
- errorOverlay = null;
17
- }
18
-
19
- /**
20
- * Muestra un overlay de error personalizado para errores de HMR (Hot Module Replacement).
21
- * @param {string} errorMessage - Mensaje de error principal.
22
- * @param {string} [errorDetails=''] - Detalles adicionales del error, opcional.
23
- * @returns {void}
24
- */
25
- export function showErrorOverlay(errorMessage, errorDetails = '') {
26
- hideErrorOverlay(); // Asegurar que no haya overlays duplicados
27
-
28
- // Crear el contenedor principal del overlay
29
- errorOverlay = document.createElement('div');
30
- errorOverlay.id = 'versa-hmr-error-overlay';
31
- errorOverlay.style.position = 'fixed';
32
- errorOverlay.style.top = '0';
33
- errorOverlay.style.left = '0';
34
- errorOverlay.style.width = '100vw';
35
- errorOverlay.style.height = '100vh';
36
- errorOverlay.style.backgroundColor = 'rgba(0, 0, 0, 1.85)';
37
- errorOverlay.style.color = '#ff8080';
38
- errorOverlay.style.zIndex = '999999';
39
- errorOverlay.style.display = 'flex';
40
- errorOverlay.style.flexDirection = 'column';
41
- errorOverlay.style.alignItems = 'center';
42
- errorOverlay.style.justifyContent = 'center';
43
- errorOverlay.style.fontFamily = 'monospace';
44
- errorOverlay.style.fontSize = '16px';
45
- errorOverlay.style.padding = '20px';
46
- errorOverlay.style.boxSizing = 'border-box';
47
- errorOverlay.style.textAlign = 'left';
48
- errorOverlay.style.overflow = 'auto';
49
-
50
- // Crear el título del overlay
51
- const title = document.createElement('h2');
52
- title.textContent = 'Versa HMR Error';
53
- title.style.color = '#ff4d4d';
54
- title.style.fontSize = '24px';
55
- title.style.marginBottom = '20px';
56
-
57
- // Crear el contenedor del mensaje principal
58
- const messageDiv = document.createElement('div');
59
- messageDiv.textContent = errorMessage;
60
- messageDiv.style.marginBottom = '15px';
61
- messageDiv.style.whiteSpace = 'pre-wrap';
62
-
63
- // Crear el contenedor de detalles del error
64
- const detailsPre = document.createElement('pre');
65
- detailsPre.textContent = errorDetails;
66
- detailsPre.style.backgroundColor = 'rgba(255, 255, 255, 0.1)';
67
- detailsPre.style.padding = '10px';
68
- detailsPre.style.borderRadius = '5px';
69
- detailsPre.style.maxHeight = '50vh';
70
- detailsPre.style.overflow = 'auto';
71
- detailsPre.style.width = '100%';
72
- detailsPre.style.maxWidth = '800px';
73
-
74
- // Agregar elementos al overlay
75
- errorOverlay.appendChild(title);
76
- errorOverlay.appendChild(messageDiv);
77
- if (errorDetails) {
78
- errorOverlay.appendChild(detailsPre);
79
- }
80
-
81
- // Agregar el overlay al DOM
82
- document.body.appendChild(errorOverlay);
83
- }
1
+ let e;export function hideErrorOverlay(){let t=document.getElementById(`versa-hmr-error-overlay`);t&&t.remove(),e=null}export function showErrorOverlay(n,r=``){hideErrorOverlay(),e=document.createElement(`div`),e.id=`versa-hmr-error-overlay`,e.style.position=`fixed`,e.style.top=`0`,e.style.left=`0`,e.style.width=`100vw`,e.style.height=`100vh`,e.style.backgroundColor=`rgba(0, 0, 0, 1.85)`,e.style.color=`#ff8080`,e.style.zIndex=`999999`,e.style.display=`flex`,e.style.flexDirection=`column`,e.style.alignItems=`center`,e.style.justifyContent=`center`,e.style.fontFamily=`monospace`,e.style.fontSize=`16px`,e.style.padding=`20px`,e.style.boxSizing=`border-box`,e.style.textAlign=`left`,e.style.overflow=`auto`;let i=document.createElement(`h2`);i.textContent=`Versa HMR Error`,i.style.color=`#ff4d4d`,i.style.fontSize=`24px`,i.style.marginBottom=`20px`;let a=document.createElement(`div`);a.textContent=n,a.style.marginBottom=`15px`,a.style.whiteSpace=`pre-wrap`;let o=document.createElement(`pre`);o.textContent=r,o.style.backgroundColor=`rgba(255, 255, 255, 0.1)`,o.style.padding=`10px`,o.style.borderRadius=`5px`,o.style.maxHeight=`50vh`,o.style.overflow=`auto`,o.style.width=`100%`,o.style.maxWidth=`800px`,e.appendChild(i),e.appendChild(a),r&&e.appendChild(o),document.body.appendChild(e)}