@limrun/api 0.72.0 → 0.73.1

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.
Files changed (50) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/index.d.mts +2 -1
  3. package/index.d.mts.map +1 -1
  4. package/index.d.ts +2 -1
  5. package/index.d.ts.map +1 -1
  6. package/index.js +4 -2
  7. package/index.js.map +1 -1
  8. package/index.mjs +1 -0
  9. package/index.mjs.map +1 -1
  10. package/ios-client.d.mts +64 -0
  11. package/ios-client.d.mts.map +1 -1
  12. package/ios-client.d.ts +64 -0
  13. package/ios-client.d.ts.map +1 -1
  14. package/ios-client.js +122 -25
  15. package/ios-client.js.map +1 -1
  16. package/ios-client.mjs +120 -24
  17. package/ios-client.mjs.map +1 -1
  18. package/package.json +11 -1
  19. package/resources/index.d.mts +1 -1
  20. package/resources/index.d.mts.map +1 -1
  21. package/resources/index.d.ts +1 -1
  22. package/resources/index.d.ts.map +1 -1
  23. package/resources/index.js.map +1 -1
  24. package/resources/index.mjs.map +1 -1
  25. package/resources/xcode-instances-helpers.d.mts +18 -0
  26. package/resources/xcode-instances-helpers.d.mts.map +1 -1
  27. package/resources/xcode-instances-helpers.d.ts +18 -0
  28. package/resources/xcode-instances-helpers.d.ts.map +1 -1
  29. package/resources/xcode-instances-helpers.js +10 -0
  30. package/resources/xcode-instances-helpers.js.map +1 -1
  31. package/resources/xcode-instances-helpers.mjs +10 -0
  32. package/resources/xcode-instances-helpers.mjs.map +1 -1
  33. package/simulator-debug-symbols.d.mts +6 -0
  34. package/simulator-debug-symbols.d.mts.map +1 -0
  35. package/simulator-debug-symbols.d.ts +6 -0
  36. package/simulator-debug-symbols.d.ts.map +1 -0
  37. package/simulator-debug-symbols.js +13 -0
  38. package/simulator-debug-symbols.js.map +1 -0
  39. package/simulator-debug-symbols.mjs +9 -0
  40. package/simulator-debug-symbols.mjs.map +1 -0
  41. package/src/index.ts +2 -0
  42. package/src/ios-client.ts +190 -27
  43. package/src/resources/index.ts +1 -0
  44. package/src/resources/xcode-instances-helpers.ts +35 -0
  45. package/src/simulator-debug-symbols.ts +11 -0
  46. package/src/version.ts +1 -1
  47. package/version.d.mts +1 -1
  48. package/version.d.ts +1 -1
  49. package/version.js +1 -1
  50. package/version.mjs +1 -1
