(opts: EntryOpts)
| 42 | } |
| 43 | |
| 44 | export default async function startEntry(opts: EntryOpts) { |
| 45 | const ORIGIN = String(opts.origin || ''); |
| 46 | const MAIN = String(opts.main || `${__NS_APP_ROOT_VIRTUAL__}/app.ts`); |
| 47 | const VER = String(opts.ver || '0'); |
| 48 | const VERBOSE = !!opts.verbose; |
| 49 | // Announce chosen origin globally for any consumers (e.g., HMR client or helpers) |
| 50 | try { |
| 51 | (globalThis as any).__NS_HTTP_ORIGIN__ = ORIGIN; |
| 52 | } catch {} |
| 53 | |
| 54 | // Module-local trace snapshot |
| 55 | const TRACE: any = { version: VER, origin: ORIGIN, mainPath: MAIN, t0: Date.now(), preload: { rt: {}, core: {} }, main: {} }; |
| 56 | |
| 57 | // Native HTTP ESM import only. |
| 58 | // Ensure a single canonical module realm. |
| 59 | const importHttp = async (u: string) => { |
| 60 | return await import(/* @vite-ignore */ u); |
| 61 | }; |
| 62 | |
| 63 | try { |
| 64 | // Preload runtime bridge and core bridge |
| 65 | const t_rt = Date.now(); |
| 66 | try { |
| 67 | await importHttp(ORIGIN + '/ns/rt/' + VER); |
| 68 | TRACE.preload.rt = { ok: true, ms: Date.now() - t_rt, url: ORIGIN + '/ns/rt/' + VER }; |
| 69 | } catch (e_rt: any) { |
| 70 | TRACE.preload.rt = { ok: false, ms: Date.now() - t_rt, url: ORIGIN + '/ns/rt/' + VER, err: String(e_rt && (e_rt.message || e_rt)) }; |
| 71 | } |
| 72 | const t_core = Date.now(); |
| 73 | try { |
| 74 | await importHttp(ORIGIN + '/ns/core/' + VER); |
| 75 | TRACE.preload.core = { ok: true, ms: Date.now() - t_core, url: ORIGIN + '/ns/core/' + VER }; |
| 76 | } catch (e_core: any) { |
| 77 | TRACE.preload.core = { ok: false, ms: Date.now() - t_core, url: ORIGIN + '/ns/core/' + VER, err: String(e_core && (e_core.message || e_core)) }; |
| 78 | } |
| 79 | |
| 80 | const MAIN_URL = ORIGIN + '/ns/m' + MAIN + '?v=' + VER; |
| 81 | if (VERBOSE) console.info('[ns-entry] entry importing', MAIN_URL); |
| 82 | (globalThis as any).__NS_ENTRY_LAST_TARGET__ = MAIN_URL; // used by fetchCodeframe sanitized-vs-raw tag |
| 83 | const t_main = Date.now(); |
| 84 | await importHttp(MAIN_URL); |
| 85 | TRACE.main = { ok: true, ms: Date.now() - t_main, url: MAIN_URL }; |
| 86 | (globalThis as any).__NS_ENTRY_OK__ = true; |
| 87 | |
| 88 | // Detect whether the early placeholder was installed; defer restoration until after a safe reset |
| 89 | let hadPlaceholder = false; |
| 90 | try { |
| 91 | const g: any = globalThis as any; |
| 92 | hadPlaceholder = !!(g && g.__NS_DEV_PLACEHOLDER_ROOT_EARLY__); |
| 93 | } catch {} |
| 94 | |
| 95 | // Placeholder detected: delegate root replacement to the HMR client. |
| 96 | // Keep entry-runtime hands-off to avoid contention and duplicated logic. |
| 97 | if (!hadPlaceholder) { |
| 98 | if (VERBOSE) console.info('[ns-entry] no placeholder root detected; nothing to handoff'); |
| 99 | } else { |
| 100 | if (VERBOSE) console.info('[ns-entry] placeholder present; delegating root reset to HMR client'); |
| 101 | } |
nothing calls this directly
no test coverage detected