peachsim 0.1.780 → 0.1.781

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 (74) hide show
  1. package/cli/commands/detox.ts +6 -2
  2. package/dist-lib/agent-daemon-client.cjs +1 -1
  3. package/dist-lib/agent-events.cjs +1 -1
  4. package/dist-lib/agent-identity.cjs +1 -1
  5. package/dist-lib/agent-sessions.cjs +1 -1
  6. package/dist-lib/attached-projects.cjs +1 -1
  7. package/dist-lib/auth/shared-session.cjs +1 -1
  8. package/dist-lib/backend-origin.cjs +1 -1
  9. package/dist-lib/beta.cjs +1 -1
  10. package/dist-lib/beta.mjs +1 -1
  11. package/dist-lib/bridge-constants.cjs +1 -1
  12. package/dist-lib/bridge-contract-input.cjs +1 -1
  13. package/dist-lib/bridge-contract-input.mjs +1 -1
  14. package/dist-lib/bridge-contract.cjs +1 -1
  15. package/dist-lib/bridge-contract.mjs +1 -1
  16. package/dist-lib/capture-contract.cjs +1 -1
  17. package/dist-lib/capture-contract.mjs +1 -1
  18. package/dist-lib/cli-constants.cjs +1 -1
  19. package/dist-lib/cloud-contract.cjs +1 -1
  20. package/dist-lib/cloud-contract.mjs +1 -1
  21. package/dist-lib/cloud-test-args.cjs +1 -1
  22. package/dist-lib/cloud-test-args.mjs +1 -1
  23. package/dist-lib/cloud.cjs +1 -1
  24. package/dist-lib/cloud.mjs +1 -1
  25. package/dist-lib/config.cjs +1 -1
  26. package/dist-lib/detox/index.cjs +1 -1
  27. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  28. package/dist-lib/home-paths.cjs +1 -1
  29. package/dist-lib/host/bridge-host.cjs +591 -257
  30. package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
  31. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  32. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  33. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  34. package/dist-lib/host/websocket-proxy.cjs +1 -1
  35. package/dist-lib/index.cjs +1 -1
  36. package/dist-lib/jump-to-source-babel.cjs +1 -1
  37. package/dist-lib/jump-to-source-native.cjs +1 -1
  38. package/dist-lib/kotlin-host.cjs +1 -1
  39. package/dist-lib/menu.cjs +1 -1
  40. package/dist-lib/menu.mjs +1 -1
  41. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  42. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  43. package/dist-lib/metro-production-bundle.cjs +1 -1
  44. package/dist-lib/metro-production-bundle.mjs +1 -1
  45. package/dist-lib/metro.cjs +1 -1
  46. package/dist-lib/native-app-identity.cjs +1 -1
  47. package/dist-lib/native-app-identity.mjs +1 -1
  48. package/dist-lib/native-firebase-metadata.cjs +1 -1
  49. package/dist-lib/native-firebase-metadata.mjs +1 -1
  50. package/dist-lib/plist.cjs +1 -1
  51. package/dist-lib/plist.mjs +1 -1
  52. package/dist-lib/profiles.cjs +1 -1
  53. package/dist-lib/public-brand.cjs +1 -1
  54. package/dist-lib/react-native-host-modules.cjs +1 -1
  55. package/dist-lib/react-native-host-modules.mjs +1 -1
  56. package/dist-lib/render-mode.cjs +1 -1
  57. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  58. package/dist-lib/sdk.cjs +1 -1
  59. package/dist-lib/sdk.mjs +1 -1
  60. package/dist-lib/skills.cjs +593 -259
  61. package/dist-lib/swift-compile.cjs +1 -1
  62. package/dist-lib/swift-compile.mjs +1 -1
  63. package/dist-lib/swift-package.cjs +1 -1
  64. package/dist-lib/swift-package.mjs +1 -1
  65. package/dist-lib/swift-submit.cjs +1 -1
  66. package/dist-lib/swift-submit.mjs +1 -1
  67. package/dist-lib/swift-toolchain.cjs +1 -1
  68. package/dist-lib/swift.cjs +1 -1
  69. package/dist-lib/vite-swift.cjs +583 -257
  70. package/dist-lib/vite.cjs +1 -1
  71. package/package.json +1 -1
  72. package/src/swift-host.ts +55 -28
  73. package/src/swift-standin-emit.ts +471 -242
  74. package/src/swift-standins.ts +285 -40
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.780 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.781 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
  let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
3
3
  "use strict";
4
4
  var __create = Object.create;
@@ -3565,6 +3565,7 @@ var import_node_os7 = __toESM(require("node:os"), 1);
3565
3565
  var import_node_path11 = __toESM(require("node:path"), 1);
3566
3566
 
3567
3567
  // src/swift-standin-emit.ts
3568
+ var STANDIN_EMIT_VERSION = "1";
3568
3569
  var TYPE_KINDS = /* @__PURE__ */ new Set([
3569
3570
  "swift.class",
3570
3571
  "swift.struct",
@@ -3598,7 +3599,7 @@ var KEEP_EXTERNAL = /* @__PURE__ */ new Map([
3598
3599
  ]);
3599
3600
  var LEADING_ATTRS = /^((?:@\w+(?:\([^)]*\))?\s*|nonisolated\s+)*)(.*)$/s;
3600
3601
  var OBJC_ONLY = /@(?:objcMembers|objc|IBOutlet|IBInspectable|IBAction|IBSegueAction|GKInspectable|nonobjc|NSCopying|NSManaged)(?:\([^)]*\))?\s*|\bdynamic\s+/g;
3601
- var text = (symbol) => (symbol.declarationFragments ?? []).map((fragment) => fragment.spelling).join("").replace(OBJC_ONLY, "").replace(/(^|\s)optional (?=func|var|init|subscript|static|class)/, "$1");
3602
+ var text = (symbol) => (symbol.declarationFragments ?? []).map((fragment) => fragment.spelling).join("").replace(OBJC_ONLY, "").replace(/(^|\s)optional (?=func|var|init|subscript|static|class)/, "$1").replace(/\bAutoreleasingUnsafeMutablePointer</g, "UnsafeMutablePointer<");
3602
3603
  var leaf = (symbol) => symbol.pathComponents[symbol.pathComponents.length - 1];
3603
3604
  var pathOf = (symbol) => symbol.pathComponents.join(".");
