versacompiler 2.0.3 → 2.0.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.
@@ -0,0 +1,442 @@
1
+ /**
2
+ * Utilidad para configurar automáticamente los tipos de Vue en proyectos
3
+ * Facilita la integración de tipado robusto para archivos Vue
4
+ */
5
+ import * as fs from 'node:fs';
6
+ import * as path from 'node:path';
7
+ /**
8
+ * Instala los archivos de tipos Vue en el proyecto
9
+ * @param projectRoot - Directorio raíz del proyecto
10
+ * @param config - Configuración para la instalación
11
+ */
12
+ export const setupVueTypes = async (projectRoot, config = {}) => {
13
+ try {
14
+ const { targetDir = 'src/types', createTsConfig = false, enableStrictMode = false, includeRouterTypes = true, includePiniaTypes = true, } = config;
15
+ const typesDir = path.join(projectRoot, targetDir);
16
+ // Crear directorio de tipos si no existe
17
+ if (!fs.existsSync(typesDir)) {
18
+ fs.mkdirSync(typesDir, { recursive: true });
19
+ } // Crear vue-shims.d.ts si no existe
20
+ const vueShimsPath = path.join(typesDir, 'vue-shims.d.ts');
21
+ if (!fs.existsSync(vueShimsPath)) {
22
+ const shimsContent = generateVueShimsContent();
23
+ fs.writeFileSync(vueShimsPath, shimsContent);
24
+ }
25
+ // Crear archivo de configuración específico del proyecto si se solicita
26
+ if (createTsConfig) {
27
+ await createProjectTsConfig(projectRoot, {
28
+ enableStrictMode,
29
+ includeRouterTypes,
30
+ includePiniaTypes,
31
+ });
32
+ }
33
+ // Crear archivo de entorno global para tipos adicionales
34
+ const globalTypesPath = path.join(typesDir, 'global.d.ts');
35
+ const globalTypesContent = generateGlobalTypes({
36
+ includeRouterTypes,
37
+ includePiniaTypes,
38
+ });
39
+ fs.writeFileSync(globalTypesPath, globalTypesContent);
40
+ return true;
41
+ }
42
+ catch (error) {
43
+ console.error('Error setting up Vue types:', error);
44
+ return false;
45
+ }
46
+ };
47
+ /**
48
+ * Crea o actualiza tsconfig.json con configuración optimizada para Vue
49
+ */
50
+ const createProjectTsConfig = async (projectRoot, options) => {
51
+ const tsconfigPath = path.join(projectRoot, 'tsconfig.json');
52
+ const tsconfigContent = {
53
+ compilerOptions: {
54
+ target: 'esnext',
55
+ module: 'esnext',
56
+ lib: ['esnext', 'dom', 'dom.iterable'],
57
+ allowJs: true,
58
+ checkJs: false,
59
+ jsx: 'preserve',
60
+ declaration: true,
61
+ declarationMap: true,
62
+ sourceMap: true,
63
+ outDir: './dist',
64
+ removeComments: true,
65
+ importHelpers: true,
66
+ isolatedModules: true,
67
+ allowSyntheticDefaultImports: true,
68
+ esModuleInterop: true,
69
+ forceConsistentCasingInFileNames: true,
70
+ useDefineForClassFields: true,
71
+ resolveJsonModule: true,
72
+ skipLibCheck: true,
73
+ moduleResolution: 'node',
74
+ // Configuraciones de strictness
75
+ strict: options.enableStrictMode,
76
+ noImplicitAny: options.enableStrictMode,
77
+ noImplicitReturns: options.enableStrictMode,
78
+ noImplicitThis: options.enableStrictMode,
79
+ strictNullChecks: options.enableStrictMode,
80
+ strictFunctionTypes: options.enableStrictMode,
81
+ // Paths para tipos
82
+ baseUrl: '.',
83
+ paths: {
84
+ '/dist/examples/*': ['src/*'],
85
+ '/dist/examples/types/*': ['src/types/*'],
86
+ },
87
+ types: [
88
+ 'node',
89
+ 'vue/ref-macros',
90
+ ...(options.includeRouterTypes ? ['@vue/router'] : []),
91
+ ...(options.includePiniaTypes ? ['pinia'] : []),
92
+ ],
93
+ },
94
+ include: [
95
+ 'src/**/*.ts',
96
+ 'src/**/*.tsx',
97
+ 'src/**/*.vue',
98
+ 'src/types/**/*.d.ts',
99
+ ],
100
+ exclude: ['node_modules', 'dist'],
101
+ 'ts-node': {
102
+ esm: true,
103
+ },
104
+ };
105
+ // Si ya existe tsconfig.json, hacer merge inteligente
106
+ if (fs.existsSync(tsconfigPath)) {
107
+ try {
108
+ const existingConfig = JSON.parse(fs.readFileSync(tsconfigPath, 'utf-8'));
109
+ const mergedConfig = {
110
+ ...existingConfig,
111
+ compilerOptions: {
112
+ ...existingConfig.compilerOptions,
113
+ ...tsconfigContent.compilerOptions,
114
+ },
115
+ include: Array.from(new Set([
116
+ ...(existingConfig.include || []),
117
+ ...tsconfigContent.include,
118
+ ])),
119
+ };
120
+ fs.writeFileSync(tsconfigPath, JSON.stringify(mergedConfig, null, 2));
121
+ }
122
+ catch {
123
+ // Si hay error parseando, crear nuevo archivo
124
+ fs.writeFileSync(tsconfigPath, JSON.stringify(tsconfigContent, null, 2));
125
+ }
126
+ }
127
+ else {
128
+ fs.writeFileSync(tsconfigPath, JSON.stringify(tsconfigContent, null, 2));
129
+ }
130
+ };
131
+ /**
132
+ * Genera tipos globales adicionales basados en las opciones
133
+ */
134
+ const generateGlobalTypes = (options) => {
135
+ let content = `/**
136
+ * Tipos globales adicionales para el proyecto
137
+ * Generado automáticamente por VersaCompiler
138
+ */
139
+
140
+ // Extensiones para window object si es necesario
141
+ declare global {
142
+ interface Window {
143
+ // Agregar propiedades globales si es necesario
144
+ [key: string]: any;
145
+ }
146
+ }
147
+
148
+ // Tipos para archivos de assets
149
+ declare module '*.svg' {
150
+ const src: string;
151
+ export default src;
152
+ }
153
+
154
+ declare module '*.png' {
155
+ const src: string;
156
+ export default src;
157
+ }
158
+
159
+ declare module '*.jpg' {
160
+ const src: string;
161
+ export default src;
162
+ }
163
+
164
+ declare module '*.jpeg' {
165
+ const src: string;
166
+ export default src;
167
+ }
168
+
169
+ declare module '*.webp' {
170
+ const src: string;
171
+ export default src;
172
+ }
173
+
174
+ declare module '*.gif' {
175
+ const src: string;
176
+ export default src;
177
+ }
178
+
179
+ declare module '*.ico' {
180
+ const src: string;
181
+ export default src;
182
+ }
183
+ `;
184
+ if (options.includeRouterTypes) {
185
+ content += `
186
+ // Vue Router tipos adicionales
187
+ declare module '@vue/runtime-core' {
188
+ interface ComponentCustomProperties {
189
+ $route: import('vue-router').RouteLocationNormalized;
190
+ $router: import('vue-router').Router;
191
+ }
192
+ }
193
+ `;
194
+ }
195
+ if (options.includePiniaTypes) {
196
+ content += `
197
+ // Pinia tipos adicionales
198
+ declare module '@vue/runtime-core' {
199
+ interface ComponentCustomProperties {
200
+ $pinia: import('pinia').Pinia;
201
+ }
202
+ }
203
+ `;
204
+ }
205
+ content += '\nexport {};';
206
+ return content;
207
+ };
208
+ /**
209
+ * Genera el contenido del archivo vue-shims.d.ts
210
+ * @returns El contenido completo del archivo de shims
211
+ */
212
+ const generateVueShimsContent = () => {
213
+ return `/**
214
+ * Declaraciones de tipos Vue para VersaCompiler
215
+ * Proporciona tipado robusto para archivos Vue
216
+ */
217
+
218
+ /// <reference types="vue/ref-macros" />
219
+ /// <reference types="vue/reactivity-transform/macros" />
220
+
221
+ declare module '*.vue' {
222
+ import type { DefineComponent } from 'vue';
223
+ const component: DefineComponent<{}, {}, any>;
224
+ export default component;
225
+ }
226
+
227
+ // Declaraciones globales para Composition API
228
+ declare global {
229
+ // Reactivity API
230
+ function ref<T>(value: T): { value: T };
231
+ function reactive<T extends object>(target: T): T;
232
+ function computed<T>(getter: () => T): { value: T };
233
+ function readonly<T>(target: T): T;
234
+ function unref<T>(ref: T): T extends { value: infer V } ? V : T;
235
+ function toRef<T, K extends keyof T>(object: T, key: K): { value: T[K] };
236
+ function toRefs<T extends object>(
237
+ object: T,
238
+ ): { [K in keyof T]: { value: T[K] } };
239
+ function isRef<T>(ref: any): ref is { value: T };
240
+ function isReactive(value: any): boolean;
241
+ function isReadonly(value: any): boolean;
242
+ function isProxy(value: any): boolean;
243
+ function shallowRef<T>(value: T): { value: T };
244
+ function shallowReactive<T extends object>(target: T): T;
245
+ function shallowReadonly<T>(target: T): T;
246
+ function toRaw<T>(observed: T): T;
247
+ function markRaw<T>(value: T): T;
248
+ function triggerRef<T>(ref: { value: T }): void;
249
+
250
+ // Component API
251
+ function defineComponent<T extends Record<string, any>>(options: T): T;
252
+ function defineAsyncComponent<T>(loader: () => Promise<T>): T;
253
+
254
+ // Props & Emits
255
+ function defineProps<T = {}>(): T;
256
+ function defineEmits<T extends Record<string, any> = {}>(): T;
257
+ function defineExpose<T = {}>(exposed: T): void;
258
+ function defineModel<T>(modelName?: string): { value: T };
259
+ function withDefaults<T, D>(props: T, defaults: D): T & D;
260
+
261
+ // Lifecycle Hooks
262
+ function onBeforeMount(hook: () => void): void;
263
+ function onMounted(hook: () => void): void;
264
+ function onBeforeUpdate(hook: () => void): void;
265
+ function onUpdated(hook: () => void): void;
266
+ function onBeforeUnmount(hook: () => void): void;
267
+ function onUnmounted(hook: () => void): void;
268
+ function onActivated(hook: () => void): void;
269
+ function onDeactivated(hook: () => void): void;
270
+ function onErrorCaptured(
271
+ hook: (err: Error, instance: any, info: string) => boolean | void,
272
+ ): void;
273
+ function onRenderTracked(hook: (event: any) => void): void;
274
+ function onRenderTriggered(hook: (event: any) => void): void;
275
+ function onServerPrefetch(hook: () => Promise<any>): void;
276
+
277
+ // Dependency Injection
278
+ function provide<T>(key: string | symbol, value: T): void;
279
+ function inject<T>(key: string | symbol, defaultValue?: T): T | undefined;
280
+
281
+ // Template Refs
282
+ function templateRef<T = any>(key?: string): { value: T | null };
283
+
284
+ // Watchers
285
+ type WatchCallback<T> = (newValue: T, oldValue: T) => void;
286
+ type WatchStopHandle = () => void;
287
+ function watch<T>(
288
+ source: () => T,
289
+ callback: WatchCallback<T>,
290
+ options?: any,
291
+ ): WatchStopHandle;
292
+ function watchEffect(effect: () => void, options?: any): WatchStopHandle;
293
+ function watchPostEffect(
294
+ effect: () => void,
295
+ options?: any,
296
+ ): WatchStopHandle;
297
+ function watchSyncEffect(
298
+ effect: () => void,
299
+ options?: any,
300
+ ): WatchStopHandle;
301
+
302
+ // Utilities
303
+ function nextTick(callback?: () => void): Promise<void>;
304
+ function useSlots(): { [key: string]: (...args: any[]) => any };
305
+ function useAttrs(): { [key: string]: any };
306
+ function useModel<T>(modelName?: string): { value: T };
307
+ function useCssModule(name?: string): { [key: string]: string };
308
+ function useCssVars(vars: Record<string, string>): void;
309
+
310
+ // Advanced Reactivity
311
+ function customRef<T>(
312
+ factory: (
313
+ track: () => void,
314
+ trigger: () => void,
315
+ ) => { get: () => T; set: (value: T) => void },
316
+ ): { value: T };
317
+ function effectScope(): any;
318
+ function getCurrentScope(): any;
319
+ function onScopeDispose(fn: () => void): void;
320
+
321
+ // Component Instance
322
+ function getCurrentInstance(): any;
323
+ function hasInjectionContext(): boolean;
324
+
325
+ // Vue Router (common imports)
326
+ function useRouter(): any;
327
+ function useRoute(): any;
328
+
329
+ // Pinia (common imports)
330
+ function useStore(): any;
331
+ function defineStore(id: string, setup: () => any): any;
332
+
333
+ // Legacy Options API support
334
+ interface ComponentOptions {
335
+ name?: string;
336
+ props?: any;
337
+ data?: () => any;
338
+ computed?: any;
339
+ methods?: any;
340
+ watch?: any;
341
+ emits?: any;
342
+ setup?: any;
343
+ [key: string]: any;
344
+ }
345
+
346
+ // Vue 3 specific APIs
347
+ function createApp(rootComponent: any, rootProps?: any): any;
348
+ function defineCustomElement(options: any): any;
349
+ function mergeModels<T>(models: T): T;
350
+ }
351
+
352
+ // Module augmentation for common Vue ecosystem types
353
+ declare module '@vue/runtime-core' {
354
+ interface ComponentCustomProperties {
355
+ $route: any;
356
+ $router: any;
357
+ $store: any;
358
+ [key: string]: any;
359
+ }
360
+ }
361
+
362
+ // Support for .vue files in TypeScript
363
+ declare module '*.vue' {
364
+ import type { DefineComponent } from 'vue';
365
+ const component: DefineComponent<{}, {}, any>;
366
+ export default component;
367
+ }
368
+
369
+ // CSS Modules support
370
+ declare module '*.module.css' {
371
+ const classes: { [key: string]: string };
372
+ export default classes;
373
+ }
374
+
375
+ declare module '*.module.scss' {
376
+ const classes: { [key: string]: string };
377
+ export default classes;
378
+ }
379
+
380
+ declare module '*.module.sass' {
381
+ const classes: { [key: string]: string };
382
+ export default classes;
383
+ }
384
+
385
+ declare module '*.module.less' {
386
+ const classes: { [key: string]: string };
387
+ export default classes;
388
+ }
389
+
390
+ declare module '*.module.styl' {
391
+ const classes: { [key: string]: string };
392
+ export default classes;
393
+ }
394
+
395
+ export {};
396
+ `;
397
+ };
398
+ /**
399
+ * Verifica si el proyecto ya tiene tipos Vue configurados
400
+ */
401
+ export const hasVueTypesSetup = (projectRoot) => {
402
+ const typesDir = path.join(projectRoot, 'src/types');
403
+ const vueShimsPath = path.join(typesDir, 'vue-shims.d.ts');
404
+ return fs.existsSync(vueShimsPath);
405
+ };
406
+ /**
407
+ * Configuración automática para proyectos Vue detectados
408
+ */
409
+ export const autoSetupVueTypes = async (projectRoot) => {
410
+ // Verificar si es un proyecto Vue
411
+ const packageJsonPath = path.join(projectRoot, 'package.json');
412
+ if (!fs.existsSync(packageJsonPath)) {
413
+ return false;
414
+ }
415
+ try {
416
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
417
+ const hasVue = packageJson.dependencies?.vue || packageJson.devDependencies?.vue;
418
+ if (!hasVue) {
419
+ return false;
420
+ }
421
+ // Si ya tiene tipos configurados, no hacer nada
422
+ if (hasVueTypesSetup(projectRoot)) {
423
+ return true;
424
+ }
425
+ // Detectar qué librerías adicionales usar
426
+ const hasRouter = packageJson.dependencies?.['vue-router'] ||
427
+ packageJson.devDependencies?.['vue-router'];
428
+ const hasPinia = packageJson.dependencies?.pinia ||
429
+ packageJson.devDependencies?.pinia;
430
+ // Configurar tipos automáticamente
431
+ return await setupVueTypes(projectRoot, {
432
+ createTsConfig: !fs.existsSync(path.join(projectRoot, 'tsconfig.json')),
433
+ includeRouterTypes: !!hasRouter,
434
+ includePiniaTypes: !!hasPinia,
435
+ });
436
+ }
437
+ catch (error) {
438
+ console.error('Error in auto-setup Vue types:', error);
439
+ return false;
440
+ }
441
+ };
442
+ //# sourceMappingURL=vue-types-setup.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "versacompiler",
3
- "version": "2.0.3",
3
+ "version": "2.0.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": {
@@ -17,6 +17,7 @@
17
17
  "type": "module",
18
18
  "scripts": {
19
19
  "dev": "tsx --watch src/main.ts --watch --verbose --tailwind",
20
+ "file": "tsx src/main.ts ",
20
21
  "compile": "tsx src/main.ts --all",
21
22
  "test": "jest --config jest.config.js",
22
23
  "build": "tsx src/main.ts --all -t --cc --co -y --verbose",
@@ -39,6 +40,14 @@
39
40
  ],
40
41
  "author": "Jorge Jara H (kriollone@gmail.com)",
41
42
  "license": "MIT",
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "git+https://github.com/kriollo/versaCompiler.git"
46
+ },
47
+ "bugs": {
48
+ "url": "https://github.com/kriollo/versaCompiler/issues"
49
+ },
50
+ "homepage": "https://github.com/kriollo/versaCompiler#readme",
42
51
  "dependencies": {
43
52
  "@vue/compiler-dom": "^3.5.16",
44
53
  "@vue/reactivity": "^3.5.16",
@@ -53,13 +62,13 @@
53
62
  "fs-extra": "^11.3.0",
54
63
  "get-port": "^7.1.0",
55
64
  "minimatch": "^10.0.1",
56
- "oxc-minify": "^0.72.3",
57
- "oxc-parser": "^0.72.3",
58
- "oxc-transform": "^0.72.3",
65
+ "oxc-minify": "^0.73.2",
66
+ "oxc-parser": "^0.73.2",
67
+ "oxc-transform": "^0.73.2",
59
68
  "resolve": "^1.22.10",
60
69
  "tsx": "^4.19.4",
61
70
  "typescript": "^5.8.3",
62
- "vue": "3.5.16",
71
+ "vue": "3.5.17",
63
72
  "yargs": "^18.0.0"
64
73
  },
65
74
  "devDependencies": {
@@ -68,7 +77,7 @@
68
77
  "@types/browser-sync": "^2.29.0",
69
78
  "@types/find-root": "^1.1.4",
70
79
  "@types/fs-extra": "^11.0.4",
71
- "@types/jest": "^29.5.14",
80
+ "@types/jest": "^30.0.0",
72
81
  "@types/mocha": "^10.0.10",
73
82
  "@types/node": "^24.0.0",
74
83
  "@types/resolve": "^1.20.6",
@@ -85,8 +94,8 @@
85
94
  "eslint-plugin-promise": "^7.2.1",
86
95
  "eslint-plugin-unicorn": "^59.0.1",
87
96
  "eslint-plugin-vue": "^10.2.0",
88
- "happy-dom": "^17.6.3",
89
- "jest": "^29.7.0",
97
+ "happy-dom": "^18.0.1",
98
+ "jest": "^30.0.0",
90
99
  "jest-environment-jsdom": "30.0.0",
91
100
  "jest-environment-node": "30.0.0",
92
101
  "oxlint": "^1.0.0",