peachsim 0.1.1716 → 0.1.1738

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 (282) hide show
  1. package/README.md +21 -3
  2. package/cli/app-bundle-resources.ts +2 -1
  3. package/cli/app-fonts.ts +4 -4
  4. package/cli/app-splash.ts +4 -4
  5. package/cli/app-stubs.ts +17 -0
  6. package/cli/command-registry.ts +1 -0
  7. package/cli/commands/control.ts +83 -822
  8. package/cli/commands/coverage-swift.ts +112 -4
  9. package/cli/commands/daemon.ts +8 -0
  10. package/cli/commands/detox.ts +3 -0
  11. package/cli/commands/doctor.ts +19 -2
  12. package/cli/commands/inspect/actions.ts +74 -14
  13. package/cli/commands/inspect/core.ts +5 -1
  14. package/cli/commands/inspect/settling.ts +5 -2
  15. package/cli/commands/inspect/wait-ready.ts +6 -0
  16. package/cli/commands/inspect.ts +48 -45
  17. package/cli/commands/kotlin.ts +12 -2
  18. package/cli/commands/package.ts +760 -0
  19. package/cli/commands/serve.ts +6 -0
  20. package/cli/commands/shell-url.ts +838 -0
  21. package/cli/commands/swift.ts +42 -102
  22. package/cli/commands/test.ts +20 -0
  23. package/cli/commands/upload.ts +1 -1
  24. package/cli/device-option.ts +1 -1
  25. package/cli/main.ts +13 -1
  26. package/cli/native-input.ts +199 -0
  27. package/cli/outbound-endpoints.ts +26 -1
  28. package/cli/packaged-app-launcher.ts +95 -0
  29. package/cli/scene-video.ts +36 -12
  30. package/detox/index.ts +196 -24
  31. package/dist-lib/agent-daemon-client.cjs +1 -1
  32. package/dist-lib/agent-events.cjs +1 -1
  33. package/dist-lib/attached-projects.cjs +5 -2
  34. package/dist-lib/auth/shared-session.cjs +5 -2
  35. package/dist-lib/backend-origin.cjs +1 -1
  36. package/dist-lib/beta.cjs +1 -1
  37. package/dist-lib/beta.mjs +1 -1
  38. package/dist-lib/bridge-constants.cjs +1 -1
  39. package/dist-lib/bridge-contract-input.cjs +1 -1
  40. package/dist-lib/bridge-contract-input.mjs +1 -1
  41. package/dist-lib/bridge-contract.cjs +1 -1
  42. package/dist-lib/bridge-contract.mjs +1 -1
  43. package/dist-lib/bundle-channel.cjs +39889 -31873
  44. package/dist-lib/capture-contract.cjs +1 -1
  45. package/dist-lib/capture-contract.mjs +1 -1
  46. package/dist-lib/cloud-contract.cjs +1 -1
  47. package/dist-lib/cloud-contract.mjs +1 -1
  48. package/dist-lib/cloud-test-args.cjs +1 -1
  49. package/dist-lib/cloud-test-args.mjs +1 -1
  50. package/dist-lib/cloud.cjs +1 -1
  51. package/dist-lib/cloud.mjs +1 -1
  52. package/dist-lib/config.cjs +1 -1
  53. package/dist-lib/config.mjs +1 -1
  54. package/dist-lib/detox/index.cjs +195 -63
  55. package/dist-lib/dev-bundle-resolution.cjs +14 -13
  56. package/dist-lib/expo-swift-bundle.cjs +18507 -11835
  57. package/dist-lib/expo-swift-metadata.cjs +4 -1
  58. package/dist-lib/expo-swift-metadata.mjs +3 -1
  59. package/dist-lib/home-paths.cjs +27 -3
  60. package/dist-lib/host/bridge-host.cjs +28373 -24090
  61. package/dist-lib/host/fetch-proxy-handler.cjs +235 -225
  62. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  63. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  64. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  65. package/dist-lib/host/websocket-proxy.cjs +1 -1
  66. package/dist-lib/index.cjs +915 -399
  67. package/dist-lib/jump-to-source-babel.cjs +1 -1
  68. package/dist-lib/jump-to-source-native.cjs +1 -1
  69. package/dist-lib/kotlin-host.cjs +335 -47
  70. package/dist-lib/menu.cjs +13 -1
  71. package/dist-lib/menu.mjs +13 -1
  72. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  73. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  74. package/dist-lib/metro-production-bundle.cjs +1 -1
  75. package/dist-lib/metro-production-bundle.mjs +1 -1
  76. package/dist-lib/metro.cjs +918 -411
  77. package/dist-lib/native-app-identity-project.cjs +703 -283
  78. package/dist-lib/native-app-identity-project.mjs +500 -87
  79. package/dist-lib/native-app-identity.cjs +13 -2
  80. package/dist-lib/native-app-identity.mjs +13 -2
  81. package/dist-lib/native-firebase-metadata.cjs +1 -1
  82. package/dist-lib/native-firebase-metadata.mjs +1 -1
  83. package/dist-lib/plist.cjs +1 -1
  84. package/dist-lib/plist.mjs +1 -1
  85. package/dist-lib/profiles.cjs +5 -2
  86. package/dist-lib/public-brand.cjs +1 -1
  87. package/dist-lib/public-origins-lib-esm.json +28 -23
  88. package/dist-lib/public-origins-lib.json +418 -224
  89. package/dist-lib/react-native-host-modules.cjs +35 -2
  90. package/dist-lib/react-native-host-modules.mjs +35 -2
  91. package/dist-lib/reap-browser.cjs +12 -4
  92. package/dist-lib/scripts/dev-server-scanner.cjs +15 -8
  93. package/dist-lib/sdk.cjs +17 -7
  94. package/dist-lib/sdk.mjs +16 -7
  95. package/dist-lib/skills.cjs +44825 -29141
  96. package/dist-lib/swift-compile.cjs +616 -400
  97. package/dist-lib/swift-compile.mjs +528 -315
  98. package/dist-lib/swift-package.cjs +1 -1
  99. package/dist-lib/swift-package.mjs +1 -1
  100. package/dist-lib/swift-submit.cjs +2 -2
  101. package/dist-lib/swift-submit.mjs +2 -2
  102. package/dist-lib/swift-toolchain.cjs +105 -17
  103. package/dist-lib/swift.cjs +1 -1
  104. package/dist-lib/vite-swift.cjs +4660 -2252
  105. package/dist-lib/vite.cjs +248 -234
  106. package/dist-lib/worklet-executable.cjs +1 -1
  107. package/dist-lib/worklet-executable.mjs +1 -1
  108. package/dist-types/packages/peach-compat/src/stubs/native-seams/react-native-cookies.d.ts +17 -8
  109. package/dist-types/packages/peach-engine/src/engine/canvaskit-renderer.d.ts +1 -0
  110. package/dist-types/packages/peach-engine/src/engine/font-config.d.ts +7 -4
  111. package/dist-types/packages/peach-engine/src/engine/image-loader.d.ts +9 -6
  112. package/dist-types/packages/peach-engine/src/engine/liquid-glass.d.ts +0 -5
  113. package/dist-types/packages/peach-engine/src/engine/memory-counts.d.ts +11 -1
  114. package/dist-types/packages/peach-engine/src/engine/node.d.ts +5 -12
  115. package/dist-types/packages/peach-engine/src/engine/render-damage.d.ts +2 -2
  116. package/dist-types/packages/peach-engine/src/engine/text-first-baseline.d.ts +5 -0
  117. package/dist-types/packages/peach-engine/src/engine/text-paragraph.d.ts +1 -0
  118. package/dist-types/packages/peach-engine/src/engine/types.d.ts +3 -0
  119. package/dist-types/packages/peach-engine/src/native-preview-bundle.d.ts +2 -0
  120. package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +9 -0
  121. package/dist-types/packages/peach-engine/src/render-worker/host-service-protocol.d.ts +3 -0
  122. package/dist-types/packages/peach-engine/src/render-worker/native-ui-commandContract.d.ts +1 -1
  123. package/dist-types/packages/peach-engine/src/render-worker/protocol.d.ts +7 -2
  124. package/dist-types/packages/peach-engine/src/render-worker/shell-protocol.d.ts +5 -0
  125. package/dist-types/packages/peach-engine/src/render-worker/tree-sync-port.d.ts +1 -1
  126. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +36 -2
  127. package/dist-types/packages/peach-engine/src/shell-events.d.ts +1 -0
  128. package/dist-types/packages/peach-globals/src/audioBridgeContract.d.ts +5 -0
  129. package/dist-types/packages/peach-globals/src/index.d.ts +1 -1
  130. package/dist-types/packages/peach-globals/src/keyboardBridgeContract.d.ts +11 -0
  131. package/dist-types/packages/peach-globals/src/shellBridgeContract.d.ts +1 -0
  132. package/dist-types/packages/peach-globals/src/testBridgeContract.d.ts +9 -2
  133. package/dist-types/packages/peach-kit/src/capabilities.d.ts +1 -0
  134. package/kotlin/README.md +3 -0
  135. package/kotlin/sdk.tar.gz +0 -0
  136. package/package.json +1 -1
  137. package/runtime-companion.json +1 -1
  138. package/scripts/dev-server-scanner.ts +12 -25
  139. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACAccount.h +55 -0
  140. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACAccountCredential.h +35 -0
  141. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACAccountStore.h +94 -0
  142. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACAccountType.h +53 -0
  143. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACError.h +37 -0
  144. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/Accounts.h +13 -0
  145. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/AccountsDefines.h +13 -0
  146. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Modules/module.modulemap +5 -0
  147. package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/ASFoundation.h +52 -0
  148. package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/ASWebAuthenticationSession.h +128 -0
  149. package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/ASWebAuthenticationSessionCallback.h +35 -0
  150. package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/AuthenticationServices.h +3 -0
  151. package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Modules/module.modulemap +5 -0
  152. package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFHTTPMessage.h +724 -0
  153. package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFNetwork.h +4 -0
  154. package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFNetworkDefs.h +27 -0
  155. package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Modules/module.modulemap +5 -0
  156. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFURL.h +1301 -0
  157. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.h +3 -1
  158. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLLocationManager.h +21 -50
  159. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLRegion.h +6 -6
  160. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.apinotes +58 -3
  161. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h +711 -46
  162. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIApplication.h +12 -0
  163. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIInterface.h +23 -0
  164. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h +7 -9
  165. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIOrientation.h +14 -0
  166. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIStringDrawing.h +12 -0
  167. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIView.h +14 -0
  168. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIViewAnimating.h +12 -0
  169. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIViewController.h +16 -0
  170. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIWindow.h +2 -0
  171. package/sdk/ios/usr/include/ConditionalMacros.h +619 -0
  172. package/sdk/ios/usr/include/module.modulemap +1 -0
  173. package/sdk/ios/usr/include/objc/objc-sync.h +59 -0
  174. package/sdk/ios/usr/include/os/signpost.h +414 -0
  175. package/sdk/ios/usr/include/os.modulemap +10 -0
  176. package/sdk/ios/usr/include/sys/cdefs.h +5 -0
  177. package/sdk/ios/usr/include/sys/ioccom.h +99 -0
  178. package/sdk/ios/usr/include/sys/syslog.h +236 -0
  179. package/sdk/ios/usr/include/syslog.h +24 -0
  180. package/sdk/ios/wasm/include/errno.h +4 -20
  181. package/sdk/ios/wasm/include/fcntl.h +4 -2
  182. package/sdk/ios/wasm/include/pthread.h +3 -0
  183. package/sdk/ios/wasm/include/setjmp.h +57 -0
  184. package/sdk/ios/wasm/include/stdio.h +24 -0
  185. package/sdk/ios/wasm/include/stdlib.h +32 -7
  186. package/sdk/ios/wasm/include/sys/file.h +7 -0
  187. package/sdk/ios/wasm/include/sys/ioctl.h +6 -0
  188. package/sdk/ios/wasm/include/sys/resource.h +2 -2
  189. package/sdk/ios/wasm/include/sys/syscall.h +9 -0
  190. package/sdk/ios/wasm/include/sys/time.h +10 -0
  191. package/sdk/ios/wasm/include/unistd.h +12 -3
  192. package/sdk/native-hashes.json +4 -3
  193. package/skills/contrast/SKILL.md +2 -1
  194. package/skills/peach-debug/SKILL.md +0 -1
  195. package/skills/peach-perf/SKILL.md +0 -1
  196. package/skills/peach-setup/SKILL.md +0 -1
  197. package/skills/peach-test/SKILL.md +7 -4
  198. package/skills/peach-visual/SKILL.md +0 -1
  199. package/src/admitted-mac-build.ts +3 -0
  200. package/src/android-app-identity.ts +18 -0
  201. package/src/android-autolinking.ts +1 -0
  202. package/src/android-bridge-packages.ts +279 -0
  203. package/src/android-root-module.ts +9 -9
  204. package/src/appPackageContract.ts +83 -0
  205. package/src/bridge-contract.ts +50 -0
  206. package/src/bundle-channel.mjs +41 -6
  207. package/src/cli-runtime.ts +9 -5
  208. package/src/dev-bundle-resolution.ts +7 -27
  209. package/src/dom-source-reference.ts +15 -0
  210. package/src/expo-discovery-cache.ts +134 -26
  211. package/src/expo-kotlin-host.ts +97 -26
  212. package/src/expo-manifest-body.ts +33 -0
  213. package/src/expo-native-workspace.ts +158 -38
  214. package/src/expo-swift-host.ts +350 -75
  215. package/src/expo-swift-ready.ts +5 -1
  216. package/src/expoKotlinContract.ts +12 -2
  217. package/src/expoSwiftContract.ts +10 -0
  218. package/src/generated/swift-c-predefines.json +1 -1
  219. package/src/home-paths.ts +41 -2
  220. package/src/host/app-package-handler.ts +47 -0
  221. package/src/host/bridge-host.ts +8 -0
  222. package/src/host/fetch-proxy-handler.ts +10 -0
  223. package/src/host/staged-host-files.ts +18 -0
  224. package/src/index.ts +3 -0
  225. package/src/kotlin-host.ts +225 -48
  226. package/src/kotlin-instance-source.ts +126 -0
  227. package/src/kotlinSdkContract.ts +2 -1
  228. package/src/menu.ts +14 -0
  229. package/src/native-app-identity-project.ts +7 -2
  230. package/src/native-app-identity.ts +11 -0
  231. package/src/native-firebase-config.ts +24 -1
  232. package/src/native-prebuilt.ts +154 -0
  233. package/src/nitro-adapter.lock.json +270 -270
  234. package/src/nitro-adapter.ts +56 -50
  235. package/src/nitro-bundle.ts +92 -74
  236. package/src/nitro-compile.ts +45 -14
  237. package/src/nitro-dependencies.ts +63 -46
  238. package/src/nitro-source.ts +64 -26
  239. package/src/nitroAdapterContract.ts +146 -98
  240. package/src/nitroContract.ts +71 -21
  241. package/src/react-native-bridge-modules.ts +70 -42
  242. package/src/react-native-host-modules.ts +34 -1
  243. package/src/reactNativeConfigurationContract.ts +14 -0
  244. package/src/reap-browser.ts +15 -3
  245. package/src/sdk.ts +5 -0
  246. package/src/settingsContract.ts +38 -1
  247. package/src/sim-client.ts +4 -1
  248. package/src/storageSnapshotContract.ts +32 -81
  249. package/src/swift-compile.ts +268 -89
  250. package/src/swift-coverage/indexdump.ts +22 -6
  251. package/src/swift-coverage/indexing.ts +4 -4
  252. package/src/swift-coverage/provenance.ts +1 -0
  253. package/src/swift-coverage/sdk.ts +104 -20
  254. package/src/swift-coverage/types.ts +34 -0
  255. package/src/swift-coverage/xcode-asset-symbols.ts +922 -0
  256. package/src/swift-coverage/xcode-assets.ts +89 -131
  257. package/src/swift-coverage/xcode.ts +10 -2
  258. package/src/swift-cxx-reachable.ts +2 -1
  259. package/src/swift-distribution.lock.json +20 -16
  260. package/src/swift-host.ts +98 -22
  261. package/src/swift-icu.ts +1 -1
  262. package/src/swift-link-roots.ts +118 -0
  263. package/src/swift-objc-compile.ts +144 -22
  264. package/src/swift-objc-import.ts +6 -0
  265. package/src/swift-objc-standin.ts +2 -14
  266. package/src/swift-package-manifest.ts +14 -6
  267. package/src/swift-packages.ts +75 -11
  268. package/src/swift-pdf-raster.ts +1 -0
  269. package/src/swift-root-lock.ts +17 -1
  270. package/src/swift-source-pods.ts +2 -10
  271. package/src/swift-standin-emit.ts +597 -57
  272. package/src/swift-standins.ts +599 -56
  273. package/src/swift-submit.ts +7 -1
  274. package/src/swift-toolchain.ts +140 -17
  275. package/src/turbo-bundle.ts +81 -0
  276. package/src/turbo-codegen-intake.ts +91 -0
  277. package/src/turbo-compile.ts +120 -0
  278. package/src/turbo-runtime.lock.json +69 -0
  279. package/src/turbo-source.ts +754 -0
  280. package/src/vite-plugin-one.ts +17 -12
  281. package/src/vite-plugin.ts +28 -15
  282. package/src/xcode-project.ts +223 -22
