@expo/metro-runtime 6.0.0 → 6.0.2
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/build/promiseRejectionTracking.d.ts +2 -0
- package/build/promiseRejectionTracking.d.ts.map +1 -0
- package/build/promiseRejectionTracking.native.d.ts +2 -0
- package/build/promiseRejectionTracking.native.d.ts.map +1 -0
- package/package.json +3 -2
- package/src/index.ts +6 -0
- package/src/promiseRejectionTracking.native.ts +73 -0
- package/src/promiseRejectionTracking.ts +2 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promiseRejectionTracking.d.ts","sourceRoot":"","sources":["../src/promiseRejectionTracking.ts"],"names":[],"mappings":"AACA,wBAAgB,8BAA8B,SAAK"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promiseRejectionTracking.native.d.ts","sourceRoot":"","sources":["../src/promiseRejectionTracking.native.ts"],"names":[],"mappings":"AAgBA,wBAAgB,8BAA8B,SAwD7C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expo/metro-runtime",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.2",
|
|
4
4
|
"description": "Tools for making advanced Metro bundler features work",
|
|
5
5
|
"sideEffects": true,
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -47,10 +47,11 @@
|
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"anser": "^1.4.9",
|
|
49
49
|
"stacktrace-parser": "^0.1.10",
|
|
50
|
+
"pretty-format": "^29.7.0",
|
|
50
51
|
"whatwg-fetch": "^3.0.0"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
53
54
|
"react-dom": "19.1.0"
|
|
54
55
|
},
|
|
55
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "eaa9b645058cf2233fbb27bb21a19bc605c90a88"
|
|
56
57
|
}
|
package/src/index.ts
CHANGED
|
@@ -9,6 +9,12 @@ import './location/install';
|
|
|
9
9
|
|
|
10
10
|
import '@expo/metro-runtime/rsc/runtime';
|
|
11
11
|
|
|
12
|
+
if (__DEV__) {
|
|
13
|
+
// TODO: Remove when fixed upstream. Expected in RN 0.82.
|
|
14
|
+
// https://github.com/facebook/react-native/commit/c4082c9ce208a324c2d011823ca2ba432411aafc
|
|
15
|
+
require('./promiseRejectionTracking').enablePromiseRejectionTracking();
|
|
16
|
+
}
|
|
17
|
+
|
|
12
18
|
if (__DEV__) {
|
|
13
19
|
// @ts-expect-error: TODO: Remove this when we remove the log box.
|
|
14
20
|
globalThis.__expo_dev_resetErrors = require('./error-overlay/LogBox').default.clearAllLogs;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import ExceptionsManager from './error-overlay/modules/ExceptionsManager';
|
|
2
|
+
|
|
3
|
+
type GlobalThis = {
|
|
4
|
+
HermesInternal:
|
|
5
|
+
| {
|
|
6
|
+
enablePromiseRejectionTracker?: (options: {
|
|
7
|
+
allRejections?: boolean;
|
|
8
|
+
onUnhandled?: (id: number, rejection?: any) => void;
|
|
9
|
+
onHandled?: (id: number) => void;
|
|
10
|
+
}) => void;
|
|
11
|
+
hasPromise?: () => boolean;
|
|
12
|
+
}
|
|
13
|
+
| undefined;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// https://github.com/facebook/react-native/commit/c4082c9ce208a324c2d011823ca2ba432411aafc
|
|
17
|
+
export function enablePromiseRejectionTracking() {
|
|
18
|
+
const global = globalThis as unknown as GlobalThis;
|
|
19
|
+
if (
|
|
20
|
+
// Early return if Hermes Promise is not available or tracker is not available
|
|
21
|
+
// https://github.com/facebook/react-native/blob/256565cb1198c02cda218e06de5700c85d8ad589/packages/react-native/Libraries/Core/polyfillPromise.js#L25
|
|
22
|
+
!global?.HermesInternal?.hasPromise?.() ||
|
|
23
|
+
!global?.HermesInternal?.enablePromiseRejectionTracker
|
|
24
|
+
) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
global.HermesInternal.enablePromiseRejectionTracker({
|
|
29
|
+
allRejections: true,
|
|
30
|
+
onUnhandled: (id, rejection) => {
|
|
31
|
+
let message: string;
|
|
32
|
+
|
|
33
|
+
if (rejection === undefined) {
|
|
34
|
+
message = '';
|
|
35
|
+
} else if (
|
|
36
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
|
37
|
+
Object.prototype.toString.call(rejection) === '[object Error]'
|
|
38
|
+
) {
|
|
39
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
|
40
|
+
message = Error.prototype.toString.call(rejection);
|
|
41
|
+
} else {
|
|
42
|
+
try {
|
|
43
|
+
message = require('pretty-format').format(rejection);
|
|
44
|
+
} catch {
|
|
45
|
+
message = typeof rejection === 'string' ? rejection : JSON.stringify(rejection);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const rejectionPrefix = `Uncaught (in promise, id: ${id})`;
|
|
50
|
+
// This is not an Expo error, but
|
|
51
|
+
// an uncaught promise rejection in the app.
|
|
52
|
+
const rejectionError = new Error(`${rejectionPrefix} ${message ?? ''}`, {
|
|
53
|
+
cause: rejection,
|
|
54
|
+
});
|
|
55
|
+
if (typeof rejection === 'object' && 'stack' in rejection) {
|
|
56
|
+
// If original rejection stack exists, use it
|
|
57
|
+
rejectionError.stack = `${rejectionPrefix} ${rejection.stack ?? ''}`;
|
|
58
|
+
} else {
|
|
59
|
+
// Deleting the stack property would trigger exception handler to collect the current stack
|
|
60
|
+
// Stack of the error created here won't be any useful to the user
|
|
61
|
+
rejectionError.stack = `${rejectionPrefix} ${message ?? ''}`;
|
|
62
|
+
}
|
|
63
|
+
ExceptionsManager.handleException(rejectionError);
|
|
64
|
+
},
|
|
65
|
+
onHandled: (id) => {
|
|
66
|
+
const warning =
|
|
67
|
+
`Promise rejection handled (id: ${id})\n` +
|
|
68
|
+
'This means you can ignore any previous messages of the form ' +
|
|
69
|
+
`"Uncaught (in promise, id: ${id})"`;
|
|
70
|
+
console.warn(warning);
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
}
|