peachsim 0.1.730 → 0.1.745

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 (105) hide show
  1. package/cli/bridge-flow-runner.ts +15 -2
  2. package/cli/commands/control.ts +13 -3
  3. package/cli/commands/desktop.ts +1 -0
  4. package/cli/commands/electron.ts +12 -8
  5. package/cli/commands/flow.ts +1 -3
  6. package/cli/commands/install-desktop.ts +105 -66
  7. package/cli/commands/logout.ts +5 -1
  8. package/cli/commands/no-bridge-hint.ts +2 -2
  9. package/cli/commands/swift.ts +26 -9
  10. package/cli/desktop-companion.ts +36 -9
  11. package/cli/drivers/desktop.ts +65 -0
  12. package/cli/drivers/electron.ts +4 -66
  13. package/cli/drivers/index.ts +1 -0
  14. package/cli/drivers/playwright.ts +3 -3
  15. package/cli/drivers/registry.ts +7 -2
  16. package/cli/drivers/types.ts +4 -3
  17. package/cli/maestro-js.ts +10 -0
  18. package/cli/outbound-endpoints.ts +2 -2
  19. package/dist-lib/agent-daemon-client.cjs +1 -1
  20. package/dist-lib/agent-events.cjs +1 -1
  21. package/dist-lib/agent-identity.cjs +1 -1
  22. package/dist-lib/agent-sessions.cjs +1 -1
  23. package/dist-lib/attached-projects.cjs +1 -1
  24. package/dist-lib/auth/shared-session.cjs +39 -9
  25. package/dist-lib/backend-origin.cjs +1 -1
  26. package/dist-lib/beta.cjs +1 -1
  27. package/dist-lib/beta.mjs +1 -1
  28. package/dist-lib/bridge-constants.cjs +1 -1
  29. package/dist-lib/bridge-contract-input.cjs +1 -1
  30. package/dist-lib/bridge-contract-input.mjs +1 -1
  31. package/dist-lib/bridge-contract.cjs +1 -1
  32. package/dist-lib/bridge-contract.mjs +1 -1
  33. package/dist-lib/capture-contract.cjs +13 -19
  34. package/dist-lib/capture-contract.mjs +13 -19
  35. package/dist-lib/cli-constants.cjs +1 -1
  36. package/dist-lib/cloud-contract.cjs +1 -1
  37. package/dist-lib/cloud-contract.mjs +1 -1
  38. package/dist-lib/cloud-test-args.cjs +1 -1
  39. package/dist-lib/cloud-test-args.mjs +1 -1
  40. package/dist-lib/cloud.cjs +1 -1
  41. package/dist-lib/cloud.mjs +1 -1
  42. package/dist-lib/config.cjs +1 -1
  43. package/dist-lib/detox/index.cjs +20 -2
  44. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  45. package/dist-lib/home-paths.cjs +32 -1
  46. package/dist-lib/host/bridge-host.cjs +1616 -532
  47. package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
  48. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  49. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  50. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  51. package/dist-lib/host/websocket-proxy.cjs +1 -1
  52. package/dist-lib/index.cjs +14 -19
  53. package/dist-lib/jump-to-source-babel.cjs +1 -1
  54. package/dist-lib/jump-to-source-native.cjs +1 -1
  55. package/dist-lib/kotlin-host.cjs +1 -1
  56. package/dist-lib/menu.cjs +1 -1
  57. package/dist-lib/menu.mjs +1 -1
  58. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  59. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  60. package/dist-lib/metro-production-bundle.cjs +1 -1
  61. package/dist-lib/metro-production-bundle.mjs +1 -1
  62. package/dist-lib/metro.cjs +1 -1
  63. package/dist-lib/native-app-identity.cjs +1 -1
  64. package/dist-lib/native-app-identity.mjs +1 -1
  65. package/dist-lib/native-firebase-metadata.cjs +1 -1
  66. package/dist-lib/native-firebase-metadata.mjs +1 -1
  67. package/dist-lib/plist.cjs +1 -1
  68. package/dist-lib/plist.mjs +1 -1
  69. package/dist-lib/profiles.cjs +1 -1
  70. package/dist-lib/public-brand.cjs +1 -1
  71. package/dist-lib/react-native-host-modules.cjs +1 -1
  72. package/dist-lib/react-native-host-modules.mjs +1 -1
  73. package/dist-lib/render-mode.cjs +1 -1
  74. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  75. package/dist-lib/sdk.cjs +2 -1
  76. package/dist-lib/sdk.mjs +2 -1
  77. package/dist-lib/skills.cjs +2306 -1067
  78. package/dist-lib/swift-compile.cjs +317 -60
  79. package/dist-lib/swift-compile.mjs +313 -61
  80. package/dist-lib/swift-package.cjs +146 -9
  81. package/dist-lib/swift-package.mjs +144 -9
  82. package/dist-lib/swift-submit.cjs +2 -2
  83. package/dist-lib/swift-submit.mjs +2 -2
  84. package/dist-lib/swift-toolchain.cjs +1 -1
  85. package/dist-lib/swift.cjs +1 -1
  86. package/dist-lib/vite-swift.cjs +1310 -226
  87. package/dist-lib/vite.cjs +1 -1
  88. package/package.json +1 -1
  89. package/skills/contrast/SKILL.md +1 -1
  90. package/src/auth/shared-session.ts +45 -9
  91. package/src/bridge-constants.ts +7 -7
  92. package/src/capture-contract.ts +18 -33
  93. package/src/desktop-host-delivery.ts +81 -0
  94. package/src/home-paths.ts +30 -0
  95. package/src/host/bridge-host.ts +11 -6
  96. package/src/native-seam-manifest.ts +0 -11
  97. package/src/sim-client.ts +1 -0
  98. package/src/swift-compile.ts +403 -68
  99. package/src/swift-distribution.lock.json +11 -11
  100. package/src/swift-host.ts +316 -43
  101. package/src/swift-package.ts +204 -19
  102. package/src/swift-remote-packages.ts +255 -0
  103. package/src/swift-submit.ts +4 -1
  104. package/src/vite-plugin.ts +19 -8
  105. package/src/xcode-project.ts +527 -0
