peachsim 0.1.2611 → 0.1.2613

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 (130) 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/attached-projects.cjs +1 -1
  4. package/dist-lib/auth/shared-session.cjs +1 -1
  5. package/dist-lib/backend-origin.cjs +1 -1
  6. package/dist-lib/beta.cjs +1 -1
  7. package/dist-lib/beta.mjs +2 -2
  8. package/dist-lib/bridge-constants.cjs +1 -1
  9. package/dist-lib/bridge-contract-input.cjs +1 -1
  10. package/dist-lib/bridge-contract-input.mjs +5 -5
  11. package/dist-lib/bridge-contract.cjs +1 -1
  12. package/dist-lib/bridge-contract.mjs +3 -3
  13. package/dist-lib/bundle-channel.cjs +1218 -737
  14. package/dist-lib/capture-contract.cjs +1 -1
  15. package/dist-lib/capture-contract.mjs +3 -3
  16. package/dist-lib/cloud-contract.cjs +1 -1
  17. package/dist-lib/cloud-contract.mjs +3 -3
  18. package/dist-lib/cloud-test-args.cjs +1 -1
  19. package/dist-lib/cloud-test-args.mjs +2 -2
  20. package/dist-lib/cloud.cjs +1 -1
  21. package/dist-lib/cloud.mjs +7 -7
  22. package/dist-lib/config.cjs +1 -1
  23. package/dist-lib/config.mjs +5 -5
  24. package/dist-lib/detox/index.cjs +1 -1
  25. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  26. package/dist-lib/esm-chunks/{acorn-BKODFARF.mjs → acorn-ACYPRRES.mjs} +3 -3
  27. package/dist-lib/esm-chunks/{chunk-7L5LUPZA.mjs → chunk-4737IGWN.mjs} +1 -1
  28. package/dist-lib/esm-chunks/{chunk-J6N5KKMZ.mjs → chunk-4KMXTJK7.mjs} +6 -6
  29. package/dist-lib/esm-chunks/{chunk-LNZNCA7M.mjs → chunk-5PYWWIEV.mjs} +1 -1
  30. package/dist-lib/esm-chunks/{chunk-HWMD7II5.mjs → chunk-ALQTIMJN.mjs} +2 -2
  31. package/dist-lib/esm-chunks/{chunk-3JA6XLP4.mjs → chunk-EHBHTMJD.mjs} +1 -1
  32. package/dist-lib/esm-chunks/{chunk-C4BW35N7.mjs → chunk-FI6ANCVK.mjs} +1 -1
  33. package/dist-lib/esm-chunks/{chunk-NUISME6Y.mjs → chunk-FKR3M3SE.mjs} +1 -1
  34. package/dist-lib/esm-chunks/{chunk-4C3LKD3A.mjs → chunk-HABUBD7F.mjs} +1 -1
  35. package/dist-lib/esm-chunks/{chunk-CAFNSCPD.mjs → chunk-HMBNKM6Z.mjs} +12 -55
  36. package/dist-lib/esm-chunks/{chunk-SFDNE5S2.mjs → chunk-HXFNAJK2.mjs} +1 -1
  37. package/dist-lib/esm-chunks/{chunk-A6GNAMLP.mjs → chunk-JA2VWD36.mjs} +1 -1
  38. package/dist-lib/esm-chunks/{chunk-JWA5AIJM.mjs → chunk-JZN72POJ.mjs} +1 -1
  39. package/dist-lib/esm-chunks/{chunk-45CENTIY.mjs → chunk-LKZBPKR7.mjs} +1 -1
  40. package/dist-lib/esm-chunks/{chunk-SNMPI3I2.mjs → chunk-LOG546WG.mjs} +1 -1
  41. package/dist-lib/esm-chunks/{chunk-KOT7HREP.mjs → chunk-MYDEA4KG.mjs} +6 -6
  42. package/dist-lib/esm-chunks/{chunk-4CJMDUKF.mjs → chunk-N4OAK5F2.mjs} +14 -14
  43. package/dist-lib/esm-chunks/{chunk-XSRZQWH5.mjs → chunk-OAXXQLLD.mjs} +5 -5
  44. package/dist-lib/esm-chunks/{chunk-H2JPB73X.mjs → chunk-RAWOUEDK.mjs} +1 -1
  45. package/dist-lib/esm-chunks/{chunk-LDV2MZFL.mjs → chunk-S6YGE7GH.mjs} +1 -1
  46. package/dist-lib/esm-chunks/{chunk-52XQJZ6O.mjs → chunk-TELXLVVV.mjs} +3 -3
  47. package/dist-lib/esm-chunks/{chunk-CWLKT7TD.mjs → chunk-VCFIXUE4.mjs} +1 -1
  48. package/dist-lib/esm-chunks/{chunk-YFSTB4CX.mjs → chunk-WHRUBPSD.mjs} +4 -4
  49. package/dist-lib/esm-chunks/{chunk-FWUDTM5Y.mjs → chunk-WN7ZU4KM.mjs} +1 -1
  50. package/dist-lib/esm-chunks/{chunk-SKW2UNWS.mjs → chunk-WYHRRW33.mjs} +1 -1
  51. package/dist-lib/esm-chunks/{metro-layout-parser-BMN3E2RD.mjs → metro-layout-parser-E7PUOWFM.mjs} +3 -3
  52. package/dist-lib/esm-chunks/{swift-package-prebuilt-VMBB763C.mjs → swift-package-prebuilt-I2HAKHB3.mjs} +12 -12
  53. package/dist-lib/esm-chunks/{swift-sdk-app-module-SJ6OZAVA.mjs → swift-sdk-app-module-KLRMLTO2.mjs} +16 -16
  54. package/dist-lib/esm-chunks/{swift-sdk-image-U53EKCZW.mjs → swift-sdk-image-GYAVDPQT.mjs} +16 -16
  55. package/dist-lib/esm-chunks/{swift-sdk-image-producer-TQQ33C3G.mjs → swift-sdk-image-producer-4XVU6GKS.mjs} +5 -5
  56. package/dist-lib/expo-swift-bundle.cjs +15 -58
  57. package/dist-lib/expo-swift-metadata.cjs +1 -1
  58. package/dist-lib/expo-swift-metadata.mjs +7 -7
  59. package/dist-lib/home-paths.cjs +1 -1
  60. package/dist-lib/host/bridge-host.cjs +1613 -1076
  61. package/dist-lib/host/fetch-proxy-handler.cjs +3 -3
  62. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  63. package/dist-lib/host/fetch-proxy-overrides.mjs +2 -2
  64. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  65. package/dist-lib/host/websocket-proxy.cjs +1 -1
  66. package/dist-lib/index.cjs +1 -1
  67. package/dist-lib/kotlin-host.cjs +676 -171
  68. package/dist-lib/menu.cjs +1 -1
  69. package/dist-lib/menu.mjs +3 -3
  70. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  71. package/dist-lib/metro-fingerprint-registry.mjs +3 -3
  72. package/dist-lib/metro-production-bundle.cjs +1 -1
  73. package/dist-lib/metro-production-bundle.mjs +4 -4
  74. package/dist-lib/native-app-identity-project.cjs +12 -55
  75. package/dist-lib/native-app-identity-project.mjs +15 -15
  76. package/dist-lib/native-app-identity.cjs +1 -1
  77. package/dist-lib/native-app-identity.mjs +6 -6
  78. package/dist-lib/native-firebase-metadata.cjs +1 -1
  79. package/dist-lib/native-firebase-metadata.mjs +3 -3
  80. package/dist-lib/pdfium-raster.cjs +1 -1
  81. package/dist-lib/pdfium-raster.mjs +2 -2
  82. package/dist-lib/plist.cjs +12 -55
  83. package/dist-lib/plist.mjs +3 -3
  84. package/dist-lib/profiles.cjs +1 -1
  85. package/dist-lib/public-brand.cjs +1 -1
  86. package/dist-lib/public-origins-lib-esm.json +85 -85
  87. package/dist-lib/public-origins-lib.json +76 -65
  88. package/dist-lib/react-native-host-modules.cjs +1 -1
  89. package/dist-lib/react-native-host-modules.mjs +2 -2
  90. package/dist-lib/reap-browser.cjs +1 -1
  91. package/dist-lib/scripts/dev-server-scanner.cjs +11 -10
  92. package/dist-lib/sdk.cjs +1 -1
  93. package/dist-lib/sdk.mjs +8 -8
  94. package/dist-lib/skills.cjs +2169 -1693
  95. package/dist-lib/swift-compile.cjs +1 -1
  96. package/dist-lib/swift-compile.mjs +12 -12
  97. package/dist-lib/swift-package.cjs +1 -1
  98. package/dist-lib/swift-package.mjs +3 -3
  99. package/dist-lib/swift-submit.cjs +1 -1
  100. package/dist-lib/swift-submit.mjs +6 -6
  101. package/dist-lib/swift-svg-raster.cjs +1 -1
  102. package/dist-lib/swift-svg-raster.mjs +2 -2
  103. package/dist-lib/swift-toolchain.cjs +1 -1
  104. package/dist-lib/swift.cjs +1 -1
  105. package/dist-lib/vendor/@peculiar/x509.cjs +1 -1
  106. package/dist-lib/vendor/@ruby/prism/src/nodes.js.cjs +1 -1
  107. package/dist-lib/vendor/@ruby/prism/src/parsePrism.js.cjs +1 -1
  108. package/dist-lib/vendor/acorn.cjs +1 -1
  109. package/dist-lib/vendor/magic-string.cjs +1 -1
  110. package/dist-lib/vendor/stream-json.cjs +1 -1
  111. package/dist-lib/vendor/sucrase/dist/index.js.cjs +1 -1
  112. package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +1 -1
  113. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +1 -1
  114. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +1 -1
  115. package/dist-lib/vendor/sucrase.cjs +1 -1
  116. package/dist-lib/vendor/terser.cjs +1 -1
  117. package/dist-lib/vendor/valibot.cjs +1 -1
  118. package/dist-lib/vendor/ws.cjs +1 -1
  119. package/dist-lib/vendor/zod.cjs +1 -1
  120. package/dist-lib/worklet-executable.cjs +1 -1
  121. package/dist-lib/worklet-executable.mjs +3 -3
  122. package/package.json +1 -1
  123. package/src/android-gradle-sources.ts +97 -2
  124. package/src/androidGradleContract.ts +11 -0
  125. package/src/gitignore.ts +1 -1
  126. package/src/kotlin-app.ts +37 -4
  127. package/src/kotlin-gradle-library-plan.ts +142 -0
  128. package/src/kotlin-host.ts +32 -3
  129. package/src/kotlin-maven-sources.ts +0 -7
  130. package/src/plist.ts +13 -56
