peachsim 0.1.686 → 0.1.688

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 (116) hide show
  1. package/cli/cloud-client.ts +3 -3
  2. package/cli/command-registry.ts +2 -0
  3. package/cli/commands/control.ts +1 -0
  4. package/cli/commands/debug.ts +10 -33
  5. package/cli/commands/do-chain.ts +56 -6
  6. package/cli/commands/inspect/core.ts +2 -0
  7. package/cli/commands/inspect/list.ts +2 -1
  8. package/cli/commands/inspect/settling.ts +17 -3
  9. package/cli/commands/inspect/shared.ts +2 -0
  10. package/cli/commands/inspect/wait-idle.ts +2 -2
  11. package/cli/commands/inspect/wait-ready.ts +3 -3
  12. package/cli/commands/inspect.ts +33 -7
  13. package/cli/commands/location.ts +164 -0
  14. package/cli/commands/platform.ts +1 -1
  15. package/cli/drivers/playwright-sim-host.ts +46 -25
  16. package/cli/main.ts +6 -0
  17. package/detox/index.ts +13 -8
  18. package/dist-lib/agent-daemon-client.cjs +1 -1
  19. package/dist-lib/agent-events.cjs +1 -1
  20. package/dist-lib/agent-identity.cjs +1 -1
  21. package/dist-lib/agent-sessions.cjs +1 -1
  22. package/dist-lib/attached-projects.cjs +1 -1
  23. package/dist-lib/auth/shared-session.cjs +1 -1
  24. package/dist-lib/backend-origin.cjs +1 -1
  25. package/dist-lib/beta.cjs +1 -1
  26. package/dist-lib/beta.mjs +1 -1
  27. package/dist-lib/bridge-constants.cjs +4 -3
  28. package/dist-lib/bridge-contract-input.cjs +12 -1
  29. package/dist-lib/bridge-contract-input.mjs +12 -1
  30. package/dist-lib/bridge-contract.cjs +4 -3
  31. package/dist-lib/bridge-contract.mjs +4 -3
  32. package/dist-lib/capture-contract.cjs +1 -1
  33. package/dist-lib/capture-contract.mjs +1 -1
  34. package/dist-lib/cli-constants.cjs +1 -1
  35. package/dist-lib/cloud-contract.cjs +2 -1
  36. package/dist-lib/cloud-contract.mjs +2 -1
  37. package/dist-lib/cloud-test-args.cjs +1 -1
  38. package/dist-lib/cloud-test-args.mjs +1 -1
  39. package/dist-lib/cloud.cjs +2 -1
  40. package/dist-lib/cloud.mjs +2 -1
  41. package/dist-lib/config.cjs +1 -1
  42. package/dist-lib/detox/index.cjs +1197 -65
  43. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  44. package/dist-lib/home-paths.cjs +1 -1
  45. package/dist-lib/host/bridge-host.cjs +402 -113
  46. package/dist-lib/host/fetch-proxy-handler.cjs +50 -40
  47. package/dist-lib/host/fetch-proxy-overrides.cjs +50 -6
  48. package/dist-lib/host/fetch-proxy-overrides.mjs +48 -5
  49. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  50. package/dist-lib/host/websocket-proxy.cjs +1 -1
  51. package/dist-lib/index.cjs +29 -11
  52. package/dist-lib/jump-to-source-babel.cjs +1 -1
  53. package/dist-lib/jump-to-source-native.cjs +1 -1
  54. package/dist-lib/kotlin-host.cjs +89 -13
  55. package/dist-lib/menu.cjs +1 -1
  56. package/dist-lib/menu.mjs +1 -1
  57. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  58. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  59. package/dist-lib/metro-production-bundle.cjs +1 -1
  60. package/dist-lib/metro-production-bundle.mjs +1 -1
  61. package/dist-lib/metro.cjs +5 -3
  62. package/dist-lib/native-app-identity.cjs +8 -3
  63. package/dist-lib/native-app-identity.mjs +8 -3
  64. package/dist-lib/native-firebase-metadata.cjs +1 -1
  65. package/dist-lib/native-firebase-metadata.mjs +1 -1
  66. package/dist-lib/plist.cjs +1 -1
  67. package/dist-lib/plist.mjs +1 -1
  68. package/dist-lib/profiles.cjs +1 -1
  69. package/dist-lib/public-brand.cjs +1 -1
  70. package/dist-lib/react-native-host-modules.cjs +1 -1
  71. package/dist-lib/react-native-host-modules.mjs +1 -1
  72. package/dist-lib/render-mode.cjs +1 -1
  73. package/dist-lib/scripts/dev-server-scanner.cjs +2 -2
  74. package/dist-lib/sdk.cjs +21 -6
  75. package/dist-lib/sdk.mjs +21 -6
  76. package/dist-lib/skills.cjs +441 -135
  77. package/dist-lib/swift-compile.cjs +317 -27
  78. package/dist-lib/swift-compile.mjs +315 -27
  79. package/dist-lib/swift-package.cjs +1 -1
  80. package/dist-lib/swift-package.mjs +1 -1
  81. package/dist-lib/swift-submit.cjs +2 -2
  82. package/dist-lib/swift-submit.mjs +2 -2
  83. package/dist-lib/swift-toolchain.cjs +10 -10
  84. package/dist-lib/swift.cjs +1 -1
  85. package/dist-lib/vite-swift.cjs +320 -49
  86. package/dist-lib/vite.cjs +1 -1
  87. package/kotlin/AppSources/android/content/res/Configuration.kt +2 -0
  88. package/kotlin/AppSources/android/content/res/Resources.kt +6 -3
  89. package/kotlin/AppSources/android/util/DisplayMetrics.kt +12 -0
  90. package/kotlin/AppSources/androidx/compose/ui/res/PainterResources.kt +70 -0
  91. package/kotlin/AppSources/dev/peach/app/PeachApp.kt +12 -10
  92. package/kotlin/AppSources/dev/peach/app/PeachDrawable.kt +95 -0
  93. package/kotlin/fixtures/kotlin-app-variants/Bitmaps.kt +50 -0
  94. package/kotlin/fixtures/kotlin-app-variants/Drawables.kt +53 -0
  95. package/package.json +2 -2
  96. package/scripts/dev-server-scanner.ts +3 -1
  97. package/skills/contrast/SKILL.md +1 -0
  98. package/src/android-drawables.ts +315 -0
  99. package/src/android-theme.ts +9 -0
  100. package/src/bridge-constants.ts +3 -2
  101. package/src/bridge-contract-input.ts +11 -0
  102. package/src/bridge-contract.ts +45 -3
  103. package/src/cloud-contract.ts +1 -0
  104. package/src/host/fetch-proxy-handler.ts +13 -49
  105. package/src/host/fetch-proxy-overrides.ts +69 -12
  106. package/src/kotlin-app.ts +6 -0
  107. package/src/kotlin-host.ts +103 -15
  108. package/src/native-app-identity.ts +16 -3
  109. package/src/swift-compile.ts +426 -29
  110. package/src/swift-distribution-contract.ts +11 -4
  111. package/src/swift-distribution.lock.json +11 -9
  112. package/src/swift-distribution.ts +4 -4
  113. package/src/swift-icu.ts +8 -11
  114. package/src/swift-submit.ts +13 -1
  115. package/src/swift-toolchain.ts +17 -9
  116. package/src/vite-plugin.ts +86 -34
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.686 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.688 | (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;
@@ -37,12 +37,15 @@ __export(swift_compile_exports, {
37
37
  compileSwiftProjectUnit: () => compileSwiftProjectUnit,
38
38
  compileTargets: () => compileTargets,
39
39
  emitSwiftPackageManifest: () => emitSwiftPackageManifest,
40
+ prepareSwiftDependency: () => prepareSwiftDependency,
40
41
  swiftArtifactHash: () => swiftArtifactHash,
41
42
  swiftDistributionAt: () => swiftDistributionAt,
42
43
  swiftIcuAsset: () => swiftIcuAsset,
43
44
  swiftModuleDigest: () => swiftModuleDigest,
44
45
  swiftModuleInputFiles: () => swiftModuleInputFiles,
46
+ swiftModuleSdk: () => swiftModuleSdk,
45
47
  swiftSourceAsIOS: () => swiftSourceAsIOS,
48
+ swiftTargetDependencies: () => swiftTargetDependencies,
46
49
  withNativeSourceGlue: () => withNativeSourceGlue,
47
50
  writeSwiftProject: () => writeSwiftProject
48
51
  });
@@ -68,7 +71,7 @@ var SWIFT_DISTRIBUTION_HOSTS = [
68
71
  ];
69
72
  var isStrings = (value) => Array.isArray(value) && value.every((item) => typeof item === "string");
70
73
  function parseSwiftDistributionManifest(value) {
71
- if (!isRecord(value) || typeof value.id !== "string" || typeof value.release !== "string" || typeof value.wasmSdkChecksum !== "string" || !isStrings(value.modules) || !isStrings(value.objects) || !isStrings(value.link) || !isRecord(value.files) || !Object.values(value.files).every((sha) => typeof sha === "string") || typeof value.host !== "string" || !isStrings(value.plugins)) {
74
+ if (!isRecord(value) || typeof value.id !== "string" || typeof value.release !== "string" || typeof value.wasmSdkId !== "string" || typeof value.wasmSdkUrl !== "string" || typeof value.wasmSdkChecksum !== "string" || !isStrings(value.modules) || !isStrings(value.objects) || !isStrings(value.link) || !isRecord(value.files) || !Object.values(value.files).every((sha) => typeof sha === "string") || typeof value.host !== "string" || !isStrings(value.plugins)) {
72
75
  throw new Error(`invalid Swift distribution ${SWIFT_DISTRIBUTION_MANIFEST}`);
73
76
  }
74
77
  const host2 = SWIFT_DISTRIBUTION_HOSTS.find((candidate) => candidate === value.host);
@@ -76,6 +79,8 @@ function parseSwiftDistributionManifest(value) {
76
79
  return {
77
80
  id: value.id,
78
81
  release: value.release,
82
+ wasmSdkId: value.wasmSdkId,
83
+ wasmSdkUrl: value.wasmSdkUrl,
79
84
  wasmSdkChecksum: value.wasmSdkChecksum,
80
85
  modules: value.modules,
81
86
  objects: value.objects,
@@ -110,25 +115,25 @@ function memo(cache, key, load2) {
110
115
  }
111
116
  return pending;
112
117
  }
113
- function swiftIcuData(toolchainBin, release) {
114
- return memo(raw, `${toolchainBin}\0${release}`, () => load(toolchainBin, release));
118
+ function swiftIcuData(toolchainBin, sdk) {
119
+ return memo(raw, `${toolchainBin}\0${sdk}`, () => load(toolchainBin, sdk));
115
120
  }
116
- function swiftIcuAsset(toolchainBin, release) {
117
- return memo(assets, `${toolchainBin}\0${release}`, async () => {
118
- const zipped = await deflate(await swiftIcuData(toolchainBin, release));
121
+ function swiftIcuAsset(toolchainBin, sdk) {
122
+ return memo(assets, `${toolchainBin}\0${sdk}`, async () => {
123
+ const zipped = await deflate(await swiftIcuData(toolchainBin, sdk));
119
124
  return { sha256: (0, import_node_crypto.createHash)("sha256").update(zipped).digest("hex"), gzip: zipped };
120
125
  });
121
126
  }
122
- async function load(toolchainBin, release) {
127
+ async function load(toolchainBin, sdk) {
123
128
  const { stdout } = await run(import_node_path.default.join(toolchainBin, "swift"), [
124
129
  "sdk",
125
130
  "configure",
126
131
  "--show-configuration",
127
- `${release}_wasm`,
132
+ sdk,
128
133
  "wasm32-unknown-wasip1"
129
134
  ]);
130
135
  const resources = /^swiftStaticResourcesPath: (.+)$/m.exec(stdout)?.[1]?.trim();
131
- if (!resources) throw new Error(`swift-icu: ${release}_wasm names no static resources`);
136
+ if (!resources) throw new Error(`swift-icu: ${sdk} names no static resources`);
132
137
  return Buffer.from(
133
138
  icuSegment(archiveMember((0, import_node_fs.readFileSync)(import_node_path.default.join(resources, ARCHIVE)), MEMBER))
134
139
  );
@@ -257,6 +262,16 @@ function swiftDistributionAt(root) {
257
262
  if (!(0, import_node_fs2.existsSync)(file)) return null;
258
263
  return parseSwiftDistributionManifest(JSON.parse((0, import_node_fs2.readFileSync)(file, "utf8")));
259
264
  }
265
+ function swiftModuleSdk(root) {
266
+ const pin = swiftDistributionAt(root) ?? JSON.parse((0, import_node_fs2.readFileSync)(import_node_path2.default.join(root, "toolchain.json"), "utf8"));
267
+ if (!pin || typeof pin !== "object" || typeof Reflect.get(pin, "wasmSdkId") !== "string" || typeof Reflect.get(pin, "wasmSdkUrl") !== "string" || typeof Reflect.get(pin, "wasmSdkChecksum") !== "string")
268
+ throw new Error(`${root} pins no wasm SDK id, url and checksum`);
269
+ return {
270
+ wasmSdkId: String(Reflect.get(pin, "wasmSdkId")),
271
+ wasmSdkUrl: String(Reflect.get(pin, "wasmSdkUrl")),
272
+ wasmSdkChecksum: String(Reflect.get(pin, "wasmSdkChecksum"))
273
+ };
274
+ }
260
275
  function swiftModuleInputFiles(root) {
261
276
  if (swiftDistributionAt(root)) return [SWIFT_DISTRIBUTION_MANIFEST];
262
277
  const files = [
@@ -268,7 +283,7 @@ function swiftModuleInputFiles(root) {
268
283
  for (const entry of (0, import_node_fs2.readdirSync)(import_node_path2.default.join(root, dir), { withFileTypes: true })) {
269
284
  const relative = `${dir}/${entry.name}`;
270
285
  if (entry.isDirectory()) walk(relative);
271
- else if (/\.(swift|c|h)$/.test(entry.name)) files.push(relative);
286
+ else if (/\.(swift|c|cpp|h)$/.test(entry.name)) files.push(relative);
272
287
  }
273
288
  };
274
289
  walk("Sources");
@@ -351,14 +366,29 @@ function withNativeSourceGlue(input, glue) {
351
366
  oneModule: true
352
367
  };
353
368
  }
354
- function swiftSiblingDependencies(files, targets) {
355
- const names = new Set(targets.map((target) => target.name));
369
+ var OPTIONAL_FRAMEWORK_DEPENDENCIES = {
370
+ Accelerate: [],
371
+ CryptoKit: [],
372
+ Security: [],
373
+ Statsig: [],
374
+ DatadogCore: [],
375
+ DatadogLogs: ["DatadogCore"],
376
+ DatadogRUM: ["DatadogCore"],
377
+ DatadogTrace: ["DatadogCore"]
378
+ };
379
+ var OPTIONAL_FRAMEWORKS = new Set(Object.keys(OPTIONAL_FRAMEWORK_DEPENDENCIES));
380
+ function swiftTargetDependencies(files, targets) {
381
+ const names = /* @__PURE__ */ new Set([...OPTIONAL_FRAMEWORKS, ...targets.map((target) => target.name)]);
356
382
  const siblings = /* @__PURE__ */ new Map();
357
383
  for (const target of targets) {
358
- const prefix = `${target.path}/`;
384
+ const prefix = target.path === "." ? "" : `${target.path}/`;
359
385
  const deps = /* @__PURE__ */ new Set();
360
386
  for (const [file, contents] of Object.entries(files)) {
361
387
  if (file === "Package.swift" || !file.startsWith(prefix)) continue;
388
+ if (targets.some(
389
+ (candidate) => candidate.name !== target.name && candidate.path !== "." && candidate.path.startsWith(prefix) && file.startsWith(`${candidate.path}/`)
390
+ ))
391
+ continue;
362
392
  for (const match of contents.matchAll(
363
393
  /^\s*(?:@\w+(?:\([^)]*\))?\s+)*import\s+(?:(?:typealias|struct|class|enum|protocol|let|var|func)\s+)?([A-Za-z_][A-Za-z0-9_]*)/gm
364
394
  )) {
@@ -376,12 +406,12 @@ var importsSpriteKit = (files) => Object.entries(files).some(
376
406
  contents
377
407
  )
378
408
  );
379
- var OBJC_IMPLICIT_FLAGS = ', "-Xfrontend", "-import-module", "-Xfrontend", "PeachObjC"';
409
+ var FOUNDATION_IMPLICIT_FLAGS = ', "-Xfrontend", "-import-module", "-Xfrontend", "PeachObjC", "-Xfrontend", "-import-module", "-Xfrontend", "Dispatch", "-Xfrontend", "-import-module", "-Xfrontend", "FoundationNetworking"';
380
410
  var ONE_IMPLICIT_FLAGS = ', "-Xfrontend", "-import-module", "-Xfrontend", "One"';
381
- var MULTI_MANIFEST_VERSION = 7;
411
+ var MULTI_MANIFEST_VERSION = 10;
382
412
  function swiftArtifactHash(input, release, moduleRoot) {
383
413
  const hash = (0, import_node_crypto2.createHash)("sha256");
384
- hash.update(`swift-compile/v7
414
+ hash.update(`swift-compile/v12
385
415
  ${release}
386
416
  `);
387
417
  if (input.oneModule) hash.update("one-module\n");
@@ -410,7 +440,7 @@ ${release}
410
440
  hash.update(
411
441
  JSON.stringify({
412
442
  targets,
413
- siblings: [...swiftSiblingDependencies(input.files, targets)].sort(
443
+ siblings: [...swiftTargetDependencies(input.files, targets)].sort(
414
444
  (a, b) => String(a) < String(b) ? -1 : String(a) > String(b) ? 1 : 0
415
445
  )
416
446
  })
@@ -420,22 +450,34 @@ ${release}
420
450
  }
421
451
  function emitSwiftPackageManifest(args) {
422
452
  const { targets, siblings, moduleRoot, oneModule, spriteKit, distribution } = args;
453
+ const reachedFrameworks = new Set(
454
+ [...siblings.values()].flat().filter(
455
+ (name) => OPTIONAL_FRAMEWORKS.has(name) && !targets.some((target) => target.name === name)
456
+ ).flatMap((name) => [name, ...OPTIONAL_FRAMEWORK_DEPENDENCIES[name] ?? []])
457
+ );
458
+ const distributionObjects = distribution?.objects.filter(
459
+ (object) => [...OPTIONAL_FRAMEWORKS].every(
460
+ (name) => !object.startsWith(`lib/${name}-`) || reachedFrameworks.has(name)
461
+ )
462
+ );
423
463
  const executable = targets.find((target) => target.executable);
424
464
  if (!executable) throw new Error("swift-compile: no executable target to emit");
425
465
  const stanza = (target) => {
426
466
  const isolation = target.mainActorIsolation ? " .defaultIsolation(MainActor.self)," : "";
427
467
  const imports = distribution ? `, "-I", ${JSON.stringify(import_node_path2.default.join(moduleRoot, "modules"))}` : "";
428
- const swiftSettings = `swiftSettings: [.swiftLanguageMode(.v${target.languageMode}),${isolation} .unsafeFlags(["-Osize"${OBJC_IMPLICIT_FLAGS}${oneModule ? ONE_IMPLICIT_FLAGS : ""}${imports}])]`;
468
+ const swiftSettings = `swiftSettings: [.swiftLanguageMode(.v${target.languageMode}),${isolation} .unsafeFlags(["-Osize"${FOUNDATION_IMPLICIT_FLAGS}${oneModule ? ONE_IMPLICIT_FLAGS : ""}${imports}])]`;
429
469
  const deps = [
430
470
  ...distribution ? [] : [
431
471
  '.product(name: "SwiftUI", package: "sootsim-swift")',
432
472
  ...oneModule ? [ONE_PRODUCT] : [],
433
473
  ...spriteKit ? [SPRITEKIT_PRODUCT] : []
434
474
  ],
435
- ...(siblings.get(target.name) ?? []).map((sibling) => `"${sibling}"`)
475
+ ...(siblings.get(target.name) ?? []).flatMap(
476
+ (dependency) => OPTIONAL_FRAMEWORKS.has(dependency) && !targets.some((candidate) => candidate.name === dependency) ? distribution ? [] : [`.product(name: "${dependency}", package: "sootsim-swift")`] : [`"${dependency}"`]
477
+ )
436
478
  ].join(", ");
437
479
  const library = distribution ? [
438
- ...distribution.objects.map((object) => import_node_path2.default.join(moduleRoot, object)),
480
+ ...(distributionObjects ?? []).map((object) => import_node_path2.default.join(moduleRoot, object)),
439
481
  ...distribution.link
440
482
  ].map((flag) => `, ${JSON.stringify(flag)}`).join("") : "";
441
483
  const kind = target.executable ? ".executableTarget" : ".target";
@@ -493,8 +535,185 @@ var DIRECTIVE = /^[ \t]*#(?:if|elseif)\b/;
493
535
  var OS_IOS = /\bos\(\s*iOS\s*\)/g;
494
536
  var OBJC_ATTRIBUTE = /^@(?:objcMembers\b|objc\b(?:(\s*)\(([^()]*)\))?|IBAction\b)/;
495
537
  var SELECTOR = /^#selector\b/;
538
+ var TYPE_AFTER_ATTRIBUTE = /^(?:\s+|\/\/[^\n]*|\/\*[\s\S]*?\*\/|@\w+(?:\([^()]*\))?|\b(?:public|open|final|internal|fileprivate|private|package|nonisolated|indirect)\b)*\b(?:class(?!\s+(?:func|var|let|subscript)\b)|struct|enum|protocol|extension|actor)\b/;
496
539
  var DELEGATE_CLASS = /^class\s+[A-Za-z_]\w*\s*(?:<[^>{]*>)?\s*:[^{]*\b(?:UIApplicationDelegate|UISceneDelegate|UIWindowSceneDelegate)\b[^{]*\{/;
497
- function swiftSourceAsIOS(source) {
540
+ var REUSABLE_INIT = /^override(?=\s+init\s*\(\s*(?:style\s*:[^,)]*,\s*reuseIdentifier|reuseIdentifier)\s*:)/;
541
+ var REUSABLE_VIEW_BASES = [
542
+ "UICollectionReusableView",
543
+ "UICollectionViewCell",
544
+ "UICollectionViewListCell"
545
+ ];
546
+ var CLASS_BASE = /^class\s+([A-Za-z_]\w*)\s*(?:<[^>{]*>)?\s*:\s*([A-Za-z_][\w.]*)[^{]*\{/;
547
+ var FRAME_INIT = /^override(?=\s+(?:(?:public|open|internal)\s+)?init\s*\(\s*frame\s*:)/;
548
+ var APPLE_CLASS = /^(?:UI|NS|CA|SK|WK|MK|AV|PK|CL|GK|PH|SF|AS|QL)[A-Z]/;
549
+ var EXTENSION_DECL = /^extension\s+([A-Za-z_][\w.]*)/;
550
+ var CLASS_DECL = /^class\s+(?!(?:func|var|let|subscript)\b)([A-Za-z_]\w*)/;
551
+ var MODIFIERS = /(?:^|\s)(public|open|internal|fileprivate|private|final|nonisolated|@MainActor)(?=\s)/g;
552
+ var OVERRIDE_FUNC = /^override((?:\s+(?:public|open|internal|fileprivate|private|final|nonisolated|dynamic|@\w+))*)\s+func\s+([A-Za-z_]\w*)\s*(<[^>{}]*>)?\s*\(/;
553
+ var OVERRIDE_VAR = /^override((?:\s+(?:public|open|internal|fileprivate|private|final|nonisolated|dynamic|@\w+))*)\s+var\s+([A-Za-z_]\w*)\s*:\s*([^{=]+?)\s*\{/;
554
+ function splitTopLevel(text) {
555
+ const parts = [];
556
+ let depth = 0;
557
+ let start = 0;
558
+ for (let i = 0; i < text.length; i++) {
559
+ const char = text[i];
560
+ if (char === "(" || char === "[" || char === "<") depth++;
561
+ else if (char === ")" || char === "]" || char === ">" && text[i - 1] !== "-")
562
+ depth--;
563
+ else if (char === "," && depth === 0) {
564
+ parts.push(text.slice(start, i));
565
+ start = i + 1;
566
+ }
567
+ }
568
+ parts.push(text.slice(start));
569
+ return parts.map((part) => part.trim()).filter((part) => part !== "");
570
+ }
571
+ function forwardedArguments(parameters) {
572
+ const args = [];
573
+ for (const parameter of splitTopLevel(parameters)) {
574
+ const match = /^(?:([A-Za-z_]\w*)\s+)?([A-Za-z_]\w*)\s*:\s*([\s\S]*)$/.exec(parameter);
575
+ if (!match || match[3].includes("...")) return null;
576
+ const label = match[1] ?? match[2];
577
+ const value = (/^(?:@\w+\s+)*inout\b/.test(match[3]) ? "&" : "") + match[2];
578
+ args.push(label === "_" ? value : `${label}: ${value}`);
579
+ }
580
+ return args.join(", ");
581
+ }
582
+ function liftExtensionOverrides(source) {
583
+ const { tokens } = swiftCodeScan(source);
584
+ const stack = [];
585
+ let pending = null;
586
+ const classes = /* @__PURE__ */ new Map();
587
+ let declaredBase = null;
588
+ let declaredObjCMembers = false;
589
+ const lifted = [];
590
+ const closing = (open) => {
591
+ let depth = 0;
592
+ for (const at of tokens) {
593
+ if (at < open) continue;
594
+ if (source[at] === "{") depth++;
595
+ else if (source[at] === "}" && --depth === 0) return at + 1;
596
+ }
597
+ return source.length;
598
+ };
599
+ for (const at of tokens) {
600
+ const rest = source.slice(at, at + 600);
601
+ if (rest.startsWith("{")) {
602
+ const frame = pending ?? { kind: "other", name: "" };
603
+ if (frame.kind === "class" && !classes.has(frame.name))
604
+ classes.set(frame.name, {
605
+ brace: at,
606
+ base: declaredBase,
607
+ objcMembers: declaredObjCMembers
608
+ });
609
+ stack.push(frame);
610
+ pending = null;
611
+ continue;
612
+ }
613
+ if (rest.startsWith("}")) {
614
+ stack.pop();
615
+ continue;
616
+ }
617
+ const declared = CLASS_DECL.exec(rest);
618
+ if (declared) {
619
+ pending = { kind: "class", name: declared[1] };
620
+ declaredBase = CLASS_BASE.exec(rest)?.[2]?.split(".").pop() ?? null;
621
+ const lines = source.lastIndexOf("\n", source.lastIndexOf("\n", at - 1) - 1) + 1;
622
+ declaredObjCMembers = /@objcMembers\b/.test(source.slice(lines, at));
623
+ continue;
624
+ }
625
+ const extended = EXTENSION_DECL.exec(rest);
626
+ if (extended) {
627
+ pending = { kind: "extension", name: extended[1].split(".").pop() };
628
+ continue;
629
+ }
630
+ const top = stack.at(-1);
631
+ if (!rest.startsWith("override") || top?.kind !== "extension" || pending) continue;
632
+ const line = source.slice(source.lastIndexOf("\n", at - 1) + 1, at);
633
+ const modifiers = (` ${line} `.match(MODIFIERS) ?? []).map((word) => word.trim());
634
+ const func = OVERRIDE_FUNC.exec(rest);
635
+ if (func) {
636
+ const name = func[2];
637
+ const open = at + func[0].length - 1;
638
+ let depth = 0;
639
+ let close = open;
640
+ for (; close < source.length; close++) {
641
+ if (source[close] === "(") depth++;
642
+ else if (source[close] === ")" && --depth === 0) break;
643
+ }
644
+ const body = tokens.find((token) => token > close && source[token] === "{");
645
+ if (body === void 0) continue;
646
+ const clause = source.slice(close + 1, body).trim();
647
+ const args = forwardedArguments(source.slice(open + 1, close));
648
+ if (args === null) continue;
649
+ const call = (clause.includes("->") ? "return " : "") + (/\b(?:throws|rethrows)\b/.test(clause) ? "try " : "") + (/\basync\b/.test(clause) ? "await " : "") + `__peach_ext_${name}(${args})`;
650
+ const signature = `func ${name}${func[3] ?? ""}${source.slice(open, close + 1)}${clause ? ` ${clause}` : ""}`;
651
+ lifted.push({
652
+ type: top.name,
653
+ member: name,
654
+ stub: `${[...modifiers, "override"].join(" ")} ${signature} { ${call} };`,
655
+ edits: [
656
+ [at, "override".length, " ".repeat("override".length)],
657
+ [
658
+ at + rest.indexOf(
659
+ name,
660
+ rest.indexOf("func", "override".length + func[1].length) + 4
661
+ ),
662
+ 0,
663
+ "__peach_ext_"
664
+ ]
665
+ ]
666
+ });
667
+ continue;
668
+ }
669
+ const property = OVERRIDE_VAR.exec(rest);
670
+ if (property) {
671
+ const open = at + property[0].length - 1;
672
+ if (/\b(?:set|willSet|didSet)\b/.test(source.slice(open, closing(open)))) continue;
673
+ const name = property[2];
674
+ lifted.push({
675
+ type: top.name,
676
+ member: name,
677
+ stub: `${[...modifiers, "override"].join(" ")} var ${name}: ${property[3].trim()} { __peach_ext_${name} };`,
678
+ edits: [
679
+ [at, "override".length, " ".repeat("override".length)],
680
+ [at + rest.indexOf(name, rest.indexOf("var")), 0, "__peach_ext_"]
681
+ ]
682
+ });
683
+ }
684
+ }
685
+ const overridesObjC = (type, member) => {
686
+ let base = classes.get(type)?.base ?? null;
687
+ while (base !== null) {
688
+ if (APPLE_CLASS.test(base)) return true;
689
+ const declaredClass = classes.get(base);
690
+ if (!declaredClass) return false;
691
+ const body = source.slice(declaredClass.brace, closing(declaredClass.brace));
692
+ const found = new RegExp(`\\b(?:func|var)\\s+${member}\\b`).exec(body);
693
+ if (found) {
694
+ const line = body.slice(body.lastIndexOf("\n", found.index) + 1, found.index);
695
+ return declaredClass.objcMembers || /@objc\b/.test(line);
696
+ }
697
+ base = declaredClass.base;
698
+ }
699
+ return false;
700
+ };
701
+ const edits = [];
702
+ const stubs = /* @__PURE__ */ new Map();
703
+ for (const entry of lifted) {
704
+ const brace = classes.get(entry.type)?.brace;
705
+ if (brace === void 0 || !overridesObjC(entry.type, entry.member)) continue;
706
+ edits.push(...entry.edits);
707
+ stubs.set(brace, [...stubs.get(brace) ?? [], entry.stub]);
708
+ }
709
+ for (const [brace, list] of stubs) edits.push([brace + 1, 0, ` ${list.join(" ")}`]);
710
+ let out = source;
711
+ for (const [at, remove, insert] of edits.sort((a, b) => b[0] - a[0]))
712
+ out = out.slice(0, at) + insert + out.slice(at + remove);
713
+ return out;
714
+ }
715
+ function swiftSourceAsIOS(original) {
716
+ const source = liftExtensionOverrides(original);
498
717
  const { lineStarts, tokens } = swiftCodeScan(source);
499
718
  let offset = 0;
500
719
  const conditioned = source.split("\n").map((line) => {
@@ -505,8 +724,30 @@ function swiftSourceAsIOS(source) {
505
724
  }).join("\n");
506
725
  let out = "";
507
726
  let copied = 0;
727
+ const reusableViews = new Set(REUSABLE_VIEW_BASES);
728
+ const reusableBodies = [];
729
+ let depth = 0;
730
+ let opensReusableBody = false;
508
731
  for (const at of tokens) {
509
732
  const rest = conditioned.slice(at, at + 400);
733
+ if (rest.startsWith("{")) {
734
+ depth++;
735
+ if (opensReusableBody) reusableBodies.push(depth);
736
+ opensReusableBody = false;
737
+ continue;
738
+ }
739
+ if (rest.startsWith("}")) {
740
+ if (reusableBodies.at(-1) === depth) reusableBodies.pop();
741
+ depth--;
742
+ continue;
743
+ }
744
+ if (rest.startsWith("override")) {
745
+ if (REUSABLE_INIT.test(rest) || reusableBodies.at(-1) === depth && FRAME_INIT.test(rest)) {
746
+ out += `${conditioned.slice(copied, at)}required`;
747
+ copied = at + "override".length;
748
+ }
749
+ continue;
750
+ }
510
751
  const imported = /^import\s+CoreImage\.CIFilterBuiltins\b/.exec(rest);
511
752
  if (imported) {
512
753
  out += conditioned.slice(copied, at) + "import CoreImage".padEnd(imported[0].length);
@@ -519,6 +760,11 @@ function swiftSourceAsIOS(source) {
519
760
  continue;
520
761
  }
521
762
  if (rest.startsWith("class")) {
763
+ const declared = CLASS_BASE.exec(rest);
764
+ if (declared && reusableViews.has(declared[2].split(".").pop())) {
765
+ reusableViews.add(declared[1]);
766
+ opensReusableBody = true;
767
+ }
522
768
  const modifiers = conditioned.slice(conditioned.lastIndexOf("\n", at - 1) + 1, at);
523
769
  if (DELEGATE_CLASS.test(rest) && !/\b(?:final|open)\b/.test(modifiers)) {
524
770
  out += `${conditioned.slice(copied, at)}final `;
@@ -533,6 +779,8 @@ function swiftSourceAsIOS(source) {
533
779
  if (selector) replacement = "#Selector";
534
780
  else if (match[0] === "@objcMembers") replacement = "@ObjCMembers";
535
781
  else if (match[0] === "@IBAction") replacement = "@ObjC".padEnd(match[0].length);
782
+ else if (TYPE_AFTER_ATTRIBUTE.test(rest.slice(match[0].length)))
783
+ replacement = " ".repeat(match[0].length);
536
784
  else if (match[2] !== void 0)
537
785
  replacement = `@ObjC${match[1]}("${match[2].trim()}")`;
538
786
  out += conditioned.slice(copied, at) + replacement;
@@ -611,6 +859,9 @@ function swiftCodeScan(source) {
611
859
  if (hashes > 0) tokens.push(at - 1);
612
860
  i = Math.max(at, i + 1);
613
861
  }
862
+ } else if (char === "{" || char === "}") {
863
+ tokens.push(i);
864
+ i++;
614
865
  } else if (char === "(") {
615
866
  top.parens++;
616
867
  i++;
@@ -619,7 +870,7 @@ function swiftCodeScan(source) {
619
870
  else top.parens--;
620
871
  i++;
621
872
  } else {
622
- const keyword = source.startsWith("class", i) ? "class" : source.startsWith("import", i) ? "import" : source.startsWith("NSClassFromString", i) ? "NSClassFromString" : null;
873
+ 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;
623
874
  if (keyword && !/[\w$]/.test(source[i - 1] ?? "") && !/[\w$]/.test(source[i + keyword.length] ?? "")) {
624
875
  tokens.push(i);
625
876
  i += keyword.length;
@@ -632,6 +883,23 @@ function swiftCodeScan(source) {
632
883
  return { lineStarts: starts, tokens };
633
884
  }
634
885
  var compiledSource = (file, contents) => file.endsWith(".swift") ? swiftSourceAsIOS(contents) : contents;
886
+ function prepareSwiftDependency(source, destination) {
887
+ (0, import_node_fs2.rmSync)(destination, { recursive: true, force: true });
888
+ const copy = (from, to, root) => {
889
+ (0, import_node_fs2.mkdirSync)(to, { recursive: true });
890
+ for (const entry of (0, import_node_fs2.readdirSync)(from, { withFileTypes: true })) {
891
+ if (entry.name === ".git" || entry.name === ".build" || entry.name === ".swiftpm")
892
+ continue;
893
+ const file = import_node_path2.default.join(from, entry.name);
894
+ const target = import_node_path2.default.join(to, entry.name);
895
+ if (entry.isDirectory()) copy(file, target, false);
896
+ else if (entry.isFile() && entry.name.endsWith(".swift") && !(root && /^Package(@swift-[\d.]+)?\.swift$/.test(entry.name)))
897
+ (0, import_node_fs2.writeFileSync)(target, compiledSource(file, (0, import_node_fs2.readFileSync)(file, "utf8")));
898
+ else (0, import_node_fs2.cpSync)(file, target, { verbatimSymlinks: true });
899
+ }
900
+ };
901
+ copy(source, destination, true);
902
+ }
635
903
  function writeSwiftProject(layout, input, moduleRoot) {
636
904
  const distribution = swiftDistributionAt(moduleRoot);
637
905
  const targets = distribution && compileTargets(input).length === 0 ? [
@@ -657,9 +925,24 @@ function writeSwiftProject(layout, input, moduleRoot) {
657
925
  import_node_path2.default.join(moduleRoot, "scripts/contrast-app-Package.swift"),
658
926
  "utf8"
659
927
  ).replaceAll("__SOOTSIM_SWIFT_PACKAGE__", moduleRoot);
928
+ const optionalProducts = swiftTargetDependencies(input.files, [{ name: "App", path: "." }]).get("App") ?? [];
929
+ if (optionalProducts.length > 0) {
930
+ const product = '.product(name: "SwiftUI", package: "sootsim-swift"),';
931
+ if (!manifest.includes(product))
932
+ throw new Error("Swift app template lost its framework dependency anchor");
933
+ manifest = manifest.replace(
934
+ product,
935
+ [
936
+ product,
937
+ ...optionalProducts.map(
938
+ (name) => `.product(name: "${name}", package: "sootsim-swift"),`
939
+ )
940
+ ].join("\n ")
941
+ );
942
+ }
660
943
  if (input.oneModule) {
661
944
  const product = '.product(name: "CoreLocation", package: "sootsim-swift"),';
662
- const flags = `"-Osize"${OBJC_IMPLICIT_FLAGS}`;
945
+ const flags = `"-Osize"${FOUNDATION_IMPLICIT_FLAGS}`;
663
946
  if (!manifest.includes(product) || !manifest.includes(flags)) {
664
947
  throw new Error(
665
948
  "scripts/contrast-app-Package.swift lost the lines the One module links at"
@@ -702,7 +985,10 @@ function writeSwiftProject(layout, input, moduleRoot) {
702
985
  import_node_path2.default.join(layout.root, "Package.swift"),
703
986
  emitSwiftPackageManifest({
704
987
  targets,
705
- siblings: swiftSiblingDependencies(input.files, targets),
988
+ siblings: swiftTargetDependencies(
989
+ input.files,
990
+ layout.multi ? targets : targets.map((target) => ({ ...target, path: "." }))
991
+ ),
706
992
  moduleRoot,
707
993
  oneModule: input.oneModule,
708
994
  spriteKit: importsSpriteKit(input.files),
@@ -780,7 +1066,8 @@ function compileSwiftProjectUnit(input, options) {
780
1066
  );
781
1067
  }
782
1068
  const macroPlugins = await ensureMacroPlugins(moduleRoot, options.toolchainBin);
783
- const icu = swiftIcuAsset(options.toolchainBin, options.release);
1069
+ const sdk = swiftModuleSdk(moduleRoot).wasmSdkId;
1070
+ const icu = swiftIcuAsset(options.toolchainBin, sdk);
784
1071
  try {
785
1072
  await run2(
786
1073
  swift,
@@ -791,7 +1078,7 @@ function compileSwiftProjectUnit(input, options) {
791
1078
  "--package-path",
792
1079
  root,
793
1080
  "--swift-sdk",
794
- `${options.release}_wasm`,
1081
+ sdk,
795
1082
  "-c",
796
1083
  "release",
797
1084
  "-Xswiftc",
@@ -822,12 +1109,15 @@ function compileSwiftProjectUnit(input, options) {
822
1109
  compileSwiftProjectUnit,
823
1110
  compileTargets,
824
1111
  emitSwiftPackageManifest,
1112
+ prepareSwiftDependency,
825
1113
  swiftArtifactHash,
826
1114
  swiftDistributionAt,
827
1115
  swiftIcuAsset,
828
1116
  swiftModuleDigest,
829
1117
  swiftModuleInputFiles,
1118
+ swiftModuleSdk,
830
1119
  swiftSourceAsIOS,
1120
+ swiftTargetDependencies,
831
1121
  withNativeSourceGlue,
832
1122
  writeSwiftProject
833
1123
  });