Skip to content

Commit ff6e6e1

Browse files
committed
新老架构改造
1 parent 50e736b commit ff6e6e1

File tree

6 files changed

+198
-23
lines changed

6 files changed

+198
-23
lines changed

harmony/exception_handler.har

5.04 KB
Binary file not shown.

package.json

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,80 @@
11
{
22
"name": "react-native-exception-handler",
3-
"version": "2.10.10",
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+
"files": [
11+
"src",
12+
"lib",
13+
"android",
14+
"!android/build",
15+
"ios",
16+
"!ios/build",
17+
"harmony/exception_handler.har",
18+
"!harmony/build",
19+
"!harmony/oh_modules",
20+
"dist",
21+
"ReactNativeExceptionHandler.podspec",
22+
"!**/__tests__",
23+
"!**/__fixtures__",
24+
"!**/__mocks__",
25+
"!**/.*"
26+
],
727
"scripts": {
8-
"test": "echo no tests && exit 1",
9-
"lint": "eslint app/",
10-
"lint:fix": "eslint app/ --fix"
28+
"bob": "bob build",
29+
"prepack": "bob build",
30+
"prepare": "npm run bob",
31+
"build": "dv-scripts build && cp src/index.js.flow dist/index.js.flow && cp src/index.js.flow dist/index.cjs.js.flow",
32+
"lint": "dv-scripts lint",
33+
"release": "dv-scripts release",
34+
"test": "dv-scripts test"
1135
},
1236
"repository": {
1337
"type": "git",
1438
"url": "git+https://github.com/a7ul/react-native-exception-handler"
1539
},
1640
"keywords": [
17-
"modal",
1841
"react",
1942
"native",
2043
"exception",
21-
"handler",
22-
"red",
23-
"screen",
24-
"production",
25-
"ios",
26-
"android",
27-
"bug",
28-
"capture"
44+
"handler"
2945
],
30-
"peerDependencies": {
31-
"react": "*",
32-
"react-native": "*"
33-
},
3446
"author": "a7ul",
3547
"license": "MIT",
3648
"bugs": {
3749
"url": "https://github.com/a7ul/react-native-exception-handler/issues"
3850
},
3951
"homepage": "https://github.com/a7ul/react-native-exception-handler",
4052
"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"
53+
"@types/react": "^18.2.12",
54+
"react-native-builder-bob": "^0.20.4",
55+
"typescript": "^5.0.4"
56+
},
57+
"peerDependencies": {
58+
"react": "*",
59+
"react-native": "*"
60+
},
61+
"react-native-builder-bob": {
62+
"source": "src",
63+
"output": "lib",
64+
"targets": [
65+
"commonjs",
66+
"module",
67+
[
68+
"typescript",
69+
{
70+
"project": "tsconfig.build.json"
71+
}
72+
]
73+
]
74+
},
75+
"codegenConfig": {
76+
"name": "RNExceptionHandlerSpec",
77+
"type": "all",
78+
"jsSrcsDir": "src"
4579
}
4680
}

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/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)