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
package/src/home-paths.ts CHANGED
@@ -185,9 +185,43 @@ export function cacheDir(): string {
185
185
  return path.join(rnxHomeDir(), 'cache')
186
186
  }
187
187
 
188
+ export const BUILDERS_ROOT_ENV = 'CONTRAST_BUILDERS_ROOT'
189
+
190
+ // builder sessions export the resolved native build root (`<heavy>/builders`
191
+ // when machine policy configures heavy storage, else `~/builders`).
192
+ // remote.sh refuses before source transfer when a configured root is
193
+ // unavailable, so a set value is always usable and nothing here falls back to
194
+ // the internal disk: a missing directory fails at first write like the other
195
+ // heavy-root consumers.
196
+ function buildersRootEnv(): string | null {
197
+ const root = process.env[BUILDERS_ROOT_ENV]?.trim()
198
+ return root ? root : null
199
+ }
200
+
201
+ // machine-wide swift scratch and package caches, shared across lanes. on a
202
+ // builder this is the resolved heavy volume; everywhere else it stays
203
+ // ~/.peach/cache, so dev machines, containers and CI keep their layout.
204
+ export function swiftCacheDir(): string {
205
+ const root = buildersRootEnv()
206
+ return root ? path.join(root, 'peach-cache') : cacheDir()
207
+ }
208
+
209
+ // per-build-key swift project roots. on a builder every lane shares one
210
+ // machine-wide directory on the heavy volume (the key is content-derived, so
211
+ // lanes agree, and the root lock serializes concurrent builders); elsewhere
212
+ // roots stay in the checkout so two checkouts never build each other's
213
+ // sources. kept apart from the shared verified artifacts below: the builder
214
+ // script prunes idle keys here and must never sweep that cache.
215
+ export function swiftProjectBuildsDir(checkoutRoot: string): string {
216
+ const root = buildersRootEnv()
217
+ return root
218
+ ? path.join(swiftCacheDir(), 'swift-project-builds')
219
+ : path.join(checkoutRoot, 'scripts', 'tmp', 'swift-projects')
220
+ }
221
+
188
222
  // swiftpm otherwise uses shared caches and configuration outside PEACH_HOME.
