@logbrew/react-native 0.1.39 → 0.1.40

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 (96) hide show
  1. package/android-native-diagnostics.d.ts +15 -5
  2. package/android-native-diagnostics.js +170 -94
  3. package/apollo.cjs +435 -226
  4. package/apollo.d.cts +2 -70
  5. package/apollo.d.ts +24 -12
  6. package/apollo.js +438 -221
  7. package/apple-native-diagnostics-config.js +176 -0
  8. package/apple-native-diagnostics-context.js +232 -0
  9. package/apple-native-diagnostics-module.js +229 -0
  10. package/apple-native-diagnostics.d.ts +42 -11
  11. package/apple-native-diagnostics.js +60 -389
  12. package/expo.cjs +29 -16
  13. package/expo.d.ts +10 -9
  14. package/expo.js +4 -3
  15. package/fatal-admission.cjs +113 -0
  16. package/fatal-record.cjs +317 -0
  17. package/fatal-replay.cjs +297 -508
  18. package/global-errors-capture.cjs +369 -0
  19. package/global-errors-event.cjs +174 -0
  20. package/global-errors-support.cjs +128 -0
  21. package/global-errors.cjs +75 -351
  22. package/global-errors.d.cts +29 -278
  23. package/global-errors.d.ts +57 -27
  24. package/global-errors.js +7 -2
  25. package/global-errors.native.js +83 -48
  26. package/index-breadcrumbs.cjs +139 -0
  27. package/index-errors.cjs +167 -0
  28. package/index-events.cjs +365 -0
  29. package/index-navigation.cjs +327 -0
  30. package/index-random.cjs +120 -0
  31. package/index-react.cjs +189 -0
  32. package/index-spans.cjs +190 -0
  33. package/index-trace-fetch.cjs +322 -0
  34. package/index-trace.cjs +335 -0
  35. package/index-transport.cjs +201 -0
  36. package/index-values.cjs +232 -0
  37. package/index.cjs +95 -1243
  38. package/index.d.cts +2 -505
  39. package/index.d.ts +130 -469
  40. package/index.native.d.ts +146 -22
  41. package/index.native.js +184 -159
  42. package/instrumentation-fetch.cjs +113 -0
  43. package/instrumentation-install.cjs +241 -0
  44. package/instrumentation-runtime.cjs +65 -0
  45. package/instrumentation-teardown.cjs +93 -0
  46. package/instrumentation-values.cjs +282 -0
  47. package/instrumentation-xhr-request.cjs +298 -0
  48. package/instrumentation-xhr.cjs +233 -0
  49. package/instrumentation.cjs +110 -599
  50. package/instrumentation.d.cts +2 -84
  51. package/instrumentation.d.ts +22 -8
  52. package/ios/AppleDiagnostics/LBRNAppleNativeDiagnostics.swift +1 -1
  53. package/lifecycle.cjs +181 -78
  54. package/lifecycle.d.cts +1 -50
  55. package/lifecycle.d.ts +17 -6
  56. package/metadata.cjs +279 -114
  57. package/metro-debug-id.cjs +296 -0
  58. package/metro-serializer.cjs +219 -0
  59. package/metro.cjs +153 -297
  60. package/metro.d.cts +2 -57
  61. package/metro.d.ts +27 -13
  62. package/metro.js +2 -3
  63. package/native-bridge-async.cjs +165 -0
  64. package/native-bridge-scope.cjs +148 -0
  65. package/native-bridge.cjs +83 -186
  66. package/native-bridge.d.cts +2 -94
  67. package/native-bridge.d.ts +28 -15
  68. package/native-client-bindings.js +230 -0
  69. package/native-diagnostics-values.js +120 -0
  70. package/native-module-lookup.js +31 -0
  71. package/native-null.js +3 -0
  72. package/null-value.cjs +4 -0
  73. package/package.json +43 -1
  74. package/persistent-delivery-store.js +247 -0
  75. package/persistent-delivery.native.js +183 -261
  76. package/promise-rejection-handlers.cjs +368 -0
  77. package/promise-rejections.cjs +169 -361
  78. package/react-native.config.js +3 -1
  79. package/release-artifacts-files.cjs +94 -0
  80. package/release-artifacts-options.cjs +182 -0
  81. package/release-artifacts.cjs +278 -207
  82. package/release-artifacts.d.cts +2 -55
  83. package/release-artifacts.d.ts +18 -7
  84. package/release-artifacts.js +2 -4
  85. package/resource-fetch-graphql.cjs +265 -0
  86. package/resource-fetch-size.cjs +156 -0
  87. package/resource-fetch.cjs +227 -428
  88. package/resource-fetch.d.cts +1 -60
  89. package/resource-fetch.d.ts +17 -6
  90. package/scripts/sync-apple-native-sources.mjs +101 -53
  91. package/types/capture.d.ts +95 -0
  92. package/types/config.d.ts +85 -0
  93. package/types/defaults.d.ts +55 -0
  94. package/types/events.d.ts +203 -0
  95. package/types/provider.d.ts +81 -0
  96. package/types/trace.d.ts +104 -0
