react-native-nitro-modules 0.10.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/NitroModules.podspec +4 -0
  2. package/README.md +2 -2
  3. package/android/CMakeLists.txt +3 -0
  4. package/android/build.gradle +27 -3
  5. package/android/src/main/cpp/JNIOnLoad.cpp +5 -5
  6. package/android/src/main/cpp/platform/NitroLogger.cpp +1 -1
  7. package/android/src/main/cpp/turbomodule/JNitroModules.cpp +41 -0
  8. package/android/src/main/cpp/turbomodule/JNitroModules.hpp +37 -0
  9. package/android/src/main/java/com/margelo/nitro/NitroModules.kt +69 -0
  10. package/android/src/main/java/com/margelo/nitro/NitroModulesPackage.kt +34 -0
  11. package/android/src/main/java/com/margelo/nitro/core/HybridObject.kt +6 -2
  12. package/android/src/newarch/NitroModulesSpec.kt +6 -0
  13. package/android/src/oldarch/NitroModulesSpec.kt +9 -0
  14. package/cpp/core/HybridFunction.hpp +13 -4
  15. package/cpp/entrypoint/HybridNitroModulesProxy.cpp +55 -0
  16. package/cpp/entrypoint/HybridNitroModulesProxy.hpp +48 -0
  17. package/cpp/entrypoint/InstallNitro.cpp +28 -0
  18. package/cpp/entrypoint/InstallNitro.hpp +41 -0
  19. package/cpp/jsi/JSIConverter+ArrayBuffer.hpp +6 -6
  20. package/cpp/jsi/JSIConverter+HostObject.hpp +73 -0
  21. package/cpp/jsi/JSIConverter+HybridObject.hpp +1 -1
  22. package/cpp/jsi/JSIConverter+Promise.hpp +1 -0
  23. package/cpp/jsi/JSIConverter+Tuple.hpp +2 -2
  24. package/cpp/jsi/JSIConverter.hpp +1 -0
  25. package/cpp/prototype/HybridObjectPrototype.cpp +4 -3
  26. package/cpp/threading/CallInvokerDispatcher.hpp +5 -0
  27. package/cpp/utils/NitroDefines.hpp +8 -0
  28. package/cpp/utils/TypeInfo.hpp +40 -20
  29. package/ios/core/ArrayBufferHolder.hpp +1 -1
  30. package/ios/core/HybridObjectSpec.swift +1 -1
  31. package/ios/platform/NitroLogger.mm +1 -2
  32. package/ios/turbomodule/NativeNitroModules+NewArch.mm +67 -0
  33. package/ios/turbomodule/NativeNitroModules+OldArch.mm +71 -0
  34. package/ios/turbomodule/NativeNitroModules.h +22 -0
  35. package/lib/BoxedHybridObject.d.ts +12 -0
  36. package/lib/BoxedHybridObject.js +1 -0
  37. package/lib/ModuleNotFoundError.js +3 -13
  38. package/lib/NitroModules.d.ts +1 -83
  39. package/lib/NitroModules.js +2 -94
  40. package/lib/NitroModulesProxy.d.ts +58 -0
  41. package/lib/NitroModulesProxy.js +1 -0
  42. package/lib/commonjs/BoxedHybridObject.js +6 -0
  43. package/lib/commonjs/BoxedHybridObject.js.map +1 -0
  44. package/lib/commonjs/ModuleNotFoundError.js +3 -15
  45. package/lib/commonjs/ModuleNotFoundError.js.map +1 -1
  46. package/lib/commonjs/NitroModules.js +11 -100
  47. package/lib/commonjs/NitroModules.js.map +1 -1
  48. package/lib/commonjs/NitroModulesProxy.js +6 -0
  49. package/lib/commonjs/NitroModulesProxy.js.map +1 -0
  50. package/lib/commonjs/turbomodule/NativeNitroModules.js +36 -0
  51. package/lib/commonjs/turbomodule/NativeNitroModules.js.map +1 -0
  52. package/lib/commonjs/turbomodule/NativeNitroModules.web.js +17 -0
  53. package/lib/commonjs/turbomodule/NativeNitroModules.web.js.map +1 -0
  54. package/lib/module/BoxedHybridObject.js +4 -0
  55. package/lib/module/BoxedHybridObject.js.map +1 -0
  56. package/lib/module/ModuleNotFoundError.js +3 -15
  57. package/lib/module/ModuleNotFoundError.js.map +1 -1
  58. package/lib/module/NitroModules.js +2 -100
  59. package/lib/module/NitroModules.js.map +1 -1
  60. package/lib/module/NitroModulesProxy.js +4 -0
  61. package/lib/module/NitroModulesProxy.js.map +1 -0
  62. package/lib/module/turbomodule/NativeNitroModules.js +31 -0
  63. package/lib/module/turbomodule/NativeNitroModules.js.map +1 -0
  64. package/lib/{NitroModulesTurboModule.web.js → module/turbomodule/NativeNitroModules.web.js} +9 -1
  65. package/lib/module/turbomodule/NativeNitroModules.web.js.map +1 -0
  66. package/lib/tsconfig.tsbuildinfo +1 -1
  67. package/lib/turbomodule/NativeNitroModules.d.ts +7 -0
  68. package/lib/turbomodule/NativeNitroModules.js +27 -0
  69. package/lib/turbomodule/NativeNitroModules.web.d.ts +2 -0
  70. package/lib/turbomodule/NativeNitroModules.web.js +9 -0
  71. package/lib/typescript/AnyMap.d.ts +20 -0
  72. package/lib/typescript/BoxedHybridObject.d.ts +13 -0
  73. package/lib/typescript/BoxedHybridObject.d.ts.map +1 -0
  74. package/lib/typescript/ModuleNotFoundError.d.ts +7 -0
  75. package/lib/typescript/ModuleNotFoundError.d.ts.map +1 -1
  76. package/lib/typescript/NitroModules.d.ts +1 -83
  77. package/lib/typescript/NitroModules.d.ts.map +1 -1
  78. package/lib/typescript/NitroModulesProxy.d.ts +59 -0
  79. package/lib/typescript/NitroModulesProxy.d.ts.map +1 -0
  80. package/lib/typescript/__tests__/index.test.d.ts +1 -0
  81. package/lib/typescript/index.d.ts +4 -0
  82. package/lib/typescript/turbomodule/NativeNitroModules.d.ts +8 -0
  83. package/lib/typescript/turbomodule/NativeNitroModules.d.ts.map +1 -0
  84. package/lib/typescript/turbomodule/NativeNitroModules.web.d.ts +3 -0
  85. package/lib/typescript/turbomodule/NativeNitroModules.web.d.ts.map +1 -0
  86. package/package.json +10 -3
  87. package/src/BoxedHybridObject.ts +13 -0
  88. package/src/ModuleNotFoundError.ts +3 -19
  89. package/src/NitroModules.ts +2 -108
  90. package/src/NitroModulesProxy.ts +61 -0
  91. package/src/turbomodule/NativeNitroModules.ts +48 -0
  92. package/src/turbomodule/NativeNitroModules.web.ts +16 -0
  93. package/android/src/main/java/com/margelo/nitro/NitroModulesPackage.java +0 -30
  94. package/cpp/turbomodule/NativeNitroModules.cpp +0 -146
  95. package/cpp/turbomodule/NativeNitroModules.h +0 -8
  96. package/cpp/turbomodule/NativeNitroModules.hpp +0 -38
  97. package/cpp/turbomodule/RegisterNativeNitroModules.cpp +0 -33
  98. package/cpp/turbomodule/RegisterNativeNitroModules.hpp +0 -21
  99. package/ios/turbomodule/NitroModuleOnLoad.mm +0 -32
  100. package/lib/NativeNitroModules.d.ts +0 -16
  101. package/lib/NativeNitroModules.js +0 -22
  102. package/lib/NativeNitroModules.web.d.ts +0 -4
  103. package/lib/NativeNitroModules.web.js +0 -3
  104. package/lib/NitroModulesTurboModule.d.ts +0 -18
  105. package/lib/NitroModulesTurboModule.js +0 -23
  106. package/lib/NitroModulesTurboModule.web.d.ts +0 -1
  107. package/lib/commonjs/NitroModulesTurboModule.js +0 -34
  108. package/lib/commonjs/NitroModulesTurboModule.js.map +0 -1
  109. package/lib/commonjs/NitroModulesTurboModule.web.js +0 -11
  110. package/lib/commonjs/NitroModulesTurboModule.web.js.map +0 -1
  111. package/lib/module/NitroModulesTurboModule.js +0 -30
  112. package/lib/module/NitroModulesTurboModule.js.map +0 -1
  113. package/lib/module/NitroModulesTurboModule.web.js +0 -7
  114. package/lib/module/NitroModulesTurboModule.web.js.map +0 -1
  115. package/lib/typescript/NitroModulesTurboModule.d.ts +0 -19
  116. package/lib/typescript/NitroModulesTurboModule.d.ts.map +0 -1
  117. package/lib/typescript/NitroModulesTurboModule.web.d.ts +0 -2
  118. package/lib/typescript/NitroModulesTurboModule.web.d.ts.map +0 -1
  119. package/src/NitroModulesTurboModule.ts +0 -50
  120. package/src/NitroModulesTurboModule.web.ts +0 -7
