peachsim 0.1.2159 → 0.1.2173

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 (131) hide show
  1. package/README.md +7 -1
  2. package/cli/app-catalog.ts +22 -15
  3. package/cli/bridge-flow-runner.ts +8 -7
  4. package/cli/commands/cleanup.ts +4 -2
  5. package/cli/commands/control.ts +2 -1
  6. package/cli/commands/kotlin.ts +2 -2
  7. package/cli/commands/package.ts +22 -7
  8. package/cli/commands/shell-url.ts +4 -2
  9. package/cli/native-input.ts +1 -1
  10. package/cli/outbound-endpoints.ts +13 -2
  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 +2 -3
  14. package/dist-lib/auth/shared-session.cjs +2 -3
  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 +3653 -3310
  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 +6 -5
  35. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  36. package/dist-lib/expo-swift-bundle.cjs +4226 -8528
  37. package/dist-lib/expo-swift-metadata.cjs +5 -1
  38. package/dist-lib/expo-swift-metadata.mjs +5 -1
  39. package/dist-lib/home-paths.cjs +2 -3
  40. package/dist-lib/host/bridge-host.cjs +4568 -4255
  41. package/dist-lib/host/fetch-proxy-handler.cjs +35 -15
  42. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  43. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  44. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  45. package/dist-lib/host/websocket-proxy.cjs +1 -1
  46. package/dist-lib/index.cjs +195 -155
  47. package/dist-lib/jump-to-source-babel.cjs +1 -1
  48. package/dist-lib/jump-to-source-native.cjs +1 -1
  49. package/dist-lib/kotlin-host.cjs +12 -7
  50. package/dist-lib/menu.cjs +1 -1
  51. package/dist-lib/menu.mjs +1 -1
  52. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  53. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  54. package/dist-lib/metro-production-bundle.cjs +1 -1
  55. package/dist-lib/metro-production-bundle.mjs +1 -1
  56. package/dist-lib/metro.cjs +42 -16
  57. package/dist-lib/native-app-identity-project.cjs +10 -5
  58. package/dist-lib/native-app-identity-project.mjs +10 -5
  59. package/dist-lib/native-app-identity.cjs +9 -1
  60. package/dist-lib/native-app-identity.mjs +9 -1
  61. package/dist-lib/native-firebase-metadata.cjs +1 -1
  62. package/dist-lib/native-firebase-metadata.mjs +1 -1
  63. package/dist-lib/pdfium-raster.cjs +1 -1
  64. package/dist-lib/pdfium-raster.mjs +1 -1
  65. package/dist-lib/plist.cjs +1 -1
  66. package/dist-lib/plist.mjs +1 -1
  67. package/dist-lib/profiles.cjs +2 -3
  68. package/dist-lib/public-brand.cjs +1 -1
  69. package/dist-lib/public-origins-lib-esm.json +24 -24
  70. package/dist-lib/public-origins-lib.json +99 -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 +4 -2
  74. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  75. package/dist-lib/sdk.cjs +1 -1
  76. package/dist-lib/sdk.mjs +1 -1
  77. package/dist-lib/skills.cjs +5762 -5118
  78. package/dist-lib/swift-compile.cjs +22 -11
  79. package/dist-lib/swift-compile.mjs +22 -11
  80. package/dist-lib/swift-package.cjs +1 -1
  81. package/dist-lib/swift-package.mjs +1 -1
  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 +1 -1
  85. package/dist-lib/swift.cjs +1 -1
  86. package/dist-lib/vite-swift.cjs +27 -13
  87. package/dist-lib/vite.cjs +119 -85
  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/inspect-info.d.ts +0 -1
  91. package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +3 -1
  92. package/dist-types/packages/peach-engine/src/render-worker/shell-protocol.d.ts +9 -1
  93. package/dist-types/packages/peach-engine/src/render-worker/ui-frame-clock.d.ts +26 -0
  94. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +2 -2
  95. package/dist-types/packages/peach-engine/src/render-worker/worklet-sab.d.ts +1 -6
  96. package/kotlin/README.md +5 -0
  97. package/kotlin/sdk.tar.gz +0 -0
  98. package/package.json +2 -1
  99. package/runtime-companion.json +1 -1
  100. package/src/answeredNativePackages.ts +1 -5
  101. package/src/disk-cleanup.ts +44 -1
  102. package/src/expo-native-compiler-digest.ts +2 -0
  103. package/src/expo-native-workspace.ts +61 -16
  104. package/src/expo-swift-host.ts +64 -53
  105. package/src/expoSwiftContract.ts +6 -0
  106. package/src/home-activity.ts +124 -0
  107. package/src/home-paths.ts +1 -2
  108. package/src/installed-native-build-options.ts +27 -3
  109. package/src/kotlin-app.ts +156 -31
  110. package/src/kotlin-compose-bom.ts +64 -0
  111. package/src/kotlin-host.ts +12 -3
  112. package/src/kotlin-version-catalog.ts +77 -0
  113. package/src/native-app-identity-project.ts +3 -0
  114. package/src/native-app-identity.ts +15 -0
  115. package/src/native-git.ts +12 -0
  116. package/src/native-prebuilt.ts +11 -2
  117. package/src/nitro-compile.ts +12 -4
  118. package/src/one-native-app-catalog.ts +59 -0
  119. package/src/one-sdk-bundle.ts +3 -3
  120. package/src/one-sdk-preparation.ts +53 -8
  121. package/src/react-native-core-digest.ts +24 -0
  122. package/src/react-native-core.ts +239 -0
  123. package/src/reap-browser.ts +3 -1
  124. package/src/swift-compile.ts +6 -5
  125. package/src/swift-packages.ts +2 -0
  126. package/src/swift-wasm-prune.ts +20 -2
  127. package/src/turbo-bundle.ts +15 -2
  128. package/src/turbo-compile.ts +32 -6
  129. package/src/turbo-source.ts +29 -9
  130. package/src/vite-plugin-one.ts +8 -5
  131. package/src/one-native-app-accent.ts +0 -32
