versacompiler 1.0.2 → 1.0.3
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/index.js +2 -45
- package/dist/utils/utils.js +22 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -22,7 +22,7 @@ import { minifyJS } from './services/minify.js';
|
|
|
22
22
|
import { preCompileTS } from './services/typescript.js';
|
|
23
23
|
import { preCompileVue } from './services/vuejs.js';
|
|
24
24
|
|
|
25
|
-
import { mapRuta, showTimingForHumans } from './utils/utils.js';
|
|
25
|
+
import { addImportEndJs, mapRuta, showTimingForHumans } from './utils/utils.js';
|
|
26
26
|
|
|
27
27
|
const log = console.log.bind(console);
|
|
28
28
|
const error = console.error.bind(console);
|
|
@@ -163,16 +163,7 @@ const deleteFile = async ruta => {
|
|
|
163
163
|
try {
|
|
164
164
|
log(chalk.yellow(`🗑️ :Eliminando ${newPath}`));
|
|
165
165
|
|
|
166
|
-
const stats = await stat(newPath)
|
|
167
|
-
if (!stats) {
|
|
168
|
-
log(
|
|
169
|
-
chalk.yellow(
|
|
170
|
-
`⚠️ :El archivo o directorio no existe: ${newPath}`,
|
|
171
|
-
),
|
|
172
|
-
);
|
|
173
|
-
return { extension: null, normalizedPath: null, fileName: null }; // Devolver un objeto válido
|
|
174
|
-
}
|
|
175
|
-
|
|
166
|
+
const stats = await stat(newPath);
|
|
176
167
|
if (stats.isDirectory()) {
|
|
177
168
|
await rmdir(newPath, { recursive: true });
|
|
178
169
|
} else if (stats.isFile()) {
|
|
@@ -305,40 +296,6 @@ const removeCodeTagImport = async data => {
|
|
|
305
296
|
return data;
|
|
306
297
|
};
|
|
307
298
|
|
|
308
|
-
/**
|
|
309
|
-
* Agrega la extensión .js a las importaciones en la cadena de datos proporcionada.
|
|
310
|
-
* @param {string} data - La cadena de entrada que contiene el código JavaScript.
|
|
311
|
-
* @returns {Promise<string>} - Una promesa que se resuelve con la cadena modificada con las importaciones actualizadas.
|
|
312
|
-
*/
|
|
313
|
-
const addImportEndJs = async data => {
|
|
314
|
-
const importRegExp = /import\s+[\s\S]*?\s+from\s+['"](.*)['"]/g;
|
|
315
|
-
|
|
316
|
-
return data.replace(importRegExp, match => {
|
|
317
|
-
const ruta = match.match(/from\s+['"](.*)['"]/)[1];
|
|
318
|
-
|
|
319
|
-
if (ruta.startsWith('@/')) {
|
|
320
|
-
// Manejar alias de ruta como @/
|
|
321
|
-
return match.replace(ruta, `${ruta}.js`);
|
|
322
|
-
} else if (ruta.endsWith('.vue')) {
|
|
323
|
-
const resultVue = match.match(/from\s+['"](.+\/(\w+))\.vue['"]/);
|
|
324
|
-
if (resultVue) {
|
|
325
|
-
const fullPath = resultVue[1].replace('.vue', '');
|
|
326
|
-
const fileName = resultVue[2];
|
|
327
|
-
return `import ${fileName} from '${fullPath}.js';`;
|
|
328
|
-
}
|
|
329
|
-
} else if (
|
|
330
|
-
!ruta.endsWith('.js') &&
|
|
331
|
-
!ruta.endsWith('.mjs') &&
|
|
332
|
-
!ruta.endsWith('.css') &&
|
|
333
|
-
ruta.includes('/')
|
|
334
|
-
) {
|
|
335
|
-
return match.replace(ruta, `${ruta}.js`);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
return match; // Devolver el match original si no se cumple ninguna condición
|
|
339
|
-
});
|
|
340
|
-
};
|
|
341
|
-
|
|
342
299
|
/**
|
|
343
300
|
* Elimina los comentarios con la etiqueta @preserve de la cadena de datos proporcionada.
|
|
344
301
|
* @param {string} data - La cadena de entrada que contiene el código JavaScript.
|
package/dist/utils/utils.js
CHANGED
|
@@ -24,3 +24,25 @@ export const showTimingForHumans = timing => {
|
|
|
24
24
|
*/
|
|
25
25
|
export const mapRuta = async (ruta, PATH_DIST, PATH_SOURCE) =>
|
|
26
26
|
path.join(PATH_DIST, path.relative(PATH_SOURCE, ruta));
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Agrega la extensión .js a las importaciones en la cadena de datos proporcionada.
|
|
30
|
+
* @param {string} data - La cadena de entrada que contiene el código JavaScript.
|
|
31
|
+
* @returns {Promise<string>} - Una promesa que se resuelve con la cadena modificada con las importaciones actualizadas.
|
|
32
|
+
*/
|
|
33
|
+
export const addImportEndJs = async data => {
|
|
34
|
+
const importRegExp =
|
|
35
|
+
/(?:import\s+.*?from\s+['"](.*?)['"]|import\(['"](.*?)['"]\))/g; // Manejar importaciones estáticas y dinámicas
|
|
36
|
+
|
|
37
|
+
return data.replace(importRegExp, (match, ruta1, ruta2) => {
|
|
38
|
+
const ruta = ruta1 || ruta2; // Usar la ruta capturada, ya sea estática o dinámica
|
|
39
|
+
if (ruta.endsWith('.vue') || ruta.endsWith('.ts')) {
|
|
40
|
+
const fullPath = ruta.replace(/\.(vue|ts)$/, '.js');
|
|
41
|
+
return match.replace(ruta, fullPath);
|
|
42
|
+
} else if (!ruta.match(/\/.*\.(js|mjs|css)$/) && ruta.includes('/')) {
|
|
43
|
+
return match.replace(ruta, `${ruta}.js`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return match; // Devolver el match original si no se cumple ninguna condición
|
|
47
|
+
});
|
|
48
|
+
};
|
package/package.json
CHANGED