peachsim 0.1.730 → 0.1.746

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 (107) 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-sim-host.ts +2 -0
  15. package/cli/drivers/playwright.ts +3 -3
  16. package/cli/drivers/registry.ts +7 -2
  17. package/cli/drivers/types.ts +4 -3
  18. package/cli/maestro-js.ts +10 -0
  19. package/cli/outbound-endpoints.ts +2 -2
  20. package/dist-lib/agent-daemon-client.cjs +1 -1
  21. package/dist-lib/agent-events.cjs +1 -1
  22. package/dist-lib/agent-identity.cjs +1 -1
  23. package/dist-lib/agent-sessions.cjs +1 -1
  24. package/dist-lib/attached-projects.cjs +1 -1
  25. package/dist-lib/auth/shared-session.cjs +39 -9
  26. package/dist-lib/backend-origin.cjs +1 -1
  27. package/dist-lib/beta.cjs +1 -1
  28. package/dist-lib/beta.mjs +1 -1
  29. package/dist-lib/bridge-constants.cjs +1 -1
  30. package/dist-lib/bridge-contract-input.cjs +1 -1
  31. package/dist-lib/bridge-contract-input.mjs +1 -1
  32. package/dist-lib/bridge-contract.cjs +1 -1
  33. package/dist-lib/bridge-contract.mjs +1 -1
  34. package/dist-lib/capture-contract.cjs +13 -19
  35. package/dist-lib/capture-contract.mjs +13 -19
  36. package/dist-lib/cli-constants.cjs +1 -1
  37. package/dist-lib/cloud-contract.cjs +1 -1
  38. package/dist-lib/cloud-contract.mjs +1 -1
  39. package/dist-lib/cloud-test-args.cjs +1 -1
  40. package/dist-lib/cloud-test-args.mjs +1 -1
  41. package/dist-lib/cloud.cjs +1 -1
  42. package/dist-lib/cloud.mjs +1 -1
  43. package/dist-lib/config.cjs +1 -1
  44. package/dist-lib/detox/index.cjs +117 -11
  45. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  46. package/dist-lib/home-paths.cjs +32 -1
  47. package/dist-lib/host/bridge-host.cjs +1741 -540
  48. package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
  49. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  50. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  51. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  52. package/dist-lib/host/websocket-proxy.cjs +1 -1
  53. package/dist-lib/index.cjs +17 -22
  54. package/dist-lib/jump-to-source-babel.cjs +1 -1
  55. package/dist-lib/jump-to-source-native.cjs +1 -1
  56. package/dist-lib/kotlin-host.cjs +1 -1
  57. package/dist-lib/menu.cjs +1 -1
  58. package/dist-lib/menu.mjs +1 -1
  59. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  60. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  61. package/dist-lib/metro-production-bundle.cjs +1 -1
  62. package/dist-lib/metro-production-bundle.mjs +1 -1
  63. package/dist-lib/metro.cjs +1 -1
  64. package/dist-lib/native-app-identity.cjs +1 -1
  65. package/dist-lib/native-app-identity.mjs +1 -1
  66. package/dist-lib/native-firebase-metadata.cjs +1 -1
  67. package/dist-lib/native-firebase-metadata.mjs +1 -1
  68. package/dist-lib/plist.cjs +1 -1
  69. package/dist-lib/plist.mjs +1 -1
  70. package/dist-lib/profiles.cjs +1 -1
  71. package/dist-lib/public-brand.cjs +1 -1
  72. package/dist-lib/react-native-host-modules.cjs +1 -1
  73. package/dist-lib/react-native-host-modules.mjs +1 -1
  74. package/dist-lib/render-mode.cjs +1 -1
  75. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  76. package/dist-lib/sdk.cjs +2 -1
  77. package/dist-lib/sdk.mjs +2 -1
  78. package/dist-lib/skills.cjs +2431 -1075
  79. package/dist-lib/swift-compile.cjs +374 -65
  80. package/dist-lib/swift-compile.mjs +369 -66
  81. package/dist-lib/swift-package.cjs +146 -9
  82. package/dist-lib/swift-package.mjs +144 -9
  83. package/dist-lib/swift-submit.cjs +2 -2
  84. package/dist-lib/swift-submit.mjs +2 -2
  85. package/dist-lib/swift-toolchain.cjs +1 -1
  86. package/dist-lib/swift.cjs +1 -1
  87. package/dist-lib/vite-swift.cjs +1690 -233
  88. package/dist-lib/vite.cjs +4 -4
  89. package/package.json +1 -1
  90. package/skills/contrast/SKILL.md +1 -1
  91. package/src/auth/shared-session.ts +45 -9
  92. package/src/bridge-constants.ts +7 -7
  93. package/src/capture-contract.ts +18 -33
  94. package/src/desktop-host-delivery.ts +81 -0
  95. package/src/home-paths.ts +30 -0
  96. package/src/host/bridge-host.ts +11 -6
  97. package/src/native-seam-manifest.ts +0 -11
  98. package/src/sim-client.ts +1 -0
  99. package/src/swift-compile.ts +479 -76
  100. package/src/swift-distribution.lock.json +11 -11
  101. package/src/swift-host.ts +338 -45
  102. package/src/swift-package.ts +204 -19
  103. package/src/swift-remote-packages.ts +255 -0
  104. package/src/swift-submit.ts +4 -1
  105. package/src/vite-plugin-one.ts +2 -2
  106. package/src/vite-plugin.ts +29 -9
  107. package/src/xcode-project.ts +612 -0
