peachsim 0.1.758 → 0.1.760

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 (79) 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/agent-identity.cjs +1 -1
  4. package/dist-lib/agent-sessions.cjs +1 -1
  5. package/dist-lib/attached-projects.cjs +1 -1
  6. package/dist-lib/auth/shared-session.cjs +1 -1
  7. package/dist-lib/backend-origin.cjs +1 -1
  8. package/dist-lib/beta.cjs +1 -1
  9. package/dist-lib/beta.mjs +1 -1
  10. package/dist-lib/bridge-constants.cjs +1 -1
  11. package/dist-lib/bridge-contract-input.cjs +1 -1
  12. package/dist-lib/bridge-contract-input.mjs +1 -1
  13. package/dist-lib/bridge-contract.cjs +1 -1
  14. package/dist-lib/bridge-contract.mjs +1 -1
  15. package/dist-lib/capture-contract.cjs +1 -1
  16. package/dist-lib/capture-contract.mjs +1 -1
  17. package/dist-lib/cli-constants.cjs +1 -1
  18. package/dist-lib/cloud-contract.cjs +1 -1
  19. package/dist-lib/cloud-contract.mjs +1 -1
  20. package/dist-lib/cloud-test-args.cjs +1 -1
  21. package/dist-lib/cloud-test-args.mjs +1 -1
  22. package/dist-lib/cloud.cjs +1 -1
  23. package/dist-lib/cloud.mjs +1 -1
  24. package/dist-lib/config.cjs +1 -1
  25. package/dist-lib/detox/index.cjs +1 -1
  26. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  27. package/dist-lib/home-paths.cjs +1 -1
  28. package/dist-lib/host/bridge-host.cjs +1316 -863
  29. package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
  30. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  31. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  32. package/dist-lib/host/replacement-module-handler.cjs +2 -4
  33. package/dist-lib/host/websocket-proxy.cjs +1 -1
  34. package/dist-lib/index.cjs +509 -336
  35. package/dist-lib/jump-to-source-babel.cjs +1 -1
  36. package/dist-lib/jump-to-source-native.cjs +1 -1
  37. package/dist-lib/kotlin-host.cjs +1 -1
  38. package/dist-lib/menu.cjs +1 -1
  39. package/dist-lib/menu.mjs +1 -1
  40. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  41. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  42. package/dist-lib/metro-production-bundle.cjs +1 -1
  43. package/dist-lib/metro-production-bundle.mjs +1 -1
  44. package/dist-lib/metro.cjs +480 -307
  45. package/dist-lib/native-app-identity.cjs +1 -1
  46. package/dist-lib/native-app-identity.mjs +1 -1
  47. package/dist-lib/native-firebase-metadata.cjs +1 -1
  48. package/dist-lib/native-firebase-metadata.mjs +1 -1
  49. package/dist-lib/plist.cjs +1 -1
  50. package/dist-lib/plist.mjs +1 -1
  51. package/dist-lib/profiles.cjs +1 -1
  52. package/dist-lib/public-brand.cjs +1 -1
  53. package/dist-lib/react-native-host-modules.cjs +1 -1
  54. package/dist-lib/react-native-host-modules.mjs +1 -1
  55. package/dist-lib/render-mode.cjs +1 -1
  56. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  57. package/dist-lib/sdk.cjs +1 -1
  58. package/dist-lib/sdk.mjs +1 -1
  59. package/dist-lib/skills.cjs +1637 -1173
  60. package/dist-lib/swift-compile.cjs +1 -1
  61. package/dist-lib/swift-compile.mjs +1 -1
  62. package/dist-lib/swift-package.cjs +1 -110
  63. package/dist-lib/swift-package.mjs +1 -109
  64. package/dist-lib/swift-submit.cjs +1 -1
  65. package/dist-lib/swift-submit.mjs +1 -1
  66. package/dist-lib/swift-toolchain.cjs +1 -1
  67. package/dist-lib/swift.cjs +1 -1
  68. package/dist-lib/vite-swift.cjs +1013 -558
  69. package/dist-lib/vite.cjs +2 -4
  70. package/package.json +1 -1
  71. package/src/host/replacement-module-handler.ts +2 -1
  72. package/src/native-seam-manifest.ts +8 -0
  73. package/src/swift-host.ts +68 -66
  74. package/src/swift-package-manifest.ts +307 -0
  75. package/src/swift-package.ts +2 -135
  76. package/src/swift-packages.ts +341 -0
  77. package/src/xcode-json-project.ts +450 -0
  78. package/src/xcode-project.ts +112 -92
  79. package/src/swift-remote-packages.ts +0 -255
