peachsim 0.1.1692 → 0.1.1700

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 (245) hide show
  1. package/cli/bridge-flow-runner.ts +61 -39
  2. package/cli/commands/agent-wrapper.ts +21 -10
  3. package/cli/commands/control.ts +27 -7
  4. package/cli/commands/coverage.ts +1 -1
  5. package/cli/commands/detect.ts +17 -4
  6. package/cli/commands/maestro-compare.ts +25 -99
  7. package/cli/help-core.ts +3 -4
  8. package/cli/maestro-compare.ts +172 -4
  9. package/cli/outbound-endpoints.ts +2 -10
  10. package/detox/index.ts +15 -0
  11. package/detox/launch-permissions.ts +169 -0
  12. package/dist-lib/agent-daemon-client.cjs +2 -2
  13. package/dist-lib/agent-events.cjs +2 -2
  14. package/dist-lib/attached-projects.cjs +2 -2
  15. package/dist-lib/auth/shared-session.cjs +2 -2
  16. package/dist-lib/backend-origin.cjs +2 -2
  17. package/dist-lib/beta.cjs +2 -2
  18. package/dist-lib/beta.mjs +1 -1
  19. package/dist-lib/bridge-constants.cjs +2 -2
  20. package/dist-lib/bridge-contract-input.cjs +2 -2
  21. package/dist-lib/bridge-contract-input.mjs +1 -1
  22. package/dist-lib/bridge-contract.cjs +2 -2
  23. package/dist-lib/bridge-contract.mjs +1 -1
  24. package/dist-lib/bundle-channel.cjs +18273 -15925
  25. package/dist-lib/capture-contract.cjs +2 -2
  26. package/dist-lib/capture-contract.mjs +1 -1
  27. package/dist-lib/cloud-contract.cjs +2 -2
  28. package/dist-lib/cloud-contract.mjs +1 -1
  29. package/dist-lib/cloud-test-args.cjs +2 -2
  30. package/dist-lib/cloud-test-args.mjs +1 -1
  31. package/dist-lib/cloud.cjs +2 -2
  32. package/dist-lib/cloud.mjs +1 -1
  33. package/dist-lib/config.cjs +2 -2
  34. package/dist-lib/config.mjs +1 -1
  35. package/dist-lib/detox/index.cjs +104 -3
  36. package/dist-lib/dev-bundle-resolution.cjs +208 -44
  37. package/dist-lib/expo-swift-bundle.cjs +2349 -1778
  38. package/dist-lib/expo-swift-metadata.cjs +2 -2
  39. package/dist-lib/expo-swift-metadata.mjs +1 -1
  40. package/dist-lib/home-paths.cjs +2 -2
  41. package/dist-lib/host/bridge-host.cjs +7885 -3334
  42. package/dist-lib/host/fetch-proxy-handler.cjs +331 -39
  43. package/dist-lib/host/fetch-proxy-overrides.cjs +2 -2
  44. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  45. package/dist-lib/host/replacement-module-handler.cjs +2 -2
  46. package/dist-lib/host/websocket-proxy.cjs +2 -2
  47. package/dist-lib/index.cjs +297 -77
  48. package/dist-lib/jump-to-source-babel.cjs +2 -2
  49. package/dist-lib/jump-to-source-native.cjs +2 -2
  50. package/dist-lib/kotlin-host.cjs +2 -2
  51. package/dist-lib/menu.cjs +2 -2
  52. package/dist-lib/menu.mjs +1 -1
  53. package/dist-lib/metro-fingerprint-registry.cjs +2 -2
  54. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  55. package/dist-lib/metro-production-bundle.cjs +2 -2
  56. package/dist-lib/metro-production-bundle.mjs +1 -1
  57. package/dist-lib/metro.cjs +294 -74
  58. package/dist-lib/native-app-identity-project.cjs +48 -37
  59. package/dist-lib/native-app-identity-project.mjs +47 -36
  60. package/dist-lib/native-app-identity.cjs +2 -2
  61. package/dist-lib/native-app-identity.mjs +1 -1
  62. package/dist-lib/native-firebase-metadata.cjs +2 -2
  63. package/dist-lib/native-firebase-metadata.mjs +1 -1
  64. package/dist-lib/plist.cjs +2 -2
  65. package/dist-lib/plist.mjs +1 -1
  66. package/dist-lib/profiles.cjs +2 -2
  67. package/dist-lib/public-brand.cjs +2 -2
  68. package/dist-lib/public-origins-lib-esm.json +24 -23
  69. package/dist-lib/public-origins-lib.json +199 -79
  70. package/dist-lib/react-native-host-modules.cjs +2 -2
  71. package/dist-lib/react-native-host-modules.mjs +1 -1
  72. package/dist-lib/reap-browser.cjs +2 -2
  73. package/dist-lib/scripts/dev-server-scanner.cjs +206 -31
  74. package/dist-lib/sdk.cjs +2 -2
  75. package/dist-lib/sdk.mjs +1 -1
  76. package/dist-lib/skills.cjs +19600 -15992
  77. package/dist-lib/swift-compile.cjs +640 -402
  78. package/dist-lib/swift-compile.mjs +595 -357
  79. package/dist-lib/swift-package.cjs +24 -20
  80. package/dist-lib/swift-package.mjs +23 -19
  81. package/dist-lib/swift-submit.cjs +2 -2
  82. package/dist-lib/swift-submit.mjs +1 -1
  83. package/dist-lib/swift-toolchain.cjs +31 -4
  84. package/dist-lib/swift.cjs +2 -2
  85. package/dist-lib/vite-swift.cjs +1559 -1208
  86. package/dist-lib/vite.cjs +251 -42
  87. package/dist-lib/worklet-executable.cjs +2 -2
  88. package/dist-lib/worklet-executable.mjs +1 -1
  89. package/dist-types/packages/peach-engine/src/engine/font-config.d.ts +1 -1
  90. package/dist-types/packages/peach-engine/src/engine/node.d.ts +1 -0
  91. package/dist-types/packages/peach-engine/src/engine/scroll-pan-contacts.d.ts +3 -1
  92. package/dist-types/packages/peach-engine/src/engine/scroll.d.ts +7 -0
  93. package/dist-types/packages/peach-engine/src/engine/types.d.ts +2 -1
  94. package/dist-types/packages/peach-engine/src/remote-stream/cloud-display.d.ts +2 -2
  95. package/dist-types/packages/peach-engine/src/render-worker/host-service-protocol.d.ts +3 -0
  96. package/dist-types/packages/peach-engine/src/render-worker/protocol.d.ts +1 -0
  97. package/dist-types/packages/peach-engine/src/render-worker/scroll-mirror.d.ts +17 -0
  98. package/dist-types/packages/peach-engine/src/render-worker/worker-input-runtime.d.ts +2 -1
  99. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +3 -0
  100. package/dist-types/packages/peach-globals/src/cameraBridgeContract.d.ts +1 -0
  101. package/dist-types/packages/peach-globals/src/replayBridgeContract.d.ts +1 -0
  102. package/dist-types/packages/peach-globals/src/shellHostBridgeContract.d.ts +3 -0
  103. package/dist-types/packages/peach-kit/src/materials/types.d.ts +1 -0
  104. package/package.json +1 -1
  105. package/runtime-companion.json +1 -1
  106. package/scripts/dev-server-scanner.ts +4 -0
  107. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/Alpha.h +2282 -0
  108. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/BasicImageTypes.h +55 -0
  109. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/Conversion.h +10551 -6
  110. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/Convolution.h +4236 -3
  111. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/Geometry.h +827 -8
  112. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/Histogram.h +1369 -0
  113. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/Morphology.h +1243 -0
  114. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/Transform.h +1747 -0
  115. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/vImage.h +291 -2
  116. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/vImage_CVUtilities.h +1283 -0
  117. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/vImage_Types.h +811 -91
  118. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/vImage_Utilities.h +1342 -25
  119. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/BNNS/bnns.h +2738 -0
  120. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/BNNS/bnns_constants.h +1685 -0
  121. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/BNNS/bnns_graph.h +913 -0
  122. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/BNNS/bnns_structures.h +1917 -0
  123. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/LinearAlgebra/LinearAlgebra.h +23 -0
  124. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/LinearAlgebra/arithmetic.h +209 -0
  125. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/LinearAlgebra/base.h +104 -0
  126. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/LinearAlgebra/linear_systems.h +77 -0
  127. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/LinearAlgebra/matrix.h +554 -0
  128. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/LinearAlgebra/norms.h +58 -0
  129. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/LinearAlgebra/object.h +186 -0
  130. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/LinearAlgebra/splat.h +86 -0
  131. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/LinearAlgebra/vector.h +364 -0
  132. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/Quadrature/Integration.h +195 -0
  133. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/Quadrature/Quadrature.h +44 -0
  134. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/Sparse/BLAS/BLAS.h +2330 -0
  135. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/Sparse/BLAS/Types.h +123 -0
  136. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/Sparse/Solve.h +8339 -0
  137. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/Sparse/SolveImplementation.h +520 -0
  138. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/Sparse/SolveImplementationTyped.h +1893 -0
  139. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/Sparse/Sparse.h +10 -0
  140. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/blas_new.h +1098 -0
  141. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/cblas.h +859 -0
  142. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/cblas_new.h +1134 -0
  143. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/clapack.h +10555 -0
  144. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/fortran_blas.h +695 -0
  145. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/lapack.h +38526 -0
  146. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/lapack_types.h +60 -0
  147. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/lapack_version.h +20 -0
  148. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/thread_api.h +50 -0
  149. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/vBasicOps.h +1218 -0
  150. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/vBigNum.h +1458 -0
  151. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/vDSP.h +10377 -0
  152. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/vDSP_translate.h +167 -0
  153. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/vForce.h +1243 -0
  154. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/vecLib.h +114 -0
  155. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/vecLibTypes.h +146 -0
  156. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/vectorOps.h +1106 -0
  157. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/vfp.h +294 -0
  158. package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Headers/Accelerate.h +25 -1
  159. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFArray.h +673 -0
  160. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFAvailability.h +232 -0
  161. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFBase.h +827 -0
  162. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFCalendar.h +121 -0
  163. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFCharacterSet.h +387 -0
  164. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFData.h +79 -0
  165. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFDate.h +122 -0
  166. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFDictionary.h +674 -0
  167. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFError.h +182 -0
  168. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFLocale.h +213 -0
  169. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFNotificationCenter.h +82 -0
  170. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFNumber.h +129 -0
  171. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFSet.h +491 -0
  172. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFString.h +883 -2
  173. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFTimeZone.h +98 -0
  174. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h +11 -229
  175. package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.h +2 -6
  176. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h +2 -1
  177. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/QuartzCore.h +1 -0
  178. package/sdk/ios/System/Library/Frameworks/Security.framework/Headers/SecBase.h +906 -3
  179. package/sdk/ios/System/Library/Frameworks/Security.framework/Headers/SecCertificate.h +613 -0
  180. package/sdk/ios/System/Library/Frameworks/Security.framework/Headers/SecItem.h +1284 -29
  181. package/sdk/ios/System/Library/Frameworks/Security.framework/Headers/SecPolicy.h +441 -0
  182. package/sdk/ios/System/Library/Frameworks/Security.framework/Headers/SecTrust.h +845 -0
  183. package/sdk/ios/System/Library/Frameworks/Security.framework/Headers/Security.h +4 -0
  184. package/sdk/ios/usr/include/AvailabilityMacros.h +3985 -0
  185. package/sdk/ios/usr/include/copyfile.h +143 -0
  186. package/sdk/ios/usr/include/malloc/_malloc.h +143 -0
  187. package/sdk/ios/usr/include/malloc/_malloc_type.h +153 -0
  188. package/sdk/ios/usr/include/malloc/_platform.h +80 -0
  189. package/sdk/ios/usr/include/malloc/_ptrcheck.h +43 -0
  190. package/sdk/ios/usr/include/malloc/malloc.h +768 -0
  191. package/sdk/ios/usr/include/os/availability.h +168 -6
  192. package/sdk/ios/usr/include/os/base.h +351 -0
  193. package/sdk/ios/usr/include/os/clock.h +18 -0
  194. package/sdk/ios/usr/include/os/lock.h +232 -10
  195. package/sdk/ios/usr/include/os/log.h +521 -38
  196. package/sdk/ios/usr/include/os/object.h +320 -3
  197. package/sdk/ios/usr/include/os/trace.h +492 -0
  198. package/sdk/ios/usr/include/os/trace_base.h +167 -0
  199. package/sdk/ios/usr/include/os/workgroup.h +37 -0
  200. package/sdk/ios/usr/include/os/workgroup_base.h +91 -0
  201. package/sdk/ios/usr/include/os/workgroup_interval.h +156 -0
  202. package/sdk/ios/usr/include/os/workgroup_object.h +359 -0
  203. package/sdk/ios/usr/include/os/workgroup_parallel.h +76 -0
  204. package/sdk/ios/usr/include/sys/cdefs.h +38 -0
  205. package/sdk/ios/wasm/include/unistd.h +3 -0
  206. package/skills/contrast/SKILL.md +3 -0
  207. package/src/codex-client.ts +11 -6
  208. package/src/dev-bundle-resolution.ts +124 -48
  209. package/src/expo-native-workspace.ts +176 -0
  210. package/src/expo-swift-host.ts +161 -26
  211. package/src/expo-swift-ready.ts +14 -28
  212. package/src/expoSwiftContract.ts +4 -1
  213. package/src/generated/swift-c-predefines.json +68 -12
  214. package/src/host/bridge-host.ts +5 -0
  215. package/src/installed-package-versions.ts +14 -1
  216. package/src/metro-project-root.ts +44 -33
  217. package/src/native-app-identity-project.ts +1 -0
  218. package/src/nitro-adapter.lock.json +916 -10
  219. package/src/nitro-adapter.ts +33 -24
  220. package/src/nitro-bundle.ts +108 -22
  221. package/src/nitro-compile.ts +32 -5
  222. package/src/nitro-source.ts +13 -3
  223. package/src/nitroAdapterContract.ts +100 -20
  224. package/src/node-http-fetch.ts +116 -0
  225. package/src/packageVersionsContract.ts +46 -0
  226. package/src/serverDiscoveryContract.ts +1 -0
  227. package/src/settingsContract.ts +0 -30
  228. package/src/swift-binary-modules.ts +20 -5
  229. package/src/swift-compile.ts +168 -48
  230. package/src/swift-coverage/xcode-assets.ts +4 -3
  231. package/src/swift-host.ts +14 -3
  232. package/src/swift-objc-compile.ts +32 -5
  233. package/src/swift-objc-metadata.ts +2 -2
  234. package/src/swift-objc-platform.ts +2 -2
  235. package/src/swift-objc-standin.ts +43 -13
  236. package/src/swift-package.ts +33 -26
  237. package/src/swift-source-pods.ts +126 -41
  238. package/src/swift-standin-digest.ts +77 -0
  239. package/src/swift-standin-emit.ts +40 -4
  240. package/src/swift-standins.ts +68 -19
  241. package/src/swift-toolchain.ts +38 -0
  242. package/src/swiftContract.ts +8 -0
  243. package/src/vite-plugin.ts +0 -10
  244. package/src/xcode-project.ts +62 -42
  245. package/src/settings-flags.ts +0 -107