package/src/ios-client.ts CHANGED
@@ -1335,6 +1335,26 @@ export type InstanceClient = {
1335
1335
  */
1336
1336
  simctl: (args: string[], opts?: SimctlOptions) => SimctlExecution;
1337
1337
 
1338
+ /**
1339
+ * Run Xcode's LLDB inside the simulator, attached to an app when `bundleId` or `pid` is given.
1340
+ * LLDB can debug the simulator's apps built with the `get-task-allow` entitlement, which
1341
+ * Xcode adds to debug builds.
1342
+ *
1343
+ * @param args Arguments passed to `lldb`, such as `['--batch', '-o', 'bt']`
1344
+ * @param opts Which process to attach to and how standard input is fed
1345
+ * @returns An LldbExecution handle for output and, with `keepStdinOpen`, live input
1346
+ *
1347
+ * @example
1348
+ * ```typescript
1349
+ * // One-shot: print a backtrace and detach
1350
+ * const result = await client
1351
+ * .lldb(['--batch', '-o', 'bt', '-o', 'detach'], { bundleId: 'com.example.app' })
1352
+ * .wait();
1353
+ * console.log(result.stdout);
1354
+ * ```
1355
+ */
1356
+ lldb: (args: string[], opts?: LldbOptions) => LldbExecution;
1357
+
1338
1358
  /**
1339
1359
  * Push a local file to the simulator. Returns the path of the file on the simulator host
1340
1360
  * that can be used in simctl commands.
@@ -1567,6 +1587,36 @@ type SimctlRequest = {
1567
1587
  stdin?: string;
1568
1588
  };
1569
1589
 
1590
+ /**
1591
+ * Options for an LLDB session
1592
+ */
1593
+ export type LldbOptions = {
1594
+ /** Attach to the running app with this bundle ID. */
1595
+ bundleId?: string;
1596
+ /** Attach to this process of the simulator. */
1597
+ pid?: number;
1598
+ /** Commands written to LLDB's standard input before anything sent with `write`. */
1599
+ stdin?: string | Buffer;
1600
+ /**
1601
+ * Keep standard input open for `write` and `end`. Without it LLDB runs its arguments and
1602
+ * `stdin`, then exits.
1603
+ */
1604
+ keepStdinOpen?: boolean;
1605
+ /** Disconnect from the instance when LLDB exits */
1606
+ disconnectOnExit?: boolean;
1607
+ };
1608
+
1609
+ type LldbRequest = {
1610
+ type: 'lldb';
1611
+ id: string;
1612
+ args: string[];
1613
+ bundleId?: string;
1614
+ pid?: number;
1615
+ /** Base64 of LLDB's initial standard input */
1616
+ stdin?: string;
1617
+ keepStdinOpen?: boolean;
1618
+ };
1619
+
1570
1620
  /**
1571
1621
  * Generic server response with optional error
1572
1622
  */
@@ -1811,6 +1861,65 @@ export class SimctlExecution extends EventEmitter {
1811
1861
  }
1812
1862
  }
1813
1863
 
1864
+ /**
1865
+ * Handle for a running LLDB session. It streams output like a simctl execution, and takes
1866
+ * commands on standard input when the session was started with `keepStdinOpen`.
1867
+ *
1868
+ * @example
1869
+ * ```typescript
1870
+ * const session = client.lldb([], { bundleId: 'com.example.app', keepStdinOpen: true });
1871
+ * session.on('stdout', (data) => process.stdout.write(data));
1872
+ * session.write('bt\n');
1873
+ * session.end(); // LLDB detaches and exits once it has read everything
1874
+ * await session.wait();
1875
+ * ```
1876
+ */
1877
+ export class LldbExecution extends SimctlExecution {
1878
+ private sendInput: (data: Buffer | undefined, close: boolean, sequence: number) => void;
1879
+ private started = false;
1880
+ private held: Array<[Buffer | undefined, boolean, number]> = [];
1881
+ private sequence = 0;
1882
+
1883
+ constructor(
1884
+ stopCallback: () => void,
1885
+ sendInput: (data: Buffer | undefined, close: boolean, sequence: number) => void,
1886
+ ) {
1887
+ super(stopCallback);
1888
+ this.sendInput = sendInput;
1889
+ }
1890
+
1891
+ /** Write to LLDB's standard input. End each command with a newline. */
1892
+ write(data: string | Buffer): void {
1893
+ this.input(Buffer.from(data), false);
1894
+ }
1895
+
1896
+ /** Close LLDB's standard input. LLDB detaches from the process and exits. */
1897
+ end(): void {
1898
+ this.input(undefined, true);
1899
+ }
1900
+
1901
+ // The instance drops input for a session it has not started yet, so input waits for the
1902
+ // session's first frame. Each write is numbered: the instance handles the messages of a
1903
+ // connection concurrently and uses the number to apply them in order.
1904
+ private input(data: Buffer | undefined, close: boolean): void {
1905
+ const sequence = this.sequence++;
1906
+ if (this.started) {
1907
+ this.sendInput(data, close, sequence);
1908
+ } else {
1909
+ this.held.push([data, close, sequence]);
1910
+ }
1911
+ }
1912
+
1913
+ /** @internal - The instance sent the session's first frame, so LLDB is reading its input */
1914
+ _handleStarted(): void {
1915
+ if (this.started) return;
1916
+ this.started = true;
1917
+ for (const [data, close, sequence] of this.held.splice(0)) {
1918
+ this.sendInput(data, close, sequence);
1919
+ }
1920
+ }
1921
+ }
1922
+
1814
1923
  export type PerformanceStreamOptions = {
1815
1924
  /** The instance's status.apiUrl. */
1816
1925
  apiUrl: string;
@@ -2274,6 +2383,9 @@ export async function createInstanceClient(options: InstanceClientOptions): Prom
2274
2383
  logger.debug(`Received simctl stream for unknown execution: ${message.id}`);
2275
2384
  return;
2276
2385
  }
