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
@@ -3,7 +3,7 @@ import {
3
3
  isLoopbackHost,
4
4
  LOOPBACK_PROBE_HOSTNAMES,
5
5
  } from './backend-origin'
6
- import { parseExpoManifestBody } from './expo-manifest-body'
6
+ import { parseExpoManifestBody, readExpoManifestFields } from './expo-manifest-body'
7
7
  import {
8
8
  alignLoopbackBundleUrlWithProbe,
9
9
  METRO_BUNDLE_PATH,
@@ -308,34 +308,17 @@ async function probeExpoManifest(
308
308
  }
309
309
 
310
310
  if (!manifest || typeof manifest !== 'object') return { state: 'no-manifest' }
311
- const extra = 'extra' in manifest ? manifest.extra : undefined
312
- const expoClient =
313
- extra && typeof extra === 'object' && 'expoClient' in extra ? extra.expoClient : extra
314
- const client = expoClient && typeof expoClient === 'object' ? expoClient : {}
315
- const launchAsset = 'launchAsset' in manifest ? manifest.launchAsset : undefined
316
- const rawLaunchUrl =
317
- launchAsset &&
318
- typeof launchAsset === 'object' &&
319
- 'url' in launchAsset &&
320
- typeof launchAsset.url === 'string'
321
- ? launchAsset.url
322
- : undefined
311
+ const { launchUrl: rawLaunchUrl, client } = readExpoManifestFields(manifest)
323
312
  const launchUrl = rawLaunchUrl
324
313
  ? alignLoopbackBundleUrlWithProbe(rawLaunchUrl, normalizedBaseUrl)
325
314
  : undefined
326
- const name =
327
- 'name' in client && typeof client.name === 'string' ? client.name : undefined
315
+ const name = typeof client.name === 'string' ? client.name : undefined
328
316
  if (!launchUrl && !name) return { state: 'no-manifest' }
329
317
 
330
- const internal =
331
- '_internal' in client && client._internal && typeof client._internal === 'object'
332
- ? client._internal
333
- : {}
334
318
  const manifestProjectRoot =
335
- 'projectRoot' in internal &&
336
- typeof internal.projectRoot === 'string' &&
337
- internal.projectRoot.length > 0
338
- ? internal.projectRoot
319
+ typeof client._internal?.projectRoot === 'string' &&
320
+ client._internal.projectRoot.length > 0
321
+ ? client._internal.projectRoot
339
322
  : null
340
323
 
341
324
  return {
@@ -346,10 +329,7 @@ async function probeExpoManifest(
346
329
  launchUrl || `${normalizedBaseUrl}${METRO_BUNDLE_PATH}`,
347
330
  ),
348
331
  port,
349
- framework: inferManifestFramework(
350
- launchUrl,
351
- 'sdkVersion' in client ? client.sdkVersion : undefined,
352
- ),
332
+ framework: inferManifestFramework(launchUrl, client.sdkVersion),
353
333
  projectName: name,
354
334
  },
355
335
  }
@@ -0,0 +1,15 @@
1
+ import { createHash } from 'node:crypto'
2
+ import { basename, dirname, join, relative, sep } from 'node:path'
3
+
4
+ export const DOM_SOURCE_ROOT = '/__peach_dom__'
5
+
6
+ // babel's filename is also expo's executable DOM identity. keep the basename
7
+ // for its route checks, but identify its directory without a builder path.
8
+ export function domSourceFilename(projectRoot: string, sourcePath: string): string {
9
+ const directory = relative(projectRoot, dirname(sourcePath)).split(sep).join('/')
10
+ return join(
11
+ DOM_SOURCE_ROOT,
12
+ createHash('sha256').update(directory).digest('hex'),
13
+ basename(sourcePath),
14
+ )
15
+ }
@@ -4,6 +4,9 @@
4
4
  // isolated homes instead of redoing the prepare and the workspace read.
5
5
  // entries address content only; a store that cannot prove its paths refuses
6
6
  // rather than serve bytes another home cannot trust.
