(wsUrl: string | undefined)
| 142 | export const moduleFetchCache = new Map<string, string>(); // spec -> resolved HTTP URL |
| 143 | |
| 144 | export function deriveHttpOrigin(wsUrl: string | undefined) { |
| 145 | try { |
| 146 | // Prefer explicit HTTP origin provided by entry-runtime when available |
| 147 | try { |
| 148 | const g: any = globalThis as any; |
| 149 | if (g && typeof g.__NS_HTTP_ORIGIN__ === 'string' && /^https?:\/\//.test(g.__NS_HTTP_ORIGIN__)) { |
| 150 | return String(g.__NS_HTTP_ORIGIN__); |
| 151 | } |
| 152 | } catch {} |
| 153 | const url = new URL(wsUrl || 'ws://localhost:5173/ns-hmr'); |
| 154 | const http = url.protocol === 'wss:' ? 'https:' : 'http:'; |
| 155 | const origin = `${http}//${url.host}`; |
| 156 | if (!/^https?:\/\/[\w\-.:\[\]]+$/.test(origin)) { |
| 157 | console.warn('[hmr-client][origin] invariant failed for', wsUrl, '→', origin); |
| 158 | } |
| 159 | return origin; |
| 160 | } catch { |
| 161 | return 'http://localhost:5173'; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | export async function requestModuleFromServer(spec: string): Promise<string> { |
| 166 | const isSfcArtifact = (s: string) => /(?:^|\/)sfc-[a-f0-9]{8}\.mjs$/i.test(s) || /\/_ns_hmr\/src\/sfc\//.test(s) || /__NSDOC__\/_ns_hmr\/src\/sfc\//.test(s); |
no test coverage detected