@vc-shell/framework 1.1.50 → 1.1.52

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/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [1.1.52](https://github.com/VirtoCommerce/vc-shell/compare/v1.1.51...v1.1.52) (2025-07-02)
2
+
3
+
4
+
5
+ ## [1.1.51](https://github.com/VirtoCommerce/vc-shell/compare/v1.1.50...v1.1.51) (2025-07-02)
6
+
7
+
8
+
1
9
  ## [1.1.50](https://github.com/VirtoCommerce/vc-shell/compare/v1.1.49...v1.1.50) (2025-07-02)
2
10
 
3
11
 
@@ -348,20 +348,94 @@ export function useDynamicModules(
348
348
  moduleLoadResults.filter((result) => result.success).map((result) => [result.moduleId, result]),
349
349
  );
350
350
 
351
- // Debug: log what we have in window.VcShellDynamicModules
352
- console.log(
353
- "🔍 Available modules in window.VcShellDynamicModules:",
351
+ console.log("🔍 LoadResultsMap keys:", Array.from(loadResultsMap.keys()));
352
+
353
+ // Wait for all modules to register themselves in the global scope
354
+ const expectedModuleIds = Array.from(loadResultsMap.keys());
355
+
356
+ const getAvailableModules = () =>
354
357
  typeof window !== "undefined" && window.VcShellDynamicModules
355
358
  ? Object.keys(window.VcShellDynamicModules)
356
- : "No modules found",
357
- );
359
+ : [];
360
+
361
+ const isModuleRegistered = (moduleId: string, availableModules: string[]) =>
362
+ availableModules.some(
363
+ (registeredId) =>
364
+ registeredId === moduleId || registeredId.includes(moduleId) || moduleId.includes(registeredId),
365
+ );
366
+
367
+ const areAllModulesRegistered = () => {
368
+ const availableModules = getAvailableModules();
369
+ return (
370
+ expectedModuleIds.length > 0 &&
371
+ expectedModuleIds.every((moduleId) => isModuleRegistered(moduleId, availableModules)) &&
372
+ availableModules.length > 0
373
+ );
374
+ };
375
+
376
+ // Check if modules are already registered
377
+ if (areAllModulesRegistered()) {
378
+ console.log("✅ All modules are already registered, proceeding with installation");
379
+ } else {
380
+ console.log(`🔍 Waiting for ${expectedModuleIds.length} modules to register:`, expectedModuleIds);
381
+
382
+ // Wait for module registration with timeout
383
+ await new Promise<void>((resolve) => {
384
+ let timeoutId: NodeJS.Timeout | null = null;
385
+ let eventListener: EventListener | null = null;
386
+ let attempts = 0;
387
+ const maxAttempts = 50; // 5 seconds max wait time
388
+
389
+ const cleanup = () => {
390
+ if (timeoutId) {
391
+ clearTimeout(timeoutId);
392
+ timeoutId = null;
393
+ }
394
+ if (eventListener && typeof window !== "undefined") {
395
+ window.removeEventListener("vc-shell-module-registered", eventListener);
396
+ }
397
+ };
358
398
 
359
- console.log("🔍 LoadedModules set:", Array.from(loadedModules));
360
- console.log("🔍 LoadResultsMap keys:", Array.from(loadResultsMap.keys()));
399
+ const checkAndResolve = () => {
400
+ if (areAllModulesRegistered()) {
401
+ console.log("✅ All modules are registered, proceeding with installation");
402
+ cleanup();
403
+ resolve();
404
+ return true;
405
+ }
406
+ return false;
407
+ };
361
408
 
362
- // Wait for the next animation frame to allow all module scripts to complete their registration.
363
- // This helps prevent race conditions where processing starts before modules are available in the global scope.
364
- await new Promise((resolve) => requestAnimationFrame(resolve));
409
+ // Set up event listener for immediate response
410
+ if (typeof window !== "undefined") {
411
+ eventListener = () => checkAndResolve();
412
+ window.addEventListener("vc-shell-module-registered", eventListener);
413
+ }
414
+
415
+ // Fallback polling with timeout
416
+ const poll = async () => {
417
+ while (attempts < maxAttempts) {
418
+ const availableModules = getAvailableModules();
419
+ console.log(
420
+ `🔍 Attempt ${attempts + 1}: Available modules:`,
421
+ availableModules,
422
+ `(${availableModules.length}/${expectedModuleIds.length})`,
423
+ );
424
+
425
+ if (checkAndResolve()) return;
426
+
427
+ attempts++;
428
+ await new Promise((r) => setTimeout(r, 100));
429
+ }
430
+
431
+ console.warn("⚠️ Timeout waiting for all modules to register, proceeding with available modules");
432
+ cleanup();
433
+ resolve();
434
+ };
435
+
436
+ poll();
437
+ });
438
+ }
365
439
 
366
440
  const moduleVersions = new Map<string, VersionInfo>();
367
441
  for (const [moduleId, result] of loadResultsMap.entries()) {
@@ -380,13 +454,24 @@ export function useDynamicModules(
380
454
 
381
455
  for (const [moduleName, moduleObject] of modulesToProcess) {
382
456
  if (loadedModules.has(moduleName)) {
457
+ console.log(`⏭️ Skipping already loaded module: ${moduleName}`);
383
458
  continue;
384
459
  }
385
460
 
386
461
  console.log(`📦 Processing module: ${moduleName}`);
387
462
 
388
- const loadResult = loadResultsMap.get(moduleName);
389
- const versionFromFile = moduleVersions.get(moduleName);
463
+ // Try to find the corresponding load result by matching module names
464
+ const loadResult =
465
+ loadResultsMap.get(moduleName) ||
466
+ Array.from(loadResultsMap.entries()).find(
467
+ ([moduleId]) => moduleId.includes(moduleName) || moduleName.includes(moduleId),
468
+ )?.[1];
469
+
470
+ const versionFromFile =
471
+ moduleVersions.get(moduleName) ||
472
+ Array.from(moduleVersions.entries()).find(
473
+ ([moduleId]) => moduleId.includes(moduleName) || moduleName.includes(moduleId),
474
+ )?.[1];
390
475
 
391
476
  const mainModule = getModuleInstall(moduleObject);
392
477
 
@@ -1 +1 @@
1
- {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../../core/plugins/modularity/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAU,MAAM,KAAK,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AA4HpC,UAAU,YAAY;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,MAAM,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAqGD,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,GAAG,EACR,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,EACxD,MAAM,GAAE,OAAO,CAAC,YAAY,CAAM;;;;EA2OnC"}
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../../core/plugins/modularity/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAU,MAAM,KAAK,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AA4HpC,UAAU,YAAY;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,MAAM,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAqGD,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,GAAG,EACR,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,EACxD,MAAM,GAAE,OAAO,CAAC,YAAY,CAAM;;;;EAgUnC"}