peachsim 0.1.2792 → 0.1.2794

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 (137) hide show
  1. package/dist-lib/agent-daemon-client.cjs +1 -1
  2. package/dist-lib/agent-events.cjs +1 -1
  3. package/dist-lib/attached-projects.cjs +1 -1
  4. package/dist-lib/auth/shared-session.cjs +1 -1
  5. package/dist-lib/backend-origin.cjs +1 -1
  6. package/dist-lib/beta.cjs +1 -1
  7. package/dist-lib/beta.mjs +2 -2
  8. package/dist-lib/bridge-constants.cjs +1 -1
  9. package/dist-lib/bridge-contract-input.cjs +1 -1
  10. package/dist-lib/bridge-contract-input.mjs +5 -5
  11. package/dist-lib/bridge-contract.cjs +1 -1
  12. package/dist-lib/bridge-contract.mjs +3 -3
  13. package/dist-lib/bundle-channel.cjs +1162 -997
  14. package/dist-lib/capture-contract.cjs +1 -1
  15. package/dist-lib/capture-contract.mjs +3 -3
  16. package/dist-lib/cloud-contract.cjs +1 -1
  17. package/dist-lib/cloud-contract.mjs +3 -3
  18. package/dist-lib/cloud-test-args.cjs +1 -1
  19. package/dist-lib/cloud-test-args.mjs +2 -2
  20. package/dist-lib/cloud.cjs +1 -1
  21. package/dist-lib/cloud.mjs +7 -7
  22. package/dist-lib/config.cjs +1 -1
  23. package/dist-lib/config.mjs +5 -5
  24. package/dist-lib/detox/index.cjs +1 -1
  25. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  26. package/dist-lib/esm-chunks/{acorn-WRJUSJKZ.mjs → acorn-A7OMJDVK.mjs} +3 -3
  27. package/dist-lib/esm-chunks/{chunk-KM6MA4GX.mjs → chunk-2TCGEMEV.mjs} +5 -5
  28. package/dist-lib/esm-chunks/{chunk-LKQFWHTY.mjs → chunk-35HEHEYA.mjs} +1 -1
  29. package/dist-lib/esm-chunks/{chunk-T2AWHCFQ.mjs → chunk-5RQ3U7WK.mjs} +1 -1
  30. package/dist-lib/esm-chunks/{chunk-HLTCPSRU.mjs → chunk-7QNWHCMJ.mjs} +1121 -1060
  31. package/dist-lib/esm-chunks/{chunk-MPN7ASMV.mjs → chunk-ANIC22U3.mjs} +1 -1
  32. package/dist-lib/esm-chunks/{chunk-2RLCLA6D.mjs → chunk-AW4Z3K2U.mjs} +1 -1
  33. package/dist-lib/esm-chunks/{chunk-UIMK6KUZ.mjs → chunk-B3E5ZI2D.mjs} +1 -1
  34. package/dist-lib/esm-chunks/{chunk-GSH5UN7J.mjs → chunk-CIFEHSEA.mjs} +2 -2
  35. package/dist-lib/esm-chunks/{chunk-DTUV3X2Q.mjs → chunk-CIR4VZ22.mjs} +1 -1
  36. package/dist-lib/esm-chunks/{chunk-JGMADAGT.mjs → chunk-DLEQ5NZ5.mjs} +4 -4
  37. package/dist-lib/esm-chunks/{chunk-KZF5BL3C.mjs → chunk-E6KA576K.mjs} +1 -1
  38. package/dist-lib/esm-chunks/{chunk-ETD4V3AD.mjs → chunk-GDITZ3K2.mjs} +1 -1
  39. package/dist-lib/esm-chunks/{chunk-6WTE57J5.mjs → chunk-GHGDWJY3.mjs} +6 -6
  40. package/dist-lib/esm-chunks/{chunk-47WU4TMV.mjs → chunk-K7RLWF5X.mjs} +1 -1
  41. package/dist-lib/esm-chunks/{chunk-6M75JXV2.mjs → chunk-KVFRYFZI.mjs} +1 -1
  42. package/dist-lib/esm-chunks/{chunk-YIQKUSLV.mjs → chunk-NKJ67PFZ.mjs} +1 -1
  43. package/dist-lib/esm-chunks/{chunk-OLGTAPUD.mjs → chunk-O6HHWO4Y.mjs} +1 -1
  44. package/dist-lib/esm-chunks/{chunk-WDTW47HC.mjs → chunk-OS6YJU3W.mjs} +1 -1
  45. package/dist-lib/esm-chunks/{chunk-IVMQXMAB.mjs → chunk-PRYC6EMT.mjs} +1 -1
  46. package/dist-lib/esm-chunks/{chunk-T66EPEFI.mjs → chunk-R6ES6QCH.mjs} +1 -1
  47. package/dist-lib/esm-chunks/{chunk-GGEXRAIP.mjs → chunk-TJULYSLY.mjs} +1 -1
  48. package/dist-lib/esm-chunks/{chunk-U66IKMQZ.mjs → chunk-V6BE34Q3.mjs} +1 -1
  49. package/dist-lib/esm-chunks/{chunk-NHFLYRY6.mjs → chunk-Y6YMRYNX.mjs} +64 -21
  50. package/dist-lib/esm-chunks/{chunk-AWVOMHWY.mjs → chunk-ZTDPCBGG.mjs} +3 -3
  51. package/dist-lib/esm-chunks/{metro-layout-parser-DCAE4BLG.mjs → metro-layout-parser-WG2ITRQD.mjs} +3 -3
  52. package/dist-lib/esm-chunks/{swift-package-prebuilt-PP63JS2U.mjs → swift-package-prebuilt-DN7G5XKR.mjs} +16 -13
  53. package/dist-lib/esm-chunks/{swift-sdk-app-module-Q5PK6AH4.mjs → swift-sdk-app-module-3DB4F4Y2.mjs} +16 -16
  54. package/dist-lib/esm-chunks/{swift-sdk-image-NTCJSARK.mjs → swift-sdk-image-JTYM3OQY.mjs} +16 -16
  55. package/dist-lib/esm-chunks/{swift-sdk-image-producer-KIVLLITM.mjs → swift-sdk-image-producer-QQUODPXF.mjs} +5 -5
  56. package/dist-lib/expo-swift-bundle.cjs +1104 -939
  57. package/dist-lib/expo-swift-metadata.cjs +1 -1
  58. package/dist-lib/expo-swift-metadata.mjs +7 -7
  59. package/dist-lib/home-paths.cjs +1 -1
  60. package/dist-lib/host/bridge-host.cjs +3747 -3456
  61. package/dist-lib/host/fetch-proxy-handler.cjs +121 -117
  62. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  63. package/dist-lib/host/fetch-proxy-overrides.mjs +2 -2
  64. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  65. package/dist-lib/host/websocket-proxy.cjs +1 -1
  66. package/dist-lib/index.cjs +1 -1
  67. package/dist-lib/kotlin-host.cjs +1 -1
  68. package/dist-lib/menu.cjs +1 -1
  69. package/dist-lib/menu.mjs +3 -3
  70. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  71. package/dist-lib/metro-fingerprint-registry.mjs +3 -3
  72. package/dist-lib/metro-production-bundle.cjs +1 -1
  73. package/dist-lib/metro-production-bundle.mjs +4 -4
  74. package/dist-lib/native-app-identity-project.cjs +3 -1
  75. package/dist-lib/native-app-identity-project.mjs +15 -15
  76. package/dist-lib/native-app-identity.cjs +1 -1
  77. package/dist-lib/native-app-identity.mjs +6 -6
  78. package/dist-lib/native-firebase-metadata.cjs +1 -1
  79. package/dist-lib/native-firebase-metadata.mjs +3 -3
  80. package/dist-lib/pdfium-raster.cjs +1 -1
  81. package/dist-lib/pdfium-raster.mjs +2 -2
  82. package/dist-lib/plist.cjs +1 -1
  83. package/dist-lib/plist.mjs +3 -3
  84. package/dist-lib/profiles.cjs +1 -1
  85. package/dist-lib/public-brand.cjs +1 -1
  86. package/dist-lib/public-origins-lib-esm.json +85 -85
  87. package/dist-lib/public-origins-lib.json +76 -76
  88. package/dist-lib/react-native-host-modules.cjs +1 -1
  89. package/dist-lib/react-native-host-modules.mjs +2 -2
  90. package/dist-lib/reap-browser.cjs +1 -1
  91. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  92. package/dist-lib/sdk.cjs +1 -1
  93. package/dist-lib/sdk.mjs +8 -8
  94. package/dist-lib/skills.cjs +2032 -1741
  95. package/dist-lib/swift-compile.cjs +1061 -967
  96. package/dist-lib/swift-compile.mjs +12 -12
  97. package/dist-lib/swift-package.cjs +1 -1
  98. package/dist-lib/swift-package.mjs +3 -3
  99. package/dist-lib/swift-submit.cjs +1 -1
  100. package/dist-lib/swift-submit.mjs +6 -6
  101. package/dist-lib/swift-svg-raster.cjs +1 -1
  102. package/dist-lib/swift-svg-raster.mjs +2 -2
  103. package/dist-lib/swift-toolchain.cjs +1 -1
  104. package/dist-lib/swift.cjs +1 -1
  105. package/dist-lib/vendor/@peculiar/x509.cjs +1 -1
  106. package/dist-lib/vendor/@ruby/prism/src/nodes.js.cjs +1 -1
  107. package/dist-lib/vendor/@ruby/prism/src/parsePrism.js.cjs +1 -1
  108. package/dist-lib/vendor/acorn.cjs +1 -1
  109. package/dist-lib/vendor/magic-string.cjs +1 -1
  110. package/dist-lib/vendor/stream-json.cjs +1 -1
  111. package/dist-lib/vendor/sucrase/dist/index.js.cjs +1 -1
  112. package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +1 -1
  113. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +1 -1
  114. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +1 -1
  115. package/dist-lib/vendor/sucrase.cjs +1 -1
  116. package/dist-lib/vendor/terser.cjs +1 -1
  117. package/dist-lib/vendor/valibot.cjs +1 -1
  118. package/dist-lib/vendor/ws.cjs +1 -1
  119. package/dist-lib/vendor/zod.cjs +1 -1
  120. package/dist-lib/worklet-executable.cjs +1 -1
  121. package/dist-lib/worklet-executable.mjs +3 -3
  122. package/dist-types/packages/peach-engine/src/engine/image-fetch.d.ts +0 -4
  123. package/dist-types/packages/peach-engine/src/engine/scene-native-binding.d.ts +2 -2
  124. package/dist-types/packages/peach-engine/src/render-worker/native-hot-ops.d.ts +1 -1
  125. package/dist-types/packages/peach-engine/src/render-worker/nativeReanimatedCSSContract.d.ts +7 -7
  126. package/dist-types/packages/peach-engine/src/render-worker/reanimated-css-contract.d.ts +1 -20
  127. package/dist-types/packages/peach-engine/src/render-worker/scene-packet-feed.d.ts +2 -0
  128. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +5 -23
  129. package/dist-types/packages/peach-engine/src/render-worker/worklet-wire.d.ts +4 -49
  130. package/package.json +1 -1
  131. package/src/one-native-controls-package.ts +56 -54
  132. package/src/swift-compile.ts +1034 -967
  133. package/src/swift-compiler-digest.ts +79 -4
  134. package/src/swift-host.ts +246 -91
  135. package/src/swift-package-prebuilt.ts +6 -3
  136. package/src/swift-sdk-surface.ts +75 -20
  137. package/src/swift-startup-split.ts +134 -12
