peachsim 0.1.729 → 0.1.745

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 (105) hide show
  1. package/cli/bridge-flow-runner.ts +15 -2
  2. package/cli/commands/control.ts +13 -3
  3. package/cli/commands/desktop.ts +1 -0
  4. package/cli/commands/electron.ts +12 -8
  5. package/cli/commands/flow.ts +1 -3
  6. package/cli/commands/install-desktop.ts +105 -66
  7. package/cli/commands/logout.ts +5 -1
  8. package/cli/commands/no-bridge-hint.ts +2 -2
  9. package/cli/commands/swift.ts +26 -9
  10. package/cli/desktop-companion.ts +36 -9
  11. package/cli/drivers/desktop.ts +65 -0
  12. package/cli/drivers/electron.ts +4 -66
  13. package/cli/drivers/index.ts +1 -0
  14. package/cli/drivers/playwright.ts +3 -3
  15. package/cli/drivers/registry.ts +7 -2
  16. package/cli/drivers/types.ts +4 -3
  17. package/cli/maestro-js.ts +10 -0
  18. package/cli/outbound-endpoints.ts +2 -2
  19. package/dist-lib/agent-daemon-client.cjs +1 -1
  20. package/dist-lib/agent-events.cjs +1 -1
  21. package/dist-lib/agent-identity.cjs +1 -1
  22. package/dist-lib/agent-sessions.cjs +1 -1
  23. package/dist-lib/attached-projects.cjs +1 -1
  24. package/dist-lib/auth/shared-session.cjs +39 -9
  25. package/dist-lib/backend-origin.cjs +1 -1
  26. package/dist-lib/beta.cjs +1 -1
  27. package/dist-lib/beta.mjs +1 -1
  28. package/dist-lib/bridge-constants.cjs +1 -1
  29. package/dist-lib/bridge-contract-input.cjs +1 -1
  30. package/dist-lib/bridge-contract-input.mjs +1 -1
  31. package/dist-lib/bridge-contract.cjs +1 -1
  32. package/dist-lib/bridge-contract.mjs +1 -1
  33. package/dist-lib/capture-contract.cjs +13 -19
  34. package/dist-lib/capture-contract.mjs +13 -19
  35. package/dist-lib/cli-constants.cjs +1 -1
  36. package/dist-lib/cloud-contract.cjs +1 -1
  37. package/dist-lib/cloud-contract.mjs +1 -1
  38. package/dist-lib/cloud-test-args.cjs +1 -1
  39. package/dist-lib/cloud-test-args.mjs +1 -1
  40. package/dist-lib/cloud.cjs +1 -1
  41. package/dist-lib/cloud.mjs +1 -1
  42. package/dist-lib/config.cjs +1 -1
  43. package/dist-lib/detox/index.cjs +20 -2
  44. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  45. package/dist-lib/home-paths.cjs +32 -1
  46. package/dist-lib/host/bridge-host.cjs +1617 -533
  47. package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
  48. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  49. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  50. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  51. package/dist-lib/host/websocket-proxy.cjs +1 -1
  52. package/dist-lib/index.cjs +14 -19
  53. package/dist-lib/jump-to-source-babel.cjs +1 -1
  54. package/dist-lib/jump-to-source-native.cjs +1 -1
  55. package/dist-lib/kotlin-host.cjs +1 -1
  56. package/dist-lib/menu.cjs +1 -1
  57. package/dist-lib/menu.mjs +1 -1
  58. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  59. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  60. package/dist-lib/metro-production-bundle.cjs +1 -1
  61. package/dist-lib/metro-production-bundle.mjs +1 -1
  62. package/dist-lib/metro.cjs +1 -1
  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/plist.cjs +1 -1
  68. package/dist-lib/plist.mjs +1 -1
  69. package/dist-lib/profiles.cjs +1 -1
  70. package/dist-lib/public-brand.cjs +1 -1
  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/render-mode.cjs +1 -1
  74. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  75. package/dist-lib/sdk.cjs +2 -1
  76. package/dist-lib/sdk.mjs +2 -1
  77. package/dist-lib/skills.cjs +2307 -1068
  78. package/dist-lib/swift-compile.cjs +318 -61
  79. package/dist-lib/swift-compile.mjs +314 -62
  80. package/dist-lib/swift-package.cjs +146 -9
  81. package/dist-lib/swift-package.mjs +144 -9
  82. package/dist-lib/swift-submit.cjs +2 -2
  83. package/dist-lib/swift-submit.mjs +2 -2
  84. package/dist-lib/swift-toolchain.cjs +1 -1
  85. package/dist-lib/swift.cjs +1 -1
  86. package/dist-lib/vite-swift.cjs +1311 -227
  87. package/dist-lib/vite.cjs +1 -1
  88. package/package.json +1 -1
  89. package/skills/contrast/SKILL.md +1 -1
  90. package/src/auth/shared-session.ts +45 -9
  91. package/src/bridge-constants.ts +7 -7
  92. package/src/capture-contract.ts +18 -33
  93. package/src/desktop-host-delivery.ts +81 -0
  94. package/src/home-paths.ts +30 -0
  95. package/src/host/bridge-host.ts +11 -6
  96. package/src/native-seam-manifest.ts +0 -11
  97. package/src/sim-client.ts +1 -0
  98. package/src/swift-compile.ts +404 -69
  99. package/src/swift-distribution.lock.json +11 -11
  100. package/src/swift-host.ts +316 -43
  101. package/src/swift-package.ts +204 -19
  102. package/src/swift-remote-packages.ts +255 -0
  103. package/src/swift-submit.ts +4 -1
  104. package/src/vite-plugin.ts +19 -8
  105. package/src/xcode-project.ts +527 -0