@@ -1,94 +1,2 @@
1
- import { getNativeNitroModules } from './NitroModulesTurboModule';
2
- /**
3
- * A lazy proxy for initializing Nitro Modules HybridObjects.
4
- */
5
- export const NitroModules = {
6
- /**
7
- * Create a new instance of the `HybridObject` {@linkcode T}.
8
- *
9
- * {@linkcode T} has to be registered beforehand under the name {@linkcode name}
10
- * in the native Nitro Modules `HybridObjectRegistry`.
11
- *
12
- * @param name The name of the `HybridObject` under which it was registered at.
13
- * @returns An instance of {@linkcode T}
14
- * @throws an Error if {@linkcode T} has not been registered under the name {@linkcode name}.
15
- */
16
- createHybridObject(name) {
17
- const nitro = getNativeNitroModules();
18
- const instance = nitro.createHybridObject(name);
19
- return instance;
20
- },
21
- /**
22
- * Get a list of all registered Hybrid Objects.
23
- */
24
- getAllHybridObjectNames() {
25
- const nitro = getNativeNitroModules();
26
- return nitro.getAllHybridObjectNames();
27
- },
28
- /**
29
- * Returns whether a HybridObject under the given {@linkcode name} is registered, or not.
30
- */
31
- hasHybridObject(name) {
32
- const nitro = getNativeNitroModules();
33
- return nitro.hasHybridObject(name);
34
- },
35
- /**
36
- * Returns whether the given {@linkcode object} has a `NativeState` or not.
37
- *
38
- * This can be a quick way to check if an object is a valid {@linkcode HybridObject},
39
- * and has not yet been disposed.
40
- * @example
41
- * ```ts
42
- * const someObject = NitroModules.createHybridObject<Some>('Some')
43
- * console.log(NitroModules.hasNativeState(someObject)) // -> true
44
- * someObject.dispose()
45
- * console.log(NitroModules.hasNativeState(someObject)) // -> false
46
- * ```
47
- */
48
- hasNativeState(object) {
49
- const nitro = getNativeNitroModules();
50
- return nitro.hasNativeState(object);
51
- },
52
- /**
53
- * Forcefully removes the `NativeState` of the given {@linkcode object}.
54
- */
55
- removeNativeState(object) {
56
- const nitro = getNativeNitroModules();
57
- nitro.removeNativeState(object);
58
- },
59
- /**
60
- * Gets the current build type configuration as defined in the `NITRO_DEBUG`
61
- * preprocessor flag.
62
- */
63
- get buildType() {
64
- const nitro = getNativeNitroModules();
65
- return nitro.buildType;
66
- },
67
- /**
68
- * Boxes the given {@linkcode hybridObject} into a {@linkcode BoxedHybridObject<T>}, which can
69
- * later be unboxed in a separate Runtime.
70
- *
71
- * While Nitro is runtime-agnostic and all `HybridObject`s can be used from a any Runtime,
72
- * some threading/worklet libraries (like [react-native-worklets-core](https://github.com/margelo/react-native-worklets-core))
73
- * do not yet support copying over `HybridObject`s as they use newer JSI APIs like `jsi::NativeState`.
74
- *
75
- * While those APIs are not yet available, you can still use every Nitro Hybrid Object in a separate
76
- * Runtime/Worklet context by just boxing it yourself:
77
- *
78
- * @example
79
- * ```ts
80
- * const something = NitroModules.createHybridObject<Something>('Something')
81
- * const boxed = NitroModules.box(something)
82
- * const context = Worklets.createContext('DummyContext')
83
- * context.runAsync(() => {
84
- * 'worklet'
85
- * const unboxed = boxed.unbox()
86
- * console.log(unboxed.name) // --> "Something"
87
- * })
88
- * ```
89
- */
90
- box(hybridObject) {
91
- const nitro = getNativeNitroModules();
92
- return nitro.box(hybridObject);
93
- },
94
- };
1
+ // Re-exports the platform specific `NitroModulesProxy` (or a stub-implementation if not found)
2
+ export * from './turbomodule/NativeNitroModules';
@@ -0,0 +1,58 @@
1
+ import type { HybridObject } from './HybridObject';
2
+ import type { BoxedHybridObject } from './BoxedHybridObject';
3
+ /**
4
+ * The Proxy class that acts as a main entry point for Nitro Modules in React Native.
5
+ *
6
+ * This is a `HybridObject` on the native side as well, and is expected to be
7
+ * installed into the runtime's `global` via the NativeModule/TurboModule's `install()` function.
8
+ */
9
+ export interface NitroModulesProxy extends HybridObject {
10
+ /**
11
+ * Create a new instance of the `HybridObject` {@linkcode T}.
12
+ *
13
+ * {@linkcode T} has to be registered beforehand under the name {@linkcode name}
14
+ * in the native Nitro Modules `HybridObjectRegistry`.
15
+ *
16
+ * @param name The name of the `HybridObject` under which it was registered at.
17
+ * @returns An instance of {@linkcode T}
18
+ * @throws an Error if {@linkcode T} has not been registered under the name {@linkcode name}.
19
+ */
20
+ createHybridObject<T extends HybridObject>(name: string): T;
21
+ /**
22
+ * Returns whether a HybridObject under the given {@linkcode name} is registered, or not.
23
+ */
24
+ hasHybridObject(name: string): boolean;
25
+ /**
26
+ * Get a list of all registered Hybrid Objects.
27
+ */
28
+ getAllHybridObjectNames(): string[];
29
+ /**
30
+ * Gets the current build type configuration as defined in the `NITRO_DEBUG`
31
+ * preprocessor flag.
32
+ */
33
+ buildType: 'debug' | 'release';
34
+ /**
35
+ * Boxes the given {@linkcode hybridObject} into a {@linkcode BoxedHybridObject<T>}, which can
36
+ * later be unboxed in a separate Runtime.
37
+ *
38
+ * While Nitro is runtime-agnostic and all `HybridObject`s can be used from a any Runtime,
39
+ * some threading/worklet libraries (like [react-native-worklets-core](https://github.com/margelo/react-native-worklets-core))
40
+ * do not yet support copying over `HybridObject`s as they use newer JSI APIs like `jsi::NativeState`.
41
+ *
42
+ * While those APIs are not yet available, you can still use every Nitro Hybrid Object in a separate
43
+ * Runtime/Worklet context by just boxing it yourself:
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * const something = NitroModules.createHybridObject<Something>('Something')
48
+ * const boxed = NitroModules.box(something)
49
+ * const context = Worklets.createContext('DummyContext')
50
+ * context.runAsync(() => {
51
+ * 'worklet'
52
+ * const unboxed = boxed.unbox()
53
+ * console.log(unboxed.name) // --> "Something"
54
+ * })
55
+ * ```
56
+ */
57
+ box<T extends HybridObject>(obj: T): BoxedHybridObject<T>;
58
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=BoxedHybridObject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["BoxedHybridObject.ts"],"mappings":"","ignoreList":[]}
@@ -25,28 +25,16 @@ function getFrameworkType() {
25
25
  }
