react-native-ai-debugger 1.0.7 → 1.0.9
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/README.md +84 -152
- package/build/core/android.d.ts +94 -0
- package/build/core/android.d.ts.map +1 -1
- package/build/core/android.js +337 -1
- package/build/core/android.js.map +1 -1
- package/build/core/executor.d.ts.map +1 -1
- package/build/core/executor.js +75 -30
- package/build/core/executor.js.map +1 -1
- package/build/core/httpServer.d.ts.map +1 -1
- package/build/core/httpServer.js +695 -5
- package/build/core/httpServer.js.map +1 -1
- package/build/core/index.d.ts +4 -4
- package/build/core/index.d.ts.map +1 -1
- package/build/core/index.js +7 -3
- package/build/core/index.js.map +1 -1
- package/build/core/ios.d.ts +70 -0
- package/build/core/ios.d.ts.map +1 -1
- package/build/core/ios.js +217 -2
- package/build/core/ios.js.map +1 -1
- package/build/index.js +364 -12
- package/build/index.js.map +1 -1
- package/package.json +1 -1
package/build/core/executor.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import WebSocket from "ws";
|
|
2
|
-
import { pendingExecutions, getNextMessageId } from "./state.js";
|
|
3
|
-
import { getFirstConnectedApp } from "./connection.js";
|
|
2
|
+
import { pendingExecutions, getNextMessageId, connectedApps } from "./state.js";
|
|
3
|
+
import { getFirstConnectedApp, connectToDevice } from "./connection.js";
|
|
4
|
+
import { fetchDevices, selectMainDevice } from "./metro.js";
|
|
5
|
+
// Hermes runtime compatibility: polyfill for 'global' which doesn't exist in Hermes
|
|
6
|
+
// In Hermes, globalThis is the standard way to access global scope
|
|
7
|
+
const GLOBAL_POLYFILL = `var global = typeof global !== 'undefined' ? global : globalThis;`;
|
|
4
8
|
// Execute JavaScript in the connected React Native app
|
|
5
9
|
export async function executeInApp(expression, awaitPromise = true) {
|
|
6
10
|
const app = getFirstConnectedApp();
|
|
@@ -12,6 +16,8 @@ export async function executeInApp(expression, awaitPromise = true) {
|
|
|
12
16
|
}
|
|
13
17
|
const TIMEOUT_MS = 10000;
|
|
14
18
|
const currentMessageId = getNextMessageId();
|
|
19
|
+
// Wrap expression with global polyfill for Hermes compatibility
|
|
20
|
+
const wrappedExpression = `(function() { ${GLOBAL_POLYFILL} return (${expression}); })()`;
|
|
15
21
|
return new Promise((resolve) => {
|
|
16
22
|
const timeoutId = setTimeout(() => {
|
|
17
23
|
pendingExecutions.delete(currentMessageId);
|
|
@@ -22,7 +28,7 @@ export async function executeInApp(expression, awaitPromise = true) {
|
|
|
22
28
|
id: currentMessageId,
|
|
23
29
|
method: "Runtime.evaluate",
|
|
24
30
|
params: {
|
|
25
|
-
expression,
|
|
31
|
+
expression: wrappedExpression,
|
|
26
32
|
returnByValue: true,
|
|
27
33
|
awaitPromise,
|
|
28
34
|
userGesture: true,
|
|
@@ -73,40 +79,79 @@ export async function inspectGlobal(objectName) {
|
|
|
73
79
|
`;
|
|
74
80
|
return executeInApp(expression, false);
|
|
75
81
|
}
|
|
76
|
-
// Reload the React Native app
|
|
82
|
+
// Reload the React Native app using __ReactRefresh (Page.reload is not supported by Hermes)
|
|
77
83
|
export async function reloadApp() {
|
|
84
|
+
// Get current connection info before reload
|
|
78
85
|
const app = getFirstConnectedApp();
|
|
79
86
|
if (!app) {
|
|
80
87
|
return { success: false, error: "No apps connected. Run 'scan_metro' first." };
|
|
81
88
|
}
|
|
82
|
-
|
|
83
|
-
|
|
89
|
+
const port = app.port;
|
|
90
|
+
// Use __ReactRefresh.performFullRefresh() which is available in Metro bundler dev mode
|
|
91
|
+
// This works with Hermes unlike the CDP Page.reload method
|
|
92
|
+
const expression = `
|
|
93
|
+
(function() {
|
|
94
|
+
try {
|
|
95
|
+
// Use React Refresh's full refresh - most reliable method
|
|
96
|
+
if (typeof __ReactRefresh !== 'undefined' && typeof __ReactRefresh.performFullRefresh === 'function') {
|
|
97
|
+
__ReactRefresh.performFullRefresh('mcp-reload');
|
|
98
|
+
return 'Reload triggered via __ReactRefresh.performFullRefresh';
|
|
99
|
+
}
|
|
100
|
+
// Fallback: Try DevSettings if available on global
|
|
101
|
+
if (typeof global !== 'undefined' && global.DevSettings && typeof global.DevSettings.reload === 'function') {
|
|
102
|
+
global.DevSettings.reload();
|
|
103
|
+
return 'Reload triggered via DevSettings';
|
|
104
|
+
}
|
|
105
|
+
return 'Reload not available - make sure app is in development mode with Metro bundler';
|
|
106
|
+
} catch (e) {
|
|
107
|
+
return 'Reload failed: ' + e.message;
|
|
108
|
+
}
|
|
109
|
+
})()
|
|
110
|
+
`;
|
|
111
|
+
const result = await executeInApp(expression, false);
|
|
112
|
+
if (!result.success) {
|
|
113
|
+
return result;
|
|
84
114
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
resolve: (result) => {
|
|
95
|
-
clearTimeout(timeoutId);
|
|
96
|
-
// Page.reload returns empty result on success, provide a friendly message
|
|
97
|
-
if (result.success && (!result.result || result.result === "undefined")) {
|
|
98
|
-
resolve({ success: true, result: "App reload triggered successfully" });
|
|
115
|
+
// Auto-reconnect after reload
|
|
116
|
+
try {
|
|
117
|
+
// Wait for app to reload (give it time to restart JS context)
|
|
118
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
119
|
+
// Close existing connections to this port
|
|
120
|
+
for (const [key, connectedApp] of connectedApps.entries()) {
|
|
121
|
+
if (connectedApp.port === port) {
|
|
122
|
+
try {
|
|
123
|
+
connectedApp.ws.close();
|
|
99
124
|
}
|
|
100
|
-
|
|
101
|
-
|
|
125
|
+
catch {
|
|
126
|
+
// Ignore close errors
|
|
102
127
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
128
|
+
connectedApps.delete(key);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// Small delay to ensure cleanup
|
|
132
|
+
await new Promise(resolve => setTimeout(resolve, 500));
|
|
133
|
+
// Reconnect to Metro on the same port
|
|
134
|
+
const devices = await fetchDevices(port);
|
|
135
|
+
const mainDevice = selectMainDevice(devices);
|
|
136
|
+
if (mainDevice) {
|
|
137
|
+
await connectToDevice(mainDevice, port);
|
|
138
|
+
return {
|
|
139
|
+
success: true,
|
|
140
|
+
result: `App reloaded and reconnected to ${mainDevice.title}`
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
return {
|
|
145
|
+
success: true,
|
|
146
|
+
result: "App reloaded but could not auto-reconnect. Run 'scan_metro' to reconnect."
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
return {
|
|
152
|
+
success: true,
|
|
153
|
+
result: `App reloaded but auto-reconnect failed: ${error instanceof Error ? error.message : String(error)}. Run 'scan_metro' to reconnect.`
|
|
154
|
+
};
|
|
155
|
+
}
|
|
111
156
|
}
|
|
112
157
|
//# sourceMappingURL=executor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../src/core/executor.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,IAAI,CAAC;AAE3B,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../src/core/executor.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,IAAI,CAAC;AAE3B,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE5D,oFAAoF;AACpF,mEAAmE;AACnE,MAAM,eAAe,GAAG,mEAAmE,CAAC;AAE5F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AE,CAAC;gBAC7B,IAAI,CAAC;oBACD,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;gBAC5B,CAAC;gBAAC,MAAM,CAAC;oBACL,sBAAsB;gBAC1B,CAAC;gBACD,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC9B,CAAC;QACL,CAAC;QAED,gCAAgC;QAChC,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;QAEvD,sCAAsC;QACtC,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,IAAI,CAAC,CAAC;QACzC,MAAM,UAAU,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAE7C,IAAI,UAAU,EAAE,CAAC;YACb,MAAM,eAAe,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;YACxC,OAAO;gBACH,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE,mCAAmC,UAAU,CAAC,KAAK,EAAE;aAChE,CAAC;QACN,CAAC;aAAM,CAAC;YACJ,OAAO;gBACH,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE,2EAA2E;aACtF,CAAC;QACN,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO;YACH,OAAO,EAAE,IAAI;YACb,MAAM,EAAE,2CAA2C,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,kCAAkC;SAC9I,CAAC;IACN,CAAC;AACL,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpServer.d.ts","sourceRoot":"","sources":["../../src/core/httpServer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"httpServer.d.ts","sourceRoot":"","sources":["../../src/core/httpServer.ts"],"names":[],"mappings":"AA8BA,UAAU,kBAAkB;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,GAAG,IAAI,CAElD;AAgxCD;;;GAGG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,GAAE,kBAAuB,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAkBnG"}
|