(spec: string)
| 197 | |
| 198 | // Centralized safe dynamic import wrapper to guard anomalous specifiers |
| 199 | export async function safeDynImport(spec: string): Promise<any> { |
| 200 | try { |
| 201 | const origin = httpOriginForVite || deriveHttpOrigin(hmrWsUrl); |
| 202 | let finalSpec = spec; |
| 203 | if (!finalSpec || finalSpec === '@') { |
| 204 | finalSpec = (origin ? origin : '') + '/ns/m/__invalid_at__.mjs'; |
| 205 | } |
| 206 | if (__NS_ENV_VERBOSE__) { |
| 207 | try { |
| 208 | console.log('[hmr-client][dyn-import]', 'spec=', spec, 'final=', finalSpec); |
| 209 | } catch {} |
| 210 | } |
| 211 | // Use native dynamic import |
| 212 | // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
| 213 | // @ts-ignore - dynamic import expression |
| 214 | return await import(finalSpec); |
| 215 | } catch (e) { |
| 216 | if (__NS_ENV_VERBOSE__) { |
| 217 | console.warn('[hmr-client][dyn-import][error]', spec, e); |
| 218 | } |
| 219 | // Best-effort diagnostics: fetch sanitized and raw sources and print a snippet around the failing frame |
| 220 | try { |
| 221 | await dumpDynImportDiagnostics(spec, e as any); |
| 222 | } catch {} |
| 223 | throw e; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | // Extract a (url, line, column) triple from a V8 stack string |
| 228 | function parseStackFrame(err: any): { |
no test coverage detected