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.
- package/dist/compiler/compile.js +26 -2332
- package/dist/compiler/error-reporter.js +38 -467
- package/dist/compiler/linter.js +1 -72
- package/dist/compiler/minify.js +1 -229
- package/dist/compiler/module-resolution-optimizer.js +1 -821
- package/dist/compiler/parser.js +1 -203
- package/dist/compiler/performance-monitor.js +56 -192
- package/dist/compiler/tailwindcss.js +1 -39
- package/dist/compiler/transform-optimizer.js +1 -392
- package/dist/compiler/transformTStoJS.js +1 -16
- package/dist/compiler/transforms.js +1 -550
- package/dist/compiler/typescript-compiler.js +2 -172
- package/dist/compiler/typescript-error-parser.js +10 -281
- package/dist/compiler/typescript-manager.js +2 -273
- package/dist/compiler/typescript-sync-validator.js +31 -295
- package/dist/compiler/typescript-worker-pool.js +1 -842
- package/dist/compiler/typescript-worker-thread.cjs +41 -466
- package/dist/compiler/typescript-worker.js +1 -339
- package/dist/compiler/vuejs.js +37 -392
- package/dist/hrm/VueHRM.js +1 -353
- package/dist/hrm/errorScreen.js +1 -83
- package/dist/hrm/getInstanciaVue.js +1 -313
- package/dist/hrm/initHRM.js +1 -141
- package/dist/main.js +7 -347
- package/dist/servicios/browserSync.js +5 -501
- package/dist/servicios/file-watcher.js +4 -379
- package/dist/servicios/logger.js +3 -63
- package/dist/servicios/readConfig.js +105 -430
- package/dist/utils/excluded-modules.js +1 -36
- package/dist/utils/module-resolver.js +1 -466
- package/dist/utils/promptUser.js +2 -48
- package/dist/utils/proxyValidator.js +1 -68
- package/dist/utils/resolve-bin.js +1 -48
- package/dist/utils/utils.js +1 -21
- package/dist/utils/vue-types-setup.js +241 -435
- package/dist/wrappers/eslint-node.js +1 -145
- package/dist/wrappers/oxlint-node.js +1 -120
- package/dist/wrappers/tailwind-node.js +1 -92
- package/package.json +36 -35
|
@@ -1,430 +1,105 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
if (!entry.fileOutput || typeof entry.fileOutput !== 'string') {
|
|
109
|
-
logger.error('Cada entrada de bundler debe tener un fileOutput válido');
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
if (!this.validatePath(entry.fileOutput)) {
|
|
113
|
-
logger.error(`Ruta de salida no válida: ${entry.fileOutput}`);
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return true;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Valida la estructura de configuración
|
|
121
|
-
*/
|
|
122
|
-
static validateConfigStructure(config) {
|
|
123
|
-
if (!config || typeof config !== 'object') {
|
|
124
|
-
logger.error('La configuración debe ser un objeto');
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
if (!config.compilerOptions ||
|
|
128
|
-
typeof config.compilerOptions !== 'object') {
|
|
129
|
-
logger.error('compilerOptions es requerido y debe ser un objeto');
|
|
130
|
-
return false;
|
|
131
|
-
}
|
|
132
|
-
if (!config.compilerOptions.pathsAlias ||
|
|
133
|
-
typeof config.compilerOptions.pathsAlias !== 'object') {
|
|
134
|
-
logger.error('pathsAlias es requerido y debe ser un objeto');
|
|
135
|
-
return false;
|
|
136
|
-
}
|
|
137
|
-
// Validar pathsAlias
|
|
138
|
-
for (const [key, value] of Object.entries(config.compilerOptions.pathsAlias)) {
|
|
139
|
-
if (!Array.isArray(value)) {
|
|
140
|
-
logger.error(`pathsAlias["${key}"] debe ser un array`);
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
for (const path of value) {
|
|
144
|
-
if (typeof path !== 'string') {
|
|
145
|
-
logger.error(`Todas las rutas en pathsAlias["${key}"] deben ser strings`);
|
|
146
|
-
return false;
|
|
147
|
-
}
|
|
148
|
-
if (!this.validatePath(path.replace('/*', ''))) {
|
|
149
|
-
logger.error(`Ruta no válida en pathsAlias["${key}"]: ${path}`);
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
// Validar sourceRoot si existe
|
|
155
|
-
if (config.compilerOptions.sourceRoot &&
|
|
156
|
-
!this.validatePath(config.compilerOptions.sourceRoot)) {
|
|
157
|
-
return false;
|
|
158
|
-
}
|
|
159
|
-
// Validar outDir si existe
|
|
160
|
-
if (config.compilerOptions.outDir &&
|
|
161
|
-
!this.validatePath(config.compilerOptions.outDir)) {
|
|
162
|
-
return false;
|
|
163
|
-
}
|
|
164
|
-
// Validar linter si existe
|
|
165
|
-
if (config.linter && config.linter !== false) {
|
|
166
|
-
if (!Array.isArray(config.linter)) {
|
|
167
|
-
logger.error('linter debe ser un array o false');
|
|
168
|
-
return false;
|
|
169
|
-
}
|
|
170
|
-
for (const linter of config.linter) {
|
|
171
|
-
if (!this.validateLinter(linter)) {
|
|
172
|
-
return false;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return true;
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Valida configuración de linter
|
|
180
|
-
*/
|
|
181
|
-
static validateLinter(linter) {
|
|
182
|
-
if (!linter || typeof linter !== 'object') {
|
|
183
|
-
logger.error('Cada linter debe ser un objeto');
|
|
184
|
-
return false;
|
|
185
|
-
}
|
|
186
|
-
if (!linter.name || typeof linter.name !== 'string') {
|
|
187
|
-
logger.error('Linter debe tener un nombre válido');
|
|
188
|
-
return false;
|
|
189
|
-
}
|
|
190
|
-
if (!linter.bin || typeof linter.bin !== 'string') {
|
|
191
|
-
logger.error('Linter debe tener un bin válido');
|
|
192
|
-
return false;
|
|
193
|
-
}
|
|
194
|
-
if (!this.validateCommand(linter.bin)) {
|
|
195
|
-
return false;
|
|
196
|
-
}
|
|
197
|
-
if (!linter.configFile || typeof linter.configFile !== 'string') {
|
|
198
|
-
logger.error('Linter debe tener un configFile válido');
|
|
199
|
-
return false;
|
|
200
|
-
}
|
|
201
|
-
if (!this.validatePath(linter.configFile)) {
|
|
202
|
-
return false;
|
|
203
|
-
}
|
|
204
|
-
if (linter.paths && !Array.isArray(linter.paths)) {
|
|
205
|
-
logger.error('linter.paths debe ser un array');
|
|
206
|
-
return false;
|
|
207
|
-
}
|
|
208
|
-
if (linter.paths) {
|
|
209
|
-
for (const path of linter.paths) {
|
|
210
|
-
if (typeof path !== 'string' || !this.validatePath(path)) {
|
|
211
|
-
logger.error(`Ruta de linter no válida: ${path}`);
|
|
212
|
-
return false;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
if (linter.fix !== undefined && typeof linter.fix !== 'boolean') {
|
|
217
|
-
logger.error('Linter fix debe ser un booleano');
|
|
218
|
-
return false;
|
|
219
|
-
}
|
|
220
|
-
return true;
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Valida el tamaño del objeto de configuración
|
|
224
|
-
*/
|
|
225
|
-
static validateConfigSize(config) {
|
|
226
|
-
try {
|
|
227
|
-
const configString = JSON.stringify(config);
|
|
228
|
-
if (configString.length > this.MAX_CONFIG_SIZE) {
|
|
229
|
-
logger.error(`Configuración demasiado grande: ${configString.length} bytes`);
|
|
230
|
-
return false;
|
|
231
|
-
}
|
|
232
|
-
return true;
|
|
233
|
-
}
|
|
234
|
-
catch (error) {
|
|
235
|
-
logger.error('Error al serializar configuración (posible referencia circular):', error);
|
|
236
|
-
return false;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Limpia y normaliza una ruta eliminando barras finales
|
|
242
|
-
*/
|
|
243
|
-
function cleanPath(path) {
|
|
244
|
-
if (!path || typeof path !== 'string') {
|
|
245
|
-
return '';
|
|
246
|
-
}
|
|
247
|
-
return path.endsWith('/') || path.endsWith('\\') ? path.slice(0, -1) : path;
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Serializa de forma segura un objeto a JSON
|
|
251
|
-
*/
|
|
252
|
-
function safeJsonStringify(obj, fallback = 'false') {
|
|
253
|
-
try {
|
|
254
|
-
if (obj === null || obj === undefined) {
|
|
255
|
-
return fallback;
|
|
256
|
-
}
|
|
257
|
-
return JSON.stringify(obj);
|
|
258
|
-
}
|
|
259
|
-
catch (error) {
|
|
260
|
-
logger.warn('Error al serializar objeto, usando valor por defecto:', error);
|
|
261
|
-
return fallback;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Wrapper para el import dinámico que permite mejor testing
|
|
266
|
-
*/
|
|
267
|
-
export async function dynamicImport(url) {
|
|
268
|
-
return import(url);
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* Timeout wrapper para promises
|
|
272
|
-
*/
|
|
273
|
-
export function withTimeout(promise, timeoutMs, errorMessage) {
|
|
274
|
-
const timeoutPromise = new Promise((resolve, reject) => setTimeout(() => reject(new Error(errorMessage)), timeoutMs));
|
|
275
|
-
return Promise.race([promise, timeoutPromise]);
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Lee y valida el archivo de configuración de forma segura
|
|
279
|
-
*/
|
|
280
|
-
export async function readConfig() {
|
|
281
|
-
try {
|
|
282
|
-
// Validar variable de entorno
|
|
283
|
-
if (!env.PATH_CONFIG_FILE) {
|
|
284
|
-
throw new Error('La variable de entorno PATH_CONFIG_FILE no está definida.');
|
|
285
|
-
}
|
|
286
|
-
// Validar la ruta del archivo de configuración
|
|
287
|
-
if (!SecurityValidators.validatePath(env.PATH_CONFIG_FILE)) {
|
|
288
|
-
throw new Error(`Ruta de configuración no válida: ${env.PATH_CONFIG_FILE}`);
|
|
289
|
-
}
|
|
290
|
-
// Convertir la ruta del archivo a una URL file://
|
|
291
|
-
const configFileUrl = pathToFileURL(env.PATH_CONFIG_FILE).href;
|
|
292
|
-
// Importar con timeout para prevenir ataques DoS
|
|
293
|
-
const importPromise = dynamicImport(configFileUrl);
|
|
294
|
-
const data = await withTimeout(importPromise, 10000, 'Timeout al cargar configuración');
|
|
295
|
-
if (!data) {
|
|
296
|
-
throw new Error('No se pudo leer el archivo de configuración.');
|
|
297
|
-
}
|
|
298
|
-
const tsConfig = data.default || data;
|
|
299
|
-
// Validar tamaño de configuración
|
|
300
|
-
if (!SecurityValidators.validateConfigSize(tsConfig)) {
|
|
301
|
-
throw new Error('Configuración demasiado grande o contiene referencias circulares.');
|
|
302
|
-
}
|
|
303
|
-
// Validar estructura de configuración
|
|
304
|
-
if (!SecurityValidators.validateConfigStructure(tsConfig)) {
|
|
305
|
-
throw new Error('El archivo de configuración no tiene una estructura válida.');
|
|
306
|
-
}
|
|
307
|
-
// Procesar pathsAlias de forma segura
|
|
308
|
-
const pathAlias = { ...tsConfig.compilerOptions.pathsAlias }; // Eliminar /* de las rutas de alias
|
|
309
|
-
for (const key in pathAlias) {
|
|
310
|
-
const values = pathAlias[key];
|
|
311
|
-
if (values && Array.isArray(values)) {
|
|
312
|
-
for (let i = 0; i < values.length; i++) {
|
|
313
|
-
if (typeof values[i] === 'string' &&
|
|
314
|
-
values[i] !== undefined) {
|
|
315
|
-
values[i] = values[i].replace('/*', '');
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
// Establecer variables de entorno de forma segura
|
|
321
|
-
env.PATH_ALIAS = safeJsonStringify(pathAlias, '{}');
|
|
322
|
-
env.tailwindcss = safeJsonStringify(tsConfig?.tailwindConfig, 'false');
|
|
323
|
-
env.proxyUrl = (tsConfig?.proxyConfig?.proxyUrl || '').toString();
|
|
324
|
-
env.AssetsOmit = (tsConfig?.proxyConfig?.assetsOmit || false).toString();
|
|
325
|
-
env.linter = safeJsonStringify(tsConfig?.linter, 'false');
|
|
326
|
-
env.tsconfigFile = tsConfig?.tsconfig || './tsconfig.json';
|
|
327
|
-
// Validar y limpiar rutas
|
|
328
|
-
const sourceRoot = cleanPath(tsConfig?.compilerOptions?.sourceRoot || './src');
|
|
329
|
-
const outDir = cleanPath(tsConfig?.compilerOptions?.outDir || './dist');
|
|
330
|
-
if (!SecurityValidators.validatePath(sourceRoot)) {
|
|
331
|
-
throw new Error(`sourceRoot no válido: ${sourceRoot}`);
|
|
332
|
-
}
|
|
333
|
-
if (!SecurityValidators.validatePath(outDir)) {
|
|
334
|
-
throw new Error(`outDir no válido: ${outDir}`);
|
|
335
|
-
}
|
|
336
|
-
env.PATH_SOURCE = sourceRoot;
|
|
337
|
-
env.PATH_DIST = outDir;
|
|
338
|
-
env.aditionalWatch = safeJsonStringify(tsConfig?.aditionalWatch, '[]');
|
|
339
|
-
env.bundlers = safeJsonStringify(tsConfig?.bundlers, 'false');
|
|
340
|
-
// Configuración adicional para compatibilidad
|
|
341
|
-
if (!tsConfig.compilerOptions.sourceRoot) {
|
|
342
|
-
env.tsConfig = safeJsonStringify(tsConfig, '{}');
|
|
343
|
-
}
|
|
344
|
-
logger.info('✅ Configuration loaded and validated successfully');
|
|
345
|
-
return true;
|
|
346
|
-
}
|
|
347
|
-
catch (error) {
|
|
348
|
-
logger.error(`🚩 Error al leer el archivo ${env.PATH_CONFIG_FILE}: ${error}`, error);
|
|
349
|
-
return false;
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* Inicializa un archivo de configuración seguro por defecto
|
|
354
|
-
*/
|
|
355
|
-
export async function initConfig() {
|
|
356
|
-
try {
|
|
357
|
-
const fs = await dynamicImport('fs');
|
|
358
|
-
const path = await dynamicImport('path');
|
|
359
|
-
const configPath = path.resolve(process.cwd(), env.PATH_CONFIG_FILE || 'versacompile.config.ts');
|
|
360
|
-
// Validar que la ruta de destino sea segura
|
|
361
|
-
if (!SecurityValidators.validatePath(configPath)) {
|
|
362
|
-
throw new Error(`Ruta de configuración no válida: ${configPath}`);
|
|
363
|
-
}
|
|
364
|
-
if (fs.existsSync(configPath)) {
|
|
365
|
-
logger.warn(`🚩 El archivo de configuración '${env.PATH_CONFIG_FILE}' ya existe.`);
|
|
366
|
-
return true;
|
|
367
|
-
}
|
|
368
|
-
const configContent = `// Archivo de configuración de VersaCompiler
|
|
369
|
-
export default {
|
|
370
|
-
tsconfig: './tsconfig.json',
|
|
371
|
-
compilerOptions: {
|
|
372
|
-
sourceRoot: './src',
|
|
373
|
-
outDir: './dist',
|
|
374
|
-
pathsAlias: {
|
|
375
|
-
'/dist/examples/*': ['src/*'],
|
|
376
|
-
'/dist/public/*': ['public/*'],
|
|
377
|
-
},
|
|
378
|
-
},
|
|
379
|
-
proxyConfig: {
|
|
380
|
-
proxyUrl: '',
|
|
381
|
-
assetsOmit: true,
|
|
382
|
-
},
|
|
383
|
-
aditionalWatch: ['./app/templates/**/*.twig', './app/templates/**/*.html'],
|
|
384
|
-
// puede dejar en false o no agregarlo si no quiere que se ejecute el compilador de tailwind
|
|
385
|
-
tailwindConfig: {
|
|
386
|
-
bin: './node_modules/.bin/tailwindcss',
|
|
387
|
-
input: './src/css/input.css',
|
|
388
|
-
output: './public/css/output.css',
|
|
389
|
-
},
|
|
390
|
-
linter: [
|
|
391
|
-
{
|
|
392
|
-
name: 'eslint',
|
|
393
|
-
bin: './node_modules/.bin/eslint',
|
|
394
|
-
configFile: './.eslintrc.json',
|
|
395
|
-
fix: false,
|
|
396
|
-
paths: ['src/']
|
|
397
|
-
},
|
|
398
|
-
{
|
|
399
|
-
name: 'oxlint',
|
|
400
|
-
bin: './node_modules/.bin/oxlint',
|
|
401
|
-
configFile: './.oxlintrc.json',
|
|
402
|
-
fix: false,
|
|
403
|
-
paths: ['src/']
|
|
404
|
-
},
|
|
405
|
-
],
|
|
406
|
-
// Configuración de bundlers
|
|
407
|
-
bundlers: [
|
|
408
|
-
{
|
|
409
|
-
name: 'appLoader',
|
|
410
|
-
fileInput: './public/module/appLoader.js',
|
|
411
|
-
fileOutput: './public/module/appLoader.prod.js',
|
|
412
|
-
},
|
|
413
|
-
{
|
|
414
|
-
name: 'mainApp',
|
|
415
|
-
fileInput: './src/main.ts',
|
|
416
|
-
fileOutput: './dist/main.bundle.js',
|
|
417
|
-
}
|
|
418
|
-
],
|
|
419
|
-
};
|
|
420
|
-
`;
|
|
421
|
-
fs.writeFileSync(configPath, configContent, 'utf8');
|
|
422
|
-
logger.info(`🚩 Archivo de configuración '${env.PATH_CONFIG_FILE}' creado correctamente.`);
|
|
423
|
-
return true;
|
|
424
|
-
}
|
|
425
|
-
catch (error) {
|
|
426
|
-
logger.error(`🚩 Error al crear el archivo de configuración: ${error}`, error);
|
|
427
|
-
return false;
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
//# sourceMappingURL=readConfig.js.map
|
|
1
|
+
import{normalize as e,relative as d,resolve as f}from"node:path";import*as p from"node:process";import{env as m}from"node:process";import{pathToFileURL as h}from"node:url";import{logger as g}from"./logger.js";const _=260,v=1024*1024,y=/^[a-zA-Z0-9.\-_/\\:@ ()[\]]+$/,b=[/\.\./,/[;&|`$]/,/\$\(/,/`.*`/,/\|\s*[a-zA-Z]/];export function validatePath(m){if(!m||typeof m!=`string`)return!1;if(m.length>260)return g.warn(`Ruta demasiado larga: ${m.length} caracteres`),!1;let h=e(m),_=f(p.cwd(),h),v=d(p.cwd(),_);return v.startsWith(`..`)||h.includes(`..`)?(g.error(`Detectado intento de path traversal: ${m}`),!1):y.test(m)?!0:(g.error(`Caracteres no permitidos en la ruta: ${m}`),!1)}export function validateCommand(e){if(!e||typeof e!=`string`)return!1;if(e.length>260)return g.warn(`Comando demasiado largo: ${e.length} caracteres`),!1;for(let d of b)if(d.test(e))return g.error(`Detectado patrón peligroso en comando: ${e}`),!1;let d=[`.exe`,`.cmd`,`.bat`,`.sh`,`.js`,`.ts`],f=d.some(d=>e.toLowerCase().includes(d)||e.startsWith(`./node_modules/.bin/`)||e.startsWith(`npx `));return f?!0:(g.error(`Comando no permitido: ${e}`),!1)}export function validateBundlers(e){if(!Array.isArray(e))return g.error(`bundlers debe ser un array`),!1;for(let d of e){if(!d||typeof d!=`object`)return g.error(`Cada entrada de bundler debe ser un objeto`),!1;if(!d.name||typeof d.name!=`string`)return g.error(`Cada entrada de bundler debe tener un nombre válido`),!1;if(!d.fileInput||typeof d.fileInput!=`string`)return g.error(`Cada entrada de bundler debe tener un fileInput válido`),!1;if(!validatePath(d.fileInput))return g.error(`Ruta de entrada no válida: ${d.fileInput}`),!1;if(!d.fileOutput||typeof d.fileOutput!=`string`)return g.error(`Cada entrada de bundler debe tener un fileOutput válido`),!1;if(!validatePath(d.fileOutput))return g.error(`Ruta de salida no válida: ${d.fileOutput}`),!1}return!0}export function validateConfigStructure(e){if(!e||typeof e!=`object`)return g.error(`La configuración debe ser un objeto`),!1;if(!e.compilerOptions||typeof e.compilerOptions!=`object`)return g.error(`compilerOptions es requerido y debe ser un objeto`),!1;if(!e.compilerOptions.pathsAlias||typeof e.compilerOptions.pathsAlias!=`object`)return g.error(`pathsAlias es requerido y debe ser un objeto`),!1;for(let[d,f]of Object.entries(e.compilerOptions.pathsAlias)){if(!Array.isArray(f))return g.error(`pathsAlias["${d}"] debe ser un array`),!1;for(let e of f){if(typeof e!=`string`)return g.error(`Todas las rutas en pathsAlias["${d}"] deben ser strings`),!1;if(!validatePath(e.replace(`/*`,``)))return g.error(`Ruta no válida en pathsAlias["${d}"]: ${e}`),!1}}if(e.compilerOptions.sourceRoot&&!validatePath(e.compilerOptions.sourceRoot)||e.compilerOptions.outDir&&!validatePath(e.compilerOptions.outDir))return!1;if(e.linter&&e.linter!==!1){if(!Array.isArray(e.linter))return g.error(`linter debe ser un array o false`),!1;for(let d of e.linter)if(!validateLinter(d))return!1}return!0}export function validateLinter(e){if(!e||typeof e!=`object`)return g.error(`Cada linter debe ser un objeto`),!1;if(!e.name||typeof e.name!=`string`)return g.error(`Linter debe tener un nombre válido`),!1;if(!e.bin||typeof e.bin!=`string`)return g.error(`Linter debe tener un bin válido`),!1;if(!validateCommand(e.bin))return!1;if(!e.configFile||typeof e.configFile!=`string`)return g.error(`Linter debe tener un configFile válido`),!1;if(!validatePath(e.configFile))return!1;if(e.paths&&!Array.isArray(e.paths))return g.error(`linter.paths debe ser un array`),!1;if(e.paths){for(let d of e.paths)if(typeof d!=`string`||!validatePath(d))return g.error(`Ruta de linter no válida: ${d}`),!1}return e.fix!==void 0&&typeof e.fix!=`boolean`?(g.error(`Linter fix debe ser un booleano`),!1):!0}export function validateConfigSize(e){try{let d=JSON.stringify(e);return d.length>1048576?(g.error(`Configuración demasiado grande: ${d.length} bytes`),!1):!0}catch(e){return g.error(`Error al serializar configuración (posible referencia circular):`,e),!1}}function x(e){return!e||typeof e!=`string`?``:e.endsWith(`/`)||e.endsWith(`\\`)?e.slice(0,-1):e}function S(e,d=`false`){try{return e==null?d:JSON.stringify(e)}catch(e){return g.warn(`Error al serializar objeto, usando valor por defecto:`,e),d}}export async function dynamicImport(e){return import(e)}export function withTimeout(e,d,f){let p=new Promise((e,p)=>setTimeout(()=>p(Error(f)),d));return Promise.race([e,p])}export async function readConfig(){try{if(!m.PATH_CONFIG_FILE)throw Error(`La variable de entorno PATH_CONFIG_FILE no está definida.`);if(!validatePath(m.PATH_CONFIG_FILE))throw Error(`Ruta de configuración no válida: ${m.PATH_CONFIG_FILE}`);let e=h(m.PATH_CONFIG_FILE).href,d=dynamicImport(e),f=await withTimeout(d,1e4,`Timeout al cargar configuración`);if(!f)throw Error(`No se pudo leer el archivo de configuración.`);let p=f.default||f;if(!validateConfigSize(p))throw Error(`Configuración demasiado grande o contiene referencias circulares.`);if(!validateConfigStructure(p))throw Error(`El archivo de configuración no tiene una estructura válida.`);let _={...p.compilerOptions.pathsAlias};for(let e in _){let d=_[e];if(d&&Array.isArray(d))for(let e=0;e<d.length;e++)typeof d[e]==`string`&&d[e]!==void 0&&(d[e]=d[e].replace(`/*`,``))}m.PATH_ALIAS=S(_,`{}`),m.tailwindcss=S(p?.tailwindConfig,`false`),m.proxyUrl=String(p?.proxyConfig?.proxyUrl||``),m.AssetsOmit=String(p?.proxyConfig?.assetsOmit||!1),m.linter=S(p?.linter,`false`),m.tsconfigFile=p?.tsconfig||`./tsconfig.json`;let v=x(p?.compilerOptions?.sourceRoot||`./src`),y=x(p?.compilerOptions?.outDir||`./dist`);if(!validatePath(v))throw Error(`sourceRoot no válido: ${v}`);if(!validatePath(y))throw Error(`outDir no válido: ${y}`);return m.PATH_SOURCE=v,m.PATH_DIST=y,m.aditionalWatch=S(p?.aditionalWatch,`[]`),m.bundlers=S(p?.bundlers,`false`),p.compilerOptions.sourceRoot||(m.tsConfig=S(p,`{}`)),g.info(`✅ Configuration loaded and validated successfully`),!0}catch(e){return g.error(`🚩 Error al leer el archivo ${m.PATH_CONFIG_FILE}: ${e}`,e),!1}}export async function initConfig(){try{let e=await dynamicImport(`fs`),d=await dynamicImport(`path`),f=d.resolve(p.cwd(),m.PATH_CONFIG_FILE||`versacompile.config.ts`);if(!validatePath(f))throw Error(`Ruta de configuración no válida: ${f}`);if(e.existsSync(f))return g.warn(`🚩 El archivo de configuración '${m.PATH_CONFIG_FILE}' ya existe.`),!0;let h=`// Archivo de configuración de VersaCompiler
|
|
2
|
+
export default {
|
|
3
|
+
tsconfig: './tsconfig.json',
|
|
4
|
+
compilerOptions: {
|
|
5
|
+
sourceRoot: './src',
|
|
6
|
+
outDir: './dist',
|
|
7
|
+
pathsAlias: {
|
|
8
|
+
'/dist/examples/*': ['src/*'],
|
|
9
|
+
'/dist/public/*': ['public/*'],
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
proxyConfig: {
|
|
13
|
+
proxyUrl: '',
|
|
14
|
+
assetsOmit: true,
|
|
15
|
+
},
|
|
16
|
+
aditionalWatch: ['./app/templates/**/*.twig', './app/templates/**/*.html'],
|
|
17
|
+
// puede dejar en false o no agregarlo si no quiere que se ejecute el compilador de tailwind
|
|
18
|
+
tailwindConfig: {
|
|
19
|
+
bin: './node_modules/.bin/tailwindcss',
|
|
20
|
+
input: './src/css/input.css',
|
|
21
|
+
output: './public/css/output.css',
|
|
22
|
+
},
|
|
23
|
+
linter: [
|
|
24
|
+
{
|
|
25
|
+
name: 'eslint',
|
|
26
|
+
bin: './node_modules/.bin/eslint',
|
|
27
|
+
configFile: './.eslintrc.json',
|
|
28
|
+
fix: false,
|
|
29
|
+
paths: ['src/']
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: 'oxlint',
|
|
33
|
+
bin: './node_modules/.bin/oxlint',
|
|
34
|
+
configFile: './.oxlintrc.json',
|
|
35
|
+
fix: false,
|
|
36
|
+
paths: ['src/']
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
// Configuración de bundlers
|
|
40
|
+
bundlers: [
|
|
41
|
+
{
|
|
42
|
+
name: 'appLoader',
|
|
43
|
+
fileInput: './public/module/appLoader.js',
|
|
44
|
+
fileOutput: './public/module/appLoader.prod.js',
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: 'mainApp',
|
|
48
|
+
fileInput: './src/main.ts',
|
|
49
|
+
fileOutput: './dist/main.bundle.js',
|
|
50
|
+
}
|
|
51
|
+
],
|
|
52
|
+
};
|
|
53
|
+
`;return e.writeFileSync(f,`// Archivo de configuración de VersaCompiler
|
|
54
|
+
export default {
|
|
55
|
+
tsconfig: './tsconfig.json',
|
|
56
|
+
compilerOptions: {
|
|
57
|
+
sourceRoot: './src',
|
|
58
|
+
outDir: './dist',
|
|
59
|
+
pathsAlias: {
|
|
60
|
+
'/dist/examples/*': ['src/*'],
|
|
61
|
+
'/dist/public/*': ['public/*'],
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
proxyConfig: {
|
|
65
|
+
proxyUrl: '',
|
|
66
|
+
assetsOmit: true,
|
|
67
|
+
},
|
|
68
|
+
aditionalWatch: ['./app/templates/**/*.twig', './app/templates/**/*.html'],
|
|
69
|
+
// puede dejar en false o no agregarlo si no quiere que se ejecute el compilador de tailwind
|
|
70
|
+
tailwindConfig: {
|
|
71
|
+
bin: './node_modules/.bin/tailwindcss',
|
|
72
|
+
input: './src/css/input.css',
|
|
73
|
+
output: './public/css/output.css',
|
|
74
|
+
},
|
|
75
|
+
linter: [
|
|
76
|
+
{
|
|
77
|
+
name: 'eslint',
|
|
78
|
+
bin: './node_modules/.bin/eslint',
|
|
79
|
+
configFile: './.eslintrc.json',
|
|
80
|
+
fix: false,
|
|
81
|
+
paths: ['src/']
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: 'oxlint',
|
|
85
|
+
bin: './node_modules/.bin/oxlint',
|
|
86
|
+
configFile: './.oxlintrc.json',
|
|
87
|
+
fix: false,
|
|
88
|
+
paths: ['src/']
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
// Configuración de bundlers
|
|
92
|
+
bundlers: [
|
|
93
|
+
{
|
|
94
|
+
name: 'appLoader',
|
|
95
|
+
fileInput: './public/module/appLoader.js',
|
|
96
|
+
fileOutput: './public/module/appLoader.prod.js',
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: 'mainApp',
|
|
100
|
+
fileInput: './src/main.ts',
|
|
101
|
+
fileOutput: './dist/main.bundle.js',
|
|
102
|
+
}
|
|
103
|
+
],
|
|
104
|
+
};
|
|
105
|
+
`,`utf8`),g.info(`🚩 Archivo de configuración '${m.PATH_CONFIG_FILE}' creado correctamente.`),!0}catch(e){return g.error(`🚩 Error al crear el archivo de configuración: ${e}`,e),!1}}
|
|
@@ -1,36 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Lista centralizada de módulos excluidos de la resolución automática
|
|
3
|
-
* Estos módulos se mantienen con su importación original sin transformar
|
|
4
|
-
*/
|
|
5
|
-
export const EXCLUDED_MODULES = new Set([
|
|
6
|
-
// Módulos de Vue.js que requieren resolución específica
|
|
7
|
-
'vue/compiler-sfc',
|
|
8
|
-
'vue/dist/vue.runtime.esm-bundler',
|
|
9
|
-
'@vue/compiler-sfc',
|
|
10
|
-
'@vue/compiler-dom',
|
|
11
|
-
'@vue/runtime-core',
|
|
12
|
-
'@vue/runtime-dom',
|
|
13
|
-
// Módulos de oxc-parser que tienen dependencias específicas de WASM
|
|
14
|
-
'oxc-parser',
|
|
15
|
-
'oxc-parser/wasm',
|
|
16
|
-
'oxc-minify',
|
|
17
|
-
'oxc-minify/browser',
|
|
18
|
-
'@oxc-parser/binding-wasm32-wasi',
|
|
19
|
-
'@oxc-minify/binding-wasm32-wasi',
|
|
20
|
-
// Módulos de TypeScript que pueden tener resoluciones complejas
|
|
21
|
-
'typescript',
|
|
22
|
-
'typescript/lib/typescript',
|
|
23
|
-
// Módulos de herramientas de build y utilidades que deben mantenerse originales
|
|
24
|
-
'yargs',
|
|
25
|
-
'yargs/helpers',
|
|
26
|
-
'yargs-parser',
|
|
27
|
-
'chalk',
|
|
28
|
-
'browser-sync',
|
|
29
|
-
'chokidar',
|
|
30
|
-
'get-port',
|
|
31
|
-
'execa',
|
|
32
|
-
'find-root',
|
|
33
|
-
'fs-extra',
|
|
34
|
-
'minimatch', // ✅ Incluir minimatch aquí
|
|
35
|
-
]);
|
|
36
|
-
//# sourceMappingURL=excluded-modules.js.map
|
|
1
|
+
export const EXCLUDED_MODULES=new Set([`vue/compiler-sfc`,`vue/dist/vue.runtime.esm-bundler`,`@vue/compiler-sfc`,`@vue/compiler-dom`,`@vue/runtime-core`,`@vue/runtime-dom`,`oxc-parser`,`oxc-parser/wasm`,`oxc-minify`,`oxc-minify/browser`,`@oxc-parser/binding-wasm32-wasi`,`@oxc-minify/binding-wasm32-wasi`,`typescript`,`typescript/lib/typescript`,`yargs`,`yargs/helpers`,`yargs-parser`,`chalk`,`browser-sync`,`chokidar`,`get-port`,`execa`,`find-root`,`fs-extra`,`minimatch`]);
|