peachsim 0.1.1879 → 0.1.1881

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 (83) 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 +1 -1
  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 +1 -1
  11. package/dist-lib/bridge-contract.cjs +1 -1
  12. package/dist-lib/bridge-contract.mjs +1 -1
  13. package/dist-lib/bundle-channel.cjs +109 -54
  14. package/dist-lib/capture-contract.cjs +1 -1
  15. package/dist-lib/capture-contract.mjs +1 -1
  16. package/dist-lib/cloud-contract.cjs +1 -1
  17. package/dist-lib/cloud-contract.mjs +1 -1
  18. package/dist-lib/cloud-test-args.cjs +1 -1
  19. package/dist-lib/cloud-test-args.mjs +1 -1
  20. package/dist-lib/cloud.cjs +1 -1
  21. package/dist-lib/cloud.mjs +1 -1
  22. package/dist-lib/config.cjs +1 -1
  23. package/dist-lib/config.mjs +1 -1
  24. package/dist-lib/detox/index.cjs +1 -1
  25. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  26. package/dist-lib/expo-swift-bundle.cjs +104 -51
  27. package/dist-lib/expo-swift-metadata.cjs +1 -1
  28. package/dist-lib/expo-swift-metadata.mjs +1 -1
  29. package/dist-lib/home-paths.cjs +1 -1
  30. package/dist-lib/host/bridge-host.cjs +107 -52
  31. package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
  32. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  33. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  34. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  35. package/dist-lib/host/websocket-proxy.cjs +1 -1
  36. package/dist-lib/index.cjs +2 -2
  37. package/dist-lib/jump-to-source-babel.cjs +1 -1
  38. package/dist-lib/jump-to-source-native.cjs +1 -1
  39. package/dist-lib/kotlin-host.cjs +1 -1
  40. package/dist-lib/menu.cjs +1 -1
  41. package/dist-lib/menu.mjs +1 -1
  42. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  43. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  44. package/dist-lib/metro-production-bundle.cjs +1 -1
  45. package/dist-lib/metro-production-bundle.mjs +1 -1
  46. package/dist-lib/metro.cjs +2 -2
  47. package/dist-lib/native-app-identity-project.cjs +2 -2
  48. package/dist-lib/native-app-identity-project.mjs +5 -2
  49. package/dist-lib/native-app-identity.cjs +1 -1
  50. package/dist-lib/native-app-identity.mjs +1 -1
  51. package/dist-lib/native-firebase-metadata.cjs +1 -1
  52. package/dist-lib/native-firebase-metadata.mjs +1 -1
  53. package/dist-lib/pdfium-raster.cjs +1 -1
  54. package/dist-lib/pdfium-raster.mjs +1 -1
  55. package/dist-lib/plist.cjs +1 -1
  56. package/dist-lib/plist.mjs +1 -1
  57. package/dist-lib/profiles.cjs +1 -1
  58. package/dist-lib/public-brand.cjs +1 -1
  59. package/dist-lib/public-origins-lib-esm.json +24 -24
  60. package/dist-lib/public-origins-lib.json +53 -53
  61. package/dist-lib/react-native-host-modules.cjs +1 -1
  62. package/dist-lib/react-native-host-modules.mjs +1 -1
  63. package/dist-lib/reap-browser.cjs +1 -1
  64. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  65. package/dist-lib/sdk.cjs +1 -1
  66. package/dist-lib/sdk.mjs +1 -1
  67. package/dist-lib/skills.cjs +109 -54
  68. package/dist-lib/swift-compile.cjs +97 -48
  69. package/dist-lib/swift-compile.mjs +100 -48
  70. package/dist-lib/swift-package.cjs +1 -1
  71. package/dist-lib/swift-package.mjs +1 -1
  72. package/dist-lib/swift-submit.cjs +1 -1
  73. package/dist-lib/swift-submit.mjs +1 -1
  74. package/dist-lib/swift-toolchain.cjs +1 -1
  75. package/dist-lib/swift.cjs +1 -1
  76. package/dist-lib/vite-swift.cjs +98 -49
  77. package/dist-lib/vite.cjs +1 -1
  78. package/dist-lib/worklet-executable.cjs +1 -1
  79. package/dist-lib/worklet-executable.mjs +1 -1
  80. package/package.json +1 -1
  81. package/src/expo-native-workspace.ts +4 -0
  82. package/src/swift-compile.ts +135 -64
  83. package/src/turbo-source.ts +4 -1
