versacompiler 2.0.0 → 2.0.2
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 +345 -69
- package/dist/compiler/compile.js +762 -183
- package/dist/compiler/minify.js +199 -10
- package/dist/compiler/module-resolution-optimizer.js +822 -0
- package/dist/compiler/parser.js +179 -6
- package/dist/compiler/performance-monitor.js +192 -0
- package/dist/compiler/transform-optimizer.js +392 -0
- package/dist/compiler/transforms.js +124 -118
- package/dist/compiler/{typescript.js → typescript-compiler.js} +27 -30
- package/dist/compiler/typescript-error-parser.js +6 -7
- package/dist/compiler/typescript-manager.js +378 -0
- package/dist/compiler/typescript-sync-validator.js +13 -15
- package/dist/compiler/typescript-worker-pool.js +845 -0
- package/dist/compiler/typescript-worker.js +51 -21
- package/dist/compiler/vuejs.js +131 -37
- package/dist/main.js +5 -6
- package/dist/servicios/browserSync.js +313 -21
- package/dist/servicios/file-watcher.js +367 -0
- package/dist/servicios/logger.js +1 -0
- package/dist/servicios/readConfig.js +1 -0
- package/dist/utils/excluded-modules.js +36 -0
- package/dist/utils/module-resolver.js +9 -48
- package/dist/utils/promptUser.js +1 -1
- package/dist/utils/resolve-bin.js +28 -9
- package/package.json +8 -7
- package/dist/servicios/chokidar.js +0 -178
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import { readdir, rmdir, stat, unlink } from 'node:fs/promises';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { env } from 'node:process';
|
|
4
|
-
import chokidar from 'chokidar';
|
|
5
|
-
import { getOutputPath, initCompile, normalizeRuta } from '../compiler/compile.js';
|
|
6
|
-
import { promptUser } from '../utils/promptUser.js';
|
|
7
|
-
import { emitirCambios } from './browserSync.js';
|
|
8
|
-
import { logger } from './logger.js';
|
|
9
|
-
// Lazy loading para chalk
|
|
10
|
-
let chalk;
|
|
11
|
-
async function loadChalk() {
|
|
12
|
-
if (!chalk) {
|
|
13
|
-
chalk = (await import('chalk')).default;
|
|
14
|
-
}
|
|
15
|
-
return chalk;
|
|
16
|
-
}
|
|
17
|
-
// const cacheImportMap = new Map<string, string[]>();
|
|
18
|
-
// const cacheComponentMap = new Map<string, string[]>();
|
|
19
|
-
export async function cleanOutputDir(outputDir, primerInteraccion = true) {
|
|
20
|
-
try {
|
|
21
|
-
if (!outputDir) {
|
|
22
|
-
throw new Error('El directorio de salida no está definido');
|
|
23
|
-
}
|
|
24
|
-
if (primerInteraccion) {
|
|
25
|
-
const stats = await stat(outputDir).catch(() => null);
|
|
26
|
-
if (!stats || !stats.isDirectory()) {
|
|
27
|
-
logger.error(`🚩 El directorio de salida no existe o no es un directorio: ${outputDir}`);
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
try {
|
|
31
|
-
if (env.yes === 'false') {
|
|
32
|
-
const chalkInstance = await loadChalk();
|
|
33
|
-
const answer = await promptUser('\n\n¿Estás seguro deseas limpiar la carpeta ' +
|
|
34
|
-
chalkInstance.yellow(outputDir) +
|
|
35
|
-
'? (s / N) : ');
|
|
36
|
-
if (answer.toLowerCase() !== 's') {
|
|
37
|
-
logger.info('🛑 Compilación cancelada por el usuario.');
|
|
38
|
-
process.exit(0);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
logger.error(`Error en la entrada del usuario: ${error}`);
|
|
44
|
-
process.exit(1);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
const chalkInstance = await loadChalk();
|
|
48
|
-
logger.info(`🗑️ Limpiando directorio de salida: ${chalkInstance.yellow(outputDir)}\n`);
|
|
49
|
-
const items = await readdir(outputDir);
|
|
50
|
-
await Promise.all(items.map(async (item) => {
|
|
51
|
-
const itemPath = path.join(outputDir, item);
|
|
52
|
-
const itemStat = await stat(itemPath);
|
|
53
|
-
if (itemStat.isDirectory()) {
|
|
54
|
-
await rmdir(itemPath, { recursive: true });
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
await unlink(itemPath);
|
|
58
|
-
}
|
|
59
|
-
}));
|
|
60
|
-
logger.info(`✅ Directorio limpiado: ${outputDir}`);
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
logger.error(`🚩 Error al limpiar directorio de salida: ${error instanceof Error ? error.message : String(error)}`);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
async function deleteFile(filePath) {
|
|
67
|
-
try {
|
|
68
|
-
await unlink(filePath);
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
logger.error(`🚩 Error eliminando archivo ${filePath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
function getAction(ruta, extendsionWatch) {
|
|
77
|
-
const action = extendsionWatch
|
|
78
|
-
.filter((item) => item !== undefined)
|
|
79
|
-
.find(item => item.ext === ruta.split('.').pop())?.action;
|
|
80
|
-
return action || 'reloadFull';
|
|
81
|
-
}
|
|
82
|
-
export async function initChokidar(bs) {
|
|
83
|
-
try {
|
|
84
|
-
if (!env.PATH_SOURCE) {
|
|
85
|
-
logger.error('Error: La variable de entorno PATH_SOURCE no está definida.');
|
|
86
|
-
process.exit(1);
|
|
87
|
-
}
|
|
88
|
-
const watchJS = `${env.PATH_SOURCE}/**/*.js`;
|
|
89
|
-
const watchVue = `${env.PATH_SOURCE}/**/*.vue`;
|
|
90
|
-
const watchTS = `${env.PATH_SOURCE}/**/*.ts`;
|
|
91
|
-
const watchCJS = `${env.PATH_SOURCE}/**/*.cjs`;
|
|
92
|
-
const watchMJS = `${env.PATH_SOURCE}/**/*.mjs`;
|
|
93
|
-
//TODO: agregar watch para CSS
|
|
94
|
-
const watchAditional = JSON.parse(env.aditionalWatch || '[]');
|
|
95
|
-
let fileWatch = [watchJS, watchVue, watchTS, watchCJS, watchMJS, ...watchAditional];
|
|
96
|
-
//extraer sólo las extesniones de fileWatch
|
|
97
|
-
const accionExtension = {
|
|
98
|
-
vue: 'HRMVue',
|
|
99
|
-
js: 'HRMHelper',
|
|
100
|
-
ts: 'HRMHelper',
|
|
101
|
-
cjs: 'HRMHelper',
|
|
102
|
-
mjs: 'HRMHelper',
|
|
103
|
-
};
|
|
104
|
-
const extendsionWatch = fileWatch.map(item => {
|
|
105
|
-
const ext = item.split('.').pop();
|
|
106
|
-
if (ext) {
|
|
107
|
-
return {
|
|
108
|
-
ext,
|
|
109
|
-
action: accionExtension[ext] ||
|
|
110
|
-
'reloadFull',
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
if (extendsionWatch.length === 0 || extendsionWatch[0] === undefined) {
|
|
115
|
-
throw new Error('No se encontraron extensiones para observar');
|
|
116
|
-
}
|
|
117
|
-
const regExtExtension = new RegExp(`\\.(?!${extendsionWatch
|
|
118
|
-
.filter(item => item !== undefined)
|
|
119
|
-
.map(item => item.ext)
|
|
120
|
-
.join('$|')}$).+$`);
|
|
121
|
-
fileWatch = fileWatch.map(item => item.replace(/\/\*\*\//g, '/'));
|
|
122
|
-
const directories = new Map();
|
|
123
|
-
fileWatch.forEach(item => {
|
|
124
|
-
const dir = item.substring(0, item.lastIndexOf('/'));
|
|
125
|
-
if (!directories.has(dir)) {
|
|
126
|
-
directories.set(dir, []);
|
|
127
|
-
}
|
|
128
|
-
directories.get(dir).push(item);
|
|
129
|
-
});
|
|
130
|
-
const DirWatch = Array.from(directories.keys());
|
|
131
|
-
const watcher = chokidar.watch(DirWatch, {
|
|
132
|
-
persistent: true,
|
|
133
|
-
ignoreInitial: true,
|
|
134
|
-
ignored: regExtExtension,
|
|
135
|
-
});
|
|
136
|
-
watcher.on('ready', async () => {
|
|
137
|
-
const chalkInstance = await loadChalk();
|
|
138
|
-
logger.info(chalkInstance.green(`👀 : Listo para observar \n${fileWatch
|
|
139
|
-
.map((item) => `${item}`)
|
|
140
|
-
.join('\n')}\n`));
|
|
141
|
-
});
|
|
142
|
-
// Evento cuando se añade un archivo
|
|
143
|
-
watcher.on('add', async (ruta) => {
|
|
144
|
-
const action = getAction(ruta, extendsionWatch.filter((item) => item !== undefined));
|
|
145
|
-
const result = await initCompile(ruta, true, 'watch');
|
|
146
|
-
if (result.success) {
|
|
147
|
-
let accion = result.action || action;
|
|
148
|
-
accion = accion == 'extension' ? action : accion;
|
|
149
|
-
emitirCambios(bs, accion || 'reloadFull', result.output);
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
// Evento cuando se modifica un archivo
|
|
153
|
-
watcher.on('change', async (ruta) => {
|
|
154
|
-
const action = getAction(ruta, extendsionWatch.filter((item) => item !== undefined));
|
|
155
|
-
const result = await initCompile(ruta, true, 'watch');
|
|
156
|
-
if (result.success) {
|
|
157
|
-
let accion = result.action || action;
|
|
158
|
-
accion = accion == 'extension' ? action : accion;
|
|
159
|
-
emitirCambios(bs, accion || 'reloadFull', result.output);
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
// Evento cuando se elimina un archivo
|
|
163
|
-
watcher.on('unlink', async (ruta) => {
|
|
164
|
-
logger.info(`\n🗑️ eliminando archivo: ${ruta}`);
|
|
165
|
-
const result = await deleteFile(getOutputPath(normalizeRuta(ruta)));
|
|
166
|
-
if (result) {
|
|
167
|
-
logger.info(`Archivo eliminado: ${ruta}`);
|
|
168
|
-
emitirCambios(bs, 'reloadFull', ruta);
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
return watcher;
|
|
172
|
-
}
|
|
173
|
-
catch (error) {
|
|
174
|
-
logger.error(`🚩 :Error al iniciar watch: ${error instanceof Error ? error.message : String(error)}`);
|
|
175
|
-
process.exit(1);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
//# sourceMappingURL=chokidar.js.map
|