2386
+ if (execution instanceof LldbExecution) {
2387
+ execution._handleStarted();
2388
+ }
2277
2389
 
2278
2390
  if (message.stdout) {
2279
2391
  try {
@@ -2457,6 +2569,7 @@ export async function createInstanceClient(options: InstanceClientOptions): Prom
2457
2569
  getConnectionState,
2458
2570
  onConnectionStateChange,
2459
2571
  simctl,
2572
+ lldb,
2460
2573
  xcrun,
2461
2574
  startXcrunShim,
2462
2575
  xcodebuild,
@@ -3171,30 +3284,23 @@ export async function createInstanceClient(options: InstanceClientOptions): Prom
3171
3284
  // Cached device info, populated during connection
3172
3285
  let cachedDeviceInfo: DeviceInfo;
3173
3286
 
3174
- const simctl = (args: string[], opts: SimctlOptions = {}): SimctlExecution => {
3175
- const id = generateId();
3176
-
3177
- const cancelCallback = () => {
3178
- // Clean up execution tracking
3179
- simctlExecutions.delete(id);
3180
- if (opts.disconnectOnExit) {
3181
- logger.debug(`Simctl execution ${id} cancelled, disconnecting due to disconnectOnExit`);
3182
- disconnect();
3183
- }
3184
- logger.debug(`Simctl execution ${id} cancelled`);
3185
- };
3186
-
3187
- const execution = new SimctlExecution(cancelCallback);
3287
+ /** Tracks a streamed command, sends its request, and returns the handle. */
3288
+ const startExecution = <E extends SimctlExecution>(
3289
+ id: string,
3290
+ execution: E,
3291
+ request: SimctlRequest | LldbRequest,
3292
+ disconnectOnExit: boolean | undefined,
3293
+ ): E => {
3188
3294
  simctlExecutions.set(id, execution);
3189
3295
 
3190
3296
  // If disconnectOnExit is enabled, register listeners before any async operations
3191
- if (opts.disconnectOnExit) {
3297
+ if (disconnectOnExit) {
3192
3298
  execution.once('exit', () => {
3193
- logger.debug(`Simctl execution ${id} finished, disconnecting due to disconnectOnExit`);
3299
+ logger.debug(`Execution ${id} finished, disconnecting due to disconnectOnExit`);
3194
3300
  disconnect();
3195
3301
  });
3196
3302
  execution.once('error', () => {
3197
- logger.debug(`Simctl execution ${id} errored, disconnecting due to disconnectOnExit`);
3303
+ logger.debug(`Execution ${id} errored, disconnecting due to disconnectOnExit`);
3198
3304
  disconnect();
3199
3305
  });
3200
3306
  }
@@ -3209,25 +3315,82 @@ export async function createInstanceClient(options: InstanceClientOptions): Prom
3209
3315
  return execution;
3210
3316
  }
3211
3317
 
3212
- const simctlRequest: SimctlRequest = {
3318
+ // stdin can carry secrets such as one-time codes, so it stays out of the log.
3319
+ logger.debug(`Sending ${request.type} request:`, { ...request, stdin: undefined });
3320
+ ws.send(JSON.stringify(request), (err?: Error) => {
3321
+ if (err) {
3322
+ logger.error(`Failed to send ${request.type} request:`, err);
3323
+ execution._handleError(err);
3324
+ simctlExecutions.delete(id);
3325
+ }
3326
+ });
3327
+
3328
+ return execution;
3329
+ };
3330
+
3331
+ /** Forgets a stopped command, and disconnects when its caller asked for that. */
3332
+ const stopExecution = (id: string, disconnectOnExit: boolean | undefined) => () => {
3333
+ simctlExecutions.delete(id);
3334
+ if (disconnectOnExit) {
3335
+ logger.debug(`Execution ${id} cancelled, disconnecting due to disconnectOnExit`);
3336
+ disconnect();
3337
+ }
3338
+ logger.debug(`Execution ${id} cancelled`);
3339
+ };
3340
+
3341
+ const simctl = (args: string[], opts: SimctlOptions = {}): SimctlExecution => {
3342
+ const id = generateId();
3343
+ const request: SimctlRequest = {
3213
3344
  type: 'simctl',
3214
3345
  ...(opts.envFromSecret && { envFromSecret: opts.envFromSecret }),
3215
3346
  id,
3216
3347
  args,
3217
3348
  ...(opts.stdin !== undefined && { stdin: Buffer.from(opts.stdin).toString('base64') }),
3218
3349
  };
3350
+ return startExecution(
3351
+ id,
3352
+ new SimctlExecution(stopExecution(id, opts.disconnectOnExit)),
3353
+ request,
3354
+ opts.disconnectOnExit,
3355
+ );
3356
+ };
3219
3357
 
3220
- // stdin can carry secrets such as one-time codes, so it stays out of the log.
3221
- logger.debug('Sending simctl request:', { ...simctlRequest, stdin: undefined });
3222
- ws.send(JSON.stringify(simctlRequest), (err?: Error) => {
3223
- if (err) {
3224
- logger.error('Failed to send simctl request:', err);
3225
- execution._handleError(err);
3358
+ const lldb = (args: string[], opts: LldbOptions = {}): LldbExecution => {
3359
+ const id = generateId();
3360
+ const sendInput = (data: Buffer | undefined, close: boolean, sequence: number) => {
3361
+ if (!ws || ws.readyState !== WebSocket.OPEN) return;
3362
+ ws.send(
3363
+ JSON.stringify({
3364
+ type: 'lldbInput',
3365
+ id,
3366
+ sequence,
3367
+ ...(data && { data: data.toString('base64') }),
3368
+ ...(close && { close }),
3369
+ }),
3370
+ );
3371
+ };
3372
+ const execution: LldbExecution = new LldbExecution(() => {
3373
+ // The session stays tracked: the instance answers with the exit of LLDB, which is what
3374
+ // ends `wait()`. A session dropped without `end` would otherwise keep the app stopped.
3375
+ if (!execution.isRunning) return;
3376
+ if (ws && ws.readyState === WebSocket.OPEN) {
3377
+ ws.send(JSON.stringify({ type: 'simctlTerminate', id }));
3378
+ } else {
3379
+ // Without a connection the instance has already ended the session and cannot say so.
3226
3380
  simctlExecutions.delete(id);
3381
+ execution._handleExit(143);
3227
3382
  }
3228
- });
3229
-
3230
- return execution;
3383
+ }, sendInput);
3384
+ const request: LldbRequest = {
3385
+ type: 'lldb',
3386
+ id,
3387
+ args,
3388
+ ...(opts.bundleId !== undefined && { bundleId: opts.bundleId }),
3389
+ ...(opts.pid !== undefined && { pid: opts.pid }),
3390
+ ...(opts.stdin !== undefined && { stdin: Buffer.from(opts.stdin).toString('base64') }),
3391
+ ...(opts.keepStdinOpen && { keepStdinOpen: true }),
3392
+ };
3393
+ return startExecution(id, execution, request, opts.disconnectOnExit);
3231
3394
  };
3232
3395
 
3233
3396
  const buildFilesUrl = (name: string, opts?: ContainerTargetOptions): string => {
@@ -89,6 +89,7 @@ export {
89
89
  type XcodeCloudSigningMethod,
90
90
  type ReactNativeBuildConfig,
91
91
  type SimulatorAttachResult,
92
+ type SimulatorDebugSymbols,
92
93
  type SimulatorStatus,
93
94
  type SimulatorBuildStatus,
94
95
  type SimulatorAttachment,
@@ -1,4 +1,5 @@
1
1
  import { DeviceDetachUnavailableError } from '../device-detach';
2
+ import { SimulatorDebugSymbolsUnavailableError } from '../simulator-debug-symbols';
2
3
  import { pullBuildFile } from '../internal/build-pull-file';
3
4
  import { pullResultBundle } from '../internal/result-bundle';
4
5
  import { normalizeAssetUpload, type BuildUpload } from '../lib/asset-permissions';
@@ -357,6 +358,16 @@ export type SimulatorStatus = {
357
358
  latestBuild?: SimulatorBuildStatus;
358
359
  };
359
360
 
361
+ export type SimulatorDebugSymbols = {
362
+ buildId: string;
363
+ bundleId?: string;
364
+ /**
365
+ * Symbol files on the simulator, one per binary of the app that carries debug info. Empty
366
+ * when the build has none the Xcode instance can read, such as a remote Bazel build.
367
+ */
368
+ paths: string[];
369
+ };
370
+
360
371
  export type SimulatorAttachResult = {
361
372
  attached: boolean;
362
373
  alreadyAttached: boolean;
@@ -551,6 +562,16 @@ export type XcodeClient = {
551
562
  */
552
563
  getSimulator: () => Promise<SimulatorStatus>;
553
564
 
565
+ /**
566
+ * Upload the debug symbols of the latest build installed on the attached simulator to it,
567
+ * so a debugger there resolves source lines and variables: load each returned path with
568
+ * LLDB's `target symbols add`. Simulator builds keep their debug info on the Xcode instance,
569
+ * out of the simulator's reach. Throws when no simulator is attached or it has no build
570
+ * from this instance, and `SimulatorDebugSymbolsUnavailableError` when the instance predates
571
+ * this feature.
572
+ */
573
+ syncSimulatorDebugSymbols: () => Promise<SimulatorDebugSymbols>;
574
+
554
575
  /** Disconnect the simulator, keeping both instances and installed apps. */
555
576
  detachSimulator: () => Promise<SimulatorStatus>;
556
577
 
@@ -1114,6 +1135,20 @@ export class XcodeInstances extends GeneratedXcodeInstances {
1114
1135
  return readJsonResponse<SimulatorStatus>(res, 'GET /simulator');
1115
1136
  },
1116
1137
 
1138
+ async syncSimulatorDebugSymbols(): Promise<SimulatorDebugSymbols> {
1139
+ // The instance links and uploads the symbols before it answers, which takes minutes
1140
+ // for a large app.
1141
+ const res = await nodeProxyTransport.fetchLongRequest(`${apiUrl}/simulator/debug-symbols`, {
1142
+ method: 'POST',
1143
+ headers: { Authorization: `Bearer ${token}` },
1144
+ });
1145
+ return readOrUnsupported<SimulatorDebugSymbols>(
1146
+ res,
1147
+ 'POST /simulator/debug-symbols',
1148
+ (op) => new SimulatorDebugSymbolsUnavailableError(op),
1149
+ );
1150
+ },
1151
+
1117
1152
  async detachSimulator(): Promise<SimulatorStatus> {
1118
1153
  const res = await nodeProxyTransport.fetch(`${apiUrl}/simulator`, {
1119
1154
  method: 'DELETE',
@@ -0,0 +1,11 @@
1
+ import { LimrunError } from './core/error';
2
+
3
+ /** The debug symbol route returned 404; the Xcode instance may be older or may be gone. */
4
+ export class SimulatorDebugSymbolsUnavailableError extends LimrunError {
5
+ constructor(operation: string) {
6
+ super(
7
+ `${operation} is unavailable; this Xcode instance may predate debug symbol support or no longer exist.`,
8
+ );
9
+ this.name = 'SimulatorDebugSymbolsUnavailableError';
10
+ }
11
+ }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.72.0'; // x-release-please-version
1
+ export const VERSION = '0.73.1'; // x-release-please-version
package/version.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.72.0";
1
+ export declare const VERSION = "0.73.1";
2
2
  //# sourceMappingURL=version.d.mts.map
package/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.72.0";
1
+ export declare const VERSION = "0.73.1";
2
2
  //# sourceMappingURL=version.d.ts.map
package/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = '0.72.0'; // x-release-please-version
4
+ exports.VERSION = '0.73.1'; // x-release-please-version
5
5
  //# sourceMappingURL=version.js.map
package/version.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '0.72.0'; // x-release-please-version
1
+ export const VERSION = '0.73.1'; // x-release-please-version
2
2
  //# sourceMappingURL=version.mjs.map