versacompiler 2.0.8 → 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.
- package/README.md +1 -1
- package/dist/compiler/compile.js +2520 -26
- 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 -0
- package/dist/compiler/module-resolution-optimizer.js +844 -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 -41
- 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 +587 -5
- package/dist/servicios/file-watcher.js +425 -4
- package/dist/servicios/logger.js +63 -3
- package/dist/servicios/readConfig.js +399 -105
- package/dist/utils/excluded-modules.js +37 -1
- package/dist/utils/module-resolver.js +466 -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 +147 -1
- package/dist/wrappers/oxlint-node.js +122 -1
- package/dist/wrappers/tailwind-node.js +94 -1
- package/package.json +39 -42
package/dist/main.js
CHANGED
|
@@ -1,8 +1,354 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import * as processModule from 'node:process';
|
|
4
|
+
const { env } = processModule;
|
|
5
|
+
// Usar el objeto process global para event listeners
|
|
6
|
+
const globalProcess = globalThis.process || processModule;
|
|
7
|
+
// Lazy loading optimizations - Only import lightweight modules synchronously
|
|
8
|
+
import { fileURLToPath } from 'node:url';
|
|
9
|
+
import { logger } from './servicios/logger.js';
|
|
10
|
+
import { readConfig } from './servicios/readConfig.js';
|
|
11
|
+
// Heavy dependencies will be loaded dynamically when needed
|
|
12
|
+
let chalk;
|
|
13
|
+
let yargs;
|
|
14
|
+
let hideBin;
|
|
15
|
+
// Obtener el directorio del archivo actual (src/)
|
|
16
|
+
env.PATH_PROY = path.dirname(fileURLToPath(import.meta.url));
|
|
17
|
+
env.PATH_CONFIG_FILE = path.resolve(globalProcess.cwd(), 'versacompile.config.ts');
|
|
18
|
+
// Lazy loading helper functions
|
|
19
|
+
async function loadChalk() {
|
|
20
|
+
if (!chalk) {
|
|
21
|
+
chalk = (await import('chalk')).default;
|
|
22
|
+
}
|
|
23
|
+
return chalk;
|
|
24
|
+
}
|
|
25
|
+
// Función para obtener la versión del package.json
|
|
26
|
+
async function getPackageVersion() {
|
|
27
|
+
try {
|
|
28
|
+
const fs = await import('node:fs/promises');
|
|
29
|
+
const packageJsonPath = path.resolve(env.PATH_PROY || path.dirname(fileURLToPath(import.meta.url)), '..', 'package.json');
|
|
30
|
+
const packageContent = await fs.readFile(packageJsonPath, 'utf-8');
|
|
31
|
+
const packageData = JSON.parse(packageContent);
|
|
32
|
+
return packageData.version || 'unknown';
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
// Fallback si no se puede leer el package.json
|
|
36
|
+
return 'unknown';
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async function loadYargs() {
|
|
40
|
+
if (!yargs) {
|
|
41
|
+
const yargsModule = await import('yargs');
|
|
42
|
+
const helpersModule = await import('yargs/helpers');
|
|
43
|
+
yargs = yargsModule.default;
|
|
44
|
+
hideBin = helpersModule.hideBin;
|
|
45
|
+
}
|
|
46
|
+
return { yargs, hideBin };
|
|
47
|
+
}
|
|
48
|
+
async function loadCompilerModule() {
|
|
49
|
+
return await import('./compiler/compile.js');
|
|
50
|
+
}
|
|
51
|
+
async function loadBrowserSyncModule() {
|
|
52
|
+
return await import('./servicios/browserSync.js');
|
|
53
|
+
}
|
|
54
|
+
async function loadChokidarModule() {
|
|
55
|
+
return await import('./servicios/file-watcher.js');
|
|
56
|
+
}
|
|
57
|
+
async function loadConfigModule() {
|
|
58
|
+
return await import('./servicios/readConfig.js');
|
|
59
|
+
}
|
|
60
|
+
function stopCompile() {
|
|
61
|
+
logger.info('VersaCompiler cerrado correctamente');
|
|
62
|
+
}
|
|
63
|
+
async function main() {
|
|
64
|
+
// Load yargs dynamically
|
|
65
|
+
const { yargs: yargsInstance, hideBin: hideBinFn } = await loadYargs();
|
|
66
|
+
const chalk = await loadChalk();
|
|
67
|
+
let yargInstance = yargsInstance(hideBinFn(globalProcess.argv))
|
|
68
|
+
.scriptName('versa')
|
|
69
|
+
.usage(chalk.blue('VersaCompiler') + ' - Compilador de archivos Vue/TS/JS')
|
|
70
|
+
.option('init', {
|
|
71
|
+
type: 'boolean',
|
|
72
|
+
description: 'Inicializar la configuración',
|
|
73
|
+
})
|
|
74
|
+
.option('watch', {
|
|
75
|
+
type: 'boolean',
|
|
76
|
+
description: 'Habilitar el modo de observación (watch)',
|
|
77
|
+
default: false, // Por defecto, el modo watch está habilitado
|
|
78
|
+
})
|
|
79
|
+
.alias('w', 'watch')
|
|
80
|
+
.option('all', {
|
|
81
|
+
type: 'boolean',
|
|
82
|
+
description: 'Compilar todos los archivos',
|
|
83
|
+
})
|
|
84
|
+
.option('file', {
|
|
85
|
+
type: 'string',
|
|
86
|
+
description: 'Compilar un archivo específico',
|
|
87
|
+
alias: 'f',
|
|
88
|
+
})
|
|
89
|
+
.option('prod', {
|
|
90
|
+
type: 'boolean',
|
|
91
|
+
description: 'Modo producción',
|
|
92
|
+
})
|
|
93
|
+
.alias('p', 'prod')
|
|
94
|
+
.option('verbose', {
|
|
95
|
+
type: 'boolean',
|
|
96
|
+
description: 'Habilitar salida detallada (verbose)',
|
|
97
|
+
default: false, // Por defecto, verbose está deshabilitado
|
|
98
|
+
})
|
|
99
|
+
.alias('v', 'verbose')
|
|
100
|
+
.option('cleanOutput', {
|
|
101
|
+
type: 'boolean',
|
|
102
|
+
description: 'Limpiar el directorio de salida antes de compilar',
|
|
103
|
+
default: false, // Por defecto, clean está deshabilitado
|
|
104
|
+
})
|
|
105
|
+
.alias('co', 'cleanOutput')
|
|
106
|
+
.option('cleanCache', {
|
|
107
|
+
type: 'boolean',
|
|
108
|
+
description: 'Limpiar el cache de compilación antes de compilar',
|
|
109
|
+
default: false, // Por defecto, clean está deshabilitado
|
|
110
|
+
})
|
|
111
|
+
.alias('cc', 'cleanCache')
|
|
112
|
+
.option('yes', {
|
|
113
|
+
type: 'boolean',
|
|
114
|
+
description: 'Confirmar automáticamente las acciones que requieren confirmación',
|
|
115
|
+
default: false, // Por defecto, no se confirma automáticamente
|
|
116
|
+
})
|
|
117
|
+
.alias('y', 'yes')
|
|
118
|
+
.option('typeCheck', {
|
|
119
|
+
type: 'boolean',
|
|
120
|
+
description: 'Habilitar/Deshabilitar la verificación de tipos. Por defecto --typeCheck=false',
|
|
121
|
+
default: false,
|
|
122
|
+
})
|
|
123
|
+
.alias('t', 'typeCheck');
|
|
124
|
+
// Definir la opción tailwind dinámicamente
|
|
125
|
+
// Asumiendo que env.TAILWIND es una cadena que podría ser 'true', 'false', o undefined
|
|
126
|
+
if (env.tailwindcss !== 'false') {
|
|
127
|
+
yargInstance = yargInstance.option('tailwind', {
|
|
128
|
+
type: 'boolean',
|
|
129
|
+
description: 'Habilitar/Deshabilitar compilación de Tailwind CSS. Por defecto --tailwind=false',
|
|
130
|
+
default: false,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
if (env.linter !== 'false') {
|
|
134
|
+
yargInstance = yargInstance.option('linter', {
|
|
135
|
+
type: 'boolean',
|
|
136
|
+
description: 'Habilitar/Deshabilitar el linter. Por defecto --linter=false',
|
|
137
|
+
default: false,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
const argv = (await yargInstance
|
|
141
|
+
.help()
|
|
142
|
+
.alias('h', 'help')
|
|
143
|
+
.command('* [files...]', 'Compilar archivos específicos', (yargs) => {
|
|
144
|
+
return yargs.positional('files', {
|
|
145
|
+
describe: 'Archivos para compilar',
|
|
146
|
+
type: 'string',
|
|
147
|
+
array: true,
|
|
148
|
+
});
|
|
149
|
+
})
|
|
150
|
+
.parse());
|
|
151
|
+
try {
|
|
152
|
+
// 🎨 Header moderno y elegante
|
|
153
|
+
const version = await getPackageVersion();
|
|
154
|
+
const headerLine = '━'.repeat(60);
|
|
155
|
+
logger.log(`\n` +
|
|
156
|
+
chalk.cyan(headerLine) +
|
|
157
|
+
`\n` +
|
|
158
|
+
chalk.bold.cyan(' ⚡ VersaCompiler ') +
|
|
159
|
+
chalk.gray(`v${version}`) +
|
|
160
|
+
`\n` +
|
|
161
|
+
chalk.gray(' Vue · TypeScript · JavaScript Compiler') +
|
|
162
|
+
`\n` +
|
|
163
|
+
chalk.cyan(headerLine) +
|
|
164
|
+
`\n`);
|
|
165
|
+
if (argv.init) {
|
|
166
|
+
logger.info('Iniciando la configuración...');
|
|
167
|
+
const { initConfig } = await loadConfigModule();
|
|
168
|
+
await initConfig();
|
|
169
|
+
globalProcess.exit(0);
|
|
170
|
+
}
|
|
171
|
+
if (!(await readConfig())) {
|
|
172
|
+
globalProcess.exit(1);
|
|
173
|
+
}
|
|
174
|
+
env.isPROD = argv.prod ? 'true' : 'false';
|
|
175
|
+
env.isALL = argv.all ? 'true' : 'false';
|
|
176
|
+
env.TAILWIND =
|
|
177
|
+
argv.tailwind === undefined ? 'true' : String(argv.tailwind);
|
|
178
|
+
env.ENABLE_LINTER = String(argv.linter);
|
|
179
|
+
env.VERBOSE = argv.verbose ? 'true' : 'false'; // 🎯 Configuración moderna y organizada
|
|
180
|
+
logger.info(chalk.bold.blue('⚙️ Configuración'));
|
|
181
|
+
logger.info(chalk.gray(' ┌─ Modo de ejecución'));
|
|
182
|
+
const modes = [
|
|
183
|
+
{ label: 'Observar', value: argv.watch, icon: '👀' },
|
|
184
|
+
{
|
|
185
|
+
label: 'Todos los archivos',
|
|
186
|
+
value: env.isALL === 'true',
|
|
187
|
+
icon: '📁',
|
|
188
|
+
},
|
|
189
|
+
{ label: 'Archivo único', value: !!argv.file, icon: '📄' },
|
|
190
|
+
{ label: 'Producción', value: env.isPROD === 'true', icon: '🏭' },
|
|
191
|
+
];
|
|
192
|
+
const features = [
|
|
193
|
+
{ label: 'Tailwind', value: env.TAILWIND === 'true', icon: '🎨' },
|
|
194
|
+
{ label: 'Minificación', value: env.isPROD === 'true', icon: '🗜️' },
|
|
195
|
+
{
|
|
196
|
+
label: 'Linter',
|
|
197
|
+
value: env.ENABLE_LINTER === 'true',
|
|
198
|
+
icon: '🔍',
|
|
199
|
+
},
|
|
200
|
+
{ label: 'Verificar tipos', value: argv.typeCheck, icon: '📘' },
|
|
201
|
+
{ label: 'Detallado', value: env.VERBOSE === 'true', icon: '📝' },
|
|
202
|
+
];
|
|
203
|
+
modes.forEach(mode => {
|
|
204
|
+
const status = mode.value ? chalk.green('●') : chalk.gray('○');
|
|
205
|
+
const label = mode.value
|
|
206
|
+
? chalk.green(mode.label)
|
|
207
|
+
: chalk.gray(mode.label);
|
|
208
|
+
logger.info(chalk.gray(' │ ') + status + ` ${mode.icon} ${label}`);
|
|
209
|
+
});
|
|
210
|
+
logger.info(chalk.gray(' ├─ Características'));
|
|
211
|
+
features.forEach(feature => {
|
|
212
|
+
const status = feature.value ? chalk.green('●') : chalk.gray('○');
|
|
213
|
+
const label = feature.value
|
|
214
|
+
? chalk.green(feature.label)
|
|
215
|
+
: chalk.gray(feature.label);
|
|
216
|
+
logger.info(chalk.gray(' │ ') + status + ` ${feature.icon} ${label}`);
|
|
217
|
+
});
|
|
218
|
+
if (argv.file) {
|
|
219
|
+
logger.info(chalk.gray(' ├─ Objetivo'));
|
|
220
|
+
logger.info(chalk.gray(' │ ') + chalk.blue('📄 ') + argv.file);
|
|
221
|
+
}
|
|
222
|
+
if (argv.cleanOutput) {
|
|
223
|
+
logger.info(chalk.gray(' ├─ Limpieza'));
|
|
224
|
+
logger.info(chalk.gray(' │ ') + chalk.yellow('🧹 Limpiar salida'));
|
|
225
|
+
}
|
|
226
|
+
if (argv.cleanCache) {
|
|
227
|
+
logger.info(chalk.gray(' │ ') + chalk.yellow('🗑️ Limpiar caché'));
|
|
228
|
+
}
|
|
229
|
+
logger.info(chalk.gray(' └─ ¡Listo para compilar!'));
|
|
230
|
+
logger.log('');
|
|
231
|
+
env.typeCheck = argv.typeCheck ? 'true' : 'false';
|
|
232
|
+
env.cleanCache = argv.cleanCache ? 'true' : 'false';
|
|
233
|
+
env.yes = argv.y ? 'true' : 'false';
|
|
234
|
+
if (argv.cleanOutput) {
|
|
235
|
+
const { cleanOutputDir } = await loadChokidarModule();
|
|
236
|
+
await cleanOutputDir(env.PATH_DIST || './dist');
|
|
237
|
+
}
|
|
238
|
+
// Manejar archivos pasados como argumentos posicionales
|
|
239
|
+
if (argv.files && argv.files.length > 0) {
|
|
240
|
+
logger.info(chalk.yellow(`📄 Compilando ${argv.files.length} archivo(s)...`));
|
|
241
|
+
const fs = await import('node:fs/promises');
|
|
242
|
+
const { compileFile } = await loadCompilerModule();
|
|
243
|
+
let hasErrors = false;
|
|
244
|
+
for (const file of argv.files) {
|
|
245
|
+
try {
|
|
246
|
+
// Verificar si el archivo existe
|
|
247
|
+
await fs.access(file);
|
|
248
|
+
logger.info(chalk.blue(`🔄 Compilando: ${file}`));
|
|
249
|
+
const result = await compileFile(file);
|
|
250
|
+
if (result.success) {
|
|
251
|
+
logger.info(chalk.green(`✅ ${file} → ${result.output}`));
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
logger.error(chalk.red(`❌ Error al compilar: ${file}`));
|
|
255
|
+
hasErrors = true;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
catch {
|
|
259
|
+
logger.error(chalk.red(`❌ El archivo '${file}' no existe.`));
|
|
260
|
+
hasErrors = true;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
globalProcess.exit(hasErrors ? 1 : 0);
|
|
264
|
+
}
|
|
265
|
+
if (argv.file) {
|
|
266
|
+
// Compilar archivo individual
|
|
267
|
+
logger.info(chalk.yellow(`📄 Compilando archivo: ${argv.file}`)); // Verificar si el archivo existe
|
|
268
|
+
const fs = await import('node:fs/promises');
|
|
269
|
+
const { compileFile } = await loadCompilerModule();
|
|
270
|
+
let absolutePathFile;
|
|
271
|
+
try {
|
|
272
|
+
await fs.access(argv.file);
|
|
273
|
+
absolutePathFile = path.resolve(argv.file);
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
logger.error(chalk.red(`❌ Error: El archivo '${argv.file}' no existe.`));
|
|
277
|
+
globalProcess.exit(1);
|
|
278
|
+
}
|
|
279
|
+
// Compilar el archivo (absolutePathFile está garantizado aquí)
|
|
280
|
+
const result = await compileFile(absolutePathFile);
|
|
281
|
+
if (result.success) {
|
|
282
|
+
logger.info(chalk.green(`✅ Archivo compilado exitosamente: ${result.output}`));
|
|
283
|
+
globalProcess.exit(0);
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
logger.error(chalk.red(`❌ Error al compilar el archivo: ${argv.file}`));
|
|
287
|
+
globalProcess.exit(1);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (argv.all) {
|
|
291
|
+
const { initCompileAll } = await loadCompilerModule();
|
|
292
|
+
await initCompileAll();
|
|
293
|
+
globalProcess.exit(0);
|
|
294
|
+
}
|
|
295
|
+
if (!argv.watch) {
|
|
296
|
+
if (env.ENABLE_LINTER === 'true') {
|
|
297
|
+
const { runLinter } = await loadCompilerModule();
|
|
298
|
+
await runLinter(true);
|
|
299
|
+
globalProcess.exit(1);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
if (env.TAILWIND === 'true') {
|
|
303
|
+
const tailwindModule = await import('./compiler/tailwindcss.js');
|
|
304
|
+
const resultTW = await tailwindModule.generateTailwindCSS();
|
|
305
|
+
if (typeof resultTW !== 'boolean') {
|
|
306
|
+
if (resultTW?.success) {
|
|
307
|
+
logger.info(`\nTailwind CSS compilado🎨 ${resultTW.message}\n`);
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
const errorMsg = `${resultTW.message}${resultTW.details ? '\n' + resultTW.details : ''}`;
|
|
311
|
+
logger.error(`\n❌ Error al generar Tailwind CSS: ${errorMsg}\n`);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
let bs;
|
|
316
|
+
let watch;
|
|
317
|
+
if (argv.watch) {
|
|
318
|
+
const { browserSyncServer } = await loadBrowserSyncModule();
|
|
319
|
+
const { initChokidar } = await loadChokidarModule();
|
|
320
|
+
bs = await browserSyncServer();
|
|
321
|
+
if (!bs) {
|
|
322
|
+
globalProcess.exit(1);
|
|
323
|
+
}
|
|
324
|
+
watch = await initChokidar(bs);
|
|
325
|
+
if (!watch) {
|
|
326
|
+
globalProcess.exit(1);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
// ✨ FIX: Cleanup handler para evitar acumulación de listeners
|
|
330
|
+
const cleanupHandler = async () => {
|
|
331
|
+
if (bs) {
|
|
332
|
+
bs.exit();
|
|
333
|
+
}
|
|
334
|
+
if (watch) {
|
|
335
|
+
// ✨ FIX #3: Usar nuevo método cleanupWatcher
|
|
336
|
+
const { cleanupWatcher } = await loadChokidarModule();
|
|
337
|
+
await cleanupWatcher(watch);
|
|
338
|
+
}
|
|
339
|
+
stopCompile();
|
|
340
|
+
globalProcess.exit(0);
|
|
341
|
+
};
|
|
342
|
+
const sigintHandler = () => cleanupHandler();
|
|
343
|
+
const sigtermHandler = () => cleanupHandler();
|
|
344
|
+
globalProcess.on('SIGINT', sigintHandler);
|
|
345
|
+
globalProcess.on('SIGTERM', sigtermHandler);
|
|
346
|
+
}
|
|
347
|
+
catch (error) {
|
|
348
|
+
logger.error('Error en la aplicación:', error);
|
|
349
|
+
stopCompile();
|
|
350
|
+
globalProcess.exit(1);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
main();
|
|
354
|
+
//# sourceMappingURL=main.js.map
|