@@ -1,15 +1,33 @@
1
1
  "use strict";
2
2
 
3
- const { createReactNativeErrorEvent } = require("./index.cjs");
4
- const { captureIssueWithAdmission } = require("./fatal-replay.cjs");
5
-
6
- const AUTOMATIC_MESSAGE = "Unhandled Promise rejection";
7
- const DEFAULT_MAX_TRACKED_REJECTIONS = 128;
8
- const MAX_TRACKED_REJECTIONS = 1024;
9
- const MAX_STRING_ID_LENGTH = 128;
3
+ const { createPromiseRejectionHandlers, inactiveHandlers } = require("./promise-rejection-handlers.cjs");
4
+ const { emitDiagnostic, isObjectLike, safeFunction, safeReadProperty } = require("./global-errors-support.cjs");
5
+
6
+ /**
7
+ * @import { UnknownFunction } from "./global-errors-support.cjs"
8
+ * @import {
9
+ * LogBrewReactNativePromiseRejectionHandlers,
10
+ * LogBrewReactNativePromiseRejectionTrackerInstallation,
11
+ * ReactNativePromiseRejectionTrackerHealth
12
+ * } from "./global-errors.cjs"
13
+ * @typedef {ReactNativePromiseRejectionTrackerHealth["engine"]} TrackerEngine
14
+ * @typedef {ReactNativePromiseRejectionTrackerHealth["lastOutcome"]} TrackerOutcome
15
+ * @typedef {Readonly<{
16
+ * enable: UnknownFunction,
17
+ * engine: TrackerEngine,
18
+ * handlers: LogBrewReactNativePromiseRejectionHandlers,
19
+ * onDiagnostic: unknown,
20
+ * tracker: object
21
+ * }>} TrackerOwnershipOptions
22
+ */
23
+
24
+ /** @type {WeakMap<object, LogBrewReactNativePromiseRejectionTrackerInstallation>} */
10
25
  const activeTrackerInstallations = new WeakMap();
11
- let nextEventSequence = 0;
12
26
 
