versacompiler 2.1.0 → 2.2.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 (41) hide show
  1. package/README.md +1 -1
  2. package/dist/compiler/compile.js +2520 -25
  3. package/dist/compiler/error-reporter.js +467 -38
  4. package/dist/compiler/linter.js +72 -1
  5. package/dist/compiler/minify.js +272 -1
  6. package/dist/compiler/minifyTemplate.js +230 -1
  7. package/dist/compiler/module-resolution-optimizer.js +844 -1
  8. package/dist/compiler/parser.js +336 -1
  9. package/dist/compiler/performance-monitor.js +204 -56
  10. package/dist/compiler/tailwindcss.js +39 -1
  11. package/dist/compiler/transform-optimizer.js +392 -1
  12. package/dist/compiler/transformTStoJS.js +16 -1
  13. package/dist/compiler/transforms.js +554 -1
  14. package/dist/compiler/typescript-compiler.js +172 -2
  15. package/dist/compiler/typescript-error-parser.js +281 -10
  16. package/dist/compiler/typescript-manager.js +304 -2
  17. package/dist/compiler/typescript-sync-validator.js +295 -31
  18. package/dist/compiler/typescript-worker-pool.js +936 -1
  19. package/dist/compiler/typescript-worker-thread.cjs +466 -22
  20. package/dist/compiler/typescript-worker.js +339 -1
  21. package/dist/compiler/vuejs.js +396 -37
  22. package/dist/hrm/VueHRM.js +359 -1
  23. package/dist/hrm/errorScreen.js +83 -1
  24. package/dist/hrm/getInstanciaVue.js +313 -1
  25. package/dist/hrm/initHRM.js +586 -1
  26. package/dist/main.js +353 -7
  27. package/dist/servicios/browserSync.js +589 -2
  28. package/dist/servicios/file-watcher.js +425 -4
  29. package/dist/servicios/logger.js +63 -3
  30. package/dist/servicios/readConfig.js +399 -53
  31. package/dist/utils/excluded-modules.js +37 -1
  32. package/dist/utils/module-resolver.js +466 -1
  33. package/dist/utils/promptUser.js +48 -2
  34. package/dist/utils/proxyValidator.js +68 -1
  35. package/dist/utils/resolve-bin.js +58 -1
  36. package/dist/utils/utils.js +21 -1
  37. package/dist/utils/vue-types-setup.js +435 -241
  38. package/dist/wrappers/eslint-node.js +1 -1
  39. package/dist/wrappers/oxlint-node.js +122 -1
  40. package/dist/wrappers/tailwind-node.js +94 -1
  41. package/package.json +106 -103
