@rngpui/craby-modules 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Geunhyeok LEE
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # craby-modules
2
+
3
+ TypeScript definitions and runtime for Craby modules
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install craby-modules
9
+ # or
10
+ pnpm add craby-modules
11
+ # or
12
+ yarn add craby-modules
13
+ ```
14
+
15
+ ## Example
16
+
17
+ ```ts
18
+ import type { NativeModule } from 'craby-modules';
19
+ import { NativeModuleRegistry } from 'craby-modules';
20
+
21
+ export interface Spec extends NativeModule {
22
+ add(a: number, b: number): number;
23
+ subtract(a: number, b: number): number;
24
+ multiply(a: number, b: number): number;
25
+ divide(a: number, b: number): number;
26
+ }
27
+
28
+ export default NativeModuleRegistry.getEnforcing<Spec>('Calculator');
29
+ ```
30
+
31
+ Visit [https://craby.rs](https://craby.rs) for full documentation.
32
+
33
+ ## License
34
+
35
+ [MIT](LICENSE)
@@ -0,0 +1,10 @@
1
+ //#region src/index.d.ts
2
+ type NativeModule = {};
3
+ type Signal<T = void> = (handler: (data: T) => void) => () => void;
4
+ interface NativeModuleRegistry {
5
+ get<T extends NativeModule>(moduleName: string): T | null;
6
+ getEnforcing<T extends NativeModule>(moduleName: string): T;
7
+ }
8
+ declare const NativeModuleRegistry: NativeModuleRegistry;
9
+ //#endregion
10
+ export { type NativeModule, NativeModuleRegistry, type Signal };
@@ -0,0 +1,10 @@
1
+ //#region src/index.d.ts
2
+ type NativeModule = {};
3
+ type Signal<T = void> = (handler: (data: T) => void) => () => void;
4
+ interface NativeModuleRegistry {
5
+ get<T extends NativeModule>(moduleName: string): T | null;
6
+ getEnforcing<T extends NativeModule>(moduleName: string): T;
7
+ }
8
+ declare const NativeModuleRegistry: NativeModuleRegistry;
9
+ //#endregion
10
+ export { type NativeModule, NativeModuleRegistry, type Signal };
package/dist/index.js ADDED
@@ -0,0 +1,35 @@
1
+ let react_native = require("react-native");
2
+
3
+ //#region src/index.ts
4
+ /**
5
+ * Android JNI initialization workaround
6
+ *
7
+ * We need `filesDir` of `Context` for JNI initialization, but it's unavailable during `PackageList` construction.
8
+ * The context is only passed when React Native calls `BaseReactPackage.getModule()`.
9
+ *
10
+ * Workaround: Load a dummy module to trigger `getModule()` before the actual module.
11
+ *
12
+ * - 1. Request non-existent module → triggers `getModule()`
13
+ * - 2. `getModule()` receives `ReactApplicationContext`
14
+ * - 2-1. Calls `nativeSetDataPath()` (C++ extern function) to set `context.filesDir.absolutePath`
15
+ * - 2-2. Returns placeholder module (no-op) instance (Actual C++ TurboModule is now can be initialized with the required values)
16
+ *
17
+ * @param moduleName The name of the module to prepare.
18
+ */
19
+ function prepareJNI(moduleName) {
20
+ if (react_native.Platform.OS !== "android") return;
21
+ react_native.TurboModuleRegistry.get(`__craby${moduleName}_JNI_prepare__`);
22
+ }
23
+ const NativeModuleRegistry = {
24
+ get(moduleName) {
25
+ prepareJNI(moduleName);
26
+ return react_native.TurboModuleRegistry.get(moduleName);
27
+ },
28
+ getEnforcing(moduleName) {
29
+ prepareJNI(moduleName);
30
+ return react_native.TurboModuleRegistry.getEnforcing(moduleName);
31
+ }
32
+ };
33
+
34
+ //#endregion
35
+ exports.NativeModuleRegistry = NativeModuleRegistry;
package/dist/index.mjs ADDED
@@ -0,0 +1,35 @@
1
+ import { Platform, TurboModuleRegistry } from "react-native";
2
+
3
+ //#region src/index.ts
4
+ /**
5
+ * Android JNI initialization workaround
6
+ *
7
+ * We need `filesDir` of `Context` for JNI initialization, but it's unavailable during `PackageList` construction.
8
+ * The context is only passed when React Native calls `BaseReactPackage.getModule()`.
9
+ *
10
+ * Workaround: Load a dummy module to trigger `getModule()` before the actual module.
11
+ *
12
+ * - 1. Request non-existent module → triggers `getModule()`
13
+ * - 2. `getModule()` receives `ReactApplicationContext`
14
+ * - 2-1. Calls `nativeSetDataPath()` (C++ extern function) to set `context.filesDir.absolutePath`
15
+ * - 2-2. Returns placeholder module (no-op) instance (Actual C++ TurboModule is now can be initialized with the required values)
16
+ *
17
+ * @param moduleName The name of the module to prepare.
18
+ */
19
+ function prepareJNI(moduleName) {
20
+ if (Platform.OS !== "android") return;
21
+ TurboModuleRegistry.get(`__craby${moduleName}_JNI_prepare__`);
22
+ }
23
+ const NativeModuleRegistry = {
24
+ get(moduleName) {
25
+ prepareJNI(moduleName);
26
+ return TurboModuleRegistry.get(moduleName);
27
+ },
28
+ getEnforcing(moduleName) {
29
+ prepareJNI(moduleName);
30
+ return TurboModuleRegistry.getEnforcing(moduleName);
31
+ }
32
+ };
33
+
34
+ //#endregion
35
+ export { NativeModuleRegistry };
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@rngpui/craby-modules",
3
+ "version": "0.1.0",
4
+ "description": "TypeScript definitions and runtime for Craby modules",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/index.d.mts",
12
+ "default": "./dist/index.mjs"
13
+ },
14
+ "require": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
+ }
18
+ }
19
+ },
20
+ "scripts": {
21
+ "prepack": "yarn build",
22
+ "typecheck": "tsc --noEmit",
23
+ "build": "tsdown"
24
+ },
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/rngpui/craby.git",
31
+ "directory": "packages/craby-modules"
32
+ },
33
+ "author": "leegeunhyeok <dev.ghlee@gmail.com> (https://github.com/leegeunhyeok)",
34
+ "license": "MIT",
35
+ "bugs": {
36
+ "url": "https://github.com/rngpui/craby/issues"
37
+ },
38
+ "homepage": "https://github.com/rngpui/craby#readme",
39
+ "devDependencies": {
40
+ "@arethetypeswrong/core": "^0.18.2",
41
+ "react": "^19.1.1",
42
+ "react-native": "^0.81.4",
43
+ "tsdown": "^0.17.0-beta.4",
44
+ "typescript": "^5.9.3"
45
+ },
46
+ "peerDependencies": {
47
+ "react-native": ">=0.76.0"
48
+ }
49
+ }