(ev: any)
| 1011 | } |
| 1012 | |
| 1013 | async function handleHmrMessage(ev: any) { |
| 1014 | let msg: any; |
| 1015 | try { |
| 1016 | msg = JSON.parse((ev as any).data); |
| 1017 | } catch { |
| 1018 | return; |
| 1019 | } |
| 1020 | if (VERBOSE) console.log('[hmr-client] msg', msg); |
| 1021 | if (msg) { |
| 1022 | if (msg.type === 'ns:hmr-full-graph') { |
| 1023 | setGraphVersion(Number(msg.version || getGraphVersion() || 0)); |
| 1024 | applyFullGraph(msg); |
| 1025 | return; |
| 1026 | } |
| 1027 | if (msg.type === 'ns:ts-module-registry') { |
| 1028 | try { |
| 1029 | const mods: string[] = Array.isArray(msg.modules) ? msg.modules.filter((m: any) => typeof m === 'string') : []; |
| 1030 | if (mods.length) { |
| 1031 | if (!tsModuleSet) tsModuleSet = new Set<string>(); |
| 1032 | mods.forEach((m) => tsModuleSet!.add(m)); |
| 1033 | // Prefer explicit app main entry if present, else first module |
| 1034 | if (mods.includes(APP_MAIN_ENTRY_SPEC)) { |
| 1035 | tsMainId = APP_MAIN_ENTRY_SPEC; |
| 1036 | } else if (!tsMainId) { |
| 1037 | tsMainId = mods[0]; |
| 1038 | } |
| 1039 | if (VERBOSE) |
| 1040 | console.log('[hmr-client][ts-registry] registered TS modules', { |
| 1041 | count: tsModuleSet.size, |
| 1042 | mainId: tsMainId, |
| 1043 | }); |
| 1044 | } |
| 1045 | } catch (e) { |
| 1046 | if (VERBOSE) console.warn('[hmr-client][ts-registry] failed to record', e); |
| 1047 | } |
| 1048 | return; |
| 1049 | } |
| 1050 | if (msg.type === 'ns:hmr-delta') { |
| 1051 | setGraphVersion(Number(msg.newVersion || getGraphVersion() || 0)); |
| 1052 | try { |
| 1053 | const ids = Array.isArray(msg.changed) ? msg.changed.map((c: any) => c?.id).filter(Boolean) : []; |
| 1054 | if (ids.length) txnClientBatches.set(getGraphVersion(), ids); |
| 1055 | } catch {} |
| 1056 | applyDelta(msg); |
| 1057 | return; |
| 1058 | } else if (handleAngularHotUpdateMessage(msg, { getCore, verbose: VERBOSE })) { |
| 1059 | return; |
| 1060 | } |
| 1061 | } |
| 1062 | // On-demand module fetch response (Option A) |
| 1063 | if (msg.type === 'ns:module-response' && typeof msg.requestId === 'number') { |
| 1064 | const pending = pendingModuleFetches.get(msg.requestId); |
| 1065 | if (pending) { |
| 1066 | pendingModuleFetches.delete(msg.requestId); |
| 1067 | if (msg.error) { |
| 1068 | if (VERBOSE) console.warn('[hmr-fetch] error', msg.error, 'spec=', pending.spec, 'id=', msg.requestId); |
| 1069 | pending.reject(new Error(`[hmr-fetch] ${msg.error} for ${pending.spec}`)); |
| 1070 | } else { |
nothing calls this directly
no test coverage detected