@@ -34,26 +34,40 @@ export function swiftImplicitResourcePaths(paths: readonly string[]): string[] {
34
34
  .sort()
35
35
  }
36
36
 
37
- /**
38
- * the library and executable targets a sent root manifest declares, in order.
39
- *
40
- * A manifest is Swift code, not data, so this is a scanner, not a parser:
41
- * each `.target(` / `.executableTarget(` call is matched to its balanced
42
- * close paren (string-aware, so a paren inside a literal cannot end it
43
- * early), and `name:` / `path:` are read from the call's own depth only, so
44
- * a nested `.product(name: "SwiftUI", ...)` inside dependencies never wins.
45
- */
46
- export function swiftManifestTargets(
47
- manifest: string,
48
- resourcePaths: readonly string[] = [],
49
- ): SwiftPackageTarget[] {
50
- const implicitResources = swiftImplicitResourcePaths(resourcePaths)
51
- const code = manifest.replace(/\/\*[\s\S]*?\*\//g, '').replace(/\/\/[^\n]*/g, '')
52
- const targets: SwiftPackageTarget[] = []
53
- const pattern = /\.(executableTarget|target)\s*\(/g
37
+ interface ManifestCall {
38
+ kind: string
39
+ /** the call's own depth only: nested calls and their arguments dropped. */
40
+ flat: string
41
+ /** the call's whole argument text. */
42
+ call: string
43
+ }
44
+
45
+ // each top-level `.<kind>(` call in a manifest with comments removed, matched
46
+ // to its balanced close paren. string-aware, so a paren inside a literal cannot end
47
+ // a call early.
48
+ const MANIFEST_DECLARATIONS = [
49
+ 'executableTarget',
50
+ 'testTarget',
51
+ 'binaryTarget',
52
+ 'systemLibrary',
53
+ 'macro',
54
+ 'plugin',
55
+ 'target',
56
+ 'library',
57
+ 'executable',
58
+ 'package',
59
+ ]
60
+
61
+ function manifestCalls(manifest: string, kinds: readonly string[]): ManifestCall[] {
62
+ const code = manifest
63
+ .replace(/\/\*[\s\S]*?\*\//g, '')
64
+ .replace(/(^|[^:"])\/\/[^\n]*/g, '$1')
65
+ const calls: ManifestCall[] = []
66
+ // every declaration kind is scanned, so a `.target(name:)` dependency
67
+ // nested in an unrequested `.testTarget(` is skipped as part of it
68
+ const pattern = new RegExp(`\\.(${MANIFEST_DECLARATIONS.join('|')})\\s*\\(`, 'g')
54
69
  let match: RegExpExecArray | null
55
70
  while ((match = pattern.exec(code)) !== null) {
56
- const executable = match[1] === 'executableTarget'
57
71
  let depth = 1
58
72
  const start = pattern.lastIndex
59
73
  let i = start
@@ -81,6 +95,178 @@ export function swiftManifestTargets(
81
95
  }
82
96
  i++
83
97
  }
98
+ if (kinds.includes(match[1]!))
99
+ calls.push({ kind: match[1]!, flat, call: code.slice(start, i) })
100
+ // declarations never nest, so a call inside one is part of it
101
+ pattern.lastIndex = i
102
+ }
103
+ return calls
104
+ }
105
+
106
+ /** a target dependency: a target of the same package, or another package's product. */
107
+ export type SwiftTargetDependency =
108
+ | { kind: 'target'; name: string }
109
+ | { kind: 'product'; name: string; package: string }
110
+
111
+ /** the parts of a manifest that say which targets a product compiles. */
112
+ export interface SwiftManifestGraph {
113
+ /** library product name to the targets it vends. */
114
+ products: Map<string, string[]>
115
+ /** every target, binary ones included, to its dependencies on iOS. */
116
+ dependencies: Map<string, SwiftTargetDependency[]>
117
+ binaryTargets: Set<string>
118
+ /** `.systemLibrary` targets: c modules the system provides. */
119
+ systemLibraries: Set<string>
120
+ /** `.package(url:)` dependencies, by the name a `.product(package:)` uses. */
121
+ packageURLs: Map<string, string>
122
+ /** `.package(path:)` dependencies, as written. */
123
+ packagePaths: string[]
124
+ }
125
+
126
+ const NAME = /\bname\s*:\s*"([^"]+)"/
127
+
128
+ // the elements of the `[...]` following `label:` at a call's top level.
129
+ function listArgument(call: string, label: string): string[] {
130
+ const start = new RegExp(`\\b${label}\\s*:\\s*\\[`).exec(call)
131
+ if (!start) return []
132
+ const items: string[] = []
133
+ let depth = 0
134
+ let inString = false
135
+ let item = ''
136
+ for (let i = start.index + start[0].length; i < call.length; i++) {
137
+ const ch = call[i]!
138
+ if (inString) {
139
+ item += ch
140
+ if (ch === '"' && call[i - 1] !== '\\') inString = false
141
+ continue
142
+ }
143
+ if (ch === '"') inString = true
144
+ else if (ch === '(' || ch === '[') depth++
145
+ else if (ch === ')' || ch === ']') {
146
+ if (depth === 0) break
147
+ depth--
148
+ } else if (ch === ',' && depth === 0) {
149
+ items.push(item.trim())
150
+ item = ''
151
+ continue
152
+ }
153
+ item += ch
154
+ }
155
+ if (item.trim()) items.push(item.trim())
156
+ return items
157
+ }
158
+
159
+ // swiftpm names a package by its explicit `name:`, else its url's last path
160
+ // component without `.git`; `.product(package:)` may use either spelling.
161
+ export function swiftPackageIdentity(url: string): string {
162
+ return (url.split('/').pop() ?? url).replace(/\.git$/, '').toLowerCase()
163
+ }
164
+
165
+ /** the products, target dependencies and package urls a manifest declares. */
166
+ export function swiftManifestGraph(manifest: string): SwiftManifestGraph {
167
+ const graph: SwiftManifestGraph = {
168
+ products: new Map(),
169
+ dependencies: new Map(),
170
+ binaryTargets: new Set(),
171
+ systemLibraries: new Set(),
172
+ packageURLs: new Map(),
173
+ packagePaths: [],
174
+ }
175
+ for (const { kind, flat, call } of manifestCalls(manifest, [
176
+ 'library',
177
+ 'executableTarget',
178
+ 'target',
179
+ 'binaryTarget',
180
+ 'systemLibrary',
181
+ 'package',
182
+ ])) {
183
+ if (kind === 'package') {
184
+ const local = /\bpath\s*:\s*"([^"]+)"/.exec(flat)?.[1]
185
+ if (local) graph.packagePaths.push(local)
186
+ const url = /\burl\s*:\s*"([^"]+)"/.exec(flat)?.[1]
187
+ if (!url) continue
188
+ graph.packageURLs.set(swiftPackageIdentity(url), url)
189
+ const name = NAME.exec(flat)?.[1]
190
+ if (name) graph.packageURLs.set(name.toLowerCase(), url)
191
+ continue
192
+ }
193
+ const name = NAME.exec(flat)?.[1]
194
+ if (!name) continue
195
+ if (kind === 'library') {
196
+ graph.products.set(
197
+ name,
198
+ listArgument(call, 'targets').flatMap(
199
+ (item) => /^"([^"]+)"$/.exec(item)?.[1] ?? [],
200
+ ),
201
+ )
202
+ continue
203
+ }
204
+ if (kind === 'binaryTarget') graph.binaryTargets.add(name)
205
+ if (kind === 'systemLibrary') graph.systemLibraries.add(name)
206
+ const dependencies: SwiftTargetDependency[] = []
207
+ for (const item of listArgument(call, 'dependencies')) {
208
+ // a dependency conditioned to other platforms never links on iOS
209
+ const platforms = /condition\s*:\s*\.when\(\s*platforms\s*:\s*\[([^\]]*)\]/.exec(
210
+ item,
211
+ )?.[1]
212
+ if (platforms !== undefined && !/\.iOS\b/.test(platforms)) continue
213
+ // a trait-gated dependency is opt-in; default traits are swift code a
214
+ // scanner cannot evaluate, and the gated ones are optional backends
215
+ if (/condition\s*:\s*\.when\([^)]*\btraits\s*:/.test(item)) continue
216
+ const plain = /^"([^"]+)"$/.exec(item)?.[1]
217
+ const product =
218
+ /^\.product(?:Item)?\(\s*name\s*:\s*"([^"]+)"\s*,\s*package\s*:\s*"([^"]+)"/.exec(
219
+ item,
220
+ )
221
+ const target = /^\.(?:target|byName)(?:Item)?\(\s*name\s*:\s*"([^"]+)"/.exec(
222
+ item,
223
+ )?.[1]
224
+ if (plain) dependencies.push({ kind: 'target', name: plain })
225
+ else if (product)
226
+ dependencies.push({
227
+ kind: 'product',
228
+ name: product[1]!,
229
+ package: product[2]!.toLowerCase(),
230
+ })
231
+ else if (target) dependencies.push({ kind: 'target', name: target })
232
+ }
233
+ graph.dependencies.set(name, dependencies)
234
+ }
235
+ // a bare name that is no target here is swiftpm's by-name product: the
236
+ // product of that name in the dependency package of the same name
237
+ for (const dependencies of graph.dependencies.values()) {
238
+ for (const [index, dependency] of dependencies.entries()) {
239
+ if (dependency.kind === 'target' && !graph.dependencies.has(dependency.name))
240
+ dependencies[index] = {
241
+ kind: 'product',
242
+ name: dependency.name,
243
+ package: dependency.name.toLowerCase(),
244
+ }
245
+ }
246
+ }
247
+ return graph
248
+ }
249
+
250
+ /**
251
+ * the library and executable targets a sent root manifest declares, in order.
252
+ *
253
+ * A manifest is Swift code, not data, so this is a scanner, not a parser:
254
+ * each `.target(` / `.executableTarget(` call is matched to its balanced
255
+ * close paren (string-aware, so a paren inside a literal cannot end it
256
+ * early), and `name:` / `path:` are read from the call's own depth only, so
257
+ * a nested `.product(name: "SwiftUI", ...)` inside dependencies never wins.
258
+ */
259
+ export function swiftManifestTargets(
260
+ manifest: string,
261
+ resourcePaths: readonly string[] = [],
262
+ ): SwiftPackageTarget[] {
263
+ const implicitResources = swiftImplicitResourcePaths(resourcePaths)
264
+ const targets: SwiftPackageTarget[] = []
265
+ for (const { kind, flat, call } of manifestCalls(manifest, [
266
+ 'executableTarget',
267
+ 'target',
268
+ ])) {
269
+ const executable = kind === 'executableTarget'
84
270
  const name = /\bname\s*:\s*"([^"]+)"/.exec(flat)?.[1]
