peachsim 0.1.1716 → 0.1.1728

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 (234) 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 +82 -822
  8. package/cli/commands/daemon.ts +8 -0
  9. package/cli/commands/detox.ts +3 -0
  10. package/cli/commands/doctor.ts +19 -2
  11. package/cli/commands/inspect/actions.ts +74 -14
  12. package/cli/commands/inspect/core.ts +5 -1
  13. package/cli/commands/inspect/settling.ts +5 -2
  14. package/cli/commands/inspect/wait-ready.ts +6 -0
  15. package/cli/commands/inspect.ts +48 -45
  16. package/cli/commands/kotlin.ts +12 -2
  17. package/cli/commands/package.ts +750 -0
  18. package/cli/commands/serve.ts +6 -0
  19. package/cli/commands/shell-url.ts +834 -0
  20. package/cli/commands/swift.ts +42 -102
  21. package/cli/commands/test.ts +20 -0
  22. package/cli/commands/upload.ts +1 -1
  23. package/cli/device-option.ts +1 -1
  24. package/cli/main.ts +13 -1
  25. package/cli/native-input.ts +199 -0
  26. package/cli/outbound-endpoints.ts +26 -1
  27. package/cli/packaged-app-launcher.ts +95 -0
  28. package/cli/scene-video.ts +13 -6
  29. package/detox/index.ts +187 -23
  30. package/dist-lib/agent-daemon-client.cjs +1 -1
  31. package/dist-lib/agent-events.cjs +1 -1
  32. package/dist-lib/attached-projects.cjs +1 -1
  33. package/dist-lib/auth/shared-session.cjs +1 -1
  34. package/dist-lib/backend-origin.cjs +1 -1
  35. package/dist-lib/beta.cjs +1 -1
  36. package/dist-lib/beta.mjs +1 -1
  37. package/dist-lib/bridge-constants.cjs +1 -1
  38. package/dist-lib/bridge-contract-input.cjs +1 -1
  39. package/dist-lib/bridge-contract-input.mjs +1 -1
  40. package/dist-lib/bridge-contract.cjs +1 -1
  41. package/dist-lib/bridge-contract.mjs +1 -1
  42. package/dist-lib/bundle-channel.cjs +38000 -31658
  43. package/dist-lib/capture-contract.cjs +1 -1
  44. package/dist-lib/capture-contract.mjs +1 -1
  45. package/dist-lib/cloud-contract.cjs +1 -1
  46. package/dist-lib/cloud-contract.mjs +1 -1
  47. package/dist-lib/cloud-test-args.cjs +1 -1
  48. package/dist-lib/cloud-test-args.mjs +1 -1
  49. package/dist-lib/cloud.cjs +1 -1
  50. package/dist-lib/cloud.mjs +1 -1
  51. package/dist-lib/config.cjs +1 -1
  52. package/dist-lib/config.mjs +1 -1
  53. package/dist-lib/detox/index.cjs +184 -60
  54. package/dist-lib/dev-bundle-resolution.cjs +14 -13
  55. package/dist-lib/expo-swift-bundle.cjs +18199 -11834
  56. package/dist-lib/expo-swift-metadata.cjs +4 -1
  57. package/dist-lib/expo-swift-metadata.mjs +3 -1
  58. package/dist-lib/home-paths.cjs +21 -2
  59. package/dist-lib/host/bridge-host.cjs +26509 -23850
  60. package/dist-lib/host/fetch-proxy-handler.cjs +221 -222
  61. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  62. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  63. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  64. package/dist-lib/host/websocket-proxy.cjs +1 -1
  65. package/dist-lib/index.cjs +876 -389
  66. package/dist-lib/jump-to-source-babel.cjs +1 -1
  67. package/dist-lib/jump-to-source-native.cjs +1 -1
  68. package/dist-lib/kotlin-host.cjs +127 -16
  69. package/dist-lib/menu.cjs +7 -1
  70. package/dist-lib/menu.mjs +7 -1
  71. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  72. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  73. package/dist-lib/metro-production-bundle.cjs +1 -1
  74. package/dist-lib/metro-production-bundle.mjs +1 -1
  75. package/dist-lib/metro.cjs +883 -404
  76. package/dist-lib/native-app-identity-project.cjs +694 -280
  77. package/dist-lib/native-app-identity-project.mjs +490 -83
  78. package/dist-lib/native-app-identity.cjs +13 -2
  79. package/dist-lib/native-app-identity.mjs +13 -2
  80. package/dist-lib/native-firebase-metadata.cjs +1 -1
  81. package/dist-lib/native-firebase-metadata.mjs +1 -1
  82. package/dist-lib/plist.cjs +1 -1
  83. package/dist-lib/plist.mjs +1 -1
  84. package/dist-lib/profiles.cjs +1 -1
  85. package/dist-lib/public-brand.cjs +1 -1
  86. package/dist-lib/public-origins-lib-esm.json +28 -23
  87. package/dist-lib/public-origins-lib.json +392 -224
  88. package/dist-lib/react-native-host-modules.cjs +32 -2
  89. package/dist-lib/react-native-host-modules.mjs +32 -2
  90. package/dist-lib/reap-browser.cjs +12 -4
  91. package/dist-lib/scripts/dev-server-scanner.cjs +15 -8
  92. package/dist-lib/sdk.cjs +17 -7
  93. package/dist-lib/sdk.mjs +16 -7
  94. package/dist-lib/skills.cjs +61838 -47851
  95. package/dist-lib/swift-compile.cjs +583 -360
  96. package/dist-lib/swift-compile.mjs +496 -275
  97. package/dist-lib/swift-package.cjs +1 -1
  98. package/dist-lib/swift-package.mjs +1 -1
  99. package/dist-lib/swift-submit.cjs +2 -2
  100. package/dist-lib/swift-submit.mjs +2 -2
  101. package/dist-lib/swift-toolchain.cjs +105 -17
  102. package/dist-lib/swift.cjs +1 -1
  103. package/dist-lib/vite-swift.cjs +4453 -2231
  104. package/dist-lib/vite.cjs +230 -228
  105. package/dist-lib/worklet-executable.cjs +1 -1
  106. package/dist-lib/worklet-executable.mjs +1 -1
  107. package/dist-types/packages/peach-compat/src/stubs/native-seams/react-native-cookies.d.ts +17 -8
  108. package/dist-types/packages/peach-engine/src/engine/canvaskit-renderer.d.ts +1 -0
  109. package/dist-types/packages/peach-engine/src/engine/image-loader.d.ts +7 -5
  110. package/dist-types/packages/peach-engine/src/engine/memory-counts.d.ts +3 -1
  111. package/dist-types/packages/peach-engine/src/engine/node.d.ts +1 -11
  112. package/dist-types/packages/peach-engine/src/engine/types.d.ts +3 -0
  113. package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +9 -0
  114. package/dist-types/packages/peach-engine/src/render-worker/host-service-protocol.d.ts +3 -0
  115. package/dist-types/packages/peach-engine/src/render-worker/native-ui-commandContract.d.ts +1 -1
  116. package/dist-types/packages/peach-engine/src/render-worker/shell-protocol.d.ts +4 -0
  117. package/dist-types/packages/peach-engine/src/render-worker/tree-sync-port.d.ts +1 -1
  118. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +23 -1
  119. package/dist-types/packages/peach-engine/src/shell-events.d.ts +1 -0
  120. package/dist-types/packages/peach-globals/src/audioBridgeContract.d.ts +5 -0
  121. package/dist-types/packages/peach-globals/src/index.d.ts +1 -1
  122. package/dist-types/packages/peach-globals/src/keyboardBridgeContract.d.ts +11 -0
  123. package/dist-types/packages/peach-globals/src/shellBridgeContract.d.ts +1 -0
  124. package/dist-types/packages/peach-globals/src/testBridgeContract.d.ts +9 -2
  125. package/package.json +1 -1
  126. package/runtime-companion.json +1 -1
  127. package/scripts/dev-server-scanner.ts +12 -25
  128. package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/ASFoundation.h +52 -0
  129. package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/ASWebAuthenticationSession.h +128 -0
  130. package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/ASWebAuthenticationSessionCallback.h +35 -0
  131. package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/AuthenticationServices.h +3 -0
  132. package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Modules/module.modulemap +5 -0
  133. package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFHTTPMessage.h +724 -0
  134. package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFNetwork.h +4 -0
  135. package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFNetworkDefs.h +27 -0
  136. package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Modules/module.modulemap +5 -0
  137. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFURL.h +1301 -0
  138. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.h +2 -0
  139. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLLocationManager.h +21 -50
  140. package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLRegion.h +6 -6
  141. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h +75 -9
  142. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIApplication.h +12 -0
  143. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIInterface.h +23 -0
  144. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h +7 -9
  145. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIOrientation.h +14 -0
  146. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIStringDrawing.h +12 -0
  147. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIView.h +14 -0
  148. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIViewAnimating.h +12 -0
  149. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIViewController.h +16 -0
  150. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIWindow.h +2 -0
  151. package/sdk/ios/usr/include/ConditionalMacros.h +619 -0
  152. package/sdk/ios/usr/include/module.modulemap +1 -0
  153. package/sdk/ios/usr/include/objc/objc-sync.h +59 -0
  154. package/sdk/ios/usr/include/os.modulemap +5 -0
  155. package/sdk/ios/usr/include/sys/cdefs.h +5 -0
  156. package/sdk/ios/usr/include/sys/ioccom.h +99 -0
  157. package/sdk/ios/usr/include/sys/syslog.h +236 -0
  158. package/sdk/ios/usr/include/syslog.h +24 -0
  159. package/sdk/ios/wasm/include/fcntl.h +4 -2
  160. package/sdk/ios/wasm/include/stdio.h +24 -0
  161. package/sdk/ios/wasm/include/stdlib.h +32 -7
  162. package/sdk/ios/wasm/include/sys/file.h +7 -0
  163. package/sdk/ios/wasm/include/sys/ioctl.h +6 -0
  164. package/sdk/ios/wasm/include/sys/syscall.h +9 -0
  165. package/sdk/ios/wasm/include/sys/time.h +10 -0
  166. package/sdk/ios/wasm/include/unistd.h +12 -3
  167. package/sdk/native-hashes.json +1 -0
  168. package/skills/contrast/SKILL.md +2 -1
  169. package/skills/peach-test/SKILL.md +7 -3
  170. package/src/admitted-mac-build.ts +3 -0
  171. package/src/android-app-identity.ts +18 -0
  172. package/src/android-root-module.ts +9 -9
  173. package/src/appPackageContract.ts +81 -0
  174. package/src/bridge-contract.ts +50 -0
  175. package/src/bundle-channel.mjs +21 -4
  176. package/src/dev-bundle-resolution.ts +7 -27
  177. package/src/dom-source-reference.ts +15 -0
  178. package/src/expo-discovery-cache.ts +127 -23
  179. package/src/expo-manifest-body.ts +33 -0
  180. package/src/expo-native-workspace.ts +38 -13
  181. package/src/expo-swift-host.ts +264 -62
  182. package/src/expoSwiftContract.ts +3 -0
  183. package/src/generated/swift-c-predefines.json +1 -1
  184. package/src/home-paths.ts +35 -1
  185. package/src/host/app-package-handler.ts +47 -0
  186. package/src/host/bridge-host.ts +3 -0
  187. package/src/host/staged-host-files.ts +18 -0
  188. package/src/index.ts +3 -0
  189. package/src/kotlin-host.ts +21 -18
  190. package/src/kotlin-instance-source.ts +126 -0
  191. package/src/menu.ts +7 -0
  192. package/src/native-app-identity-project.ts +7 -2
  193. package/src/native-app-identity.ts +11 -0
  194. package/src/native-firebase-config.ts +24 -1
  195. package/src/nitro-adapter.lock.json +268 -268
  196. package/src/nitro-bundle.ts +8 -0
  197. package/src/nitro-compile.ts +35 -9
  198. package/src/nitro-dependencies.ts +21 -19
  199. package/src/nitro-source.ts +4 -0
  200. package/src/nitroContract.ts +7 -0
  201. package/src/react-native-bridge-modules.ts +68 -42
  202. package/src/react-native-host-modules.ts +31 -1
  203. package/src/reactNativeConfigurationContract.ts +14 -0
  204. package/src/reap-browser.ts +15 -3
  205. package/src/sdk.ts +5 -0
  206. package/src/settingsContract.ts +27 -1
  207. package/src/sim-client.ts +4 -1
  208. package/src/storageSnapshotContract.ts +3 -0
  209. package/src/swift-compile.ts +221 -41
  210. package/src/swift-coverage/provenance.ts +1 -0
  211. package/src/swift-coverage/xcode-asset-symbols.ts +922 -0
  212. package/src/swift-coverage/xcode-assets.ts +89 -131
  213. package/src/swift-coverage/xcode.ts +1 -1
  214. package/src/swift-cxx-reachable.ts +2 -1
  215. package/src/swift-distribution.lock.json +14 -13
  216. package/src/swift-host.ts +95 -22
  217. package/src/swift-icu.ts +1 -1
  218. package/src/swift-link-roots.ts +118 -0
  219. package/src/swift-objc-compile.ts +144 -22
  220. package/src/swift-objc-import.ts +6 -0
  221. package/src/swift-objc-standin.ts +2 -14
  222. package/src/swift-package-manifest.ts +14 -6
  223. package/src/swift-packages.ts +75 -11
  224. package/src/swift-pdf-raster.ts +1 -0
  225. package/src/swift-root-lock.ts +17 -1
  226. package/src/swift-source-pods.ts +2 -10
  227. package/src/swift-standin-emit.ts +592 -57
  228. package/src/swift-standins.ts +430 -49
  229. package/src/swift-submit.ts +3 -1
  230. package/src/swift-toolchain.ts +140 -17
  231. package/src/turbo-codegen-intake.ts +91 -0
  232. package/src/vite-plugin-one.ts +13 -9
  233. package/src/vite-plugin.ts +28 -15
  234. package/src/xcode-project.ts +223 -22
