versacompiler 2.4.1 → 2.6.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 +722 -722
- package/dist/compiler/compile-worker-pool.js +108 -0
- package/dist/compiler/compile-worker-thread.cjs +72 -0
- package/dist/compiler/compile.js +177 -18
- package/dist/compiler/error-reporter.js +12 -0
- package/dist/compiler/integrity-validator.js +13 -1
- package/dist/compiler/linter.js +12 -0
- package/dist/compiler/minify.js +12 -0
- package/dist/compiler/minifyTemplate.js +12 -0
- package/dist/compiler/module-resolution-optimizer.js +35 -20
- package/dist/compiler/parser.js +12 -0
- package/dist/compiler/performance-monitor.js +73 -61
- package/dist/compiler/pipeline/build-pipeline.js +139 -0
- package/dist/compiler/pipeline/core-plugins.js +230 -0
- package/dist/compiler/pipeline/module-graph.js +75 -0
- package/dist/compiler/pipeline/plugin-driver.js +99 -0
- package/dist/compiler/pipeline/types.js +14 -0
- package/dist/compiler/tailwindcss.js +12 -0
- package/dist/compiler/transform-optimizer.js +12 -0
- package/dist/compiler/transformTStoJS.js +38 -5
- package/dist/compiler/transforms.js +234 -16
- package/dist/compiler/typescript-compiler.js +12 -0
- package/dist/compiler/typescript-error-parser.js +12 -0
- package/dist/compiler/typescript-manager.js +15 -1
- package/dist/compiler/typescript-sync-validator.js +45 -31
- package/dist/compiler/typescript-worker-pool.js +12 -0
- package/dist/compiler/typescript-worker-thread.cjs +482 -475
- package/dist/compiler/typescript-worker.js +12 -0
- package/dist/compiler/vuejs.js +73 -47
- package/dist/config.js +14 -0
- package/dist/hrm/VueHRM.js +484 -359
- package/dist/hrm/errorScreen.js +95 -83
- package/dist/hrm/getInstanciaVue.js +325 -313
- package/dist/hrm/initHRM.js +736 -586
- package/dist/hrm/versaHMR.js +317 -0
- package/dist/main.js +23 -3
- package/dist/servicios/browserSync.js +127 -6
- package/dist/servicios/file-watcher.js +139 -8
- package/dist/servicios/logger.js +12 -0
- package/dist/servicios/readConfig.js +141 -54
- package/dist/servicios/versacompile.config.types.js +14 -0
- package/dist/utils/excluded-modules.js +12 -0
- package/dist/utils/module-resolver.js +86 -40
- package/dist/utils/promptUser.js +12 -0
- package/dist/utils/proxyValidator.js +12 -0
- package/dist/utils/resolve-bin.js +12 -0
- package/dist/utils/utils.js +12 -0
- package/dist/utils/vue-types-setup.js +260 -248
- package/dist/wrappers/eslint-node.js +15 -1
- package/dist/wrappers/oxlint-node.js +15 -1
- package/dist/wrappers/tailwind-node.js +12 -0
- package/package.json +74 -54
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
/* VersaCompiler HMR shim [dev] */
|
|
2
|
+
if (typeof window !== 'undefined' && window.__versaHMR) {
|
|
3
|
+
(() => {
|
|
4
|
+
const _id = new URL(import.meta.url).pathname;
|
|
5
|
+
import.meta.hot = {
|
|
6
|
+
accept(cb) { window.__versaHMR.accept(_id, typeof cb === 'function' ? cb : () => {}); },
|
|
7
|
+
invalidate() { window.__versaHMR._invalidate?.(_id); },
|
|
8
|
+
dispose(cb) { window.__versaHMR._onDispose?.(_id, cb); },
|
|
9
|
+
get data() { return window.__versaHMR._getHotData?.(_id) ?? {}; },
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
}
|
|
1
13
|
/**
|
|
2
14
|
* Module Resolution Optimizer
|
|
3
15
|
*
|
|
@@ -14,6 +26,7 @@ import { dirname, join, relative } from 'node:path';
|
|
|
14
26
|
import { cwd, env } from 'node:process';
|
|
15
27
|
import { logger } from '../servicios/logger.js';
|
|
16
28
|
import { EXCLUDED_MODULES } from '../utils/excluded-modules.js';
|
|
29
|
+
import { parseModuleSpecifier, resolveExportValue, } from '../utils/module-resolver.js';
|
|
17
30
|
/**
|
|
18
31
|
* Sistema de optimización de resolución de módulos
|
|
19
32
|
* Implementa indexación, caché y búsquedas O(1)
|
|
@@ -122,7 +135,7 @@ export class ModuleResolutionOptimizer {
|
|
|
122
135
|
for (const entry of entries) {
|
|
123
136
|
const modulePath = join(nodeModulesPath, entry);
|
|
124
137
|
try {
|
|
125
|
-
if (entry.startsWith('/dist/
|
|
138
|
+
if (entry.startsWith('/dist/public')) {
|
|
126
139
|
// Scoped packages
|
|
127
140
|
const scopedModules = readdirSync(modulePath);
|
|
128
141
|
this.metrics.filesystemAccess++;
|
|
@@ -207,10 +220,7 @@ export class ModuleResolutionOptimizer {
|
|
|
207
220
|
entryPoint = dotExport;
|
|
208
221
|
}
|
|
209
222
|
else if (typeof dotExport === 'object') {
|
|
210
|
-
entryPoint =
|
|
211
|
-
dotExport.import ||
|
|
212
|
-
dotExport.browser ||
|
|
213
|
-
dotExport.default;
|
|
223
|
+
entryPoint = resolveExportValue(dotExport);
|
|
214
224
|
}
|
|
215
225
|
}
|
|
216
226
|
}
|
|
@@ -420,7 +430,9 @@ export class ModuleResolutionOptimizer {
|
|
|
420
430
|
this.aliasIndex = [];
|
|
421
431
|
// Convertir alias a índice con prioridad
|
|
422
432
|
for (const [alias, target] of Object.entries(pathAlias)) {
|
|
423
|
-
|
|
433
|
+
// Quitar solo el '*' final para conservar el separador '/'
|
|
434
|
+
// Ejemplo: '@/*' → '@/', así '@vueuse/core' no hace match pero '@/foo' sí
|
|
435
|
+
const pattern = alias.replace('*', '');
|
|
424
436
|
const priority = pattern.length; // Patrones más largos tienen prioridad
|
|
425
437
|
// El regex debe coincidir con el patrón al inicio, seguido de cualquier cosa o fin de cadena
|
|
426
438
|
// Por ejemplo, para "@/" debe coincidir con "@/cualquier-cosa" o solo "@/"
|
|
@@ -453,6 +465,7 @@ export class ModuleResolutionOptimizer {
|
|
|
453
465
|
path: null,
|
|
454
466
|
cached: false,
|
|
455
467
|
resolveTime: performance.now() - startTime,
|
|
468
|
+
excluded: true,
|
|
456
469
|
};
|
|
457
470
|
}
|
|
458
471
|
// Crear clave de caché
|
|
@@ -472,13 +485,16 @@ export class ModuleResolutionOptimizer {
|
|
|
472
485
|
// Resolver módulo
|
|
473
486
|
let resolvedPath = null;
|
|
474
487
|
try {
|
|
475
|
-
// 1.
|
|
476
|
-
|
|
488
|
+
// 1. Parse specifier to correctly handle scoped packages
|
|
489
|
+
const { packageName, subPath } = parseModuleSpecifier(moduleName);
|
|
490
|
+
if (subPath) {
|
|
491
|
+
// Has a real subpath (e.g. 'vue/dist/x' or '@scope/pkg/sub')
|
|
477
492
|
resolvedPath = await this.resolveSubPath(moduleName);
|
|
478
493
|
}
|
|
479
494
|
else {
|
|
495
|
+
// Direct package (e.g. 'vue' or '@vueuse/core')
|
|
480
496
|
// 2. Búsqueda O(1) en el índice
|
|
481
|
-
resolvedPath = this.resolveFromIndex(
|
|
497
|
+
resolvedPath = this.resolveFromIndex(packageName);
|
|
482
498
|
}
|
|
483
499
|
// 3. Si no se encuentra en índice, intentar resolución tradicional
|
|
484
500
|
if (!resolvedPath) {
|
|
@@ -521,8 +537,7 @@ export class ModuleResolutionOptimizer {
|
|
|
521
537
|
* Resuelve subpaths de módulos (ej: 'vue/dist/vue.esm-bundler')
|
|
522
538
|
*/
|
|
523
539
|
async resolveSubPath(moduleName) {
|
|
524
|
-
const
|
|
525
|
-
const subPath = subPathParts.join('/');
|
|
540
|
+
const { packageName, subPath } = parseModuleSpecifier(moduleName);
|
|
526
541
|
if (!packageName) {
|
|
527
542
|
return null;
|
|
528
543
|
}
|
|
@@ -531,19 +546,19 @@ export class ModuleResolutionOptimizer {
|
|
|
531
546
|
if (!moduleInfo) {
|
|
532
547
|
return null;
|
|
533
548
|
}
|
|
549
|
+
// If no subPath, resolve as direct package
|
|
550
|
+
if (!subPath) {
|
|
551
|
+
const entryPoint = moduleInfo.optimizedEntry || moduleInfo.entryPoint;
|
|
552
|
+
return join(moduleInfo.fullPath, entryPoint);
|
|
553
|
+
}
|
|
534
554
|
// Verificar exports field para subpaths
|
|
535
555
|
if (moduleInfo.hasExports && moduleInfo.packageJson.exports) {
|
|
536
556
|
const exportKey = `./${subPath}`;
|
|
537
557
|
const exportPath = moduleInfo.packageJson.exports[exportKey];
|
|
538
558
|
if (exportPath) {
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
else if (typeof exportPath === 'object') {
|
|
543
|
-
const importPath = exportPath.import || exportPath.default;
|
|
544
|
-
if (typeof importPath === 'string') {
|
|
545
|
-
return join(moduleInfo.fullPath, importPath);
|
|
546
|
-
}
|
|
559
|
+
const resolved = resolveExportValue(exportPath);
|
|
560
|
+
if (resolved) {
|
|
561
|
+
return join(moduleInfo.fullPath, resolved);
|
|
547
562
|
}
|
|
548
563
|
}
|
|
549
564
|
}
|
|
@@ -872,7 +887,7 @@ export class ModuleResolutionOptimizer {
|
|
|
872
887
|
export async function getOptimizedModulePath(moduleName, fromFile) {
|
|
873
888
|
const optimizer = ModuleResolutionOptimizer.getInstance();
|
|
874
889
|
const result = await optimizer.resolveModule(moduleName, fromFile);
|
|
875
|
-
return result.path;
|
|
890
|
+
return { path: result.path, excluded: result.excluded === true };
|
|
876
891
|
}
|
|
877
892
|
export function getOptimizedAliasPath(path) {
|
|
878
893
|
const optimizer = ModuleResolutionOptimizer.getInstance();
|
package/dist/compiler/parser.js
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
/* VersaCompiler HMR shim [dev] */
|
|
2
|
+
if (typeof window !== 'undefined' && window.__versaHMR) {
|
|
3
|
+
(() => {
|
|
4
|
+
const _id = new URL(import.meta.url).pathname;
|
|
5
|
+
import.meta.hot = {
|
|
6
|
+
accept(cb) { window.__versaHMR.accept(_id, typeof cb === 'function' ? cb : () => {}); },
|
|
7
|
+
invalidate() { window.__versaHMR._invalidate?.(_id); },
|
|
8
|
+
dispose(cb) { window.__versaHMR._onDispose?.(_id, cb); },
|
|
9
|
+
get data() { return window.__versaHMR._getHotData?.(_id) ?? {}; },
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
}
|
|
1
13
|
import { createHash } from 'node:crypto';
|
|
2
14
|
import { statSync } from 'node:fs';
|
|
3
15
|
import { open, readFile } from 'node:fs/promises';
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
/* VersaCompiler HMR shim [dev] */
|
|
2
|
+
if (typeof window !== 'undefined' && window.__versaHMR) {
|
|
3
|
+
(() => {
|
|
4
|
+
const _id = new URL(import.meta.url).pathname;
|
|
5
|
+
import.meta.hot = {
|
|
6
|
+
accept(cb) { window.__versaHMR.accept(_id, typeof cb === 'function' ? cb : () => {}); },
|
|
7
|
+
invalidate() { window.__versaHMR._invalidate?.(_id); },
|
|
8
|
+
dispose(cb) { window.__versaHMR._onDispose?.(_id, cb); },
|
|
9
|
+
get data() { return window.__versaHMR._getHotData?.(_id) ?? {}; },
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
}
|
|
1
13
|
/**
|
|
2
14
|
* Performance Monitor - Sistema centralizado de monitoreo de optimizaciones
|
|
3
15
|
* Reúne todas las métricas de cache y performance del VersaCompiler
|
|
@@ -85,67 +97,67 @@ export class PerformanceMonitor {
|
|
|
85
97
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
86
98
|
return (parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]);
|
|
87
99
|
};
|
|
88
|
-
const report = `
|
|
89
|
-
🚀 VERSACOMPILER PERFORMANCE REPORT
|
|
90
|
-
=====================================
|
|
91
|
-
|
|
92
|
-
📊 RESUMEN GENERAL
|
|
93
|
-
Hit Rate Total: ${stats.summary.overallHitRate}%
|
|
94
|
-
Cache Hits: ${stats.summary.totalCacheHits}
|
|
95
|
-
Cache Misses: ${stats.summary.totalCacheMisses}
|
|
96
|
-
Memoria Total: ${formatBytes(stats.summary.totalMemoryUsage)}
|
|
97
|
-
Entradas Cache: ${stats.summary.totalCacheEntries}
|
|
98
|
-
|
|
99
|
-
🎯 VUE HMR CACHE
|
|
100
|
-
Size: ${stats.vueHMRCache.size}/${stats.vueHMRCache.maxSize}
|
|
101
|
-
TTL: ${Math.round(stats.vueHMRCache.ttl / 1000 / 60)}min
|
|
102
|
-
|
|
103
|
-
📝 PARSER AST CACHE
|
|
104
|
-
Hit Rate: ${stats.parserCache.hitRate}%
|
|
105
|
-
Cache Hits: ${stats.parserCache.cacheHits}
|
|
106
|
-
Cache Misses: ${stats.parserCache.cacheMisses}
|
|
107
|
-
Size: ${stats.parserCache.cacheSize}/${stats.parserCache.maxCacheSize}
|
|
108
|
-
Memoria: ${formatBytes(stats.parserCache.memoryUsage)}/${formatBytes(stats.parserCache.maxMemoryUsage)}
|
|
109
|
-
|
|
110
|
-
📖 FILE CONTENT CACHE
|
|
111
|
-
Hit Rate: ${stats.fileContentCache.hitRate}%
|
|
112
|
-
Cache Hits: ${stats.fileContentCache.cacheHits}
|
|
113
|
-
Cache Misses: ${stats.fileContentCache.cacheMisses}
|
|
114
|
-
Size: ${stats.fileContentCache.cacheSize}/${stats.fileContentCache.maxCacheSize}
|
|
115
|
-
|
|
116
|
-
🌐 BROWSERSYNC FILE CACHE
|
|
117
|
-
Hit Rate: ${stats.browserSyncCache.hitRate}%
|
|
118
|
-
Cache Hits: ${stats.browserSyncCache.cacheHits}
|
|
119
|
-
Cache Misses: ${stats.browserSyncCache.cacheMisses}
|
|
120
|
-
Size: ${stats.browserSyncCache.cacheSize}/${stats.browserSyncCache.maxCacheSize}
|
|
121
|
-
Memoria: ${formatBytes(stats.browserSyncCache.memoryUsage)}/${formatBytes(stats.browserSyncCache.maxMemoryUsage)}
|
|
122
|
-
|
|
123
|
-
🗜️ MINIFICATION CACHE
|
|
124
|
-
Hit Rate: ${stats.minificationCache.hitRate}%
|
|
125
|
-
Cache Hits: ${stats.minificationCache.cacheHits}
|
|
126
|
-
Cache Misses: ${stats.minificationCache.cacheMisses}
|
|
127
|
-
Size: ${stats.minificationCache.cacheSize}/${stats.minificationCache.maxCacheSize}
|
|
128
|
-
Memoria: ${formatBytes(stats.minificationCache.memoryUsage)}/${formatBytes(stats.minificationCache.maxMemoryUsage)}
|
|
129
|
-
Compresión Promedio: ${stats.minificationCache.avgCompressionRatio}%
|
|
130
|
-
|
|
131
|
-
🔄 TRANSFORM OPTIMIZER
|
|
132
|
-
Hit Rate: ${stats.transformOptimizer.hitRate}%
|
|
133
|
-
Cache Hits: ${stats.transformOptimizer.cacheHits}
|
|
134
|
-
Cache Misses: ${stats.transformOptimizer.cacheMisses}
|
|
135
|
-
Transformaciones: ${stats.transformOptimizer.totalTransforms}
|
|
136
|
-
Size: ${stats.transformOptimizer.cacheSize}
|
|
137
|
-
Memoria: ${formatBytes(stats.transformOptimizer.memoryUsage)}
|
|
138
|
-
|
|
139
|
-
📦 MODULE RESOLUTION
|
|
140
|
-
Hit Rate: ${stats.moduleResolution.cacheHitRate?.toFixed(1)}%
|
|
141
|
-
Cache Hits: ${stats.moduleResolution.cacheHits}
|
|
142
|
-
Cache Misses: ${stats.moduleResolution.cacheMisses}
|
|
143
|
-
Resoluciones: ${stats.moduleResolution.totalResolutions}
|
|
144
|
-
Índice Módulos: ${stats.moduleResolution.moduleIndexSize}
|
|
145
|
-
Índice Alias: ${stats.moduleResolution.aliasIndexSize}
|
|
146
|
-
Tiempo Promedio: ${stats.moduleResolution.averageResolveTime?.toFixed(2)}ms
|
|
147
|
-
|
|
148
|
-
=====================================
|
|
100
|
+
const report = `
|
|
101
|
+
🚀 VERSACOMPILER PERFORMANCE REPORT
|
|
102
|
+
=====================================
|
|
103
|
+
|
|
104
|
+
📊 RESUMEN GENERAL
|
|
105
|
+
Hit Rate Total: ${stats.summary.overallHitRate}%
|
|
106
|
+
Cache Hits: ${stats.summary.totalCacheHits}
|
|
107
|
+
Cache Misses: ${stats.summary.totalCacheMisses}
|
|
108
|
+
Memoria Total: ${formatBytes(stats.summary.totalMemoryUsage)}
|
|
109
|
+
Entradas Cache: ${stats.summary.totalCacheEntries}
|
|
110
|
+
|
|
111
|
+
🎯 VUE HMR CACHE
|
|
112
|
+
Size: ${stats.vueHMRCache.size}/${stats.vueHMRCache.maxSize}
|
|
113
|
+
TTL: ${Math.round(stats.vueHMRCache.ttl / 1000 / 60)}min
|
|
114
|
+
|
|
115
|
+
📝 PARSER AST CACHE
|
|
116
|
+
Hit Rate: ${stats.parserCache.hitRate}%
|
|
117
|
+
Cache Hits: ${stats.parserCache.cacheHits}
|
|
118
|
+
Cache Misses: ${stats.parserCache.cacheMisses}
|
|
119
|
+
Size: ${stats.parserCache.cacheSize}/${stats.parserCache.maxCacheSize}
|
|
120
|
+
Memoria: ${formatBytes(stats.parserCache.memoryUsage)}/${formatBytes(stats.parserCache.maxMemoryUsage)}
|
|
121
|
+
|
|
122
|
+
📖 FILE CONTENT CACHE
|
|
123
|
+
Hit Rate: ${stats.fileContentCache.hitRate}%
|
|
124
|
+
Cache Hits: ${stats.fileContentCache.cacheHits}
|
|
125
|
+
Cache Misses: ${stats.fileContentCache.cacheMisses}
|
|
126
|
+
Size: ${stats.fileContentCache.cacheSize}/${stats.fileContentCache.maxCacheSize}
|
|
127
|
+
|
|
128
|
+
🌐 BROWSERSYNC FILE CACHE
|
|
129
|
+
Hit Rate: ${stats.browserSyncCache.hitRate}%
|
|
130
|
+
Cache Hits: ${stats.browserSyncCache.cacheHits}
|
|
131
|
+
Cache Misses: ${stats.browserSyncCache.cacheMisses}
|
|
132
|
+
Size: ${stats.browserSyncCache.cacheSize}/${stats.browserSyncCache.maxCacheSize}
|
|
133
|
+
Memoria: ${formatBytes(stats.browserSyncCache.memoryUsage)}/${formatBytes(stats.browserSyncCache.maxMemoryUsage)}
|
|
134
|
+
|
|
135
|
+
🗜️ MINIFICATION CACHE
|
|
136
|
+
Hit Rate: ${stats.minificationCache.hitRate}%
|
|
137
|
+
Cache Hits: ${stats.minificationCache.cacheHits}
|
|
138
|
+
Cache Misses: ${stats.minificationCache.cacheMisses}
|
|
139
|
+
Size: ${stats.minificationCache.cacheSize}/${stats.minificationCache.maxCacheSize}
|
|
140
|
+
Memoria: ${formatBytes(stats.minificationCache.memoryUsage)}/${formatBytes(stats.minificationCache.maxMemoryUsage)}
|
|
141
|
+
Compresión Promedio: ${stats.minificationCache.avgCompressionRatio}%
|
|
142
|
+
|
|
143
|
+
🔄 TRANSFORM OPTIMIZER
|
|
144
|
+
Hit Rate: ${stats.transformOptimizer.hitRate}%
|
|
145
|
+
Cache Hits: ${stats.transformOptimizer.cacheHits}
|
|
146
|
+
Cache Misses: ${stats.transformOptimizer.cacheMisses}
|
|
147
|
+
Transformaciones: ${stats.transformOptimizer.totalTransforms}
|
|
148
|
+
Size: ${stats.transformOptimizer.cacheSize}
|
|
149
|
+
Memoria: ${formatBytes(stats.transformOptimizer.memoryUsage)}
|
|
150
|
+
|
|
151
|
+
📦 MODULE RESOLUTION
|
|
152
|
+
Hit Rate: ${stats.moduleResolution.cacheHitRate?.toFixed(1)}%
|
|
153
|
+
Cache Hits: ${stats.moduleResolution.cacheHits}
|
|
154
|
+
Cache Misses: ${stats.moduleResolution.cacheMisses}
|
|
155
|
+
Resoluciones: ${stats.moduleResolution.totalResolutions}
|
|
156
|
+
Índice Módulos: ${stats.moduleResolution.moduleIndexSize}
|
|
157
|
+
Índice Alias: ${stats.moduleResolution.aliasIndexSize}
|
|
158
|
+
Tiempo Promedio: ${stats.moduleResolution.averageResolveTime?.toFixed(2)}ms
|
|
159
|
+
|
|
160
|
+
=====================================
|
|
149
161
|
`;
|
|
150
162
|
return report;
|
|
151
163
|
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/* VersaCompiler HMR shim [dev] */
|
|
2
|
+
if (typeof window !== 'undefined' && window.__versaHMR) {
|
|
3
|
+
(() => {
|
|
4
|
+
const _id = new URL(import.meta.url).pathname;
|
|
5
|
+
import.meta.hot = {
|
|
6
|
+
accept(cb) { window.__versaHMR.accept(_id, typeof cb === 'function' ? cb : () => {}); },
|
|
7
|
+
invalidate() { window.__versaHMR._invalidate?.(_id); },
|
|
8
|
+
dispose(cb) { window.__versaHMR._onDispose?.(_id, cb); },
|
|
9
|
+
get data() { return window.__versaHMR._getHotData?.(_id) ?? {}; },
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
}
|
|
13
|
+
import { stat } from 'node:fs/promises';
|
|
14
|
+
import path from 'node:path';
|
|
15
|
+
import { parser } from '../parser.js';
|
|
16
|
+
import { ModuleGraph } from './module-graph.js';
|
|
17
|
+
import { PluginDriver } from './plugin-driver.js';
|
|
18
|
+
function guessLoader(filePath) {
|
|
19
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
20
|
+
if (ext === '.vue')
|
|
21
|
+
return 'vue';
|
|
22
|
+
if (ext === '.ts')
|
|
23
|
+
return 'ts';
|
|
24
|
+
if (ext === '.json')
|
|
25
|
+
return 'json';
|
|
26
|
+
if (ext === '.css')
|
|
27
|
+
return 'css';
|
|
28
|
+
return 'js';
|
|
29
|
+
}
|
|
30
|
+
function getAstType(loader) {
|
|
31
|
+
return loader === 'ts' ? 'ts' : 'js';
|
|
32
|
+
}
|
|
33
|
+
function collectModuleRequests(ast) {
|
|
34
|
+
const requests = [];
|
|
35
|
+
const staticImports = ast?.module?.staticImports || [];
|
|
36
|
+
for (const item of staticImports) {
|
|
37
|
+
const value = item?.moduleRequest?.value;
|
|
38
|
+
if (typeof value === 'string')
|
|
39
|
+
requests.push(value);
|
|
40
|
+
}
|
|
41
|
+
const dynamicImports = ast?.module?.dynamicImports || [];
|
|
42
|
+
for (const item of dynamicImports) {
|
|
43
|
+
const value = item?.moduleRequest?.value;
|
|
44
|
+
if (typeof value === 'string')
|
|
45
|
+
requests.push(value);
|
|
46
|
+
}
|
|
47
|
+
return requests;
|
|
48
|
+
}
|
|
49
|
+
async function resolveLocalImport(importer, specifier) {
|
|
50
|
+
if (!specifier.startsWith('.') && !specifier.startsWith('/'))
|
|
51
|
+
return null;
|
|
52
|
+
const base = specifier.startsWith('/')
|
|
53
|
+
? path.normalize(specifier)
|
|
54
|
+
: path.resolve(path.dirname(importer), specifier);
|
|
55
|
+
const ext = path.extname(base);
|
|
56
|
+
if (ext)
|
|
57
|
+
return base;
|
|
58
|
+
const candidates = [
|
|
59
|
+
`${base}.ts`,
|
|
60
|
+
`${base}.js`,
|
|
61
|
+
`${base}.vue`,
|
|
62
|
+
`${base}.mjs`,
|
|
63
|
+
`${base}.cjs`,
|
|
64
|
+
`${base}.json`,
|
|
65
|
+
path.join(base, 'index.ts'),
|
|
66
|
+
path.join(base, 'index.js'),
|
|
67
|
+
path.join(base, 'index.vue'),
|
|
68
|
+
];
|
|
69
|
+
for (const candidate of candidates) {
|
|
70
|
+
try {
|
|
71
|
+
await stat(candidate);
|
|
72
|
+
return candidate;
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return base;
|
|
79
|
+
}
|
|
80
|
+
export class BuildPipeline {
|
|
81
|
+
driver;
|
|
82
|
+
graph;
|
|
83
|
+
constructor(plugins) {
|
|
84
|
+
this.driver = new PluginDriver(plugins);
|
|
85
|
+
this.graph = new ModuleGraph();
|
|
86
|
+
}
|
|
87
|
+
getModuleGraph() {
|
|
88
|
+
return this.graph;
|
|
89
|
+
}
|
|
90
|
+
async hotUpdate(args) {
|
|
91
|
+
return this.driver.hotUpdate(args);
|
|
92
|
+
}
|
|
93
|
+
async compileFile(filePath) {
|
|
94
|
+
const resolved = await this.driver.resolve({
|
|
95
|
+
path: filePath,
|
|
96
|
+
kind: 'entry',
|
|
97
|
+
});
|
|
98
|
+
const entryPath = resolved.path || filePath;
|
|
99
|
+
const loaded = await this.driver.load({ path: entryPath });
|
|
100
|
+
const loadErrors = loaded.errors || [];
|
|
101
|
+
if (!loaded.contents) {
|
|
102
|
+
await this.driver.end(loadErrors);
|
|
103
|
+
return {
|
|
104
|
+
code: '',
|
|
105
|
+
loader: guessLoader(entryPath),
|
|
106
|
+
dependencies: [],
|
|
107
|
+
errors: loadErrors,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
const transformResult = await this.driver.transform({
|
|
111
|
+
path: entryPath,
|
|
112
|
+
contents: loaded.contents,
|
|
113
|
+
loader: loaded.loader || guessLoader(entryPath),
|
|
114
|
+
meta: loaded.meta,
|
|
115
|
+
});
|
|
116
|
+
const transformErrors = transformResult.errors || [];
|
|
117
|
+
const finalCode = transformResult.contents || '';
|
|
118
|
+
const finalLoader = transformResult.loader || loaded.loader || guessLoader(entryPath);
|
|
119
|
+
const ast = await parser(entryPath, finalCode, getAstType(finalLoader));
|
|
120
|
+
const requests = collectModuleRequests(ast);
|
|
121
|
+
const resolvedDeps = [];
|
|
122
|
+
for (const request of requests) {
|
|
123
|
+
const resolvedDep = await resolveLocalImport(entryPath, request);
|
|
124
|
+
if (resolvedDep)
|
|
125
|
+
resolvedDeps.push(resolvedDep);
|
|
126
|
+
}
|
|
127
|
+
this.graph.updateImports(entryPath, resolvedDeps);
|
|
128
|
+
const errors = loadErrors.concat(transformErrors);
|
|
129
|
+
await this.driver.end(errors);
|
|
130
|
+
return {
|
|
131
|
+
code: finalCode,
|
|
132
|
+
loader: finalLoader,
|
|
133
|
+
meta: transformResult.meta || loaded.meta,
|
|
134
|
+
dependencies: resolvedDeps,
|
|
135
|
+
errors,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=build-pipeline.js.map
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/* VersaCompiler HMR shim [dev] */
|
|
2
|
+
if (typeof window !== 'undefined' && window.__versaHMR) {
|
|
3
|
+
(() => {
|
|
4
|
+
const _id = new URL(import.meta.url).pathname;
|
|
5
|
+
import.meta.hot = {
|
|
6
|
+
accept(cb) { window.__versaHMR.accept(_id, typeof cb === 'function' ? cb : () => {}); },
|
|
7
|
+
invalidate() { window.__versaHMR._invalidate?.(_id); },
|
|
8
|
+
dispose(cb) { window.__versaHMR._onDispose?.(_id, cb); },
|
|
9
|
+
get data() { return window.__versaHMR._getHotData?.(_id) ?? {}; },
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
}
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
import { env } from 'node:process';
|
|
15
|
+
import { logger } from '../../servicios/logger.js';
|
|
16
|
+
import { CompileWorkerPool } from '../compile-worker-pool.js';
|
|
17
|
+
let preCompileVue;
|
|
18
|
+
let preCompileTS;
|
|
19
|
+
let estandarizaCode;
|
|
20
|
+
let minifyJS;
|
|
21
|
+
let getCodeFile;
|
|
22
|
+
let compileWorkerPool = null;
|
|
23
|
+
async function loadVue() {
|
|
24
|
+
if (!preCompileVue) {
|
|
25
|
+
const mod = await import('../vuejs.js');
|
|
26
|
+
preCompileVue = mod.preCompileVue;
|
|
27
|
+
}
|
|
28
|
+
return preCompileVue;
|
|
29
|
+
}
|
|
30
|
+
async function loadTypeScript() {
|
|
31
|
+
if (!preCompileTS) {
|
|
32
|
+
const mod = await import('../typescript-manager.js');
|
|
33
|
+
preCompileTS = mod.preCompileTS;
|
|
34
|
+
}
|
|
35
|
+
return preCompileTS;
|
|
36
|
+
}
|
|
37
|
+
async function loadTransforms() {
|
|
38
|
+
if (!estandarizaCode) {
|
|
39
|
+
const mod = await import('../transforms.js');
|
|
40
|
+
estandarizaCode = mod.estandarizaCode;
|
|
41
|
+
}
|
|
42
|
+
return estandarizaCode;
|
|
43
|
+
}
|
|
44
|
+
async function loadMinify() {
|
|
45
|
+
if (!minifyJS) {
|
|
46
|
+
const mod = await import('../minify.js');
|
|
47
|
+
minifyJS = mod.minifyJS;
|
|
48
|
+
}
|
|
49
|
+
return minifyJS;
|
|
50
|
+
}
|
|
51
|
+
async function loadParser() {
|
|
52
|
+
if (!getCodeFile) {
|
|
53
|
+
const mod = await import('../parser.js');
|
|
54
|
+
getCodeFile = mod.getCodeFile;
|
|
55
|
+
}
|
|
56
|
+
return getCodeFile;
|
|
57
|
+
}
|
|
58
|
+
function getWorkerPool() {
|
|
59
|
+
if (!compileWorkerPool) {
|
|
60
|
+
compileWorkerPool = CompileWorkerPool.getInstance();
|
|
61
|
+
}
|
|
62
|
+
return compileWorkerPool;
|
|
63
|
+
}
|
|
64
|
+
function guessLoader(filePath) {
|
|
65
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
66
|
+
if (ext === '.vue')
|
|
67
|
+
return 'vue';
|
|
68
|
+
if (ext === '.ts')
|
|
69
|
+
return 'ts';
|
|
70
|
+
if (ext === '.json')
|
|
71
|
+
return 'json';
|
|
72
|
+
if (ext === '.css')
|
|
73
|
+
return 'css';
|
|
74
|
+
return 'js';
|
|
75
|
+
}
|
|
76
|
+
function withStageError(stage, error) {
|
|
77
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
78
|
+
return `${stage}: ${message}`;
|
|
79
|
+
}
|
|
80
|
+
export function createCorePlugins() {
|
|
81
|
+
const loadPlugin = {
|
|
82
|
+
name: 'core-load',
|
|
83
|
+
async onLoad(args) {
|
|
84
|
+
try {
|
|
85
|
+
const read = await loadParser();
|
|
86
|
+
const result = await read(args.path);
|
|
87
|
+
if (result.error) {
|
|
88
|
+
return {
|
|
89
|
+
errors: [withStageError('file-read', result.error)],
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
contents: result.code,
|
|
94
|
+
loader: guessLoader(args.path),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
return { errors: [withStageError('file-read', error)] };
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
const vuePlugin = {
|
|
103
|
+
name: 'core-vue',
|
|
104
|
+
async onTransform(args) {
|
|
105
|
+
if (args.loader !== 'vue')
|
|
106
|
+
return {};
|
|
107
|
+
try {
|
|
108
|
+
const useWorkers = env.WORKER_COMPILE === 'true';
|
|
109
|
+
const result = useWorkers
|
|
110
|
+
? await getWorkerPool().runTask('vue', {
|
|
111
|
+
fileName: args.path,
|
|
112
|
+
source: args.contents,
|
|
113
|
+
isProd: env.isPROD === 'true',
|
|
114
|
+
})
|
|
115
|
+
: await (await loadVue())(args.contents, args.path, env.isPROD === 'true');
|
|
116
|
+
if (result?.error) {
|
|
117
|
+
return {
|
|
118
|
+
errors: [withStageError('vue', result.error)],
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
contents: result.data || '',
|
|
123
|
+
loader: result.lang === 'ts' ? 'ts' : 'js',
|
|
124
|
+
meta: {
|
|
125
|
+
vueScriptInfo: result.scriptInfo,
|
|
126
|
+
vueScriptLang: result.lang,
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
return { errors: [withStageError('vue', error)] };
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
const tsPlugin = {
|
|
136
|
+
name: 'core-ts',
|
|
137
|
+
async onTransform(args) {
|
|
138
|
+
const isTsFile = args.loader === 'ts';
|
|
139
|
+
const vueLang = args.meta?.vueScriptLang;
|
|
140
|
+
if (!isTsFile && vueLang !== 'ts')
|
|
141
|
+
return {};
|
|
142
|
+
try {
|
|
143
|
+
const useWorkers = env.WORKER_COMPILE === 'true';
|
|
144
|
+
const result = useWorkers
|
|
145
|
+
? await getWorkerPool().runTask('ts', {
|
|
146
|
+
fileName: args.path,
|
|
147
|
+
source: args.contents,
|
|
148
|
+
scriptInfo: args.meta?.vueScriptInfo,
|
|
149
|
+
})
|
|
150
|
+
: await (await loadTypeScript())(args.contents, args.path, args.meta?.vueScriptInfo);
|
|
151
|
+
if (result?.error) {
|
|
152
|
+
return {
|
|
153
|
+
errors: [withStageError('typescript', result.error)],
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
contents: result.data || '',
|
|
158
|
+
loader: 'js',
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
return { errors: [withStageError('typescript', error)] };
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
const transformPlugin = {
|
|
167
|
+
name: 'core-transforms',
|
|
168
|
+
async onTransform(args) {
|
|
169
|
+
try {
|
|
170
|
+
const transform = await loadTransforms();
|
|
171
|
+
const result = await transform(args.contents, args.path);
|
|
172
|
+
if (result?.error) {
|
|
173
|
+
return {
|
|
174
|
+
errors: [
|
|
175
|
+
withStageError('standardization', result.error),
|
|
176
|
+
],
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
return { contents: result.code || '' };
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
return { errors: [withStageError('standardization', error)] };
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
const minifyPlugin = {
|
|
187
|
+
name: 'core-minify',
|
|
188
|
+
async onTransform(args) {
|
|
189
|
+
if (env.isPROD !== 'true')
|
|
190
|
+
return {};
|
|
191
|
+
try {
|
|
192
|
+
const useWorkers = env.WORKER_COMPILE === 'true';
|
|
193
|
+
const result = useWorkers
|
|
194
|
+
? await getWorkerPool().runTask('minify', {
|
|
195
|
+
fileName: args.path,
|
|
196
|
+
source: args.contents,
|
|
197
|
+
})
|
|
198
|
+
: await (await loadMinify())(args.contents, args.path, true);
|
|
199
|
+
if (result?.error) {
|
|
200
|
+
return {
|
|
201
|
+
errors: [withStageError('minification', result.error)],
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
return { contents: result.code || '' };
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
return { errors: [withStageError('minification', error)] };
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
const logPlugin = {
|
|
212
|
+
name: 'core-log',
|
|
213
|
+
onEnd(args) {
|
|
214
|
+
if (!args.errors.length)
|
|
215
|
+
return;
|
|
216
|
+
if (env.VERBOSE === 'true') {
|
|
217
|
+
logger.warn(`Pipeline errores: ${args.errors.length}`);
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
};
|
|
221
|
+
return [
|
|
222
|
+
loadPlugin,
|
|
223
|
+
vuePlugin,
|
|
224
|
+
tsPlugin,
|
|
225
|
+
transformPlugin,
|
|
226
|
+
minifyPlugin,
|
|
227
|
+
logPlugin,
|
|
228
|
+
];
|
|
229
|
+
}
|
|
230
|
+
//# sourceMappingURL=core-plugins.js.map
|