@swmansion/argent 0.34.1-next.35 → 0.34.1-next.36

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/cli-cmds.mjs CHANGED
@@ -36256,7 +36256,7 @@ function isCi(env = process.env) {
36256
36256
  var SESSION_ID2 = randomUUID5();
36257
36257
  function readCliVersion() {
36258
36258
  if (true) {
36259
- return "0.34.1-next.35";
36259
+ return "0.34.1-next.36";
36260
36260
  }
36261
36261
  return "0.0.0";
36262
36262
  }
@@ -16942,7 +16942,7 @@ function isCi(env = process.env) {
16942
16942
  var SESSION_ID = randomUUID4();
16943
16943
  function readCliVersion() {
16944
16944
  if (true) {
16945
- return "0.34.1-next.35";
16945
+ return "0.34.1-next.36";
16946
16946
  }
16947
16947
  return "0.0.0";
16948
16948
  }
@@ -101440,7 +101440,7 @@ function isCi(env = process.env) {
101440
101440
  var SESSION_ID = (0, import_node_crypto3.randomUUID)();
101441
101441
  function readCliVersion() {
101442
101442
  if (true) {
101443
- return "0.34.1-next.35";
101443
+ return "0.34.1-next.36";
101444
101444
  }
101445
101445
  return "0.0.0";
101446
101446
  }
@@ -127849,6 +127849,59 @@ function bracketed(hostname4) {
127849
127849
  return hostname4.includes(":") && !hostname4.startsWith("[") ? `[${hostname4}]` : hostname4;
127850
127850
  }
127851
127851
 
127852
+ // ../tool-server/src/utils/debugger/scripts/await-promise.ts
127853
+ var WATCH_PROMISE_FUNCTION = `function (slot) {
127854
+ var self = this;
127855
+ var then = self.then;
127856
+ if (typeof then !== "function") return self;
127857
+
127858
+ var box = { settled: false, rejected: false, value: undefined };
127859
+ globalThis[slot] = box;
127860
+
127861
+ new Promise(function (resolve, reject) {
127862
+ then.call(self, resolve, reject);
127863
+ }).then(
127864
+ function (value) {
127865
+ box.settled = true;
127866
+ box.value = value;
127867
+ },
127868
+ function (reason) {
127869
+ box.settled = true;
127870
+ box.rejected = true;
127871
+ box.value = reason;
127872
+ }
127873
+ );
127874
+
127875
+ return slot;
127876
+ }`;
127877
+ function takeSettledScript(slot) {
127878
+ return `(function (slot) {
127879
+ var box = globalThis[slot];
127880
+ if (!box) throw ownError("The JS context reloaded while the Promise was pending.");
127881
+ if (!box.settled) return slot;
127882
+
127883
+ delete globalThis[slot];
127884
+ if (!box.rejected) return box.value;
127885
+ if (box.value instanceof Error) throw box.value;
127886
+ throw ownError("Promise rejected with: " + describe(box.value));
127887
+
127888
+ function ownError(message) {
127889
+ var error = new Error(message);
127890
+ error.stack = "";
127891
+ return error;
127892
+ }
127893
+
127894
+ function describe(reason) {
127895
+ try {
127896
+ var json = JSON.stringify(reason);
127897
+ return json === undefined ? String(reason) : json;
127898
+ } catch (e) {
127899
+ return Object.prototype.toString.call(reason);
127900
+ }
127901
+ }
127902
+ })(${JSON.stringify(slot)})`;
127903
+ }
127904
+
127852
127905
  // ../tool-server/src/utils/debugger/cdp-client.ts
127853
127906
  var BLOCKED_WHILE_PAUSED = /* @__PURE__ */ new Set(["Runtime.evaluate", "Runtime.callFunctionOn"]);
127854
127907
  function trimBundleQuery(url2) {
@@ -127869,7 +127922,16 @@ function formatExceptionDetails(details) {
127869
127922
  return `${description}
127870
127923
  ${frameLines}`;
127871
127924
  }
127925
+ function runtimeException(details) {
127926
+ return new FailureError(formatExceptionDetails(details), {
127927
+ error_code: FAILURE_CODES.DEBUGGER_CDP_RUNTIME_EXCEPTION,
127928
+ failure_stage: "debugger_cdp_evaluate",
127929
+ failure_area: "tool_server",
127930
+ error_kind: "unknown"
127931
+ });
127932
+ }
127872
127933
  var DEFAULT_TIMEOUT_MS2 = 1e4;
127934
+ var PROMISE_POLL_INTERVAL_MS = 100;
127873
127935
  var ORIGIN_SETTLE_MS = 100;
127874
127936
  var acceptedOrigins = /* @__PURE__ */ new Map();
127875
127937
  var CDPClient = class {
@@ -127891,9 +127953,16 @@ var CDPClient = class {
127891
127953
  paused;
127892
127954
  wsUrl;
127893
127955
  sendOrigin;
127956
+ /**
127957
+ * Hermes ignores `awaitPromise`, so {@linkcode evaluateAwaited} waits for a
127958
+ * returned Promise inside the app instead. Set only for Hermes behind the
127959
+ * modern inspector: it relies on `Runtime.callFunctionOn`.
127960
+ */
127961
+ awaitPromisesInApp;
127894
127962
  constructor(wsUrl, options) {
127895
127963
  this.wsUrl = wsUrl;
127896
127964
  this.sendOrigin = options?.sendOrigin !== false;
127965
+ this.awaitPromisesInApp = options?.awaitPromisesInApp === true;
127897
127966
  }
127898
127967
  async connect() {
127899
127968
  if (!this.sendOrigin) {
@@ -128162,20 +128231,68 @@ var CDPClient = class {
128162
128231
  async evaluate(expression, options) {
128163
128232
  const returnByValue = options?.returnByValue ?? true;
128164
128233
  const awaitPromise = options?.awaitPromise ?? true;
128165
- const result = await this.send(
128234
+ const result = await this.runtimeCall(
128166
128235
  "Runtime.evaluate",
128167
128236
  { expression, returnByValue, awaitPromise },
128168
128237
  options?.timeout
128169
128238
  );
128170
- if (result.exceptionDetails) {
128171
- throw new FailureError(formatExceptionDetails(result.exceptionDetails), {
128172
- error_code: FAILURE_CODES.DEBUGGER_CDP_RUNTIME_EXCEPTION,
128173
- failure_stage: "debugger_cdp_evaluate",
128174
- failure_area: "tool_server",
128175
- error_kind: "unknown"
128239
+ return result?.value;
128240
+ }
128241
+ /**
128242
+ * {@linkcode evaluate}, also on runtimes that ignore `awaitPromise`: a
128243
+ * returned Promise yields the value it resolves to, and a rejection throws
128244
+ * like an exception. A Promise still pending after {@linkcode DEFAULT_TIMEOUT_MS}
128245
+ * fails with DEBUGGER_CDP_REQUEST_TIMEOUT.
128246
+ */
128247
+ async evaluateAwaited(expression) {
128248
+ if (!this.awaitPromisesInApp) return this.evaluate(expression);
128249
+ const result = await this.runtimeCall("Runtime.evaluate", { expression, returnByValue: false });
128250
+ const objectId = result?.objectId;
128251
+ if (!objectId || result?.type !== "object" && result?.type !== "function") {
128252
+ return result?.value;
128253
+ }
128254
+ const slot = `__argentPromise_${crypto3.randomUUID().replace(/-/g, "")}`;
128255
+ let watched2;
128256
+ try {
128257
+ const response = await this.runtimeCall("Runtime.callFunctionOn", {
128258
+ objectId,
128259
+ functionDeclaration: WATCH_PROMISE_FUNCTION,
128260
+ arguments: [{ value: slot }],
128261
+ returnByValue: true
128262
+ });
128263
+ watched2 = response?.value;
128264
+ } finally {
128265
+ this.send("Runtime.releaseObject", { objectId }).catch(() => {
128176
128266
  });
128177
128267
  }
128178
- return result.result?.value;
128268
+ if (watched2 !== slot) return watched2;
128269
+ return this.waitForSettled(slot);
128270
+ }
128271
+ async runtimeCall(method, params, timeout) {
128272
+ const response = await this.send(method, params, timeout);
128273
+ if (response.exceptionDetails) throw runtimeException(response.exceptionDetails);
128274
+ return response.result;
128275
+ }
128276
+ async waitForSettled(slot) {
128277
+ const take2 = takeSettledScript(slot);
128278
+ const deadline = Date.now() + DEFAULT_TIMEOUT_MS2;
128279
+ let taken = await this.evaluate(take2);
128280
+ while (taken === slot && Date.now() < deadline) {
128281
+ await sleep(PROMISE_POLL_INTERVAL_MS);
128282
+ taken = await this.evaluate(take2);
128283
+ }
128284
+ if (taken !== slot) return taken;
128285
+ this.evaluate(`delete globalThis[${JSON.stringify(slot)}]`).catch(() => {
128286
+ });
128287
+ throw new FailureError(
128288
+ `The expression returned a Promise that did not settle within ${DEFAULT_TIMEOUT_MS2}ms. The expression ran, and running it again repeats its side effects.`,
128289
+ {
128290
+ error_code: FAILURE_CODES.DEBUGGER_CDP_REQUEST_TIMEOUT,
128291
+ failure_stage: "debugger_cdp_await_promise",
128292
+ failure_area: "tool_server",
128293
+ error_kind: "timeout"
128294
+ }
128295
+ );
128179
128296
  }
128180
128297
  /**
128181
128298
  * With `legacyInspector`, a protocol error leaves the binding unavailable
@@ -151780,7 +151897,9 @@ var jsRuntimeDebuggerBlueprint = {
151780
151897
  });
151781
151898
  const onPublishedBundler = publishedMetroPort(deviceId, port) === void 0;
151782
151899
  const proxied = onPublishedBundler ? externalJsDebuggerUrl(deviceId) : void 0;
151783
- const cdp = new CDPClient(proxied ?? selected.webSocketUrl);
151900
+ const cdp = new CDPClient(proxied ?? selected.webSocketUrl, {
151901
+ awaitPromisesInApp: !selected.legacyInspector
151902
+ });
151784
151903
  await cdp.connect();
151785
151904
  const sourceMaps = new SourceMapsRegistry();
151786
151905
  cdp.events.on("scriptParsed", (script) => {
@@ -162249,7 +162368,7 @@ var zodSchema33 = external_exports.object({
162249
162368
  var debuggerEvaluateTool = {
162250
162369
  id: "debugger-evaluate",
162251
162370
  description: `Execute arbitrary JavaScript in the app's JS runtime via CDP: Hermes on iOS / Android / Vega, V8 on Chromium.
162252
- Returns the result serialized by value as JSON, with deviceName, appName, and logicalDeviceId. Use when you need to read app state, including localStorage and sessionStorage on Chromium, call app functions, or test logic at runtime. Cyclic objects, which many RN runtime values are (fiber nodes, navigation refs, global), fail with a serialization error. Fails if the expression throws or the runtime is not connected. On React Native, a module that fails to load while the expression runs (e.g. a lazy react-native export whose native module the app lacks) fails the call with that module's error instead of opening the app's red box.`,
162371
+ Returns the result serialized by value as JSON, with deviceName, appName, and logicalDeviceId. A returned Promise is awaited and its resolved value returned. Use when you need to read app state, including localStorage and sessionStorage on Chromium, call app functions, or test logic at runtime. Cyclic objects, which many RN runtime values are (fiber nodes, navigation refs, global), fail with a serialization error. Fails if the expression throws or the runtime is not connected. On React Native, a module that fails to load while the expression runs (e.g. a lazy react-native export whose native module the app lacks) fails the call with that module's error instead of opening the app's red box.`,
162253
162372
  zodSchema: zodSchema33,
162254
162373
  searchHint: "javascript js eval expression runtime app state localstorage sessionstorage web storage",
162255
162374
  interaction: {
@@ -162266,7 +162385,7 @@ Returns the result serialized by value as JSON, with deviceName, appName, and lo
162266
162385
  let result;
162267
162386
  try {
162268
162387
  const expression = isChromiumDebuggerTarget(params.device_id) ? params.expression : guardModuleLoadErrors(params.expression);
162269
- result = await api.cdp.evaluate(expression);
162388
+ result = await api.cdp.evaluateAwaited(expression);
162270
162389
  } catch (err) {
162271
162390
  if (err instanceof Error && getFailureSignal(err)?.error_code === FAILURE_CODES.DEBUGGER_CDP_RUNTIME_EXCEPTION) {
162272
162391
  throw new FailureError(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swmansion/argent",
3
- "version": "0.34.1-next.35",
3
+ "version": "0.34.1-next.36",
4
4
  "mcpName": "io.github.software-mansion/argent",
5
5
  "description": "MCP server for iOS Simulator, Android Emulator, Chromium app and Mac app control",
6
6
  "license": "Apache-2.0",