peachsim 0.1.2430 → 0.1.2431

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 (104) hide show
  1. package/cli/commands/preview.ts +2 -1
  2. package/cli/outbound-endpoints.ts +10 -2
  3. package/dist-lib/agent-daemon-client.cjs +1 -1
  4. package/dist-lib/agent-events.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/bundle-channel.cjs +15765 -5973
  16. package/dist-lib/capture-contract.cjs +1 -1
  17. package/dist-lib/capture-contract.mjs +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/config.mjs +1 -1
  26. package/dist-lib/detox/index.cjs +1 -1
  27. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  28. package/dist-lib/expo-swift-bundle.cjs +14638 -4888
  29. package/dist-lib/expo-swift-metadata.cjs +1 -1
  30. package/dist-lib/expo-swift-metadata.mjs +1 -1
  31. package/dist-lib/home-paths.cjs +1 -1
  32. package/dist-lib/host/bridge-host.cjs +15464 -5754
  33. package/dist-lib/host/fetch-proxy-handler.cjs +3204 -54
  34. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  35. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  36. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  37. package/dist-lib/host/websocket-proxy.cjs +1 -1
  38. package/dist-lib/index.cjs +3541 -391
  39. package/dist-lib/jump-to-source-babel.cjs +1 -1
  40. package/dist-lib/jump-to-source-native.cjs +1 -1
  41. package/dist-lib/kotlin-host.cjs +1 -1
  42. package/dist-lib/menu.cjs +1 -1
  43. package/dist-lib/menu.mjs +1 -1
  44. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  45. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  46. package/dist-lib/metro-production-bundle.cjs +1 -1
  47. package/dist-lib/metro-production-bundle.mjs +1 -1
  48. package/dist-lib/metro.cjs +3437 -287
  49. package/dist-lib/native-app-identity-project.cjs +2 -2
  50. package/dist-lib/native-app-identity-project.mjs +2 -2
  51. package/dist-lib/native-app-identity.cjs +1 -1
  52. package/dist-lib/native-app-identity.mjs +1 -1
  53. package/dist-lib/native-firebase-metadata.cjs +1 -1
  54. package/dist-lib/native-firebase-metadata.mjs +1 -1
  55. package/dist-lib/pdfium-raster.cjs +1 -1
  56. package/dist-lib/pdfium-raster.mjs +1 -1
  57. package/dist-lib/plist.cjs +1 -1
  58. package/dist-lib/plist.mjs +1 -1
  59. package/dist-lib/profiles.cjs +1 -1
  60. package/dist-lib/public-brand.cjs +1 -1
  61. package/dist-lib/public-origins-lib-esm.json +24 -24
  62. package/dist-lib/public-origins-lib.json +172 -79
  63. package/dist-lib/react-native-host-modules.cjs +1 -1
  64. package/dist-lib/react-native-host-modules.mjs +1 -1
  65. package/dist-lib/reap-browser.cjs +1 -1
  66. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  67. package/dist-lib/sdk.cjs +1 -1
  68. package/dist-lib/sdk.mjs +1 -1
  69. package/dist-lib/skills.cjs +16782 -6989
  70. package/dist-lib/swift-compile.cjs +2 -2
  71. package/dist-lib/swift-compile.mjs +2 -2
  72. package/dist-lib/swift-package.cjs +1 -1
  73. package/dist-lib/swift-package.mjs +1 -1
  74. package/dist-lib/swift-submit.cjs +1 -1
  75. package/dist-lib/swift-submit.mjs +1 -1
  76. package/dist-lib/swift-toolchain.cjs +1 -1
  77. package/dist-lib/swift.cjs +1 -1
  78. package/dist-lib/vite-swift.cjs +74 -6
  79. package/dist-lib/vite.cjs +3331 -181
  80. package/dist-lib/worklet-executable.cjs +1 -1
  81. package/dist-lib/worklet-executable.mjs +1 -1
  82. package/package.json +1 -1
  83. package/src/expo-native-workspace.ts +23 -63
  84. package/src/pbx-table.ts +200 -0
  85. package/src/pod-sources.ts +628 -0
  86. package/src/podfile-cocoapods.ts +40 -3
  87. package/src/pods-analysis.ts +488 -0
  88. package/src/pods-build-settings.ts +1015 -0
  89. package/src/pods-files.ts +478 -0
  90. package/src/pods-install.ts +475 -0
  91. package/src/pods-integration.ts +778 -0
  92. package/src/pods-post-install.ts +1811 -0
  93. package/src/pods-project.ts +2416 -0
  94. package/src/pods-scripts.ts +409 -0
  95. package/src/pods-targets.ts +757 -0
  96. package/src/pods-xcconfig.ts +198 -0
  97. package/src/podspec-cocoapods.ts +29 -3
  98. package/src/podspec-ruby-stdlib.ts +111 -10
  99. package/src/podspec-ruby.ts +52 -8
  100. package/src/swift-catalog-png.ts +75 -0
  101. package/src/swift-host.ts +4 -3
  102. package/src/swift-root-lock.ts +0 -10
  103. package/src/swift-source-pods.ts +29 -73
  104. package/src/turbo-source.ts +16 -37
