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,313 +1 @@
1
- /**
2
- * Script para obtener la instancia de Vue usando solo JavaScript
3
- * Compatible con Vue 2 y Vue 3
4
- */
5
-
6
- /**
7
- * @typedef {Object} VueInstance
8
- * @property {string} [version] - Versión de Vue
9
- * @property {Object} [config] - Configuración de Vue
10
- * @property {Object} [proxy] - Proxy del componente
11
- * @property {Object} [$options] - Opciones del componente (Vue 2)
12
- * @property {Object} [$router] - Router de Vue
13
- * @property {Object} [$store] - Store de Vuex/Pinia
14
- * @property {Array} [$children] - Componentes hijos (Vue 2)
15
- * @property {Object} [$data] - Datos del componente (Vue 2)
16
- */
17
-
18
- /**
19
- * @typedef {Object} VueInstanceInfo
20
- * @property {string|null} version - Versión de Vue detectada
21
- * @property {string|null} type - Tipo de instancia de Vue
22
- * @property {boolean} hasRouter - Indica si tiene Vue Router
23
- * @property {boolean} hasStore - Indica si tiene Vuex/Pinia
24
- * @property {Object|number} components - Información de componentes
25
- * @property {string[]|null} data - Claves de datos del componente
26
- */
27
-
28
- /**
29
- * Obtiene la instancia de Vue desde un elemento específico del DOM
30
- * @param {string} [selector='#app'] - Selector CSS del elemento que contiene la aplicación Vue
31
- * @returns {VueInstance|null} Instancia de Vue o null si no se encuentra
32
- */
33
- function getVueInstanceFromElement(selector = '#app') {
34
- const element = document.querySelector(selector);
35
- if (!element) {
36
- return null;
37
- }
38
-
39
- // Para Vue 3
40
- if (element.__vue_app__) {
41
- return element.__vue_app__;
42
- }
43
-
44
- // Para Vue 2
45
- if (element.__vue__) {
46
- return element.__vue__;
47
- }
48
-
49
- return null;
50
- }
51
-
52
- /**
53
- * Busca instancias de Vue en todos los elementos del DOM
54
- * @returns {VueInstance|null} Primera instancia de Vue encontrada o null si no se encuentra ninguna
55
- */
56
- function findVueInstanceInDOM() {
57
- const allElements = document.querySelectorAll('*');
58
-
59
- for (const element of allElements) {
60
- // Vue 3
61
- if (element.__vue_app__) {
62
- return element.__vue_app__;
63
- }
64
-
65
- // Vue 2
66
- if (element.__vue__) {
67
- return element.__vue__;
68
- }
69
- }
70
-
71
- return null;
72
- }
73
-
74
- /**
75
- * Obtiene la instancia de Vue desde variables globales o herramientas de desarrollo
76
- * @returns {VueInstance|null} Instancia de Vue desde el contexto global o null si no se encuentra
77
- */
78
- function getVueFromGlobal() {
79
- // Verificar si Vue está en el objeto global
80
- if (typeof window !== 'undefined') {
81
- // Vue como variable global
82
- if (window.Vue) {
83
- return window.Vue;
84
- }
85
-
86
- // Instancia específica guardada globalmente
87
- if (window.__VUE_APP_INSTANCE__) {
88
- return window.__VUE_APP_INSTANCE__;
89
- }
90
-
91
- // Vue DevTools
92
- if (window.__VUE_DEVTOOLS_GLOBAL_HOOK__) {
93
- const apps = window.__VUE_DEVTOOLS_GLOBAL_HOOK__.apps;
94
- if (apps && apps.length > 0) {
95
- return apps[0];
96
- }
97
- }
98
- }
99
-
100
- return null;
101
- }
102
-
103
- /**
104
- * Obtiene el componente raíz específico de Vue 3
105
- * @param {string} [selector='#app'] - Selector CSS del elemento que contiene la aplicación Vue
106
- * @returns {VueInstance|null} Componente raíz de Vue 3 o null si no se encuentra
107
- */
108
- function getVue3RootComponent(selector = '#app') {
109
- const element = document.querySelector(selector);
110
- if (!element) return null;
111
-
112
- // Vue 3 específico
113
- if (element._vnode && element._vnode.component) {
114
- return element._vnode.component;
115
- }
116
-
117
- if (element.__vueParentComponent) {
118
- return element.__vueParentComponent;
119
- }
120
-
121
- return null;
122
- }
123
-
124
- /**
125
- * Método principal que intenta obtener la instancia de Vue usando múltiples estrategias
126
- * @param {string} [selector='#app'] - Selector CSS del elemento que contiene la aplicación Vue
127
- * @returns {VueInstance|null} Instancia de Vue encontrada o null si no se encuentra
128
- */
129
- function getVueInstance(selector = '#app') {
130
- let instance = null;
131
-
132
- // Intentar método 1: Desde elemento específico
133
- instance = getVueInstanceFromElement(selector);
134
- if (instance) {
135
- return instance;
136
- }
137
-
138
- // Intentar método 2: Buscar en DOM
139
- instance = findVueInstanceInDOM();
140
- if (instance) {
141
- return instance;
142
- }
143
-
144
- // Intentar método 3: Desde global
145
- instance = getVueFromGlobal();
146
- if (instance) {
147
- return instance;
148
- } // Intentar método 4: Componente raíz Vue 3
149
- instance = getVue3RootComponent(selector);
150
- if (instance) {
151
- return instance;
152
- }
153
-
154
- return null;
155
- }
156
-
157
- /**
158
- * Espera a que una instancia de Vue esté disponible en el DOM
159
- * @param {string} [selector='#app'] - Selector CSS del elemento que contiene la aplicación Vue
160
- * @param {number} [timeout=5000] - Tiempo máximo de espera en milisegundos
161
- * @returns {Promise<VueInstance>} Promise que resuelve con la instancia de Vue o rechaza si hay timeout
162
- */
163
- function waitForVue(selector = '#app', timeout = 5000) {
164
- return new Promise((resolve, reject) => {
165
- const startTime = Date.now();
166
-
167
- function check() {
168
- const instance = getVueInstance(selector);
169
-
170
- if (instance) {
171
- resolve(instance);
172
- return;
173
- }
174
-
175
- if (Date.now() - startTime > timeout) {
176
- reject(
177
- new Error(
178
- 'Timeout: No se pudo encontrar la instancia de Vue',
179
- ),
180
- );
181
- return;
182
- }
183
-
184
- setTimeout(check, 100);
185
- }
186
-
187
- check();
188
- });
189
- }
190
-
191
- /**
192
- * Obtiene información detallada sobre una instancia de Vue
193
- * @param {VueInstance} instance - Instancia de Vue a analizar
194
- * @returns {VueInstanceInfo|null} Objeto con información detallada de la instancia o null si no es válida
195
- */
196
- function getVueInstanceInfo(instance) {
197
- if (!instance) return null;
198
-
199
- const info = {
200
- version: null,
201
- type: null,
202
- hasRouter: false,
203
- hasStore: false,
204
- components: {},
205
- data: null,
206
- };
207
-
208
- // Detectar versión y tipo
209
- if (instance.version) {
210
- info.version = instance.version;
211
- info.type = 'Vue Constructor';
212
- } else if (instance.config && instance.config.globalProperties) {
213
- info.type = 'Vue 3 App Instance';
214
- info.version = '3.x';
215
- } else if (instance.$options) {
216
- info.type = 'Vue 2 Component Instance';
217
- info.version = '2.x';
218
- }
219
-
220
- // Verificar router
221
- if (
222
- instance.$router ||
223
- (instance.config && instance.config.globalProperties.$router)
224
- ) {
225
- info.hasRouter = true;
226
- }
227
-
228
- // Verificar store (Vuex/Pinia)
229
- if (
230
- instance.$store ||
231
- (instance.config && instance.config.globalProperties.$store)
232
- ) {
233
- info.hasStore = true;
234
- }
235
-
236
- // Obtener componentes (Vue 2)
237
- if (instance.$children) {
238
- info.components = instance.$children.length;
239
- }
240
-
241
- // Obtener data (Vue 2)
242
- if (instance.$data) {
243
- info.data = Object.keys(instance.$data);
244
- }
245
- return info;
246
- }
247
-
248
- /**
249
- * Función principal que obtiene la instancia de Vue con toda la lógica integrada
250
- * @param {string} [selector='#app'] - Selector CSS del elemento que contiene la aplicación Vue
251
- * @param {number} [timeout=3000] - Tiempo máximo de espera en milisegundos
252
- * @returns {Promise<VueInstance|null>} Promise que resuelve con la instancia de Vue o null si no se encuentra
253
- */
254
- async function obtenerInstanciaVue(selector = '#app', timeout = 3000) {
255
- try {
256
- // Intentar obtener la instancia inmediatamente
257
- let instance = getVueInstance(selector);
258
-
259
- if (instance) {
260
- // Obtener información detallada
261
- const info = getVueInstanceInfo(instance);
262
- console.log('✔️ Instancia Vue encontrada:', {
263
- instance,
264
- info,
265
- version: info?.version || 'Desconocida',
266
- type: info?.type || 'Desconocido',
267
- });
268
- return instance;
269
- }
270
-
271
- // Si no se encuentra inmediatamente, esperar
272
- console.log('⏳ Esperando instancia Vue...');
273
- instance = await waitForVue(selector, timeout);
274
-
275
- if (instance) {
276
- const info = getVueInstanceInfo(instance);
277
- console.log('✔️ Instancia Vue encontrada después de esperar:', {
278
- instance,
279
- info,
280
- version: info?.version || 'Desconocida',
281
- type: info?.type || 'Desconocido',
282
- });
283
- return instance;
284
- }
285
-
286
- console.warn('⚠️ No se pudo encontrar la instancia de Vue');
287
- return null;
288
- } catch (error) {
289
- console.error('❌ Error obteniendo instancia Vue:', error);
290
- return null;
291
- }
292
- }
293
-
294
- /**
295
- * Exporta la función principal para obtener instancias de Vue
296
- * @default obtenerInstanciaVue
297
- */
298
- export default obtenerInstanciaVue;
299
-
300
- /**
301
- * Exporta funciones adicionales para uso individual
302
- * @namespace VueInstanceHelpers
303
- */
304
- export {
305
- findVueInstanceInDOM,
306
- getVue3RootComponent,
307
- getVueFromGlobal,
308
- getVueInstance,
309
- getVueInstanceFromElement,
310
- getVueInstanceInfo,
311
- obtenerInstanciaVue,
312
- waitForVue,
313
- };
1
+ function e(e=`#app`){let t=document.querySelector(e);return t?t.__vue_app__?t.__vue_app__:t.__vue__?t.__vue__:null:null}function t(){let e=document.querySelectorAll(`*`);for(let t of e){if(t.__vue_app__)return t.__vue_app__;if(t.__vue__)return t.__vue__}return null}function n(){if(typeof window<`u`){if(window.Vue)return window.Vue;if(window.__VUE_APP_INSTANCE__)return window.__VUE_APP_INSTANCE__;if(window.__VUE_DEVTOOLS_GLOBAL_HOOK__){let e=window.__VUE_DEVTOOLS_GLOBAL_HOOK__.apps;if(e&&e.length>0)return e[0]}}return null}function r(e=`#app`){let t=document.querySelector(e);return t?t._vnode&&t._vnode.component?t._vnode.component:t.__vueParentComponent?t.__vueParentComponent:null:null}function i(i=`#app`){let a=null;return a=e(i),a||(a=t(),a)||(a=n(),a)||(a=r(i),a)?a:null}function a(e=`#app`,t=5e3){return new Promise((n,r)=>{let a=Date.now();function o(){let s=i(e);if(s){n(s);return}if(Date.now()-a>t){r(Error(`Timeout: No se pudo encontrar la instancia de Vue`));return}setTimeout(o,100)}o()})}function o(e){if(!e)return null;let t={version:null,type:null,hasRouter:!1,hasStore:!1,components:{},data:null};return e.version?(t.version=e.version,t.type=`Vue Constructor`):e.config&&e.config.globalProperties?(t.type=`Vue 3 App Instance`,t.version=`3.x`):e.$options&&(t.type=`Vue 2 Component Instance`,t.version=`2.x`),(e.$router||e.config&&e.config.globalProperties.$router)&&(t.hasRouter=!0),(e.$store||e.config&&e.config.globalProperties.$store)&&(t.hasStore=!0),e.$children&&(t.components=e.$children.length),e.$data&&(t.data=Object.keys(e.$data)),t}async function s(e=`#app`,t=3e3){try{let n=i(e);if(n){let e=o(n);return console.log(`✔️ Instancia Vue encontrada:`,{instance:n,info:e,version:e?.version||`Desconocida`,type:e?.type||`Desconocido`}),n}if(console.log(`⏳ Esperando instancia Vue...`),n=await a(e,t),n){let e=o(n);return console.log(`✔️ Instancia Vue encontrada después de esperar:`,{instance:n,info:e,version:e?.version||`Desconocida`,type:e?.type||`Desconocido`}),n}return console.warn(`⚠️ No se pudo encontrar la instancia de Vue`),null}catch(e){return console.error(`❌ Error obteniendo instancia Vue:`,e),null}}export default s;export{t as findVueInstanceInDOM,r as getVue3RootComponent,n as getVueFromGlobal,i as getVueInstance,e as getVueInstanceFromElement,o as getVueInstanceInfo,s as obtenerInstanciaVue,a as waitForVue};
@@ -1,141 +1 @@
1
- /**
2
- * @fileoverview Inicialización del sistema Hot Module Replacement (HMR) para VersaCompiler
3
- * Este archivo maneja la conexión con BrowserSync y configura los listeners para HMR de Vue
4
- */
5
-
6
- /**
7
- * @typedef {Object} ComponentInfo
8
- * @property {string} normalizedPath - Ruta normalizada del componente
9
- * @property {string} nameFile - Nombre del archivo del componente
10
- */
11
-
12
- import { hideErrorOverlay, showErrorOverlay } from './errorScreen.js';
13
- import { obtenerInstanciaVue } from './getInstanciaVue.js';
14
- import { reloadComponent } from './VueHRM.js';
15
-
16
- /**
17
- * Inicializa la conexión socket con BrowserSync y configura los listeners para HMR
18
- * @param {number} [retries=0] - Número de reintentos realizados
19
- * @returns {Promise<void>} Promise que se resuelve cuando la conexión está configurada
20
- */
21
- async function initSocket(retries = 0) {
22
- const maxRetries = 10;
23
- const retryDelay = Math.min(2000 * (retries + 1), 10000); // Backoff exponencial hasta 10s
24
-
25
- // Verificar si BrowserSync está disponible y tiene socket
26
- if (window.___browserSync___ && window.___browserSync___.socket) {
27
- const socket = window.___browserSync___.socket;
28
- let connected = socket.connected; // Verificar estado inicial de conexión
29
-
30
- // Limpiar listeners previos para evitar duplicados
31
- socket.off('connect');
32
- socket.off('disconnect');
33
- socket.off('reloadFull');
34
- socket.off('HRMVue');
35
- socket.off('HRMHelper');
36
- socket.off('error');
37
-
38
- // Configurar listener para eventos de conexión
39
- socket.on('connect', async () => {
40
- connected = true;
41
- hideErrorOverlay();
42
- console.log('✔️ Versa HMR: Socket conectado');
43
- });
44
-
45
- // Configurar listener para eventos de desconexión
46
- socket.on('disconnect', () => {
47
- connected = false;
48
- console.log('❌ Versa HMR: Socket desconectado, reintentando...');
49
- // Lógica de reintentos para desconexión
50
- setTimeout(() => {
51
- if (!socket.connected && retries < maxRetries) {
52
- initSocket(retries + 1);
53
- } else if (!socket.connected) {
54
- console.error(
55
- `❌ Versa HMR: Socket no conectado después de ${maxRetries} reintentos tras desconexión.`,
56
- );
57
- showErrorOverlay(
58
- 'HMR Desconectado',
59
- 'No se pudo reconectar a BrowserSync después de múltiples reintentos.',
60
- );
61
- }
62
- }, retryDelay);
63
- });
64
-
65
- // Configurar listener para recarga completa
66
- socket.on('reloadFull', () => window.location.reload()); // Obtener la instancia de Vue con toda la lógica integrada
67
- let vueInstance = await obtenerInstanciaVue();
68
-
69
- // Configurar listener para HMR de componentes Vue
70
- socket.on('HRMVue', async (/** @type {ComponentInfo} */ data) => {
71
- hideErrorOverlay();
72
- vueInstance = window.__VUE_APP__ || vueInstance;
73
- if (vueInstance) {
74
- console.log('🔥 Preparando HMR para Vue...');
75
- await reloadComponent(vueInstance, data);
76
- } else {
77
- console.log('🔄 Usando método fallback:', vueInstance);
78
- }
79
- });
80
-
81
- // Configurar listener para datos auxiliares de HMR
82
- socket.on('HRMHelper', data => {
83
- //TODO: Implementar lógica de HMRHelper
84
- window.location.reload();
85
- console.log('🔄 Recargando página por HMRHelper:', data);
86
- });
87
-
88
- // Configurar listener para errores de socket
89
- socket.on('error', err => {
90
- console.error('❌ Versa HMR: Error en el socket:', err);
91
- showErrorOverlay(
92
- 'Error de Socket',
93
- 'Se produjo un error en la conexión de BrowserSync.',
94
- );
95
- }); // Watchdog para verificar conexión inicial si el socket existe pero no está conectado
96
- if (!connected) {
97
- console.log(
98
- `Versa HMR: Objeto socket encontrado, intentando conexión (Intento ${
99
- retries + 1
100
- }/${maxRetries})`,
101
- );
102
- setTimeout(() => {
103
- if (!socket.connected && retries <= maxRetries) {
104
- console.warn(
105
- 'Versa HMR: Sin conexión de socket después del tiempo de espera inicial, reintentando initSocket...',
106
- );
107
- initSocket(retries + 1);
108
- } else if (!socket.connected) {
109
- console.error(
110
- `❌ Versa HMR: Socket aún no conectado después de ${maxRetries} intentos iniciales.`,
111
- );
112
- showErrorOverlay(
113
- 'Falló HMR de BrowserSync',
114
- 'No se pudo conectar al socket de BrowserSync después de intentos iniciales.',
115
- );
116
- }
117
- }, 5000); // Timeout de 5s para el watchdog inicial
118
- }
119
- } else {
120
- // BrowserSync no está disponible, intentar reinicializar
121
- console.warn(
122
- `[HMR] Socket de BrowserSync no encontrado o BrowserSync no completamente inicializado. Reintentando initSocket... (${
123
- retries + 1
124
- }/${maxRetries})`,
125
- );
126
- if (retries < maxRetries) {
127
- setTimeout(() => initSocket(retries + 1), retryDelay);
128
- } else {
129
- console.error(
130
- `❌ Versa HMR: Socket de BrowserSync no encontrado después de ${maxRetries} reintentos.`,
131
- );
132
- showErrorOverlay(
133
- 'Falló HMR de BrowserSync',
134
- 'Socket o cliente de BrowserSync no encontrado después de múltiples reintentos.',
135
- );
136
- }
137
- }
138
- }
139
-
140
- // Inicializar el sistema HMR al cargar el script
141
- initSocket();
1
+ import{hideErrorOverlay as e,showErrorOverlay as t}from"./errorScreen.js";import{obtenerInstanciaVue as n}from"./getInstanciaVue.js";import{reloadComponent as r}from"./VueHRM.js";async function i(a=0){let o=10,s=Math.min(2e3*(a+1),1e4);if(window.___browserSync___&&window.___browserSync___.socket){let o=window.___browserSync___.socket,c=o.connected;o.off(`connect`),o.off(`disconnect`),o.off(`reloadFull`),o.off(`HRMVue`),o.off(`HRMHelper`),o.off(`error`),o.on(`connect`,async()=>{c=!0,e(),console.log(`✔️ Versa HMR: Socket conectado`)}),o.on(`disconnect`,()=>{c=!1,console.log(`❌ Versa HMR: Socket desconectado, reintentando...`),setTimeout(()=>{!o.connected&&a<10?i(a+1):o.connected||(console.error(`❌ Versa HMR: Socket no conectado después de 10 reintentos tras desconexión.`),t(`HMR Desconectado`,`No se pudo reconectar a BrowserSync después de múltiples reintentos.`))},s)}),o.on(`reloadFull`,()=>window.location.reload());let l=await n();o.on(`HRMVue`,async t=>{e(),l=window.__VUE_APP__||l,l?(console.log(`🔥 Preparando HMR para Vue...`),await r(l,t)):console.log(`🔄 Usando método fallback:`,l)}),o.on(`HRMHelper`,e=>{window.location.reload(),console.log(`🔄 Recargando página por HMRHelper:`,e)}),o.on(`error`,e=>{console.error(`❌ Versa HMR: Error en el socket:`,e),t(`Error de Socket`,`Se produjo un error en la conexión de BrowserSync.`)}),c||(console.log(`Versa HMR: Objeto socket encontrado, intentando conexión (Intento ${a+1}/10)`),setTimeout(()=>{!o.connected&&a<=10?(console.warn(`Versa HMR: Sin conexión de socket después del tiempo de espera inicial, reintentando initSocket...`),i(a+1)):o.connected||(console.error(`❌ Versa HMR: Socket aún no conectado después de 10 intentos iniciales.`),t(`Falló HMR de BrowserSync`,`No se pudo conectar al socket de BrowserSync después de intentos iniciales.`))},5e3))}else console.warn(`[HMR] Socket de BrowserSync no encontrado o BrowserSync no completamente inicializado. Reintentando initSocket... (${a+1}/10)`),a<10?setTimeout(()=>i(a+1),s):(console.error(`❌ Versa HMR: Socket de BrowserSync no encontrado después de 10 reintentos.`),t(`Falló HMR de BrowserSync`,`Socket o cliente de BrowserSync no encontrado después de múltiples reintentos.`))}i();