peachsim 0.1.1886 → 0.1.1888

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 (92) hide show
  1. package/cli/native-input.ts +1 -1
  2. package/dist-lib/agent-daemon-client.cjs +1 -1
  3. package/dist-lib/agent-events.cjs +1 -1
  4. package/dist-lib/attached-projects.cjs +1 -1
  5. package/dist-lib/auth/shared-session.cjs +1 -1
  6. package/dist-lib/backend-origin.cjs +1 -1
  7. package/dist-lib/beta.cjs +1 -1
  8. package/dist-lib/beta.mjs +1 -1
  9. package/dist-lib/bridge-constants.cjs +1 -1
  10. package/dist-lib/bridge-contract-input.cjs +1 -1
  11. package/dist-lib/bridge-contract-input.mjs +1 -1
  12. package/dist-lib/bridge-contract.cjs +1 -1
  13. package/dist-lib/bridge-contract.mjs +1 -1
  14. package/dist-lib/bundle-channel.cjs +208 -83
  15. package/dist-lib/capture-contract.cjs +1 -1
  16. package/dist-lib/capture-contract.mjs +1 -1
  17. package/dist-lib/cloud-contract.cjs +1 -1
  18. package/dist-lib/cloud-contract.mjs +1 -1
  19. package/dist-lib/cloud-test-args.cjs +1 -1
  20. package/dist-lib/cloud-test-args.mjs +1 -1
  21. package/dist-lib/cloud.cjs +1 -1
  22. package/dist-lib/cloud.mjs +1 -1
  23. package/dist-lib/config.cjs +1 -1
  24. package/dist-lib/config.mjs +1 -1
  25. package/dist-lib/detox/index.cjs +5 -3
  26. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  27. package/dist-lib/expo-swift-bundle.cjs +138 -43
  28. package/dist-lib/expo-swift-metadata.cjs +1 -1
  29. package/dist-lib/expo-swift-metadata.mjs +1 -1
  30. package/dist-lib/home-paths.cjs +1 -1
  31. package/dist-lib/host/bridge-host.cjs +149 -25
  32. package/dist-lib/host/fetch-proxy-handler.cjs +2 -2
  33. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  34. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  35. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  36. package/dist-lib/host/websocket-proxy.cjs +1 -1
  37. package/dist-lib/index.cjs +18 -4
  38. package/dist-lib/jump-to-source-babel.cjs +1 -1
  39. package/dist-lib/jump-to-source-native.cjs +1 -1
  40. package/dist-lib/kotlin-host.cjs +1 -1
  41. package/dist-lib/menu.cjs +1 -1
  42. package/dist-lib/menu.mjs +1 -1
  43. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  44. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  45. package/dist-lib/metro-production-bundle.cjs +1 -1
  46. package/dist-lib/metro-production-bundle.mjs +1 -1
  47. package/dist-lib/metro.cjs +18 -4
  48. package/dist-lib/native-app-identity-project.cjs +17 -3
  49. package/dist-lib/native-app-identity-project.mjs +24 -4
  50. package/dist-lib/native-app-identity.cjs +1 -1
  51. package/dist-lib/native-app-identity.mjs +1 -1
  52. package/dist-lib/native-firebase-metadata.cjs +1 -1
  53. package/dist-lib/native-firebase-metadata.mjs +1 -1
  54. package/dist-lib/pdfium-raster.cjs +1 -1
  55. package/dist-lib/pdfium-raster.mjs +1 -1
  56. package/dist-lib/plist.cjs +1 -1
  57. package/dist-lib/plist.mjs +1 -1
  58. package/dist-lib/profiles.cjs +1 -1
  59. package/dist-lib/public-brand.cjs +1 -1
  60. package/dist-lib/public-origins-lib-esm.json +27 -24
  61. package/dist-lib/public-origins-lib.json +70 -53
  62. package/dist-lib/react-native-host-modules.cjs +1 -1
  63. package/dist-lib/react-native-host-modules.mjs +1 -1
  64. package/dist-lib/reap-browser.cjs +1 -1
  65. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  66. package/dist-lib/sdk.cjs +1 -1
  67. package/dist-lib/sdk.mjs +1 -1
  68. package/dist-lib/skills.cjs +185 -43
  69. package/dist-lib/swift-compile.cjs +102 -13
  70. package/dist-lib/swift-compile.mjs +106 -12
  71. package/dist-lib/swift-package.cjs +1 -1
  72. package/dist-lib/swift-package.mjs +1 -1
  73. package/dist-lib/swift-submit.cjs +2 -2
  74. package/dist-lib/swift-submit.mjs +2 -2
  75. package/dist-lib/swift-toolchain.cjs +1 -1
  76. package/dist-lib/swift.cjs +1 -1
  77. package/dist-lib/vite-swift.cjs +118 -19
  78. package/dist-lib/vite.cjs +2 -2
  79. package/dist-lib/worklet-executable.cjs +1 -1
  80. package/dist-lib/worklet-executable.mjs +1 -1
  81. package/package.json +1 -1
  82. package/runtime-companion.json +1 -1
  83. package/src/expo-swift-bundle.ts +2 -7
  84. package/src/expo-swift-ready.ts +5 -2
  85. package/src/nitro-bundle.ts +7 -10
  86. package/src/podspec-sources.ts +20 -0
  87. package/src/swift-compile.ts +11 -5
  88. package/src/swift-host.ts +32 -19
  89. package/src/swift-icu.ts +60 -18
  90. package/src/swift-submit.ts +3 -1
  91. package/src/turbo-bundle.ts +1 -1
  92. package/src/turbo-codegen-intake.ts +10 -3
