@expo/metro-runtime 3.0.0 → 3.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.
Files changed (219) hide show
  1. package/build/HMRClient.js +43 -15
  2. package/build/HMRClient.js.map +1 -1
  3. package/build/HMRClient.native.js +3 -1
  4. package/build/HMRClient.native.js.map +1 -1
  5. package/build/LoadingView.d.ts +6 -0
  6. package/build/LoadingView.d.ts.map +1 -1
  7. package/build/LoadingView.js +12 -4
  8. package/build/LoadingView.js.map +1 -1
  9. package/build/LoadingView.native.js +7 -2
  10. package/build/LoadingView.native.js.map +1 -1
  11. package/build/async-require/buildAsyncRequire.js +7 -3
  12. package/build/async-require/buildAsyncRequire.js.map +1 -1
  13. package/build/async-require/buildUrlForBundle.js +5 -1
  14. package/build/async-require/buildUrlForBundle.js.map +1 -1
  15. package/build/async-require/buildUrlForBundle.native.js +5 -1
  16. package/build/async-require/buildUrlForBundle.native.js.map +1 -1
  17. package/build/async-require/fetchAsync.d.ts +6 -0
  18. package/build/async-require/fetchAsync.d.ts.map +1 -1
  19. package/build/async-require/fetchAsync.js +6 -3
  20. package/build/async-require/fetchAsync.js.map +1 -1
  21. package/build/async-require/fetchAsync.native.js +13 -6
  22. package/build/async-require/fetchAsync.native.js.map +1 -1
  23. package/build/async-require/fetchThenEval.d.ts +1 -6
  24. package/build/async-require/fetchThenEval.d.ts.map +1 -1
  25. package/build/async-require/fetchThenEval.js +5 -31
  26. package/build/async-require/fetchThenEval.js.map +1 -1
  27. package/build/async-require/fetchThenEval.web.js +6 -2
  28. package/build/async-require/fetchThenEval.web.js.map +1 -1
  29. package/build/async-require/fetchThenEvalJs.d.ts +7 -0
  30. package/build/async-require/fetchThenEvalJs.d.ts.map +1 -0
  31. package/build/async-require/fetchThenEvalJs.js +36 -0
  32. package/build/async-require/fetchThenEvalJs.js.map +1 -0
  33. package/build/async-require/index.js +4 -2
  34. package/build/async-require/index.js.map +1 -1
  35. package/build/async-require/index.native.d.ts +7 -0
  36. package/build/async-require/index.native.d.ts.map +1 -0
  37. package/build/async-require/index.native.js +14 -0
  38. package/build/async-require/index.native.js.map +1 -0
  39. package/build/async-require/loadBundle.js +10 -6
  40. package/build/async-require/loadBundle.js.map +1 -1
  41. package/build/effects.d.ts +0 -1
  42. package/build/effects.js +7 -10
  43. package/build/effects.js.map +1 -1
  44. package/build/error-overlay/Data/LogBoxData.d.ts.map +1 -1
  45. package/build/error-overlay/Data/LogBoxData.js +82 -33
  46. package/build/error-overlay/Data/LogBoxData.js.map +1 -1
  47. package/build/error-overlay/Data/LogBoxLog.js +29 -2
  48. package/build/error-overlay/Data/LogBoxLog.js.map +1 -1
  49. package/build/error-overlay/Data/LogBoxSymbolication.js +12 -4
  50. package/build/error-overlay/Data/LogBoxSymbolication.js.map +1 -1
  51. package/build/error-overlay/Data/LogContext.js +17 -9
  52. package/build/error-overlay/Data/LogContext.js.map +1 -1
  53. package/build/error-overlay/Data/parseLogBoxLog.d.ts.map +1 -1
  54. package/build/error-overlay/Data/parseLogBoxLog.js +20 -11
  55. package/build/error-overlay/Data/parseLogBoxLog.js.map +1 -1
  56. package/build/error-overlay/ErrorOverlay.d.ts.map +1 -1
  57. package/build/error-overlay/ErrorOverlay.js +73 -41
  58. package/build/error-overlay/ErrorOverlay.js.map +1 -1
  59. package/build/error-overlay/LogBox.js +3 -1
  60. package/build/error-overlay/LogBox.js.map +1 -1
  61. package/build/error-overlay/LogBox.web.d.ts.map +1 -1
  62. package/build/error-overlay/LogBox.web.js +4 -3
  63. package/build/error-overlay/LogBox.web.js.map +1 -1
  64. package/build/error-overlay/UI/AnsiHighlight.js +15 -8
  65. package/build/error-overlay/UI/AnsiHighlight.js.map +1 -1
  66. package/build/error-overlay/UI/LogBoxButton.js +35 -8
  67. package/build/error-overlay/UI/LogBoxButton.js.map +1 -1
  68. package/build/error-overlay/UI/LogBoxMessage.js +13 -6
  69. package/build/error-overlay/UI/LogBoxMessage.js.map +1 -1
  70. package/build/error-overlay/UI/LogBoxStyle.js +31 -14
  71. package/build/error-overlay/UI/LogBoxStyle.js.map +1 -1
  72. package/build/error-overlay/UI/constants.js +5 -2
  73. package/build/error-overlay/UI/constants.js.map +1 -1
  74. package/build/error-overlay/formatProjectFilePath.js +7 -2
  75. package/build/error-overlay/formatProjectFilePath.js.map +1 -1
  76. package/build/error-overlay/index.d.ts.map +1 -1
  77. package/build/error-overlay/index.js +19 -9
  78. package/build/error-overlay/index.js.map +1 -1
  79. package/build/error-overlay/modules/ExceptionsManager/index.js +8 -3
  80. package/build/error-overlay/modules/ExceptionsManager/index.js.map +1 -1
  81. package/build/error-overlay/modules/ExceptionsManager/index.native.js +7 -2
  82. package/build/error-overlay/modules/ExceptionsManager/index.native.js.map +1 -1
  83. package/build/error-overlay/modules/NativeLogBox/index.js +10 -5
  84. package/build/error-overlay/modules/NativeLogBox/index.js.map +1 -1
  85. package/build/error-overlay/modules/NativeLogBox/index.native.js +7 -2
  86. package/build/error-overlay/modules/NativeLogBox/index.native.js.map +1 -1
  87. package/build/error-overlay/modules/openFileInEditor/index.js +3 -1
  88. package/build/error-overlay/modules/openFileInEditor/index.js.map +1 -1
  89. package/build/error-overlay/modules/openFileInEditor/index.native.js +7 -2
  90. package/build/error-overlay/modules/openFileInEditor/index.native.js.map +1 -1
  91. package/build/error-overlay/modules/parseErrorStack/index.d.ts.map +1 -1
  92. package/build/error-overlay/modules/parseErrorStack/index.js +10 -7
  93. package/build/error-overlay/modules/parseErrorStack/index.js.map +1 -1
  94. package/build/error-overlay/modules/parseErrorStack/parseHermesStack.js +8 -2
  95. package/build/error-overlay/modules/parseErrorStack/parseHermesStack.js.map +1 -1
  96. package/build/error-overlay/modules/stringifySafe/index.js +6 -2
  97. package/build/error-overlay/modules/stringifySafe/index.js.map +1 -1
  98. package/build/error-overlay/modules/symbolicateStackTrace/index.js +3 -1
  99. package/build/error-overlay/modules/symbolicateStackTrace/index.js.map +1 -1
  100. package/build/error-overlay/modules/symbolicateStackTrace/index.native.js +7 -2
  101. package/build/error-overlay/modules/symbolicateStackTrace/index.native.js.map +1 -1
  102. package/build/error-overlay/overlay/LogBoxInspectorCodeFrame.d.ts.map +1 -1
  103. package/build/error-overlay/overlay/LogBoxInspectorCodeFrame.js +52 -22
  104. package/build/error-overlay/overlay/LogBoxInspectorCodeFrame.js.map +1 -1
  105. package/build/error-overlay/overlay/LogBoxInspectorFooter.js +48 -18
  106. package/build/error-overlay/overlay/LogBoxInspectorFooter.js.map +1 -1
  107. package/build/error-overlay/overlay/LogBoxInspectorHeader.js +53 -23
  108. package/build/error-overlay/overlay/LogBoxInspectorHeader.js.map +1 -1
  109. package/build/error-overlay/overlay/LogBoxInspectorMessageHeader.js +43 -13
  110. package/build/error-overlay/overlay/LogBoxInspectorMessageHeader.js.map +1 -1
  111. package/build/error-overlay/overlay/LogBoxInspectorSection.js +39 -9
  112. package/build/error-overlay/overlay/LogBoxInspectorSection.js.map +1 -1
  113. package/build/error-overlay/overlay/LogBoxInspectorSourceMapStatus.js +41 -14
  114. package/build/error-overlay/overlay/LogBoxInspectorSourceMapStatus.js.map +1 -1
  115. package/build/error-overlay/overlay/LogBoxInspectorStackFrame.js +44 -14
  116. package/build/error-overlay/overlay/LogBoxInspectorStackFrame.js.map +1 -1
  117. package/build/error-overlay/overlay/LogBoxInspectorStackFrames.d.ts.map +1 -1
  118. package/build/error-overlay/overlay/LogBoxInspectorStackFrames.js +55 -24
  119. package/build/error-overlay/overlay/LogBoxInspectorStackFrames.js.map +1 -1
  120. package/build/error-overlay/toast/ErrorToast.d.ts.map +1 -1
  121. package/build/error-overlay/toast/ErrorToast.js +48 -21
  122. package/build/error-overlay/toast/ErrorToast.js.map +1 -1
  123. package/build/error-overlay/toast/ErrorToastContainer.js +9 -3
  124. package/build/error-overlay/toast/ErrorToastContainer.js.map +1 -1
  125. package/build/error-overlay/toast/ErrorToastContainer.web.d.ts.map +1 -1
  126. package/build/error-overlay/toast/ErrorToastContainer.web.js +49 -21
  127. package/build/error-overlay/toast/ErrorToastContainer.web.js.map +1 -1
  128. package/build/error-overlay/toast/ErrorToastMessage.js +37 -7
  129. package/build/error-overlay/toast/ErrorToastMessage.js.map +1 -1
  130. package/build/error-overlay/useRejectionHandler.js +16 -9
  131. package/build/error-overlay/useRejectionHandler.js.map +1 -1
  132. package/build/getDevServer.d.ts.map +1 -1
  133. package/build/getDevServer.js +10 -9
  134. package/build/getDevServer.js.map +1 -1
  135. package/build/getDevServer.native.js +7 -2
  136. package/build/getDevServer.native.js.map +1 -1
  137. package/build/index.d.ts +7 -0
  138. package/build/index.d.ts.map +1 -1
  139. package/build/index.js +12 -8
  140. package/build/index.js.map +1 -1
  141. package/build/location/Location.js +7 -2
  142. package/build/location/Location.js.map +1 -1
  143. package/build/location/Location.native.js +12 -4
  144. package/build/location/Location.native.js.map +1 -1
  145. package/build/location/install.native.js +16 -11
  146. package/build/location/install.native.js.map +1 -1
  147. package/build/setupHMR.js +28 -26
  148. package/build/setupHMR.js.map +1 -1
  149. package/build/symbolicate.js +25 -4
  150. package/build/symbolicate.js.map +1 -1
  151. package/package.json +5 -2
  152. package/src/HMRClient.native.ts +3 -0
  153. package/src/HMRClient.ts +316 -0
  154. package/src/LoadingView.native.ts +3 -0
  155. package/src/LoadingView.ts +24 -0
  156. package/src/__mocks__/LoadingView.ts +4 -0
  157. package/src/async-require/buildAsyncRequire.ts +34 -0
  158. package/src/async-require/buildUrlForBundle.native.ts +28 -0
  159. package/src/async-require/buildUrlForBundle.ts +18 -0
  160. package/src/async-require/fetchAsync.native.ts +72 -0
  161. package/src/async-require/fetchAsync.ts +19 -0
  162. package/src/async-require/fetchThenEval.ts +1 -0
  163. package/src/async-require/fetchThenEval.web.ts +70 -0
  164. package/src/async-require/fetchThenEvalJs.ts +39 -0
  165. package/src/async-require/index.native.ts +15 -0
  166. package/src/async-require/index.ts +10 -0
  167. package/src/async-require/loadBundle.ts +46 -0
  168. package/src/effects.native.ts +0 -0
  169. package/src/effects.ts +11 -0
  170. package/src/error-overlay/Data/LogBoxData.tsx +438 -0
  171. package/src/error-overlay/Data/LogBoxLog.ts +221 -0
  172. package/src/error-overlay/Data/LogBoxSymbolication.tsx +64 -0
  173. package/src/error-overlay/Data/LogContext.tsx +41 -0
  174. package/src/error-overlay/Data/parseLogBoxLog.tsx +342 -0
  175. package/src/error-overlay/ErrorOverlay.tsx +191 -0
  176. package/src/error-overlay/LogBox.ts +51 -0
  177. package/src/error-overlay/LogBox.web.ts +174 -0
  178. package/src/error-overlay/UI/AnsiHighlight.tsx +96 -0
  179. package/src/error-overlay/UI/LogBoxButton.tsx +63 -0
  180. package/src/error-overlay/UI/LogBoxMessage.tsx +73 -0
  181. package/src/error-overlay/UI/LogBoxStyle.ts +64 -0
  182. package/src/error-overlay/UI/constants.ts +7 -0
  183. package/src/error-overlay/formatProjectFilePath.ts +38 -0
  184. package/src/error-overlay/index.tsx +34 -0
  185. package/src/error-overlay/modules/ExceptionsManager/index.native.ts +4 -0
  186. package/src/error-overlay/modules/ExceptionsManager/index.ts +82 -0
  187. package/src/error-overlay/modules/NativeLogBox/index.native.ts +3 -0
  188. package/src/error-overlay/modules/NativeLogBox/index.tsx +27 -0
  189. package/src/error-overlay/modules/openFileInEditor/index.native.ts +3 -0
  190. package/src/error-overlay/modules/openFileInEditor/index.ts +16 -0
  191. package/src/error-overlay/modules/parseErrorStack/index.ts +26 -0
  192. package/src/error-overlay/modules/parseErrorStack/parseHermesStack.ts +3 -0
  193. package/src/error-overlay/modules/stringifySafe/index.ts +115 -0
  194. package/src/error-overlay/modules/symbolicateStackTrace/index.native.ts +3 -0
  195. package/src/error-overlay/modules/symbolicateStackTrace/index.ts +39 -0
  196. package/src/error-overlay/overlay/LogBoxInspectorCodeFrame.tsx +102 -0
  197. package/src/error-overlay/overlay/LogBoxInspectorFooter.tsx +111 -0
  198. package/src/error-overlay/overlay/LogBoxInspectorHeader.tsx +167 -0
  199. package/src/error-overlay/overlay/LogBoxInspectorMessageHeader.tsx +116 -0
  200. package/src/error-overlay/overlay/LogBoxInspectorSection.tsx +52 -0
  201. package/src/error-overlay/overlay/LogBoxInspectorSourceMapStatus.tsx +125 -0
  202. package/src/error-overlay/overlay/LogBoxInspectorStackFrame.tsx +89 -0
  203. package/src/error-overlay/overlay/LogBoxInspectorStackFrames.tsx +201 -0
  204. package/src/error-overlay/toast/ErrorToast.tsx +167 -0
  205. package/src/error-overlay/toast/ErrorToastContainer.tsx +9 -0
  206. package/src/error-overlay/toast/ErrorToastContainer.web.tsx +92 -0
  207. package/src/error-overlay/toast/ErrorToastMessage.tsx +28 -0
  208. package/src/error-overlay/useRejectionHandler.ts +61 -0
  209. package/src/getDevServer.native.ts +3 -0
  210. package/src/getDevServer.ts +34 -0
  211. package/src/index.ts +12 -0
  212. package/src/location/Location.native.ts +201 -0
  213. package/src/location/Location.ts +3 -0
  214. package/src/location/install.native.ts +90 -0
  215. package/src/location/install.ts +0 -0
  216. package/src/messageSocket.ts +25 -0
  217. package/src/setupFastRefresh.ts +30 -0
  218. package/src/setupHMR.ts +28 -0
  219. package/src/symbolicate.ts +6 -0
