versacompiler 2.3.3 → 2.3.5
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 +106 -17
- package/dist/compiler/compile.js +21 -2
- package/dist/compiler/integrity-validator.js +527 -0
- package/dist/compiler/minify.js +19 -1
- package/dist/compiler/minifyTemplate.js +16 -0
- package/dist/compiler/transforms.js +34 -3
- package/dist/compiler/typescript-error-parser.js +113 -26
- package/dist/compiler/typescript-manager.js +10 -4
- package/dist/compiler/vuejs.js +16 -1
- package/dist/main.js +14 -2
- package/dist/servicios/readConfig.js +6 -3
- package/dist/utils/module-resolver.js +164 -154
- package/package.json +5 -4
|
@@ -6,6 +6,48 @@ import { cwd, env } from 'node:process';
|
|
|
6
6
|
// import resolve from '/node_modules/resolve/index.js';
|
|
7
7
|
import { logger } from '../servicios/logger.js';
|
|
8
8
|
import { EXCLUDED_MODULES } from './excluded-modules.js';
|
|
9
|
+
class PackageJsonCache {
|
|
10
|
+
static instance;
|
|
11
|
+
cache = new Map();
|
|
12
|
+
MAX_CACHE_SIZE = 200;
|
|
13
|
+
static getInstance() {
|
|
14
|
+
if (!PackageJsonCache.instance) {
|
|
15
|
+
PackageJsonCache.instance = new PackageJsonCache();
|
|
16
|
+
}
|
|
17
|
+
return PackageJsonCache.instance;
|
|
18
|
+
}
|
|
19
|
+
get(packagePath) {
|
|
20
|
+
try {
|
|
21
|
+
if (!fs.existsSync(packagePath)) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const stats = fs.statSync(packagePath);
|
|
25
|
+
const cached = this.cache.get(packagePath);
|
|
26
|
+
if (cached && cached.mtime === stats.mtimeMs) {
|
|
27
|
+
return cached.content;
|
|
28
|
+
}
|
|
29
|
+
const content = JSON.parse(readFileSync(packagePath, 'utf-8'));
|
|
30
|
+
if (this.cache.size >= this.MAX_CACHE_SIZE) {
|
|
31
|
+
const firstKey = this.cache.keys().next().value;
|
|
32
|
+
if (firstKey) {
|
|
33
|
+
this.cache.delete(firstKey);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
this.cache.set(packagePath, {
|
|
37
|
+
content,
|
|
38
|
+
mtime: stats.mtimeMs,
|
|
39
|
+
});
|
|
40
|
+
return content;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
clear() {
|
|
47
|
+
this.cache.clear();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const packageJsonCache = PackageJsonCache.getInstance();
|
|
9
51
|
// function resolveESMWithLibrary(moduleName: string): string | null {
|
|
10
52
|
// try {
|
|
11
53
|
// // Resolver el módulo
|
|
@@ -141,166 +183,130 @@ function findOptimalESMVersion(moduleDir, entryPoint) {
|
|
|
141
183
|
}
|
|
142
184
|
return optimizedPath;
|
|
143
185
|
}
|
|
144
|
-
}
|
|
145
|
-
|
|
186
|
+
}
|
|
187
|
+
// ✨ OPTIMIZACIÓN CRÍTICA: Clasificar archivos en un solo loop
|
|
188
|
+
const fileGroups = {
|
|
189
|
+
esmBrowserProd: [],
|
|
190
|
+
esmBrowserMin: [],
|
|
191
|
+
esmBrowserDev: [],
|
|
192
|
+
esmProd: [],
|
|
193
|
+
esmMin: [],
|
|
194
|
+
esmDev: [],
|
|
195
|
+
browserMin: [],
|
|
196
|
+
runtimeDev: [],
|
|
197
|
+
runtime: [],
|
|
198
|
+
other: [],
|
|
199
|
+
};
|
|
200
|
+
for (const file of files) {
|
|
201
|
+
if (!file.endsWith('.js') && !file.endsWith('.mjs'))
|
|
202
|
+
continue;
|
|
146
203
|
const lowerFile = file.toLowerCase();
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
// ✨ MODO PRODUCCIÓN: Priorizar .prod.js o .min.js
|
|
161
|
-
if (env.isPROD === 'true') {
|
|
162
|
-
// Primera opción: archivos .prod.js
|
|
163
|
-
const prodFiles = esmBrowserCombined.filter((file) => file.toLowerCase().includes('.prod.'));
|
|
164
|
-
if (prodFiles.length > 0 && prodFiles[0]) {
|
|
165
|
-
const optimizedPath = join(dir, prodFiles[0]).replace(/\\/g, '/');
|
|
166
|
-
if (env.VERBOSE === 'true') {
|
|
167
|
-
logger.info(`🏭 Versión ESM-Browser producción encontrada: ${optimizedPath}`);
|
|
168
|
-
}
|
|
169
|
-
return optimizedPath;
|
|
170
|
-
}
|
|
171
|
-
// Segunda opción: archivos .min.js
|
|
172
|
-
const minFiles = esmBrowserCombined.filter((file) => file.toLowerCase().includes('.min.'));
|
|
173
|
-
if (minFiles.length > 0 && minFiles[0]) {
|
|
174
|
-
const optimizedPath = join(dir, minFiles[0]).replace(/\\/g, '/');
|
|
175
|
-
if (env.VERBOSE === 'true') {
|
|
176
|
-
logger.info(`🗜️ Versión ESM-Browser minificada encontrada: ${optimizedPath}`);
|
|
177
|
-
}
|
|
178
|
-
return optimizedPath;
|
|
179
|
-
}
|
|
180
|
-
// Fallback: si no hay .prod ni .min, usar desarrollo
|
|
181
|
-
if (env.VERBOSE === 'true') {
|
|
182
|
-
logger.warn('⚠️ No se encontró versión de producción, usando desarrollo');
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
// ✨ MODO DESARROLLO: Priorizar desarrollo > .prod > .min
|
|
186
|
-
const devFiles = esmBrowserCombined.filter((file) => !file.toLowerCase().includes('.prod.') &&
|
|
187
|
-
!file.toLowerCase().includes('.min.'));
|
|
188
|
-
if (devFiles.length > 0 && devFiles[0]) {
|
|
189
|
-
const optimizedPath = join(dir, devFiles[0]).replace(/\\/g, '/');
|
|
190
|
-
if (env.VERBOSE === 'true') {
|
|
191
|
-
logger.info(`🔧 Versión ESM-Browser desarrollo encontrada: ${optimizedPath}`);
|
|
192
|
-
}
|
|
193
|
-
return optimizedPath;
|
|
194
|
-
}
|
|
195
|
-
// Fallback en desarrollo: si no hay versión dev, usar prod
|
|
196
|
-
const prodFiles = esmBrowserCombined.filter((file) => file.toLowerCase().includes('.prod.'));
|
|
197
|
-
if (prodFiles.length > 0 && prodFiles[0]) {
|
|
198
|
-
const optimizedPath = join(dir, prodFiles[0]).replace(/\\/g, '/');
|
|
199
|
-
if (env.VERBOSE === 'true') {
|
|
200
|
-
logger.info(`Versión ESM-Browser producción encontrada (fallback): ${optimizedPath}`);
|
|
201
|
-
}
|
|
202
|
-
return optimizedPath;
|
|
203
|
-
}
|
|
204
|
-
const minFiles = esmBrowserCombined.filter((file) => file.toLowerCase().includes('.min.'));
|
|
205
|
-
if (minFiles.length > 0 && minFiles[0]) {
|
|
206
|
-
const optimizedPath = join(dir, minFiles[0]).replace(/\\/g, '/');
|
|
207
|
-
if (env.VERBOSE === 'true') {
|
|
208
|
-
logger.info(`Versión ESM-Browser minificada encontrada (fallback): ${optimizedPath}`);
|
|
209
|
-
}
|
|
210
|
-
return optimizedPath;
|
|
211
|
-
}
|
|
212
|
-
if (esmBrowserCombined[0]) {
|
|
213
|
-
const optimizedPath = join(dir, esmBrowserCombined[0]).replace(/\\/g, '/');
|
|
214
|
-
if (env.VERBOSE === 'true') {
|
|
215
|
-
logger.info(`Versión ESM-Browser encontrada: ${optimizedPath}`);
|
|
216
|
-
}
|
|
217
|
-
return optimizedPath;
|
|
218
|
-
}
|
|
204
|
+
const hasEsmBrowser = lowerFile.includes('.esm-browser.');
|
|
205
|
+
const hasEsm = lowerFile.includes('.esm.') || lowerFile.includes('.module.');
|
|
206
|
+
const hasBrowser = lowerFile.includes('.browser.') || lowerFile.includes('.web.');
|
|
207
|
+
const hasRuntime = lowerFile.includes('.runtime.');
|
|
208
|
+
const isProd = lowerFile.includes('.prod.');
|
|
209
|
+
const isMin = lowerFile.includes('.min.');
|
|
210
|
+
if (hasEsmBrowser && !hasRuntime) {
|
|
211
|
+
if (isProd)
|
|
212
|
+
fileGroups.esmBrowserProd.push(file);
|
|
213
|
+
else if (isMin)
|
|
214
|
+
fileGroups.esmBrowserMin.push(file);
|
|
215
|
+
else
|
|
216
|
+
fileGroups.esmBrowserDev.push(file);
|
|
219
217
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
!file.toLowerCase().includes('.runtime.'));
|
|
228
|
-
if (esmProdFiles.length > 0 && esmProdFiles[0]) {
|
|
229
|
-
const optimizedPath = join(dir, esmProdFiles[0]).replace(/\\/g, '/');
|
|
230
|
-
if (env.VERBOSE === 'true') {
|
|
231
|
-
logger.info(`🏭 Versión ESM producción encontrada: ${optimizedPath}`);
|
|
232
|
-
}
|
|
233
|
-
return optimizedPath;
|
|
234
|
-
}
|
|
218
|
+
else if (hasEsm && !hasRuntime) {
|
|
219
|
+
if (isProd)
|
|
220
|
+
fileGroups.esmProd.push(file);
|
|
221
|
+
else if (isMin)
|
|
222
|
+
fileGroups.esmMin.push(file);
|
|
223
|
+
else
|
|
224
|
+
fileGroups.esmDev.push(file);
|
|
235
225
|
}
|
|
236
|
-
else {
|
|
237
|
-
|
|
238
|
-
const esmFiles = esmBrowserFiles.filter((file) => (file.toLowerCase().includes('.esm.') ||
|
|
239
|
-
file.toLowerCase().includes('.module.')) &&
|
|
240
|
-
!file.toLowerCase().includes('.min.') &&
|
|
241
|
-
!file.toLowerCase().includes('.prod.') &&
|
|
242
|
-
!file.toLowerCase().includes('.runtime.'));
|
|
243
|
-
if (esmFiles.length > 0 && esmFiles[0]) {
|
|
244
|
-
const optimizedPath = join(dir, esmFiles[0]).replace(/\\/g, '/');
|
|
245
|
-
if (env.VERBOSE === 'true') {
|
|
246
|
-
logger.info(`🔧 Versión ESM desarrollo encontrada: ${optimizedPath}`);
|
|
247
|
-
}
|
|
248
|
-
return optimizedPath;
|
|
249
|
-
}
|
|
226
|
+
else if (hasBrowser && isMin) {
|
|
227
|
+
fileGroups.browserMin.push(file);
|
|
250
228
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
// Priorizar ESM sobre browser sobre UMD
|
|
257
|
-
const esmFiles = minifiedFiles.filter((file) => file.toLowerCase().includes('.esm.') ||
|
|
258
|
-
file.toLowerCase().includes('.module.'));
|
|
259
|
-
if (esmFiles.length > 0 && esmFiles[0]) {
|
|
260
|
-
const optimizedPath = join(dir, esmFiles[0]).replace(/\\/g, '/');
|
|
261
|
-
if (env.VERBOSE === 'true') {
|
|
262
|
-
logger.info(`Versión ESM minificada encontrada: ${optimizedPath}`);
|
|
263
|
-
}
|
|
264
|
-
return optimizedPath;
|
|
265
|
-
}
|
|
266
|
-
if (minifiedFiles[0]) {
|
|
267
|
-
const optimizedPath = join(dir, minifiedFiles[0]).replace(/\\/g, '/');
|
|
268
|
-
if (env.VERBOSE === 'true') {
|
|
269
|
-
logger.info(`Versión minificada encontrada: ${optimizedPath}`);
|
|
270
|
-
}
|
|
271
|
-
return optimizedPath;
|
|
272
|
-
}
|
|
229
|
+
else if (hasRuntime && hasEsmBrowser) {
|
|
230
|
+
if (!isProd && !isMin)
|
|
231
|
+
fileGroups.runtimeDev.push(file);
|
|
232
|
+
else
|
|
233
|
+
fileGroups.runtime.push(file);
|
|
273
234
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
if (runtimeFiles.length > 0) {
|
|
277
|
-
// Priorizar desarrollo sobre producción en runtime también
|
|
278
|
-
const devRuntimeFiles = runtimeFiles.filter((file) => !file.toLowerCase().includes('.prod.') &&
|
|
279
|
-
!file.toLowerCase().includes('.min.'));
|
|
280
|
-
if (devRuntimeFiles.length > 0 && devRuntimeFiles[0]) {
|
|
281
|
-
const optimizedPath = join(dir, devRuntimeFiles[0]).replace(/\\/g, '/');
|
|
282
|
-
if (env.VERBOSE === 'true') {
|
|
283
|
-
logger.info(`Versión Runtime ESM-Browser dev encontrada: ${optimizedPath}`);
|
|
284
|
-
}
|
|
285
|
-
return optimizedPath;
|
|
286
|
-
}
|
|
287
|
-
if (runtimeFiles[0]) {
|
|
288
|
-
const optimizedPath = join(dir, runtimeFiles[0]).replace(/\\/g, '/');
|
|
289
|
-
if (env.VERBOSE === 'true') {
|
|
290
|
-
logger.info(`Versión Runtime ESM-Browser encontrada: ${optimizedPath}`);
|
|
291
|
-
}
|
|
292
|
-
return optimizedPath;
|
|
293
|
-
}
|
|
235
|
+
else if (hasEsm || hasBrowser) {
|
|
236
|
+
fileGroups.other.push(file);
|
|
294
237
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
238
|
+
}
|
|
239
|
+
// Seleccionar archivo según prioridad y modo
|
|
240
|
+
const isProd = env.isPROD === 'true';
|
|
241
|
+
// Prioridad 1: ESM-Browser
|
|
242
|
+
if (isProd) {
|
|
243
|
+
if (fileGroups.esmBrowserProd[0]) {
|
|
244
|
+
const optimizedPath = join(dir, fileGroups.esmBrowserProd[0]).replace(/\\/g, '/');
|
|
245
|
+
if (env.VERBOSE === 'true')
|
|
246
|
+
logger.info(`🏭 Versión ESM-Browser producción encontrada: ${optimizedPath}`);
|
|
247
|
+
return optimizedPath;
|
|
248
|
+
}
|
|
249
|
+
if (fileGroups.esmBrowserMin[0]) {
|
|
250
|
+
const optimizedPath = join(dir, fileGroups.esmBrowserMin[0]).replace(/\\/g, '/');
|
|
251
|
+
if (env.VERBOSE === 'true')
|
|
252
|
+
logger.info(`🗜️ Versión ESM-Browser minificada encontrada: ${optimizedPath}`);
|
|
301
253
|
return optimizedPath;
|
|
302
254
|
}
|
|
303
255
|
}
|
|
256
|
+
if (fileGroups.esmBrowserDev[0]) {
|
|
257
|
+
const optimizedPath = join(dir, fileGroups.esmBrowserDev[0]).replace(/\\/g, '/');
|
|
258
|
+
if (env.VERBOSE === 'true')
|
|
259
|
+
logger.info(`🔧 Versión ESM-Browser desarrollo encontrada: ${optimizedPath}`);
|
|
260
|
+
return optimizedPath;
|
|
261
|
+
}
|
|
262
|
+
// Prioridad 2: ESM puro
|
|
263
|
+
if (isProd) {
|
|
264
|
+
if (fileGroups.esmProd[0]) {
|
|
265
|
+
const optimizedPath = join(dir, fileGroups.esmProd[0]).replace(/\\/g, '/');
|
|
266
|
+
if (env.VERBOSE === 'true')
|
|
267
|
+
logger.info(`Versión ESM producción encontrada: ${optimizedPath}`);
|
|
268
|
+
return optimizedPath;
|
|
269
|
+
}
|
|
270
|
+
if (fileGroups.esmMin[0]) {
|
|
271
|
+
const optimizedPath = join(dir, fileGroups.esmMin[0]).replace(/\\/g, '/');
|
|
272
|
+
if (env.VERBOSE === 'true')
|
|
273
|
+
logger.info(`Versión ESM minificada encontrada: ${optimizedPath}`);
|
|
274
|
+
return optimizedPath;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (fileGroups.esmDev[0]) {
|
|
278
|
+
const optimizedPath = join(dir, fileGroups.esmDev[0]).replace(/\\/g, '/');
|
|
279
|
+
if (env.VERBOSE === 'true')
|
|
280
|
+
logger.info(`Versión ESM encontrada: ${optimizedPath}`);
|
|
281
|
+
return optimizedPath;
|
|
282
|
+
}
|
|
283
|
+
// Prioridad 3: Browser minificado
|
|
284
|
+
if (fileGroups.browserMin[0]) {
|
|
285
|
+
const optimizedPath = join(dir, fileGroups.browserMin[0]).replace(/\\/g, '/');
|
|
286
|
+
if (env.VERBOSE === 'true')
|
|
287
|
+
logger.info(`Versión browser minificada encontrada: ${optimizedPath}`);
|
|
288
|
+
return optimizedPath;
|
|
289
|
+
}
|
|
290
|
+
// Prioridad 4: Runtime
|
|
291
|
+
if (fileGroups.runtimeDev[0]) {
|
|
292
|
+
const optimizedPath = join(dir, fileGroups.runtimeDev[0]).replace(/\\/g, '/');
|
|
293
|
+
if (env.VERBOSE === 'true')
|
|
294
|
+
logger.info(`Versión Runtime ESM-Browser dev encontrada: ${optimizedPath}`);
|
|
295
|
+
return optimizedPath;
|
|
296
|
+
}
|
|
297
|
+
if (fileGroups.runtime[0]) {
|
|
298
|
+
const optimizedPath = join(dir, fileGroups.runtime[0]).replace(/\\/g, '/');
|
|
299
|
+
if (env.VERBOSE === 'true')
|
|
300
|
+
logger.info(`Versión Runtime ESM-Browser encontrada: ${optimizedPath}`);
|
|
301
|
+
return optimizedPath;
|
|
302
|
+
}
|
|
303
|
+
// Fallback: otros archivos browser/esm
|
|
304
|
+
if (fileGroups.other[0]) {
|
|
305
|
+
const optimizedPath = join(dir, fileGroups.other[0]).replace(/\\/g, '/');
|
|
306
|
+
if (env.VERBOSE === 'true')
|
|
307
|
+
logger.info(`Versión browser encontrada: ${optimizedPath}`);
|
|
308
|
+
return optimizedPath;
|
|
309
|
+
}
|
|
304
310
|
}
|
|
305
311
|
catch (error) {
|
|
306
312
|
if (env.VERBOSE === 'true') {
|
|
@@ -323,7 +329,9 @@ function simpleESMResolver(moduleName) {
|
|
|
323
329
|
catch {
|
|
324
330
|
return null;
|
|
325
331
|
}
|
|
326
|
-
const packageJson =
|
|
332
|
+
const packageJson = packageJsonCache.get(packagePath);
|
|
333
|
+
if (!packageJson)
|
|
334
|
+
return null;
|
|
327
335
|
const moduleDir = dirname(packagePath);
|
|
328
336
|
const isESM = packageJson.type === 'module'; // Determinar el entry point ESM/Browser optimizado
|
|
329
337
|
let entryPoint = null;
|
|
@@ -392,7 +400,7 @@ function simpleESMResolver(moduleName) {
|
|
|
392
400
|
entryPoint = isESM ? 'index.js' : 'index.cjs';
|
|
393
401
|
} // Resolver la ruta final
|
|
394
402
|
let finalPath = join(moduleDir, entryPoint);
|
|
395
|
-
// Buscar una versión ESM/browser optimizada
|
|
403
|
+
// Buscar una versión ESM/browser optimizada (garantizar que entryPoint es string)
|
|
396
404
|
const optimizedEntry = findOptimalESMVersion(moduleDir, entryPoint);
|
|
397
405
|
if (optimizedEntry && optimizedEntry !== entryPoint) {
|
|
398
406
|
finalPath = join(moduleDir, optimizedEntry);
|
|
@@ -507,7 +515,9 @@ export function getModuleSubPath(moduleName, fromFile) {
|
|
|
507
515
|
if (!fs.existsSync(packagePath)) {
|
|
508
516
|
return null;
|
|
509
517
|
}
|
|
510
|
-
const packageJson =
|
|
518
|
+
const packageJson = packageJsonCache.get(packagePath);
|
|
519
|
+
if (!packageJson)
|
|
520
|
+
return null;
|
|
511
521
|
const moduleDir = dirname(packagePath);
|
|
512
522
|
// Revisar exports field para subpaths
|
|
513
523
|
if (packageJson.exports &&
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "versacompiler",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.5",
|
|
4
4
|
"description": "Una herramienta para compilar y minificar archivos .vue, .js y .ts para proyectos de Vue 3 con soporte para TypeScript.",
|
|
5
5
|
"main": "dist/main.js",
|
|
6
6
|
"bin": {
|
|
@@ -18,13 +18,14 @@
|
|
|
18
18
|
"scripts": {
|
|
19
19
|
"dev": "tsx --watch src/main.ts --watch --verbose --tailwind",
|
|
20
20
|
"file": "tsx src/main.ts ",
|
|
21
|
-
"
|
|
22
|
-
"compileDev": "tsx src/main.ts --all --cc -y --verbose",
|
|
21
|
+
"build": "tsx src/main.ts --all -t --cc --co -y --verbose",
|
|
22
|
+
"compileDev": "tsx src/main.ts --all --ci --cc -y -t --linter --verbose",
|
|
23
|
+
"vlint": "tsx src/main.ts --all --cc --co -y --linter",
|
|
24
|
+
"vtlint": "tsx src/main.ts --all --cc --co -y -t",
|
|
23
25
|
"test": "vitest run",
|
|
24
26
|
"test:watch": "vitest",
|
|
25
27
|
"test:ui": "vitest --ui",
|
|
26
28
|
"test:coverage": "vitest run --coverage",
|
|
27
|
-
"build": "tsx src/main.ts --all -t --cc --co -y --verbose",
|
|
28
29
|
"lint": "oxlint --fix --config .oxlintrc.json",
|
|
29
30
|
"lint:eslint": "eslint --ext .js,.ts,.vue src/ --fix"
|
|
30
31
|
},
|