wu-framework 1.0.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/LICENSE +21 -0
- package/README.md +559 -0
- package/package.json +84 -0
- package/src/api/wu-simple.js +316 -0
- package/src/core/wu-app.js +192 -0
- package/src/core/wu-cache.js +374 -0
- package/src/core/wu-core.js +1296 -0
- package/src/core/wu-error-boundary.js +380 -0
- package/src/core/wu-event-bus.js +257 -0
- package/src/core/wu-hooks.js +348 -0
- package/src/core/wu-html-parser.js +280 -0
- package/src/core/wu-loader.js +271 -0
- package/src/core/wu-logger.js +119 -0
- package/src/core/wu-manifest.js +366 -0
- package/src/core/wu-performance.js +226 -0
- package/src/core/wu-plugin.js +213 -0
- package/src/core/wu-proxy-sandbox.js +153 -0
- package/src/core/wu-registry.js +130 -0
- package/src/core/wu-sandbox-pool.js +390 -0
- package/src/core/wu-sandbox.js +720 -0
- package/src/core/wu-script-executor.js +216 -0
- package/src/core/wu-snapshot-sandbox.js +184 -0
- package/src/core/wu-store.js +297 -0
- package/src/core/wu-strategies.js +241 -0
- package/src/core/wu-style-bridge.js +357 -0
- package/src/index.js +690 -0
- package/src/utils/dependency-resolver.js +326 -0
package/src/index.js
ADDED
|
@@ -0,0 +1,690 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 🚀 WU-FRAMEWORK: UNIVERSAL MICROFRONTENDS
|
|
3
|
+
*
|
|
4
|
+
* Framework puro para microfrontends con sistemas esenciales
|
|
5
|
+
* - Framework Agnostic: React, Vue, Angular, Svelte, Vanilla JS
|
|
6
|
+
* - Zero Config: npm install wu-framework y funciona
|
|
7
|
+
* - Shadow DOM: Aislamiento real sin hacks CSS
|
|
8
|
+
* - Runtime Loading: Apps dinámicas sin rebuild
|
|
9
|
+
* - Style Sharing: Comparte estilos de node_modules automáticamente
|
|
10
|
+
* - Internal Cache: Cacheo inteligente de manifests y módulos (interno)
|
|
11
|
+
* - Event Bus: Comunicación pub/sub entre microfrontends
|
|
12
|
+
* - Performance Monitor: Monitoreo de lifecycle del framework (mount/unmount)
|
|
13
|
+
* - Health Monitoring: Sistema de auto-healing para microfrontends
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```js
|
|
17
|
+
* import { wu, emit, on } from 'wu-framework';
|
|
18
|
+
*
|
|
19
|
+
* // ✨ API SIMPLIFICADA
|
|
20
|
+
* const canvas = wu.app('canvas', {
|
|
21
|
+
* url: 'http://localhost:5178',
|
|
22
|
+
* container: '#canvas-container'
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* await canvas.mount(); // Monta la app
|
|
26
|
+
* canvas.isMounted; // Verifica estado
|
|
27
|
+
* await canvas.unmount(); // Desmonta
|
|
28
|
+
*
|
|
29
|
+
* // 📡 EVENT BUS (Comunicación entre microfrontends)
|
|
30
|
+
* import { emit, on, once } from 'wu-framework';
|
|
31
|
+
*
|
|
32
|
+
* // Emitir evento
|
|
33
|
+
* emit('user:login', { userId: 123, name: 'John' });
|
|
34
|
+
*
|
|
35
|
+
* // Escuchar eventos (soporta wildcards)
|
|
36
|
+
* on('user:*', (event) => {
|
|
37
|
+
* console.log('User event:', event.data);
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // Escuchar una sola vez
|
|
41
|
+
* once('app:ready', () => console.log('App is ready!'));
|
|
42
|
+
*
|
|
43
|
+
* // ⚡ PERFORMANCE MONITORING (Framework lifecycle)
|
|
44
|
+
* import { startMeasure, endMeasure, generatePerformanceReport } from 'wu-framework';
|
|
45
|
+
*
|
|
46
|
+
* // Medir tiempos de mount/unmount
|
|
47
|
+
* startMeasure('custom-operation', 'canvas');
|
|
48
|
+
* await doSomething();
|
|
49
|
+
* const duration = endMeasure('custom-operation', 'canvas');
|
|
50
|
+
* console.log(`Operation took ${duration}ms`);
|
|
51
|
+
*
|
|
52
|
+
* // Generar reporte
|
|
53
|
+
* const report = generatePerformanceReport();
|
|
54
|
+
* console.log('Framework performance:', report);
|
|
55
|
+
*
|
|
56
|
+
* // 🔄 API CLÁSICA (también disponible)
|
|
57
|
+
* wu.init({
|
|
58
|
+
* apps: [{ name: 'header', url: 'http://localhost:3001' }]
|
|
59
|
+
* });
|
|
60
|
+
* await wu.mount('header', '#header-container');
|
|
61
|
+
*
|
|
62
|
+
* // Micro app (cualquier framework)
|
|
63
|
+
* wu.define('header', {
|
|
64
|
+
* mount: (container) => {
|
|
65
|
+
* // React: ReactDOM.render(<HeaderApp />, container);
|
|
66
|
+
* // Vue: createApp(HeaderApp).mount(container);
|
|
67
|
+
* // Vanilla: container.innerHTML = '<h1>Header</h1>';
|
|
68
|
+
* },
|
|
69
|
+
* unmount: (container) => {
|
|
70
|
+
* // Cleanup logic aquí
|
|
71
|
+
* }
|
|
72
|
+
* });
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
import { WuCore } from './core/wu-core.js';
|
|
77
|
+
|
|
78
|
+
// Crear instancia global única de wu-framework
|
|
79
|
+
// Por defecto: Health Monitoring activado PERO aging refresh DESACTIVADO
|
|
80
|
+
const wu = new WuCore({
|
|
81
|
+
healthMonitoring: true, // Detecta containers perdidos
|
|
82
|
+
autoHeal: true, // Recupera automáticamente
|
|
83
|
+
agingThreshold: Infinity, // NUNCA refresca por edad (era el problema)
|
|
84
|
+
healthCheckInterval: 60000 // Chequeo cada 60 segundos
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// Hacer wu disponible globalmente para debugging
|
|
88
|
+
if (typeof window !== 'undefined') {
|
|
89
|
+
window.wu = wu;
|
|
90
|
+
|
|
91
|
+
// Agregar información de versión
|
|
92
|
+
wu.version = '1.0.0';
|
|
93
|
+
wu.info = {
|
|
94
|
+
name: 'Wu Framework',
|
|
95
|
+
description: 'Universal Microfrontends',
|
|
96
|
+
features: [
|
|
97
|
+
'Framework Agnostic',
|
|
98
|
+
'Zero Config',
|
|
99
|
+
'Shadow DOM Isolation',
|
|
100
|
+
'Runtime Loading',
|
|
101
|
+
'Component Sharing'
|
|
102
|
+
]
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
console.log('🚀 Wu Framework loaded - Universal Microfrontends ready');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Exportar API principal
|
|
109
|
+
export { wu };
|
|
110
|
+
export default wu;
|
|
111
|
+
|
|
112
|
+
// Exportar clases individuales para uso avanzado
|
|
113
|
+
export { WuCore } from './core/wu-core.js';
|
|
114
|
+
export { WuLoader } from './core/wu-loader.js';
|
|
115
|
+
export { WuSandbox } from './core/wu-sandbox.js';
|
|
116
|
+
export { WuManifest } from './core/wu-manifest.js';
|
|
117
|
+
export { WuStore } from './core/wu-store.js';
|
|
118
|
+
export { WuApp } from './core/wu-app.js';
|
|
119
|
+
export { WuStyleBridge } from './core/wu-style-bridge.js';
|
|
120
|
+
export { default as store } from './core/wu-store.js';
|
|
121
|
+
|
|
122
|
+
// 🚀 NUEVOS SISTEMAS DE AISLAMIENTO (basados en video-code)
|
|
123
|
+
export { WuProxySandbox } from './core/wu-proxy-sandbox.js';
|
|
124
|
+
export { WuSnapshotSandbox } from './core/wu-snapshot-sandbox.js';
|
|
125
|
+
export { WuScriptExecutor, executeScript, executeScripts } from './core/wu-script-executor.js';
|
|
126
|
+
export { WuHtmlParser, parseHtml, parseHtmlFromUrl } from './core/wu-html-parser.js';
|
|
127
|
+
|
|
128
|
+
// 🚀 Exportar sistemas esenciales
|
|
129
|
+
export { WuCache } from './core/wu-cache.js';
|
|
130
|
+
export { WuEventBus } from './core/wu-event-bus.js';
|
|
131
|
+
export { WuPerformance } from './core/wu-performance.js';
|
|
132
|
+
|
|
133
|
+
// 🎯 Exportar advanced systems
|
|
134
|
+
export { WuPluginSystem, createPlugin } from './core/wu-plugin.js';
|
|
135
|
+
export { WuLoadingStrategy } from './core/wu-strategies.js';
|
|
136
|
+
export { WuErrorBoundary } from './core/wu-error-boundary.js';
|
|
137
|
+
export {
|
|
138
|
+
WuLifecycleHooks,
|
|
139
|
+
createSimpleHook,
|
|
140
|
+
createConditionalHook,
|
|
141
|
+
createGuardHook,
|
|
142
|
+
createTransformHook,
|
|
143
|
+
createTimedHook
|
|
144
|
+
} from './core/wu-hooks.js';
|
|
145
|
+
export { WuSandboxPool } from './core/wu-sandbox-pool.js';
|
|
146
|
+
export { WuRegistry } from './core/wu-registry.js';
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Utilidades de conveniencia para uso común
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Inicializar wu-framework con configuración simple
|
|
154
|
+
* @param {Array} apps - Lista de apps: [{ name, url }, ...]
|
|
155
|
+
* @returns {Promise} Promesa de inicialización
|
|
156
|
+
*/
|
|
157
|
+
export const init = async (apps) => {
|
|
158
|
+
return await wu.init({ apps });
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Montar app en contenedor
|
|
163
|
+
* @param {string} appName - Nombre de la app
|
|
164
|
+
* @param {string} containerSelector - Selector del contenedor
|
|
165
|
+
* @returns {Promise} Promesa de montaje
|
|
166
|
+
*/
|
|
167
|
+
export const mount = async (appName, containerSelector) => {
|
|
168
|
+
return await wu.mount(appName, containerSelector);
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Definir lifecycle de micro-app
|
|
173
|
+
* @param {string} appName - Nombre de la app
|
|
174
|
+
* @param {Object} lifecycle - { mount, unmount }
|
|
175
|
+
*/
|
|
176
|
+
export const define = (appName, lifecycle) => {
|
|
177
|
+
return wu.define(appName, lifecycle);
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Desmontar app
|
|
182
|
+
* @param {string} appName - Nombre de la app
|
|
183
|
+
* @returns {Promise} Promesa de desmontaje
|
|
184
|
+
*/
|
|
185
|
+
export const unmount = async (appName) => {
|
|
186
|
+
return await wu.unmount(appName);
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Crear instancia de WuApp (API simplificada)
|
|
191
|
+
* @param {string} name - Nombre de la app
|
|
192
|
+
* @param {Object} config - Configuración { url, container, autoInit }
|
|
193
|
+
* @returns {WuApp} Instancia de WuApp
|
|
194
|
+
*/
|
|
195
|
+
export const app = (name, config) => {
|
|
196
|
+
return wu.app(name, config);
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Usar componente compartido
|
|
201
|
+
* @param {string} componentPath - Ruta del componente (ej: "shared.Button")
|
|
202
|
+
* @returns {Promise} Componente cargado
|
|
203
|
+
*/
|
|
204
|
+
export const use = async (componentPath) => {
|
|
205
|
+
return await wu.use(componentPath);
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Obtener información de una app
|
|
211
|
+
* @param {string} appName - Nombre de la app
|
|
212
|
+
* @returns {Object} Información de la app
|
|
213
|
+
*/
|
|
214
|
+
export const getAppInfo = (appName) => {
|
|
215
|
+
return wu.getAppInfo(appName);
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Obtener estadísticas del framework
|
|
220
|
+
* @returns {Object} Estadísticas
|
|
221
|
+
*/
|
|
222
|
+
export const getStats = () => {
|
|
223
|
+
return wu.getStats();
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* 🏪 STORE CONVENIENCE METHODS
|
|
228
|
+
*/
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Get value from global store
|
|
232
|
+
* @param {string} path - Dot notation path
|
|
233
|
+
* @returns {*} Value at path
|
|
234
|
+
*/
|
|
235
|
+
export const getState = (path) => {
|
|
236
|
+
return wu.getState(path);
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Set value in global store
|
|
241
|
+
* @param {string} path - Dot notation path
|
|
242
|
+
* @param {*} value - Value to set
|
|
243
|
+
* @returns {number} Sequence number
|
|
244
|
+
*/
|
|
245
|
+
export const setState = (path, value) => {
|
|
246
|
+
return wu.setState(path, value);
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Subscribe to state changes
|
|
251
|
+
* @param {string} pattern - Path or pattern
|
|
252
|
+
* @param {Function} callback - Callback function
|
|
253
|
+
* @returns {Function} Unsubscribe function
|
|
254
|
+
*/
|
|
255
|
+
export const onStateChange = (pattern, callback) => {
|
|
256
|
+
return wu.onStateChange(pattern, callback);
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Batch set multiple state values
|
|
261
|
+
* @param {Object} updates - Object with path:value pairs
|
|
262
|
+
* @returns {Array} Sequence numbers
|
|
263
|
+
*/
|
|
264
|
+
export const batchState = (updates) => {
|
|
265
|
+
return wu.batchState(updates);
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Get store metrics
|
|
270
|
+
* @returns {Object} Performance metrics
|
|
271
|
+
*/
|
|
272
|
+
export const getStoreMetrics = () => {
|
|
273
|
+
return wu.getStoreMetrics();
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Clear all state
|
|
278
|
+
*/
|
|
279
|
+
export const clearState = () => {
|
|
280
|
+
wu.clearState();
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Limpiar y destruir framework
|
|
285
|
+
* @returns {Promise} Promesa de destrucción
|
|
286
|
+
*/
|
|
287
|
+
export const destroy = async () => {
|
|
288
|
+
return await wu.destroy();
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* 🎨 STYLE SHARING: Configurar compartición de estilos en Shadow DOM
|
|
293
|
+
* @param {Object} config - Configuración del StyleBridge
|
|
294
|
+
*/
|
|
295
|
+
export const configureStyleSharing = (config) => {
|
|
296
|
+
return wu.sandbox.configureStyleSharing(config);
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* 🔄 RE-INYECTAR ESTILOS: Vuelve a inyectar estilos en una app
|
|
301
|
+
* @param {string} appName - Nombre de la app
|
|
302
|
+
* @returns {Promise}
|
|
303
|
+
*/
|
|
304
|
+
export const reinjectStyles = async (appName) => {
|
|
305
|
+
return await wu.sandbox.reinjectStyles(appName);
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* 📊 ESTADÍSTICAS DE ESTILOS: Información sobre estilos compartidos
|
|
310
|
+
* @returns {Object}
|
|
311
|
+
*/
|
|
312
|
+
export const getStyleStats = () => {
|
|
313
|
+
return wu.sandbox.getStyleStats();
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* 📡 EVENT BUS: Sistema de eventos avanzado
|
|
318
|
+
*/
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Emitir evento
|
|
322
|
+
* @param {string} eventName - Nombre del evento
|
|
323
|
+
* @param {*} data - Datos del evento
|
|
324
|
+
* @param {Object} options - Opciones { appName, timestamp, meta }
|
|
325
|
+
*/
|
|
326
|
+
export const emit = (eventName, data, options) => {
|
|
327
|
+
wu.eventBus.emit(eventName, data, options);
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Suscribirse a evento
|
|
332
|
+
* @param {string} eventName - Nombre del evento (soporta wildcards: 'app.*')
|
|
333
|
+
* @param {Function} callback - Función callback
|
|
334
|
+
* @returns {Function} Función para desuscribirse
|
|
335
|
+
*/
|
|
336
|
+
export const on = (eventName, callback) => {
|
|
337
|
+
return wu.eventBus.on(eventName, callback);
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Suscribirse a evento una sola vez
|
|
342
|
+
* @param {string} eventName - Nombre del evento
|
|
343
|
+
* @param {Function} callback - Función callback
|
|
344
|
+
* @returns {Function} Función para desuscribirse
|
|
345
|
+
*/
|
|
346
|
+
export const once = (eventName, callback) => {
|
|
347
|
+
return wu.eventBus.once(eventName, callback);
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Desuscribirse de evento
|
|
352
|
+
* @param {string} eventName - Nombre del evento
|
|
353
|
+
* @param {Function} callback - Función callback
|
|
354
|
+
*/
|
|
355
|
+
export const off = (eventName, callback) => {
|
|
356
|
+
wu.eventBus.off(eventName, callback);
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Reproducir eventos del historial
|
|
361
|
+
* @param {string} eventNameOrPattern - Nombre o patrón de eventos
|
|
362
|
+
* @param {Function} callback - Callback para cada evento
|
|
363
|
+
*/
|
|
364
|
+
export const replayEvents = (eventNameOrPattern, callback) => {
|
|
365
|
+
wu.eventBus.replay(eventNameOrPattern, callback);
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Obtener estadísticas del event bus
|
|
370
|
+
* @returns {Object}
|
|
371
|
+
*/
|
|
372
|
+
export const getEventBusStats = () => {
|
|
373
|
+
return wu.eventBus.getStats();
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* ⚡ PERFORMANCE: Monitoreo de lifecycle del framework
|
|
378
|
+
*/
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Iniciar medición de performance
|
|
382
|
+
* @param {string} name - Nombre de la medición
|
|
383
|
+
* @param {string} appName - Nombre de la app (opcional)
|
|
384
|
+
*/
|
|
385
|
+
export const startMeasure = (name, appName) => {
|
|
386
|
+
wu.performance.startMeasure(name, appName);
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Finalizar medición de performance
|
|
391
|
+
* @param {string} name - Nombre de la medición
|
|
392
|
+
* @param {string} appName - Nombre de la app (opcional)
|
|
393
|
+
* @returns {number} Duración en ms
|
|
394
|
+
*/
|
|
395
|
+
export const endMeasure = (name, appName) => {
|
|
396
|
+
return wu.performance.endMeasure(name, appName);
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Obtener métricas de performance de una app
|
|
401
|
+
* @param {string} appName - Nombre de la app
|
|
402
|
+
* @returns {Object}
|
|
403
|
+
*/
|
|
404
|
+
export const getPerformanceMetrics = (appName) => {
|
|
405
|
+
return wu.performance.getMetrics(appName);
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Obtener todas las métricas de performance
|
|
410
|
+
* @returns {Object}
|
|
411
|
+
*/
|
|
412
|
+
export const getAllPerformanceMetrics = () => {
|
|
413
|
+
return wu.performance.getAllMetrics();
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Generar reporte de performance del framework
|
|
418
|
+
* @returns {Object}
|
|
419
|
+
*/
|
|
420
|
+
export const generatePerformanceReport = () => {
|
|
421
|
+
return wu.performance.generateReport();
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Limpiar métricas de performance
|
|
426
|
+
* @param {string} appName - Nombre de la app (opcional, si no se pasa limpia todas)
|
|
427
|
+
*/
|
|
428
|
+
export const clearPerformanceMetrics = (appName) => {
|
|
429
|
+
wu.performance.clearMetrics(appName);
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* 🔌 PLUGINS: Sistema de plugins extensible
|
|
434
|
+
*/
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Instalar plugin en el framework
|
|
438
|
+
* @param {Object|Function} plugin - Plugin o factory function
|
|
439
|
+
* @param {Object} options - Opciones del plugin
|
|
440
|
+
*/
|
|
441
|
+
export const usePlugin = (plugin, options) => {
|
|
442
|
+
wu.pluginSystem.use(plugin, options);
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Desinstalar plugin
|
|
447
|
+
* @param {string} pluginName - Nombre del plugin
|
|
448
|
+
*/
|
|
449
|
+
export const uninstallPlugin = (pluginName) => {
|
|
450
|
+
wu.pluginSystem.uninstall(pluginName);
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* Obtener estadísticas de plugins
|
|
455
|
+
* @returns {Object}
|
|
456
|
+
*/
|
|
457
|
+
export const getPluginStats = () => {
|
|
458
|
+
return wu.pluginSystem.getStats();
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* 🪝 HOOKS: Sistema de lifecycle hooks
|
|
463
|
+
*/
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Registrar lifecycle hook
|
|
467
|
+
* @param {string} phase - Fase del lifecycle
|
|
468
|
+
* @param {Function} middleware - Función middleware
|
|
469
|
+
* @param {Object} options - Opciones { priority, name }
|
|
470
|
+
* @returns {Function} Función para desregistrar
|
|
471
|
+
*/
|
|
472
|
+
export const useHook = (phase, middleware, options) => {
|
|
473
|
+
return wu.hooks.use(phase, middleware, options);
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Remover lifecycle hook
|
|
478
|
+
* @param {string} phase - Fase del lifecycle
|
|
479
|
+
* @param {string} name - Nombre del hook
|
|
480
|
+
*/
|
|
481
|
+
export const removeHook = (phase, name) => {
|
|
482
|
+
wu.hooks.remove(phase, name);
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Obtener estadísticas de hooks
|
|
487
|
+
* @returns {Object}
|
|
488
|
+
*/
|
|
489
|
+
export const getHookStats = () => {
|
|
490
|
+
return wu.hooks.getStats();
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* 🎯 STRATEGIES: Sistema de loading strategies
|
|
495
|
+
*/
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* Registrar loading strategy personalizada
|
|
499
|
+
* @param {string} name - Nombre de la estrategia
|
|
500
|
+
* @param {Object} strategy - Configuración de la estrategia
|
|
501
|
+
*/
|
|
502
|
+
export const registerStrategy = (name, strategy) => {
|
|
503
|
+
wu.strategies.register(name, strategy);
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* Obtener estadísticas de strategies
|
|
508
|
+
* @returns {Object}
|
|
509
|
+
*/
|
|
510
|
+
export const getStrategyStats = () => {
|
|
511
|
+
return wu.strategies.getStats();
|
|
512
|
+
};
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* 🛡️ ERROR BOUNDARY: Sistema de error handling
|
|
516
|
+
*/
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
* Registrar error handler personalizado
|
|
520
|
+
* @param {Object} handler - Error handler { name, canHandle, handle }
|
|
521
|
+
*/
|
|
522
|
+
export const registerErrorHandler = (handler) => {
|
|
523
|
+
wu.errorBoundary.register(handler);
|
|
524
|
+
};
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Configurar error boundary
|
|
528
|
+
* @param {Object} config - Nueva configuración
|
|
529
|
+
*/
|
|
530
|
+
export const configureErrorBoundary = (config) => {
|
|
531
|
+
wu.errorBoundary.configure(config);
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* Obtener log de errores
|
|
536
|
+
* @param {number} limit - Límite de errores a retornar
|
|
537
|
+
* @returns {Array}
|
|
538
|
+
*/
|
|
539
|
+
export const getErrorLog = (limit) => {
|
|
540
|
+
return wu.errorBoundary.getErrorLog(limit);
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* Obtener estadísticas de error boundary
|
|
545
|
+
* @returns {Object}
|
|
546
|
+
*/
|
|
547
|
+
export const getErrorBoundaryStats = () => {
|
|
548
|
+
return wu.errorBoundary.getStats();
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* 🏊 SANDBOX POOL: Sistema de sandbox pooling
|
|
553
|
+
*/
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* Configurar sandbox pool
|
|
557
|
+
* @param {Object} config - Nueva configuración
|
|
558
|
+
*/
|
|
559
|
+
export const configureSandboxPool = (config) => {
|
|
560
|
+
wu.sandboxPool.configure(config);
|
|
561
|
+
};
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* Obtener estadísticas de sandbox pool
|
|
565
|
+
* @returns {Object}
|
|
566
|
+
*/
|
|
567
|
+
export const getSandboxPoolStats = () => {
|
|
568
|
+
return wu.sandboxPool.getStats();
|
|
569
|
+
};
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* Presets comunes para configuración rápida
|
|
573
|
+
*/
|
|
574
|
+
export const presets = {
|
|
575
|
+
/**
|
|
576
|
+
* Configuración para desarrollo local
|
|
577
|
+
* @param {Array} apps - Apps con puertos locales
|
|
578
|
+
*/
|
|
579
|
+
development: (apps) => {
|
|
580
|
+
const devApps = apps.map(app => ({
|
|
581
|
+
...app,
|
|
582
|
+
url: app.url || `http://localhost:${app.port || 3001}`
|
|
583
|
+
}));
|
|
584
|
+
|
|
585
|
+
return {
|
|
586
|
+
apps: devApps,
|
|
587
|
+
debug: true,
|
|
588
|
+
hotReload: true
|
|
589
|
+
};
|
|
590
|
+
},
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* Configuración para producción
|
|
594
|
+
* @param {Array} apps - Apps con URLs de producción
|
|
595
|
+
*/
|
|
596
|
+
production: (apps) => {
|
|
597
|
+
return {
|
|
598
|
+
apps,
|
|
599
|
+
debug: false,
|
|
600
|
+
cache: true,
|
|
601
|
+
preload: true
|
|
602
|
+
};
|
|
603
|
+
},
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* Configuración para single page application
|
|
607
|
+
* @param {Object} config - Configuración SPA
|
|
608
|
+
*/
|
|
609
|
+
spa: (config) => {
|
|
610
|
+
return {
|
|
611
|
+
apps: [
|
|
612
|
+
{
|
|
613
|
+
name: 'main',
|
|
614
|
+
url: config.url || window.location.origin,
|
|
615
|
+
container: config.container || '#app'
|
|
616
|
+
}
|
|
617
|
+
]
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
};
|
|
621
|
+
|
|
622
|
+
/**
|
|
623
|
+
* Helpers para desarrollo
|
|
624
|
+
*/
|
|
625
|
+
export const dev = {
|
|
626
|
+
/**
|
|
627
|
+
* Activar modo debug
|
|
628
|
+
*/
|
|
629
|
+
enableDebug: () => {
|
|
630
|
+
wu.debug = true;
|
|
631
|
+
console.log('🐛 Wu Framework debug mode enabled');
|
|
632
|
+
},
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* Desactivar modo debug
|
|
636
|
+
*/
|
|
637
|
+
disableDebug: () => {
|
|
638
|
+
wu.debug = false;
|
|
639
|
+
console.log('🐛 Wu Framework debug mode disabled');
|
|
640
|
+
},
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Inspeccionar estado del framework
|
|
644
|
+
*/
|
|
645
|
+
inspect: () => {
|
|
646
|
+
return {
|
|
647
|
+
version: wu.version,
|
|
648
|
+
stats: wu.getStats(),
|
|
649
|
+
apps: Array.from(wu.apps.keys()).map(name => wu.getAppInfo(name))
|
|
650
|
+
};
|
|
651
|
+
},
|
|
652
|
+
|
|
653
|
+
/**
|
|
654
|
+
* Recargar app específica (útil para desarrollo)
|
|
655
|
+
* @param {string} appName - Nombre de la app
|
|
656
|
+
*/
|
|
657
|
+
reload: async (appName) => {
|
|
658
|
+
console.log(`🔄 Reloading app: ${appName}`);
|
|
659
|
+
await wu.unmount(appName);
|
|
660
|
+
|
|
661
|
+
// Limpiar caches
|
|
662
|
+
wu.loader.clearCache(appName);
|
|
663
|
+
wu.manifest.clearCache(appName);
|
|
664
|
+
|
|
665
|
+
await wu.mount(appName);
|
|
666
|
+
console.log(`✅ App reloaded: ${appName}`);
|
|
667
|
+
}
|
|
668
|
+
};
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* Eventos del framework
|
|
672
|
+
*/
|
|
673
|
+
export const events = {
|
|
674
|
+
// Event listeners para el ciclo de vida de las apps
|
|
675
|
+
onAppMounted: (callback) => {
|
|
676
|
+
document.addEventListener('wu:app:mounted', callback);
|
|
677
|
+
},
|
|
678
|
+
|
|
679
|
+
onAppUnmounted: (callback) => {
|
|
680
|
+
document.addEventListener('wu:app:unmounted', callback);
|
|
681
|
+
},
|
|
682
|
+
|
|
683
|
+
onAppError: (callback) => {
|
|
684
|
+
document.addEventListener('wu:app:error', callback);
|
|
685
|
+
},
|
|
686
|
+
|
|
687
|
+
onFrameworkReady: (callback) => {
|
|
688
|
+
document.addEventListener('wu:framework:ready', callback);
|
|
689
|
+
}
|
|
690
|
+
};
|