peachsim 0.1.2605 → 0.1.2607

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 (147) hide show
  1. package/cli/commands/package.ts +71 -39
  2. package/cli/commands/perf-native.ts +259 -6
  3. package/cli/commands/shell-url.ts +1 -0
  4. package/dist-lib/agent-daemon-client.cjs +1 -1
  5. package/dist-lib/agent-events.cjs +1 -1
  6. package/dist-lib/attached-projects.cjs +1 -1
  7. package/dist-lib/auth/shared-session.cjs +1 -1
  8. package/dist-lib/backend-origin.cjs +1 -1
  9. package/dist-lib/beta.cjs +1 -1
  10. package/dist-lib/beta.mjs +2 -2
  11. package/dist-lib/bridge-constants.cjs +1 -1
  12. package/dist-lib/bridge-contract-input.cjs +1 -1
  13. package/dist-lib/bridge-contract-input.mjs +5 -5
  14. package/dist-lib/bridge-contract.cjs +1 -1
  15. package/dist-lib/bridge-contract.mjs +3 -3
  16. package/dist-lib/bundle-channel.cjs +1520 -932
  17. package/dist-lib/capture-contract.cjs +1 -1
  18. package/dist-lib/capture-contract.mjs +3 -3
  19. package/dist-lib/cloud-contract.cjs +1 -1
  20. package/dist-lib/cloud-contract.mjs +3 -3
  21. package/dist-lib/cloud-test-args.cjs +1 -1
  22. package/dist-lib/cloud-test-args.mjs +2 -2
  23. package/dist-lib/cloud.cjs +1 -1
  24. package/dist-lib/cloud.mjs +7 -7
  25. package/dist-lib/config.cjs +1 -1
  26. package/dist-lib/config.mjs +5 -5
  27. package/dist-lib/detox/index.cjs +1 -1
  28. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  29. package/dist-lib/esm-chunks/{acorn-UNOYFUKI.mjs → acorn-KFWXYMX5.mjs} +3 -3
  30. package/dist-lib/esm-chunks/{chunk-WSRPZF7M.mjs → chunk-6JPUMAC2.mjs} +1 -1
  31. package/dist-lib/esm-chunks/{chunk-M4G5YUO7.mjs → chunk-6NDABMDX.mjs} +3 -3
  32. package/dist-lib/esm-chunks/{chunk-GT54N3GG.mjs → chunk-7SKDPTZN.mjs} +1 -1
  33. package/dist-lib/esm-chunks/{chunk-FXONOT2L.mjs → chunk-ACAXWH62.mjs} +1 -1
  34. package/dist-lib/esm-chunks/chunk-ARYRQJUB.mjs +326 -0
  35. package/dist-lib/esm-chunks/{chunk-WB2EBX5Q.mjs → chunk-BNAXRY5Q.mjs} +1 -1
  36. package/dist-lib/esm-chunks/{chunk-AST6VA7D.mjs → chunk-CA64UUHF.mjs} +1 -1
  37. package/dist-lib/esm-chunks/{chunk-B54SPDLA.mjs → chunk-DBW62F4N.mjs} +3 -2
  38. package/dist-lib/esm-chunks/{chunk-7K33ENH6.mjs → chunk-ESS2CG5G.mjs} +5 -5
  39. package/dist-lib/esm-chunks/{chunk-LFN7VAPB.mjs → chunk-IGSLOAPL.mjs} +1 -1
  40. package/dist-lib/esm-chunks/{chunk-RJCM34J7.mjs → chunk-KIIALACX.mjs} +1 -1
  41. package/dist-lib/esm-chunks/{chunk-YO756PYQ.mjs → chunk-LJZ373SO.mjs} +819 -681
  42. package/dist-lib/esm-chunks/{chunk-VRQPEROV.mjs → chunk-M4ORY3NH.mjs} +1 -1
  43. package/dist-lib/esm-chunks/{chunk-3XUIDCBF.mjs → chunk-MBWWOGI5.mjs} +4 -4
  44. package/dist-lib/esm-chunks/{chunk-M3V4F5OV.mjs → chunk-O5BPZVLB.mjs} +5 -5
  45. package/dist-lib/esm-chunks/chunk-P5Q5QCTP.mjs +32 -0
  46. package/dist-lib/esm-chunks/{chunk-O55DZ2EL.mjs → chunk-QJUAWJDB.mjs} +1 -1
  47. package/dist-lib/esm-chunks/{chunk-HHS4A7GI.mjs → chunk-RIDXKGBZ.mjs} +1 -1
  48. package/dist-lib/esm-chunks/{chunk-LG76KUUO.mjs → chunk-TD2DBEKQ.mjs} +1 -1
  49. package/dist-lib/esm-chunks/{chunk-AYHTHFG4.mjs → chunk-UTSB5CDG.mjs} +1 -1
  50. package/dist-lib/esm-chunks/{chunk-UPUOCALX.mjs → chunk-WMWOBH7E.mjs} +1 -1
  51. package/dist-lib/esm-chunks/{chunk-6TE7WLSF.mjs → chunk-ZNGLVJYL.mjs} +1 -1
  52. package/dist-lib/esm-chunks/{metro-layout-parser-YRBZCLVD.mjs → metro-layout-parser-UY3B6VGU.mjs} +3 -3
  53. package/dist-lib/esm-chunks/{swift-package-prebuilt-S7KR6TKE.mjs → swift-package-prebuilt-HDHPWS44.mjs} +10 -10
  54. package/dist-lib/esm-chunks/{swift-sdk-app-module-3JNA7PCB.mjs → swift-sdk-app-module-U6G5RZV2.mjs} +14 -14
  55. package/dist-lib/esm-chunks/{swift-sdk-image-3P4IUP2A.mjs → swift-sdk-image-PVDA2MVM.mjs} +14 -14
  56. package/dist-lib/esm-chunks/{swift-sdk-image-producer-EA2RYBM4.mjs → swift-sdk-image-producer-YHPS3KNR.mjs} +4 -4
  57. package/dist-lib/expo-swift-bundle.cjs +1519 -931
  58. package/dist-lib/expo-swift-metadata.cjs +1 -1
  59. package/dist-lib/expo-swift-metadata.mjs +7 -7
  60. package/dist-lib/home-paths.cjs +1 -1
  61. package/dist-lib/host/bridge-host.cjs +1677 -947
  62. package/dist-lib/host/fetch-proxy-handler.cjs +44 -37
  63. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  64. package/dist-lib/host/fetch-proxy-overrides.mjs +2 -2
  65. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  66. package/dist-lib/host/websocket-proxy.cjs +1 -1
  67. package/dist-lib/index.cjs +1 -1
  68. package/dist-lib/kotlin-host.cjs +1 -1
  69. package/dist-lib/menu.cjs +1 -1
  70. package/dist-lib/menu.mjs +3 -3
  71. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  72. package/dist-lib/metro-fingerprint-registry.mjs +3 -3
  73. package/dist-lib/metro-production-bundle.cjs +1 -1
  74. package/dist-lib/metro-production-bundle.mjs +4 -4
  75. package/dist-lib/native-app-identity-project.cjs +540 -247
  76. package/dist-lib/native-app-identity-project.mjs +218 -1828
  77. package/dist-lib/native-app-identity.cjs +1 -1
  78. package/dist-lib/native-app-identity.mjs +6 -6
  79. package/dist-lib/native-firebase-metadata.cjs +1 -1
  80. package/dist-lib/native-firebase-metadata.mjs +3 -3
  81. package/dist-lib/pdfium-raster.cjs +1 -1
  82. package/dist-lib/pdfium-raster.mjs +2 -2
  83. package/dist-lib/plist.cjs +327 -15
  84. package/dist-lib/plist.mjs +13 -5
  85. package/dist-lib/profiles.cjs +1 -1
  86. package/dist-lib/public-brand.cjs +1 -1
  87. package/dist-lib/public-origins-lib-esm.json +82 -129
  88. package/dist-lib/public-origins-lib.json +69 -140
  89. package/dist-lib/react-native-host-modules.cjs +1 -1
  90. package/dist-lib/react-native-host-modules.mjs +2 -2
  91. package/dist-lib/reap-browser.cjs +1 -1
  92. package/dist-lib/scripts/dev-server-scanner.cjs +211 -3
  93. package/dist-lib/sdk.cjs +1 -1
  94. package/dist-lib/sdk.mjs +8 -8
  95. package/dist-lib/skills.cjs +1693 -963
  96. package/dist-lib/swift-compile.cjs +812 -673
  97. package/dist-lib/swift-compile.mjs +10 -10
  98. package/dist-lib/swift-package.cjs +1 -1
  99. package/dist-lib/swift-package.mjs +3 -3
  100. package/dist-lib/swift-submit.cjs +1 -1
  101. package/dist-lib/swift-submit.mjs +6 -6
  102. package/dist-lib/swift-svg-raster.cjs +1 -1
  103. package/dist-lib/swift-svg-raster.mjs +2 -2
  104. package/dist-lib/swift-toolchain.cjs +3 -2
  105. package/dist-lib/swift.cjs +1 -1
  106. package/dist-lib/vendor/@peculiar/x509.cjs +1 -1
  107. package/dist-lib/vendor/@ruby/prism/src/nodes.js.cjs +1 -1
  108. package/dist-lib/vendor/@ruby/prism/src/parsePrism.js.cjs +1 -1
  109. package/dist-lib/vendor/acorn.cjs +1 -1
  110. package/dist-lib/vendor/magic-string.cjs +1 -1
  111. package/dist-lib/vendor/stream-json.cjs +1 -1
  112. package/dist-lib/vendor/sucrase/dist/index.js.cjs +1 -1
  113. package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +1 -1
  114. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +1 -1
  115. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +1 -1
  116. package/dist-lib/vendor/sucrase.cjs +1 -1
  117. package/dist-lib/vendor/terser.cjs +1 -1
  118. package/dist-lib/vendor/valibot.cjs +1 -1
  119. package/dist-lib/vendor/ws.cjs +1 -1
  120. package/dist-lib/vendor/zod.cjs +1 -1
  121. package/dist-lib/worklet-executable.cjs +1 -1
  122. package/dist-lib/worklet-executable.mjs +3 -3
  123. package/dist-types/packages/peach-engine/src/ios/apps/canvas-map-data.d.ts +38 -2
  124. package/dist-types/packages/peach-globals/src/canvasAgentContract.d.ts +8 -0
  125. package/dist-types/packages/peach-globals/src/index.d.ts +1 -1
  126. package/package.json +1 -6
  127. package/src/agent-prompt.ts +5 -1
  128. package/src/bazel-project.ts +1 -1
  129. package/src/expo-native-prebuilt.ts +1 -1
  130. package/src/expo-workspace-exclusion.ts +1 -1
  131. package/src/gitignore.ts +175 -0
  132. package/src/intent-definition/plist-reader.ts +22 -168
  133. package/src/one-native-controls-package.ts +143 -1
  134. package/src/oneNativeControlsContract.ts +1 -0
  135. package/src/plist-bytes.ts +144 -2
  136. package/src/plist.ts +359 -2
  137. package/src/swift-compile-budget.ts +28 -7
  138. package/src/swift-compile.ts +972 -809
  139. package/src/swift-guest-compile.ts +3 -0
  140. package/src/swift-toolchain.ts +4 -1
  141. package/src/xcode-project.ts +1 -1
  142. package/dist-lib/esm-chunks/chunk-OW4VRQKO.mjs +0 -10993
  143. package/dist-lib/esm-chunks/chunk-ZSHGFGW7.mjs +0 -65
  144. package/dist-lib/vendor/@xmldom/xmldom.cjs +0 -6481
  145. package/dist-lib/vendor/bplist-parser.cjs +0 -1589
  146. package/dist-lib/vendor/ignore.cjs +0 -455
  147. package/dist-lib/vendor/plist.cjs +0 -10978