27
+ /**
28
+ * @param {unknown} [options]
29
+ * @returns {LogBrewReactNativePromiseRejectionHandlers}
30
+ */
13
31
  function createLogBrewReactNativePromiseRejectionHandlers(options = {}) {
14
32
  return createPromiseRejectionHandlers(
15
33
  options,
@@ -17,319 +35,12 @@ function createLogBrewReactNativePromiseRejectionHandlers(options = {}) {
17
35
  );
18
36
  }
19
37
 
20
- function createPromiseRejectionHandlers(options, mechanism) {
21
- const input = isObjectLike(options) ? options : {};
22
- const client = safeReadProperty(input, "client");
23
- const issue = safeFunction(client, "issue");
24
- const onDiagnostic = safeFunction(input, "onDiagnostic");
25
- if (!issue) {
26
- emitDiagnostic(onDiagnostic, "promise_rejection_handler_unavailable");
27
- return inactiveHandlers();
28
- }
29
-
30
- const configuredMaximum = safeReadProperty(input, "maxTrackedRejections");
31
- const maxTrackedRejections = validMaximum(configuredMaximum)
32
- ? configuredMaximum
33
- : DEFAULT_MAX_TRACKED_REJECTIONS;
34
- if (configuredMaximum !== undefined && maxTrackedRejections !== configuredMaximum) {
35
- emitDiagnostic(onDiagnostic, "promise_rejection_configuration_invalid");
36
- }
37
-
38
- const tracked = new Map();
39
- const state = {
40
- capturedEvents: 0,
41
- emittingDiagnostic: false,
42
- evictedRejections: 0,
43
- handledLaterEvents: 0,
44
- handling: false,
45
- lastOutcome: "idle",
46
- suppressedEvents: 0,
47
- unknownHandledEvents: 0,
48
- untrackedEvents: 0
49
- };
50
- let emittedEvictionDiagnostic = false;
51
-
52
- return Object.freeze({
53
- health() {
54
- return healthSnapshot(state, tracked.size, maxTrackedRejections);
55
- },
56
- onHandled(runtimeRejectionId) {
57
- const key = rejectionKey(runtimeRejectionId);
58
- const record = key === undefined ? undefined : tracked.get(key);
59
- if (!record) {
60
- state.unknownHandledEvents = incrementBounded(state.unknownHandledEvents);
61
- state.lastOutcome = "handled_unknown";
62
- return;
63
- }
64
- if (record.handled) {
65
- recordSuppression(
66
- state,
67
- onDiagnostic,
68
- "promise_rejection_duplicate_suppressed",
69
- "duplicate_suppressed"
70
- );
71
- return;
72
- }
73
- record.handled = true;
74
- state.handledLaterEvents = incrementBounded(state.handledLaterEvents);
75
- state.lastOutcome = "handled_later";
76
- },
77
- onUnhandled(runtimeRejectionId) {
78
- if (state.handling) {
79
- recordSuppression(
80
- state,
81
- onDiagnostic,
82
- "promise_rejection_recursive_capture_suppressed",
83
- "recursive_suppressed"
84
- );
85
- return;
86
- }
87
-
88
- const key = rejectionKey(runtimeRejectionId);
89
- if (key !== undefined && tracked.has(key)) {
90
- recordSuppression(
91
- state,
92
- onDiagnostic,
93
- "promise_rejection_duplicate_suppressed",
94
- "duplicate_suppressed"
95
- );
96
- return;
97
- }
98
-
99
- state.handling = true;
100
- try {
101
- if (key === undefined) {
102
- emitStateDiagnostic(state, onDiagnostic, "promise_rejection_id_unavailable");
103
- }
104
- const event = createEvent(mechanism);
105
- const admission = captureIssueWithAdmission(client, issue, event.id, event.timestamp, event.attributes);
106
- if (admission !== "admitted") {
107
- state.lastOutcome = admission === "unavailable"
108
- ? "admission_unavailable"
109
- : admission === "filtered" ? "filtered" : "capture_failed";
110
- emitStateDiagnostic(state, onDiagnostic, admission === "unavailable"
111
- ? "promise_rejection_admission_unavailable"
112
- : admission === "filtered" ? "promise_rejection_filtered" : "promise_rejection_capture_failed");
113
- return;
114
- }
115
- state.capturedEvents = incrementBounded(state.capturedEvents);
116
-
117
- if (key === undefined) {
118
- state.untrackedEvents = incrementBounded(state.untrackedEvents);
119
- state.lastOutcome = "captured_untracked";
120
- return;
121
- }
122
-
123
- let evicted = false;
124
- if (tracked.size === maxTrackedRejections) {
125
- tracked.delete(tracked.keys().next().value);
126
- state.evictedRejections = incrementBounded(state.evictedRejections);
127
- evicted = true;
128
- if (!emittedEvictionDiagnostic) {
129
- emittedEvictionDiagnostic = true;
130
- emitStateDiagnostic(state, onDiagnostic, "promise_rejection_tracking_evicted");
131
- }
132
- }
133
- tracked.set(key, { handled: false });
134
- state.lastOutcome = evicted ? "captured_with_eviction" : "captured";
135
- } catch {
136
- state.lastOutcome = "capture_failed";
137
- emitStateDiagnostic(state, onDiagnostic, "promise_rejection_capture_failed");
138
- } finally {
139
- state.handling = false;
140
- }
141
- }
142
- });
143
- }
144
-
145
- function installLogBrewReactNativePromiseRejectionTracker(options = {}) {
146
- const input = isObjectLike(options) ? options : {};
147
- const onDiagnostic = safeFunction(input, "onDiagnostic");
148
- if (safeReadProperty(input, "takeOwnership") !== true) {
149
- emitDiagnostic(onDiagnostic, "promise_rejection_tracker_ownership_required");
150
- return inactiveTrackerInstallation("ownership_required");
151
- }
152
-
153
- const tracker = safeReadProperty(input, "tracker");
154
- const enable = safeFunction(tracker, "enable");
155
- const engine = safeReadProperty(input, "trackerKind") === "hermes"
156
- ? "hermes"
157
- : isObjectLike(tracker) ? "custom" : "unavailable";
158
- if (!isObjectLike(tracker) || !enable) {
159
- emitDiagnostic(onDiagnostic, "promise_rejection_tracker_unavailable");
160
- return inactiveTrackerInstallation("tracker_unavailable", engine);
161
- }
162
-
163
- const existing = activeTrackerInstallations.get(tracker);
164
- if (existing?.health().active) {
165
- return existing;
166
- }
167
-
168
- const handlers = createPromiseRejectionHandlers(
169
- input,
170
- "logbrew_owned_promise_rejection_tracker"
171
- );
172
- if (!handlers.health().available) {
173
- return inactiveTrackerInstallation("handler_unavailable", engine, handlers);
174
- }
175
-
176
- const state = {
177
- active: true,
178
- lastOutcome: "installed"
179
- };
180
- const trackerOptions = Object.freeze({
181
- allRejections: true,
182
- onHandled(runtimeRejectionId) {
183
- if (state.active) {
184
- handlers.onHandled(runtimeRejectionId);
185
- }
186
- },
187
- onUnhandled(runtimeRejectionId, rejection) {
188
- if (state.active) {
189
- handlers.onUnhandled(runtimeRejectionId, rejection);
190
- }
191
- }
192
- });
193
-
194
- const installation = Object.freeze({
195
- deactivate() {
196
- if (!state.active) {
197
- return false;
198
- }
199
- state.active = false;
200
- state.lastOutcome = "deactivated";
201
- if (activeTrackerInstallations.get(tracker) === installation) {
202
- activeTrackerInstallations.delete(tracker);
203
- }
204
- return true;
205
- },
206
- health() {
207
- return trackerHealthSnapshot(state, engine, true);
208
- },
209
- rejectionHealth() {
210
- return handlers.health();
211
- }
212
- });
213
-
214
- try {
215
- enable.call(tracker, trackerOptions);
216
- } catch {
217
- state.active = false;
218
- state.lastOutcome = "installation_failed";
219
- emitDiagnostic(onDiagnostic, "promise_rejection_tracker_installation_failed");
220
- return inactiveTrackerInstallation(
221
- "installation_failed",
222
- engine,
223
- handlers
224
- );
225
- }
226
-
227
- activeTrackerInstallations.set(tracker, installation);
228
- return installation;
229
- }
230
-
231
- function createEvent(mechanism) {
232
- const error = new Error(AUTOMATIC_MESSAGE);
233
- delete error.stack;
234
- const event = createReactNativeErrorEvent(error, {
235
- id: nextEventId(),
236
- handled: false,
237
- includeStack: false,
238
- mechanism
239
- });
240
- return {
241
- ...event,
242
- attributes: {
243
- ...event.attributes,
244
- title: AUTOMATIC_MESSAGE,
245
- message: AUTOMATIC_MESSAGE,
246
- metadata: {
247
- ...event.attributes.metadata,
248
- automatic: true,
249
- fatal: false,
250
- handled: false,
251
- mechanism,
252
- source: "react-native.promise_rejection"
253
- }
254
- }
255
- };
256
- }
257
-
258
- function rejectionKey(value) {
259
- if (typeof value === "number" && Number.isSafeInteger(value) && value >= 0) {
260
- return `number:${value}`;
261
- }
262
- if (typeof value === "string"
263
- && value.length > 0
264
- && value.length <= MAX_STRING_ID_LENGTH
265
- && !hasControlCharacter(value)) {
266
- return `string:${value}`;
267
- }
268
- return undefined;
269
- }
270
-
271
- function validMaximum(value) {
272
- return Number.isInteger(value) && value >= 1 && value <= MAX_TRACKED_REJECTIONS;
273
- }
274
-
275
- function nextEventId() {
276
- nextEventSequence = incrementBounded(nextEventSequence);
277
- return `evt_rn_promise_${Date.now().toString(36)}_${nextEventSequence.toString(36)}`;
278
- }
279
-
280
- function incrementBounded(value) {
281
- return value >= Number.MAX_SAFE_INTEGER ? Number.MAX_SAFE_INTEGER : value + 1;
282
- }
283
-
284
- function recordSuppression(state, onDiagnostic, code, outcome) {
285
- state.suppressedEvents = incrementBounded(state.suppressedEvents);
286
- state.lastOutcome = outcome;
287
- emitStateDiagnostic(state, onDiagnostic, code);
288
- }
289
-
290
- function emitStateDiagnostic(state, onDiagnostic, code) {
291
- if (state.emittingDiagnostic) {
292
- return;
293
- }
294
- state.emittingDiagnostic = true;
295
- try {
296
- emitDiagnostic(onDiagnostic, code);
297
- } finally {
298
- state.emittingDiagnostic = false;
299
- }
300
- }
301
-
302
- function emitDiagnostic(onDiagnostic, code) {
303
- if (typeof onDiagnostic !== "function") {
304
- return;
305
- }
306
- try {
307
- onDiagnostic(Object.freeze({ code }));
308
- } catch {
309
- // Diagnostics must never interfere with application rejection handling.
310
- }
311
- }
312
-
313
- function inactiveHandlers() {
314
- const snapshot = Object.freeze({
315
- available: false,
316
- capturedEvents: 0,
317
- evictedRejections: 0,
318
- handledLaterEvents: 0,
319
- lastOutcome: "unavailable",
320
- maxTrackedRejections: 0,
321
- suppressedEvents: 0,
322
- trackedRejections: 0,
323
- unknownHandledEvents: 0,
324
- untrackedEvents: 0
325
- });
326
- return Object.freeze({
327
- health: () => snapshot,
328
- onHandled: () => {},
329
- onUnhandled: () => {}
330
- });
331
- }
332
-
38
+ /**
39
+ * @param {TrackerOutcome} lastOutcome
40
+ * @param {TrackerEngine} [engine]
41
+ * @param {LogBrewReactNativePromiseRejectionHandlers} [handlers]
42
+ * @returns {LogBrewReactNativePromiseRejectionTrackerInstallation}
43
+ */
333
44
  function inactiveTrackerInstallation(
334
45
  lastOutcome,
335
46
  engine = "unavailable",
@@ -349,56 +60,153 @@ function inactiveTrackerInstallation(
349
60
  });
350
61
  }