@@ -0,0 +1,142 @@
1
+ import { createHash } from 'node:crypto'
2
+ import fs from 'node:fs'
3
+ import path from 'node:path'
4
+ import { compileKotlinLibrarySources } from './kotlin-library-sources'
5
+ import { readMavenSourcesArchive } from './kotlin-maven-sources'
6
+ import type {
7
+ AndroidGradleDependencySource,
8
+ AndroidGradleModule,
9
+ } from './androidGradleContract'
10
+ import type { KotlinToolchainInstallation } from './kotlinSdkContract'
11
+
12
+ export interface KotlinGradleLibrary {
13
+ coordinate: string
14
+ archive: string
15
+ jars: readonly string[]
16
+ dependencies: readonly string[]
17
+ }
18
+
19
+ export interface KotlinGradleLibraries {
20
+ libraries: KotlinGradleLibrary[]
21
+ classpath: string[]
22
+ }
23
+
24
+ export function kotlinGradleLibraryPlan(input: {
25
+ compile: readonly AndroidGradleModule[]
26
+ runtime: readonly AndroidGradleModule[]
27
+ sourceArchives: readonly AndroidGradleDependencySource[]
28
+ roots: readonly string[]
29
+ supplied: (coordinate: string) => boolean
30
+ }): KotlinGradleLibrary[] {
31
+ const compile = new Map(input.compile.map((module) => [module.coordinate, module]))
32
+ const runtime = new Map(input.runtime.map((module) => [module.coordinate, module]))
33
+ const archives = new Map(
34
+ input.sourceArchives.map((row) => [
35
+ [row.group, row.name, row.version].join(':'),
36
+ row.archive,
37
+ ]),
38
+ )
39
+ const active = new Set<string>()
40
+ const visited = new Map<string, readonly string[]>()
41
+ const name = (coordinate: string) => coordinate.slice(0, coordinate.lastIndexOf(':'))
42
+ const runtimeSelection = new Map(
43
+ input.runtime.map(({ coordinate }) => [name(coordinate), coordinate]),
44
+ )
45
+ const result: KotlinGradleLibrary[] = []
46
+ const visit = (requested: string): readonly string[] => {
47
+ const coordinate = runtimeSelection.get(name(requested)) ?? requested
48
+ if (input.supplied(coordinate)) return []
49
+ const previous = visited.get(coordinate)
50
+ if (previous) return previous
51
+ if (active.has(coordinate))
52
+ throw new Error('Android dependencies form a cycle at ' + coordinate)
53
+ active.add(coordinate)
54
+ const compileModule = compile.get(coordinate)
55
+ const runtimeModule = runtime.get(coordinate)
56
+ if (!compileModule && !runtimeModule)
57
+ throw new Error('Gradle did not resolve Android module ' + coordinate)
58
+ const edges = new Set([
59
+ ...(compileModule?.dependencies ?? []),
60
+ ...(runtimeModule?.dependencies ?? []),
61
+ ])
62
+ const dependencies = [...new Set([...edges].flatMap(visit))]
63
+ const jars = compileModule?.jars.length
64
+ ? compileModule.jars
65
+ : (runtimeModule?.jars ?? [])
66
+ let closure: readonly string[] = dependencies
67
+ if (jars.length) {
68
+ const archive = archives.get(coordinate)
69
+ if (!archive)
70
+ throw new Error('Gradle did not resolve a source archive for ' + coordinate)
71
+ result.push({ coordinate, archive, jars, dependencies })
72
+ closure = [...dependencies, coordinate]
73
+ }
74
+ active.delete(coordinate)
75
+ visited.set(coordinate, closure)
76
+ return closure
77
+ }
78
+ input.roots.forEach(visit)
79
+ return result
80
+ }
81
+
82
+ export async function compileKotlinGradleLibraries(input: {
83
+ plan: KotlinGradleLibraries
84
+ ready: KotlinToolchainInstallation
85
+ sdkRoot: string
86
+ libraries: readonly string[]
87
+ language: string
88
+ output: string
89
+ }): Promise<string[]> {
90
+ const compiled = new Map<string, { klib: string; jars: readonly string[] }>()
91
+ for (const library of input.plan.libraries) {
92
+ const { java: archiveJava, kotlin } = await readMavenSourcesArchive(library.archive)
93
+ const java = archiveJava.filter((file) => path.basename(file) !== 'module-info.java')
94
+ const dependencies = library.dependencies.map((name) => {
95
+ const dependency = compiled.get(name)
96
+ if (!dependency) throw new Error(`${library.coordinate} depends on missing ${name}`)
97
+ return dependency
98
+ })
99
+ const classpath = [
100
+ ...new Set([
101
+ ...library.jars,
102
+ ...dependencies.flatMap(({ jars }) => jars),
103
+ ...input.plan.classpath,
104
+ ]),
105
+ ]
106
+ const name = library.coordinate.replace(/[^a-zA-Z0-9._-]/g, '-')
107
+ const suffix = createHash('sha256')
108
+ .update(library.coordinate)
109
+ .digest('hex')
110
+ .slice(0, 12)
111
+ const klib = path.join(input.output, `${name}-${suffix}.klib`)
112
+ const kotlinJvmAbi =
113
+ java.length && kotlin.length && library.jars.length === 1
114
+ ? library.jars[0]
115
+ : undefined
116
+ const abiPairs = java.length
117
+ ? dependencies.flatMap(({ klib, jars }) =>
118
+ jars.length === 1 ? [{ klib, jar: jars[0] }] : [],
119
+ )
120
+ : []
121
+ const dependencyJvmAbi = abiPairs.length ? `${klib}.json` : undefined
122
+ if (dependencyJvmAbi) {
123
+ fs.mkdirSync(input.output, { recursive: true })
124
+ fs.writeFileSync(dependencyJvmAbi, JSON.stringify(abiPairs))
125
+ }
126
+ await compileKotlinLibrarySources({
127
+ ready: input.ready,
128
+ sdkRoot: input.sdkRoot,
129
+ libraries: input.libraries,
130
+ source: { kind: 'files', java, kotlin },
131
+ javaClasspath: classpath,
132
+ release: '17',
133
+ kotlinJvmAbi,
134
+ dependencyJvmAbi,
135
+ kotlinLanguage: input.language,
136
+ dependencies: dependencies.map(({ klib }) => klib),
137
+ output: klib,
138
+ })
139
+ compiled.set(library.coordinate, { klib, jars: library.jars })
140
+ }
141
+ return [...compiled.values()].map(({ klib }) => klib)
142
+ }
@@ -27,6 +27,10 @@ import {
27
27
  readJavaModuleSpecs,
28
28
  } from './java-module-abi'