@@ -2,23 +2,18 @@ import { spawn, spawnSync } from 'node:child_process'
2
2
  import fs from 'node:fs'
3
3
  import http from 'node:http'
4
4
  import https from 'node:https'
5
- import { createRequire } from 'node:module'
6
5
  import net from 'node:net'
7
6
  import os from 'node:os'
8
7
  import path from 'node:path'
9
8
  import { WebSocket } from 'ws'
10
- import { pinSharedListenerScan, probePort } from '../../scripts/dev-server-scanner'
11
9
  import { formatLockOwner } from '../../src/agent-identity'
12
- import { readAndroidLauncherRootModuleName } from '../../src/android-root-module'
13
10
  import { ANDROID_ROOT_MODULE_QUERY_PARAM } from '../../src/androidRootModuleContract'
14
11
  import { isAppDeepLinkTarget, openAppUrl } from '../../src/app-url'
15
- import { isLoopbackHost, loopbackOriginOf } from '../../src/backend-origin'
16
- import { resolveSootsimShellBaseUrlForBridgePort } from '../../src/bridge-constants'
12
+ import { isLoopbackHost } from '../../src/backend-origin'
17
13
  import { getCliRuntime } from '../../src/cli-runtime.ts'
18
14
  import {
19
15
  applyPeachConfigToUrl,
20
16
  mergePeachConfig,
21
- PEACH_CONFIG_QUERY_PARAM,
22
17
  readPeachConfigFromSearchParams,
23
18
  type PeachConfig,
24
19
  } from '../../src/config'
@@ -27,10 +22,7 @@ import {
27
22
  desktopHostPlatform,
28
23
  headlessHostCommand,
29
24
  } from '../../src/desktop-host-delivery'
30
- import {
31
- resolveConnectionInput,
32
- type ResolvedDevBundle,
33
- } from '../../src/dev-bundle-resolution'
25
+ import { type ResolvedDevBundle } from '../../src/dev-bundle-resolution'
34
26
  import { isDeviceModel, type DeviceModel } from '../../src/device-catalog.ts'
35
27
  import { readProjectDotEnv } from '../../src/dot-env'
36
28
  import { awaitStampedExpoSwiftReady } from '../../src/expo-swift-ready'
@@ -48,59 +40,21 @@ import {
48
40
  runtimeDir,
49
41
  runtimesDir,
50
42
  } from '../../src/home-paths'
