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,4 +1,4 @@
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
  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;
@@ -38,13 +38,19 @@ __export(swift_compile_exports, {
38
38
  compileTargets: () => compileTargets,
39
39
  emitSwiftPackageManifest: () => emitSwiftPackageManifest,
40
40
  lowerAnyObjectDoubleValue: () => lowerAnyObjectDoubleValue,
41
+ missingSwiftModules: () => missingSwiftModules,
42
+ objcExtensionMemberIndex: () => objcExtensionMemberIndex,
41
43
  prepareSwiftDependency: () => prepareSwiftDependency,
44
+ swiftApplicationEntry: () => swiftApplicationEntry,
42
45
  swiftArtifactHash: () => swiftArtifactHash,
46
+ swiftAvailableModules: () => swiftAvailableModules,
43
47
  swiftDistributionAt: () => swiftDistributionAt,
44
48
  swiftIcuAsset: () => swiftIcuAsset,
49
+ swiftImportNames: () => swiftImportNames,
45
50
  swiftModuleDigest: () => swiftModuleDigest,
46
51
  swiftModuleInputFiles: () => swiftModuleInputFiles,
47
52
  swiftModuleSdk: () => swiftModuleSdk,
53
+ swiftPeachModules: () => swiftPeachModules,
48
54
  swiftSourceAsIOS: () => swiftSourceAsIOS,
49
55
  swiftTargetDependencies: () => swiftTargetDependencies,
50
56
  syncSwiftTree: () => syncSwiftTree,
@@ -200,14 +206,24 @@ function swiftImplicitResourcePaths(paths) {
200
206
  ) || /(?:^|\/)[^/]+\.lproj\/[^/]+$/.test(file))
201
207
  ).sort();
202
208
  }
203
- function swiftManifestTargets(manifest, resourcePaths = []) {
204
- const implicitResources = swiftImplicitResourcePaths(resourcePaths);
205
- const code = manifest.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/[^\n]*/g, "");
206
- const targets = [];
207
- const pattern = /\.(executableTarget|target)\s*\(/g;
209
+ var MANIFEST_DECLARATIONS = [
210
+ "executableTarget",
211
+ "testTarget",
212
+ "binaryTarget",
213
+ "systemLibrary",
214
+ "macro",
215
+ "plugin",
216
+ "target",
217
+ "library",
218
+ "executable",
219
+ "package"
220
+ ];
221
+ function manifestCalls(manifest, kinds) {
222
+ const code = manifest.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[^:"])\/\/[^\n]*/g, "$1");
223
+ const calls = [];
224
+ const pattern = new RegExp(`\\.(${MANIFEST_DECLARATIONS.join("|")})\\s*\\(`, "g");
208
225
  let match;
209
226
  while ((match = pattern.exec(code)) !== null) {
210
- const executable = match[1] === "executableTarget";
211
227
  let depth = 1;
212
228
  const start = pattern.lastIndex;
213
229
  let i = start;
@@ -235,18 +251,31 @@ function swiftManifestTargets(manifest, resourcePaths = []) {
235
251
  }
236
252
  i++;
237
253
  }
254
+ if (kinds.includes(match[1]))
255
+ calls.push({ kind: match[1], flat, call: code.slice(start, i) });
256
+ pattern.lastIndex = i;
257
+ }
258
+ return calls;
259
+ }
260
+ function swiftManifestTargets(manifest, resourcePaths = []) {
261
+ const implicitResources = swiftImplicitResourcePaths(resourcePaths);
262
+ const targets = [];
263
+ for (const { kind, flat, call } of manifestCalls(manifest, [
264
+ "executableTarget",
265
+ "target"
266
+ ])) {
267
+ const executable = kind === "executableTarget";
238
268
  const name = /\bname\s*:\s*"([^"]+)"/.exec(flat)?.[1];
239
269
  if (!name) continue;
240
270
  const rawPath = /\bpath\s*:\s*"([^"]*)"/.exec(flat)?.[1];
241
271
  const targetPath = rawPath == null || rawPath === "" ? `Sources/${name}` : rawPath.replace(/^\.\//, "").replace(/\/+$/, "");
242
- const call = code.slice(start, i);
243
272
  const languageMode = Number(
244
273
  /\.swiftLanguageMode\(\s*\.v(\d+)\s*\)/.exec(call)?.[1] ?? "5"
245
274
  );
246
275
  const mainActorIsolation = /\.defaultIsolation\(\s*MainActor\.self\s*\)/.test(call);
247
276
  const excluded = [
248
277
  ...(/\bexclude\s*:\s*\[([^\]]*)\]/.exec(flat)?.[1] ?? "").matchAll(/"([^"]+)"/g)