@@ -1,13 +1,155 @@
1
- import binaryPlist from 'bplist-parser'
1
+ import assert from 'node:assert/strict'
2
2
  import { parsePlistSource } from './plist'
3
3
 
4
+ export interface ParseBinaryPlistOptions {
5
+ strict?: boolean
6
+ onInteger?: (value: bigint) => unknown
7
+ onReal?: (value: number) => unknown
8
+ }
9
+
10
+ function defaultInteger(value: bigint): number | bigint {
11
+ return value >= BigInt(Number.MIN_SAFE_INTEGER) &&
12
+ value <= BigInt(Number.MAX_SAFE_INTEGER)
13
+ ? Number(value)
14
+ : value
15
+ }
16
+
17
+ export function parseBinaryPlist(
18
+ source: Uint8Array,
19
+ options: ParseBinaryPlistOptions = {},
20
+ ): unknown {
21
+ const bytes = Buffer.isBuffer(source) ? source : Buffer.from(source)
22
+ assert(bytes.length >= 40, 'binary plist is too short')
23
+ assert(bytes.toString('ascii', 0, 8) === 'bplist00', 'invalid binary plist header')
24
+ const trailer = bytes.length - 32
25
+ const offsetWidth = bytes[trailer + 6]!
26
+ const refWidth = bytes[trailer + 7]!
27
+ assert(offsetWidth > 0 && offsetWidth <= 8 && refWidth > 0 && refWidth <= 8)
28
+ const count = Number(bytes.readBigUInt64BE(trailer + 8))
29
+ const root = Number(bytes.readBigUInt64BE(trailer + 16))
30
+ const table = Number(bytes.readBigUInt64BE(trailer + 24))
31
+ assert(
32
+ table >= 8 &&
33
+ table < trailer &&
34
+ count > 0 &&
35
+ count <= (trailer - table) / offsetWidth,
36
+ )
37
+ const unsigned = (at: number, width: number): bigint => {
38
+ assert(at >= 8 && at + width <= trailer)
39
+ let result = 0n
40
+ for (let i = at; i < at + width; i++) result = result * 256n + BigInt(bytes[i]!)
41
+ return result
42
+ }
43
+ const cache = new Map<number, unknown>()
44
+ const visiting = new Set<number>()
45
+ const visit = (ref: number): unknown => {
46
+ assert(ref >= 0 && ref < count && !visiting.has(ref))
47
+ if (cache.has(ref)) return cache.get(ref)
48
+ visiting.add(ref)
49
+ const at = Number(unsigned(table + ref * offsetWidth, offsetWidth))
50
+ assert(at >= 8 && at < table)
51
+ const marker = bytes[at]!
52
+ const type = marker >> 4
53
+ let length = marker & 15
54
+ let data = at + 1
55
+ if (length === 15 && [4, 5, 6, 7, 10, 12, 13].includes(type)) {
56
+ assert(data < table && bytes[data]! >> 4 === 1)
57
+ const width = 2 ** (bytes[data]! & 15)
58
+ assert(width <= 8 && data + 1 + width <= table)
59
+ length = Number(unsigned(data + 1, width))
60
+ data += 1 + width
61
+ }
62
+ const end = (size: number): number => {
63
+ assert(Number.isSafeInteger(size) && data + size <= table)
64
+ return data + size
65
+ }
66
+ const references = (total: number): unknown[] => {
67
+ end(total * refWidth)
68
+ return Array.from({ length: total }, (_, i) =>
69
+ visit(Number(unsigned(data + i * refWidth, refWidth))),
70
+ )
71
+ }
72
+ let value: unknown
73
+ switch (type) {
74
+ case 0:
75
+ if (!options.strict && marker === 0) {
76
+ value = null
77
+ break
78
+ }
79
+ assert(marker === 8 || marker === 9)
80
+ value = marker === 9
81
+ break
82
+ case 1: {
83
+ const size = 2 ** length
84
+ assert(size <= 16)
85
+ end(size)
86
+ const raw = unsigned(data, size)
87
+ const signed = size >= 8 ? BigInt.asIntN(size * 8, raw) : raw
88
+ value = options.onInteger ? options.onInteger(signed) : defaultInteger(signed)
89
+ break
90
+ }
91
+ case 2: {
92
+ assert(length === 2 || length === 3)
93
+ end(2 ** length)
94
+ const real = length === 2 ? bytes.readFloatBE(data) : bytes.readDoubleBE(data)
95
+ value = options.onReal ? options.onReal(real) : real
96
+ break
97
+ }
98
+ case 3:
99
+ assert(length === 3)
100
+ end(8)
101
+ value = new Date(Date.UTC(2001, 0, 1) + bytes.readDoubleBE(data) * 1000)
102
+ break
103
+ case 4:
104
+ value = bytes.subarray(data, end(length))
105
+ break
106
+ case 5:
107
+ value = bytes.toString('ascii', data, end(length))
108
+ break
109
+ case 6:
110
+ value = Buffer.from(bytes.subarray(data, end(length * 2)))
111
+ .swap16()
112
+ .toString('utf16le')
113
+ break
114
+ case 7:
115
+ value = bytes.toString('utf8', data, end(length))
116
+ break
117
+ case 8: {
118
+ if (options.strict) throw new Error(`unsupported binary plist type ${type}`)
119
+ const size = length + 1
120
+ assert(size >= 1 && size <= 8)
121
+ end(size)
122
+ value = { UID: Number(unsigned(data, size)) }
123
+ break
124
+ }
125
+ case 10:
126
+ case 12:
127
+ value = references(length)
128
+ break
129
+ case 13: {
130
+ const elements = references(length * 2)
131
+ const keys = elements.slice(0, length)
132
+ assert(keys.every((key) => typeof key === 'string'))
133
+ value = Object.fromEntries(keys.map((key, i) => [key, elements[length + i]]))
134
+ break
135
+ }
136
+ default:
137
+ throw new Error(`unsupported binary plist type ${type}`)
138
+ }
139
+ visiting.delete(ref)
140
+ cache.set(ref, value)
141
+ return value
142
+ }
143
+ return visit(root)
144
+ }
145
+
4
146
  export function parsePlistBytes(
5
147
  source: Uint8Array,
6
148
  parseXml: (source: string) => unknown = parsePlistSource,
7
149
  ): unknown {
8
150
  const bytes = Buffer.from(source)
9
151
  return bytes.subarray(0, 8).toString('ascii') === 'bplist00'
10
- ? binaryPlist.parseBuffer<unknown>(bytes)[0]
152
+ ? parseBinaryPlist(bytes)
11
153
  : parseXml(bytes.toString('utf8'))
12
154
  }