@@ -0,0 +1,757 @@
1
+ // CocoaPods 1.17's Target, PodTarget, AggregateTarget and Sandbox::HeadersStore
2
+ // over the analysis the Podfile's interpreter exported (MIT, Eloy Durán and the
3
+ // CocoaPods team), kept to what generating the pod targets reads.
4
+ import { existsSync } from 'node:fs'
5
+ import path from 'node:path'
6
+ import {
7
+ type AnalyzedAggregateTarget,
8
+ type AnalyzedPodTarget,
9
+ type PodSpec,
10
+ } from './pods-analysis'
11
+ import { FileAccessor, PathList, XCFramework } from './pods-files'
12
+
13
+ export type ConfigurationType = 'debug' | 'release'
14
+
15
+ export const CONFIGURATION_BUILD_DIR_VARIABLE = '${PODS_CONFIGURATION_BUILD_DIR}'
16
+
17
+ // Pathname#relative_path_from, which is lexical
18
+ export const relativePath = (to: string, from: string) => path.relative(from, to) || '.'
19
+
20
+ export const c99extIdentifier = (name: string) =>
21
+ name.replace(/^([0-9])/, '_$1').replace(/[^a-zA-Z0-9_]/g, '_')
22
+
23
+ /** a header link `pod install` writes: the link's path below the sandbox, and its relative target. */
24
+ export interface HeaderLink {
25
+ link: string
26
+ target: string
27
+ }
28
+
29
+ export class HeadersStore {
30
+ readonly #searchPaths: { platform: string; path: string }[] = []
31
+ readonly links: HeaderLink[] = []
32
+
33
+ constructor(
34
+ readonly sandbox: Sandbox,
35
+ readonly relativePath: 'Public' | 'Private',
36
+ readonly scope: 'public' | 'private',
37
+ ) {}
38
+
39
+ get root(): string {
40
+ return path.join(this.sandbox.headersRoot, this.relativePath)
41
+ }
42
+
43
+ searchPaths(
44
+ platform: string,
45
+ targetName: string | null = null,
46
+ useModularHeaders = false,
47
+ ): string[] {
48
+ const headersDir = path.dirname(relativePath(this.root, this.sandbox.root))
49
+ const paths = this.#searchPaths
50
+ .filter(
51
+ (entry) =>
52
+ entry.platform === platform &&
53
+ (targetName === null || path.basename(entry.path) === targetName),
54
+ )
55
+ .flatMap((entry) => [
56
+ ...(!useModularHeaders || this.scope === 'public'
57
+ ? [`\${PODS_ROOT}/${headersDir}/${this.relativePath}`]
58
+ : []),
59
+ ...(!useModularHeaders || this.scope === 'private'
60
+ ? [`\${PODS_ROOT}/${headersDir}/${entry.path}`]
61
+ : []),
62
+ ])
63
+ return [...new Set(paths)]
64
+ }
65
+
66
+ addFiles(namespace: string, headers: string[]): void {
67
+ const namespaced = path.join(this.root, namespace)
68
+ for (const header of headers)
69
+ this.links.push({
70
+ link: relativePath(
71
+ path.join(namespaced, path.basename(header)),
72
+ this.sandbox.root,
73
+ ),
74
+ target: relativePath(path.resolve(this.sandbox.root, header), namespaced),
75
+ })
76
+ }
77
+
78
+ addSearchPath(searchPath: string, platform: string): void {
79
+ this.#searchPaths.push({
80
+ platform,
81
+ path: path.join(this.relativePath, searchPath),
82
+ })
83
+ }
84
+ }
85
+
86
+ export class Sandbox {
87
+ readonly publicHeaders: HeadersStore
88
+
89
+ /** `root` is where `pod install` keeps Pods; `podDir` names each downloaded pod's directory. */
90
+ constructor(
91
+ readonly root: string,
92
+ readonly downloadedPodDir: (name: string) => string,
93
+ ) {
94
+ this.publicHeaders = new HeadersStore(this, 'Public', 'public')
95
+ }
96
+
97
+ get headersRoot(): string {
98
+ return path.join(this.root, 'Headers')
99
+ }
100
+
101
+ get projectPath(): string {
102
+ return path.join(this.root, 'Pods.xcodeproj')
103
+ }
104
+
105
+ targetSupportFilesDir(name: string): string {
106
+ return path.join(this.root, 'Target Support Files', name)
107
+ }
108
+ }
109
+
110
+ // Pod::Version's numeric segments, as PodTarget#version joins them
111
+ function versionTriple(version: string): string {
112
+ const numbers = version
113
+ .split('-')[0]!
114
+ .split('.')
115
+ .map((part) => Number.parseInt(part, 10) || 0)
116
+ return [numbers[0] ?? 0, numbers[1] ?? 0, numbers[2] ?? 0].join('.')
117
+ }
118
+
119
+ abstract class Target {
120
+ abstract readonly label: string
121
+ abstract readonly framework: boolean
122
+ abstract readonly dynamic: boolean
123
+
124
+ constructor(
125
+ readonly sandbox: Sandbox,
126
+ readonly platform: { name: string; deploymentTarget: string },
127
+ readonly userBuildConfigurations: Record<string, ConfigurationType>,
128
+ ) {}
129
+
130
+ get name(): string {
131
+ return this.label
132
+ }
133
+ get buildAsFramework() {
134
+ return this.framework
135
+ }
136
+ get buildAsLibrary() {
137
+ return !this.framework
138
+ }
139
+ get buildAsDynamic() {
140
+ return this.dynamic
141
+ }
142
+ get buildAsStatic() {
143
+ return !this.dynamic
144
+ }
145
+ get buildAsDynamicFramework() {
146
+ return this.dynamic && this.framework
147
+ }
148
+ get buildAsStaticFramework() {
149
+ return !this.dynamic && this.framework
150
+ }
151
+ get buildAsDynamicLibrary() {
152
+ return this.dynamic && !this.framework
153
+ }
154
+ get buildAsStaticLibrary() {
155
+ return !this.dynamic && !this.framework
156
+ }
157
+ get productModuleName(): string {
158
+ return c99extIdentifier(this.label)
159
+ }
160
+ get productName(): string {
161
+ return this.framework ? this.frameworkName : this.staticLibraryName
162
+ }
163
+ get productBasename(): string {
164
+ return this.framework ? this.productModuleName : this.label
165
+ }
166
+ get frameworkName(): string {
167
+ return `${this.productModuleName}.framework`
168
+ }
169
+ get staticLibraryName(): string {
170
+ return `lib${this.label}.a`
171
+ }
172
+ get supportFilesDir(): string {
173
+ return this.sandbox.targetSupportFilesDir(this.name)
174
+ }
175
+ xcconfigPath(variant?: string): string {
176
+ return path.join(
177
+ this.supportFilesDir,
178
+ variant
179
+ ? `${this.label}.${variant.replaceAll('/', '-').toLowerCase()}.xcconfig`
180
+ : `${this.label}.xcconfig`,
181
+ )
182
+ }
183
+ get moduleMapPath(): string {
184
+ return path.join(this.supportFilesDir, `${this.label}.modulemap`)
185
+ }
186
+ get umbrellaHeaderPath(): string {
187
+ return path.join(path.dirname(this.moduleMapPath), `${this.label}-umbrella.h`)
188
+ }
189
+ get infoPlistPath(): string {
190
+ return path.join(this.supportFilesDir, `${this.label}-Info.plist`)
191
+ }
192
+ get dummySourcePath(): string {
193
+ return path.join(this.supportFilesDir, `${this.label}-dummy.m`)
194
+ }
195
+ /** the configuration types the user's configurations map to, debug and release when none. */
196
+ get configVariants(): ConfigurationType[] {
197
+ const types = Object.values(this.userBuildConfigurations)
198
+ return types.length === 0 ? ['debug', 'release'] : [...new Set(types)]
199
+ }
200
+ }
201
+
202
+ export interface FrameworkPaths {
203
+ sourcePath: string
204
+ dsymPath: string | null
205
+ bcsymbolmapPaths: string[] | null
206
+ }
207
+
208
+ export class PodTarget extends Target {
209
+ readonly label: string
210
+ readonly framework: boolean
211
+ readonly dynamic: boolean
212
+ readonly specs: PodSpec[]
213
+ readonly fileAccessors: FileAccessor[]
214
+ readonly buildHeaders: HeadersStore
215
+ dependentTargetsByConfig: Record<ConfigurationType, PodTarget[]> = {
216
+ debug: [],
217
+ release: [],
218
+ }
219
+
220
+ constructor(
221
+ sandbox: Sandbox,
222
+ userBuildConfigurations: Record<string, ConfigurationType>,
223
+ readonly analyzed: AnalyzedPodTarget,
224
+ pathLists: Map<string, PathList>,
225
+ ) {
226
+ super(sandbox, analyzed.platform, userBuildConfigurations)
227
+ this.label = analyzed.label
228
+ this.framework = analyzed.framework
229
+ this.dynamic = analyzed.dynamic
230
+ this.specs = analyzed.specs
231
+ this.buildHeaders = new HeadersStore(sandbox, 'Private', 'private')
232
+ const root = this.podDir
233
+ let pathList = pathLists.get(root)
234
+ if (!pathList) {
235
+ pathList = new PathList(root)
236
+ pathLists.set(root, pathList)
237
+ }
238
+ const list = pathList
239
+ this.fileAccessors = this.specs.map(
240
+ (spec) => new FileAccessor(list, spec.name, spec.consumer),
241
+ )
242
+ }
243
+
244
+ get podName(): string {
245
+ return this.analyzed.name
246
+ }
247
+ get podDir(): string {
248
+ return this.analyzed.local ?? this.sandbox.downloadedPodDir(this.podName)
249
+ }
250
+ get rootSpec(): PodSpec {
251
+ const root = this.specs.find((spec) => spec.root)
252
+ if (root) return root
253
+ return {
254
+ name: this.podName,
255
+ root: true,
256
+ deploymentTarget: this.specs[0]!.deploymentTarget,
257
+ consumer: this.specs[0]!.consumer,
258
+ }
259
+ }
260
+ get librarySpecs(): PodSpec[] {
261
+ return this.specs
262
+ }
263
+ override get productModuleName(): string {
264
+ return this.analyzed.moduleName
265
+ }
266
+ get version(): string {
267
+ return versionTriple(this.analyzed.version)
268
+ }
269
+ get swiftVersion(): string | null {
270
+ return this.analyzed.swiftVersion
271
+ }
272
+ get specSwiftVersions(): string[] {
273
+ return this.analyzed.swiftVersions
274
+ }
275
+ get inhibitWarnings(): boolean {
276
+ return this.analyzed.inhibitWarnings
277
+ }
278
+ get headersSandbox(): string {
279
+ return this.podName
280
+ }
281
+ get dependentTargets(): PodTarget[] {
282
+ return [
283
+ ...new Set([
284
+ ...this.dependentTargetsByConfig.debug,
285
+ ...this.dependentTargetsByConfig.release,
286
+ ]),
287
+ ]
288
+ }
289
+
290
+ #shouldBuild: boolean | undefined
291
+ get shouldBuild(): boolean {
292
+ if (this.#shouldBuild === undefined) {
293
+ const headers = new Set(this.fileAccessors.flatMap((fa) => fa.headers))
294
+ this.#shouldBuild = this.fileAccessors
295
+ .flatMap((fa) => fa.sourceFiles)
296
+ .some((file) => !headers.has(file))
297
+ }
298
+ return this.#shouldBuild
299
+ }
300
+
301
+ #usesSwift: boolean | undefined
302
+ get usesSwift(): boolean {
303
+ this.#usesSwift ??=
304
+ (!this.shouldBuild && this.specSwiftVersions.length > 0) ||
305
+ this.fileAccessors.some((fa) => this.usesSwiftForSpec(fa.specName))
306
+ return this.#usesSwift
307
+ }
308
+
309
+ #swiftBySpec = new Map<string, boolean>()
310
+ usesSwiftForSpec(specName: string): boolean {
311
+ let uses = this.#swiftBySpec.get(specName)
312
+ if (uses === undefined) {
313
+ const accessor = this.fileAccessors.find((fa) => fa.specName === specName)
314
+ if (!accessor)
315
+ throw new Error(`no file accessor for ${specName} in pod target ${this.label}`)
316
+ uses = accessor.sourceFiles.some((file) => path.extname(file) === '.swift')
317
+ this.#swiftBySpec.set(specName, uses)
318
+ }
319
+ return uses
320
+ }
321
+
322
+ get definesModule(): boolean {
323
+ if (this.usesSwift || this.framework) return true
324
+ if (this.analyzed.buildPodAsModule) return true
325
+ return this.specs.some(
326
+ (spec) => spec.consumer.pod_target_xcconfig.DEFINES_MODULE === 'YES',
327
+ )
328
+ }
329
+
330
+ usesModularHeaders(onlyIfDefinesModules = true): boolean {
331
+ if (onlyIfDefinesModules && !this.definesModule) return false
332
+ return this.specs.every(
333
+ (spec) => !spec.consumer.header_mappings_dir && !spec.consumer.header_dir,
334
+ )
335
+ }
336
+
337
+ #headerMappings(accessor: FileAccessor, headers: string[]): Map<string, string[]> {
338
+ const { header_mappings_dir: mappingsDir, header_dir: headerDir } = accessor.consumer
339
+ const dir = headerDir
340
+ ? path.join(this.headersSandbox, headerDir)
341
+ : this.headersSandbox
342
+ const mappings = new Map<string, string[]>()
343
+ for (const header of headers) {
344
+ if (header.includes('.framework/')) continue
345
+ const sub = mappingsDir
346
+ ? path.join(
347
+ dir,
348
+ path.dirname(relativePath(header, path.join(accessor.root, mappingsDir))),
349
+ )
350
+ : dir
351
+ const list = mappings.get(sub)
352
+ if (list) list.push(header)
353
+ else mappings.set(sub, [header])
354
+ }
355
+ return mappings
356
+ }
357
+
358
+ get headerMappingsByFileAccessor(): Map<string, string[]>[] {
359
+ return this.fileAccessors.map((fa) => this.#headerMappings(fa, fa.headers))
360
+ }
361
+
362
+ get publicHeaderMappingsByFileAccessor(): Map<string, string[]>[] {
363
+ return this.fileAccessors.map((fa) => this.#headerMappings(fa, fa.publicHeaders()))
364
+ }
365
+
366
+ #recursive = new Map<ConfigurationType | null, PodTarget[]>()
367
+ recursiveDependentTargets(configuration: ConfigurationType | null = null): PodTarget[] {
368
+ if (this.#recursive.size === 0) {
369
+ const byConfig = this.configVariants.map(
370
+ (config): [ConfigurationType, PodTarget[]] => {
371
+ const seen = new Set<PodTarget>()
372
+ const add = (target: PodTarget) => {
373
+ for (const dependency of target.dependentTargetsByConfig[config])
374
+ if (!seen.has(dependency)) {
375
+ seen.add(dependency)
376
+ add(dependency)
377
+ }
378
+ }
379
+ add(this)
380
+ seen.delete(this)
381
+ return [config, [...seen]]
382
+ },
383
+ )
384
+ for (const [config, targets] of byConfig) this.#recursive.set(config, targets)
385
+ this.#recursive.set(null, [...new Set(byConfig.flatMap(([, targets]) => targets))])
386
+ }
387
+ const found = this.#recursive.get(configuration)
388
+ if (!found) throw new Error(`No configuration ${configuration} for ${this.label}`)
389
+ return found
390
+ }
391
+
392
+ configurationBuildDir(dir = CONFIGURATION_BUILD_DIR_VARIABLE): string {
393
+ return `${dir}/${this.label}`
394
+ }
395
+
396
+ buildProductPath(dir = CONFIGURATION_BUILD_DIR_VARIABLE): string {
397
+ return `${this.configurationBuildDir(dir)}/${this.productName}`
398
+ }
399
+
400
+ get podTargetSrcroot(): string {
401
+ return `\${PODS_ROOT}/${relativePath(this.podDir, this.sandbox.root)}`
402
+ }
403
+
404
+ headerSearchPaths(
405
+ options: {
406
+ includePrivateHeaders?: boolean
407
+ configuration?: ConfigurationType | null
408
+ } = {},
409
+ ): string[] {
410
+ const paths: string[] = []
411
+ if (options.includePrivateHeaders !== false)
412
+ paths.push(...this.buildHeaders.searchPaths(this.platform.name, null, false))
413
+ paths.push(
414
+ ...this.sandbox.publicHeaders.searchPaths(
415
+ this.platform.name,
416
+ this.podName,
417
+ this.usesModularHeaders(),
418
+ ),
419
+ )
420
+ for (const dependent of new Set(
421
+ this.recursiveDependentTargets(options.configuration ?? null),
422
+ ))
423
+ paths.push(
424
+ ...this.sandbox.publicHeaders.searchPaths(
425
+ this.platform.name,
426
+ dependent.podName,
427
+ this.definesModule && dependent.usesModularHeaders(false),
428
+ ),
429
+ )
430
+ return [...new Set(paths)]
431
+ }
432
+
433
+ override get moduleMapPath(): string {
434
+ const basename = `${this.label}.modulemap`
435
+ if (this.framework) return super.moduleMapPath
436
+ if (this.fileAccessors.some((fa) => fa.moduleMap))
437
+ return path.join(this.buildHeaders.root, this.productModuleName, basename)
438
+ return path.join(this.sandbox.publicHeaders.root, this.productModuleName, basename)
439
+ }
440
+
441
+ get prefixHeaderPath(): string {
442
+ return path.join(this.supportFilesDir, `${this.label}-prefix.pch`)
443
+ }
444
+
445
+ get copyXcframeworksScriptPath(): string {
446
+ return path.join(this.supportFilesDir, `${this.label}-xcframeworks.sh`)
447
+ }
448
+
449
+ resourcesBundleTargetLabel(bundle: string): string {
450
+ return `${this.label}-${bundle}`
451
+ }
452
+
453
+ get scriptPhases(): Record<string, unknown>[] {
454
+ return this.specs.flatMap((spec) => spec.consumer.script_phases)
455
+ }
456
+
457
+ #frameworkPaths: Map<string, FrameworkPaths[]> | undefined
458
+ get frameworkPaths(): Map<string, FrameworkPaths[]> {
459
+ this.#frameworkPaths ??= new Map(
460
+ this.fileAccessors.map((fa) => {
461
+ const frameworks = fa.vendoredDynamicArtifacts.map(
462
+ (framework): FrameworkPaths => {
463
+ const relative = relativePath(framework, this.sandbox.root)
464
+ const dsym = `${path.dirname(framework)}/${path.basename(framework)}.dSYM`
465
+ return {
466
+ sourcePath: `\${PODS_ROOT}/${relative}`,
467
+ dsymPath: existsSync(dsym) ? `\${PODS_ROOT}/${relative}.dSYM` : null,
468
+ bcsymbolmapPaths: null,
469
+ }
470
+ },
471
+ )
472
+ if (this.shouldBuild && this.buildAsDynamicFramework)
473
+ frameworks.push({
474
+ sourcePath: this.buildProductPath('${BUILT_PRODUCTS_DIR}'),
475
+ dsymPath: null,
476
+ bcsymbolmapPaths: null,
477
+ })
478
+ return [fa.specName, frameworks]
479
+ }),
480
+ )
481
+ return this.#frameworkPaths
482
+ }
483
+
484
+ #xcframeworks: Map<string, XCFramework[]> | undefined
485
+ get xcframeworks(): Map<string, XCFramework[]> {
486
+ this.#xcframeworks ??= new Map(
487
+ this.fileAccessors.map((fa) => [
488
+ fa.specName,
489
+ fa.vendoredXCFrameworks.map(
490
+ (framework) => new XCFramework(fa.specName, framework),
491
+ ),
492
+ ]),
493
+ )
494
+ return this.#xcframeworks
495
+ }
496
+
497
+ #resourcePaths: Map<string, string[]> | undefined
498
+ get resourcePaths(): Map<string, string[]> {
499
+ this.#resourcePaths ??= new Map(
500
+ this.fileAccessors.map((fa) => [
501
+ fa.specName,
502
+ [
503
+ ...fa.resources.map(
504
+ (resource) =>
505
+ `\${PODS_ROOT}/${relativePath(resource, path.dirname(this.sandbox.projectPath))}`,
506
+ ),
507
+ ...Object.keys(fa.resourceBundles).map(
508
+ (name) => `${this.configurationBuildDir()}/${shellEscape(name)}.bundle`,
509
+ ),
510
+ ],
511
+ ]),
512
+ )
513
+ return this.#resourcePaths
514
+ }
515
+ }
516
+
517
+ export class AggregateTarget extends Target {
518
+ readonly label: string
519
+ readonly framework: boolean
520
+ readonly dynamic = false
521
+ podTargetsForBuildConfiguration: Map<string, PodTarget[]>
522
+ searchPathsAggregateTargets: AggregateTarget[] = []
523
+
524
+ constructor(
525
+ sandbox: Sandbox,
526
+ readonly analyzed: AnalyzedAggregateTarget,
527
+ podTargets: Map<string, PodTarget>,
528
+ readonly clientRoot: string,
529
+ readonly podfilePath: string,
530
+ ) {
531
+ super(sandbox, analyzed.platform, analyzed.userBuildConfigurations)
532
+ this.label = analyzed.label
533
+ this.framework = analyzed.framework
534
+ this.podTargetsForBuildConfiguration = new Map(
535
+ Object.entries(analyzed.podsByConfiguration).map(([config, labels]) => [
536
+ config,
537
+ labels.map((label) => {
538
+ const target = podTargets.get(label)
539
+ if (!target)
540
+ throw new Error(`${this.label} lists an unknown pod target ${label}`)
541
+ return target
542
+ }),
543
+ ]),
544
+ )
545
+ }
546
+
547
+ get podTargets(): PodTarget[] {
548
+ return [...new Set([...this.podTargetsForBuildConfiguration.values()].flat())]
549
+ }
550
+
551
+ podTargetsFor(configuration: string): PodTarget[] {
552
+ return this.podTargetsForBuildConfiguration.get(configuration) ?? []
553
+ }
554
+
555
+ get usesSwift(): boolean {
556
+ return this.podTargets.some((target) => target.usesSwift)
557
+ }
558
+
559
+ get relativePodsRoot(): string {
560
+ return `\${SRCROOT}/${relativePath(this.sandbox.root, this.clientRoot)}`
561
+ }
562
+
563
+ get podfileDirRelativePath(): string {
564
+ return `\${SRCROOT}/${path.dirname(relativePath(this.podfilePath, this.clientRoot))}`
565
+ }
566
+
567
+ get embedFrameworksScriptPath(): string {
568
+ return path.join(this.supportFilesDir, `${this.label}-frameworks.sh`)
569
+ }
570
+
571
+ get copyResourcesScriptPath(): string {
572
+ return path.join(this.supportFilesDir, `${this.label}-resources.sh`)
573
+ }
574
+
575
+ get acknowledgementsBasepath(): string {
576
+ return path.join(this.supportFilesDir, `${this.label}-acknowledgements`)
577
+ }
578
+
579
+ frameworkPathsByConfig(): Map<string, FrameworkPaths[]> {
580
+ return new Map(
581
+ Object.keys(this.userBuildConfigurations).map((config) => [
582
+ config,
583
+ uniqueBy(
584
+ this.podTargetsFor(config).flatMap((target) =>
585
+ target.librarySpecs.flatMap(
586
+ (spec) => target.frameworkPaths.get(spec.name) ?? [],
587
+ ),
588
+ ),
589
+ (paths) => JSON.stringify(paths),
590
+ ),
591
+ ]),
592
+ )
593
+ }
594
+
595
+ xcframeworksByConfig(): Map<string, XCFramework[]> {
596
+ return new Map(
597
+ Object.keys(this.userBuildConfigurations).map((config) => [
598
+ config,
599
+ uniqueBy(
600
+ this.podTargetsFor(config).flatMap((target) =>
601
+ target.librarySpecs.flatMap(
602
+ (spec) => target.xcframeworks.get(spec.name) ?? [],
603
+ ),
604
+ ),
605
+ (xcframework) => xcframework.path,
606
+ ),
607
+ ]),
608
+ )
609
+ }
610
+
611
+ resourcePathsByConfig(): Map<string, string[]> {
612
+ const relevant = new Set(
613
+ this.podTargets.filter(
614
+ (target) => !(target.shouldBuild && target.buildAsDynamicFramework),
615
+ ),
616
+ )
617
+ return new Map(
618
+ Object.keys(this.userBuildConfigurations).map((config) => [
619
+ config,
620
+ [
621
+ ...new Set(
622
+ this.podTargetsFor(config)
623
+ .filter((target) => relevant.has(target))
624
+ .flatMap((target) => {
625
+ const paths = target.librarySpecs.flatMap(
626
+ (spec) => target.resourcePaths.get(spec.name) ?? [],
627
+ )
628
+ if (!target.buildAsStaticFramework) return paths
629
+ const productDir = target.buildProductPath('${BUILT_PRODUCTS_DIR}')
630
+ return paths.map((resource) => {
631
+ const extension = path.extname(resource)
632
+ const output = outputExtensionForResource(extension)
633
+ if (output === extension || extension === '.xcassets') return resource
634
+ const components = resource
635
+ .split('/')
636
+ .filter((part) => path.extname(part) === '.lproj')
637
+ return path.join(
638
+ productDir,
639
+ ...components,
640
+ path.basename(resource, extension) + output,
641
+ )
642
+ })
643
+ }),
644
+ ),
645
+ ],
646
+ ]),
647
+ )
648
+ }
649
+
650
+ get includesResources(): boolean {
651
+ return [...this.resourcePathsByConfig().values()].some((paths) => paths.length > 0)
652
+ }
653
+
654
+ get includesFrameworks(): boolean {
655
+ return [...this.frameworkPathsByConfig().values()].some((paths) => paths.length > 0)
656
+ }
657
+ }
658
+
659
+ // Target.output_extension_for_resource
660
+ export function outputExtensionForResource(extension: string): string {
661
+ const compiled: Record<string, string> = {
662
+ '.storyboard': '.storyboardc',
663
+ '.xib': '.nib',
664
+ '.xcdatamodel': '.mom',
665
+ '.xcdatamodeld': '.momd',
666
+ '.xcmappingmodel': '.cdm',
667
+ '.xcassets': '.car',
668
+ }
669
+ return compiled[extension] ?? extension
670
+ }
671
+
672
+ export interface PodTargets {
673
+ sandbox: Sandbox
674
+ podTargets: PodTarget[]
675
+ aggregateTargets: AggregateTarget[]
676
+ }
677
+
678
+ /**
679
+ * the targets for an analysis, with their header search paths and header links
680
+ * staged as `pod install` stages them before generating the project.
681
+ */
682
+ export function createPodTargets(
683
+ analysis: {
684
+ pods: AnalyzedPodTarget[]
685
+ aggregates: AnalyzedAggregateTarget[]
686
+ },
687
+ sandbox: Sandbox,
688
+ clientRoot: string,
689
+ podfilePath: string,
690
+ ): PodTargets {
691
+ const userBuildConfigurations = analysis.aggregates[0]?.userBuildConfigurations ?? {}
692
+ const pathLists = new Map<string, PathList>()
693
+ const podTargets = analysis.pods.map(
694
+ (pod) => new PodTarget(sandbox, userBuildConfigurations, pod, pathLists),
695
+ )
696
+ const byLabel = new Map(podTargets.map((target) => [target.label, target]))
697
+ for (const target of podTargets)
698
+ for (const config of ['debug', 'release'] as const)
699
+ target.dependentTargetsByConfig[config] = target.analyzed.dependencies[config].map(
700
+ (label) => {
701
+ const dependency = byLabel.get(label)
702
+ if (!dependency)
703
+ throw new Error(`${target.label} depends on an unknown pod target ${label}`)
704
+ return dependency
705
+ },
706
+ )
707
+ const aggregates = new Map(
708
+ analysis.aggregates.map((aggregate) => [
709
+ aggregate.label,
710
+ new AggregateTarget(sandbox, aggregate, byLabel, clientRoot, podfilePath),
711
+ ]),
712
+ )
713
+ for (const aggregate of aggregates.values())
714
+ aggregate.searchPathsAggregateTargets = aggregate.analyzed.searchPathsAggregates.map(
715
+ (label) => {
716
+ const found = aggregates.get(label)
717
+ if (!found)
718
+ throw new Error(
719
+ `${aggregate.label} searches an unknown aggregate target ${label}`,
720
+ )
721
+ return found
722
+ },
723
+ )
724
+
725
+ for (const target of podTargets) {
726
+ if (target.buildAsFramework && target.shouldBuild) continue
727
+ const buildMappings = target.headerMappingsByFileAccessor
728
+ const publicMappings = target.publicHeaderMappingsByFileAccessor
729
+ if (buildMappings.some((mappings) => mappings.size > 0))
730
+ target.buildHeaders.addSearchPath(target.headersSandbox, target.platform.name)
731
+ if (publicMappings.some((mappings) => mappings.size > 0))
732
+ sandbox.publicHeaders.addSearchPath(target.headersSandbox, target.platform.name)
733
+ for (const mappings of buildMappings)
734
+ for (const [namespace, files] of mappings)
735
+ target.buildHeaders.addFiles(namespace, files)
736
+ for (const mappings of publicMappings)
737
+ for (const [namespace, files] of mappings)
738
+ sandbox.publicHeaders.addFiles(namespace, files)
739
+ }
740
+ return { sandbox, podTargets, aggregateTargets: [...aggregates.values()] }
741
+ }
742
+
743
+ const uniqueBy = <T>(values: T[], key: (value: T) => string): T[] => {
744
+ const seen = new Set<string>()
745
+ return values.filter((value) => {
746
+ const k = key(value)
747
+ if (seen.has(k)) return false
748
+ seen.add(k)
749
+ return true
750
+ })
751
+ }
752
+
753
+ // Shellwords.escape
754
+ export function shellEscape(value: string): string {
755
+ if (value === '') return "''"
756
+ return value.replace(/[^A-Za-z0-9_\-.,:+/@\n]/g, '\\$&').replace(/\n/g, "'\n'")
757
+ }