@@ -1,7 +1,7 @@
1
- /*! rnx v0.1.730 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.745 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
 
3
3
  // src/swift-compile.ts
4
- import { execFile as execFile2 } from "node:child_process";
4
+ import { execFile as execFile2, execFileSync } from "node:child_process";
5
5
  import { createHash as createHash2 } from "node:crypto";
6
6
  import {
7
7
  cpSync,
@@ -159,14 +159,24 @@ function swiftImplicitResourcePaths(paths) {
159
159
  ) || /(?:^|\/)[^/]+\.lproj\/[^/]+$/.test(file))
160
160
  ).sort();
161
161
  }
162
- function swiftManifestTargets(manifest, resourcePaths = []) {
163
- const implicitResources = swiftImplicitResourcePaths(resourcePaths);
164
- const code = manifest.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/[^\n]*/g, "");
165
- const targets = [];
166
- const pattern = /\.(executableTarget|target)\s*\(/g;
162
+ var MANIFEST_DECLARATIONS = [
163
+ "executableTarget",
164
+ "testTarget",
165
+ "binaryTarget",
166
+ "systemLibrary",
167
+ "macro",
168
+ "plugin",
169
+ "target",
170
+ "library",
171
+ "executable",
172
+ "package"
173
+ ];
174
+ function manifestCalls(manifest, kinds) {
175
+ const code = manifest.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[^:"])\/\/[^\n]*/g, "$1");
176
+ const calls = [];
177
+ const pattern = new RegExp(`\\.(${MANIFEST_DECLARATIONS.join("|")})\\s*\\(`, "g");
167
178
  let match;
168
179
  while ((match = pattern.exec(code)) !== null) {
169
- const executable = match[1] === "executableTarget";
170
180
  let depth = 1;
171
181
  const start = pattern.lastIndex;
172
182
  let i = start;
@@ -194,18 +204,31 @@ function swiftManifestTargets(manifest, resourcePaths = []) {
194
204
  }
195
205
  i++;
196
206
  }
207
+ if (kinds.includes(match[1]))
208
+ calls.push({ kind: match[1], flat, call: code.slice(start, i) });
209
+ pattern.lastIndex = i;
210
+ }
211
+ return calls;
212
+ }
213
+ function swiftManifestTargets(manifest, resourcePaths = []) {
214
+ const implicitResources = swiftImplicitResourcePaths(resourcePaths);
215
+ const targets = [];
216
+ for (const { kind, flat, call } of manifestCalls(manifest, [
217
+ "executableTarget",
218
+ "target"
219
+ ])) {
220
+ const executable = kind === "executableTarget";
197
221
  const name = /\bname\s*:\s*"([^"]+)"/.exec(flat)?.[1];
198
222
  if (!name) continue;
199
223
  const rawPath = /\bpath\s*:\s*"([^"]*)"/.exec(flat)?.[1];
