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
@@ -0,0 +1,527 @@
1
+ // reads an xcode project's application target the way xcode builds it: the
2
+ // swift sources and resources that are members of the target, the local
3
+ // swift packages its products come from, the remote package products it links,
4
+ // and the build settings that change how its swift compiles. never runs xcode
5
+ // or evaluates a build phase; project.pbxproj is data.
6
+
7
+ import fs from 'node:fs'
8
+ import path from 'node:path'
9
+ import { swiftManifestGraph } from './swift-package'
10
+
11
+ type PlistValue = string | PlistValue[] | { [key: string]: PlistValue }
12
+ type PlistDict = { [key: string]: PlistValue }
13
+
14
+ // project.pbxproj is an old-style (openstep) property list: dictionaries,
15
+ // arrays and strings, with c comments. node's plist package reads only xml.
16
+ export function parseOpenStepPlist(text: string): PlistValue {
17
+ let i = 0
18
+ const fail = (message: string): never => {
19
+ const line = text.slice(0, i).split('\n').length
20
+ throw new Error(`project.pbxproj line ${line}: ${message}`)
21
+ }
22
+ const skip = () => {
23
+ for (;;) {
24
+ const ch = text[i]
25
+ if (ch === ' ' || ch === '\t' || ch === '\n' || ch === '\r') i++
26
+ else if (ch === '/' && text[i + 1] === '*') {
27
+ const end = text.indexOf('*/', i + 2)
28
+ if (end < 0) fail('unterminated comment')
29
+ i = end + 2
30
+ } else if (ch === '/' && text[i + 1] === '/') {
31
+ const end = text.indexOf('\n', i)
32
+ i = end < 0 ? text.length : end + 1
33
+ } else return
34
+ }
35
+ }
36
+ const quoted = (): string => {
37
+ i++
38
+ let out = ''
39
+ for (;;) {
40
+ const ch = text[i++]
41
+ if (ch === undefined) fail('unterminated string')
42
+ if (ch === '"') return out
43
+ if (ch !== '\\') {
44
+ out += ch
45
+ continue
46
+ }
47
+ const next = text[i++]
48
+ if (next === 'n') out += '\n'
49
+ else if (next === 't') out += '\t'
50
+ else if (next === 'r') out += '\r'
51
+ else if (next === 'U') {
52
+ out += String.fromCharCode(parseInt(text.slice(i, i + 4), 16))
53
+ i += 4
54
+ } else out += next
55
+ }
56
+ }
57
+ const value = (): PlistValue => {
58
+ skip()
59
+ const ch = text[i]
60
+ if (ch === '{') {
61
+ i++
62
+ const dict: PlistDict = {}
63
+ for (;;) {
64
+ skip()
65
+ if (text[i] === '}') {
66
+ i++
67
+ return dict
68
+ }
69
+ const key = value()
70
+ if (typeof key !== 'string') fail('dictionary key is not a string')
71
+ skip()
72
+ if (text[i++] !== '=') fail('expected =')
73
+ dict[key as string] = value()
74
+ skip()
75
+ if (text[i++] !== ';') fail('expected ;')
76
+ }
77
+ }
78
+ if (ch === '(') {
79
+ i++
80
+ const list: PlistValue[] = []
81
+ for (;;) {
82
+ skip()
83
+ if (text[i] === ')') {
84
+ i++
85
+ return list
86
+ }
87
+ list.push(value())
88
+ skip()
89
+ if (text[i] === ',') i++
90
+ else if (text[i] !== ')') fail('expected , or )')
91
+ }
92
+ }
93
+ if (ch === '"') return quoted()
94
+ const start = i
95
+ while (i < text.length && /[A-Za-z0-9_$+/:.\-<>]/.test(text[i]!)) i++
96
+ if (i === start) fail(`unexpected ${JSON.stringify(ch ?? 'end of file')}`)
97
+ return text.slice(start, i)
98
+ }
99
+ if (text.startsWith('// !$*UTF8*$!')) i = text.indexOf('\n') + 1
100
+ const root = value()
101
+ skip()
102
+ if (i !== text.length) fail('trailing content')
103
+ return root
104
+ }
105
+
106
+ const isDict = (value: PlistValue | undefined): value is PlistDict =>
107
+ typeof value === 'object' && value !== null && !Array.isArray(value)
108
+ const str = (value: PlistValue | undefined): string | undefined =>
109
+ typeof value === 'string' ? value : undefined
110
+ const list = (value: PlistValue | undefined): string[] =>
111
+ Array.isArray(value)
112
+ ? value.filter((item): item is string => typeof item === 'string')
113
+ : []
114
+
115
+ /** a remote package product the target links, as the project names it. */
116
+ export interface XcodeRemoteProduct {
117
+ product: string
118
+ repositoryURL: string
119
+ }
120
+
121
+ /** an application target, resolved to files on disk. */
122
+ export interface XcodeAppTarget {
123
+ /** the directory holding the .xcodeproj: every relative path starts here. */
124
+ projectDir: string
125
+ pbxproj: string
126
+ name: string
127
+ /** the module name the target's sources compile as. */
128
+ moduleName: string
129
+ /** absolute paths of the swift sources that are members of the target. */
130
+ sources: string[]
131
+ /** absolute paths of every resource file the target copies, bundles expanded. */
132
+ resources: string[]
133
+ languageMode: number
134
+ mainActorIsolation: boolean
135
+ /** directories of the local swift packages whose products the target links. */
136
+ localPackages: string[]
137
+ remoteProducts: XcodeRemoteProduct[]
138
+ /** the Package.resolved pinning the remote packages' revisions, when resolved. */
139
+ packageResolved: string | null
140
+ /** linked product names no local or remote package reference supplies. */
141
+ unresolvedProducts: string[]
142
+ /** every application target in the project, for a chooser. */
143
+ appTargets: string[]
144
+ }
145
+
146
+ const APPLICATION = 'com.apple.product-type.application'
147
+ // files xcode never builds into a target even inside a synchronized folder.
148
+ const NEVER_MEMBER =
149
+ /(?:^|\/)(?:Info\.plist|[^/]+\.entitlements|[^/]+\.xcconfig|\.DS_Store)$/
150
+ // directories xcode copies as a whole resource.
151
+ const BUNDLE_DIR =
152
+ /\.(xcassets|bundle|lproj|xcdatamodeld|scnassets|spriteatlas|rcproject|storyboardc|icon)$/
153
+
154
+ function walkFiles(dir: string): string[] {
155
+ if (!fs.existsSync(dir)) return []
156
+ const out: string[] = []
157
+ for (const entry of fs
158
+ .readdirSync(dir, { withFileTypes: true })
159
+ .sort((left, right) => left.name.localeCompare(right.name))) {
160
+ if (entry.name.startsWith('.')) continue
161
+ const full = path.join(dir, entry.name)
162
+ if (entry.isDirectory()) out.push(...walkFiles(full))
163
+ else if (entry.isFile()) out.push(full)
164
+ }
165
+ return out
166
+ }
167
+
168
+ function readXcconfig(file: string, seen = new Set<string>()): Record<string, string> {
169
+ if (seen.has(file) || !fs.existsSync(file)) return {}
170
+ seen.add(file)
171
+ const settings: Record<string, string> = {}
172
+ for (const raw of fs.readFileSync(file, 'utf8').split('\n')) {
173
+ const line = raw.replace(/\/\/.*$/, '').trim()
174
+ const include = /^#include\??\s+"([^"]+)"/.exec(line)
175
+ if (include) {
176
+ Object.assign(
177
+ settings,
178
+ readXcconfig(path.resolve(path.dirname(file), include[1]!), seen),
179
+ )
180
+ continue
181
+ }
182
+ const setting = /^([A-Z_][A-Z0-9_]*)(?:\[[^\]]*\])?\s*=\s*(.*)$/.exec(line)
183
+ if (setting) settings[setting[1]!] = setting[2]!.trim()
184
+ }
185
+ return settings
186
+ }
187
+
188
+ // xcode's c99extidentifier: what PRODUCT_MODULE_NAME defaults to.
189
+ function c99Identifier(name: string): string {
190
+ const id = name.replace(/[^A-Za-z0-9_]/g, '_')
191
+ return /^[0-9]/.test(id) ? `_${id}` : id
192
+ }
193
+
194
+ /** the .xcodeproj a path names: the bundle itself, or the only one in a directory. */
195
+ export function findXcodeProject(input: string): string | null {
196
+ const resolved = path.resolve(input)
197
+ if (resolved.endsWith('.xcodeproj')) return resolved
198
+ if (resolved.endsWith('.xcworkspace')) {
199
+ const data = path.join(resolved, 'contents.xcworkspacedata')
200
+ const projects = fs.existsSync(data)
201
+ ? [
202
+ ...fs
203
+ .readFileSync(data, 'utf8')
204
+ .matchAll(/location\s*=\s*"group:([^"]+\.xcodeproj)"/g),
205
+ ]
206
+ .map((match) => path.resolve(path.dirname(resolved), match[1]!))
207
+ .filter((project) => !project.includes(`${path.sep}Pods${path.sep}`))
208
+ : []
209
+ if (projects.length !== 1) {
210
+ throw new Error(
211
+ `${path.basename(resolved)} lists ${projects.length} app projects; pass the .xcodeproj`,
212
+ )
213
+ }
214
+ return projects[0]!
215
+ }
216
+ if (!fs.existsSync(resolved) || !fs.statSync(resolved).isDirectory()) return null
217
+ const projects = fs.readdirSync(resolved).filter((name) => name.endsWith('.xcodeproj'))
218
+ if (projects.length > 1) {
219
+ throw new Error(
220
+ `${resolved} holds ${projects.length} Xcode projects (${projects.join(', ')}); pass one`,
221
+ )
222
+ }
223
+ return projects.length === 1 ? path.join(resolved, projects[0]!) : null
224
+ }
225
+
226
+ const parsed = new Map<string, { mtimeMs: number; root: PlistDict }>()
227
+
228
+ function readProject(pbxproj: string): PlistDict {
229
+ const mtimeMs = fs.statSync(pbxproj).mtimeMs
230
+ const cached = parsed.get(pbxproj)
231
+ if (cached?.mtimeMs === mtimeMs) return cached.root
232
+ const root = parseOpenStepPlist(fs.readFileSync(pbxproj, 'utf8'))
233
+ if (!isDict(root) || !isDict(root.objects)) {
234
+ throw new Error(`${pbxproj} has no objects table`)
235
+ }
236
+ parsed.set(pbxproj, { mtimeMs, root })
237
+ return root
238
+ }
239
+
240
+ /**
241
+ * the application target `targetName` names (or the project's only one),
242
+ * with its member files listed fresh from disk: a file added to a
243
+ * synchronized folder joins the target without any project change.
244
+ */
245
+ export function readXcodeAppTarget(
246
+ xcodeproj: string,
247
+ targetName?: string,
248
+ ): XcodeAppTarget {
249
+ const pbxproj = path.join(xcodeproj, 'project.pbxproj')
250
+ if (!fs.existsSync(pbxproj)) throw new Error(`${xcodeproj} has no project.pbxproj`)
251
+ const root = readProject(pbxproj)
252
+ const objects = root.objects as PlistDict
253
+ const object = (id: string | undefined): PlistDict | undefined => {
254
+ const found = id === undefined ? undefined : objects[id]
255
+ return isDict(found) ? found : undefined
256
+ }
257
+ const project = object(str(root.rootObject))
258
+ if (!project || project.isa !== 'PBXProject') {
259
+ throw new Error(`${pbxproj} has no PBXProject root`)
260
+ }
261
+ // canonical, so every member path agrees with the host's realpath checks
262
+ const projectDir = fs.realpathSync(
263
+ path.resolve(path.dirname(xcodeproj), str(project.projectDirPath) ?? ''),
264
+ )
265
+
266
+ // every group child's parent, so a "<group>" path resolves up the tree.
267
+ const parent = new Map<string, string>()
268
+ for (const [id, entry] of Object.entries(objects)) {
269
+ if (!isDict(entry)) continue
270
+ if (entry.isa === 'PBXGroup' || entry.isa === 'PBXVariantGroup') {
271
+ for (const child of list(entry.children)) parent.set(child, id)
272
+ }
273
+ }
274
+ const resolvedPaths = new Map<string, string | null>()
275
+ const resolvePath = (id: string): string | null => {
276
+ if (resolvedPaths.has(id)) return resolvedPaths.get(id)!
277
+ const entry = object(id)
278
+ let result: string | null = null
279
+ if (entry) {
280
+ const own = str(entry.path) ?? ''
281
+ const tree = str(entry.sourceTree) ?? '<group>'
282
+ if (tree === '<absolute>') result = own
283
+ else if (tree === 'SOURCE_ROOT') result = path.join(projectDir, own)
284
+ else if (tree === '<group>') {
285
+ const up = parent.get(id)
286
+ const base = up ? resolvePath(up) : projectDir
287
+ result = base === null ? null : path.join(base, own)
288
+ }
289
+ }
290
+ resolvedPaths.set(id, result)
291
+ return result
292
+ }
293
+
294
+ const targets = list(project.targets)
295
+ .map((id) => ({ id, target: object(id) }))
296
+ .filter(
297
+ (entry): entry is { id: string; target: PlistDict } =>
298
+ entry.target?.isa === 'PBXNativeTarget',
299
+ )
300
+ const appTargets = targets.filter((entry) => entry.target.productType === APPLICATION)
301
+ const appTargetNames = appTargets.map((entry) => str(entry.target.name) ?? entry.id)
302
+ const chosen = targetName
303
+ ? appTargets.find((entry) => entry.target.name === targetName)
304
+ : appTargets.length === 1
305
+ ? appTargets[0]
306
+ : undefined
307
+ if (!chosen) {
308
+ throw new Error(
309
+ targetName
310
+ ? `${path.basename(xcodeproj)} has no application target ${targetName}; it has ${appTargetNames.join(', ') || 'none'}`
311
+ : `${path.basename(xcodeproj)} has ${appTargetNames.length} application targets (${appTargetNames.join(', ') || 'none'}); pass --target`,
312
+ )
313
+ }
314
+ const { id: targetId, target } = chosen
315
+
316
+ const configSettings = (listId: string | undefined): Record<string, string> => {
317
+ const configs = list(object(listId)?.buildConfigurations).map(object)
318
+ const config =
319
+ configs.find((entry) => entry?.name === 'Debug') ?? configs.find(Boolean)
320
+ if (!config) return {}
321
+ const base = str(config.baseConfigurationReference)
322
+ const fromFile = base ? readXcconfig(resolvePath(base) ?? '') : {}
323
+ const own = isDict(config.buildSettings) ? config.buildSettings : {}
324
+ return {
325
+ ...fromFile,
326
+ ...Object.fromEntries(
327
+ Object.entries(own).flatMap(([key, value]) =>
328
+ typeof value === 'string' ? [[key, value]] : [],
329
+ ),
330
+ ),
331
+ }
332
+ }
333
+ const settings = {
334
+ ...configSettings(str(project.buildConfigurationList)),
335
+ ...configSettings(str(target.buildConfigurationList)),
336
+ }
337
+ const name = str(target.name) ?? targetId
338
+ const productName = (settings.PRODUCT_NAME ?? '$(TARGET_NAME)')
339
+ .replaceAll('$(TARGET_NAME)', name)
340
+ .replaceAll('${TARGET_NAME}', name)
341
+ const moduleName = c99Identifier(
342
+ settings.PRODUCT_MODULE_NAME && !settings.PRODUCT_MODULE_NAME.includes('$(')
343
+ ? settings.PRODUCT_MODULE_NAME
344
+ : productName,
345
+ )
346
+
347
+ const sources = new Set<string>()
348
+ const resources = new Set<string>()
349
+ const addResource = (file: string) => {
350
+ if (fs.existsSync(file) && fs.statSync(file).isDirectory()) {
351
+ for (const inner of walkFiles(file)) resources.add(inner)
352
+ } else if (fs.existsSync(file)) resources.add(file)
353
+ }
354
+ const fileRefPaths = (refId: string): string[] => {
355
+ const ref = object(refId)
356
+ if (!ref) return []
357
+ if (ref.isa === 'PBXVariantGroup') {
358
+ return list(ref.children).flatMap((child) => {
359
+ const resolved = resolvePath(child)
360
+ return resolved ? [resolved] : []
361
+ })
362
+ }
363
+ const resolved = resolvePath(refId)
364
+ return resolved ? [resolved] : []
365
+ }
366
+ for (const phaseId of list(target.buildPhases)) {
367
+ const phase = object(phaseId)
368
+ if (phase?.isa !== 'PBXSourcesBuildPhase' && phase?.isa !== 'PBXResourcesBuildPhase')
369
+ continue
370
+ for (const buildFileId of list(phase.files)) {
371
+ for (const file of fileRefPaths(str(object(buildFileId)?.fileRef) ?? '')) {
372
+ if (phase.isa === 'PBXSourcesBuildPhase' && file.endsWith('.swift')) {
373
+ if (fs.existsSync(file)) sources.add(file)
374
+ } else if (phase.isa === 'PBXResourcesBuildPhase') addResource(file)
375
+ }
376
+ }
377
+ }
378
+
379
+ // synchronized folders: every file under a folder the target owns is a
380
+ // member, minus that folder's exceptions for this target; a folder the
381
+ // target does not own adds exactly the files its exceptions name for it.
382
+ const addSynchronized = (folder: string, relative: string) => {
383
+ const file = path.join(folder, relative)
384
+ if (NEVER_MEMBER.test(relative)) return
385
+ if (file.endsWith('.swift')) {
386
+ if (!relative.split('/').some((segment) => BUNDLE_DIR.test(segment)))
387
+ sources.add(file)
388
+ } else if (/\.(h|m|mm|c|cpp|metal)$/.test(file)) {
389
+ return
390
+ } else resources.add(file)
391
+ }
392
+ const owned = new Set(list(target.fileSystemSynchronizedGroups))
393
+ for (const [groupId, group] of Object.entries(objects)) {
394
+ if (!isDict(group) || group.isa !== 'PBXFileSystemSynchronizedRootGroup') continue
395
+ const folder = resolvePath(groupId)
396
+ if (!folder) continue
397
+ const exceptions = new Set<string>()
398
+ for (const exceptionId of list(group.exceptions)) {
399
+ const exception = object(exceptionId)
400
+ if (exception?.target !== targetId) continue
401
+ for (const relative of list(exception.membershipExceptions))
402
+ exceptions.add(relative)
403
+ }
404
+ if (owned.has(groupId)) {
405
+ for (const file of walkFiles(folder)) {
406
+ const relative = path.relative(folder, file).split(path.sep).join('/')
407
+ if (
408
+ [...exceptions].some(
409
+ (exception) => relative === exception || relative.startsWith(`${exception}/`),
410
+ )
411
+ )
412
+ continue
413
+ addSynchronized(folder, relative)
414
+ }
415
+ } else {
416
+ for (const relative of exceptions) {
417
+ const file = path.join(folder, relative)
418
+ if (fs.existsSync(file) && fs.statSync(file).isDirectory()) {
419
+ for (const inner of walkFiles(file))
420
+ addSynchronized(
421
+ folder,
422
+ path.relative(folder, inner).split(path.sep).join('/'),
423
+ )
424
+ } else if (fs.existsSync(file)) addSynchronized(folder, relative)
425
+ }
426
+ }
427
+ }
428
+
429
+ // linked products: a remote reference names its repository; one without a
430
+ // package comes from a local package folder the project references.
431
+ const localPackageDirs = Object.entries(objects).flatMap(([id, entry]) => {
432
+ if (!isDict(entry)) return []
433
+ const candidate =
434
+ entry.isa === 'XCLocalSwiftPackageReference'
435
+ ? path.resolve(projectDir, str(entry.relativePath) ?? '')
436
+ : entry.isa === 'PBXFileReference' && entry.lastKnownFileType === 'wrapper'
437
+ ? resolvePath(id)
438
+ : null
439
+ return candidate && fs.existsSync(path.join(candidate, 'Package.swift'))
440
+ ? [candidate]
441
+ : []
442
+ })
443
+ const graphs = new Map<string, ReturnType<typeof swiftManifestGraph>>()
444
+ const graphOf = (dir: string) => {
445
+ const cached = graphs.get(dir)
446
+ if (cached) return cached
447
+ const graph = swiftManifestGraph(
448
+ fs.readFileSync(path.join(dir, 'Package.swift'), 'utf8'),
449
+ )
450
+ graphs.set(dir, graph)
451
+ return graph
452
+ }
453
+ const localProducts = new Map<string, string>()
454
+ for (const dir of localPackageDirs) {
455
+ for (const product of graphOf(dir).products.keys()) localProducts.set(product, dir)
456
+ }
457
+ const localPackages = new Set<string>()
458
+ const remoteProducts: XcodeRemoteProduct[] = []
459
+ const unresolvedProducts: string[] = []
460
+ for (const dependencyId of list(target.packageProductDependencies)) {
461
+ const dependency = object(dependencyId)
462
+ const product = str(dependency?.productName)
463
+ if (!dependency || !product) continue
464
+ const reference = object(str(dependency.package))
465
+ if (reference?.isa === 'XCRemoteSwiftPackageReference') {
466
+ remoteProducts.push({ product, repositoryURL: str(reference.repositoryURL) ?? '' })
467
+ } else if (reference?.isa === 'XCLocalSwiftPackageReference') {
468
+ localPackages.add(path.resolve(projectDir, str(reference.relativePath) ?? ''))
469
+ } else if (localProducts.has(product)) {
470
+ localPackages.add(localProducts.get(product)!)
471
+ } else unresolvedProducts.push(product)
472
+ }
473
+
474
+ // local packages depend on further local packages by path, and on remote
475
+ // products by the package's url.
476
+ const pending = [...localPackages]
477
+ while (pending.length > 0) {
478
+ const dir = pending.pop()!
479
+ const graph = graphOf(dir)
480
+ for (const relative of graph.packagePaths) {
481
+ const next = path.resolve(dir, relative)
482
+ if (localPackages.has(next) || !fs.existsSync(path.join(next, 'Package.swift')))
483
+ continue
484
+ localPackages.add(next)
485
+ pending.push(next)
486
+ }
487
+ for (const dependencies of graph.dependencies.values()) {
488
+ for (const dependency of dependencies) {
489
+ if (dependency.kind !== 'product') continue
490
+ const url = graph.packageURLs.get(dependency.package)
491
+ if (url && !remoteProducts.some((entry) => entry.product === dependency.name))
492
+ remoteProducts.push({ product: dependency.name, repositoryURL: url })
493
+ }
494
+ }
495
+ }
496
+
497
+ // xcode keeps the pins beside the project, or in the workspace that opens it
498
+ const packageResolved =
499
+ [
500
+ path.join(xcodeproj, 'project.xcworkspace'),
501
+ ...fs
502
+ .readdirSync(projectDir)
503
+ .filter((entry) => entry.endsWith('.xcworkspace'))
504
+ .map((entry) => path.join(projectDir, entry)),
505
+ ]
506
+ .map((workspace) =>
507
+ path.join(workspace, 'xcshareddata', 'swiftpm', 'Package.resolved'),
508
+ )
509
+ .find((file) => fs.existsSync(file)) ?? null
510
+
511
+ const swiftVersion = Number.parseFloat(settings.SWIFT_VERSION ?? '5')
512
+ return {
513
+ projectDir,
514
+ pbxproj,
515
+ name,
516
+ moduleName,
517
+ sources: [...sources].sort(),
518
+ resources: [...resources].sort(),
519
+ languageMode: swiftVersion >= 6 ? 6 : 5,
520
+ mainActorIsolation: settings.SWIFT_DEFAULT_ACTOR_ISOLATION === 'MainActor',
521
+ localPackages: [...localPackages].sort(),
522
+ remoteProducts,
523
+ packageResolved,
524
+ unresolvedProducts,
525
+ appTargets: appTargetNames,
526
+ }
527
+ }