@@ -1,3 +1,4 @@
1
+ import { AsyncLocalStorage } from 'node:async_hooks'
1
2
  import { execFileSync, spawnSync } from 'node:child_process'
2
3
  import { createHash, randomUUID } from 'node:crypto'
3
4
  import {
@@ -550,8 +551,25 @@ export function swiftMacroPlugins(moduleRoot: string): {
550
551
  }
551
552
 
552
553
  const linkedModuleDigests = new Map<string, { stamp: string; digest: Buffer }>()
554
+ const moduleDigestScopes = new AsyncLocalStorage<
555
+ Map<string, { stamp: string; digest: Buffer }>
556
+ >()
557
+
558
+ /** reuse one moduleRoot stat walk across a single build or artifact-check call. */
559
+ export function withSwiftModuleDigestScope<T>(fn: () => T): T {
560
+ if (moduleDigestScopes.getStore()) return fn()
561
+ return moduleDigestScopes.run(new Map(), fn)
562
+ }
563
+
564
+ export function clearSwiftModuleDigestScope(root?: string): void {
565
+ const scope = moduleDigestScopes.getStore()
566
+ if (!scope) return
567
+ if (root === undefined) scope.clear()
568
+ else scope.delete(path.resolve(root))
569
+ }
553
570
 
554
571
  export function clearLinkedModuleDigests(root?: string): void {
572
+ clearSwiftModuleDigestScope(root)
555
573
  if (root === undefined) linkedModuleDigests.clear()
556
574
  else linkedModuleDigests.delete(root)
557
575
  }
@@ -623,9 +641,11 @@ function gitCleanModuleInputsKey(root: string, files: readonly string[]): string
623
641
  return keyHash.digest('hex')
624
642
  }
