peachsim 0.1.1673 → 0.1.1684

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 (213) hide show
  1. package/cli/commands/control.ts +13 -1
  2. package/cli/commands/coverage-swift.ts +83 -27
  3. package/cli/commands/coverage.ts +219 -20
  4. package/cli/commands/detect.ts +10 -6
  5. package/cli/commands/inspect/core.ts +2 -0
  6. package/cli/commands/inspect/settling.ts +37 -4
  7. package/cli/commands/inspect/wait-ready.ts +7 -0
  8. package/cli/outbound-endpoints.ts +12 -0
  9. package/detox/index.ts +11 -1
  10. package/detox/jest-environment.cjs +14 -0
  11. package/dist-lib/agent-daemon-client.cjs +1 -1
  12. package/dist-lib/agent-events.cjs +1 -1
  13. package/dist-lib/attached-projects.cjs +1 -1
  14. package/dist-lib/auth/shared-session.cjs +1 -1
  15. package/dist-lib/backend-origin.cjs +1 -1
  16. package/dist-lib/beta.cjs +1 -1
  17. package/dist-lib/beta.mjs +1 -1
  18. package/dist-lib/bridge-constants.cjs +1 -1
  19. package/dist-lib/bridge-contract-input.cjs +1 -1
  20. package/dist-lib/bridge-contract-input.mjs +1 -1
  21. package/dist-lib/bridge-contract.cjs +1 -1
  22. package/dist-lib/bridge-contract.mjs +1 -1
  23. package/dist-lib/bundle-channel.cjs +3299 -1665
  24. package/dist-lib/capture-contract.cjs +1 -1
  25. package/dist-lib/capture-contract.mjs +1 -1
  26. package/dist-lib/cloud-contract.cjs +1 -1
  27. package/dist-lib/cloud-contract.mjs +1 -1
  28. package/dist-lib/cloud-test-args.cjs +1 -1
  29. package/dist-lib/cloud-test-args.mjs +1 -1
  30. package/dist-lib/cloud.cjs +1 -1
  31. package/dist-lib/cloud.mjs +1 -1
  32. package/dist-lib/config.cjs +1 -1
  33. package/dist-lib/config.mjs +1 -1
  34. package/dist-lib/detox/index.cjs +43 -8
  35. package/dist-lib/detox/jest-environment.cjs +14 -0
  36. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  37. package/dist-lib/expo-swift-bundle.cjs +2432 -1128
  38. package/dist-lib/expo-swift-metadata.cjs +1 -1
  39. package/dist-lib/expo-swift-metadata.mjs +1 -1
  40. package/dist-lib/home-paths.cjs +1 -1
  41. package/dist-lib/host/bridge-host.cjs +2908 -1601
  42. package/dist-lib/host/fetch-proxy-handler.cjs +22 -6
  43. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  44. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  45. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  46. package/dist-lib/host/websocket-proxy.cjs +1 -1
  47. package/dist-lib/index.cjs +1941 -742
  48. package/dist-lib/jump-to-source-babel.cjs +1 -1
  49. package/dist-lib/jump-to-source-native.cjs +1 -1
  50. package/dist-lib/kotlin-host.cjs +1 -1
  51. package/dist-lib/menu.cjs +1 -1
  52. package/dist-lib/menu.mjs +1 -1
  53. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  54. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  55. package/dist-lib/metro-production-bundle.cjs +1 -1
  56. package/dist-lib/metro-production-bundle.mjs +1 -1
  57. package/dist-lib/metro.cjs +6215 -4283
  58. package/dist-lib/native-app-identity-project.cjs +31 -6
  59. package/dist-lib/native-app-identity-project.mjs +31 -6
  60. package/dist-lib/native-app-identity.cjs +1 -1
  61. package/dist-lib/native-app-identity.mjs +1 -1
  62. package/dist-lib/native-firebase-metadata.cjs +1 -1
  63. package/dist-lib/native-firebase-metadata.mjs +1 -1
  64. package/dist-lib/plist.cjs +1 -1
  65. package/dist-lib/plist.mjs +1 -1
  66. package/dist-lib/profiles.cjs +1 -1
  67. package/dist-lib/public-brand.cjs +1 -1
  68. package/dist-lib/public-origins-lib-esm.json +24 -23
  69. package/dist-lib/public-origins-lib-static.json +1 -1
  70. package/dist-lib/public-origins-lib.json +134 -78
  71. package/dist-lib/react-native-host-modules.cjs +1 -1
  72. package/dist-lib/react-native-host-modules.mjs +1 -1
  73. package/dist-lib/reap-browser.cjs +2 -2
  74. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  75. package/dist-lib/sdk.cjs +39 -5
  76. package/dist-lib/sdk.mjs +39 -5
  77. package/dist-lib/skills.cjs +3637 -2168
  78. package/dist-lib/swift-compile.cjs +496 -352
  79. package/dist-lib/swift-compile.mjs +494 -350
  80. package/dist-lib/swift-package.cjs +58 -9
  81. package/dist-lib/swift-package.mjs +57 -9
  82. package/dist-lib/swift-submit.cjs +1 -1
  83. package/dist-lib/swift-submit.mjs +1 -1
  84. package/dist-lib/swift-toolchain.cjs +26 -11
  85. package/dist-lib/swift.cjs +1 -1
  86. package/dist-lib/vite-swift.cjs +2443 -1134
  87. package/dist-lib/vite.cjs +1907 -763
  88. package/dist-lib/worklet-executable.cjs +1 -1
  89. package/dist-lib/worklet-executable.mjs +1 -1
  90. package/dist-types/packages/peach-engine/src/engine/canvaskit-api.d.ts +1 -1
  91. package/dist-types/packages/peach-engine/src/engine/clipboardContract.d.ts +9 -1
  92. package/dist-types/packages/peach-engine/src/engine/paint-boundary.d.ts +1 -0
  93. package/dist-types/packages/peach-engine/src/preview/upload-protocol.d.ts +11 -3
  94. package/dist-types/packages/peach-engine/src/rolldown-bundle-inventory.d.ts +1 -1
  95. package/dist-types/packages/peach-engine/src/webview-automation-host.d.ts +6 -0
  96. package/dist-types/packages/peach-globals/src/clipboardBridgeContract.d.ts +2 -0
  97. package/dist-types/packages/peach-globals/src/compositorBridgeContract.d.ts +10 -1
  98. package/dist-types/packages/peach-globals/src/index.d.ts +1 -1
  99. package/package.json +1 -1
  100. package/runtime-companion.json +1 -1
  101. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h +69 -2
  102. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h +44 -4
  103. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MFComposeAssistantViewController.h +29 -0
  104. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MFMailComposeControllerDeferredAction.h +14 -0
  105. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MFMailComposeViewController.h +162 -0
  106. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MFMailDraft.h +24 -0
  107. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MFMessageComposeViewController+UPI.h +31 -0
  108. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MFMessageComposeViewController.h +169 -0
  109. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MessageUI.h +13 -0
  110. package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Modules/module.modulemap +11 -0
  111. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h +10 -0
  112. package/sdk/ios/usr/include/_ctype.h +388 -0
  113. package/sdk/ios/usr/include/_inttypes.h +296 -0
  114. package/sdk/ios/usr/include/_locale.h +83 -0
  115. package/sdk/ios/usr/include/_locale_posix2008.h +65 -0
  116. package/sdk/ios/usr/include/_time.h +207 -0
  117. package/sdk/ios/usr/include/arm/param.h +151 -0
  118. package/sdk/ios/usr/include/ctype.h +70 -0
  119. package/sdk/ios/usr/include/dispatch/dispatch.h +72 -6
  120. package/sdk/ios/usr/include/dlfcn.h +1 -2
  121. package/sdk/ios/usr/include/inttypes.h +35 -0
  122. package/sdk/ios/usr/include/locale.h +59 -0
  123. package/sdk/ios/usr/include/machine/param.h +42 -0
  124. package/sdk/ios/usr/include/net/if.h +1 -2
  125. package/sdk/ios/usr/include/peach/pthread.h +4 -4
  126. package/sdk/ios/usr/include/pthread/qos.h +304 -0
  127. package/sdk/ios/usr/include/runetype.h +118 -0
  128. package/sdk/ios/usr/include/setjmp.h +99 -0
  129. package/sdk/ios/usr/include/sys/_types/_clock_t.h +32 -0
  130. package/sdk/ios/usr/include/sys/_types/_ct_rune_t.h +33 -0
  131. package/sdk/ios/usr/include/sys/_types/_fd_clr.h +31 -0
  132. package/sdk/ios/usr/include/sys/_types/_fd_copy.h +31 -0
  133. package/sdk/ios/usr/include/sys/_types/_fd_def.h +121 -0
  134. package/sdk/ios/usr/include/sys/_types/_fd_isset.h +31 -0
  135. package/sdk/ios/usr/include/sys/_types/_fd_set.h +31 -0
  136. package/sdk/ios/usr/include/sys/_types/_fd_setsize.h +31 -0
  137. package/sdk/ios/usr/include/sys/_types/_fd_zero.h +31 -0
  138. package/sdk/ios/usr/include/sys/_types/_rune_t.h +32 -0
  139. package/sdk/ios/usr/include/sys/_types/_time_t.h +32 -0
  140. package/sdk/ios/usr/include/sys/_types/_wint_t.h +33 -0
  141. package/sdk/ios/usr/include/sys/cdefs.h +5 -0
  142. package/sdk/ios/usr/include/sys/param.h +235 -0
  143. package/sdk/ios/usr/include/sys/proc.h +1 -0
  144. package/sdk/ios/usr/include/sys/qos.h +151 -12
  145. package/sdk/ios/usr/include/time.h +67 -2
  146. package/sdk/ios/wasm/include/__typedef_sigset_t.h +7 -0
  147. package/sdk/ios/wasm/include/fcntl.h +11 -0
  148. package/sdk/ios/wasm/include/mach/machine/boolean.h +2 -0
  149. package/sdk/ios/wasm/include/mach/machine/exception.h +5 -0
  150. package/sdk/ios/wasm/include/mach/machine/kern_return.h +2 -0
  151. package/sdk/ios/wasm/include/mach/machine/processor_info.h +2 -0
  152. package/sdk/ios/wasm/include/mach/machine/rpc.h +2 -0
  153. package/sdk/ios/wasm/include/mach/machine/thread_state.h +3 -0
  154. package/sdk/ios/wasm/include/mach/machine/thread_status.h +3 -0
  155. package/sdk/ios/wasm/include/mach/machine/vm_param.h +3 -0
  156. package/sdk/ios/wasm/include/mach/machine/vm_types.h +18 -0
  157. package/sdk/ios/wasm/include/machine/_types.h +153 -0
  158. package/sdk/ios/wasm/include/machine/endian.h +2 -0
  159. package/sdk/ios/wasm/include/machine/limits.h +2 -0
  160. package/sdk/ios/wasm/include/machine/types.h +30 -0
  161. package/sdk/ios/wasm/include/poll.h +8 -0
  162. package/sdk/ios/wasm/include/pthread.h +50 -0
  163. package/sdk/ios/wasm/include/signal.h +72 -0
  164. package/sdk/ios/wasm/include/stdlib.h +3 -0
  165. package/sdk/ios/wasm/include/string.h +10 -0
  166. package/sdk/ios/wasm/include/sys/_pthread/_pthread_attr_t.h +7 -0
  167. package/sdk/ios/wasm/include/sys/_pthread/_pthread_t.h +7 -0
  168. package/sdk/ios/wasm/include/sys/mman.h +122 -0
  169. package/sdk/ios/wasm/include/sys/select.h +37 -0
  170. package/sdk/ios/wasm/include/sys/signal.h +259 -0
  171. package/sdk/ios/wasm/include/sys/socket.h +8 -0
  172. package/sdk/ios/wasm/include/sys/types.h +14 -0
  173. package/sdk/ios/wasm/include/sys/ucontext.h +1 -0
  174. package/sdk/ios/wasm/include/sys/uio.h +11 -0
  175. package/sdk/ios/wasm/include/sys/wait.h +89 -0
  176. package/sdk/ios/wasm/include/time.h +8 -0
  177. package/sdk/ios/wasm/include/unistd.h +17 -0
  178. package/src/bridge-contract.ts +2 -0
  179. package/src/chromium-admission.ts +10 -5
  180. package/src/device-catalog.ts +4 -4
  181. package/src/host/fetch-proxy-handler.ts +20 -0
  182. package/src/host/rolldown-bundle-forward.ts +4 -1
  183. package/src/metro-plugin.ts +5 -2
  184. package/src/nitro-adapter.lock.json +6 -6
  185. package/src/nitro-compile.ts +63 -2
  186. package/src/numbered-lock.ts +72 -0
  187. package/src/react-native-coverage/capability-reference-resolution.ts +62 -5
  188. package/src/react-native-coverage/capability-source-references.ts +50 -13
  189. package/src/react-native-coverage/native-source-credit.ts +126 -0
  190. package/src/react-native-coverage/native-source-ranges-file.ts +38 -0
  191. package/src/react-native-coverage/native-surface.ts +49 -0
  192. package/src/react-native-coverage/verified-reach.ts +22 -2
  193. package/src/runtime-assets.ts +17 -0
  194. package/src/swift-compile.ts +84 -47
  195. package/src/swift-coverage/indexing.ts +17 -1
  196. package/src/swift-coverage/sdk.ts +71 -0
  197. package/src/swift-coverage/source.ts +74 -2
  198. package/src/swift-coverage/types.ts +6 -0
  199. package/src/swift-distribution.lock.json +12 -12
  200. package/src/swift-host.ts +133 -14
  201. package/src/swift-objc-compile.ts +11 -22
  202. package/src/swift-objc-metadata.ts +2 -8
  203. package/src/swift-objc-platform.ts +53 -0
  204. package/src/swift-objc-standin.ts +49 -0
  205. package/src/swift-package-manifest.ts +48 -3
  206. package/src/swift-package.ts +85 -12
  207. package/src/swift-packages.ts +157 -44
  208. package/src/swift-source-pods.ts +288 -0
  209. package/src/swift-standins.ts +4 -1
  210. package/src/swift-toolchain.ts +32 -10
  211. package/src/vite-plugin-one.ts +5 -4
  212. package/src/worker-system-chunks.ts +7 -1
  213. package/src/xcode-project.ts +40 -11