package/kotlin/README.md CHANGED
@@ -66,6 +66,11 @@ hashes. Archive installs verify that exact flat inventory and atomically publish
66
66
  under a content-addressed cache. Matching artifact keys reuse compiled output;
67
67
  SDK keys bind all producer and SDK source bytes. Client artifact keys bind the
68
68
  SDK archive, selected profile, toolchain/language pins, guest sources and glue.
69
+ The producer also caches each JVM jar and Wasm profile by its selected source
70
+ bytes, producer, SDK contract and toolchain. Profiles include compiler-plugin
71
+ inputs in that key. A source edit recompiles only the jars or profiles that use
72
+ it; reused binaries are checked against their cached size and SHA256 before
73
+ packing the complete SDK archive.
69
74
 
70
75
  The dev server compiles every `.kt` source of the app, One's glue for each and
71
76
  a generated entry into one Kotlin/Wasm module, held to the Kotlin language
package/kotlin/sdk.tar.gz CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "peachsim",
3
- "version": "0.1.2159",
3
+ "version": "0.1.2173",
4
4
  "description": "Vite and Metro plugins, testing drivers, and SDK exports for peach.",
5
5
  "author": "Tamagui LLC",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -362,6 +362,7 @@
362
362
  "oxc-parser": "^0.112.0",
363
363
  "playwright-core": "1.64.1",
364
364
  "plist": "3.1.1",
365
+ "smol-toml": "1.9.0",
365
366
  "stream-json": "3.8.0",
366
367
  "sucrase": "3.35.1",
367
368
  "svgpath": "2.6.0",
@@ -1 +1 @@
1
- {"abi":1,"sha256":"9b370a218cb12559cba2bb30e1e33d168ccd0f310e473c5428133b85938be20a","file":"node/cli-9b370a218cb12559cba2bb30e1e33d168ccd0f310e473c5428133b85938be20a.cjs"}
1
+ {"abi":1,"sha256":"c5311b24d34f15e1e93e1e7fc426600404705562e03ce05c7c359e341afc75cd","file":"node/cli-c5311b24d34f15e1e93e1e7fc426600404705562e03ce05c7c359e341afc75cd.cjs"}
@@ -31,13 +31,9 @@ export function readPeachRuntimeJson(relative: string): unknown {
31
31
  }
32
32
  }
33
33
 
34
- let answered: ReadonlySet<string> | undefined
35
-
36
34
  export function peachAnsweredNativePackages(): ReadonlySet<string> {
37
- if (answered) return answered
38
35
  const names = readPeachRuntimeJson(ANSWERED_NATIVE_PACKAGES_PATH)
39
36
  if (!Array.isArray(names) || !names.every((name) => typeof name === 'string'))
40
37
  throw new Error(`${ANSWERED_NATIVE_PACKAGES_PATH} must list package names`)
41
- answered = new Set(names)
42
- return answered
38
+ return new Set(names)
43
39
  }
@@ -1,10 +1,15 @@
1
1
  import fs from 'node:fs'
2
2
  import path from 'node:path'
3
3
  import { isDisposableBrowserCacheDir } from './browser-cache'
4
+ import {
5
+ expirePortHomeCache,
6
+ PORT_HOME_DISPOSABLE_DIRS,
7
+ portHomeCleanupState,
8
+ } from './home-activity'
4
9
  import { ensureRnxHome, readLiveRuntimeVersions, rnxHomeDir } from './home-paths'
5
10
  import { rnxRuntime } from './runtime-delivery'
6
11
 
7
- const AUTOMATIC_CLEANUP_GENERATION = 1
12
+ const AUTOMATIC_CLEANUP_GENERATION = 2
8
13
  const AUTOMATIC_CLEANUP_INTERVAL_MS = 24 * 60 * 60 * 1000