@@ -9,6 +9,8 @@ import os from 'node:os'
9
9
  import path from 'node:path'
10
10
  import { fileURLToPath } from 'node:url'
11
11
  import { promisify } from 'node:util'
12
+ import { loadRNXAppConfig } from '../cli/app-config'
13
+ import { resolveAppProject } from '../cli/app-project'
12
14
  import { RNX_FORKED_SCRIPT_ENV } from '../cli/internal-child'
13
15
  import { isLoopbackHost } from './backend-origin'
14
16
  import {
@@ -17,7 +19,10 @@ import {
17
19
  writeExpoDiscovery,
18
20
  } from './expo-discovery-cache'
19
21
  import { prepareExpoNativeWorkspace } from './expo-native-workspace'
20
- import { cacheDir } from './home-paths'
22
+ import { COMPILED_EXPO_NATIVE_PACKAGES } from './expoSwiftContract'
23
+ import { cacheDir, swiftCacheDir } from './home-paths'
24
+ import { isRecord } from './is-record'
25
+ import { readExpoConfigAsync } from './native-firebase-config'
21
26
  import { NativePreparationReceipts } from './native-preparation'
22
27
  import {
23
28
  NATIVE_PREPARE_QUERY_PARAM,
@@ -27,6 +32,7 @@ import { collectBridgeModuleSources } from './react-native-bridge-modules'
27
32
  import { swiftBinaryModules } from './swift-binary-modules'
28
33
  import {
29
34
  swiftAvailableModules,
35
+ swiftCodeMask,
30
36
  swiftImportNames,
31
37
  swiftPeachModules,
32
38
  swiftSourceClosure,
@@ -55,12 +61,14 @@ import {
55
61
  } from './swift-standins'
56
62
  import { MAX_SWIFT_COMPILE_FILES, MAX_SWIFT_COMPILE_SOURCE_BYTES } from './swift-submit'
57
63
  import { sourceSwiftCheckout } from './swift-toolchain'
64
+ import type { PeachConfig } from './config'
58
65
  import type {
59
66
  ExpoSwiftSourceUnit,
60
67
  ExpoSwiftCompilationResult,
61
68
  ExpoSwiftPreparationOptions,
62
69
  } from './expoSwiftContract'
63
70
  import type { SwiftPackageBinary } from './swift-packages'
71
+ import type { SwiftStandin } from './swift-standins'
64
72
  import type { SwiftNativeTarget } from './swiftContract'
65
73
  import type { IncomingMessage, ServerResponse } from 'node:http'
66
74
 
@@ -277,8 +285,9 @@ function installSwiftInputTrace(): void {
277
285
  savedFs = saved
278
286
  const prefixes = [
279
287
  path.join(cacheDir(), 'swift-builds'),
288
+ path.join(swiftCacheDir(), 'swift-builds'),
280
289
  path.join(cacheDir(), 'swift-root-locks'),
281
- ]
290
+ ].filter((prefix, index, all) => all.indexOf(prefix) === index)
282
291
  ignoredRoots = prefixes.flatMap((root) => {
283
292
  try {
284
293
  const real = saved.realpathSync(root)
@@ -387,12 +396,13 @@ function nativePreparation(): boolean {
387
396
  )
388
397
  }
389
398
 
390
- function discoveryKey(
399
+ async function discoveryKey(
391
400
  root: string,
392
401
  installedWorkspace: string | undefined,
393
402
  prepareNative: boolean,
394
- ): string {
395
- return `${fs.realpathSync(root)}\0${installedWorkspace ?? ''}\0${prepareNative ? '1' : '0'}`
403
+ ): Promise<string> {
404
+ const config = await loadRNXAppConfig(resolveAppProject(root))
405
+ return `${fs.realpathSync(root)}\0${installedWorkspace ?? ''}\0${prepareNative ? '1' : '0'}\0${JSON.stringify(config)}`
396
406
  }
397
407
 
398
408
  function cloneNativeTarget(target: SwiftNativeTarget): SwiftNativeTarget {
@@ -443,6 +453,49 @@ function synthesizedNativeTarget(
443
453
  }
444
454
  }
445
455
 
456
+ // a deployment entry for a generated stand-in target carries its real clang
457
+ // inputs, so native preparation stages the hand-written module map and
458
+ // headers exactly like a swiftpm clang target. a bare entry fails
459
+ // preparation and the pure-c target compiles as an empty swift module,
460
+ // hiding every c declaration from its swift importers.
461
+ function standinNativeTarget(
462
+ standin: SwiftStandin,
463
+ deploymentTarget: string,
464
+ ): SwiftNativeTarget {
465
+ const prefix = `${SWIFT_STANDINS_DIR}/${standin.module}/`
466
+ const headers = Object.keys(standin.files)
467
+ .filter((file) => /\.(?:h|hpp|hh|hxx)$/.test(file))
468
+ .map((file) => `${prefix}${file}`)
469
+ .sort()
470
+ const modulemap = Object.keys(standin.files).find(
471
+ (file) => file === 'module.modulemap' || file.endsWith('/module.modulemap'),
472
+ )
473
+ const headerDir =
474
+ (modulemap ? path.posix.dirname(`${prefix}${modulemap}`) : null) ??
475
+ commonStandinHeaderDir(prefix, headers) ??
476
+ `${prefix}include`
477
+ return {
478
+ ...synthesizedNativeTarget(standin.module, deploymentTarget),
479
+ headers,
480
+ publicHeaders: headers.filter((file) => file.startsWith(`${headerDir}/`)),
481
+ headerSearchPaths: [headerDir],
482
+ }
483
+ }
484
+
485
+ // the deepest stand-in directory holding every header, or null when the
486
+ // headers span disjoint trees. both paths share the stand-in prefix, so the
487
+ // climb always stops at or under it.
488
+ function commonStandinHeaderDir(prefix: string, headers: string[]): string | null {
489
+ if (headers.length === 0) return null
490
+ let common = path.posix.dirname(headers[0]!)
491
+ for (const header of headers.slice(1)) {
492
+ const dir = path.posix.dirname(header)
493
+ while (dir !== common && !dir.startsWith(`${common}/`))
494
+ common = path.posix.dirname(common)
495
+ }
496
+ return common === prefix.slice(0, -1) || common.startsWith(prefix) ? common : null
497
+ }
498
+
446
499
  // the synthesized executable stands in for the app itself; without a pod of
447
500
  // its own it builds at the minimum resolved floor of the targets it links,
448
501
  // so it runs everywhere its modules run.
@@ -468,6 +521,8 @@ function cloneUnits(units: ExpoSwiftSourceUnit[] | null): ExpoSwiftSourceUnit[]
468
521
  ...unit,
469
522
  classes: unit.classes.slice(),
470
523
  bridgeModules: unit.bridgeModules.slice(),
524
+ appDelegateSubscribers: unit.appDelegateSubscribers.slice(),
525
+ reactDelegateHandlers: unit.reactDelegateHandlers.slice(),
471
526
  frameworks: unit.frameworks.slice(),
472
527
  files: { ...unit.files },
473
528
  ...(unit.nativeFiles ? { nativeFiles: { ...unit.nativeFiles } } : {}),
@@ -537,11 +592,51 @@ function autolinkerAppleFlags(autolinkerManifest: string, appRoot: string) {
537
592
  )
538
593
  const atLeast = (m: number, n: number, p: number) =>
539
594
  major !== m ? major > m : minor !== n ? minor > n : patch >= p
540
- if (atLeast(1, 10, 3))
541
- return { args: ['--platform', 'apple', '--project-root', appRoot], cwd: undefined }
542
- if (atLeast(1, 8, 0))
543
- return { args: ['--platform', 'ios', '--project-root', appRoot], cwd: undefined }
544
- return { args: ['--platform', 'ios'], cwd: appRoot }
595
+ if (atLeast(1, 10, 3)) return ['--platform', 'apple', '--project-root', appRoot]
596
+ if (atLeast(1, 8, 0)) return ['--platform', 'ios', '--project-root', appRoot]
597
+ return ['--platform', 'ios']
598
+ }
599
+
600
+ // only omit a class when its module and every declared view have app-owned
601
+ // answers. an unresolved definition stays native, including partial overrides.
602
+ function configuredExpoSwiftModule(
603
+ files: Record<string, string>,
604
+ className: string,
605
+ registrationName: string | null,
606
+ config: PeachConfig | undefined,
607
+ ): boolean {
608
+ if (!config) return false
609
+ for (const source of Object.values(files)) {
610
+ const code = swiftCodeMask(source)
611
+ const declaration = new RegExp(`\\bclass\\s+${className}\\b[^{}]*\\{`).exec(code)
612
+ if (!declaration) continue
613
+ const start = declaration.index + declaration[0].length
614
+ let depth = 1
615
+ let end = start
616
+ while (end < code.length && depth > 0) {
617
+ if (code[end] === '{') depth++
618
+ else if (code[end] === '}') depth--
619
+ end++
620
+ }
621
+ const body = source.slice(start, end - 1)
622
+ const mask = code.slice(start, end - 1)
623
+ const names = [...body.matchAll(/\bName\s*\(\s*"([A-Za-z_]\w*)"\s*\)/g)].filter(
624
+ (match) => mask.startsWith('Name', match.index),
625
+ )
626
+ if (names.length > 1) return false
627
+ const name = registrationName ?? names[0]?.[1]
628
+ if (!name || !config.nativeModules?.[name]) return false
629
+ const views = [
630
+ ...mask.matchAll(/\bView\s*\(\s*([A-Za-z_]\w*(?:\.[A-Za-z_]\w*)*)\.self\s*\)/g),
631
+ ]
632
+ if ([...mask.matchAll(/\bView\s*\(/g)].length !== views.length) return false
633
+ return views.every(
634
+ (view) =>
635
+ Boolean(config.nativeViews?.[`${name}_${view[1]!.split('.').pop()!}`]) ||
636
+ (views.length === 1 && Boolean(config.nativeViews?.[name])),
637
+ )
638
+ }
639
+ return false
545
640
  }
546
641
 
547
642
  export async function collectExpoSwiftSources(
@@ -559,7 +654,7 @@ export async function collectExpoSwiftSources(
559
654
  )
560
655
  signal?.throwIfAborted()
561
656
  installSwiftInputTrace()
562
- const key = discoveryKey(appRoot, installedWorkspace, prepareNative)
657
+ const key = await discoveryKey(appRoot, installedWorkspace, prepareNative)
563
658
  const cached = discoveryCache.get(key)
564
659
  if (cached && (await witnessMatches(cached.witness))) {
565
660
  signal?.throwIfAborted()
@@ -585,6 +680,7 @@ async function collectExpoSwiftSourcesUncached(
585
680
  console.error(`[expo-swift ${Math.round(performance.now() - started)}ms] ${message}`)
586
681
  signal?.throwIfAborted()
587
682
  appRoot = fs.realpathSync(appRoot)
683
+ const appConfig = await loadRNXAppConfig(resolveAppProject(appRoot))
588
684
  const appRequire = createRequire(path.join(appRoot, 'package.json'))
589
685
  let expoRoot: string | undefined
590
686
  try {
@@ -644,11 +740,13 @@ async function collectExpoSwiftSourcesUncached(
644
740
  // before propagating errors so a failed request leaves no child running.
645
741
  const [searched, resolvedModules] = await Promise.allSettled(
646
742
  ['search', 'resolve'].map((command) =>
647
- run(process.execPath, [cli, command, ...flags.args, '--json'], {
743
+ run(process.execPath, [cli, command, ...flags, '--json'], {
648
744
  timeout: 120_000,
649
745
  maxBuffer: 8 * 1024 * 1024,
650
746
  env: scriptEnv,
651
- cwd: flags.cwd,
747
+ // autolinkers call process.cwd() at startup, which throws when the
748
+ // bridge's inherited cwd was deleted.
749
+ cwd: appRoot,
652
750
  signal,
653
751
  }),
654
752
  ),
@@ -666,6 +764,7 @@ async function collectExpoSwiftSourcesUncached(
666
764
  if (!Array.isArray(resolutions)) throw new Error('invalid Expo Apple resolution')
667
765
  const units: ExpoSwiftSourceUnit[] = []
668
766
  const namespacesSeen = new Set<string>()
767
+ let needsNativeWorkspace = false
669
768
  let bytes = 0
670
769
  let fileCount = 0
671
770
  // native Expo resolves packages by name before generating its Apple provider.
@@ -679,8 +778,13 @@ async function collectExpoSwiftSourcesUncached(
679
778
  if (typeof sourceRoot !== 'string')
680
779
  throw new Error('Expo autolinking entry has no path')
681
780
  const canonical = fs.realpathSync(sourceRoot)
682
- // installed dependency implementations remain with their native seams.
683
- if (canonical.split(path.sep).includes('node_modules')) continue
781
+ // other installed dependencies retain their existing native seams.
782
+ if (
783
+ canonical.split(path.sep).includes('node_modules') &&
784
+ (typeof packageName !== 'string' ||
785
+ !COMPILED_EXPO_NATIVE_PACKAGES.ios.includes(packageName))
786
+ )
787
+ continue
684
788
  // the autolinker read these in a child, so the parent can only stamp them
685
789
  // afterwards. one modified since the child started may be newer than what
686
790
  // the child consumed, and so may a module directory that gained or lost one.
@@ -710,36 +814,22 @@ async function collectExpoSwiftSourcesUncached(
710
814
  resolution && typeof resolution === 'object'
711
815
  ? Reflect.get(resolution, 'pods')
712
816
  : null
713
- if (prepareNative && !installedWorkspace && Array.isArray(pods) && pods.length > 0) {
714
- const discovery = expoDiscoveryKey({
715
- appRoot,
716
- searchText: searched.value.stdout,
717
- resolveText: resolvedText,
718
- signal,
719
- })
720
- const cached = readExpoDiscovery(discovery.key)
721
- if (cached !== undefined) {
722
- report(`reusing cached discovery ${discovery.key.slice(0, 12)}`)
723
- return cached
724
- }
725
- report('discovery cache miss; preparing native workspace')
726
- const prepared = await prepareExpoNativeWorkspace(appRoot, signal)
727
- const discovered = await collectExpoSwiftSources(
728
- prepared.app,
729
- signal,
730
- prepared.workspace,
731
- )
732
- const stored = writeExpoDiscovery({
733
- key: discovery.key,
734
- units: discovered,
735
- sourceRoot: discovery.root,
736
- preparedRoot: prepared.work,
737
- signal,
738
- })
739
- report(stored === true ? 'cached discovery' : `discovery not cached: ${stored}`)
740
- return discovered
817
+ const delegateNames = (key: string): unknown[] => {
818
+ const names =
819
+ resolution && typeof resolution === 'object' ? Reflect.get(resolution, key) : null
820
+ return Array.isArray(names) ? names : []
741
821
  }
742
- if (!Array.isArray(modules) || modules.length === 0) continue
822
+ const subscriberNames = delegateNames('appDelegateSubscribers')
823
+ const handlerNames = delegateNames('reactDelegateHandlers')
824
+ // a package with pods is rediscovered in the prepared workspace, which has no caps.
825
+ const deferredToWorkspace =
826
+ prepareNative && !installedWorkspace && Array.isArray(pods) && pods.length > 0
827
+ if (
828
+ (!Array.isArray(modules) || modules.length === 0) &&
829
+ subscriberNames.length === 0 &&
830
+ handlerNames.length === 0
831
+ )
832
+ continue
743
833
  if (
744
834
  !Array.isArray(namespaces) ||
745
835
  namespaces.length !== 1 ||
@@ -755,8 +845,14 @@ async function collectExpoSwiftSourcesUncached(
755
845
  namespacesSeen.add(namespace)
756
846
  const files: Record<string, string> = {}
757
847
  const frameworks = new Set<string>()
758
- const classes: { name: string; registration: string }[] = []
759
- for (const module of modules) {
848
+ const classes: {
849
+ name: string
850
+ nativeName: string | null
851
+ registration: string | null
852
+ subscriber: string | null
853
+ handler: string | null
854
+ }[] = []
855
+ for (const module of Array.isArray(modules) ? modules : []) {
760
856
  const className =
761
857
  typeof module === 'string'
762
858
  ? module
@@ -777,10 +873,54 @@ async function collectExpoSwiftSourcesUncached(
777
873
  throw new Error(`${sourceRoot}: invalid Expo Apple module descriptor`)
778
874
  classes.push({
779
875
  name: className.split('.').pop()!,
780
- registration: `(${className.includes('.') ? className : `${namespace}.${className}`}.self, ${name === null ? 'nil' : JSON.stringify(name)})`,
876
+ nativeName: name,
877
+ // a class named like its module shadows that module, so only the bare
878
+ // name reaches it; Swift's unqualified lookup finds the class.
879
+ registration: `(${className.includes('.') || className === namespace ? className : `${namespace}.${className}`}.self, ${name === null ? 'nil' : JSON.stringify(name)})`,
880
+ subscriber: null,
881
+ handler: null,
781
882
  })
782
883
  }
884
+ // a delegate class is compiled with its closure like a module class; one
885
+ // class may be both a module and a delegate
886
+ for (const [names, role] of [
887
+ [subscriberNames, 'subscriber'],
888
+ [handlerNames, 'handler'],
889
+ ] as const) {
890
+ for (const className of names) {
891
+ if (
892
+ typeof className !== 'string' ||
893
+ !/^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*$/.test(className)
894
+ )
895
+ throw new Error(`${sourceRoot}: invalid Expo Apple delegate descriptor`)
896
+ const name = className.split('.').pop()!
897
+ const reference = `${className.includes('.') || className === namespace ? className : `${namespace}.${className}`}.self`
898
+ const expression =
899
+ role === 'subscriber'
900
+ ? reference
901
+ : `(packageName: ${JSON.stringify(packageName)}, handler: ${reference})`
902
+ const existing = classes.find((item) => item.name === name)
903
+ if (existing) existing[role] = expression
904
+ else
905
+ classes.push({
906
+ name,
907
+ nativeName: null,
908
+ registration: null,
909
+ subscriber: role === 'subscriber' ? expression : null,
910
+ handler: role === 'handler' ? expression : null,
911
+ })
912
+ }
913
+ }
783
914
  const ios = path.join(canonical, 'ios')
915
+ // an app's own module may share sources with its other native targets
916
+ // through links that stay inside the app; installed packages stay sealed.
917
+ const appOwned = !canonical.split(path.sep).includes('node_modules')
918
+ const withinApp = path.relative(appRoot, canonical)
919
+ const sourceBoundary =
920
+ appOwned && withinApp !== '..' && !withinApp.startsWith(`..${path.sep}`)
921
+ ? appRoot
922
+ : canonical
923
+ const boundaryName = sourceBoundary === appRoot ? 'app root' : 'module root'
784
924
  const directories = new Set<string>()
785
925
  const sources = new Set<string>()
786
926
  const resolveSource = (file: string) => {
@@ -790,13 +930,13 @@ async function collectExpoSwiftSourcesUncached(
790
930
  } catch (cause) {
791
931
  throw new Error(`Cannot resolve Expo Swift source: ${file}`, { cause })
792
932
  }
793
- const relative = path.relative(canonical, target)
933
+ const relative = path.relative(sourceBoundary, target)
794
934
  if (
795
935
  relative === '..' ||
796
936
  relative.startsWith(`..${path.sep}`) ||
797
937
  path.isAbsolute(relative)
798
938
  )
799
- throw new Error(`Expo Swift source escapes module root: ${file} -> ${target}`)
939
+ throw new Error(`Expo Swift source escapes ${boundaryName}: ${file} -> ${target}`)
800
940
  return target
801
941
  }
802
942
  const walk = (dir: string, binary = false) => {
@@ -822,15 +962,16 @@ async function collectExpoSwiftSourcesUncached(
822
962
  const source = linked ?? resolveSource(file)
823
963
  if (sources.has(source)) continue
824
964
  sources.add(source)
825
- const size = fs.statSync(source).size
826
- bytes += size
827
- fileCount++
828
- if (
829
- !installedWorkspace &&
830
- (fileCount > MAX_SWIFT_COMPILE_FILES - 2 ||
831
- bytes > MAX_SWIFT_COMPILE_SOURCE_BYTES)
832
- )
833
- throw new Error('Expo Swift sources exceed compile service caps')
965
+ if (!deferredToWorkspace) {
966
+ bytes += fs.statSync(source).size
967
+ fileCount++
968
+ if (
969
+ !installedWorkspace &&
970
+ (fileCount > MAX_SWIFT_COMPILE_FILES - 2 ||
971
+ bytes > MAX_SWIFT_COMPILE_SOURCE_BYTES)
972
+ )
973
+ throw new Error('Expo Swift sources exceed compile service caps')
974
+ }
834
975
  files[
835
976
  `Sources/${namespace}/${path.relative(ios, file).split(path.sep).join('/')}`
836
977
  ] =
@@ -870,18 +1011,132 @@ async function collectExpoSwiftSourcesUncached(
870
1011
  walk(ios)
871
1012
  walkFrameworks(canonical)
872
1013
  for (const module of classes) {
1014
+ const closure = swiftSourceClosure(files, [module.name])
1015
+ const configured =
1016
+ module.registration !== null &&
1017
+ configuredExpoSwiftModule(closure, module.name, module.nativeName, appConfig)
1018
+ if (configured && !module.subscriber && !module.handler) continue
1019
+ if (Array.isArray(pods) && pods.length > 0) needsNativeWorkspace = true
873
1020
  const unit: ExpoSwiftSourceUnit = {
874
1021
  namespace,
875
1022
  moduleId: `${namespace}.${module.name}`,
876
- classes: [module.registration],
1023
+ classes: module.registration && !configured ? [module.registration] : [],
877
1024
  bridgeModules: [],
878
- files: swiftSourceClosure(files, [module.name]),
1025
+ appDelegateSubscribers: module.subscriber ? [module.subscriber] : [],
1026
+ reactDelegateHandlers: module.handler ? [module.handler] : [],
1027
+ files: closure,
879
1028
  frameworks: [...frameworks],
880
1029
  }
881
1030
  unit.files[EXPO_SWIFT_ENTRY] = expoEntry([unit])
882
1031
  units.push(unit)
883
1032
  }
884
1033
  }
1034
+ if (prepareNative && !installedWorkspace && needsNativeWorkspace) {
1035
+ const discovery = await expoDiscoveryKey({
1036
+ appRoot,
1037
+ searchText: searched.value.stdout,
1038
+ resolveText: resolvedText,
1039
+ configuration: appConfig,
1040
+ signal,
1041
+ })
1042
+ const cached = readExpoDiscovery(discovery.key)
1043
+ if (cached !== undefined) return cached
1044
+ const prepared = await prepareExpoNativeWorkspace(appRoot, signal)
1045
+ const discovered = await collectExpoSwiftSources(
1046
+ prepared.app,
1047
+ signal,
1048
+ prepared.workspace,
1049
+ )
1050
+ const stored = writeExpoDiscovery({
1051
+ key: discovery.key,
1052
+ units: discovered,
1053
+ sourceRoot: discovery.root,
1054
+ preparedRoot: prepared.work,
1055
+ signal,
1056
+ })
1057
+ return typeof stored === 'string' ? discovered : stored
1058
+ }
1059
+ // inline modules belong to the app target, including non-module intent files.
1060
+ // use Expo's scanner so its watched directories and class selection stay native.
1061
+ const config = await readExpoConfigAsync(appRoot)
1062
+ signal?.throwIfAborted()
1063
+ const experiments = config.experiments
1064
+ const inlineConfig = isRecord(experiments) ? experiments.inlineModules : undefined
1065
+ const directories = isRecord(inlineConfig) ? inlineConfig.watchedDirectories : undefined
1066
+ if (
1067
+ directories !== undefined &&
1068
+ (!Array.isArray(directories) ||
1069
+ !directories.every((directory) => typeof directory === 'string'))
1070
+ )
1071
+ throw new Error('invalid Expo inline watched directories')
1072
+ if (directories !== undefined && directories.length > 0) {
1073
+ const inlineResult = await run(
1074
+ process.execPath,
1075
+ [
1076
+ '-e',
1077
+ `
1078
+ const appRoot = process.argv[1];
1079
+ const { getMirrorStateObject } = require(process.argv[2]);
1080
+ getMirrorStateObject({ appRoot, watchedDirectories: JSON.parse(process.argv[3]) })
1081
+ .then(value => process.stdout.write(JSON.stringify(value)));
1082
+ `,
1083
+ appRoot,
1084
+ path.join(path.dirname(autolinker), 'build/inlineModules/inlineModules.js'),
1085
+ JSON.stringify(directories),
1086
+ ],
1087
+ { timeout: 30_000, maxBuffer: 8 * 1024 * 1024, env: scriptEnv, signal },
1088
+ )
1089
+ const inline: unknown = JSON.parse(inlineResult.stdout)
1090
+ if (!inline || typeof inline !== 'object')
1091
+ throw new Error('invalid Expo inline modules')
1092
+ const inlineFiles = Reflect.get(inline, 'files')
1093
+ const inlineClasses = Reflect.get(inline, 'swiftModuleClassNames')
1094
+ if (
1095
+ !Array.isArray(inlineFiles) ||
1096
+ !Array.isArray(inlineClasses) ||
1097
+ !inlineClasses.every(
1098
+ (name) => typeof name === 'string' && /^[A-Za-z_][A-Za-z0-9_]*$/.test(name),
1099
+ )
1100
+ )
1101
+ throw new Error('invalid Expo inline modules')
1102
+ const appFiles: Record<string, string> = {}
1103
+ for (const entry of inlineFiles) {
1104
+ const file: unknown =
1105
+ entry && typeof entry === 'object' ? Reflect.get(entry, 'filePath') : null
1106
+ if (typeof file !== 'string') throw new Error('invalid Expo inline source')
1107
+ if (!file.endsWith('.swift')) continue
1108
+ const relative = path.relative(appRoot, fs.realpathSync(file))
1109
+ if (
1110
+ relative === '..' ||
1111
+ relative.startsWith(`..${path.sep}`) ||
1112
+ path.isAbsolute(relative)
1113
+ )
1114
+ throw new Error(`Expo inline source escapes app root: ${file}`)
1115
+ bytes += fs.statSync(file).size
1116
+ fileCount++
1117
+ if (
1118
+ fileCount > MAX_SWIFT_COMPILE_FILES - 2 ||
1119
+ bytes > MAX_SWIFT_COMPILE_SOURCE_BYTES
1120
+ )
1121
+ throw new Error('Expo Swift sources exceed compile service caps')
1122
+ appFiles[`Sources/PeachExpoApp/Inline/${relative.split(path.sep).join('/')}`] =
1123
+ `import UIKit\n#sourceLocation(file: ${JSON.stringify(file)}, line: 1)\n${fs.readFileSync(file, 'utf8')}`
1124
+ }
1125
+ if (Object.keys(appFiles).length > 0) {
1126
+ const inlineUnit: ExpoSwiftSourceUnit = {
1127
+ namespace: 'PeachExpoApp',
1128
+ moduleId: 'PeachExpoApp',
1129
+ classes: inlineClasses.map((name) => `(${name}.self, nil)`),
1130
+ bridgeModules: [],
1131
+ appDelegateSubscribers: [],
1132
+ reactDelegateHandlers: [],
1133
+ files: appFiles,
1134
+ frameworks: [],
1135
+ }
1136
+ inlineUnit.files[EXPO_SWIFT_ENTRY] = expoEntry([inlineUnit])
1137
+ units.push(inlineUnit)
1138
+ }
1139
+ }
885
1140
  if (units.length === 0) return null
886
1141
  if (installedWorkspace) {
887
1142
  report(`reading installed workspace ${installedWorkspace}`)
@@ -898,9 +1153,13 @@ async function collectExpoSwiftSourcesUncached(
898
1153
  const target = targets.find((item) => item.name === unit.namespace)
899
1154
  const native = input.nativeTargets?.find((item) => item.name === unit.namespace)
900
1155
  if (!target || !native) continue
1156
+ // cocoapods compiles each pod at its own SWIFT_VERSION
1157
+ unit.swiftLanguageMode = target.languageMode
1158
+ // package reads skip node_modules directories, so an installed pod's
1159
+ // unit takes its path below the package that ships it.
901
1160
  const map = (file: string) =>
902
1161
  file.startsWith(`${target.path}/`)
903
- ? `Sources/${unit.namespace}/${file.slice(target.path.length + 1)}`
1162
+ ? `Sources/${unit.namespace}/${file.slice(target.path.length + 1).replace(/^(?:.*\/)?node_modules\//, '')}`
904
1163
  : file
905
1164
  const isDummyUnit = (file: string) =>
906
1165
  /(?:^|\/)Target Support Files\/[^/]+\/[^/]+-dummy\.m$/.test(file)
@@ -999,7 +1258,11 @@ async function collectExpoSwiftSourcesUncached(
999
1258
  if (name.startsWith(`Sources/${namespace}/`)) unit.files[name] = source
1000
1259
  }
1001
1260
  }
1002
- unit.files['Package.swift'] = expoManifest(unit.files)
1261
+ unit.files['Package.swift'] = expoManifest(
1262
+ unit.files,
1263
+ '',
1264
+ languageModes([...included].flatMap((namespace) => byNamespace.get(namespace)!)),
1265
+ )
1003
1266
  }
1004
1267
  return units
1005
1268
  }
@@ -1034,14 +1297,21 @@ function languageModes(units: ExpoSwiftSourceUnit[]): Map<string, number> {
1034
1297
 
1035
1298
  function expoEntry(units: ExpoSwiftSourceUnit[]): string {
1036
1299
  // an Objective-C bridge module registers with no Swift of its own
1037
- const namespaces = [...new Set(units.map((unit) => unit.namespace))].filter(
1038
- (namespace) =>
1300
+ const namespaces = [...new Set(units.map((unit) => unit.namespace))]
1301
+ .filter((namespace) => namespace !== 'PeachExpoApp')
1302
+ .filter((namespace) =>
1039
1303
  units.some((unit) =>
1040
1304
  Object.keys(unit.files).some((file) => file.startsWith(`Sources/${namespace}/`)),
1041
1305
  ),
1042
- )
1306
+ )
1043
1307
  const bridgeModules = units.flatMap((unit) => unit.bridgeModules)
1044
- return `import SwiftUI\nimport ExpoModulesCore\n${bridgeModules.length ? 'import React\n' : ''}${namespaces.map((namespace) => `import ${namespace}`).join('\n')}\n\n@main struct PeachExpoApp: PeachPackage {\n init() { MainActor.assumeIsolated { PeachExpoRuntime.register([${units.flatMap((unit) => unit.classes).join(', ')}])${bridgeModules.length ? `; RCTModuleHost.register([${bridgeModules.join(', ')}])` : ''} } }\n func view(props: JSON) -> PeachExpoNativeView { PeachExpoNativeView(props: props) }\n}\n\n@_expose(wasm, "peach_expo_call")\n@_cdecl("peach_expo_call")\n@MainActor public func peachExpoCall(_ payload: UnsafePointer<UInt8>?, _ length: Int32) -> UnsafeMutablePointer<UInt8>? {\n PeachExpoRuntime.dispatch(payload, length)\n}\n`
1308
+ const subscribers = units.flatMap((unit) => unit.appDelegateSubscribers)
1309
+ const handlers = units.flatMap((unit) => unit.reactDelegateHandlers)
1310
+ const delegates =
1311
+ subscribers.length + handlers.length > 0
1312
+ ? `; PeachExpoRuntime.registerDelegates(subscribers: [${subscribers.join(', ')}], handlers: [${handlers.join(', ')}])`
1313
+ : ''
1314
+ return `import SwiftUI\nimport ExpoModulesCore\n${bridgeModules.length ? 'import React\n' : ''}${namespaces.map((namespace) => `import ${namespace}`).join('\n')}\n\n@main struct PeachExpoApp: PeachPackage {\n init() { MainActor.assumeIsolated { PeachExpoRuntime.register([${units.flatMap((unit) => unit.classes).join(', ')}])${delegates}${bridgeModules.length ? `; RCTModuleHost.register([${bridgeModules.join(', ')}])` : ''} } }\n func view(props: JSON) -> PeachExpoNativeView { PeachExpoNativeView(props: props) }\n}\n\n@_expose(wasm, "peach_expo_call")\n@_cdecl("peach_expo_call")\n@MainActor public func peachExpoCall(_ payload: UnsafePointer<UInt8>?, _ length: Int32) -> UnsafeMutablePointer<UInt8>? {\n PeachExpoRuntime.dispatch(payload, length)\n}\n`
1045
1315
  }
1046
1316
 
1047
1317
  const compiling = new Map<
@@ -1143,7 +1413,7 @@ export async function compileExpoSwiftModules(
1143
1413
  installSwiftInputTrace()
1144
1414
  let key: string
1145
1415
  try {
1146
- key = discoveryKey(root, options.installedWorkspace, nativePreparation())
1416
+ key = await discoveryKey(root, options.installedWorkspace, nativePreparation())
1147
1417
  } catch {
1148
1418
  return compileExpoSwiftModulesTraced(root, base, publishArtifact, options)
1149
1419
  }
@@ -1319,8 +1589,10 @@ async function compileExpoSwiftModulesTraced(
1319
1589
  // a generated shim replaces a prebuilt binary that declares no
1320
1590
  // deployment floor of its own; it inherits its consuming unit's
1321
1591
  // resolved floor so the link compiles every target with real
1322
- // intake versions. without a resolved floor the entry stays
1323
- // absent and the builder keeps refusing the target honestly.
1592
+ // intake versions. the entry also carries the shim's headers and
1593
+ // module map directory, so preparation stages the real clang
1594
+ // module. without a resolved floor the entry stays absent and the
1595
+ // builder keeps refusing the target honestly.
1324
1596
  const deploymentTarget = unit.nativeTargets?.find(
1325
1597
  (item) => item.name === unit.namespace,
1326
1598
  )?.deploymentTarget
@@ -1328,9 +1600,7 @@ async function compileExpoSwiftModulesTraced(
1328
1600
  for (const standin of built.standins) {
1329
1601
  unit.nativeTargets ??= []
1330
1602
  if (!unit.nativeTargets.some((item) => item.name === standin.module))
1331
- unit.nativeTargets.push(
1332
- synthesizedNativeTarget(standin.module, deploymentTarget),
1333
- )
1603
+ unit.nativeTargets.push(standinNativeTarget(standin, deploymentTarget))
1334
1604
  }
1335
1605
  if (linkedLibraries.size > 0)
1336
1606
  libraries.set(
@@ -1518,6 +1788,11 @@ async function compileExpoSwiftModulesTraced(
1518
1788
  line,
1519
1789
  ),
1520
1790
  )
1791
+ // native preparation failures name the target, not a file; they
1792
+ // are input-determined like a source error, so they ride with
1793
+ // them instead of hiding behind the filtered diagnostic.
1794
+ const targetErrors = diagnostic.match(/^error: target .*$/gm) ?? []
1795
+ const unitErrors = [...targetErrors, ...sourceErrors]
1521
1796
  if (
1522
1797
  publishArtifact &&
1523
1798
  (sourceErrors.length === 0 || sourceErrors.length !== errors.length) &&
@@ -1531,17 +1806,17 @@ async function compileExpoSwiftModulesTraced(
1531
1806
  // so no reload would ever reuse its artifact.
1532
1807
  const missing = error instanceof SwiftMissingModulesError
1533
1808
  if (
1534
- (missing || sourceErrors.length > 0) &&
1809
+ (missing || unitErrors.length > 0) &&
1535
1810
  sourceContentStamp(packagePath, module.root) === stamps.get(unit)
1536
1811
  ) {
1537
1812
  failureRecords.set(packagePath, {
1538
1813
  stamp: stamps.get(unit)!,
1539
- diagnostic: missing ? diagnostic : sourceErrors.join('\n'),
1814
+ diagnostic: missing ? diagnostic : unitErrors.join('\n'),
1540
1815
  })
1541
1816
  }
1542
1817
  failures.set(
1543
1818
  unit.moduleId,
1544
- sourceErrors.length ? sourceErrors.join('\n') : diagnostic,
1819
+ unitErrors.length ? unitErrors.join('\n') : diagnostic,
1545
1820
  )
1546
1821
  }
1547
1822
  }