peachsim 0.1.1815 → 0.1.1818

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 (147) hide show
  1. package/cli/commands/agent-indicator-mode.ts +2 -1
  2. package/cli/commands/coverage-swift.ts +4 -3
  3. package/cli/commands/flow.ts +7 -0
  4. package/cli/commands/inspect/core.ts +1 -1
  5. package/cli/commands/maestro-compare.ts +7 -0
  6. package/cli/commands/package.ts +87 -31
  7. package/cli/commands/screenshot-mode.ts +2 -1
  8. package/cli/commands/shell-boolean-mode.ts +7 -3
  9. package/cli/commands/shell-url.ts +4 -0
  10. package/cli/commands/show-touches-mode.ts +2 -1
  11. package/cli/commands/test.ts +3 -2
  12. package/cli/commands/three-mode.ts +2 -1
  13. package/cli/outbound-endpoints.ts +1 -1
  14. package/cli/packaged-app-launcher.ts +6 -1
  15. package/dist-lib/agent-daemon-client.cjs +1 -1
  16. package/dist-lib/agent-events.cjs +1 -1
  17. package/dist-lib/attached-projects.cjs +1 -1
  18. package/dist-lib/auth/shared-session.cjs +1 -1
  19. package/dist-lib/backend-origin.cjs +1 -1
  20. package/dist-lib/beta.cjs +1 -1
  21. package/dist-lib/beta.mjs +1 -1
  22. package/dist-lib/bridge-constants.cjs +1 -1
  23. package/dist-lib/bridge-contract-input.cjs +1 -1
  24. package/dist-lib/bridge-contract-input.mjs +1 -1
  25. package/dist-lib/bridge-contract.cjs +1 -1
  26. package/dist-lib/bridge-contract.mjs +1 -1
  27. package/dist-lib/bundle-channel.cjs +5728 -7551
  28. package/dist-lib/capture-contract.cjs +1 -1
  29. package/dist-lib/capture-contract.mjs +1 -1
  30. package/dist-lib/cloud-contract.cjs +1 -1
  31. package/dist-lib/cloud-contract.mjs +1 -1
  32. package/dist-lib/cloud-test-args.cjs +1 -1
  33. package/dist-lib/cloud-test-args.mjs +1 -1
  34. package/dist-lib/cloud.cjs +1 -1
  35. package/dist-lib/cloud.mjs +1 -1
  36. package/dist-lib/config.cjs +1 -1
  37. package/dist-lib/config.mjs +1 -1
  38. package/dist-lib/detox/index.cjs +13 -4
  39. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  40. package/dist-lib/expo-swift-bundle.cjs +5234 -5704
  41. package/dist-lib/expo-swift-metadata.cjs +1 -1
  42. package/dist-lib/expo-swift-metadata.mjs +1 -1
  43. package/dist-lib/home-paths.cjs +1 -1
  44. package/dist-lib/host/bridge-host.cjs +4913 -6811
  45. package/dist-lib/host/fetch-proxy-handler.cjs +13 -4
  46. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  47. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  48. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  49. package/dist-lib/host/websocket-proxy.cjs +1 -1
  50. package/dist-lib/index.cjs +40 -30
  51. package/dist-lib/jump-to-source-babel.cjs +1 -1
  52. package/dist-lib/jump-to-source-native.cjs +1 -1
  53. package/dist-lib/kotlin-host.cjs +1 -1
  54. package/dist-lib/menu.cjs +1 -1
  55. package/dist-lib/menu.mjs +1 -1
  56. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  57. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  58. package/dist-lib/metro-production-bundle.cjs +1 -1
  59. package/dist-lib/metro-production-bundle.mjs +1 -1
  60. package/dist-lib/metro.cjs +39 -29
  61. package/dist-lib/native-app-identity-project.cjs +31 -26
  62. package/dist-lib/native-app-identity-project.mjs +295 -279
  63. package/dist-lib/native-app-identity.cjs +1 -1
  64. package/dist-lib/native-app-identity.mjs +1 -1
  65. package/dist-lib/native-firebase-metadata.cjs +1 -1
  66. package/dist-lib/native-firebase-metadata.mjs +1 -1
  67. package/dist-lib/pdfium-raster.cjs +1 -1
  68. package/dist-lib/pdfium-raster.mjs +1 -1
  69. package/dist-lib/plist.cjs +1 -1
  70. package/dist-lib/plist.mjs +1 -1
  71. package/dist-lib/profiles.cjs +1 -1
  72. package/dist-lib/public-brand.cjs +1 -1
  73. package/dist-lib/public-origins-lib-esm.json +29 -24
  74. package/dist-lib/public-origins-lib.json +121 -93
  75. package/dist-lib/react-native-host-modules.cjs +1 -1
  76. package/dist-lib/react-native-host-modules.mjs +1 -1
  77. package/dist-lib/reap-browser.cjs +1 -1
  78. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  79. package/dist-lib/sdk.cjs +2 -2
  80. package/dist-lib/sdk.mjs +2 -2
  81. package/dist-lib/skills.cjs +64622 -66476
  82. package/dist-lib/swift-compile.cjs +328 -265
  83. package/dist-lib/swift-compile.mjs +335 -270
  84. package/dist-lib/swift-package.cjs +1 -1
  85. package/dist-lib/swift-package.mjs +1 -1
  86. package/dist-lib/swift-submit.cjs +1 -1
  87. package/dist-lib/swift-submit.mjs +1 -1
  88. package/dist-lib/swift-toolchain.cjs +52 -6
  89. package/dist-lib/swift.cjs +1 -1
  90. package/dist-lib/vite-swift.cjs +2405 -2262
  91. package/dist-lib/vite.cjs +13 -4
  92. package/dist-lib/worklet-executable.cjs +1 -1
  93. package/dist-lib/worklet-executable.mjs +1 -1
  94. package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +5 -0
  95. package/dist-types/packages/peach-engine/src/render-worker/map-command-channel.d.ts +41 -0
  96. package/dist-types/packages/peach-engine/src/render-worker/mapServicesContract.d.ts +45 -0
  97. package/package.json +2 -1
  98. package/runtime-companion.json +1 -1
  99. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIKit.apinotes +1 -1
  100. package/sdk/ios/usr/include/module.modulemap +3 -0
  101. package/sdk/ios/usr/include/notify.modulemap +9 -0
  102. package/sdk/ios/usr/lib/swift/Darwin.swiftmodule/arm64-apple-ios-simulator.swiftinterface +4 -0
  103. package/sdk/ios/usr/lib/swift/Dispatch.swiftmodule/arm64-apple-ios-simulator.swiftinterface +1 -1
  104. package/sdk/ios/usr/lib/swift/Foundation.swiftmodule/arm64-apple-ios-simulator.swiftinterface +7 -1
  105. package/sdk/ios/usr/lib/swift/ObjectiveC.swiftmodule/arm64-apple-ios-simulator.swiftinterface +1 -0
  106. package/sdk/ios/usr/lib/swift/SwiftUI.swiftmodule/arm64-apple-ios-simulator.swiftinterface +21 -0
  107. package/sdk/ios/usr/lib/swift/SwiftUICore.swiftmodule/arm64-apple-ios-simulator.swiftinterface +6 -1
  108. package/sdk/ios/wasm/include/__header_time.h +4 -0
  109. package/sdk/ios/wasm/include/pthread.h +2 -0
  110. package/sdk/ios/wasm/include/sys/mman.h +1 -1
  111. package/sdk/ios/wasm/include/sys/resource.h +31 -0
  112. package/sdk/ios/wasm/include/unistd.h +4 -0
  113. package/src/answeredNativePackages.ts +43 -0
  114. package/src/cli-runtime.ts +2 -9
  115. package/src/expo-discovery-cache.ts +71 -52
  116. package/src/expo-kotlin-host.ts +11 -9
  117. package/src/expo-swift-host.ts +55 -13
  118. package/src/installed-native-libraries.ts +103 -20
  119. package/src/native-static-libraries.ts +69 -33
  120. package/src/nitro-adapter.ts +0 -9
  121. package/src/nitro-bundle.ts +8 -6
  122. package/src/nitro-compile.ts +45 -16
  123. package/src/nitro-compiler-digest.ts +2 -4
  124. package/src/nitro-superset.lock.json +19 -251
  125. package/src/nitro-superset.ts +63 -68
  126. package/src/plist-bytes.ts +9 -0
  127. package/src/portable-expo-workspace.ts +4 -3
  128. package/src/react-native-bridge-modules.ts +13 -19
  129. package/src/swift-compile.ts +379 -269
  130. package/src/swift-cxx-reachable.ts +13 -0
  131. package/src/swift-distribution.ts +3 -4
  132. package/src/swift-host.ts +5 -3
  133. package/src/swift-installed-targets.ts +32 -14
  134. package/src/swift-native-pin.ts +45 -0
  135. package/src/swift-objc-compile.ts +23 -1
  136. package/src/swift-objc-standin.ts +14 -7
  137. package/src/swift-package-manifest.ts +2 -2
  138. package/src/swift-root-lock.ts +4 -3
  139. package/src/swift-standins.ts +41 -38
  140. package/src/swift-toolchain.ts +69 -12
  141. package/src/swift-wasm-prune.ts +1 -0
  142. package/src/swift-xcframework.ts +23 -12
  143. package/src/swiftContract.ts +2 -0
  144. package/src/swiftNativePinContract.ts +68 -0
  145. package/src/turbo-bundle.ts +14 -6
  146. package/src/turbo-compile.ts +76 -11
  147. package/src/turbo-source.ts +93 -18