51
- import { projectLoopbackUrl } from '../../src/host/loopback-ports'
52
- import {
53
- isStagedHostFileRequest,
54
- stageHostBytes,
55
- stageHostFile,
56
- stageHostLaunchMetadata,
57
- } from '../../src/host/staged-host-files'
58
- import { readInstalledNativePackageVersions } from '../../src/installed-package-versions'
43
+ import { stageHostBytes } from '../../src/host/staged-host-files'
59
44
  import { LAUNCH_METADATA_QUERY_PARAM } from '../../src/launchMetadataContract'
60
45
  import { detectBundleModeFromText } from '../../src/metro-production-bundle'
61
- import { resolveMetroProjectRoot } from '../../src/metro-project-root'
62
- import {
63
- canExtractNativeAppIdentity,
64
- createNativeAppIdentityHeader,
65
- } from '../../src/native-app-identity'
66
- import {
67
- NativeAppTargetSelectionError,
68
- readNativeAppIdentityFromProject,
69
- } from '../../src/native-app-identity-project'
70
46
  import { applyHotMode } from '../../src/native-dev-bundle-url'
71
- import {
72
- readExpoConfigAsync,
73
- readNativeFirebaseConfig,
74
- } from '../../src/native-firebase-config'
75
47
  import { isProcessRunning } from '../../src/process-liveness'
76
48
  import { ensureProfile } from '../../src/profiles'
77
- import { rnxPublicBrand } from '../../src/public-brand'
78
49
  import {
79
50
  resolveDevCheckoutRuntimeRoot,
80
51
  runtimeVersionHostname,
81
52
  } from '../../src/runtime-assets'
82
53
  import { rnxRuntime } from '../../src/runtime-delivery'
83
- import {
84
- PEACH_SIMULATOR_SHELL_FILE,
85
- isPeachSimulatorDocumentPath,
86
- } from '../../src/simulator-route'
87
54
  import { sleep } from '../../src/sleep'
88
- import { stageAppBundleResources } from '../app-bundle-resources'
89
- import { discoverAppCatalog } from '../app-catalog'
90
55
  import { loadRNXAppConfig } from '../app-config'
91
- import { discoverNativeLinkedAppFonts } from '../app-fonts'
92
- import {
93
- findExpoAppConfig,
94
- resolveAppProject,
95
- type ResolvedAppProject,
96
- } from '../app-project'
97
- import {
98
- type DiscoveredAppSplashSpec,
99
- discoverConfigPluginAppSplash,
100
- discoverOneNativeAppSplash,
101
- encodeAppSplashWire,
102
- splashImageUrls,
103
- } from '../app-splash'
56
+ import { findExpoAppConfig } from '../app-project'
57
+ import { discoverOneNativeAppSplash } from '../app-splash'
104
58
  import { printBridgeFailureDiagnostics } from '../bridge-diagnostics'