85
271
  if (!name) continue
86
272
  const rawPath = /\bpath\s*:\s*"([^"]*)"/.exec(flat)?.[1]
@@ -90,7 +276,6 @@ export function swiftManifestTargets(
90
276
  : rawPath.replace(/^\.\//, '').replace(/\/+$/, '')
91
277
  // settings sit inside nested calls, which `flat` drops, so they are read
92
278
  // from the call's whole text; a dependency list cannot spell either one.
93
- const call = code.slice(start, i)
94
279
  const languageMode = Number(
95
280
  /\.swiftLanguageMode\(\s*\.v(\d+)\s*\)/.exec(call)?.[1] ?? '5',
96
281
  )
@@ -0,0 +1,255 @@
1
+ // the remote swift packages an app links, compiled from source: each package
2
+ // is fetched at the revision the project's Package.resolved pins, into the
3
+ // project's .build/peach/checkouts, and each linked product resolves to the
4
+ // source targets that build it. peach compiles swift source only, so a
5
+ // product reaching a binary or c-family target stays missing, with the reason.
6
+
7
+ import { execFileSync } from 'node:child_process'
8
+ import fs from 'node:fs'
9
+ import path from 'node:path'
10
+ import {
11
+ swiftManifestGraph,
12
+ swiftManifestTargets,
13
+ swiftPackageIdentity,
14
+ type SwiftManifestGraph,
15
+ type SwiftPackageTarget,
16
+ } from './swift-package'
17
+
18
+ export interface RemoteProduct {
19
+ product: string
20
+ repositoryURL: string
21
+ }
22
+
23
+ /** a source target from a remote checkout, its path absolute. */
24
+ export interface RemotePackageTarget extends SwiftPackageTarget {
25
+ dir: string
26
+ /** every file under the target directory. */
27
+ files: string[]
28
+ }
29
+
30
+ export interface RemotePackages {
31
+ targets: RemotePackageTarget[]
32
+ /** linked products peach cannot compile, with why. */
33
+ unavailable: Map<string, { repositoryURL: string; reason: string }>
34
+ }
35
+
36
+ /** where checkouts live, relative to the project directory. */
37
+ export const REMOTE_CHECKOUTS = path.join('.build', 'peach', 'checkouts')
38
+
39
+ interface Pin {
40
+ location: string
41
+ revision: string
42
+ }
43
+
44
+ // sources the swift compile cannot build: c, c++, objective-c and assembly.
45
+ const C_FAMILY = /\.(c|cc|cpp|cxx|m|mm|s|S)$/
46
+
47
+ function readPins(resolved: string): Map<string, Pin> {
48
+ const data: unknown = JSON.parse(fs.readFileSync(resolved, 'utf8'))
49
+ const pins =
50
+ data && typeof data === 'object' && 'pins' in data && Array.isArray(data.pins)
51
+ ? data.pins
52
+ : null
53
+ if (!pins)
54
+ throw new Error(`${resolved} has no pins; resolve packages in a current Xcode`)
55
+ const out = new Map<string, Pin>()
56
+ for (const pin of pins) {
57
+ const identity = pin?.identity
58
+ const location = pin?.location
59
+ const revision = pin?.state?.revision
60
+ if (
61
+ typeof identity === 'string' &&
62
+ typeof location === 'string' &&
63
+ typeof revision === 'string'
64
+ )
65
+ out.set(identity, { location, revision })
66
+ }
67
+ return out
68
+ }
69
+
70
+ function walk(dir: string): string[] {
71
+ if (!fs.existsSync(dir)) return []
72
+ const out: string[] = []
73
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
74
+ if (entry.name.startsWith('.')) continue
75
+ const full = path.join(dir, entry.name)
76
+ if (entry.isDirectory()) out.push(...walk(full))
77
+ else if (entry.isFile()) out.push(full)
78
+ }
79
+ return out.sort()
80
+ }
81
+
82
+ const verified = new Set<string>()
83
+
84
+ // a shallow checkout of exactly the pinned revision, reused while HEAD is it.
85
+ function checkout(checkouts: string, identity: string, pin: Pin): string {
86
+ const dir = path.join(checkouts, identity)
87
+ const key = `${dir}\0${pin.revision}`
88
+ if (verified.has(key)) return dir
89
+ const git = (...args: string[]) =>
90
+ execFileSync('git', ['-C', dir, ...args], {
91
+ encoding: 'utf8',
92
+ stdio: ['ignore', 'pipe', 'pipe'],
93
+ }).trim()
94
+ const current = fs.existsSync(path.join(dir, '.git')) ? git('rev-parse', 'HEAD') : ''
95
+ if (current !== pin.revision) {
96
+ fs.rmSync(dir, { recursive: true, force: true })
97
+ fs.mkdirSync(dir, { recursive: true })
98
+ try {
99
+ git('init', '-q')
100
+ git('fetch', '-q', '--depth', '1', pin.location, pin.revision)
101
+ git('checkout', '-q', 'FETCH_HEAD')
102
+ } catch (error) {
103
+ fs.rmSync(dir, { recursive: true, force: true })
104
+ const stderr =
105
+ error instanceof Error && 'stderr' in error ? String(error.stderr).trim() : ''
106
+ throw new Error(
107
+ `could not fetch ${pin.location} at ${pin.revision}${stderr ? `: ${stderr}` : ''}`,
108
+ )
109
+ }
110
+ }
111
+ verified.add(key)
112
+ return dir
113
+ }
114
+
115
+ /**
116
+ * fetches and resolves `products` against the pins in `resolved`. products
117
+ * named in `provided` are peach modules and link as those instead.
118
+ */
119
+ export function resolveRemotePackages(
120
+ projectDir: string,
121
+ resolved: string | null,
122
+ products: readonly RemoteProduct[],
123
+ provided: ReadonlySet<string>,
124
+ ): RemotePackages {
125
+ const result: RemotePackages = { targets: [], unavailable: new Map() }
126
+ const wanted = products.filter((entry) => !provided.has(entry.product))
127
+ if (wanted.length === 0) return result
128
+ if (!resolved) {
129
+ for (const entry of wanted)
130
+ result.unavailable.set(entry.product, {
131
+ repositoryURL: entry.repositoryURL,
132
+ reason: 'no Package.resolved pins it; resolve packages in Xcode once',
133
+ })
134
+ return result
135
+ }
136
+ const pins = readPins(resolved)
137
+ const checkouts = path.join(projectDir, REMOTE_CHECKOUTS)
138
+ fs.mkdirSync(checkouts, { recursive: true })
139
+ // fetched sources never show up as changes in the app's repository
140
+ fs.writeFileSync(path.join(path.dirname(checkouts), '.gitignore'), '*\n')
141
+
142
+ const packages = new Map<
143
+ string,
144
+ { dir: string; manifest: string; graph: SwiftManifestGraph }
145
+ >()
146
+ const load = (identity: string) => {
147
+ const cached = packages.get(identity)
148
+ if (cached) return cached
149
+ const pin = pins.get(identity)
150
+ if (!pin) return null
151
+ const dir = checkout(checkouts, identity, pin)
152
+ const manifest = fs.readFileSync(path.join(dir, 'Package.swift'), 'utf8')
153
+ const loaded = { dir, manifest, graph: swiftManifestGraph(manifest) }
154
+ packages.set(identity, loaded)
155
+ return loaded
156
+ }
157
+
158
+ const targets = new Map<string, RemotePackageTarget>()
159
+ // product key to the reason it cannot compile, or null once it can
160
+ const outcomes = new Map<string, string | null>()
161
+ const resolveProduct = (identity: string, product: string): string | null => {
162
+ const key = `${identity}\0${product}`
163
+ if (outcomes.has(key)) return outcomes.get(key)!
164
+ outcomes.set(key, null)
165
+ const pkg = load(identity)
166
+ if (!pkg) {
167
+ outcomes.set(key, `package ${identity} is not pinned in Package.resolved`)
168
+ return outcomes.get(key)!
169
+ }
170
+ const roots = pkg.graph.products.get(product)
171
+ if (!roots) {
172
+ outcomes.set(key, `package ${identity} has no library ${product}`)
173
+ return outcomes.get(key)!
174
+ }
175
+ const declared = new Map(
176
+ swiftManifestTargets(pkg.manifest).map((target) => [target.name, target]),
177
+ )
178
+ const reached: SwiftPackageTarget[] = []
179
+ const seen = new Set<string>()
180
+ const pending = [...roots]
181
+ let reason: string | null = null
182
+ while (pending.length > 0 && !reason) {
183
+ const name = pending.pop()!
184
+ if (seen.has(name) || provided.has(name)) continue
185
+ seen.add(name)
186
+ if (pkg.graph.binaryTargets.has(name)) {
187
+ reason = `${name} is a binary framework`
188
+ break
189
+ }
190
+ if (pkg.graph.systemLibraries.has(name)) {
191
+ reason = `${name} is a system C library`
192
+ break
193
+ }
194
+ const target = declared.get(name)
195
+ if (!target) {
196
+ reason = `${identity} declares no target ${name}`
197
+ break
198
+ }
199
+ const files = walk(path.join(pkg.dir, target.path))
200
+ if (files.some((file) => C_FAMILY.test(file))) {
201
+ reason = `${name} is a C or Objective-C target`
202
+ break
203
+ }
204
+ reached.push(target)
205
+ for (const dependency of pkg.graph.dependencies.get(name) ?? []) {
206
+ if (dependency.kind === 'target') pending.push(dependency.name)
207
+ else if (!provided.has(dependency.name)) {
208
+ const url = pkg.graph.packageURLs.get(dependency.package)
209
+ const nested = resolveProduct(
210
+ url ? swiftPackageIdentity(url) : dependency.package,
211
+ dependency.name,
212
+ )
213
+ if (nested) reason = `${dependency.name}: ${nested}`
214
+ }
215
+ }
216
+ }
217
+ if (reason) {
218
+ outcomes.set(key, reason)
219
+ return reason
220
+ }
221
+ // resources need the files each target holds, relative to its package
222
+ const relative = reached.flatMap((target) =>
223
+ walk(path.join(pkg.dir, target.path)).map((file) =>
224
+ path.relative(pkg.dir, file).split(path.sep).join(path.posix.sep),
225
+ ),
226
+ )
227
+ const withResources = new Map(
228
+ swiftManifestTargets(pkg.manifest, relative).map((target) => [target.name, target]),
229
+ )
230
+ for (const target of reached) {
231
+ const dir = path.join(pkg.dir, target.path)
232
+ targets.set(target.name, {
233
+ ...(withResources.get(target.name) ?? target),
234
+ executable: false,
235
+ dir,
236
+ files: walk(dir),
237
+ })
238
+ }
239
+ return null
240
+ }
241
+
242
+ for (const entry of wanted) {
243
+ const reason = resolveProduct(
244
+ swiftPackageIdentity(entry.repositoryURL),
245
+ entry.product,
246
+ )
247
+ if (reason)
248
+ result.unavailable.set(entry.product, {
249
+ repositoryURL: entry.repositoryURL,
250
+ reason,
251
+ })
252
+ }
253
+ result.targets = [...targets.values()]
254
+ return result
255
+ }
@@ -68,8 +68,11 @@ export const MAX_SWIFT_COMPILE_IMAGE_TOTAL_BYTES = 16 * 1024 * 1024
68
68
  * 19: synchronous UIImage/ImageIO bitmap decode, frame sources and context drawing.
69
69
  * 20: peach_codec provides synchronous streaming Brotli and zlib decoders.
70
70
  * 21: the system environment supplies UIKitCore's semantic color components.
71
+ * 22: WebKit script messages carry request ids and receive Promise replies.
72
+ * 23: URLSessionWebSocketTask uses the networking host for real WebSocket transport.
73
+ * 24: WebKit cookie stores share native jars with isolated store lifetimes.
71
74
  */
72
- export const SWIFT_HOST_ABI = 21
75
+ export const SWIFT_HOST_ABI = 24
73
76
 
74
77
  export interface SwiftImageUpload {
75
78
  /** the raster file picked for the asset (has the extension). */
@@ -465,8 +465,9 @@ export function engineShellWorkerPlugins(): Plugin[] {
465
465
  ]
466
466
  }
467
467
 
468
- // admitted coverage repeats prefixes across entries; share their emitted bytes
469
- // while each consumer still receives its own unchanged array.
468
+ // admitted coverage repeats prefixes across entries, and entries repeat the same
469
+ // image records; share their emitted bytes while each consumer still receives
470
+ // its own unchanged array and record.
470
471
  function warmManifestJsonPlugin(): Plugin {
471
472
  const marker = '\0peach:warm-manifest:'
472
473
  return {
@@ -482,12 +483,20 @@ function warmManifestJsonPlugin(): Plugin {
482
483
  this.addWatchFile(filename)
483
484
  const value: unknown = JSON.parse(fs.readFileSync(filename, 'utf8'))
484
485
  const manifest = readPeachWarmManifest(value)
485
- const prefixes = new Map<string, { values: number[]; count: number }>()
486
- for (const entry of [
486
+ const entries = [
487
487
  manifest.home,
488
488
  ...Object.values(manifest.launches),
489
489
  ...Object.values(manifest.screens),
490
- ]) {
490
+ ]
491
+ const imageCounts = new Map<string, number>()
492
+ for (const image of entries.flatMap((entry) => entry.images)) {
493
+ const key = JSON.stringify(image)
494
+ imageCounts.set(key, (imageCounts.get(key) ?? 0) + 1)
495
+ }
496
+ const sharedImages = [...imageCounts].filter(([, count]) => count > 1)
497
+ const sharedImageIndex = new Map(sharedImages.map(([key], index) => [key, index]))
498
+ const prefixes = new Map<string, { values: number[]; count: number }>()
499
+ for (const entry of entries) {
491
500
  for (let length = 1; length <= entry.pipelines.length; length++) {
492
501
  const values = entry.pipelines.slice(0, length)
493
502
  const key = JSON.stringify(values)
@@ -515,6 +524,8 @@ function warmManifestJsonPlugin(): Plugin {
515
524
  return '[' + item.map(serialize).join(',') + ']'
516
525
  }
517
526
  if (isRecord(item)) {
527
+ const image = sharedImageIndex.get(JSON.stringify(item))
528
+ if (image !== undefined) return `{...images[${image}]}`
518
529
  return (
519
530
  '{' +
520
531
  Object.entries(item)
@@ -532,7 +543,7 @@ function warmManifestJsonPlugin(): Plugin {
532
543
  }
533
544
  return JSON.stringify(item)
534
545
  }
535
- const code = `const shared=${JSON.stringify(shared)};const manifest=${serialize(value)};`
546
+ const code = `const shared=${JSON.stringify(shared)};const images=[${sharedImages.map(([key]) => key).join(',')}];const manifest=${serialize(value)};`
536
547
  const reconstructed: unknown = runInNewContext(
537
548
  code + 'manifest',
538
549
  Object.create(null),
@@ -1192,7 +1203,7 @@ function sootsimConfigPlugin(
1192
1203
  ): Plugin {
1193
1204
  return {
1194
1205
  name: 'sootsim-config',
1195
- config(_, { mode }) {
1206
+ config() {
1196
1207
  const fsAllow = ['.']
1197
1208
  for (const src of extraSources) fsAllow.push(src)
1198
1209
  if (appDir) {
@@ -1258,7 +1269,7 @@ function sootsimConfigPlugin(
1258
1269
 
1259
1270
  return {
1260
1271
  define: {
1261
- 'process.env.NODE_ENV': JSON.stringify(mode),
1272
+ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
1262
1273
  'process.env.TEST_NATIVE_PLATFORM': JSON.stringify(''),
1263
1274
  'process.env.TAMAGUI_TARGET': JSON.stringify('native'),
1264
1275
  // expo sdk 57's winter runtime (expo/src/winter/runtime.native.ts)