351
62
 
352
- function trackerHealthSnapshot(state, engine, available) {
353
- return Object.freeze({
354
- active: state.active,
355
- available,
356
- engine,
357
- lastOutcome: state.lastOutcome,
358
- restoration: "deactivate_only"
359
- });
360
- }
63
+ class TrackerOwnership {
64
+ active = true;
65
+
66
+ /** @type {TrackerOutcome} */
67
+ lastOutcome = "installed";
68
+
69
+ /**
70
+ * @param {TrackerOwnershipOptions} options
71
+ */
72
+ constructor(options) {
73
+ this.options = options;
74
+ const { handlers } = options;
75
+ this.trackerOptions = Object.freeze({
76
+ allRejections: true,
77
+ /**
78
+ * @param {unknown} runtimeRejectionId
79
+ * @returns {void}
80
+ */
81
+ onHandled: (runtimeRejectionId) => {
82
+ if (this.active) {
83
+ handlers.onHandled(runtimeRejectionId);
84
+ }
85
+ },
86
+ /**
87
+ * @param {unknown} runtimeRejectionId
88
+ * @param {unknown} rejection
89
+ * @returns {void}
90
+ */
91
+ onUnhandled: (runtimeRejectionId, rejection) => {
92
+ if (this.active) {
93
+ handlers.onUnhandled(runtimeRejectionId, rejection);
94
+ }
95
+ }
96
+ });
97
+ }
361
98
 
362
- function healthSnapshot(state, trackedRejections, maxTrackedRejections) {
363
- return Object.freeze({
364
- available: true,
365
- capturedEvents: state.capturedEvents,
366
- evictedRejections: state.evictedRejections,
367
- handledLaterEvents: state.handledLaterEvents,
368
- lastOutcome: state.lastOutcome,
369
- maxTrackedRejections,
370
- suppressedEvents: state.suppressedEvents,
371
- trackedRejections,
372
- unknownHandledEvents: state.unknownHandledEvents,
373
- untrackedEvents: state.untrackedEvents
374
- });
375
- }
99
+ /**
100
+ * @returns {ReactNativePromiseRejectionTrackerHealth}
101
+ */
102
+ health() {
103
+ return Object.freeze({
104
+ active: this.active,
105
+ available: true,
106
+ engine: this.options.engine,
107
+ lastOutcome: this.lastOutcome,
108
+ restoration: "deactivate_only"
109
+ });
110
+ }
376
111
 
377
- function safeReadProperty(value, property) {
378
- if (!isObjectLike(value)) {
379
- return undefined;
112
+ /**
113
+ * @param {LogBrewReactNativePromiseRejectionTrackerInstallation} installation
114
+ * @returns {boolean}
115
+ */
116
+ deactivate(installation) {
117
+ if (!this.active) {
118
+ return false;
119
+ }
120
+ this.active = false;
121
+ this.lastOutcome = "deactivated";
122
+ const { tracker } = this.options;
123
+ if (activeTrackerInstallations.get(tracker) === installation) {
124
+ activeTrackerInstallations.delete(tracker);
125
+ }
126
+ return true;
380
127
  }
381
- try {
382
- return value[property];
383
- } catch {
384
- return undefined;
128
+
129
+ /**
130
+ * @returns {LogBrewReactNativePromiseRejectionTrackerInstallation}
131
+ */
132
+ install() {
133
+ const { enable, engine, handlers, onDiagnostic, tracker } = this.options;
134
+ /** @type {LogBrewReactNativePromiseRejectionTrackerInstallation} */
135
+ const installation = Object.freeze({
136
+ deactivate: () => this.deactivate(installation),
137
+ health: () => this.health(),
138
+ rejectionHealth: () => handlers.health()
139
+ });
140
+ try {
141
+ enable.call(tracker, this.trackerOptions);
142
+ } catch {
143
+ this.active = false;
144
+ this.lastOutcome = "installation_failed";
145
+ emitDiagnostic(onDiagnostic, "promise_rejection_tracker_installation_failed");
146
+ return inactiveTrackerInstallation("installation_failed", engine, handlers);
147
+ }
148
+ activeTrackerInstallations.set(tracker, installation);
149
+ return installation;
385
150
  }
386
151
  }
387
152
 
388
- function safeFunction(value, property) {
389
- const candidate = safeReadProperty(value, property);
390
- return typeof candidate === "function" ? candidate : undefined;
153
+ /**
154
+ * @param {unknown} input
155
+ * @param {unknown} tracker
156
+ * @returns {TrackerEngine}
157
+ */
158
+ function trackerEngine(input, tracker) {
159
+ if (safeReadProperty(input, "trackerKind") === "hermes") {
160
+ return "hermes";
161
+ }
162
+ return isObjectLike(tracker) ? "custom" : "unavailable";
391
163
  }
392
164
 
393
- function hasControlCharacter(value) {
394
- return Array.from(value).some((character) => {
395
- const code = character.codePointAt(0);
396
- return code !== undefined && (code <= 31 || code === 127);
397
- });
165
+ /**
166
+ * @param {object} input
167
+ * @param {Omit<TrackerOwnershipOptions, "handlers">} ownership
168
+ * @returns {LogBrewReactNativePromiseRejectionTrackerInstallation}
169
+ */
170
+ function startTracker(input, ownership) {
171
+ const existing = activeTrackerInstallations.get(ownership.tracker);
172
+ if (existing?.health().active === true) {
173
+ return existing;
174
+ }
175
+ const handlers = createPromiseRejectionHandlers(input, "logbrew_owned_promise_rejection_tracker");
176
+ if (!handlers.health().available) {
177
+ return inactiveTrackerInstallation("handler_unavailable", ownership.engine, handlers);
178
+ }
179
+ return new TrackerOwnership({ ...ownership, handlers }).install();
180
+ }
181
+
182
+ /**
183
+ * @param {object} input
184
+ * @param {UnknownFunction | undefined} onDiagnostic
185
+ * @returns {LogBrewReactNativePromiseRejectionTrackerInstallation}
186
+ */
187
+ function installTracker(input, onDiagnostic) {
188
+ const tracker = safeReadProperty(input, "tracker");
189
+ const enable = safeFunction(tracker, "enable");
190
+ const engine = trackerEngine(input, tracker);
191
+ if (!isObjectLike(tracker) || !enable) {
192
+ emitDiagnostic(onDiagnostic, "promise_rejection_tracker_unavailable");
193
+ return inactiveTrackerInstallation("tracker_unavailable", engine);
194
+ }
195
+ return startTracker(input, { enable, engine, onDiagnostic, tracker });
398
196
  }
399
197
 
400
- function isObjectLike(value) {
401
- return value !== null && (typeof value === "object" || typeof value === "function");
198
+ /**
199
+ * @param {unknown} [options]
200
+ * @returns {LogBrewReactNativePromiseRejectionTrackerInstallation}
201
+ */
202
+ function installLogBrewReactNativePromiseRejectionTracker(options = {}) {
203
+ const input = isObjectLike(options) ? options : {};
204
+ const onDiagnostic = safeFunction(input, "onDiagnostic");
205
+ if (safeReadProperty(input, "takeOwnership") !== true) {
206
+ emitDiagnostic(onDiagnostic, "promise_rejection_tracker_ownership_required");
207
+ return inactiveTrackerInstallation("ownership_required");
208
+ }
209
+ return installTracker(input, onDiagnostic);
402
210
  }
403
211
 
404
212
  module.exports = {
@@ -1,4 +1,4 @@
1
- export default {
1
+ const config = {
2
2
  dependency: {
3
3
  platforms: {
4
4
  android: {
@@ -9,3 +9,5 @@ export default {
9
9
  }
10
10
  }
11
11
  };
12
+
13
+ export default config;
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+
3
+ const fs = require("node:fs");
4
+ const path = require("node:path");
5
+
6
+ const HERMES_MAGIC = Buffer.from("c61fbc03c103191f", "hex");
7
+ const HERMES_RUNTIME_DEBUG_ID_RE =
8
+ /\/\*logbrew-runtime-debug-id\*\/\/\/# debugId=[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/iu;
9
+ const SOURCE_MAPPING_COMMENT_RE = /(?:\/\/#|\/\*#)\s*sourceMappingURL=[^\r\n]*/giu;
10
+ const TRAILING_WHITESPACE_RE = /[ \t\r\n]*$/u;
11
+ const START = 0;
12
+
13
+ /**
14
+ * @param {string} root
15
+ * @param {string} value
16
+ * @returns {string}
17
+ */
18
+ function resolvePathFromRoot(root, value) {
19
+ return path.isAbsolute(value) ? path.resolve(value) : path.resolve(root, value);
20
+ }
21
+
22
+ /**
23
+ * @param {string} label
24
+ * @param {string} filePath
25
+ * @returns {void}
26
+ */
27
+ function requireExistingFile(label, filePath) {
28
+ if (!fs.existsSync(filePath) || !fs.statSync(filePath).isFile()) {
29
+ throw new Error(`LogBrew React Native release-artifact helper ${label} does not exist: ${filePath}`);
30
+ }
31
+ }
32
+
33
+ /**
34
+ * @param {string} label
35
+ * @param {string} filePath
36
+ * @param {string} buildDir
37
+ * @returns {string}
38
+ */
39
+ function ensureInsideBuildDir(label, filePath, buildDir) {
40
+ const relative = path.relative(buildDir, filePath);
41
+ if (relative === "" || relative.startsWith("..") || path.isAbsolute(relative)) {
42
+ throw new Error(`LogBrew React Native release-artifact helper ${label} must stay inside buildDir`);
43
+ }
44
+ return relative.split(path.sep).join("/");
45
+ }
46
+
47
+ /**
48
+ * @param {string} source
49
+ * @param {string} reference
50
+ * @returns {string}
51
+ */
52
+ function sourceWithSourceMappingUrl(source, reference) {
53
+ const sourceWithoutMapComments = source.replaceAll(SOURCE_MAPPING_COMMENT_RE, "").replace(TRAILING_WHITESPACE_RE, "");
54
+ return `${sourceWithoutMapComments}${sourceWithoutMapComments === "" ? "" : "\n"}//# sourceMappingURL=${reference}\n`;
55
+ }
56
+
57
+ /**
58
+ * @param {Buffer} bundle
59
+ * @param {string} bundlePath
60
+ * @param {string} sourcemapPath
61
+ * @returns {boolean}
62
+ */
63
+ function isHermesBytecode(bundle, bundlePath, sourcemapPath) {
64
+ if (!bundle.subarray(START, HERMES_MAGIC.length).equals(HERMES_MAGIC)) {
65
+ return false;
66
+ }
67
+ if (!HERMES_RUNTIME_DEBUG_ID_RE.test(bundle.toString("latin1"))) {
68
+ throw new Error("LogBrew React Native Hermes bytecode requires the LogBrew Metro wrapper");
69
+ }
70
+ if (sourcemapPath !== `${bundlePath}.map`) {
71
+ throw new Error("LogBrew React Native Hermes source map must use the bundle's sibling .map path");
72
+ }
73
+ return true;
74
+ }
75
+
76
+ /**
77
+ * @param {string} bundlePath
78
+ * @param {string} sourcemapPath
79
+ * @returns {void}
80
+ */
81
+ function applyExplicitSourceMapReference(bundlePath, sourcemapPath) {
82
+ const bundle = fs.readFileSync(bundlePath);
83
+ if (isHermesBytecode(bundle, bundlePath, sourcemapPath)) {
84
+ return;
85
+ }
86
+ const reference = path.relative(path.dirname(bundlePath), sourcemapPath).split(path.sep).join("/");
87
+ const source = bundle.toString("utf8");
88
+ const updated = sourceWithSourceMappingUrl(source, reference);
89
+ if (updated !== source) {
90
+ fs.writeFileSync(bundlePath, updated, "utf8");
91
+ }
92
+ }
93
+
94
+ module.exports = { applyExplicitSourceMapReference, ensureInsideBuildDir, requireExistingFile, resolvePathFromRoot };