105
59
  import {
106
60
  assertNoPendingOpen,
@@ -130,15 +84,25 @@ import {
130
84
  parseBridgeCliArgs,
131
85
  printBridgeWorldNotice,
132
86
  resolveBridgePortForPin,
133
- resolveBridgeWorld,
134
87
  worldForBridgePort,
135
88
  type BridgeSimInfo,
136
89
  type ParsedBridgeCliArgs,
90
+ type WsBridge,
137
91
  } from '../ws-bridge'
138
- import { readNativeProjectRenderer } from './detect'
139
92
  import { inspectDescribe, inspectReadySnapshot, waitReadyReason } from './inspect/core'
140
93
  import { waitForSimReady } from './inspect/shared'
141
94
  import { runInstallDesktop } from './install-desktop'
95
+ import {
96
+ buildShellUrl,
97
+ looksLikeShellPathTarget,
98
+ looksLikeSootsimUrl,
99
+ resolveAppProjectForBundleUrl,
100
+ resolveConnectionInputForCli,
101
+ resolveShellBaseUrlForBridgePort,
102
+ shouldResolveBundleTargetInCli,
103
+ startExpoConfigRead,
104
+ type BuildShellUrlOptions,
105
+ } from './shell-url'
142
106
  import { hasInstalledPeachSkills } from './skills'
143
107
  import type { DriverId, DriverLaunchResult } from '../drivers/types'
144
108
 
@@ -179,19 +143,6 @@ const OPEN_BRIDGE_SILENCE_MS = 30_000
179
143
  // live daemon as unreachable.
180
144
  const LIVE_BRIDGE_HANDSHAKE_TIMEOUT_MS = 2_000
181
145
 
182
- // built-in shell apps use pathname-based routing, not ?bundle= params
183
- const SHELL_APPS: Record<string, string> = {
184
- rn: '/rn',
185
- connectrn: '/rn',
186
- 'connect-rn': '/rn',
187
- clock: '/app/clock',
188
- 'native-ui': '/app/native-ui',
189
- tamagui: '/app/tamagui',
190
- settings: '/app/settings',
191
- photos: '/app/photos',
192
- camera: '/app/camera',
193
- }
194
-
195
146
  function parsePositiveIntegerEnv(name: string): number | null {
196
147
  const value = process.env[name]?.trim()
197
148
  if (!value) return null
@@ -261,10 +212,6 @@ export function resolveDriverHeadless(args: string[], driverId: string): boolean
261
212
  return false
262
213
  }
263
214
 
264
- function normalizeKnownTarget(target: string): string {
265
- return target.trim()
266
- }
267
-
268
215
  type BridgeOpenGate = {
269
216
  newShell: boolean
270
217
  simId?: string
@@ -633,71 +580,6 @@ function canConnectToBridge(
633
580
  return bridgeHandshake(port, timeoutMs, signal).then((result) => result === 'open')
634
581
  }
635
582
 
636
- function looksLikeSootsimUrl(target: string): boolean {
637
- try {
638
- const url = new URL(target)
639
- const pathname = url.pathname.replace(/\/+$/, '') || '/'
640
- return (
641
- url.searchParams.has('open') ||
642
- url.searchParams.has('port') ||
643
- url.searchParams.has('bundle') ||
644
- url.searchParams.has('demo') ||
645
- url.searchParams.has('test') ||
646
- url.searchParams.has('case') ||
647
- url.pathname.includes(PEACH_SIMULATOR_SHELL_FILE) ||
648
- isPeachSimulatorDocumentPath(pathname) ||
649
- pathname === '/sootsim' ||
650
- url.pathname === '/__peachsim' ||
651
- url.pathname === '/__peachsim/' ||
652
- pathname === '/rn' ||
653
- /^\/rn\/[^/]+$/i.test(pathname) ||
654
- /^\/app\/[^/]+$/i.test(pathname) ||
655
- pathname === '/__peachsim/rn' ||
656
- /^\/__peachsim\/rn\/[^/]+$/i.test(pathname) ||
657
- /^\/__peachsim\/app\/[^/]+$/i.test(pathname)
658
- )
659
- } catch {
660
- return false
661
- }
662
- }
663
-
664
- function looksLikeShellPathTarget(target: string): boolean {
665
- try {
666
- const url = new URL(target, 'http://sootsim.local')
667
- if (url.origin !== 'http://sootsim.local') return false
668
- const pathname = url.pathname.replace(/\/+$/, '') || '/'
669
- return (
670
- pathname === '/rn' ||
671
- /^\/rn\/[^/]+$/i.test(pathname) ||
672
- /^\/app\/[^/]+$/i.test(pathname) ||
673
- pathname === '/__peachsim/rn' ||
674
- /^\/__peachsim\/rn\/[^/]+$/i.test(pathname) ||
675
- /^\/__peachsim\/app\/[^/]+$/i.test(pathname)
676
- )
677
- } catch {
678
- return false
679
- }
680
- }
681
-
682
- function buildShellPathOpenUrl(target: string, baseUrl: string): string {
683
- const targetUrl = new URL(target, 'http://sootsim.local')
684
- const url = new URL(baseUrl)
685
- const prefix = getShellRoutePrefix(url.pathname)
686
- const routePath = targetUrl.pathname.startsWith('/__peachsim/')
687
- ? targetUrl.pathname.slice('/__peachsim'.length)
688
- : targetUrl.pathname
689
-
690
- url.pathname = `${prefix}${routePath}`
691
- const baseDemo = url.searchParams.getAll('demo')
692
- url.search = targetUrl.search
693
- // demo also sets embed chrome around native routes; a target can override it.
694
- if (!targetUrl.searchParams.has('demo')) {
695
- for (const demo of baseDemo) url.searchParams.append('demo', demo)
696
- }
697
- url.hash = targetUrl.hash
698
- return url.toString()
699
- }
700
-
701
583
  // peach share/preview/build links (e.g. https://peachsim.com/preview/<id>,
702
584
  // https://contrast.dev/build/<owner>/<repo>/<branch>) are full player pages
703
585
  // served by the Contrast app — NOT Metro bundles and NOT driveable shell sims.
@@ -721,90 +603,6 @@ function looksLikeSootSimShareUrl(target: string): boolean {
721
603
  }
722
604
  }
723
605
 
724
- function localBasePort(target: string): number | null {
725
- try {
726
- const url = new URL(target.startsWith('http') ? target : `http://${target}`)
727
- const pathname = url.pathname || '/'
728
- if ((pathname !== '/' && pathname !== '') || url.search || url.hash) return null
729
- if (!isLoopbackHost(url.hostname)) return null
730
- const port = url.port ? Number(url.port) : url.protocol === 'https:' ? 443 : 80
731
- return Number.isFinite(port) && port > 0 ? port : null
732
- } catch {
733
- return null
734
- }
735
- }
736
-
737
- // a dev server started alongside open connect may still be booting when the
738
- // first probe lands. retry briefly so staging does not fail on a server that
739
- // becomes probe-ready a few seconds later.
740
- const DEV_BUNDLE_RESOLVE_ATTEMPTS = 15
741
- const DEV_BUNDLE_RESOLVE_INTERVAL_MS = 1000
742
-
743
- async function resolveConnectionInputForCli(
744
- target: string,
745
- signal?: AbortSignal,
746
- ): Promise<ResolvedDevBundle> {
747
- const normalized = normalizeKnownTarget(target)
748
- const registeredPort = /^\d+$/.test(normalized)
749
- ? Number(normalized)
750
- : localBasePort(normalized)
751
-
752
- console.log(` resolving native bundle for ${normalized} (waiting for the dev server)…`)
753
- let lastError: Error | null = null
754
- const releaseListenerScan = pinSharedListenerScan()
755
- try {
756
- for (let attempt = 0; attempt < DEV_BUNDLE_RESOLVE_ATTEMPTS; attempt++) {
757
- signal?.throwIfAborted()
758
- let resolutionTarget = normalized
759
- if (registeredPort && registeredPort > 0) {
760
- const discovered = await probePort(registeredPort)
761
- // a provisional bundle URL is enough to LIST the server but not to open
762
- // it; resolveConnectionInput joins the scanner's pending manifest with
763
- // the server response instead of starting the same work again.
764
- if (discovered && !discovered.bundleUrlProvisional) {
765
- return {
766
- bundleUrl: projectLoopbackUrl(discovered.bundleUrl),
767
- port: discovered.port,
768
- framework: discovered.framework,
769
- projectName: discovered.projectName,
770
- manifestProjectRoot: discovered.manifestProjectRoot,
771
- }
772
- }
773
- // keep the scanner's answering address and join its manifest request.
774
- // probing both loopback families again duplicates cold config work.
775
- if (discovered?.bundleUrlProvisional && /^\d+$/.test(normalized)) {
776
- resolutionTarget = new URL(discovered.bundleUrl).origin
777
- }
778
- }
779
-
780
- try {
781
- const resolved = await resolveConnectionInput(resolutionTarget, undefined, {
782
- waitMs: null,
783
- signal,
784
- })
785
- return { ...resolved, bundleUrl: projectLoopbackUrl(resolved.bundleUrl) }
786
- } catch (error) {
787
- if (
788
- !(error instanceof Error) ||
789
- !error.message.startsWith('could not resolve a native bundle')
790
- ) {
791
- throw error
792
- }
793
- lastError = error
794
- }
795
- await sleep(DEV_BUNDLE_RESOLVE_INTERVAL_MS)
796
- }
797
- throw (
798
- lastError ??
799
- new Error(
800
- 'could not resolve a native bundle for ' + normalized + ' after retrying.',
801
- )
802
- )
803
- } finally {
804
- releaseListenerScan()
805
- }
806
- }
807
-
808
606
  // a dev server builds an app's graph on the first request for its bundle and
809
607
  // finishes the build after that request goes away. `peach open` asks as soon as
810
608
  // the bundle is resolved, so the build overlaps bridge, host and runtime boot;
@@ -821,45 +619,13 @@ function startDevServerBuild(bundleUrl: string): void {
821
619
  request.on('error', () => {})
822
620
  }
823
621
 
824
- function getShellRoutePrefix(pathname: string): string {
825
- const normalized = pathname.replace(/\/+$/, '') || '/'
826
- if (normalized === '/__peachsim' || normalized.startsWith('/__peachsim/')) {
827
- return '/__peachsim'
828
- }
829
- return ''
830
- }
831
-
832
- function buildConnectOpenUrl(target: string, baseUrl: string): string {
833
- const normalizedTarget = normalizeKnownTarget(target)
834
- const url = new URL(baseUrl)
835
- const prefix = getShellRoutePrefix(url.pathname)
836
-
837
- url.pathname = `${prefix}/rn`
838
- url.searchParams.delete('bundle')
839
- url.searchParams.delete('app')
840
- url.searchParams.delete('open')
841
- url.searchParams.delete('port')
842
-
843
- if (/^\d+$/.test(normalizedTarget)) {
844
- url.pathname = `${prefix}/rn/${normalizedTarget}`
845
- } else {
846
- url.pathname = `${prefix}/rn`
847
- url.searchParams.set('open', normalizedTarget)
622
+ async function readSimDevice(bridge: WsBridge, simId: string): Promise<string | null> {
623
+ try {
624
+ const sim = (await bridge.listSims()).find((candidate) => candidate.id === simId)
625
+ return sim?.url ? new URL(sim.url).searchParams.get('device') : null
626
+ } finally {
627
+ bridge.close()
848
628
  }
849
-
850
- return url.toString()
851
- }
852
-
853
- function shouldResolveBundleTargetInCli(target: string): boolean {
854
- // a shell url already names its app; resolving it as a dev server turned
855
- // http://localhost:5173/?demo=x into the native app /rn/443.
856
- if (looksLikeSootsimUrl(target)) return false
857
- const normalizedTarget = normalizeKnownTarget(target)
858
- if (/^\d+$/.test(normalizedTarget)) return true
859
- if (/^https?:\/\//i.test(normalizedTarget)) return true
860
- return /^(localhost|127\.0\.0\.1|\[::1\]|[^/]+\.localhost):\d+(?:\/.*)?$/i.test(
861
- normalizedTarget,
862
- )
863
629
  }
864
630
 
865
631
  // a built bundle on disk (`peach open ./dist/ios.js`). the bridge serves a
@@ -870,14 +636,6 @@ function prebuiltBundleFile(target: string): string | null {
870
636
  return fs.statSync(file, { throwIfNoEntry: false })?.isFile() ? file : null
871
637
  }
872
638
 
873
- // the nearest app above the bundle supplies its fonts, splash and identity
874
- function appDirAbove(file: string): string | undefined {
875
- for (let dir = path.dirname(file); dir !== path.dirname(dir); dir = path.dirname(dir)) {
876
- if (resolveAppProject(dir)) return dir
877
- }
878
- return undefined
879
- }
880
-
881
639
  // the url names the bundle's own mode, so the engine boots the matching
882
640
  // tenant first instead of restarting into it after the fetch.
883
641
  export async function stagePrebuiltBundle(
@@ -898,11 +656,11 @@ export async function stagePrebuiltBundle(
898
656
  'application/javascript',
899
657
  )
900
658
  const { stageMetroBundleAssets } = await import('../metro-bundle-assets')
901
- await stageMetroBundleAssets(file, source, `http://localhost:${bridgePort}`)
659
+ await stageMetroBundleAssets(file, source, `http://127.0.0.1:${bridgePort}`)
902
660
  const url = new URL(
903
661
  stageHostBytes(
904
662
  prepared === source ? bytes : Buffer.from(prepared, 'utf8'),
905
- `http://localhost:${bridgePort}`,
663
+ `http://127.0.0.1:${bridgePort}`,
906
664
  path.extname(file),
907
665
  ),
908
666
  )
@@ -910,26 +668,6 @@ export async function stagePrebuiltBundle(
910
668
  return { bundleUrl: url.toString(), port: bridgePort, framework: 'unknown' }
911
669
  }
912
670
 
913
- async function buildResolvedBundleOpenUrl(
914
- target: string,
915
- baseUrl: string,
916
- opts: BuildShellUrlOptions = {},
917
- ): Promise<string> {
918
- const resolved = opts.resolvedBundle ?? (await resolveConnectionInputForCli(target))
919
- const url = new URL(baseUrl)
920
- const prefix = getShellRoutePrefix(url.pathname)
921
- url.pathname = `${prefix}/rn`
922
- url.searchParams.delete('open')
923
- url.searchParams.delete('port')
924
- url.searchParams.delete('app')
925
- const bundleUrl =
926
- opts.hot === undefined
927
- ? resolved.bundleUrl
928
- : applyHotMode(resolved.bundleUrl, opts.hot)
929
- url.searchParams.set('bundle', bundleUrl)
930
- return url.toString()
931
- }
932
-
933
671
  function normalizeReplacementPath(filePath: string): string {
934
672
  if (filePath.startsWith('~/')) {
935
673
  return path.join(os.homedir(), filePath.slice(2))
@@ -986,25 +724,6 @@ function parseOpenRuntimeConfig(args: string[]): PeachConfig | undefined {
986
724
  return config.modules || config.network ? config : undefined
987
725
  }
988
726
 
989
- export async function resolveAppProjectForBundleUrl(
990
- bundleUrl?: string,
991
- projectRoot?: string,
992
- manifestProjectRoot?: string | null,
993
- signal?: AbortSignal,
994
- ): Promise<ResolvedAppProject | null> {
995
- if (projectRoot !== undefined) {
996
- const project = resolveAppProject(projectRoot)
997
- if (!project) throw new Error(`app project could not be found at ${projectRoot}`)
998
- return project
999
- }
1000
- if (!bundleUrl) return null
1001
- const advertisedRoot = await resolveMetroProjectRoot(bundleUrl, manifestProjectRoot, {
1002
- waitMs: null,
1003
- signal,
1004
- })
1005
- return advertisedRoot ? resolveAppProject(advertisedRoot) : null
1006
- }
1007
-
1008
727
  async function ensureConfiguredRuntime(version: string): Promise<void> {
1009
728
  if (fs.existsSync(path.join(runtimeDir(version), 'index.html'))) return
1010
729
  console.error(` installing configured engine runtime ${version}...`)
@@ -1032,517 +751,6 @@ export function applyRuntimeGenerationOrigin(baseUrl: string, version?: string):
1032
751
  return url.toString()
1033
752
  }
1034
753
 
1035
- export function resolveDefaultShellBaseUrl(): string {
1036
- return resolveBridgeWorld().shellBaseUrl
1037
- }
1038
-
1039
- /** the shell that belongs to a bridge port: the world a fresh lockfile claims
1040
- * for it, otherwise the shell that shares the port's own offset. every caller
1041
- * that has already settled on a bridge port goes through this, so a page can
1042
- * never open in one stack's shell while the CLI polls another's bridge. the
1043
- * development bridge registry keeps every live port addressable, while this
1044
- * function preserves an explicit caller's already-selected world. */
1045
- export function resolveShellBaseUrlForBridgePort(bridgePort: number): string {
1046
- return (
1047
- worldForBridgePort(bridgePort)?.shellBaseUrl ??
1048
- resolveSootsimShellBaseUrlForBridgePort(bridgePort) ??
1049
- resolveDefaultShellBaseUrl()
1050
- )
1051
- }
1052
-
1053
- // stamp a bounded catalog reference on the engine page url so the
1054
- // engine's app-font-loader registers native config-only fonts at boot. fonts
1055
- // loaded by JS already flow through normal runtime fetch capture; this covers
1056
- // UIAppFonts-style assets that Metro can serve but the guest bundle never
1057
- // fetches itself. auto-discovery only — scans the repo for expo-font config
1058
- // plugin declarations, no user-facing flag. discovery keeps only font files
1059
- // that exist on disk, so the stamp never waits on the dev server.
1060
- function stampAppFonts(
1061
- urlStr: string,
1062
- platform: 'ios' | 'android',
1063
- nativeAssetOrigin: string,
1064
- project?: ResolvedAppProject | null,
1065
- ): string {
1066
- try {
1067
- const url = new URL(urlStr)
1068
- if (!url.searchParams.get('bundle') || !project) return urlStr
1069
- const specs = discoverNativeLinkedAppFonts({
1070
- projectDir: project.appDir,
1071
- platform,
1072
- nativeAssetOrigin,
1073
- })
1074
- if (specs.length === 0) return urlStr
1075
- const catalogUrl = stageHostBytes(
1076
- new TextEncoder().encode(
1077
- getCliRuntime().engine_config_plugin_fonts.encodeAppFontsWire(specs),
1078
- ),
1079
- nativeAssetOrigin,
1080
- )
1081
- url.searchParams.set('appFonts', `@${catalogUrl}`)
1082
- return url.toString()
1083
- } catch {
1084
- return urlStr
1085
- }
1086
- }
1087
-
1088
- async function resolveShellUrl(
1089
- target: string,
1090
- baseUrl: string,
1091
- opts: BuildShellUrlOptions = {},
1092
- ): Promise<string> {
1093
- // no target = open home screen
1094
- if (!target) {
1095
- return new URL(baseUrl).toString()
1096
- }
1097
-
1098
- if (looksLikeSootsimUrl(target)) {
1099
- const url = new URL(target)
1100
- const base = new URL(baseUrl)
1101
- const baseConfig = base.searchParams.get(PEACH_CONFIG_QUERY_PARAM)
1102
- if (baseConfig && !url.searchParams.has(PEACH_CONFIG_QUERY_PARAM)) {
1103
- url.searchParams.set(PEACH_CONFIG_QUERY_PARAM, baseConfig)
1104
- }
1105
- return url.toString()
1106
- }
1107
-
1108
- if (looksLikeShellPathTarget(target)) {
1109
- return buildShellPathOpenUrl(target, baseUrl)
1110
- }
1111
-
1112
- // check if this is a shell app (pathname-based route, not bundle)
1113
- const shellPath = SHELL_APPS[target.toLowerCase()]
1114
- if (shellPath) {
1115
- const url = new URL(baseUrl)
1116
- const prefix = getShellRoutePrefix(url.pathname)
1117
- url.pathname = `${prefix}${shellPath}`
1118
- return url.toString()
1119
- }
1120
-
1121
- if (shouldResolveBundleTargetInCli(target)) {
1122
- return buildResolvedBundleOpenUrl(target, baseUrl, opts)
1123
- }
1124
-
1125
- return buildConnectOpenUrl(target, baseUrl)
1126
- }
1127
-
1128
- // stamp the engine page url with `?appSplash=<encodeURIComponent(JSON)>` so the
1129
- // engine paints the app's REAL configured splash image + background on boot
1130
- // (instead of the contrast device-default chrome). same discovery path as
1131
- // fonts: scan the bundle's project for the expo-splash-screen /
1132
- // react-native-bootsplash config plugin (or legacy `expo.splash`). the metro
1133
- // manifest fallback in the engine covers the typed-URL case; this wire is the
1134
- // instant-first-paint optimization.
1135
- async function stampAppSplash(
1136
- urlStr: string,
1137
- project?: ResolvedAppProject | null,
1138
- oneAppSplash?: Promise<DiscoveredAppSplashSpec | null>,
1139
- ): Promise<string> {
1140
- try {
1141
- const url = new URL(urlStr)
1142
- const bundleUrl = url.searchParams.get('bundle') || ''
1143
- if (!bundleUrl || !project) return urlStr
1144
- const spec = findExpoAppConfig(project.appDir)
1145
- ? discoverConfigPluginAppSplash({
1146
- bundleUrl,
1147
- projectDir: project.appDir,
1148
- })
1149
- : await (oneAppSplash ?? discoverOneNativeAppSplash(bundleUrl))
1150
- if (!spec) return urlStr
1151
- // native splash assets are required for the first frame.
1152
- for (const imageUrl of splashImageUrls(spec)) {
1153
- if (!splashImageOnDisk(imageUrl, project.appDir)) return urlStr
1154
- }
1155
- url.searchParams.set('appSplash', encodeAppSplashWire(spec))
1156
- return url.toString()
1157
- } catch {
1158
- return urlStr
1159
- }
1160
- }
1161
-
1162
- // stamp the engine page url with `?appCatalog=` so an app's asset-catalog
1163
- // colors and images and its declared accent reach the tenant, which applies
1164
- // them to the bundle this url opens. the catalog lives in the native binary,
1165
- // never in the js bundle, so only the app's ios project on disk has it.
1166
- function stampAppCatalog(urlStr: string, project?: ResolvedAppProject | null): string {
1167
- try {
1168
- const url = new URL(urlStr)
1169
- const metroOrigin = loopbackOriginOf(url.searchParams.get('bundle') ?? '')
1170
- if (!metroOrigin || !project) return urlStr
1171
- const catalog = discoverAppCatalog(project.appDir, metroOrigin)
1172
- if (!catalog) return urlStr
1173
- url.searchParams.set(
1174
- 'appCatalog',
1175
- getCliRuntime().engine_app_catalog_wire.encodeAppCatalogWire(catalog),
1176
- )
1177
- return url.toString()
1178
- } catch {
1179
- return urlStr
1180
- }
1181
- }
1182
-
1183
- // a splash spec names `<origin>/assets/<project-relative-path>`, the file the
1184
- // dev server serves from its project root, so the file is checked on disk and
1185
- // the stamp never waits on a dev server busy building.
1186
- function splashImageOnDisk(imageUrl: string, appDir: string): boolean {
1187
- const { pathname } = new URL(imageUrl)
1188
- if (!pathname.startsWith('/assets/')) return false
1189
- try {
1190
- return fs
1191
- .statSync(path.join(appDir, decodeURIComponent(pathname.slice('/assets/'.length))))
1192
- .isFile()
1193
- } catch {
1194
- return false
1195
- }
1196
- }
1197
-
1198
- export interface BuildShellUrlOptions {
1199
- // manifest and asset origin provided by an authenticated recorder proxy.
1200
- bundleOriginOverride?: string
1201
- // marks native host windows so the bridge can reuse a CLI-opened desktop sim.
1202
- hostDriver?: 'desktop'
1203
- // when set, forces the metro `hot` query on the resolved bundle URL. true
1204
- // for interactive opens (HMR runtime in bundle, edits hot-apply), false
1205
- // for `--driver playwright`/agent runs (no in-bundle HMR wiring, no ws
1206
- // chatter, deterministic e2e). undefined leaves whatever value metro's
1207
- // manifest emitted — matches real iOS sims so metro's bundle cache is
1208
- // shared. set by `runOpenCommand` only.
1209
- hot?: boolean
1210
- // device model slug (e.g. iphone-16) stamped onto the engine URL as
1211
- // ?device=<model> — the shell reads it at boot (main.tsx) and live-switch
1212
- // uses the same param. without this, every driver-opened sim silently ran
1213
- // whatever profile the shell last persisted.
1214
- device?: string
1215
- // fold posture (open|closed) stamped onto the engine URL as ?posture= next
1216
- // to ?device=. the shell reads it at boot (readUrlSettingOverrides) and
1217
- // keeps it in the URL on every pose change, so it round-trips the way
1218
- // device and orientation do. without this a manual ?posture= appended
1219
- // after the app path lands inside the bundle param and never reaches the
1220
- // shell. non-foldable devices resolve it to closed at boot.
1221
- posture?: string
1222
- // raster quality (high|medium|low) stamped as ?renderResolution=. high
1223
- // renders at the device's native scale, so a native-parity capture is not
1224
- // left at the interactive medium default of 2.
1225
- renderResolution?: string
1226
- // interface orientation (portrait|landscape) stamped as ?orientation=,
1227
- // which the shell reads at boot over the device's default: an open duo
1228
- // boots landscape unless this asks for it upright.
1229
- orientation?: string
1230
- // portrayed os version (major.minor) stamped as ?osVersion=, which the
1231
- // shell pins at boot over the device profile's own version. an oracle on a
1232
- // newer os than the profile compares only when the sim runs that os era.
1233
- osVersion?: string
1234
- // appearance scheme (light|dark|auto) stamped as ?theme=, which the shell
1235
- // reads at boot over the persisted scheme. set by `peach open -t/--theme`.
1236
- theme?: string
1237
- // the xcode application target whose version, bundle id and display name
1238
- // the app reads, for a project with several. set by `peach open --ios-target`.
1239
- iosTarget?: string
1240
- resolvedBundle?: ResolvedDevBundle
1241
- project?: ResolvedAppProject | null
1242
- // a One app's splash, read from its dev server's manifest. `peach open`
1243
- // starts the read beside its early bundle request so the answer overlaps
1244
- // bridge and host setup instead of preceding the launch.
1245
- oneAppSplash?: Promise<DiscoveredAppSplashSpec | null>
1246
- // deterministic-capture mode, stamped onto the engine URL as ?proof=1. the
1247
- // shell worker, compositor worker and tenant worker each read it off the
1248
- // host page URL at boot (syncProofModeFromInitUrl) and pin everything that
1249
- // would otherwise differ frame to frame: the TextInput caret stops blinking
1250
- // and stays visible, and notifications stop auto-dismissing. capture-frame
1251
- // also reads the raw param and stops clipping the device corners, and the
1252
- // shell leaves out the Dynamic Island, which is hardware, so a
1253
- // capture matches simctl's rectangular framebuffer. without it a
1254
- // screen holding a focused text field never reaches three identical idle
1255
- // frames, so the screenshot guard burns all 12 attempts and then fails.
1256
- proof?: boolean
1257
- // a temporary storage profile, stamped as ?ephemeral=1. the shell then
1258
- // neither reads nor writes the machine-wide settings in
1259
- // ~/.peach/config.json, so a preference another sim saved (bold text,
1260
- // reduce motion, appearance) cannot steer this boot.
1261
- ephemeral?: boolean
1262
- // launch-time environment variables, stamped as repeated ?env=KEY%3DVALUE.
1263
- // see the --env flag above.
1264
- env?: string[]
1265
- // the project's env file as react-native-config's iOS build compiles it,
1266
- // stamped as ?dotEnv=<json>. set by `peach open --load-env` only.
1267
- dotEnv?: Record<string, string>
1268
- // the bridge an explicit --port names; the expo swift compile endpoint
1269
- // stamped onto the URL uses it instead of the discovered world's bridge.
1270
- bridgePort?: number
1271
- }
1272
-
1273
- type ProjectExpoConfigRead = { config: Record<string, unknown> } | { error: string }
1274
-
1275
- function errorMessage(error: unknown): string {
1276
- return error instanceof Error ? error.message : String(error)
1277
- }
1278
-
1279
- function readProjectExpoConfig(
1280
- project: ResolvedAppProject,
1281
- ): Promise<ProjectExpoConfigRead | null> {
1282
- const require = createRequire(path.join(project.appDir, 'package.json'))
1283
- try {
1284
- require.resolve('@expo/config')
1285
- } catch {
1286
- return Promise.resolve(null)
1287
- }
1288
- return readExpoConfigAsync(project.appDir).then(
1289
- (config) => ({ config }),
1290
- (error: unknown) => ({ error: errorMessage(error) }),
1291
- )
1292
- }
1293
-
1294
- // evaluating the Expo config spawns node, so `peach open` starts the read as
1295
- // soon as the project resolves and the shell url it builds takes that read. a
1296
- // later build reads the config again.
1297
- const startedExpoConfigReads = new Map<string, Promise<ProjectExpoConfigRead | null>>()
1298
-
1299
- function startExpoConfigRead(project: ResolvedAppProject | null) {
1300
- if (project) startedExpoConfigReads.set(project.appDir, readProjectExpoConfig(project))
1301
- }
1302
-
1303
- function takeExpoConfigRead(project: ResolvedAppProject | null | undefined) {
1304
- if (!project) return Promise.resolve(null)
1305
- const started = startedExpoConfigReads.get(project.appDir)
1306
- startedExpoConfigReads.delete(project.appDir)
1307
- return started ?? readProjectExpoConfig(project)
1308
- }
1309
-
1310
- function nativeFirebaseFromExpoConfig(
1311
- project: ResolvedAppProject,
1312
- read: ProjectExpoConfigRead,
1313
- iosTarget: string | undefined,
1314
- ): Record<string, unknown> {
1315
- if ('error' in read) return read
1316
- try {
1317
- return readNativeFirebaseConfig(
1318
- project.appDir,
1319
- undefined,
1320
- iosTarget,
1321
- read.config,
1322
- true,
1323
- )
1324
- } catch (error) {
1325
- return { error: errorMessage(error) }
1326
- }
1327
- }
1328
-
1329
- // a built bundle staged on the bridge has no packager to serve its manifest.
1330
- // the built binary embeds its evaluated app config (expo's `app.config`
1331
- // resource, and the Info.plist prebuild writes from it), so the bundle's
1332
- // manifest is that config, staged beside it
1333
- function stageBuiltBundleManifest(
1334
- bundleUrl: string,
1335
- config: Record<string, unknown>,
1336
- ): string | null {
1337
- const bundle = new URL(bundleUrl)
1338
- if (!isStagedHostFileRequest(bundle.pathname) || Object.keys(config).length === 0)
1339
- return null
1340
- const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'peach-app-manifest-'))
1341
- try {
1342
- const file = path.join(directory, 'manifest.json')
1343
- fs.writeFileSync(file, JSON.stringify({ extra: { expoClient: config } }))
1344
- return stageHostFile(file, bundle.origin)
1345
- } finally {
1346
- fs.rmSync(directory, { recursive: true, force: true })
1347
- }
1348
- }
1349
-
1350
- // a plain Metro carries no identity footer or header, so the page carries the
1351
- // identity the Peach Metro plugin reads from the same project. its icon
1352
- // artwork stays with bundle builders, where data uris cannot swell a url. a
1353
- // project with several app targets needs a named target, as xcode needs a
1354
- // scheme: `--ios-target` here, the plugin's iosTarget for a Peach Metro.
1355
- function readProjectNativeAppIdentityWire(
1356
- project: ResolvedAppProject,
1357
- platform: 'ios' | 'android',
1358
- iosTarget: string | undefined,
1359
- ): string | null {
1360
- if (!canExtractNativeAppIdentity(platform)) return null
1361
- try {
1362
- const identity = readNativeAppIdentityFromProject(
1363
- project.appDir,
1364
- platform,
1365
- undefined,
1366
- iosTarget,
1367
- )
1368
- return (
1369
- identity &&
1370
- createNativeAppIdentityHeader({ ...identity, appIconArtwork: undefined })
1371
- )
1372
- } catch (error) {
1373
- if (error instanceof NativeAppTargetSelectionError) return null
1374
- throw error
1375
- }
1376
- }
1377
-
1378
- function bundleUrlOf(urlStr: string): string | undefined {
1379
- try {
1380
- return new URL(urlStr).searchParams.get('bundle') || undefined
1381
- } catch {
1382
- return undefined
1383
- }
1384
- }
1385
-
1386
- export async function buildShellUrl(
1387
- target: string,
1388
- baseUrl: string = resolveDefaultShellBaseUrl(),
1389
- opts: BuildShellUrlOptions = {},
1390
- ): Promise<string> {
1391
- const resolved = await resolveShellUrl(target, baseUrl, opts)
1392
- // callers that hand us a bare port or url (the flow/maestro runner, the
1393
- // electron companion) have no project to pass. derive it from the bundle
1394
- // metro advertises so those paths get the same UIAppFonts and splash
1395
- // stamping an `peach open` gets. without it a flow renders the app's text in a
1396
- // fallback typeface, which then reads as a conformance diff.
1397
- const project =
1398
- opts.project ?? (await resolveAppProjectForBundleUrl(bundleUrlOf(resolved)))
1399
- const expoRoot = project?.appDir ?? null
1400
- const world = resolveBridgeWorld()
1401
- const port = resolveBridgePortForPin({
1402
- baseUrl,
1403
- wsPort: opts.bridgePort ?? world.bridgePort,
1404
- explicitPort: opts.bridgePort !== undefined,
1405
- })
1406
- if (project && port.error) throw new Error(port.error)
1407
- const device = opts.device ?? new URL(resolved).searchParams.get('device')
1408
- const bundle = bundleUrlOf(resolved)
1409
- const platform =
1410
- device && isDeviceModel(device)
1411
- ? getCliRuntime().settings_devices.getRuntimePlatform(device)
1412
- : bundle && new URL(bundle).searchParams.get('platform') === 'android'
1413
- ? 'android'
1414
- : 'ios'
1415
- const stamped = stampAppCatalog(
1416
- await stampAppSplash(
1417
- stampAppFonts(resolved, platform, `http://localhost:${port.port}`, project),
1418
- project,
1419
- opts.oneAppSplash,
1420
- ),
1421
- project,
1422
- )
1423
- const expoStamped = new URL(stamped)
1424
- expoStamped.searchParams.delete('nativeAppIdentity')
1425
- expoStamped.searchParams.delete(ANDROID_ROOT_MODULE_QUERY_PARAM)
1426
- expoStamped.searchParams.delete('appBundleResources')
1427
- if (project) {
1428
- const nativeRenderer = readNativeProjectRenderer(project.appDir, platform)
1429
- if (nativeRenderer !== undefined) {
1430
- const config = readPeachConfigFromSearchParams(expoStamped.searchParams)
1431
- if (
1432
- config?.nativeRenderer !== undefined &&
1433
- config.nativeRenderer !== nativeRenderer
1434
- )
1435
- throw new Error('peach config contradicts native project renderer')
1436
- expoStamped.searchParams.set(
1437
- PEACH_CONFIG_QUERY_PARAM,
1438
- JSON.stringify(mergePeachConfig(config, { nativeRenderer })),
1439
- )
1440
- }
1441
- const nativeAppIdentity = bundle
1442
- ? readProjectNativeAppIdentityWire(project, platform, opts.iosTarget)
1443
- : null
1444
- if (nativeAppIdentity)
1445
- expoStamped.searchParams.set('nativeAppIdentity', nativeAppIdentity)
1446
- const androidRoot =
1447
- bundle && platform === 'android'
1448
- ? readAndroidLauncherRootModuleName(project.appDir)
1449
- : undefined
1450
- if (androidRoot !== undefined)
1451
- expoStamped.searchParams.set(ANDROID_ROOT_MODULE_QUERY_PARAM, androidRoot)
1452
- if (platform === 'ios' && nativeAppIdentity) {
1453
- const resources = stageAppBundleResources(
1454
- project.appDir,
1455
- `http://localhost:${port.port}`,
1456
- opts.iosTarget,
1457
- )
1458
- if (Object.keys(resources).length > 0)
1459
- expoStamped.searchParams.set('appBundleResources', JSON.stringify(resources))
1460
- }
1461
- }
1462
- // a plain Metro has no native Firebase config endpoint, so the CLI reads it
1463
- // from the project whose Expo config it can evaluate. a project without its
1464
- // own `@expo/config` (a dependency-free recorder) leaves it to the Peach
1465
- // Metro plugin's endpoint.
1466
- expoStamped.searchParams.delete('nativeFirebase')
1467
- expoStamped.searchParams.delete('appManifest')
1468
- expoStamped.searchParams.delete('packageVersions')
1469
- if (project && expoStamped.searchParams.get('bundle')) {
1470
- expoStamped.searchParams.set(
1471
- 'packageVersions',
1472
- JSON.stringify(readInstalledNativePackageVersions(project.appDir)),
1473
- )
1474
- }
1475
- const expoConfigRead = await takeExpoConfigRead(project)
1476
- const stampedBundle = expoStamped.searchParams.get('bundle')
1477
- if (project && !expoConfigRead && stampedBundle) {
1478
- // no Expo config tooling, but the native project still configures Firebase
1479
- const nativeFirebase = nativeFirebaseFromExpoConfig(
1480
- project,
1481
- { config: {} },
1482
- opts.iosTarget,
1483
- )
1484
- if (Object.keys(nativeFirebase).length > 0)
1485
- expoStamped.searchParams.set('nativeFirebase', JSON.stringify(nativeFirebase))
1486
- }
1487
- if (project && expoConfigRead && stampedBundle) {
1488
- expoStamped.searchParams.set(
1489
- 'nativeFirebase',
1490
- JSON.stringify(
1491
- nativeFirebaseFromExpoConfig(project, expoConfigRead, opts.iosTarget),
1492
- ),
1493
- )
1494
- const manifest =
1495
- 'config' in expoConfigRead
1496
- ? stageBuiltBundleManifest(stampedBundle, expoConfigRead.config)
1497
- : null
1498
- if (manifest) expoStamped.searchParams.set('appManifest', manifest)
1499
- }
1500
- if (opts.bundleOriginOverride)
1501
- expoStamped.searchParams.set('bundleOriginOverride', opts.bundleOriginOverride)
1502
- if (opts.hostDriver) expoStamped.searchParams.set('peachHostDriver', opts.hostDriver)
1503
- if (expoRoot) {
1504
- expoStamped.searchParams.set(
1505
- 'expoSwift',
1506
- `http://localhost:${port.port}/__peach/expo-swift?root=${encodeURIComponent(expoRoot)}`,
1507
- )
1508
- expoStamped.searchParams.set(
1509
- 'nitro',
1510
- `http://localhost:${port.port}/__peach/nitro?root=${encodeURIComponent(expoRoot)}`,
1511
- )
1512
- // the engine fetches only its device platform's build
1513
- expoStamped.searchParams.set(
1514
- 'expoKotlin',
1515
- `http://localhost:${port.port}/__peach/expo-kotlin?root=${encodeURIComponent(expoRoot)}`,
1516
- )
1517
- }
1518
- if (
1519
- !opts.device &&
1520
- !opts.proof &&
1521
- !opts.ephemeral &&
1522
- !opts.posture &&
1523
- !opts.renderResolution &&
1524
- !opts.orientation &&
1525
- !opts.osVersion &&
1526
- !opts.theme &&
1527
- !opts.env?.length &&
1528
- !opts.dotEnv
1529
- )
1530
- return stageHostLaunchMetadata(expoStamped, `http://localhost:${port.port}`)
1531
- const url = expoStamped
1532
- if (opts.dotEnv) url.searchParams.set('dotEnv', JSON.stringify(opts.dotEnv))
1533
- if (opts.device) url.searchParams.set('device', opts.device)
1534
- if (opts.posture) url.searchParams.set('posture', opts.posture)
1535
- if (opts.renderResolution)
1536
- url.searchParams.set('renderResolution', opts.renderResolution)
1537
- if (opts.orientation) url.searchParams.set('orientation', opts.orientation)
1538
- if (opts.osVersion) url.searchParams.set('osVersion', opts.osVersion)
1539
- if (opts.theme) url.searchParams.set('theme', opts.theme)
1540
- if (opts.proof) url.searchParams.set('proof', '1')
1541
- if (opts.ephemeral) url.searchParams.set('ephemeral', '1')
1542
- for (const entry of opts.env ?? []) url.searchParams.append('env', entry)
1543
- return stageHostLaunchMetadata(url, `http://localhost:${port.port}`)
1544
- }
1545
-
1546
754
  function deriveCurrentSimBaseUrl(
1547
755
  sim: BridgeSimInfo | null | undefined,
1548
756
  fallback: string,
@@ -2102,11 +1310,15 @@ async function openSim(
2102
1310
  '--profile',
2103
1311
  '--cdp-port',
2104
1312
  '--device',
1313
+ '-d',
2105
1314
  '--posture',
2106
1315
  '--render-resolution',
2107
1316
  '--orientation',
2108
1317
  '--os-version',
2109
1318
  '--ios-target',
1319
+ '--target',
1320
+ '--scheme',
1321
+ '--activity',
2110
1322
  '--viewport',
2111
1323
  '--env',
2112
1324
  '--theme',
@@ -2212,6 +1424,30 @@ async function openSim(
2212
1424
  peachExit(1)
2213
1425
  }
2214
1426
 
1427
+ const { resolveNativeInput } = await import('../native-input')
1428
+ const nativeInput = resolveNativeInput(target)
1429
+ if (nativeInput) {
1430
+ const nativeArgs = [nativeInput.path]
1431
+ const openArgs: string[] = []
1432
+ const selectionFlags = new Set(['--target', '--scheme', '--activity'])
1433
+ for (let index = 0; index < args.length; index++) {
1434
+ const arg = args[index]
1435
+ if (index === args.indexOf(target)) continue
1436
+ if (selectionFlags.has(arg)) nativeArgs.push(arg, args[++index])
1437
+ else openArgs.push(arg)
1438
+ }
1439
+ const code =
1440
+ nativeInput.kind === 'kotlin'
1441
+ ? await (
1442
+ await import('./kotlin')
1443
+ ).runKotlin(nativeArgs, { port: opts.port, openArgs })
1444
+ : await (
1445
+ await import('./swift')
1446
+ ).runSwift(nativeArgs, { port: opts.port, openArgs })
1447
+ if (code) peachExit(code)
1448
+ return
1449
+ }
1450
+
2215
1451
  // an absolute path to a built bundle is a file, not an app path
2216
1452
  const prebuiltBundle = prebuiltBundleFile(target)
2217
1453
  if (!prebuiltBundle && isAppDeepLinkTarget(target)) {
@@ -2280,7 +1516,7 @@ async function openSim(
2280
1516
  }
2281
1517
  const project = await resolveAppProjectForBundleUrl(
2282
1518
  resolvedBundle?.bundleUrl,
2283
- projectRoot ?? (prebuiltBundle ? appDirAbove(prebuiltBundle) : undefined),
1519
+ projectRoot,
2284
1520
  resolvedBundle?.manifestProjectRoot,
2285
1521
  opts.signal,
2286
1522
  )
@@ -2362,7 +1598,9 @@ async function openSim(
2362
1598
  // the engine URL, so both playwright and electron honor it). without it
2363
1599
  // the sim runs whatever profile the
2364
1600
  // shell last persisted, which silently skews browser comparisons.
2365
- const deviceArg = args.find((_, i) => args[i - 1] === '--device')
1601
+ const deviceArg = args.find(
1602
+ (_, i) => args[i - 1] === '--device' || args[i - 1] === '-d',
1603
+ )
2366
1604
  if (!validateDeviceOption(deviceArg)) peachExit(1)
2367
1605
 
2368
1606
  // asked before the bundle so the dev server answers it ahead of the build
@@ -2436,11 +1674,24 @@ async function openSim(
2436
1674
  if (resolvedBundle) {
2437
1675
  // platform selection needs the verified companion after runtime preparation
2438
1676
  const bundleUrl = applyHotMode(resolvedBundle.bundleUrl, hotMode)
1677
+ // a reused sim keeps its own device, so the engine asks for that device's
1678
+ // platform even when this open names none
1679
+ const reusedSimId =
1680
+ parsed.simIdSource === 'flag'
1681
+ ? parsed.simId
1682
+ : parsed.simIdSource === 'saved' && !openInNewSim
1683
+ ? savedSimId
1684
+ : undefined
1685
+ const warmDevice =
1686
+ deviceArg ??
1687
+ (reusedSimId
1688
+ ? await readSimDevice(createBridgeFromParsed(parsed), reusedSimId)
1689
+ : null)
2439
1690
  startDevServerBuild(
2440
- deviceArg && isDeviceModel(deviceArg)
1691
+ warmDevice && isDeviceModel(warmDevice)
2441
1692
  ? getCliRuntime().bundle_platform_url.bundleUrlForPlatform(
2442
1693
  bundleUrl,
2443
- getCliRuntime().settings_devices.getRuntimePlatform(deviceArg),
1694
+ getCliRuntime().settings_devices.getRuntimePlatform(warmDevice),
2444
1695
  () => bundleUrl,
2445
1696
  )
2446
1697
  : bundleUrl,
@@ -3349,4 +2600,13 @@ export async function runCloseCommand(args: string[], opts: ControlCommandOption
3349
2600
  }
3350
2601
  }
3351
2602
 
3352
- export { looksLikeSootsimUrl, shouldResolveBundleTargetInCli, looksLikeShellPathTarget }
2603
+ export {
2604
+ buildShellUrl,
2605
+ looksLikeShellPathTarget,
2606
+ looksLikeSootsimUrl,
2607
+ resolveAppProjectForBundleUrl,
2608
+ resolveShellBaseUrlForBridgePort,
2609
+ shouldResolveBundleTargetInCli,
2610
+ type BuildShellUrlOptions,
2611
+ }
2612
+ export { resolveDefaultShellBaseUrl } from './shell-url'