@@ -0,0 +1,174 @@
1
+ /**
2
+ * Copyright (c) 650 Industries.
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ import { IgnorePattern, LogData } from './Data/LogBoxData';
10
+ import { ExtendedExceptionData } from './Data/parseLogBoxLog';
11
+
12
+ export { LogData, ExtendedExceptionData, IgnorePattern };
13
+
14
+ let LogBox: ILogBox;
15
+
16
+ interface ILogBox {
17
+ install(): void;
18
+ uninstall(): void;
19
+ isInstalled(): boolean;
20
+ ignoreLogs(patterns: readonly IgnorePattern[]): void;
21
+ ignoreAllLogs(ignore?: boolean): void;
22
+ clearAllLogs(): void;
23
+ addLog(log: LogData): void;
24
+ addException(error: ExtendedExceptionData): void;
25
+ }
26
+
27
+ /**
28
+ * LogBox displays logs in the app.
29
+ */
30
+ if (__DEV__) {
31
+ const LogBoxData = require('./Data/LogBoxData');
32
+ const { parseLogBoxLog, parseInterpolation } =
33
+ require('./Data/parseLogBoxLog') as typeof import('./Data/parseLogBoxLog');
34
+
35
+ let originalConsoleError: typeof console.error | undefined;
36
+ let consoleErrorImpl: typeof console.error | undefined;
37
+
38
+ let isLogBoxInstalled: boolean = false;
39
+
40
+ LogBox = {
41
+ install(): void {
42
+ if (isLogBoxInstalled) {
43
+ return;
44
+ }
45
+
46
+ isLogBoxInstalled = true;
47
+
48
+ // Trigger lazy initialization of module.
49
+ // require("../NativeModules/specs/NativeLogBox");
50
+
51
+ // IMPORTANT: we only overwrite `console.error` and `console.warn` once.
52
+ // When we uninstall we keep the same reference and only change its
53
+ // internal implementation
54
+ const isFirstInstall = originalConsoleError == null;
55
+ if (isFirstInstall) {
56
+ originalConsoleError = console.error.bind(console);
57
+
58
+ console.error = (...args) => {
59
+ consoleErrorImpl?.(...args);
60
+ };
61
+ }
62
+
63
+ consoleErrorImpl = registerError;
64
+
65
+ if (process.env.NODE_ENV === 'test') {
66
+ LogBoxData.setDisabled(true);
67
+ }
68
+ },
69
+
70
+ uninstall(): void {
71
+ if (!isLogBoxInstalled) {
72
+ return;
73
+ }
74
+
75
+ isLogBoxInstalled = false;
76
+
77
+ // IMPORTANT: we don't re-assign to `console` in case the method has been
78
+ // decorated again after installing LogBox. E.g.:
79
+ // Before uninstalling: original > LogBox > OtherErrorHandler
80
+ // After uninstalling: original > LogBox (noop) > OtherErrorHandler
81
+ consoleErrorImpl = originalConsoleError;
82
+ delete (console as any).disableLogBox;
83
+ },
84
+
85
+ isInstalled(): boolean {
86
+ return isLogBoxInstalled;
87
+ },
88
+
89
+ ignoreLogs(patterns: readonly IgnorePattern[]): void {
90
+ LogBoxData.addIgnorePatterns(patterns);
91
+ },
92
+
93
+ ignoreAllLogs(value?: boolean): void {
94
+ LogBoxData.setDisabled(value == null ? true : value);
95
+ },
96
+
97
+ clearAllLogs(): void {
98
+ LogBoxData.clear();
99
+ },
100
+
101
+ addLog(log: LogData): void {
102
+ if (isLogBoxInstalled) {
103
+ LogBoxData.addLog(log);
104
+ }
105
+ },
106
+
107
+ addException(error: ExtendedExceptionData): void {
108
+ if (isLogBoxInstalled) {
109
+ LogBoxData.addException(error);
110
+ }
111
+ },
112
+ };
113
+
114
+ const isWarningModuleWarning = (...args: any) => {
115
+ return typeof args[0] === 'string' && args[0].startsWith('Warning: ');
116
+ };
117
+
118
+ const registerError = (...args: Parameters<typeof console.error>): void => {
119
+ // Let errors within LogBox itself fall through.
120
+ if (LogBoxData.isLogBoxErrorMessage(args[0])) {
121
+ originalConsoleError?.(...args);
122
+ return;
123
+ }
124
+
125
+ try {
126
+ if (!isWarningModuleWarning(...args)) {
127
+ // Only show LogBox for the 'warning' module, otherwise pass through.
128
+ // By passing through, this will get picked up by the React console override,
129
+ // potentially adding the component stack. React then passes it back to the
130
+ // React Native ExceptionsManager, which reports it to LogBox as an error.
131
+ //
132
+ // The 'warning' module needs to be handled here because React internally calls
133
+ // `console.error('Warning: ')` with the component stack already included.
134
+ originalConsoleError?.(...args);
135
+ return;
136
+ }
137
+
138
+ const { category, message, componentStack } = parseLogBoxLog(args);
139
+
140
+ if (!LogBoxData.isMessageIgnored(message.content)) {
141
+ // Interpolate the message so they are formatted for adb and other CLIs.
142
+ // This is different than the message.content above because it includes component stacks.
143
+ const interpolated = parseInterpolation(args);
144
+ originalConsoleError?.(interpolated.message.content);
145
+
146
+ LogBoxData.addLog({
147
+ // Always show the static rendering issues as full screen since they
148
+ // are too confusing otherwise.
149
+ level: /did not match\. Server:/.test(message.content) ? 'fatal' : 'error',
150
+ category,
151
+ message,
152
+ componentStack,
153
+ });
154
+ }
155
+ } catch (err) {
156
+ LogBoxData.reportUnexpectedLogBoxError(err);
157
+ }
158
+ };
159
+ } else {
160
+ LogBox = {
161
+ install(): void {},
162
+ uninstall(): void {},
163
+ isInstalled(): boolean {
164
+ return false;
165
+ },
166
+ ignoreLogs(patterns: readonly IgnorePattern[]): void {},
167
+ ignoreAllLogs(value?: boolean): void {},
168
+ clearAllLogs(): void {},
169
+ addLog(log: LogData): void {},
170
+ addException(ex: ExtendedExceptionData): void {},
171
+ };
172
+ }
173
+
174
+ export default LogBox;
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Copyright (c) 650 Industries.
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import Anser from 'anser';
9
+ import React from 'react';
10
+ import { StyleProp, StyleSheet, Text, TextStyle, View } from 'react-native';
11
+
12
+ // Afterglow theme from https://iterm2colorschemes.com/
13
+ const COLORS: Record<string, string> = {
14
+ 'ansi-black': 'rgb(27, 27, 27)',
15
+ 'ansi-red': 'rgb(187, 86, 83)',
16
+ 'ansi-green': 'rgb(144, 157, 98)',
17
+ 'ansi-yellow': 'rgb(234, 193, 121)',
18
+ 'ansi-blue': 'rgb(125, 169, 199)',
19
+ 'ansi-magenta': 'rgb(176, 101, 151)',
20
+ 'ansi-cyan': 'rgb(140, 220, 216)',
21
+ // Instead of white, use the default color provided to the component
22
+ // 'ansi-white': 'rgb(216, 216, 216)',
23
+ 'ansi-bright-black': 'rgb(98, 98, 98)',
24
+ 'ansi-bright-red': 'rgb(187, 86, 83)',
25
+ 'ansi-bright-green': 'rgb(144, 157, 98)',
26
+ 'ansi-bright-yellow': 'rgb(234, 193, 121)',
27
+ 'ansi-bright-blue': 'rgb(125, 169, 199)',
28
+ 'ansi-bright-magenta': 'rgb(176, 101, 151)',
29
+ 'ansi-bright-cyan': 'rgb(140, 220, 216)',
30
+ 'ansi-bright-white': 'rgb(247, 247, 247)',
31
+ };
32
+
33
+ export function Ansi({ text, style }: { text: string; style: StyleProp<TextStyle> }) {
34
+ let commonWhitespaceLength = Infinity;
35
+ const parsedLines = text.split(/\n/).map((line) =>
36
+ Anser.ansiToJson(line, {
37
+ json: true,
38
+ remove_empty: true,
39
+ use_classes: true,
40
+ })
41
+ );
42
+
43
+ parsedLines.map((lines) => {
44
+ // The third item on each line includes the whitespace of the source code.
45
+ // We are looking for the least amount of common whitespace to trim all lines.
46
+ // Example: Array [" ", " 96 |", " text", ...]
47
+ const match = lines[2] && lines[2]?.content?.match(/^ +/);
48
+ const whitespaceLength = (match && match[0]?.length) || 0;
49
+ if (whitespaceLength < commonWhitespaceLength) {
50
+ commonWhitespaceLength = whitespaceLength;
51
+ }
52
+ });
53
+
54
+ const getText = (content: string, key: number) => {
55
+ if (key === 1) {
56
+ // Remove the vertical bar after line numbers
57
+ return content.replace(/\| $/, ' ');
58
+ } else if (key === 2 && commonWhitespaceLength < Infinity) {
59
+ // Remove common whitespace at the beginning of the line
60
+ return content.substr(commonWhitespaceLength);
61
+ } else {
62
+ return content;
63
+ }
64
+ };
65
+
66
+ return (
67
+ <View>
68
+ {parsedLines.map((items, i) => (
69
+ <View style={styles.line} key={i}>
70
+ {items.map((bundle, key) => {
71
+ const textStyle =
72
+ bundle.fg && COLORS[bundle.fg]
73
+ ? {
74
+ backgroundColor: bundle.bg && COLORS[bundle.bg],
75
+ color: bundle.fg && COLORS[bundle.fg],
76
+ }
77
+ : {
78
+ backgroundColor: bundle.bg && COLORS[bundle.bg],
79
+ };
80
+ return (
81
+ <Text style={[style, textStyle]} key={key}>
82
+ {getText(bundle.content, key)}
83
+ </Text>
84
+ );
85
+ })}
86
+ </View>
87
+ ))}
88
+ </View>
89
+ );
90
+ }
91
+
92
+ const styles = StyleSheet.create({
93
+ line: {
94
+ flexDirection: 'row',
95
+ },
96
+ });
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Copyright (c) 650 Industries.
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import React, { useState } from 'react';
9
+ import { GestureResponderEvent, Insets, Platform, Pressable, View, ViewStyle } from 'react-native';
10
+
11
+ import * as LogBoxStyle from './LogBoxStyle';
12
+
13
+ type Props = {
14
+ backgroundColor: {
15
+ default: string;
16
+ pressed: string;
17
+ };
18
+ children?: any;
19
+ hitSlop?: Insets;
20
+ onPress?: ((event: GestureResponderEvent) => void) | null;
21
+ style?: ViewStyle;
22
+ };
23
+
24
+ export function LogBoxButton(props: Props) {
25
+ const [pressed, setPressed] = useState(false);
26
+
27
+ let backgroundColor = props.backgroundColor;
28
+ if (!backgroundColor) {
29
+ backgroundColor = {
30
+ default: LogBoxStyle.getBackgroundColor(0.95),
31
+ pressed: LogBoxStyle.getBackgroundColor(0.6),
32
+ };
33
+ }
34
+
35
+ const content = (
36
+ <View
37
+ style={[
38
+ {
39
+ backgroundColor: pressed ? backgroundColor.pressed : backgroundColor.default,
40
+ ...Platform.select({
41
+ web: {
42
+ cursor: 'pointer',
43
+ },
44
+ }),
45
+ },
46
+ props.style,
47
+ ]}>
48
+ {props.children}
49
+ </View>
50
+ );
51
+
52
+ return props.onPress == null ? (
53
+ content
54
+ ) : (
55
+ <Pressable
56
+ hitSlop={props.hitSlop}
57
+ onPress={props.onPress}
58
+ onPressIn={() => setPressed(true)}
59
+ onPressOut={() => setPressed(false)}>
60
+ {content}
61
+ </Pressable>
62
+ );
63
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Copyright (c) 650 Industries.
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import React from 'react';
9
+ import { StyleProp, Text, TextStyle } from 'react-native';
10
+
11
+ import type { Message } from '../Data/parseLogBoxLog';
12
+
13
+ type Props = {
14
+ message: Message;
15
+ style: StyleProp<TextStyle>;
16
+ plaintext?: boolean;
17
+ maxLength?: number;
18
+ };
19
+
20
+ const cleanContent = (content: string) =>
21
+ content.replace(/^(TransformError |Warning: (Warning: )?|Error: )/g, '');
22
+
23
+ export function LogBoxMessage(props: Props): JSX.Element {
24
+ const { content, substitutions }: Message = props.message;
25
+
26
+ if (props.plaintext === true) {
27
+ return <Text>{cleanContent(content)}</Text>;
28
+ }
29
+
30
+ const maxLength = props.maxLength != null ? props.maxLength : Infinity;
31
+ const substitutionStyle: StyleProp<TextStyle> = props.style;
32
+ const elements: JSX.Element[] = [];
33
+ let length = 0;
34
+ const createUnderLength = (key: string | '-1', message: string, style?: StyleProp<TextStyle>) => {
35
+ let cleanMessage = cleanContent(message);
36
+
37
+ if (props.maxLength != null) {
38
+ cleanMessage = cleanMessage.slice(0, props.maxLength - length);
39
+ }
40
+
41
+ if (length < maxLength) {
42
+ elements.push(
43
+ <Text key={key} style={style}>
44
+ {cleanMessage}
45
+ </Text>
46
+ );
47
+ }
48
+
49
+ length += cleanMessage.length;
50
+ };
51
+
52
+ const lastOffset = substitutions.reduce((prevOffset, substitution, index) => {
53
+ const key = String(index);
54
+
55
+ if (substitution.offset > prevOffset) {
56
+ const prevPart = content.substr(prevOffset, substitution.offset - prevOffset);
57
+
58
+ createUnderLength(key, prevPart);
59
+ }
60
+
61
+ const substititionPart = content.substr(substitution.offset, substitution.length);
62
+
63
+ createUnderLength(key + '.5', substititionPart, substitutionStyle);
64
+ return substitution.offset + substitution.length;
65
+ }, 0);
66
+
67
+ if (lastOffset < content.length) {
68
+ const lastPart = content.substr(lastOffset);
69
+ createUnderLength('-1', lastPart);
70
+ }
71
+
72
+ return <>{elements}</>;
73
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Copyright (c) 650 Industries.
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ export function getBackgroundColor(opacity?: number): string {
10
+ return `rgba(0, 0, 0, ${opacity == null ? 1 : opacity})`;
11
+ // return `rgba(51, 51, 51, ${opacity == null ? 1 : opacity})`;
12
+ }
13
+
14
+ export function getBackgroundLightColor(opacity?: number): string {
15
+ return `rgba(69, 69, 69, ${opacity == null ? 1 : opacity})`;
16
+ }
17
+
18
+ export function getBackgroundDarkColor(opacity?: number): string {
19
+ return `rgba(34, 34, 34, ${opacity == null ? 1 : opacity})`;
20
+ }
21
+
22
+ export function getWarningColor(opacity?: number): string {
23
+ return `rgba(250, 186, 48, ${opacity == null ? 1 : opacity})`;
24
+ }
25
+
26
+ export function getWarningDarkColor(opacity?: number): string {
27
+ return `rgba(224, 167, 8, ${opacity == null ? 1 : opacity})`;
28
+ }
29
+
30
+ export function getFatalColor(opacity?: number): string {
31
+ return `rgba(243, 83, 105, ${opacity == null ? 1 : opacity})`;
32
+ }
33
+
34
+ export function getFatalDarkColor(opacity?: number): string {
35
+ return `rgba(208, 75, 95, ${opacity == null ? 1 : opacity})`;
36
+ }
37
+
38
+ export function getErrorColor(opacity?: number): string {
39
+ return `rgba(243, 83, 105, ${opacity == null ? 1 : opacity})`;
40
+ }
41
+
42
+ export function getErrorDarkColor(opacity?: number): string {
43
+ return `rgba(208, 75, 95, ${opacity == null ? 1 : opacity})`;
44
+ }
45
+
46
+ export function getLogColor(opacity?: number): string {
47
+ return `rgba(119, 119, 119, ${opacity == null ? 1 : opacity})`;
48
+ }
49
+
50
+ export function getWarningHighlightColor(opacity?: number): string {
51
+ return `rgba(252, 176, 29, ${opacity == null ? 1 : opacity})`;
52
+ }
53
+
54
+ export function getDividerColor(opacity?: number): string {
55
+ return `rgba(255, 255, 255, ${opacity == null ? 1 : opacity})`;
56
+ }
57
+
58
+ export function getHighlightColor(opacity?: number): string {
59
+ return `rgba(252, 176, 29, ${opacity == null ? 1 : opacity})`;
60
+ }
61
+
62
+ export function getTextColor(opacity?: number): string {
63
+ return `rgba(255, 255, 255, ${opacity == null ? 1 : opacity})`;
64
+ }
@@ -0,0 +1,7 @@
1
+ import { Platform } from 'react-native';
2
+
3
+ export const CODE_FONT = Platform.select({
4
+ default: 'Courier',
5
+ ios: 'Courier New',
6
+ android: 'monospace',
7
+ });
@@ -0,0 +1,38 @@
1
+ import type { StackFrame } from 'stacktrace-parser';
2
+
3
+ export type MetroStackFrame = StackFrame & { collapse?: boolean };
4
+
5
+ export function formatProjectFilePath(projectRoot: string, file?: string | null): string {
6
+ if (file == null) {
7
+ return '<unknown>';
8
+ }
9
+
10
+ return pathRelativeToPath(file.replace(/\\/g, '/'), projectRoot.replace(/\\/g, '/')).replace(
11
+ /\?.*$/,
12
+ ''
13
+ );
14
+ }
15
+
16
+ function pathRelativeToPath(path: string, relativeTo: string, sep = '/') {
17
+ const relativeToParts = relativeTo.split(sep);
18
+ const pathParts = path.split(sep);
19
+ let i = 0;
20
+ while (i < relativeToParts.length && i < pathParts.length) {
21
+ if (relativeToParts[i] !== pathParts[i]) {
22
+ break;
23
+ }
24
+ i++;
25
+ }
26
+ return pathParts.slice(i).join(sep);
27
+ }
28
+
29
+ export function getStackFormattedLocation(projectRoot: string, frame: MetroStackFrame) {
30
+ const column = frame.column != null && parseInt(String(frame.column), 10);
31
+ const location =
32
+ formatProjectFilePath(projectRoot, frame.file) +
33
+ (frame.lineNumber != null
34
+ ? ':' + frame.lineNumber + (column && !isNaN(column) ? ':' + (column + 1) : '')
35
+ : '');
36
+
37
+ return location;
38
+ }
@@ -0,0 +1,34 @@
1
+ import React from 'react';
2
+ // TODO: This will break tree shaking due to how we transpile this package.
3
+ import { Platform } from 'react-native';
4
+
5
+ import ErrorToastContainer from './toast/ErrorToastContainer';
6
+
7
+ declare const process: any;
8
+
9
+ if (!global.setImmediate) {
10
+ global.setImmediate = function (fn) {
11
+ return setTimeout(fn, 0);
12
+ };
13
+ }
14
+
15
+ if (process.env.NODE_ENV === 'development') {
16
+ if (Platform.OS === 'web') {
17
+ // Stack traces are big with React Navigation
18
+
19
+ require('./LogBox').default.install();
20
+ }
21
+ }
22
+
23
+ export function withErrorOverlay(Comp: React.ComponentType<any>) {
24
+ if (process.env.NODE_ENV === 'production') {
25
+ return Comp;
26
+ }
27
+ return function ErrorOverlay(props: any) {
28
+ return (
29
+ <ErrorToastContainer>
30
+ <Comp {...props} />
31
+ </ErrorToastContainer>
32
+ );
33
+ };
34
+ }
@@ -0,0 +1,4 @@
1
+ // @ts-expect-error
2
+ import ExceptionsManager from 'react-native/Library/Core/ExceptionsManager';
3
+
4
+ export default ExceptionsManager;
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Copyright (c) 650 Industries.
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ import parseErrorStack from '../parseErrorStack';
10
+
11
+ type ExtendedError = any;
12
+
13
+ class SyntheticError extends Error {
14
+ name: string = '';
15
+ }
16
+
17
+ /**
18
+ * Handles the developer-visible aspect of errors and exceptions
19
+ */
20
+ let exceptionID = 0;
21
+
22
+ function parseException(e: ExtendedError, isFatal: boolean) {
23
+ const stack = parseErrorStack(e?.stack);
24
+ const currentExceptionID = ++exceptionID;
25
+ const originalMessage = e.message || '';
26
+ let message = originalMessage;
27
+ if (e.componentStack != null) {
28
+ message += `\n\nThis error is located at:${e.componentStack}`;
29
+ }
30
+ const namePrefix = e.name == null || e.name === '' ? '' : `${e.name}: `;
31
+
32
+ if (!message.startsWith(namePrefix)) {
33
+ message = namePrefix + message;
34
+ }
35
+
36
+ message = e.jsEngine == null ? message : `${message}, js engine: ${e.jsEngine}`;
37
+
38
+ const data = {
39
+ message,
40
+ originalMessage: message === originalMessage ? null : originalMessage,
41
+ name: e.name == null || e.name === '' ? null : e.name,
42
+ componentStack: typeof e.componentStack === 'string' ? e.componentStack : null,
43
+ stack,
44
+ id: currentExceptionID,
45
+ isFatal,
46
+ extraData: {
47
+ jsEngine: e.jsEngine,
48
+ rawStack: e.stack,
49
+ },
50
+ };
51
+
52
+ return {
53
+ ...data,
54
+ isComponentError: !!e.isComponentError,
55
+ };
56
+ }
57
+
58
+ /**
59
+ * Logs exceptions to the (native) console and displays them
60
+ */
61
+ function handleException(e: any) {
62
+ let error: Error;
63
+ if (e instanceof Error) {
64
+ error = e;
65
+ } else {
66
+ // Workaround for reporting errors caused by `throw 'some string'`
67
+ // Unfortunately there is no way to figure out the stacktrace in this
68
+ // case, so if you ended up here trying to trace an error, look for
69
+ // `throw '<error message>'` somewhere in your codebase.
70
+ error = new SyntheticError(e);
71
+ }
72
+
73
+ require('../../LogBox').default.addException(parseException(error, true));
74
+ }
75
+
76
+ const ErrorUtils = {
77
+ parseException,
78
+ handleException,
79
+ SyntheticError,
80
+ };
81
+
82
+ export default ErrorUtils;
@@ -0,0 +1,3 @@
1
+ import NativeLogBox from 'react-native/Libraries/NativeModules/specs/NativeLogBox';
2
+
3
+ export default NativeLogBox;
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+ import ReactDOM from 'react-dom/client';
3
+ let currentRoot: ReactDOM.Root | null = null;
4
+ export default {
5
+ show() {
6
+ if (currentRoot) {
7
+ return;
8
+ }
9
+ const ErrorOverlay: React.ComponentType = require('../../ErrorOverlay').default;
10
+ // Create a new div with ID `error-overlay` element and render LogBoxInspector into it.
11
+ const div = document.createElement('div');
12
+ div.id = 'error-overlay';
13
+ document.body.appendChild(div);
14
+
15
+ currentRoot = ReactDOM.createRoot(div);
16
+ currentRoot.render(<ErrorOverlay />);
17
+ },
18
+ hide() {
19
+ // Remove div with ID `error-overlay`
20
+ if (currentRoot) {
21
+ currentRoot.unmount();
22
+ currentRoot = null;
23
+ }
24
+ const div = document.getElementById('error-overlay');
25
+ div?.remove();
26
+ },
27
+ };
@@ -0,0 +1,3 @@
1
+ import openFileInEditor from 'react-native/Libraries/Core/Devtools/openFileInEditor';
2
+
3
+ export default openFileInEditor;