7
+ // every unit carries the same headers, so each distinct body is stored once
8
+ // under its digest and units hold references; without that a large discovery
9
+ // exceeds the longest string the runtime can build and no repeat ever hits.
7
10
  import { createHash, randomUUID } from 'node:crypto'
8
11
  import fs from 'node:fs'
9
12
  import { homedir } from 'node:os'
@@ -14,7 +17,7 @@ import { hashExpoWorkspace } from './expo-native-workspace'
14
17
  import { isRecord } from './is-record'
15
18
  import type { ExpoSwiftSourceUnit } from './expoSwiftContract'
16
19
 
17
- const FORMAT = 'expo-discovery-v1'
20
+ const FORMAT = 'expo-discovery-v2'
18
21
 
19
22
  // pipeline files whose bytes change discovery output. resolved beside this
20
23
  // module in source (.ts) and in a built cli (.js); a missing file pins as
@@ -60,16 +63,18 @@ function stable(value: unknown): string {
60
63
  return JSON.stringify(value) ?? 'null'
61
64
  }
62
65
 
63
- export function expoDiscoveryKey(options: {
66
+ export async function expoDiscoveryKey(options: {
64
67
  appRoot: string
65
68
  searchText: string
66
69
  resolveText: string
70
+ configuration?: unknown
67
71
  signal?: AbortSignal
68
- }): { key: string; root: string } {
69
- const { root, hash } = hashExpoWorkspace(options.appRoot, options.signal)
72
+ }): Promise<{ key: string; root: string }> {
73
+ const { root, hash } = await hashExpoWorkspace(options.appRoot, options.signal)
70
74
  const key = createHash('sha256')
71
75
  .update(`${peachPin()}\0${hash}\0`)
72
76
  .update(`${stable(JSON.parse(options.searchText))}\0`)
77
+ .update(`${stable(options.configuration)}\0`)
73
78
  .update(stable(JSON.parse(options.resolveText)))
74
79
  .digest('hex')
75
80
  return { key, root }
@@ -94,6 +99,8 @@ function isExpoSwiftSourceUnit(value: unknown): value is ExpoSwiftSourceUnit {
94
99
  typeof value.moduleId === 'string' &&
95
100
  strings(value.classes) &&
96
101
  strings(value.bridgeModules) &&
102
+ strings(value.appDelegateSubscribers) &&
103
+ strings(value.reactDelegateHandlers) &&
97
104
  stringRecord(value.files) &&
98
105
  strings(value.frameworks) &&
99
106
  (value.nativeTargets === undefined ||
@@ -103,6 +110,33 @@ function isExpoSwiftSourceUnit(value: unknown): value is ExpoSwiftSourceUnit {
103
110
  )
104
111
  }
105
112
 
113
+ // a stored unit holds blob digests where a live unit holds bodies.
114
+ type StoredExpoSwiftSourceUnit = Omit<ExpoSwiftSourceUnit, 'files' | 'nativeFiles'> & {
115
+ files: Record<string, string>
116
+ nativeFiles?: Record<string, string>
117
+ }
118
+
119
+ const digestRecord = (value: unknown): value is Record<string, string> =>
120
+ stringRecord(value) && Object.values(value).every((item) => /^[0-9a-f]{64}$/.test(item))
121
+
122
+ function isStoredUnit(value: unknown): value is StoredExpoSwiftSourceUnit {
123
+ return (
124
+ isRecord(value) &&
125
+ typeof value.namespace === 'string' &&
126
+ typeof value.moduleId === 'string' &&
127
+ strings(value.classes) &&
128
+ strings(value.bridgeModules) &&
129
+ strings(value.appDelegateSubscribers) &&
130
+ strings(value.reactDelegateHandlers) &&
131
+ digestRecord(value.files) &&
132
+ strings(value.frameworks) &&
133
+ (value.nativeTargets === undefined ||
134
+ (Array.isArray(value.nativeTargets) && value.nativeTargets.every(isRecord))) &&
135
+ (value.nativeFiles === undefined || digestRecord(value.nativeFiles)) &&
136
+ (value.swiftLanguageMode === undefined || typeof value.swiftLanguageMode === 'number')
137
+ )
138
+ }
139
+
106
140
  // a hit returns cached units (or a cached empty); anything unreadable or
107
141
  // misshapen misses, never throws: the cache must not break discovery.
108
142
  export function readExpoDiscovery(key: string): ExpoSwiftSourceUnit[] | null | undefined {
@@ -115,9 +149,38 @@ export function readExpoDiscovery(key: string): ExpoSwiftSourceUnit[] | null | u
115
149
  if (!isRecord(parsed) || parsed.format !== FORMAT || parsed.key !== key)
116
150
  return undefined
117
151
  if (parsed.units === null) return null
118
- if (!Array.isArray(parsed.units) || !parsed.units.every(isExpoSwiftSourceUnit))
152
+ if (
153
+ !Array.isArray(parsed.units) ||
154
+ !parsed.units.every(isStoredUnit) ||
155
+ !stringRecord(parsed.blobs)
156
+ )
119
157
  return undefined
120
- return parsed.units
158
+ const blobs = parsed.blobs
159
+ const resolve = (refs: Record<string, string>): Record<string, string> | undefined => {
160
+ const bodies: Record<string, string> = {}
161
+ for (const [name, digest] of Object.entries(refs)) {
162
+ const body = blobs[digest]
163
+ if (body === undefined) return undefined
164
+ bodies[name] = body
165
+ }
166
+ return bodies
167
+ }
168
+ const units: ExpoSwiftSourceUnit[] = []
169
+ for (const stored of parsed.units) {
170
+ const files = resolve(stored.files)
171
+ if (files === undefined) return undefined
172
+ const nativeFiles =
173
+ stored.nativeFiles === undefined ? undefined : resolve(stored.nativeFiles)
174
+ if (stored.nativeFiles !== undefined && nativeFiles === undefined) return undefined
175
+ const unit: ExpoSwiftSourceUnit = {
176
+ ...stored,
177
+ files,
178
+ ...(nativeFiles === undefined ? {} : { nativeFiles }),
179
+ }
180
+ if (!isExpoSwiftSourceUnit(unit)) return undefined
181
+ units.push(unit)
182
+ }
183
+ return units
121
184
  }
122
185
 
123
186
  const sourceLocationLine = /^#sourceLocation\(file: "(.*)", line: 1\)$/
@@ -230,41 +293,86 @@ function rewritePreparedPaths(options: {
230
293
  }
231
294
  rewritten.push({ ...unit, files, frameworks })
232
295
  }
233
- if (JSON.stringify(rewritten).includes(preparedRoot))
234
- return { refuse: 'a prepared path survives the rewrite' }
235
296
  return { units: rewritten }
236
297
  }
237
298
 
238
299
  // stores discovery units (or a cached empty) under their key, addressed by
239
- // content and written atomically. returns true on a store, else the reason the
240
- // entry was refused; cache failures never throw.
300
+ // content and written atomically. returns the units exactly as a later read
301
+ // returns them, so a cold discovery keys the same build as a warm one; else the
302
+ // reason the entry was refused. cache failures never throw.
241
303
  export function writeExpoDiscovery(options: {
242
304
  key: string
243
305
  units: ExpoSwiftSourceUnit[] | null
244
306
  sourceRoot: string
245
307
  preparedRoot: string
246
308
  signal?: AbortSignal
247
- }): true | string {
309
+ }): ExpoSwiftSourceUnit[] | null | string {
248
310
  try {
249
- let units: ExpoSwiftSourceUnit[] | null
250
- if (options.units === null) {
251
- units = null
252
- } else {
253
- const rewritten = rewritePreparedPaths({
254
- units: options.units,
255
- sourceRoot: options.sourceRoot,
256
- preparedRoot: options.preparedRoot,
257
- signal: options.signal,
258
- })
259
- if ('refuse' in rewritten) return rewritten.refuse
260
- units = rewritten.units
261
- }
262
311
  const dir = sharedDir()
263
312
  fs.mkdirSync(dir, { recursive: true })
264
313
  const tmp = path.join(dir, `.${options.key}.${process.pid}.${randomUUID()}.tmp`)
265
- fs.writeFileSync(tmp, JSON.stringify({ format: FORMAT, key: options.key, units }))
314
+ if (options.units === null) {
315
+ fs.writeFileSync(
316
+ tmp,
317
+ JSON.stringify({ format: FORMAT, key: options.key, units: null, blobs: {} }),
318
+ )
319
+ fs.renameSync(tmp, path.join(dir, `${options.key}.json`))
320
+ return null
321
+ }
322
+ const rewritten = rewritePreparedPaths({
323
+ units: options.units,
324
+ sourceRoot: options.sourceRoot,
325
+ preparedRoot: options.preparedRoot,
326
+ signal: options.signal,
327
+ })
328
+ if ('refuse' in rewritten) return rewritten.refuse
329
+ // one blob per distinct body; units keep digests. repeated bodies hash
330
+ // once: string hashes memoize, so a shared body is a cheap map hit.
331
+ const blobs = new Map<string, string>()
332
+ const seen = new Map<string, string>()
333
+ const digestFor = (body: string): string => {
334
+ const known = seen.get(body)
335
+ if (known !== undefined) return known
336
+ const digest = createHash('sha256').update(body).digest('hex')
337
+ seen.set(body, digest)
338
+ blobs.set(digest, body)
339
+ return digest
340
+ }
341
+ const reference = (bodies: Record<string, string>) =>
342
+ Object.fromEntries(
343
+ Object.entries(bodies).map(([name, body]) => [name, digestFor(body)]),
344
+ )
345
+ const stored: StoredExpoSwiftSourceUnit[] = rewritten.units.map((unit) => {
346
+ options.signal?.throwIfAborted()
347
+ return {
348
+ ...unit,
349
+ files: reference(unit.files),
350
+ ...(unit.nativeFiles === undefined
351
+ ? {}
352
+ : { nativeFiles: reference(unit.nativeFiles) }),
353
+ }
354
+ })
355
+ // the surviving-path scan stays on bounded strings: the small reference
356
+ // maps, then each body alone. stringifying whole units here is what used
357
+ // to exceed the longest buildable string on large discoveries.
358
+ if (JSON.stringify(stored).includes(options.preparedRoot))
359
+ return 'a prepared path survives the rewrite'
360
+ for (const body of blobs.values()) {
361
+ options.signal?.throwIfAborted()
362
+ if (body.includes(options.preparedRoot))
363
+ return 'a prepared path survives the rewrite'
364
+ }
365
+ fs.writeFileSync(
366
+ tmp,
367
+ JSON.stringify({
368
+ format: FORMAT,
369
+ key: options.key,
370
+ units: stored,
371
+ blobs: Object.fromEntries(blobs),
372
+ }),
373
+ )
266
374
  fs.renameSync(tmp, path.join(dir, `${options.key}.json`))
267
- return true
375
+ return rewritten.units
268
376
  } catch (error) {
269
377
  if (options.signal?.aborted) throw error
270
378
  return error instanceof Error ? error.message : String(error)
@@ -4,7 +4,14 @@
4
4
  import fs from 'node:fs'
5
5
  import path from 'node:path'
6
6
  import { resolveExpoAndroidAutolinking } from './android-autolinking'
7
+ import {
8
+ androidAppSources,
9
+ selectBridgePackages,
10
+ type BridgePackage,
11
+ type BridgeSelection,
12
+ } from './android-bridge-packages'
7
13
  import { isLoopbackHost } from './backend-origin'
14
+ import { COMPILED_EXPO_NATIVE_PACKAGES } from './expoSwiftContract'
8
15
  import { isRecord } from './is-record'
9
16
  import { peachKotlinModuleRoot } from './kotlin-module'
10
17
  import type { ExpoKotlinCompilationResult } from './expoKotlinContract'
@@ -16,13 +23,15 @@ export interface ExpoKotlinModules {
16
23
  // the registration names Android's ExpoModulesPackageList passes, in order
17
24
  modules: { classifier: string; name: string | null }[]
18
25
  sources: string[]
26
+ // the app's own legacy React Native modules, hosted beside the Expo ones
27
+ bridge: BridgeSelection | null
19
28
  }
20
29
 
21
30
  export async function collectExpoKotlinModules(
22
31
  appRoot: string,
23
32
  ): Promise<ExpoKotlinModules | null> {
24
33
  const modules = await resolveExpoAndroidAutolinking(appRoot)
25
- const result: ExpoKotlinModules = { modules: [], sources: [] }
34
+ const result: ExpoKotlinModules = { modules: [], sources: [], bridge: null }
26
35
  for (const entry of modules) {
27
36
  // plugin-only dependencies have no local Kotlin module project.
28
37
  if (entry.projects === undefined) continue
@@ -36,8 +45,13 @@ export async function collectExpoKotlinModules(
36
45
  )
37
46
  throw new Error('invalid Expo Android project')
38
47
  const sourceDir = fs.realpathSync(project.sourceDir)
39
- // installed dependency implementations remain with their native seams.
40
- if (sourceDir.split(path.sep).includes('node_modules')) continue
48
+ // other installed dependencies retain their existing native seams.
49
+ if (
50
+ sourceDir.split(path.sep).includes('node_modules') &&
51
+ (typeof entry.packageName !== 'string' ||
52
+ !COMPILED_EXPO_NATIVE_PACKAGES.android.includes(entry.packageName))
53
+ )
54
+ continue
41
55
  if (project.modules.length === 0) continue
42
56
  for (const module of project.modules) {
43
57
  if (
@@ -73,36 +87,93 @@ export async function collectExpoKotlinModules(
73
87
  return result.modules.length === 0 ? null : result
74
88
  }
75
89
 
90
+ // the app module's ReactPackage classes the application registers
91
+ async function collectBridgePackages(appRoot: string): Promise<BridgeSelection | null> {
92
+ const app = androidAppSources(appRoot)
93
+ if (
94
+ !app ||
95
+ !app.kotlin.some((file) =>
96
+ /\b(?:Base|Turbo)?ReactPackage\b/.test(fs.readFileSync(file, 'utf8')),
97
+ )
98
+ )
99
+ return null
100
+ const { scanBridgeFiles } = await import('./kotlin-host')
101
+ const files = await scanBridgeFiles(peachKotlinModuleRoot(), app.kotlin)
102
+ const selection = selectBridgePackages(app.applicationId, files, app.java)
103
+ return selection.packages.length === 0 ? null : selection
104
+ }
105
+
76
106
  export async function compileExpoKotlinModules(
77
107
  root: string,
78
108
  origin: string,
79
109
  ): Promise<ExpoKotlinCompilationResult | null> {
80
- const found = await collectExpoKotlinModules(root)
81
- if (!found) return null
82
- const namespaces = found.modules.map(
110
+ const expo = await collectExpoKotlinModules(root)
111
+ const selection = await collectBridgePackages(root)
112
+ if (!expo && !selection) return null
113
+ const modules = expo?.modules ?? []
114
+ const expoNamespaces = modules.map(
83
115
  (module) => module.name ?? module.classifier.split('.').pop()!,
84
116
  )
85
117
  const { expoKotlinArtifact } = await import('./kotlin-host')
86
- try {
87
- const artifact = await expoKotlinArtifact(
88
- root,
89
- peachKotlinModuleRoot(),
90
- origin,
91
- found,
92
- )
93
- return { namespaces, module: artifact, failures: [] }
94
- } catch (error) {
95
- const message = error instanceof Error ? error.message : String(error)
96
- // kotlinc names each failing source line; anything else is the host's
97
- const errors = message.match(/^.+\.kt:\d+:\d+: error:.*$/gm)
98
- if (!errors) throw error
99
- return {
100
- namespaces,
101
- module: null,
102
- failures: namespaces.map((namespace) => ({
103
- namespace,
104
- diagnostic: errors.join('\n'),
105
- })),
118
+ // a package that cannot be hosted, or whose sources fail to compile, is
119
+ // unavailable alone: the rest of the app's modules still link
120
+ const bridgeModules = (selection?.packages ?? []).flatMap((entry) =>
121
+ entry.modules.map((module) => module.name),
122
+ )
123
+ const failures: ExpoKotlinCompilationResult['failures'] = []
124
+ let hosted = selection?.packages ?? []
125
+ const drop = (dropped: typeof hosted, diagnostic: (entry: BridgePackage) => string) => {
126
+ for (const entry of dropped)
127
+ for (const module of entry.modules)
128
+ failures.push({ namespace: module.name, diagnostic: diagnostic(entry) })
129
+ hosted = hosted.filter((entry) => !dropped.includes(entry))
130
+ }
131
+ drop(
132
+ hosted.filter((entry) => entry.unsupported !== null),
133
+ (entry) => entry.unsupported!,
134
+ )
135
+ const result = (module: ExpoKotlinCompilationResult['module']) => ({
136
+ namespaces: [...expoNamespaces, ...bridgeModules],
137
+ module,
138
+ failures,
139
+ bridgeModules,
140
+ })
141
+ for (;;) {
142
+ const sources = [
143
+ ...new Set([...(expo?.sources ?? []), ...hosted.flatMap((entry) => entry.sources)]),
144
+ ]
145
+ if (modules.length === 0 && hosted.length === 0) return result(null)
146
+ try {
147
+ const artifact = await expoKotlinArtifact(root, peachKotlinModuleRoot(), origin, {
148
+ modules,
149
+ sources,
150
+ bridge: selection && { applicationId: selection.applicationId, packages: hosted },
151
+ })
152
+ return result(artifact)
153
+ } catch (error) {
154
+ const message = error instanceof Error ? error.message : String(error)
155
+ // kotlinc names each failing source line; anything else is the host's
156
+ const errors = message.match(/^.+\.kt:\d+:\d+: error:.*$/gm)
157
+ if (!errors) throw error
158
+ const broken = hosted.filter((entry) =>
159
+ entry.sources.some((source) =>
160
+ errors.some((line) => line.startsWith(`${source}:`)),
161
+ ),
162
+ )
163
+ if (broken.length > 0) {
164
+ drop(broken, (entry) =>
165
+ errors
166
+ .filter((line) =>
167
+ entry.sources.some((source) => line.startsWith(`${source}:`)),
168
+ )
169
+ .join('\n'),
170
+ )
171
+ continue
172
+ }
173
+ const diagnostic = errors.join('\n')
174
+ for (const namespace of expoNamespaces) failures.push({ namespace, diagnostic })
175
+ drop(hosted, () => diagnostic)
176
+ return result(null)
106
177
  }
107
178
  }
108
179
  }
@@ -11,3 +11,36 @@ export function parseExpoManifestBody(body: string) {
11
11
  }
12
12
  throw new Error('Expo manifest response has no manifest part')
13
13
  }
14
+
15
+ // the app config fields dev-server discovery reads from a manifest.
16
+ export interface ExpoManifestClient {
17
+ name?: string
18
+ primaryColor?: unknown
19
+ sdkVersion?: unknown
20
+ icon?: unknown
21
+ iconUrl?: unknown
22
+ ios?: { bundleIdentifier?: string; icon?: unknown; iconUrl?: unknown }
23
+ _internal?: { projectRoot?: unknown }
24
+ }
25
+
26
+ export interface ExpoManifestFields {
27
+ // the url the dev server advertises for its entry bundle.
28
+ launchUrl: string | undefined
29
+ client: ExpoManifestClient
30
+ }
31
+
32
+ // two manifest shapes name the entry bundle. SDK 48+ wraps the app config in
33
+ // `extra.expoClient` and names the bundle at `launchAsset.url`. the legacy
34
+ // shape (SDK 47 and older) is the app config itself, with `bundleUrl` at the
35
+ // root; its `extra` is the app's own user config.
36
+ export function readExpoManifestFields(
37
+ manifest: ReturnType<typeof parseExpoManifestBody>,
38
+ ): ExpoManifestFields {
39
+ if (typeof manifest?.bundleUrl === 'string')
40
+ return { launchUrl: manifest.bundleUrl, client: manifest }
41
+ const launchUrl = manifest?.launchAsset?.url
42
+ return {
43
+ launchUrl: typeof launchUrl === 'string' ? launchUrl : undefined,
44
+ client: manifest?.extra?.expoClient || manifest?.extra || {},
45
+ }
46
+ }