versacompiler 2.1.0 → 2.3.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 +1 -1
- package/dist/compiler/compile.js +2520 -25
- package/dist/compiler/error-reporter.js +467 -38
- package/dist/compiler/linter.js +72 -1
- package/dist/compiler/minify.js +272 -1
- package/dist/compiler/minifyTemplate.js +230 -1
- package/dist/compiler/module-resolution-optimizer.js +888 -1
- package/dist/compiler/parser.js +336 -1
- package/dist/compiler/performance-monitor.js +204 -56
- package/dist/compiler/tailwindcss.js +39 -1
- package/dist/compiler/transform-optimizer.js +392 -1
- package/dist/compiler/transformTStoJS.js +16 -1
- package/dist/compiler/transforms.js +554 -1
- package/dist/compiler/typescript-compiler.js +172 -2
- package/dist/compiler/typescript-error-parser.js +281 -10
- package/dist/compiler/typescript-manager.js +304 -2
- package/dist/compiler/typescript-sync-validator.js +295 -31
- package/dist/compiler/typescript-worker-pool.js +936 -1
- package/dist/compiler/typescript-worker-thread.cjs +466 -22
- package/dist/compiler/typescript-worker.js +339 -1
- package/dist/compiler/vuejs.js +396 -37
- package/dist/hrm/VueHRM.js +359 -1
- package/dist/hrm/errorScreen.js +83 -1
- package/dist/hrm/getInstanciaVue.js +313 -1
- package/dist/hrm/initHRM.js +586 -1
- package/dist/main.js +353 -7
- package/dist/servicios/browserSync.js +589 -2
- package/dist/servicios/file-watcher.js +425 -4
- package/dist/servicios/logger.js +63 -3
- package/dist/servicios/readConfig.js +399 -53
- package/dist/utils/excluded-modules.js +37 -1
- package/dist/utils/module-resolver.js +552 -1
- package/dist/utils/promptUser.js +48 -2
- package/dist/utils/proxyValidator.js +68 -1
- package/dist/utils/resolve-bin.js +58 -1
- package/dist/utils/utils.js +21 -1
- package/dist/utils/vue-types-setup.js +435 -241
- package/dist/wrappers/eslint-node.js +1 -1
- package/dist/wrappers/oxlint-node.js +122 -1
- package/dist/wrappers/tailwind-node.js +94 -1
- package/package.json +109 -104
|
@@ -1,22 +1,466 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript Worker Thread - Ejecuta type checking asíncrono
|
|
3
|
+
* Este archivo se ejecuta en un worker thread separado para validación de tipos
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const fs = require('node:fs');
|
|
7
|
+
const path = require('node:path');
|
|
8
|
+
const { parentPort } = require('node:worker_threads');
|
|
9
|
+
|
|
10
|
+
// Debug: Log de inicio del worker
|
|
11
|
+
// console.log('[Worker] TypeScript Worker Thread iniciado');
|
|
12
|
+
|
|
13
|
+
let ts;
|
|
14
|
+
try {
|
|
15
|
+
ts = require('typescript');
|
|
16
|
+
// console.log('[Worker] TypeScript cargado exitosamente');
|
|
17
|
+
} catch (error) {
|
|
18
|
+
console.error('[Worker] Error cargando TypeScript:', error);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Language Service Host para validación de tipos en el worker
|
|
24
|
+
*/
|
|
25
|
+
class WorkerTypeScriptLanguageServiceHost {
|
|
26
|
+
constructor(compilerOptions) {
|
|
27
|
+
this.files = new Map();
|
|
28
|
+
// Crear opciones ultra-limpias para evitar problemas de serialización
|
|
29
|
+
this.compilerOptions =
|
|
30
|
+
this.createUltraCleanCompilerOptions(compilerOptions);
|
|
31
|
+
} /**
|
|
32
|
+
* Crea opciones del compilador que respetan la configuración del tsconfig.json
|
|
33
|
+
*/
|
|
34
|
+
createUltraCleanCompilerOptions(options) {
|
|
35
|
+
// Usar las opciones del tsconfig.json pasadas desde el hilo principal
|
|
36
|
+
const cleanOptions = {
|
|
37
|
+
// target: options.target || ts.ScriptTarget.ES2020,
|
|
38
|
+
// module: options.module || ts.ModuleKind.ES2020,
|
|
39
|
+
// strict: Boolean(options.strict),
|
|
40
|
+
// noEmitOnError: Boolean(options.noEmitOnError),
|
|
41
|
+
// skipLibCheck: Boolean(options.skipLibCheck !== false), // true por defecto
|
|
42
|
+
// skipDefaultLibCheck: Boolean(options.skipDefaultLibCheck !== false), // true por defecto
|
|
43
|
+
// allowJs: Boolean(options.allowJs !== false), // true por defecto
|
|
44
|
+
// esModuleInterop: Boolean(options.esModuleInterop !== false), // true por defecto
|
|
45
|
+
// allowSyntheticDefaultImports: Boolean(
|
|
46
|
+
// options.allowSyntheticDefaultImports !== false,
|
|
47
|
+
// ), // true por defecto
|
|
48
|
+
// declaration: Boolean(options.declaration),
|
|
49
|
+
// sourceMap: Boolean(options.sourceMap),
|
|
50
|
+
// noImplicitAny: Boolean(options.noImplicitAny),
|
|
51
|
+
// noImplicitReturns: Boolean(options.noImplicitReturns),
|
|
52
|
+
// noImplicitThis: Boolean(options.noImplicitThis),
|
|
53
|
+
// noUnusedLocals: Boolean(options.noUnusedLocals),
|
|
54
|
+
// noUnusedParameters: Boolean(options.noUnusedParameters),
|
|
55
|
+
// isolatedModules: Boolean(options.isolatedModules !== false), // true por defecto // Usar las librerías especificadas en el tsconfig.json
|
|
56
|
+
// lib: Array.isArray(options.lib)
|
|
57
|
+
// ? options.lib
|
|
58
|
+
// : ['es2020', 'dom', 'dom.iterable'],
|
|
59
|
+
|
|
60
|
+
// // Soporte para decorators
|
|
61
|
+
// experimentalDecorators: Boolean(
|
|
62
|
+
// options.experimentalDecorators !== false,
|
|
63
|
+
// ),
|
|
64
|
+
// emitDecoratorMetadata: Boolean(
|
|
65
|
+
// options.emitDecoratorMetadata !== false,
|
|
66
|
+
// ),
|
|
67
|
+
|
|
68
|
+
// // Opciones críticas para el worker pero manteniendo compatibilidad
|
|
69
|
+
// noLib: false, // Permitir librerías para APIs básicas (DOM, Promise, etc.)
|
|
70
|
+
// noResolve: true, // Evitar resolución de módulos compleja pero mantener tipos globales
|
|
71
|
+
// suppressOutputPathCheck: true,
|
|
72
|
+
// allowNonTsExtensions: true,
|
|
73
|
+
...options,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// console.log(
|
|
77
|
+
// '[Worker] Opciones del compilador recibidas:',
|
|
78
|
+
// Object.keys(cleanOptions),
|
|
79
|
+
// );
|
|
80
|
+
return cleanOptions;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
addFile(fileName, content) {
|
|
84
|
+
const existing = this.files.get(fileName);
|
|
85
|
+
this.files.set(fileName, {
|
|
86
|
+
version: existing ? existing.version + 1 : 1,
|
|
87
|
+
content,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
getCompilationSettings() {
|
|
92
|
+
return this.compilerOptions;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
getScriptFileNames() {
|
|
96
|
+
return Array.from(this.files.keys());
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
getScriptVersion(fileName) {
|
|
100
|
+
const file = this.files.get(fileName);
|
|
101
|
+
return file ? file.version.toString() : '0';
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
getScriptSnapshot(fileName) {
|
|
105
|
+
const file = this.files.get(fileName);
|
|
106
|
+
if (file) {
|
|
107
|
+
return ts.ScriptSnapshot.fromString(file.content);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Intentar leer el archivo del sistema de archivos para dependencias
|
|
111
|
+
if (fs.existsSync(fileName)) {
|
|
112
|
+
try {
|
|
113
|
+
const content = fs.readFileSync(fileName, 'utf-8');
|
|
114
|
+
return ts.ScriptSnapshot.fromString(content);
|
|
115
|
+
} catch {
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
getCurrentDirectory() {
|
|
124
|
+
return process.cwd();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
getDefaultLibFileName(options) {
|
|
128
|
+
return ts.getDefaultLibFilePath(options);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
fileExists(path) {
|
|
132
|
+
return this.files.has(path) || fs.existsSync(path);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
readFile(path) {
|
|
136
|
+
const file = this.files.get(path);
|
|
137
|
+
if (file) {
|
|
138
|
+
return file.content;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (fs.existsSync(path)) {
|
|
142
|
+
try {
|
|
143
|
+
return fs.readFileSync(path, 'utf-8');
|
|
144
|
+
} catch {
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
getNewLine() {
|
|
153
|
+
return ts.sys.newLine;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Realiza validación de tipos en el worker thread
|
|
159
|
+
*/
|
|
160
|
+
function validateTypesInWorker(fileName, content, compilerOptions) {
|
|
161
|
+
let actualFileName = fileName;
|
|
162
|
+
try {
|
|
163
|
+
const scriptContent = content;
|
|
164
|
+
|
|
165
|
+
// Si el script está vacío o es solo espacios en blanco, no validar
|
|
166
|
+
if (!scriptContent.trim()) {
|
|
167
|
+
return { diagnostics: [], hasErrors: false };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Crear Language Service Host
|
|
171
|
+
const host = new WorkerTypeScriptLanguageServiceHost(compilerOptions); // Para archivos Vue, crear un archivo virtual .ts
|
|
172
|
+
if (fileName.endsWith('.vue')) {
|
|
173
|
+
// Crear un nombre de archivo virtual único
|
|
174
|
+
const virtualFileName = `${fileName}.ts`;
|
|
175
|
+
host.addFile(virtualFileName, scriptContent);
|
|
176
|
+
actualFileName = virtualFileName;
|
|
177
|
+
// console.log('[Worker] Archivo Vue agregado como:', virtualFileName);
|
|
178
|
+
} else {
|
|
179
|
+
// Para archivos virtuales, usar el nombre tal como viene
|
|
180
|
+
host.addFile(fileName, scriptContent);
|
|
181
|
+
actualFileName = fileName;
|
|
182
|
+
// console.log('[Worker] Archivo agregado como:', fileName);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// console.log(
|
|
186
|
+
// '[Worker] Contenido del archivo:',
|
|
187
|
+
// scriptContent.substring(0, 100) + '...',
|
|
188
|
+
// );
|
|
189
|
+
// console.log('[Worker] Archivos en host:', host.getScriptFileNames());
|
|
190
|
+
|
|
191
|
+
// Agregar declaraciones básicas de tipos para Vue si es necesario
|
|
192
|
+
if (fileName.endsWith('.vue')) {
|
|
193
|
+
// Usar el directorio del archivo actual para las declaraciones
|
|
194
|
+
const projectDir = path.dirname(actualFileName);
|
|
195
|
+
const vueTypesPath = path.join(projectDir, 'vue-types.d.ts');
|
|
196
|
+
const vueTypesDeclaration = `// Declaraciones de tipos Vue para validación
|
|
197
|
+
declare global {
|
|
198
|
+
function ref<T>(value: T): { value: T };
|
|
199
|
+
function reactive<T extends object>(target: T): T;
|
|
200
|
+
function computed<T>(getter: () => T): { value: T };
|
|
201
|
+
function defineComponent<T>(options: T): T;
|
|
202
|
+
function defineProps<T = {}>(): T;
|
|
203
|
+
function defineEmits<T = {}>(): T;
|
|
204
|
+
function defineExpose<T = {}>(exposed: T): void;
|
|
205
|
+
function mergeModels<T>(models: T): T;
|
|
206
|
+
function provide<T>(key: string | symbol, value: T): void;
|
|
207
|
+
function inject<T>(key: string | symbol, defaultValue?: T): T | undefined;
|
|
208
|
+
function useSlots(): { [key: string]: (...args: any[]) => any };
|
|
209
|
+
function useAttrs(): { [key: string]: any };
|
|
210
|
+
function useModel<T>(modelName: string): { value: T };
|
|
211
|
+
function onMounted(fn: () => void): void;
|
|
212
|
+
function onUnmounted(fn: () => void): void;
|
|
213
|
+
function watch<T>(source: () => T, callback: (newValue: T, oldValue: T) => void): void;
|
|
214
|
+
}
|
|
215
|
+
export {};`;
|
|
216
|
+
host.addFile(vueTypesPath, vueTypesDeclaration);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Crear Language Service
|
|
220
|
+
const languageService = ts.createLanguageService(host);
|
|
221
|
+
|
|
222
|
+
try {
|
|
223
|
+
// Verificar que el archivo existe en el host antes de solicitar diagnósticos
|
|
224
|
+
if (!host.fileExists(actualFileName)) {
|
|
225
|
+
return { diagnostics: [], hasErrors: false };
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Obtener diagnósticos de tipos con manejo de errores
|
|
229
|
+
let syntacticDiagnostics = [];
|
|
230
|
+
let semanticDiagnostics = [];
|
|
231
|
+
try {
|
|
232
|
+
syntacticDiagnostics =
|
|
233
|
+
languageService.getSyntacticDiagnostics(actualFileName);
|
|
234
|
+
// console.log(
|
|
235
|
+
// '[Worker] Diagnósticos sintácticos:',
|
|
236
|
+
// syntacticDiagnostics.length,
|
|
237
|
+
// );
|
|
238
|
+
} catch (error) {
|
|
239
|
+
console.error(
|
|
240
|
+
'[Worker] Error obteniendo diagnósticos sintácticos:',
|
|
241
|
+
error.message,
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
try {
|
|
246
|
+
semanticDiagnostics =
|
|
247
|
+
languageService.getSemanticDiagnostics(actualFileName);
|
|
248
|
+
// console.log(
|
|
249
|
+
// '[Worker] Diagnósticos semánticos:',
|
|
250
|
+
// semanticDiagnostics.length,
|
|
251
|
+
// );
|
|
252
|
+
} catch (error) {
|
|
253
|
+
console.error(
|
|
254
|
+
'[Worker] Error obteniendo diagnósticos semánticos:',
|
|
255
|
+
error.message,
|
|
256
|
+
);
|
|
257
|
+
} // Combinar todos los diagnósticos
|
|
258
|
+
const allDiagnostics = [
|
|
259
|
+
...syntacticDiagnostics,
|
|
260
|
+
...semanticDiagnostics,
|
|
261
|
+
];
|
|
262
|
+
|
|
263
|
+
// console.log(
|
|
264
|
+
// '[Worker] Total diagnósticos encontrados:',
|
|
265
|
+
// allDiagnostics.length,
|
|
266
|
+
// );
|
|
267
|
+
|
|
268
|
+
// Log de todos los diagnósticos antes del filtrado
|
|
269
|
+
// allDiagnostics.forEach((diag, index) => {
|
|
270
|
+
// const messageText = ts.flattenDiagnosticMessageText(
|
|
271
|
+
// diag.messageText,
|
|
272
|
+
// '\n',
|
|
273
|
+
// );
|
|
274
|
+
// console.log(
|
|
275
|
+
// `[Worker] Diagnóstico ${index + 1}: [${diag.category}] ${messageText}`,
|
|
276
|
+
// );
|
|
277
|
+
// });
|
|
278
|
+
|
|
279
|
+
// Filtrar diagnósticos relevantes
|
|
280
|
+
const filteredDiagnostics = allDiagnostics.filter(diag => {
|
|
281
|
+
const messageText = ts.flattenDiagnosticMessageText(
|
|
282
|
+
diag.messageText,
|
|
283
|
+
'\n',
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
// Solo errores de categoría Error
|
|
287
|
+
if (diag.category !== ts.DiagnosticCategory.Error) {
|
|
288
|
+
return false;
|
|
289
|
+
} // Ignorar SOLO errores específicos de infraestructura Vue y rutas de módulos
|
|
290
|
+
return (
|
|
291
|
+
!messageText.includes('Cannot find module') &&
|
|
292
|
+
!messageText.includes('Could not find source file') &&
|
|
293
|
+
!messageText.includes(
|
|
294
|
+
"has no exported member 'mergeModels'",
|
|
295
|
+
) &&
|
|
296
|
+
!messageText.includes(
|
|
297
|
+
"Parameter '$props' implicitly has an 'any' type",
|
|
298
|
+
) &&
|
|
299
|
+
!messageText.includes(
|
|
300
|
+
"Parameter '$setup' implicitly has an 'any' type",
|
|
301
|
+
) &&
|
|
302
|
+
!messageText.includes(
|
|
303
|
+
"Parameter '$data' implicitly has an 'any' type",
|
|
304
|
+
) &&
|
|
305
|
+
!messageText.includes(
|
|
306
|
+
"Parameter '$options' implicitly has an 'any' type",
|
|
307
|
+
) &&
|
|
308
|
+
!messageText.includes(
|
|
309
|
+
"Parameter '$event' implicitly has an 'any' type",
|
|
310
|
+
) &&
|
|
311
|
+
!messageText.includes(
|
|
312
|
+
"Parameter '_ctx' implicitly has an 'any' type",
|
|
313
|
+
) &&
|
|
314
|
+
!messageText.includes(
|
|
315
|
+
"Parameter '_cache' implicitly has an 'any' type",
|
|
316
|
+
) &&
|
|
317
|
+
// Ignorar errores específicos de decorators cuando están mal configurados
|
|
318
|
+
!messageText.includes(
|
|
319
|
+
'Unable to resolve signature of method decorator when called as an expression',
|
|
320
|
+
) &&
|
|
321
|
+
!messageText.includes(
|
|
322
|
+
'The runtime will invoke the decorator with',
|
|
323
|
+
) &&
|
|
324
|
+
// NO ignorar errores TS7031 y TS7006 de forma general, solo para parámetros específicos de Vue
|
|
325
|
+
// diag.code !== 7031 &&
|
|
326
|
+
// diag.code !== 7006 &&
|
|
327
|
+
// Ignorar errores TS1241 (decorator signature mismatch) durante desarrollo
|
|
328
|
+
diag.code !== 1241 &&
|
|
329
|
+
!(
|
|
330
|
+
messageText.includes("implicitly has an 'any' type") &&
|
|
331
|
+
(messageText.includes('_ctx') ||
|
|
332
|
+
messageText.includes('_cache') ||
|
|
333
|
+
messageText.includes('$props') ||
|
|
334
|
+
messageText.includes('$setup') ||
|
|
335
|
+
messageText.includes('__expose') ||
|
|
336
|
+
messageText.includes('__emit'))
|
|
337
|
+
)
|
|
338
|
+
);
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
return {
|
|
342
|
+
diagnostics: filteredDiagnostics,
|
|
343
|
+
hasErrors: filteredDiagnostics.length > 0,
|
|
344
|
+
};
|
|
345
|
+
} catch {
|
|
346
|
+
return { diagnostics: [], hasErrors: false };
|
|
347
|
+
}
|
|
348
|
+
} catch (error) {
|
|
349
|
+
// En caso de error, devolver diagnóstico de error
|
|
350
|
+
const errorDiagnostic = {
|
|
351
|
+
file: undefined,
|
|
352
|
+
start: undefined,
|
|
353
|
+
length: undefined,
|
|
354
|
+
messageText: `Error en validación de tipos: ${error instanceof Error ? error.message : 'Error desconocido'}`,
|
|
355
|
+
category: ts.DiagnosticCategory.Error,
|
|
356
|
+
code: 0,
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
return {
|
|
360
|
+
diagnostics: [errorDiagnostic],
|
|
361
|
+
hasErrors: true,
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// Escuchar mensajes del proceso principal
|
|
367
|
+
if (parentPort) {
|
|
368
|
+
parentPort.on('message', message => {
|
|
369
|
+
try {
|
|
370
|
+
// console.log('[Worker] Mensaje recibido:', {
|
|
371
|
+
// id: message.id,
|
|
372
|
+
// fileName: message.fileName,
|
|
373
|
+
// contentLength: message.content?.length,
|
|
374
|
+
// compilerOptions: Object.keys(message.compilerOptions || {}),
|
|
375
|
+
// });
|
|
376
|
+
|
|
377
|
+
const { id, fileName, content, compilerOptions } = message;
|
|
378
|
+
|
|
379
|
+
// Validar que el mensaje tiene la estructura correcta
|
|
380
|
+
if (!id || !fileName || typeof content !== 'string') {
|
|
381
|
+
parentPort.postMessage({
|
|
382
|
+
id: id || 'unknown',
|
|
383
|
+
success: false,
|
|
384
|
+
error: 'Mensaje del worker inválido',
|
|
385
|
+
});
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// Realizar validación de tipos
|
|
390
|
+
const result = validateTypesInWorker(
|
|
391
|
+
fileName,
|
|
392
|
+
content,
|
|
393
|
+
compilerOptions,
|
|
394
|
+
); // Serializar diagnósticos de forma segura
|
|
395
|
+
const serializableDiagnostics = result.diagnostics.map(diag => ({
|
|
396
|
+
category: diag.category,
|
|
397
|
+
code: diag.code,
|
|
398
|
+
messageText:
|
|
399
|
+
typeof diag.messageText === 'string'
|
|
400
|
+
? diag.messageText
|
|
401
|
+
: ts.flattenDiagnosticMessageText(
|
|
402
|
+
diag.messageText,
|
|
403
|
+
'\n',
|
|
404
|
+
),
|
|
405
|
+
file: diag.file
|
|
406
|
+
? {
|
|
407
|
+
fileName: diag.file.fileName,
|
|
408
|
+
text: diag.file.text,
|
|
409
|
+
}
|
|
410
|
+
: undefined,
|
|
411
|
+
start: diag.start,
|
|
412
|
+
length: diag.length,
|
|
413
|
+
}));
|
|
414
|
+
|
|
415
|
+
// Enviar respuesta al proceso principal
|
|
416
|
+
// console.log('[Worker] Enviando respuesta:', {
|
|
417
|
+
// id,
|
|
418
|
+
// success: true,
|
|
419
|
+
// diagnosticsCount: serializableDiagnostics.length,
|
|
420
|
+
// hasErrors: result.hasErrors,
|
|
421
|
+
// });
|
|
422
|
+
|
|
423
|
+
parentPort.postMessage({
|
|
424
|
+
id,
|
|
425
|
+
success: true,
|
|
426
|
+
diagnostics: serializableDiagnostics,
|
|
427
|
+
hasErrors: result.hasErrors,
|
|
428
|
+
});
|
|
429
|
+
} catch (error) {
|
|
430
|
+
// Enviar error al proceso principal
|
|
431
|
+
parentPort.postMessage({
|
|
432
|
+
id: message?.id || 'unknown',
|
|
433
|
+
success: false,
|
|
434
|
+
error:
|
|
435
|
+
error instanceof Error
|
|
436
|
+
? error.message
|
|
437
|
+
: 'Error desconocido en worker',
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// Manejar errores no capturados en el worker
|
|
444
|
+
process.on('uncaughtException', error => {
|
|
445
|
+
console.error('[Worker] Error no capturado en TypeScript worker:', error);
|
|
446
|
+
if (parentPort) {
|
|
447
|
+
parentPort.postMessage({
|
|
448
|
+
id: 'error',
|
|
449
|
+
success: false,
|
|
450
|
+
error: `Error crítico en worker: ${error.message}`,
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
process.exit(1);
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
// Log de confirmación de que el worker está listo
|
|
457
|
+
// console.log('[Worker] TypeScript Worker Thread listo para recibir mensajes');
|
|
458
|
+
|
|
459
|
+
// Señal de que el worker está listo
|
|
460
|
+
if (parentPort) {
|
|
461
|
+
parentPort.postMessage({
|
|
462
|
+
id: 'worker-ready',
|
|
463
|
+
success: true,
|
|
464
|
+
message: 'TypeScript worker iniciado correctamente',
|
|
465
|
+
});
|
|
466
|
+
}
|