@lynx-js/devtool-connector 0.19.2 → 0.20.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/dist/az.js CHANGED
@@ -92,6 +92,65 @@ function describeRequest(input) {
92
92
  function isNonEmptyListSessionResponse(response) {
93
93
  return isListSessionResponse(response) && response.data.data.length > 0;
94
94
  }
95
+ function attachAbortSignalToStream(stream, signal, onAborted) {
96
+ let reader;
97
+ let cleanup = ()=>{};
98
+ let finished = false;
99
+ return new ReadableStream({
100
+ start (controller) {
101
+ reader = stream.getReader();
102
+ const onAbort = ()=>{
103
+ if (finished) return;
104
+ finished = true;
105
+ cleanup();
106
+ onAborted?.();
107
+ const reason = signal.reason ?? new DOMException("The operation was aborted", "AbortError");
108
+ reader?.cancel(reason).catch(()=>{});
109
+ controller.error(reason);
110
+ };
111
+ cleanup = ()=>signal.removeEventListener("abort", onAbort);
112
+ signal.addEventListener("abort", onAbort, {
113
+ once: true
114
+ });
115
+ if (signal.aborted) onAbort();
116
+ },
117
+ async pull (controller) {
118
+ if (finished || !reader) return;
119
+ try {
120
+ const { value, done } = await reader.read();
121
+ if (finished) return;
122
+ if (done) {
123
+ finished = true;
124
+ cleanup();
125
+ reader.releaseLock();
126
+ controller.close();
127
+ return;
128
+ }
129
+ controller.enqueue(value);
130
+ } catch (error) {
131
+ if (finished) return;
132
+ finished = true;
133
+ cleanup();
134
+ reader.releaseLock();
135
+ controller.error(error);
136
+ }
137
+ },
138
+ async cancel (reason) {
139
+ finished = true;
140
+ cleanup();
141
+ const activeReader = reader;
142
+ reader = void 0;
143
+ if (!activeReader) return;
144
+ try {
145
+ await activeReader.cancel(reason);
146
+ } finally{
147
+ activeReader.releaseLock();
148
+ }
149
+ }
150
+ }, {
151
+ highWaterMark: 0
152
+ });
153
+ }
95
154
  class Connector {
96
155
  #transports;
97
156
  #hdtTransports;
@@ -181,12 +240,14 @@ class Connector {
181
240
  const results = await Promise.allSettled(this.#transports.map((t)=>t.listDevices()));
182
241
  return results.filter((result)=>"fulfilled" === result.status).flatMap(({ value })=>value);
183
242
  }
184
- async listAvailableApps(deviceId) {
185
- const transport = await this.#findTransportWithDeviceId(deviceId);
186
- return await transport.listAvailableApps(deviceId);
243
+ async listAvailableApps(deviceId, options) {
244
+ const transport = await this.#findTransportWithDeviceId(deviceId, options?.platform);
245
+ return await transport.listAvailableApps(deviceId, options?.platform === void 0 ? void 0 : {
246
+ platform: options.platform
247
+ });
187
248
  }
188
249
  async openApp(deviceId, packageName, options) {
189
- const transport = await this.#findTransportWithDeviceId(deviceId);
250
+ const transport = await this.#findTransportWithDeviceId(deviceId, options?.platform);
190
251
  await transport.openApp(deviceId, packageName, options);
191
252
  const signal = AbortSignal.any([
192
253
  options?.signal,
@@ -260,7 +321,7 @@ class Connector {
260
321
  ]
261
322
  }, signal);
262
323
  }
263
- async sendCDPMessage(clientId, sessionId, method, params, isMainThread = false) {
324
+ async sendCDPMessage(clientId, sessionId, method, params, isMainThread = false, signal) {
264
325
  const id = nextRequestId();
265
326
  const SUPPORTED_DOMAIN = [
266
327
  "Debugger",
@@ -278,10 +339,10 @@ class Connector {
278
339
  new CDPRequestTransformStream(sessionId, id)
279
340
  ],
280
341
  output: [
281
- new CDPResponseTransformStream(id),
342
+ new CDPResponseTransformStream(id, sessionId),
282
343
  new CDPOutputTransformStream()
283
344
  ]
284
- });
345
+ }, signal);
285
346
  }
286
347
  async sendListSessionMessage(clientId) {
287
348
  return await this.#sendListSessionMessage(clientId);
@@ -355,7 +416,7 @@ class Connector {
355
416
  ],
356
417
  output: [
357
418
  new SessionGuardTransformStream(sessionId),
358
- new CDPResponseTransformStream()
419
+ new CDPResponseTransformStream(void 0, sessionId)
359
420
  ]
360
421
  }
361
422
  });
@@ -404,30 +465,44 @@ class Connector {
404
465
  });
405
466
  const inputAbortController = new AbortController();
406
467
  const inputAbortReason = new Error("Connector input stream disposed");
468
+ const inputSignal = options.signal ? AbortSignal.any([
469
+ inputAbortController.signal,
470
+ options.signal
471
+ ]) : inputAbortController.signal;
407
472
  const inputClosed = [
408
473
  ...pipeline.input,
409
474
  new CustomizedClientIdTransformStream(port),
410
475
  new InspectStream((msg)=>debug(`connect ${deviceId}:${port} input stream send %o`, JSON.stringify(msg)))
411
476
  ].reduce((stream, transform)=>stream.pipeThrough(transform), inputStream).pipeTo(conn.writable, {
412
477
  preventClose: true,
413
- signal: inputAbortController.signal
478
+ signal: inputSignal
414
479
  }).catch((err)=>{
415
480
  if (err === inputAbortReason) return;
416
481
  debug(`connect ${deviceId}:${port} input stream err %O`, err);
417
482
  throw err;
418
483
  });