625
643
 
626
- /** the digest of a module checkout's inputs: what an artifact address and a
627
- * distribution's id name it by. */
628
- export function swiftModuleDigest(root: string): Buffer {
644
+ function swiftModuleEntry(root: string): { stamp: string; digest: Buffer } {
645
+ const scope = moduleDigestScopes.getStore()
646
+ const key = path.resolve(root)
647
+ const scoped = scope?.get(key)
648
+ if (scoped) return scoped
629
649
  const files = swiftModuleInputFiles(root)
630
650
  const stampHash = createHash('sha256')
631
651
  for (const file of files) {
@@ -637,7 +657,10 @@ export function swiftModuleDigest(root: string): Buffer {
637
657
  }
638
658
  const stamp = stampHash.digest('hex')
639
659
  const cached = linkedModuleDigests.get(root)
640
- if (cached?.stamp === stamp) return cached.digest
660
+ if (cached?.stamp === stamp) {
661
+ scope?.set(key, cached)
662
+ return cached
663
+ }
641
664
  // a source checkout holds thousands of inputs, so a fresh bridge reuses the
642
665
  // digest an earlier process recorded under the same stamp.
643
666
  const digestDir = path.join(swiftCacheDir(), 'swift-module-digests')
@@ -660,8 +683,10 @@ export function swiftModuleDigest(root: string): Buffer {
660
683
  typeof Reflect.get(saved, 'digest') === 'string'
661
684
  ) {
662
685
  const digest = Buffer.from(String(Reflect.get(saved, 'digest')), 'hex')
663
- linkedModuleDigests.set(root, { stamp, digest })
664
- return digest
686
+ const entry = { stamp, digest }
687
+ linkedModuleDigests.set(root, entry)
688
+ scope?.set(key, entry)
689
+ return entry
665
690
  }
666
691
  }
667
692
  const gitKey = gitCleanModuleInputsKey(root, files)
@@ -675,9 +700,11 @@ export function swiftModuleDigest(root: string): Buffer {
675
700
  ) {
676
701
  const hex = String(Reflect.get(saved, 'digest'))
677
702
  const digest = Buffer.from(hex, 'hex')
678
- linkedModuleDigests.set(root, { stamp, digest })
703
+ const entry = { stamp, digest }
704
+ linkedModuleDigests.set(root, entry)
705
+ scope?.set(key, entry)
679
706
  writeRecord(record, JSON.stringify({ stamp, digest: hex }))
680
- return digest
707
+ return entry
681
708
  }
682
709
  }
683
710
  const hash = createHash('sha256')
@@ -691,10 +718,23 @@ export function swiftModuleDigest(root: string): Buffer {
691
718
  }
692
719
  const digest = hash.digest()
693
720
  const hex = digest.toString('hex')
694
- linkedModuleDigests.set(root, { stamp, digest })
721
+ const entry = { stamp, digest }
722
+ linkedModuleDigests.set(root, entry)
723
+ scope?.set(key, entry)
695
724
  writeRecord(record, JSON.stringify({ stamp, digest: hex }))
696
725
  if (gitRecord) writeRecord(gitRecord, JSON.stringify({ digest: hex }))
697
- return digest
726
+ return entry
727
+ }
728
+
729
+ /** the digest of a module checkout's inputs: what an artifact address and a
730
+ * distribution's id name it by. */
731
+ export function swiftModuleDigest(root: string): Buffer {
732
+ return swiftModuleEntry(root).digest
733
+ }
734
+
735
+ /** stat stamp of a module checkout's inputs, sharing one walk with swiftModuleDigest. */
736
+ export function swiftModuleStamp(root: string): string {
737
+ return swiftModuleEntry(root).stamp
698
738
  }