3604
3605
  var unavailable = (symbol) => (symbol.availability ?? []).some(
@@ -3639,7 +3640,11 @@ function emitSwiftStandin(graphs, options) {
3639
3640
  if (local) return { name: pathOf(local), local: true };
3640
3641
  if (!fallback) return null;
3641
3642
  const parts = fallback.split(".");
3642
- return { name: family.has(parts[0]) ? parts.join(".") : parts.slice(1).join(".") || parts[0], module: parts[0], local: false };
3643
+ return {
3644
+ name: family.has(parts[0]) ? parts.join(".") : parts.slice(1).join(".") || parts[0],
3645
+ module: parts[0],
3646
+ local: false
3647
+ };
3643
3648
  };
3644
3649
  for (const graph of graphs)
3645
3650
  for (const edge of graph.relationships) {
@@ -3650,7 +3655,10 @@ function emitSwiftStandin(graphs, options) {
3650
3655
  const parent = byId.get(edge.target);
3651
3656
  if (parent) {
3652
3657
  owner.set(edge.source, edge.target);
3653
- children.set(edge.target, [...children.get(edge.target) ?? [], ...all(edge.source)]);
3658
+ children.set(edge.target, [
3659
+ ...children.get(edge.target) ?? [],
3660
+ ...all(edge.source)
3661
+ ]);
3654
3662
  } else if (edge.targetFallback) {
3655
3663
  const name = nameOf(edge.target, edge.targetFallback).name;
3656
3664
  external.set(name, [...external.get(name) ?? [], ...all(edge.source)]);
@@ -3668,7 +3676,8 @@ function emitSwiftStandin(graphs, options) {
3668
3676
  const target = nameOf(edge.target, edge.targetFallback);
3669
3677
  const kept = KEEP_EXTERNAL.get(edge.target);
3670
3678
  const name = kept ?? (target && (target.local || family.has(target.module ?? "")) ? target.name : null);
3671
- if (name) conforms.set(edge.source, [...conforms.get(edge.source) ?? [], name]);
3679
+ if (name)
3680
+ conforms.set(edge.source, [...conforms.get(edge.source) ?? [], name]);
3672
3681
  if (byId.has(edge.target)) {
3673
3682
  const map = source.kind.identifier === "swift.protocol" ? protocolParents : conformIds;
3674
3683
  map.set(edge.source, [...map.get(edge.source) ?? [], edge.target]);
@@ -3681,7 +3690,10 @@ function emitSwiftStandin(graphs, options) {
3681
3690
  if (edge.kind === "optionalRequirementOf") optional.add(edge.source);
3682
3691
  if (byId.has(edge.target) && !owner.has(edge.source)) {
3683
3692
  owner.set(edge.source, edge.target);
3684
- children.set(edge.target, [...children.get(edge.target) ?? [], ...all(edge.source)]);
3693
+ children.set(edge.target, [
3694
+ ...children.get(edge.target) ?? [],
3695
+ ...all(edge.source)
3696
+ ]);
3685
3697
  }
3686
3698
  break;
3687
3699
  case "overrides":
@@ -3720,59 +3732,77 @@ function emitSwiftStandin(graphs, options) {
3720
3732
  });
3721
3733
  };
3722
3734
  const access = (symbol, openOwner) => symbol.accessLevel === "open" && openOwner ? "open" : "public";
3723
- const emitMember = scoped((member, indent, context) => {
3724
- const path15 = pathOf(member);
3725
- if (TYPE_KINDS.has(member.kind.identifier)) {
3726
- emitType(member, indent);
3727
- return;
3728
- }
3729
- if (member.kind.identifier === "swift.enum.case") return;
3730
- if (!MEMBER_KINDS.has(member.kind.identifier)) {
3731
- skipped.push({ path: path15, reason: `unhandled ${member.kind.identifier}` });
3732
- return;
3733
- }
3734
- const { 1: attrs, 2: rest } = LEADING_ATTRS.exec(text(member));
3735
- const modifiers = /^((?:(?:required|final|override|convenience|unowned(?:\(\w+\))?|weak|lazy|nonisolated|mutating|nonmutating) )*)(.*)$/s.exec(rest);
3736
- const flags = new Set(modifiers[1].trim().split(/\s+/).filter(Boolean).map((flag) => flag.replace(/\(.*/, "")));
3737
- const required = context.inClass && flags.has("required");
3738
- const final = context.inClass && flags.has("final") ? "final " : "";
3739
- const mutating = flags.has("mutating") ? "mutating " : flags.has("nonmutating") ? "nonmutating " : "";
3740
- let core = `${context.inClass && flags.has("convenience") ? "convenience " : ""}${modifiers[2]}`;
3741
- const override = context.inClass && !options.plain?.has(path15) && (flags.has("override") || overrides.has(member.identifier.precise) || isObjC(member) && path15.endsWith(".init()")) ? "override " : "";
3742
- const head = `${indent}${attrs}${access(member, context.openOwner)} ${required ? "required " : ""}${final}${override}${mutating}`;
3743
- const measured = behavior.get(path15);
3744
- if (measured) used.add(path15);
3745
- const overloadBody = /\basync\b/.test(core) ? measured?.asyncBody : /\bResult</.test(core) ? measured?.resultBody : void 0;
3746
- const body = overloadBody ?? measured?.body ?? trap(path15);
3747
- switch (member.kind.identifier) {
3748
- case "swift.property":
3749
- case "swift.type.property":
3750
- case "swift.subscript":
3751
- case "swift.type.subscript": {
3752
- const accessors = ACCESSORS.exec(core);
3753
- const decl = core.replace(ACCESSORS, "").trimEnd();
3754
- const effects = `${accessors?.[1] ?? ""}${accessors?.[2] ?? ""}`;
3755
- const settable = accessors ? Boolean(accessors[3]) : /^(?:static |class )?var /.test(core);
3756
- const computed = decl.replace(/^((?:static |class )*)let /, "$1var ");
3757
- if (measured?.stored !== void 0) {
3758
- const ownership = flags.has("weak") ? "weak " : flags.has("unowned") ? "unowned " : "";
3759
- const setter = settable ? "" : "internal(set) ";
3760
- const value = measured.stored ? ` = ${measured.stored}` : "";
3761
- emit(`${indent}${attrs}${access(member, context.openOwner)} ${setter}${final}${override}${ownership}${computed}${value}`);
3735
+ const emitMember = scoped(
3736
+ (member, indent, context) => {
3737
+ const path15 = pathOf(member);
3738
+ if (TYPE_KINDS.has(member.kind.identifier)) {
3739
+ emitType(member, indent);
3740
+ return;
3741
+ }
3742
+ if (member.kind.identifier === "swift.enum.case") return;
3743
+ if (!MEMBER_KINDS.has(member.kind.identifier)) {
3744
+ skipped.push({ path: path15, reason: `unhandled ${member.kind.identifier}` });
3745
+ return;
3746
+ }
3747
+ const { 1: attrs, 2: rest } = LEADING_ATTRS.exec(text(member));
3748
+ const modifiers = /^((?:(?:required|final|override|convenience|unowned(?:\(\w+\))?|weak|lazy|nonisolated|mutating|nonmutating) )*)(.*)$/s.exec(
3749
+ rest
3750
+ );
3751
+ const flags = new Set(
3752
+ modifiers[1].trim().split(/\s+/).filter(Boolean).map((flag) => flag.replace(/\(.*/, ""))
3753
+ );
3754
+ const required = context.inClass && flags.has("required");
3755
+ const final = context.inClass && flags.has("final") ? "final " : "";
3756
+ const mutating = flags.has("mutating") ? "mutating " : flags.has("nonmutating") ? "nonmutating " : "";
3757
+ let core = `${context.inClass && flags.has("convenience") ? "convenience " : ""}${modifiers[2]}`;
3758
+ const override = context.inClass && !options.plain?.has(path15) && (flags.has("override") || overrides.has(member.identifier.precise) || isObjC(member) && path15.endsWith(".init()")) ? "override " : "";
3759
+ const head = `${indent}${attrs}${access(member, context.openOwner)} ${required ? "required " : ""}${final}${override}${mutating}`;
3760
+ const measured = behavior.get(path15);
3761
+ if (measured) used.add(path15);
3762
+ const overloadBody = /\basync\b/.test(core) ? measured?.asyncBody : /\bResult</.test(core) ? measured?.resultBody : void 0;
3763
+ const body = overloadBody ?? measured?.body ?? trap(path15);
3764
+ switch (member.kind.identifier) {
3765
+ case "swift.property":
3766
+ case "swift.type.property":
3767
+ case "swift.subscript":
3768
+ case "swift.type.subscript": {
3769
+ const accessors = ACCESSORS.exec(core);
3770
+ const decl = core.replace(ACCESSORS, "").trimEnd();
3771
+ const effects = `${accessors?.[1] ?? ""}${accessors?.[2] ?? ""}`;
3772
+ const settable = accessors ? Boolean(accessors[3]) : /^(?:static |class )?var /.test(core);
3773
+ const computed = decl.replace(/^((?:static |class )*)let /, "$1var ");
3774
+ if (measured?.stored !== void 0) {
3775
+ const ownership = flags.has("weak") ? "weak " : flags.has("unowned") ? "unowned " : "";
3776
+ const setter = settable ? "" : "internal(set) ";
3777
+ const value = measured.stored ? ` = ${measured.stored}` : "";
3778
+ emit(
3779
+ `${indent}${attrs}${access(member, context.openOwner)} ${setter}${final}${override}${ownership}${computed}${value}`
3780
+ );
3781
+ return;
3782
+ }
3783
+ emit(
3784
+ `${head}${computed} { get${effects} { ${body} }${settable && !effects ? ` set { ${measured?.set ?? trap(path15)} }` : ""} }`
3785
+ );
3762
3786
  return;
3763
3787
  }
3764
- emit(`${head}${computed} { get${effects} { ${body} }${settable && !effects ? ` set { ${measured?.set ?? trap(path15)} }` : ""} }`);
3765
- return;
3788
+ default:
3789
+ emit(`${head}${core} { ${body} }`);
3766
3790
  }
3767
- default:
3768
- emit(`${head}${core} { ${body} }`);
3769
3791
  }
3770
- });
3792
+ );
3771
3793
  const header = (symbol, keyword, indent) => {
3772
3794
  const { 1: attrs, 2: rest } = LEADING_ATTRS.exec(text(symbol));
3773
- const shape = new RegExp(`^(?:final )?${keyword}\\s+\`?(\\w+)\`?(<[^>]*>)?\\s*(?::\\s*([^{]*?))?(\\s+where\\s+.*)?$`).exec(rest);
3795
+ const shape = new RegExp(
3796
+ `^(?:final )?${keyword}\\s+\`?(\\w+)\`?(<[^>]*>)?\\s*(?::\\s*([^{]*?))?(\\s+where\\s+.*)?$`
3797
+ ).exec(rest);
3774
3798
  if (!shape) return null;
3775
- return { attrs, name: shape[1], generics: shape[2] ?? "", where: shape[4] ?? "", indent };
3799
+ return {
3800
+ attrs,
3801
+ name: shape[1],
3802
+ generics: shape[2] ?? "",
3803
+ where: shape[4] ?? "",
3804
+ indent
3805
+ };
3776
3806
  };
3777
3807
  const externalRoot = (id) => {
3778
3808
  for (let at = id; at; at = superId.get(at)) {
@@ -3787,7 +3817,8 @@ function emitSwiftStandin(graphs, options) {
3787
3817
  if (!parentSymbol) return null;
3788
3818
  if (/^(?:final )?class\s+\w+</.test(LEADING_ATTRS.exec(text(parentSymbol))[2]) && !options.superclasses?.has(pathOf(byId.get(id))))
3789
3819
  return `superclass ${pathOf(parentSymbol)} is generic and the graph omits its arguments`;
3790
- if (unavailable(parentSymbol)) return `superclass ${pathOf(parentSymbol)} is unavailable`;
3820
+ if (unavailable(parentSymbol))
3821
+ return `superclass ${pathOf(parentSymbol)} is unavailable`;
3791
3822
  return classBlocked(parent) && `superclass ${pathOf(parentSymbol)} is left out`;
3792
3823
  };
3793
3824
  const objcProtocols = new Set(
@@ -3801,153 +3832,203 @@ function emitSwiftStandin(graphs, options) {
3801
3832
  const list2 = [...first ? [first] : [], ...conforms.get(id) ?? []];
3802
3833
  return [...new Set(list2)];
3803
3834
  };
3804
- const emitType = scoped((symbol, indent) => {
3805
- const path15 = pathOf(symbol);
3806
- const id = symbol.identifier.precise;
3807
- const inner = `${indent} `;
3808
- switch (symbol.kind.identifier) {
3809
- case "swift.typealias": {
3810
- const { 1: attrs, 2: rest } = LEADING_ATTRS.exec(text(symbol));
3811
- emit(`${indent}${attrs}public ${rest}`);
3812
- return;
3813
- }
3814
- case "swift.class": {
3815
- const shape = header(symbol, "class", indent);
3816
- if (!shape) return void skipped.push({ path: path15, reason: `unparsed class ${text(symbol)}` });
3817
- const parent = options.superclasses?.get(path15) ?? superclass.get(id);
3818
- const blocked = classBlocked(id);
3819
- if (blocked) return void skipped.push({ path: path15, reason: blocked });
3820
- const ancestors = /* @__PURE__ */ new Set();
3821
- for (let at = superId.get(id); at; at = superId.get(at))
3822
- for (const name of conforms.get(at) ?? []) ancestors.add(name);
3823
- const list2 = [
3824
- ...parent ? [parent] : [],
3825
- ...(conforms.get(id) ?? []).filter(
3826
- (name) => !ancestors.has(name) && !(parent && [...KEEP_EXTERNAL.values()].includes(name))
3827
- )
3828
- ].filter((name, at, all2) => all2.indexOf(name) === at);
3829
- const parentSymbol = superId.has(id) ? byId.get(superId.get(id)) : void 0;
3830
- const open = symbol.accessLevel === "open" && (!parentSymbol || parentSymbol.accessLevel === "open");
3831
- emit(`${indent}${shape.attrs}${open ? "open" : "public"} class ${shape.name}${shape.generics}${list2.length ? `: ${list2.join(", ")}` : ""}${selfConforming(shape.where)} {`);
3832
- const members = membersOf(id);
3833
- for (const member of members)
3834
- emitMember(member, inner, { openOwner: open, inClass: true, ownerName: shape.name });
3835
- const designated = members.some(
3836
- (member) => member.kind.identifier === "swift.init" && !text(member).startsWith("convenience")
3837
- );
3838
- const have = /* @__PURE__ */ new Set();
3839
- for (let at = id; at; at = superId.get(at))
3840
- for (const member of children.get(at) ?? []) have.add(witnessKey(member));
3841
- const protocols = [];
3842
- const visit = (protocolId) => {
3843
- if (protocols.includes(protocolId)) return;
3844
- protocols.push(protocolId);
3845
- for (const edge of protocolParents.get(protocolId) ?? []) visit(edge);
3846
- };
3847
- for (const protocolId of conformIds.get(id) ?? []) visit(protocolId);
3848
- for (const protocolId of protocols)
3849
- for (const member of children.get(protocolId) ?? []) {
3850
- if (!requirement.has(member.identifier.precise) || optional.has(member.identifier.precise)) continue;
3851
- if (isObjC(member) && / async\b/.test(text(member))) continue;
3852
- if (have.has(witnessKey(member)) || member.kind.identifier === "swift.associatedtype") continue;
3853
- have.add(witnessKey(member));
3854
- emitWitness(member, inner, path15);
3855
- }
3856
- const coder = members.some((member) => leaf(member) === "init(coder:)");
3857
- if (designated && !coder && externalRoot(id) !== "NSObject" && externalRoot(id) !== null)
3858
- emit(`${inner}public required init?(coder: NSCoder) { ${trap(`${path15}.init(coder:)`)} }`);
3859
- emit(`${indent}}`);
3860
- return;
3861
- }
3862
- case "swift.struct": {
3863
- const shape = header(symbol, "struct", indent);
3864
- if (!shape) return void skipped.push({ path: path15, reason: `unparsed struct ${text(symbol)}` });
3865
- const members = membersOf(id);
3866
- const raw2 = rawType(members);
3867
- const list2 = inheritance(id);
3868
- emit(`${indent}${shape.attrs}public struct ${shape.name}${shape.generics}${list2.length ? `: ${list2.join(", ")}` : ""}${shape.where} {`);
3869
- if (raw2) {
3870
- emit(`${inner}public let rawValue: ${raw2}`);
3871
- emit(`${inner}public init(rawValue: ${raw2}) { self.rawValue = rawValue }`);
3835
+ const emitType = scoped(
3836
+ (symbol, indent) => {
3837
+ const path15 = pathOf(symbol);
3838
+ const id = symbol.identifier.precise;
3839
+ const inner = `${indent} `;
3840
+ switch (symbol.kind.identifier) {
3841
+ case "swift.typealias": {
3842
+ const { 1: attrs, 2: rest } = LEADING_ATTRS.exec(text(symbol));
3843
+ emit(`${indent}${attrs}public ${rest}`);
3844
+ return;
3872
3845
  }
3873
- for (const member of members) {
3874
- if (raw2 && (leaf(member) === "rawValue" || leaf(member) === "init(rawValue:)" || leaf(member) === "init(_:)"))
3875
- continue;
3876
- const value = values.get(member.identifier.precise);
3877
- if (value !== void 0 && member.kind.identifier === "swift.type.property") {
3878
- emit(`${inner}public static let ${tick(leaf(member))} = ${shape.name}(rawValue: ${value})`);
3879
- continue;
3880
- }
3881
- emitMember(member, inner, { openOwner: false, inClass: false, ownerName: shape.name });
3846
+ case "swift.class": {
3847
+ const shape = header(symbol, "class", indent);
3848
+ if (!shape)
3849
+ return void skipped.push({ path: path15, reason: `unparsed class ${text(symbol)}` });
3850
+ const parent = options.superclasses?.get(path15) ?? superclass.get(id);
3851
+ const blocked = classBlocked(id);
3852
+ if (blocked) return void skipped.push({ path: path15, reason: blocked });
3853
+ const ancestors = /* @__PURE__ */ new Set();
3854
+ for (let at = superId.get(id); at; at = superId.get(at))
3855
+ for (const name of conforms.get(at) ?? []) ancestors.add(name);
3856
+ const list2 = [
3857
+ ...parent ? [parent] : [],
3858
+ ...(conforms.get(id) ?? []).filter(
3859
+ (name) => !ancestors.has(name) && !(parent && [...KEEP_EXTERNAL.values()].includes(name))
3860
+ )
3861
+ ].filter((name, at, all2) => all2.indexOf(name) === at);
3862
+ const parentSymbol = superId.has(id) ? byId.get(superId.get(id)) : void 0;
3863
+ const open = symbol.accessLevel === "open" && (!parentSymbol || parentSymbol.accessLevel === "open");
3864
+ emit(
3865
+ `${indent}${shape.attrs}${open ? "open" : "public"} class ${shape.name}${shape.generics}${list2.length ? `: ${list2.join(", ")}` : ""}${selfConforming(shape.where)} {`
3866
+ );
3867
+ const members = membersOf(id);
3868
+ for (const member of members)
3869
+ emitMember(member, inner, {
3870
+ openOwner: open,
3871
+ inClass: true,
3872
+ ownerName: shape.name
3873
+ });
3874
+ const designated = members.some(
3875
+ (member) => member.kind.identifier === "swift.init" && !text(member).startsWith("convenience")
3876
+ );
3877
+ const have = /* @__PURE__ */ new Set();
3878
+ for (let at = id; at; at = superId.get(at))
3879
+ for (const member of children.get(at) ?? []) have.add(witnessKey(member));
3880
+ const protocols = [];
3881
+ const visit = (protocolId) => {
3882
+ if (protocols.includes(protocolId)) return;
3883
+ protocols.push(protocolId);
3884
+ for (const edge of protocolParents.get(protocolId) ?? []) visit(edge);
3885
+ };
3886
+ for (const protocolId of conformIds.get(id) ?? []) visit(protocolId);
3887
+ for (const protocolId of protocols)
3888
+ for (const member of children.get(protocolId) ?? []) {
3889
+ if (!requirement.has(member.identifier.precise) || optional.has(member.identifier.precise))
3890
+ continue;
3891
+ if (isObjC(member) && / async\b/.test(text(member))) continue;
3892
+ if (have.has(witnessKey(member)) || member.kind.identifier === "swift.associatedtype")
3893
+ continue;
3894
+ have.add(witnessKey(member));
3895
+ emitWitness(member, inner, path15);
3896
+ }
3897
+ const coder = members.some((member) => leaf(member) === "init(coder:)");
3898
+ if (designated && !coder && externalRoot(id) !== "NSObject" && externalRoot(id) !== null)
3899
+ emit(
3900
+ `${inner}public required init?(coder: NSCoder) { ${trap(`${path15}.init(coder:)`)} }`
3901
+ );
3902
+ emit(`${indent}}`);
3903
+ return;
3882
3904
  }
3883
- emit(`${indent}}`);
3884
- return;
3885
- }
3886
- case "swift.enum": {
3887
- const shape = header(symbol, "enum", indent);
3888
- if (!shape) return void skipped.push({ path: path15, reason: `unparsed enum ${text(symbol)}` });
3889
- const members = membersOf(id);
3890
- const raw2 = rawType(members);
3891
- const cases = (children.get(id) ?? []).filter((member) => member.kind.identifier === "swift.enum.case");
3892
- const missing = raw2 ? cases.filter((member) => !values.has(member.identifier.precise)) : [];
3893
- if (raw2 && isObjC(symbol) && missing.length > 0)
3894
- return void skipped.push({ path: path15, reason: `no header value for ${missing.map(leaf).join(", ")}` });
3895
- const list2 = inheritance(id, raw2 ?? void 0).filter((name) => name !== "RawRepresentable");
3896
- emit(`${indent}${shape.attrs}public enum ${shape.name}${shape.generics}${list2.length ? `: ${list2.join(", ")}` : ""}${shape.where} {`);
3897
- const seenValues = /* @__PURE__ */ new Map();
3898
- for (const member of cases) {
3899
- const value = values.get(member.identifier.precise);
3900
- if (value !== void 0 && seenValues.has(value)) {
3901
- emit(`${inner}public static var ${tick(leaf(member))}: ${shape.name} { .${seenValues.get(value)} }`);
3902
- continue;
3905
+ case "swift.struct": {
3906
+ const shape = header(symbol, "struct", indent);
3907
+ if (!shape)
3908
+ return void skipped.push({ path: path15, reason: `unparsed struct ${text(symbol)}` });
3909
+ const members = membersOf(id);
3910
+ const raw2 = rawType(members);
3911
+ const list2 = inheritance(id);
3912
+ emit(
3913
+ `${indent}${shape.attrs}public struct ${shape.name}${shape.generics}${list2.length ? `: ${list2.join(", ")}` : ""}${shape.where} {`
3914
+ );
3915
+ if (raw2) {
3916
+ emit(`${inner}public let rawValue: ${raw2}`);
3917
+ emit(`${inner}public init(rawValue: ${raw2}) { self.rawValue = rawValue }`);
3903
3918
  }
3904
- if (value !== void 0) seenValues.set(value, tick(leaf(member)));
3905
- const caseText = text(member).replace(/^case\s+/, "");
3906
- emit(`${inner}case ${caseText}${value !== void 0 ? ` = ${value}` : ""}`);
3907
- }
3908
- for (const member of members) {
3909
- if (member.kind.identifier === "swift.enum.case") continue;
3910
- if (raw2 && (leaf(member) === "rawValue" || leaf(member) === "init(rawValue:)")) continue;
3911
- emitMember(member, inner, { openOwner: false, inClass: false, ownerName: shape.name });
3919
+ for (const member of members) {
3920
+ if (raw2 && (leaf(member) === "rawValue" || leaf(member) === "init(rawValue:)" || leaf(member) === "init(_:)"))
3921
+ continue;
3922
+ const value = values.get(member.identifier.precise);
3923
+ if (value !== void 0 && member.kind.identifier === "swift.type.property") {
3924
+ emit(
3925
+ `${inner}public static let ${tick(leaf(member))} = ${shape.name}(rawValue: ${value})`
3926
+ );
3927
+ continue;
3928
+ }
3929
+ emitMember(member, inner, {
3930
+ openOwner: false,
3931
+ inClass: false,
3932
+ ownerName: shape.name
3933
+ });
3934
+ }
3935
+ emit(`${indent}}`);
3936
+ return;
3912
3937
  }
3913
- emit(`${indent}}`);
3914
- return;
3915
- }
3916
- case "swift.protocol": {
3917
- const shape = header(symbol, "protocol", indent);
3918
- if (!shape) return void skipped.push({ path: path15, reason: `unparsed protocol ${text(symbol)}` });
3919
- const list2 = [...isObjC(symbol) ? ["AnyObject"] : [], ...inheritance(id)];
3920
- emit(`${indent}${shape.attrs}public protocol ${shape.name}${list2.length ? `: ${list2.join(", ")}` : ""}${shape.where} {`);
3921
- const members = membersOf(id);
3922
- const defaults = [];
3923
- for (const member of members) {
3924
- if (member.kind.identifier === "swift.associatedtype") {
3925
- emit(`${inner}${text(member)}`);
3926
- continue;
3938
+ case "swift.enum": {
3939
+ const shape = header(symbol, "enum", indent);
3940
+ if (!shape)
3941
+ return void skipped.push({ path: path15, reason: `unparsed enum ${text(symbol)}` });
3942
+ const members = membersOf(id);
3943
+ const raw2 = rawType(members);
3944
+ const cases = (children.get(id) ?? []).filter(
3945
+ (member) => member.kind.identifier === "swift.enum.case"
3946
+ );
3947
+ const missing = raw2 ? cases.filter((member) => !values.has(member.identifier.precise)) : [];
3948
+ if (raw2 && isObjC(symbol) && missing.length > 0)
3949
+ return void skipped.push({
3950
+ path: path15,
3951
+ reason: `no header value for ${missing.map(leaf).join(", ")}`
3952
+ });
3953
+ const list2 = inheritance(id, raw2 ?? void 0).filter(
3954
+ (name) => name !== "RawRepresentable"
3955
+ );
3956
+ emit(
3957
+ `${indent}${shape.attrs}public enum ${shape.name}${shape.generics}${list2.length ? `: ${list2.join(", ")}` : ""}${shape.where} {`
3958
+ );
3959
+ const seenValues = /* @__PURE__ */ new Map();
3960
+ for (const member of cases) {
3961
+ const value = values.get(member.identifier.precise);
3962
+ if (value !== void 0 && seenValues.has(value)) {
3963
+ emit(
3964
+ `${inner}public static var ${tick(leaf(member))}: ${shape.name} { .${seenValues.get(value)} }`
3965
+ );
3966
+ continue;
3967
+ }
3968
+ if (value !== void 0) seenValues.set(value, tick(leaf(member)));
3969
+ const caseText = text(member).replace(/^case\s+/, "");
3970
+ emit(`${inner}case ${caseText}${value !== void 0 ? ` = ${value}` : ""}`);
3927
3971
  }
3928
- const asyncTwin = isObjC(member) && / async\b/.test(text(member));
3929
- if (!requirement.has(member.identifier.precise) || asyncTwin) {
3930
- defaults.push(member);
3931
- continue;
3972
+ for (const member of members) {
3973
+ if (member.kind.identifier === "swift.enum.case") continue;
3974
+ if (raw2 && (leaf(member) === "rawValue" || leaf(member) === "init(rawValue:)"))
3975
+ continue;
3976
+ emitMember(member, inner, {
3977
+ openOwner: false,
3978
+ inClass: false,
3979
+ ownerName: shape.name
3980
+ });
3932
3981
  }
3933
- emitRequirement(member, inner);
3934
- if (optional.has(member.identifier.precise)) defaults.push(member);
3982
+ emit(`${indent}}`);
3983
+ return;
3935
3984
  }
3936
- emit(`${indent}}`);
3937
- if (defaults.length > 0) {
3938
- emit(`${indent}extension ${path15} {`);
3939
- for (const member of defaults) {
3940
- const decl = text(member);
3941
- if (optional.has(member.identifier.precise) && member.kind.identifier === "swift.method" && !decl.replace(/\([^)]*\)/g, "").includes("->") && !/ async\b/.test(decl))
3942
- emitNoop(member, inner);
3943
- else emitMember(member, inner, { openOwner: false, inClass: false, ownerName: shape.name });
3985
+ case "swift.protocol": {
3986
+ const shape = header(symbol, "protocol", indent);
3987
+ if (!shape)
3988
+ return void skipped.push({
3989
+ path: path15,
3990
+ reason: `unparsed protocol ${text(symbol)}`
3991
+ });
3992
+ const list2 = [...isObjC(symbol) ? ["AnyObject"] : [], ...inheritance(id)];
3993
+ emit(
3994
+ `${indent}${shape.attrs}public protocol ${shape.name}${list2.length ? `: ${list2.join(", ")}` : ""}${shape.where} {`
3995
+ );
3996
+ const members = membersOf(id);
3997
+ const defaults = [];
3998
+ for (const member of members) {
3999
+ if (member.kind.identifier === "swift.associatedtype") {
4000
+ emit(`${inner}${text(member)}`);
4001
+ continue;
4002
+ }
4003
+ const asyncTwin = isObjC(member) && / async\b/.test(text(member));
4004
+ if (!requirement.has(member.identifier.precise) || asyncTwin) {
4005
+ defaults.push(member);
4006
+ continue;
4007
+ }
4008
+ emitRequirement(member, inner);
4009
+ if (optional.has(member.identifier.precise)) defaults.push(member);
3944
4010
  }
3945
4011
  emit(`${indent}}`);
4012
+ if (defaults.length > 0) {
4013
+ emit(`${indent}extension ${path15} {`);
4014
+ for (const member of defaults) {
4015
+ const decl = text(member);
4016
+ if (optional.has(member.identifier.precise) && member.kind.identifier === "swift.method" && !decl.replace(/\([^)]*\)/g, "").includes("->") && !/ async\b/.test(decl))
4017
+ emitNoop(member, inner);
4018
+ else
4019
+ emitMember(member, inner, {
4020
+ openOwner: false,
4021
+ inClass: false,
4022
+ ownerName: shape.name
4023
+ });
4024
+ }
4025
+ emit(`${indent}}`);
4026
+ }
4027
+ return;
3946
4028
  }
3947
- return;
3948
4029
  }
3949
4030
  }
3950
- });
4031
+ );
3951
4032
  const emitWitness = (member, indent, owner2) => {
3952
4033
  const { 2: rest } = LEADING_ATTRS.exec(text(member));
3953
4034
  const decl = rest.replace(/^(?:weak |unowned )/, "").replace(/^((?:static )?)let /, "$1var ");
@@ -3956,15 +4037,22 @@ function emitSwiftStandin(graphs, options) {
3956
4037
  if (member.kind.identifier === "swift.property" || member.kind.identifier === "swift.type.property") {
3957
4038
  const accessors = ACCESSORS.exec(decl);
3958
4039
  const bare = decl.replace(ACCESSORS, "").trimEnd();
3959
- emit(`${indent}public ${bare} { get { ${body} }${accessors?.[3] ? ` set { ${body} }` : ""} }`);
3960
- } else emit(`${indent}public ${member.kind.identifier === "swift.init" ? "required " : ""}${stripDefaults(decl)} { ${body} }`);
4040
+ emit(
4041
+ `${indent}public ${bare} { get { ${body} }${accessors?.[3] ? ` set { ${body} }` : ""} }`
4042
+ );
4043
+ } else
4044
+ emit(
4045
+ `${indent}public ${member.kind.identifier === "swift.init" ? "required " : ""}${stripDefaults(decl)} { ${body} }`
4046
+ );
3961
4047
  };
3962
4048
  const emitNoop = scoped((member, indent) => {
3963
4049
  emit(`${indent}public ${stripDefaults(text(member))} {}`);
3964
4050
  });
3965
4051
  const emitRequirement = scoped((member, indent) => {
3966
4052
  const { 1: attrs, 2: rest } = LEADING_ATTRS.exec(text(member));
3967
- emit(`${indent}${attrs}${stripDefaults(rest.replace(/^(?:weak |unowned )/, "").replace(/^((?:static )?)let /, "$1var "))}`);
4053
+ emit(
4054
+ `${indent}${attrs}${stripDefaults(rest.replace(/^(?:weak |unowned )/, "").replace(/^((?:static )?)let /, "$1var "))}`
4055
+ );
3968
4056
  });
3969
4057
  const rawType = (members) => {
3970
4058
  const init = members.find((member) => leaf(member) === "init(rawValue:)");
@@ -3977,7 +4065,9 @@ function emitSwiftStandin(graphs, options) {
3977
4065
  emit(`${attrs}public ${rest} { ${trap(path15)} }`);
3978
4066
  } else if (symbol.kind.identifier === "swift.var") {
3979
4067
  const decl = text(symbol).replace(/^let /, "var ").replace(ACCESSORS, "").trimEnd();
3980
- emit(`public ${decl} { ${trap(path15)} }`);
4068
+ const measured = behavior.get(path15);
4069
+ if (measured) used.add(path15);
4070
+ emit(`public ${decl} { ${measured?.body ?? trap(path15)} }`);
3981
4071
  } else skipped.push({ path: path15, reason: `unhandled top-level ${symbol.kind.identifier}` });
3982
4072
  });
3983
4073
  const roots = [...byId.values()].filter((symbol) => !owner.has(symbol.identifier.precise) && !unavailable(symbol)).sort((a, b) => pathOf(a).localeCompare(pathOf(b)));
@@ -3998,11 +4088,20 @@ function emitSwiftStandin(graphs, options) {
3998
4088
  emit(`extension ${name} {`);
3999
4089
  for (const member of kept)
4000
4090
  if (member.kind.identifier === "swift.init" && !text(member).startsWith("convenience"))
4001
- emitMember({ ...member, declarationFragments: [{ kind: "text", spelling: `convenience ${text(member)}` }] }, " ", {
4002
- openOwner: false,
4003
- inClass: true,
4004
- ownerName: name
4005
- });
4091
+ emitMember(
4092
+ {
4093
+ ...member,
4094
+ declarationFragments: [
4095
+ { kind: "text", spelling: `convenience ${text(member)}` }
4096
+ ]
4097
+ },
4098
+ " ",
4099
+ {
4100
+ openOwner: false,
4101
+ inClass: true,
4102
+ ownerName: name
4103
+ }
4104
+ );
4006
4105
  else emitMember(member, " ", { openOwner: false, inClass: false, ownerName: name });
4007
4106
  emit(`}`);
4008
4107
  }
@@ -4016,7 +4115,8 @@ function emitSwiftStandin(graphs, options) {
4016
4115
  ""
4017
4116
  ];
4018
4117
  for (const path15 of behavior.keys())
4019
- if (!used.has(path15)) skipped.push({ path: path15, reason: "behavior names no emitted declaration" });
4118
+ if (!used.has(path15))
4119
+ skipped.push({ path: path15, reason: "behavior names no emitted declaration" });
4020
4120
  return {
4021
4121
  source: `${[...banner, ...lines].join("\n")}
4022
4122
  `,
@@ -4024,7 +4124,41 @@ function emitSwiftStandin(graphs, options) {
4024
4124
  owners: [...banner.map(() => ""), ...owners]
4025
4125
  };
4026
4126
  }
4027
- var KEYWORDS = /* @__PURE__ */ new Set(["Type", "Protocol", "Self", "default", "init", "self", "class", "func", "var", "let", "in", "is", "as", "repeat", "internal", "public", "private", "operator", "extension", "subscript", "static", "struct", "protocol", "enum", "case", "where", "return", "throw", "throws", "import", "true", "false", "nil"]);
4127
+ var KEYWORDS = /* @__PURE__ */ new Set([
4128
+ "Type",
4129
+ "Protocol",
4130
+ "Self",
4131
+ "default",
4132
+ "init",
4133
+ "self",
4134
+ "class",
4135
+ "func",
4136
+ "var",
4137
+ "let",
4138
+ "in",
4139
+ "is",
4140
+ "as",
4141
+ "repeat",
4142
+ "internal",
4143
+ "public",
4144
+ "private",
4145
+ "operator",
4146
+ "extension",
4147
+ "subscript",
4148
+ "static",
4149
+ "struct",
4150
+ "protocol",
4151
+ "enum",
4152
+ "case",
4153
+ "where",
4154
+ "return",
4155
+ "throw",
4156
+ "throws",
4157
+ "import",
4158
+ "true",
4159
+ "false",
4160
+ "nil"
4161
+ ]);
4028
4162
  var tick = (name) => KEYWORDS.has(name) ? `\`${name}\`` : name;
4029
4163
  function stripDefaults(decl) {
4030
4164
  let out = "";
@@ -4073,19 +4207,34 @@ ${"stdout" in error ? String(error.stdout) : ""}` : String(error);
4073
4207
  return [...new Set(errors)].slice(0, 3).join("; ") || output.trim().slice(0, 400);
4074
4208
  }
4075
4209
  var key = (...parts) => (0, import_node_crypto6.createHash)("sha256").update(parts.join("\0")).digest("hex").slice(0, 32);
4076
- function xcframework(binary) {
4077
- if (!binary.url && !binary.dir.endsWith(".zip")) return binary.dir;
4078
- const dir = import_node_path11.default.join(cacheDir3, "archives", key(binary.url ?? binary.dir));
4079
- if (!import_node_fs10.default.existsSync(import_node_path11.default.join(dir, ".complete"))) {
4080
- import_node_fs10.default.rmSync(dir, { recursive: true, force: true });
4081
- import_node_fs10.default.mkdirSync(dir, { recursive: true });
4082
- const archive = import_node_path11.default.join(dir, "archive.zip");
4083
- if (binary.url) exec("curl", ["-fsSL", "--retry", "2", "-o", archive, binary.url]);
4084
- else import_node_fs10.default.copyFileSync(binary.dir, archive);
4085
- exec("unzip", ["-q", archive, "-d", import_node_path11.default.join(dir, "tree")]);
4086
- import_node_fs10.default.rmSync(archive);
4087
- import_node_fs10.default.writeFileSync(import_node_path11.default.join(dir, ".complete"), "");
4088
- }
4210
+ var digests = /* @__PURE__ */ new Map();
4211
+ function treeDigest(root) {
4212
+ const names = [];
4213
+ const walk2 = (dir) => {
4214
+ for (const entry of import_node_fs10.default.readdirSync(dir, { withFileTypes: true }).sort((left, right) => left.name < right.name ? -1 : 1)) {
4215
+ const full = import_node_path11.default.join(dir, entry.name);
4216
+ if (entry.isDirectory()) walk2(full);
4217
+ else if (entry.isFile()) names.push(import_node_path11.default.relative(root, full));
4218
+ }
4219
+ };
4220
+ walk2(root);
4221
+ const stamp = names.map((name) => {
4222
+ const stat = import_node_fs10.default.statSync(import_node_path11.default.join(root, name));
4223
+ return `${name}\0${stat.size}:${stat.mtimeMs}`;
4224
+ }).join("\n");
4225
+ const memo2 = digests.get(`tree\0${root}`);
4226
+ if (memo2?.stamp === stamp) return memo2.digest;
4227
+ const hash = (0, import_node_crypto6.createHash)("sha256");
4228
+ for (const name of names) {
4229
+ hash.update(`${name}\0`);
4230
+ hash.update(import_node_fs10.default.readFileSync(import_node_path11.default.join(root, name)));
4231
+ hash.update("\0");
4232
+ }
4233
+ const digest = hash.digest("hex");
4234
+ digests.set(`tree\0${root}`, { stamp, digest });
4235
+ return digest;
4236
+ }
4237
+ function locateXcframework(tree) {
4089
4238
  const find = (root, depth) => {
4090
4239
  for (const entry of import_node_fs10.default.readdirSync(root, { withFileTypes: true })) {
4091
4240
  if (!entry.isDirectory() || entry.name === "__MACOSX") continue;
@@ -4096,9 +4245,53 @@ function xcframework(binary) {
4096
4245
  }
4097
4246
  return null;
4098
4247
  };
4099
- const found = find(import_node_path11.default.join(dir, "tree"), 2);
4248
+ return find(tree, 2);
4249
+ }
4250
+ function xcframework(binary) {
4251
+ if (!binary.url && !binary.dir.endsWith(".zip"))
4252
+ return { dir: binary.dir, digest: treeDigest(binary.dir) };
4253
+ const dir = import_node_path11.default.join(cacheDir3, "archives", key(binary.url ?? binary.dir));
4254
+ const archive = import_node_path11.default.join(dir, "archive.zip");
4255
+ const fingerprint = import_node_path11.default.join(dir, ".fingerprint");
4256
+ const stored = (() => {
4257
+ try {
4258
+ const parsed = JSON.parse(import_node_fs10.default.readFileSync(fingerprint, "utf8"));
4259
+ return parsed && typeof parsed === "object" && "sha" in parsed ? parsed : null;
4260
+ } catch {
4261
+ return null;
4262
+ }
4263
+ })();
4264
+ if (!binary.url) {
4265
+ const stat = import_node_fs10.default.statSync(binary.dir);
4266
+ const stamp = `${stat.size}:${stat.mtimeMs}`;
4267
+ if (stored?.stamp === stamp) {
4268
+ const found3 = locateXcframework(import_node_path11.default.join(dir, "tree"));
4269
+ if (found3) return { dir: found3, digest: stored.sha };
4270
+ }
4271
+ const sha2 = (0, import_node_crypto6.createHash)("sha256").update(import_node_fs10.default.readFileSync(binary.dir)).digest("hex");
4272
+ if (sha2 !== stored?.sha || !locateXcframework(import_node_path11.default.join(dir, "tree"))) {
4273
+ import_node_fs10.default.rmSync(dir, { recursive: true, force: true });
4274
+ import_node_fs10.default.mkdirSync(import_node_path11.default.join(dir, "tree"), { recursive: true });
4275
+ exec("unzip", ["-q", binary.dir, "-d", import_node_path11.default.join(dir, "tree")]);
4276
+ }
4277
+ import_node_fs10.default.writeFileSync(fingerprint, JSON.stringify({ stamp, sha: sha2 }));
4278
+ const found2 = locateXcframework(import_node_path11.default.join(dir, "tree"));
4279
+ if (!found2) throw new Error("its archive holds no .xcframework");
4280
+ return { dir: found2, digest: sha2 };
4281
+ }
4282
+ if (stored && import_node_fs10.default.existsSync(archive)) {
4283
+ const found2 = locateXcframework(import_node_path11.default.join(dir, "tree"));
4284
+ if (found2) return { dir: found2, digest: stored.sha };
4285
+ }
4286
+ import_node_fs10.default.rmSync(dir, { recursive: true, force: true });
4287
+ import_node_fs10.default.mkdirSync(import_node_path11.default.join(dir, "tree"), { recursive: true });
4288
+ exec("curl", ["-fsSL", "--retry", "2", "-o", archive, binary.url]);
4289
+ const sha = (0, import_node_crypto6.createHash)("sha256").update(import_node_fs10.default.readFileSync(archive)).digest("hex");
4290
+ exec("unzip", ["-q", archive, "-d", import_node_path11.default.join(dir, "tree")]);
4291
+ import_node_fs10.default.writeFileSync(fingerprint, JSON.stringify({ sha }));
4292
+ const found = locateXcframework(import_node_path11.default.join(dir, "tree"));
4100
4293
  if (!found) throw new Error("its archive holds no .xcframework");
4101
- return found;
4294
+ return { dir: found, digest: sha };
4102
4295
  }
4103
4296
  var files = (dir, test) => import_node_fs10.default.existsSync(dir) ? import_node_fs10.default.readdirSync(dir, { recursive: true, encoding: "utf8" }).filter((file) => test(import_node_path11.default.basename(file))).sort() : [];
4104
4297
  function surfaces(xcframeworkDir) {
@@ -4317,6 +4510,62 @@ function functionDeclarations(ast, headers) {
4317
4510
  }
4318
4511
  return found;
4319
4512
  }
4513
+ function matchOpen(text3, close) {
4514
+ const open = text3[close] === ")" ? "(" : "[";
4515
+ let depth = 0;
4516
+ for (let index = close; index >= 0; index--) {
4517
+ if (text3[index] === text3[close]) depth++;
4518
+ else if (text3[index] === open && --depth === 0) return index;
4519
+ }
4520
+ return -1;
4521
+ }
4522
+ var identChar = (char) => char !== void 0 && /[\w$]/.test(char);
4523
+ function splitDeclarators(statement, names) {
4524
+ const chunks = [];
4525
+ let depth = 0;
4526
+ let quote = null;
4527
+ let start = 0;
4528
+ for (let index = 0; index < statement.length; index++) {
4529
+ const char = statement[index];
4530
+ if (quote) {
4531
+ if (char === "\\") index++;
4532
+ else if (char === quote) quote = null;
4533
+ } else if (char === '"' || char === "'") quote = char;
4534
+ else if (char === "(" || char === "[" || char === "{") depth++;
4535
+ else if (char === ")" || char === "]" || char === "}") depth--;
4536
+ else if (char === "," && depth === 0) {
4537
+ chunks.push(statement.slice(start, index));
4538
+ start = index + 1;
4539
+ }
4540
+ }
4541
+ chunks.push(statement.slice(start));
4542
+ if (chunks.length !== names.length)
4543
+ throw new Error(
4544
+ `${names[0]} has an unexpected grouped declaration in ${JSON.stringify(statement.trim().slice(0, 80))}`
4545
+ );
4546
+ let end = chunks[0].indexOf(names[0]);
4547
+ if (end < 0) throw new Error(`${names[0]} names no declarator in its own declaration`);
4548
+ for (; ; ) {
4549
+ while (end > 0 && /[\s*]/.test(chunks[0][end - 1])) end--;
4550
+ if (end > 0 && (chunks[0][end - 1] === ")" || chunks[0][end - 1] === "]")) {
4551
+ end = matchOpen(chunks[0], end - 1);
4552
+ if (end < 0) throw new Error(`${names[0]} has unbalanced groups in its declaration`);
4553
+ while (end > 0 && identChar(chunks[0][end - 1])) end--;
4554
+ continue;
4555
+ }
4556
+ if (end > 1 && chunks[0][end - 1] === "(" && identChar(chunks[0][end - 2])) {
4557
+ end--;
4558
+ while (end > 0 && identChar(chunks[0][end - 1])) end--;
4559
+ continue;
4560
+ }
4561
+ break;
4562
+ }
4563
+ if (end > 0 && chunks[0][end - 1] === "(") end--;
4564
+ const specifiers = chunks[0].slice(0, end);
4565
+ return chunks.map(
4566
+ (chunk, index) => index === 0 ? chunk : `${specifiers} ${chunk.trim()}`
4567
+ );
4568
+ }
4320
4569
  function cStandin(surface, binary, toolchain, work) {
4321
4570
  const named = [
4322
4571
  ...import_node_fs10.default.readFileSync(surface.modulemap, "utf8").matchAll(/(?:umbrella\s+)?header\s+"([^"]+)"/g)
@@ -4361,26 +4610,40 @@ ${roots.map((file) => ` header "${file}"
4361
4610
  );
4362
4611
  const byPath = new Map(headers.map((file) => [import_node_path11.default.join(include, file), file]));
4363
4612
  const declarations = functionDeclarations(ast, new Set(byPath.keys()));
4613
+ const groups = /* @__PURE__ */ new Map();
4614
+ for (const declaration of declarations) {
4615
+ const group = groups.get(`${declaration.file}\0${declaration.begin}`) ?? [];
4616
+ group.push(declaration);
4617
+ groups.set(`${declaration.file}\0${declaration.begin}`, group);
4618
+ }
4364
4619
  const seen = /* @__PURE__ */ new Set();
4365
4620
  const definitions = [];
4366
- for (const { name, file, begin, end } of declarations) {
4367
- if (seen.has(name)) continue;
4368
- seen.add(name);
4369
- const text3 = texts.get(byPath.get(file));
4370
- const close = text3.indexOf(";", end);
4621
+ for (const group of groups.values()) {
4622
+ const first = group[0];
4623
+ const text3 = texts.get(byPath.get(first.file));
4624
+ const close = text3.indexOf(";", first.end);
4371
4625
  if (close < 0)
4372
- throw new Error(`${name} has no declaration end in ${byPath.get(file)}`);
4373
- definitions.push(
4374
- `${text3.slice(begin, close).trim()} {
4375
- peach_standin_trap("${name}");
4626
+ throw new Error(`${first.name} has no declaration end in ${byPath.get(first.file)}`);
4627
+ const statement = text3.slice(first.begin, close);
4628
+ const declarators = group.length === 1 ? [statement] : splitDeclarators(
4629
+ statement,
4630
+ group.map((declaration) => declaration.name)
4631
+ );
4632
+ group.forEach((declaration, index) => {
4633
+ if (seen.has(declaration.name)) return;
4634
+ seen.add(declaration.name);
4635
+ definitions.push(
4636
+ `${declarators[index].trim()} {
4637
+ peach_standin_trap("${declaration.name}");
4376
4638
  }
4377
4639
  `
4378
- );
4640
+ );
4641
+ });
4379
4642
  }
4380
4643
  const sdk = JSON.stringify(`${binary.target} (${binary.source})`);
4381
4644
  const source = [
4382
4645
  `// generated by peach from ${surface.module}'s headers: ${binary.target} ships`,
4383
- "// iOS machine code only, so every function traps naming itself.",
4646
+ "// iOS machine code only, so every extern function traps naming itself.",
4384
4647
  ...roots.map((file) => `#include "${file}"`),
4385
4648
  "#include <stdio.h>",
4386
4649
  "#include <stdlib.h>",
@@ -4392,6 +4655,22 @@ ${roots.map((file) => ` header "${file}"
4392
4655
  "",
4393
4656
  ...definitions
4394
4657
  ].join("\n");
4658
+ const out = import_node_path11.default.join(work, `${surface.module}.c`);
4659
+ import_node_fs10.default.writeFileSync(out, source);
4660
+ try {
4661
+ exec(import_node_path11.default.join(toolchain.toolchainBin, "clang"), [
4662
+ "-target",
4663
+ TRIPLE,
4664
+ "--sysroot",
4665
+ sysroot,
4666
+ "-fsyntax-only",
4667
+ "-I",
4668
+ include,
4669
+ out
4670
+ ]);
4671
+ } catch (error) {
4672
+ throw new Error(`its generated source does not compile: ${failure(error)}`);
4673
+ }
4395
4674
  return {
4396
4675
  module: surface.module,
4397
4676
  target: binary.target,
@@ -4405,18 +4684,48 @@ ${roots.map((file) => ` header "${file}"
4405
4684
  };
4406
4685
  }
4407
4686
  var built = /* @__PURE__ */ new Map();
4408
- function binaryStandins(binary, toolchain) {
4409
- let found;
4687
+ function standinGenerationInputs(binaries, toolchain) {
4688
+ const { moduleRoot, toolchainBin, release } = toolchain;
4689
+ const parts = [
4690
+ "standin/v2",
4691
+ toolchainBin,
4692
+ release,
4693
+ swiftModuleSdk(moduleRoot).wasmSdkId,
4694
+ swiftModuleDigest(moduleRoot).toString("hex"),
4695
+ `emit/${STANDIN_EMIT_VERSION}`
4696
+ ];
4697
+ for (const binary of binaries) {
4698
+ try {
4699
+ parts.push(
4700
+ binary.target,
4701
+ binary.source,
4702
+ binary.url ?? "",
4703
+ xcframework(binary).digest
4704
+ );
4705
+ } catch {
4706
+ parts.push(binary.target, binary.source, binary.url ?? "", "unreadable");
4707
+ }
4708
+ }
4709
+ return (0, import_node_crypto6.createHash)("sha256").update(parts.join("\0")).digest("hex");
4710
+ }
4711
+ function binaryStandins(binary, toolchain, provided) {
4712
+ if (provided.has(binary.target)) return [];
4713
+ let all;
4714
+ let digest;
4410
4715
  try {
4411
- found = surfaces(xcframework(binary));
4716
+ const artifact = xcframework(binary);
4717
+ all = surfaces(artifact.dir);
4718
+ digest = artifact.digest;
4412
4719
  } catch (error) {
4413
4720
  return error instanceof Error ? error.message : String(error);
4414
4721
  }
4415
- if (found.length === 0)
4722
+ const found = all.filter((surface) => !provided.has(surface.module));
4723
+ if (found.length === 0) {
4724
+ if (all.length > 0) return [];
4416
4725
  return "its iOS simulator slice has no Swift interface or C modulemap";
4417
- const hash = (0, import_node_crypto6.createHash)("sha256").update(
4418
- `standin/v1\0${toolchain.toolchainBin}\0${swiftModuleSdk(toolchain.moduleRoot).wasmSdkId}\0${toolchain.moduleRoot}\0${binary.target}\0${binary.source}\0`
4419
- );
4726
+ }
4727
+ const hash = (0, import_node_crypto6.createHash)("sha256").update(standinGenerationInputs([binary], toolchain));
4728
+ hash.update(digest);
4420
4729
  for (const surface of found) {
4421
4730
  hash.update(`${surface.kind}\0${surface.module}\0`);
4422
4731
  for (const file of surface.kind === "swift" ? [surface.interface] : [
@@ -4459,11 +4768,11 @@ function binaryStandins(binary, toolchain) {
4459
4768
  }
4460
4769
  return result;
4461
4770
  }
4462
- function swiftStandins(binaries, toolchain) {
4771
+ function swiftStandins(binaries, toolchain, provided = /* @__PURE__ */ new Set()) {
4463
4772
  const standins = [];
4464
4773
  const gaps = /* @__PURE__ */ new Map();
4465
4774
  for (const binary of binaries) {
4466
- const result = binaryStandins(binary, toolchain);
4775
+ const result = binaryStandins(binary, toolchain, provided);
4467
4776
  if (typeof result === "string") gaps.set(binary.target, result);
4468
4777
  else standins.push(...result);
4469
4778
  }
@@ -5702,32 +6011,49 @@ function swiftPackages(entry, app) {
5702
6011
  ({ source }) => source.kind === "local" ? stamp(import_node_path14.default.join(source.dir, "Package.swift")) : 0
5703
6012
  )
5704
6013
  ]);
5705
- if (entry.packages?.key !== key2) {
5706
- const resolve2 = (provided, binaryGaps) => resolveSwiftPackages({
5707
- rootDir: app.rootDir,
5708
- resolved: app.packageResolved,
5709
- products: app.linkedProducts,
5710
- localDirs: app.localPackageDirs,
5711
- provided,
5712
- binaryGaps
5713
- });
5714
- let packages = resolve2(entry.provided);
5715
- let standins = [];
5716
- const reached = packages.binaries.filter((binary) => binary.reached);
5717
- if (entry.moduleRoot && entry.provided && reached.length > 0) {
5718
- const built2 = swiftStandins(reached, {
5719
- moduleRoot: entry.moduleRoot,
5720
- toolchainBin: swiftModuleToolchain(entry.moduleRoot).toolchainBin
6014
+ let cached = entry.packages;
6015
+ if (cached?.key !== key2) {
6016
+ cached = {
6017
+ key: key2,
6018
+ standinKey: "",
6019
+ packages: resolveSwiftPackages({
6020
+ rootDir: app.rootDir,
6021
+ resolved: app.packageResolved,
6022
+ products: app.linkedProducts,
6023
+ localDirs: app.localPackageDirs,
6024
+ provided: entry.provided
6025
+ }),
6026
+ standins: []
6027
+ };
6028
+ entry.packages = cached;
6029
+ }
6030
+ const reached = cached.packages.binaries.filter((binary) => binary.reached);
6031
+ if (entry.moduleRoot && entry.provided && reached.length > 0) {
6032
+ const resolved = swiftModuleToolchain(entry.moduleRoot);
6033
+ const toolchain = {
6034
+ moduleRoot: entry.moduleRoot,
6035
+ toolchainBin: resolved.toolchainBin,
6036
+ release: resolved.release
6037
+ };
6038
+ const generation = standinGenerationInputs(reached, toolchain);
6039
+ if (cached.standinKey !== generation) {
6040
+ const built2 = swiftStandins(reached, toolchain, entry.provided);
6041
+ cached.packages = resolveSwiftPackages({
6042
+ rootDir: app.rootDir,
6043
+ resolved: app.packageResolved,
6044
+ products: app.linkedProducts,
6045
+ localDirs: app.localPackageDirs,
6046
+ provided: /* @__PURE__ */ new Set([
6047
+ ...entry.provided,
6048
+ ...built2.standins.map((standin) => standin.target)
6049
+ ]),
6050
+ binaryGaps: built2.gaps
5721
6051
  });
5722
- standins = built2.standins;
5723
- packages = resolve2(
5724
- /* @__PURE__ */ new Set([...entry.provided, ...standins.map((standin) => standin.target)]),
5725
- built2.gaps
5726
- );
6052
+ cached.standins = built2.standins;
6053
+ cached.standinKey = generation;
5727
6054
  }
5728
- entry.packages = { key: key2, packages, standins };
5729
6055
  }
5730
- return entry.packages;
6056
+ return cached;
5731
6057
  }
5732
6058
  var XCODE_APP_DIR = "__app__";
5733
6059
  var XCODE_FRAMEWORKS_DIR = "__frameworks__";