Skip to content

Commit 6d20d94

Browse files
authored
Merge pull request #1 from react-native-oh-library/dev
Add harmony support
2 parents 50e736b + be8a0ec commit 6d20d94

File tree

6 files changed

+204
-25
lines changed

6 files changed

+204
-25
lines changed

harmony/exception_handler.har

5.04 KB
Binary file not shown.

package.json

Lines changed: 63 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,84 @@
11
{
2-
"name": "react-native-exception-handler",
3-
"version": "2.10.10",
2+
"name": "@react-native-oh-tpl/react-native-exception-handler",
3+
"version": "2.10.10-0.0.2",
44
"description": "A react native module that lets you to register a global error handler that can capture fatal/non fatal uncaught exceptions.",
5-
"main": "index.js",
6-
"typings": "index.d.ts",
5+
"react-native": "src/index",
6+
"source": "src/index",
7+
"main": "lib/commonjs/index",
8+
"module": "lib/module/index",
9+
"typings": "lib/typescript/index.d.ts",
10+
"publishConfig": {
11+
"registry": "https://registry.npmjs.org/",
12+
"access": "public"
13+
},
14+
"files": [
15+
"src",
16+
"lib",
17+
"android",
18+
"!android/build",
19+
"ios",
20+
"!ios/build",
21+
"harmony/exception_handler.har",
22+
"!harmony/build",
23+
"!harmony/oh_modules",
24+
"dist",
25+
"ReactNativeExceptionHandler.podspec",
26+
"!**/__tests__",
27+
"!**/__fixtures__",
28+
"!**/__mocks__",
29+
"!**/.*"
30+
],
731
"scripts": {
8-
"test": "echo no tests && exit 1",
9-
"lint": "eslint app/",
10-
"lint:fix": "eslint app/ --fix"
32+
"bob": "bob build",
33+
"prepack": "bob build",
34+
"prepare": "npm run bob",
35+
"build": "dv-scripts build && cp src/index.js.flow dist/index.js.flow && cp src/index.js.flow dist/index.cjs.js.flow",
36+
"lint": "dv-scripts lint",
37+
"release": "dv-scripts release",
38+
"test": "dv-scripts test"
1139
},
1240
"repository": {
1341
"type": "git",
14-
"url": "git+https://github.com/a7ul/react-native-exception-handler"
42+
"url": "https://github.com/react-native-oh-library/react-native-exception-handler.git"
1543
},
1644
"keywords": [
17-
"modal",
1845
"react",
1946
"native",
2047
"exception",
21-
"handler",
22-
"red",
23-
"screen",
24-
"production",
25-
"ios",
26-
"android",
27-
"bug",
28-
"capture"
48+
"handler"
2949
],
30-
"peerDependencies": {
31-
"react": "*",
32-
"react-native": "*"
33-
},
3450
"author": "a7ul",
3551
"license": "MIT",
3652
"bugs": {
3753
"url": "https://github.com/a7ul/react-native-exception-handler/issues"
3854
},
3955
"homepage": "https://github.com/a7ul/react-native-exception-handler",
4056
"devDependencies": {
41-
"babel-eslint": "^7.2.3",
42-
"eslint": "^4.0.0",
43-
"eslint-plugin-react": "^7.1.0",
44-
"eslint-plugin-react-native": "^2.3.2"
57+
"@types/react": "^18.2.12",
58+
"react-native-builder-bob": "^0.20.4",
59+
"typescript": "^5.0.4"
60+
},
61+
"peerDependencies": {
62+
"react": "*",
63+
"react-native": "*"
64+
},
65+
"react-native-builder-bob": {
66+
"source": "src",
67+
"output": "lib",
68+
"targets": [
69+
"commonjs",
70+
"module",
71+
[
72+
"typescript",
73+
{
74+
"project": "tsconfig.build.json"
75+
}
76+
]
77+
]
78+
},
79+
"codegenConfig": {
80+
"name": "RNExceptionHandlerSpec",
81+
"type": "all",
82+
"jsSrcsDir": "src"
4583
}
4684
}