699
739
 
700
740
  const compileSurfaces = new WeakMap<SwiftDistributionManifest, Buffer>()
@@ -873,15 +913,18 @@ export function* swiftConditionalLines(
873
913
  * it to true. a branch the scan cannot decide may compile out, so its
874
914
  * imports stay out of the list.
875
915
  */
876
- const importNamesCache = new Map<string, string[]>()
916
+ const importNamesCache = new Map<string, Map<string, string[]>>()
877
917
 
878
918
  export function swiftImportNames(
879
919
  contents: string,
880
920
  available?: ReadonlySet<string>,
881
921
  defines?: ReadonlySet<string>,
882
922
  ): string[] {
883
- if (available === undefined && defines === undefined) {
884
- const cached = importNamesCache.get(contents)
923
+ if (!contents.includes('import')) return []
924
+ const definesKey =
925
+ available === undefined ? (defines ? [...defines].sort().join('\0') : '') : undefined
926
+ if (definesKey !== undefined) {
927
+ const cached = importNamesCache.get(definesKey)?.get(contents)
885
928
  if (cached !== undefined) return cached
886
929
  }
887
930
  const names: string[] = []
@@ -890,8 +933,14 @@ export function swiftImportNames(
890
933
  const name = SWIFT_IMPORT.exec(line)?.[1]
891
934
  if (name) names.push(name)
892
935
  }
893
- if (available === undefined && defines === undefined)
894
- importNamesCache.set(contents, names)
936
+ if (definesKey !== undefined) {
937
+ let bucket = importNamesCache.get(definesKey)
938
+ if (!bucket) {
939
+ bucket = new Map()
940
+ importNamesCache.set(definesKey, bucket)
941
+ }
942
+ bucket.set(contents, names)
943
+ }
895
944
  return names
896
945
  }
897
946
 
@@ -1664,17 +1713,23 @@ export function swiftCDefinedNames(sources: Iterable<string>): Set<string> {
1664
1713
  return names
1665
1714
  }
1666
1715
 
1716
+ /** the compiler release pinned by a module root, without verifying binaries. */
1717
+ export function swiftModuleRelease(root: string): string {
1718
+ const pin: { release: string } =
1719
+ swiftDistributionAt(root) ??
1720
+ JSON.parse(readFileSync(path.join(root, 'toolchain.json'), 'utf8'))
1721
+ return pin.release
1722
+ }
1723
+
1667
1724
  /** the host compiler selected by a module root, without requiring a guest SDK. */
1668
1725
  export function swiftModuleCompiler(root: string): {
1669
1726
  release: string
1670
1727
  toolchainBin: string
1671
1728
  } {
1672
- const pin: { release: string } =
1673
- swiftDistributionAt(root) ??
1674
- JSON.parse(readFileSync(path.join(root, 'toolchain.json'), 'utf8'))
1729
+ const release = swiftModuleRelease(root)
1675
1730
  return {
1676
- release: pin.release,
1677
- toolchainBin: swiftCompiler(pin.release),
1731
+ release,
1732
+ toolchainBin: swiftCompiler(release),
1678
1733
  }
1679
1734
  }
1680
1735
 
@@ -4,6 +4,7 @@ import {
4
4
  existsSync,
5
5
  mkdirSync,
6
6
  mkdtempSync,
7
+ promises as fsPromises,
7
8
  readdirSync,
8
9
  readFileSync,
9
10
  renameSync,
@@ -19,7 +20,6 @@ import {
19
20
  PEACH_SIMULATOR_SHELL_FILE,
20
21
  } from '@peach/globals/simulator-route'
21
22
  import { NATIVE_PROFILE_ENDPOINT } from '../../peach-kit/src/nativeWasmContract'
22
- import { launchProvisionedPlaywright } from '../cli/drivers/playwright-provisioning'
23
23
  import { swiftGuestBundle } from './guest-bundle'
24
24
  import { serveBrowserProxyRoute } from './host/fetch-proxy-handler'
25
25
  import { handleWebSocketProxyUpgrade } from './host/websocket-proxy'
@@ -158,12 +158,67 @@ export function readSwiftStartupImage(cache: string): SwiftStartupImage | null {
158
158
  }
159
159
  }
160
160
 
161
+ async function readSwiftStartupImageAsync(
162
+ cache: string,
163
+ ): Promise<SwiftStartupImage | null> {
164
+ try {
165
+ const receipt: unknown = JSON.parse(
166
+ await fsPromises.readFile(join(cache, 'image.json'), 'utf8'),
167
+ )
168
+ let names: unknown = receipt
169
+ let source: string | undefined
170
+ let dataPlanHash: string | undefined
171
+ if (receipt && typeof receipt === 'object' && 'source' in receipt) {
172
+ if (typeof receipt.source !== 'string' || !partDigest.test(receipt.source))
173
+ return null
174
+ source = receipt.source
175
+ names = 'chunks' in receipt ? receipt.chunks : undefined
176
+ if ('dataPlan' in receipt) {
177
+ const hash = receipt.dataPlan
178
+ if (typeof hash !== 'string' || !partDigest.test(hash)) return null
179
+ dataPlanHash = hash
180
+ }
181
+ }
182
+ if (
183
+ !Array.isArray(names) ||
184
+ !names.length ||
185
+ !names.every(
186
+ (name): name is string => typeof name === 'string' && partDigest.test(name),
187
+ )
188
+ )
189
+ return null
190
+ const [dataPlan, ...chunks] = await Promise.all([
191
+ dataPlanHash
192
+ ? fsPromises.readFile(join(cache, dataPlanHash + '.bin'))
193
+ : Promise.resolve(undefined),
194
+ ...names.map(
195
+ async (name): Promise<[string, Buffer]> => [
196
+ name,
197
+ await fsPromises.readFile(join(cache, name + '.wasm')),
198
+ ],
199
+ ),
200
+ ])
201
+ if (dataPlanHash && (!dataPlan || digest(dataPlan) !== dataPlanHash)) return null
202
+ if (chunks.some(([name, bytes]) => digest(bytes) !== name)) return null
203
+ return { primary: chunks[0]![1], parts: new Map(chunks.slice(1)), source, dataPlan }
204
+ } catch (error) {
205
+ if (
206
+ error instanceof SyntaxError ||
207
+ (error instanceof Error && 'code' in error && error.code === 'ENOENT')
208
+ )
209
+ return null
210
+ throw error
211
+ }
212
+ }
213
+
161
214
  const platform = `${process.platform}-${process.arch}`
162
215
 
163
- export async function splitSwiftApp(
164
- bytes: Buffer,
165
- launch: SwiftStartupLaunch,
166
- ): Promise<SwiftStartupImage> {
216
+ function swiftAppStartupCacheDir(
217
+ launch: Pick<
218
+ SwiftStartupLaunch,
219
+ 'artifactHash' | 'environment' | 'guest' | 'arguments'
220
+ >,
221
+ ): { parent: string; cache: string } {
167
222
  const parent = join(swiftCacheDir(), 'swift-projects', launch.artifactHash, 'artifact')
168
223
  const environment = launch.environment.length
169
224
  ? `-${digest(Buffer.from(JSON.stringify(launch.environment)))}`
@@ -172,7 +227,26 @@ export async function splitSwiftApp(
172
227
  const args = launch.arguments?.length
173
228
  ? `-argv-${digest(Buffer.from(JSON.stringify(launch.arguments)))}`
174
229
  : ''
175
- const cache = join(parent, `startup-v9-${platform}${environment}${guest}${args}`)
230
+ return {
231
+ parent,
232
+ cache: join(parent, `startup-v9-${platform}${environment}${guest}${args}`),
233
+ }
234
+ }
235
+
236
+ export function readCachedSwiftAppStartupSplit(
237
+ launch: Pick<
238
+ SwiftStartupLaunch,
239
+ 'artifactHash' | 'environment' | 'guest' | 'arguments'
240
+ >,
241
+ ): Promise<SwiftStartupImage | null> {
242
+ return readSwiftStartupImageAsync(swiftAppStartupCacheDir(launch).cache)
243
+ }
244
+
245
+ export async function splitSwiftApp(
246
+ bytes: Buffer,
247
+ launch: SwiftStartupLaunch,
248
+ ): Promise<SwiftStartupImage> {
249
+ const { parent, cache } = swiftAppStartupCacheDir(launch)
176
250
  return (
177
251
  readSwiftStartupImage(cache) ??
178
252
  (await withStartupWork(bytes, async (work) => {
@@ -204,6 +278,52 @@ function mergeProfileBitsets(files: readonly Buffer[]): Buffer {
204
278
  return merged
205
279
  }
206
280
 
281
+ async function currentSwiftSdkStartupCache(
282
+ directory: string,
283
+ artifactHash: string,
284
+ app: string,
285
+ requireCurrentProfile: boolean,
286
+ ): Promise<{ merged: Buffer; cache: string } | undefined> {
287
+ const profiles = join(directory, `profiles-v3-${platform}`)
288
+ const prefix = `${app}-`
289
+ const own = join(profiles, `${prefix}${artifactHash}.profile`)
290
+ const names = () =>
291
+ existsSync(profiles)
292
+ ? readdirSync(profiles)
293
+ .filter((name) => !name.startsWith('.') && name.endsWith('.profile'))
294
+ .sort()
295
+ : []
296
+ return withSwiftRootLock(profiles, async () => {
297
+ const recorded = requireCurrentProfile
298
+ ? existsSync(own)
299
+ : names().some((name) => name.startsWith(prefix))
300
+ if (!recorded) return undefined
301
+ const merged = mergeProfileBitsets(
302
+ names().map((name) => readFileSync(join(profiles, name))),
303
+ )
304
+ const cache = join(
305
+ directory,
306
+ `startup-v11-${platform}-${digest(merged).slice(0, 16)}`,
307
+ )
308
+ return { merged, cache }
309
+ })
310
+ }
311
+
312
+ export async function readCachedSwiftSdkStartupSplit(
313
+ directory: string,
314
+ artifactHash: string,
315
+ app: string,
316
+ requireCurrentProfile: boolean,
317
+ ): Promise<SwiftStartupImage | null> {
318
+ const available = await currentSwiftSdkStartupCache(
319
+ directory,
320
+ artifactHash,
321
+ app,
322
+ requireCurrentProfile,
323
+ )
324
+ return available ? readSwiftStartupImageAsync(available.cache) : null
325
+ }
326
+
207
327
  /**
208
328
  * splits a shared sdk image by the merged startup of every app profiled on it: each app's
209
329
  * profile stays beside the image, and a new app's profile widens the startup file.
@@ -237,12 +357,12 @@ export async function splitSwiftSdkImage(
237
357
  // routine app edits retain the recorded startup paths. compiled controls carry their
238
358
  // profiling view in the artifact, so they need a fresh profile when that artifact changes.
239
359
  const current = () =>
240
- withSwiftRootLock(profiles, async () => {
241
- const recorded = requireCurrentProfile
242
- ? existsSync(own)
243
- : names().some((name) => name.startsWith(prefix))
244
- return recorded ? union() : undefined
245
- })
360
+ currentSwiftSdkStartupCache(
361
+ directory,
362
+ launch.artifactHash,
363
+ app,
364
+ requireCurrentProfile,
365
+ )
246
366
  const available = await current()
247
367
  if (available) {
248
368
  const ready = readSwiftStartupImage(available.cache)
@@ -415,6 +535,8 @@ export async function bootSwiftPreview(
415
535
  launch: SwiftStartupPreview,
416
536
  profile?: SwiftStartupProfile,
417
537
  ): Promise<void | Buffer> {
538
+ const { launchProvisionedPlaywright } =
539
+ await import('../cli/drivers/playwright-provisioning')
418
540
  const browser = await launchProvisionedPlaywright({
419
541
  chromiumSandbox: true,
420
542
  ...(profile && {