peachsim 0.1.2430 → 0.1.2432

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 +16786 -6994
  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
@@ -1,4 +1,4 @@
1
- /*! peach v0.1.2430 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
1
+ /*! peach v0.1.2432 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
2
2
  let __sootsim_import_meta_url = '', __sootsim_import_meta_dirname = '', __sootsim_import_meta_filename = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; __sootsim_import_meta_dirname = __dirname; __sootsim_import_meta_filename = __filename; } catch {}
3
3
  "use strict";
4
4
  var __defProp = Object.defineProperty;
@@ -1,4 +1,4 @@
1
- /*! peach v0.1.2430 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
1
+ /*! peach v0.1.2432 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
2
2
  var __defProp = Object.defineProperty;
3
3
  var __typeError = (msg) => {
4
4
  throw TypeError(msg);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "peachsim",
3
- "version": "0.1.2430",
3
+ "version": "0.1.2432",
4
4
  "description": "Vite and Metro plugins, testing drivers, and SDK exports for peach.",
5
5
  "author": "Tamagui LLC",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -1,4 +1,4 @@
1
- // prepare Expo's own CocoaPods workspace in a private cache on the Mac.
1
+ // prepare Expo's native workspace, with its pods installed, in a private cache.
2
2
  import { execFile, execFileSync, spawnSync } from 'node:child_process'
3
3
  import { createHash } from 'node:crypto'
4
4
  import fs from 'node:fs'
@@ -18,6 +18,7 @@ import { cacheDir } from './home-paths.ts'
18
18
  import { failedOutputLine } from './native-failure-output.ts'
19
19
  import { requireNativeGit } from './native-git.ts'
20
20
  import { prepareOneSDKSources } from './one-sdk-preparation.ts'
21
+ import { installPods } from './pods-install.ts'
21
22
  import { readInstalledPodspecs } from './podspec-sources.ts'
22
23
  import { portableExpoWorkspace } from './portable-expo-workspace.ts'
23
24
  import {
@@ -25,11 +26,7 @@ import {
25
26
  removeRetiredDirectory,
26
27
  } from './retired-cache-directory.ts'
27
28
  import { compiledSwiftHelper } from './swift-helper.ts'
28
- import {
29
- withCocoaPodsCacheLock,
30
- withSwiftRootLock,
31
- type SwiftRootLease,
32
- } from './swift-root-lock.ts'
29
+ import { withSwiftRootLock, type SwiftRootLease } from './swift-root-lock.ts'
33
30
  import { sharedCacheDir } from './swift-toolchain.ts'
34
31
  import { findWorkspaceRoot } from './workspace-root.ts'
35
32
  import { resolveXcodeSwiftPackages, selectXcodeWorkspace } from './xcode-project.ts'
@@ -44,10 +41,7 @@ function cleanWorkspaceGitEnv(): NodeJS.ProcessEnv {
44
41
  return { ...withoutGitRepositoryEnv(), ...isolatedGitEnv }
45
42
  }
46
43
 
47
- // CocoaPods refuses a non UTF-8 locale, so even its version probe names one.
48
- const utf8Env = { ...process.env, LANG: 'en_US.UTF-8', LC_ALL: 'en_US.UTF-8' }
49
-
50
- // react native uses these existing CocoaPods inputs to select source targets
44
+ // react native uses these pod install inputs to select source targets
51
45
  // or its prebuilt frameworks; each choice needs its own prepared workspace.
52
46
  export function reactNativePodsEnvironment() {
53
47
  return {
@@ -413,28 +407,18 @@ async function walkWorkspaceInputs(
413
407
  excluded,
414
408
  }
415
409
  }
416
- // cocoapods and xcode exist only on a Mac; elsewhere only the prebuild stage runs
417
- const execFileAsync = promisify(execFile)
418
410
  const pinnedNode =
419
411
  typeof manifest.engines?.node === 'string' &&
420
412
  /^\d+(\.\d+){0,2}$/.test(manifest.engines.node)
421
413
  ? `node@${manifest.engines.node}`
422
414
  : null
423
- const [mac, node] = await Promise.all([
415
+ const execFileAsync = promisify(execFile)
416
+ const [xcode, node] = await Promise.all([
417
+ // podfile hooks may branch on the xcode version, which exists only on a Mac
424
418
  process.platform === 'darwin'
425
- ? Promise.all([
426
- // runner-toolchain-platform: darwin
427
- execFileAsync('pod', ['--version'], { env: utf8Env }).catch(
428
- (cause: unknown) => {
429
- throw new Error('CocoaPods is required to install source dependencies', {
430
- cause,
431
- })
432
- },
433
- ),
434
- // runner-toolchain-platform: darwin
435
- execFileAsync('xcodebuild', ['-version'], { env: utf8Env }),
436
- ]).then(([pod, xcode]) => ({ podVersion: pod.stdout, xcode: xcode.stdout }))
437
- : {},
419
+ ? // runner-toolchain-platform: darwin
420
+ execFileAsync('xcodebuild', ['-version']).then(({ stdout }) => stdout)
421
+ : null,
438
422
  execFileAsync(
439
423
  pinnedNode ? 'mise' : 'node',
440
424
  pinnedNode ? ['exec', pinnedNode, '--', 'node', '--version'] : ['--version'],
@@ -442,9 +426,9 @@ async function walkWorkspaceInputs(
442
426
  ),
443
427
  ])
444
428
  const toolchain = JSON.stringify({
445
- preparation: 8,
429
+ preparation: 9,
446
430
  appRelative,
447
- ...mac,
431
+ xcode,
448
432
  node: node.stdout.trim(),
449
433
  packageManager: workspacePackageManager(root, manifest.packageManager, excluded),
450
434
  podsEnvironment,
@@ -851,17 +835,10 @@ export async function prepareInstalledExpoWorkspace(app: string, work: string) {
851
835
  const manifest = JSON.parse(
852
836
  fs.readFileSync(path.join(preparedApp, 'package.json'), 'utf8'),
853
837
  )
854
- const run: NativeRun = (command, args, cwd, env = {}) =>
855
- runAdmitted(lease, command, args, cwd, env)
856
838
  const execute: NativeExecute = (args, cwd, env = {}) =>
857
- run(args[0]!, args.slice(1), cwd, env)
858
- await prepareNativeProject(
859
- preparedApp,
860
- manifest,
861
- 'workspace',
862
- execute,
863
- run,
864
- (message) => console.error(`[expo-native-workspace] ${message}`),
839
+ runAdmitted(lease, args[0]!, args.slice(1), cwd, env)
840
+ await prepareNativeProject(preparedApp, manifest, 'workspace', execute, (message) =>
841
+ console.error(`[expo-native-workspace] ${message}`),
865
842
  )
866
843
  fs.writeFileSync(path.join(work, '.peach-complete'), 'complete\n')
867
844
  const ios = path.join(preparedApp, 'ios')
@@ -1105,7 +1082,6 @@ async function prepareWorkspace(
1105
1082
  appManifest,
1106
1083
  'project',
1107
1084
  execute,
1108
- run,
1109
1085
  report,
1110
1086
  oneSdkPrepared,
1111
1087
  )
@@ -1117,7 +1093,6 @@ async function prepareWorkspace(
1117
1093
  appManifest,
1118
1094
  'workspace',
1119
1095
  execute,
1120
- run,
1121
1096
  report,
1122
1097
  oneSdkPrepared,
1123
1098
  )
@@ -1138,12 +1113,6 @@ async function prepareWorkspace(
1138
1113
  return result
1139
1114
  }
1140
1115
 
1141
- type NativeRun = (
1142
- command: string,
1143
- args: string[],
1144
- cwd: string,
1145
- env?: Record<string, string>,
1146
- ) => Promise<void>
1147
1116
  type NativeExecute = (
1148
1117
  args: string[],
1149
1118
  cwd: string,
@@ -1167,7 +1136,6 @@ async function prepareNativeProject(
1167
1136
  manifest: NativeProjectManifest,
1168
1137
  stage: 'project' | 'workspace',
1169
1138
  execute: NativeExecute,
1170
- run: NativeRun,
1171
1139
  report: (message: string) => void,
1172
1140
  oneSdkPrepared?: Set<string>,
1173
1141
  ) {
@@ -1210,25 +1178,17 @@ async function prepareNativeProject(
1210
1178
  if (stage === 'project') return
1211
1179
  // react-native-skia leaves Dawn to react-native-webgpu whenever that package
1212
1180
  // is installed, but autolinking links it only into apps that declare it.
1213
- const iosRoot = path.join(app, 'ios')
1214
- // a Podfile that calls ensure_bundler! refuses a global CocoaPods
1215
- const bundled = fs
1216
- .readFileSync(path.join(iosRoot, 'Podfile'), 'utf8')
1217
- .includes('ensure_bundler!')
1218
- const podEnv = {
1181
+ stageCachedQuickCryptoOpenSsl(app)
1182
+ report('installing pods')
1183
+ const { timings } = await installPods(app, {
1184
+ ...cleanWorkspaceGitEnv(),
1185
+ EXPO_NO_TELEMETRY: '1',
1186
+ LANG: 'en_US.UTF-8',
1187
+ LC_ALL: 'en_US.UTF-8',
1219
1188
  ...sourcePodEnv,
1220
1189
  ...(declares('react-native-webgpu') ? {} : { RNSKIA_VENDOR_DAWN: '1' }),
1221
- }
1222
- stageCachedQuickCryptoOpenSsl(app)
1223
- report('waiting for CocoaPods cache')
1224
- await withCocoaPodsCacheLock(async () => {
1225
- report('installing CocoaPods dependencies')
1226
- if (bundled) {
1227
- await run('bundle', ['install'], iosRoot, podEnv)
1228
- await run('bundle', ['exec', 'pod', 'install'], iosRoot, podEnv)
1229
- } else await run('pod', ['install'], iosRoot, podEnv)
1230
1190
  })
1231
- report('pod install done')
1191
+ report(`pods installed ${JSON.stringify(timings)}`)
1232
1192
  }
1233
1193
 
1234
1194
  function stageCachedQuickCryptoOpenSsl(app: string) {
@@ -0,0 +1,200 @@
1
+ // an Xcode project's objects table, as project.pbxproj holds it, that Peach
2
+ // builds and edits in memory. object ids derive from what each object is, so
3
+ // the same project gets the same ids.
4
+ import { createHash } from 'node:crypto'
5
+ import { isDict, type PlistDict, type PlistValue } from './openstep-plist'
6
+
7
+ const isIdList = (value: PlistValue): value is string[] =>
8
+ Array.isArray(value) && value.every((item) => typeof item === 'string')
9
+
10
+ export class PbxTable {
11
+ constructor(
12
+ readonly objects: Record<string, PlistDict> = {},
13
+ public rootObject = '',
14
+ ) {}
15
+
16
+ /** adds `object` under an id derived from `seed`, which names it among the objects. */
17
+ add(seed: string, object: PlistDict): string {
18
+ let id = createHash('sha1').update(seed).digest('hex').slice(0, 24).toUpperCase()
19
+ for (let n = 1; this.objects[id]; n++)
20
+ id = createHash('sha1')
21
+ .update(`${seed}#${n}`)
22
+ .digest('hex')
23
+ .slice(0, 24)
24
+ .toUpperCase()
25
+ this.objects[id] = object
26
+ return id
27
+ }
28
+
29
+ get(id: string): PlistDict {
30
+ const object = this.objects[id]
31
+ if (!object) throw new Error(`the project has no object ${id}`)
32
+ return object
33
+ }
34
+
35
+ /** the ids `key` of object `id` lists, as a live list. */
36
+ list(id: string, key: string): string[] {
37
+ const object = this.get(id)
38
+ const value = object[key]
39
+ if (value === undefined) {
40
+ const created: string[] = []
41
+ object[key] = created
42
+ return created
43
+ }
44
+ if (!isIdList(value)) throw new Error(`${id}.${key} lists no ids`)
45
+ return value
46
+ }
47
+
48
+ /** `id`'s build settings, as a live dictionary. */
49
+ buildSettings(id: string): PlistDict {
50
+ const object = this.get(id)
51
+ const settings = object.buildSettings ?? (object.buildSettings = {})
52
+ if (!isDict(settings)) throw new Error(`${id} has no build settings`)
53
+ return settings
54
+ }
55
+
56
+ /** the configurations of a target or project's configuration list. */
57
+ configurations(id: string): string[] {
58
+ const list = this.get(id).buildConfigurationList
59
+ if (typeof list !== 'string') throw new Error(`${id} has no configuration list`)
60
+ return this.list(list, 'buildConfigurations')
61
+ }
62
+
63
+ ids(isa: string): string[] {
64
+ return Object.keys(this.objects).filter((id) => this.objects[id]!.isa === isa)
65
+ }
66
+
67
+ string(id: string, key: string): string | undefined {
68
+ const value = this.get(id)[key]
69
+ return typeof value === 'string' ? value : undefined
70
+ }
71
+
72
+ /** the objects reachable from the root, which is what Xcodeproj loads and saves. */
73
+ reachable(): Record<string, PlistDict> {
74
+ const seen = new Set<string>()
75
+ const visit = (value: PlistValue | undefined, key: string) => {
76
+ // these name an object without referring to it
77
+ if (key === 'remoteGlobalIDString' || key === 'containerPortal') return
78
+ if (typeof value === 'string') {
79
+ const object = this.objects[value]
80
+ if (!object || seen.has(value)) return
81
+ seen.add(value)
82
+ for (const [childKey, child] of Object.entries(object)) visit(child, childKey)
83
+ } else if (Array.isArray(value)) for (const item of value) visit(item, key)
84
+ }
85
+ visit(this.rootObject, 'rootObject')
86
+ return Object.fromEntries([...seen].map((id) => [id, this.objects[id]!]))
87
+ }
88
+ }
89
+
90
+ const ARRAY_SETTINGS = new Set([
91
+ 'ALTERNATE_PERMISSIONS_FILES',
92
+ 'ARCHS',
93
+ 'BUILD_VARIANTS',
94
+ 'EXCLUDED_SOURCE_FILE_NAMES',
95
+ 'FRAMEWORK_SEARCH_PATHS',
96
+ 'GCC_PREPROCESSOR_DEFINITIONS',
97
+ 'GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS',
98
+ 'HEADER_SEARCH_PATHS',
99
+ 'INCLUDED_SOURCE_FILE_NAMES',
100
+ 'INFOPLIST_PREPROCESSOR_DEFINITIONS',
101
+ 'LD_RUNPATH_SEARCH_PATHS',
102
+ 'LIBRARY_SEARCH_PATHS',
103
+ 'LOCALIZED_STRING_MACRO_NAMES',
104
+ 'OTHER_CFLAGS',
105
+ 'OTHER_CPLUSPLUSFLAGS',
106
+ 'OTHER_LDFLAGS',
107
+ 'REZ_SEARCH_PATHS',
108
+ 'SECTORDER_FLAGS',
109
+ 'SYSTEM_FRAMEWORK_SEARCH_PATHS',
110
+ 'SYSTEM_HEADER_SEARCH_PATHS',
111
+ 'USER_HEADER_SEARCH_PATHS',
112
+ 'WARNING_CFLAGS',
113
+ 'WARNING_LDFLAGS',
114
+ ])
115
+ const LEGACY_ARRAY_SETTINGS = new Set(
116
+ [...ARRAY_SETTINGS].filter(
117
+ (key) =>
118
+ ![
119
+ 'INCLUDED_SOURCE_FILE_NAMES',
120
+ 'LD_RUNPATH_SEARCH_PATHS',
121
+ 'LOCALIZED_STRING_MACRO_NAMES',
122
+ 'SYSTEM_FRAMEWORK_SEARCH_PATHS',
123
+ 'SYSTEM_HEADER_SEARCH_PATHS',
124
+ 'USER_HEADER_SEARCH_PATHS',
125
+ ].includes(key),
126
+ ),
127
+ )
128
+
129
+ /** XCBuildConfiguration#normalize_array_settings, which runs as Xcodeproj saves a project. */
130
+ export function normalizeArraySettings(settings: PlistDict, objectVersion: string): void {
131
+ const arraySettings =
132
+ Number(objectVersion) >= 50 ? ARRAY_SETTINGS : LEGACY_ARRAY_SETTINGS
133
+ for (const key of Object.keys(settings)) {
134
+ const value = settings[key]
135
+ if (!value) continue
136
+ const stripped = key.replace(/\[[^\]]+\]$/, '')
137
+ if (typeof value === 'string') {
138
+ if (!arraySettings.has(stripped)) continue
139
+ const parts = [...value.matchAll(/ *((['"]?).*?[^\\]\2)(?= |(?![\s\S]))/g)].map(
140
+ (match) => match[1]!,
141
+ )
142
+ if (parts.length > 1) settings[key] = parts
143
+ } else if (Array.isArray(value)) {
144
+ if (value.length > 1 && arraySettings.has(stripped)) continue
145
+ settings[key] = value
146
+ .map((item) => (typeof item === 'string' ? item : ''))
147
+ .join(' ')
148
+ }
149
+ }
150
+ }
151
+
152
+ const PLAIN_STRING = /^[A-Za-z0-9_$./]+$/
153
+ const STRING_ESCAPES: Record<string, string> = {
154
+ '"': '\\"',
155
+ '\\': '\\\\',
156
+ '\n': '\\n',
157
+ '\t': '\\t',
158
+ '\r': '\\r',
159
+ }
160
+ const quote = (text: string) =>
161
+ PLAIN_STRING.test(text)
162
+ ? text
163
+ : `"${text.replace(
164
+ /["\\\n\t\r]|[\u0000-\u001f]/g,
165
+ (c) => STRING_ESCAPES[c] ?? `\\U${c.charCodeAt(0).toString(16).padStart(4, '0')}`,
166
+ )}"`
167
+ const byBytes = (a: string, b: string) => Buffer.compare(Buffer.from(a), Buffer.from(b))
168
+
169
+ /** project.pbxproj text for `objects`: objects grouped by isa as Xcode writes them, without its comments. */
170
+ export function serializePbxproj(
171
+ objects: Record<string, PlistDict>,
172
+ rootObject: string,
173
+ objectVersion: string,
174
+ ): string {
175
+ const write = (value: PlistValue, depth: number): string => {
176
+ const indent = '\t'.repeat(depth)
177
+ if (typeof value === 'string') return quote(value)
178
+ if (Array.isArray(value))
179
+ return `(\n${value.map((item) => `${indent}\t${write(item, depth + 1)},\n`).join('')}${indent})`
180
+ const keys = Object.keys(value).sort((a, b) =>
181
+ a === 'isa' ? -1 : b === 'isa' ? 1 : byBytes(a, b),
182
+ )
183
+ return `{\n${keys.map((key) => `${indent}\t${quote(key)} = ${write(value[key]!, depth + 1)};\n`).join('')}${indent}}`
184
+ }
185
+ const byIsa = new Map<string, string[]>()
186
+ for (const id of Object.keys(objects).sort(byBytes)) {
187
+ const isa = String(objects[id]!.isa)
188
+ byIsa.set(isa, [...(byIsa.get(isa) ?? []), id])
189
+ }
190
+ const sections = [...byIsa.keys()].sort(byBytes).map(
191
+ (isa) =>
192
+ `\n/* Begin ${isa} section */\n${byIsa
193
+ .get(isa)!
194
+ .map((id) => `\t\t${quote(id)} = ${write(objects[id]!, 2)};\n`)
195
+ .join('')}/* End ${isa} section */\n`,
196
+ )
197
+ return `// !$*UTF8*$!\n{\n\tarchiveVersion = 1;\n\tclasses = {\n\t};\n\tobjectVersion = ${objectVersion};\n\tobjects = {\n${sections.join('')}\t};\n\trootObject = ${quote(rootObject)};\n}\n`
198
+ }
199
+
200
+ export type { PlistDict, PlistValue }