@@ -15,7 +15,6 @@ import {
15
15
  IOS_SDK_ID,
16
16
  iosDeploymentMinimum,
17
17
  materializeObjcSdk,
18
- OBJC_IMPORT_VERSION,
19
18
  objcSdkIntakeFlags,
20
19
  } from './swift-objc-standin'
21
20
  import {
@@ -26,6 +25,7 @@ import {
26
25
  import { swiftPackageManifest, swiftTargetFiles } from './swift-package-manifest'
27
26
  import { remoteSwiftCheckouts, type SwiftPackageBinary } from './swift-packages'
28
27
  import { readPackageFile } from './swift-source-file'
28
+ import { STANDIN_SOURCE_DIGEST } from './swift-standin-digest'
29
29
  import { binaryFrameworkSearchPath } from './swift-standins'
30
30
  import { swiftEnvironment } from './swift-toolchain'
31
31
  import { writeXcodeHeaderSearch } from './xcode-header-search'
@@ -212,6 +212,13 @@ export function xcodeObjCInputs(
212
212
  ...Object.values(target.objc.fileFlags).flat(),
213
213
  ]
214
214
  for (const [index, flag] of flags.entries()) {
215
+ if (flag.startsWith('-fmodule-map-file=')) {
216
+ const moduleMap = path.resolve(
217
+ app.rootDir,
218
+ flag.slice('-fmodule-map-file='.length),
219
+ )
220
+ if (fs.existsSync(moduleMap)) add(moduleMap, true)
221
+ }
215
222
  const directory = ['-I', '-F', '-iquote', '-isystem', '-iframework'].includes(
216
223
  flags[index - 1] ?? '',
217
224
  )
@@ -259,9 +266,19 @@ export function prepareXcodeObjCImplementations(
259
266
  const inputs = Object.fromEntries(
260
267
  [...sources].map(([file, bytes]) => [file, digest(bytes)]),
261
268
  )
269
+ // hoisted: the identity keys the resolved intake flags as data, so a flag
270
+ // change rebuilds even when no input file changed. an unparseable minimum
271
+ // records as a marker here; minimumFor still owns the failure below.
272
+ const headers = materializeObjcSdk(path.join(cacheDir(), 'swift-standins'))
262
273
  const identity = {
263
- version: 16,
264
- importer: OBJC_IMPORT_VERSION,
274
+ version: 17,
275
+ importer: STANDIN_SOURCE_DIGEST,
276
+ intake: targets.map((target) => {
277
+ const minimum = iosDeploymentMinimum(target.deploymentTarget)
278
+ return minimum === undefined
279
+ ? [`invalid-minimum:${target.deploymentTarget}`]
280
+ : objcSdkIntakeFlags(headers, toolchain.toolchainBin, minimum)
281
+ }),
265
282
  peers,
266
283
  metadataDeploymentTarget: peers ? app.iosDeploymentTarget : undefined,
267
284
  release: toolchain.release,
@@ -397,10 +414,21 @@ export function prepareXcodeObjCImplementations(
397
414
  `Objective-C compiler input is outside the project and its pinned packages: ${file}`,
398
415
  )
399
416
  }
417
+ // a linked header stays a link to its staged file, so clang sees one file
418
+ // through every path as it does natively and #import includes it once.
400
419
  for (const [file, bytes] of sources) {
401
420
  const output = staged(file)
402
421
  fs.mkdirSync(path.dirname(output), { recursive: true })
403
- fs.writeFileSync(output, bytes)
422
+ const target = links[file]
423
+ if (target === undefined) {
424
+ fs.writeFileSync(output, bytes)
425
+ continue
426
+ }
427
+ const real = staged(target)
428
+ fs.mkdirSync(path.dirname(real), { recursive: true })
429
+ fs.writeFileSync(real, bytes)
430
+ fs.rmSync(output, { force: true })
431
+ fs.symlinkSync(path.relative(path.dirname(output), real), output)
404
432
  }
405
433
  const headerSearch = writeXcodeHeaderSearch(
406
434
  work,
@@ -424,7 +452,6 @@ export function prepareXcodeObjCImplementations(
424
452
  userHeaderSearchPaths: target.userIncludes.map(staged),
425
453
  })),
426
454
  )
427
- const headers = materializeObjcSdk(path.join(cacheDir(), 'swift-standins'))
428
455
  const modulemaps = targets.flatMap((target, index) => {
429
456
  if (!target.publicHeaders) return []
430
457
  const custom = path.join(target.publicHeaders, 'module.modulemap')
@@ -7,11 +7,11 @@ import { IOS_SDK_TARGET } from './swift-objc-sdk'
7
7
  import {
8
8
  IOS_SDK_ID,
9
9
  materializeObjcSdk,
10
- OBJC_IMPORT_VERSION,
11
10
  objcSdkIntakeFlags,
12
11
  objcView,
13
12
  type ObjcView,
14
13
  } from './swift-objc-standin'
14
+ import { STANDIN_SOURCE_DIGEST } from './swift-standin-digest'
15
15
  import { swiftEnvironment } from './swift-toolchain'
16
16
  import type { SwiftObjCPeerClass } from './swiftContract'
17
17
 
@@ -475,7 +475,7 @@ export function compileObjcPeerMetadata(args: {
475
475
  {
476
476
  classes: args.classes.map((peer) => ({ ...peer, ...types.get(peer.name) })),
477
477
  declarations: IOS_SDK_ID,
478
- importer: OBJC_IMPORT_VERSION,
478
+ importer: STANDIN_SOURCE_DIGEST,
479
479
  compiler: digest(compiler),
480
480
  command,
481
481
  source: digest(source),
@@ -40,10 +40,10 @@ export function swiftObjCPlatformFlags(
40
40
  throw new Error(
41
41
  `could not read iOS compiler platform predefines: ${result.error?.message ?? result.stderr}`,
42
42
  )
43
- // copy OS and vendor identity, never arm64 widths, instructions or Apple's objc ABI.
43
+ // copy OS and vendor identity and the darwin nullability spellings, never arm64 widths, instructions or Apple's objc ABI.
44
44
  const flags = [
45
45
  ...result.stdout.matchAll(
46
- /^#define (TARGET_OS_\w+|TARGET_IPHONE_SIMULATOR|__APPLE\w*__|__MACH__|__ENVIRONMENT_\w+) (.*)$/gm,
46
+ /^#define (TARGET_OS_\w+|TARGET_IPHONE_SIMULATOR|__APPLE\w*__|__MACH__|__ENVIRONMENT_\w+|__nonnull|__nullable|__null_unspecified) (.*)$/gm,
47
47
  ),
48
48
  ].map(([, name, value]) => `-D${name}=${value}`)
49
49
  if (!flags.includes('-D__APPLE__=1') || !flags.includes('-D__MACH__=1'))
@@ -41,9 +41,6 @@ export interface ObjcView {
41
41
  imports: string[]
42
42
  }
43
43
 
44
- /** bump when importer behavior changes the Swift view independently of SDK headers. */
45
- export const OBJC_IMPORT_VERSION = '5'
46
-
47
44
  export const NATIVE_GRAPH_SDK_VERSION = '27.1'
48
45
 
49
46
  /** the installed libc's emulated surfaces: its signal.h is an #error without them,
@@ -235,22 +232,55 @@ const headerFiles = (dir: string): string[] =>
235
232
  .filter((file) => file.endsWith('.h'))
236
233
  .sort()
237
234
 
238
- /** headers a module map includes, without its explicitly excluded headers. */
235
+ /**
236
+ * headers a module map includes, without the headers a module excludes. an
237
+ * exclusion applies to the module that declares it; a header another module
238
+ * names explicitly stays. directory headers belong to the top-level module.
239
+ */
239
240
  export function moduleMapHeaders(
240
241
  modulemap: string,
241
242
  directoryHeaders: readonly string[] = [],
242
243
  ): string[] {
243
- const headers: string[] = []
244
- const excluded = new Set<string>()
245
- for (const match of fs
246
- .readFileSync(modulemap, 'utf8')
247
- .matchAll(/\b(?:(exclude)\s+)?header\s+"([^"]+)"/g)) {
248
- if (match[1] === 'exclude') excluded.add(match[2]!)
249
- else headers.push(match[2]!)
244
+ // one pass keeps strings and comments from hiding each other: a quoted path
245
+ // may hold `//`, a comment may hold quotes.
246
+ const tokens = (
247
+ fs
248
+ .readFileSync(modulemap, 'utf8')
249
+ .match(/\/\*[\s\S]*?\*\/|\/\/[^\n]*|"[^"]*"|[\w.*]+|[{}\[\]]/g) ?? []
250
+ ).filter((token) => !token.startsWith('/'))
251
+ // each open brace holds its module index, or -1 for any other block
252
+ const open: number[] = []
253
+ const declared: string[][] = []
254
+ const excluded: Set<string>[] = []
255
+ const topLevel: number[] = []
256
+ // a `module` declaration with a body opens a module at its next brace; an
257
+ // `extern module` reference has none.
258
+ let moduleBody = false
259
+ for (const [i, token] of tokens.entries()) {
260
+ if (token === 'module') moduleBody = tokens[i - 1] !== 'extern'
261
+ else if (token === '}') open.pop()
262
+ else if (token === '{') {
263
+ if (moduleBody) {
264
+ declared.push([])
265
+ excluded.push(new Set())
266
+ if (open.every((index) => index < 0)) topLevel.push(declared.length - 1)
267
+ open.push(declared.length - 1)
268
+ } else open.push(-1)
269
+ moduleBody = false
270
+ } else if (token === 'header' && tokens[i + 1]?.startsWith('"')) {
271
+ const index = open.findLast((owner) => owner >= 0)
272
+ if (index === undefined) continue
273
+ const header = tokens[i + 1]!.slice(1, -1)
274
+ if (tokens[i - 1] === 'exclude') excluded[index]!.add(header)
275
+ else declared[index]!.push(header)
276
+ }
250
277
  }
251
- return (headers.length > 0 ? headers : directoryHeaders).filter(
252
- (header) => !excluded.has(header),
278
+ const headers = declared.flatMap((list, index) =>
279
+ list.filter((header) => !excluded[index]!.has(header)),
253
280
  )
281
+ if (headers.length > 0) return headers
282
+ const topExcluded = new Set(topLevel.flatMap((index) => [...excluded[index]!]))
283
+ return directoryHeaders.filter((header) => !topExcluded.has(header))
254
284
  }
255
285
 
256
286
  // the opaque declarations, behind the sdk's own frameworks so they can name
@@ -254,6 +254,19 @@ const swiftEscapes: Record<string, string> = {
254
254
  t: '\t',
255
255
  }
256
256
 
257
+ // the value of a single-line swift string literal; interpolation, unicode and
258
+ // NUL escapes are refused with their context, never evaluated or dropped.
259
+ function swiftStringValue(raw: string, context: string): string {
260
+ return raw.replace(/\\(.)/g, (_, escape: string) => {
261
+ const value = swiftEscapes[escape]
262
+ if (value === undefined)
263
+ throw new Error(
264
+ `Unsupported ${escape === '(' ? 'interpolation' : `escape \\${escape}`} in ${context}`,
265
+ )
266
+ return value
267
+ })
268
+ }
269
+
257
270
  /**
258
271
  * the macros a target declares unconditionally in one tool's settings array,
259
272
  * as `NAME` or `NAME=value`. swiftSettings conditions never reach clang, and
@@ -286,7 +299,7 @@ function settingsBlocks(call: string, tool: 'swift' | 'c' | 'cxx'): string[] {
286
299
 
287
300
  // the feature names and raw flags a target's swiftSettings carry: features
288
301
  // are identifiers, flags round-trip through json exactly as rendered.
289
- function settingFeatures(call: string, setting: string): string[] {
302
+ function settingFeatures(call: string, setting: string, target: string): string[] {
290
303
  const found: string[] = []
291
304
  for (const body of settingsBlocks(call, 'swift')) {
292
305
  if (setting === '.unsafeFlags') {
@@ -294,7 +307,9 @@ function settingFeatures(call: string, setting: string): string[] {
294
307
  for (const match of bracketBody(body, open.index + open[0].length).matchAll(
295
308
  /"((?:[^"\\]|\\.)*)"/g,
296
309
  ))
297
- found.push(JSON.parse(`"${match[1]}"`))
310
+ found.push(
311
+ swiftStringValue(match[1]!, `unsafeFlags of target ${target} (${match[0]})`),
312
+ )
298
313
  } else {
299
314
  const name = '([A-Za-z_][A-Za-z0-9_]*(?:=[A-Za-z_][A-Za-z0-9_.-]*)?)'
300
315
  const pattern =
@@ -318,20 +333,21 @@ function settingDefines(call: string, tool: 'swift' | 'c' | 'cxx'): string[] {
318
333
  defines.push(
319
334
  match[2] === undefined
320
335
  ? name
321
- : `${name}=${match[2].replace(/\\(.)/g, (_, escape: string) => {
322
- const value = swiftEscapes[escape]
323
- if (value === undefined)
324
- throw new Error(
325
- `Unsupported escape \\${escape} in the value of macro ${name}`,
326
- )
327
- return value
328
- })}`,
336
+ : `${name}=${swiftStringValue(match[2], `the value of macro ${name}`)}`,
329
337
  )
330
338
  }
331
339
  }
332
340
  return defines
333
341
  }
334
342
 
343
+ interface SwiftManifestDeclaration extends ManifestCall {
344
+ name: string
345
+ path: string
346
+ executable: boolean
347
+ resources: boolean
348
+ exclude: string[]
349
+ }
350
+
335
351
  /**
336
352
  * the library and executable targets a sent root manifest declares, in order.
337
353
  *
@@ -341,14 +357,6 @@ function settingDefines(call: string, tool: 'swift' | 'c' | 'cxx'): string[] {
341
357
  * it early), and `name:` / `path:` are read from the call's own depth only,
342
358
  * so a nested `.product(name: "SwiftUI", ...)` inside dependencies never wins.
343
359
  */
344
- interface SwiftManifestDeclaration extends ManifestCall {
345
- name: string
346
- path: string
347
- executable: boolean
348
- resources: boolean
349
- exclude: string[]
350
- }
351
-
352
360
  // inventory reads declarations without interpreting compiler settings or swift expressions.
353
361
  export function swiftManifestDeclarations(
354
362
  manifest: string,
@@ -429,9 +437,9 @@ export function swiftManifestTargets(
429
437
  call.replace(/"(?:\\.|[^"\\])*"/g, ''),
430
438
  )
431
439
  const defines = settingDefines(call, 'swift').map((define) => define.split('=')[0]!)
432
- const experimentalFeatures = settingFeatures(call, '.enableExperimentalFeature')
433
- const upcomingFeatures = settingFeatures(call, '.enableUpcomingFeature')
434
- const swiftFlags = settingFeatures(call, '.unsafeFlags')
440
+ const experimentalFeatures = settingFeatures(call, '.enableExperimentalFeature', name)
441
+ const upcomingFeatures = settingFeatures(call, '.enableUpcomingFeature', name)
442
+ const swiftFlags = settingFeatures(call, '.unsafeFlags', name)
435
443
  const cDefines = settingDefines(call, 'c')
436
444
  const cxxDefines = settingDefines(call, 'cxx')
437
445
  const linkedLibraries = [...call.matchAll(/\.linkedLibrary\(\s*"([^"]+)"\s*\)/g)].map(
@@ -554,10 +562,9 @@ export function swiftObjCResourceAccessor(bundleName: string): {
554
562
  header: string
555
563
  body: string
556
564
  } {
557
- if (!/^[A-Za-z_]\w*$/.test(bundleName))
558
- throw new Error(`Objective-C resource bundle symbol is unqualified: ${bundleName}`)
559
- const symbol = `${bundleName}_SWIFTPM_MODULE_BUNDLE`
560
- const finder = `${bundleName}_SWIFTPM_MODULE_BUNDLER_FINDER`
565
+ const accessorName = swiftTargetModuleName(bundleName.replace(/[^\x00-\x7f]/gu, '_'))
566
+ const symbol = `${accessorName}_SWIFTPM_MODULE_BUNDLE`
567
+ const finder = `${accessorName}_SWIFTPM_MODULE_BUNDLER_FINDER`
561
568
  return {
562
569
  header: [
563
570
  '#import <Foundation/Foundation.h>',
@@ -582,7 +589,7 @@ export function swiftObjCResourceAccessor(bundleName: string): {
582
589
  '@end',
583
590
  '',
584
591
  `NSBundle* ${symbol}() {`,
585
- ` NSString *bundleName = @"${bundleName}";`,
592
+ ` NSString *bundleName = @"${accessorName}";`,
586
593
  '',
587
594
  ' NSArray<NSURL*> *candidates = @[',
588
595
  ' NSBundle.mainBundle.resourceURL,',
@@ -76,23 +76,86 @@ function lockedPods(value: unknown): Map<string, LockedPod> {
76
76
  return pods
77
77
  }
78
78
 
79
- /** install only the locked closure of missing imports, then read CocoaPods' real project. */
79
+ // CocoaPods names a pod's module from module_name, else header_dir, else the pod.
80
+ const podModuleName = (spec: Record<string, unknown>, root: string) =>
81
+ String(spec.module_name ?? spec.header_dir ?? root).replace(/[^A-Za-z0-9_]/g, '_')
82
+
83
+ /** a locked trunk pod's JSON specification, verified against the lock's
84
+ * checksum and kept under that checksum. */
85
+ async function trunkSpecification(
86
+ lockFile: string,
87
+ root: string,
88
+ version: string,
89
+ checksum: unknown,
90
+ ): Promise<{ text: string; spec: Record<string, unknown> }> {
91
+ if (typeof checksum !== 'string' || !/^[a-f0-9]{40}$/.test(checksum))
92
+ throw new Error(`${lockFile}: missing checksum for ${root}`)
93
+ const file = path.join(
94
+ cacheDir(),
95
+ 'swift-source-pods',
96
+ 'specifications',
97
+ `${checksum}.json`,
98
+ )
99
+ let text: string
100
+ if (fs.existsSync(file)) text = fs.readFileSync(file, 'utf8')
101
+ else {
102
+ const shard = createHash('md5')
103
+ .update(root)
104
+ .digest('hex')
105
+ .slice(0, 3)
106
+ .split('')
107
+ .join('/')
108
+ const response = await fetch(
109
+ `https://cdn.cocoapods.org/Specs/${shard}/${root}/${version}/${root}.podspec.json`,
110
+ )
111
+ if (!response.ok)
112
+ throw new Error(
113
+ `CocoaPods specification ${root} ${version}: HTTP ${response.status}`,
114
+ )
115
+ text = await response.text()
116
+ }
117
+ if (createHash('sha1').update(text).digest('hex') !== checksum)
118
+ throw new Error(`${root} podspec checksum differs from ${lockFile}`)
119
+ const spec: unknown = JSON.parse(text)
120
+ if (!record(spec) || spec.name !== root || spec.version !== version)
121
+ throw new Error(`specification identity differs for ${root} ${version}`)
122
+ if (!fs.existsSync(file)) {
123
+ fs.mkdirSync(path.dirname(file), { recursive: true })
124
+ fs.writeFileSync(file, text)
125
+ }
126
+ return { text, spec }
127
+ }
128
+
129
+ /** the app's Podfile.lock, which CocoaPods writes beside its Podfile: ios/ in a
130
+ * React Native project, the root when the app keeps its lock there. */
131
+ export function appPodfileLock(appRoot: string): string | undefined {
132
+ return [
133
+ path.join(appRoot, 'ios', 'Podfile.lock'),
134
+ path.join(appRoot, 'Podfile.lock'),
135
+ ].find((file) => fs.existsSync(file))
136
+ }
137
+
138
+ /** install only the locked closure of missing imports, then read CocoaPods' real project.
139
+ * `headerModules` are framework names C and C++ sources include (`<MMKVCore/MMKV.h>`)
140
+ * that no collected file provides; they select only trunk pods, since a pod the
141
+ * app installs from a local path is React Native's own or the provider itself. */
80
142
  export async function collectSwiftSourcePods(
81
- appRoot: string,
143
+ lockFile: string,
82
144
  modules: readonly string[],
83
145
  moduleRoot: string,
146
+ headerModules: readonly string[] = [],
84
147
  ): Promise<SwiftCompileInput | null> {
85
- const lockFile = path.join(appRoot, 'Podfile.lock')
86
- if (modules.length === 0 || !fs.existsSync(lockFile)) return null
148
+ if (modules.length === 0 && headerModules.length === 0) return null
87
149
  const original = fs.readFileSync(lockFile, 'utf8')
88
150
  const lock: unknown = yaml.parse(original)
89
151
  const pods = lockedPods(lock)
90
- if (!record(lock) || !record(lock['SPEC CHECKSUMS']) || !record(lock['SPEC REPOS']))
91
- throw new Error(
92
- `${lockFile}: source pods require specification checksums and repositories`,
93
- )
152
+ if (!record(lock) || !record(lock['SPEC CHECKSUMS']))
153
+ throw new Error(`${lockFile}: source pods require specification checksums`)
94
154
  const checksums = lock['SPEC CHECKSUMS']
95
- const repositories = lock['SPEC REPOS']
155
+ // CocoaPods omits SPEC REPOS when no pod comes from a specification repository.
156
+ const repositories: Record<string, unknown> = record(lock['SPEC REPOS'])
157
+ ? lock['SPEC REPOS']
158
+ : {}
96
159
  const selected = new Map<string, LockedPod>()
97
160
  const visit = (name: string) => {
98
161
  if (selected.has(name)) return
@@ -106,13 +169,50 @@ export async function collectSwiftSourcePods(
106
169
  selected.set(name, pod)
107
170
  for (const dependency of pod.dependencies) visit(dependency)
108
171
  }
109
- for (const module of modules) {
110
- const roots = [
111
- ...new Set([...pods.keys()].map((name) => name.split('/')[0]!)),
112
- ].filter((name) => name.replace(/[^A-Za-z0-9_]/g, '_') === module)
172
+ const trunkRoots: readonly unknown[] = Array.isArray(repositories.trunk)
173
+ ? repositories.trunk
174
+ : []
175
+ const requested = [
176
+ ...modules,
177
+ ...headerModules.filter((module) => !modules.includes(module)),
178
+ ]
179
+ const lockedRoots = [...new Set([...pods.keys()].map((name) => name.split('/')[0]!))]
180
+ const rootVersion = (root: string) =>
181
+ [...pods.values()].find((pod) => pod.name.split('/')[0] === root)!.version
182
+ // a module named apart from its pod (GzipSwift's Gzip) needs the trunk
183
+ // specifications, read only when some import matches no pod name.
184
+ let trunkModules: Map<string, string> | undefined
185
+ const moduleRoots = new Map<string, string>()
186
+ for (const module of requested) {
187
+ let roots = lockedRoots.filter(
188
+ (name) =>
189
+ name.replace(/[^A-Za-z0-9_]/g, '_') === module &&
190
+ (modules.includes(module) || trunkRoots.includes(name)),
191
+ )
192
+ if (roots.length === 0) {
193
+ trunkModules ??= new Map(
194
+ await Promise.all(
195
+ lockedRoots
196
+ .filter((root) => trunkRoots.includes(root))
197
+ .map(async (root): Promise<[string, string]> => {
198
+ const { spec } = await trunkSpecification(
199
+ lockFile,
200
+ root,
201
+ rootVersion(root),
202
+ checksums[root],
203
+ )
204
+ return [root, podModuleName(spec, root)]
205
+ }),
206
+ ),
207
+ )
208
+ roots = [...trunkModules]
209
+ .filter(([, name]) => name === module)
210
+ .map(([root]) => root)
211
+ }
113
212
  if (roots.length === 0) continue
114
213
  if (roots.length !== 1) throw new Error(`${lockFile}: ambiguous pod module ${module}`)
115
214
  const root = roots[0]!
215
+ moduleRoots.set(module, root)
116
216
  if (pods.has(root)) visit(root)
117
217
  else for (const name of pods.keys()) if (name.startsWith(`${root}/`)) visit(name)
118
218
  }
@@ -157,7 +257,12 @@ export async function collectSwiftSourcePods(
157
257
  return withSwiftRootLock(work, async (lease) => {
158
258
  fs.mkdirSync(path.join(work, `${APP}.xcodeproj`), { recursive: true })
159
259
  const runPod = async (args: string[]): Promise<string> => {
160
- const child = lease.spawn('pod', args, { cwd: work })
260
+ // CocoaPods refuses a non UTF-8 locale, which a daemon or editor parent
261
+ // may not set, so the child names one whatever its caller runs under.
262
+ const child = lease.spawn('pod', args, {
263
+ cwd: work,
264
+ env: { ...process.env, LANG: 'en_US.UTF-8', LC_ALL: 'en_US.UTF-8' },
265
+ })
161
266
  child.stdin.end()
162
267
  const output: Buffer[] = []
163
268
  const errors: Buffer[] = []
@@ -194,33 +299,13 @@ export async function collectSwiftSourcePods(
194
299
  const installedChecksums: Record<string, string> = {}
195
300
  // checksum-pinned JSON binds the original prepare_command too; CocoaPods owns execution.
196
301
  for (const root of [...roots].sort()) {
197
- const version = [...selected.values()].find(
198
- (pod) => pod.name.split('/')[0] === root,
199
- )!.version
200
302
  const file = path.join(work, `${root}.podspec.json`)
201
- let text: string
202
- if (fs.existsSync(file)) text = fs.readFileSync(file, 'utf8')
203
- else {
204
- const shard = createHash('md5')
205
- .update(root)
206
- .digest('hex')
207
- .slice(0, 3)
208
- .split('')
209
- .join('/')
210
- const response = await fetch(
211
- `https://cdn.cocoapods.org/Specs/${shard}/${root}/${version}/${root}.podspec.json`,
212
- )
213
- if (!response.ok)
214
- throw new Error(
215
- `CocoaPods specification ${root} ${version}: HTTP ${response.status}`,
216
- )
217
- text = await response.text()
218
- }
219
- if (createHash('sha1').update(text).digest('hex') !== specificationChecksums[root])
220
- throw new Error(`${work}: ${root} podspec checksum differs from ${lockFile}`)
221
- const spec: unknown = JSON.parse(text)
222
- if (!record(spec) || spec.name !== root || spec.version !== version)
223
- throw new Error(`${work}: specification identity differs for ${root} ${version}`)
303
+ const { text } = await trunkSpecification(
304
+ lockFile,
305
+ root,
306
+ rootVersion(root),
307
+ specificationChecksums[root],
308
+ )
224
309
  if (!fs.existsSync(file)) fs.writeFileSync(file, text)
225
310
  // CocoaPods serializes external JSON specs before computing their installed checksum.
226
311
  const serialized = await runPod(['ipc', 'spec', file])
@@ -278,7 +363,7 @@ export async function collectSwiftSourcePods(
278
363
  (bundle) => bundle.target !== APP,
279
364
  )
280
365
  for (const module of modules)
281
- if (roots.has(module) && !targets.some((target) => target.name === module))
366
+ if (moduleRoots.has(module) && !targets.some((target) => target.name === module))
282
367
  throw new Error(`${work}: CocoaPods did not provide module ${module}`)
283
368
  return input
284
369
  } finally {
@@ -0,0 +1,77 @@
1
+ import { createHash } from 'node:crypto'
2
+ import { existsSync, readFileSync } from 'node:fs'
3
+ import path from 'node:path'
4
+
5
+ // the stand-in entrypoints: the generation key, the objc implementation
6
+ // identity, and the peer metadata receipt all derive from these.
7
+ const STANDIN_DIGEST_ENTRYPOINTS = [
8
+ 'swift-standins.ts',
9
+ 'swift-objc-compile.ts',
10
+ 'swift-objc-metadata.ts',
11
+ ]
12
+
13
+ const SPECIFIER = /from\s*['"]([^'"]+)['"]|import\s*\(\s*['"]([^'"]+)['"]\s*\)/g
14
+
15
+ function resolveImport(fromDir: string, specifier: string): string | null {
16
+ if (!specifier.startsWith('.')) return null
17
+ const absolute = path.resolve(fromDir, specifier)
18
+ for (const candidate of [
19
+ absolute,
20
+ `${absolute}.ts`,
21
+ `${absolute}.tsx`,
22
+ path.join(absolute, 'index.ts'),
23
+ ])
24
+ if (existsSync(candidate)) return candidate
25
+ return null
26
+ }
27
+
28
+ /** the entrypoints' local import closure: every source file whose bytes can
29
+ * change generated stand-ins or objc objects, sorted. a relative specifier
30
+ * that resolves to no file cannot have affected the running program, so it
31
+ * is skipped; a missing entrypoint is a partial set and throws. */
32
+ export function standinDigestFiles(srcDir: string = import.meta.dirname): string[] {
33
+ for (const entry of STANDIN_DIGEST_ENTRYPOINTS)
34
+ if (!existsSync(path.join(srcDir, entry)))
35
+ throw new Error(`stand-in digest entrypoint is missing: ${entry}`)
36
+ const files: string[] = []
37
+ const seen = new Set<string>()
38
+ const queue = STANDIN_DIGEST_ENTRYPOINTS.map((file) => path.join(srcDir, file))
39
+ while (queue.length > 0) {
40
+ const file = queue.pop()!
41
+ if (seen.has(file)) continue
42
+ seen.add(file)
43
+ files.push(file)
44
+ for (const match of readFileSync(file, 'utf8').matchAll(SPECIFIER)) {
45
+ const specifier = match[1] ?? match[2]!
46
+ if (!specifier.startsWith('.')) continue
47
+ const hit = resolveImport(path.dirname(file), specifier)
48
+ if (hit) queue.push(hit)
49
+ }
50
+ }
51
+ return files.sort()
52
+ }
53
+
54
+ /** a digest of the stand-in entrypoints' local import closure: any edit to
55
+ * the emitter, the importer, or anything they reach rebuilds without a
56
+ * manual bump. a bundled cli ships no sources and digests its own bundle
57
+ * instead, which changes with every release. */
58
+ export function standinSourceDigest(srcDir: string = import.meta.dirname): string {
59
+ const entries = STANDIN_DIGEST_ENTRYPOINTS.map((file) => path.join(srcDir, file))
60
+ if (entries.every((file) => !existsSync(file)))
61
+ return createHash('sha256')
62
+ .update(readFileSync(import.meta.filename))
63
+ .digest('hex')
64
+ const hash = createHash('sha256')
65
+ for (const file of standinDigestFiles(srcDir)) {
66
+ const key = path.relative(srcDir, file)
67
+ const bytes = readFileSync(file)
68
+ hash.update(`${Buffer.byteLength(key)}:${key}${bytes.length}:`).update(bytes)
69
+ }
70
+ return hash.digest('hex')
71
+ }
72
+
73
+ /** the running code's own digest, read once at load: a long-lived host runs
74
+ * the code it started with, so rereading disk after an edit would store
75
+ * old-code output under the new digest and poison the cache for fresh
76
+ * processes. */
77
+ export const STANDIN_SOURCE_DIGEST = standinSourceDigest()
@@ -89,9 +89,6 @@ export type StandinResult = {
89
89
  owners: string[]
90
90
  }
91
91
 
92
- /** bump when emitted source changes: the stand-in cache keys on it. */
93
- export const STANDIN_EMIT_VERSION = '12'
94
-
95
92
  /** the modules every stand-in source imports. */
96
93
  export const STANDIN_IMPORTS = ['Foundation', 'UIKit']
97
94
 
@@ -184,10 +181,49 @@ const synthesizedEquality = (symbol: GraphSymbol, conforms: string[]) =>
184
181
  const trap = (path: string) =>
185
182
  `fatalError("${path} is a binary framework peach cannot run")`
186
183
 
184
+ // a graph spells a type from an imported swift module by its leaf, which another
185
+ // module sharing that leaf shadows. the precise id names the owning module, so a
186
+ // top-level type of an imported module keeps it.
187
+ const swiftTopLevel = /^s:(\d+)(\D.*)$/s
188
+ const importedModule = (id: string) => {
189
+ const match = swiftTopLevel.exec(id)
190
+ if (!match) return null
191
+ const name = match[2]!.slice(0, Number(match[1]))
192
+ // exactly one declaration after the module: a length-prefixed leaf and its kind
193
+ const top = /^(\d+)(.+)$/s.exec(match[2]!.slice(name.length))
194
+ return top && top[2]!.length === Number(top[1]) + 1 && /^\w+[CVOPa]$/.test(top[2]!)
195
+ ? name
196
+ : null
197
+ }
198
+ function qualifyImportedTypes(graph: SymbolGraph, imported: Set<string>): SymbolGraph {
199
+ const qualify = (fragment: SymbolFragment) => {
200
+ const module =
201
+ fragment.kind === 'typeIdentifier' && fragment.preciseIdentifier
202
+ ? importedModule(fragment.preciseIdentifier)
203
+ : null
204
+ return module && imported.has(module) && /^\w+$/.test(fragment.spelling)
205
+ ? { ...fragment, spelling: `${module}.${fragment.spelling}` }
206
+ : fragment
207
+ }
208
+ return {
209
+ ...graph,
210
+ symbols: graph.symbols.map((symbol) => ({
211
+ ...symbol,
212
+ declarationFragments: symbol.declarationFragments?.map(qualify),
213
+ functionSignature: symbol.functionSignature && {
214
+ ...symbol.functionSignature,
215
+ returns: symbol.functionSignature.returns?.map(qualify),
216
+ },
217
+ })),
218
+ }
219
+ }
220
+
187
221
  export function emitSwiftStandin(
188
- graphs: SymbolGraph[],
222
+ sourceGraphs: SymbolGraph[],
189
223
  options: StandinOptions,
190
224
  ): StandinResult {
225
+ const imported = new Set(options.imports)
226
+ const graphs = sourceGraphs.map((graph) => qualifyImportedTypes(graph, imported))
191
227
  const skipped: StandinResult['skipped'] = []
192
228
  const behavior = options.behavior ?? new Map<string, StandinBehavior>()
193
229
  const used = new Set<string>()