29
29
  import { kotlinCoroutineDispatcher, kotlinNodeDetection } from './kotlin-browser-seams'
30
+ import {
31
+ compileKotlinGradleLibraries,
32
+ type KotlinGradleLibraries,
33
+ } from './kotlin-gradle-library-plan'
30
34
  import { kotlinInstanceSource } from './kotlin-instance-source'
31
35
  import { installKotlinSdkArchive } from './kotlin-sdk'
32
36
  import { kotlinSkikoSource } from './kotlin-skiko-source'
@@ -924,6 +928,7 @@ export async function kotlinAppArtifact(
924
928
  kotlinOptIns: app.kotlinOptIns,
925
929
  sources: app.sources,
926
930
  javaSpecs: app.javaSources,
931
+ gradleLibraries: app.gradleLibraries,
927
932
  generated,
928
933
  sdkProfile: 'app',
929
934
  usesCompose: true,
@@ -1217,6 +1222,7 @@ async function compileKotlin(
1217
1222
  kotlinOptIns?: readonly string[]
1218
1223
  sources: string[]
1219
1224
  javaSpecs?: string[]
1225
+ gradleLibraries?: KotlinGradleLibraries
1220
1226
  generated: Record<string, string>
1221
1227
  // the app source a generated file rewrites, which its diagnostics name
1222
1228
  origins?: Record<string, string>
@@ -1247,6 +1253,7 @@ async function compileKotlin(
1247
1253
  usesSerialization = false,
1248
1254
  viewModels,
1249
1255
  javaSpecs = [],
1256
+ gradleLibraries,
1250
1257
  } = input
1251
1258
  const sdk = await loadKotlinSdk(moduleRoot, toolchain)
1252
1259
  const plugin = path.join(sdk.root, 'plugin.jar')
@@ -1304,6 +1311,16 @@ async function compileKotlin(
1304
1311
  )
1305
1312
  for (const { file, bytes } of inputs)
1306
1313
  digest.update(path.relative(root, file)).update('\0').update(bytes).update('\0')
1314
+ if (gradleLibraries) {
1315
+ digest.update(JSON.stringify(gradleLibraries))
1316
+ const files = new Set([
1317
+ ...gradleLibraries.classpath,
1318
+ ...gradleLibraries.libraries.flatMap(({ archive, jars }) => [archive, ...jars]),
1319
+ ])
1320
+ for (const file of files) {
1321
+ digest.update(createHash('sha256').update(fs.readFileSync(file)).digest())
1322
+ }
1323
+ }
1307
1324
  if (viewModels) digest.update(viewModels.toolClass)
1308
1325
  for (const [name, text] of Object.entries(generated))
1309
1326
  digest.update(`${name}\0${text}\0`)
@@ -1337,7 +1354,7 @@ async function compileKotlin(
1337
1354
  fs.writeFileSync(target, bytes)
1338
1355
  return { file, target }
1339
1356
  })
1340
- const common = [
1357
+ const common = () => [
1341
1358
  // the full upstream Compose graph exceeds kotlinc's 512 mib default heap.
1342
1359
  '-J-Xmx2g',
1343
1360
  '-Xallow-kotlin-package',
@@ -1349,7 +1366,7 @@ async function compileKotlin(
1349
1366
  run(
1350
1367
  kotlinc,
1351
1368
  [
1352
- ...common,
1369
+ ...common(),
1353
1370
  `-Xplugin=${plugin}`,
1354
1371
  `-Xfriend-modules=${[sdkLibrary, ...(javaLibrary ? [javaLibrary] : [])].join(path.delimiter)}`,
1355
1372
  ...(usesCompose
@@ -1379,6 +1396,18 @@ async function compileKotlin(
1379
1396
  { maxBuffer: 16 * 1024 * 1024 },
1380
1397
  )
1381
1398
  try {
1399
+ if (gradleLibraries) {
1400
+ libraries.push(
1401
+ ...(await compileKotlinGradleLibraries({
1402
+ plan: gradleLibraries,
1403
+ ready,
1404
+ sdkRoot: sdk.root,
1405
+ libraries: libraries.filter((library) => library !== javaLibrary),
1406
+ language,
1407
+ output: path.join(work, 'gradle-libraries'),
1408
+ })),
1409
+ )
1410
+ }
1382
1411
  if (java)
1383
1412
  await compileJavaModuleAbi({
1384
1413
  specs: java,
@@ -1416,7 +1445,7 @@ async function compileKotlin(
1416
1445
  await run(
1417
1446
  kotlinc,
1418
1447
  [
1419
- ...common,
1448
+ ...common(),
1420
1449
  '-nowarn',
1421
1450
  '-Xpartial-linkage-loglevel=error',
1422
1451
  `-Xinclude=${path.join(work, 'klib')}`,
@@ -330,13 +330,6 @@ export async function mavenKotlinSources(
330
330
  return null
331
331
  }
332
332
 
333
- export function readKotlinSourcesArchive(
334
- archive: string,
335
- where: string,
336
- ): Promise<string[]> {
337
- return kotlinSources(readSourcesJar(archive, where), where)
338
- }
339
-
340
333
  export function readMavenSourcesArchive(archive: string): Promise<MavenSources> {
341
334
  return extract(readSourcesJar(archive, archive), archive)
342
335
  }
package/src/plist.ts CHANGED
@@ -180,6 +180,8 @@ function parseXmlDocument(input: string): XmlElementNode {
180
180
  return readElement()
181
181
  }
182
182
 
183
+ export function parseXmlPlist(source: string): PlistValue
184
+ export function parseXmlPlist(source: string, options: ParseXmlPlistOptions): unknown
183
185
  export function parseXmlPlist(
184
186
  source: string,
185
187
  options: ParseXmlPlistOptions = {},
@@ -188,10 +190,6 @@ export function parseXmlPlist(
188
190
  if (root.tag !== 'plist') {
189
191
  throw new Error(`expected <plist> root element, got <${root.tag}>`)
190
192
  }
191
- if (root.children.length === 0) {
192
- if (options.strict) throw new Error('<plist> element has no root value')
193
- return undefined
194
- }
195
193
  if (options.strict && root.children.length !== 1) {
196
194
  throw new Error('<plist> element must contain exactly one root value')
197
195
  }
@@ -206,18 +204,23 @@ export function parseXmlPlist(
206
204
  const visit = (node: XmlElementNode): unknown => {
207
205
  switch (node.tag) {
208
206
  case 'dict': {
209
- const result: Record<string, unknown> = {}
207
+ const entries: [string, unknown][] = []
210
208
  if (options.strict && node.children.length % 2 !== 0) {
211
209
  throw new Error('<dict> must contain key/value pairs')
212
210
  }
213
- for (let i = 0; i + 1 < node.children.length; i += 2) {
211
+ for (let i = 0; i < node.children.length; i += 2) {
214
212
  const keyNode = node.children[i]!
215
213
  if (keyNode.tag !== 'key') {
216
214
  throw new Error(`expected <key> in <dict>, got <${keyNode.tag}>`)
217
215
  }
218
- result[leafText(keyNode)] = visit(node.children[i + 1]!)
216
+ const key = leafText(keyNode)
217
+ if (!options.strict && key === '__proto__') {
218
+ throw new Error('unsupported plist dictionary key __proto__')
219
+ }
220
+ const value = node.children[i + 1]
221
+ entries.push([key, value ? visit(value) : ''])
219
222
  }
220
- return result
223
+ return Object.fromEntries(entries)
221
224
  }
222
225
  case 'array':
223
226
  return node.children.map(visit)
@@ -248,57 +251,11 @@ export function parseXmlPlist(
248
251
  }
249
252
  }
250
253
 
251
- return visit(root.children[0]!)
254
+ return root.children.length === 1 ? visit(root.children[0]!) : root.children.map(visit)
252
255
  }
253
256
 
254
257
  export function parsePlist(source: string): PlistValue {
255
- const root = parseXmlDocument(source)
256
- if (root.tag !== 'plist') {
257
- throw new Error(`expected <plist> root element, got <${root.tag}>`)
258
- }
259
- if (root.children.length === 0) return {}
260
-
261
- const visit = (node: XmlElementNode): PlistValue => {
262
- switch (node.tag) {
263
- case 'dict': {
264
- const result: PlistObject = {}
265
- for (let i = 0; i + 1 < node.children.length; i += 2) {
266
- const keyNode = node.children[i]!
267
- if (keyNode.tag !== 'key') {
268
- throw new Error(`expected <key> in <dict>, got <${keyNode.tag}>`)
269
- }
270
- result[keyNode.text] = visit(node.children[i + 1]!)
271
- }
272
- return result
273
- }
274
- case 'array':
275
- return node.children.map(visit)
276
- case 'string':
277
- return node.text
278
- case 'integer': {
279
- const raw = node.text.trim()
280
- if (!raw) throw new Error('empty <integer> element')
281
- return Number.parseInt(raw, 10)
282
- }
283
- case 'real': {
284
- const raw = node.text.trim()
285
- if (!raw) throw new Error('empty <real> element')
286
- return Number.parseFloat(raw)
287
- }
288
- case 'true':
289
- return true
290
- case 'false':
291
- return false
292
- case 'data':
293
- return Buffer.from(node.text.replace(/\s+/g, ''), 'base64')
294
- case 'date':
295
- return new Date(node.text.trim())
296
- default:
297
- throw new Error(`unsupported plist element ${node.tag}`)
298
- }
299
- }
300
-
301
- return visit(root.children[0]!)
258
+ return parseXmlPlist(source)
302
259
  }
303
260
 
304
261
  export function parsePlistSource(source: string): unknown {