200
224
  const targetPath = rawPath == null || rawPath === "" ? `Sources/${name}` : rawPath.replace(/^\.\//, "").replace(/\/+$/, "");
201
- const call = code.slice(start, i);
202
225
  const languageMode = Number(
203
226
  /\.swiftLanguageMode\(\s*\.v(\d+)\s*\)/.exec(call)?.[1] ?? "5"
204
227
  );
205
228
  const mainActorIsolation = /\.defaultIsolation\(\s*MainActor\.self\s*\)/.test(call);
206
229
  const excluded = [
207
230
  ...(/\bexclude\s*:\s*\[([^\]]*)\]/.exec(flat)?.[1] ?? "").matchAll(/"([^"]+)"/g)
208
- ].map((match2) => match2[1].replace(/^\.\//, "").replace(/\/+$/, ""));
231
+ ].map((match) => match[1].replace(/^\.\//, "").replace(/\/+$/, ""));
209
232
  const prefix = targetPath === "." ? "" : `${targetPath}/`;
210
233
  const resources = /\bresources\s*:/.test(flat) || implicitResources.some((file) => {
211
234
  if (!file.startsWith(prefix)) return false;
@@ -353,6 +376,9 @@ var OPTIONAL_FRAMEWORK_DEPENDENCIES = {
353
376
  CryptoKit: [],
354
377
  CommonCrypto: [],
355
378
  CoreText: [],
379
+ Compression: ["PeachCodec"],
380
+ zlib: ["PeachCodec"],
381
+ PeachCodec: [],
356
382
  Security: ["CryptoKit"],
357
383
  TikTokBusinessSDK: [],
358
384
  nSure: [],
@@ -363,6 +389,66 @@ var OPTIONAL_FRAMEWORK_DEPENDENCIES = {
363
389
  DatadogTrace: ["DatadogCore"]
364
390
  };
365
391
  var OPTIONAL_FRAMEWORKS = new Set(Object.keys(OPTIONAL_FRAMEWORK_DEPENDENCIES));
392
+ var SWIFT_IMPORT = /^\s*(?:@\w+(?:\([^)]*\))?\s+)*import\s+(?:(?:typealias|struct|class|enum|protocol|let|var|func)\s+)?([A-Za-z_][A-Za-z0-9_]*)/;
393
+ function swiftImportNames(contents, unconditional = false) {
394
+ const names = [];
395
+ let depth = 0;
396
+ for (const line of contents.split("\n")) {
397
+ const directive = /^\s*#(if|endif)\b/.exec(line)?.[1];
398
+ if (directive === "if") depth++;
399
+ else if (directive === "endif") depth = Math.max(0, depth - 1);
400
+ if (unconditional && depth > 0) continue;
401
+ const name = SWIFT_IMPORT.exec(line)?.[1];
402
+ if (name) names.push(name);
403
+ }
404
+ return names;
405
+ }
406
+ function swiftPeachModules(moduleRoot) {
407
+ const distribution = swiftDistributionAt(moduleRoot);
408
+ return distribution ? distribution.modules : [
409
+ ...readFileSync2(path2.join(moduleRoot, "Package.swift"), "utf8").matchAll(
410
+ /\.(?:target|systemLibrary)\(\s*name:\s*"([^"]+)"/g
411
+ )
412
+ ].map((match) => match[1]);
413
+ }
414
+ var availableModules = /* @__PURE__ */ new Map();
415
+ function swiftAvailableModules(moduleRoot, toolchainBin) {
416
+ const sdk = swiftModuleSdk(moduleRoot).wasmSdkId;
417
+ const key = `${moduleRoot}\0${sdk}`;
418
+ const cached = availableModules.get(key);
419
+ if (cached) return cached;
420
+ const modules = new Set(swiftPeachModules(moduleRoot));
421
+ const configuration = execFileSync(
422
+ path2.join(toolchainBin, "swift"),
423
+ ["sdk", "configure", "--show-configuration", sdk, "wasm32-unknown-wasip1"],
424
+ { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }
425
+ );
426
+ const resources = /^swiftResourcesPath:\s*(.+)$/m.exec(configuration)?.[1]?.trim();
427
+ if (!resources) throw new Error(`swift sdk ${sdk} reports no swiftResourcesPath`);
428
+ for (const entry of readdirSync(path2.join(resources, "wasi"))) {
429
+ if (entry.endsWith(".swiftmodule"))
430
+ modules.add(entry.slice(0, -".swiftmodule".length));
431
+ }
432
+ for (const entry of readdirSync(resources)) {
433
+ const map = path2.join(resources, entry, "module.modulemap");
434
+ if (!existsSync(map)) continue;
435
+ for (const match of readFileSync2(map, "utf8").matchAll(/^module\s+([A-Za-z_]\w*)/gm))
436
+ modules.add(match[1]);
437
+ }
438
+ availableModules.set(key, modules);
439
+ return modules;
440
+ }
441
+ function missingSwiftModules(files, available) {
442
+ const missing = /* @__PURE__ */ new Map();
443
+ for (const [file, contents] of Object.entries(files)) {
444
+ if (!file.endsWith(".swift") || file === "Package.swift") continue;
445
+ for (const name of new Set(swiftImportNames(contents, true))) {
446
+ if (available.has(name)) continue;
447
+ missing.set(name, [...missing.get(name) ?? [], file]);
448
+ }
449
+ }
450
+ return new Map([...missing].sort(([left], [right]) => left.localeCompare(right)));
451
+ }
366
452
  function swiftTargetDependencies(files, targets) {
367
453
  const names = /* @__PURE__ */ new Set([...OPTIONAL_FRAMEWORKS, ...targets.map((target) => target.name)]);
368
454
  const siblings = /* @__PURE__ */ new Map();
@@ -375,10 +461,8 @@ function swiftTargetDependencies(files, targets) {
375
461
  (candidate) => candidate.name !== target.name && candidate.path !== "." && candidate.path.startsWith(prefix) && file.startsWith(`${candidate.path}/`)
376
462
  ))
377
463
  continue;
378
- for (const match of contents.matchAll(
379
- /^\s*(?:@\w+(?:\([^)]*\))?\s+)*import\s+(?:(?:typealias|struct|class|enum|protocol|let|var|func)\s+)?([A-Za-z_][A-Za-z0-9_]*)/gm
380
- )) {
381
- if (names.has(match[1]) && match[1] !== target.name) deps.add(match[1]);
464
+ for (const name of swiftImportNames(contents)) {
465
+ if (names.has(name) && name !== target.name) deps.add(name);
382
466
  }
383
467
  }
384
468
  siblings.set(target.name, [...deps].sort());
@@ -388,16 +472,14 @@ function swiftTargetDependencies(files, targets) {
388
472
  var ONE_PRODUCT = '.product(name: "One", package: "sootsim-swift")';
389
473
  var SPRITEKIT_PRODUCT = '.product(name: "SpriteKit", package: "sootsim-swift")';
390
474
  var importsSpriteKit = (files) => Object.entries(files).some(
391
- ([file, contents]) => file.endsWith(".swift") && /^\s*(?:@\w+(?:\([^)]*\))?\s+)*import\s+(?:(?:typealias|struct|class|enum|protocol|let|var|func)\s+)?SpriteKit\b/m.test(
392
- contents
393
- )
475
+ ([file, contents]) => file.endsWith(".swift") && swiftImportNames(contents).includes("SpriteKit")
394
476
  );
395
- var FOUNDATION_IMPLICIT_FLAGS = ', "-Xfrontend", "-import-module", "-Xfrontend", "PeachObjC", "-Xfrontend", "-import-module", "-Xfrontend", "Dispatch", "-Xfrontend", "-import-module", "-Xfrontend", "FoundationNetworking"';
477
+ var FOUNDATION_IMPLICIT_FLAGS = ', "-Xfrontend", "-import-module", "-Xfrontend", "PeachObjC", "-Xfrontend", "-import-module", "-Xfrontend", "Dispatch", "-Xfrontend", "-import-module", "-Xfrontend", "FoundationNetworking", "-Xfrontend", "-import-module", "-Xfrontend", "WASILibc", "-Xfrontend", "-import-module", "-Xfrontend", "wasi_pthread"';
396
478
  var ONE_IMPLICIT_FLAGS = ', "-Xfrontend", "-import-module", "-Xfrontend", "One"';
397
- var MULTI_MANIFEST_VERSION = 10;
479
+ var MULTI_MANIFEST_VERSION = 11;
398
480
  function swiftArtifactHash(input, release, moduleRoot) {
399
481
  const hash = createHash2("sha256");
400
- hash.update(`swift-compile/v14
482
+ hash.update(`swift-compile/v16
401
483
  ${release}
402
484
  `);
403
485
  if (input.oneModule) hash.update("one-module\n");
@@ -569,23 +651,98 @@ function forwardedArguments(parameters) {
569
651
  }
570
652
  return args.join(", ");
571
653
  }
572
- function liftExtensionOverrides(source) {
654
+ function closingBrace(source, tokens, open) {
655
+ let depth = 0;
656
+ for (const at of tokens) {
657
+ if (at < open) continue;
658
+ if (source[at] === "{") depth++;
659
+ else if (source[at] === "}" && --depth === 0) return at + 1;
660
+ }
661
+ return source.length;
662
+ }
663
+ function scanObjCExtensionMembers(source, tokens, records) {
664
+ const masked = swiftCodeMask(source);
665
+ const found = /* @__PURE__ */ new Map();
666
+ const member = /\b(func|var)\s+([A-Za-z_]\w*)/g;
667
+ for (const record of records) {
668
+ const close = closingBrace(source, tokens, record.open);
669
+ const body = masked.slice(record.open, close);
670
+ member.lastIndex = 0;
671
+ for (let match = member.exec(body); match; match = member.exec(body)) {
672
+ const at = record.open + match.index + match[0].indexOf(match[1]);
673
+ let depth = 0;
674
+ for (const token of tokens) {
675
+ if (token <= record.open) continue;
676
+ if (token >= at) break;
677
+ if (source[token] === "{") depth++;
678
+ else if (source[token] === "}") depth--;
679
+ }
680
+ if (depth > 0) continue;
681
+ const head = masked.slice(record.open, at);
682
+ const bound = Math.max(
683
+ head.lastIndexOf(";"),
684
+ head.lastIndexOf("{"),
685
+ head.lastIndexOf("}")
686
+ );
687
+ const prefix = head.slice(bound + 1);
688
+ if (/(?:^|[^A-Za-z0-9_$])(?:private|fileprivate|static|class)(?:[^A-Za-z0-9_$]|$)/.test(
689
+ prefix
690
+ ))
691
+ continue;
692
+ if (!/@objc\b/.test(prefix) && !/@IBAction\b/.test(prefix) && !record.objcMembers)
693
+ continue;
694
+ const members = found.get(record.type) ?? /* @__PURE__ */ new Set();
695
+ members.add(match[2]);
696
+ found.set(record.type, members);
697
+ }
698
+ }
699
+ return found;
700
+ }
701
+ function objcExtensionMemberIndex(sources) {
702
+ const index = /* @__PURE__ */ new Map();
703
+ for (const source of sources) {
704
+ const { tokens } = swiftCodeScan(source);
705
+ const masked = swiftCodeMask(source);
706
+ const records = [];
707
+ let pending = null;
708
+ for (const at of tokens) {
709
+ const rest = source.slice(at, at + 600);
710
+ if (rest.startsWith("{")) {
711
+ if (pending) records.push({ ...pending, open: at });
712
+ pending = null;
713
+ continue;
714
+ }
715
+ if (rest.startsWith("}")) continue;
716
+ const extended = EXTENSION_DECL.exec(rest);
717
+ if (extended) {
718
+ const lines = source.lastIndexOf("\n", source.lastIndexOf("\n", at - 1) - 1) + 1;
719
+ pending = {
720
+ type: extended[1].split(".").pop(),
721
+ objcMembers: /@objcMembers\b/.test(masked.slice(lines, at))
722
+ };
723
+ }
724
+ }
725
+ for (const [type, members] of scanObjCExtensionMembers(source, tokens, records)) {
726
+ const into = index.get(type) ?? /* @__PURE__ */ new Set();
727
+ for (const member of members) into.add(member);
728
+ index.set(type, into);
729
+ }
730
+ }
731
+ return index;
732
+ }
733
+ function liftExtensionOverrides(source, extraObjCExtensions) {
573
734
  const { tokens } = swiftCodeScan(source);
735
+ const masked = swiftCodeMask(source);
574
736
  const stack = [];
575
737
  let pending = null;
576
738
  const classes = /* @__PURE__ */ new Map();
577
739
  let declaredBase = null;
578
740
  let declaredObjCMembers = false;
741
+ const extensions = [];
742
+ let declaredExtObjCMembers = false;
579
743
  const lifted = [];
580
- const closing = (open) => {
581
- let depth = 0;
582
- for (const at of tokens) {
583
- if (at < open) continue;
584
- if (source[at] === "{") depth++;
585
- else if (source[at] === "}" && --depth === 0) return at + 1;
586
- }
587
- return source.length;
588
- };
744
+ const overrides = [];
745
+ const closing = (open) => closingBrace(source, tokens, open);
589
746
  for (const at of tokens) {
590
747
  const rest = source.slice(at, at + 600);
591
748
  if (rest.startsWith("{")) {
@@ -596,6 +753,12 @@ function liftExtensionOverrides(source) {
596
753
  base: declaredBase,
597
754
  objcMembers: declaredObjCMembers
598
755
  });
756
+ if (frame.kind === "extension")
757
+ extensions.push({
758
+ type: frame.name,
759
+ open: at,
760
+ objcMembers: declaredExtObjCMembers
761
+ });
599
762
  stack.push(frame);
600
763
  pending = null;
601
764
  continue;
@@ -615,12 +778,39 @@ function liftExtensionOverrides(source) {
615
778
  const extended = EXTENSION_DECL.exec(rest);
616
779
  if (extended) {
617
780
  pending = { kind: "extension", name: extended[1].split(".").pop() };
781
+ const lines = source.lastIndexOf("\n", source.lastIndexOf("\n", at - 1) - 1) + 1;
782
+ declaredExtObjCMembers = /@objcMembers\b/.test(masked.slice(lines, at));
618
783
  continue;
619
784
  }
620
785
  const top = stack.at(-1);
621
- if (!rest.startsWith("override") || top?.kind !== "extension" || pending) continue;
786
+ if (!rest.startsWith("override") || pending) continue;
622
787
  const line = source.slice(source.lastIndexOf("\n", at - 1) + 1, at);
623
788
  const modifiers = (` ${line} `.match(MODIFIERS) ?? []).map((word) => word.trim());
789
+ if (top?.kind === "class") {
790
+ let member;
791
+ let nameAt = 0;
792
+ const direct = OVERRIDE_FUNC.exec(rest);
793
+ if (direct) {
794
+ member = direct[2];
795
+ nameAt = at + rest.indexOf(
796
+ member,
797
+ rest.indexOf("func", "override".length + direct[1].length) + 4
798
+ );
799
+ } else {
800
+ const property2 = OVERRIDE_VAR.exec(rest);
801
+ if (property2) {
802
+ const open = at + property2[0].length - 1;
803
+ if (!/\b(?:set|willSet|didSet)\b/.test(source.slice(open, closing(open)))) {
804
+ member = property2[2];
805
+ nameAt = at + rest.indexOf(member, rest.indexOf("var"));
806
+ }
807
+ }
808
+ }
809
+ if (member !== void 0 && !modifiers.includes("private") && !modifiers.includes("fileprivate"))
810
+ overrides.push({ type: top.name, member, at, nameAt });
811
+ continue;
812
+ }
813
+ if (top?.kind !== "extension") continue;
624
814
  const func = OVERRIDE_FUNC.exec(rest);
625
815
  if (func) {
626
816
  const name = func[2];
@@ -638,20 +828,18 @@ function liftExtensionOverrides(source) {
638
828
  if (args === null) continue;
639
829
  const call = (clause.includes("->") ? "return " : "") + (/\b(?:throws|rethrows)\b/.test(clause) ? "try " : "") + (/\basync\b/.test(clause) ? "await " : "") + `__peach_ext_${name}(${args})`;
640
830
  const signature = `func ${name}${func[3] ?? ""}${source.slice(open, close + 1)}${clause ? ` ${clause}` : ""}`;
831
+ const nameAt = at + rest.indexOf(name, rest.indexOf("func", "override".length + func[1].length) + 4);
641
832
  lifted.push({
642
833
  type: top.name,
643
834
  member: name,
644
- stub: `${[...modifiers, "override"].join(" ")} ${signature} { ${call} };`,
835
+ at,
836
+ modifiers,
837
+ decl: signature,
838
+ forward: `{ ${call} };`,
839
+ nameAt,
645
840
  edits: [
646
841
  [at, "override".length, " ".repeat("override".length)],
647
- [
648
- at + rest.indexOf(
649
- name,
650
- rest.indexOf("func", "override".length + func[1].length) + 4
651
- ),
652
- 0,
653
- "__peach_ext_"
654
- ]
842
+ [nameAt, 0, "__peach_ext_"]
655
843
  ]
656
844
  });
657
845
  continue;
@@ -661,40 +849,77 @@ function liftExtensionOverrides(source) {
661
849
  const open = at + property[0].length - 1;
662
850
  if (/\b(?:set|willSet|didSet)\b/.test(source.slice(open, closing(open)))) continue;
663
851
  const name = property[2];
852
+ const nameAt = at + rest.indexOf(name, rest.indexOf("var"));
664
853
  lifted.push({
665
854
  type: top.name,
666
855
  member: name,
667
- stub: `${[...modifiers, "override"].join(" ")} var ${name}: ${property[3].trim()} { __peach_ext_${name} };`,
856
+ at,
857
+ modifiers,
858
+ decl: `var ${name}: ${property[3].trim()}`,
859
+ forward: `{ __peach_ext_${name} };`,
860
+ nameAt,
668
861
  edits: [
669
862
  [at, "override".length, " ".repeat("override".length)],
670
- [at + rest.indexOf(name, rest.indexOf("var")), 0, "__peach_ext_"]
863
+ [nameAt, 0, "__peach_ext_"]
671
864
  ]
672
865
  });
673
866
  }
674
867
  }
675
- const overridesObjC = (type, member) => {
868
+ const extIndex = /* @__PURE__ */ new Map();
869
+ if (extraObjCExtensions)
870
+ for (const [type, members] of extraObjCExtensions)
871
+ extIndex.set(type, new Set(members));
872
+ for (const [type, members] of scanObjCExtensionMembers(source, tokens, extensions)) {
873
+ const into = extIndex.get(type) ?? /* @__PURE__ */ new Set();
874
+ for (const member of members) into.add(member);
875
+ extIndex.set(type, into);
876
+ }
877
+ const overrideKind = (type, member) => {
676
878
  let base = classes.get(type)?.base ?? null;
677
879
  while (base !== null) {
678
- if (APPLE_CLASS.test(base)) return true;
679
880
  const declaredClass = classes.get(base);
680
- if (!declaredClass) return false;
681
- const body = source.slice(declaredClass.brace, closing(declaredClass.brace));
682
- const found = new RegExp(`\\b(?:func|var)\\s+${member}\\b`).exec(body);
683
- if (found) {
684
- const line = body.slice(body.lastIndexOf("\n", found.index) + 1, found.index);
685
- return declaredClass.objcMembers || /@objc\b/.test(line);
686
- }
687
- base = declaredClass.base;
881
+ if (declaredClass) {
882
+ const body = source.slice(declaredClass.brace, closing(declaredClass.brace));
883
+ const found = new RegExp(`\\b(?:func|var)\\s+${member}\\b`).exec(body);
884
+ if (found) {
885
+ const line = body.slice(body.lastIndexOf("\n", found.index) + 1, found.index);
886
+ return declaredClass.objcMembers || /@objc\b/.test(line) ? "objc" : "plain";
887
+ }
888
+ if (extIndex.get(base)?.has(member)) return "ext";
889
+ base = declaredClass.base;
890
+ } else if (extIndex.get(base)?.has(member)) return "ext";
891
+ else if (APPLE_CLASS.test(base)) return "apple";
892
+ else return "unknown";
688
893
  }
689
- return false;
894
+ return "unknown";
690
895
  };
896
+ const rename = (at, nameAt) => [
897
+ [at, "override".length, " ".repeat("override".length)],
898
+ [nameAt, 0, "__peach_ovr_"]
899
+ ];
691
900
  const edits = [];
692
901
  const stubs = /* @__PURE__ */ new Map();
693
902
  for (const entry of lifted) {
694
903
  const brace = classes.get(entry.type)?.brace;
695
- if (brace === void 0 || !overridesObjC(entry.type, entry.member)) continue;
904
+ if (brace === void 0) continue;
905
+ const kind = overrideKind(entry.type, entry.member);
906
+ if (kind !== "apple" && kind !== "objc" && kind !== "ext") continue;
907
+ if (kind === "ext" && (entry.modifiers.includes("private") || entry.modifiers.includes("fileprivate")))
908
+ continue;
909
+ if (kind === "ext") {
910
+ edits.push(...rename(entry.at, entry.nameAt));
911
+ continue;
912
+ }
696
913
  edits.push(...entry.edits);
697
- stubs.set(brace, [...stubs.get(brace) ?? [], entry.stub]);
914
+ const head = [...entry.modifiers, "override"].filter((word) => word !== "").join(" ");
915
+ stubs.set(brace, [
916
+ ...stubs.get(brace) ?? [],
917
+ `${head} ${entry.decl} ${entry.forward}`
918
+ ]);
919
+ }
920
+ for (const candidate of overrides) {
921
+ if (overrideKind(candidate.type, candidate.member) !== "ext") continue;
922
+ edits.push(...rename(candidate.at, candidate.nameAt));
698
923
  }
699
924
  for (const [brace, list] of stubs) edits.push([brace + 1, 0, ` ${list.join(" ")}`]);
700
925
  let out = source;
@@ -876,8 +1101,8 @@ function swiftCodeMask(source) {
876
1101
  scanCode(0, false);
877
1102
  return chars.join("");
878
1103
  }
879
- function swiftSourceAsIOS(original) {
880
- const source = liftExtensionOverrides(original);
1104
+ function swiftSourceAsIOS(original, extraObjCExtensions) {
1105
+ const source = liftExtensionOverrides(original, extraObjCExtensions);
881
1106
  const { lineStarts, tokens } = swiftCodeScan(source);
882
1107
  let offset = 0;
883
1108
  const conditioned = source.split("\n").map((line) => {
@@ -1046,9 +1271,22 @@ function swiftCodeScan(source) {
1046
1271
  }
1047
1272
  return { lineStarts: starts, tokens };
1048
1273
  }
1049
- var compiledSource = (file, contents) => file.endsWith(".swift") ? swiftSourceAsIOS(contents) : contents;
1274
+ var compiledSource = (file, contents, extraObjCExtensions) => file.endsWith(".swift") ? swiftSourceAsIOS(contents, extraObjCExtensions) : contents;
1050
1275
  function prepareSwiftDependency(source, destination) {
1051
1276
  rmSync(destination, { recursive: true, force: true });
1277
+ const origins = [];
1278
+ const gather = (from, root) => {
1279
+ for (const entry of readdirSync(from, { withFileTypes: true })) {
1280
+ if (entry.name === ".git" || entry.name === ".build" || entry.name === ".swiftpm")
1281
+ continue;
1282
+ const file = path2.join(from, entry.name);
1283
+ if (entry.isDirectory()) gather(file, false);
1284
+ else if (entry.isFile() && entry.name.endsWith(".swift") && !(root && /^Package(@swift-[\d.]+)?\.swift$/.test(entry.name)))
1285
+ origins.push(readFileSync2(file, "utf8"));
1286
+ }
1287
+ };
1288
+ gather(source, true);
1289
+ const objcExtensions = objcExtensionMemberIndex(origins);
1052
1290
  const copy = (from, to, root) => {
1053
1291
  mkdirSync(to, { recursive: true });
1054
1292
  for (const entry of readdirSync(from, { withFileTypes: true })) {
@@ -1058,7 +1296,10 @@ function prepareSwiftDependency(source, destination) {
1058
1296
  const target = path2.join(to, entry.name);
1059
1297
  if (entry.isDirectory()) copy(file, target, false);
1060
1298
  else if (entry.isFile() && entry.name.endsWith(".swift") && !(root && /^Package(@swift-[\d.]+)?\.swift$/.test(entry.name)))
1061
- writeFileSync(target, compiledSource(file, readFileSync2(file, "utf8")));
1299
+ writeFileSync(
1300
+ target,
1301
+ compiledSource(file, readFileSync2(file, "utf8"), objcExtensions)
1302
+ );
1062
1303
  else cpSync(file, target, { verbatimSymlinks: true });
1063
1304
  }
1064
1305
  };
@@ -1096,10 +1337,16 @@ function writeSwiftProject(layout, input, moduleRoot) {
1096
1337
  // sootsim-swift files ${modulePlan.digest("hex").slice(0, 16)}
1097
1338
  // resource accessors ${resourcePlan}
1098
1339
  `;
1340
+ const objcExtensions = objcExtensionMemberIndex(
1341
+ Object.entries(input.files).filter(([file]) => file.endsWith(".swift")).map(([, contents]) => contents)
1342
+ );
1099
1343
  if (targets.length === 0) {
1100
1344
  for (const [file, contents] of Object.entries(input.files)) {
1101
1345
  if (file === "Package.swift") continue;
1102
- files.set(path2.join(layout.sources, file), compiledSource(file, contents));
1346
+ files.set(
1347
+ path2.join(layout.sources, file),
1348
+ compiledSource(file, contents, objcExtensions)
1349
+ );
1103
1350
  }
1104
1351
  let manifest = readFileSync2(
1105
1352
  path2.join(moduleRoot, "scripts/contrast-app-Package.swift"),
@@ -1145,7 +1392,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
1145
1392
  const base = layout.multi ? layout.root : layout.sources;
1146
1393
  for (const [file, contents] of Object.entries(input.files)) {
1147
1394
  if (file === "Package.swift") continue;
1148
- files.set(path2.join(base, file), compiledSource(file, contents));
1395
+ files.set(path2.join(base, file), compiledSource(file, contents, objcExtensions));
1149
1396
  }
1150
1397
  files.set(
1151
1398
  path2.join(layout.root, "Package.swift"),
@@ -1290,13 +1537,18 @@ export {
1290
1537
  compileTargets,
1291
1538
  emitSwiftPackageManifest,
1292
1539
  lowerAnyObjectDoubleValue,
1540
+ missingSwiftModules,
1541
+ objcExtensionMemberIndex,
1293
1542
  prepareSwiftDependency,
1294
1543
  swiftArtifactHash,
1544
+ swiftAvailableModules,
1295
1545
  swiftDistributionAt,
1296
1546
  swiftIcuAsset,
1547
+ swiftImportNames,
1297
1548
  swiftModuleDigest,
1298
1549
  swiftModuleInputFiles,
1299
1550
  swiftModuleSdk,
1551
+ swiftPeachModules,
1300
1552
  swiftSourceAsIOS,
1301
1553
  swiftTargetDependencies,
1302
1554
  syncSwiftTree,