@@ -4,23 +4,24 @@
4
4
  // isolated homes instead of redoing the prepare and the workspace read.
5
5
  // entries address content only; a store that cannot prove its paths refuses
6
6
  // rather than serve bytes another home cannot trust.
7
- // every unit carries the same headers, so each distinct body is stored once
8
- // under its digest and units hold references; without that a large discovery
9
- // exceeds the longest string the runtime can build and no repeat ever hits.
7
+ // bodies, target metadata and units are separate content-addressed records.
8
+ // repeated headers and header maps share bytes without building one discovery-
9
+ // sized string on either the write or read path.
10
10
  import { createHash, randomUUID } from 'node:crypto'
11
11
  import fs from 'node:fs'
12
12
  import { homedir } from 'node:os'
13
13
  import path from 'node:path'
14
14
  import { fileURLToPath } from 'node:url'
15
15
  import { EXPO_EAGER_NATIVE_VIEWS } from '../../peach-compat/src/stubs/native-seams/expo-eager-seam-contract'
16
+ import { peachAnsweredNativePackages } from './answeredNativePackages'
16
17
  import { getCliVersion } from './cli-version'
17
18
  import { hashExpoWorkspace } from './expo-native-workspace'
18
19
  import { isRecord } from './is-record'
19
20
  import { isNativeAppIdentity } from './native-app-identity'
20
- import { isSwiftResourceBundles } from './swiftContract'
21
+ import { isSwiftNativeTargets, isSwiftResourceBundles } from './swiftContract'
21
22
  import type { ExpoSwiftSourceUnit } from './expoSwiftContract'
22
23
 
23
- const FORMAT = 'expo-discovery-v4'
24
+ const FORMAT = 'expo-discovery-v5'
24
25
 