26
26
  class ModuleNotFoundError extends Error {
27
27
  constructor(cause) {
28
- // TurboModule not found, something went wrong!
29
- if (global.__turboModuleProxy == null) {
30
- // TurboModules are not available/new arch is not enabled.
31
- const message = 'Failed to get NitroModules: NitroModules require the new architecture to be enabled!';
32
- const suggestions = [];
33
- suggestions.push('Enable the new architecture in your app to use NitroModules. (See https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-apps.md)');
34
- const error = messageWithSuggestions(message, suggestions);
35
- super(error, {
36
- cause: cause
37
- });
38
- return;
39
- }
40
28
  const framework = getFrameworkType();
41
29
  if (framework === 'expo-go') {
42
30
  super('NitroModules are not supported in Expo Go! Use EAS (`expo prebuild`) or eject to a bare workflow instead.');
43
31
  return;
44
32
  }
45
- const message = 'Failed to get NitroModules: The native "NitroModules" TurboModule could not be found.';
33
+ const message = 'Failed to get NitroModules: The native "NitroModules" Turbo/Native-Module could not be found.';
46
34
  const suggestions = [];
47
35
  suggestions.push('Make sure react-native-nitro-modules/NitroModules is correctly autolinked (run `npx react-native config` to verify)');
48
- suggestions.push('Make sure you enabled the new architecture (TurboModules) and CodeGen properly generated the "NativeNitroModules"/NitroModulesCxx specs. See https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-apps.md');
49
- suggestions.push('Make sure you are using react-native 0.74.0 or higher, because NitroModules are built with C++ TurboModules.');
36
+ suggestions.push('Make sure you enabled the new architecture (TurboModules) and CodeGen properly generated the "NativeNitroModules"/NitroModules specs. See https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-apps.md');
37
+ suggestions.push('Make sure you are using react-native 0.75.0 or higher.');
50
38
  suggestions.push('Make sure you rebuilt the app.');
51
39
  if (framework === 'expo') {
52
40
  suggestions.push('Make sure you ran `expo prebuild`.');
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNative","require","BULLET_POINT","messageWithSuggestions","message","suggestions","join","getFrameworkType","ExpoConstants","NativeModules","NativeUnimoduleProxy","modulesConstants","ExponentConstants","appOwnership","ModuleNotFoundError","Error","constructor","cause","global","__turboModuleProxy","push","error","framework","Platform","OS","exports"],"sourceRoot":"../../src","sources":["ModuleNotFoundError.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAOA,MAAMC,YAAY,GAAG,MAAM;AAE3B,SAASC,sBAAsBA,CAC7BC,OAAe,EACfC,WAAqB,EACb;EACR,OAAOD,OAAO,GAAGF,YAAY,GAAGG,WAAW,CAACC,IAAI,CAACJ,YAAY,CAAC;AAChE;AAEA,SAASK,gBAAgBA,CAAA,EAAwC;EAC/D;EACA,MAAMC,aAAa,GACjBC,0BA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AC,6BAA6B,CAAC;QAC/C;MACF;QACE,MAAM,IAAIL,KAAK,CAAC,yCAAyCQ,qBAAQ,CAACC,EAAE,GAAG,CAAC;IAC5E;IAEA,MAAMH,KAAK,GAAGlB,sBAAsB,CAACC,OAAO,EAAEC,WAAW,CAAC;IAC1D,KAAK,CAACgB,KAAK,EAAE;MAAEJ,KAAK,EAAEA;IAAM,CAAC,CAAC;EAChC;AACF;AAACQ,OAAA,CAAAX,mBAAA,GAAAA,mBAAA","ignoreList":[]}
1
+ {"version":3,"names":["_reactNative","require","BULLET_POINT","messageWithSuggestions","message","suggestions","join","getFrameworkType","ExpoConstants","NativeModules","NativeUnimoduleProxy","modulesConstants","ExponentConstants","appOwnership","ModuleNotFoundError","Error","constructor","cause","framework","push","Platform","OS","error","exports"],"sourceRoot":"../../src","sources":["ModuleNotFoundError.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAOA,MAAMC,YAAY,GAAG,MAAM;AAE3B,SAASC,sBAAsBA,CAC7BC,OAAe,EACfC,WAAqB,EACb;EACR,OAAOD,OAAO,GAAGF,YAAY,GAAGG,WAAW,CAACC,IAAI,CAACJ,YAAY,CAAC;AAChE;AAEA,SAASK,gBAAgBA,CAAA,EAAwC;EAC/D;EACA,MAAMC,aAAa,GACjBC,0BAAa,CAACC,oBAAoB,EAAEC,gBAAgB,EAAEC,iBAAiB;EACzE,IAAIJ,aAAa,IAAI,IAAI,EAAE;IACzB,IAAIA,aAAa,CAACK,YAAY,KAAK,MAAM,EAAE;MACzC;MACA,OAAO,SAAS;IAClB,CAAC,MAAM;MACL;MACA,OAAO,MAAM;IACf;EACF;EACA,OAAO,cAAc;AACvB;AAEO,MAAMC,mBAAmB,SAASC,KAAK,CAAC;EAC7CC,WAAWA,CAACC,KAAe,EAAE;IAC3B,MAAMC,SAAS,GAAGX,gBAAgB,CAAC,CAAC;IACpC,IAAIW,SAAS,KAAK,SAAS,EAAE;MAC3B,KAAK,CACH,2GACF,CAAC;MACD;IACF;IAEA,MAAMd,OAAO,GACX,+FAA+F;IACjG,MAAMC,WAAqB,GAAG,EAAE;IAChCA,WAAW,CAACc,IAAI,CACd,qHACF,CAAC;IACDd,WAAW,CAACc,IAAI,CACd,kOACF,CAAC;IACDd,WAAW,CAACc,IAAI,CAAC,wDAAwD,CAAC;IAC1Ed,WAAW,CAACc,IAAI,CAAC,gCAAgC,CAAC;IAClD,IAAID,SAAS,KAAK,MAAM,EAAE;MACxBb,WAAW,CAACc,IAAI,CAAC,oCAAoC,CAAC;IACxD;IACA,QAAQC,qBAAQ,CAACC,EAAE;MACjB,KAAK,KAAK;MACV,KAAK,OAAO;QACVhB,WAAW,CAACc,IAAI,CACd,wDACF,CAAC;QACD;MACF,KAAK,SAAS;QACZd,WAAW,CAACc,IAAI,CAAC,6BAA6B,CAAC;QAC/C;MACF;QACE,MAAM,IAAIJ,KAAK,CAAC,yCAAyCK,qBAAQ,CAACC,EAAE,GAAG,CAAC;IAC5E;IAEA,MAAMC,KAAK,GAAGnB,sBAAsB,CAACC,OAAO,EAAEC,WAAW,CAAC;IAC1D,KAAK,CAACiB,KAAK,EAAE;MAAEL,KAAK,EAAEA;IAAM,CAAC,CAAC;EAChC;AACF;AAACM,OAAA,CAAAT,mBAAA,GAAAA,mBAAA","ignoreList":[]}
@@ -3,104 +3,15 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.NitroModules = void 0;
7
- var _NitroModulesTurboModule = require("./NitroModulesTurboModule");
8
- /**
9
- * Represents a boxed {@linkcode HybridObject} that can later be unboxed again.
10
- * This is implemented as a `jsi::HostObject`.
11
- */
12
-
13
- /**
14
- * A lazy proxy for initializing Nitro Modules HybridObjects.
15
- */
16
- const NitroModules = exports.NitroModules = {
17
- /**
18
- * Create a new instance of the `HybridObject` {@linkcode T}.
19
- *
20
- * {@linkcode T} has to be registered beforehand under the name {@linkcode name}
21
- * in the native Nitro Modules `HybridObjectRegistry`.
22
- *
23
- * @param name The name of the `HybridObject` under which it was registered at.
24
- * @returns An instance of {@linkcode T}
25
- * @throws an Error if {@linkcode T} has not been registered under the name {@linkcode name}.
26
- */
27
- createHybridObject(name) {
28
- const nitro = (0, _NitroModulesTurboModule.getNativeNitroModules)();
29
- const instance = nitro.createHybridObject(name);
30
- return instance;
31
- },
32
- /**
33
- * Get a list of all registered Hybrid Objects.
34
- */
35
- getAllHybridObjectNames() {
36
- const nitro = (0, _NitroModulesTurboModule.getNativeNitroModules)();
37
- return nitro.getAllHybridObjectNames();
38
- },
39
- /**
40
- * Returns whether a HybridObject under the given {@linkcode name} is registered, or not.
41
- */
42
- hasHybridObject(name) {
43
- const nitro = (0, _NitroModulesTurboModule.getNativeNitroModules)();
44
- return nitro.hasHybridObject(name);
45
- },
46
- /**
47
- * Returns whether the given {@linkcode object} has a `NativeState` or not.
48
- *
49
- * This can be a quick way to check if an object is a valid {@linkcode HybridObject},
50
- * and has not yet been disposed.
51
- * @example
52
- * ```ts
53
- * const someObject = NitroModules.createHybridObject<Some>('Some')
54
- * console.log(NitroModules.hasNativeState(someObject)) // -> true
55
- * someObject.dispose()
56
- * console.log(NitroModules.hasNativeState(someObject)) // -> false
57
- * ```
58
- */
59
- hasNativeState(object) {
60
- const nitro = (0, _NitroModulesTurboModule.getNativeNitroModules)();
61
- return nitro.hasNativeState(object);
62
- },
63
- /**
64
- * Forcefully removes the `NativeState` of the given {@linkcode object}.
65
- */
66
- removeNativeState(object) {
67
- const nitro = (0, _NitroModulesTurboModule.getNativeNitroModules)();
68
- nitro.removeNativeState(object);
69
- },
70
- /**
71
- * Gets the current build type configuration as defined in the `NITRO_DEBUG`
72
- * preprocessor flag.
73
- */
74
- get buildType() {
75
- const nitro = (0, _NitroModulesTurboModule.getNativeNitroModules)();
76
- return nitro.buildType;
77
- },
78
- /**
79
- * Boxes the given {@linkcode hybridObject} into a {@linkcode BoxedHybridObject<T>}, which can
80
- * later be unboxed in a separate Runtime.
81
- *
82
- * While Nitro is runtime-agnostic and all `HybridObject`s can be used from a any Runtime,
83
- * some threading/worklet libraries (like [react-native-worklets-core](https://github.com/margelo/react-native-worklets-core))
84
- * do not yet support copying over `HybridObject`s as they use newer JSI APIs like `jsi::NativeState`.
85
- *
86
- * While those APIs are not yet available, you can still use every Nitro Hybrid Object in a separate
87
- * Runtime/Worklet context by just boxing it yourself:
88
- *
89
- * @example
90
- * ```ts
91
- * const something = NitroModules.createHybridObject<Something>('Something')
92
- * const boxed = NitroModules.box(something)
93
- * const context = Worklets.createContext('DummyContext')
94
- * context.runAsync(() => {
95
- * 'worklet'
96
- * const unboxed = boxed.unbox()
97
- * console.log(unboxed.name) // --> "Something"
98
- * })
99
- * ```
100
- */
101
- box(hybridObject) {
102
- const nitro = (0, _NitroModulesTurboModule.getNativeNitroModules)();
103
- return nitro.box(hybridObject);
104
- }
105
- };
6
+ var _NativeNitroModules = require("./turbomodule/NativeNitroModules");
7
+ Object.keys(_NativeNitroModules).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _NativeNitroModules[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _NativeNitroModules[key];
14
+ }
15
+ });
16
+ });
106
17
  //# sourceMappingURL=NitroModules.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_NitroModulesTurboModule","require","NitroModules","exports","createHybridObject","name","nitro","getNativeNitroModules","instance","getAllHybridObjectNames","hasHybridObject","hasNativeState","object","removeNativeState","buildType","box","hybridObject"],"sourceRoot":"../../src","sources":["NitroModules.ts"],"mappings":";;;;;;AAAA,IAAAA,wBAAA,GAAAC,OAAA;AAGA;AACA;AACA;AACA;;AASA;AACA;AACA;AACO,MAAMC,YAAY,GAAAC,OAAA,CAAAD,YAAA,GAAG;EAC1B;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEE,kBAAkBA,CAA8BC,IAAY,EAAK;IAC/D,MAAMC,KAAK,GAAG,IAAAC,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"version":3,"names":["_NativeNitroModules","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sourceRoot":"../../src","sources":["NitroModules.ts"],"mappings":";;;;;AACA,IAAAA,mBAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,mBAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,mBAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,mBAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=NitroModulesProxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["NitroModulesProxy.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.NitroModules = void 0;