@@ -6,12 +6,15 @@ import {
6
6
  } from 'node:child_process'
7
7
  import { createHash, randomUUID } from 'node:crypto'
8
8
  import {
9
+ copyFileSync,
9
10
  cpSync,
10
11
  existsSync,
12
+ lstatSync,
11
13
  mkdirSync,
12
14
  mkdtempSync,
13
15
  readFileSync,
14
16
  readdirSync,
17
+ readlinkSync,
15
18
  realpathSync,
16
19
  renameSync,
17
20
  rmSync,
@@ -6075,7 +6078,7 @@ interface SwiftFrameworkProducts {
6075
6078
  // targets differ only by case overwrite each other on a case-insensitive
6076
6079
  // volume. building the framework package into the sibling scratch leaves each
6077
6080
  // target's objects and modules under its own package, on either volume.
6078
- async function compileFrameworkProducts(args: {
6081
+ type FrameworkBuildArgs = {
6079
6082
  moduleRoot: string
6080
6083
  frameworkKey: string
6081
6084
  input: SwiftCompileInput
@@ -6088,18 +6091,11 @@ async function compileFrameworkProducts(args: {
6088
6091
  lease?: SwiftRootLease
6089
6092
  frameworkLease?: SwiftRootLease
6090
6093
  }
6091
- }): Promise<SwiftFrameworkProducts> {
6092
- const scratch = swiftFrameworkScratch(args.frameworkKey)
6093
- mkdirSync(scratch, { recursive: true })
6094
- // incremental builds leave the directory's own mtime alone, which the prune reads
6095
- const now = new Date()
6096
- utimesSync(scratch, now, now)
6097
- return buildFrameworkProducts(scratch, args)
6098
6094
  }
6099
6095
 
6100
6096
  async function buildFrameworkProducts(
6101
6097
  scratch: string,
6102
- args: Parameters<typeof compileFrameworkProducts>[0],
6098
+ args: FrameworkBuildArgs,
6103
6099
  ): Promise<SwiftFrameworkProducts> {
6104
6100
  const linkedTargets = linkedFrameworkTargets(args.moduleRoot, args.input)
6105
6101
  const linkRoot = path.join(scratch, 'link')
@@ -6240,9 +6236,14 @@ async function buildFrameworkProducts(
6240
6236
  // the way the builder's per-build-key roots do.
6241
6237
  const SWIFT_LINK_STAMP = '.peach-link-stamp'
6242
6238
 
6243
- // one scratch per framework revision on the machine: every app built against
6244
- // that revision reuses its compiled products.
6245
- const SWIFT_FRAMEWORK_SCRATCHES_KEPT = 3
6239
+ // a few scratch slots at fixed paths hold the framework revisions in use; every
6240
+ // app built against a revision reuses its slot's compiled products. a revision
6241
+ // with no slot takes the least recently built one, restages only the files that
6242
+ // differ and rebuilds only the modules those files reach: swiftpm and llbuild
6243
+ // key their plans on absolute paths, so a fresh path per revision recompiled
6244
+ // every module.
6245
+ const SWIFT_FRAMEWORK_SLOTS = 3
6246
+ const SWIFT_FRAMEWORK_SLOT_KEY = '.peach-framework-key'
6246
6247
 
6247
6248
  function swiftFrameworksDir(): string {
6248
6249
  return path.join(swiftCacheDir(), 'swift-frameworks')
@@ -6252,35 +6253,124 @@ function swiftFrameworkScratch(frameworkKey: string): string {
6252
6253
  return path.join(swiftFrameworksDir(), frameworkKey)
6253
6254
  }
6254
6255
 
6255
- // a builder receives every delivery at a new path, and swiftpm keys its plan and
6256
- // llbuild its inputs on absolute paths and inodes. one copy of the module and
6257
- // its shared sdk per framework key, at a fixed path, gives every delivery
6258
- // identical inputs. a published distribution is already immutable and stays put.
6259
- function stageFrameworkSource(moduleRoot: string, frameworkKey: string): string {
6260
- if (swiftDistributionAt(moduleRoot)) return moduleRoot
6261
- const staged = path.join(swiftFrameworkScratch(frameworkKey), 'source')
6262
- const stagedModule = path.join(staged, 'packages', path.basename(moduleRoot))
6263
- if (existsSync(path.join(staged, '.complete'))) return stagedModule
6264
- const partial = `${staged}.${randomUUID()}`
6265
- mkdirSync(partial, { recursive: true })
6266
- cpSync(moduleRoot, path.join(partial, 'packages', path.basename(moduleRoot)), {
6267
- recursive: true,
6268
- preserveTimestamps: true,
6269
- filter: (source) => path.relative(moduleRoot, source) !== '.build',
6256
+ function swiftFrameworkSlotKey(slot: string): string | null {
6257
+ try {
6258
+ return readFileSync(path.join(slot, SWIFT_FRAMEWORK_SLOT_KEY), 'utf8').trim()
6259
+ } catch (error) {
6260
+ if (!vanished(error)) throw error
6261
+ return null
6262
+ }
6263
+ }
6264
+
6265
+ /** runs `work` holding the slot that builds `frameworkKey`'s products: the slot
6266
+ * already staged for it, else an idle one, else the least recently built. */
6267
+ async function withSwiftFrameworkSlot<T>(
6268
+ frameworkKey: string,
6269
+ signal: AbortSignal | undefined,
6270
+ work: (slot: string, lease: SwiftRootLease) => Promise<T>,
6271
+ ): Promise<T> {
6272
+ const slots = Array.from({ length: SWIFT_FRAMEWORK_SLOTS }, (_, index) => {
6273
+ const slot = path.join(swiftFrameworksDir(), `slot-${index}`)
6274
+ mkdirSync(slot, { recursive: true })
6275
+ return slot
6270
6276
  })
6271
- cpSync(
6272
- swiftSharedSdkRoot(moduleRoot, false),
6273
- path.join(partial, 'packages/peachsim/sdk/ios'),
6274
- { recursive: true, preserveTimestamps: true },
6275
- )
6276
- // the plugin build resolves the macro scanner from the module's node_modules
6277
- symlinkSync(
6278
- realpathSync(path.join(moduleRoot, '../../node_modules')),
6279
- path.join(partial, 'node_modules'),
6277
+ const run = (slot: string) => (lease: SwiftRootLease) => {
6278
+ // an incremental build leaves the directory's own mtime alone, which orders reuse
6279
+ const now = new Date()
6280
+ utimesSync(slot, now, now)
6281
+ return work(slot, lease)
6282
+ }
6283
+ const staged = slots.find((slot) => swiftFrameworkSlotKey(slot) === frameworkKey)
6284
+ if (staged) return withSwiftRootLock(staged, run(staged), signal)
6285
+ const oldest = slots.sort(
6286
+ (left, right) => statSync(left).mtimeMs - statSync(right).mtimeMs,
6280
6287
  )
6281
- writeFileSync(path.join(partial, '.complete'), '')
6282
- rmSync(staged, { recursive: true, force: true })
6283
- renameSync(partial, staged)
6288
+ for (const slot of oldest) {
6289
+ const result = await withSwiftRootLock(
6290
+ slot,
6291
+ async (lease) => ({ value: await run(slot)(lease) }),
6292
+ signal,
6293
+ false,
6294
+ )
6295
+ if (result) return result.value
6296
+ }
6297
+ return withSwiftRootLock(oldest[0]!, run(oldest[0]!), signal)
6298
+ }
6299
+
6300
+ // copies the files of `source` that differ into `target` and removes the rest of
6301
+ // `target`. a file whose size and mtime match, or whose bytes match, is left
6302
+ // alone so llbuild sees it unchanged; a changed file arrives as a new inode.
6303
+ function mirrorTree(source: string, target: string, skip?: string): void {
6304
+ mkdirSync(target, { recursive: true })
6305
+ const wanted = new Set<string>()
6306
+ for (const entry of readdirSync(source, { withFileTypes: true })) {
6307
+ if (entry.name === skip) continue
6308
+ wanted.add(entry.name)
6309
+ const from = path.join(source, entry.name)
6310
+ const to = path.join(target, entry.name)
6311
+ let existing: ReturnType<typeof lstatSync> | null = null
6312
+ try {
6313
+ existing = lstatSync(to)
6314
+ } catch (error) {
6315
+ if (!vanished(error)) throw error
6316
+ }
6317
+ if (entry.isDirectory()) {
6318
+ if (existing && !existing.isDirectory()) rmSync(to, { force: true })
6319
+ mirrorTree(from, to)
6320
+ } else if (entry.isSymbolicLink()) {
6321
+ const link = readlinkSync(from)
6322
+ if (existing?.isSymbolicLink() && readlinkSync(to) === link) continue
6323
+ if (existing) rmSync(to, { recursive: true, force: true })
6324
+ symlinkSync(link, to)
6325
+ } else {
6326
+ const stat = statSync(from)
6327
+ if (
6328
+ existing?.isFile() &&
6329
+ existing.size === stat.size &&
6330
+ (existing.mtimeMs === stat.mtimeMs || readFileSync(from).equals(readFileSync(to)))
6331
+ )
6332
+ continue
6333
+ if (existing) rmSync(to, { recursive: true, force: true })
6334
+ const partial = `${to}.${randomUUID()}`
6335
+ copyFileSync(from, partial)
6336
+ utimesSync(partial, stat.atime, stat.mtime)
6337
+ renameSync(partial, to)
6338
+ }
6339
+ }
6340
+ for (const name of readdirSync(target))
6341
+ if (!wanted.has(name) && name !== skip)
6342
+ rmSync(path.join(target, name), { recursive: true, force: true })
6343
+ }
6344
+
6345
+ // a builder receives every delivery at a new path, and swiftpm keys its plan and
6346
+ // llbuild its inputs on absolute paths and inodes. the module and its shared sdk
6347
+ // are mirrored into the slot at a fixed path, so a revision rebuilds only what
6348
+ // changed. a published distribution is already immutable and stays put.
6349
+ function stageFrameworkSource(
6350
+ moduleRoot: string,
6351
+ slot: string | null,
6352
+ frameworkKey: string,
6353
+ ): string {
6354
+ if (!slot) return moduleRoot
6355
+ const staged = path.join(slot, 'source')
6356
+ const stagedModule = path.join(staged, 'packages', path.basename(moduleRoot))
6357
+ if (swiftFrameworkSlotKey(slot) !== frameworkKey) {
6358
+ // an interrupted restage must not look like a finished one
6359
+ rmSync(path.join(slot, SWIFT_FRAMEWORK_SLOT_KEY), { force: true })
6360
+ mirrorTree(moduleRoot, stagedModule, '.build')
6361
+ mirrorTree(
6362
+ swiftSharedSdkRoot(moduleRoot, false),
6363
+ path.join(staged, 'packages/peachsim/sdk/ios'),
6364
+ )
6365
+ // the plugin build resolves the macro scanner from the module's node_modules
6366
+ const modules = path.join(staged, 'node_modules')
6367
+ const target = realpathSync(path.join(moduleRoot, '../../node_modules'))
6368
+ if (!existsSync(modules) || readlinkSync(modules) !== target) {
6369
+ rmSync(modules, { recursive: true, force: true })
6370
+ symlinkSync(target, modules)
6371
+ }
6372
+ writeFileSync(path.join(slot, SWIFT_FRAMEWORK_SLOT_KEY), frameworkKey)
6373
+ }
6284
6374
  return stagedModule
6285
6375
  }
6286
6376
 
@@ -6308,24 +6398,6 @@ function swiftLinkStamp(args: {
6308
6398
  return hash.digest('hex')
6309
6399
  }
6310
6400
 
6311
- // each scratch holds over a gibibyte, so the least recently built revisions go.
6312
- // a scratch another process holds is skipped.
6313
- async function pruneFrameworkScratches(keep: string): Promise<void> {
6314
- const dir = swiftFrameworksDir()
6315
- const idle = readdirSync(dir)
6316
- .filter((name) => name !== keep)
6317
- .map((name) => ({ name, modified: statSync(path.join(dir, name)).mtimeMs }))
6318
- .sort((left, right) => right.modified - left.modified)
6319
- .slice(SWIFT_FRAMEWORK_SCRATCHES_KEPT - 1)
6320
- for (const { name } of idle)
6321
- await withSwiftRootLock(
6322
- path.join(dir, name),
6323
- async () => rmSync(path.join(dir, name), { recursive: true, force: true }),
6324
- undefined,
6325
- false,
6326
- )
6327
- }
6328
-
6329
6401
  /** the root keeps one app object tree per linked framework build. */
6330
6402
  function retireStaleSwiftLink(root: string, stamp: string): boolean {
6331
6403
  const receipt = path.join(root, SWIFT_LINK_STAMP)
@@ -6493,13 +6565,13 @@ function compileSwiftProjectOnce(
6493
6565
  // roots compiling against it overlap and only its plugin check queues.
6494
6566
  const frameworkScratch = swiftFrameworkScratch(frameworkKey)
6495
6567
  const withFrameworkLock = <T>(
6496
- work: (frameworkLease?: SwiftRootLease) => Promise<T>,
6568
+ work: (slot: string | null, frameworkLease?: SwiftRootLease) => Promise<T>,
6497
6569
  ) =>
6498
6570
  distribution
6499
- ? work()
6500
- : withSwiftRootLock(frameworkScratch, work, options.signal)
6501
- return withFrameworkLock(async (frameworkLease) => {
6502
- const frameworkRoot = stageFrameworkSource(moduleRoot, frameworkKey)
6571
+ ? work(null)
6572
+ : withSwiftFrameworkSlot(frameworkKey, options.signal, work)
6573
+ return withFrameworkLock(async (slot, frameworkLease) => {
6574
+ const frameworkRoot = stageFrameworkSource(moduleRoot, slot, frameworkKey)
6503
6575
  report('preparing compiler plugins')
6504
6576
  const pluginsFor = (pluginLease?: SwiftRootLease) =>
6505
6577
  ensureMacroPlugins(
@@ -6542,7 +6614,7 @@ function compileSwiftProjectOnce(
6542
6614
  let prebuilt: SwiftFrameworkProducts | undefined
6543
6615
  if (!distribution) {
6544
6616
  report('compiling framework products')
6545
- prebuilt = await compileFrameworkProducts({
6617
+ prebuilt = await buildFrameworkProducts(slot!, {
6546
6618
  moduleRoot: frameworkRoot,
6547
6619
  frameworkKey,
6548
6620
  input,
@@ -6552,7 +6624,6 @@ function compileSwiftProjectOnce(
6552
6624
  plugins: macroPlugins,
6553
6625
  buildOptions,
6554
6626
  })
6555
- await pruneFrameworkScratches(frameworkKey)
6556
6627
  }
6557
6628
  if (options.project) removeProjectLinks(root)
6558
6629
  if (
@@ -995,7 +995,10 @@ function readFollyConfig(reactNativeRoot: string) {
995
995
  path.join(reactNativeRoot, 'scripts/cocoapods/helpers.rb'),
996
996
  'utf8',
997
997
  )
998
- const config = /@@folly_config\s*=\s*\{([\s\S]*?)\n\s*\}/.exec(helpers)?.[1]
998
+ const config =
999
+ /(?:@@folly_config\s*=|def self\.folly_config\s+return)\s*\{([\s\S]*?)\n\s*\}/.exec(
1000
+ helpers,
1001
+ )?.[1]
999
1002
  const flags = config && /:compiler_flags\s*=>\s*'([^']*)'/.exec(config)?.[1]
1000
1003
  const lines = config && /:config_file\s*=>\s*\[([\s\S]*?)\]/.exec(config)?.[1]
1001
1004
  if (!flags) throw new Error(`${reactNativeRoot}: helpers.rb has no folly config`)