package/src/swift-host.ts CHANGED
@@ -27,7 +27,9 @@ import {
27
27
  missingSwiftModules,
28
28
  swiftAvailableModules,
29
29
  swiftSystemLibrarySurface,
30
- swiftIcuBrotliQ4,
30
+ swiftIcuAddress,
31
+ swiftIcuBundleAsset,
32
+ swiftIcuPacked,
31
33
  swiftImportNames,
32
34
  swiftPeachModules,
33
35
  withNativeSourceGlue,
@@ -2264,7 +2266,7 @@ export function entryRootId(packagePath: string, file: string): string {
2264
2266
  export function icuUrl(origin: string, artifact: SwiftArtifact): string {
2265
2267
  return 'url' in artifact.icu
2266
2268
  ? artifact.icu.url
2267
- : `${origin}${ICU_PATH}${artifact.icu.sha256}`
2269
+ : `${origin}${ICU_PATH}${swiftIcuAddress(artifact.icu)}`
2268
2270
  }
2269
2271
 
2270
2272
  // a c stand-in whose framework has a WebAssembly build links that library,
@@ -3250,22 +3252,34 @@ export async function serveSwiftPackageAsset(
3250
3252
  for (const project of projects().values()) {
3251
3253
  const icu = project.artifacts.find(
3252
3254
  (artifact) =>
3253
- 'sha256' in artifact.icu && pathname === `${ICU_PATH}${artifact.icu.sha256}`,
3255
+ 'sha256' in artifact.icu &&
3256
+ pathname === `${ICU_PATH}${swiftIcuAddress(artifact.icu)}`,
3254
3257
  )?.icu
3255
- if (!icu || 'url' in icu || pathname !== `${ICU_PATH}${icu.sha256}`) continue
3258
+ if (!icu || 'url' in icu) continue
3256
3259
  // the address is the content, so the browser keeps it across reloads,
3257
- // restarts and every app built with this toolchain
3260
+ // restarts and every app built with this toolchain. the tenant reads
3261
+ // the index and then one pack at a time by range.
3262
+ const packed = await swiftIcuPacked(icu)
3258
3263
  res.setHeader('access-control-allow-origin', '*')
3259
3264
  res.setHeader('cache-control', 'public, max-age=31536000, immutable')
3260
- res.setHeader('vary', 'accept-encoding')
3261
- if (acceptsBr) {
3262
- res.setHeader('content-type', 'application/octet-stream')
3263
- res.setHeader('content-encoding', 'br')
3264
- res.end(await swiftIcuBrotliQ4(icu))
3265
- } else {
3266
- res.setHeader('content-type', 'application/gzip')
3267
- res.end(icu.gzip)
3265
+ res.setHeader('content-type', 'application/octet-stream')
3266
+ res.setHeader('accept-ranges', 'bytes')
3267
+ const range = /^bytes=(\d+)-(\d+)$/.exec(res.req?.headers.range ?? '')
3268
+ if (!range) {
3269
+ res.end(packed)
3270
+ return true
3268
3271
  }
3272
+ const start = Number(range[1])
3273
+ const end = Math.min(Number(range[2]), packed.length - 1)
3274
+ if (start > end) {
3275
+ res.statusCode = 416
3276
+ res.setHeader('content-range', `bytes */${packed.length}`)
3277
+ res.end()
3278
+ return true
3279
+ }
3280
+ res.statusCode = 206
3281
+ res.setHeader('content-range', `bytes ${start}-${end}/${packed.length}`)
3282
+ res.end(packed.subarray(start, end + 1))
3269
3283
  return true
3270
3284
  }
3271
3285
  res.statusCode = 404
@@ -3295,7 +3309,7 @@ export async function serveSwiftPackageAsset(
3295
3309
  }
3296
3310
 
3297
3311
  // packages retain the exact bytes the foreground host serves, including ICU.
3298
- export function swiftPackageAssets(packagePath: string, hash: string) {
3312
+ export async function swiftPackageAssets(packagePath: string, hash: string) {
3299
3313
  const project = projects().get(fs.realpathSync(packagePath))
3300
3314
  const artifact = project?.artifacts.find((candidate) => candidate.hash === hash)
3301
3315
  if (!project || !artifact) throw new Error(`Swift artifact ${hash} was not built`)
@@ -3307,11 +3321,10 @@ export function swiftPackageAssets(packagePath: string, hash: string) {
3307
3321
  ])
3308
3322
  for (const [key, resource] of project.resourceFiles)
3309
3323
  assets.set(`${RESOURCE_PATH}${key}`, resource)
3310
- if ('sha256' in artifact.icu)
3311
- assets.set(`${ICU_PATH}${artifact.icu.sha256}`, {
3312
- bytes: artifact.icu.gzip,
3313
- contentType: 'application/gzip',
3314
- })
3324
+ if ('sha256' in artifact.icu) {
3325
+ const asset = await swiftIcuBundleAsset(artifact.icu)
3326
+ assets.set(`/${asset.path}`, asset)
3327
+ }
3315
3328
  return assets
3316
3329
  }
3317
3330
 
package/src/swift-icu.ts CHANGED
@@ -5,7 +5,14 @@ import { mkdir, readFile, rename, writeFile } from 'node:fs/promises'
5
5
  import os from 'node:os'
6
6
  import path from 'node:path'
7
7
  import { promisify } from 'node:util'
8
- import { brotliCompress, constants as zlibConstants, gunzip, gzip } from 'node:zlib'
8
+ import {
9
+ brotliCompress,
10
+ constants as zlibConstants,
11
+ deflateRawSync,
12
+ gunzip,
13
+ gzip,
14
+ } from 'node:zlib'
15
+ import { SWIFT_ICU_PACKED, swiftIcuPack } from '../../sootsim-swift/src/icuData.ts'
9
16
  import { swiftEnvironment, swiftSdkOptions } from './swift-toolchain.ts'
10
17
 
11
18
  /**
@@ -15,11 +22,11 @@ import { swiftEnvironment, swiftSdkOptions } from './swift-toolchain.ts'
15
22
  * leaves out, so it is exactly the bytes the linker used to place: one blob
16
23
  * per toolchain release.
17
24
  *
18
- * node builtins only: the fixture harnesses import this file straight from
19
- * the checkout.
25
+ * node builtins and plain typescript only: the fixture harnesses import this
26
+ * file straight from the checkout.
20
27
  */
21
28
  export interface SwiftIcuAsset {
22
- /** sha256 of `gzip`, the address a host serves it at. */
29
+ /** sha256 of `gzip`: the blob's content address (swiftIcuAddress). */
23
30
  sha256: string
24
31
  /**
25
32
  * the blob gzipped, for local artifact receipts and clients without brotli
@@ -84,20 +91,6 @@ export function brotliCompressQ4(bytes: Buffer, cacheKey?: string): Promise<Buff
84
91
  return cachedBrotli(bytes, 4, cacheKey)
85
92
  }
86
93
 
87
- export async function swiftIcuBrotli(icu: SwiftIcuAsset): Promise<Buffer> {
88
- return (
89
- brotliMemoryCache.get(`11:${icu.sha256}`) ??
90
- brotliCompressQ11(await inflateGzip(icu.gzip), icu.sha256)
91
- )
92
- }
93
-
94
- export async function swiftIcuBrotliQ4(icu: SwiftIcuAsset): Promise<Buffer> {
95
- return (
96
- brotliMemoryCache.get(`4:${icu.sha256}`) ??
97
- brotliCompressQ4(await inflateGzip(icu.gzip), icu.sha256)
98
- )
99
- }
100
-
101
94
  async function memo<T>(
102
95
  cache: Map<string, T>,
103
96
  key: string,
@@ -219,3 +212,52 @@ function icuSegment(object: Buffer): Buffer {
219
212
  throw new Error(`swift-icu: expected one icu data segment, found ${found.length}`)
220
213
  return found[0]
221
214
  }
215
+
216
+ /**
217
+ * the packed file's name under a host's icu root: the blob's content address
218
+ * and the packed format (packages/sootsim-swift/src/icuData.ts).
219
+ */
220
+ export function swiftIcuAddress(icu: SwiftIcuAsset): string {
221
+ return `${icu.sha256}.${SWIFT_ICU_PACKED}`
222
+ }
223
+
224
+ const packedFiles = new Map<string, Buffer>()
225
+
226
+ /**
227
+ * the blob packed for on-demand reads: an index, the deflated table of
228
+ * contents and each deflated pack. a host serves it as is and answers range
229
+ * requests, so it carries no content encoding.
230
+ */
231
+ export function swiftIcuPacked(icu: SwiftIcuAsset): Promise<Buffer> {
232
+ return memo(packedFiles, icu.sha256, async () => {
233
+ const file = path.join(
234
+ os.homedir(),
235
+ '.peach',
236
+ 'cache',
237
+ 'swift-brotli',
238
+ swiftIcuAddress(icu),
239
+ )
240
+ if (existsSync(file)) return readFile(file)
241
+ const packed = Buffer.from(
242
+ swiftIcuPack(await inflateGzip(icu.gzip), (bytes) =>
243
+ deflateRawSync(bytes, { level: 9 }),
244
+ ),
245
+ )
246
+ await mkdir(path.dirname(file), { recursive: true })
247
+ const tmp = `${file}.${randomUUID()}.tmp`
248
+ await writeFile(tmp, packed)
249
+ await rename(tmp, file)
250
+ return packed
251
+ })
252
+ }
253
+
254
+ /** the packed icu file a bundle carries beside its wasm, at the path its icu url names. */
255
+ export async function swiftIcuBundleAsset(
256
+ icu: SwiftIcuAsset,
257
+ ): Promise<{ path: string; bytes: Buffer; contentType: string }> {
258
+ return {
259
+ path: `__peach/swift-icu/${swiftIcuAddress(icu)}`,
260
+ bytes: await swiftIcuPacked(icu),
261
+ contentType: 'application/octet-stream',
262
+ }
263
+ }
@@ -144,7 +144,9 @@ export const MAX_SWIFT_COMPILE_IMAGE_TOTAL_BYTES = 16 * 1024 * 1024
144
144
  // sysctl hw.model board configuration.
145
145
  // 67: `peach.dyld_image_uuid` supplies the compiled app image identity.
146
146
  // 68: fetch headers replies carry `setCookies`, the response's Set-Cookie list.
147
- export const SWIFT_HOST_ABI = 68
147
+ // 69: `peach.icu_item_v1` replaces `icu_data_v1`: the host fills icu's table of
148
+ // contents and places each item's pack the first time icu opens it.
149
+ export const SWIFT_HOST_ABI = 69
148
150
 
149
151
  export interface SwiftImageUpload {
150
152
  /** the raster file picked for the asset (has the extension). */
@@ -115,7 +115,7 @@ export async function buildTurboBundle(
115
115
  if (!compiled) return null
116
116
  return {
117
117
  metadata: compiled.metadata,
118
- assets: compiled.artifact ? compiledModuleAssets(compiled.artifact) : [],
118
+ assets: compiled.artifact ? await compiledModuleAssets(compiled.artifact) : [],
119
119
  }
120
120
  }
121
121
 
@@ -54,7 +54,6 @@ const RENDERER_PODS = new Set([
54
54
  'React-FabricComponents',
55
55
  'React-FabricImage',
56
56
  'React-RCTFabric',
57
- 'React-RCTFBReactNativeSpec',
58
57
  'React-graphics',
59
58
  'React-rendererdebug',
60
59
  'React-utils',
@@ -67,7 +66,6 @@ const RENDERER_PODS = new Set([
67
66
  'React-runtimescheduler',
68
67
  'React-ImageManager',
69
68
  'React-performancetimeline',
70
- 'React-jsinspectortracing',
71
69
  'React-jsinspector',
72
70
  'React-cxxreact',
73
71
  'React-jserrorhandler',
@@ -76,6 +74,9 @@ const RENDERER_PODS = new Set([
76
74
 
77
75
  // renderer pods added between releases; compile those installed
78
76
  const RENDERER_PODS_VERSIONED = new Set([
77
+ // added after react-native 0.75
78
+ 'React-RCTFBReactNativeSpec',
79
+ 'React-jsinspectortracing',
79
80
  // missing in 0.78, present in 0.81
80
81
  'React-renderercss',
81
82
  'React-oscompat',
@@ -142,7 +143,13 @@ export function installedFabricSources(
142
143
  path.basename(file, '.podspec'),
143
144
  ),
144
145
  )
145
- if (required.length !== (bridgeOnly ? LEGACY_BRIDGE_PODS : RENDERER_PODS).size)
146
+ const expected = [...(bridgeOnly ? LEGACY_BRIDGE_PODS : RENDERER_PODS)].filter(
147
+ (name) => !RENDERER_PODS_VERSIONED.has(name),
148
+ )
149
+ const present = required.filter(
150
+ (file) => !RENDERER_PODS_VERSIONED.has(path.basename(file, '.podspec')),
151
+ )
152
+ if (present.length !== expected.length)
146
153
  throw new Error(`${reactNativeRoot}: installed renderer podspecs are incomplete`)
147
154
  return specs.map((file) => {
148
155
  const directory = path.dirname(file)