@rnperf/sdk 0.0.0-stage → 0.1.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/dist/probes.js ADDED
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ /**
3
+ * Runtime probes. Every one of these degrades to "no data" rather than
4
+ * throwing: the SDK runs inside someone else's app and must never be the
5
+ * reason it crashes.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.BridgeProbe = exports.StallProbe = exports.FpsProbe = void 0;
9
+ exports.readJsHeap = readJsHeap;
10
+ exports.isHermes = isHermes;
11
+ exports.now = now;
12
+ const rn_js_1 = require("./rn.js");
13
+ /* --------------------------------------------------------------- JS FPS */
14
+ /**
15
+ * Counts animation frames the JS thread actually serviced. React Native drives
16
+ * `requestAnimationFrame` from the JS thread, so a shortfall here is a direct
17
+ * measure of JS thread saturation — the thing that makes touch handling feel
18
+ * sticky even when the UI thread is fine.
19
+ */
20
+ class FpsProbe {
21
+ frames = 0;
22
+ windowStart = now();
23
+ running = false;
24
+ rafId = null;
25
+ start() {
26
+ if (this.running)
27
+ return;
28
+ this.running = true;
29
+ this.windowStart = now();
30
+ this.frames = 0;
31
+ const loop = () => {
32
+ if (!this.running)
33
+ return;
34
+ this.frames += 1;
35
+ this.rafId = safeRaf(loop);
36
+ };
37
+ this.rafId = safeRaf(loop);
38
+ }
39
+ /** Frames per second since the last read, then resets the window. */
40
+ read() {
41
+ const elapsed = now() - this.windowStart;
42
+ if (elapsed < 100)
43
+ return undefined;
44
+ const fps = (this.frames * 1000) / elapsed;
45
+ this.frames = 0;
46
+ this.windowStart = now();
47
+ // A backgrounded app stops producing frames entirely; reporting 0 would
48
+ // look like a catastrophic stall rather than an idle app.
49
+ return Math.min(fps, 120);
50
+ }
51
+ stop() {
52
+ this.running = false;
53
+ if (this.rafId !== null && typeof global.cancelAnimationFrame === 'function') {
54
+ try {
55
+ global.cancelAnimationFrame(this.rafId);
56
+ }
57
+ catch { /* ignore */ }
58
+ }
59
+ this.rafId = null;
60
+ }
61
+ }
62
+ exports.FpsProbe = FpsProbe;
63
+ /* ------------------------------------------------------------- JS stalls */
64
+ /**
65
+ * Measures how late a fixed-period timer actually fires. Drift is time the JS
66
+ * thread spent inside one synchronous block, which is what users experience as
67
+ * a freeze. FPS alone cannot distinguish "steadily slow" from "fine, then a
68
+ * 400ms lockup" — this can.
69
+ */
70
+ class StallProbe {
71
+ timer = null;
72
+ expected = 0;
73
+ maxStall = 0;
74
+ stallCount = 0;
75
+ periodMs;
76
+ thresholdMs;
77
+ constructor(periodMs = 50, thresholdMs = 100) {
78
+ this.periodMs = periodMs;
79
+ this.thresholdMs = thresholdMs;
80
+ }
81
+ start() {
82
+ if (this.timer)
83
+ return;
84
+ this.expected = now() + this.periodMs;
85
+ this.timer = setInterval(() => {
86
+ const current = now();
87
+ const drift = current - this.expected;
88
+ this.expected = current + this.periodMs;
89
+ if (drift > this.thresholdMs) {
90
+ this.stallCount += 1;
91
+ if (drift > this.maxStall)
92
+ this.maxStall = drift;
93
+ }
94
+ }, this.periodMs);
95
+ }
96
+ read() {
97
+ const result = { jsStallMaxMs: this.maxStall, jsStallCount: this.stallCount };
98
+ this.maxStall = 0;
99
+ this.stallCount = 0;
100
+ return result;
101
+ }
102
+ stop() {
103
+ if (this.timer)
104
+ clearInterval(this.timer);
105
+ this.timer = null;
106
+ }
107
+ }
108
+ exports.StallProbe = StallProbe;
109
+ /* --------------------------------------------------------------- JS heap */
110
+ /** Hermes exposes allocator stats; JSC and V8 expose `performance.memory`. */
111
+ function readJsHeap() {
112
+ const toMb = (bytes) => Math.round((bytes / (1024 * 1024)) * 100) / 100;
113
+ try {
114
+ const hermes = global.HermesInternal;
115
+ if (hermes && typeof hermes.getInstrumentedStats === 'function') {
116
+ const stats = hermes.getInstrumentedStats();
117
+ const used = stats.js_allocatedBytes ?? stats.js_heapSize;
118
+ const total = stats.js_heapSize ?? stats.js_totalAllocatedBytes;
119
+ if (typeof used === 'number') {
120
+ return {
121
+ jsHeapMB: toMb(used),
122
+ jsHeapTotalMB: typeof total === 'number' ? toMb(total) : undefined,
123
+ };
124
+ }
125
+ }
126
+ }
127
+ catch { /* fall through */ }
128
+ try {
129
+ const mem = global.performance?.memory;
130
+ if (mem && typeof mem.usedJSHeapSize === 'number') {
131
+ return { jsHeapMB: toMb(mem.usedJSHeapSize), jsHeapTotalMB: toMb(mem.totalJSHeapSize ?? 0) };
132
+ }
133
+ }
134
+ catch { /* fall through */ }
135
+ return {};
136
+ }
137
+ function isHermes() {
138
+ return Boolean(global.HermesInternal);
139
+ }
140
+ /* --------------------------------------------------------------- bridge */
141
+ /**
142
+ * Counts calls crossing the legacy bridge by installing MessageQueue's spy
143
+ * hook on the live bridge instance. Under the new architecture most calls are
144
+ * synchronous JSI and never appear here, so a zero reading means "nothing on
145
+ * the bridge", not "nothing happening".
146
+ */
147
+ class BridgeProbe {
148
+ calls = 0;
149
+ installed = false;
150
+ start() {
151
+ if (this.installed)
152
+ return true;
153
+ try {
154
+ const bridge = (0, rn_js_1.getBatchedBridge)();
155
+ if (bridge) {
156
+ // MessageQueue checks `this.__spy` on every call it dispatches.
157
+ bridge.__spy = () => { this.calls += 1; };
158
+ this.installed = true;
159
+ }
160
+ }
161
+ catch { /* bridge spying unavailable */ }
162
+ return this.installed;
163
+ }
164
+ read() {
165
+ if (!this.installed)
166
+ return undefined;
167
+ const value = this.calls;
168
+ this.calls = 0;
169
+ return value;
170
+ }
171
+ stop() {
172
+ try {
173
+ const bridge = (0, rn_js_1.getBatchedBridge)();
174
+ if (bridge)
175
+ bridge.__spy = null;
176
+ }
177
+ catch { /* ignore */ }
178
+ this.installed = false;
179
+ }
180
+ }
181
+ exports.BridgeProbe = BridgeProbe;
182
+ /* --------------------------------------------------------------- helpers */
183
+ function now() {
184
+ if (typeof global.nativePerformanceNow === 'function')
185
+ return global.nativePerformanceNow();
186
+ if (global.performance && typeof global.performance.now === 'function')
187
+ return global.performance.now();
188
+ return Date.now();
189
+ }
190
+ function safeRaf(fn) {
191
+ try {
192
+ if (typeof global.requestAnimationFrame === 'function')
193
+ return global.requestAnimationFrame(fn);
194
+ }
195
+ catch { /* ignore */ }
196
+ // Without rAF there is no frame signal at all; a timer would measure the
197
+ // timer, not the frame loop, so report nothing instead of something wrong.
198
+ return null;
199
+ }
200
+ /**
201
+ * Metro resolves `require` at build time, so these deep imports have to go
202
+ * through an indirect lookup to stay optional — the SDK must not hard-fail in
203
+ * an app that has tree-shaken or renamed an internal module.
204
+ */
205
+ //# sourceMappingURL=probes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"probes.js","sourceRoot":"","sources":["../src/probes.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAyGH,gCA0BC;AAED,4BAEC;AA6CD,kBAIC;AAtLD,mCAA2C;AAI3C,4EAA4E;AAE5E;;;;;GAKG;AACH,MAAa,QAAQ;IACX,MAAM,GAAG,CAAC,CAAC;IACX,WAAW,GAAG,GAAG,EAAE,CAAC;IACpB,OAAO,GAAG,KAAK,CAAC;IAChB,KAAK,GAAkB,IAAI,CAAC;IAEpC,KAAK;QACH,IAAI,IAAI,CAAC,OAAO;YAAE,OAAO;QACzB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,CAAC,WAAW,GAAG,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QAChB,MAAM,IAAI,GAAG,GAAG,EAAE;YAChB,IAAI,CAAC,IAAI,CAAC,OAAO;gBAAE,OAAO;YAC1B,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC;YACjB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAC7B,CAAC,CAAC;QACF,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED,qEAAqE;IACrE,IAAI;QACF,MAAM,OAAO,GAAG,GAAG,EAAE,GAAG,IA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C,qBAAqB,CAAC,EAAE,CAAC,CAAC;IAClG,CAAC;IAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC;IACxB,yEAAyE;IACzE,2EAA2E;IAC3E,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;GAIG"}
@@ -0,0 +1,23 @@
1
+ import type { ComponentRenderStat } from './types.js';
2
+ /**
3
+ * Attributes render work to components by reading React's own commit data.
4
+ *
5
+ * React populates `actualDuration` on every fiber in a profiling build, which
6
+ * development bundles are. A fiber whose `actualDuration` is zero did not
7
+ * re-render, and because the value is inclusive of children, a zero also means
8
+ * nothing below it re-rendered — so whole subtrees can be skipped. That prune
9
+ * is what makes walking the tree on every commit affordable.
10
+ */
11
+ export declare class RenderTracker {
12
+ private stats;
13
+ private installed;
14
+ private previousHandler?;
15
+ private hook?;
16
+ install(): boolean;
17
+ private walk;
18
+ private record;
19
+ /** Returns everything accumulated since the last read, then resets. */
20
+ read(): Record<string, ComponentRenderStat> | undefined;
21
+ uninstall(): void;
22
+ }
23
+ //# sourceMappingURL=renders.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renders.d.ts","sourceRoot":"","sources":["../src/renders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AA0BtD;;;;;;;;GAQG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,KAAK,CAA0C;IACvD,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,eAAe,CAAC,CAA8D;IACtF,OAAO,CAAC,IAAI,CAAC,CAAM;IAEnB,OAAO,IAAI,OAAO;IAwBlB,OAAO,CAAC,IAAI;IAoBZ,OAAO,CAAC,MAAM;IA4Bd,uEAAuE;IACvE,IAAI,IAAI,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,GAAG,SAAS;IAevD,SAAS,IAAI,IAAI;CAMlB"}
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RenderTracker = void 0;
4
+ /* React fiber tags we care about — everything else is a host view or internal. */
5
+ const FUNCTION_COMPONENT = 0;
6
+ const CLASS_COMPONENT = 1;
7
+ const FORWARD_REF = 11;
8
+ const MEMO_COMPONENT = 14;
9
+ const SIMPLE_MEMO_COMPONENT = 15;
10
+ const TRACKED_TAGS = new Set([
11
+ FUNCTION_COMPONENT, CLASS_COMPONENT, FORWARD_REF, MEMO_COMPONENT, SIMPLE_MEMO_COMPONENT,
12
+ ]);
13
+ /**
14
+ * Attributes render work to components by reading React's own commit data.
15
+ *
16
+ * React populates `actualDuration` on every fiber in a profiling build, which
17
+ * development bundles are. A fiber whose `actualDuration` is zero did not
18
+ * re-render, and because the value is inclusive of children, a zero also means
19
+ * nothing below it re-rendered — so whole subtrees can be skipped. That prune
20
+ * is what makes walking the tree on every commit affordable.
21
+ */
22
+ class RenderTracker {
23
+ stats = new Map();
24
+ installed = false;
25
+ previousHandler;
26
+ hook;
27
+ install() {
28
+ if (this.installed)
29
+ return true;
30
+ const hook = global.__REACT_DEVTOOLS_GLOBAL_HOOK__;
31
+ if (!hook) {
32
+ // React has not been loaded yet, or DevTools support was stripped. The
33
+ // caller decides whether to warn; render data is simply unavailable.
34
+ return false;
35
+ }
36
+ this.hook = hook;
37
+ this.previousHandler = hook.onCommitFiberRoot;
38
+ hook.onCommitFiberRoot = (rendererId, root, priority) => {
39
+ try {
40
+ this.walk(root?.current ?? null);
41
+ }
42
+ catch {
43
+ // Never let instrumentation break a commit.
44
+ }
45
+ try {
46
+ this.previousHandler?.call(hook, rendererId, root, priority);
47
+ }
48
+ catch { /* the other listener's problem */ }
49
+ };
50
+ this.installed = true;
51
+ return true;
52
+ }
53
+ walk(root) {
54
+ if (!root)
55
+ return;
56
+ // Iterative traversal: a deep React Native tree can blow a recursive stack.
57
+ const stack = [root];
58
+ while (stack.length) {
59
+ const fiber = stack.pop();
60
+ const duration = fiber.actualDuration ?? 0;
61
+ // Inclusive of children, so zero prunes the whole subtree.
62
+ if (duration <= 0)
63
+ continue;
64
+ if (TRACKED_TAGS.has(fiber.tag)) {
65
+ const name = displayName(fiber);
66
+ if (name)
67
+ this.record(name, fiber, duration);
68
+ }
69
+ for (let child = fiber.child; child; child = child.sibling)
70
+ stack.push(child);
71
+ }
72
+ }
73
+ record(name, fiber, duration) {
74
+ // Self time: a parent's duration includes its children's, and charging the
75
+ // same milliseconds to every ancestor would make the root look like the
76
+ // hotspot in every single app.
77
+ let childDuration = 0;
78
+ for (let child = fiber.child; child; child = child.sibling) {
79
+ childDuration += child.actualDuration ?? 0;
80
+ }
81
+ const selfMs = Math.max(0, duration - childDuration);
82
+ const existing = this.stats.get(name);
83
+ const entry = existing ?? { count: 0, totalMs: 0, maxMs: 0, wasted: 0 };
84
+ entry.count += 1;
85
+ entry.totalMs += selfMs;
86
+ if (selfMs > entry.maxMs)
87
+ entry.maxMs = selfMs;
88
+ // A render whose props are shallow-equal to the previous commit's did no
89
+ // useful work — the signature of a missing React.memo or a callback prop
90
+ // that gets a new identity on every parent render.
91
+ const props = fiber.memoizedProps;
92
+ const previousProps = fiber.alternate?.memoizedProps;
93
+ if (props && previousProps && typeof props === 'object' && shallowEqual(previousProps, props)) {
94
+ entry.wasted = (entry.wasted ?? 0) + 1;
95
+ }
96
+ this.stats.set(name, entry);
97
+ }
98
+ /** Returns everything accumulated since the last read, then resets. */
99
+ read() {
100
+ if (this.stats.size === 0)
101
+ return undefined;
102
+ const out = {};
103
+ for (const [name, stat] of this.stats) {
104
+ out[name] = {
105
+ count: stat.count,
106
+ totalMs: Math.round(stat.totalMs * 100) / 100,
107
+ maxMs: Math.round(stat.maxMs * 100) / 100,
108
+ ...(stat.wasted ? { wasted: stat.wasted } : {}),
109
+ };
110
+ }
111
+ this.stats.clear();
112
+ return out;
113
+ }
114
+ uninstall() {
115
+ if (!this.installed || !this.hook)
116
+ return;
117
+ this.hook.onCommitFiberRoot = this.previousHandler;
118
+ this.installed = false;
119
+ this.stats.clear();
120
+ }
121
+ }
122
+ exports.RenderTracker = RenderTracker;
123
+ function displayName(fiber) {
124
+ const type = fiber.elementType ?? fiber.type;
125
+ if (!type)
126
+ return null;
127
+ // memo()/forwardRef() wrap the real component one or two levels down.
128
+ const candidates = [type, type.type, type.render, type.type?.type, type.type?.render];
129
+ for (const candidate of candidates) {
130
+ if (!candidate)
131
+ continue;
132
+ const name = candidate.displayName ?? candidate.name;
133
+ if (typeof name === 'string' && name.length > 0 && name !== 'Unknown') {
134
+ // Strip the wrappers HOCs add, so `Memo(ProductCard)` reports as ProductCard.
135
+ return name.replace(/^(Memo|ForwardRef|Anonymous)\(?/, '').replace(/\)$/, '') || null;
136
+ }
137
+ }
138
+ return null;
139
+ }
140
+ function shallowEqual(a, b) {
141
+ if (a === b)
142
+ return true;
143
+ if (!a || !b)
144
+ return false;
145
+ const aKeys = Object.keys(a);
146
+ const bKeys = Object.keys(b);
147
+ if (aKeys.length !== bKeys.length)
148
+ return false;
149
+ for (const key of aKeys) {
150
+ if (key === 'children')
151
+ continue; // a new element object every render by design
152
+ if (!Object.is(a[key], b[key]))
153
+ return false;
154
+ }
155
+ return true;
156
+ }
157
+ //# sourceMappingURL=renders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renders.js","sourceRoot":"","sources":["../src/renders.ts"],"names":[],"mappings":";;;AAIA,kFAAkF;AAClF,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,MAAM,eAAe,GAAG,CAAC,CAAC;AAC1B,MAAM,WAAW,GAAG,EAAE,CAAC;AACvB,MAAM,cAAc,GAAG,EAAE,CAAC;AAC1B,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAEjC,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC;IAC3B,kBAAkB,EAAE,eAAe,EAAE,WAAW,EAAE,cAAc,EAAE,qBAAqB;CACxF,CAAC,CAAC;AAaH;;;;;;;;GAQG;AACH,MAAa,aAAa;IAChB,KAAK,GAAG,IAAI,GAAG,EAA+B,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K,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC7B,IAAI,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAChD,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;QACxB,IAAI,GAAG,KAAK,UAAU;YAAE,SAAS,CAAC,8CAA8C;QAChF,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;IAC/C,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
package/dist/rn.d.ts ADDED
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Access to React Native's own modules.
3
+ *
4
+ * A literal `require` is what Metro resolves at build time; `global.require`
5
+ * is Metro's internal numeric-id loader and does not take module names, so
6
+ * reaching for it silently yields undefined inside a real bundle. The
7
+ * try/catch keeps the package importable outside React Native (tests, tooling)
8
+ * where the peer dependency is absent.
9
+ */
10
+ export interface NativeModuleRegistry {
11
+ [name: string]: any;
12
+ }
13
+ export declare const NativeModules: NativeModuleRegistry;
14
+ export declare const Platform: {
15
+ OS: string;
16
+ constants?: any;
17
+ };
18
+ export declare const isReactNative: boolean;
19
+ /**
20
+ * React Native's batched bridge instance, used to count calls crossing it.
21
+ * Reached through the global rather than by importing MessageQueue, so a
22
+ * future reshuffle of React Native's internals cannot break the bundle.
23
+ */
24
+ export declare function getBatchedBridge(): any;
25
+ /**
26
+ * Whether this looks like an Expo runtime. Detected through globals and the
27
+ * module registry, never by requiring an Expo package: that package is absent
28
+ * in a bare app and a literal require of it would fail the build there.
29
+ */
30
+ export declare function isExpoRuntime(): boolean;
31
+ /** The app's own bundle id, where a module that exposes it is installed. */
32
+ export declare function inferBundleId(): string | undefined;
33
+ /**
34
+ * Metro's bundle URL is the most reliable way to find the dev machine.
35
+ *
36
+ * Only an http(s) bundle URL identifies one: an app running an embedded bundle
37
+ * reports something like `assets://index.android.bundle`, whose "host" is a
38
+ * filename. Connecting to that would fail silently, so treat it as unknown and
39
+ * let the caller pass a host.
40
+ */
41
+ export declare function inferHost(): string | undefined;
42
+ //# sourceMappingURL=rn.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rn.d.ts","sourceRoot":"","sources":["../src/rn.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAwBH,MAAM,WAAW,oBAAoB;IACnC,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAC;CACrB;AAED,eAAO,MAAM,aAAa,EAAE,oBAA8C,CAAC;AAE3E,eAAO,MAAM,QAAQ,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,GAAG,CAAA;CAAsC,CAAC;AAE3F,eAAO,MAAM,aAAa,SAAc,CAAC;AAEzC;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,GAAG,CAEtC;AAED;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAIvC;AAED,4EAA4E;AAC5E,wBAAgB,aAAa,IAAI,MAAM,GAAG,SAAS,CAMlD;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,IAAI,MAAM,GAAG,SAAS,CAc9C"}
package/dist/rn.js ADDED
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ /**
3
+ * Access to React Native's own modules.
4
+ *
5
+ * A literal `require` is what Metro resolves at build time; `global.require`
6
+ * is Metro's internal numeric-id loader and does not take module names, so
7
+ * reaching for it silently yields undefined inside a real bundle. The
8
+ * try/catch keeps the package importable outside React Native (tests, tooling)
9
+ * where the peer dependency is absent.
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.isReactNative = exports.Platform = exports.NativeModules = void 0;
13
+ exports.getBatchedBridge = getBatchedBridge;
14
+ exports.isExpoRuntime = isExpoRuntime;
15
+ exports.inferBundleId = inferBundleId;
16
+ exports.inferHost = inferHost;
17
+ /**
18
+ * `react-native` is the only module this package requires, and deliberately so.
19
+ *
20
+ * Metro resolves `require` at build time by scanning for string literals, which
21
+ * cuts both ways: `require(someVariable)` resolves to nothing at runtime, while
22
+ * a literal require of an optional package FAILS THE WHOLE BUNDLE when that
23
+ * module is absent — a try/catch cannot rescue a build-time resolution error.
24
+ * So there are no optional requires here; optional things are detected through
25
+ * globals and the native module registry instead.
26
+ *
27
+ * The try/catch only covers use outside React Native, such as tests.
28
+ */
29
+ const RN = (() => {
30
+ try {
31
+ return typeof require === 'function' ? require('react-native') : undefined;
32
+ }
33
+ catch {
34
+ return undefined;
35
+ }
36
+ })();
37
+ exports.NativeModules = RN?.NativeModules ?? {};
38
+ exports.Platform = RN?.Platform ?? { OS: 'unknown' };
39
+ exports.isReactNative = Boolean(RN);
40
+ /**
41
+ * React Native's batched bridge instance, used to count calls crossing it.
42
+ * Reached through the global rather than by importing MessageQueue, so a
43
+ * future reshuffle of React Native's internals cannot break the bundle.
44
+ */
45
+ function getBatchedBridge() {
46
+ return globalThis.__fbBatchedBridge;
47
+ }
48
+ /**
49
+ * Whether this looks like an Expo runtime. Detected through globals and the
50
+ * module registry, never by requiring an Expo package: that package is absent
51
+ * in a bare app and a literal require of it would fail the build there.
52
+ */
53
+ function isExpoRuntime() {
54
+ const g = globalThis;
55
+ if (g.expo || g.__expo || g.ExpoModules)
56
+ return true;
57
+ return Boolean(exports.NativeModules.ExponentConstants || exports.NativeModules.NativeUnimoduleProxy);
58
+ }
59
+ /** The app's own bundle id, where a module that exposes it is installed. */
60
+ function inferBundleId() {
61
+ return (exports.NativeModules.RNDeviceInfo?.bundleId ??
62
+ exports.NativeModules.SettingsManager?.settings?.CFBundleIdentifier ??
63
+ undefined);
64
+ }
65
+ /**
66
+ * Metro's bundle URL is the most reliable way to find the dev machine.
67
+ *
68
+ * Only an http(s) bundle URL identifies one: an app running an embedded bundle
69
+ * reports something like `assets://index.android.bundle`, whose "host" is a
70
+ * filename. Connecting to that would fail silently, so treat it as unknown and
71
+ * let the caller pass a host.
72
+ */
73
+ function inferHost() {
74
+ const source = exports.NativeModules.SourceCode;
75
+ const scriptURL = source?.getConstants?.().scriptURL ?? source?.scriptURL;
76
+ if (!scriptURL)
77
+ return undefined;
78
+ const match = /^(https?):\/\/([^/:]+)/i.exec(scriptURL);
79
+ const host = match?.[2];
80
+ if (!host)
81
+ return undefined;
82
+ // An Android emulator reaches the host machine through this alias.
83
+ if (host === 'localhost' || host === '127.0.0.1') {
84
+ return exports.Platform.OS === 'android' ? '10.0.2.2' : 'localhost';
85
+ }
86
+ return host;
87
+ }
88
+ //# sourceMappingURL=rn.js.map
package/dist/rn.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rn.js","sourceRoot":"","sources":["../src/rn.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AAuCH,4CAEC;AAOD,sCAIC;AAGD,sCAMC;AAUD,8BAcC;AAjFD;;;;;;;;;;;GAWG;AACH,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE;IACf,IAAI,CAAC;QACH,OAAO,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC7E,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC,CAAC,EAAE,CAAC;AAMQ,QAAA,aAAa,GAAyB,EAAE,EAAE,aAAa,IAAI,EAAE,CAAC;AAE9D,QAAA,QAAQ,GAAoC,EAAE,EAAE,QAAQ,IAAI,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC;AAE9E,QAAA,aAAa,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC;AAEzC;;;;GAIG;AACH,SAAgB,gBAAgB;IAC9B,OAAQ,UAAkB,CAAC,iBAAiB,CAAC;AAC/C,CAAC;AAED;;;;GAIG;AACH,SAAgB,aAAa;IAC3B,MAAM,CAAC,GAAG,UAAiB,CAAC;IAC5B,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,WAAW;QAAE,OAAO,IAAI,CAAC;IACrD,OAAO,OAAO,CAAC,qBAAa,CAAC,iBAAiB,IAAI,qBAAa,CAAC,oBAAoB,CAAC,CAAC;AACxF,CAAC;AAED,4EAA4E;AAC5E,SAAgB,aAAa;IAC3B,OAAO,CACL,qBAAa,CAAC,YAAY,EAAE,QAAQ;QACpC,qBAAa,CAAC,eAAe,EAAE,QAAQ,EAAE,kBAAkB;QAC3D,SAAS,CACV,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,SAAS;IACvB,MAAM,MAAM,GAAG,qBAAa,CAAC,UAAU,CAAC;IACxC,MAAM,SAAS,GAAuB,MAAM,EAAE,YAAY,EAAE,EAAE,CAAC,SAAS,IAAI,MAAM,EAAE,SAAS,CAAC;IAC9F,IAAI,CAAC,SAAS;QAAE,OAAO,SAAS,CAAC;IAEjC,MAAM,KAAK,GAAG,yBAAyB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACxD,MAAM,IAAI,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;IACxB,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAC;IAE5B,mEAAmE;IACnE,IAAI,IAAI,KAAK,WAAW,IAAI,IAAI,KAAK,WAAW,EAAE,CAAC;QACjD,OAAO,gBAAQ,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC;IAC9D,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,39 @@
1
+ import type { PerfEvent, Sample } from './types.js';
2
+ export interface HelloPayload {
3
+ app: {
4
+ bundleId?: string;
5
+ name?: string;
6
+ version?: string;
7
+ };
8
+ platform: 'ios' | 'android';
9
+ deviceName?: string;
10
+ runtime: {
11
+ rnVersion?: string;
12
+ hermes: boolean;
13
+ dev: boolean;
14
+ };
15
+ }
16
+ /**
17
+ * Reconnecting WebSocket to the daemon. Everything is best-effort: when the
18
+ * daemon is not running the app must behave exactly as if the SDK were absent,
19
+ * so failures are swallowed and retried with backoff rather than surfaced.
20
+ */
21
+ export declare class Transport {
22
+ private readonly hello;
23
+ private readonly onStatus?;
24
+ private socket;
25
+ private url;
26
+ private closed;
27
+ private retryMs;
28
+ private reconnectTimer;
29
+ private queue;
30
+ constructor(host: string, port: number, hello: HelloPayload, onStatus?: ((s: "connecting" | "connected" | "disconnected") => void) | undefined);
31
+ connect(): void;
32
+ private handleDrop;
33
+ private send;
34
+ sendSample(sample: Sample): void;
35
+ sendEvent(event: PerfEvent): void;
36
+ close(): void;
37
+ get connected(): boolean;
38
+ }
39
+ //# sourceMappingURL=transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAgBpD,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC5D,QAAQ,EAAE,KAAK,GAAG,SAAS,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,OAAO,CAAC;QAAC,GAAG,EAAE,OAAO,CAAA;KAAE,CAAC;CAChE;AAED;;;;GAIG;AACH,qBAAa,SAAS;IAWlB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;IAX5B,OAAO,CAAC,MAAM,CAA0B;IACxC,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,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