@snap/valdi 1.1.7 → 1.2.0
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/.metadata/.bazelrc.template +8 -2
- package/.metadata/MODULE.bazel.template +20 -3
- package/.metadata/bzl/patches/rules_python/1.9.0/BUILD.bazel.template +1 -0
- package/.metadata/bzl/patches/rules_python/1.9.0/remove_setuptools_spaces.patch.template +96 -0
- package/README.md +35 -1
- package/bundled-skills/registry.json +2 -1
- package/bundled-skills/skills/valdi-animations/skill.md +49 -0
- package/bundled-skills/skills/valdi-async/skill.md +3 -2
- package/bundled-skills/skills/valdi-bazel/skill.md +2 -6
- package/bundled-skills/skills/valdi-cpp-runtime/skill.md +18 -0
- package/bundled-skills/skills/valdi-error-handling/skill.md +1 -1
- package/bundled-skills/skills/valdi-gestures/skill.md +3 -3
- package/bundled-skills/skills/valdi-migrate/skill.md +2 -1
- package/bundled-skills/skills/valdi-mock-breakdown/skill.md +4 -4
- package/bundled-skills/skills/valdi-mock-to-module/skill.md +9 -6
- package/bundled-skills/skills/valdi-overview/skill.md +2 -1
- package/bundled-skills/skills/valdi-perf/skill.md +121 -5
- package/bundled-skills/skills/valdi-pr-review/skill.md +189 -0
- package/bundled-skills/skills/valdi-profile/skill.md +5 -3
- package/bundled-skills/skills/valdi-setup/skill.md +3 -6
- package/bundled-skills/skills/valdi-testing/skill.md +1 -1
- package/bundled-skills/skills/valdi-tsx/skill.md +47 -11
- package/debugger/README.md +356 -0
- package/debugger/debugger-actions.js +373 -0
- package/debugger/debugger-api.js +225 -0
- package/debugger/debugger-bootstrap.js +295 -0
- package/debugger/debugger-model.js +790 -0
- package/debugger/debugger-performance.js +573 -0
- package/debugger/debugger-preview-html.js +676 -0
- package/debugger/debugger-providers.js +389 -0
- package/debugger/debugger-render.js +529 -0
- package/debugger/debugger-runtime.js +387 -0
- package/debugger/debugger-session.js +188 -0
- package/debugger/debugger-settings.js +209 -0
- package/debugger/debugger-state.js +221 -0
- package/debugger/debugger-tree-model.js +539 -0
- package/debugger/debugger.css +1865 -0
- package/debugger/devtools-panel.css +1318 -0
- package/debugger/devtools-panel.html +273 -0
- package/debugger/devtools-panel.js +3329 -0
- package/debugger/index.html +279 -0
- package/dist/commands/bootstrap.js +6 -5
- package/dist/commands/debugger.js +163 -0
- package/dist/commands/doctor.js +3 -62
- package/dist/commands/inspect.js +5 -2
- package/dist/commands/inspect_commands/input.js +176 -0
- package/dist/commands/inspect_commands/snapshot.js +1 -1
- package/dist/commands/inspect_commands/tree.js +1 -1
- package/dist/commands/projectsync.js +15 -0
- package/dist/commands/webHotreload.js +31 -0
- package/dist/core/constants.js +22 -6
- package/dist/debugger/chromiumConsole.js +279 -0
- package/dist/debugger/inputClient.js +473 -0
- package/dist/debugger/server.js +3801 -0
- package/dist/debugger/targetRegistry.js +436 -0
- package/dist/debugger/webPreviewPerformance.js +864 -0
- package/dist/index.js +0 -0
- package/dist/utils/BazelClient.js +34 -5
- package/dist/utils/applicationUtils.js +3 -0
- package/dist/utils/chromiumDevToolsClient.js +350 -0
- package/dist/utils/daemonClient.js +364 -44
- package/dist/utils/hermesClient.js +82 -176
- package/dist/utils/loopbackHost.js +14 -0
- package/dist/utils/owlCdpClient.js +282 -0
- package/dist/utils/owlDevToolsExtension.js +142 -0
- package/dist/utils/stringUtils.js +13 -1
- package/package.json +4 -2
- package/dist/commands/inspect_commands/snapshot.spec.js +0 -105
- package/dist/core/packageFiles.spec.js +0 -29
- package/dist/preview/previewGenerator.spec.js +0 -203
- package/dist/preview/viewModelParser.spec.js +0 -171
- package/dist/utils/linuxDistro.spec.js +0 -122
- package/dist/utils/skillsAdapters.spec.js +0 -141
- package/dist/utils/stringUtils.spec.js +0 -81
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DebuggerTargetIdentityMode = exports.DebuggerTargetState = exports.DebuggerTargetCapability = exports.DebuggerTargetTransport = exports.DebuggerTargetPlatform = void 0;
|
|
4
|
+
exports.parseAndroidDaemonForwards = parseAndroidDaemonForwards;
|
|
5
|
+
exports.discoverAndroidDaemonEndpoints = discoverAndroidDaemonEndpoints;
|
|
6
|
+
exports.discoverDebuggerProxyTargets = discoverDebuggerProxyTargets;
|
|
7
|
+
exports.buildDebuggerTargetRegistry = buildDebuggerTargetRegistry;
|
|
8
|
+
const tslib_1 = require("tslib");
|
|
9
|
+
const node_child_process_1 = require("node:child_process");
|
|
10
|
+
const node_crypto_1 = require("node:crypto");
|
|
11
|
+
const node_http_1 = tslib_1.__importDefault(require("node:http"));
|
|
12
|
+
const node_util_1 = require("node:util");
|
|
13
|
+
const constants_1 = require("../core/constants");
|
|
14
|
+
const daemonClient_1 = require("../utils/daemonClient");
|
|
15
|
+
const loopbackHost_1 = require("../utils/loopbackHost");
|
|
16
|
+
var DebuggerTargetPlatform;
|
|
17
|
+
(function (DebuggerTargetPlatform) {
|
|
18
|
+
DebuggerTargetPlatform["Android"] = "android";
|
|
19
|
+
DebuggerTargetPlatform["IOS"] = "ios";
|
|
20
|
+
DebuggerTargetPlatform["MacOS"] = "macos";
|
|
21
|
+
DebuggerTargetPlatform["Web"] = "web";
|
|
22
|
+
DebuggerTargetPlatform["Unknown"] = "unknown";
|
|
23
|
+
})(DebuggerTargetPlatform || (exports.DebuggerTargetPlatform = DebuggerTargetPlatform = {}));
|
|
24
|
+
var DebuggerTargetTransport;
|
|
25
|
+
(function (DebuggerTargetTransport) {
|
|
26
|
+
DebuggerTargetTransport["ChromiumCDP"] = "chromium-cdp";
|
|
27
|
+
DebuggerTargetTransport["ValdiDaemon"] = "valdi-daemon";
|
|
28
|
+
})(DebuggerTargetTransport || (exports.DebuggerTargetTransport = DebuggerTargetTransport = {}));
|
|
29
|
+
var DebuggerTargetCapability;
|
|
30
|
+
(function (DebuggerTargetCapability) {
|
|
31
|
+
DebuggerTargetCapability["ComponentPropertyEdit"] = "component-property-edit";
|
|
32
|
+
DebuggerTargetCapability["ComponentProperties"] = "component-properties";
|
|
33
|
+
DebuggerTargetCapability["Components"] = "components";
|
|
34
|
+
DebuggerTargetCapability["Console"] = "console";
|
|
35
|
+
DebuggerTargetCapability["Highlight"] = "highlight";
|
|
36
|
+
DebuggerTargetCapability["JavaScriptDebugger"] = "javascript-debugger";
|
|
37
|
+
DebuggerTargetCapability["Performance"] = "performance";
|
|
38
|
+
DebuggerTargetCapability["Snapshot"] = "snapshot";
|
|
39
|
+
DebuggerTargetCapability["Storage"] = "storage";
|
|
40
|
+
})(DebuggerTargetCapability || (exports.DebuggerTargetCapability = DebuggerTargetCapability = {}));
|
|
41
|
+
var DebuggerTargetState;
|
|
42
|
+
(function (DebuggerTargetState) {
|
|
43
|
+
DebuggerTargetState["Attached"] = "attached";
|
|
44
|
+
DebuggerTargetState["Available"] = "available";
|
|
45
|
+
DebuggerTargetState["Waiting"] = "waiting";
|
|
46
|
+
})(DebuggerTargetState || (exports.DebuggerTargetState = DebuggerTargetState = {}));
|
|
47
|
+
var DebuggerTargetIdentityMode;
|
|
48
|
+
(function (DebuggerTargetIdentityMode) {
|
|
49
|
+
DebuggerTargetIdentityMode["InspectedPage"] = "inspected-page";
|
|
50
|
+
DebuggerTargetIdentityMode["TargetId"] = "target-id";
|
|
51
|
+
})(DebuggerTargetIdentityMode || (exports.DebuggerTargetIdentityMode = DebuggerTargetIdentityMode = {}));
|
|
52
|
+
const execFile = (0, node_util_1.promisify)(node_child_process_1.execFile);
|
|
53
|
+
const MAX_ANDROID_DAEMON_ENDPOINTS = 8;
|
|
54
|
+
const MAX_ADB_FORWARD_OUTPUT_BYTES = 256 * 1024;
|
|
55
|
+
const MAX_PROXY_RESPONSE_BYTES = 512 * 1024;
|
|
56
|
+
const MAX_PROXY_TARGETS = 128;
|
|
57
|
+
const MAX_PROXY_URL_BYTES = 4096;
|
|
58
|
+
const MAX_PROXY_STRING_BYTES = 1024;
|
|
59
|
+
const MAX_REGISTRY_PORTS = 10;
|
|
60
|
+
const MAX_REGISTRY_TARGETS = 256;
|
|
61
|
+
const OPAQUE_TARGET_ID_DOMAIN = 'valdi-debugger-target-v1';
|
|
62
|
+
const NATIVE_CAPABILITIES = [
|
|
63
|
+
DebuggerTargetCapability.Components,
|
|
64
|
+
DebuggerTargetCapability.Snapshot,
|
|
65
|
+
];
|
|
66
|
+
function containsControlCharacter(value) {
|
|
67
|
+
for (const character of value) {
|
|
68
|
+
const codePoint = character.codePointAt(0);
|
|
69
|
+
if (codePoint !== undefined && (codePoint <= 31 || codePoint === 127))
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
function boundedString(value, maximumBytes) {
|
|
75
|
+
if (typeof value !== 'string' ||
|
|
76
|
+
value.length === 0 ||
|
|
77
|
+
Buffer.byteLength(value, 'utf8') > maximumBytes ||
|
|
78
|
+
containsControlCharacter(value)) {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
83
|
+
function assertBoundedIdentityString(value, name, allowEmpty) {
|
|
84
|
+
if (typeof value !== 'string' ||
|
|
85
|
+
(!allowEmpty && value.length === 0) ||
|
|
86
|
+
Buffer.byteLength(value, 'utf8') > MAX_PROXY_STRING_BYTES ||
|
|
87
|
+
containsControlCharacter(value)) {
|
|
88
|
+
throw new Error(`Debugger target discovery returned an invalid ${name}.`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function platformFromValue(value) {
|
|
92
|
+
switch (value.toLowerCase()) {
|
|
93
|
+
case constants_1.PLATFORM.ANDROID: {
|
|
94
|
+
return DebuggerTargetPlatform.Android;
|
|
95
|
+
}
|
|
96
|
+
case constants_1.PLATFORM.IOS: {
|
|
97
|
+
return DebuggerTargetPlatform.IOS;
|
|
98
|
+
}
|
|
99
|
+
case constants_1.PLATFORM.MACOS:
|
|
100
|
+
case 'standalone': {
|
|
101
|
+
return DebuggerTargetPlatform.MacOS;
|
|
102
|
+
}
|
|
103
|
+
default: {
|
|
104
|
+
return DebuggerTargetPlatform.Unknown;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function opaqueTargetId(kind, identity) {
|
|
109
|
+
const serializedIdentity = JSON.stringify([OPAQUE_TARGET_ID_DOMAIN, kind, identity]);
|
|
110
|
+
return `vdt_${(0, node_crypto_1.createHash)('sha256').update(serializedIdentity).digest('base64url').slice(0, 32)}`;
|
|
111
|
+
}
|
|
112
|
+
function loopbackWebSocketTransportKey(value) {
|
|
113
|
+
if (value.includes('#') || Buffer.byteLength(value, 'utf8') > MAX_PROXY_URL_BYTES)
|
|
114
|
+
return undefined;
|
|
115
|
+
try {
|
|
116
|
+
const parsed = new URL(value);
|
|
117
|
+
if (parsed.protocol !== 'ws:' || !(0, loopbackHost_1.isLoopbackHost)(parsed.hostname) || parsed.username || parsed.password) {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
return `${parsed.protocol}//${parsed.host}${parsed.pathname}${parsed.search}`;
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function isLoopbackWebSocketUrl(value) {
|
|
127
|
+
return loopbackWebSocketTransportKey(value) !== undefined;
|
|
128
|
+
}
|
|
129
|
+
function parseAndroidDaemonForwards(output) {
|
|
130
|
+
if (Buffer.byteLength(output, 'utf8') > MAX_ADB_FORWARD_OUTPUT_BYTES) {
|
|
131
|
+
throw new Error('ADB returned an oversized forwarding table.');
|
|
132
|
+
}
|
|
133
|
+
const endpoints = [];
|
|
134
|
+
const knownEndpoints = new Set();
|
|
135
|
+
const deviceByPort = new Map();
|
|
136
|
+
for (const line of output.split(/\r?\n/)) {
|
|
137
|
+
const [deviceId, local, remote, ...extra] = line.trim().split(/\s+/);
|
|
138
|
+
if (!deviceId ||
|
|
139
|
+
!/^[\w.:-]{1,128}$/.test(deviceId) ||
|
|
140
|
+
!local ||
|
|
141
|
+
!remote ||
|
|
142
|
+
extra.length > 0 ||
|
|
143
|
+
remote !== `tcp:${daemonClient_1.MOBILE_PORT}`) {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
const match = /^tcp:(\d+)$/.exec(local);
|
|
147
|
+
if (!match)
|
|
148
|
+
continue;
|
|
149
|
+
const portText = match[1];
|
|
150
|
+
if (!portText)
|
|
151
|
+
continue;
|
|
152
|
+
const port = Number.parseInt(portText, 10);
|
|
153
|
+
if (!Number.isSafeInteger(port) || port < 1 || port > 65_535)
|
|
154
|
+
continue;
|
|
155
|
+
const otherDevice = deviceByPort.get(port);
|
|
156
|
+
if (otherDevice !== undefined && otherDevice !== deviceId) {
|
|
157
|
+
throw new Error('ADB reported an ambiguous local Valdi daemon forwarding port.');
|
|
158
|
+
}
|
|
159
|
+
deviceByPort.set(port, deviceId);
|
|
160
|
+
const key = `${deviceId}\0${port.toString()}`;
|
|
161
|
+
if (knownEndpoints.has(key))
|
|
162
|
+
continue;
|
|
163
|
+
if (endpoints.length >= MAX_ANDROID_DAEMON_ENDPOINTS) {
|
|
164
|
+
throw new Error(`ADB reported more than ${MAX_ANDROID_DAEMON_ENDPOINTS.toString()} Valdi daemon forwards.`);
|
|
165
|
+
}
|
|
166
|
+
knownEndpoints.add(key);
|
|
167
|
+
endpoints.push({ deviceId, port });
|
|
168
|
+
}
|
|
169
|
+
return endpoints.sort((left, right) => (left.deviceId ?? '').localeCompare(right.deviceId ?? '') || left.port - right.port);
|
|
170
|
+
}
|
|
171
|
+
async function discoverAndroidDaemonEndpoints() {
|
|
172
|
+
try {
|
|
173
|
+
const { stdout } = await execFile('adb', ['forward', '--list'], {
|
|
174
|
+
maxBuffer: MAX_ADB_FORWARD_OUTPUT_BYTES,
|
|
175
|
+
timeout: 2500,
|
|
176
|
+
});
|
|
177
|
+
return { endpoints: parseAndroidDaemonForwards(stdout), error: null };
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
return {
|
|
181
|
+
endpoints: [],
|
|
182
|
+
error: error instanceof Error ? error.message : String(error),
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
function parseDebuggerProxyTarget(candidate) {
|
|
187
|
+
if (typeof candidate !== 'object' || candidate === null || Array.isArray(candidate))
|
|
188
|
+
return undefined;
|
|
189
|
+
const value = candidate;
|
|
190
|
+
const id = boundedString(value['id'], MAX_PROXY_STRING_BYTES);
|
|
191
|
+
const webSocketDebuggerUrl = boundedString(value['webSocketDebuggerUrl'], MAX_PROXY_URL_BYTES);
|
|
192
|
+
if (!id || !webSocketDebuggerUrl || !isLoopbackWebSocketUrl(webSocketDebuggerUrl))
|
|
193
|
+
return undefined;
|
|
194
|
+
const rawMetadata = value['metadata'];
|
|
195
|
+
const metadataValue = typeof rawMetadata === 'object' && rawMetadata !== null && !Array.isArray(rawMetadata)
|
|
196
|
+
? rawMetadata
|
|
197
|
+
: undefined;
|
|
198
|
+
const adapterType = boundedString(value['adapterType'], MAX_PROXY_STRING_BYTES);
|
|
199
|
+
const hasAppId = Object.prototype.hasOwnProperty.call(value, 'appId');
|
|
200
|
+
const rawAppId = hasAppId ? value['appId'] : undefined;
|
|
201
|
+
const appId = boundedString(rawAppId, MAX_PROXY_STRING_BYTES);
|
|
202
|
+
if (hasAppId && (appId === undefined || appId.trim().length === 0))
|
|
203
|
+
return undefined;
|
|
204
|
+
const title = boundedString(value['title'], MAX_PROXY_STRING_BYTES);
|
|
205
|
+
const deviceId = boundedString(metadataValue?.['deviceId'], MAX_PROXY_STRING_BYTES);
|
|
206
|
+
const deviceName = boundedString(metadataValue?.['deviceName'], MAX_PROXY_STRING_BYTES);
|
|
207
|
+
return {
|
|
208
|
+
id,
|
|
209
|
+
webSocketDebuggerUrl,
|
|
210
|
+
...(adapterType === undefined ? {} : { adapterType }),
|
|
211
|
+
...(appId === undefined ? {} : { appId }),
|
|
212
|
+
...(title === undefined ? {} : { title }),
|
|
213
|
+
...(deviceId === undefined && deviceName === undefined
|
|
214
|
+
? {}
|
|
215
|
+
: {
|
|
216
|
+
metadata: {
|
|
217
|
+
...(deviceId === undefined ? {} : { deviceId }),
|
|
218
|
+
...(deviceName === undefined ? {} : { deviceName }),
|
|
219
|
+
},
|
|
220
|
+
}),
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
async function discoverDebuggerProxyTargets(port) {
|
|
224
|
+
return await new Promise((resolve, reject) => {
|
|
225
|
+
let settled = false;
|
|
226
|
+
let body = '';
|
|
227
|
+
let bodyBytes = 0;
|
|
228
|
+
const finishWithError = (error) => {
|
|
229
|
+
if (settled)
|
|
230
|
+
return;
|
|
231
|
+
settled = true;
|
|
232
|
+
reject(error);
|
|
233
|
+
};
|
|
234
|
+
const request = node_http_1.default.get(`http://127.0.0.1:${port.toString()}/json/list`, response => {
|
|
235
|
+
response.setEncoding('utf8');
|
|
236
|
+
response.on('data', (chunk) => {
|
|
237
|
+
bodyBytes += Buffer.byteLength(chunk, 'utf8');
|
|
238
|
+
if (bodyBytes > MAX_PROXY_RESPONSE_BYTES) {
|
|
239
|
+
request.destroy(new Error('The Valdi debugging proxy returned an oversized target list.'));
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
body += chunk;
|
|
243
|
+
});
|
|
244
|
+
response.once('error', error => finishWithError(error));
|
|
245
|
+
response.once('end', () => {
|
|
246
|
+
if (settled)
|
|
247
|
+
return;
|
|
248
|
+
if (response.statusCode !== 200) {
|
|
249
|
+
finishWithError(new Error(`The Valdi debugging proxy returned HTTP ${String(response.statusCode)}.`));
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
try {
|
|
253
|
+
const parsed = JSON.parse(body);
|
|
254
|
+
if (!Array.isArray(parsed)) {
|
|
255
|
+
finishWithError(new Error('The Valdi debugging proxy did not return a target list.'));
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if (parsed.length > MAX_PROXY_TARGETS) {
|
|
259
|
+
finishWithError(new Error(`The Valdi debugging proxy returned more than ${MAX_PROXY_TARGETS.toString()} targets.`));
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
const targets = parsed
|
|
263
|
+
.map(candidate => parseDebuggerProxyTarget(candidate))
|
|
264
|
+
.filter((candidate) => candidate !== undefined);
|
|
265
|
+
settled = true;
|
|
266
|
+
resolve(targets);
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
269
|
+
finishWithError(error instanceof Error ? error : new Error('The debugging proxy returned invalid JSON.'));
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
request.setTimeout(2500, () => request.destroy(new Error('Timed out discovering Valdi debugging proxy targets.')));
|
|
274
|
+
request.once('error', error => finishWithError(error));
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
function nativeTarget(port, client, context) {
|
|
278
|
+
if (!Number.isSafeInteger(port.port) || port.port < 1 || port.port > 65_535) {
|
|
279
|
+
throw new Error('Debugger target discovery returned an invalid daemon port.');
|
|
280
|
+
}
|
|
281
|
+
if (port.deviceId !== undefined)
|
|
282
|
+
assertBoundedIdentityString(port.deviceId, 'device ID', false);
|
|
283
|
+
assertBoundedIdentityString(client.client_id, 'client ID', false);
|
|
284
|
+
assertBoundedIdentityString(client.application_id, 'application ID', false);
|
|
285
|
+
assertBoundedIdentityString(client.platform, 'platform', true);
|
|
286
|
+
assertBoundedIdentityString(context.id, 'context ID', false);
|
|
287
|
+
assertBoundedIdentityString(context.rootComponentName, 'root component name', true);
|
|
288
|
+
const platform = platformFromValue(client.platform || port.portName);
|
|
289
|
+
return {
|
|
290
|
+
applicationId: client.application_id,
|
|
291
|
+
attachable: true,
|
|
292
|
+
capabilities: NATIVE_CAPABILITIES,
|
|
293
|
+
clientId: client.client_id,
|
|
294
|
+
contextId: context.id,
|
|
295
|
+
...(port.deviceId === undefined ? {} : { deviceId: port.deviceId }),
|
|
296
|
+
id: opaqueTargetId('valdi-daemon', [
|
|
297
|
+
platform,
|
|
298
|
+
client.platform,
|
|
299
|
+
port.portName,
|
|
300
|
+
port.deviceId ?? null,
|
|
301
|
+
port.port,
|
|
302
|
+
client.client_id,
|
|
303
|
+
client.application_id,
|
|
304
|
+
context.id,
|
|
305
|
+
]),
|
|
306
|
+
identityMode: DebuggerTargetIdentityMode.TargetId,
|
|
307
|
+
name: context.rootComponentName || client.application_id || `Client ${client.client_id}`,
|
|
308
|
+
platform,
|
|
309
|
+
port: port.port,
|
|
310
|
+
proxyPort: port.port,
|
|
311
|
+
state: DebuggerTargetState.Available,
|
|
312
|
+
transport: DebuggerTargetTransport.ValdiDaemon,
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
function proxyTargetPlatform(target) {
|
|
316
|
+
const deviceId = target.metadata?.deviceId;
|
|
317
|
+
if (deviceId === undefined)
|
|
318
|
+
return DebuggerTargetPlatform.Unknown;
|
|
319
|
+
assertBoundedIdentityString(deviceId, 'proxy device ID', false);
|
|
320
|
+
const adapterType = target.adapterType;
|
|
321
|
+
if (adapterType === 'android' || adapterType === '_android' || adapterType === `_android_${deviceId}`) {
|
|
322
|
+
return DebuggerTargetPlatform.Android;
|
|
323
|
+
}
|
|
324
|
+
if (adapterType === '_ios' || adapterType === `_ios_${deviceId}`) {
|
|
325
|
+
return DebuggerTargetPlatform.IOS;
|
|
326
|
+
}
|
|
327
|
+
return DebuggerTargetPlatform.Unknown;
|
|
328
|
+
}
|
|
329
|
+
function waitingProxyTarget(target, platform) {
|
|
330
|
+
const deviceId = target.metadata?.deviceId;
|
|
331
|
+
const applicationId = target.appId ?? deviceId ?? 'unknown';
|
|
332
|
+
return {
|
|
333
|
+
applicationId,
|
|
334
|
+
attachable: false,
|
|
335
|
+
capabilities: [DebuggerTargetCapability.JavaScriptDebugger],
|
|
336
|
+
...(deviceId === undefined ? {} : { deviceId }),
|
|
337
|
+
id: opaqueTargetId('javascript-proxy', [
|
|
338
|
+
platform,
|
|
339
|
+
target.adapterType ?? null,
|
|
340
|
+
target.id,
|
|
341
|
+
target.appId ?? null,
|
|
342
|
+
deviceId ?? null,
|
|
343
|
+
target.webSocketDebuggerUrl,
|
|
344
|
+
]),
|
|
345
|
+
identityMode: DebuggerTargetIdentityMode.TargetId,
|
|
346
|
+
javascriptDebuggerUrl: target.webSocketDebuggerUrl,
|
|
347
|
+
name: target.title ?? target.metadata?.deviceName ?? deviceId ?? target.appId ?? 'JavaScript runtime',
|
|
348
|
+
platform,
|
|
349
|
+
state: DebuggerTargetState.Waiting,
|
|
350
|
+
transport: DebuggerTargetTransport.ChromiumCDP,
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
function assertUniqueTargetIds(targets) {
|
|
354
|
+
const ids = new Set();
|
|
355
|
+
for (const target of targets) {
|
|
356
|
+
if (ids.has(target.id)) {
|
|
357
|
+
throw new Error('Debugger target discovery produced an ambiguous target identity.');
|
|
358
|
+
}
|
|
359
|
+
ids.add(target.id);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
function buildDebuggerTargetRegistry(options) {
|
|
363
|
+
if (options.ports.length > MAX_REGISTRY_PORTS) {
|
|
364
|
+
throw new Error(`Debugger target discovery exceeded ${MAX_REGISTRY_PORTS.toString()} daemon endpoints.`);
|
|
365
|
+
}
|
|
366
|
+
if (options.proxyTargets.length > MAX_PROXY_TARGETS || options.webPreviewTargets.length > 1) {
|
|
367
|
+
throw new Error('Debugger target discovery exceeded its bounded target sources.');
|
|
368
|
+
}
|
|
369
|
+
const targets = [];
|
|
370
|
+
for (const port of options.ports) {
|
|
371
|
+
if (!port.connected)
|
|
372
|
+
continue;
|
|
373
|
+
for (const client of port.clients) {
|
|
374
|
+
for (const context of client.contexts) {
|
|
375
|
+
if (targets.length >= MAX_REGISTRY_TARGETS) {
|
|
376
|
+
throw new Error(`Debugger target discovery exceeded ${MAX_REGISTRY_TARGETS.toString()} targets.`);
|
|
377
|
+
}
|
|
378
|
+
targets.push(nativeTarget(port, client, context));
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
if (targets.length + options.webPreviewTargets.length > MAX_REGISTRY_TARGETS) {
|
|
383
|
+
throw new Error(`Debugger target discovery exceeded ${MAX_REGISTRY_TARGETS.toString()} targets.`);
|
|
384
|
+
}
|
|
385
|
+
targets.push(...options.webPreviewTargets);
|
|
386
|
+
const claimedProxyTransportKeys = new Set();
|
|
387
|
+
for (const proxyTarget of options.proxyTargets) {
|
|
388
|
+
const proxyTransportKey = loopbackWebSocketTransportKey(proxyTarget.webSocketDebuggerUrl);
|
|
389
|
+
if (proxyTransportKey === undefined) {
|
|
390
|
+
throw new Error('Debugger proxy discovery returned a non-loopback target URL.');
|
|
391
|
+
}
|
|
392
|
+
if (claimedProxyTransportKeys.has(proxyTransportKey)) {
|
|
393
|
+
throw new Error('Debugger proxy discovery produced duplicate JavaScript transport endpoint ownership.');
|
|
394
|
+
}
|
|
395
|
+
claimedProxyTransportKeys.add(proxyTransportKey);
|
|
396
|
+
const platform = proxyTargetPlatform(proxyTarget);
|
|
397
|
+
if (platform === DebuggerTargetPlatform.Unknown)
|
|
398
|
+
continue;
|
|
399
|
+
const deviceId = proxyTarget.metadata?.deviceId;
|
|
400
|
+
const deviceScopedAndroidPlaceholder = platform === DebuggerTargetPlatform.Android &&
|
|
401
|
+
deviceId !== undefined &&
|
|
402
|
+
proxyTarget.adapterType === `_android_${deviceId}` &&
|
|
403
|
+
proxyTarget.appId !== undefined &&
|
|
404
|
+
proxyTarget.appId === deviceId;
|
|
405
|
+
const matchingNativeTargets = targets.filter(candidate => {
|
|
406
|
+
if (candidate.transport !== DebuggerTargetTransport.ValdiDaemon || deviceId === undefined)
|
|
407
|
+
return false;
|
|
408
|
+
if (candidate.deviceId !== deviceId || candidate.platform !== platform)
|
|
409
|
+
return false;
|
|
410
|
+
if (deviceScopedAndroidPlaceholder)
|
|
411
|
+
return true;
|
|
412
|
+
return proxyTarget.appId === undefined || candidate.applicationId === proxyTarget.appId;
|
|
413
|
+
});
|
|
414
|
+
if (matchingNativeTargets.length === 1) {
|
|
415
|
+
const existing = matchingNativeTargets[0];
|
|
416
|
+
if (!existing)
|
|
417
|
+
throw new Error('Debugger proxy discovery lost a unique native target match.');
|
|
418
|
+
if (existing.capabilities.includes(DebuggerTargetCapability.JavaScriptDebugger)) {
|
|
419
|
+
throw new Error('Debugger proxy discovery produced an ambiguous JavaScript target identity.');
|
|
420
|
+
}
|
|
421
|
+
const index = targets.indexOf(existing);
|
|
422
|
+
targets[index] = {
|
|
423
|
+
...existing,
|
|
424
|
+
capabilities: [...existing.capabilities, DebuggerTargetCapability.JavaScriptDebugger],
|
|
425
|
+
javascriptDebuggerUrl: proxyTarget.webSocketDebuggerUrl,
|
|
426
|
+
};
|
|
427
|
+
continue;
|
|
428
|
+
}
|
|
429
|
+
if (targets.length >= MAX_REGISTRY_TARGETS) {
|
|
430
|
+
throw new Error(`Debugger target discovery exceeded ${MAX_REGISTRY_TARGETS.toString()} targets.`);
|
|
431
|
+
}
|
|
432
|
+
targets.push(waitingProxyTarget(proxyTarget, platform));
|
|
433
|
+
}
|
|
434
|
+
assertUniqueTargetIds(targets);
|
|
435
|
+
return targets.sort((left, right) => left.platform.localeCompare(right.platform) || left.name.localeCompare(right.name));
|
|
436
|
+
}
|