7
+ exports.isRuntimeAlive = isRuntimeAlive;
8
+ var _reactNative = require("react-native");
9
+ var _ModuleNotFoundError = require("../ModuleNotFoundError");
10
+ // 1. Get (and initialize) the TurboModule
11
+ let turboModule;
12
+ try {
13
+ turboModule = _reactNative.TurboModuleRegistry.getEnforcing('NitroModules');
14
+ } catch (e) {
15
+ throw new _ModuleNotFoundError.ModuleNotFoundError(e);
16
+ }
17
+
18
+ // 2. Install Dispatcher and install `NitroModulesProxy` into the Runtime's `global`
19
+ const errorMessage = turboModule.install();
20
+ if (errorMessage != null) {
21
+ throw new Error(`Failed to install Nitro: ${errorMessage}`);
22
+ }
23
+
24
+ // 3. Find `NitroModulesProxy` in `global`
25
+ // @ts-expect-error
26
+ const NitroModules = exports.NitroModules = global.NitroModulesProxy;
27
+ if (NitroModules == null) {
28
+ const cause = new Error('NitroModules was installed, but `global.NitroModulesProxy` was null!');
29
+ throw new _ModuleNotFoundError.ModuleNotFoundError(cause);
30
+ }
31
+ function isRuntimeAlive() {
32
+ const cache = global.__nitroModulesJSICache;
33
+ const dispatcher = global.__nitroDispatcher;
34
+ return cache != null && dispatcher != null;
35
+ }
36
+ //# sourceMappingURL=NativeNitroModules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNative","require","_ModuleNotFoundError","turboModule","TurboModuleRegistry","getEnforcing","e","ModuleNotFoundError","errorMessage","install","Error","NitroModules","exports","global","NitroModulesProxy","cause","isRuntimeAlive","cache","__nitroModulesJSICache","dispatcher","__nitroDispatcher"],"sourceRoot":"../../../src","sources":["turbomodule/NativeNitroModules.ts"],"mappings":";;;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,oBAAA,GAAAD,OAAA;AAYA;AACA,IAAIE,WAA6B;AACjC,IAAI;EACFA,WAAW,GAAGC,gCAAmB,CAACC,YAAY,CAAO,cAAc,CAAC;AACtE,CAAC,CAAC,OAAOC,CAAC,EAAE;EACV,MAAM,IAAIC,wCAAmB,CAACD,CAAC,CAAC;AAClC;;AAEA;AACA,MAAME,YAAY,GAAGL,WAAW,CAACM,OAAO,CAAC,CAAC;AAC1C,IAAID,YAAY,IAAI,IAAI,EAAE;EACxB,MAAM,IAAIE,KAAK,CAAC,4BAA4BF,YAAY,EAAE,CAAC;AAC7D;;AAEA;AACA;AACO,MAAMG,YAAY,GAAAC,OAAA,CAAAD,YAAA,GAAGE,MAAM,CAACC,iBAAsC;AACzE,IAAIH,YAAY,IAAI,IAAI,EAAE;EACxB,MAAMI,KAAK,GAAG,IAAIL,KAAK,CACrB,sEACF,CAAC;EACD,MAAM,IAAIH,wCAAmB,CAACQ,KAAK,CAAC;AACtC;AAOO,SAASC,cAAcA,CAAA,EAAG;EAC/B,MAAMC,KAAK,GAAGJ,MAAM,CAACK,sBAAsB;EAC3C,MAAMC,UAAU,GAAGN,MAAM,CAACO,iBAAiB;EAC3C,OAAOH,KAAK,IAAI,IAAI,IAAIE,UAAU,IAAI,IAAI;AAC5C","ignoreList":[]}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.NitroModules = void 0;
7
+ exports.isRuntimeAlive = isRuntimeAlive;
8
+ var _reactNative = require("react-native");
9
+ const NitroModules = exports.NitroModules = new Proxy({}, {
10
+ get: () => {
11
+ throw new Error(`Native NitroModules are not available on ${_reactNative.Platform.OS}! Make sure you're not calling getNativeNitroModules() in a ${_reactNative.Platform.OS} (.${_reactNative.Platform.OS}.ts) environment.`);
12
+ }
13
+ });
14
+ function isRuntimeAlive() {
15
+ return false;
16
+ }
17
+ //# sourceMappingURL=NativeNitroModules.web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNative","require","NitroModules","exports","Proxy","get","Error","Platform","OS","isRuntimeAlive"],"sourceRoot":"../../../src","sources":["turbomodule/NativeNitroModules.web.ts"],"mappings":";;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEO,MAAMC,YAAY,GAAAC,OAAA,CAAAD,YAAA,GAAG,IAAIE,KAAK,CACnC,CAAC,CAAC,EACF;EACEC,GAAG,EAAEA,CAAA,KAAM;IACT,MAAM,IAAIC,KAAK,CACb,4CAA4CC,qBAAQ,CAACC,EAAE,+DAA+DD,qBAAQ,CAACC,EAAE,MAAMD,qBAAQ,CAACC,EAAE,mBACpJ,CAAC;EACH;AACF,CACF,CAAC;AAEM,SAASC,cAAcA,CAAA,EAAY;EACxC,OAAO,KAAK;AACd","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ export {};
4
+ //# sourceMappingURL=BoxedHybridObject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["BoxedHybridObject.ts"],"mappings":"","ignoreList":[]}
@@ -21,28 +21,16 @@ function getFrameworkType() {
21
21
  }