@@ -12,8 +12,19 @@ import {
12
12
  type NitroSourceCollection,
13
13
  type NitroSourceOptions,
14
14
  } from './nitro-source'
15
- import { syncSwiftTree } from './swift-compile'
15
+ import {
16
+ missingSwiftModules,
17
+ swiftAvailableModules,
18
+ syncSwiftTree,
19
+ } from './swift-compile'
20
+ import { swiftModuleToolchain } from './swift-distribution'
16
21
  import { artifactFor, projectFor, type SwiftArtifact } from './swift-host'
22
+ import {
23
+ manifestCalls,
24
+ swiftManifestCxxLanguageStandard,
25
+ swiftManifestTargets,
26
+ } from './swift-package'
27
+ import { collectSwiftSourcePods } from './swift-source-pods'
17
28
  import type { SwiftCompileInput } from './swift-compile'
18
29
 
19
30
  // every selected installed implementation, its generated registration and the
@@ -23,8 +34,30 @@ import type { SwiftCompileInput } from './swift-compile'
23
34
  export function collectNitroCompileInput(
24
35
  collection: NitroSourceCollection,
25
36
  adapter: NitroAdapterArchive,
37
+ dependencies?: SwiftCompileInput | null,
26
38
  ): SwiftCompileInput {
27
39
  const files = { ...collection.files }
40
+ for (const [file, source] of Object.entries(dependencies?.files ?? {})) {
41
+ if (file === 'Package.swift') continue
42
+ if (Object.hasOwn(files, file))
43
+ throw new Error(`Nitro dependency source collision: ${file}`)
44
+ files[file] = source
45
+ }
46
+ const manifest = dependencies?.files['Package.swift'] ?? ''
47
+ const dependencyTargets = manifestCalls(manifest, ['target', 'systemLibrary']).map(
48
+ ({ kind, call }) => `.${kind}(${call},`,
49
+ )
50
+ const targets = swiftManifestTargets(manifest).filter((target) => !target.executable)
51
+ const cxxStandard = swiftManifestCxxLanguageStandard(manifest)
52
+ if (cxxStandard && cxxStandard !== 'cxx20')
53
+ throw new Error(`Nitro pod C++ standard ${cxxStandard} differs from cxx20`)
54
+ if (
55
+ targets.length !== dependencyTargets.length ||
56
+ targets.some((target) =>
57
+ collection.targets.some((provider) => provider.name === target.name),
58
+ )
59
+ )
60
+ throw new Error('Nitro pod targets have ambiguous names or declarations')
28
61
  // the archive has no module, so NitroCore's module map declares its entry.
29
62
  files['Sources/NitroCore/include/PeachNitroEntry.hpp'] =
30
63
  '#pragma once\nextern "C" void peachNitroInitialize();\n'
@@ -43,6 +76,7 @@ export function collectNitroCompileInput(
43
76
  '// swift-tools-version: 6.2',
44
77
  'import PackageDescription',
45
78
  'let package = Package(name: "PeachNativeModule", targets: [',
79
+ ...dependencyTargets,
46
80
  ...collection.targets.map(
47
81
  (target) =>
48
82
  `.target(name: ${JSON.stringify(target.name)}, dependencies: ${JSON.stringify(target.dependencies?.map((dependency) => dependency.name) ?? [])}, path: ${JSON.stringify(target.path)}, ${target.cxxInterop ? 'swiftSettings: [.interoperabilityMode(.Cxx)]' : 'cxxSettings: [.define("DEBUG")]'}),`,
@@ -51,16 +85,41 @@ export function collectNitroCompileInput(
51
85
  '], cxxLanguageStandard: .cxx20)',
52
86
  '',
53
87
  ].join('\n')
54
- return { files, entry, libraries: { NitroCore: adapter.base64 } }
88
+ return {
89
+ files,
90
+ entry,
91
+ libraries: { NitroCore: adapter.base64 },
92
+ ...(dependencies?.nativeTargets ? { nativeTargets: dependencies.nativeTargets } : {}),
93
+ ...(dependencies?.resourceBundles
94
+ ? { resourceBundles: dependencies.resourceBundles }
95
+ : {}),
96
+ }
55
97
  }
56
98
 
57
99
  export async function compileNitroModule(
58
100
  options: NitroSourceOptions & { moduleRoot: string },
59
101
  ): Promise<{ artifact: SwiftArtifact; collection: NitroSourceCollection }> {
60
102
  const collection = collectNitroSources(options)
103
+ let dependencies: SwiftCompileInput | null = null
104
+ if (options.appRoot && fs.existsSync(path.join(options.appRoot, 'Podfile.lock'))) {
105
+ const available = new Set(
106
+ swiftAvailableModules(
107
+ options.moduleRoot,
108
+ swiftModuleToolchain(options.moduleRoot).toolchainBin,
109
+ ),
110
+ )
111
+ for (const target of collection.targets) available.add(target.name)
112
+ const missing = [...missingSwiftModules(collection.files, available).keys()]
113
+ dependencies = await collectSwiftSourcePods(
114
+ options.appRoot,
115
+ missing,
116
+ options.moduleRoot,
117
+ )
118
+ }
61
119
  const input = collectNitroCompileInput(
62
120
  collection,
63
121
  await resolveNitroAdapter(collection, options.moduleRoot, committedNitroAdapterLock),
122
+ dependencies,
64
123
  )
65
124
  const key = createHash('sha256')
66
125
  .update(
@@ -83,6 +142,8 @@ export async function compileNitroModule(
83
142
  )
84
143
  const project = projectFor(packagePath)
85
144
  project.libraries = input.libraries
145
+ project.nativeTargets = input.nativeTargets
146
+ project.resourceBundles = input.resourceBundles
86
147
  return {
87
148
  artifact: await artifactFor(project, input.entry, options.moduleRoot),
88
149
  collection,
@@ -0,0 +1,72 @@
1
+ import { randomUUID } from 'node:crypto'
2
+ import {
3
+ linkSync,
4
+ mkdirSync,
5
+ readFileSync,
6
+ readdirSync,
7
+ renameSync,
8
+ rmSync,
9
+ writeFileSync,
10
+ } from 'node:fs'
11
+ import { join } from 'node:path'
12
+
13
+ const errorCode = (error: unknown) =>
14
+ error instanceof Error && 'code' in error ? error.code : undefined
15
+
16
+ function alive(pid: number): boolean {
17
+ try {
18
+ process.kill(pid, 0)
19
+ return true
20
+ } catch (error) {
21
+ return errorCode(error) !== 'ESRCH'
22
+ }
23
+ }
24
+
25
+ // the highest number is never deleted until a higher claim exists. linking a fully
26
+ // written pid elects one owner; stale readers that recreate pruned numbers withdraw.
27
+ export function tryAcquireNumberedLock(
28
+ directory: string,
29
+ detail = '',
30
+ ): (() => void) | null {
31
+ mkdirSync(directory, { recursive: true })
32
+ const claim = join(directory, `claim-${process.pid}-${randomUUID()}`)
33
+ for (;;) {
34
+ const numbers = readdirSync(directory)
35
+ .filter((name) => /^\d+$/.test(name))
36
+ .map(Number)
37
+ const top = Math.max(-1, ...numbers)
38
+ let holder = 'free'
39
+ if (top >= 0) {
40
+ try {
41
+ holder = readFileSync(join(directory, String(top)), 'utf8')
42
+ } catch (error) {
43
+ if (errorCode(error) === 'ENOENT') continue
44
+ throw error
45
+ }
46
+ }
47
+ if (holder !== 'free' && alive(Number(holder.split('\n')[0]))) return null
48
+ const held = join(directory, String(top + 1))
49
+ writeFileSync(claim, `${process.pid}${detail ? `\n${detail}` : ''}`)
50
+ try {
51
+ linkSync(claim, held)
52
+ } catch (error) {
53
+ if (errorCode(error) === 'EEXIST') continue
54
+ throw error
55
+ } finally {
56
+ rmSync(claim, { force: true })
57
+ }
58
+ if (readdirSync(directory).some((name) => Number(name) > top + 1)) {
59
+ rmSync(held, { force: true })
60
+ continue
61
+ }
62
+ for (const number of numbers) rmSync(join(directory, String(number)), { force: true })
63
+ let released = false
64
+ return () => {
65
+ if (released) return
66
+ released = true
67
+ // publish free atomically so readers never mistake a partial write for a dead pid.
68
+ writeFileSync(claim, 'free')
69
+ renameSync(claim, held)
70
+ }
71
+ }
72
+ }
@@ -21,6 +21,10 @@ type MatchDefinition = {
21
21
 
22
22
  function propOwners(contract: string): string[] {
23
23
  if (contract === 'Style') return []
24
+ // this internal wrapper's props belong to the sticky header, not ScrollView.
25
+ if (contract === 'ScrollViewStickyHeaderProps') return []
26
+ if (contract.includes('KeyboardAvoidingView')) return ['KeyboardAvoidingView']
27
+ if (contract.includes('ImageBackground')) return ['ImageBackground']
24
28
  if (/TextInput|InputAccessory/.test(contract)) {
25
29
  return contract.includes('InputAccessory') ? ['InputAccessoryView'] : ['TextInput']
26
30
  }
@@ -284,7 +288,15 @@ export function capabilityReferenceDefinition(
284
288
  const exportName = commandOwner
285
289
  ? (commandExports[commandOwner] ?? commandOwner)
286
290
  : contract
287
- const publicExport = exportName === 'ReactNativeElement' ? 'View' : exportName
291
+ const publicOwners: Record<string, string> = {
292
+ ReactNativeElement: 'View',
293
+ AppStateImpl: 'AppState',
294
+ KeyboardImpl: 'Keyboard',
295
+ LinkingImpl: 'Linking',
296
+ StyleSheetProperties: 'StyleSheet',
297
+ IOSPlatform: 'Platform',
298
+ }
299
+ const publicExport = publicOwners[exportName] ?? exportName
288
300
  if (
289
301
  !/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(publicExport) ||
290
302
  !reactNativePublicExports.has(publicExport)
@@ -325,6 +337,29 @@ export type CapabilitySourceDefinition = Pick<
325
337
  'id' | 'packageName' | 'upstreamKind' | 'upstreamName' | 'publicReferencePaths'
326
338
  >
327
339
 
340
+ const REACT_NATIVE_EXCLUSIONS = [
341
+ {
342
+ kind: 'prop',
343
+ exportName: null,
344
+ members: ['key'],
345
+ reason: 'React reconciliation key; no independent native behavior cell',
346
+ },
347
+ {
348
+ kind: 'member',
349
+ exportName: 'StyleSheet',
350
+ members: ['create', 'flatten', 'compose', 'absoluteFill', 'absoluteFillObject'],
351
+ reason:
352
+ 'published JavaScript helper or constant; native effects belong to its consumers',
353
+ },
354
+ {
355
+ kind: 'member',
356
+ exportName: 'Platform',
357
+ members: ['OS', 'select'],
358
+ reason:
359
+ 'published JavaScript helper or constant; native effects belong to its consumers',
360
+ },
361
+ ]
362
+
328
363
  export function resolveCapabilityReferences(
329
364
  rows: readonly CapabilitySourceDefinition[],
330
365
  candidates: readonly CapabilityReferenceCandidate[],
@@ -338,6 +373,7 @@ export function resolveCapabilityReferences(
338
373
  .map((row) => row.upstreamName),
339
374
  )
340
375
  const index = new Map<string, Set<string>>()
376
+ const priorities = new Map<string, number>()
341
377
  for (const row of rows) {
342
378
  const definition = capabilityReferenceDefinition(row, publicExports)
343
379
  if (!definition.source) continue
@@ -362,16 +398,29 @@ export function resolveCapabilityReferences(
362
398
  `${definition.source}:${definition.upstreamKind === 'prop' || definition.upstreamKind === 'event' ? 'prop' : 'member'}:${owner}:${definition.memberName}`,
363
399
  )
364
400
  for (const key of keys) {
401
+ // a component's own public prop overrides the inherited View prop and
402
+ // its lower-level codegen declaration. unrelated equal matches stay unknown.
403
+ const owner = key.split(':')[2]
404
+ const contract = row.upstreamName.slice(0, row.upstreamName.lastIndexOf('.'))
405
+ const priority =
406
+ row.packageName === 'react-native' &&
407
+ (row.upstreamKind === 'prop' || row.upstreamKind === 'event')
408
+ ? (owner && contract.includes(owner) ? 2 : 0) +
409
+ (row.id.includes(':prop:host-prop-') || row.id.includes(':event:event-')
410
+ ? 1
411
+ : 0)
412
+ : 0
413
+ const previous = priorities.get(key)
414
+ if (previous !== undefined && previous > priority) continue
415
+ if (previous === undefined || previous < priority) index.delete(key)
416
+ priorities.set(key, priority)
365
417
  const matches = index.get(key) ?? new Set<string>()
366
418
  matches.add(row.id)
367
419
  index.set(key, matches)
368
420
  }
369
421
  }
370
422
  for (const door of sourceApiDoors) {
371
- const key =
372
- door.memberName === null
373
- ? `${door.module}:export:${door.exportName}:`
374
- : `${door.module}:member:${door.exportName}:${door.memberName}`
423
+ const key = `${door.module}:${door.referenceKind}:${door.exportName}:${door.memberName ?? ''}`
375
424
  const matches = index.get(key) ?? new Set<string>()
376
425
  matches.add(door.id)
377
426
  index.set(key, matches)
@@ -383,6 +432,14 @@ export function resolveCapabilityReferences(
383
432
  seen.add(candidate.id)
384
433
  if (candidate.exclusion)
385
434
  return { ...candidate, state: 'excluded', reason: candidate.exclusion }
435
+ const exclusion = REACT_NATIVE_EXCLUSIONS.find(
436
+ (rule) =>
437
+ candidate.module === 'react-native' &&
438
+ candidate.kind === rule.kind &&
439
+ (rule.exportName === null || candidate.exportName === rule.exportName) &&
440
+ rule.members.includes(candidate.memberName ?? ''),
441
+ )
442
+ if (exclusion) return { ...candidate, state: 'excluded', reason: exclusion.reason }
386
443
  const matches = index.get(
387
444
  `${candidate.module}:${candidate.kind}:${candidate.exportName}:${candidate.memberName ?? ''}`,
388
445
  )
@@ -3,6 +3,9 @@ import * as ts from 'typescript/ast'
3
3
  import type { TypeScriptSourceParser } from './native-typescript-parser'
4
4
  import type { Symbol as NativeSymbol } from 'typescript/async'
5
5
 
6
+ export const NESTED_ROOT_CONTAINER_EXCLUSION =
7
+ 'nested root container; member chains counted at use sites'
8
+
6
9
  export type CapabilityReferenceKind =
7
10
  | 'export'
8
11
  | 'member'
@@ -62,8 +65,14 @@ export async function collectCapabilityReferences(
62
65
  path: string,
63
66
  packageNames: ReadonlySet<string> | null,
64
67
  corpus = 'fixture',
65
- nestedRoots: readonly { exportName: string | null; module: string }[] = [],
68
+ sourceRoots: readonly { exportName: string | null; module: string }[] = [],
66
69
  ): Promise<CapabilityReferenceCandidate[]> {
70
+ // native namespaces are export containers but retain one-level member identities.
71
+ const nestedRoots = [
72
+ ...sourceRoots.map((root) => ({ ...root, nestedMembers: true })),
73
+ { module: 'react-native', exportName: 'Platform', nestedMembers: false },
74
+ { module: 'react-native', exportName: 'StyleSheet', nestedMembers: false },
75
+ ]
67
76
  // an escaped module name needs decoding. otherwise a package-bound literal
68
77
  // must contain its package name before opening a native compiler program.
69
78
  if (
@@ -192,7 +201,7 @@ export async function collectCapabilityReferences(
192
201
  (root) =>
193
202
  root.module === binding.module && root.exportName === binding.exportName,
194
203
  )
195
- ? 'nested root container; member chains counted at use sites'
204
+ ? NESTED_ROOT_CONTAINER_EXCLUSION
196
205
  : null)),
197
206
  importForm,
198
207
  }
@@ -207,13 +216,38 @@ export async function collectCapabilityReferences(
207
216
  bindings.set(symbol.id, binding)
208
217
  bindingNames.set(symbol.id, name)
209
218
  }
219
+ // the global require: absent, or the declaration-less symbol the binder gives it in
220
+ // JavaScript files. a local binding of the name has declarations and is not it.
221
+ function isGlobalRequire(node: ts.Expression): node is ts.Identifier {
222
+ if (!ts.isIdentifier(node) || node.text !== 'require') return false
223
+ const symbol = symbols.get(node)
224
+ return !symbol || symbol.declarations.length === 0
225
+ }
226
+ // `require('m')` as the owner of a member read, whose members are the module's
227
+ // exports like a namespace import's
228
+ function requireModuleBinding(node: ts.Node): SourceBinding | undefined {
229
+ if (
230
+ !ts.isCallExpression(node) ||
231
+ !isGlobalRequire(node.expression) ||
232
+ !node.arguments[0] ||
233
+ !ts.isStringLiteralLikeNode(node.arguments[0])
234
+ )
235
+ return undefined
236
+ const module = node.arguments[0].text
237
+ const packageName = packageFor(module)
238
+ return packageName
239
+ ? { packageName, module, exportName: '*', typeOnly: false }
240
+ : undefined
241
+ }
210
242
  function bindingFor(node: ts.Node, nestedMembers = false): SourceBinding | undefined {
211
243
  if (ts.isIdentifier(node)) {
212
244
  const symbol = symbols.get(node)
213
245
  return symbol ? bindings.get(symbol.id) : undefined
214
246
  }
215
247
  if (ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) {
216
- const owner = bindingFor(node.expression, nestedMembers)
248
+ const owner =
249
+ requireModuleBinding(node.expression) ??
250
+ bindingFor(node.expression, nestedMembers)
217
251
  if (!owner || owner.typeOnly) return undefined
218
252
  const member = ts.isPropertyAccessExpression(node)
219
253
  ? node.name.text
@@ -232,7 +266,9 @@ export async function collectCapabilityReferences(
232
266
  member &&
233
267
  nestedRoots.some(
234
268
  (root) =>
235
- root.module === owner.module && root.exportName === owner.exportName,
269
+ root.nestedMembers &&
270
+ root.module === owner.module &&
271
+ root.exportName === owner.exportName,
236
272
  )
237
273
  )
238
274
  return { ...owner, memberPath: [...(owner.memberPath ?? []), member] }
@@ -260,7 +296,9 @@ export async function collectCapabilityReferences(
260
296
  !binding.typeOnly &&
261
297
  nestedRoots.some(
262
298
  (root) =>
263
- root.module === binding.module && root.exportName === binding.exportName,
299
+ root.nestedMembers &&
300
+ root.module === binding.module &&
301
+ root.exportName === binding.exportName,
264
302
  )
265
303
  ? { binding, names: [...(binding.memberPath ?? []), name] }
266
304
  : undefined
@@ -406,9 +444,7 @@ export async function collectCapabilityReferences(
406
444
  ) {
407
445
  const call = node.initializer
408
446
  if (
409
- ts.isIdentifier(call.expression) &&
410
- call.expression.text === 'require' &&
411
- !symbols.get(call.expression) &&
447
+ isGlobalRequire(call.expression) &&
412
448
  call.arguments[0] &&
413
449
  ts.isStringLiteralLikeNode(call.arguments[0])
414
450
  ) {
@@ -459,9 +495,7 @@ export async function collectCapabilityReferences(
459
495
  if (
460
496
  ts.isCallExpression(node) &&
461
497
  ts.isExpressionStatement(node.parent) &&
462
- ts.isIdentifier(node.expression) &&
463
- node.expression.text === 'require' &&
464
- !symbols.get(node.expression) &&
498
+ isGlobalRequire(node.expression) &&
465
499
  node.arguments[0] &&
466
500
  ts.isStringLiteralLikeNode(node.arguments[0])
467
501
  ) {
@@ -488,6 +522,7 @@ export async function collectCapabilityReferences(
488
522
  !binding.typeOnly &&
489
523
  nestedRoots.some(
490
524
  (root) =>
525
+ root.nestedMembers &&
491
526
  root.module === binding.module &&
492
527
  (binding.exportName === '*' || root.exportName === binding.exportName),
493
528
  )
@@ -621,7 +656,9 @@ export async function collectCapabilityReferences(
621
656
  ts.isIdentifier(node.name) &&
622
657
  (!nestedRoots.some(
623
658
  (root) =>
624
- root.module === owner.module && root.exportName === owner.exportName,
659
+ root.nestedMembers &&
660
+ root.module === owner.module &&
661
+ root.exportName === owner.exportName,
625
662
  ) ||
626
663
  (safeNamespaceBinding(node.name) &&
627
664
  ts.isIdentifier(root) &&
@@ -1133,7 +1170,7 @@ export async function collectCapabilityReferences(
1133
1170
  ts.isPropertyAccessExpression(node) ||
1134
1171
  ts.isElementAccessExpression(node)
1135
1172
  ) {
1136
- const owner = bindingFor(node.expression)
1173
+ const owner = requireModuleBinding(node.expression) ?? bindingFor(node.expression)
1137
1174
  if (owner && !owner.typeOnly) {
1138
1175
  const member = ts.isPropertyAccessExpression(node)
1139
1176
  ? node.name.text
@@ -0,0 +1,126 @@
1
+ import {
2
+ compareReleases,
3
+ isRelease,
4
+ nativeSourceRelease,
5
+ nativeSourceVerdict,
6
+ } from '../../../peach-compat/src/native-source-ranges'
7
+ import { NATIVE_SOURCE_RANGES } from './native-source-ranges-file'
8
+ import type { NativeSourcePackage } from '../../../peach-compat/src/native-source-ranges-types'
9
+
10
+ // what an app declares about the iOS renderer, read from its project files.
11
+ // unreadable: the project builds its configuration in code, so a missing
12
+ // declaration says nothing.
13
+ export type ArchitectureSetting =
14
+ | { renderer: 'fabric' | 'paper' | undefined }
15
+ | { unreadable: string }
16
+
17
+ export type FeatureCredit =
18
+ | { status: 'credited'; verifiedRelease: string }
19
+ | {
20
+ status: 'unknown'
21
+ reason: string
22
+ // per group whose native source differs from the closest verified release
23
+ differs: readonly {
24
+ group: string
25
+ verifiedRelease: string
26
+ files: readonly string[]
27
+ }[]
28
+ }
29
+
30
+ const unknown = (reason: string): FeatureCredit => ({
31
+ status: 'unknown',
32
+ reason,
33
+ differs: [],
34
+ })
35
+
36
+ // the React Native release an app installs and the package that defines which
37
+ // releases build which architecture
38
+ export type ReactNativeHost = {
39
+ config: NativeSourcePackage
40
+ version: string | undefined
41
+ }
42
+
43
+ /**
44
+ * a verified cell holds on another release when the native source behind the
45
+ * feature is byte identical there, and the app builds the architecture that
46
+ * source describes. a library builds the architecture its React Native release
47
+ * builds.
48
+ */
49
+ export function creditFeature(
50
+ config: NativeSourcePackage,
51
+ featureId: string,
52
+ version: string,
53
+ architecture: ArchitectureSetting,
54
+ host: ReactNativeHost,
55
+ ): FeatureCredit {
56
+ const groups = config.features[featureId]
57
+ if (!groups) return unknown(`no native source is mapped for feature ${featureId}`)
58
+ const verdict = nativeSourceVerdict(
59
+ NATIVE_SOURCE_RANGES,
60
+ config.packageName,
61
+ groups,
62
+ version,
63
+ )
64
+ if (verdict.status === 'unknown') return unknown(verdict.reason)
65
+ if (verdict.status === 'differs')
66
+ return {
67
+ status: 'unknown',
68
+ reason: `${config.packageName} ${version} changed native source this feature executes: ${verdict.changed.map((entry) => `${entry.group} (${entry.files.length})`).join(', ')}`,
69
+ differs: verdict.changed,
70
+ }
71
+ const release = nativeSourceRelease(NATIVE_SOURCE_RANGES, config.packageName, version)
72
+ const legacy =
73
+ release && !release.onlyArchitecture
74
+ ? legacyArchitectureReason(architecture, host)
75
+ : undefined
76
+ if (legacy) return unknown(legacy)
77
+ return { status: 'credited', verifiedRelease: verdict.verifiedRelease }
78
+ }
79
+
80
+ /**
81
+ * why the app may build the legacy iOS architecture, which runs different
82
+ * native code than the new one every verified cell is captured on. undefined
83
+ * when it builds the new one.
84
+ */
85
+ export function legacyArchitectureReason(
86
+ architecture: ArchitectureSetting,
87
+ host: ReactNativeHost,
88
+ ): string | undefined {
89
+ if (host.version === undefined || !isRelease(host.version))
90
+ return `the ${host.config.packageName} release is unknown, so the iOS architecture is too`
91
+ const forced = host.config.onlyArchitectureFrom
92
+ if (forced && compareReleases(host.version, forced.version) >= 0) return undefined
93
+ if ('unreadable' in architecture) return architecture.unreadable
94
+ const renderer =
95
+ architecture.renderer ??
96
+ (host.config.newArchitectureDefaultFrom &&
97
+ compareReleases(host.version, host.config.newArchitectureDefaultFrom.version) >= 0
98
+ ? 'fabric'
99
+ : 'paper')
100
+ return renderer === 'paper'
101
+ ? `the app builds the legacy iOS architecture on ${host.config.packageName} ${host.version}; verified cells are captured on the new one`
102
+ : undefined
103
+ }
104
+
105
+ /**
106
+ * releases that would credit a feature if a cell were captured on them. the
107
+ * architecture is not considered: it depends on each app.
108
+ */
109
+ export function creditingReleases(
110
+ config: NativeSourcePackage,
111
+ featureId: string,
112
+ version: string,
113
+ ): string[] {
114
+ const groups = config.features[featureId]
115
+ const entry = NATIVE_SOURCE_RANGES.packages[config.packageName]
116
+ if (!groups || !entry) return []
117
+ return entry.releases
118
+ .map((release) => release.version)
119
+ .filter(
120
+ (release) =>
121
+ !entry.verifiedReleases.includes(release) &&
122
+ nativeSourceVerdict(NATIVE_SOURCE_RANGES, config.packageName, groups, version, [
123
+ release,
124
+ ]).status === 'identical',
125
+ )
126
+ }
@@ -0,0 +1,38 @@
1
+ import { z } from 'zod'
2
+ import rangesData from '../../../peach-compat/src/generated/native-source-ranges.json'
3
+ import type { NativeSourceRangesFile } from '../../../peach-compat/src/native-source-ranges-types'
4
+
5
+ const run = z.object({
6
+ from: z.string(),
7
+ to: z.string(),
8
+ digest: z.string(),
9
+ changed: z.array(z.tuple([z.number(), z.string()])),
10
+ files: z.number(),
11
+ })
12
+
13
+ const schema = z.object({
14
+ schemaVersion: z.literal(1),
15
+ packages: z.record(
16
+ z.string(),
17
+ z.object({
18
+ repository: z.string(),
19
+ reference: z.string(),
20
+ referenceCommit: z.string(),
21
+ verifiedReleases: z.array(z.string()),
22
+ definitionDigest: z.string(),
23
+ releases: z.array(z.object({ version: z.string(), onlyArchitecture: z.boolean() })),
24
+ groups: z.record(
25
+ z.string(),
26
+ z.object({
27
+ files: z.number(),
28
+ referenceDigest: z.string(),
29
+ keys: z.array(z.string()),
30
+ runs: z.array(run),
31
+ }),
32
+ ),
33
+ }),
34
+ ),
35
+ })
36
+
37
+ // the checked-in output of scripts/generate/native-source-ranges.ts
38
+ export const NATIVE_SOURCE_RANGES: NativeSourceRangesFile = schema.parse(rangesData)
@@ -0,0 +1,49 @@
1
+ import { existsSync, readFileSync, readdirSync } from 'node:fs'
2
+ import { dirname, join } from 'node:path'
3
+
4
+ export type NativeSurface =
5
+ | { kind: 'none' }
6
+ | { kind: 'native'; evidence: string }
7
+ | { kind: 'unread'; reason: string }
8
+
9
+ // whether an installed package ships native iOS code of its own: a podspec, an
10
+ // ios directory, an Expo module manifest, an Expo config plugin (it edits the
11
+ // native project at prebuild) or a React Native codegen config. a
12
+ // package without any is pure JavaScript; the React Native it renders through
13
+ // stays attributed to react-native itself, which the scan does not follow into
14
+ // library source.
15
+ export function installedNativeSurface(from: string, packageName: string): NativeSurface {
16
+ let directory = from
17
+ while (true) {
18
+ const root = join(directory, 'node_modules', packageName)
19
+ if (existsSync(join(root, 'package.json'))) return surfaceOf(root)
20
+ const parent = dirname(directory)
21
+ if (parent === directory) break
22
+ directory = parent
23
+ }
24
+ return {
25
+ kind: 'unread',
26
+ reason: `${packageName} is not installed, so its files were not read`,
27
+ }
28
+ }
29
+
30
+ function surfaceOf(root: string): NativeSurface {
31
+ try {
32
+ const podspec = readdirSync(root).find((name) => name.endsWith('.podspec'))
33
+ if (podspec) return { kind: 'native', evidence: podspec }
34
+ if (existsSync(join(root, 'ios'))) return { kind: 'native', evidence: 'ios/' }
35
+ if (existsSync(join(root, 'expo-module.config.json')))
36
+ return { kind: 'native', evidence: 'expo-module.config.json' }
37
+ if (existsSync(join(root, 'app.plugin.js')))
38
+ return { kind: 'native', evidence: 'app.plugin.js' }
39
+ const manifest: unknown = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'))
40
+ if (typeof manifest === 'object' && manifest !== null && 'codegenConfig' in manifest)
41
+ return { kind: 'native', evidence: 'package.json codegenConfig' }
42
+ return { kind: 'none' }
43
+ } catch (error) {
44
+ return {
45
+ kind: 'unread',
46
+ reason: error instanceof Error ? error.message : String(error),
47
+ }
48
+ }
49
+ }