@@ -1,7 +1,7 @@
1
- /*! rnx v0.1.730 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.746 | (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;
@@ -236,7 +259,10 @@ function swiftPackagePartition(manifest, resourcePaths = []) {
236
259
  var run2 = promisify2(execFile2);
237
260
  var WASM_TRIPLE = "wasm32-unknown-wasip1";
238
261
  var cores = os.availableParallelism();
239
- var BUILD_ENV = { ...process.env, BINARYEN_CORES: String(Math.min(4, cores)) };
262
+ var BUILD_ENV = {
263
+ ...process.env,
264
+ BINARYEN_CORES: String(Math.min(4, cores))
265
+ };
240
266
  var BUILD_JOBS = String(Math.max(1, Math.floor(cores / 2)));
241
267
  function swiftDistributionAt(root) {
242
268
  const file = path2.join(root, SWIFT_DISTRIBUTION_MANIFEST);
@@ -261,7 +287,9 @@ function swiftModuleInputFiles(root) {
261
287
  "toolchain.json"
262
288
  ];
263
289
  const walk = (dir) => {
264
- for (const entry of readdirSync(path2.join(root, dir), { withFileTypes: true })) {
290
+ for (const entry of readdirSync(path2.join(root, dir), {
291
+ withFileTypes: true
292
+ })) {
265
293
  const relative = `${dir}/${entry.name}`;
266
294
  if (entry.isDirectory()) walk(relative);
267
295
  else if (/\.(swift|c|cpp|h)$/.test(entry.name)) files.push(relative);
@@ -353,6 +381,9 @@ var OPTIONAL_FRAMEWORK_DEPENDENCIES = {
353
381
  CryptoKit: [],
354
382
  CommonCrypto: [],
355
383
  CoreText: [],
384
+ Compression: ["PeachCodec"],
385
+ zlib: ["PeachCodec"],
386
+ PeachCodec: [],
356
387
  Security: ["CryptoKit"],
357
388
  TikTokBusinessSDK: [],
358
389
  nSure: [],
@@ -363,6 +394,66 @@ var OPTIONAL_FRAMEWORK_DEPENDENCIES = {
363
394
  DatadogTrace: ["DatadogCore"]
364
395
  };
365
396
  var OPTIONAL_FRAMEWORKS = new Set(Object.keys(OPTIONAL_FRAMEWORK_DEPENDENCIES));
397
+ var SWIFT_IMPORT = /^\s*(?:@\w+(?:\([^)]*\))?\s+)*import\s+(?:(?:typealias|struct|class|enum|protocol|let|var|func)\s+)?([A-Za-z_][A-Za-z0-9_]*)/;
398
+ function swiftImportNames(contents, unconditional = false) {
399
+ const names = [];
400
+ let depth = 0;
401
+ for (const line of contents.split("\n")) {
402
+ const directive = /^\s*#(if|endif)\b/.exec(line)?.[1];
403
+ if (directive === "if") depth++;
404
+ else if (directive === "endif") depth = Math.max(0, depth - 1);
405
+ if (unconditional && depth > 0) continue;
406
+ const name = SWIFT_IMPORT.exec(line)?.[1];
407
+ if (name) names.push(name);
408
+ }
409
+ return names;
410
+ }
411
+ function swiftPeachModules(moduleRoot) {
412
+ const distribution = swiftDistributionAt(moduleRoot);
413
+ return distribution ? distribution.modules : [
414
+ ...readFileSync2(path2.join(moduleRoot, "Package.swift"), "utf8").matchAll(
415
+ /\.(?:target|systemLibrary)\(\s*name:\s*"([^"]+)"/g
416
+ )
417
+ ].map((match) => match[1]);
418
+ }
419
+ var availableModules = /* @__PURE__ */ new Map();
420
+ function swiftAvailableModules(moduleRoot, toolchainBin) {
421
+ const sdk = swiftModuleSdk(moduleRoot).wasmSdkId;
422
+ const key = `${moduleRoot}\0${sdk}`;
423
+ const cached = availableModules.get(key);
424
+ if (cached) return cached;
425
+ const modules = new Set(swiftPeachModules(moduleRoot));
426
+ const configuration = execFileSync(
427
+ path2.join(toolchainBin, "swift"),
428
+ ["sdk", "configure", "--show-configuration", sdk, "wasm32-unknown-wasip1"],
429
+ { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }
430
+ );
431
+ const resources = /^swiftResourcesPath:\s*(.+)$/m.exec(configuration)?.[1]?.trim();
432
+ if (!resources) throw new Error(`swift sdk ${sdk} reports no swiftResourcesPath`);
433
+ for (const entry of readdirSync(path2.join(resources, "wasi"))) {
434
+ if (entry.endsWith(".swiftmodule"))
435
+ modules.add(entry.slice(0, -".swiftmodule".length));
436
+ }
437
+ for (const entry of readdirSync(resources)) {
438
+ const map = path2.join(resources, entry, "module.modulemap");
439
+ if (!existsSync(map)) continue;
440
+ for (const match of readFileSync2(map, "utf8").matchAll(/^module\s+([A-Za-z_]\w*)/gm))
441
+ modules.add(match[1]);
442
+ }
443
+ availableModules.set(key, modules);
444
+ return modules;
445
+ }
446
+ function missingSwiftModules(files, available) {
447
+ const missing = /* @__PURE__ */ new Map();
448
+ for (const [file, contents] of Object.entries(files)) {
449
+ if (!file.endsWith(".swift") || file === "Package.swift") continue;
450
+ for (const name of new Set(swiftImportNames(contents, true))) {
451
+ if (available.has(name)) continue;
452
+ missing.set(name, [...missing.get(name) ?? [], file]);
453
+ }
454
+ }
455
+ return new Map([...missing].sort(([left], [right]) => left.localeCompare(right)));
456
+ }
366
457
  function swiftTargetDependencies(files, targets) {
367
458
  const names = /* @__PURE__ */ new Set([...OPTIONAL_FRAMEWORKS, ...targets.map((target) => target.name)]);
368
459
  const siblings = /* @__PURE__ */ new Map();
@@ -375,10 +466,8 @@ function swiftTargetDependencies(files, targets) {
375
466
  (candidate) => candidate.name !== target.name && candidate.path !== "." && candidate.path.startsWith(prefix) && file.startsWith(`${candidate.path}/`)
376
467
  ))