249
- ].map((match2) => match2[1].replace(/^\.\//, "").replace(/\/+$/, ""));
278
+ ].map((match) => match[1].replace(/^\.\//, "").replace(/\/+$/, ""));
250
279
  const prefix = targetPath === "." ? "" : `${targetPath}/`;
251
280
  const resources = /\bresources\s*:/.test(flat) || implicitResources.some((file) => {
252
281
  if (!file.startsWith(prefix)) return false;
@@ -277,7 +306,10 @@ function swiftPackagePartition(manifest, resourcePaths = []) {
277
306
  var run2 = (0, import_node_util2.promisify)(import_node_child_process2.execFile);
278
307
  var WASM_TRIPLE = "wasm32-unknown-wasip1";
279
308
  var cores = import_node_os.default.availableParallelism();
280
- var BUILD_ENV = { ...process.env, BINARYEN_CORES: String(Math.min(4, cores)) };
309
+ var BUILD_ENV = {
310
+ ...process.env,
311
+ BINARYEN_CORES: String(Math.min(4, cores))
312
+ };
281
313
  var BUILD_JOBS = String(Math.max(1, Math.floor(cores / 2)));
282
314
  function swiftDistributionAt(root) {
283
315
  const file = import_node_path2.default.join(root, SWIFT_DISTRIBUTION_MANIFEST);
@@ -302,7 +334,9 @@ function swiftModuleInputFiles(root) {
302
334
  "toolchain.json"
303
335
  ];
304
336
  const walk = (dir) => {
305
- for (const entry of (0, import_node_fs2.readdirSync)(import_node_path2.default.join(root, dir), { withFileTypes: true })) {
337
+ for (const entry of (0, import_node_fs2.readdirSync)(import_node_path2.default.join(root, dir), {
338
+ withFileTypes: true
339
+ })) {
306
340
  const relative = `${dir}/${entry.name}`;
307
341
  if (entry.isDirectory()) walk(relative);
308
342
  else if (/\.(swift|c|cpp|h)$/.test(entry.name)) files.push(relative);
@@ -394,6 +428,9 @@ var OPTIONAL_FRAMEWORK_DEPENDENCIES = {
394
428
  CryptoKit: [],
395
429
  CommonCrypto: [],
396
430
  CoreText: [],
431
+ Compression: ["PeachCodec"],
432
+ zlib: ["PeachCodec"],
433
+ PeachCodec: [],
397
434
  Security: ["CryptoKit"],
398
435
  TikTokBusinessSDK: [],
399
436
  nSure: [],
@@ -404,6 +441,66 @@ var OPTIONAL_FRAMEWORK_DEPENDENCIES = {
404
441
  DatadogTrace: ["DatadogCore"]
405
442
  };
406
443
  var OPTIONAL_FRAMEWORKS = new Set(Object.keys(OPTIONAL_FRAMEWORK_DEPENDENCIES));
444
+ var SWIFT_IMPORT = /^\s*(?:@\w+(?:\([^)]*\))?\s+)*import\s+(?:(?:typealias|struct|class|enum|protocol|let|var|func)\s+)?([A-Za-z_][A-Za-z0-9_]*)/;
445
+ function swiftImportNames(contents, unconditional = false) {
446
+ const names = [];
447
+ let depth = 0;
448
+ for (const line of contents.split("\n")) {
449
+ const directive = /^\s*#(if|endif)\b/.exec(line)?.[1];
450
+ if (directive === "if") depth++;
451
+ else if (directive === "endif") depth = Math.max(0, depth - 1);
452
+ if (unconditional && depth > 0) continue;
453
+ const name = SWIFT_IMPORT.exec(line)?.[1];
454
+ if (name) names.push(name);
455
+ }
456
+ return names;
457
+ }
458
+ function swiftPeachModules(moduleRoot) {
459
+ const distribution = swiftDistributionAt(moduleRoot);
460
+ return distribution ? distribution.modules : [
461
+ ...(0, import_node_fs2.readFileSync)(import_node_path2.default.join(moduleRoot, "Package.swift"), "utf8").matchAll(
462
+ /\.(?:target|systemLibrary)\(\s*name:\s*"([^"]+)"/g
463
+ )
464
+ ].map((match) => match[1]);
465
+ }
466
+ var availableModules = /* @__PURE__ */ new Map();
467
+ function swiftAvailableModules(moduleRoot, toolchainBin) {
468
+ const sdk = swiftModuleSdk(moduleRoot).wasmSdkId;
469
+ const key = `${moduleRoot}\0${sdk}`;
470
+ const cached = availableModules.get(key);
471
+ if (cached) return cached;
472
+ const modules = new Set(swiftPeachModules(moduleRoot));
473
+ const configuration = (0, import_node_child_process2.execFileSync)(
474
+ import_node_path2.default.join(toolchainBin, "swift"),
475
+ ["sdk", "configure", "--show-configuration", sdk, "wasm32-unknown-wasip1"],
476
+ { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }
477
+ );
478
+ const resources = /^swiftResourcesPath:\s*(.+)$/m.exec(configuration)?.[1]?.trim();
479
+ if (!resources) throw new Error(`swift sdk ${sdk} reports no swiftResourcesPath`);
480
+ for (const entry of (0, import_node_fs2.readdirSync)(import_node_path2.default.join(resources, "wasi"))) {
481
+ if (entry.endsWith(".swiftmodule"))
482
+ modules.add(entry.slice(0, -".swiftmodule".length));
483
+ }
484
+ for (const entry of (0, import_node_fs2.readdirSync)(resources)) {
485
+ const map = import_node_path2.default.join(resources, entry, "module.modulemap");
486
+ if (!(0, import_node_fs2.existsSync)(map)) continue;
487
+ for (const match of (0, import_node_fs2.readFileSync)(map, "utf8").matchAll(/^module\s+([A-Za-z_]\w*)/gm))
488
+ modules.add(match[1]);
489
+ }
490
+ availableModules.set(key, modules);
491
+ return modules;
492
+ }
493
+ function missingSwiftModules(files, available) {
494
+ const missing = /* @__PURE__ */ new Map();
495
+ for (const [file, contents] of Object.entries(files)) {
496
+ if (!file.endsWith(".swift") || file === "Package.swift") continue;
497
+ for (const name of new Set(swiftImportNames(contents, true))) {
498
+ if (available.has(name)) continue;
499
+ missing.set(name, [...missing.get(name) ?? [], file]);
500
+ }
501
+ }
502
+ return new Map([...missing].sort(([left], [right]) => left.localeCompare(right)));
503
+ }
407
504
  function swiftTargetDependencies(files, targets) {
408
505
  const names = /* @__PURE__ */ new Set([...OPTIONAL_FRAMEWORKS, ...targets.map((target) => target.name)]);
409
506
  const siblings = /* @__PURE__ */ new Map();
@@ -416,10 +513,8 @@ function swiftTargetDependencies(files, targets) {
416
513
  (candidate) => candidate.name !== target.name && candidate.path !== "." && candidate.path.startsWith(prefix) && file.startsWith(`${candidate.path}/`)
417
514
  ))
418
515
  continue;
419
- for (const match of contents.matchAll(
420
- /^\s*(?:@\w+(?:\([^)]*\))?\s+)*import\s+(?:(?:typealias|struct|class|enum|protocol|let|var|func)\s+)?([A-Za-z_][A-Za-z0-9_]*)/gm
421
- )) {
422
- if (names.has(match[1]) && match[1] !== target.name) deps.add(match[1]);
516
+ for (const name of swiftImportNames(contents)) {
517
+ if (names.has(name) && name !== target.name) deps.add(name);
423
518
  }
424
519
  }
425
520
  siblings.set(target.name, [...deps].sort());
@@ -429,16 +524,14 @@ function swiftTargetDependencies(files, targets) {
429
524
  var ONE_PRODUCT = '.product(name: "One", package: "sootsim-swift")';
430
525
  var SPRITEKIT_PRODUCT = '.product(name: "SpriteKit", package: "sootsim-swift")';
431
526
  var importsSpriteKit = (files) => Object.entries(files).some(
432
- ([file, contents]) => file.endsWith(".swift") && /^\s*(?:@\w+(?:\([^)]*\))?\s+)*import\s+(?:(?:typealias|struct|class|enum|protocol|let|var|func)\s+)?SpriteKit\b/m.test(
433
- contents
434
- )
527
+ ([file, contents]) => file.endsWith(".swift") && swiftImportNames(contents).includes("SpriteKit")
435
528
  );
436
- var FOUNDATION_IMPLICIT_FLAGS = ', "-Xfrontend", "-import-module", "-Xfrontend", "PeachObjC", "-Xfrontend", "-import-module", "-Xfrontend", "Dispatch", "-Xfrontend", "-import-module", "-Xfrontend", "FoundationNetworking"';
529
+ 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"';
437
530
  var ONE_IMPLICIT_FLAGS = ', "-Xfrontend", "-import-module", "-Xfrontend", "One"';
438
- var MULTI_MANIFEST_VERSION = 10;
531
+ var MULTI_MANIFEST_VERSION = 11;
439
532
  function swiftArtifactHash(input, release, moduleRoot) {
440
533
  const hash = (0, import_node_crypto2.createHash)("sha256");
441
- hash.update(`swift-compile/v14
534
+ hash.update(`swift-compile/v16
442
535
  ${release}
443
536
  `);
444
537
  if (input.oneModule) hash.update("one-module\n");
@@ -610,23 +703,98 @@ function forwardedArguments(parameters) {
610
703
  }
611
704
  return args.join(", ");
612
705
  }
613
- function liftExtensionOverrides(source) {
706
+ function closingBrace(source, tokens, open) {
707
+ let depth = 0;
708
+ for (const at of tokens) {
709
+ if (at < open) continue;
710
+ if (source[at] === "{") depth++;
711
+ else if (source[at] === "}" && --depth === 0) return at + 1;
712
+ }
713
+ return source.length;
714
+ }
715
+ function scanObjCExtensionMembers(source, tokens, records) {
716
+ const masked = swiftCodeMask(source);
717
+ const found = /* @__PURE__ */ new Map();
718
+ const member = /\b(func|var)\s+([A-Za-z_]\w*)/g;
719
+ for (const record of records) {
720
+ const close = closingBrace(source, tokens, record.open);
721
+ const body = masked.slice(record.open, close);
722
+ member.lastIndex = 0;
723
+ for (let match = member.exec(body); match; match = member.exec(body)) {
724
+ const at = record.open + match.index + match[0].indexOf(match[1]);
725
+ let depth = 0;
726
+ for (const token of tokens) {
727
+ if (token <= record.open) continue;
728
+ if (token >= at) break;
729
+ if (source[token] === "{") depth++;
730
+ else if (source[token] === "}") depth--;
731
+ }
732
+ if (depth > 0) continue;
733
+ const head = masked.slice(record.open, at);
734
+ const bound = Math.max(
735
+ head.lastIndexOf(";"),
736
+ head.lastIndexOf("{"),
737
+ head.lastIndexOf("}")
738
+ );
739
+ const prefix = head.slice(bound + 1);
740
+ if (/(?:^|[^A-Za-z0-9_$])(?:private|fileprivate|static|class)(?:[^A-Za-z0-9_$]|$)/.test(
741
+ prefix
742
+ ))
743
+ continue;
744
+ if (!/@objc\b/.test(prefix) && !/@IBAction\b/.test(prefix) && !record.objcMembers)
745
+ continue;
746
+ const members = found.get(record.type) ?? /* @__PURE__ */ new Set();
747
+ members.add(match[2]);
748
+ found.set(record.type, members);
749
+ }
750
+ }
751
+ return found;
752
+ }
753
+ function objcExtensionMemberIndex(sources) {
754
+ const index = /* @__PURE__ */ new Map();
755
+ for (const source of sources) {
756
+ const { tokens } = swiftCodeScan(source);
757
+ const masked = swiftCodeMask(source);
758
+ const records = [];
759
+ let pending = null;
760
+ for (const at of tokens) {
761
+ const rest = source.slice(at, at + 600);
762
+ if (rest.startsWith("{")) {
763
+ if (pending) records.push({ ...pending, open: at });
764
+ pending = null;
765
+ continue;
766
+ }
767
+ if (rest.startsWith("}")) continue;
768
+ const extended = EXTENSION_DECL.exec(rest);
769
+ if (extended) {
770
+ const lines = source.lastIndexOf("\n", source.lastIndexOf("\n", at - 1) - 1) + 1;
771
+ pending = {
772
+ type: extended[1].split(".").pop(),
773
+ objcMembers: /@objcMembers\b/.test(masked.slice(lines, at))
774
+ };
775
+ }
776
+ }
777
+ for (const [type, members] of scanObjCExtensionMembers(source, tokens, records)) {
778
+ const into = index.get(type) ?? /* @__PURE__ */ new Set();
779
+ for (const member of members) into.add(member);
780
+ index.set(type, into);
781
+ }
782
+ }
783
+ return index;
784
+ }
785
+ function liftExtensionOverrides(source, extraObjCExtensions) {
614
786
  const { tokens } = swiftCodeScan(source);
787
+ const masked = swiftCodeMask(source);
615
788
  const stack = [];
616
789
  let pending = null;
617
790
  const classes = /* @__PURE__ */ new Map();
618
791
  let declaredBase = null;
619
792
  let declaredObjCMembers = false;
793
+ const extensions = [];
794
+ let declaredExtObjCMembers = false;
620
795
  const lifted = [];
621
- const closing = (open) => {
622
- let depth = 0;
623
- for (const at of tokens) {
624
- if (at < open) continue;
625
- if (source[at] === "{") depth++;
626
- else if (source[at] === "}" && --depth === 0) return at + 1;
627
- }
628
- return source.length;
629
- };
796
+ const overrides = [];
797
+ const closing = (open) => closingBrace(source, tokens, open);
630
798
  for (const at of tokens) {
631
799
  const rest = source.slice(at, at + 600);
632
800
  if (rest.startsWith("{")) {
@@ -637,6 +805,12 @@ function liftExtensionOverrides(source) {
637
805
  base: declaredBase,
638
806
  objcMembers: declaredObjCMembers
639
807
  });
808
+ if (frame.kind === "extension")
809
+ extensions.push({
810
+ type: frame.name,
811
+ open: at,
812
+ objcMembers: declaredExtObjCMembers
813
+ });
640
814
  stack.push(frame);
641
815
  pending = null;
642
816
  continue;
@@ -656,12 +830,39 @@ function liftExtensionOverrides(source) {
656
830
  const extended = EXTENSION_DECL.exec(rest);
657
831
  if (extended) {
658
832
  pending = { kind: "extension", name: extended[1].split(".").pop() };
833
+ const lines = source.lastIndexOf("\n", source.lastIndexOf("\n", at - 1) - 1) + 1;
834
+ declaredExtObjCMembers = /@objcMembers\b/.test(masked.slice(lines, at));
659
835
  continue;
660
836
  }
661
837
  const top = stack.at(-1);
662
- if (!rest.startsWith("override") || top?.kind !== "extension" || pending) continue;
838
+ if (!rest.startsWith("override") || pending) continue;
663
839
  const line = source.slice(source.lastIndexOf("\n", at - 1) + 1, at);
664
840
  const modifiers = (` ${line} `.match(MODIFIERS) ?? []).map((word) => word.trim());
841
+ if (top?.kind === "class") {
842
+ let member;
843
+ let nameAt = 0;
844
+ const direct = OVERRIDE_FUNC.exec(rest);
845
+ if (direct) {
846
+ member = direct[2];
847
+ nameAt = at + rest.indexOf(
848
+ member,
849
+ rest.indexOf("func", "override".length + direct[1].length) + 4
850
+ );
851
+ } else {
852
+ const property2 = OVERRIDE_VAR.exec(rest);
853
+ if (property2) {
854
+ const open = at + property2[0].length - 1;
855
+ if (!/\b(?:set|willSet|didSet)\b/.test(source.slice(open, closing(open)))) {
856
+ member = property2[2];
857
+ nameAt = at + rest.indexOf(member, rest.indexOf("var"));
858
+ }
859
+ }
860
+ }
861
+ if (member !== void 0 && !modifiers.includes("private") && !modifiers.includes("fileprivate"))
862
+ overrides.push({ type: top.name, member, at, nameAt });
863
+ continue;
864
+ }
865
+ if (top?.kind !== "extension") continue;
665
866
  const func = OVERRIDE_FUNC.exec(rest);
666
867
  if (func) {
667
868
  const name = func[2];
@@ -679,20 +880,18 @@ function liftExtensionOverrides(source) {
679
880
  if (args === null) continue;
680
881
  const call = (clause.includes("->") ? "return " : "") + (/\b(?:throws|rethrows)\b/.test(clause) ? "try " : "") + (/\basync\b/.test(clause) ? "await " : "") + `__peach_ext_${name}(${args})`;
681
882
  const signature = `func ${name}${func[3] ?? ""}${source.slice(open, close + 1)}${clause ? ` ${clause}` : ""}`;
883
+ const nameAt = at + rest.indexOf(name, rest.indexOf("func", "override".length + func[1].length) + 4);
682
884
  lifted.push({
683
885
  type: top.name,
684
886
  member: name,
685
- stub: `${[...modifiers, "override"].join(" ")} ${signature} { ${call} };`,
887
+ at,
888
+ modifiers,
889
+ decl: signature,
890
+ forward: `{ ${call} };`,
891
+ nameAt,
686
892
  edits: [
687
893
  [at, "override".length, " ".repeat("override".length)],
688
- [
689
- at + rest.indexOf(
690
- name,
691
- rest.indexOf("func", "override".length + func[1].length) + 4
692
- ),
693
- 0,
694
- "__peach_ext_"
695
- ]
894
+ [nameAt, 0, "__peach_ext_"]
696
895
  ]
697
896
  });
698
897
  continue;
@@ -702,40 +901,77 @@ function liftExtensionOverrides(source) {
702
901
  const open = at + property[0].length - 1;
703
902
  if (/\b(?:set|willSet|didSet)\b/.test(source.slice(open, closing(open)))) continue;
704
903
  const name = property[2];
904
+ const nameAt = at + rest.indexOf(name, rest.indexOf("var"));
705
905
  lifted.push({
706
906
  type: top.name,
707
907
  member: name,
708
- stub: `${[...modifiers, "override"].join(" ")} var ${name}: ${property[3].trim()} { __peach_ext_${name} };`,
908
+ at,
909
+ modifiers,
910
+ decl: `var ${name}: ${property[3].trim()}`,
911
+ forward: `{ __peach_ext_${name} };`,
912
+ nameAt,
709
913
  edits: [
710
914
  [at, "override".length, " ".repeat("override".length)],
711
- [at + rest.indexOf(name, rest.indexOf("var")), 0, "__peach_ext_"]
915
+ [nameAt, 0, "__peach_ext_"]
712
916
  ]
713
917
  });
714
918
  }
715
919
  }
716
- const overridesObjC = (type, member) => {
920
+ const extIndex = /* @__PURE__ */ new Map();
921
+ if (extraObjCExtensions)
922
+ for (const [type, members] of extraObjCExtensions)
923
+ extIndex.set(type, new Set(members));
924
+ for (const [type, members] of scanObjCExtensionMembers(source, tokens, extensions)) {
925
+ const into = extIndex.get(type) ?? /* @__PURE__ */ new Set();
926
+ for (const member of members) into.add(member);
927
+ extIndex.set(type, into);
928
+ }
929
+ const overrideKind = (type, member) => {
717
930
  let base = classes.get(type)?.base ?? null;
718
931
  while (base !== null) {
719
- if (APPLE_CLASS.test(base)) return true;
720
932
  const declaredClass = classes.get(base);
721
- if (!declaredClass) return false;
722
- const body = source.slice(declaredClass.brace, closing(declaredClass.brace));
723
- const found = new RegExp(`\\b(?:func|var)\\s+${member}\\b`).exec(body);
724
- if (found) {
725
- const line = body.slice(body.lastIndexOf("\n", found.index) + 1, found.index);
726
- return declaredClass.objcMembers || /@objc\b/.test(line);
727
- }
728
- base = declaredClass.base;
933
+ if (declaredClass) {
934
+ const body = source.slice(declaredClass.brace, closing(declaredClass.brace));
935
+ const found = new RegExp(`\\b(?:func|var)\\s+${member}\\b`).exec(body);
936
+ if (found) {
937
+ const line = body.slice(body.lastIndexOf("\n", found.index) + 1, found.index);
938
+ return declaredClass.objcMembers || /@objc\b/.test(line) ? "objc" : "plain";
939
+ }
940
+ if (extIndex.get(base)?.has(member)) return "ext";
941
+ base = declaredClass.base;
942
+ } else if (extIndex.get(base)?.has(member)) return "ext";
943
+ else if (APPLE_CLASS.test(base)) return "apple";
944
+ else return "unknown";
729
945
  }
730
- return false;
946
+ return "unknown";
731
947
  };
948
+ const rename = (at, nameAt) => [
949
+ [at, "override".length, " ".repeat("override".length)],
950
+ [nameAt, 0, "__peach_ovr_"]
951
+ ];
732
952
  const edits = [];
733
953
  const stubs = /* @__PURE__ */ new Map();
734
954
  for (const entry of lifted) {
735
955
  const brace = classes.get(entry.type)?.brace;
736
- if (brace === void 0 || !overridesObjC(entry.type, entry.member)) continue;
956
+ if (brace === void 0) continue;
957
+ const kind = overrideKind(entry.type, entry.member);
958
+ if (kind !== "apple" && kind !== "objc" && kind !== "ext") continue;
959
+ if (kind === "ext" && (entry.modifiers.includes("private") || entry.modifiers.includes("fileprivate")))
960
+ continue;
961
+ if (kind === "ext") {
962
+ edits.push(...rename(entry.at, entry.nameAt));
963
+ continue;
964
+ }
737
965
  edits.push(...entry.edits);
738
- stubs.set(brace, [...stubs.get(brace) ?? [], entry.stub]);
966
+ const head = [...entry.modifiers, "override"].filter((word) => word !== "").join(" ");
967
+ stubs.set(brace, [
968
+ ...stubs.get(brace) ?? [],
969
+ `${head} ${entry.decl} ${entry.forward}`
970
+ ]);
971
+ }
972
+ for (const candidate of overrides) {
973
+ if (overrideKind(candidate.type, candidate.member) !== "ext") continue;
974
+ edits.push(...rename(candidate.at, candidate.nameAt));
739
975
  }
740
976
  for (const [brace, list] of stubs) edits.push([brace + 1, 0, ` ${list.join(" ")}`]);
741
977
  let out = source;
@@ -917,8 +1153,8 @@ function swiftCodeMask(source) {
917
1153
  scanCode(0, false);
918
1154
  return chars.join("");
919
1155
  }
920
- function swiftSourceAsIOS(original) {
921
- const source = liftExtensionOverrides(original);
1156
+ function swiftSourceAsIOS(original, extraObjCExtensions) {
1157
+ const source = liftExtensionOverrides(original, extraObjCExtensions);
922
1158
  const { lineStarts, tokens } = swiftCodeScan(source);
923
1159
  let offset = 0;
924
1160
  const conditioned = source.split("\n").map((line) => {
@@ -933,9 +1169,14 @@ function swiftSourceAsIOS(original) {
933
1169
  const reusableBodies = [];
934
1170
  let depth = 0;
935
1171
  let opensReusableBody = false;
1172
+ const sceneLifecycleBodies = /* @__PURE__ */ new Set();
936
1173
  for (const at of tokens) {
937
1174
  const rest = conditioned.slice(at, at + 400);
938
1175
  if (rest.startsWith("{")) {
1176
+ if (sceneLifecycleBodies.has(at)) {
1177
+ out += conditioned.slice(copied, at + 1) + " public var _peachUsesSceneLifecycle: Bool { true };";
1178
+ copied = at + 1;
1179
+ }
939
1180
  depth++;
940
1181
  if (opensReusableBody) reusableBodies.push(depth);
941
1182
  opensReusableBody = false;
@@ -971,12 +1212,33 @@ function swiftSourceAsIOS(original) {
971
1212
  opensReusableBody = true;
972
1213
  }
973
1214
  const modifiers = conditioned.slice(conditioned.lastIndexOf("\n", at - 1) + 1, at);
1215
+ const delegateClass = DELEGATE_CLASS.exec(rest);
1216
+ if (delegateClass && /\bUIApplicationDelegate\b/.test(delegateClass[0])) {
1217
+ const body = at + delegateClass[0].lastIndexOf("{");
1218
+ let bodyDepth = 0;
1219
+ for (const token of tokens) {
1220
+ if (token < body) continue;
1221
+ if (conditioned[token] === "{") bodyDepth++;
1222
+ else if (conditioned[token] === "}" && --bodyDepth === 0) break;
1223
+ else if (bodyDepth === 1 && /^func\s+application\s*\([^{}]*\bconfigurationForConnecting\s+/.test(
1224
+ conditioned.slice(token, token + 600)
1225
+ )) {
1226
+ sceneLifecycleBodies.add(body);
1227
+ break;
1228
+ }
1229
+ }
1230
+ }
974
1231
  if (DELEGATE_CLASS.test(rest) && !/\b(?:final|open)\b/.test(modifiers)) {
975
1232
  out += `${conditioned.slice(copied, at)}final `;
976
1233
  copied = at;
977
1234
  }
978
1235
  continue;
979
1236
  }
1237
+ if (/^@UIApplicationMain\b/.test(rest)) {
1238
+ out += conditioned.slice(copied, at) + "@main".padEnd("@UIApplicationMain".length);
1239
+ copied = at + "@UIApplicationMain".length;
1240
+ continue;
1241
+ }
980
1242
  const selector = SELECTOR.exec(rest);
981
1243
  const match = selector ?? OBJC_ATTRIBUTE.exec(rest);
982
1244
  if (!match) continue;
@@ -993,6 +1255,19 @@ function swiftSourceAsIOS(original) {
993
1255
  }
994
1256
  return lowerAnyObjectDoubleValue(out + conditioned.slice(copied));
995
1257
  }
1258
+ function swiftApplicationEntry(file, source) {
1259
+ const { tokens } = swiftCodeScan(source);
1260
+ let depth = 0;
1261
+ for (const at of tokens) {
1262
+ if (source[at] === "{") depth++;
1263
+ else if (source[at] === "}") depth--;
1264
+ else if (depth === 0 && /^@(?:main|UIApplicationMain)\b/.test(source.slice(at)))
1265
+ return true;
1266
+ else if (depth === 0 && import_node_path2.default.basename(file) === "main.swift" && /^UIApplicationMain\s*\(/.test(source.slice(at)))
1267
+ return true;
1268
+ }
1269
+ return false;
1270
+ }
996
1271
  function swiftCodeScan(source) {
997
1272
  const starts = /* @__PURE__ */ new Set();
998
1273
  const tokens = [];
@@ -1075,7 +1350,7 @@ function swiftCodeScan(source) {
1075
1350
  else top.parens--;
1076
1351
  i++;
1077
1352
  } else {
1078
- 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;
1353
+ 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;
1079
1354
  if (keyword && !/[\w$]/.test(source[i - 1] ?? "") && !/[\w$]/.test(source[i + keyword.length] ?? "")) {
1080
1355
  tokens.push(i);
1081
1356
  i += keyword.length;
@@ -1087,9 +1362,22 @@ function swiftCodeScan(source) {
1087
1362
  }
1088
1363
  return { lineStarts: starts, tokens };
1089
1364
  }
1090
- var compiledSource = (file, contents) => file.endsWith(".swift") ? swiftSourceAsIOS(contents) : contents;
1365
+ var compiledSource = (file, contents, extraObjCExtensions) => file.endsWith(".swift") ? swiftSourceAsIOS(contents, extraObjCExtensions) : contents;
1091
1366
  function prepareSwiftDependency(source, destination) {
1092
1367
  (0, import_node_fs2.rmSync)(destination, { recursive: true, force: true });
1368
+ const origins = [];
1369
+ const gather = (from, root) => {
1370
+ for (const entry of (0, import_node_fs2.readdirSync)(from, { withFileTypes: true })) {
1371
+ if (entry.name === ".git" || entry.name === ".build" || entry.name === ".swiftpm")
1372
+ continue;
1373
+ const file = import_node_path2.default.join(from, entry.name);
1374
+ if (entry.isDirectory()) gather(file, false);
1375
+ else if (entry.isFile() && entry.name.endsWith(".swift") && !(root && /^Package(@swift-[\d.]+)?\.swift$/.test(entry.name)))
1376
+ origins.push((0, import_node_fs2.readFileSync)(file, "utf8"));
1377
+ }
1378
+ };
1379
+ gather(source, true);
1380
+ const objcExtensions = objcExtensionMemberIndex(origins);
1093
1381
  const copy = (from, to, root) => {
1094
1382
  (0, import_node_fs2.mkdirSync)(to, { recursive: true });
1095
1383
  for (const entry of (0, import_node_fs2.readdirSync)(from, { withFileTypes: true })) {
@@ -1099,7 +1387,10 @@ function prepareSwiftDependency(source, destination) {
1099
1387
  const target = import_node_path2.default.join(to, entry.name);
1100
1388
  if (entry.isDirectory()) copy(file, target, false);
1101
1389
  else if (entry.isFile() && entry.name.endsWith(".swift") && !(root && /^Package(@swift-[\d.]+)?\.swift$/.test(entry.name)))
1102
- (0, import_node_fs2.writeFileSync)(target, compiledSource(file, (0, import_node_fs2.readFileSync)(file, "utf8")));
1390
+ (0, import_node_fs2.writeFileSync)(
1391
+ target,
1392
+ compiledSource(file, (0, import_node_fs2.readFileSync)(file, "utf8"), objcExtensions)
1393
+ );
1103
1394
  else (0, import_node_fs2.cpSync)(file, target, { verbatimSymlinks: true });
1104
1395
  }
1105
1396
  };
@@ -1137,10 +1428,16 @@ function writeSwiftProject(layout, input, moduleRoot) {
1137
1428
  // sootsim-swift files ${modulePlan.digest("hex").slice(0, 16)}
1138
1429
  // resource accessors ${resourcePlan}
1139
1430
  `;
1431
+ const objcExtensions = objcExtensionMemberIndex(
1432
+ Object.entries(input.files).filter(([file]) => file.endsWith(".swift")).map(([, contents]) => contents)
1433
+ );
1140
1434
  if (targets.length === 0) {
1141
1435
  for (const [file, contents] of Object.entries(input.files)) {
1142
1436
  if (file === "Package.swift") continue;
1143
- files.set(import_node_path2.default.join(layout.sources, file), compiledSource(file, contents));
1437
+ files.set(
1438
+ import_node_path2.default.join(layout.sources, file),
1439
+ compiledSource(file, contents, objcExtensions)
1440
+ );
1144
1441
  }
1145
1442
  let manifest = (0, import_node_fs2.readFileSync)(
1146
1443
  import_node_path2.default.join(moduleRoot, "scripts/contrast-app-Package.swift"),
@@ -1186,7 +1483,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
1186
1483
  const base = layout.multi ? layout.root : layout.sources;
1187
1484
  for (const [file, contents] of Object.entries(input.files)) {
1188
1485
  if (file === "Package.swift") continue;
1189
- files.set(import_node_path2.default.join(base, file), compiledSource(file, contents));
1486
+ files.set(import_node_path2.default.join(base, file), compiledSource(file, contents, objcExtensions));
1190
1487
  }
1191
1488
  files.set(
1192
1489
  import_node_path2.default.join(layout.root, "Package.swift"),
@@ -1312,10 +1609,16 @@ function compileSwiftProjectUnit(input, options) {
1312
1609
  plugin
1313
1610
  ])
1314
1611
  ],
1315
- { env: BUILD_ENV, maxBuffer: 64 * 1024 * 1024, timeout: options.timeoutMs }
1612
+ {
1613
+ env: BUILD_ENV,
1614
+ maxBuffer: 64 * 1024 * 1024,
1615
+ timeout: options.timeoutMs
1616
+ }
1316
1617
  );
1317
1618
  } catch (error) {
1318
- throw new Error(projectDiagnostic(outputOf(error), layout), { cause: error });
1619
+ throw new Error(projectDiagnostic(outputOf(error), layout), {
1620
+ cause: error
1621
+ });
1319
1622
  }
1320
1623
  return {
1321
1624
  hash,
@@ -1332,13 +1635,19 @@ function compileSwiftProjectUnit(input, options) {
1332
1635
  compileTargets,
1333
1636
  emitSwiftPackageManifest,
1334
1637
  lowerAnyObjectDoubleValue,
1638
+ missingSwiftModules,
1639
+ objcExtensionMemberIndex,
1335
1640
  prepareSwiftDependency,
1641
+ swiftApplicationEntry,
1336
1642
  swiftArtifactHash,
1643
+ swiftAvailableModules,
1337
1644
  swiftDistributionAt,
1338
1645
  swiftIcuAsset,
1646
+ swiftImportNames,
1339
1647
  swiftModuleDigest,
1340
1648
  swiftModuleInputFiles,
1341
1649
  swiftModuleSdk,
1650
+ swiftPeachModules,
1342
1651
  swiftSourceAsIOS,
1343
1652
  swiftTargetDependencies,
1344
1653
  syncSwiftTree,