peachsim 0.1.1728 → 0.1.1738

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/cli/commands/control.ts +1 -0
  2. package/cli/commands/coverage-swift.ts +112 -4
  3. package/cli/commands/package.ts +11 -1
  4. package/cli/commands/shell-url.ts +4 -0
  5. package/cli/scene-video.ts +24 -7
  6. package/detox/index.ts +9 -1
  7. package/dist-lib/agent-daemon-client.cjs +1 -1
  8. package/dist-lib/agent-events.cjs +1 -1
  9. package/dist-lib/attached-projects.cjs +5 -2
  10. package/dist-lib/auth/shared-session.cjs +5 -2
  11. package/dist-lib/backend-origin.cjs +1 -1
  12. package/dist-lib/beta.cjs +1 -1
  13. package/dist-lib/beta.mjs +1 -1
  14. package/dist-lib/bridge-constants.cjs +1 -1
  15. package/dist-lib/bridge-contract-input.cjs +1 -1
  16. package/dist-lib/bridge-contract-input.mjs +1 -1
  17. package/dist-lib/bridge-contract.cjs +1 -1
  18. package/dist-lib/bridge-contract.mjs +1 -1
  19. package/dist-lib/bundle-channel.cjs +3592 -1918
  20. package/dist-lib/capture-contract.cjs +1 -1
  21. package/dist-lib/capture-contract.mjs +1 -1
  22. package/dist-lib/cloud-contract.cjs +1 -1
  23. package/dist-lib/cloud-contract.mjs +1 -1
  24. package/dist-lib/cloud-test-args.cjs +1 -1
  25. package/dist-lib/cloud-test-args.mjs +1 -1
  26. package/dist-lib/cloud.cjs +1 -1
  27. package/dist-lib/cloud.mjs +1 -1
  28. package/dist-lib/config.cjs +1 -1
  29. package/dist-lib/config.mjs +1 -1
  30. package/dist-lib/detox/index.cjs +13 -5
  31. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  32. package/dist-lib/expo-swift-bundle.cjs +1329 -1022
  33. package/dist-lib/expo-swift-metadata.cjs +2 -2
  34. package/dist-lib/expo-swift-metadata.mjs +2 -2
  35. package/dist-lib/home-paths.cjs +7 -2
  36. package/dist-lib/host/bridge-host.cjs +3773 -2149
  37. package/dist-lib/host/fetch-proxy-handler.cjs +16 -5
  38. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  39. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  40. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  41. package/dist-lib/host/websocket-proxy.cjs +1 -1
  42. package/dist-lib/index.cjs +97 -68
  43. package/dist-lib/jump-to-source-babel.cjs +1 -1
  44. package/dist-lib/jump-to-source-native.cjs +1 -1
  45. package/dist-lib/kotlin-host.cjs +209 -32
  46. package/dist-lib/menu.cjs +7 -1
  47. package/dist-lib/menu.mjs +7 -1
  48. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  49. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  50. package/dist-lib/metro-production-bundle.cjs +1 -1
  51. package/dist-lib/metro-production-bundle.mjs +1 -1
  52. package/dist-lib/metro.cjs +93 -65
  53. package/dist-lib/native-app-identity-project.cjs +37 -31
  54. package/dist-lib/native-app-identity-project.mjs +37 -31
  55. package/dist-lib/native-app-identity.cjs +1 -1
  56. package/dist-lib/native-app-identity.mjs +1 -1
  57. package/dist-lib/native-firebase-metadata.cjs +1 -1
  58. package/dist-lib/native-firebase-metadata.mjs +1 -1
  59. package/dist-lib/plist.cjs +1 -1
  60. package/dist-lib/plist.mjs +1 -1
  61. package/dist-lib/profiles.cjs +5 -2
  62. package/dist-lib/public-brand.cjs +1 -1
  63. package/dist-lib/public-origins-lib-esm.json +23 -23
  64. package/dist-lib/public-origins-lib.json +79 -53
  65. package/dist-lib/react-native-host-modules.cjs +5 -2
  66. package/dist-lib/react-native-host-modules.mjs +5 -2
  67. package/dist-lib/reap-browser.cjs +1 -1
  68. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  69. package/dist-lib/sdk.cjs +1 -1
  70. package/dist-lib/sdk.mjs +1 -1
  71. package/dist-lib/skills.cjs +4486 -2789
  72. package/dist-lib/swift-compile.cjs +53 -60
  73. package/dist-lib/swift-compile.mjs +52 -60
  74. package/dist-lib/swift-package.cjs +1 -1
  75. package/dist-lib/swift-package.mjs +1 -1
  76. package/dist-lib/swift-submit.cjs +2 -2
  77. package/dist-lib/swift-submit.mjs +2 -2
  78. package/dist-lib/swift-toolchain.cjs +17 -17
  79. package/dist-lib/swift.cjs +1 -1
  80. package/dist-lib/vite-swift.cjs +1056 -870
  81. package/dist-lib/vite.cjs +20 -8
  82. package/dist-lib/worklet-executable.cjs +1 -1
  83. package/dist-lib/worklet-executable.mjs +1 -1
  84. package/dist-types/packages/peach-engine/src/engine/font-config.d.ts +7 -4
  85. package/dist-types/packages/peach-engine/src/engine/image-loader.d.ts +2 -1
  86. package/dist-types/packages/peach-engine/src/engine/liquid-glass.d.ts +0 -5
  87. package/dist-types/packages/peach-engine/src/engine/memory-counts.d.ts +8 -0
  88. package/dist-types/packages/peach-engine/src/engine/node.d.ts +4 -1
  89. package/dist-types/packages/peach-engine/src/engine/render-damage.d.ts +2 -2
  90. package/dist-types/packages/peach-engine/src/engine/text-first-baseline.d.ts +5 -0
  91. package/dist-types/packages/peach-engine/src/engine/text-paragraph.d.ts +1 -0
  92. package/dist-types/packages/peach-engine/src/native-preview-bundle.d.ts +2 -0
  93. package/dist-types/packages/peach-engine/src/render-worker/protocol.d.ts +7 -2
  94. package/dist-types/packages/peach-engine/src/render-worker/shell-protocol.d.ts +1 -0
  95. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +13 -1
  96. package/dist-types/packages/peach-kit/src/capabilities.d.ts +1 -0
  97. package/kotlin/README.md +3 -0
  98. package/kotlin/sdk.tar.gz +0 -0
  99. package/package.json +1 -1
  100. package/runtime-companion.json +1 -1
  101. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACAccount.h +55 -0
  102. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACAccountCredential.h +35 -0
  103. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACAccountStore.h +94 -0
  104. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACAccountType.h +53 -0
  105. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/ACError.h +37 -0
  106. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/Accounts.h +13 -0
  107. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Headers/AccountsDefines.h +13 -0
  108. package/sdk/ios/System/Library/Frameworks/Accounts.framework/Modules/module.modulemap +5 -0
  109. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.h +1 -1
  110. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.apinotes +58 -3
  111. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h +636 -37
  112. package/sdk/ios/usr/include/os/signpost.h +414 -0
  113. package/sdk/ios/usr/include/os.modulemap +5 -0
  114. package/sdk/ios/wasm/include/errno.h +4 -20
  115. package/sdk/ios/wasm/include/pthread.h +3 -0
  116. package/sdk/ios/wasm/include/setjmp.h +57 -0
  117. package/sdk/ios/wasm/include/sys/resource.h +2 -2
  118. package/sdk/native-hashes.json +3 -3
  119. package/skills/peach-debug/SKILL.md +0 -1
  120. package/skills/peach-perf/SKILL.md +0 -1
  121. package/skills/peach-setup/SKILL.md +0 -1
  122. package/skills/peach-test/SKILL.md +0 -1
  123. package/skills/peach-visual/SKILL.md +0 -1
  124. package/src/android-autolinking.ts +1 -0
  125. package/src/android-bridge-packages.ts +279 -0
  126. package/src/appPackageContract.ts +2 -0
  127. package/src/bundle-channel.mjs +20 -2
  128. package/src/cli-runtime.ts +9 -5
  129. package/src/expo-discovery-cache.ts +7 -3
  130. package/src/expo-kotlin-host.ts +97 -26
  131. package/src/expo-native-workspace.ts +135 -40
  132. package/src/expo-swift-host.ts +93 -20
  133. package/src/expo-swift-ready.ts +5 -1
  134. package/src/expoKotlinContract.ts +12 -2
  135. package/src/expoSwiftContract.ts +9 -2
  136. package/src/generated/swift-c-predefines.json +1 -1
  137. package/src/home-paths.ts +6 -1
  138. package/src/host/bridge-host.ts +5 -0
  139. package/src/host/fetch-proxy-handler.ts +10 -0
  140. package/src/kotlin-host.ts +204 -30
  141. package/src/kotlinSdkContract.ts +2 -1
  142. package/src/menu.ts +7 -0
  143. package/src/native-prebuilt.ts +154 -0
  144. package/src/nitro-adapter.lock.json +251 -251
  145. package/src/nitro-adapter.ts +56 -50
  146. package/src/nitro-bundle.ts +84 -74
  147. package/src/nitro-compile.ts +10 -5
  148. package/src/nitro-dependencies.ts +43 -28
  149. package/src/nitro-source.ts +60 -26
  150. package/src/nitroAdapterContract.ts +146 -98
  151. package/src/nitroContract.ts +64 -21
  152. package/src/react-native-bridge-modules.ts +2 -0
  153. package/src/react-native-host-modules.ts +4 -1
  154. package/src/settingsContract.ts +11 -0
  155. package/src/storageSnapshotContract.ts +29 -81
  156. package/src/swift-compile.ts +49 -50
  157. package/src/swift-coverage/indexdump.ts +22 -6
  158. package/src/swift-coverage/indexing.ts +4 -4
  159. package/src/swift-coverage/sdk.ts +104 -20
  160. package/src/swift-coverage/types.ts +34 -0
  161. package/src/swift-coverage/xcode.ts +9 -1
  162. package/src/swift-distribution.lock.json +15 -12
  163. package/src/swift-host.ts +3 -0
  164. package/src/swift-standin-emit.ts +6 -1
  165. package/src/swift-standins.ts +172 -10
  166. package/src/swift-submit.ts +5 -1
  167. package/src/swift-toolchain.ts +16 -16
  168. package/src/turbo-bundle.ts +81 -0
  169. package/src/turbo-compile.ts +120 -0
  170. package/src/turbo-runtime.lock.json +69 -0
  171. package/src/turbo-source.ts +754 -0
  172. package/src/vite-plugin-one.ts +4 -3
