import type {} from '../../types/globals'; /* Module version validation and sync */ export const checkModuleVersions = ( serverVersions: Record | undefined, clientVersions: Record | undefined ) => { if (!serverVersions || !clientVersions) { return { needsSync: false, stale: [] }; } const stale = Object.entries(serverVersions) .filter(([modulePath, serverVersion]) => { const clientVersion = clientVersions[modulePath]; return clientVersion === undefined || clientVersion < serverVersion; }) .map(([modulePath]) => modulePath); return { needsSync: stale.length > 0, stale }; }; const resolveManifestPath = ( modulePath: string, manifest: Record | undefined ) => { if (!manifest) { return modulePath; } for (const key of Object.keys(manifest)) { const path = manifest[key] ?? modulePath; if (path === modulePath || path.includes(modulePath)) { return path; } } return modulePath; }; export const prefetchModules = ( modulePaths: string[], manifest: Record | undefined ) => { const prefetchPromises: Promise[] = []; for (const modulePath of modulePaths) { const manifestPath = resolveManifestPath(modulePath, manifest); const cacheBuster = `?t=${Date.now()}`; const fullPath = manifestPath.startsWith('/') ? manifestPath + cacheBuster : `/${manifestPath}${cacheBuster}`; prefetchPromises.push( import(fullPath).catch(() => { /* ignore */ }) ); } return Promise.all(prefetchPromises); };