9
14
  const AUTOMATIC_CLEANUP_COMPLETE_FILE = `automatic-cleanup-v${AUTOMATIC_CLEANUP_GENERATION}.json`
10
15
  const AUTOMATIC_CLEANUP_LOCK_FILE = `automatic-cleanup-v${AUTOMATIC_CLEANUP_GENERATION}.lock`
@@ -22,6 +27,7 @@ const AUTOMATIC_CLEANUP_DEFERRED_FILE = `automatic-cleanup-v${AUTOMATIC_CLEANUP_
22
27
  const AUTOMATIC_CLEANUP_DEFER_RETRY_MS = 30 * 60 * 1000
23
28
 
24
29
  export type SootsimCleanupKind =
30
+ | 'port-home-cache'
25
31
  | 'browser-cache'
26
32
  | 'camera-fixture'
27
33
  | 'recording'
@@ -326,6 +332,7 @@ export function planSootsimCleanup(
326
332
  ...collectElectronCaches(home),
327
333
  ...collectRecordingEntries(home, aggressive),
328
334
  ...collectCameraFixtureEntries(home, aggressive),
335
+ ...collectPortHomeCaches(home),
329
336
  ].sort((left, right) => right.bytes - left.bytes || left.path.localeCompare(right.path))
330
337
  return {
331
338
  home,
@@ -343,6 +350,34 @@ export function planSootsimCleanup(
343
350
  }
344
351
  }
345
352
 
353
+ function collectPortHomeCaches(home: string): SootsimCleanupEntry[] {
354
+ const root = path.join(home, 'port-homes')
355
+ if (!fs.existsSync(root)) return []
356
+ return fs.readdirSync(root, { withFileTypes: true }).flatMap((entry) => {
357
+ if (!entry.isDirectory() || !/^[0-9]+$/.test(entry.name)) return []
358
+ const portHome = path.join(root, entry.name)
359
+ const state = portHomeCleanupState(portHome)
360
+ return PORT_HOME_DISPOSABLE_DIRS.flatMap((name): SootsimCleanupEntry[] => {
361
+ const target = path.join(portHome, name)
362
+ const stat = fs.lstatSync(target, { throwIfNoEntry: false })
363
+ if (!stat?.isDirectory() || stat.isSymbolicLink()) return []
364
+ return [
365
+ {
366
+ path: target,
367
+ bytes: allocatedBytes(target),
368
+ kind: 'port-home-cache',
369
+ state,
370
+ selected: state === 'safe',
371
+ detail:
372
+ state === 'safe'
373
+ ? 'inactive development home older than seven days'
374
+ : 'active, recent, or packaged app home',
375
+ },
376
+ ]
377
+ })
378
+ })
379
+ }
380
+
346
381
  function assertInsideHome(home: string, target: string): void {
347
382
  const relative = path.relative(home, target)
348
383
  if (!relative || relative.startsWith('..') || path.isAbsolute(relative)) {
@@ -363,6 +398,14 @@ export function applySootsimCleanup(
363
398
  for (const entry of plan.entries) {
364
399
  if (!entry.selected) continue
365
400
  if (entry.kind === 'runtime-archive' || entry.kind === 'runtime-version') continue
401
+ if (entry.kind === 'port-home-cache') {
402
+ if (!expirePortHomeCache(path.dirname(entry.path), entry.path)) {
403
+ entry.state = 'in-use'
404
+ entry.selected = false
405
+ entry.detail = 'home activated while cleanup was starting'
406
+ }
407
+ continue
408
+ }
366
409
  if (entry.kind === 'browser-cache') {
367
410
  const relative = path.relative(plan.home, entry.path)
368
411
  const parts = relative.split(path.sep)
@@ -1,4 +1,5 @@
1
1
  import { createHash } from 'node:crypto'
2
+ import { reactNativeCoreDigest } from './react-native-core-digest'
2
3
  import { swiftCompilerSourceDigest } from './swift-compiler-digest'
3
4
  import { sourceClosureDigest, sourceClosureFiles } from './swift-standin-digest'
4
5
 
@@ -15,4 +16,5 @@ export const expoNativeCompilerDigest = (srcDir: string) =>
15
16
  .update(sourceClosureDigest(srcDir, ENTRYPOINTS))
16
17
  .update('\0')
17
18
  .update(swiftCompilerSourceDigest(srcDir))
19
+ .update(reactNativeCoreDigest(srcDir))
18
20
  .digest('hex')
@@ -10,6 +10,7 @@ import { teamMachineInstalled } from './admitted-mac-build'
10
10
  import { workspaceExclusion } from './expo-workspace-exclusion'
11
11
  import { cacheDir } from './home-paths'
12
12
  import { failedOutputLine } from './native-failure-output'
13
+ import { requireNativeGit } from './native-git'
13
14
  import { prepareOneSDKSources } from './one-sdk-preparation'
14
15
  import { portableExpoWorkspace } from './portable-expo-workspace'
15
16
  import {
@@ -347,11 +348,20 @@ async function hashWorkspaceInputs(
347
348
  }),
348
349
  }
349
350
  : {}
351
+ const pinnedNode =
352
+ typeof manifest.engines?.node === 'string' &&
353
+ /^\d+(\.\d+){0,2}$/.test(manifest.engines.node)
354
+ ? `node@${manifest.engines.node}`
355
+ : null
350
356
  const toolchain = JSON.stringify({
351
357
  preparation: 7,
352
358
  appRelative,
353
359
  ...mac,
354
- node: process.version,
360
+ node: execFileSync(
361
+ pinnedNode ? 'mise' : 'node',
362
+ pinnedNode ? ['exec', pinnedNode, '--', 'node', '--version'] : ['--version'],
363
+ { cwd: root, encoding: 'utf8' },
364
+ ).trim(),
355
365
  packageManager: workspacePackageManager(root, manifest.packageManager, excluded),
356
366
  podsEnvironment,
357
367
  })
@@ -426,18 +436,58 @@ async function pruneExpoNativeWorkspaces(parent: string, keep: string) {
426
436
  }
427
437
 
428
438
  // an edit that leaves the native inputs alone lands in the prepared copy by
429
- // stat, so a warm open reads no file it did not have to.
439
+ // stat, so a warm open reads no file it did not have to. installed
440
+ // dependencies are not hashed, so a copy that has yet to pass pod install also
441
+ // takes the files the app's tree gained since the copy: a native dependency's
442
+ // own install step (react-native-skia's install-skia) adds libraries pod install
443
+ // checks for. a newer source file replaces its copy; one the prepare wrote in
444
+ // the copy stays.
430
445
  function syncChangedFiles(
431
446
  root: string,
432
447
  work: string,
433
448
  appRelative: string,
434
449
  excluded: (relative: string) => boolean,
450
+ installed: boolean,
435
451
  ) {
452
+ const copyIfNewer = (file: string, relative: string, newerOnly: boolean) => {
453
+ const source = fs.statSync(file)
454
+ const target = path.join(work, relative)
455
+ const existing = fs.statSync(target, { throwIfNoEntry: false })
456
+ // timestamp-preserving copies use Dates, which truncate fractional
457
+ // milliseconds; compare at that same precision to avoid copying again.
458
+ if (
459
+ existing &&
460
+ (newerOnly
461
+ ? existing.mtime.getTime() >= source.mtime.getTime()
462
+ : existing.size === source.size &&
463
+ existing.mtime.getTime() === source.mtime.getTime())
464
+ )
465
+ return
466
+ fs.mkdirSync(path.dirname(target), { recursive: true })
467
+ fs.copyFileSync(file, target)
468
+ fs.utimesSync(target, source.atime, source.mtime)
469
+ }
470
+ const walkInstalled = (directory: string) => {
471
+ for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
472
+ const file = path.join(directory, entry.name)
473
+ if (entry.isDirectory()) walkInstalled(file)
474
+ else if (entry.isFile()) copyIfNewer(file, path.relative(root, file), true)
475
+ }
476
+ }
436
477
  const sourceIos = fs.existsSync(path.join(root, appRelative, 'ios', 'Podfile'))
437
478
  const walk = (directory: string) => {
438
479
  for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
439
480
  const file = path.join(directory, entry.name)
440
481
  const relative = path.relative(root, file)
482
+ if (
483
+ installed &&
484
+ entry.name === 'node_modules' &&
485
+ entry.isDirectory() &&
486
+ fs.existsSync(path.join(work, relative))
487
+ ) {
488
+ walkInstalled(file)
489
+ continue
490
+ }
441
491
  // the app's ios project is prebuild output, not a source
442
492
  if (
443
493
  excluded(relative) ||
@@ -451,19 +501,7 @@ function syncChangedFiles(
451
501
  // several of them (the project, the lock), so copying the source's
452
502
  // pre-install copy back would undo the install
453
503
  if (NATIVE_CONFIG_FILE.test(relative.split(path.sep).join('/'))) continue
454
- const source = fs.statSync(file)
455
- const target = path.join(work, relative)
456
- const existing = fs.statSync(target, { throwIfNoEntry: false })
457
- // timestamp-preserving copies use Dates, which truncate fractional
458
- // milliseconds; compare at that same precision to avoid copying again.
459
- if (
460
- existing?.size === source.size &&
461
- existing.mtime.getTime() === source.mtime.getTime()
462
- )
463
- continue
464
- fs.mkdirSync(path.dirname(target), { recursive: true })
465
- fs.copyFileSync(file, target)
466
- fs.utimesSync(target, source.atime, source.mtime)
504
+ copyIfNewer(file, relative, false)
467
505
  }
468
506
  }
469
507
  }
@@ -684,6 +722,7 @@ export async function prepareInstalledExpoWorkspace(app: string, work: string) {
684
722
  }
685
723
 
686
724
  function initializeWorkspaceGit(work: string) {
725
+ requireNativeGit()
687
726
  for (const args of [
688
727
  ['init', '--quiet'],
689
728
  [
@@ -744,7 +783,13 @@ async function prepareWorkspace(
744
783
  const preparedApp = path.join(work, appRelative)
745
784
  const projectReady = fs.existsSync(marker) || fs.existsSync(projectMarker)
746
785
  if (projectReady) {
747
- syncChangedFiles(root, work, appRelative, excluded)
786
+ syncChangedFiles(
787
+ root,
788
+ work,
789
+ appRelative,
790
+ excluded,
791
+ stage === 'workspace' && !fs.existsSync(marker),
792
+ )
748
793
  report(`reusing prepared workspace ${work}`)
749
794
  }
750
795
  if (!projectReady) {
@@ -43,6 +43,7 @@ import {
43
43
  BRIDGE_MODULE_FILE_PREFIX,
44
44
  collectBridgeModuleSources,
45
45
  } from './react-native-bridge-modules'
46
+ import { prebuiltReactNativeCore } from './react-native-core'
46
47
  import { swiftBinaryModules } from './swift-binary-modules'
47
48
  import {
48
49
  swiftAvailableModules,
@@ -55,7 +56,11 @@ import {
55
56
  syncSwiftTree,
56
57
  withoutSwiftDeclarations,
57
58
  } from './swift-compile'
58
- import { ensureSwiftToolchain, resolveSwiftModule } from './swift-distribution'
59
+ import {
60
+ ensureSwiftToolchain,
61
+ resolveSwiftModule,
62
+ swiftModuleToolchain,
63
+ } from './swift-distribution'
59
64
  import {
60
65
  artifactFor,
61
66
  icuUrl,
@@ -85,18 +90,14 @@ import { swiftRootLocksDir } from './swift-root-lock'
85
90
  import { standinGenerationInputs, swiftStandins } from './swift-standins'
86
91
  import { MAX_SWIFT_COMPILE_FILES, MAX_SWIFT_COMPILE_SOURCE_BYTES } from './swift-submit'
87
92
  import { swiftCacheDir } from './swift-toolchain'
88
- import { collectTurboCompileInput } from './turbo-compile'
89
- import {
90
- collectTurboSources,
91
- prepareTurboSourceDependencies,
92
- registersReactModule,
93
- } from './turbo-source'
93
+ import { registersReactModule } from './turbo-source'
94
94
  import type { PeachConfig } from './config'
95
95
  import type {
96
96
  ExpoSwiftSourceUnit,
97
97
  ExpoSwiftCompilationResult,
98
98
  ExpoSwiftDiscoveryResult,
99
99
  ExpoSwiftPreparationOptions,
100
+ ExpoSwiftSourceOptions,
100
101
  } from './expoSwiftContract'
101
102
  import type { NativeAppIdentity } from './native-app-identity'
102
103
  import type { SwiftPackageBinary } from './swift-packages'
@@ -318,6 +319,7 @@ function installSwiftInputTrace(): void {
318
319
  const prefixes = [
319
320
  path.join(cacheDir(), 'swift-builds'),
320
321
  path.join(swiftCacheDir(), 'swift-builds'),
322
+ path.join(swiftCacheDir(), 'swift-sdk-views'),
321
323
  swiftRootLocksDir(),
322
324
  path.join(cacheDir(), 'swift-tmp'),
323
325
  ].filter((prefix, index, all) => all.indexOf(prefix) === index)
@@ -441,12 +443,13 @@ async function discoveryKey(
441
443
  installedWorkspace: string | undefined,
442
444
  prepareNative: boolean,
443
445
  iosTarget: string | undefined,
446
+ moduleRoot?: string,
444
447
  ): Promise<string> {
445
448
  const [config, expoConfig] = await Promise.all([
446
449
  loadRNXAppConfig(resolveAppProject(root)),
447
450
  readExpoConfigAsync(root),
448
451
  ])
449
- return `${fs.realpathSync(root)}\0${installedWorkspace ?? ''}\0${iosTarget ?? ''}\0${prepareNative ? '1' : '0'}\0${JSON.stringify(config)}\0${JSON.stringify(expoConfig)}`
452
+ return `${fs.realpathSync(root)}\0${installedWorkspace ?? ''}\0${iosTarget ?? ''}\0${moduleRoot ?? ''}\0${prepareNative ? '1' : '0'}\0${JSON.stringify(config)}\0${JSON.stringify(expoConfig)}`
450
453
  }
451
454
 
452
455
  function cloneNativeTarget(target: SwiftNativeTarget): SwiftNativeTarget {
@@ -1023,7 +1026,7 @@ export async function collectExpoSwiftSources(
1023
1026
  installedWorkspace?: string,
1024
1027
  prepareNative = false,
1025
1028
  iosTarget?: string,
1026
- metadataOnly = false,
1029
+ options: ExpoSwiftSourceOptions = {},
1027
1030
  ): Promise<ExpoSwiftSourceUnit[] | null> {
1028
1031
  if (traceStore.getStore())
1029
1032
  return collectExpoSwiftSourcesUncached(
@@ -1032,11 +1035,20 @@ export async function collectExpoSwiftSources(
1032
1035
  installedWorkspace,
1033
1036
  prepareNative,
1034
1037
  iosTarget,
1035
- metadataOnly,
1038
+ options,
1036
1039
  )
1037
1040
  signal?.throwIfAborted()
1038
1041
  installSwiftInputTrace()
1039
- const key = `${await discoveryKey(appRoot, installedWorkspace, prepareNative, iosTarget)}\0${metadataOnly}`
1042
+ const key =
1043
+ (await discoveryKey(
1044
+ appRoot,
1045
+ installedWorkspace,
1046
+ prepareNative,
1047
+ iosTarget,
1048
+ options.moduleRoot,
1049
+ )) +
1050
+ '\0' +
1051
+ (options.metadataOnly ?? false)
1040
1052
  const cached = discoveryCache.get(key)
1041
1053
  if (cached && (await witnessMatches(cached.witness))) {
1042
1054
  signal?.throwIfAborted()
@@ -1050,7 +1062,7 @@ export async function collectExpoSwiftSources(
1050
1062
  installedWorkspace,
1051
1063
  prepareNative,
1052
1064
  iosTarget,
1053
- metadataOnly,
1065
+ options,
1054
1066
  ),
1055
1067
  )
1056
1068
  if (witness.marks.size > 0 && (await witnessMatches(witness)))
@@ -1064,7 +1076,7 @@ async function collectExpoSwiftSourcesUncached(
1064
1076
  installedWorkspace?: string,
1065
1077
  prepareNative = false,
1066
1078
  iosTarget?: string,
1067
- metadataOnly = false,
1079
+ { moduleRoot: moduleRootOverride, metadataOnly = false }: ExpoSwiftSourceOptions = {},
1068
1080
  ): Promise<ExpoSwiftSourceUnit[] | null> {
1069
1081
  const started = performance.now()
1070
1082
  const report = (message: string) =>
@@ -1179,7 +1191,9 @@ async function collectExpoSwiftSourcesUncached(
1179
1191
  let nativeAppIdentity: NativeAppIdentity | undefined
1180
1192
  if (installedWorkspace) {
1181
1193
  report(`reading installed workspace ${installedWorkspace}`)
1182
- const module = await resolveSwiftModule({ signal })
1194
+ const module = moduleRootOverride
1195
+ ? { root: moduleRootOverride, ...swiftModuleToolchain(moduleRootOverride) }
1196
+ : await resolveSwiftModule({ signal })
1183
1197
  moduleRoot = module.root
1184
1198
  provided = new Set(swiftPeachModules(module.root))
1185
1199
  await prepareXcodeSwiftPackages(installedWorkspace, iosTarget, undefined, signal)
@@ -1324,7 +1338,9 @@ async function collectExpoSwiftSourcesUncached(
1324
1338
  if (!namespaces.some((name) => typeof name === 'string' && imports.has(name)))
1325
1339
  continue
1326
1340
  if (!moduleRoot) {
1327
- const module = await resolveSwiftModule({ signal })
1341
+ const module = moduleRootOverride
1342
+ ? { root: moduleRootOverride, ...swiftModuleToolchain(moduleRootOverride) }
1343
+ : await resolveSwiftModule({ signal })
1328
1344
  moduleRoot = module.root
1329
1345
  provided = new Set(swiftPeachModules(module.root))
1330
1346
  }
@@ -1370,6 +1386,7 @@ async function collectExpoSwiftSourcesUncached(
1370
1386
  prepared.workspace,
1371
1387
  false,
1372
1388
  iosTarget,
1389
+ { moduleRoot: moduleRootOverride, metadataOnly },
1373
1390
  )
1374
1391
  }
1375
1392
  const declarations: {
@@ -1699,7 +1716,7 @@ async function collectExpoSwiftSourcesUncached(
1699
1716
  signal,
1700
1717
  })
1701
1718
  const cached = readExpoDiscovery(discovery.key)
1702
- if (cached !== undefined) return cached
1719
+ if (!moduleRootOverride && cached !== undefined) return cached
1703
1720
  const prepared = await prepareExpoNativeWorkspace(appRoot, signal, iosTarget)
1704
1721
  const discovered = await collectExpoSwiftSources(
1705
1722
  prepared.app,
@@ -1707,7 +1724,9 @@ async function collectExpoSwiftSourcesUncached(
1707
1724
  prepared.workspace,
1708
1725
  false,
1709
1726
  iosTarget,
1727
+ { moduleRoot: moduleRootOverride, metadataOnly },
1710
1728
  )
1729
+ if (moduleRootOverride) return discovered
1711
1730
  const stored = writeExpoDiscovery({
1712
1731
  key: discovery.key,
1713
1732
  units: discovered,
@@ -2134,7 +2153,7 @@ export async function compileExpoSwiftModules(
2134
2153
  installSwiftInputTrace()
2135
2154
  let key: string
2136
2155
  try {
2137
- key = `${await discoveryKey(root, options.installedWorkspace, true, options.iosTarget)}\0${options.only?.join(',') ?? ''}`
2156
+ key = `${await discoveryKey(root, options.installedWorkspace, true, options.iosTarget, options.moduleRoot)}\0${options.only?.join(',') ?? ''}`
2138
2157
  } catch {
2139
2158
  return compileExpoSwiftModulesTraced(root, base, publishArtifact, options)
2140
2159
  }
@@ -2177,7 +2196,7 @@ async function compileExpoSwiftModulesTraced(
2177
2196
  // a package-scoped compile is what per-package entries hold, so it never
2178
2197
  // reads the whole-app entry or a CocoaPods workspace
2179
2198
  const prebuilt =
2180
- options.installedWorkspace || options.only
2199
+ options.installedWorkspace || options.only || options.moduleRoot
2181
2200
  ? null
2182
2201
  : await prebuiltExpoNative(root, options.iosTarget)
2183
2202
  if (prebuilt) {
@@ -2191,6 +2210,7 @@ async function compileExpoSwiftModulesTraced(
2191
2210
  options.installedWorkspace,
2192
2211
  nativeWorkspaceAvailable() && !options.only,
2193
2212
  options.iosTarget,
2213
+ { moduleRoot: options.moduleRoot },
2194
2214
  )
2195
2215
  signal.throwIfAborted()
2196
2216
  // reading the app's xcode project resolves remote swift packages with the
@@ -2233,7 +2253,9 @@ async function compileExpoSwiftModulesTraced(
2233
2253
  const workspace =
2234
2254
  options.installedWorkspace ??
2235
2255
  (await prepareExpoNativeWorkspace(root, signal, options.iosTarget)).workspace
2236
- const module = await resolveSwiftModule({ signal })
2256
+ const module = options.moduleRoot
2257
+ ? { root: options.moduleRoot, ...swiftModuleToolchain(options.moduleRoot) }
2258
+ : await resolveSwiftModule({ signal })
2237
2259
  await prepareXcodeSwiftPackages(workspace, options.iosTarget, undefined, signal)
2238
2260
  await withXcodeProject(
2239
2261
  workspace,
@@ -2304,7 +2326,9 @@ async function compileExpoSwiftModulesTraced(
2304
2326
  }
2305
2327
  // every candidate links into one app first; only a failed link compiles each
2306
2328
  // namespace alone to isolate the failures, so a framework change costs one build.
2307
- const module = await resolveSwiftModule({ signal })
2329
+ const module = options.moduleRoot
2330
+ ? { root: options.moduleRoot, ...swiftModuleToolchain(options.moduleRoot) }
2331
+ : await resolveSwiftModule({ signal })
2308
2332
  signal.throwIfAborted()
2309
2333
  const reactProvider = units.some((unit) => unit.reactNativeProvider)
2310
2334
  ? await (async () => {
@@ -2316,27 +2340,13 @@ async function compileExpoSwiftModulesTraced(
2316
2340
  'react-native/package.json',
2317
2341
  ),
2318
2342
  )
2319
- await prepareTurboSourceDependencies(reactNativeRoot)
2320
- fs.mkdirSync(swiftCacheDir(), { recursive: true })
2321
- const codegenDir = fs.mkdtempSync(
2322
- path.join(swiftCacheDir(), 'expo-react-codegen-'),
2323
- )
2324
- const collection = await collectTurboSources({
2325
- appRoot: projectRoot,
2326
- projectRoot,
2327
- reactNativeRoot,
2328
- providers: [],
2329
- codegenDir,
2330
- reactNativeProvider: true,
2331
- })
2343
+ const provider = prebuiltReactNativeCore(reactNativeRoot, module.root, 'expo')
2332
2344
  const headers = new Map<string, { file: string; relative: string }[]>()
2333
- const reactRoot = fs.realpathSync(reactNativeRoot) + path.sep
2334
- for (const { file, source } of collection.sources) {
2335
- if (!/\.(?:h|hh|hpp|hxx)$/.test(file) || !source.startsWith(reactRoot))
2336
- continue
2337
- const body = collection.files[file]!
2345
+ for (const [file, body] of Object.entries(provider.files)) {
2346
+ const relative = file.split('/upstream/react-native/')[1]
2347
+ if (!relative || !/\.(?:h|hh|hpp|hxx)$/.test(file)) continue
2338
2348
  const matches = headers.get(body) ?? []
2339
- matches.push({ file, relative: source.slice(reactRoot.length) })
2349
+ matches.push({ file, relative })
2340
2350
  headers.set(body, matches)
2341
2351
  }
2342
2352
  for (const unit of units)
@@ -2345,14 +2355,10 @@ async function compileExpoSwiftModulesTraced(
2345
2355
  .get(source)
2346
2356
  ?.find(({ relative }) => file.endsWith(`/${relative}`))
2347
2357
  if (!original) continue
2348
- collection.headerAliases ??= {}
2349
- collection.headerAliases[file] = original.file
2358
+ provider.headerAliases ??= {}
2359
+ provider.headerAliases[file] = original.file
2350
2360
  }
2351
- const floor = inheritExecutableFloor(
2352
- units.flatMap((unit) => unit.nativeTargets ?? []),
2353
- )?.find((target) => target.name === 'PeachExpoApp')?.deploymentTarget
2354
- if (!floor) throw new Error('Expo React provider has no iOS deployment target')
2355
- return collectTurboCompileInput(collection, null, floor)
2361
+ return provider
2356
2362
  })()
2357
2363
  : undefined
2358
2364
  const reactProviderStamp = reactProvider
@@ -2423,8 +2429,10 @@ async function compileExpoSwiftModulesTraced(
2423
2429
  const names = swiftManifestTargets(provider.files['Package.swift']!)
2424
2430
  .filter((target) => !target.executable)
2425
2431
  .map((target) => JSON.stringify(target.name))
2426
- const floor = swiftManifestTargets(provider.files['Package.swift']!)[0]!
2427
- .iosDeploymentTarget
2432
+ const floor = inheritExecutableFloor(
2433
+ linked.flatMap((unit) => unit.nativeTargets ?? []),
2434
+ )?.find((target) => target.name === 'PeachExpoApp')?.deploymentTarget
2435
+ if (!floor) throw new Error('Expo React provider has no iOS deployment target')
2428
2436
  files['Package.swift'] = files['Package.swift']!.replace(
2429
2437
  'Package(name: "PeachExpo", targets:',
2430
2438
  `Package(name: "PeachExpo", platforms: [.iOS(${JSON.stringify(floor)})], targets:`,
@@ -2448,7 +2456,9 @@ async function compileExpoSwiftModulesTraced(
2448
2456
  ]),
2449
2457
  ),
2450
2458
  )
2451
- const linkedLibraries = new Map<string, string>()
2459
+ const linkedLibraries = new Map<string, string>(
2460
+ Object.entries(provider?.libraries ?? {}),
2461
+ )
2452
2462
  let linkedSharedLibrary = false
2453
2463
  for (const unit of linked)
2454
2464
  for (const [name, library] of Object.entries(libraries.get(unit) ?? {})) {
@@ -2463,9 +2473,10 @@ async function compileExpoSwiftModulesTraced(
2463
2473
  projectFor(packagePath).oneModule = false
2464
2474
  projectFor(packagePath).optimize = true
2465
2475
  projectFor(packagePath).staticClangTargets = provider?.staticClangTargets
2466
- projectFor(packagePath).binaryModules = Object.fromEntries(
2467
- linked.flatMap((unit) => Object.entries(binaryModules.get(unit) ?? {})),
2468
- )
2476
+ projectFor(packagePath).binaryModules = Object.fromEntries([
2477
+ ...Object.entries(provider?.binaryModules ?? {}),
2478
+ ...linked.flatMap((unit) => Object.entries(binaryModules.get(unit) ?? {})),
2479
+ ])
2469
2480
  projectFor(packagePath).libraries =
2470
2481
  linkedLibraries.size > 0 ? Object.fromEntries(linkedLibraries) : undefined
2471
2482
  projectFor(packagePath).nativeTargets = inheritExecutableFloor([
@@ -2933,7 +2944,7 @@ export async function handleExpoSwiftRequest(
2933
2944
  undefined,
2934
2945
  false,
2935
2946
  iosTarget,
2936
- true,
2947
+ { metadataOnly: true },
2937
2948
  )
2938
2949
  const metadata: ExpoSwiftDiscoveryResult | null = units && {
2939
2950
  namespaces: units.map((unit) => unit.moduleId),
@@ -16,10 +16,16 @@ export interface ExpoSwiftPreparationOptions {
16
16
  signal?: AbortSignal
17
17
  installedWorkspace?: string
18
18
  iosTarget?: string
19
+ moduleRoot?: string
19
20
  // compile only these Swift modules and the modules they import
20
21
  only?: readonly string[]
21
22
  }
22
23
 
24
+ export interface ExpoSwiftSourceOptions {
25
+ moduleRoot?: string
26
+ metadataOnly?: boolean
27
+ }
28
+
23
29
  export interface ExpoSwiftSourceUnit {
24
30
  nativeAppIdentity?: NativeAppIdentity
25
31
  namespace: string