419
484
  const inputSettled = inputClosed.catch(()=>{});
420
- const outputStream = [
485
+ let connectionDisposePromise;
486
+ const disposeConnection = ()=>{
487
+ connectionDisposePromise ??= Promise.resolve().then(()=>conn[Symbol.asyncDispose]());
488
+ connectionDisposePromise.catch(()=>{});
489
+ return connectionDisposePromise;
490
+ };
491
+ const pipedOutputStream = [
421
492
  new InspectStream((msg)=>debug(`connect ${deviceId}:${port} output stream receive %O`, msg)),
422
493
  ...pipeline.output
423
494
  ].reduce((stream, transform)=>stream.pipeThrough(transform), conn.readable);
495
+ const outputStream = options.signal ? attachAbortSignalToStream(pipedOutputStream, options.signal, ()=>{
496
+ inputAbortController.abort(inputAbortReason);
497
+ disposeConnection();
498
+ }) : pipedOutputStream;
424
499
  return Object.assign(outputStream, {
425
500
  inputClosed,
426
501
  async [Symbol.asyncDispose] () {
427
502
  debug(`connect ${deviceId}:${port} close connection`);
428
503
  inputAbortController.abort(inputAbortReason);
429
- const connectionDisposed = Promise.resolve().then(()=>conn[Symbol.asyncDispose]());
430
- connectionDisposed.catch(()=>{});
504
+ if (!outputStream.locked) outputStream.cancel(inputAbortReason).catch(()=>{});
505
+ const connectionDisposed = disposeConnection();
431
506
  await inputSettled;
432
507
  return connectionDisposed;
433
508
  }
@@ -231,5 +231,5 @@ class InProcessCommandClient {
231
231
  }
232
232
  var command_DEFAULT_REACTLYNX_IDLE_MS = 700;
233
233
  var command_DEFAULT_REACTLYNX_MAX_MS = 5000;
234
- export { ActionCore, DevNodeType, NO_CLIENTS_FOUND_MESSAGE, ScreenshotAnnotationError, ScreenshotTimeoutError, annotateScreenshot, applyOperationV2, applyRootOrder, buildReactLynxOutboundFrame, buildReactLynxUpdatePath, buildRefs, buildRegexMatcher, buildSnapshot, buildSubstringMatcher, captureScreenshot, captureScreenshotFrame, centerOfQuad, createRendererState, deserializeRendererState, fail, fetchDebugMetadata, findReactLynxComponents, formatReactLynxTree, getOriginalNodeSourceInfo, listClientsAction, listSessionsAction, normalizeRef, ok, openAction, parseReactLynxComponentRef, parseReactLynxLinkRef, reactLynxEmptyTreeDiagnostic, remapOriginalNodeSourceInfo, runReactLynxSession, serializeRendererState, touchTap, typeTag, validateRef, waitForClientStream } from "../f.js";
234
+ export { ActionCore, DevNodeType, NO_CLIENTS_FOUND_MESSAGE, ScreenshotAnnotationError, ScreenshotTimeoutError, annotateScreenshot, applyOperationV2, applyRootOrder, buildReactLynxOutboundFrame, buildReactLynxPageHookFrame, buildReactLynxUpdatePath, buildRefs, buildRegexMatcher, buildSnapshot, buildSubstringMatcher, captureScreenshot, captureScreenshotFrame, centerOfQuad, createRendererState, deserializeRendererState, fail, fetchDebugMetadata, findReactLynxComponents, formatReactLynxTree, getOriginalNodeSourceInfo, listClientsAction, listSessionsAction, normalizeRef, ok, openAction, parseReactLynxComponentRef, parseReactLynxLinkRef, reactLynxEmptyTreeDiagnostic, remapOriginalNodeSourceInfo, runReactLynxSession, serializeRendererState, touchTap, typeTag, validateRef, waitForClientStream } from "../f.js";
235
235
  export { HttpCommandClient, InProcessCommandClient, callCommand, callRawCommand, command_DEFAULT_REACTLYNX_IDLE_MS as DEFAULT_REACTLYNX_IDLE_MS, command_DEFAULT_REACTLYNX_MAX_MS as DEFAULT_REACTLYNX_MAX_MS, streamCommand, streamRawCommand };
@@ -50,7 +50,7 @@ export declare class ReactLynxController {
50
50
  refresh: boolean;
51
51
  }, signal: AbortSignal): Promise<ReactLynxComponentData>;
52
52
  componentForElement(connector: Connector, target: Target, options: {
53
- uniqueId: number;
53
+ uniqueIds: readonly number[];
54
54
  showShells: boolean;
55
55
  refresh: boolean;
56
56
  }, signal: AbortSignal): Promise<ReactLynxElementToComponentMapping>;
@@ -8,6 +8,7 @@ export interface PreactEnvelope<T = unknown> {
8
8
  data: T;
9
9
  }
10
10
  export interface ReactLynxOutboundFrame {
11
+ id?: number;
11
12
  method: string;
12
13
  params: {
13
14
  vmType: string;
@@ -16,6 +17,8 @@ export interface ReactLynxOutboundFrame {
16
17
  };
17
18
  }
18
19
  export declare function buildReactLynxOutboundFrame<T = null>(type: string, data?: T): ReactLynxOutboundFrame;
20
+ /** Build a `preact-page-hook` frame (e.g. `root-order-page` FIFO sentinel). */
21
+ export declare function buildReactLynxPageHookFrame<T = null>(type: string, data?: T): ReactLynxOutboundFrame;
19
22
  export interface ReactLynxSessionResult {
20
23
  state: RendererState;
21
24
  framesSeen: number;