MCPcopy Create free account
hub / github.com/RtlZeroMemory/Rezi / loadNative

Function loadNative

packages/node/src/worker/engineWorker.ts:93–119  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

91}
92
93async 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
121const native = await loadNative();
122

Callers 1

engineWorker.tsFile · 0.70

Calls 2

unwrapFunction · 0.70
safeDetailFunction · 0.50

Tested by

no test coverage detected