(name: 'Application' | 'Frame' | 'Page' | 'Label')
| 42 | |
| 43 | // Resolve NativeScript core classes/Application from the vendor realm or globalThis. |
| 44 | export function getCore(name: 'Application' | 'Frame' | 'Page' | 'Label'): any { |
| 45 | const g = globalThis; |
| 46 | // 1) Prefer vendor registry to guarantee single realm |
| 47 | try { |
| 48 | const reg: Map<string, any> | undefined = g.__nsVendorRegistry; |
| 49 | if (reg && typeof reg.get === 'function') { |
| 50 | const mod = reg.get('@nativescript/core'); |
| 51 | const ns = (mod && (mod.default || mod)) || mod; |
| 52 | if (name === 'Application' && (ns?.Application || ns)) return ns.Application || ns; |
| 53 | if (ns && ns[name]) return ns[name]; |
| 54 | } |
| 55 | } catch {} |
| 56 | // 2) Fallback to global installed |
| 57 | try { |
| 58 | if (g && g[name]) return g[name]; |
| 59 | } catch {} |
| 60 | // 3) Device require (still resolves to vendor realm when available) |
| 61 | try { |
| 62 | const req = g && (g.__nsVendorRequire || g.__nsRequire || g.require); |
| 63 | if (typeof req === 'function') { |
| 64 | const mod = req('@nativescript/core'); |
| 65 | const ns = (mod && (mod.default || mod)) || mod; |
| 66 | if (name === 'Application' && (ns?.Application || ns)) return ns.Application || ns; |
| 67 | if (ns && ns[name]) return ns[name]; |
| 68 | } |
| 69 | } catch {} |
| 70 | // 4) Last resort: nativeRequire if available |
| 71 | try { |
| 72 | const nativeReq = g && g.__nativeRequire; |
| 73 | if (typeof nativeReq === 'function') { |
| 74 | try { |
| 75 | const mod = nativeReq('@nativescript/core', '/'); |
| 76 | const ns = (mod && (mod.default || mod)) || mod; |
| 77 | if (name === 'Application' && (ns?.Application || ns)) return ns.Application || ns; |
| 78 | if (ns && ns[name]) return ns[name]; |
| 79 | } catch {} |
| 80 | } |
| 81 | } catch {} |
| 82 | return undefined; |
| 83 | } |
| 84 | |
| 85 | // last mounted app instance |
| 86 | let CURRENT_APP: any | null = null; |
no test coverage detected