22
22
  export class ModuleNotFoundError extends Error {
23
23
  constructor(cause) {
24
- // TurboModule not found, something went wrong!
25
- if (global.__turboModuleProxy == null) {
26
- // TurboModules are not available/new arch is not enabled.
27
- const message = 'Failed to get NitroModules: NitroModules require the new architecture to be enabled!';
28
- const suggestions = [];
29
- suggestions.push('Enable the new architecture in your app to use NitroModules. (See https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-apps.md)');
30
- const error = messageWithSuggestions(message, suggestions);
31
- super(error, {
32
- cause: cause
33
- });
34
- return;
35
- }
36
24
  const framework = getFrameworkType();
37
25
  if (framework === 'expo-go') {
38
26
  super('NitroModules are not supported in Expo Go! Use EAS (`expo prebuild`) or eject to a bare workflow instead.');
39
27
  return;
40
28
  }
41
- const message = 'Failed to get NitroModules: The native "NitroModules" TurboModule could not be found.';
29
+ const message = 'Failed to get NitroModules: The native "NitroModules" Turbo/Native-Module could not be found.';
42
30
  const suggestions = [];
43
31
  suggestions.push('Make sure react-native-nitro-modules/NitroModules is correctly autolinked (run `npx react-native config` to verify)');
44
- suggestions.push('Make sure you enabled the new architecture (TurboModules) and CodeGen properly generated the "NativeNitroModules"/NitroModulesCxx specs. See https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-apps.md');
45
- suggestions.push('Make sure you are using react-native 0.74.0 or higher, because NitroModules are built with C++ TurboModules.');
32
+ suggestions.push('Make sure you enabled the new architecture (TurboModules) and CodeGen properly generated the "NativeNitroModules"/NitroModules specs. See https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-apps.md');
33
+ suggestions.push('Make sure you are using react-native 0.75.0 or higher.');
46
34
  suggestions.push('Make sure you rebuilt the app.');
47
35
  if (framework === 'expo') {
48
36
  suggestions.push('Make sure you ran `expo prebuild`.');
@@ -1 +1 @@
1
- {"version":3,"names":["NativeModules","Platform","BULLET_POINT","messageWithSuggestions","message","suggestions","join","getFrameworkType","ExpoConstants","NativeUnimoduleProxy","modulesConstants","ExponentConstants","appOwnership","ModuleNotFoundError","Error","constructor","cause","global","__turboModuleProxy","push","error","framework","OS"],"sourceRoot":"../../src","sources":["ModuleNotFoundError.ts"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAOtD,MAAMC,YAAY,GAAG,MAAM;AAE3B,SAASC,sBAAsBA,CAC7BC,OAAe,EACfC,WAAqB,EACb;EACR,OAAOD,OAAO,GAAGF,YAAY,GAAGG,WAAW,CAACC,IAAI,CAACJ,YAAY,CAAC;AAChE;AAEA,SAASK,gBAAgBA,CAAA,EAAwC;EAC/D;EACA,MAAMC,aAAa,GACjBR,aAAa,CAACS,oBAAoB,EAAEC,gBAAgB,EAAEC,iBAAiB;EACzE,IAAIH,aAAa,IAAI,IAAI,EAAE;IACzB,IAAIA,aAAa,CAACI,YAAY,KAAK,MAAM,EAAE;MACzC;MACA,OAAO,SAAS;IAClB,CAAC,MAAM;MACL;MACA,OAAO,MAAM;IACf;EACF;EACA,OAAO,cAAc;AACvB;AAEA,OAAO,MAAMC,mBAAmB,SAASC,KAAK,CAAC;EAC7CC,WAAWA,CAACC,KAAe,EAAE;IAC3B;IACA,IAAIC,MAAM,CAACC,kBAAkB,IAAI,IAAI,EAAE;MACrC;MACA,MAAMd,OAAO,GACX,sFAAsF;MACxF,MAAMC,WAAqB,GAAG,EAAE;MAChCA,WAAW,CAACc,IAAI,CACd,2JACF,CAAC;MACD,MAAMC,KAAK,GAAGjB,sBAAsB,CAACC,OAAO,EAAEC,WAAW,CAAC;MAC1D,KAAK,CAACe,KAAK,EAAE;QAAEJ,KAAK,EAAEA;MAAM,CAAC,CAAC;MAC9B;IACF;IAEA,MAAMK,SAAS,GAAGd,gBAAgB,CAAC,CAAC;IACpC,IAAIc,SAAS,KAAK,SAAS,EAAE;MAC3B,KAAK,CACH,2GACF,CAAC;MACD;IACF;IAEA,MAAMjB,OAAO,GACX,uFAAuF;IACzF,MAAMC,WAAqB,GAAG,EAAE;IAChCA,WAAW,CAACc,IAAI,CACd,qHACF,CAAC;IACDd,WAAW,CAACc,IAAI,CACd,qOACF,CAAC;IACDd,WAAW,CAACc,IAAI,CACd,8GACF,CAAC;IACDd,WAAW,CAACc,IAAI,CAAC,gCAAgC,CAAC;IAClD,IAAIE,SAAS,KAAK,MAAM,EAAE;MACxBhB,WAAW,CAACc,IAAI,CAAC,oCAAoC,CAAC;IACxD;IACA,QAAQlB,QAAQ,CAACqB,EAAE;MACjB,KAAK,KAAK;MACV,KAAK,OAAO;QACVjB,WAAW,CAACc,IAAI,CACd,wDACF,CAAC;QACD;MACF,KAAK,SAAS;QACZd,WAAW,CAACc,IAAI,CAAC,6BAA6B,CAAC;QAC/C;MACF;QACE,MAAM,IAAIL,KAAK,CAAC,yCAAyCb,QAAQ,CAACqB,EAAE,GAAG,CAAC;IAC5E;IAEA,MAAMF,KAAK,GAAGjB,sBAAsB,CAACC,OAAO,EAAEC,WAAW,CAAC;IAC1D,KAAK,CAACe,KAAK,EAAE;MAAEJ,KAAK,EAAEA;IAAM,CAAC,CAAC;EAChC;AACF","ignoreList":[]}
1
+ {"version":3,"names":["NativeModules","Platform","BULLET_POINT","messageWithSuggestions","message","suggestions","join","getFrameworkType","ExpoConstants","NativeUnimoduleProxy","modulesConstants","ExponentConstants","appOwnership","ModuleNotFoundError","Error","constructor","cause","framework","push","OS","error"],"sourceRoot":"../../src","sources":["ModuleNotFoundError.ts"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAOtD,MAAMC,YAAY,GAAG,MAAM;AAE3B,SAASC,sBAAsBA,CAC7BC,OAAe,EACfC,WAAqB,EACb;EACR,OAAOD,OAAO,GAAGF,YAAY,GAAGG,WAAW,CAACC,IAAI,CAACJ,YAAY,CAAC;AAChE;AAEA,SAASK,gBAAgBA,CAAA,EAAwC;EAC/D;EACA,MAAMC,aAAa,GACjBR,aAAa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3
- import { getNativeNitroModules } from './NitroModulesTurboModule';
4
-
5
- /**
6
- * Represents a boxed {@linkcode HybridObject} that can later be unboxed again.
7
- * This is implemented as a `jsi::HostObject`.
8
- */
9
-
10
- /**
11
- * A lazy proxy for initializing Nitro Modules HybridObjects.
12
- */
13
- export const NitroModules = {
14
- /**
15
- * Create a new instance of the `HybridObject` {@linkcode T}.
16
- *
17
- * {@linkcode T} has to be registered beforehand under the name {@linkcode name}
18
- * in the native Nitro Modules `HybridObjectRegistry`.
19
- *
20
- * @param name The name of the `HybridObject` under which it was registered at.
21
- * @returns An instance of {@linkcode T}
22
- * @throws an Error if {@linkcode T} has not been registered under the name {@linkcode name}.
23
- */
24
- createHybridObject(name) {
25
- const nitro = getNativeNitroModules();
26
- const instance = nitro.createHybridObject(name);
27
- return instance;
28
- },
29
- /**
30
- * Get a list of all registered Hybrid Objects.
31
- */
32
- getAllHybridObjectNames() {
33
- const nitro = getNativeNitroModules();
34
- return nitro.getAllHybridObjectNames();
35
- },
36
- /**
37
- * Returns whether a HybridObject under the given {@linkcode name} is registered, or not.
38
- */
39
- hasHybridObject(name) {
40
- const nitro = getNativeNitroModules();
41
- return nitro.hasHybridObject(name);
42
- },
43
- /**
44
- * Returns whether the given {@linkcode object} has a `NativeState` or not.
45
- *
46
- * This can be a quick way to check if an object is a valid {@linkcode HybridObject},
47
- * and has not yet been disposed.
48
- * @example
49
- * ```ts
50
- * const someObject = NitroModules.createHybridObject<Some>('Some')
51
- * console.log(NitroModules.hasNativeState(someObject)) // -> true
52
- * someObject.dispose()
53
- * console.log(NitroModules.hasNativeState(someObject)) // -> false
54
- * ```
55
- */
56
- hasNativeState(object) {
57
- const nitro = getNativeNitroModules();
58
- return nitro.hasNativeState(object);
59
- },
60
- /**
61
- * Forcefully removes the `NativeState` of the given {@linkcode object}.
62
- */
63
- removeNativeState(object) {
64
- const nitro = getNativeNitroModules();
65
- nitro.removeNativeState(object);
66
- },
67
- /**
68
- * Gets the current build type configuration as defined in the `NITRO_DEBUG`
69
- * preprocessor flag.
70
- */
71
- get buildType() {
72
- const nitro = getNativeNitroModules();
73
- return nitro.buildType;
74
- },
75
- /**
76
- * Boxes the given {@linkcode hybridObject} into a {@linkcode BoxedHybridObject<T>}, which can
77
- * later be unboxed in a separate Runtime.
78
- *
79
- * While Nitro is runtime-agnostic and all `HybridObject`s can be used from a any Runtime,
80
- * some threading/worklet libraries (like [react-native-worklets-core](https://github.com/margelo/react-native-worklets-core))
81
- * do not yet support copying over `HybridObject`s as they use newer JSI APIs like `jsi::NativeState`.
82
- *
83
- * While those APIs are not yet available, you can still use every Nitro Hybrid Object in a separate
84
- * Runtime/Worklet context by just boxing it yourself:
85
- *
86
- * @example
87
- * ```ts
88
- * const something = NitroModules.createHybridObject<Something>('Something')
89
- * const boxed = NitroModules.box(something)
90
- * const context = Worklets.createContext('DummyContext')
91
- * context.runAsync(() => {
92
- * 'worklet'
93
- * const unboxed = boxed.unbox()
94
- * console.log(unboxed.name) // --> "Something"
95
- * })
96
- * ```
97
- */
98
- box(hybridObject) {
99
- const nitro = getNativeNitroModules();
100
- return nitro.box(hybridObject);
101
- }
102
- };
3
+ // Re-exports the platform specific `NitroModulesProxy` (or a stub-implementation if not found)
4
+ export * from './turbomodule/NativeNitroModules';
103
5
  //# sourceMappingURL=NitroModules.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["getNativeNitroModules","NitroModules","createHybridObject","name","nitro","instance","getAllHybridObjectNames","hasHybridObject","hasNativeState","object","removeNativeState","buildType","box","hybridObject"],"sourceRoot":"../../src","sources":["NitroModules.ts"],"mappings":";;AAAA,SAASA,qBAAqB,QAAQ,2BAA2B;;AAGjE;AACA;AACA;AACA;;AASA;AACA;AACA;AACA,OAAO,MAAMC,YAAY,GAAG;EAC1B;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,kBAAkBA,CAA8BC,IAAY,EAAK;IAC/D,MAAMC,KAAK,GAAGJ,qBAAqB,CAAC,CAAC;IACrC,MAAMK,QAAQ,GAAGD,KAAK,CAACF,kBAAkB,CAACC,IAAI,CAAC;IAC/C,OAAOE,QAAQ;EACjB,CAAC;EACD;AACF;AACA;EACEC,uBAAuBA,CAAA,EAAa;IAClC,MAAMF,KAAK,GAAGJ,qBAAqB,CAAC,CAAC;IACrC,OAAOI,KAAK,CAACE,uBAAuB,CAAC,CAAC;EACxC,CAAC;EACD;AACF;AACA;EACEC,eAAeA,CAACJ,IAAY,EAAW;IACrC,MAAMC,KAAK,GAAGJ,qBAAqB,CAAC,CAAC;IACrC,OAAOI,KAAK,CAACG,eAAe,CAACJ,IAAI,CAAC;EACpC,CAAC;EACD;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEK,cAAcA,CAACC,MAAc,EAAW;IACtC,MAAML,KAAK,GAAGJ,qBAAqB,CAAC,CAAC;IACrC,OAAOI,KAAK,CAACI,cAAc,CAACC,MAAM,CAAC;EACrC,CAAC;EACD;AACF;AACA;EACEC,iBAAiBA,CAACD,MAAc,EAAQ;IACtC,MAAML,KAAK,GAAGJ,qBAAqB,CAAC,CAAC;IACrCI,KAAK,CAACM,iBAAiB,CAACD,MAAM,CAAC;EACjC,CAAC;EACD;AACF;AACA;AACA;EACE,IAAIE,SAASA,CAAA,EAAwB;IACnC,MAAMP,KAAK,GAAGJ,qBAAqB,CAAC,CAAC;IACrC,OAAOI,KAAK,CAACO,SAAS;EACxB,CAAC;EACD;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,GAAGA,CAAyBC,YAAe,EAAwB;IACjE,MAAMT,KAAK,GAAGJ,qBAAqB,CAAC,CAAC;IACrC,OAAOI,KAAK,CAACQ,GAAG,CAACC,YAAY,CAAC;EAChC;AACF,CAAC","ignoreList":[]}
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["NitroModules.ts"],"mappings":";;AAAA;AACA,cAAc,kCAAkC","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ export {};
4
+ //# sourceMappingURL=NitroModulesProxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["NitroModulesProxy.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ import { TurboModuleRegistry } from 'react-native';
4
+ import { ModuleNotFoundError } from '../ModuleNotFoundError';
5
+ // 1. Get (and initialize) the TurboModule
6
+ let turboModule;
7
+ try {
8
+ turboModule = TurboModuleRegistry.getEnforcing('NitroModules');
9
+ } catch (e) {
10
+ throw new ModuleNotFoundError(e);
11
+ }
12
+
13
+ // 2. Install Dispatcher and install `NitroModulesProxy` into the Runtime's `global`
14
+ const errorMessage = turboModule.install();
15
+ if (errorMessage != null) {
16
+ throw new Error(`Failed to install Nitro: ${errorMessage}`);
17
+ }
18
+
19
+ // 3. Find `NitroModulesProxy` in `global`
20
+ // @ts-expect-error
21
+ export const NitroModules = global.NitroModulesProxy;
22
+ if (NitroModules == null) {
23
+ const cause = new Error('NitroModules was installed, but `global.NitroModulesProxy` was null!');
24
+ throw new ModuleNotFoundError(cause);
25
+ }
26
+ export function isRuntimeAlive() {
27
+ const cache = global.__nitroModulesJSICache;
28
+ const dispatcher = global.__nitroDispatcher;
29
+ return cache != null && dispatcher != null;
30
+ }
31
+ //# sourceMappingURL=NativeNitroModules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["TurboModuleRegistry","ModuleNotFoundError","turboModule","getEnforcing","e","errorMessage","install","Error","NitroModules","global","NitroModulesProxy","cause","isRuntimeAlive","cache","__nitroModulesJSICache","dispatcher","__nitroDispatcher"],"sourceRoot":"../../../src","sources":["turbomodule/NativeNitroModules.ts"],"mappings":";;AACA,SAASA,mBAAmB,QAAQ,cAAc;AAClD,SAASC,mBAAmB,QAAQ,wBAAwB;AAY5D;AACA,IAAIC,WAA6B;AACjC,IAAI;EACFA,WAAW,GAAGF,mBAAmB,CAACG,YAAY,CAAO,cAAc,CAAC;AACtE,CAAC,CAAC,OAAOC,CAAC,EAAE;EACV,MAAM,IAAIH,mBAAmB,CAACG,CAAC,CAAC;AAClC;;AAEA;AACA,MAAMC,YAAY,GAAGH,WAAW,CAACI,OAAO,CAAC,CAAC;AAC1C,IAAID,YAAY,IAAI,IAAI,EAAE;EACxB,MAAM,IAAIE,KAAK,CAAC,4BAA4BF,YAAY,EAAE,CAAC;AAC7D;;AAEA;AACA;AACA,OAAO,MAAMG,YAAY,GAAGC,MAAM,CAACC,iBAAsC;AACzE,IAAIF,YAAY,IAAI,IAAI,EAAE;EACxB,MAAMG,KAAK,GAAG,IAAIJ,KAAK,CACrB,sEACF,CAAC;EACD,MAAM,IAAIN,mBAAmB,CAACU,KAAK,CAAC;AACtC;AAOA,OAAO,SAASC,cAAcA,CAAA,EAAG;EAC/B,MAAMC,KAAK,GAAGJ,MAAM,CAACK,sBAAsB;EAC3C,MAAMC,UAAU,GAAGN,MAAM,CAACO,iBAAiB;EAC3C,OAAOH,KAAK,IAAI,IAAI,IAAIE,UAAU,IAAI,IAAI;AAC5C","ignoreList":[]}