1d46e3a1aSTomasz Sapetaimport NativeModulesProxy from './NativeModulesProxy';
2d46e3a1aSTomasz Sapeta/**
3d46e3a1aSTomasz Sapeta * Imports the native module registered with given name. In the first place it tries to load
4d46e3a1aSTomasz Sapeta * the module installed through the JSI host object and then falls back to the bridge proxy module.
5d46e3a1aSTomasz Sapeta * Notice that the modules loaded from the proxy may not support some features like synchronous functions.
6d46e3a1aSTomasz Sapeta *
7d46e3a1aSTomasz Sapeta * @param moduleName Name of the requested native module.
8d46e3a1aSTomasz Sapeta * @returns Object representing the native module.
9d46e3a1aSTomasz Sapeta * @throws Error when there is no native module with given name.
10d46e3a1aSTomasz Sapeta */
11d46e3a1aSTomasz Sapetaexport function requireNativeModule(moduleName) {
12*5585864bSTomasz Sapeta    const nativeModule = requireOptionalNativeModule(moduleName);
13d46e3a1aSTomasz Sapeta    if (!nativeModule) {
14d46e3a1aSTomasz Sapeta        throw new Error(`Cannot find native module '${moduleName}'`);
15d46e3a1aSTomasz Sapeta    }
16d46e3a1aSTomasz Sapeta    return nativeModule;
17d46e3a1aSTomasz Sapeta}
18*5585864bSTomasz Sapeta/**
19*5585864bSTomasz Sapeta * Imports the native module registered with the given name. The same as `requireNativeModule`,
20*5585864bSTomasz Sapeta * but returns `null` when the module cannot be found instead of throwing an error.
21*5585864bSTomasz Sapeta *
22*5585864bSTomasz Sapeta * @param moduleName Name of the requested native module.
23*5585864bSTomasz Sapeta * @returns Object representing the native module or `null` when it cannot be found.
24*5585864bSTomasz Sapeta */
25*5585864bSTomasz Sapetaexport function requireOptionalNativeModule(moduleName) {
26*5585864bSTomasz Sapeta    return (globalThis.expo?.modules?.[moduleName] ??
27*5585864bSTomasz Sapeta        globalThis.ExpoModules?.[moduleName] ??
28*5585864bSTomasz Sapeta        NativeModulesProxy[moduleName] ??
29*5585864bSTomasz Sapeta        null);
30*5585864bSTomasz Sapeta}
31d46e3a1aSTomasz Sapeta//# sourceMappingURL=requireNativeModule.js.map