13
155
 
package/src/plist.ts CHANGED
@@ -1,5 +1,362 @@
1
- import plist from 'plist'
1
+ export type PlistValue =
2
+ | string
3
+ | number
4
+ | boolean
5
+ | Date
6
+ | Buffer
7
+ | PlistObject
8
+ | PlistArray
9
+
10
+ export type PlistObject = { [key: string]: PlistValue }
11
+ export type PlistArray = PlistValue[]
12
+
13
+ export interface ParseXmlPlistOptions {
14
+ strict?: boolean
15
+ onInteger?: (raw: string) => unknown
16
+ onReal?: (raw: string) => unknown
17
+ }
18
+
19
+ const NAMED_ENTITIES: Record<string, string> = {
20
+ amp: '&',
21
+ lt: '<',
22
+ gt: '>',
23
+ quot: '"',
24
+ apos: "'",
25
+ }
26
+
27
+ function decodeXmlEntities(text: string): string {
28
+ if (!text.includes('&')) return text
29
+ return text.replace(/&(#x[0-9a-fA-F]+|#[0-9]+|[a-zA-Z]+);/g, (full, entity: string) => {
30
+ if (entity.startsWith('#x') || entity.startsWith('#X')) {
31
+ const code = Number.parseInt(entity.slice(2), 16)
32
+ return Number.isFinite(code) ? String.fromCodePoint(code) : full
33
+ }
34
+ if (entity.startsWith('#')) {
35
+ const code = Number.parseInt(entity.slice(1), 10)
36
+ return Number.isFinite(code) ? String.fromCodePoint(code) : full
37
+ }
38
+ return NAMED_ENTITIES[entity] ?? full
39
+ })
40
+ }
41
+
42
+ function escapeXmlText(text: string): string {
43
+ return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
44
+ }
45
+
46
+ interface XmlElementNode {
47
+ tag: string
48
+ children: XmlElementNode[]
49
+ text: string
50
+ }
51
+
52
+ function parseXmlDocument(input: string): XmlElementNode {
53
+ const source = input.startsWith('\uFEFF') ? input.slice(1) : input
54
+ const len = source.length
55
+ let pos = 0
56
+
57
+ const skipIgnorable = () => {
58
+ while (pos < len) {
59
+ while (pos < len && /\s/.test(source[pos]!)) pos++
60
+ if (source.startsWith('<!--', pos)) {
61
+ const end = source.indexOf('-->', pos + 4)
62
+ if (end === -1) throw new Error('unterminated XML comment')
63
+ pos = end + 3
64
+ continue
65
+ }
66
+ if (source.startsWith('<?', pos)) {
67
+ const end = source.indexOf('?>', pos + 2)
68
+ if (end === -1) throw new Error('unterminated XML processing instruction')
69
+ pos = end + 2
70
+ continue
71
+ }
72
+ if (source.startsWith('<!DOCTYPE', pos)) {
73
+ pos += 9
74
+ let depth = 0
75
+ let quote = ''
76
+ while (pos < len) {
77
+ const ch = source[pos]!
78
+ pos++
79
+ if (quote) {
80
+ if (ch === quote) quote = ''
81
+ } else if (ch === '"' || ch === "'") {
82
+ quote = ch
83
+ } else if (ch === '[') {
84
+ depth++
85
+ } else if (ch === ']') {
86
+ depth = Math.max(0, depth - 1)
87
+ } else if (ch === '>' && depth === 0) {
88
+ break
89
+ }
90
+ }
91
+ continue
92
+ }
93
+ break
94
+ }
95
+ }
96
+
97
+ const readElement = (): XmlElementNode => {
98
+ if (source[pos] !== '<') {
99
+ throw new Error(`expected XML tag at offset ${pos}`)
100
+ }
101
+ pos++
102
+ const nameStart = pos
103
+ while (pos < len && /[^\s/>]/.test(source[pos]!)) pos++
104
+ const tag = source.slice(nameStart, pos)
105
+ if (!tag) throw new Error(`empty XML tag name at offset ${nameStart}`)
106
+
107
+ // skip attributes until > or />
108
+ let quote = ''
109
+ let selfClosing = false
110
+ while (pos < len) {
111
+ const ch = source[pos]!
112
+ if (quote) {
113
+ pos++
114
+ if (ch === quote) quote = ''
115
+ continue
116
+ }
117
+ if (ch === '"' || ch === "'") {
118
+ quote = ch
119
+ pos++
120
+ continue
121
+ }
122
+ if (ch === '/' && source[pos + 1] === '>') {
123
+ selfClosing = true
124
+ pos += 2
125
+ break
126
+ }
127
+ if (ch === '>') {
128
+ pos++
129
+ break
130
+ }
131
+ pos++
132
+ }
133
+ if (selfClosing) {
134
+ return { tag, children: [], text: '' }
135
+ }
136
+
137
+ const children: XmlElementNode[] = []
138
+ let text = ''
139
+ while (pos < len) {
140
+ if (source.startsWith('<!--', pos)) {
141
+ const end = source.indexOf('-->', pos + 4)
142
+ if (end === -1) throw new Error('unterminated XML comment')
143
+ pos = end + 3
144
+ continue
145
+ }
146
+ if (source.startsWith('<![CDATA[', pos)) {
147
+ const end = source.indexOf(']]>', pos + 9)
148
+ if (end === -1) throw new Error('unterminated CDATA section')
149
+ text += source.slice(pos + 9, end)
150
+ pos = end + 3
151
+ continue
152
+ }
153
+ if (source.startsWith('</', pos)) {
154
+ pos += 2
155
+ const closeStart = pos
156
+ while (pos < len && /[^\s>]/.test(source[pos]!)) pos++
157
+ const closeTag = source.slice(closeStart, pos)
158
+ while (pos < len && /\s/.test(source[pos]!)) pos++
159
+ if (source[pos] !== '>') throw new Error(`malformed closing tag </${closeTag}>`)
160
+ pos++
161
+ if (closeTag !== tag) {
162
+ throw new Error(`mismatched XML closing tag </${closeTag}> for <${tag}>`)
163
+ }
164
+ return { tag, children, text }
165
+ }
166
+ if (source[pos] === '<') {
167
+ children.push(readElement())
168
+ continue
169
+ }
170
+ const nextTag = source.indexOf('<', pos)
171
+ const end = nextTag === -1 ? len : nextTag
172
+ text += decodeXmlEntities(source.slice(pos, end))
173
+ pos = end
174
+ }
175
+ throw new Error(`unclosed XML tag <${tag}>`)
176
+ }
177
+
178
+ skipIgnorable()
179
+ if (pos >= len) throw new Error('empty XML plist document')
180
+ return readElement()
181
+ }
182
+
183
+ export function parseXmlPlist(
184
+ source: string,
185
+ options: ParseXmlPlistOptions = {},
186
+ ): unknown {
187
+ const root = parseXmlDocument(source)
188
+ if (root.tag !== 'plist') {
189
+ throw new Error(`expected <plist> root element, got <${root.tag}>`)
190
+ }
191
+ if (root.children.length === 0) {
192
+ if (options.strict) throw new Error('<plist> element has no root value')
193
+ return undefined
194
+ }
195
+ if (options.strict && root.children.length !== 1) {
196
+ throw new Error('<plist> element must contain exactly one root value')
197
+ }
198
+
199
+ const leafText = (node: XmlElementNode): string => {
200
+ if (options.strict && node.children.length > 0) {
201
+ throw new Error(`<${node.tag}> must not contain child elements`)
202
+ }
203
+ return node.text
204
+ }
205
+
206
+ const visit = (node: XmlElementNode): unknown => {
207
+ switch (node.tag) {
208
+ case 'dict': {
209
+ const result: Record<string, unknown> = {}
210
+ if (options.strict && node.children.length % 2 !== 0) {
211
+ throw new Error('<dict> must contain key/value pairs')
212
+ }
213
+ for (let i = 0; i + 1 < node.children.length; i += 2) {
214
+ const keyNode = node.children[i]!
215
+ if (keyNode.tag !== 'key') {
216
+ throw new Error(`expected <key> in <dict>, got <${keyNode.tag}>`)
217
+ }
218
+ result[leafText(keyNode)] = visit(node.children[i + 1]!)
219
+ }
220
+ return result
221
+ }
222
+ case 'array':
223
+ return node.children.map(visit)
224
+ case 'string':
225
+ return leafText(node)
226
+ case 'integer': {
227
+ const raw = leafText(node).trim()
228
+ if (options.onInteger) return options.onInteger(raw)
229
+ if (!raw) throw new Error('empty <integer> element')
230
+ return Number.parseInt(raw, 10)
231
+ }
232
+ case 'real': {
233
+ const raw = leafText(node).trim()
234
+ if (options.onReal) return options.onReal(raw)
235
+ if (!raw) throw new Error('empty <real> element')
236
+ return Number.parseFloat(raw)
237
+ }
238
+ case 'true':
239
+ return true
240
+ case 'false':
241
+ return false
242
+ case 'data':
243
+ return Buffer.from(leafText(node).replace(/\s+/g, ''), 'base64')
244
+ case 'date':
245
+ return new Date(leafText(node).trim())
246
+ default:
247
+ throw new Error(`unsupported plist element ${node.tag}`)
248
+ }
249
+ }
250
+
251
+ return visit(root.children[0]!)
252
+ }
253
+
254
+ 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]!)
302
+ }
2
303
 