25
26
  // pipeline files whose bytes change discovery output. resolved beside this
26
27
  // module in source (.ts) and in a built cli (.js); a missing file pins as
@@ -53,6 +54,7 @@ function peachPin(): string {
53
54
  const hash = createHash('sha256')
54
55
  hash.update(`${FORMAT}\0${getCliVersion()}\0`)
55
56
  hash.update(JSON.stringify([...EXPO_EAGER_NATIVE_VIEWS]))
57
+ hash.update(JSON.stringify([...peachAnsweredNativePackages()].sort()))
56
58
  for (const name of PIPELINE_FILES) {
57
59
  let bytes: string | null = null
58
60
  for (const ext of ['.ts', '.js']) {
@@ -135,15 +137,18 @@ function isExpoSwiftSourceUnit(value: unknown): value is ExpoSwiftSourceUnit {
135
137
  // a stored unit holds blob digests where a live unit holds bodies.
136
138
  type StoredExpoSwiftSourceUnit = Omit<
137
139
  ExpoSwiftSourceUnit,
138
- 'files' | 'nativeFiles' | 'resources'
140
+ 'files' | 'nativeFiles' | 'resources' | 'nativeTargets'
139
141
  > & {
140
142
  files: Record<string, string>
141
143
  nativeFiles?: Record<string, string>
142
144
  resources?: Record<string, string>
145
+ nativeTargets?: string[]
143
146
  }
144
147
 
148
+ const isDigest = (value: string): boolean => /^[0-9a-f]{64}$/.test(value)
149
+
145
150
  const digestRecord = (value: unknown): value is Record<string, string> =>
146
- stringRecord(value) && Object.values(value).every((item) => /^[0-9a-f]{64}$/.test(item))
151
+ stringRecord(value) && Object.values(value).every(isDigest)
147
152
 
148
153
  function isStoredUnit(value: unknown): value is StoredExpoSwiftSourceUnit {
149
154
  return (
@@ -157,7 +162,7 @@ function isStoredUnit(value: unknown): value is StoredExpoSwiftSourceUnit {
157
162
  digestRecord(value.files) &&
158
163
  strings(value.frameworks) &&
159
164
  (value.nativeTargets === undefined ||
160
- (Array.isArray(value.nativeTargets) && value.nativeTargets.every(isRecord))) &&
165
+ (strings(value.nativeTargets) && value.nativeTargets.every(isDigest))) &&
161
166
  (value.nativeFiles === undefined || digestRecord(value.nativeFiles)) &&
162
167
  (value.resources === undefined || digestRecord(value.resources)) &&
163
168
  (value.resourceBundles === undefined ||
@@ -191,42 +196,53 @@ export function readExpoDiscovery(key: string): ExpoSwiftSourceUnit[] | null | u
191
196
  return undefined
192
197
  }
193
198
  if (parsed.units === null) return null
194
- if (
195
- !Array.isArray(parsed.units) ||
196
- !parsed.units.every(isStoredUnit) ||
197
- !stringRecord(parsed.blobs)
198
- )
199
- return undefined
200
- const blobs = parsed.blobs
201
- const resolve = (refs: Record<string, string>): Record<string, string> | undefined => {
199
+ if (!strings(parsed.units) || !parsed.units.every(isDigest)) return undefined
200
+ const blobs = new Map<string, string>()
201
+ const read = (digest: string): string => {
202
+ const known = blobs.get(digest)
203
+ if (known !== undefined) return known
204
+ const body = fs.readFileSync(path.join(sharedDir(), 'blobs', digest), 'utf8')
205
+ if (createHash('sha256').update(body).digest('hex') !== digest)
206
+ throw new Error('discovery blob differs from its digest')
207
+ blobs.set(digest, body)
208
+ return body
209
+ }
210
+ const resolve = (refs: Record<string, string>): Record<string, string> => {
202
211
  const bodies: Record<string, string> = {}
203
212
  for (const [name, digest] of Object.entries(refs)) {
204
- const body = blobs[digest]
205
- if (body === undefined) return undefined
206
- bodies[name] = body
213
+ bodies[name] = read(digest)
207
214
  }
208
215
  return bodies
209
216
  }
210
217
  const units: ExpoSwiftSourceUnit[] = []
211
- for (const stored of parsed.units) {
212
- const files = resolve(stored.files)
213
- if (files === undefined) return undefined
214
- const nativeFiles =
215
- stored.nativeFiles === undefined ? undefined : resolve(stored.nativeFiles)
216
- if (stored.nativeFiles !== undefined && nativeFiles === undefined) return undefined
217
- const resources =
218
- stored.resources === undefined ? undefined : resolve(stored.resources)
219
- if (stored.resources !== undefined && resources === undefined) return undefined
220
- const unit: ExpoSwiftSourceUnit = {
221
- ...stored,
222
- files,
223
- ...(nativeFiles === undefined ? {} : { nativeFiles }),
224
- ...(resources === undefined ? {} : { resources }),
218
+ try {
219
+ for (const digest of parsed.units) {
220
+ const stored: unknown = JSON.parse(read(digest))
221
+ if (!isStoredUnit(stored)) return undefined
222
+ const nativeTargets: unknown = stored.nativeTargets?.map((ref) =>
223
+ JSON.parse(read(ref)),
224
+ )
225
+ if (nativeTargets !== undefined && !isSwiftNativeTargets(nativeTargets))
226
+ return undefined
227
+ const files = resolve(stored.files)
228
+ const nativeFiles =
229
+ stored.nativeFiles === undefined ? undefined : resolve(stored.nativeFiles)
230
+ const resources =
231
+ stored.resources === undefined ? undefined : resolve(stored.resources)
232
+ const unit: ExpoSwiftSourceUnit = {
233
+ ...stored,
234
+ nativeTargets,
235
+ files,
236
+ ...(nativeFiles === undefined ? {} : { nativeFiles }),
237
+ ...(resources === undefined ? {} : { resources }),
238
+ }
239
+ if (!isExpoSwiftSourceUnit(unit)) return undefined
240
+ units.push(unit)
225
241
  }
226
- if (!isExpoSwiftSourceUnit(unit)) return undefined
227
- units.push(unit)
242
+ return units
243
+ } catch {
244
+ return undefined
228
245
  }
229
- return units
230
246
  }
231
247
 
232
248
  const sourceLocationLine = /^#sourceLocation\(file: "(.*)", line: 1\)$/
@@ -456,7 +472,6 @@ export function writeExpoDiscovery(options: {
456
472
  format: FORMAT,
457
473
  key: options.key,
458
474
  units: null,
459
- blobs: {},
460
475
  dependencies: {},
461
476
  frameworks: {},
462
477
  }),
@@ -473,48 +488,52 @@ export function writeExpoDiscovery(options: {
473
488
  if ('refuse' in rewritten) return rewritten.refuse
474
489
  // one blob per distinct body; units keep digests. repeated bodies hash
475
490
  // once: string hashes memoize, so a shared body is a cheap map hit.
476
- const blobs = new Map<string, string>()
491
+ const blobDir = path.join(dir, 'blobs')
492
+ fs.mkdirSync(blobDir, { recursive: true })
477
493
  const seen = new Map<string, string>()
478
494
  const digestFor = (body: string): string => {
479
495
  const known = seen.get(body)
480
496
  if (known !== undefined) return known
497
+ options.signal?.throwIfAborted()
498
+ if (body.includes(options.preparedRoot))
499
+ throw new Error('a prepared path survives the rewrite')
481
500
  const digest = createHash('sha256').update(body).digest('hex')
501
+ const file = path.join(blobDir, digest)
502
+ const temporary = path.join(blobDir, '.' + randomUUID() + '.tmp')
503
+ try {
504
+ fs.writeFileSync(temporary, body)
505
+ fs.renameSync(temporary, file)
506
+ } finally {
507
+ fs.rmSync(temporary, { force: true })
508
+ }
482
509
  seen.set(body, digest)
483
- blobs.set(digest, body)
484
510
  return digest
485
511
  }
486
512
  const reference = (bodies: Record<string, string>) =>
487
513
  Object.fromEntries(
488
514
  Object.entries(bodies).map(([name, body]) => [name, digestFor(body)]),
489
515
  )
490
- const stored: StoredExpoSwiftSourceUnit[] = rewritten.units.map((unit) => {
516
+ const stored = rewritten.units.map((unit) => {
491
517
  options.signal?.throwIfAborted()
492
- return {
518
+ const value: StoredExpoSwiftSourceUnit = {
493
519
  ...unit,
520
+ nativeTargets: unit.nativeTargets?.map((target) =>
521
+ digestFor(JSON.stringify(target)),
522
+ ),
494
523
  files: reference(unit.files),
495
524
  ...(unit.nativeFiles === undefined
496
525
  ? {}
497
526
  : { nativeFiles: reference(unit.nativeFiles) }),
498
527
  ...(unit.resources === undefined ? {} : { resources: reference(unit.resources) }),
499
528
  }
529
+ return digestFor(JSON.stringify(value))
500
530
  })
501
- // the surviving-path scan stays on bounded strings: the small reference
502
- // maps, then each body alone. stringifying whole units here is what used
503
- // to exceed the longest buildable string on large discoveries.
504
- if (JSON.stringify(stored).includes(options.preparedRoot))
505
- return 'a prepared path survives the rewrite'
506
- for (const body of blobs.values()) {
507
- options.signal?.throwIfAborted()
508
- if (body.includes(options.preparedRoot))
509
- return 'a prepared path survives the rewrite'
510
- }
511
531
  fs.writeFileSync(
512
532
  tmp,
513
533
  JSON.stringify({
514
534
  format: FORMAT,
515
535
  key: options.key,
516
536
  units: stored,
517
- blobs: Object.fromEntries(blobs),
518
537
  dependencies: rewritten.dependencies,
519
538
  frameworks: rewritten.frameworks,
520
539
  }),
@@ -4,7 +4,6 @@
4
4
  // package with a native seam keeps it; one without compiles here.
5
5
  import fs from 'node:fs'
6
6
  import path from 'node:path'
7
- import { PEACH_ANSWERED_NATIVE_PACKAGE_NAMES } from '../../peach-compat/src/generated/supported-native-packages'
8
7
  import { resolveExpoAndroidAutolinking } from './android-autolinking'
9
8
  import {
10
9
  androidAppSources,
@@ -12,6 +11,7 @@ import {
12
11
  type BridgePackage,
13
12
  type BridgeSelection,
14
13
  } from './android-bridge-packages'
14
+ import { peachAnsweredNativePackages } from './answeredNativePackages'
15
15
  import { isLoopbackHost } from './backend-origin'
16
16
  import { isRecord } from './is-record'
17
17
  import { peachKotlinModuleRoot } from './kotlin-module'
@@ -20,8 +20,6 @@ import type { IncomingMessage, ServerResponse } from 'node:http'
20
20
 
21
21
  export const EXPO_KOTLIN_ROUTE = '/__peach/expo-kotlin'
22
22
 
23
- const answeredPackages: ReadonlySet<string> = new Set(PEACH_ANSWERED_NATIVE_PACKAGE_NAMES)
24
-
25
23
  export interface ExpoKotlinModules {
26
24
  // the registration names Android's ExpoModulesPackageList passes, in order
27
25
  modules: { classifier: string; name: string | null }[]
@@ -44,6 +42,7 @@ export async function collectExpoKotlinModules(
44
42
  ): Promise<ExpoKotlinProject[] | null> {
45
43
  const modules = await resolveExpoAndroidAutolinking(appRoot)
46
44
  const result: ExpoKotlinProject[] = []
45
+ let answeredInstalled = false
47
46
  for (const entry of modules) {
48
47
  // plugin-only dependencies have no local Kotlin module project.
49
48
  if (entry.projects === undefined) continue
@@ -58,11 +57,13 @@ export async function collectExpoKotlinModules(
58
57
  throw new Error('invalid Expo Android project')
59
58
  const sourceDir = fs.realpathSync(project.sourceDir)
60
59
  const installed = sourceDir.split(path.sep).includes('node_modules')
61
- if (
62
- installed &&
63
- (typeof entry.packageName !== 'string' || answeredPackages.has(entry.packageName))
64
- )
65
- continue
60
+ if (installed) {
61
+ if (typeof entry.packageName !== 'string') continue
62
+ if (peachAnsweredNativePackages().has(entry.packageName)) {
63
+ answeredInstalled = true
64
+ continue
65
+ }
66
+ }
66
67
  if (project.modules.length === 0) continue
67
68
  const group: ExpoKotlinProject = {
68
69
  modules: [],
@@ -105,7 +106,8 @@ export async function collectExpoKotlinModules(
105
106
  result.push(group)
106
107
  }
107
108
  }
108
- return result.length === 0 ? null : result
109
+ // an app whose installed modules a seam answers still links native modules.
110
+ return result.length === 0 && !answeredInstalled ? null : result
109
111
  }
110
112
 
111
113
  // the app module's ReactPackage classes the application registers
@@ -9,10 +9,10 @@ import os from 'node:os'
9
9
  import path from 'node:path'
10
10
  import { fileURLToPath } from 'node:url'
11
11
  import { promisify } from 'node:util'
12
- import { PEACH_ANSWERED_NATIVE_PACKAGE_NAMES } from '../../peach-compat/src/generated/supported-native-packages'
13
12
  import { EXPO_EAGER_NATIVE_VIEWS } from '../../peach-compat/src/stubs/native-seams/expo-eager-seam-contract'
14
13
  import { loadRNXAppConfig } from '../cli/app-config'
15
14
  import { resolveAppProject } from '../cli/app-project'
15
+ import { peachAnsweredNativePackages } from './answeredNativePackages'
16
16
  import { isLoopbackHost } from './backend-origin'
17
17
  import { autolinkerAppleFlags } from './expo-autolinking'
18
18
  import {
@@ -29,6 +29,10 @@ import { cacheDir } from './home-paths'
29
29
  import { isRecord } from './is-record'
30
30
  import { readExpoConfigAsync } from './native-firebase-config'
31
31
  import { NativePreparationReceipts } from './native-preparation'
32
+ import {
33
+ combineNativeStaticLibraries,
34
+ nonmodularFrameworkLibraries,
35
+ } from './native-static-libraries'
32
36
  import {
33
37
  NATIVE_PREPARE_QUERY_PARAM,
34
38
  NATIVE_PREPARED_QUERY_PARAM,
@@ -108,7 +112,6 @@ const WITNESS_BATCH = 200
108
112
  const traceStore = new AsyncLocalStorage<Witness>()
109
113
  const discoveryCache = new Map<string, DiscoveryEntry>()
110
114
  const preparedCache = new Map<string, PreparedEntry>()
111
- const answeredPackages: ReadonlySet<string> = new Set(PEACH_ANSWERED_NATIVE_PACKAGE_NAMES)
112
115
 
113
116
  type MissingMark = { missing: true }
114
117
  type PresentMark = {
@@ -642,7 +645,10 @@ function enrichInstalledUnits(
642
645
  interfaceRoot?: string,
643
646
  ): void {
644
647
  const { input, binaryFrameworks } = installed
645
- const installedTargets = swiftManifestTargets(input.files['Package.swift'] ?? '')
648
+ // each unit generates its own binary stand-ins, so the workspace's are not re-mapped
649
+ const installedTargets = swiftManifestTargets(
650
+ input.files['Package.swift'] ?? '',
651
+ ).filter((target) => !target.path.startsWith(`${SWIFT_STANDINS_DIR}/`))
646
652
  const targetByName = new Map(installedTargets.map((target) => [target.name, target]))
647
653
  const importedTargets = swiftTargetDependencies(input.files, installedTargets)
648
654
  const byPath = [...installedTargets].sort((a, b) => b.path.length - a.path.length)
@@ -685,6 +691,12 @@ function enrichInstalledUnits(
685
691
  }
686
692
  for (const name of namespaceGroups.get(unit.namespace) ?? [unit.namespace])
687
693
  visit(name, true)
694
+ // a unit lays each included target out at Sources/<name>, where its Bundle.module accessor reads the assignment
695
+ unit.resourceBundles = input.resourceBundles?.map((bundle) =>
696
+ targetByName.has(bundle.target)
697
+ ? { ...bundle, sourcePath: `Sources/${bundle.target}` }
698
+ : bundle,
699
+ )
688
700
  for (const [file, source] of Object.entries(input.files)) {
689
701
  const owner = byPath.find((target) => file.startsWith(`${target.path}/`))
690
702
  if (
@@ -1019,6 +1031,7 @@ async function collectExpoSwiftSourcesUncached(
1019
1031
  {
1020
1032
  configuration: 'Debug',
1021
1033
  interfaceRoot: module.root,
1034
+ moduleRoot: module.root,
1022
1035
  nativeModules: resolutions.flatMap((resolution) =>
1023
1036
  isRecord(resolution) && Array.isArray(resolution.swiftModuleNames)
1024
1037
  ? resolution.swiftModuleNames.filter(
@@ -1049,6 +1062,7 @@ async function collectExpoSwiftSourcesUncached(
1049
1062
  const units: ExpoSwiftSourceUnit[] = []
1050
1063
  const namespacesSeen = new Set<string>()
1051
1064
  const namespaceGroups = new Map<string, string[]>()
1065
+ let answeredInstalled = false
1052
1066
  let needsNativeWorkspace = false
1053
1067
  let bytes = 0
1054
1068
  let fileCount = 0
@@ -1067,9 +1081,11 @@ async function collectExpoSwiftSourcesUncached(
1067
1081
  // through the same autolinker-selected route as app-local modules.
1068
1082
  if (
1069
1083
  canonical.split(path.sep).includes('node_modules') &&
1070
- answeredPackages.has(packageName)
1071
- )
1084
+ peachAnsweredNativePackages().has(packageName)
1085
+ ) {
1086
+ answeredInstalled = true
1072
1087
  continue
1088
+ }
1073
1089
  // the autolinker read these in a child, so the parent can only stamp them
1074
1090
  // afterwards. one modified since the child started may be newer than what
1075
1091
  // the child consumed, and so may a module directory that gained or lost one.
@@ -1530,7 +1546,8 @@ async function collectExpoSwiftSourcesUncached(
1530
1546
  units.push(inlineUnit)
1531
1547
  }
1532
1548
  }
1533
- if (units.length === 0) return null
1549
+ // an app whose installed modules a seam answers still links native modules.
1550
+ if (units.length === 0) return answeredInstalled ? [] : null
1534
1551
  if (installed)
1535
1552
  enrichInstalledUnits(
1536
1553
  units,
@@ -1634,7 +1651,7 @@ function expoManifest(
1634
1651
  ? [dependency.name]
1635
1652
  : [],
1636
1653
  )
1637
- return `.target(name: ${JSON.stringify(name)}, dependencies: ${JSON.stringify(dependencies)}, path: ${JSON.stringify(dir)}${configuration ? ', ' + swiftManifestSettings(configuration) : ''})`
1654
+ return `.target(name: ${JSON.stringify(name)}, dependencies: ${JSON.stringify(dependencies)}, path: ${JSON.stringify(dir)}${declared?.resources ? ', resources: []' : ''}${configuration ? ', ' + swiftManifestSettings(configuration) : ''})`
1638
1655
  })
1639
1656
  return `// swift-tools-version: 6.0\nimport PackageDescription\nlet package = Package(name: "PeachExpo", targets: [${declarations.join(', ')}, .executableTarget(name: "PeachExpoApp", path: "Sources/PeachExpoApp")])\n// stand-in inputs: ${generation}\n`
1640
1657
  }
@@ -1642,7 +1659,9 @@ function expoManifest(
1642
1659
  function targetSettings(units: ExpoSwiftSourceUnit[]) {
1643
1660
  const settings = new Map<
1644
1661
  string,
1645
- Parameters<typeof swiftManifestSettings>[0] & Pick<SwiftPackageTarget, 'dependencies'>
1662
+ Parameters<typeof swiftManifestSettings>[0] &
1663
+ Pick<SwiftPackageTarget, 'dependencies'> &
1664
+ Partial<Pick<SwiftPackageTarget, 'resources'>>
1646
1665
  >()
1647
1666
  for (const unit of units) {
1648
1667
  for (const target of swiftManifestTargets(unit.files['Package.swift'] ?? ''))
@@ -1892,7 +1911,8 @@ async function compileExpoSwiftModulesTraced(
1892
1911
  }
1893
1912
  const units = [...(expoUnits ?? []), ...(bridge?.units ?? [])]
1894
1913
  const bridgeFailures = bridge?.failures ?? []
1895
- if (units.length === 0 && bridgeFailures.length === 0) return null
1914
+ if (units.length === 0 && bridgeFailures.length === 0 && expoUnits === null)
1915
+ return null
1896
1916
  report(
1897
1917
  `preparing ${units.length} modules: ${units.map((unit) => unit.moduleId).join(', ')}`,
1898
1918
  )
@@ -1933,8 +1953,25 @@ async function compileExpoSwiftModulesTraced(
1933
1953
  const generations = new Map<ExpoSwiftSourceUnit, string>()
1934
1954
  const gaps = new Map<ExpoSwiftSourceUnit, string[]>()
1935
1955
  const libraries = new Map<ExpoSwiftSourceUnit, Record<string, string>>()
1956
+ const [firstSharedLibrary, ...otherSharedLibraries] = nonmodularFrameworkLibraries(
1957
+ [...new Set(units.flatMap((unit) => unit.frameworks))],
1958
+ module.root,
1959
+ )
1960
+ const sharedLibrary =
1961
+ firstSharedLibrary === undefined
1962
+ ? undefined
1963
+ : fs
1964
+ .readFileSync(
1965
+ combineNativeStaticLibraries(
1966
+ [firstSharedLibrary, ...otherSharedLibraries],
1967
+ module.root,
1968
+ ),
1969
+ )
1970
+ .toString('base64')
1936
1971
  for (const unit of units) {
1937
1972
  signal.throwIfAborted()
1973
+ if (sharedLibrary !== undefined)
1974
+ libraries.set(unit, { [unit.namespace]: sharedLibrary })
1938
1975
  if (unit.absentFrameworks)
1939
1976
  gaps.set(
1940
1977
  unit,
@@ -2021,15 +2058,15 @@ async function compileExpoSwiftModulesTraced(
2021
2058
  unit.nativeTargets.push(standinNativeTarget(standin, deploymentTarget))
2022
2059
  }
2023
2060
  if (linkedLibraries.size > 0)
2024
- libraries.set(
2025
- unit,
2026
- Object.fromEntries(
2061
+ libraries.set(unit, {
2062
+ ...libraries.get(unit),
2063
+ ...Object.fromEntries(
2027
2064
  [...linkedLibraries].map(([library, [first]]) => [
2028
2065
  first!.module,
2029
2066
  fs.readFileSync(library).toString('base64'),
2030
2067
  ]),
2031
2068
  ),
2032
- )
2069
+ })
2033
2070
  generations.set(unit, generation)
2034
2071
  gaps.set(unit, [
2035
2072
  ...(gaps.get(unit) ?? []),
@@ -2110,8 +2147,13 @@ async function compileExpoSwiftModulesTraced(
2110
2147
  ),
2111
2148
  )
2112
2149
  const linkedLibraries = new Map<string, string>()
2150
+ let linkedSharedLibrary = false
2113
2151
  for (const unit of linked)
2114
2152
  for (const [name, library] of Object.entries(libraries.get(unit) ?? {})) {
2153
+ if (name === unit.namespace && library === sharedLibrary) {
2154
+ if (linkedSharedLibrary) continue
2155
+ linkedSharedLibrary = true
2156
+ }
2115
2157
  if (linkedLibraries.has(name) && linkedLibraries.get(name) !== library)
2116
2158
  throw new Error(`conflicting Expo Swift binary libraries for ${name}`)
2117
2159
  linkedLibraries.set(name, library)
@@ -9,22 +9,24 @@ import { isRecord } from './is-record'
9
9
  import {
10
10
  combineNativeStaticLibraries,
11
11
  nativeStaticLibrary,
12
+ nonmodularFrameworkLibraries,
12
13
  nativeStaticLibraryRecipe,
13
14
  } from './native-static-libraries'
14
15
  import { readPackageFile, relativeInside } from './swift-source-file'
15
- import { simulatorStaticArchive } from './swift-xcframework'
16
+ import { simulatorNativeLibrary } from './swift-xcframework'
16
17
  import { readXcodeAppTarget, requireInstalledXcodeWorkspace } from './xcode-project'
17
- import type { TurboInstalledPod, TurboProvider } from './turbo-source'
18
+ import type {
19
+ TurboInstalledPod,
20
+ TurboInstalledSources,
21
+ TurboProvider,
22
+ } from './turbo-source'
23
+ import type { XcodeModuleTarget } from './xcode-project'
18
24
 
19
- export function installedNativeLibraries(
25
+ function installedProviderTargets(
20
26
  providers: readonly Pick<TurboProvider, 'name' | 'podspecPath'>[],
21
27
  projectRoot: string,
22
- moduleRoot: string,
23
28
  iosTarget?: string,
24
- frameworkLinkOwner: 'workspace' | 'provider' = 'workspace',
25
- ): InstalledNativeLibraries {
26
- const result: InstalledNativeLibraries = { pods: new Map(), unavailable: new Map() }
27
- if (providers.length === 0) return result
29
+ ) {
28
30
  const workspace = requireInstalledXcodeWorkspace(projectRoot, 'native providers')
29
31
  const app = readXcodeAppTarget(workspace, iosTarget, 'Release', {
30
32
  installedPods: true,
@@ -34,6 +36,66 @@ export function installedNativeLibraries(
34
36
  path.basename(provider.podspecPath, '.podspec'),
35
37
  ),
36
38
  })
39
+ const targets = new Map<string, XcodeModuleTarget>()
40
+ for (const provider of providers) {
41
+ const name = path.basename(provider.podspecPath, '.podspec')
42
+ const target = app.frameworks.find((item) => item.name === name)
43
+ if (!target?.podRoot)
44
+ throw new Error(`${name}: installed target has no PODS_TARGET_SRCROOT`)
45
+ targets.set(provider.name, target)
46
+ }
47
+ return { app, targets }
48
+ }
49
+
50
+ function installedTargetSources(target: XcodeModuleTarget) {
51
+ const root = fs.realpathSync(target.podRoot!)
52
+ const files = new Set(
53
+ [
54
+ ...target.allSources,
55
+ ...(target.objc?.headers ?? []),
56
+ ...(target.objc?.publicHeaders ?? []),
57
+ ].map((file) => fs.realpathSync(file)),
58
+ )
59
+ return { root, files }
60
+ }
61
+
62
+ export function installedNativeSources(
63
+ providers: readonly Pick<TurboProvider, 'name' | 'podspecPath'>[],
64
+ projectRoot: string,
65
+ iosTarget?: string,
66
+ ): Map<string, TurboInstalledSources> {
67
+ if (providers.length === 0) return new Map()
68
+ const { targets } = installedProviderTargets(providers, projectRoot, iosTarget)
69
+ return new Map(
70
+ [...targets].map(([name, target]): [string, TurboInstalledSources] => {
71
+ const { root, files } = installedTargetSources(target)
72
+ return [
73
+ name,
74
+ {
75
+ root,
76
+ files: [...files]
77
+ .flatMap((file) => {
78
+ const relative = relativeInside(root, file)
79
+ return relative === null ? [] : [relative.split(path.sep).join('/')]
80
+ })
81
+ .sort(),
82
+ },
83
+ ]
84
+ }),
85
+ )
86
+ }
87
+
88
+ export function installedNativeLibraries(
89
+ providers: readonly Pick<TurboProvider, 'name' | 'podspecPath'>[],
90
+ projectRoot: string,
91
+ moduleRoot: string,
92
+ iosTarget?: string,
93
+ frameworkLinkOwner: 'workspace' | 'provider' = 'workspace',
94
+ ): InstalledNativeLibraries {
95
+ const result: InstalledNativeLibraries = { pods: new Map(), unavailable: new Map() }
96
+ if (providers.length === 0) return result
97
+ projectRoot = fs.realpathSync(projectRoot)
98
+ const { app, targets } = installedProviderTargets(providers, projectRoot, iosTarget)
37
99
  const podsRoot = app.cocoapods && path.dirname(app.cocoapods.manifestLock)
38
100
  const localPods = new Set(
39
101
  (app.cocoapods?.localPodspecs ?? []).map((file) =>
@@ -49,6 +111,16 @@ export function installedNativeLibraries(
49
111
  reactNativeRoot,
50
112
  path.join(projectRoot, 'node_modules/react-native'),
51
113
  ]
114
+ // nonmodular frameworks publish their headers through CocoaPods search
115
+ // roots. their verified implementations link once through the shared core.
116
+ const [firstShared, ...otherShared] = nonmodularFrameworkLibraries(
117
+ app.binaryFrameworks.flatMap(({ path: directory }) => (directory ? [directory] : [])),
118
+ moduleRoot,
119
+ )
120
+ const sharedLibrary =
121
+ firstShared === undefined
122
+ ? undefined
123
+ : combineNativeStaticLibraries([firstShared, ...otherShared], moduleRoot)
52
124
  for (const provider of providers) {
53
125
  const name = path.basename(provider.podspecPath, '.podspec')
54
126
  const specFile = app.cocoapods?.localPodspecs.find(
@@ -71,10 +143,8 @@ export function installedNativeLibraries(
71
143
  return value
72
144
  throw new Error(`${specFile}: invalid vendored native paths`)
73
145
  })
74
- const target = app.frameworks.find((item) => item.name === name)
75
- if (!target?.podRoot)
76
- throw new Error(`${name}: installed target has no PODS_TARGET_SRCROOT`)
77
- const root = fs.realpathSync(target.podRoot)
146
+ const target = targets.get(provider.name)!
147
+ const { root, files } = installedTargetSources(target)
78
148
  // a declared archive selects its WebAssembly slice by its original bytes;
79
149
  // one with no registered slice, or one CocoaPods selects through a
80
150
  // subspec or a pattern, has no build peach can link.
@@ -82,7 +152,7 @@ export function installedNativeLibraries(
82
152
  if (spec.subspecs || /[*?{]/.test(file)) return { file, recipe: null }
83
153
  const declared = path.resolve(root, file)
84
154
  const framework = declared.endsWith('.xcframework')
85
- ? simulatorStaticArchive(declared)
155
+ ? simulatorNativeLibrary(declared)
86
156
  : null
87
157
  if (declared.endsWith('.xcframework') && !framework) return { file, recipe: null }
88
158
  const native = framework?.file ?? declared
@@ -124,13 +194,6 @@ export function installedNativeLibraries(
124
194
  return framework && frameworkLinkOwner === 'workspace' ? [] : [library]
125
195
  })
126
196
  const [firstLibrary, ...otherLibraries] = ownedLibraries
127
- const files = new Set(
128
- [
129
- ...target.allSources,
130
- ...(target.objc?.headers ?? []),
131
- ...(target.objc?.publicHeaders ?? []),
132
- ].map((file) => fs.realpathSync(file)),
133
- )
134
197
  const publicHeaders = new Set(
135
198
  (target.objc?.publicHeaders ?? []).map((file) => fs.realpathSync(file)),
136
199
  )
@@ -188,11 +251,30 @@ export function installedNativeLibraries(
188
251
  return []
189
252
  }),
190
253
  })),
254
+ dependencyHeaderMaps: (target.objc?.headerMaps ?? []).map(({ flag, entries }) => ({
255
+ flag,
256
+ root: projectRoot,
257
+ entries: entries.flatMap(([name, file]): [string, string][] => {
258
+ if (reactNativeRoots.some((root) => relativeInside(root, file) !== null))
259
+ return []
260
+ const relative = relativeInside(projectRoot, file)
261
+ return relative === null ? [] : [[name, relative.split(path.sep).join('/')]]
262
+ }),
263
+ })),
191
264
  headerSearchPaths: (target.objc?.headerSearchPaths ?? []).flatMap((directory) => {
192
265
  if (!fs.existsSync(directory)) return []
193
266
  const relative = relativeInside(root, fs.realpathSync(directory))
194
267
  return relative === null ? [] : [relative.split(path.sep).join('/')]
195
268
  }),
269
+ dependencySearchPaths: [...new Set(target.objc?.headerSearchPaths ?? [])].flatMap(
270
+ (directory) => {
271
+ if (!fs.statSync(directory, { throwIfNoEntry: false })?.isDirectory()) return []
272
+ const canonical = fs.realpathSync(directory)
273
+ if (relativeInside(root, canonical) !== null) return []
274
+ const relative = relativeInside(projectRoot, canonical)
275
+ return relative === null ? [] : [{ root: projectRoot, directory: relative }]
276
+ },
277
+ ),
196
278
  publicHeaders: [...publicHeaders].flatMap((file) => {
197
279
  const relative = relativeInside(root, fs.realpathSync(file))
198
280
  return relative === null ? [] : [relative.split(path.sep).join('/')]
@@ -207,6 +289,7 @@ export function installedNativeLibraries(
207
289
  moduleRoot,
208
290
  ),
209
291
  }),
292
+ ...(sharedLibrary === undefined ? {} : { sharedLibrary }),
210
293
  files: [...files]
211
294
  .flatMap((file) => {
212
295
  const relative = relativeInside(root, file)