@@ -0,0 +1,450 @@
1
+ // reads xcode's json project format (`project.xcproj`, xcode 27.2) into the
2
+ // object table `project.pbxproj` holds, so one reader serves both formats.
3
+ // the schema is apple's xcode-project-format package (XCSchema): a tree of
4
+ // files that name their own target membership, targets referring to each
5
+ // other by name, settings with `[config=Name]` conditions in their keys, and
6
+ // cross-project references by the referenced project's file in the tree.
7
+ // paths resolve here, so every emitted file reference is absolute or lives in
8
+ // the build products directory.
9
+
10
+ import path from 'node:path'
11
+ import JSON5 from 'json5'
12
+ import type { PlistDict, PlistValue } from './xcode-project'
13
+
14
+ type Json = null | boolean | number | string | Json[] | { [key: string]: Json }
15
+ type JsonObject = { [key: string]: Json }
16
+
17
+ const isObject = (value: Json | undefined): value is JsonObject =>
18
+ typeof value === 'object' && value !== null && !Array.isArray(value)
19
+ const text = (value: Json | undefined): string | undefined =>
20
+ typeof value === 'string' ? value : undefined
21
+ const items = (value: Json | undefined): Json[] => (Array.isArray(value) ? value : [])
22
+
23
+ const PHASE_ISA: Record<string, string> = {
24
+ 'compile-sources': 'PBXSourcesBuildPhase',
25
+ resources: 'PBXResourcesBuildPhase',
26
+ frameworks: 'PBXFrameworksBuildPhase',
27
+ headers: 'PBXHeadersBuildPhase',
28
+ copy: 'PBXCopyFilesBuildPhase',
29
+ script: 'PBXShellScriptBuildPhase',
30
+ }
31
+
32
+ interface TreeNode {
33
+ id: string
34
+ name: string
35
+ /** the directory a child's group-relative path resolves against. */
36
+ dir: string | null
37
+ parent: TreeNode | null
38
+ children: TreeNode[]
39
+ }
40
+
41
+ /** the root of a json project, shaped as parseOpenStepPlist returns a pbxproj. */
42
+ export function readXcodeJsonProject(xcodeproj: string, source: string): PlistDict {
43
+ const json: unknown = JSON5.parse(source)
44
+ if (!isJsonObject(json)) throw new Error(`${xcodeproj}/project.xcproj is not an object`)
45
+ const projectDir = path.dirname(xcodeproj)
46
+ const objects: PlistDict = {}
47
+ let next = 0
48
+ const add = (entry: PlistDict, id?: string): string => {
49
+ const key = id ?? `XCPROJ${(next++).toString(16).toUpperCase().padStart(18, '0')}`
50
+ objects[key] = entry
51
+ return key
52
+ }
53
+
54
+ // a file path's base: `<PROJECT>/`, `<PRODUCTS>/`, `<USER:VAR>/`, absolute,
55
+ // or relative to the enclosing group.
56
+ const locate = (
57
+ raw: string,
58
+ groupDir: string | null,
59
+ ): { sourceTree: string; path: string } | null => {
60
+ if (raw.startsWith('<USER:')) return null
61
+ const base = /^<([A-Z]+)>\/(.*)$/.exec(raw)
62
+ if (base) {
63
+ if (base[1] === 'PROJECT')
64
+ return { sourceTree: '<absolute>', path: path.join(projectDir, base[2]!) }
65
+ if (base[1] === 'PRODUCTS')
66
+ return { sourceTree: 'BUILT_PRODUCTS_DIR', path: base[2]! }
67
+ return null
68
+ }
69
+ const unescaped = raw.replaceAll('\\<', '<')
70
+ if (unescaped.startsWith('/')) return { sourceTree: '<absolute>', path: unescaped }
71
+ if (unescaped.startsWith('~')) return null
72
+ return groupDir === null
73
+ ? null
74
+ : { sourceTree: '<absolute>', path: path.join(groupDir, unescaped) }
75
+ }
76
+
77
+ // the groups and files tree, with each reference's target memberships
78
+ const memberships: { refId: string; entry: Json }[] = []
79
+ const folders: { id: string; folder: JsonObject }[] = []
80
+ const projectFiles: string[] = []
81
+ const root: TreeNode = { id: '', name: '', dir: projectDir, parent: null, children: [] }
82
+ const walk = (entries: Json[], parent: TreeNode): string[] =>
83
+ entries.flatMap((entry) => {
84
+ if (!isObject(entry)) return []
85
+ const kind = text(entry.kind) ?? 'file-reference'
86
+ const raw = text(entry.path) ?? ''
87
+ const located = raw === '' ? null : locate(raw, parent.dir)
88
+ const name = text(entry.name) ?? path.basename(raw)
89
+ const node: TreeNode = { id: '', name, dir: null, parent, children: [] }
90
+ if (kind === 'group' || kind === 'variant-group' || kind === 'version-group') {
91
+ node.dir =
92
+ raw === ''
93
+ ? parent.dir
94
+ : located?.sourceTree === '<absolute>'
95
+ ? located.path
96
+ : null
97
+ const childIds = walk(items(entry.children), node)
98
+ node.id = add(
99
+ kind === 'version-group' && located
100
+ ? {
101
+ isa: 'PBXFileReference',
102
+ ...located,
103
+ lastKnownFileType: 'wrapper.xcdatamodel',
104
+ }
105
+ : {
106
+ isa: kind === 'variant-group' ? 'PBXVariantGroup' : 'PBXGroup',
107
+ children: childIds,
108
+ ...(kind === 'variant-group'
109
+ ? {}
110
+ : { sourceTree: '<absolute>', path: node.dir ?? '' }),
111
+ name,
112
+ },
113
+ text(entry.id),
114
+ )
115
+ } else if (kind === 'folder') {
116
+ node.id = add(
117
+ {
118
+ isa: 'PBXFileSystemSynchronizedRootGroup',
119
+ ...(located ?? { sourceTree: 'SDKROOT', path: raw }),
120
+ },
121
+ text(entry.id),
122
+ )
123
+ folders.push({ id: node.id, folder: entry })
124
+ } else {
125
+ node.id = add(
126
+ {
127
+ isa: 'PBXFileReference',
128
+ ...(located ?? { sourceTree: 'SDKROOT', path: raw }),
129
+ name,
130
+ },
131
+ text(entry.id),
132
+ )
133
+ if (located?.sourceTree === '<absolute>' && located.path.endsWith('.xcodeproj'))
134
+ projectFiles.push(node.id)
135
+ }
136
+ parent.children.push(node)
137
+ for (const membership of items(entry['target-membership'])) {
138
+ if (kind !== 'folder') memberships.push({ refId: node.id, entry: membership })
139
+ }
140
+ return [node.id]
141
+ })
142
+ const mainGroupChildren = walk(items(json.files), root)
143
+ const mainGroup = add({
144
+ isa: 'PBXGroup',
145
+ children: mainGroupChildren,
146
+ sourceTree: '<absolute>',
147
+ path: projectDir,
148
+ })
149
+ root.id = mainGroup
150
+
151
+ // a reference into the tree: `id:<object id>`, or names from the root
152
+ const lookup = (
153
+ reference: Json | undefined,
154
+ from: TreeNode = root,
155
+ ): string | undefined => {
156
+ if (isObject(reference)) {
157
+ const anchor = lookupNode(reference.anchor, root)
158
+ return anchor ? lookup(reference['relative-path'], anchor) : undefined
159
+ }
160
+ if (Array.isArray(reference)) {
161
+ return lookupNode(
162
+ reference
163
+ .map((component) =>
164
+ isObject(component) ? (text(component.name) ?? '') : (text(component) ?? ''),
165
+ )
166
+ .join('/'),
167
+ from,
168
+ )?.id
169
+ }
170
+ return lookupNode(reference, from)?.id
171
+ }
172
+ const lookupNode = (
173
+ reference: Json | undefined,
174
+ from: TreeNode,
175
+ ): TreeNode | undefined => {
176
+ const value = text(reference)
177
+ if (value === undefined) return undefined
178
+ if (value.startsWith('id:')) {
179
+ const id = value.slice(3)
180
+ const find = (node: TreeNode): TreeNode | undefined =>
181
+ node.id === id ? node : node.children.map(find).find(Boolean)
182
+ return find(root)
183
+ }
184
+ let node: TreeNode | undefined = from
185
+ for (const component of value.split('/')) {
186
+ if (!node) return undefined
187
+ node =
188
+ component === '.'
189
+ ? node
190
+ : component === '..'
191
+ ? (node.parent ?? undefined)
192
+ : node.children.find((child) => child.name === component)
193
+ }
194
+ return node
195
+ }
196
+
197
+ // configurations: each carries the level's settings, conditions intact,
198
+ // and its xcconfig as the base configuration reference
199
+ const configurations = items(json.configurations).flatMap((entry) => {
200
+ const name = isObject(entry) ? text(entry.name) : text(entry)
201
+ return name ? [{ name, file: isObject(entry) ? entry.file : undefined }] : []
202
+ })
203
+ const settingsOf = (value: Json | undefined): PlistDict =>
204
+ Object.fromEntries(
205
+ Object.entries(isObject(value) ? value : {}).flatMap(
206
+ ([key, setting]): [string, PlistValue][] =>
207
+ typeof setting === 'string'
208
+ ? [[key, setting]]
209
+ : Array.isArray(setting)
210
+ ? [
211
+ [
212
+ key,
213
+ setting.filter((item): item is string => typeof item === 'string'),
214
+ ],
215
+ ]
216
+ : [],
217
+ ),
218
+ )
219
+ const configurationList = (
220
+ settings: PlistDict,
221
+ specialized: Map<string, Json | undefined>,
222
+ ): string =>
223
+ add({
224
+ isa: 'XCConfigurationList',
225
+ defaultConfigurationName: text(json['default-configuration']) ?? 'Debug',
226
+ buildConfigurations: configurations.map(({ name, file }) => {
227
+ const base = lookup(specialized.has(name) ? specialized.get(name) : file)
228
+ return add({
229
+ isa: 'XCBuildConfiguration',
230
+ name,
231
+ buildSettings: settings,
232
+ ...(base ? { baseConfigurationReference: base } : {}),
233
+ })
234
+ }),
235
+ })
236
+
237
+ // packages, keyed by swiftpm identity: the url's or the package directory's
238
+ // last component, lowercased
239
+ const packageIds = new Map<string, string>()
240
+ for (const entry of items(json.packages)) {
241
+ if (!isObject(entry)) continue
242
+ const repository = text(entry.repository)
243
+ const local = text(entry.path)
244
+ const name =
245
+ local !== undefined
246
+ ? path.basename(path.resolve(path.dirname(xcodeproj), local))
247
+ : path.basename(repository ?? '').replace(/\.git$/, '')
248
+ const id =
249
+ text(entry.kind) === 'local' && local !== undefined
250
+ ? add({ isa: 'XCLocalSwiftPackageReference', relativePath: local })
251
+ : add({ isa: 'XCRemoteSwiftPackageReference', repositoryURL: repository ?? '' })
252
+ packageIds.set(name.toLowerCase(), id)
253
+ }
254
+ const productDependency = (entry: JsonObject): string =>
255
+ add({
256
+ isa: 'XCSwiftPackageProductDependency',
257
+ productName: text(entry['product-name']) ?? '',
258
+ // xcode finds a product by name across packages when none is named
259
+ ...(packageIds.has(text(entry.package)?.toLowerCase() ?? '')
260
+ ? { package: packageIds.get(text(entry.package)!.toLowerCase()) }
261
+ : {}),
262
+ })
263
+
264
+ // a container proxy into another project's target or product
265
+ const proxy = (
266
+ entry: JsonObject,
267
+ remote: string | undefined,
268
+ proxyType: string,
269
+ ): string =>
270
+ add({
271
+ isa: 'PBXContainerItemProxy',
272
+ containerPortal: lookup(entry.project) ?? '',
273
+ proxyType,
274
+ remoteGlobalIDString: remote ?? '',
275
+ remoteInfo: text(entry.target) ?? '',
276
+ })
277
+
278
+ // targets and their phases, keyed by `Target/kind[/name]` for memberships
279
+ const phases = new Map<string, string>()
280
+ const targetIds = new Map<string, string>()
281
+ const targets: { id: string; target: PlistDict; entry: JsonObject }[] = []
282
+ for (const entry of items(json.targets)) {
283
+ if (!isObject(entry)) continue
284
+ const name = text(entry.name) ?? ''
285
+ const productType = text(entry['product-type'])
286
+ const target: PlistDict = {
287
+ isa: text(entry.kind) === 'aggregate' ? 'PBXAggregateTarget' : 'PBXNativeTarget',
288
+ name,
289
+ productName: name,
290
+ productType: productType
291
+ ? `com.apple.product-type.${productType}`
292
+ : (text(entry['full-product-type']) ?? ''),
293
+ buildPhases: [],
294
+ dependencies: [],
295
+ packageProductDependencies: [],
296
+ fileSystemSynchronizedGroups: [],
297
+ }
298
+ const product = lookup(entry.product)
299
+ if (product) target.productReference = product
300
+ const id = add(target, text(entry.id))
301
+ targetIds.set(name, id)
302
+ targets.push({ id, target, entry })
303
+ for (const phase of items(entry['build-phases'])) {
304
+ const kind = isObject(phase) ? text(phase.kind) : text(phase)
305
+ const isa = kind ? PHASE_ISA[kind] : undefined
306
+ if (!kind || !isa) continue
307
+ const phaseName = isObject(phase) ? text(phase.name) : undefined
308
+ const phaseId = add(
309
+ { isa, files: [] },
310
+ isObject(phase) ? text(phase.id) : undefined,
311
+ )
312
+ ;(target.buildPhases as string[]).push(phaseId)
313
+ phases.set([name, kind, phaseName].filter(Boolean).join('/'), phaseId)
314
+ phases.set(`id:${phaseId}`, phaseId)
315
+ }
316
+ }
317
+ const phaseFiles = (
318
+ reference: Json | undefined,
319
+ targetName?: string,
320
+ ): PlistValue[] | null => {
321
+ const value = text(reference)
322
+ if (value === undefined) return null
323
+ const key = value.startsWith('id:') || !targetName ? value : `${targetName}/${value}`
324
+ const phase = objects[phases.get(key) ?? '']
325
+ return phase &&
326
+ typeof phase === 'object' &&
327
+ !Array.isArray(phase) &&
328
+ Array.isArray(phase.files)
329
+ ? phase.files
330
+ : null
331
+ }
332
+ for (const { refId, entry } of memberships) {
333
+ const files = phaseFiles(isObject(entry) ? entry['build-phase'] : entry)
334
+ files?.push(add({ isa: 'PBXBuildFile', fileRef: refId }))
335
+ }
336
+
337
+ for (const { target, entry } of targets) {
338
+ const name = text(entry.name) ?? ''
339
+ target.buildConfigurationList = configurationList(
340
+ settingsOf(entry['build-settings']),
341
+ new Map(
342
+ items(entry['specialized-configurations']).flatMap((configuration) =>
343
+ isObject(configuration) && text(configuration.name)
344
+ ? [[text(configuration.name)!, configuration.file] as const]
345
+ : [],
346
+ ),
347
+ ),
348
+ )
349
+ for (const dependency of items(entry.dependencies)) {
350
+ const kind = isObject(dependency)
351
+ ? (text(dependency.kind) ?? 'localTarget')
352
+ : 'localTarget'
353
+ if (kind === 'package' && isObject(dependency)) {
354
+ ;(target.dependencies as string[]).push(
355
+ add({ isa: 'PBXTargetDependency', productRef: productDependency(dependency) }),
356
+ )
357
+ } else if (kind === 'remoteTarget' && isObject(dependency)) {
358
+ ;(target.dependencies as string[]).push(
359
+ add({
360
+ isa: 'PBXTargetDependency',
361
+ targetProxy: proxy(dependency, text(dependency['target-id']), '1'),
362
+ }),
363
+ )
364
+ } else {
365
+ const local = isObject(dependency) ? text(dependency.target) : text(dependency)
366
+ const id = local ? targetIds.get(local) : undefined
367
+ if (id)
368
+ (target.dependencies as string[]).push(
369
+ add({ isa: 'PBXTargetDependency', target: id }),
370
+ )
371
+ }
372
+ }
373
+ for (const member of items(entry['package-product-members'])) {
374
+ if (!isObject(member)) continue
375
+ const dependency = productDependency(member)
376
+ ;(target.packageProductDependencies as string[]).push(dependency)
377
+ // a target build file: {build-phase, id?, platforms?}
378
+ const buildFile = member['build-phase']
379
+ phaseFiles(isObject(buildFile) ? buildFile['build-phase'] : buildFile, name)?.push(
380
+ add({ isa: 'PBXBuildFile', productRef: dependency }),
381
+ )
382
+ }
383
+ }
384
+
385
+ // products of other projects' targets, linked or copied into this one's phases
386
+ for (const imported of items(json['imported-products'])) {
387
+ if (!isObject(imported)) continue
388
+ const reference = add({
389
+ isa: 'PBXReferenceProxy',
390
+ path: text(imported.name) ?? text(imported.path) ?? '',
391
+ sourceTree: 'BUILT_PRODUCTS_DIR',
392
+ remoteRef: proxy(imported, text(imported['product-id']), '2'),
393
+ })
394
+ for (const membership of items(imported['target-membership'])) {
395
+ phaseFiles(isObject(membership) ? membership['build-phase'] : membership)?.push(
396
+ add({ isa: 'PBXBuildFile', fileRef: reference }),
397
+ )
398
+ }
399
+ }
400
+
401
+ // synchronized folders: owners list the folder, and each target's exception
402
+ // set lists the paths whose membership differs for that target
403
+ for (const { id, folder } of folders) {
404
+ const exceptions: string[] = []
405
+ for (const exception of items(folder['membership-exceptions'])) {
406
+ if (!isObject(exception)) continue
407
+ const target = targetIds.get(text(exception.target) ?? '')
408
+ if (!target) continue
409
+ exceptions.push(
410
+ add({
411
+ isa: 'PBXFileSystemSynchronizedBuildFileExceptionSet',
412
+ target,
413
+ membershipExceptions: [
414
+ ...items(exception.exclusions),
415
+ ...items(exception.inclusions),
416
+ ].flatMap((member) => (typeof member === 'string' ? [member] : [])),
417
+ }),
418
+ )
419
+ }
420
+ const group = objects[id]
421
+ if (group && typeof group === 'object' && !Array.isArray(group))
422
+ group.exceptions = exceptions
423
+ for (const owner of items(folder['target-membership'])) {
424
+ const target = targets.find(
425
+ (candidate) => candidate.id === targetIds.get(text(owner) ?? ''),
426
+ )
427
+ ;(target?.target.fileSystemSynchronizedGroups as string[] | undefined)?.push(id)
428
+ }
429
+ }
430
+
431
+ const localizations = isObject(json.localizations) ? json.localizations : {}
432
+ const project = add({
433
+ isa: 'PBXProject',
434
+ mainGroup,
435
+ projectDirPath: '',
436
+ developmentRegion: text(localizations.development) ?? 'en',
437
+ buildConfigurationList: configurationList(
438
+ settingsOf(json['build-settings']),
439
+ new Map(),
440
+ ),
441
+ targets: targets.map((entry) => entry.id),
442
+ packageReferences: [...packageIds.values()],
443
+ projectReferences: projectFiles.map((ProjectRef) => ({ ProjectRef })),
444
+ })
445
+ return { objects, rootObject: project }
446
+ }
447
+
448
+ function isJsonObject(value: unknown): value is JsonObject {
449
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
450
+ }