377
468
  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]);
469
+ for (const name of swiftImportNames(contents)) {
470
+ if (names.has(name) && name !== target.name) deps.add(name);
382
471
  }
383
472
  }
384
473
  siblings.set(target.name, [...deps].sort());
@@ -388,16 +477,14 @@ function swiftTargetDependencies(files, targets) {
388
477
  var ONE_PRODUCT = '.product(name: "One", package: "sootsim-swift")';
389
478
  var SPRITEKIT_PRODUCT = '.product(name: "SpriteKit", package: "sootsim-swift")';
390
479
  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
- )
480
+ ([file, contents]) => file.endsWith(".swift") && swiftImportNames(contents).includes("SpriteKit")
394
481
  );
395
- var FOUNDATION_IMPLICIT_FLAGS = ', "-Xfrontend", "-import-module", "-Xfrontend", "PeachObjC", "-Xfrontend", "-import-module", "-Xfrontend", "Dispatch", "-Xfrontend", "-import-module", "-Xfrontend", "FoundationNetworking"';
482
+ 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
483
  var ONE_IMPLICIT_FLAGS = ', "-Xfrontend", "-import-module", "-Xfrontend", "One"';
397
- var MULTI_MANIFEST_VERSION = 10;
484
+ var MULTI_MANIFEST_VERSION = 11;
398
485
  function swiftArtifactHash(input, release, moduleRoot) {
399
486
  const hash = createHash2("sha256");
400
- hash.update(`swift-compile/v14
487
+ hash.update(`swift-compile/v16
401
488
  ${release}
402
489
  `);
403
490
  if (input.oneModule) hash.update("one-module\n");
@@ -569,23 +656,98 @@ function forwardedArguments(parameters) {
569
656
  }
570
657
  return args.join(", ");
571
658
  }
572
- function liftExtensionOverrides(source) {
659
+ function closingBrace(source, tokens, open) {
660
+ let depth = 0;
661
+ for (const at of tokens) {
662
+ if (at < open) continue;
663
+ if (source[at] === "{") depth++;
664
+ else if (source[at] === "}" && --depth === 0) return at + 1;
665
+ }
666
+ return source.length;
667
+ }
668
+ function scanObjCExtensionMembers(source, tokens, records) {
669
+ const masked = swiftCodeMask(source);
670
+ const found = /* @__PURE__ */ new Map();
671
+ const member = /\b(func|var)\s+([A-Za-z_]\w*)/g;
672
+ for (const record of records) {
673
+ const close = closingBrace(source, tokens, record.open);
674
+ const body = masked.slice(record.open, close);
675
+ member.lastIndex = 0;
676
+ for (let match = member.exec(body); match; match = member.exec(body)) {
677
+ const at = record.open + match.index + match[0].indexOf(match[1]);
678
+ let depth = 0;
679
+ for (const token of tokens) {
680
+ if (token <= record.open) continue;
681
+ if (token >= at) break;
682
+ if (source[token] === "{") depth++;
683
+ else if (source[token] === "}") depth--;
684
+ }
685
+ if (depth > 0) continue;
686
+ const head = masked.slice(record.open, at);
687
+ const bound = Math.max(
688
+ head.lastIndexOf(";"),
689
+ head.lastIndexOf("{"),
690
+ head.lastIndexOf("}")
691
+ );
692
+ const prefix = head.slice(bound + 1);
693
+ if (/(?:^|[^A-Za-z0-9_$])(?:private|fileprivate|static|class)(?:[^A-Za-z0-9_$]|$)/.test(
694
+ prefix
695
+ ))
696
+ continue;
697
+ if (!/@objc\b/.test(prefix) && !/@IBAction\b/.test(prefix) && !record.objcMembers)
698
+ continue;
699
+ const members = found.get(record.type) ?? /* @__PURE__ */ new Set();
700
+ members.add(match[2]);
701
+ found.set(record.type, members);
702
+ }
703
+ }
704
+ return found;
705
+ }
706
+ function objcExtensionMemberIndex(sources) {
707
+ const index = /* @__PURE__ */ new Map();
708
+ for (const source of sources) {
709
+ const { tokens } = swiftCodeScan(source);
710
+ const masked = swiftCodeMask(source);
711
+ const records = [];
712
+ let pending = null;
713
+ for (const at of tokens) {
714
+ const rest = source.slice(at, at + 600);
715
+ if (rest.startsWith("{")) {
716
+ if (pending) records.push({ ...pending, open: at });
717
+ pending = null;
718
+ continue;
719
+ }
720
+ if (rest.startsWith("}")) continue;
721
+ const extended = EXTENSION_DECL.exec(rest);
722
+ if (extended) {
723
+ const lines = source.lastIndexOf("\n", source.lastIndexOf("\n", at - 1) - 1) + 1;
724
+ pending = {
725
+ type: extended[1].split(".").pop(),
726
+ objcMembers: /@objcMembers\b/.test(masked.slice(lines, at))
727
+ };
728
+ }
729
+ }
730
+ for (const [type, members] of scanObjCExtensionMembers(source, tokens, records)) {
731
+ const into = index.get(type) ?? /* @__PURE__ */ new Set();
732
+ for (const member of members) into.add(member);
733
+ index.set(type, into);
734
+ }
735
+ }
736
+ return index;
737
+ }
738
+ function liftExtensionOverrides(source, extraObjCExtensions) {
573
739
  const { tokens } = swiftCodeScan(source);
740
+ const masked = swiftCodeMask(source);
574
741
  const stack = [];
575
742
  let pending = null;
576
743
  const classes = /* @__PURE__ */ new Map();
577
744
  let declaredBase = null;
578
745
  let declaredObjCMembers = false;
746
+ const extensions = [];
747
+ let declaredExtObjCMembers = false;
579
748
  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
- };
749
+ const overrides = [];
750
+ const closing = (open) => closingBrace(source, tokens, open);
589
751
  for (const at of tokens) {
590
752
  const rest = source.slice(at, at + 600);
591
753
  if (rest.startsWith("{")) {
@@ -596,6 +758,12 @@ function liftExtensionOverrides(source) {
596
758
  base: declaredBase,
597
759
  objcMembers: declaredObjCMembers
598
760
  });
761
+ if (frame.kind === "extension")
762
+ extensions.push({
763
+ type: frame.name,
764
+ open: at,
765
+ objcMembers: declaredExtObjCMembers
766
+ });
599
767
  stack.push(frame);
600
768
  pending = null;
601
769
  continue;
@@ -615,12 +783,39 @@ function liftExtensionOverrides(source) {
615
783
  const extended = EXTENSION_DECL.exec(rest);
616
784
  if (extended) {
617
785
  pending = { kind: "extension", name: extended[1].split(".").pop() };
786
+ const lines = source.lastIndexOf("\n", source.lastIndexOf("\n", at - 1) - 1) + 1;
787
+ declaredExtObjCMembers = /@objcMembers\b/.test(masked.slice(lines, at));
618
788
  continue;
619
789
  }
620
790
  const top = stack.at(-1);
621
- if (!rest.startsWith("override") || top?.kind !== "extension" || pending) continue;
791
+ if (!rest.startsWith("override") || pending) continue;
622
792
  const line = source.slice(source.lastIndexOf("\n", at - 1) + 1, at);
623
793
  const modifiers = (` ${line} `.match(MODIFIERS) ?? []).map((word) => word.trim());
794
+ if (top?.kind === "class") {
795
+ let member;
796
+ let nameAt = 0;
797
+ const direct = OVERRIDE_FUNC.exec(rest);
798
+ if (direct) {
799
+ member = direct[2];
800
+ nameAt = at + rest.indexOf(
801
+ member,
802
+ rest.indexOf("func", "override".length + direct[1].length) + 4
803
+ );
804
+ } else {
805
+ const property2 = OVERRIDE_VAR.exec(rest);
806
+ if (property2) {
807
+ const open = at + property2[0].length - 1;
808
+ if (!/\b(?:set|willSet|didSet)\b/.test(source.slice(open, closing(open)))) {
809
+ member = property2[2];
810
+ nameAt = at + rest.indexOf(member, rest.indexOf("var"));
811
+ }
812
+ }
813
+ }
814
+ if (member !== void 0 && !modifiers.includes("private") && !modifiers.includes("fileprivate"))
815
+ overrides.push({ type: top.name, member, at, nameAt });
816
+ continue;
817
+ }
818
+ if (top?.kind !== "extension") continue;
624
819
  const func = OVERRIDE_FUNC.exec(rest);
625
820
  if (func) {
626
821
  const name = func[2];
@@ -638,20 +833,18 @@ function liftExtensionOverrides(source) {
638
833
  if (args === null) continue;
639
834
  const call = (clause.includes("->") ? "return " : "") + (/\b(?:throws|rethrows)\b/.test(clause) ? "try " : "") + (/\basync\b/.test(clause) ? "await " : "") + `__peach_ext_${name}(${args})`;
640
835
  const signature = `func ${name}${func[3] ?? ""}${source.slice(open, close + 1)}${clause ? ` ${clause}` : ""}`;
836
+ const nameAt = at + rest.indexOf(name, rest.indexOf("func", "override".length + func[1].length) + 4);
641
837
  lifted.push({
642
838
  type: top.name,
643
839
  member: name,
644
- stub: `${[...modifiers, "override"].join(" ")} ${signature} { ${call} };`,
840
+ at,
841
+ modifiers,
842
+ decl: signature,
843
+ forward: `{ ${call} };`,
844
+ nameAt,
645
845
  edits: [
646
846
  [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
- ]
847
+ [nameAt, 0, "__peach_ext_"]
655
848
  ]
656
849
  });
657
850
  continue;
@@ -661,40 +854,77 @@ function liftExtensionOverrides(source) {
661
854
  const open = at + property[0].length - 1;
662
855
  if (/\b(?:set|willSet|didSet)\b/.test(source.slice(open, closing(open)))) continue;
663
856
  const name = property[2];
857
+ const nameAt = at + rest.indexOf(name, rest.indexOf("var"));
664
858
  lifted.push({
665
859
  type: top.name,
666
860
  member: name,
667
- stub: `${[...modifiers, "override"].join(" ")} var ${name}: ${property[3].trim()} { __peach_ext_${name} };`,
861
+ at,
862
+ modifiers,
863
+ decl: `var ${name}: ${property[3].trim()}`,
864
+ forward: `{ __peach_ext_${name} };`,
865
+ nameAt,
668
866
  edits: [
669
867
  [at, "override".length, " ".repeat("override".length)],
670
- [at + rest.indexOf(name, rest.indexOf("var")), 0, "__peach_ext_"]
868
+ [nameAt, 0, "__peach_ext_"]
671
869
  ]
672
870
  });
673
871
  }
674
872
  }
675
- const overridesObjC = (type, member) => {
873
+ const extIndex = /* @__PURE__ */ new Map();
874
+ if (extraObjCExtensions)
875
+ for (const [type, members] of extraObjCExtensions)
876
+ extIndex.set(type, new Set(members));
877
+ for (const [type, members] of scanObjCExtensionMembers(source, tokens, extensions)) {
878
+ const into = extIndex.get(type) ?? /* @__PURE__ */ new Set();
879
+ for (const member of members) into.add(member);
880
+ extIndex.set(type, into);
881
+ }
882
+ const overrideKind = (type, member) => {
676
883
  let base = classes.get(type)?.base ?? null;
677
884
  while (base !== null) {
678
- if (APPLE_CLASS.test(base)) return true;
679
885
  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;
886
+ if (declaredClass) {
887
+ const body = source.slice(declaredClass.brace, closing(declaredClass.brace));
888
+ const found = new RegExp(`\\b(?:func|var)\\s+${member}\\b`).exec(body);
889
+ if (found) {
890
+ const line = body.slice(body.lastIndexOf("\n", found.index) + 1, found.index);
891
+ return declaredClass.objcMembers || /@objc\b/.test(line) ? "objc" : "plain";
892
+ }
893
+ if (extIndex.get(base)?.has(member)) return "ext";
894
+ base = declaredClass.base;
895
+ } else if (extIndex.get(base)?.has(member)) return "ext";
896
+ else if (APPLE_CLASS.test(base)) return "apple";
897
+ else return "unknown";
688
898
  }
689
- return false;
899
+ return "unknown";
690
900
  };
901
+ const rename = (at, nameAt) => [
902
+ [at, "override".length, " ".repeat("override".length)],
903
+ [nameAt, 0, "__peach_ovr_"]
904
+ ];
691
905
  const edits = [];
692
906
  const stubs = /* @__PURE__ */ new Map();
693
907
  for (const entry of lifted) {
694
908
  const brace = classes.get(entry.type)?.brace;
695
- if (brace === void 0 || !overridesObjC(entry.type, entry.member)) continue;
909
+ if (brace === void 0) continue;
910
+ const kind = overrideKind(entry.type, entry.member);
911
+ if (kind !== "apple" && kind !== "objc" && kind !== "ext") continue;
912
+ if (kind === "ext" && (entry.modifiers.includes("private") || entry.modifiers.includes("fileprivate")))
913
+ continue;
914
+ if (kind === "ext") {
915
+ edits.push(...rename(entry.at, entry.nameAt));
916
+ continue;
917
+ }
696
918
  edits.push(...entry.edits);
697
- stubs.set(brace, [...stubs.get(brace) ?? [], entry.stub]);
919
+ const head = [...entry.modifiers, "override"].filter((word) => word !== "").join(" ");
920
+ stubs.set(brace, [
921
+ ...stubs.get(brace) ?? [],
922
+ `${head} ${entry.decl} ${entry.forward}`
923
+ ]);
924
+ }
925
+ for (const candidate of overrides) {
926
+ if (overrideKind(candidate.type, candidate.member) !== "ext") continue;
927
+ edits.push(...rename(candidate.at, candidate.nameAt));
698
928
  }
699
929
  for (const [brace, list] of stubs) edits.push([brace + 1, 0, ` ${list.join(" ")}`]);
700
930
  let out = source;
@@ -876,8 +1106,8 @@ function swiftCodeMask(source) {
876
1106
  scanCode(0, false);
877
1107
  return chars.join("");
878
1108
  }
879
- function swiftSourceAsIOS(original) {
880
- const source = liftExtensionOverrides(original);
1109
+ function swiftSourceAsIOS(original, extraObjCExtensions) {
1110
+ const source = liftExtensionOverrides(original, extraObjCExtensions);
881
1111
  const { lineStarts, tokens } = swiftCodeScan(source);
882
1112
  let offset = 0;
883
1113
  const conditioned = source.split("\n").map((line) => {
@@ -892,9 +1122,14 @@ function swiftSourceAsIOS(original) {
892
1122
  const reusableBodies = [];
893
1123
  let depth = 0;
894
1124
  let opensReusableBody = false;
1125
+ const sceneLifecycleBodies = /* @__PURE__ */ new Set();
895
1126
  for (const at of tokens) {
896
1127
  const rest = conditioned.slice(at, at + 400);
897
1128
  if (rest.startsWith("{")) {
1129
+ if (sceneLifecycleBodies.has(at)) {
1130
+ out += conditioned.slice(copied, at + 1) + " public var _peachUsesSceneLifecycle: Bool { true };";
1131
+ copied = at + 1;
1132
+ }
898
1133
  depth++;
899
1134
  if (opensReusableBody) reusableBodies.push(depth);
900
1135
  opensReusableBody = false;
@@ -930,12 +1165,33 @@ function swiftSourceAsIOS(original) {
930
1165
  opensReusableBody = true;
931
1166
  }
932
1167
  const modifiers = conditioned.slice(conditioned.lastIndexOf("\n", at - 1) + 1, at);
1168
+ const delegateClass = DELEGATE_CLASS.exec(rest);
1169
+ if (delegateClass && /\bUIApplicationDelegate\b/.test(delegateClass[0])) {
1170
+ const body = at + delegateClass[0].lastIndexOf("{");
1171
+ let bodyDepth = 0;
1172
+ for (const token of tokens) {
1173
+ if (token < body) continue;
1174
+ if (conditioned[token] === "{") bodyDepth++;
1175
+ else if (conditioned[token] === "}" && --bodyDepth === 0) break;
1176
+ else if (bodyDepth === 1 && /^func\s+application\s*\([^{}]*\bconfigurationForConnecting\s+/.test(
1177
+ conditioned.slice(token, token + 600)
1178
+ )) {
1179
+ sceneLifecycleBodies.add(body);
1180
+ break;
1181
+ }
1182
+ }
1183
+ }
933
1184
  if (DELEGATE_CLASS.test(rest) && !/\b(?:final|open)\b/.test(modifiers)) {
934
1185
  out += `${conditioned.slice(copied, at)}final `;
935
1186
  copied = at;
936
1187
  }
937
1188
  continue;
938
1189
  }
1190
+ if (/^@UIApplicationMain\b/.test(rest)) {
1191
+ out += conditioned.slice(copied, at) + "@main".padEnd("@UIApplicationMain".length);
1192
+ copied = at + "@UIApplicationMain".length;
1193
+ continue;
1194
+ }
939
1195
  const selector = SELECTOR.exec(rest);
940
1196
  const match = selector ?? OBJC_ATTRIBUTE.exec(rest);
941
1197
  if (!match) continue;
@@ -952,6 +1208,19 @@ function swiftSourceAsIOS(original) {
952
1208
  }
953
1209
  return lowerAnyObjectDoubleValue(out + conditioned.slice(copied));
954
1210
  }
1211
+ function swiftApplicationEntry(file, source) {
1212
+ const { tokens } = swiftCodeScan(source);
1213
+ let depth = 0;
1214
+ for (const at of tokens) {
1215
+ if (source[at] === "{") depth++;
1216
+ else if (source[at] === "}") depth--;
1217
+ else if (depth === 0 && /^@(?:main|UIApplicationMain)\b/.test(source.slice(at)))
1218
+ return true;
1219
+ else if (depth === 0 && path2.basename(file) === "main.swift" && /^UIApplicationMain\s*\(/.test(source.slice(at)))
1220
+ return true;
1221
+ }
1222
+ return false;
1223
+ }
955
1224
  function swiftCodeScan(source) {
956
1225
  const starts = /* @__PURE__ */ new Set();
957
1226
  const tokens = [];
@@ -1034,7 +1303,7 @@ function swiftCodeScan(source) {
1034
1303
  else top.parens--;
1035
1304
  i++;
1036
1305
  } else {
1037
- const keyword = source.startsWith("class", i) ? "class" : source.startsWith("extension", i) ? "extension" : source.startsWith("override", i) ? "override" : source.startsWith("import", i) ? "import" : source.startsWith("NSClassFromString", i) ? "NSClassFromString" : null;
1306
+ const keyword = source.startsWith("class", i) ? "class" : source.startsWith("extension", i) ? "extension" : source.startsWith("override", i) ? "override" : source.startsWith("import", i) ? "import" : source.startsWith("func", i) ? "func" : source.startsWith("UIApplicationMain", i) ? "UIApplicationMain" : source.startsWith("NSClassFromString", i) ? "NSClassFromString" : null;
1038
1307
  if (keyword && !/[\w$]/.test(source[i - 1] ?? "") && !/[\w$]/.test(source[i + keyword.length] ?? "")) {
1039
1308
  tokens.push(i);
1040
1309
  i += keyword.length;
@@ -1046,9 +1315,22 @@ function swiftCodeScan(source) {
1046
1315
  }
1047
1316
  return { lineStarts: starts, tokens };
1048
1317
  }
1049
- var compiledSource = (file, contents) => file.endsWith(".swift") ? swiftSourceAsIOS(contents) : contents;
1318
+ var compiledSource = (file, contents, extraObjCExtensions) => file.endsWith(".swift") ? swiftSourceAsIOS(contents, extraObjCExtensions) : contents;
1050
1319
  function prepareSwiftDependency(source, destination) {
1051
1320
  rmSync(destination, { recursive: true, force: true });
1321
+ const origins = [];
1322
+ const gather = (from, root) => {
1323
+ for (const entry of readdirSync(from, { withFileTypes: true })) {
1324
+ if (entry.name === ".git" || entry.name === ".build" || entry.name === ".swiftpm")
1325
+ continue;
1326
+ const file = path2.join(from, entry.name);
1327
+ if (entry.isDirectory()) gather(file, false);
1328
+ else if (entry.isFile() && entry.name.endsWith(".swift") && !(root && /^Package(@swift-[\d.]+)?\.swift$/.test(entry.name)))
1329
+ origins.push(readFileSync2(file, "utf8"));
1330
+ }
1331
+ };
1332
+ gather(source, true);
1333
+ const objcExtensions = objcExtensionMemberIndex(origins);
1052
1334
  const copy = (from, to, root) => {
1053
1335
  mkdirSync(to, { recursive: true });
1054
1336
  for (const entry of readdirSync(from, { withFileTypes: true })) {
@@ -1058,7 +1340,10 @@ function prepareSwiftDependency(source, destination) {
1058
1340
  const target = path2.join(to, entry.name);
1059
1341
  if (entry.isDirectory()) copy(file, target, false);
1060
1342
  else if (entry.isFile() && entry.name.endsWith(".swift") && !(root && /^Package(@swift-[\d.]+)?\.swift$/.test(entry.name)))
1061
- writeFileSync(target, compiledSource(file, readFileSync2(file, "utf8")));
1343
+ writeFileSync(
1344
+ target,
1345
+ compiledSource(file, readFileSync2(file, "utf8"), objcExtensions)
1346
+ );
1062
1347
  else cpSync(file, target, { verbatimSymlinks: true });
1063
1348
  }
1064
1349
  };
@@ -1096,10 +1381,16 @@ function writeSwiftProject(layout, input, moduleRoot) {
1096
1381
  // sootsim-swift files ${modulePlan.digest("hex").slice(0, 16)}
1097
1382
  // resource accessors ${resourcePlan}
1098
1383
  `;
1384
+ const objcExtensions = objcExtensionMemberIndex(
1385
+ Object.entries(input.files).filter(([file]) => file.endsWith(".swift")).map(([, contents]) => contents)
1386
+ );
1099
1387
  if (targets.length === 0) {
1100
1388
  for (const [file, contents] of Object.entries(input.files)) {
1101
1389
  if (file === "Package.swift") continue;
1102
- files.set(path2.join(layout.sources, file), compiledSource(file, contents));
1390
+ files.set(
1391
+ path2.join(layout.sources, file),
1392
+ compiledSource(file, contents, objcExtensions)
1393
+ );
1103
1394
  }
1104
1395
  let manifest = readFileSync2(
1105
1396
  path2.join(moduleRoot, "scripts/contrast-app-Package.swift"),
@@ -1145,7 +1436,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
1145
1436
  const base = layout.multi ? layout.root : layout.sources;
1146
1437
  for (const [file, contents] of Object.entries(input.files)) {
1147
1438
  if (file === "Package.swift") continue;
1148
- files.set(path2.join(base, file), compiledSource(file, contents));
1439
+ files.set(path2.join(base, file), compiledSource(file, contents, objcExtensions));
1149
1440
  }
1150
1441
  files.set(
1151
1442
  path2.join(layout.root, "Package.swift"),
@@ -1271,10 +1562,16 @@ function compileSwiftProjectUnit(input, options) {
1271
1562
  plugin
1272
1563
  ])
1273
1564
  ],
1274
- { env: BUILD_ENV, maxBuffer: 64 * 1024 * 1024, timeout: options.timeoutMs }
1565
+ {
1566
+ env: BUILD_ENV,
1567
+ maxBuffer: 64 * 1024 * 1024,
1568
+ timeout: options.timeoutMs
1569
+ }
1275
1570
  );
1276
1571
  } catch (error) {
1277
- throw new Error(projectDiagnostic(outputOf(error), layout), { cause: error });
1572
+ throw new Error(projectDiagnostic(outputOf(error), layout), {
1573
+ cause: error
1574
+ });
1278
1575
  }
1279
1576
  return {
1280
1577
  hash,
@@ -1290,13 +1587,19 @@ export {
1290
1587
  compileTargets,
1291
1588
  emitSwiftPackageManifest,
1292
1589
  lowerAnyObjectDoubleValue,
1590
+ missingSwiftModules,
1591
+ objcExtensionMemberIndex,
1293
1592
  prepareSwiftDependency,
1593
+ swiftApplicationEntry,
1294
1594
  swiftArtifactHash,
1595
+ swiftAvailableModules,
1295
1596
  swiftDistributionAt,
1296
1597
  swiftIcuAsset,
1598
+ swiftImportNames,
1297
1599
  swiftModuleDigest,
1298
1600
  swiftModuleInputFiles,
1299
1601
  swiftModuleSdk,
1602
+ swiftPeachModules,
1300
1603
  swiftSourceAsIOS,
1301
1604
  swiftTargetDependencies,
1302
1605
  syncSwiftTree,