@@ -1,35 +1,41 @@
1
- // the private Nitro adapter archive an installed peach links into every Nitro
2
- // compile: the one built against the app's own original React Native JSI and
3
- // Nitro headers, downloaded from PEACH_SWIFT_ENDPOINT, verified against the lock
4
- // this build carries, then checked against the compiler, SDK and framework the
5
- // module root compiles with (docs/swift-distribution.md). the adapter source
6
- // never reaches this machine.
1
+ // the private adapter archives an installed peach links into a native module
2
+ // compile: the Nitro adapter, and the TurboModule runtime, each built against
3
+ // the app's own original headers, downloaded from PEACH_SWIFT_ENDPOINT,
4
+ // verified against the lock this build carries, then checked against the
5
+ // compiler, SDK and framework the module root compiles with
6
+ // (docs/swift-distribution.md). the adapter source never reaches this machine.
7
7
  import fs from 'node:fs'
8
8
  import path from 'node:path'
9
9
  import { installVerifiedTarball } from '@contrast/runtime-delivery'
10
10
  import { rnxHomeDir } from './home-paths'
11
- import lockJson from './nitro-adapter.lock.json' with { type: 'json' }
11
+ import nitroLockJson from './nitro-adapter.lock.json' with { type: 'json' }
12
12
  import {
13
+ ADAPTER_FAMILIES,
14
+ ADAPTER_MANIFEST,
15
+ adapterArchiveKey,
16
+ adapterPin,
13
17
  headerDigests,
14
- NITRO_ADAPTER_MANIFEST,
15
- nitroAdapterArchiveKey,
16
- nitroAdapterPin,
17
- parseNitroAdapterLock,
18
- verifyInstalledNitroAdapter,
19
- type NitroAdapterLock,
20
- type NitroAdapterManifest,
21
- type NitroAdapterPin,
18
+ parseAdapterLock,
19
+ verifyInstalledAdapter,
20
+ type AdapterFamily,
21
+ type AdapterLock,
22
+ type AdapterManifest,
23
+ type AdapterPin,
24
+ type NitroAdapterRoots,
22
25
  } from './nitroAdapterContract'