@@ -1,38 +1,467 @@
1
- let e;function t(){function e(){let t=e=>String(e),n=`reset.bold.dim.italic.underline.strikethrough.inverse.hidden.visible.black.red.green.yellow.blue.magenta.cyan.white.gray.grey.blackBright.redBright.greenBright.yellowBright.blueBright.magentaBright.cyanBright.whiteBright.bgBlack.bgRed.bgGreen.bgYellow.bgBlue.bgMagenta.bgCyan.bgWhite.bgGray.bgGrey.bgBlackBright.bgRedBright.bgGreenBright.bgYellowBright.bgBlueBright.bgMagentaBright.bgCyanBright.bgWhiteBright`.split(`.`);return n.forEach(n=>{Object.defineProperty(t,n,{get(){return e()},enumerable:!0,configurable:!0})}),new Proxy(t,{apply(e,t,n){return String(n[0]||``)},get(t,r){if(typeof r==`string`||typeof r==`symbol`)return typeof r==`string`&&n.includes(r)?e():t[r]}})}return e()}function n(){return e||(e=t()),e}export class ErrorReporter{options;constructor(e={}){this.options={showLineNumbers:e.showLineNumbers??!0,showCodeContext:e.showCodeContext??!0,contextLines:e.contextLines??2,colorize:e.colorize??!0}}analyzeParsingError(e,t,n){let r={file:n,message:e.message||`Error de parsing desconocido`,severity:`error`};if(e.labels&&e.labels.length>0){let n=e.labels[0];if(n.start!==void 0){let e=this.getLineAndColumnFromOffset(t,n.start);r.line=e.line,r.column=e.column}}else if(e.span){let n=this.getLineAndColumnFromSpan(t,e.span.start);r.line=n.line,r.column=n.column}else if(e.offset!==void 0){let n=this.getLineAndColumnFromOffset(t,e.offset);r.line=n.line,r.column=n.column}return this.options.showCodeContext&&r.line&&t&&(r.codeContext=this.generateCodeContext(t,r.line,r.column)),r.suggestion=this.generateIntelligentSuggestion(e.message,t,r.line,r.column),e.code&&(r.errorCode=e.code),e.codeframe&&(r.codeContext=this.combineWithOxcCodeframe(r.codeContext,e.codeframe)),r}getLineAndColumnFromSpan(e,t){return this.getLineAndColumnFromOffset(e,t)}getLineAndColumnFromOffset(e,t){let n=e.split(`
2
- `),r=0,i=1,a=1;for(let e=0;e<n.length;e++){let o=n[e];if(o===void 0)continue;let s=o.length+1;if(r+s>t){i=e+1,a=t-r+1;break}r+=s}return{line:i,column:a}}generateCodeContext(e,t,r){let i=e.split(`
3
- `),a=Math.max(1,t-this.options.contextLines),o=Math.min(i.length,t+this.options.contextLines),s=n(),c=`
4
- `+s.dim(`Contexto del código:`)+`
5
- `;for(let e=a;e<=o;e++){let n=i[e-1]||``,a=e.toString().padStart(3,` `);if(e===t){if(this.options.colorize){if(c+=s.red(`${a} ❌ ${n}\n`),r){let e=` `.repeat(6+(r-1)),t=s.red(`^`);c+=`${e}${t}\n`}}else if(c+=`${a} ❌ ${n}\n`,r){let e=` `.repeat(6+(r-1));c+=`${e}^\n`}}else{let e=this.options.colorize?s.dim:e=>e;c+=e(`${a} ${n}\n`)}}return c}generateSuggestion(e){let t=e.toLowerCase();if(t.includes(`unexpected`)&&t.includes(`identifier`))return`Verifica si hay una coma faltante antes del identificador o si la línea anterior no está completa.`;if(t.includes(`expected`)&&t.includes(`but found`))return`Revisa la sintaxis alrededor de este punto. Puede faltar un carácter específico.`;if(t.includes(`missing`)){if(t.includes(`semicolon`))return`Agrega un punto y coma (;) al final de la declaración.`;if(t.includes(`comma`))return`Verifica si falta una coma (,) en una lista o declaración.`;if(t.includes(`parenthesis`))return`Verifica que los paréntesis estén balanceados.`}return t.includes(`import`)||t.includes(`export`)?`Revisa la sintaxis de import/export. Las líneas pueden estar cortadas o malformadas.`:t.includes(`const`)&&t.includes(`initializer`)?`Las declaraciones const requieren un valor inicial. Ejemplos válidos:
6
- const variable = "valor";
7
- const numero = 42;
8
- const objeto = { propiedad: "valor" };`:`Revisa la sintaxis del código alrededor de esta ubicación.`}combineWithOxcCodeframe(e,t){if(!e)return t;let r=n();return e+`
9
- `+r.dim(`Codeframe de oxc-parser:`)+`
10
- `+t}formatError(e){let t=``,r=e.severity.toUpperCase(),i=n(),a=e.severity===`error`?i.red:e.severity===`warning`?i.yellow:i.blue;if(this.options.colorize?t+=a(`[${r}]`)+` en ${i.cyan(e.file)}`:t+=`[${r}] en ${e.file}`,e.line){let n=e.column?`línea ${e.line}, columna ${e.column}`:`línea ${e.line}`;this.options.colorize?t+=` (${i.dim(n)})`:t+=` (${n})`}return t+=`
11
- `,this.options.colorize?t+=`💥 ${i.bold(e.message)}\n`:t+=`💥 ${e.message}\n`,e.errorCode&&(this.options.colorize?t+=i.dim(` Código: ${e.errorCode}\n`):t+=` Código: ${e.errorCode}\n`),e.codeContext&&(t+=e.codeContext),e.suggestion&&(this.options.colorize?t+=`\n💡 ${i.yellow(`Sugerencia:`)} ${e.suggestion}\n`:t+=`\n💡 Sugerencia: ${e.suggestion}\n`),t}analyzeMultipleErrors(e,t,n){return e.map(e=>this.analyzeParsingError(e,t,n))}formatMultipleErrors(e){if(e.length===0)return`No se encontraron errores.`;let t=n(),r=``;return this.options.colorize?r+=t.bold.red(`\n🚨 Se encontraron ${e.length} error(es) de parsing:\n\n`):r+=`\n🚨 Se encontraron ${e.length} error(es) de parsing:\n\n`,e.forEach((n,i)=>{r+=this.formatError(n),i<e.length-1&&(this.options.colorize?r+=t.dim(`─`.repeat(60))+`
12
-
13
- `:r+=`─`.repeat(60)+`
14
-
15
- `)}),r}generateIntelligentSuggestion(e,t,n,r){let i=e.toLowerCase();if(n&&t){let e=t.split(`
16
- `),r=e[n-1]||``,a=n>1&&e[n-2]||``;if(i.includes(`const`)&&i.includes(`initializer`))return r.trim().match(/^const\s+[a-zA-Z_][a-zA-Z0-9_]*\s*;/)?`Declaración const incompleta. Agrega un valor inicial:
17
- • const `+r.match(/const\s+([a-zA-Z_][a-zA-Z0-9_]*)/)?.[1]+` = "valor";
18
- • const `+r.match(/const\s+([a-zA-Z_][a-zA-Z0-9_]*)/)?.[1]+` = 42;
19
- • O cambia a "let" si planeas asignar después`:r.includes(`=`)&&!r.trim().endsWith(`;`)?`Parece que la declaración const está incompleta. Verifica:
20
- • Que la expresión del lado derecho esté completa
21
- • Que termine con punto y coma (;)
22
- • Que no falten paréntesis o comillas`:`Las declaraciones const requieren un valor inicial:
23
- • const variable = "valor";
24
- • const numero = 42;
25
- • const objeto = { propiedad: "valor" };
26
- • const array = [1, 2, 3];`;if(i.includes(`unexpected`)&&i.includes(`identifier`)){if(a.trim()&&!a.trim().endsWith(`;`)&&!a.trim().endsWith(`{`)&&!a.trim().endsWith(`}`))return`La línea anterior parece incompleta. Verifica:
27
- • Que termine con punto y coma (;)
28
- • Que no falten operadores o comas
29
- • Que los paréntesis estén balanceados`;if(r.includes(`,`)&&!r.includes(`=`))return`Posible error en declaración de múltiples variables:
30
- • const a = 1, b = 2; (para const)
31
- • let a, b; a = 1; b = 2; (para let)
32
- • Verifica que cada variable tenga su valor asignado`}if(i.includes(`import`)||i.includes(`export`)){if(r.includes(`import`)&&!r.includes(`from`))return`Import statement incompleto:
33
- • import { item } from "modulo";
34
- • import defaultItem from "modulo";
35
- • import * as alias from "modulo";`;if(r.includes(`export`)&&r.trim().endsWith(`export`))return`Export statement incompleto:
36
- • export { item };
37
- • export default item;
38
- • export const item = valor;`}if(i.includes(`expected`)){let e=(r.match(/\(/g)||[]).length,t=(r.match(/\)/g)||[]).length,n=(r.match(/\{/g)||[]).length,i=(r.match(/\}/g)||[]).length;if(e!==t)return`Paréntesis desbalanceados (${e} abiertos, ${t} cerrados):\n • Verifica que cada ( tenga su correspondiente )\n • Revisa llamadas a funciones y expresiones`;if(n!==i)return`Llaves desbalanceadas (${n} abiertas, ${i} cerradas):\n • Verifica que cada { tenga su correspondiente }\n • Revisa objetos, funciones y bloques de código`}}return this.generateSuggestion(e)}}export const defaultErrorReporter=new ErrorReporter({showLineNumbers:!0,showCodeContext:!0,contextLines:2,colorize:!0});export function analyzeAndFormatError(e,t,n,a){let o=a?new ErrorReporter(a):defaultErrorReporter,s=o.analyzeParsingError(e,t,n);return o.formatError(s)}export function analyzeAndFormatMultipleErrors(e,t,n,a){let o=a?new ErrorReporter(a):defaultErrorReporter,s=o.analyzeMultipleErrors(e,t,n);return o.formatMultipleErrors(s)}
1
+ // Lazy loading optimizations - Only import lightweight modules synchronously
2
+ // Heavy dependencies will be loaded dynamically when needed
3
+ let chalk;
4
+ // Función que proporciona chalk sin color como fallback
5
+ function createChalkFallback() {
6
+ // Crear una función que siempre retorna el texto sin modificar
7
+ function createChainableFunction() {
8
+ const fn = (text) => String(text);
9
+ // Lista de métodos de chalk que deben ser encadenables
10
+ const methods = [
11
+ 'reset',
12
+ 'bold',
13
+ 'dim',
14
+ 'italic',
15
+ 'underline',
16
+ 'strikethrough',
17
+ 'inverse',
18
+ 'hidden',
19
+ 'visible',
20
+ 'black',
21
+ 'red',
22
+ 'green',
23
+ 'yellow',
24
+ 'blue',
25
+ 'magenta',
26
+ 'cyan',
27
+ 'white',
28
+ 'gray',
29
+ 'grey',
30
+ 'blackBright',
31
+ 'redBright',
32
+ 'greenBright',
33
+ 'yellowBright',
34
+ 'blueBright',
35
+ 'magentaBright',
36
+ 'cyanBright',
37
+ 'whiteBright',
38
+ 'bgBlack',
39
+ 'bgRed',
40
+ 'bgGreen',
41
+ 'bgYellow',
42
+ 'bgBlue',
43
+ 'bgMagenta',
44
+ 'bgCyan',
45
+ 'bgWhite',
46
+ 'bgGray',
47
+ 'bgGrey',
48
+ 'bgBlackBright',
49
+ 'bgRedBright',
50
+ 'bgGreenBright',
51
+ 'bgYellowBright',
52
+ 'bgBlueBright',
53
+ 'bgMagentaBright',
54
+ 'bgCyanBright',
55
+ 'bgWhiteBright',
56
+ ];
57
+ // Añadir todos los métodos como propiedades que retornan nuevas funciones encadenables
58
+ methods.forEach(method => {
59
+ Object.defineProperty(fn, method, {
60
+ get() {
61
+ return createChainableFunction();
62
+ },
63
+ enumerable: true,
64
+ configurable: true,
65
+ });
66
+ });
67
+ // Hacer que la función misma sea callable
68
+ return new Proxy(fn, {
69
+ apply(target, thisArg, argumentsList) {
70
+ return String(argumentsList[0] || '');
71
+ },
72
+ get(target, prop) {
73
+ // Verificar si es una propiedad de la función
74
+ if (typeof prop === 'string' || typeof prop === 'symbol') {
75
+ // Si es un método de chalk, retorna una nueva función encadenable
76
+ if (typeof prop === 'string' && methods.includes(prop)) {
77
+ return createChainableFunction();
78
+ }
79
+ // Retornar propiedades existentes de la función
80
+ return target[prop];
81
+ }
82
+ return undefined;
83
+ },
84
+ });
85
+ }
86
+ return createChainableFunction();
87
+ }
88
+ // Obtener chalk de forma síncrona con fallback
89
+ function getChalkSync() {
90
+ if (!chalk) {
91
+ // Si no tenemos chalk cargado, usar fallback
92
+ chalk = createChalkFallback();
93
+ }
94
+ return chalk;
95
+ }
96
+ /**
97
+ * Clase para generar reportes detallados de errores de parsing
98
+ */
99
+ export class ErrorReporter {
100
+ options;
101
+ constructor(options = {}) {
102
+ this.options = {
103
+ showLineNumbers: options.showLineNumbers ?? true,
104
+ showCodeContext: options.showCodeContext ?? true,
105
+ contextLines: options.contextLines ?? 2,
106
+ colorize: options.colorize ?? true,
107
+ };
108
+ }
109
+ /**
110
+ * Analiza un error de oxc-parser y extrae información detallada
111
+ */
112
+ analyzeParsingError(error, sourceCode, fileName) {
113
+ const detailedError = {
114
+ file: fileName,
115
+ message: error.message || 'Error de parsing desconocido',
116
+ severity: 'error',
117
+ };
118
+ // Intentar extraer información de ubicación del error
119
+ if (error.labels && error.labels.length > 0) {
120
+ // oxc-parser proporciona información en labels
121
+ const label = error.labels[0];
122
+ if (label.start !== undefined) {
123
+ const position = this.getLineAndColumnFromOffset(sourceCode, label.start);
124
+ detailedError.line = position.line;
125
+ detailedError.column = position.column;
126
+ }
127
+ }
128
+ else if (error.span) {
129
+ // oxc-parser también puede proporcionar información de span
130
+ const position = this.getLineAndColumnFromSpan(sourceCode, error.span.start);
131
+ detailedError.line = position.line;
132
+ detailedError.column = position.column;
133
+ }
134
+ else if (error.offset !== undefined) {
135
+ // Si tenemos un offset, calculamos línea y columna
136
+ const position = this.getLineAndColumnFromOffset(sourceCode, error.offset);
137
+ detailedError.line = position.line;
138
+ detailedError.column = position.column;
139
+ }
140
+ // Agregar contexto del código si está disponible
141
+ if (this.options.showCodeContext && detailedError.line && sourceCode) {
142
+ detailedError.codeContext = this.generateCodeContext(sourceCode, detailedError.line, detailedError.column);
143
+ }
144
+ // Detectar patrones específicos de errores para sugerencias más inteligentes
145
+ detailedError.suggestion = this.generateIntelligentSuggestion(error.message, sourceCode, detailedError.line, detailedError.column);
146
+ // Extraer código de error si está disponible
147
+ if (error.code) {
148
+ detailedError.errorCode = error.code;
149
+ }
150
+ // Si oxc-parser ya proporciona un codeframe, usarlo como referencia adicional
151
+ if (error.codeframe) {
152
+ detailedError.codeContext = this.combineWithOxcCodeframe(detailedError.codeContext, error.codeframe);
153
+ }
154
+ return detailedError;
155
+ }
156
+ /**
157
+ * Calcula línea y columna desde un span de oxc-parser
158
+ */
159
+ getLineAndColumnFromSpan(sourceCode, spanStart) {
160
+ return this.getLineAndColumnFromOffset(sourceCode, spanStart);
161
+ }
162
+ /**
163
+ * Calcula línea y columna desde un offset
164
+ */
165
+ getLineAndColumnFromOffset(sourceCode, offset) {
166
+ const lines = sourceCode.split('\n');
167
+ let currentOffset = 0;
168
+ let line = 1;
169
+ let column = 1;
170
+ for (let i = 0; i < lines.length; i++) {
171
+ const currentLine = lines[i];
172
+ if (currentLine === undefined)
173
+ continue;
174
+ const lineLength = currentLine.length + 1; // +1 para el \n
175
+ if (currentOffset + lineLength > offset) {
176
+ line = i + 1;
177
+ column = offset - currentOffset + 1;
178
+ break;
179
+ }
180
+ currentOffset += lineLength;
181
+ }
182
+ return { line, column };
183
+ }
184
+ /**
185
+ * Genera contexto del código alrededor del error
186
+ */
187
+ generateCodeContext(sourceCode, errorLine, errorColumn) {
188
+ const lines = sourceCode.split('\n');
189
+ const startLine = Math.max(1, errorLine - this.options.contextLines);
190
+ const endLine = Math.min(lines.length, errorLine + this.options.contextLines);
191
+ const chalkSync = getChalkSync();
192
+ let context = '\n' + chalkSync.dim('Contexto del código:') + '\n';
193
+ for (let i = startLine; i <= endLine; i++) {
194
+ const lineContent = lines[i - 1] || '';
195
+ const lineNumber = i.toString().padStart(3, ' ');
196
+ const isErrorLine = i === errorLine;
197
+ if (isErrorLine) {
198
+ if (this.options.colorize) {
199
+ context += chalkSync.red(`${lineNumber} ❌ ${lineContent}\n`);
200
+ // Agregar flecha apuntando al error si tenemos la columna
201
+ if (errorColumn) {
202
+ const spaces = ' '.repeat(6 + (errorColumn - 1));
203
+ const arrow = chalkSync.red('^');
204
+ context += `${spaces}${arrow}\n`;
205
+ }
206
+ }
207
+ else {
208
+ context += `${lineNumber} ❌ ${lineContent}\n`;
209
+ if (errorColumn) {
210
+ const spaces = ' '.repeat(6 + (errorColumn - 1));
211
+ context += `${spaces}^\n`;
212
+ }
213
+ }
214
+ }
215
+ else {
216
+ const prefix = this.options.colorize
217
+ ? chalkSync.dim
218
+ : (s) => s;
219
+ context += prefix(`${lineNumber} ${lineContent}\n`);
220
+ }
221
+ }
222
+ return context;
223
+ }
224
+ /**
225
+ * Genera sugerencias basadas en el mensaje de error
226
+ */
227
+ generateSuggestion(errorMessage) {
228
+ const message = errorMessage.toLowerCase();
229
+ if (message.includes('unexpected') && message.includes('identifier')) {
230
+ return 'Verifica si hay una coma faltante antes del identificador o si la línea anterior no está completa.';
231
+ }
232
+ if (message.includes('expected') && message.includes('but found')) {
233
+ return 'Revisa la sintaxis alrededor de este punto. Puede faltar un carácter específico.';
234
+ }
235
+ if (message.includes('missing')) {
236
+ if (message.includes('semicolon')) {
237
+ return 'Agrega un punto y coma (;) al final de la declaración.';
238
+ }
239
+ if (message.includes('comma')) {
240
+ return 'Verifica si falta una coma (,) en una lista o declaración.';
241
+ }
242
+ if (message.includes('parenthesis')) {
243
+ return 'Verifica que los paréntesis estén balanceados.';
244
+ }
245
+ }
246
+ if (message.includes('import') || message.includes('export')) {
247
+ return 'Revisa la sintaxis de import/export. Las líneas pueden estar cortadas o malformadas.';
248
+ }
249
+ if (message.includes('const') && message.includes('initializer')) {
250
+ return 'Las declaraciones const requieren un valor inicial. Ejemplos válidos:\n • const variable = "valor";\n • const numero = 42;\n • const objeto = { propiedad: "valor" };';
251
+ }
252
+ return 'Revisa la sintaxis del código alrededor de esta ubicación.';
253
+ }
254
+ /**
255
+ * Combina nuestro contexto de código con el codeframe de oxc-parser
256
+ */
257
+ combineWithOxcCodeframe(ourContext, oxcCodeframe) {
258
+ if (!ourContext) {
259
+ return oxcCodeframe;
260
+ }
261
+ // Si ya tenemos nuestro contexto, podemos agregar el de oxc como referencia adicional
262
+ const chalkSync = getChalkSync();
263
+ return (ourContext +
264
+ '\n' +
265
+ chalkSync.dim('Codeframe de oxc-parser:') +
266
+ '\n' +
267
+ oxcCodeframe);
268
+ }
269
+ /**
270
+ * Formatea un error detallado como texto legible
271
+ */
272
+ formatError(error) {
273
+ let output = '';
274
+ // Encabezado del error
275
+ const severity = error.severity.toUpperCase();
276
+ const chalkSync = getChalkSync();
277
+ const severityColor = error.severity === 'error'
278
+ ? chalkSync.red
279
+ : error.severity === 'warning'
280
+ ? chalkSync.yellow
281
+ : chalkSync.blue;
282
+ if (this.options.colorize) {
283
+ output +=
284
+ severityColor(`[${severity}]`) +
285
+ ` en ${chalkSync.cyan(error.file)}`;
286
+ }
287
+ else {
288
+ output += `[${severity}] en ${error.file}`;
289
+ }
290
+ // Ubicación específica
291
+ if (error.line) {
292
+ const location = error.column
293
+ ? `línea ${error.line}, columna ${error.column}`
294
+ : `línea ${error.line}`;
295
+ if (this.options.colorize) {
296
+ output += ` (${chalkSync.dim(location)})`;
297
+ }
298
+ else {
299
+ output += ` (${location})`;
300
+ }
301
+ }
302
+ output += '\n';
303
+ // Mensaje de error
304
+ if (this.options.colorize) {
305
+ output += `💥 ${chalkSync.bold(error.message)}\n`;
306
+ }
307
+ else {
308
+ output += `💥 ${error.message}\n`;
309
+ }
310
+ // Código de error si está disponible
311
+ if (error.errorCode) {
312
+ if (this.options.colorize) {
313
+ output += chalkSync.dim(` Código: ${error.errorCode}\n`);
314
+ }
315
+ else {
316
+ output += ` Código: ${error.errorCode}\n`;
317
+ }
318
+ }
319
+ // Contexto del código
320
+ if (error.codeContext) {
321
+ output += error.codeContext;
322
+ }
323
+ // Sugerencia
324
+ if (error.suggestion) {
325
+ if (this.options.colorize) {
326
+ output += `\n💡 ${chalkSync.yellow('Sugerencia:')} ${error.suggestion}\n`;
327
+ }
328
+ else {
329
+ output += `\n💡 Sugerencia: ${error.suggestion}\n`;
330
+ }
331
+ }
332
+ return output;
333
+ }
334
+ /**
335
+ * Analiza múltiples errores de un resultado de parsing
336
+ */
337
+ analyzeMultipleErrors(errors, sourceCode, fileName) {
338
+ return errors.map(error => this.analyzeParsingError(error, sourceCode, fileName));
339
+ }
340
+ /**
341
+ * Formatea múltiples errores como un reporte completo
342
+ */
343
+ formatMultipleErrors(errors) {
344
+ if (errors.length === 0) {
345
+ return 'No se encontraron errores.';
346
+ }
347
+ const chalkSync = getChalkSync();
348
+ let output = '';
349
+ if (this.options.colorize) {
350
+ output += chalkSync.bold.red(`\n🚨 Se encontraron ${errors.length} error(es) de parsing:\n\n`);
351
+ }
352
+ else {
353
+ output += `\n🚨 Se encontraron ${errors.length} error(es) de parsing:\n\n`;
354
+ }
355
+ errors.forEach((error, index) => {
356
+ output += this.formatError(error);
357
+ // Separador entre errores (excepto el último)
358
+ if (index < errors.length - 1) {
359
+ if (this.options.colorize) {
360
+ output += chalkSync.dim('─'.repeat(60)) + '\n\n';
361
+ }
362
+ else {
363
+ output += '─'.repeat(60) + '\n\n';
364
+ }
365
+ }
366
+ });
367
+ return output;
368
+ } /**
369
+ * Genera sugerencias más inteligentes basadas en análisis contextual del error
370
+ */
371
+ generateIntelligentSuggestion(errorMessage, sourceCode, line, _column) {
372
+ const message = errorMessage.toLowerCase();
373
+ // Análisis contextual del código si tenemos la línea
374
+ if (line && sourceCode) {
375
+ const lines = sourceCode.split('\n');
376
+ const errorLine = lines[line - 1] || '';
377
+ const prevLine = line > 1 ? lines[line - 2] || '' : '';
378
+ // Análisis específico para declaraciones const
379
+ if (message.includes('const') && message.includes('initializer')) {
380
+ // Detectar el tipo de error específico analizando el contexto
381
+ if (errorLine
382
+ .trim()
383
+ .match(/^const\s+[a-zA-Z_][a-zA-Z0-9_]*\s*;/)) {
384
+ return ('Declaración const incompleta. Agrega un valor inicial:\n • const ' +
385
+ errorLine.match(/const\s+([a-zA-Z_][a-zA-Z0-9_]*)/)?.[1] +
386
+ ' = "valor";\n • const ' +
387
+ errorLine.match(/const\s+([a-zA-Z_][a-zA-Z0-9_]*)/)?.[1] +
388
+ ' = 42;\n • O cambia a "let" si planeas asignar después');
389
+ }
390
+ if (errorLine.includes('=') &&
391
+ !errorLine.trim().endsWith(';')) {
392
+ return 'Parece que la declaración const está incompleta. Verifica:\n • Que la expresión del lado derecho esté completa\n • Que termine con punto y coma (;)\n • Que no falten paréntesis o comillas';
393
+ }
394
+ return 'Las declaraciones const requieren un valor inicial:\n • const variable = "valor";\n • const numero = 42;\n • const objeto = { propiedad: "valor" };\n • const array = [1, 2, 3];';
395
+ }
396
+ // Análisis para identificadores inesperados
397
+ if (message.includes('unexpected') &&
398
+ message.includes('identifier')) {
399
+ if (prevLine.trim() &&
400
+ !prevLine.trim().endsWith(';') &&
401
+ !prevLine.trim().endsWith('{') &&
402
+ !prevLine.trim().endsWith('}')) {
403
+ return 'La línea anterior parece incompleta. Verifica:\n • Que termine con punto y coma (;)\n • Que no falten operadores o comas\n • Que los paréntesis estén balanceados';
404
+ }
405
+ if (errorLine.includes(',') && !errorLine.includes('=')) {
406
+ return 'Posible error en declaración de múltiples variables:\n • const a = 1, b = 2; (para const)\n • let a, b; a = 1; b = 2; (para let)\n • Verifica que cada variable tenga su valor asignado';
407
+ }
408
+ }
409
+ // Análisis para import/export malformados
410
+ if (message.includes('import') || message.includes('export')) {
411
+ if (errorLine.includes('import') &&
412
+ !errorLine.includes('from')) {
413
+ return 'Import statement incompleto:\n • import { item } from "modulo";\n • import defaultItem from "modulo";\n • import * as alias from "modulo";';
414
+ }
415
+ if (errorLine.includes('export') &&
416
+ errorLine.trim().endsWith('export')) {
417
+ return 'Export statement incompleto:\n • export { item };\n • export default item;\n • export const item = valor;';
418
+ }
419
+ }
420
+ // Análisis para paréntesis y brackets
421
+ if (message.includes('expected')) {
422
+ const openParens = (errorLine.match(/\(/g) || []).length;
423
+ const closeParens = (errorLine.match(/\)/g) || []).length;
424
+ const openBrackets = (errorLine.match(/\{/g) || []).length;
425
+ const closeBrackets = (errorLine.match(/\}/g) || []).length;
426
+ if (openParens !== closeParens) {
427
+ return `Paréntesis desbalanceados (${openParens} abiertos, ${closeParens} cerrados):\n • Verifica que cada ( tenga su correspondiente )\n • Revisa llamadas a funciones y expresiones`;
428
+ }
429
+ if (openBrackets !== closeBrackets) {
430
+ return `Llaves desbalanceadas (${openBrackets} abiertas, ${closeBrackets} cerradas):\n • Verifica que cada { tenga su correspondiente }\n • Revisa objetos, funciones y bloques de código`;
431
+ }
432
+ }
433
+ }
434
+ // Fallback a sugerencias básicas si no hay análisis contextual específico
435
+ return this.generateSuggestion(errorMessage);
436
+ }
437
+ }
438
+ /**
439
+ * Instancia predeterminada del reporter con configuración estándar
440
+ */
441
+ export const defaultErrorReporter = new ErrorReporter({
442
+ showLineNumbers: true,
443
+ showCodeContext: true,
444
+ contextLines: 2,
445
+ colorize: true,
446
+ });
447
+ /**
448
+ * Función helper para analizar y formatear rápidamente un error
449
+ */
450
+ export function analyzeAndFormatError(error, sourceCode, fileName, options) {
451
+ const reporter = options
452
+ ? new ErrorReporter(options)
453
+ : defaultErrorReporter;
454
+ const detailedError = reporter.analyzeParsingError(error, sourceCode, fileName);
455
+ return reporter.formatError(detailedError);
456
+ }
457
+ /**
458
+ * Función helper para analizar y formatear múltiples errores
459
+ */
460
+ export function analyzeAndFormatMultipleErrors(errors, sourceCode, fileName, options) {
461
+ const reporter = options
462
+ ? new ErrorReporter(options)
463
+ : defaultErrorReporter;
464
+ const detailedErrors = reporter.analyzeMultipleErrors(errors, sourceCode, fileName);
465
+ return reporter.formatMultipleErrors(detailedErrors);
466
+ }
467
+ //# sourceMappingURL=error-reporter.js.map
@@ -1 +1,72 @@
1
- import{env as e}from"node:process";import{logger as t}from"../servicios/logger.js";import{ESLintNode as n}from"./../wrappers/eslint-node.js";import{OxlintNode as r}from"./../wrappers/oxlint-node.js";export async function OxLint(n={}){try{if(!n||!n.bin)return t.warn(`⚠️ Oxlint no se ejecutará: falta la propiedad "bin" en la configuración.`),!1;let i=new r({binPath:n.bin,configFile:n.configFile,fix:n.fix||!1,formats:[`json`],tsconfigPath:e.tsconfigFile||`./tsconfig.json`,...n.oxlintConfig}),a=n.paths||[e.PATH_SOURCE||`./src`];return await i.run(a)}catch(e){throw t.error(`❌ :Error al compilar OxLint:`,e),e}}export async function ESLint(e={}){try{if(!e||!e.bin)return t.warn(`⚠️ ESLint no se ejecutará: falta la propiedad "bin" en la configuración.`),{json:{results:[],errorCount:0,warningCount:0,fixableErrorCount:0,fixableWarningCount:0,fatalErrorCount:0}};let r=new n({binPath:e.bin,configFile:e.configFile,fix:e.fix||!1,extensions:[`.vue`,`.ts`,`.js`],formats:e.format?[e.format]:[`stylish`,`json`],cache:!0,maxWarnings:100,...e.eslintConfig}),i=e.paths||[`src/`];return await r.run(i)}catch(e){throw t.error(`❌ Error al ejecutar ESLint:`,e),e}}
1
+ import { env } from 'node:process';
2
+ import { logger } from '../servicios/logger.js';
3
+ import { ESLintNode, } from './../wrappers/eslint-node.js';
4
+ import { OxlintNode } from './../wrappers/oxlint-node.js';
5
+ export async function OxLint(oxlintConfig = {}) {
6
+ try {
7
+ if (!oxlintConfig || !oxlintConfig.bin) {
8
+ // configFile es opcional si Oxlint lo encuentra por defecto
9
+ logger.warn('⚠️ Oxlint no se ejecutará: falta la propiedad "bin" en la configuración.');
10
+ return false; // O un resultado que indique fallo/no ejecución
11
+ }
12
+ const oxlintRunner = new OxlintNode({
13
+ binPath: oxlintConfig.bin, // Usar bin de LinterConfig
14
+ configFile: oxlintConfig.configFile, // Usar configFile de LinterConfig
15
+ fix: oxlintConfig.fix || false,
16
+ formats: ['json'], // Mantener json para parseo consistente si es necesario
17
+ tsconfigPath: env.tsconfigFile || './tsconfig.json', // Esto es específico de OxlintNode
18
+ // ... cualquier otra opción específica de oxlintConfig.oxlintConfig
19
+ ...oxlintConfig.oxlintConfig,
20
+ });
21
+ const targetPaths = oxlintConfig.paths || [env.PATH_SOURCE || './src']; // Usar paths de LinterConfig
22
+ return await oxlintRunner.run(targetPaths);
23
+ }
24
+ catch (err) {
25
+ logger.error('❌ :Error al compilar OxLint:', err);
26
+ throw err;
27
+ }
28
+ }
29
+ /**
30
+ * Ejecuta ESLint en el proyecto con estructura compatible con Oxlint
31
+ */
32
+ export async function ESLint(config = {}) {
33
+ try {
34
+ if (!config || !config.bin) {
35
+ // configFile es opcional si ESLint lo encuentra por defecto
36
+ logger.warn('⚠️ ESLint no se ejecutará: falta la propiedad "bin" en la configuración.');
37
+ // Devolver un ESLintMultiFormatResult vacío o que indique error
38
+ return {
39
+ json: {
40
+ results: [],
41
+ errorCount: 0,
42
+ warningCount: 0,
43
+ fixableErrorCount: 0,
44
+ fixableWarningCount: 0,
45
+ fatalErrorCount: 0,
46
+ },
47
+ };
48
+ }
49
+ // Configuración por defecto para el proyecto
50
+ const eslintRunner = new ESLintNode({
51
+ binPath: config.bin, // Usar bin de LinterConfig
52
+ configFile: config.configFile, // Usar configFile de LinterConfig
53
+ fix: config.fix || false,
54
+ // Las siguientes son opciones más específicas de ESLintNode,
55
+ // podrían moverse a config.eslintConfig si se prefiere mayor anidación.
56
+ extensions: ['.vue', '.ts', '.js'], // Ejemplo, podría venir de eslintConfig
57
+ formats: config.format ? [config.format] : ['stylish', 'json'], // Usar format de LinterConfig
58
+ cache: true, // Ejemplo, podría venir de eslintConfig
59
+ maxWarnings: 100, // Ejemplo, podría venir de eslintConfig
60
+ // Sobrescribir o añadir con configuraciones específicas de eslintConfig
61
+ ...config.eslintConfig,
62
+ });
63
+ const targetPaths = config.paths || ['src/']; // Usar paths de LinterConfig
64
+ const result = await eslintRunner.run(targetPaths);
65
+ return result;
66
+ }
67
+ catch (err) {
68
+ logger.error('❌ Error al ejecutar ESLint:', err);
69
+ throw err;
70
+ }
71
+ }
72
+ //# sourceMappingURL=linter.js.map