3
304
  export function parsePlistSource(source: string): unknown {
4
- return plist.parse(source)
305
+ return parseXmlPlist(source)
306
+ }
307
+
308
+ function renderValue(value: unknown, indent: string): string | null {
309
+ if (value === undefined || value === null) return null
310
+ if (typeof value === 'string') {
311
+ return `${indent}<string>${escapeXmlText(value)}</string>`
312
+ }
313
+ if (typeof value === 'boolean') {
314
+ return `${indent}${value ? '<true/>' : '<false/>'}`
315
+ }
316
+ if (typeof value === 'number') {
317
+ if (Number.isInteger(value) && !Object.is(value, -0)) {
318
+ return `${indent}<integer>${value}</integer>`
319
+ }
320
+ return `${indent}<real>${value}</real>`
321
+ }
322
+ if (value instanceof Date) {
323
+ return `${indent}<date>${value.toISOString().replace(/\.\d{3}Z$/, 'Z')}</date>`
324
+ }
325
+ if (Buffer.isBuffer(value) || value instanceof Uint8Array) {
326
+ const encoded = Buffer.from(value).toString('base64')
327
+ return encoded ? `${indent}<data>${encoded}</data>` : `${indent}<data/>`
328
+ }
329
+ if (Array.isArray(value)) {
330
+ const items = value
331
+ .map((entry) => renderValue(entry, `${indent} `))
332
+ .filter((entry): entry is string => entry !== null)
333
+ if (items.length === 0) return `${indent}<array/>`
334
+ return `${indent}<array>\n${items.join('\n')}\n${indent}</array>`
335
+ }
336
+ if (typeof value === 'object') {
337
+ const lines: string[] = []
338
+ for (const [key, entry] of Object.entries(value)) {
339
+ const rendered = renderValue(entry, `${indent} `)
340
+ if (rendered === null) continue
341
+ lines.push(`${indent} <key>${escapeXmlText(key)}</key>`)
342
+ lines.push(rendered)
343
+ }
344
+ if (lines.length === 0) return `${indent}<dict/>`
345
+ return `${indent}<dict>\n${lines.join('\n')}\n${indent}</dict>`
346
+ }
347
+ throw new Error(`unsupported plist value type: ${typeof value}`)
348
+ }
349
+
350
+ export function buildPlist(value: PlistValue): string {
351
+ const body = renderValue(value, ' ')
352
+ return [
353
+ '<?xml version="1.0" encoding="UTF-8"?>',
354
+ '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
355
+ '<plist version="1.0">',
356
+ ...(body ? [body] : []),
357
+ '</plist>',
358
+ '',
359
+ ].join('\n')
5
360
  }
