()
| 91 | } |
| 92 | |
| 93 | async function loadNative(): Promise<NativeApi> { |
| 94 | const wd: WorkerData = |
| 95 | workerData && typeof workerData === "object" ? (workerData as WorkerData) : Object.freeze({}); |
| 96 | const shim = typeof wd.nativeShimModule === "string" ? wd.nativeShimModule : null; |
| 97 | |
| 98 | const unwrap = (m: unknown): NativeApi => { |
| 99 | if (typeof m === "object" && m !== null) { |
| 100 | const rec = m as { native?: unknown; default?: unknown }; |
| 101 | const candidate = (rec.native ?? rec.default ?? rec) as unknown; |
| 102 | return candidate as NativeApi; |
| 103 | } |
| 104 | return m as NativeApi; |
| 105 | }; |
| 106 | |
| 107 | if (shim !== null && shim.length > 0) { |
| 108 | return unwrap((await import(shim)) as unknown); |
| 109 | } |
| 110 | |
| 111 | try { |
| 112 | return unwrap((await import("@rezi-ui/native")) as unknown); |
| 113 | } catch (err) { |
| 114 | const detail = safeDetail(err); |
| 115 | throw new Error( |
| 116 | `Failed to load @rezi-ui/native.\n\nThis usually means the native addon was not built or not installed for this platform.\n\n${detail}`, |
| 117 | ); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | const native = await loadNative(); |
| 122 |
no test coverage detected