23
26
  import { NITRO_GUEST_PLATFORM } from './nitroContract'
24
27
  import { swiftDistributionAt, swiftModuleSdk, WASM_TRIPLE } from './swift-compile'
25
28
  import { SWIFT_ENDPOINT_ENV } from './swift-distribution'
26
- import type { NitroSourceCollection } from './nitro-source'
29
+ import turboLockJson from './turbo-runtime.lock.json' with { type: 'json' }
27
30
 
28
- /** the verified adapters this build ships, the only lock normal compiles use. */
29
- export const committedNitroAdapterLock = parseNitroAdapterLock(lockJson)
31
+ /** the verified archives this build ships, the only locks normal compiles use. */
32
+ export const committedAdapterLocks: Record<AdapterFamily, AdapterLock> = {
33
+ nitro: parseAdapterLock('nitro', nitroLockJson),
34
+ turbo: parseAdapterLock('turbo', turboLockJson),
35
+ }
30
36
 
31
- export interface NitroAdapterArchive {
32
- manifest: NitroAdapterManifest
37
+ export interface AdapterArchive {
38
+ manifest: AdapterManifest
33
39
  /** the static archive, base64, as SwiftCompileInput.libraries carries it. */
34
40
  base64: string
35
41
  }
@@ -44,11 +50,12 @@ const installedVersion = (root: string) =>
44
50
  * fixes; the consumer cannot recompute it and the framework distribution id
45
51
  * does not independently bind it. */
46
52
  function selectPin(
47
- lock: NitroAdapterLock,
48
- collection: NitroSourceCollection,
53
+ family: AdapterFamily,
54
+ lock: AdapterLock,
55
+ roots: NitroAdapterRoots,
49
56
  moduleRoot: string,
50
- ): NitroAdapterPin {
51
- const { nitro, reactNative } = collection
57
+ ): AdapterPin {
58
+ const { label } = ADAPTER_FAMILIES[family]
52
59
  const distribution = swiftDistributionAt(moduleRoot)
53
60
  if (!distribution) throw new Error(`${moduleRoot} holds no Swift distribution`)
54
61
  const sdk = swiftModuleSdk(moduleRoot)
@@ -62,49 +69,48 @@ function selectPin(
62
69
  ].filter((name) => name !== false)
63
70
  if (mismatched.length > 0)
64
71
  throw new Error(
65
- `Nitro adapter archives do not match this toolchain: ${mismatched.join(', ')}`,
72
+ `${label} archives do not match this toolchain: ${mismatched.join(', ')}`,
66
73
  )
67
- const pin = nitroAdapterPin(
68
- lock,
69
- headerDigests({ nitroModules: nitro.root, reactNative: reactNative.root }),
70
- )
74
+ const pin = adapterPin(lock, headerDigests(family, roots))
71
75
  if (!pin)
72
76
  throw new Error(
73
- `this peach has no Nitro adapter for react-native ${installedVersion(reactNative.root)} with react-native-nitro-modules ${installedVersion(nitro.root)}`,
77
+ `this peach has no ${label} for react-native ${installedVersion(roots.reactNative)}${roots.nitroModules ? ` with react-native-nitro-modules ${installedVersion(roots.nitroModules)}` : ''}`,
74
78
  )
75
79
  return pin
76
80
  }
77
81
 
78
- /** the verified adapter archive for a collection: identity first, then the
79
- * download, whose tarball and unpacked bytes the lock pins. */
80
- export async function resolveNitroAdapter(
81
- collection: NitroSourceCollection,
82
+ /** the verified archive for an app's original headers: identity first, then
83
+ * the download, whose tarball and unpacked bytes the lock pins. */
84
+ export async function resolveAdapterArchive(
85
+ family: AdapterFamily,
86
+ roots: NitroAdapterRoots,
82
87
  moduleRoot: string,
83
- lock: NitroAdapterLock,
88
+ lock: AdapterLock,
84
89
  signal?: AbortSignal,
85
- ): Promise<NitroAdapterArchive> {
86
- const pin = selectPin(lock, collection, moduleRoot)
87
- const endpoint = process.env[SWIFT_ENDPOINT_ENV]?.trim().replace(/\/+$/, '')
88
- if (!endpoint)
89
- throw new Error(
90
- `Nitro compilation needs ${SWIFT_ENDPOINT_ENV} for its adapter archive`,
91
- )
92
- const dir = path.join(rnxHomeDir(), 'swift', `nitro-adapter-${pin.archive.sha256}`)
93
- if (!fs.existsSync(path.join(dir, NITRO_ADAPTER_MANIFEST))) {
94
- process.stderr.write(`peach: downloading Nitro adapter ${pin.archive.sha256}…\n`)
90
+ ): Promise<AdapterArchive> {
91
+ const { label, key } = ADAPTER_FAMILIES[family]
92
+ const pin = selectPin(family, lock, roots, moduleRoot)
93
+ const dir = path.join(rnxHomeDir(), 'swift', `${key}-${pin.archive.sha256}`)
94
+ if (!fs.existsSync(path.join(dir, ADAPTER_MANIFEST))) {
95
+ const endpoint = process.env[SWIFT_ENDPOINT_ENV]?.trim().replace(/\/+$/, '')
96
+ if (!endpoint)
97
+ throw new Error(
98
+ `native module compilation needs ${SWIFT_ENDPOINT_ENV} for its ${label}`,
99
+ )
100
+ process.stderr.write(`peach: downloading ${label} ${pin.archive.sha256}…\n`)
95
101
  await installVerifiedTarball({
96
102
  signal,
97
- url: `${endpoint}/${nitroAdapterArchiveKey(pin)}`,
103
+ url: `${endpoint}/${adapterArchiveKey(family, pin)}`,
98
104
  digest: { algorithm: 'sha256', encoding: 'hex', value: pin.archive.sha256 },
99
105
  destDir: dir,
100
- installedMarker: NITRO_ADAPTER_MANIFEST,
101
- label: 'Nitro adapter archive',
106
+ installedMarker: ADAPTER_MANIFEST,
107
+ label: `${label} archive`,
102
108
  verify: (installed) => {
103
- verifyInstalledNitroAdapter(installed, pin)
109
+ verifyInstalledAdapter(family, installed, pin)
104
110
  },
105
111
  })
106
112
  }
107
- const manifest = verifyInstalledNitroAdapter(dir, pin)
113
+ const manifest = verifyInstalledAdapter(family, dir, pin)
108
114
  return {
109
115
  manifest,
110
116
  base64: fs.readFileSync(path.join(dir, manifest.archive.path)).toString('base64'),
@@ -20,9 +20,11 @@ import type { IncomingMessage, ServerResponse } from 'node:http'
20
20
 
21
21
  export const NITRO_ROUTE = '/__peach/nitro'
22
22
 
23
+ export type CompiledModuleAsset = { path: string; bytes: Buffer; contentType: string }
24
+
23
25
  export interface NitroBundle {
24
26
  metadata: NitroCompiledModule
25
- assets: { path: string; bytes: Buffer; contentType: string }[]
27
+ assets: CompiledModuleAsset[]
26
28
  }
27
29
 
28
30
  const answeredPackages: ReadonlySet<string> = new Set(PEACH_ANSWERED_NATIVE_PACKAGE_NAMES)
@@ -93,14 +95,9 @@ export async function compileNitroApp(
93
95
  }
94
96
  }
95
97
 
96
- export async function buildNitroBundle(
97
- appRoot: string,
98
- moduleRoot?: string,
99
- ): Promise<NitroBundle | null> {
100
- const compiled = await compileNitroApp(appRoot, '', moduleRoot)
101
- if (!compiled) return null
102
- const { artifact, metadata } = compiled
103
- const assets: NitroBundle['assets'] = [
98
+ /** a compiled module's served files: its wasm and, unless shared, its ICU. */
99
+ export function compiledModuleAssets(artifact: SwiftArtifact): CompiledModuleAsset[] {
100
+ const assets: CompiledModuleAsset[] = [
104
101
  {
105
102
  path: `__peach/swift/${artifact.hash}.wasm`,
106
103
  bytes: artifact.bytes,
@@ -113,78 +110,91 @@ export async function buildNitroBundle(
113
110
  bytes: artifact.icu.gzip,
114
111
  contentType: 'application/gzip',
115
112
  })
116
- return { metadata, assets }
113
+ return assets
117
114
  }
118
115
 
119
- // one build per app root and dev server; concurrent boots share it. the
120
- // compiler reuses an unchanged artifact, so a reload pays only the source check.
121
- const compiling = new Map<string, Promise<NitroCompiledModule | null>>()
122
- const openPreparations = new NativePreparationReceipts<NitroCompiledModule | null>()
116
+ export async function buildNitroBundle(
117
+ appRoot: string,
118
+ moduleRoot?: string,
119
+ ): Promise<NitroBundle | null> {
120
+ const compiled = await compileNitroApp(appRoot, '', moduleRoot)
121
+ if (!compiled) return null
122
+ return { metadata: compiled.metadata, assets: compiledModuleAssets(compiled.artifact) }
123
+ }
123
124
 
124
- // the dev server's build of an app's installed Nitro providers. its wasm and
125
- // ICU are served from the same host by the Swift artifact route.
126
- export async function handleNitroRequest(
127
- req: IncomingMessage,
128
- res: ServerResponse,
129
- ): Promise<void> {
130
- const url = new URL(req.url ?? '/', 'http://localhost')
131
- const remote = req.socket.remoteAddress?.replace(/^::ffff:/, '')
132
- const origin = req.headers.origin
133
- if (
134
- !remote ||
135
- !isLoopbackHost(remote) ||
136
- (origin && !isLoopbackHost(new URL(origin).hostname))
137
- ) {
138
- res.writeHead(403)
139
- res.end('Nitro compilation requires a loopback client')
140
- return
141
- }
142
- res.setHeader('Access-Control-Allow-Origin', origin ?? '*')
143
- res.setHeader('Vary', 'Origin')
144
- res.setHeader('Cross-Origin-Resource-Policy', 'cross-origin')
145
- const root = url.searchParams.get('root')
146
- const host = req.headers.host
147
- if (req.method !== 'GET' || !root || !path.isAbsolute(root) || !host) {
148
- res.writeHead(400)
149
- res.end('Nitro compilation needs GET with an absolute app root')
150
- return
151
- }
152
- try {
153
- const key = `${host}\0${fs.realpathSync(root)}`
154
- const prepared = openPreparations.take(
155
- key,
156
- url.searchParams.get(NATIVE_PREPARED_QUERY_PARAM),
157
- )
158
- if (prepared) {
125
+ // the dev server's build of one kind of an app's installed native modules.
126
+ // one build per app root and dev server; concurrent boots share it. the
127
+ // compiler reuses an unchanged artifact, so a reload pays only the source
128
+ // check. its wasm and ICU are served from the same host by the Swift artifact
129
+ // route.
130
+ export function compiledModuleRequestHandler<Metadata>(
131
+ label: string,
132
+ compile: (appRoot: string, origin: string) => Promise<{ metadata: Metadata } | null>,
133
+ ): (req: IncomingMessage, res: ServerResponse) => Promise<void> {
134
+ const compiling = new Map<string, Promise<Metadata | null>>()
135
+ const openPreparations = new NativePreparationReceipts<Metadata | null>()
136
+ return async (req, res) => {
137
+ const url = new URL(req.url ?? '/', 'http://localhost')
138
+ const remote = req.socket.remoteAddress?.replace(/^::ffff:/, '')
139
+ const origin = req.headers.origin
140
+ if (
141
+ !remote ||
142
+ !isLoopbackHost(remote) ||
143
+ (origin && !isLoopbackHost(new URL(origin).hostname))
144
+ ) {
145
+ res.writeHead(403)
146
+ res.end(`${label} compilation requires a loopback client`)
147
+ return
148
+ }
149
+ res.setHeader('Access-Control-Allow-Origin', origin ?? '*')
150
+ res.setHeader('Vary', 'Origin')
151
+ res.setHeader('Cross-Origin-Resource-Policy', 'cross-origin')
152
+ const root = url.searchParams.get('root')
153
+ const host = req.headers.host
154
+ if (req.method !== 'GET' || !root || !path.isAbsolute(root) || !host) {
155
+ res.writeHead(400)
156
+ res.end(`${label} compilation needs GET with an absolute app root`)
157
+ return
158
+ }
159
+ try {
160
+ const key = `${host}\0${fs.realpathSync(root)}`
161
+ const prepared = openPreparations.take(
162
+ key,
163
+ url.searchParams.get(NATIVE_PREPARED_QUERY_PARAM),
164
+ )
165
+ if (prepared) {
166
+ res.writeHead(200, {
167
+ 'Content-Type': 'application/json',
168
+ 'Cache-Control': 'no-store',
169
+ })
170
+ res.end(JSON.stringify(prepared.value))
171
+ return
172
+ }
173
+ let pending = compiling.get(key)
174
+ if (!pending) {
175
+ pending = compile(fs.realpathSync(root), `http://${host}`)
176
+ .then((compiled) => compiled?.metadata ?? null)
177
+ .finally(() => compiling.delete(key))
178
+ compiling.set(key, pending)
179
+ }
180
+ const metadata = await pending
181
+ if (res.destroyed) return
182
+ openPreparations.store(
183
+ key,
184
+ url.searchParams.get(NATIVE_PREPARE_QUERY_PARAM),
185
+ metadata,
186
+ )
159
187
  res.writeHead(200, {
160
188
  'Content-Type': 'application/json',
161
189
  'Cache-Control': 'no-store',
162
190
  })
163
- res.end(JSON.stringify(prepared.value))
164
- return
165
- }
166
- let pending = compiling.get(key)
167
- if (!pending) {
168
- pending = compileNitroApp(fs.realpathSync(root), `http://${host}`)
169
- .then((compiled) => compiled?.metadata ?? null)
170
- .finally(() => compiling.delete(key))
171
- compiling.set(key, pending)
191
+ res.end(JSON.stringify(metadata))
192
+ } catch (error) {
193
+ if (res.destroyed) return
194
+ res.writeHead(500, { 'Content-Type': 'text/plain' })
195
+ res.end(error instanceof Error ? error.message : String(error))
172
196
  }
173
- const metadata = await pending
174
- if (res.destroyed) return
175
- openPreparations.store(
176
- key,
177
- url.searchParams.get(NATIVE_PREPARE_QUERY_PARAM),
178
- metadata,
179
- )
180
- res.writeHead(200, {
181
- 'Content-Type': 'application/json',
182
- 'Cache-Control': 'no-store',
183
- })
184
- res.end(JSON.stringify(metadata))
185
- } catch (error) {
186
- if (res.destroyed) return
187
- res.writeHead(500, { 'Content-Type': 'text/plain' })
188
- res.end(error instanceof Error ? error.message : String(error))
189
197
  }
190
198
  }
199
+
200
+ export const handleNitroRequest = compiledModuleRequestHandler('Nitro', compileNitroApp)
@@ -4,9 +4,9 @@ import os from 'node:os'
4
4
  import path from 'node:path'
5
5
  import { readIosAppTarget } from './native-app-identity-project'
6
6
  import {
7
- committedNitroAdapterLock,
8
- resolveNitroAdapter,
9
- type NitroAdapterArchive,
7
+ committedAdapterLocks,
8
+ resolveAdapterArchive,
9
+ type AdapterArchive,
10
10
  } from './nitro-adapter'
11
11
  import {
12
12
  collectNitroSources,
@@ -58,7 +58,7 @@ function bundledNamespaceDefines(
58
58
  // linking and reuse.
59
59
  export function collectNitroCompileInput(
60
60
  collection: NitroSourceCollection,
61
- adapter: NitroAdapterArchive,
61
+ adapter: AdapterArchive,
62
62
  dependencies: SwiftCompileInput | null,
63
63
  iosDeploymentTarget: string,
64
64
  ): SwiftCompileInput {
@@ -183,7 +183,12 @@ export async function compileNitroModule(
183
183
  )
184
184
  const input = collectNitroCompileInput(
185
185
  collection,
186
- await resolveNitroAdapter(collection, options.moduleRoot, committedNitroAdapterLock),
186
+ await resolveAdapterArchive(
187
+ 'nitro',
188
+ { nitroModules: collection.nitro.root, reactNative: collection.reactNative.root },
189
+ options.moduleRoot,
190
+ committedAdapterLocks.nitro,
191
+ ),
187
192
  dependencies,
188
193
  iosDeploymentTarget,
189
194
  )
@@ -59,31 +59,43 @@ export interface NitroDependencyHeader {
59
59
  derivation?: { upstreamCommit: string; originalSha256: string }
60
60
  }
61
61
 
62
+ // the archives React Native's podspecs pin, shared until a release moves one
63
+ const RN_SHARED_DEPENDENCIES: NitroDependency[] = [
64
+ {
65
+ name: 'RCT-Folly',
66
+ url: 'https://github.com/facebook/folly/archive/v2024.11.18.00.tar.gz',
67
+ sha256: 'b2c6879ba8ba625218d1ab9eefcc1611a9003d05bc2cb1a38f3bae21892e5167',
68
+ prefix: 'folly-2024.11.18.00',
69
+ headers: { from: 'folly', to: 'folly' },
70
+ },
71
+ {
72
+ name: 'boost',
73
+ url: 'https://github.com/react-native-community/boost-for-react-native/archive/v1.84.0.tar.gz',
74
+ sha256: '954a04e9468dee21259937b83a2b21c3985cc96f91ee0152a34a7f0f752093e8',
75
+ prefix: 'boost-for-react-native-1.84.0',
76
+ headers: { from: 'boost', to: 'boost' },
77
+ },
78
+ {
79
+ // the podspec's prepare_command renames src to double-conversion.
80
+ name: 'DoubleConversion',
81
+ url: 'https://github.com/google/double-conversion/archive/v1.1.6.tar.gz',
82
+ sha256: '6b850acd8e88515764472c52973277744a945f9a769a93968efc42efef64d67a',
83
+ prefix: 'double-conversion-1.1.6',
84
+ headers: { from: 'src', to: 'double-conversion' },
85
+ backport: { file: 'src/utils.h', ...DOUBLE_CONVERSION_WASM32_BACKPORT },
86
+ },
87
+ {
88
+ name: 'fast_float',
89
+ url: 'https://github.com/fastfloat/fast_float/archive/v8.0.0.tar.gz',
90
+ sha256: 'f312f2dc34c61e665f4b132c0307d6f70ad9420185fa831911bc24408acf625d',
91
+ prefix: 'fast_float-8.0.0',
92
+ headers: { from: 'include/fast_float', to: 'fast_float' },
93
+ },
94
+ ]
95
+
62
96
  const RN_DEPENDENCIES: Record<string, NitroDependency[]> = {
63
97
  '0.83.1': [
64
- {
65
- name: 'RCT-Folly',
66
- url: 'https://github.com/facebook/folly/archive/v2024.11.18.00.tar.gz',
67
- sha256: 'b2c6879ba8ba625218d1ab9eefcc1611a9003d05bc2cb1a38f3bae21892e5167',
68
- prefix: 'folly-2024.11.18.00',
69
- headers: { from: 'folly', to: 'folly' },
70
- },
71
- {
72
- name: 'boost',
73
- url: 'https://github.com/react-native-community/boost-for-react-native/archive/v1.84.0.tar.gz',
74
- sha256: '954a04e9468dee21259937b83a2b21c3985cc96f91ee0152a34a7f0f752093e8',
75
- prefix: 'boost-for-react-native-1.84.0',
76
- headers: { from: 'boost', to: 'boost' },
77
- },
78
- {
79
- // the podspec's prepare_command renames src to double-conversion.
80
- name: 'DoubleConversion',
81
- url: 'https://github.com/google/double-conversion/archive/v1.1.6.tar.gz',
82
- sha256: '6b850acd8e88515764472c52973277744a945f9a769a93968efc42efef64d67a',
83
- prefix: 'double-conversion-1.1.6',
84
- headers: { from: 'src', to: 'double-conversion' },
85
- backport: { file: 'src/utils.h', ...DOUBLE_CONVERSION_WASM32_BACKPORT },
86
- },
98
+ ...RN_SHARED_DEPENDENCIES,
87
99
  {
88
100
  name: 'fmt',
89
101
  url: 'https://github.com/fmtlib/fmt/archive/11.0.2.tar.gz',
@@ -91,12 +103,15 @@ const RN_DEPENDENCIES: Record<string, NitroDependency[]> = {
91
103
  prefix: 'fmt-11.0.2',
92
104
  headers: { from: 'include/fmt', to: 'fmt' },
93
105
  },
106
+ ],
107
+ '0.88.0': [
108
+ ...RN_SHARED_DEPENDENCIES,
94
109
  {
95
- name: 'fast_float',
96
- url: 'https://github.com/fastfloat/fast_float/archive/v8.0.0.tar.gz',
97
- sha256: 'f312f2dc34c61e665f4b132c0307d6f70ad9420185fa831911bc24408acf625d',
98
- prefix: 'fast_float-8.0.0',
99
- headers: { from: 'include/fast_float', to: 'fast_float' },
110
+ name: 'fmt',
111
+ url: 'https://github.com/fmtlib/fmt/archive/12.1.0.tar.gz',
112
+ sha256: 'ea7de4299689e12b6dddd392f9896f08fb0777ac7168897a244a6d6085043fea',
113
+ prefix: 'fmt-12.1.0',
114
+ headers: { from: 'include/fmt', to: 'fmt' },
100
115
  },
101
116
  ],
102
117
  }
@@ -30,6 +30,22 @@ export type NitroSourceOptions = { packageRoots: string[]; answers?: NitroAnswer
30
30
 
31
31
  const run = promisify(execFile)
32
32
 
33
+ // an autolinker that exits 0 with unparseable stdout names what it printed,
34
+ // so a truncated or empty pipe read is distinguishable from a bad command.
35
+ function autolinkerJson(
36
+ command: string,
37
+ output: { stdout: string; stderr: string },
38
+ ): unknown {
39
+ try {
40
+ return JSON.parse(output.stdout)
41
+ } catch (cause) {
42
+ throw new Error(
43
+ `${command} exited 0 with ${output.stdout.length} bytes of stdout that is not JSON (${cause instanceof Error ? cause.message : cause}); stderr: ${output.stderr.trim().slice(0, 500) || '(empty)'}; stdout: ${output.stdout.slice(0, 200) || '(empty)'}`,
44
+ { cause },
45
+ )
46
+ }
47
+ }
48
+
33
49
  type NitroPackage = { name: string; version: string; root: string }
34
50
 
35
51
  /** source fragments for the common Swift host; its caller owns the executable,
@@ -240,7 +256,7 @@ async function cliAdvertises(
240
256
  args: string[],
241
257
  token: string,
242
258
  ): Promise<boolean> {
243
- const { stdout } = await run(process.execPath, [cli, ...args], {
259
+ const { stdout } = await run('node', [cli, ...args], {
244
260
  timeout: 30_000,
245
261
  maxBuffer: 1 * 1024 * 1024,
246
262
  env: { ...process.env, [RNX_FORKED_SCRIPT_ENV]: '1' },
@@ -271,18 +287,18 @@ async function autolinkingConfig(
271
287
  // through to their own `react-native config`, the command their Podfile's
272
288
  // use_native_modules! runs.
273
289
  if (await cliAdvertises(cli, ['--help'], 'react-native-config')) {
274
- const { stdout } = await run(
275
- process.execPath,
276
- [
277
- cli,
278
- 'react-native-config',
279
- '--json',
280
- '--platform',
281
- 'ios',
282
- '--project-root',
283
- appRoot,
284
- ],
285
- {
290
+ const args = [
291
+ cli,
292
+ 'react-native-config',
293
+ '--json',
294
+ '--platform',
295
+ 'ios',
296
+ '--project-root',
297
+ appRoot,
298
+ ]
299
+ return autolinkerJson(
300
+ 'expo-modules-autolinking react-native-config',
301
+ await run('node', args, {
286
302
  timeout: 30_000,
287
303
  maxBuffer: 8 * 1024 * 1024,
288
304
  env: { ...process.env, [RNX_FORKED_SCRIPT_ENV]: '1' },
@@ -290,9 +306,8 @@ async function autolinkingConfig(
290
306
  // process cwd and ignores --project-root. the corpus bridge starts
291
307
  // outside the app, where that walk finds no package.json.
292
308
  cwd: appRoot,
293
- },
309
+ }),
294
310
  )
295
- return JSON.parse(stdout)
296
311
  }
297
312
  }
298
313
  // the app's own `react-native config`, the command its Podfile runs, so any
@@ -310,13 +325,15 @@ async function autolinkingConfig(
310
325
  const configArgs = (await cliAdvertises(cliPath, ['config', '--help'], '--platform'))
311
326
  ? ['config', '--platform', 'ios']
312
327
  : ['config']
313
- const { stdout } = await run(process.execPath, [cliPath, ...configArgs], {
314
- cwd: appRoot,
315
- timeout: 30_000,
316
- maxBuffer: 16 * 1024 * 1024,
317
- env: { ...process.env, [RNX_FORKED_SCRIPT_ENV]: '1', NO_COLOR: '1' },
318
- })
319
- return JSON.parse(stdout)
328
+ return autolinkerJson(
329
+ `react-native ${configArgs.join(' ')}`,
330
+ await run('node', [cliPath, ...configArgs], {
331
+ cwd: appRoot,
332
+ timeout: 30_000,
333
+ maxBuffer: 16 * 1024 * 1024,
334
+ env: { ...process.env, [RNX_FORKED_SCRIPT_ENV]: '1', NO_COLOR: '1' },
335
+ }),
336
+ )
320
337
  }
321
338
 
322
339
  /** the packages react native's iOS autolinking links into the app that ship a
@@ -326,26 +343,43 @@ async function autolinkingConfig(
326
343
  * app's Podfile asks expo-modules-autolinking, any other app the React Native
327
344
  * CLI. */
328
345
  export async function discoverNitroProviders(appRoot: string): Promise<string[]> {
346
+ return (await iosAutolinkedDependencies(appRoot))
347
+ .map(({ root }) => root)
348
+ .filter(hasNitroIosInitializer)
349
+ .sort()
350
+ }
351
+
352
+ /** every dependency React Native iOS autolinking links into the app, with the
353
+ * podspec CocoaPods installs it from, as the app's own autolinker answers. */
354
+ export async function iosAutolinkedDependencies(
355
+ appRoot: string,
356
+ ): Promise<{ name: string; root: string; podspecPath: string | null }[]> {
329
357
  appRoot = fs.realpathSync(appRoot)
330
358
  const appRequire = createRequire(path.join(appRoot, 'package.json'))
331
359
  const config = await autolinkingConfig(appRoot, appRequire)
332
360
  const dependencies = object(config) ? config.dependencies : undefined
333
361
  if (!object(dependencies))
334
362
  throw new Error(`${appRoot}: React Native autolinking config has no dependencies`)
335
- const roots: string[] = []
363
+ const linked: { name: string; root: string; podspecPath: string | null }[] = []
336
364
  for (const [name, dependency] of Object.entries(dependencies)) {
337
365
  if (!object(dependency) || !object(dependency.platforms))
338
366
  throw new Error(
339
367
  `${appRoot}: React Native autolinking dependency ${name} is malformed`,
340
368
  )
341
- if (dependency.platforms.ios == null) continue
369
+ const ios = dependency.platforms.ios
370
+ if (ios == null) continue
342
371
  if (typeof dependency.root !== 'string')
343
372
  throw new Error(
344
373
  `${appRoot}: React Native autolinking dependency ${name} has no root`,
345
374
  )
346
- if (hasNitroIosInitializer(dependency.root)) roots.push(dependency.root)
375
+ linked.push({
376
+ name,
377
+ root: dependency.root,
378
+ podspecPath:
379
+ object(ios) && typeof ios.podspecPath === 'string' ? ios.podspecPath : null,
380
+ })
347
381
  }
348
- return roots.sort()
382
+ return linked.sort((a, b) => a.root.localeCompare(b.root))
349
383
  }
350
384
 
351
385
  function dependencyRootsFor(