361
+
362
+ export { parsePlist as parse, buildPlist as build }
@@ -10,31 +10,52 @@ export function swiftBuilderHopTimeoutMs(compileTimeoutMs: number | undefined):
10
10
  )
11
11
  }
12
12
 
13
+ // the compile budget bounds a stall, not a build: compiler output and stage
14
+ // changes restart it, so a large app that keeps progressing is never cut off.
13
15
  export async function withSwiftCompileBudget<T>(
14
16
  compileTimeoutMs: number | undefined,
15
17
  signal: AbortSignal | undefined,
16
- work: (budget: { signal: AbortSignal; startCompile(): void }) => Promise<T>,
18
+ work: (budget: {
19
+ signal: AbortSignal
20
+ startCompile(): void
21
+ progress(): void
22
+ }) => Promise<T>,
17
23
  ): Promise<T> {
18
24
  const deadline = new AbortController()
19
25
  const combined = signal ? AbortSignal.any([signal, deadline.signal]) : deadline.signal
26
+ const stallMs = compileTimeoutMs ?? SWIFT_COMPILE_TIMEOUT_MS
27
+ let compiling = false
20
28
  let timer = setTimeout(
21
29
  () => deadline.abort(new Error('Swift build lock wait timed out')),
22
30
  SWIFT_LOCK_WAIT_TIMEOUT_MS,
23
31
  )
32
+ const restart = () => {
33
+ clearTimeout(timer)
34
+ timer = setTimeout(
35
+ () =>
36
+ deadline.abort(
37
+ new Error(
38
+ `Swift compilation made no progress for ${Math.round(stallMs / 1000)}s`,
39
+ ),
40
+ ),
41
+ stallMs,
42
+ )
43
+ }
24
44
  try {
25
45
  combined.throwIfAborted()
26
46
  const result = await work({
27
47
  signal: combined,
28
48
  startCompile() {
29
49
  combined.throwIfAborted()
30
- clearTimeout(timer)
31
- timer = setTimeout(
32
- () => deadline.abort(new Error('Swift compilation timed out')),
33
- compileTimeoutMs ?? SWIFT_COMPILE_TIMEOUT_MS,
34
- )
50
+ compiling = true
51
+ restart()
52
+ },
53
+ progress() {
54
+ if (compiling && !deadline.signal.aborted) restart()
35
55
  },
36
56
  })
37
- combined.throwIfAborted()
57
+ // a finished build is kept even if a silent final step outlasted the stall bound.
58
+ signal?.throwIfAborted()
38
59
  return result
39
60
  } finally {
40
61
  clearTimeout(timer)