versacompiler 2.4.1 → 2.5.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 +96 -0
- package/dist/compiler/compile-worker-thread.cjs +72 -0
- package/dist/compiler/compile.js +81 -2
- package/dist/compiler/integrity-validator.js +1 -1
- package/dist/compiler/module-resolution-optimizer.js +23 -20
- package/dist/compiler/performance-monitor.js +61 -61
- package/dist/compiler/pipeline/build-pipeline.js +127 -0
- package/dist/compiler/pipeline/core-plugins.js +218 -0
- package/dist/compiler/pipeline/module-graph.js +63 -0
- package/dist/compiler/pipeline/plugin-driver.js +87 -0
- package/dist/compiler/pipeline/types.js +2 -0
- package/dist/compiler/transforms.js +222 -16
- package/dist/compiler/typescript-manager.js +3 -1
- package/dist/compiler/typescript-sync-validator.js +33 -31
- package/dist/compiler/typescript-worker-thread.cjs +482 -475
- package/dist/compiler/vuejs.js +32 -32
- package/dist/config.js +2 -0
- package/dist/hrm/VueHRM.js +359 -359
- package/dist/hrm/errorScreen.js +83 -83
- package/dist/hrm/getInstanciaVue.js +313 -313
- package/dist/hrm/initHRM.js +628 -586
- package/dist/main.js +2 -1
- package/dist/servicios/browserSync.js +8 -2
- package/dist/servicios/file-watcher.js +48 -6
- package/dist/servicios/readConfig.js +129 -54
- package/dist/servicios/versacompile.config.types.js +2 -0
- package/dist/utils/module-resolver.js +74 -40
- package/dist/utils/vue-types-setup.js +248 -248
- package/dist/wrappers/eslint-node.js +3 -1
- package/dist/wrappers/oxlint-node.js +3 -1
- package/package.json +72 -53
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { env } from 'node:process';
|
|
3
|
+
import { logger } from '../../servicios/logger.js';
|
|
4
|
+
import { CompileWorkerPool } from '../compile-worker-pool.js';
|
|
5
|
+
let preCompileVue;
|
|
6
|
+
let preCompileTS;
|
|
7
|
+
let estandarizaCode;
|
|
8
|
+
let minifyJS;
|
|
9
|
+
let getCodeFile;
|
|
10
|
+
let compileWorkerPool = null;
|
|
11
|
+
async function loadVue() {
|
|
12
|
+
if (!preCompileVue) {
|
|
13
|
+
const mod = await import('../vuejs.js');
|
|
14
|
+
preCompileVue = mod.preCompileVue;
|
|
15
|
+
}
|
|
16
|
+
return preCompileVue;
|
|
17
|
+
}
|
|
18
|
+
async function loadTypeScript() {
|
|
19
|
+
if (!preCompileTS) {
|
|
20
|
+
const mod = await import('../typescript-manager.js');
|
|
21
|
+
preCompileTS = mod.preCompileTS;
|
|
22
|
+
}
|
|
23
|
+
return preCompileTS;
|
|
24
|
+
}
|
|
25
|
+
async function loadTransforms() {
|
|
26
|
+
if (!estandarizaCode) {
|
|
27
|
+
const mod = await import('../transforms.js');
|
|
28
|
+
estandarizaCode = mod.estandarizaCode;
|
|
29
|
+
}
|
|
30
|
+
return estandarizaCode;
|
|
31
|
+
}
|
|
32
|
+
async function loadMinify() {
|
|
33
|
+
if (!minifyJS) {
|
|
34
|
+
const mod = await import('../minify.js');
|
|
35
|
+
minifyJS = mod.minifyJS;
|
|
36
|
+
}
|
|
37
|
+
return minifyJS;
|
|
38
|
+
}
|
|
39
|
+
async function loadParser() {
|
|
40
|
+
if (!getCodeFile) {
|
|
41
|
+
const mod = await import('../parser.js');
|
|
42
|
+
getCodeFile = mod.getCodeFile;
|
|
43
|
+
}
|
|
44
|
+
return getCodeFile;
|
|
45
|
+
}
|
|
46
|
+
function getWorkerPool() {
|
|
47
|
+
if (!compileWorkerPool) {
|
|
48
|
+
compileWorkerPool = CompileWorkerPool.getInstance();
|
|
49
|
+
}
|
|
50
|
+
return compileWorkerPool;
|
|
51
|
+
}
|
|
52
|
+
function guessLoader(filePath) {
|
|
53
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
54
|
+
if (ext === '.vue')
|
|
55
|
+
return 'vue';
|
|
56
|
+
if (ext === '.ts')
|
|
57
|
+
return 'ts';
|
|
58
|
+
if (ext === '.json')
|
|
59
|
+
return 'json';
|
|
60
|
+
if (ext === '.css')
|
|
61
|
+
return 'css';
|
|
62
|
+
return 'js';
|
|
63
|
+
}
|
|
64
|
+
function withStageError(stage, error) {
|
|
65
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
66
|
+
return `${stage}: ${message}`;
|
|
67
|
+
}
|
|
68
|
+
export function createCorePlugins() {
|
|
69
|
+
const loadPlugin = {
|
|
70
|
+
name: 'core-load',
|
|
71
|
+
async onLoad(args) {
|
|
72
|
+
try {
|
|
73
|
+
const read = await loadParser();
|
|
74
|
+
const result = await read(args.path);
|
|
75
|
+
if (result.error) {
|
|
76
|
+
return {
|
|
77
|
+
errors: [withStageError('file-read', result.error)],
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
contents: result.code,
|
|
82
|
+
loader: guessLoader(args.path),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
return { errors: [withStageError('file-read', error)] };
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
const vuePlugin = {
|
|
91
|
+
name: 'core-vue',
|
|
92
|
+
async onTransform(args) {
|
|
93
|
+
if (args.loader !== 'vue')
|
|
94
|
+
return {};
|
|
95
|
+
try {
|
|
96
|
+
const useWorkers = env.WORKER_COMPILE === 'true';
|
|
97
|
+
const result = useWorkers
|
|
98
|
+
? await getWorkerPool().runTask('vue', {
|
|
99
|
+
fileName: args.path,
|
|
100
|
+
source: args.contents,
|
|
101
|
+
isProd: env.isPROD === 'true',
|
|
102
|
+
})
|
|
103
|
+
: await (await loadVue())(args.contents, args.path, env.isPROD === 'true');
|
|
104
|
+
if (result?.error) {
|
|
105
|
+
return {
|
|
106
|
+
errors: [withStageError('vue', result.error)],
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
contents: result.data || '',
|
|
111
|
+
loader: result.lang === 'ts' ? 'ts' : 'js',
|
|
112
|
+
meta: {
|
|
113
|
+
vueScriptInfo: result.scriptInfo,
|
|
114
|
+
vueScriptLang: result.lang,
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
return { errors: [withStageError('vue', error)] };
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
const tsPlugin = {
|
|
124
|
+
name: 'core-ts',
|
|
125
|
+
async onTransform(args) {
|
|
126
|
+
const isTsFile = args.loader === 'ts';
|
|
127
|
+
const vueLang = args.meta?.vueScriptLang;
|
|
128
|
+
if (!isTsFile && vueLang !== 'ts')
|
|
129
|
+
return {};
|
|
130
|
+
try {
|
|
131
|
+
const useWorkers = env.WORKER_COMPILE === 'true';
|
|
132
|
+
const result = useWorkers
|
|
133
|
+
? await getWorkerPool().runTask('ts', {
|
|
134
|
+
fileName: args.path,
|
|
135
|
+
source: args.contents,
|
|
136
|
+
scriptInfo: args.meta?.vueScriptInfo,
|
|
137
|
+
})
|
|
138
|
+
: await (await loadTypeScript())(args.contents, args.path, args.meta?.vueScriptInfo);
|
|
139
|
+
if (result?.error) {
|
|
140
|
+
return {
|
|
141
|
+
errors: [withStageError('typescript', result.error)],
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
contents: result.data || '',
|
|
146
|
+
loader: 'js',
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
return { errors: [withStageError('typescript', error)] };
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
const transformPlugin = {
|
|
155
|
+
name: 'core-transforms',
|
|
156
|
+
async onTransform(args) {
|
|
157
|
+
try {
|
|
158
|
+
const transform = await loadTransforms();
|
|
159
|
+
const result = await transform(args.contents, args.path);
|
|
160
|
+
if (result?.error) {
|
|
161
|
+
return {
|
|
162
|
+
errors: [
|
|
163
|
+
withStageError('standardization', result.error),
|
|
164
|
+
],
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
return { contents: result.code || '' };
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
return { errors: [withStageError('standardization', error)] };
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
const minifyPlugin = {
|
|
175
|
+
name: 'core-minify',
|
|
176
|
+
async onTransform(args) {
|
|
177
|
+
if (env.isPROD !== 'true')
|
|
178
|
+
return {};
|
|
179
|
+
try {
|
|
180
|
+
const useWorkers = env.WORKER_COMPILE === 'true';
|
|
181
|
+
const result = useWorkers
|
|
182
|
+
? await getWorkerPool().runTask('minify', {
|
|
183
|
+
fileName: args.path,
|
|
184
|
+
source: args.contents,
|
|
185
|
+
})
|
|
186
|
+
: await (await loadMinify())(args.contents, args.path, true);
|
|
187
|
+
if (result?.error) {
|
|
188
|
+
return {
|
|
189
|
+
errors: [withStageError('minification', result.error)],
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
return { contents: result.code || '' };
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
return { errors: [withStageError('minification', error)] };
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
const logPlugin = {
|
|
200
|
+
name: 'core-log',
|
|
201
|
+
onEnd(args) {
|
|
202
|
+
if (!args.errors.length)
|
|
203
|
+
return;
|
|
204
|
+
if (env.VERBOSE === 'true') {
|
|
205
|
+
logger.warn(`Pipeline errores: ${args.errors.length}`);
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
return [
|
|
210
|
+
loadPlugin,
|
|
211
|
+
vuePlugin,
|
|
212
|
+
tsPlugin,
|
|
213
|
+
transformPlugin,
|
|
214
|
+
minifyPlugin,
|
|
215
|
+
logPlugin,
|
|
216
|
+
];
|
|
217
|
+
}
|
|
218
|
+
//# sourceMappingURL=core-plugins.js.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export class ModuleGraph {
|
|
2
|
+
nodes = new Map();
|
|
3
|
+
getNode(id) {
|
|
4
|
+
return this.nodes.get(id);
|
|
5
|
+
}
|
|
6
|
+
ensureNode(id) {
|
|
7
|
+
const existing = this.nodes.get(id);
|
|
8
|
+
if (existing)
|
|
9
|
+
return existing;
|
|
10
|
+
const node = {
|
|
11
|
+
id,
|
|
12
|
+
importers: new Set(),
|
|
13
|
+
imports: new Set(),
|
|
14
|
+
lastUpdated: Date.now(),
|
|
15
|
+
};
|
|
16
|
+
this.nodes.set(id, node);
|
|
17
|
+
return node;
|
|
18
|
+
}
|
|
19
|
+
updateImports(id, imports) {
|
|
20
|
+
const node = this.ensureNode(id);
|
|
21
|
+
node.imports.clear();
|
|
22
|
+
for (const dep of imports) {
|
|
23
|
+
node.imports.add(dep);
|
|
24
|
+
const depNode = this.ensureNode(dep);
|
|
25
|
+
depNode.importers.add(id);
|
|
26
|
+
}
|
|
27
|
+
node.lastUpdated = Date.now();
|
|
28
|
+
}
|
|
29
|
+
invalidate(id) {
|
|
30
|
+
const invalidated = new Set();
|
|
31
|
+
const queue = [id];
|
|
32
|
+
while (queue.length > 0) {
|
|
33
|
+
const current = queue.shift();
|
|
34
|
+
if (invalidated.has(current))
|
|
35
|
+
continue;
|
|
36
|
+
invalidated.add(current);
|
|
37
|
+
const node = this.nodes.get(current);
|
|
38
|
+
if (!node)
|
|
39
|
+
continue;
|
|
40
|
+
for (const importer of node.importers) {
|
|
41
|
+
queue.push(importer);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return Array.from(invalidated);
|
|
45
|
+
}
|
|
46
|
+
remove(id) {
|
|
47
|
+
const node = this.nodes.get(id);
|
|
48
|
+
if (!node)
|
|
49
|
+
return;
|
|
50
|
+
for (const dep of node.imports) {
|
|
51
|
+
const depNode = this.nodes.get(dep);
|
|
52
|
+
if (depNode)
|
|
53
|
+
depNode.importers.delete(id);
|
|
54
|
+
}
|
|
55
|
+
for (const importer of node.importers) {
|
|
56
|
+
const importerNode = this.nodes.get(importer);
|
|
57
|
+
if (importerNode)
|
|
58
|
+
importerNode.imports.delete(id);
|
|
59
|
+
}
|
|
60
|
+
this.nodes.delete(id);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=module-graph.js.map
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
export class PluginDriver {
|
|
2
|
+
plugins;
|
|
3
|
+
constructor(plugins) {
|
|
4
|
+
this.plugins = plugins;
|
|
5
|
+
}
|
|
6
|
+
async resolve(args) {
|
|
7
|
+
for (const plugin of this.plugins) {
|
|
8
|
+
if (!plugin.onResolve)
|
|
9
|
+
continue;
|
|
10
|
+
const result = await plugin.onResolve(args);
|
|
11
|
+
if (result && (result.path || result.external || result.errors)) {
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
17
|
+
async load(args) {
|
|
18
|
+
for (const plugin of this.plugins) {
|
|
19
|
+
if (!plugin.onLoad)
|
|
20
|
+
continue;
|
|
21
|
+
const result = await plugin.onLoad(args);
|
|
22
|
+
if (result && (result.contents || result.errors)) {
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return {};
|
|
27
|
+
}
|
|
28
|
+
async transform(args) {
|
|
29
|
+
let current = args.contents;
|
|
30
|
+
let currentLoader = args.loader;
|
|
31
|
+
let currentMeta = args.meta;
|
|
32
|
+
let errors = [];
|
|
33
|
+
for (const plugin of this.plugins) {
|
|
34
|
+
if (!plugin.onTransform)
|
|
35
|
+
continue;
|
|
36
|
+
const result = await plugin.onTransform({
|
|
37
|
+
...args,
|
|
38
|
+
contents: current,
|
|
39
|
+
loader: currentLoader,
|
|
40
|
+
meta: currentMeta,
|
|
41
|
+
});
|
|
42
|
+
if (result.errors?.length)
|
|
43
|
+
errors = errors.concat(result.errors);
|
|
44
|
+
if (result.contents)
|
|
45
|
+
current = result.contents;
|
|
46
|
+
if (result.loader)
|
|
47
|
+
currentLoader = result.loader;
|
|
48
|
+
if (result.meta)
|
|
49
|
+
currentMeta = {
|
|
50
|
+
...(currentMeta || {}),
|
|
51
|
+
...result.meta,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
contents: current,
|
|
56
|
+
loader: currentLoader,
|
|
57
|
+
meta: currentMeta,
|
|
58
|
+
errors: errors.length ? errors : undefined,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
async hotUpdate(args) {
|
|
62
|
+
let reload = 'none';
|
|
63
|
+
let errors = [];
|
|
64
|
+
for (const plugin of this.plugins) {
|
|
65
|
+
if (!plugin.onHotUpdate)
|
|
66
|
+
continue;
|
|
67
|
+
const result = await plugin.onHotUpdate(args);
|
|
68
|
+
if (result.errors?.length)
|
|
69
|
+
errors = errors.concat(result.errors);
|
|
70
|
+
if (result.reload === 'full')
|
|
71
|
+
reload = 'full';
|
|
72
|
+
if (result.reload === 'module' && reload !== 'full')
|
|
73
|
+
reload = 'module';
|
|
74
|
+
}
|
|
75
|
+
return { reload, errors: errors.length ? errors : undefined };
|
|
76
|
+
}
|
|
77
|
+
async end(errors) {
|
|
78
|
+
const args = { errors };
|
|
79
|
+
for (const plugin of this.plugins) {
|
|
80
|
+
if (!plugin.onEnd)
|
|
81
|
+
continue;
|
|
82
|
+
await plugin.onEnd(args);
|
|
83
|
+
}
|
|
84
|
+
return { errors };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=plugin-driver.js.map
|
|
@@ -90,7 +90,9 @@ function isExternalModule(moduleRequest, pathAlias) {
|
|
|
90
90
|
return true;
|
|
91
91
|
} // Descartar alias conocidos
|
|
92
92
|
for (const alias of Object.keys(pathAlias)) {
|
|
93
|
-
|
|
93
|
+
// Quitar solo el '*' final para conservar el separador '/'
|
|
94
|
+
// Ejemplo: '@/*' → '@/', así '@vueuse/core' no hace match pero '@/foo' sí
|
|
95
|
+
const aliasPattern = alias.replace('*', '');
|
|
94
96
|
if (moduleRequest.startsWith(aliasPattern)) {
|
|
95
97
|
return false;
|
|
96
98
|
}
|
|
@@ -105,6 +107,211 @@ function isExternalModule(moduleRequest, pathAlias) {
|
|
|
105
107
|
// Si llegamos aquí, es probablemente un módulo externo
|
|
106
108
|
return true;
|
|
107
109
|
}
|
|
110
|
+
async function resolveModuleRequest(moduleRequest, file, pathAlias) {
|
|
111
|
+
let newPath = null;
|
|
112
|
+
let transformed = false;
|
|
113
|
+
if (!transformed && isExternalModule(moduleRequest, pathAlias)) {
|
|
114
|
+
try {
|
|
115
|
+
const optimizedResult = await getOptimizedModulePath(moduleRequest, file);
|
|
116
|
+
if (optimizedResult.excluded) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
if (optimizedResult.path) {
|
|
120
|
+
newPath = optimizedResult.path;
|
|
121
|
+
transformed = true;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
const modulePath = getModuleSubPath(moduleRequest, file);
|
|
125
|
+
if (modulePath === null) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
if (modulePath) {
|
|
129
|
+
newPath = modulePath;
|
|
130
|
+
transformed = true;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
if (env.VERBOSE === 'true')
|
|
136
|
+
logger.warn(`Error resolviendo módulo ${moduleRequest}: ${error instanceof Error ? error.message : String(error)}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (!transformed) {
|
|
140
|
+
const aliasPath = getOptimizedAliasPath(moduleRequest);
|
|
141
|
+
if (aliasPath) {
|
|
142
|
+
let newImportPath = aliasPath;
|
|
143
|
+
if (newImportPath.endsWith('.ts') ||
|
|
144
|
+
newImportPath.endsWith('.vue')) {
|
|
145
|
+
newImportPath = newImportPath.replace(/\.(ts|vue)$/, '.js');
|
|
146
|
+
}
|
|
147
|
+
else if (!/\.(js|mjs|css|json)$/.test(newImportPath)) {
|
|
148
|
+
newImportPath += '.js';
|
|
149
|
+
}
|
|
150
|
+
newPath = newImportPath;
|
|
151
|
+
transformed = true;
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
for (const [alias] of Object.entries(pathAlias)) {
|
|
155
|
+
const aliasPattern = alias.replace('*', '');
|
|
156
|
+
if (moduleRequest.startsWith(aliasPattern)) {
|
|
157
|
+
const relativePath = moduleRequest.replace(aliasPattern, '');
|
|
158
|
+
let newImportPath = path.join('/', env.PATH_DIST, relativePath);
|
|
159
|
+
newImportPath = newImportPath
|
|
160
|
+
.replace(/\/\.\//g, '/')
|
|
161
|
+
.replace(/\\/g, '/');
|
|
162
|
+
if (newImportPath.endsWith('.ts') ||
|
|
163
|
+
newImportPath.endsWith('.vue')) {
|
|
164
|
+
newImportPath = newImportPath.replace(/\.(ts|vue)$/, '.js');
|
|
165
|
+
}
|
|
166
|
+
else if (!/\.(js|mjs|css|json)$/.test(newImportPath)) {
|
|
167
|
+
newImportPath += '.js';
|
|
168
|
+
}
|
|
169
|
+
newPath = newImportPath;
|
|
170
|
+
transformed = true;
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (!transformed &&
|
|
177
|
+
(moduleRequest.startsWith('./') || moduleRequest.startsWith('../'))) {
|
|
178
|
+
let relativePath = moduleRequest;
|
|
179
|
+
if (relativePath.endsWith('.ts') || relativePath.endsWith('.vue')) {
|
|
180
|
+
relativePath = relativePath.replace(/\.(ts|vue)$/, '.js');
|
|
181
|
+
newPath = relativePath;
|
|
182
|
+
transformed = true;
|
|
183
|
+
}
|
|
184
|
+
else if (!/\.(js|mjs|css|json)$/.test(relativePath)) {
|
|
185
|
+
newPath = relativePath + '.js';
|
|
186
|
+
transformed = true;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return transformed ? newPath : null;
|
|
190
|
+
}
|
|
191
|
+
function extractLiteralValue(raw) {
|
|
192
|
+
if (!raw || raw.length < 2)
|
|
193
|
+
return null;
|
|
194
|
+
const quote = raw[0];
|
|
195
|
+
const last = raw[raw.length - 1];
|
|
196
|
+
if ((quote !== '"' && quote !== "'" && quote !== '`') || last !== quote) {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
if (quote === '`' && raw.includes('${')) {
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
return { quote, value: raw.slice(1, -1) };
|
|
203
|
+
}
|
|
204
|
+
function resolveAliasTemplateLiteral(raw, pathAlias) {
|
|
205
|
+
if (!raw.startsWith('`'))
|
|
206
|
+
return null;
|
|
207
|
+
const exprIndex = raw.indexOf('${');
|
|
208
|
+
if (exprIndex === -1)
|
|
209
|
+
return null;
|
|
210
|
+
const prefix = raw.slice(1, exprIndex);
|
|
211
|
+
if (!prefix)
|
|
212
|
+
return null;
|
|
213
|
+
const sortedAliases = Object.entries(pathAlias).sort((a, b) => {
|
|
214
|
+
const aliasA = a[0].replace('/*', '');
|
|
215
|
+
const aliasB = b[0].replace('/*', '');
|
|
216
|
+
return aliasB.length - aliasA.length;
|
|
217
|
+
});
|
|
218
|
+
for (const [alias, target] of sortedAliases) {
|
|
219
|
+
const aliasPattern = alias.replace('/*', '');
|
|
220
|
+
if (!prefix.startsWith(aliasPattern))
|
|
221
|
+
continue;
|
|
222
|
+
const relativePath = prefix.replace(aliasPattern, '');
|
|
223
|
+
const targetArray = Array.isArray(target) ? target : [target];
|
|
224
|
+
const targetPath = targetArray[0];
|
|
225
|
+
if (!targetPath)
|
|
226
|
+
continue;
|
|
227
|
+
let newPrefix;
|
|
228
|
+
if (targetPath.startsWith('/')) {
|
|
229
|
+
newPrefix = path.join('/', env.PATH_DIST, relativePath);
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
const cleanTarget = targetPath.replace('./', '').replace('/*', '');
|
|
233
|
+
const normalizedPathDist = env.PATH_DIST.replace('./', '');
|
|
234
|
+
if (cleanTarget === normalizedPathDist) {
|
|
235
|
+
newPrefix = path.join('/', normalizedPathDist, relativePath);
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
newPrefix = path.join('/', normalizedPathDist, cleanTarget, relativePath);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
newPrefix = newPrefix
|
|
242
|
+
.replace(/\/\.\//g, '/')
|
|
243
|
+
.replace(/\\/g, '/')
|
|
244
|
+
.replace(/\/+/g, '/');
|
|
245
|
+
return `\`${newPrefix}${raw.slice(exprIndex)}`;
|
|
246
|
+
}
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
async function replaceAliasImportsAst(code, file, ast) {
|
|
250
|
+
if (!env.PATH_ALIAS || !env.PATH_DIST) {
|
|
251
|
+
return code;
|
|
252
|
+
}
|
|
253
|
+
const pathAlias = getParsedPathAlias();
|
|
254
|
+
if (!pathAlias)
|
|
255
|
+
return code;
|
|
256
|
+
const replacements = [];
|
|
257
|
+
const staticImports = ast?.module?.staticImports || [];
|
|
258
|
+
for (const item of staticImports) {
|
|
259
|
+
const moduleRequest = item?.moduleRequest?.value;
|
|
260
|
+
const start = item?.moduleRequest?.start;
|
|
261
|
+
const end = item?.moduleRequest?.end;
|
|
262
|
+
if (typeof moduleRequest !== 'string')
|
|
263
|
+
continue;
|
|
264
|
+
if (typeof start !== 'number' || typeof end !== 'number')
|
|
265
|
+
continue;
|
|
266
|
+
const newPath = await resolveModuleRequest(moduleRequest, file, pathAlias);
|
|
267
|
+
if (!newPath || newPath === moduleRequest)
|
|
268
|
+
continue;
|
|
269
|
+
const raw = code.slice(start, end);
|
|
270
|
+
const literal = extractLiteralValue(raw);
|
|
271
|
+
if (!literal)
|
|
272
|
+
continue;
|
|
273
|
+
replacements.push({
|
|
274
|
+
start,
|
|
275
|
+
end,
|
|
276
|
+
value: `${literal.quote}${newPath}${literal.quote}`,
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
const dynamicImports = ast?.module?.dynamicImports || [];
|
|
280
|
+
for (const item of dynamicImports) {
|
|
281
|
+
const start = item?.moduleRequest?.start;
|
|
282
|
+
const end = item?.moduleRequest?.end;
|
|
283
|
+
if (typeof start !== 'number' || typeof end !== 'number')
|
|
284
|
+
continue;
|
|
285
|
+
const raw = code.slice(start, end);
|
|
286
|
+
const literal = extractLiteralValue(raw);
|
|
287
|
+
if (!literal) {
|
|
288
|
+
const replaced = resolveAliasTemplateLiteral(raw, pathAlias);
|
|
289
|
+
if (replaced) {
|
|
290
|
+
replacements.push({ start, end, value: replaced });
|
|
291
|
+
}
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
const newPath = await resolveModuleRequest(literal.value, file, pathAlias);
|
|
295
|
+
if (!newPath || newPath === literal.value)
|
|
296
|
+
continue;
|
|
297
|
+
replacements.push({
|
|
298
|
+
start,
|
|
299
|
+
end,
|
|
300
|
+
value: `${literal.quote}${newPath}${literal.quote}`,
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
if (replacements.length === 0)
|
|
304
|
+
return code;
|
|
305
|
+
replacements.sort((a, b) => b.start - a.start);
|
|
306
|
+
let resultCode = code;
|
|
307
|
+
for (const replacement of replacements) {
|
|
308
|
+
resultCode =
|
|
309
|
+
resultCode.slice(0, replacement.start) +
|
|
310
|
+
replacement.value +
|
|
311
|
+
resultCode.slice(replacement.end);
|
|
312
|
+
}
|
|
313
|
+
return resultCode;
|
|
314
|
+
}
|
|
108
315
|
export async function replaceAliasImportStatic(file, code) {
|
|
109
316
|
if (!env.PATH_ALIAS || !env.PATH_DIST) {
|
|
110
317
|
return code;
|
|
@@ -124,13 +331,13 @@ export async function replaceAliasImportStatic(file, code) {
|
|
|
124
331
|
if (!transformed && isExternalModule(moduleRequest, pathAlias)) {
|
|
125
332
|
try {
|
|
126
333
|
// Usar el sistema optimizado primero
|
|
127
|
-
const
|
|
128
|
-
if (
|
|
129
|
-
//
|
|
334
|
+
const optimizedResult = await getOptimizedModulePath(moduleRequest, file);
|
|
335
|
+
if (optimizedResult.excluded) {
|
|
336
|
+
// Módulo excluido explícitamente: mantener importación original
|
|
130
337
|
continue;
|
|
131
338
|
}
|
|
132
|
-
if (
|
|
133
|
-
newPath =
|
|
339
|
+
if (optimizedResult.path) {
|
|
340
|
+
newPath = optimizedResult.path;
|
|
134
341
|
transformed = true;
|
|
135
342
|
}
|
|
136
343
|
else {
|
|
@@ -169,7 +376,7 @@ export async function replaceAliasImportStatic(file, code) {
|
|
|
169
376
|
else {
|
|
170
377
|
// Fallback al sistema anterior
|
|
171
378
|
for (const [alias] of Object.entries(pathAlias)) {
|
|
172
|
-
const aliasPattern = alias.replace('
|
|
379
|
+
const aliasPattern = alias.replace('*', '');
|
|
173
380
|
if (moduleRequest.startsWith(aliasPattern)) {
|
|
174
381
|
// Reemplazar el alias con la ruta del target
|
|
175
382
|
const relativePath = moduleRequest.replace(aliasPattern, '');
|
|
@@ -239,13 +446,13 @@ export async function replaceAliasImportDynamic(code, _imports, file) {
|
|
|
239
446
|
if (!transformed && isExternalModule(moduleRequest, pathAlias)) {
|
|
240
447
|
try {
|
|
241
448
|
// Usar el sistema optimizado primero
|
|
242
|
-
const
|
|
243
|
-
if (
|
|
244
|
-
//
|
|
449
|
+
const optimizedResult = await getOptimizedModulePath(moduleRequest, file);
|
|
450
|
+
if (optimizedResult.excluded) {
|
|
451
|
+
// Módulo excluido explícitamente: mantener importación original
|
|
245
452
|
continue;
|
|
246
453
|
}
|
|
247
|
-
if (
|
|
248
|
-
newPath =
|
|
454
|
+
if (optimizedResult.path) {
|
|
455
|
+
newPath = optimizedResult.path;
|
|
249
456
|
transformed = true;
|
|
250
457
|
}
|
|
251
458
|
else {
|
|
@@ -284,7 +491,7 @@ export async function replaceAliasImportDynamic(code, _imports, file) {
|
|
|
284
491
|
else {
|
|
285
492
|
// Fallback al sistema anterior
|
|
286
493
|
for (const [alias] of Object.entries(pathAlias)) {
|
|
287
|
-
const aliasPattern = alias.replace('
|
|
494
|
+
const aliasPattern = alias.replace('*', '');
|
|
288
495
|
if (moduleRequest.startsWith(aliasPattern)) {
|
|
289
496
|
// Reemplazar el alias con la ruta del target
|
|
290
497
|
const relativePath = moduleRequest.replace(aliasPattern, '');
|
|
@@ -356,7 +563,7 @@ export async function replaceAliasImportDynamic(code, _imports, file) {
|
|
|
356
563
|
// 2. Verificar aliases en template literals
|
|
357
564
|
if (!transformed) {
|
|
358
565
|
for (const [alias] of Object.entries(pathAlias)) {
|
|
359
|
-
const aliasPattern = alias.replace('
|
|
566
|
+
const aliasPattern = alias.replace('*', '');
|
|
360
567
|
if (moduleRequest.includes(aliasPattern)) {
|
|
361
568
|
const relativePath = moduleRequest.replace(aliasPattern, '');
|
|
362
569
|
// Para alias que apuntan a la raíz (como @/* -> /src/*),
|
|
@@ -550,8 +757,7 @@ export async function estandarizaCode(code, file) {
|
|
|
550
757
|
const firstError = ast.errors[0];
|
|
551
758
|
throw new Error(firstError?.message || 'Error sin mensaje');
|
|
552
759
|
}
|
|
553
|
-
code = await
|
|
554
|
-
code = await replaceAliasImportDynamic(code, ast?.module.dynamicImports, file);
|
|
760
|
+
code = await replaceAliasImportsAst(code, file, ast);
|
|
555
761
|
code = await replaceAliasInStrings(code);
|
|
556
762
|
code = await removehtmlOfTemplateString(code);
|
|
557
763
|
code = await removeCodeTagImport(code);
|
|
@@ -55,7 +55,9 @@ export const loadTypeScriptConfig = (fileName) => {
|
|
|
55
55
|
}
|
|
56
56
|
catch (error) {
|
|
57
57
|
console.warn(`[loadTypeScriptConfig] Error cargando ${configPath}:`, error);
|
|
58
|
-
throw new Error(`No se puede continuar sin un tsconfig.json válido. Error: ${error}`, {
|
|
58
|
+
throw new Error(`No se puede continuar sin un tsconfig.json válido. Error: ${error}`, {
|
|
59
|
+
cause: error,
|
|
60
|
+
});
|
|
59
61
|
}
|
|
60
62
|
// ✨ FIX #9: Guardar en cache con timestamp
|
|
61
63
|
configCache = {
|