src/NativeExceptionHandler.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (C) 2023 Huawei Device Co., Ltd.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
import type { TurboModule } from "react-native/Libraries/TurboModule/RCTExport";
26+
import { TurboModuleRegistry } from 'react-native';
27+
28+
interface ExceptionHandlerTurboModuleProtocol {
29+
setHandlerforNativeException(
30+
handler: (errMsg: string) => void,
31+
forceAppQuit?: boolean,
32+
executeDefaultHandler?: boolean
33+
): void;
34+
}
35+
36+
interface Spec extends TurboModule, ExceptionHandlerTurboModuleProtocol {
37+
}
38+
39+
export default TurboModuleRegistry.getEnforcing<Spec>('ExceptionHandlerTurboModule')

src/index.tsx

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (C) 2023 Huawei Device Co., Ltd.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
import ExceptionHandlerTurboModule from './NativeExceptionHandler'
26+
import { Platform } from "react-native";
27+
28+
const noop = () => { };
29+
30+
export const setJSExceptionHandler = (handler = noop, allowedInDevMode = false) => {
31+
if (typeof allowedInDevMode !== "boolean" || typeof handler !== "function") {
32+
console.log("setJSExceptionHandler is called with wrong argument types.. first argument should be callback function and second argument is optional should be a boolean");
33+
console.log("Not setting the JS handler .. please fix setJSExceptionHandler call");
34+
return;
35+
}
36+
const allowed = allowedInDevMode ? true : !__DEV__;
37+
if (allowed) {
38+
ErrorUtils.setGlobalHandler(handler);
39+
const consoleError = console.error;
40+
console.error = (...args) => {
41+
consoleError(...args);
42+
};
43+
} else {
44+
console.log("Skipping setJSExceptionHandler: Reason: In DEV mode and allowedInDevMode = false");
45+
}
46+
};
47+
48+
export const getJSExceptionHandler = () => ErrorUtils.getGlobalHandler();
49+
50+
export const setNativeExceptionHandler = (handler = noop, forceAppQuit = true, executeDefaultHandler = false) => {
51+
if (typeof handler !== "function" || typeof forceAppQuit !== "boolean") {
52+
console.log("setNativeExceptionHandler is called with wrong argument types.. first argument should be callback function and second argument is optional should be a boolean");
53+
console.log("Not setting the native handler .. please fix setNativeExceptionHandler call");
54+
return;
55+
}
56+
if (Platform.OS === "ios") {
57+
ExceptionHandlerTurboModule.setHandlerforNativeException(handler, executeDefaultHandler);
58+
} else {
59+
ExceptionHandlerTurboModule.setHandlerforNativeException(handler, forceAppQuit, executeDefaultHandler);
60+
}
61+
};
62+
63+
export default {
64+
setJSExceptionHandler,
65+
getJSExceptionHandler,
66+
setNativeExceptionHandler
67+
};

tsconfig.build.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
{
3+
"extends": "./tsconfig",
4+
"exclude": ["harmony"]
5+
}
6+

tsconfig.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"compilerOptions": {
3+
"jsx": "react",
4+
"baseUrl": "./",
5+
"paths": {
6+
"react-native-exception-handler": ["./src/index"]
7+
},
8+
"ignoreDeprecations":"5.0",
9+
"allowUnreachableCode": false,
10+
"allowUnusedLabels": false,
11+
"esModuleInterop": true,
12+
"importsNotUsedAsValues": "error",
13+
"forceConsistentCasingInFileNames": true,
14+
"lib": ["esnext"],
15+
"module": "esnext",
16+
"moduleResolution": "node",
17+
"noFallthroughCasesInSwitch": true,
18+
"noImplicitReturns": true,
19+
"noImplicitUseStrict": false,
20+
"noStrictGenericChecks": false,
21+
"noUncheckedIndexedAccess": true,
22+
"noUnusedLocals": true,
23+
"noUnusedParameters": true,
24+
"resolveJsonModule": true,
25+
"skipLibCheck": true,
26+
"strict": true,
27+
"target": "esnext"
28+
}
29+
}

0 commit comments

Comments
 (0)