devlens-mcp 0.3.1 → 0.3.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/src/config/devlens-config.d.ts +92 -0
- package/dist/src/config/devlens-config.d.ts.map +1 -0
- package/dist/src/config/devlens-config.js +70 -0
- package/dist/src/config/devlens-config.js.map +1 -0
- package/dist/src/index.d.ts +35 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +8 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/metro/cdp-client.d.ts +48 -0
- package/dist/src/metro/cdp-client.d.ts.map +1 -0
- package/dist/src/metro/cdp-client.js +127 -0
- package/dist/src/metro/cdp-client.js.map +1 -0
- package/dist/src/metro/log-collector.d.ts +30 -0
- package/dist/src/metro/log-collector.d.ts.map +1 -0
- package/dist/src/metro/log-collector.js +114 -0
- package/dist/src/metro/log-collector.js.map +1 -0
- package/dist/src/metro/metro-bridge.d.ts +56 -0
- package/dist/src/metro/metro-bridge.d.ts.map +1 -0
- package/dist/src/metro/metro-bridge.js +255 -0
- package/dist/src/metro/metro-bridge.js.map +1 -0
- package/dist/src/metro/network-inspector.d.ts +34 -0
- package/dist/src/metro/network-inspector.d.ts.map +1 -0
- package/dist/src/metro/network-inspector.js +100 -0
- package/dist/src/metro/network-inspector.js.map +1 -0
- package/dist/src/platform/android/adb.d.ts +50 -0
- package/dist/src/platform/android/adb.d.ts.map +1 -0
- package/dist/src/platform/android/adb.js +137 -0
- package/dist/src/platform/android/adb.js.map +1 -0
- package/dist/src/platform/android/android-device.d.ts +21 -0
- package/dist/src/platform/android/android-device.d.ts.map +1 -0
- package/dist/src/platform/android/android-device.js +94 -0
- package/dist/src/platform/android/android-device.js.map +1 -0
- package/dist/src/platform/android/ui-automator.d.ts +17 -0
- package/dist/src/platform/android/ui-automator.d.ts.map +1 -0
- package/dist/src/platform/android/ui-automator.js +126 -0
- package/dist/src/platform/android/ui-automator.js.map +1 -0
- package/dist/src/platform/device-manager.d.ts +28 -0
- package/dist/src/platform/device-manager.d.ts.map +1 -0
- package/dist/src/platform/device-manager.js +185 -0
- package/dist/src/platform/device-manager.js.map +1 -0
- package/dist/src/platform/device.d.ts +86 -0
- package/dist/src/platform/device.d.ts.map +1 -0
- package/dist/src/platform/device.js +7 -0
- package/dist/src/platform/device.js.map +1 -0
- package/dist/src/platform/ios/accessibility.d.ts +17 -0
- package/dist/src/platform/ios/accessibility.d.ts.map +1 -0
- package/dist/src/platform/ios/accessibility.js +159 -0
- package/dist/src/platform/ios/accessibility.js.map +1 -0
- package/dist/src/platform/ios/ios-device.d.ts +22 -0
- package/dist/src/platform/ios/ios-device.d.ts.map +1 -0
- package/dist/src/platform/ios/ios-device.js +97 -0
- package/dist/src/platform/ios/ios-device.js.map +1 -0
- package/dist/src/platform/ios/simctl.d.ts +54 -0
- package/dist/src/platform/ios/simctl.d.ts.map +1 -0
- package/dist/src/platform/ios/simctl.js +192 -0
- package/dist/src/platform/ios/simctl.js.map +1 -0
- package/dist/src/server.d.ts +3 -0
- package/dist/src/server.d.ts.map +1 -0
- package/dist/src/server.js +176 -0
- package/dist/src/server.js.map +1 -0
- package/dist/src/snapshot/formatter.d.ts +18 -0
- package/dist/src/snapshot/formatter.d.ts.map +1 -0
- package/dist/src/snapshot/formatter.js +86 -0
- package/dist/src/snapshot/formatter.js.map +1 -0
- package/dist/src/snapshot/ref-registry.d.ts +67 -0
- package/dist/src/snapshot/ref-registry.d.ts.map +1 -0
- package/dist/src/snapshot/ref-registry.js +169 -0
- package/dist/src/snapshot/ref-registry.js.map +1 -0
- package/dist/src/snapshot/snapshot-differ.d.ts +57 -0
- package/dist/src/snapshot/snapshot-differ.d.ts.map +1 -0
- package/dist/src/snapshot/snapshot-differ.js +153 -0
- package/dist/src/snapshot/snapshot-differ.js.map +1 -0
- package/dist/src/tools/app-tools.d.ts +71 -0
- package/dist/src/tools/app-tools.d.ts.map +1 -0
- package/dist/src/tools/app-tools.js +97 -0
- package/dist/src/tools/app-tools.js.map +1 -0
- package/dist/src/tools/device-tools.d.ts +53 -0
- package/dist/src/tools/device-tools.d.ts.map +1 -0
- package/dist/src/tools/device-tools.js +86 -0
- package/dist/src/tools/device-tools.js.map +1 -0
- package/dist/src/tools/ds-tools.d.ts +65 -0
- package/dist/src/tools/ds-tools.d.ts.map +1 -0
- package/dist/src/tools/ds-tools.js +314 -0
- package/dist/src/tools/ds-tools.js.map +1 -0
- package/dist/src/tools/interaction-tools.d.ts +248 -0
- package/dist/src/tools/interaction-tools.d.ts.map +1 -0
- package/dist/src/tools/interaction-tools.js +391 -0
- package/dist/src/tools/interaction-tools.js.map +1 -0
- package/dist/src/tools/metro-tools.d.ts +115 -0
- package/dist/src/tools/metro-tools.d.ts.map +1 -0
- package/dist/src/tools/metro-tools.js +270 -0
- package/dist/src/tools/metro-tools.js.map +1 -0
- package/dist/src/tools/navigation-tools.d.ts +36 -0
- package/dist/src/tools/navigation-tools.d.ts.map +1 -0
- package/dist/src/tools/navigation-tools.js +60 -0
- package/dist/src/tools/navigation-tools.js.map +1 -0
- package/dist/src/tools/screenshot-tools.d.ts +298 -0
- package/dist/src/tools/screenshot-tools.d.ts.map +1 -0
- package/dist/src/tools/screenshot-tools.js +565 -0
- package/dist/src/tools/screenshot-tools.js.map +1 -0
- package/dist/src/tools/snapshot-tools.d.ts +161 -0
- package/dist/src/tools/snapshot-tools.d.ts.map +1 -0
- package/dist/src/tools/snapshot-tools.js +479 -0
- package/dist/src/tools/snapshot-tools.js.map +1 -0
- package/dist/src/utils/image-preprocess.d.ts +49 -0
- package/dist/src/utils/image-preprocess.d.ts.map +1 -0
- package/dist/src/utils/image-preprocess.js +322 -0
- package/dist/src/utils/image-preprocess.js.map +1 -0
- package/dist/src/utils/retry.d.ts +21 -0
- package/dist/src/utils/retry.d.ts.map +1 -0
- package/dist/src/utils/retry.js +33 -0
- package/dist/src/utils/retry.js.map +1 -0
- package/dist/src/visual/comparator.d.ts +51 -0
- package/dist/src/visual/comparator.d.ts.map +1 -0
- package/dist/src/visual/comparator.js +119 -0
- package/dist/src/visual/comparator.js.map +1 -0
- package/dist/src/visual/layout-analyzer.d.ts +64 -0
- package/dist/src/visual/layout-analyzer.d.ts.map +1 -0
- package/dist/src/visual/layout-analyzer.js +198 -0
- package/dist/src/visual/layout-analyzer.js.map +1 -0
- package/dist/src/visual/screenshot.d.ts +17 -0
- package/dist/src/visual/screenshot.d.ts.map +1 -0
- package/dist/src/visual/screenshot.js +39 -0
- package/dist/src/visual/screenshot.js.map +1 -0
- package/docs/setup-guide.md +28 -3
- package/package.json +1 -1
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* DevLens configuration file support.
|
|
4
|
+
*
|
|
5
|
+
* Loaded from (in priority order):
|
|
6
|
+
* 1. Path pointed to by DEVLENS_CONFIG env var
|
|
7
|
+
* 2. ./devlens.config.json in CWD
|
|
8
|
+
*
|
|
9
|
+
* Place devlens.config.json in your consumer app root and point to it
|
|
10
|
+
* via the MCP env block:
|
|
11
|
+
*
|
|
12
|
+
* "env": {
|
|
13
|
+
* "METRO_PORT": "8081",
|
|
14
|
+
* "FIGMA_TOKEN": "figd_xxx",
|
|
15
|
+
* "DEVLENS_CONFIG": "/path/to/your-app/devlens.config.json"
|
|
16
|
+
* }
|
|
17
|
+
*/
|
|
18
|
+
export declare const DesignSystemConfigSchema: z.ZodObject<{
|
|
19
|
+
/** Design system identifier, e.g. "jds3" */
|
|
20
|
+
name: z.ZodString;
|
|
21
|
+
/** Absolute or CWD-relative path to the consumer app root */
|
|
22
|
+
projectRoot: z.ZodString;
|
|
23
|
+
/** Relative path from projectRoot to the tokens file, e.g. "src/constants/figmaTokens.ts" */
|
|
24
|
+
tokensFile: z.ZodString;
|
|
25
|
+
/** Relative path from projectRoot to the generated component interface directory */
|
|
26
|
+
componentsDir: z.ZodOptional<z.ZodString>;
|
|
27
|
+
/** Glob pattern for component source files (default: "src/**\/*.tsx") */
|
|
28
|
+
componentsGlob: z.ZodDefault<z.ZodString>;
|
|
29
|
+
}, "strip", z.ZodTypeAny, {
|
|
30
|
+
name: string;
|
|
31
|
+
projectRoot: string;
|
|
32
|
+
tokensFile: string;
|
|
33
|
+
componentsGlob: string;
|
|
34
|
+
componentsDir?: string | undefined;
|
|
35
|
+
}, {
|
|
36
|
+
name: string;
|
|
37
|
+
projectRoot: string;
|
|
38
|
+
tokensFile: string;
|
|
39
|
+
componentsDir?: string | undefined;
|
|
40
|
+
componentsGlob?: string | undefined;
|
|
41
|
+
}>;
|
|
42
|
+
export declare const DevLensConfigSchema: z.ZodObject<{
|
|
43
|
+
designSystem: z.ZodOptional<z.ZodObject<{
|
|
44
|
+
/** Design system identifier, e.g. "jds3" */
|
|
45
|
+
name: z.ZodString;
|
|
46
|
+
/** Absolute or CWD-relative path to the consumer app root */
|
|
47
|
+
projectRoot: z.ZodString;
|
|
48
|
+
/** Relative path from projectRoot to the tokens file, e.g. "src/constants/figmaTokens.ts" */
|
|
49
|
+
tokensFile: z.ZodString;
|
|
50
|
+
/** Relative path from projectRoot to the generated component interface directory */
|
|
51
|
+
componentsDir: z.ZodOptional<z.ZodString>;
|
|
52
|
+
/** Glob pattern for component source files (default: "src/**\/*.tsx") */
|
|
53
|
+
componentsGlob: z.ZodDefault<z.ZodString>;
|
|
54
|
+
}, "strip", z.ZodTypeAny, {
|
|
55
|
+
name: string;
|
|
56
|
+
projectRoot: string;
|
|
57
|
+
tokensFile: string;
|
|
58
|
+
componentsGlob: string;
|
|
59
|
+
componentsDir?: string | undefined;
|
|
60
|
+
}, {
|
|
61
|
+
name: string;
|
|
62
|
+
projectRoot: string;
|
|
63
|
+
tokensFile: string;
|
|
64
|
+
componentsDir?: string | undefined;
|
|
65
|
+
componentsGlob?: string | undefined;
|
|
66
|
+
}>>;
|
|
67
|
+
}, "strip", z.ZodTypeAny, {
|
|
68
|
+
designSystem?: {
|
|
69
|
+
name: string;
|
|
70
|
+
projectRoot: string;
|
|
71
|
+
tokensFile: string;
|
|
72
|
+
componentsGlob: string;
|
|
73
|
+
componentsDir?: string | undefined;
|
|
74
|
+
} | undefined;
|
|
75
|
+
}, {
|
|
76
|
+
designSystem?: {
|
|
77
|
+
name: string;
|
|
78
|
+
projectRoot: string;
|
|
79
|
+
tokensFile: string;
|
|
80
|
+
componentsDir?: string | undefined;
|
|
81
|
+
componentsGlob?: string | undefined;
|
|
82
|
+
} | undefined;
|
|
83
|
+
}>;
|
|
84
|
+
export type DevLensConfig = z.infer<typeof DevLensConfigSchema>;
|
|
85
|
+
export type DesignSystemConfig = z.infer<typeof DesignSystemConfigSchema>;
|
|
86
|
+
/**
|
|
87
|
+
* Load DevLens config from DEVLENS_CONFIG env var path, or ./devlens.config.json in CWD.
|
|
88
|
+
* Returns empty config {} if neither is found or both are invalid.
|
|
89
|
+
* Never throws — invalid config is logged and skipped.
|
|
90
|
+
*/
|
|
91
|
+
export declare function loadDevLensConfig(): Promise<DevLensConfig>;
|
|
92
|
+
//# sourceMappingURL=devlens-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devlens-config.d.ts","sourceRoot":"","sources":["../../../src/config/devlens-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB;;;;;;;;;;;;;;;GAeG;AAEH,eAAO,MAAM,wBAAwB;IACnC,4CAA4C;;IAE5C,6DAA6D;;IAE7D,6FAA6F;;IAE7F,oFAAoF;;IAEpF,yEAAyE;;;;;;;;;;;;;;EAEzE,CAAC;AAEH,eAAO,MAAM,mBAAmB;;QAZ9B,4CAA4C;;QAE5C,6DAA6D;;QAE7D,6FAA6F;;QAE7F,oFAAoF;;QAEpF,yEAAyE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAMzE,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAChE,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE1E;;;;GAIG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,aAAa,CAAC,CA6BhE"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DevLensConfigSchema = exports.DesignSystemConfigSchema = void 0;
|
|
4
|
+
exports.loadDevLensConfig = loadDevLensConfig;
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const promises_1 = require("fs/promises");
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
/**
|
|
9
|
+
* DevLens configuration file support.
|
|
10
|
+
*
|
|
11
|
+
* Loaded from (in priority order):
|
|
12
|
+
* 1. Path pointed to by DEVLENS_CONFIG env var
|
|
13
|
+
* 2. ./devlens.config.json in CWD
|
|
14
|
+
*
|
|
15
|
+
* Place devlens.config.json in your consumer app root and point to it
|
|
16
|
+
* via the MCP env block:
|
|
17
|
+
*
|
|
18
|
+
* "env": {
|
|
19
|
+
* "METRO_PORT": "8081",
|
|
20
|
+
* "FIGMA_TOKEN": "figd_xxx",
|
|
21
|
+
* "DEVLENS_CONFIG": "/path/to/your-app/devlens.config.json"
|
|
22
|
+
* }
|
|
23
|
+
*/
|
|
24
|
+
exports.DesignSystemConfigSchema = zod_1.z.object({
|
|
25
|
+
/** Design system identifier, e.g. "jds3" */
|
|
26
|
+
name: zod_1.z.string(),
|
|
27
|
+
/** Absolute or CWD-relative path to the consumer app root */
|
|
28
|
+
projectRoot: zod_1.z.string(),
|
|
29
|
+
/** Relative path from projectRoot to the tokens file, e.g. "src/constants/figmaTokens.ts" */
|
|
30
|
+
tokensFile: zod_1.z.string(),
|
|
31
|
+
/** Relative path from projectRoot to the generated component interface directory */
|
|
32
|
+
componentsDir: zod_1.z.string().optional(),
|
|
33
|
+
/** Glob pattern for component source files (default: "src/**\/*.tsx") */
|
|
34
|
+
componentsGlob: zod_1.z.string().default("src/**/*.tsx"),
|
|
35
|
+
});
|
|
36
|
+
exports.DevLensConfigSchema = zod_1.z.object({
|
|
37
|
+
designSystem: exports.DesignSystemConfigSchema.optional(),
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* Load DevLens config from DEVLENS_CONFIG env var path, or ./devlens.config.json in CWD.
|
|
41
|
+
* Returns empty config {} if neither is found or both are invalid.
|
|
42
|
+
* Never throws — invalid config is logged and skipped.
|
|
43
|
+
*/
|
|
44
|
+
async function loadDevLensConfig() {
|
|
45
|
+
const candidates = [];
|
|
46
|
+
const envPath = process.env.DEVLENS_CONFIG;
|
|
47
|
+
if (envPath) {
|
|
48
|
+
candidates.push((0, path_1.resolve)(envPath));
|
|
49
|
+
}
|
|
50
|
+
candidates.push((0, path_1.resolve)(process.cwd(), "devlens.config.json"));
|
|
51
|
+
for (const candidate of candidates) {
|
|
52
|
+
try {
|
|
53
|
+
const raw = await (0, promises_1.readFile)(candidate, "utf-8");
|
|
54
|
+
const parsed = JSON.parse(raw);
|
|
55
|
+
const result = exports.DevLensConfigSchema.safeParse(parsed);
|
|
56
|
+
if (result.success) {
|
|
57
|
+
console.error(`[devlens] Config loaded from: ${candidate}`);
|
|
58
|
+
return result.data;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
console.error(`[devlens] Config at ${candidate} is invalid:`, JSON.stringify(result.error.format(), null, 2));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
// File not found or JSON parse error — try next candidate
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return {};
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=devlens-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devlens-config.js","sourceRoot":"","sources":["../../../src/config/devlens-config.ts"],"names":[],"mappings":";;;AA8CA,8CA6BC;AA3ED,6BAAwB;AACxB,0CAAuC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OAAO,EAAE,CAAC;gBACnB,OAAO,CAAC,KAAK,CAAC,iCAAiC,SAAS,EAAE,CAAC,CAAC;gBAC5D,OAAO,MAAM,CAAC,IAAI,CAAC;YACrB,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,KAAK,CACX,uBAAuB,SAAS,cAAc,EAC9C,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAC/C,CAAC;YACJ,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,0DAA0D;QAC5D,CAAC;IACH,CAAC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export declare function createServer(): Promise<import("@modelcontextprotocol/sdk/server").Server<{
|
|
2
|
+
method: string;
|
|
3
|
+
params?: {
|
|
4
|
+
[x: string]: unknown;
|
|
5
|
+
_meta?: {
|
|
6
|
+
[x: string]: unknown;
|
|
7
|
+
progressToken?: string | number | undefined;
|
|
8
|
+
"io.modelcontextprotocol/related-task"?: {
|
|
9
|
+
taskId: string;
|
|
10
|
+
} | undefined;
|
|
11
|
+
} | undefined;
|
|
12
|
+
} | undefined;
|
|
13
|
+
}, {
|
|
14
|
+
method: string;
|
|
15
|
+
params?: {
|
|
16
|
+
[x: string]: unknown;
|
|
17
|
+
_meta?: {
|
|
18
|
+
[x: string]: unknown;
|
|
19
|
+
progressToken?: string | number | undefined;
|
|
20
|
+
"io.modelcontextprotocol/related-task"?: {
|
|
21
|
+
taskId: string;
|
|
22
|
+
} | undefined;
|
|
23
|
+
} | undefined;
|
|
24
|
+
} | undefined;
|
|
25
|
+
}, {
|
|
26
|
+
[x: string]: unknown;
|
|
27
|
+
_meta?: {
|
|
28
|
+
[x: string]: unknown;
|
|
29
|
+
progressToken?: string | number | undefined;
|
|
30
|
+
"io.modelcontextprotocol/related-task"?: {
|
|
31
|
+
taskId: string;
|
|
32
|
+
} | undefined;
|
|
33
|
+
} | undefined;
|
|
34
|
+
}>>;
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,wBAAsB,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAEjC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createServer = createServer;
|
|
4
|
+
const server_js_1 = require("./server.js");
|
|
5
|
+
async function createServer() {
|
|
6
|
+
return (0, server_js_1.startServer)();
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;AAEA,oCAEC;AAJD,2CAA0C;AAEnC,KAAK,UAAU,YAAY;IAChC,OAAO,IAAA,uBAAW,GAAE,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chrome DevTools Protocol (CDP) client for communicating with the
|
|
3
|
+
* Metro/Hermes debugger. Connects via WebSocket and sends JSON-RPC messages.
|
|
4
|
+
*
|
|
5
|
+
* Metro exposes the debugger endpoint at:
|
|
6
|
+
* ws://localhost:{METRO_PORT}/inspector/device?device=0&page=-1
|
|
7
|
+
*
|
|
8
|
+
* Through CDP we can:
|
|
9
|
+
* - Get console logs (Console.enable → Console.messageAdded)
|
|
10
|
+
* - Intercept network requests (Network.enable → Network.requestWillBeSent)
|
|
11
|
+
* - Execute JavaScript in the RN context (Runtime.evaluate)
|
|
12
|
+
* - Trigger hot reload (via Runtime.evaluate)
|
|
13
|
+
*/
|
|
14
|
+
export interface CdpMessage {
|
|
15
|
+
id?: number;
|
|
16
|
+
method?: string;
|
|
17
|
+
params?: any;
|
|
18
|
+
result?: any;
|
|
19
|
+
error?: {
|
|
20
|
+
message: string;
|
|
21
|
+
code?: number;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
type MessageHandler = (message: CdpMessage) => void;
|
|
25
|
+
export declare class CdpClient {
|
|
26
|
+
private endpoint;
|
|
27
|
+
private ws;
|
|
28
|
+
private messageId;
|
|
29
|
+
private pendingRequests;
|
|
30
|
+
private eventHandlers;
|
|
31
|
+
private connected;
|
|
32
|
+
constructor(endpoint: string);
|
|
33
|
+
/** Connect to the CDP endpoint */
|
|
34
|
+
connect(): Promise<void>;
|
|
35
|
+
/** Send a CDP command and wait for the response */
|
|
36
|
+
send(method: string, params?: any): Promise<any>;
|
|
37
|
+
/** Register an event handler for CDP events */
|
|
38
|
+
on(method: string, handler: MessageHandler): void;
|
|
39
|
+
/** Remove event handlers for a method */
|
|
40
|
+
off(method: string): void;
|
|
41
|
+
/** Check if connected */
|
|
42
|
+
isConnected(): boolean;
|
|
43
|
+
/** Close the connection */
|
|
44
|
+
close(): void;
|
|
45
|
+
private handleMessage;
|
|
46
|
+
}
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=cdp-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cdp-client.d.ts","sourceRoot":"","sources":["../../../src/metro/cdp-client.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AAEH,MAAM,WAAW,UAAU;IACzB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,KAAK,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC5C;AAED,KAAK,cAAc,GAAG,CAAC,OAAO,EAAE,UAAU,KAAK,IAAI,CAAC;AAEpD,qBAAa,SAAS;IAUR,OAAO,CAAC,QAAQ;IAT5B,OAAO,CAAC,EAAE,CAA0B;IACpC,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,eAAe,CAGT;IACd,OAAO,CAAC,aAAa,CAA4C;IACjE,OAAO,CAAC,SAAS,CAAkB;gBAEf,QAAQ,EAAE,MAAM;IAEpC,kCAAkC;IAC5B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAyC9B,mDAAmD;IAC7C,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IA6BtD,+CAA+C;IAC/C,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,IAAI;IAMjD,yCAAyC;IACzC,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAIzB,yBAAyB;IACzB,WAAW,IAAI,OAAO;IAItB,2BAA2B;IAC3B,KAAK,IAAI,IAAI;IAQb,OAAO,CAAC,aAAa;CAuBtB"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CdpClient = void 0;
|
|
7
|
+
const ws_1 = __importDefault(require("ws"));
|
|
8
|
+
class CdpClient {
|
|
9
|
+
endpoint;
|
|
10
|
+
ws = null;
|
|
11
|
+
messageId = 0;
|
|
12
|
+
pendingRequests = new Map();
|
|
13
|
+
eventHandlers = new Map();
|
|
14
|
+
connected = false;
|
|
15
|
+
constructor(endpoint) {
|
|
16
|
+
this.endpoint = endpoint;
|
|
17
|
+
}
|
|
18
|
+
/** Connect to the CDP endpoint */
|
|
19
|
+
async connect() {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
this.ws = new ws_1.default(this.endpoint);
|
|
22
|
+
const timeout = setTimeout(() => {
|
|
23
|
+
reject(new Error(`CDP connection timeout to ${this.endpoint}`));
|
|
24
|
+
}, 5000);
|
|
25
|
+
this.ws.on("open", () => {
|
|
26
|
+
clearTimeout(timeout);
|
|
27
|
+
this.connected = true;
|
|
28
|
+
resolve();
|
|
29
|
+
});
|
|
30
|
+
this.ws.on("message", (data) => {
|
|
31
|
+
try {
|
|
32
|
+
const message = JSON.parse(data.toString());
|
|
33
|
+
this.handleMessage(message);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// Ignore malformed messages
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
this.ws.on("close", () => {
|
|
40
|
+
this.connected = false;
|
|
41
|
+
// Reject all pending requests
|
|
42
|
+
for (const [, { reject }] of this.pendingRequests) {
|
|
43
|
+
reject(new Error("CDP connection closed"));
|
|
44
|
+
}
|
|
45
|
+
this.pendingRequests.clear();
|
|
46
|
+
});
|
|
47
|
+
this.ws.on("error", (err) => {
|
|
48
|
+
clearTimeout(timeout);
|
|
49
|
+
if (!this.connected) {
|
|
50
|
+
reject(err);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/** Send a CDP command and wait for the response */
|
|
56
|
+
async send(method, params) {
|
|
57
|
+
if (!this.ws || !this.connected) {
|
|
58
|
+
throw new Error("CDP client not connected");
|
|
59
|
+
}
|
|
60
|
+
const id = ++this.messageId;
|
|
61
|
+
const message = JSON.stringify({ id, method, params });
|
|
62
|
+
return new Promise((resolve, reject) => {
|
|
63
|
+
const timeout = setTimeout(() => {
|
|
64
|
+
this.pendingRequests.delete(id);
|
|
65
|
+
reject(new Error(`CDP request timeout: ${method}`));
|
|
66
|
+
}, 10000);
|
|
67
|
+
this.pendingRequests.set(id, {
|
|
68
|
+
resolve: (result) => {
|
|
69
|
+
clearTimeout(timeout);
|
|
70
|
+
resolve(result);
|
|
71
|
+
},
|
|
72
|
+
reject: (error) => {
|
|
73
|
+
clearTimeout(timeout);
|
|
74
|
+
reject(error);
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
this.ws.send(message);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/** Register an event handler for CDP events */
|
|
81
|
+
on(method, handler) {
|
|
82
|
+
const handlers = this.eventHandlers.get(method) || [];
|
|
83
|
+
handlers.push(handler);
|
|
84
|
+
this.eventHandlers.set(method, handlers);
|
|
85
|
+
}
|
|
86
|
+
/** Remove event handlers for a method */
|
|
87
|
+
off(method) {
|
|
88
|
+
this.eventHandlers.delete(method);
|
|
89
|
+
}
|
|
90
|
+
/** Check if connected */
|
|
91
|
+
isConnected() {
|
|
92
|
+
return this.connected;
|
|
93
|
+
}
|
|
94
|
+
/** Close the connection */
|
|
95
|
+
close() {
|
|
96
|
+
if (this.ws) {
|
|
97
|
+
this.ws.close();
|
|
98
|
+
this.ws = null;
|
|
99
|
+
this.connected = false;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
handleMessage(message) {
|
|
103
|
+
// Response to a request
|
|
104
|
+
if (message.id !== undefined) {
|
|
105
|
+
const pending = this.pendingRequests.get(message.id);
|
|
106
|
+
if (pending) {
|
|
107
|
+
this.pendingRequests.delete(message.id);
|
|
108
|
+
if (message.error) {
|
|
109
|
+
pending.reject(new Error(message.error.message));
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
pending.resolve(message.result);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
// Event notification
|
|
118
|
+
if (message.method) {
|
|
119
|
+
const handlers = this.eventHandlers.get(message.method) || [];
|
|
120
|
+
for (const handler of handlers) {
|
|
121
|
+
handler(message);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.CdpClient = CdpClient;
|
|
127
|
+
//# sourceMappingURL=cdp-client.js.map
|
|
@@ -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C,wBAAwB;QACxB,IAAI,OAAO,CAAC,EAAE,KAAK,SAAS,EAAE,CAAC;YAC7B,MAAM,OAAO,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YACrD,IAAI,OAAO,EAAE,CAAC;gBACZ,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;gBACxC,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;oBAClB,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;gBACnD,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;gBAClC,CAAC;YACH,CAAC;YACD,OAAO;QACT,CAAC;QAED,qBAAqB;QACrB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YACnB,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YAC9D,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;gBAC/B,OAAO,CAAC,OAAO,CAAC,CAAC;YACnB,CAAC;QACH,CAAC;IACH,CAAC;CACF;AArID,8BAqIC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { CdpClient } from "./cdp-client.js";
|
|
2
|
+
/**
|
|
3
|
+
* Collects console.log/warn/error messages from the React Native app
|
|
4
|
+
* via the CDP Console and Runtime domains.
|
|
5
|
+
*/
|
|
6
|
+
export interface LogEntry {
|
|
7
|
+
level: "log" | "info" | "warn" | "error" | "debug";
|
|
8
|
+
message: string;
|
|
9
|
+
timestamp: number;
|
|
10
|
+
source?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare class LogCollector {
|
|
13
|
+
private cdp;
|
|
14
|
+
private logs;
|
|
15
|
+
private maxLogs;
|
|
16
|
+
constructor(cdp: CdpClient);
|
|
17
|
+
/** Start listening for console messages */
|
|
18
|
+
start(): void;
|
|
19
|
+
/** Get collected logs, optionally filtered by level and time */
|
|
20
|
+
getLogs(options?: {
|
|
21
|
+
level?: "log" | "info" | "warn" | "error" | "debug";
|
|
22
|
+
since?: number;
|
|
23
|
+
limit?: number;
|
|
24
|
+
}): LogEntry[];
|
|
25
|
+
/** Clear all collected logs */
|
|
26
|
+
clear(): void;
|
|
27
|
+
private addLog;
|
|
28
|
+
private normalizeLevel;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=log-collector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-collector.d.ts","sourceRoot":"","sources":["../../../src/metro/log-collector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAc,MAAM,iBAAiB,CAAC;AAE7D;;;GAGG;AAEH,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;IACnD,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,YAAY;IAIX,OAAO,CAAC,GAAG;IAHvB,OAAO,CAAC,IAAI,CAAkB;IAC9B,OAAO,CAAC,OAAO,CAAe;gBAEV,GAAG,EAAE,SAAS;IAElC,2CAA2C;IAC3C,KAAK,IAAI,IAAI;IAyDb,gEAAgE;IAChE,OAAO,CAAC,OAAO,CAAC,EAAE;QAChB,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;QACpD,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,GAAG,QAAQ,EAAE;IAsBd,+BAA+B;IAC/B,KAAK,IAAI,IAAI;IAIb,OAAO,CAAC,MAAM;IAQd,OAAO,CAAC,cAAc;CAkBvB"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogCollector = void 0;
|
|
4
|
+
class LogCollector {
|
|
5
|
+
cdp;
|
|
6
|
+
logs = [];
|
|
7
|
+
maxLogs = 500;
|
|
8
|
+
constructor(cdp) {
|
|
9
|
+
this.cdp = cdp;
|
|
10
|
+
}
|
|
11
|
+
/** Start listening for console messages */
|
|
12
|
+
start() {
|
|
13
|
+
// Listen for Console.messageAdded (older CDP)
|
|
14
|
+
this.cdp.on("Console.messageAdded", (msg) => {
|
|
15
|
+
const entry = msg.params?.message;
|
|
16
|
+
if (entry) {
|
|
17
|
+
this.addLog({
|
|
18
|
+
level: this.normalizeLevel(entry.level),
|
|
19
|
+
message: entry.text || "",
|
|
20
|
+
timestamp: Date.now(),
|
|
21
|
+
source: entry.source,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
// Listen for Runtime.consoleAPICalled (newer CDP)
|
|
26
|
+
this.cdp.on("Runtime.consoleAPICalled", (msg) => {
|
|
27
|
+
const params = msg.params;
|
|
28
|
+
if (params) {
|
|
29
|
+
const args = params.args || [];
|
|
30
|
+
const message = args
|
|
31
|
+
.map((arg) => {
|
|
32
|
+
if (arg.type === "string")
|
|
33
|
+
return arg.value;
|
|
34
|
+
if (arg.type === "number")
|
|
35
|
+
return String(arg.value);
|
|
36
|
+
if (arg.type === "boolean")
|
|
37
|
+
return String(arg.value);
|
|
38
|
+
if (arg.type === "undefined")
|
|
39
|
+
return "undefined";
|
|
40
|
+
if (arg.type === "object" && arg.value)
|
|
41
|
+
return JSON.stringify(arg.value);
|
|
42
|
+
if (arg.description)
|
|
43
|
+
return arg.description;
|
|
44
|
+
return String(arg.value ?? "");
|
|
45
|
+
})
|
|
46
|
+
.join(" ");
|
|
47
|
+
this.addLog({
|
|
48
|
+
level: this.normalizeLevel(params.type),
|
|
49
|
+
message,
|
|
50
|
+
timestamp: params.timestamp || Date.now(),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
// Listen for Runtime.exceptionThrown
|
|
55
|
+
this.cdp.on("Runtime.exceptionThrown", (msg) => {
|
|
56
|
+
const details = msg.params?.exceptionDetails;
|
|
57
|
+
if (details) {
|
|
58
|
+
this.addLog({
|
|
59
|
+
level: "error",
|
|
60
|
+
message: details.text ||
|
|
61
|
+
details.exception?.description ||
|
|
62
|
+
"Unknown exception",
|
|
63
|
+
timestamp: Date.now(),
|
|
64
|
+
source: "exception",
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/** Get collected logs, optionally filtered by level and time */
|
|
70
|
+
getLogs(options) {
|
|
71
|
+
let filtered = this.logs;
|
|
72
|
+
if (options?.level) {
|
|
73
|
+
const levelOrder = { debug: 0, log: 1, info: 2, warn: 3, error: 4 };
|
|
74
|
+
const minLevel = levelOrder[options.level] ?? 0;
|
|
75
|
+
filtered = filtered.filter((log) => (levelOrder[log.level] ?? 0) >= minLevel);
|
|
76
|
+
}
|
|
77
|
+
if (options?.since) {
|
|
78
|
+
filtered = filtered.filter((log) => log.timestamp >= options.since);
|
|
79
|
+
}
|
|
80
|
+
if (options?.limit) {
|
|
81
|
+
filtered = filtered.slice(-options.limit);
|
|
82
|
+
}
|
|
83
|
+
return filtered;
|
|
84
|
+
}
|
|
85
|
+
/** Clear all collected logs */
|
|
86
|
+
clear() {
|
|
87
|
+
this.logs = [];
|
|
88
|
+
}
|
|
89
|
+
addLog(entry) {
|
|
90
|
+
this.logs.push(entry);
|
|
91
|
+
// Keep buffer bounded
|
|
92
|
+
if (this.logs.length > this.maxLogs) {
|
|
93
|
+
this.logs = this.logs.slice(-Math.floor(this.maxLogs * 0.8));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
normalizeLevel(level) {
|
|
97
|
+
switch (level?.toLowerCase()) {
|
|
98
|
+
case "warning":
|
|
99
|
+
case "warn":
|
|
100
|
+
return "warn";
|
|
101
|
+
case "error":
|
|
102
|
+
return "error";
|
|
103
|
+
case "debug":
|
|
104
|
+
case "verbose":
|
|
105
|
+
return "debug";
|
|
106
|
+
case "info":
|
|
107
|
+
return "info";
|
|
108
|
+
default:
|
|
109
|
+
return "log";
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.LogCollector = LogCollector;
|
|
114
|
+
//# sourceMappingURL=log-collector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-collector.js","sourceRoot":"","sources":["../../../src/metro/log-collector.ts"],"names":[],"mappings":";;;AAcA,MAAa,YAAY;IAIH;IAHZ,IAAI,GAAe,EAAE,CAAC;IACtB,OAAO,GAAW,GAAG,CAAC;IAE9B,YAAoB,GAAc;QAAd,QAAG,GAAH,GAAG,CAAW;IAAG,CAAC;IAEtC,2CAA2C;IAC3C,KAAK;QACH,8CAA8C;QAC9C,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,sBAAsB,EAAE,CAAC,GAAe,EAAE,EAAE;YACtD,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;YAClC,IAAI,KAAK,EAAE,CAAC;gBACV,IAAI,CAAC,MAAM,CAAC;oBACV,KAAK,EAAE,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC;oBACvC,OAAO,EAAE,KAAK,CAAC,IAAI,IAAI,EAAE;oBACzB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;oBACrB,MAAM,EAAE,KAAK,CAAC,MAAM;iBACrB,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,kDAAkD;QAClD,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,0BAA0B,EAAE,CAAC,GAAe,EAAE,EAAE;YAC1D,MAAM,MAAM,GAAG,GAAG,CAAC,M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KAAK;QACH,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;IACjB,CAAC;IAEO,MAAM,CAAC,KAAe;QAC5B,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACtB,sBAAsB;QACtB,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;YACpC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;IAEO,cAAc,CACpB,KAAa;QAEb,QAAQ,KAAK,EAAE,WAAW,EAAE,EAAE,CAAC;YAC7B,KAAK,SAAS,CAAC;YACf,KAAK,MAAM;gBACT,OAAO,MAAM,CAAC;YAChB,KAAK,OAAO;gBACV,OAAO,OAAO,CAAC;YACjB,KAAK,OAAO,CAAC;YACb,KAAK,SAAS;gBACZ,OAAO,OAAO,CAAC;YACjB,KAAK,MAAM;gBACT,OAAO,MAAM,CAAC;YAChB;gBACE,OAAO,KAAK,CAAC;QACjB,CAAC;IACH,CAAC;CACF;AA1HD,oCA0HC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { LogCollector } from "./log-collector.js";
|
|
2
|
+
import { NetworkInspector } from "./network-inspector.js";
|
|
3
|
+
/**
|
|
4
|
+
* Metro Bridge — manages the connection to Metro bundler's debugger
|
|
5
|
+
* and provides access to console logs, network requests, and JS execution.
|
|
6
|
+
*
|
|
7
|
+
* Metro/Hermes exposes CDP endpoints. To discover available pages:
|
|
8
|
+
* GET http://localhost:{port}/json
|
|
9
|
+
*
|
|
10
|
+
* The main debugger endpoint is typically:
|
|
11
|
+
* ws://localhost:{port}/inspector/device?device=0&page=-1
|
|
12
|
+
*
|
|
13
|
+
* For newer React Native (0.76+) with the new debugger:
|
|
14
|
+
* ws://localhost:{port}/inspector/device?device=0&page=1
|
|
15
|
+
*/
|
|
16
|
+
export interface MetroStatus {
|
|
17
|
+
/** Whether the Metro packager process is running and responding */
|
|
18
|
+
running: boolean;
|
|
19
|
+
/** The port being checked */
|
|
20
|
+
port: number;
|
|
21
|
+
/** Raw response from /status endpoint (e.g., "packager-status:running") */
|
|
22
|
+
packagerStatus: string | null;
|
|
23
|
+
/** Whether a CDP WebSocket connection is currently active */
|
|
24
|
+
cdpConnected: boolean;
|
|
25
|
+
/** Error message if Metro is unreachable */
|
|
26
|
+
error?: string;
|
|
27
|
+
}
|
|
28
|
+
export declare class MetroBridge {
|
|
29
|
+
private port;
|
|
30
|
+
private cdp;
|
|
31
|
+
private _logCollector;
|
|
32
|
+
private _networkInspector;
|
|
33
|
+
private _connected;
|
|
34
|
+
constructor(port?: number);
|
|
35
|
+
/** Connect to Metro bundler's debugger */
|
|
36
|
+
connect(): Promise<void>;
|
|
37
|
+
/** Disconnect from Metro */
|
|
38
|
+
disconnect(): void;
|
|
39
|
+
/** Check if connected to Metro */
|
|
40
|
+
get connected(): boolean;
|
|
41
|
+
/** Get the log collector */
|
|
42
|
+
get logCollector(): LogCollector;
|
|
43
|
+
/** Get the network inspector */
|
|
44
|
+
get networkInspector(): NetworkInspector;
|
|
45
|
+
/** Execute JavaScript in the React Native context */
|
|
46
|
+
evaluate(expression: string): Promise<any>;
|
|
47
|
+
/** Trigger a hot reload / fast refresh */
|
|
48
|
+
hotReload(): Promise<void>;
|
|
49
|
+
/** Get the React component tree by evaluating JS in the RN context */
|
|
50
|
+
getComponentTree(maxDepth?: number): Promise<string>;
|
|
51
|
+
/** Proactively check if Metro bundler is running and healthy */
|
|
52
|
+
getStatus(): Promise<MetroStatus>;
|
|
53
|
+
/** Discover the debugger WebSocket endpoint */
|
|
54
|
+
private discoverEndpoint;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=metro-bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metro-bridge.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