()
| 27 | let _mod: KeyringModule | null | 'not-tried' = 'not-tried' |
| 28 | |
| 29 | async function loadModule(): Promise<KeyringModule> { |
| 30 | if (_mod !== 'not-tried') { |
| 31 | if (_mod === null) |
| 32 | throw new KeychainUnavailableError('module load failed previously') |
| 33 | return _mod |
| 34 | } |
| 35 | try { |
| 36 | // Dynamic import so the rest of the codebase compiles even without the module. |
| 37 | const m = (await import('@napi-rs/keyring')) as unknown as KeyringModule |
| 38 | if (!m || typeof m.Entry !== 'function') { |
| 39 | _mod = null |
| 40 | throw new KeychainUnavailableError('module does not export Entry') |
| 41 | } |
| 42 | _mod = m |
| 43 | return m |
| 44 | } catch (err: unknown) { |
| 45 | if (err instanceof KeychainUnavailableError) throw err |
| 46 | _mod = null |
| 47 | throw new KeychainUnavailableError( |
| 48 | err instanceof Error ? err.message : String(err), |
| 49 | ) |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Reset module cache — for testing only. |
no outgoing calls
no test coverage detected