189
223
  export function swiftPackageCacheOptions(): string[] {
190
- const root = path.join(cacheDir(), 'swiftpm')
224
+ const root = path.join(swiftCacheDir(), 'swiftpm')
191
225
  return ['cache', 'config', 'security'].flatMap((name) => [
192
226
  `--${name}-path`,
193
227
  path.join(root, name),
@@ -0,0 +1,47 @@
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+ import { cacheDir } from '../home-paths'
4
+ import { isRecord } from '../is-record'
5
+ import type { IncomingMessage, ServerResponse } from 'node:http'
6
+
7
+ function readRoutes() {
8
+ const file = process.env.PEACH_APP_MANIFEST
9
+ const routes = new Map<string, { file: string; contentType: string }>()
10
+ if (!file) return routes
11
+ const manifest: unknown = JSON.parse(fs.readFileSync(file, 'utf8'))
12
+ if (!isRecord(manifest) || manifest.schemaVersion !== 1 || !isRecord(manifest.routes))
13
+ throw new Error('invalid packaged app manifest')
14
+ for (const [route, resource] of Object.entries(manifest.routes)) {
15
+ if (
16
+ !route.startsWith('/') ||
17
+ !isRecord(resource) ||
18
+ typeof resource.file !== 'string' ||
19
+ !resource.file ||
20
+ path.basename(resource.file) !== resource.file ||
21
+ ['.', '..'].includes(resource.file) ||
22
+ typeof resource.contentType !== 'string' ||
23
+ /[\r\n]/.test(resource.contentType)
24
+ )
25
+ throw new Error(`invalid packaged app resource: ${route}`)
26
+ routes.set(route, { file: resource.file, contentType: resource.contentType })
27
+ }
28
+ return routes
29
+ }
30
+
31
+ const routes = readRoutes()
32
+
33
+ export function serveAppPackageResource(
34
+ req: IncomingMessage,
35
+ res: ServerResponse,
36
+ ): boolean {
37
+ const resource = routes.get(new URL(req.url ?? '/', 'http://localhost').pathname)
38
+ if (!resource) return false
39
+ res.setHeader('Content-Type', resource.contentType)
40
+ const stream = fs.createReadStream(path.join(cacheDir(), 'staged', resource.file))
41
+ stream.on('error', () => {
42
+ res.statusCode = 500
43
+ res.end('packaged resource unavailable')
44
+ })
45
+ stream.pipe(res)
46
+ return true
47
+ }
@@ -54,6 +54,7 @@ import {
54
54
  } from '../runtime-assets.ts'
55
55
  import { rnxRuntime } from '../runtime-delivery.ts'
56
56
  import { AgentHost, type AgentHostOptions } from './agent-host.ts'
57
+ import { serveAppPackageResource } from './app-package-handler'
57
58
  import {
58
59
  handleAppApiRequest,
59
60
  handleFetchProxyRequest,
@@ -1514,6 +1515,8 @@ export class SootSimBridgeHost {
1514
1515
  url.pathname,
1515
1516
  )
1516
1517
  if (!publicEngineFont && rejectUntrustedBridgeOrigin(req, res)) return
1518
+ if ((method === 'GET' || method === 'HEAD') && serveAppPackageResource(req, res))
1519
+ return
1517
1520
  if (req.url === '/__peach/fetch-transport') {
1518
1521
  res.writeHead(200, {
1519
1522
  'Content-Type': 'application/json',
@@ -1,3 +1,4 @@
1
+ import { AsyncLocalStorage } from 'node:async_hooks'
1
2
  import { createHash, randomUUID } from 'node:crypto'
2
3
  import fs from 'node:fs'
3
4
  import path from 'node:path'
@@ -9,6 +10,21 @@ import {
9
10
  } from '../launchMetadataContract'
10
11
  import type { IncomingMessage, ServerResponse } from 'node:http'
11
12
 
13
+ const stagedCapture = new AsyncLocalStorage<Set<string>>()
14
+
15
+ // capture only this preparation's resources, rather than copying a user's
16
+ // whole staging cache into an app. concurrent preparations remain isolated.
17
+ export async function captureStagedHostFiles<T>(
18
+ prepare: () => Promise<T>,
19
+ ): Promise<{ value: T; files: Map<string, string> }> {
20
+ const names = new Set<string>()
21
+ const value = await stagedCapture.run(names, prepare)
22
+ return {
23
+ value,
24
+ files: new Map([...names].map((name) => [name, path.join(stagedDir(), name)])),
25
+ }
26
+ }
27
+
12
28
  // local files a sim loads from the bridge: native-linked app fonts and
13
29
  // prebuilt app bundles. each is copied under its content digest, so the
14
30
  // bridge serves only what the cli staged and never an arbitrary path.
@@ -84,6 +100,7 @@ export function stageHostMetroAssets(
84
100
  )
85
101
  const name = staged.pathname.slice(STAGED_PREFIX.length)
86
102
  const destination = path.join(directory, index)
103
+ stagedCapture.getStore()?.add(index)
87
104
  const temporary = path.join(directory, randomUUID())
88
105
  try {
89
106
  fs.writeFileSync(temporary, name, { flag: 'wx' })
@@ -150,6 +167,7 @@ function writeStagedBytes(
150
167
  const digest = createHash('sha256').update(bytes).digest('hex')
151
168
  extension = extension.toLowerCase()
152
169
  const name = STAGED_NAME.test(digest + extension) ? digest + extension : digest
170
+ stagedCapture.getStore()?.add(name)
153
171
  const destination = path.join(directory, name)
154
172
  const now = Date.now()
155
173
  if (fs.existsSync(destination)) {
package/src/index.ts CHANGED
@@ -35,6 +35,9 @@ export type {
35
35
  SimSemanticResolveSelector,
36
36
  SimSemanticTargetSelector,
37
37
  SimSemanticSelector,
38
+ SimTapDiagnostics,
39
+ SimTapResult,
40
+ SimTapResultReason,
38
41
  } from './bridge-contract'
39
42
  export {
40
43
  isRnxCaptureRegionAtlas,
@@ -13,6 +13,7 @@ import { promisify } from 'node:util'
13
13
  import { parse } from 'acorn'
14
14
  import { rnxHomeDir } from './home-paths'
15
15
  import { isRecord } from './is-record'
16
+ import { kotlinInstanceSource } from './kotlin-instance-source'
16
17
  import { installKotlinSdkArchive } from './kotlin-sdk'
17
18
  import {
18
19
  ensureToolchain,
@@ -151,7 +152,7 @@ function entrySource(ids: string[]): string {
151
152
  ].join('\n')
152
153
  }
153
154
 
154
- const BUILD_FORMAT = 17
155
+ const BUILD_FORMAT = 19
155
156
  const builds = new Map<string, Promise<KotlinArtifact>>()
156
157
 
157
158
  function buildsDir(): string {
@@ -1249,27 +1250,29 @@ async function compileKotlin(
1249
1250
  }
1250
1251
  const entry = path.join(work, 'js/app.mjs')
1251
1252
  const entrySource = fs.readFileSync(entry, 'utf8')
1252
- const hasDefault = parse(entrySource, {
1253
- ecmaVersion: 'latest',
1254
- sourceType: 'module',
1255
- }).body.some(
1256
- (statement) =>
1257
- statement.type === 'ExportDefaultDeclaration' ||
1258
- (statement.type === 'ExportNamedDeclaration' &&
1259
- statement.specifiers.some(
1260
- (specifier) =>
1261
- specifier.exported.type === 'Identifier' &&
1262
- specifier.exported.name === 'default',
1263
- )),
1253
+ const importsPath = path.join(work, 'js/app.import-object.mjs')
1254
+ const importsFactory = kotlinInstanceSource(
1255
+ fs.readFileSync(importsPath, 'utf8'),
1256
+ 'createKotlinImportObject',
1264
1257
  )
1265
- fs.renameSync(entry, path.join(work, 'js/app-runtime.mjs'))
1258
+ const runtimeFactory = kotlinInstanceSource(
1259
+ entrySource,
1260
+ 'createKotlinInstance',
1261
+ new Map([['./app.import-object.mjs', 'createKotlinImportObject']]),
1262
+ )
1263
+ fs.writeFileSync(importsPath, importsFactory.source)
1264
+ fs.writeFileSync(path.join(work, 'js/app-runtime.mjs'), runtimeFactory.source)
1266
1265
  fs.writeFileSync(
1267
1266
  entry,
1268
1267
  [
1269
- "export * from './app-runtime.mjs';",
1270
- ...(hasDefault ? ["export { default } from './app-runtime.mjs';"] : []),
1271
- "import { peachInitializeModuleBindings } from './app-runtime.mjs';",
1272
- 'peachInitializeModuleBindings();',
1268
+ "import { createKotlinInstance } from './app-runtime.mjs';",
1269
+ 'const instance = await createKotlinInstance();',
1270
+ ...runtimeFactory.exports.map(({ exported }) =>
1271
+ exported === 'default'
1272
+ ? 'export default instance.default;'
1273
+ : `export const ${exported} = instance[${JSON.stringify(exported)}];`,
1274
+ ),
1275
+ 'instance.peachInitializeModuleBindings();',
1273
1276
  '',
1274
1277
  ].join('\n'),
1275
1278
  )
@@ -0,0 +1,126 @@
1
+ import { parse, type Pattern, type Expression } from 'acorn'
2
+
3
+ function bindingNames(pattern: Pattern | Expression): string[] {
4
+ if (pattern.type === 'Identifier') return [pattern.name]
5
+ if (pattern.type === 'ObjectPattern')
6
+ return pattern.properties.flatMap((property) =>
7
+ bindingNames(property.type === 'RestElement' ? property.argument : property.value),
8
+ )
9
+ if (pattern.type === 'ArrayPattern')
10
+ return pattern.elements.flatMap((element) => (element ? bindingNames(element) : []))
11
+ if (pattern.type === 'AssignmentPattern') return bindingNames(pattern.left)
12
+ if (pattern.type === 'RestElement') return bindingNames(pattern.argument)
13
+ throw new Error(`unsupported Kotlin export binding ${pattern.type}`)
14
+ }
15
+
16
+ // compiler-generated module state belongs to an instance, including closures in
17
+ // the import object that retain its exports, memory and guest object identities.
18
+ export function kotlinInstanceSource(
19
+ source: string,
20
+ factory: string,
21
+ instanceImports: ReadonlyMap<string, string> = new Map(),
22
+ ): { source: string; exports: { local: string; exported: string }[] } {
23
+ const program = parse(source, { ecmaVersion: 'latest', sourceType: 'module' })
24
+ const imports: string[] = []
25
+ const body: string[] = []
26
+ let dependencies = 0
27
+ const exports: { local: string; exported: string }[] = []
28
+ for (const statement of program.body) {
29
+ if (statement.type === 'ImportDeclaration') {
30
+ const importedFactory =
31
+ typeof statement.source.value === 'string'
32
+ ? instanceImports.get(statement.source.value)
33
+ : undefined
34
+ if (!importedFactory) {
35
+ imports.push(source.slice(statement.start, statement.end))
36
+ continue
37
+ }
38
+ imports.push(
39
+ `import { ${importedFactory} } from ${JSON.stringify(statement.source.value)};`,
40
+ )
41
+ const names = statement.specifiers.map((specifier) => {
42
+ if (
43
+ specifier.type !== 'ImportSpecifier' ||
44
+ specifier.imported.type !== 'Identifier'
45
+ )
46
+ throw new Error('unsupported Kotlin instance import')
47
+ return `${specifier.imported.name}: ${specifier.local.name}`
48
+ })
49
+ const dependency = `__peachDependency${dependencies++}`
50
+ body.push(
51
+ `const ${dependency} = ${importedFactory}();`,
52
+ `__peachDisposers.push(${dependency}.peachDisposeInstance);`,
53
+ `const { ${names.join(', ')} } = ${dependency};`,
54
+ )
55
+ } else if (statement.type === 'ExportNamedDeclaration') {
56
+ const declaration = statement.declaration
57
+ if (declaration) {
58
+ body.push(source.slice(declaration.start, declaration.end))
59
+ const names =
60
+ declaration.type === 'VariableDeclaration'
61
+ ? declaration.declarations.flatMap((item) => bindingNames(item.id))
62
+ : declaration.id
63
+ ? [declaration.id.name]
64
+ : []
65
+ exports.push(...names.map((name) => ({ local: name, exported: name })))
66
+ } else {
67
+ if (statement.source) throw new Error('unsupported Kotlin instance re-export')
68
+ for (const specifier of statement.specifiers) {
69
+ if (
70
+ specifier.local.type !== 'Identifier' ||
71
+ specifier.exported.type !== 'Identifier'
72
+ )
73
+ throw new Error('unsupported Kotlin export name')
74
+ exports.push({ local: specifier.local.name, exported: specifier.exported.name })
75
+ }
76
+ }
77
+ } else if (statement.type === 'ExportDefaultDeclaration') {
78
+ body.push(
79
+ `const __defaultExport = (${source.slice(statement.declaration.start, statement.declaration.end)});`,
80
+ )
81
+ exports.push({ local: '__defaultExport', exported: 'default' })
82
+ } else if (statement.type === 'ExportAllDeclaration') {
83
+ throw new Error('unsupported Kotlin instance re-export')
84
+ } else {
85
+ body.push(source.slice(statement.start, statement.end))
86
+ }
87
+ }
88
+ return {
89
+ source: `${imports.join('\n')}
90
+ export ${instanceImports.size ? 'async ' : ''}function ${factory}() {
91
+ const __peachTimers = new Set();
92
+ const __peachDisposers = [];
93
+ let __peachClosed = false;
94
+ function peachDisposeInstance() {
95
+ if (__peachClosed) return;
96
+ __peachClosed = true;
97
+ for (const timer of __peachTimers) globalThis.clearTimeout(timer);
98
+ __peachTimers.clear();
99
+ for (const dispose of __peachDisposers) dispose();
100
+ __peachDisposers.length = 0;
101
+ }
102
+ const setTimeout = (callback, delay, ...args) => {
103
+ if (__peachClosed) return 0;
104
+ const timer = globalThis.setTimeout(() => {
105
+ __peachTimers.delete(timer);
106
+ if (!__peachClosed) callback(...args);
107
+ }, delay);
108
+ __peachTimers.add(timer);
109
+ return timer;
110
+ };
111
+ const clearTimeout = timer => {
112
+ __peachTimers.delete(timer);
113
+ globalThis.clearTimeout(timer);
114
+ };
115
+ try {
116
+ ${body.join('\n')}
117
+ return { peachDisposeInstance, ${exports.map((item) => `${JSON.stringify(item.exported)}: ${item.local}`).join(', ')} };
118
+ } catch (error) {
119
+ peachDisposeInstance();
120
+ throw error;
121
+ }
122
+ }
123
+ `,
124
+ exports,
125
+ }
126
+ }
package/src/menu.ts CHANGED
@@ -136,6 +136,7 @@ export interface SootSimMenuState {
136
136
  developmentMode: boolean
137
137
  showBezels: boolean
138
138
  showTouches: boolean
139
+ systemCursor: boolean
139
140
  slowAnimations: boolean
140
141
  showMenuBar: boolean
141
142
  showRail: boolean
@@ -571,6 +572,12 @@ function windowMenu(state: SootSimMenuState): SootSimMenuDef {
571
572
  checked: state.showTouches,
572
573
  action: 'toggle-touches',
573
574
  },
575
+ {
576
+ label: 'Use System Cursor',
577
+ type: 'checkbox',
578
+ checked: state.systemCursor,
579
+ action: 'toggle-system-cursor',
580
+ },
574
581
  {
575
582
  label: 'Show Menu Bar',
576
583
  type: 'checkbox',
@@ -224,10 +224,12 @@ export function readNativeAppIdentityFromProject(
224
224
  parseInfoPlist: (source: string) => unknown = parsePlistSource,
225
225
  iosTarget?: string,
226
226
  androidMergedManifest?: string,
227
+ environment?: Record<string, string>,
227
228
  ): NativeAppIdentity | null {
228
229
  const read = selectNativeAppIdentityReader(platform, {
229
230
  android: () => readAndroidNativeAppIdentity(projectRoot, androidMergedManifest),
230
- ios: () => readIosNativeAppIdentity(projectRoot, parseInfoPlist, iosTarget),
231
+ ios: () =>
232
+ readIosNativeAppIdentity(projectRoot, parseInfoPlist, iosTarget, environment),
231
233
  })
232
234
  return read ? read() : null
233
235
  }
@@ -329,8 +331,9 @@ function readIosNativeAppIdentity(
329
331
  projectRoot: string,
330
332
  parseInfoPlist: (source: string) => unknown,
331
333
  iosTarget: string | undefined,
334
+ environment: Record<string, string> | undefined,
332
335
  ): NativeAppIdentity | null {
333
- const app = readIosAppTarget(projectRoot, iosTarget)
336
+ const app = readIosAppTarget(projectRoot, iosTarget, environment)
334
337
  if (!app) return null
335
338
  const identity = readNativeAppIdentityFromXcodeTarget(app, parseInfoPlist)
336
339
  const projectManifestPath = path.join(projectRoot, 'package.json')
@@ -395,6 +398,7 @@ function readIosNativeAppIdentity(
395
398
  export function readIosAppTarget(
396
399
  projectRoot: string,
397
400
  iosTarget?: string,
401
+ environment?: Record<string, string>,
398
402
  ): XcodeAppTarget | null {
399
403
  const iosRoot = path.join(projectRoot, 'ios')
400
404
  if (!fs.existsSync(iosRoot)) return null
@@ -434,5 +438,6 @@ export function readIosAppTarget(
434
438
  return readXcodeAppTarget(xcodeproj, iosTarget ?? appTargets[0], 'Release', {
435
439
  requireSources: false,
436
440
  prepareGeneratedSources: true,
441
+ environment,
437
442
  })
438
443
  }
@@ -65,6 +65,9 @@ export interface NativeAppIdentity {
65
65
  // declarations from the selected app manifest merger output; install-time
66
66
  // SDK filtering belongs to the evaluation's device, not the bundle builder.
67
67
  androidManifestPermissions?: readonly AndroidManifestPermission[]
68
+ // the application meta-data one prebuild stamps for native.app.photoLibrary.addOnly.
69
+ // carried only from the completed merger output when the value is literal true.
70
+ androidPhotoLibraryAddOnly?: true
68
71
  permissionUsageDescriptions?: Readonly<Record<string, unknown>>
69
72
  // every top-level string the app's Info.plist declares, build settings
70
73
  // resolved, for native code that reads its own plist keys.
@@ -151,6 +154,11 @@ export function isNativeAppIdentity(value: unknown): value is NativeAppIdentity
151
154
  ))
152
155
  )
153
156
  return false
157
+ if (
158
+ value.androidPhotoLibraryAddOnly !== undefined &&
159
+ value.androidPhotoLibraryAddOnly !== true
160
+ )
161
+ return false
154
162
  if (value.googleSignIn !== undefined && !isRecord(value.googleSignIn)) return false
155
163
  const descriptions = value.permissionUsageDescriptions
156
164
  if (
@@ -315,6 +323,9 @@ export function readNativeAppIdentity(value: unknown): NativeAppIdentity | null
315
323
  (permission) => ({ ...permission }),
316
324
  ),
317
325
  }),
326
+ ...(value.androidPhotoLibraryAddOnly === undefined
327
+ ? {}
328
+ : { androidPhotoLibraryAddOnly: value.androidPhotoLibraryAddOnly }),
318
329
  ...(value.googleSignIn === undefined
319
330
  ? {}
320
331
  : { googleSignIn: structuredClone(value.googleSignIn) }),
@@ -2,6 +2,7 @@
2
2
  // expose only FirebaseOptions, never a partner-specific extra configuration.
3
3
  import { spawn, spawnSync } from 'node:child_process'
4
4
  import fs from 'node:fs'
5
+ import { createRequire } from 'node:module'
5
6
  import os from 'node:os'
6
7
  import path from 'node:path'
7
8
  import { isRecord } from './is-record'
@@ -10,15 +11,37 @@ import { listXcodeAppTargets, readXcodeAppTarget } from './xcode-project'
10
11
 
11
12
  // expo's synchronous ESM/TypeScript loader requires Node's module evaluator.
12
13
  // a private result file keeps authored console output off the configuration wire.
14
+ // Expo's CLI loads the project's .env files into process.env before it reads the
15
+ // config, so an app.config that reads EXPO_PUBLIC_* values evaluates the same here.
16
+ // @expo/config is a dependency of the project's expo package, and @expo/env
17
+ // ships with the CLI that package depends on; a strict pnpm layout exposes
18
+ // neither to the project itself.
13
19
  const EXPO_CONFIG_SCRIPT = `const { createRequire } = require('node:module');
14
20
  const { writeFileSync } = require('node:fs');
15
21
  const { join } = require('node:path');
16
22
  const root = process.argv[1];
17
- const { getConfig } = createRequire(join(root, 'package.json'))('@expo/config');
23
+ const projectRequire = createRequire(join(root, 'package.json'));
24
+ const expoRequire = createRequire(projectRequire.resolve('expo/package.json'));
25
+ const { getConfig } = expoRequire('@expo/config');
26
+ let expoEnv = null;
27
+ try { expoEnv = createRequire(expoRequire.resolve('@expo/cli/package.json'))('@expo/env'); } catch {}
28
+ if (expoEnv) {
29
+ process.env.NODE_ENV ||= 'development';
30
+ expoEnv.load(root, { silent: true });
31
+ }
18
32
  const result = JSON.stringify(getConfig(root, { skipSDKVersionRequirement: true }).exp);
19
33
  if (Buffer.byteLength(result) > 1024 * 1024) throw new Error('Expo native configuration exceeds 1 MiB.');
20
34
  writeFileSync(process.argv[2], result, { mode: 0o600 });`
21
35
 
36
+ // the project's own @expo/config, reached through its expo package as in
37
+ // EXPO_CONFIG_SCRIPT; throws when the project has no expo install.
38
+ export function resolveExpoConfigModule(appDir: string) {
39
+ const expo = createRequire(path.join(appDir, 'package.json')).resolve(
40
+ 'expo/package.json',
41
+ )
42
+ return createRequire(expo).resolve('@expo/config')
43
+ }
44
+
22
45
  function hasExpoConfig(projectRoot: string) {
23
46
  const appJsonPath = path.join(projectRoot, 'app.json')
24
47
  const appJson: unknown = fs.existsSync(appJsonPath)