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
@@ -3,14 +3,6 @@ import http from 'node:http'
3
3
  import path from 'node:path'
4
4
  import { WebSocket, WebSocketServer } from 'ws'
5
5
  import { resolveContrastBackendOrigin } from '../../src/backend-origin'
6
- import { produceConfiguredBundle } from '../../src/configured-bundle-producer'
7
- import { swiftGuestBundle } from '../../src/guest-bundle'
8
- import { insertNativeAppIdentityFooter } from '../../src/native-app-identity'
9
- import {
10
- resolveSwiftModule,
11
- SWIFT_ENDPOINT_ENV,
12
- type SwiftModule,
13
- } from '../../src/swift-distribution'
14
6
  import { SWIFT_HMR_PATH, SWIFT_PACKAGE_PATH } from '../../src/swift-submit'
15
7
  import {
16
8
  SWIFT_DISCOVERY_PATH,
@@ -18,11 +10,9 @@ import {
18
10
  SWIFT_ICON_PATH,
19
11
  type SwiftHostDiscovery,
20
12
  } from '../../src/swiftDiscoveryContract'
21
- import { findXcodeProject, readXcodeScheme } from '../../src/xcode-project'
22
- import { loadRNXAppConfig } from '../app-config'
23
- import { resolveAppProject } from '../app-project'
24
13
  import { authHeaderValue, resolveCliAuth } from '../auth'
25
14
  import { validateDeviceOption } from '../device-option'
15
+ import { prepareSwiftInput, resolveNativeInput } from '../native-input'
26
16
  import { PeachExit } from '../run-rnx'
27
17
  import { runOpenCommand, type OpenCommandResources } from './control'
28
18
  import {
@@ -39,6 +29,7 @@ export async function runSwift(
39
29
  device?: string
40
30
  driver?: string
41
31
  headless?: boolean
32
+ openArgs?: string[]
42
33
  } = {},
43
34
  ): Promise<number> {
44
35
  const input = [...args]
@@ -119,68 +110,22 @@ export async function runSwift(
119
110
  authorization: authHeaderValue(auth),
120
111
  }
121
112
  : null
122
- let module: SwiftModule | null = null
123
- if (!hosted) {
124
- try {
125
- module = await resolveSwiftModule({ required: true })
126
- } catch (error) {
127
- console.error(` ${error instanceof Error ? error.message : String(error)}`)
128
- return 1
129
- }
130
- if (!module) {
131
- console.error(
132
- ` peach swift compiles on this machine against Peach's Swift distribution: set ${SWIFT_ENDPOINT_ENV} to the endpoint you were given, or pass --upload-source to compile on Contrast`,
133
- )
134
- return 1
135
- }
136
- }
137
- const host = await import('../../src/swift-host')
138
- packagePath = fs.realpathSync(packagePath)
139
- // a SwiftPM package compiles as itself; an xcode project compiles its
140
- // application target, with the project directory as the package path.
141
- const swiftPackage =
142
- fs.statSync(packagePath).isDirectory() &&
143
- fs.existsSync(path.join(packagePath, 'Package.swift'))
144
- const xcodeproj = swiftPackage ? null : findXcodeProject(packagePath)
145
- if (!swiftPackage && !xcodeproj) {
113
+ const nativeInput = resolveNativeInput(packagePath, true)
114
+ if (!nativeInput || nativeInput.kind === 'kotlin')
146
115
  throw new Error(
147
- 'peach swift needs a directory containing Package.swift, or an Xcode project or workspace',
116
+ 'peach swift needs a Swift file, SwiftPM directory, or Xcode project or workspace',
148
117
  )
149
- }
150
- if ((target || scheme) && !xcodeproj)
151
- throw new Error(
152
- `${scheme ? '--scheme' : '--target'} selects an Xcode application target`,
153
- )
154
- if (target && scheme) throw new Error('--scheme names its own target; pass one of them')
155
- // a scheme runs its launch action's target in that action's configuration
156
- const run = scheme && xcodeproj ? readXcodeScheme(xcodeproj, scheme) : null
157
- if (xcodeproj) {
158
- packagePath = host.openXcodeProject(
159
- xcodeproj,
160
- run?.target ?? target,
161
- module?.root,
162
- run?.configuration,
163
- )
164
- }
165
- const appProject = resolveAppProject(packagePath)
166
- host.configureSwiftStandinBehavior(packagePath, await loadRNXAppConfig(appProject))
167
- // collection preflights every input path before any source bytes are read.
168
- try {
169
- host.swiftPackageWatchFiles(packagePath, undefined)
170
- } catch (error) {
171
- const { SwiftObjCCompilationError } = await import('../../src/swift-objc-compile')
172
- if (!(error instanceof SwiftObjCCompilationError)) throw error
173
- console.error(error.message)
174
- host.disposeSwiftProject(packagePath)
175
- return 1
176
- }
177
- const packageName = path.basename(packagePath)
178
- const appInfo = host.swiftProjectAppInfo(packagePath)
179
- const guestSource = swiftGuestBundle(packageName)
180
- const withIdentity = (source: string) =>
181
- appInfo.identity ? insertNativeAppIdentityFooter(source, appInfo.identity) : source
182
- let guest = withIdentity(guestSource)
183
118
  const controller = new AbortController()
119
+ const prepared = await prepareSwiftInput(nativeInput, {
120
+ target,
121
+ scheme,
122
+ hosted: hosted ?? undefined,
123
+ signal: controller.signal,
124
+ })
125
+ const { host, module, appInfo } = prepared
126
+ packagePath = prepared.packagePath
127
+ const packageName = prepared.name
128
+ let guest = ''
184
129
  const resources: OpenCommandResources = {}
185
130
  let metadata: (SwiftEntryModuleArgs & { hmrPath: string }) | null = null
186
131
  let compileError = 'Swift compilation is starting'
@@ -201,19 +146,9 @@ export async function runSwift(
201
146
  while (!controller.signal.aborted && completed !== requested) {
202
147
  const revision = requested
203
148
  try {
204
- const config = await loadRNXAppConfig(appProject)
205
- host.configureSwiftStandinBehavior(packagePath, config)
206
- guest = withIdentity(
207
- await produceConfiguredBundle(guestSource, config, new Set()),
208
- )
209
- const next = await host.swiftPackageMetadata(
210
- packagePath,
211
- packageName,
212
- module?.root,
213
- origin,
214
- hosted ?? undefined,
215
- controller.signal,
216
- )
149
+ const nextBuild = await prepared.build(origin)
150
+ guest = nextBuild.guestSource
151
+ const next = nextBuild.metadata
217
152
  if (controller.signal.aborted) return
218
153
  if (revision === requested) {
219
154
  const sameArtifact = metadata?.hash === next.hash
@@ -330,24 +265,28 @@ export async function runSwift(
330
265
  code = 1
331
266
  stop()
332
267
  })
333
- watcher = fs.watch(packagePath, { recursive: true }, (_event, file) => {
334
- if (
335
- file &&
336
- file
337
- .split(/[\\/]/)
338
- .some(
339
- (segment) =>
340
- (segment.startsWith('.') &&
341
- segment !== '.one-native-source.json' &&
342
- segment !== '.one-native-source.swift.txt') ||
343
- ['node_modules', 'ios', 'android', 'build', 'dist', 'types'].includes(
344
- segment,
345
- ),
346
- )
347
- )
348
- return
349
- void refresh()
350
- })
268
+ watcher = fs.watch(
269
+ nativeInput.kind === 'swift-file' ? nativeInput.path : packagePath,
270
+ { recursive: nativeInput.kind !== 'swift-file' },
271
+ (_event, file) => {
272
+ if (
273
+ file &&
274
+ file
275
+ .split(/[\\/]/)
276
+ .some(
277
+ (segment) =>
278
+ (segment.startsWith('.') &&
279
+ segment !== '.one-native-source.json' &&
280
+ segment !== '.one-native-source.swift.txt') ||
281
+ ['node_modules', 'ios', 'android', 'build', 'dist', 'types'].includes(
282
+ segment,
283
+ ),
284
+ )
285
+ )
286
+ return
287
+ void refresh()
288
+ },
289
+ )
351
290
  watcher.on('error', (error) => {
352
291
  console.error(error.message)
353
292
  code = 1
@@ -363,6 +302,7 @@ export async function runSwift(
363
302
  controller.signal.throwIfAborted()
364
303
  // refresh already printed the error
365
304
  if (!metadata || compileError) return 1
305
+ if (opts.openArgs) openArgs.push(...opts.openArgs)
366
306
  if (opts.device) openArgs.push('--device', opts.device)
367
307
  if (opts.driver) openArgs.push('--driver', opts.driver)
368
308
  if (opts.headless) openArgs.push('--headless')
@@ -395,7 +335,7 @@ export async function runSwift(
395
335
  server.closeAllConnections()
396
336
  await new Promise<void>((resolve) => server.close(() => resolve()))
397
337
  if (!(await closeGuestResources(resources, 'Swift preview'))) code = 1
398
- host.disposeSwiftProject(packagePath)
338
+ prepared.dispose()
399
339
  }
400
340
  return code
401
341
  }
@@ -2,11 +2,13 @@
2
2
 
3
3
  import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
4
4
  import { basename, dirname, extname, join, relative, resolve, sep } from 'node:path'
5
+ import { loopbackOriginOf } from '../../src/backend-origin'
5
6
  import {
6
7
  RNX_CLOUD_TEST_FILES_MAX_BYTES,
7
8
  RNX_CLOUD_TEST_FILES_MAX_COUNT,
8
9
  } from '../../src/cloud-contract'
9
10
  import { isCloudTestValueFlag, parseCloudTestArgs } from '../../src/cloud-test-args'
11
+ import { rnxPublicBrand } from '../../src/public-brand'
10
12
  import { authHeaderValue, resolveCliAuth } from '../auth'
11
13
  import {
12
14
  parseCloudTestSidecarPorts,
@@ -542,6 +544,18 @@ async function readJobStatus(
542
544
  }
543
545
  }
544
546
 
547
+ // the operator token proves admission to Contrast's own hosted queue only: never send it
548
+ // to an arbitrary --origin. other contrast.dev subdomains serve deployments and
549
+ // custom-domain targets, so only the exact queue hosts qualify.
550
+ function sendsAdminToken(origin: string): boolean {
551
+ const { hostname, origin: exact } = new URL(origin)
552
+ return (
553
+ hostname === 'contrast.dev' ||
554
+ loopbackOriginOf(origin) !== null ||
555
+ exact === new URL(rnxPublicBrand.origin).origin
556
+ )
557
+ }
558
+
545
559
  export async function cancelCloudTest(jobId: string, origin: string): Promise<number> {
546
560
  const auth = resolveCliAuth()
547
561
  if (!auth) {
@@ -1012,6 +1026,12 @@ export async function runCloudTest(
1012
1026
  headers: {
1013
1027
  'content-type': 'application/json',
1014
1028
  authorization: authHeaderValue(auth),
1029
+ // standalone submissions ride the private hosted queue, which
1030
+ // admits operators only: the account key above proves billing
1031
+ // entitlement while this header proves operator admission.
1032
+ ...(process.env.E2E_ADMIN_TOKEN && sendsAdminToken(origin)
1033
+ ? { 'x-soot-admin-token': process.env.E2E_ADMIN_TOKEN }
1034
+ : {}),
1015
1035
  },
1016
1036
  body: JSON.stringify(submitPayload),
1017
1037
  })
@@ -124,7 +124,7 @@ function normalizeOrigin(origin: string): string {
124
124
  return origin.replace(/\/$/, '')
125
125
  }
126
126
 
127
- function isContrastOrigin(origin: string): boolean {
127
+ export function isContrastOrigin(origin: string): boolean {
128
128
  try {
129
129
  const hostname = new URL(origin).hostname.toLowerCase()
130
130
  return hostname === 'contrast.dev' || hostname.endsWith('.contrast.dev')
@@ -2,7 +2,7 @@ import { devices, listSelectableDeviceModels } from '../src/device-catalog.ts'
2
2
 
3
3
  export function validateDeviceOption(device: string | undefined): boolean {
4
4
  if (!device || device in devices) return true
5
- console.error(` peach open: unknown device "${device}"`)
5
+ console.error(` peach: unknown device "${device}"`)
6
6
  console.error(` known devices: ${listSelectableDeviceModels().join(', ')}`)
7
7
  return false
8
8
  }
package/cli/main.ts CHANGED
@@ -6,6 +6,7 @@ import { automaticPeachUpdatesEnabled } from '../src/automatic-update-policy'
6
6
  import { getCliRuntime } from '../src/cli-runtime.ts'
7
7
  import { exitWithFlushedOutput } from '../src/process-output'
8
8
  import { rnxPublicBrand } from '../src/public-brand'
9
+ import { validateDeviceOption } from './device-option'
9
10
  import { levenshtein } from './levenshtein'
10
11
  import { COMMANDS, parseArgs, TOP_LEVEL_RUNTIME_COMMANDS } from './parse-args'
11
12
  import { PeachExit } from './run-rnx'
@@ -328,6 +329,10 @@ if (theme && theme !== 'light' && theme !== 'dark' && theme !== 'auto') {
328
329
  await exitWithFlush(1)
329
330
  }
330
331
 
332
+ // the global -d/--device lands in settings unvalidated otherwise, and an unknown
333
+ // model silently renders the default device instead of the one asked for.
334
+ if (!validateDeviceOption(device)) await exitWithFlush(1)
335
+
331
336
  // apply device/theme to settings store if provided
332
337
  if (device || theme) {
333
338
  // the settings store lives in the runtime companion, so a first-use home
@@ -581,7 +586,8 @@ try {
581
586
  // global --device/--theme seed the opened sim like the open flags;
582
587
  // an explicit open flag wins
583
588
  const openArgs = [...commandArgsWithSim]
584
- if (device && !openArgs.includes('--device')) openArgs.push('--device', device)
589
+ if (device && !openArgs.some((arg) => arg === '--device' || arg === '-d'))
590
+ openArgs.push('--device', device)
585
591
  if (theme && !openArgs.some((arg) => arg === '--theme' || arg === '-t')) {
586
592
  openArgs.push('--theme', theme)
587
593
  }
@@ -589,6 +595,12 @@ try {
589
595
  break
590
596
  }
591
597
 
598
+ case 'package': {
599
+ const { runPackage } = await import('./commands/package')
600
+ await runPackage(parsed.commandArgs)
601
+ break
602
+ }
603
+
592
604
  case 'ios':
593
605
  case 'android': {
594
606
  const { runPlatformCommand } = await import('./commands/platform')
@@ -0,0 +1,199 @@
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+ import { produceConfiguredBundle } from '../src/configured-bundle-producer'
4
+ import { swiftGuestBundle, kotlinGuestBundle } from '../src/guest-bundle'
5
+ import { KOTLIN_GUEST_PATH } from '../src/kotlinDiscoveryContract'
6
+ import { insertNativeAppIdentityFooter } from '../src/native-app-identity'
7
+ import { resolveSwiftModule } from '../src/swift-distribution'
8
+ import { SWIFT_HMR_PATH, SWIFT_PACKAGE_PATH } from '../src/swift-submit'
9
+ import { SWIFT_GUEST_PATH } from '../src/swiftDiscoveryContract'
10
+ import { findXcodeProject, readXcodeScheme } from '../src/xcode-project'
11
+ import { loadRNXAppConfig } from './app-config'
12
+ import { resolveAppProject } from './app-project'
13
+ import type { SwiftHostedCompileOptions } from '../src/swift-host'
14
+
15
+ export type NativeInput =
16
+ | { kind: 'swift-file' | 'swift-package' | 'xcode'; path: string }
17
+ | { kind: 'kotlin'; path: string }
18
+
19
+ // URLs, ports, JavaScript, loose native files and directories holding several
20
+ // Xcode projects retain open's existing resolution path; peach swift passes
21
+ // ambiguous so the several-projects error reaches its user.
22
+ export function resolveNativeInput(
23
+ target: string,
24
+ ambiguous = false,
25
+ ): NativeInput | null {
26
+ if (!target || /^\w+:\/\//.test(target) || /^\d+$/.test(target)) return null
27
+ const resolved = path.resolve(target)
28
+ const stat = fs.statSync(resolved, { throwIfNoEntry: false })
29
+ if (!stat) return null
30
+ if (stat.isFile()) {
31
+ if (resolved.endsWith('.swift') && path.basename(resolved) !== 'Package.swift')
32
+ return { kind: 'swift-file', path: fs.realpathSync(resolved) }
33
+ if (path.basename(resolved) === 'Package.swift')
34
+ return { kind: 'swift-package', path: fs.realpathSync(path.dirname(resolved)) }
35
+ return null
36
+ }
37
+ if (!stat.isDirectory()) return null
38
+ if (fs.existsSync(path.join(resolved, 'Package.swift')))
39
+ return { kind: 'swift-package', path: fs.realpathSync(resolved) }
40
+ const xcode = ambiguous ? findXcodeProject(resolved) : singleXcodeProject(resolved)
41
+ if (xcode) return { kind: 'xcode', path: fs.realpathSync(xcode) }
42
+ if (fs.existsSync(path.join(resolved, 'src/main/AndroidManifest.xml')))
43
+ return { kind: 'kotlin', path: fs.realpathSync(resolved) }
44
+ return null
45
+ }
46
+
47
+ // findXcodeProject's own search order, answering null where it would throw.
48
+ function singleXcodeProject(directory: string): string | null {
49
+ const names = fs.readdirSync(directory)
50
+ for (const extension of ['.xcworkspace', '.xcodeproj']) {
51
+ const found = names.filter((name) => name.endsWith(extension))
52
+ if (found.length > 1) return null
53
+ if (found.length === 1) return findXcodeProject(directory)
54
+ }
55
+ return null
56
+ }
57
+
58
+ export async function prepareSwiftInput(
59
+ input: Exclude<NativeInput, { kind: 'kotlin' }>,
60
+ opts: {
61
+ target?: string
62
+ scheme?: string
63
+ hosted?: SwiftHostedCompileOptions
64
+ signal?: AbortSignal
65
+ } = {},
66
+ ) {
67
+ if ((opts.target || opts.scheme) && input.kind !== 'xcode')
68
+ throw new Error(
69
+ `${opts.scheme ? '--scheme' : '--target'} selects an Xcode application target`,
70
+ )
71
+ if (opts.target && opts.scheme)
72
+ throw new Error('--scheme names its own target; pass one of them')
73
+ const module = opts.hosted
74
+ ? null
75
+ : await resolveSwiftModule({ required: true, signal: opts.signal })
76
+ if (!module && !opts.hosted)
77
+ throw new Error(
78
+ 'peach needs a local Swift distribution: set PEACH_SWIFT_ENDPOINT or pass --upload-source to compile on Contrast',
79
+ )
80
+ const host = await import('../src/swift-host')
81
+ const run = opts.scheme ? readXcodeScheme(input.path, opts.scheme) : null
82
+ const packagePath =
83
+ input.kind === 'swift-file'
84
+ ? host.openSwiftFile(input.path)
85
+ : input.kind === 'xcode'
86
+ ? host.openXcodeProject(
87
+ input.path,
88
+ run?.target ?? opts.target,
89
+ module?.root,
90
+ run?.configuration,
91
+ )
92
+ : input.path
93
+ const name =
94
+ input.kind === 'swift-file'
95
+ ? path.basename(input.path, '.swift')
96
+ : path.basename(packagePath)
97
+ const appProject = resolveAppProject(packagePath)
98
+ let appInfo: ReturnType<typeof host.swiftProjectAppInfo>
99
+ try {
100
+ host.configureSwiftStandinBehavior(packagePath, await loadRNXAppConfig(appProject))
101
+ host.swiftPackageWatchFiles(packagePath, undefined)
102
+ appInfo = host.swiftProjectAppInfo(packagePath)
103
+ } catch (error) {
104
+ host.disposeSwiftProject(packagePath)
105
+ throw error
106
+ }
107
+ return {
108
+ host,
109
+ module,
110
+ packagePath,
111
+ name,
112
+ appProject,
113
+ appInfo,
114
+ async build(origin: string) {
115
+ const config = await loadRNXAppConfig(appProject)
116
+ host.configureSwiftStandinBehavior(packagePath, config)
117
+ const source = await produceConfiguredBundle(
118
+ swiftGuestBundle(name),
119
+ config,
120
+ new Set(),
121
+ )
122
+ const guestSource = appInfo.identity
123
+ ? insertNativeAppIdentityFooter(source, appInfo.identity)
124
+ : source
125
+ const metadata = await host.swiftPackageMetadata(
126
+ packagePath,
127
+ name,
128
+ module?.root,
129
+ origin,
130
+ opts.hosted,
131
+ opts.signal,
132
+ )
133
+ return { guestSource, metadata }
134
+ },
135
+ dispose() {
136
+ host.disposeSwiftProject(packagePath, opts.signal)
137
+ },
138
+ }
139
+ }
140
+
141
+ // the packager writes these existing guest routes beside its own runtime.
142
+ // no source checkout, compiler or foreground build server is needed at launch.
143
+ export async function prepareNativeInput(
144
+ input: NativeInput,
145
+ opts: {
146
+ origin: string
147
+ target?: string
148
+ scheme?: string
149
+ activity?: string
150
+ signal?: AbortSignal
151
+ },
152
+ ) {
153
+ if (input.kind === 'kotlin') {
154
+ const host = await import('../src/kotlin-host')
155
+ const { readAndroidPins, readKotlinApp } = await import('../src/kotlin-app')
156
+ const moduleRoot = host.peachKotlinModuleRoot()
157
+ const project = readKotlinApp(input.path, {
158
+ activity: opts.activity,
159
+ pins: readAndroidPins(moduleRoot),
160
+ })
161
+ const metadata = await host.kotlinAppArtifact(project, moduleRoot, opts.origin)
162
+ const prefix = new URL(metadata.url).pathname.slice(0, -'app.mjs'.length)
163
+ return {
164
+ name: path.basename(project.projectDir),
165
+ guestSource: kotlinGuestBundle(),
166
+ guestPath: KOTLIN_GUEST_PATH,
167
+ metadataPath: host.KOTLIN_PACKAGE_PATH,
168
+ metadata: { ...metadata, hmrPath: '/__peach/kotlin-hmr' },
169
+ icon: null,
170
+ assets: new Map(
171
+ host
172
+ .kotlinArtifactFiles(metadata.hash)
173
+ .map(({ name, ...asset }) => [prefix + name, asset]),
174
+ ),
175
+ dispose() {},
176
+ }
177
+ }
178
+ const prepared = await prepareSwiftInput(input, opts)
179
+ try {
180
+ const built = await prepared.build(opts.origin)
181
+ const assets = prepared.host.swiftPackageAssets(
182
+ prepared.packagePath,
183
+ built.metadata.hash,
184
+ )
185
+ return {
186
+ name: prepared.appInfo.name,
187
+ ...built,
188
+ metadata: { ...built.metadata, hmrPath: opts.origin + SWIFT_HMR_PATH },
189
+ guestPath: SWIFT_GUEST_PATH,
190
+ metadataPath: SWIFT_PACKAGE_PATH + encodeURIComponent(prepared.name),
191
+ icon: prepared.appInfo.icon,
192
+ assets,
193
+ dispose: prepared.dispose,
194
+ }
195
+ } catch (error) {
196
+ prepared.dispose()
197
+ throw error
198
+ }
199
+ }
@@ -266,6 +266,27 @@ export interface OutboundCallDeclaration {
266
266
  // a new fetch, websocket, node HTTP request, or TCP connection has no entry and
267
267
  // fails scripts/check/outbound-endpoints.ts until its destination and consent behavior are declared.
268
268
  export const DECLARED_OUTBOUND_CALLS: Record<string, OutboundCallDeclaration> = {
269
+ 'packages/peachsim/cli/commands/package.ts :: fetch :: target': {
270
+ category: 'guest_app_network',
271
+ count: 1,
272
+ },
273
+ 'packages/peachsim/cli/commands/package.ts :: fetch :: channel.bundleUrl': {
274
+ category: 'guest_app_network',
275
+ count: 1,
276
+ },
277
+ 'packages/peachsim/cli/commands/package.ts :: fetch :: channel.iconUrl': {
278
+ category: 'guest_app_network',
279
+ count: 1,
280
+ },
281
+ "packages/peachsim/cli/commands/package.ts :: fetch :: `${directory.href.replace(/\\/$/, '')}/${filename}`":
282
+ {
283
+ category: 'guest_app_network',
284
+ count: 1,
285
+ },
286
+ 'packages/peachsim/cli/commands/package.ts :: fetch :: url': {
287
+ category: 'guest_app_network',
288
+ count: 1,
289
+ },
269
290
  'packages/peach-engine/src/launch-metadata.ts :: fetch :: reference': {
270
291
  category: 'local_development',
271
292
  count: 1,
@@ -519,6 +540,10 @@ export const DECLARED_OUTBOUND_CALLS: Record<string, OutboundCallDeclaration> =
519
540
  category: 'guest_app_network',
520
541
  count: 1,
521
542
  },
543
+ 'packages/peach-engine/src/react-native/NetworkingBody.ts :: fetch :: data.uri': {
544
+ category: 'guest_app_network',
545
+ count: 1,
546
+ },
522
547
  'packages/peach-engine/src/engine/font-data.ts :: fetch-alias :: String(wasmUrl)': {
523
548
  category: 'same_origin_runtime',
524
549
  count: 1,
@@ -583,7 +608,7 @@ export const DECLARED_OUTBOUND_CALLS: Record<string, OutboundCallDeclaration> =
583
608
  category: 'guest_app_network',
584
609
  count: 1,
585
610
  },
586
- 'packages/peach-engine/src/react-native/index.ts :: fetch :: resource': {
611
+ 'packages/peach-engine/src/react-native/file-access-module.ts :: fetch :: resource': {
587
612
  category: 'guest_app_network',
588
613
  count: 1,
589
614
  },
@@ -0,0 +1,95 @@
1
+ import { APP_PACKAGE_ADDRESS_PATTERN } from '../src/appPackageContract'
2
+
3
+ // runs with the host's bundled Node, then replaces itself with the native host.
4
+ // keeping the pid lets Launch Services and background launchers track the app.
5
+ export const packagedAppLauncher = String.raw`
6
+ const fs = require('node:fs');
7
+ const path = require('node:path');
8
+ const os = require('node:os');
9
+ const { spawn } = require('node:child_process');
10
+
11
+ async function main() {
12
+ const resources = __dirname;
13
+ const manifest = JSON.parse(fs.readFileSync(path.join(resources, 'peach-app.json'), 'utf8'));
14
+ const args = process.argv.slice(2);
15
+ const homeFlag = args.indexOf('--peach-app-home');
16
+ const home = homeFlag < 0 ? path.join(os.homedir(), 'Library', 'Application Support', manifest.identifier) : path.resolve(args.splice(homeFlag, 2)[1]);
17
+ fs.mkdirSync(path.join(home, 'runtimes'), { recursive: true, mode: 0o700 });
18
+ const config = path.join(home, 'config.json');
19
+ if (!fs.existsSync(config)) fs.writeFileSync(config, JSON.stringify({ settings: manifest.defaults }), { flag: 'wx', mode: 0o600 });
20
+ const desktop = path.join(home, 'desktop');
21
+ fs.mkdirSync(desktop, { recursive: true });
22
+ const windowState = path.join(desktop, 'window-state.json');
23
+ if (!fs.existsSync(windowState)) fs.writeFileSync(windowState, JSON.stringify({ default: { device: manifest.defaults.deviceModel, posture: { posture: manifest.defaults.posture }, orientation: manifest.defaults.orientation, bezels: manifest.defaults.showFrame } }), { flag: 'wx', mode: 0o600 });
24
+ const runtime = path.join(resources, 'runtime');
25
+ const link = path.join(home, 'runtimes', manifest.runtimeVersion);
26
+ const env = Object.fromEntries(Object.entries({ ...process.env, PEACH_HOME: home, PEACH_APP_MANIFEST: path.join(resources, 'peach-app.json'), PEACH_UPDATE_CHECK: '0', SOOTSIM_DEV: '0' }).filter(([, value]) => value !== undefined));
27
+ const lockPath = path.join(home, 'daemon.json');
28
+ function readLock() {
29
+ if (!fs.existsSync(lockPath)) return null;
30
+ const lock = JSON.parse(fs.readFileSync(lockPath, 'utf8'));
31
+ if (Date.now() - lock.heartbeatAt > 30000) return null;
32
+ try { process.kill(lock.pid, 0); } catch (error) { if (error.code === 'ESRCH') return null; throw error; }
33
+ if (lock.bootstrapping) return null;
34
+ return lock;
35
+ }
36
+ let lock = readLock();
37
+ const recordPath = path.join(home, 'app-runtime.json');
38
+ const record = fs.existsSync(recordPath) ? JSON.parse(fs.readFileSync(recordPath, 'utf8')) : null;
39
+ if (lock && (record?.pid !== lock.pid || record.buildId !== manifest.buildId)) {
40
+ await new Promise((resolve, reject) => {
41
+ const watcher = fs.watch(home, () => { if (!readLock()) { watcher.close(); clearTimeout(timer); resolve(); } });
42
+ const timer = setTimeout(() => { watcher.close(); reject(new Error('Quit the previous app version before opening this update.')); }, 30000);
43
+ });
44
+ lock = null;
45
+ }
46
+ if (fs.lstatSync(link, { throwIfNoEntry: false })) fs.unlinkSync(link);
47
+ fs.symlinkSync(runtime, link, 'dir');
48
+ fs.writeFileSync(path.join(home, 'runtimes', 'active'), manifest.runtimeVersion + '\n');
49
+ if (!lock) {
50
+ lock = await new Promise((resolve, reject) => {
51
+ let child;
52
+ let settled = false;
53
+ const watcher = fs.watch(home, () => {
54
+ try { const ready = readLock(); if (ready) finish(null, ready); } catch (error) { finish(error); }
55
+ });
56
+ const timer = setTimeout(() => finish(new Error('The bundled Peach runtime did not become ready.')), 30000);
57
+ function finish(error, ready) {
58
+ if (settled) return;
59
+ settled = true;
60
+ watcher.close(); clearTimeout(timer);
61
+ if (error) { child?.kill('SIGTERM'); reject(error); } else resolve(ready);
62
+ }
63
+ const log = fs.openSync(path.join(home, 'runtime.log'), 'a', 0o600);
64
+ child = spawn(path.join(resources, 'bin', 'peach'), ['serve', '--quiet', '--port', '0', '--exit-when-unused'], { env, detached: true, stdio: ['pipe', log, log] });
65
+ fs.closeSync(log);
66
+ child.once('error', error => finish(error));
67
+ child.once('exit', code => finish(new Error('Bundled runtime exited: ' + code)));
68
+ child.unref();
69
+ });
70
+ }
71
+ fs.writeFileSync(recordPath, JSON.stringify({ pid: lock.pid, buildId: manifest.buildId }));
72
+ const address = new RegExp(${JSON.stringify(APP_PACKAGE_ADDRESS_PATTERN)}, 'gi');
73
+ function relocate(text) {
74
+ return text.replace(address, match => match.slice(0, -new URL(manifest.origin).port.length) + lock.bridgePort);
75
+ }
76
+ const staged = path.join(home, 'cache', 'staged');
77
+ fs.mkdirSync(staged, { recursive: true });
78
+ for (const name of fs.readdirSync(path.join(resources, 'payload'))) {
79
+ const source = path.join(resources, 'payload', name);
80
+ const destination = path.join(staged, name);
81
+ if (manifest.relocatableFiles.includes(name)) fs.writeFileSync(destination, relocate(fs.readFileSync(source, 'utf8')));
82
+ else fs.copyFileSync(source, destination);
83
+ }
84
+ const url = new URL(relocate(manifest.launchUrl));
85
+ url.searchParams.set('wsPort', String(lock.bridgePort));
86
+ const saved = JSON.parse(fs.readFileSync(windowState, 'utf8')).default;
87
+ url.searchParams.set('device', saved.device);
88
+ url.searchParams.set('posture', saved.posture.posture);
89
+ url.searchParams.set('orientation', saved.orientation ?? manifest.defaults.orientation);
90
+ env.PEACH_BRIDGE_PORT = String(lock.bridgePort);
91
+ const executable = path.join(resources, '..', 'MacOS', manifest.hostExecutable);
92
+ process.execve(executable, [executable, '--url', url.href, '-SUEnableAutomaticChecks', 'NO', '-SUAutomaticallyUpdate', 'NO', ...manifest.hostArguments, ...args], env);
93
+ }
94
+ main().catch(error => { console.error(error); process.exitCode = 1; });
95
+ `