peachsim 0.1.1808 → 0.1.1811

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 (229) hide show
  1. package/README.md +4 -2
  2. package/cli/app-bundle-resources.ts +15 -2
  3. package/cli/cloud-box-artifact.ts +115 -0
  4. package/cli/cloud-client.ts +95 -53
  5. package/cli/cloud-dispatch.ts +4 -4
  6. package/cli/cloud-session.ts +60 -22
  7. package/cli/commands/box.ts +8 -2
  8. package/cli/commands/compat.ts +7 -4
  9. package/cli/commands/control.ts +60 -3
  10. package/cli/commands/coverage.ts +14 -4
  11. package/cli/commands/daemon.ts +41 -0
  12. package/cli/commands/no-bridge-hint.ts +9 -0
  13. package/cli/commands/package.ts +31 -56
  14. package/cli/commands/platform.ts +70 -52
  15. package/cli/commands/preview.ts +73 -24
  16. package/cli/commands/record.ts +10 -2
  17. package/cli/commands/screenshot.ts +17 -60
  18. package/cli/commands/setup.ts +3 -1
  19. package/cli/commands/three-mode.ts +22 -12
  20. package/cli/commands/upload.ts +2 -1
  21. package/cli/desktop-companion.ts +6 -1
  22. package/cli/drivers/desktop.ts +4 -1
  23. package/cli/main.ts +12 -2
  24. package/cli/metro-bundle-assets.ts +14 -4
  25. package/cli/outbound-endpoints.ts +7 -3
  26. package/cli/output-redaction.ts +38 -0
  27. package/cli/privacy.ts +2 -2
  28. package/cli/recording-access.ts +5 -0
  29. package/cli/remote-project-bundle.ts +83 -0
  30. package/cli/shell-init.ts +7 -11
  31. package/cli/telemetry.ts +41 -4
  32. package/cli/usage-error.ts +3 -0
  33. package/cli/ws-bridge.ts +42 -6
  34. package/dist-lib/agent-daemon-client.cjs +1 -1
  35. package/dist-lib/agent-events.cjs +1 -1
  36. package/dist-lib/attached-projects.cjs +1 -1
  37. package/dist-lib/auth/shared-session.cjs +1 -1
  38. package/dist-lib/backend-origin.cjs +1 -1
  39. package/dist-lib/beta.cjs +1 -1
  40. package/dist-lib/beta.mjs +1 -1
  41. package/dist-lib/bridge-constants.cjs +1 -1
  42. package/dist-lib/bridge-contract-input.cjs +1 -1
  43. package/dist-lib/bridge-contract-input.mjs +1 -1
  44. package/dist-lib/bridge-contract.cjs +1 -1
  45. package/dist-lib/bridge-contract.mjs +1 -1
  46. package/dist-lib/bundle-channel.cjs +42783 -40717
  47. package/dist-lib/capture-contract.cjs +7 -8
  48. package/dist-lib/capture-contract.mjs +7 -8
  49. package/dist-lib/cloud-contract.cjs +1 -1
  50. package/dist-lib/cloud-contract.mjs +1 -1
  51. package/dist-lib/cloud-test-args.cjs +1 -1
  52. package/dist-lib/cloud-test-args.mjs +1 -1
  53. package/dist-lib/cloud.cjs +1 -1
  54. package/dist-lib/cloud.mjs +1 -1
  55. package/dist-lib/config.cjs +1 -1
  56. package/dist-lib/config.mjs +1 -1
  57. package/dist-lib/detox/index.cjs +13 -7
  58. package/dist-lib/dev-bundle-resolution.cjs +10 -4
  59. package/dist-lib/expo-swift-bundle.cjs +15819 -15559
  60. package/dist-lib/expo-swift-metadata.cjs +2 -1
  61. package/dist-lib/expo-swift-metadata.mjs +2 -1
  62. package/dist-lib/home-paths.cjs +2 -33
  63. package/dist-lib/host/bridge-host.cjs +20857 -18756
  64. package/dist-lib/host/fetch-proxy-handler.cjs +10 -10
  65. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  66. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  67. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  68. package/dist-lib/host/websocket-proxy.cjs +1 -1
  69. package/dist-lib/index.cjs +588 -544
  70. package/dist-lib/jump-to-source-babel.cjs +1 -1
  71. package/dist-lib/jump-to-source-native.cjs +1 -1
  72. package/dist-lib/kotlin-host.cjs +1 -1
  73. package/dist-lib/menu.cjs +1 -1
  74. package/dist-lib/menu.mjs +1 -1
  75. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  76. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  77. package/dist-lib/metro-production-bundle.cjs +1 -1
  78. package/dist-lib/metro-production-bundle.mjs +1 -1
  79. package/dist-lib/metro.cjs +25 -19
  80. package/dist-lib/native-app-identity-project.cjs +15 -6
  81. package/dist-lib/native-app-identity-project.mjs +23 -12
  82. package/dist-lib/native-app-identity.cjs +1 -1
  83. package/dist-lib/native-app-identity.mjs +1 -1
  84. package/dist-lib/native-firebase-metadata.cjs +1 -1
  85. package/dist-lib/native-firebase-metadata.mjs +1 -1
  86. package/dist-lib/pdfium-raster.cjs +1 -1
  87. package/dist-lib/pdfium-raster.mjs +1 -1
  88. package/dist-lib/plist.cjs +1 -1
  89. package/dist-lib/plist.mjs +1 -1
  90. package/dist-lib/profiles.cjs +1 -1
  91. package/dist-lib/public-brand.cjs +1 -1
  92. package/dist-lib/public-origins-lib-esm.json +27 -26
  93. package/dist-lib/public-origins-lib.json +104 -81
  94. package/dist-lib/react-native-host-modules.cjs +1 -1
  95. package/dist-lib/react-native-host-modules.mjs +1 -1
  96. package/dist-lib/reap-browser.cjs +1 -1
  97. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  98. package/dist-lib/sdk.cjs +1 -1
  99. package/dist-lib/sdk.mjs +1 -1
  100. package/dist-lib/skills.cjs +30496 -24309
  101. package/dist-lib/swift-compile.cjs +292 -213
  102. package/dist-lib/swift-compile.mjs +334 -254
  103. package/dist-lib/swift-package.cjs +8 -4
  104. package/dist-lib/swift-package.mjs +8 -4
  105. package/dist-lib/swift-submit.cjs +1 -1
  106. package/dist-lib/swift-submit.mjs +1 -1
  107. package/dist-lib/swift-toolchain.cjs +32 -1
  108. package/dist-lib/swift.cjs +1 -1
  109. package/dist-lib/vite-swift.cjs +19172 -18941
  110. package/dist-lib/vite.cjs +11 -11
  111. package/dist-lib/worklet-executable.cjs +1 -1
  112. package/dist-lib/worklet-executable.mjs +1 -1
  113. package/dist-types/packages/peach-engine/src/engine/animated.d.ts +4 -0
  114. package/dist-types/packages/peach-engine/src/engine/animation-graph.d.ts +1 -0
  115. package/dist-types/packages/peach-engine/src/engine/expo-manifest.d.ts +1 -0
  116. package/dist-types/packages/peach-engine/src/engine/image-loader.d.ts +1 -1
  117. package/dist-types/packages/peach-engine/src/preview/upload-protocol.d.ts +1 -0
  118. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +8 -1
  119. package/dist-types/packages/peach-globals/src/electronBridgeContract.d.ts +2 -1
  120. package/dist-types/packages/peach-kit/src/capabilities.d.ts +1 -0
  121. package/kotlin/sdk.tar.gz +0 -0
  122. package/package.json +1 -1
  123. package/runtime-companion.json +1 -1
  124. package/sdk/ios/System/Library/Frameworks/CoreTelephony.framework/Headers/CTCall.h +1 -1
  125. package/sdk/ios/System/Library/Frameworks/CoreTelephony.framework/Headers/CTCallCenter.h +1 -1
  126. package/sdk/ios/System/Library/Frameworks/CoreTelephony.framework/Headers/CTCarrier.h +1 -1
  127. package/sdk/ios/System/Library/Frameworks/CoreTelephony.framework/Headers/CTSubscriber.h +1 -1
  128. package/sdk/ios/System/Library/Frameworks/CoreTelephony.framework/Headers/CTSubscriberInfo.h +1 -1
  129. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/NSArray.h +1 -1
  130. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/NSDictionary.h +1 -1
  131. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/NSExtensionItem.h +1 -1
  132. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/AVFoundation+MPNowPlayingInfoLanguageOptionAdditions.h +39 -0
  133. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/AVPlayerItem+MediaPlayerAdditions.h +26 -0
  134. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPContentItem.h +67 -0
  135. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPError.h +33 -0
  136. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaEntity.h +53 -0
  137. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaItem.h +346 -0
  138. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaItemCollection.h +42 -0
  139. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaLibrary.h +76 -0
  140. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaPickerController.h +64 -0
  141. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaPlayback.h +47 -0
  142. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaPlaylist.h +82 -0
  143. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaQuery.h +120 -0
  144. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaQuerySection.h +26 -0
  145. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMoviePlayerController.h +444 -0
  146. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMoviePlayerViewController.h +43 -0
  147. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMusicPlayerApplicationController.h +47 -0
  148. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMusicPlayerController.h +147 -0
  149. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMusicPlayerQueueDescriptor.h +75 -0
  150. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPNowPlayingInfoCenter.h +197 -0
  151. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPNowPlayingInfoLanguageOption.h +107 -0
  152. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPNowPlayingSession.h +89 -0
  153. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPPlayableContentDataSource.h +59 -0
  154. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPPlayableContentDelegate.h +64 -0
  155. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPPlayableContentManager.h +46 -0
  156. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPPlayableContentManagerContext.h +32 -0
  157. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPRemoteCommand.h +143 -0
  158. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPRemoteCommandCenter.h +66 -0
  159. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPRemoteCommandEvent.h +128 -0
  160. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPRemoteControlTypes.h +27 -0
  161. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPVolumeSettings.h +20 -0
  162. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MPVolumeView.h +82 -0
  163. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MediaPlayer.apinotes +74 -0
  164. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MediaPlayer.h +40 -0
  165. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/MediaPlayerDefines.h +84 -0
  166. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Headers/NSUserActivity+MediaPlayerAdditions.h +20 -0
  167. package/sdk/ios/System/Library/Frameworks/MediaPlayer.framework/Modules/module.modulemap +5 -0
  168. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIAccessibilityCustomRotor.h +2 -2
  169. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIAction.h +1 -1
  170. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIBackgroundConfiguration.h +1 -1
  171. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIButtonConfiguration.h +1 -1
  172. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIContextMenuConfiguration.h +1 -1
  173. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIContextMenuInteraction.h +1 -1
  174. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIDeferredMenuElement.h +1 -1
  175. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIMenu.h +1 -1
  176. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIPointerStyle.h +5 -5
  177. package/sdk/ios/usr/include/dispatch.modulemap +22 -0
  178. package/sdk/ios/usr/include/net/if.h +24 -0
  179. package/sdk/ios/usr/include/sys/time.h +1 -1
  180. package/sdk/ios/usr/lib/swift/Foundation.swiftmodule/arm64-apple-ios-simulator.swiftinterface +265 -0
  181. package/sdk/ios/usr/lib/swift/ObjectiveC.swiftmodule/arm64-apple-ios-simulator.swiftinterface +2 -0
  182. package/sdk/ios/wasm/include/fcntl.h +2 -0
  183. package/sdk/ios/wasm/include/pthread.h +3 -0
  184. package/sdk/ios/wasm/include/stdlib.h +2 -0
  185. package/sdk/ios/wasm/include/unistd.h +2 -2
  186. package/skills/contrast/SKILL.md +2 -2
  187. package/src/bundle-channel.mjs +9 -72
  188. package/src/capture-contract.ts +12 -9
  189. package/src/desktop-host-delivery.ts +16 -2
  190. package/src/dev-bundle-resolution.ts +12 -3
  191. package/src/expo-native-workspace.ts +57 -19
  192. package/src/expo-swift-host.ts +17 -12
  193. package/src/expo-swift-ready.ts +4 -1
  194. package/src/expoSwiftContract.ts +1 -0
  195. package/src/home-paths.ts +4 -48
  196. package/src/host/bridge-host.ts +1 -0
  197. package/src/installed-native-libraries.ts +2 -8
  198. package/src/metro-project-root.ts +2 -1
  199. package/src/native-bundles.ts +122 -0
  200. package/src/native-static-libraries.ts +65 -8
  201. package/src/nitro-adapter.lock.json +278 -278
  202. package/src/nitro-bundle.ts +2 -2
  203. package/src/nitro-compile.ts +68 -28
  204. package/src/nitro-source.ts +24 -6
  205. package/src/nitro-superset.lock.json +94 -34
  206. package/src/nitroContract.ts +2 -0
  207. package/src/podspec-sources.ts +1966 -0
  208. package/src/storageSnapshotContract.ts +40 -0
  209. package/src/swift-compile.ts +57 -20
  210. package/src/swift-design-time.ts +18 -1
  211. package/src/swift-distribution.lock.json +11 -11
  212. package/src/swift-distribution.ts +9 -6
  213. package/src/swift-host.ts +1 -2
  214. package/src/swift-objc-standin.ts +316 -112
  215. package/src/swift-package-manifest.ts +4 -3
  216. package/src/swift-package.ts +10 -3
  217. package/src/swift-root-lock.ts +11 -0
  218. package/src/swift-shared-sdk.ts +10 -9
  219. package/src/swift-source-pods.ts +2 -2
  220. package/src/swift-standins.ts +40 -143
  221. package/src/swift-toolchain.ts +42 -0
  222. package/src/swift-wasm-prune.ts +53 -21
  223. package/src/turbo-bundle.ts +2 -2
  224. package/src/turbo-codegen-intake.ts +111 -108
  225. package/src/turbo-compile.ts +63 -33
  226. package/src/turbo-runtime.lock.json +21 -21
  227. package/src/turbo-source.ts +171 -76
  228. package/src/wasm-optimize.ts +31 -2
  229. package/src/xcode-project.ts +36 -3
@@ -0,0 +1,1966 @@
1
+ // the source membership react-native's own podspecs declare, read without
2
+ // CocoaPods or Ruby. the React Native, Folly, DoubleConversion and fmt
3
+ // podspecs use a small slice of Ruby: local variables, string and array
4
+ // literals, `if` on use_hermes() and ENV, `podspec_sources`, and subspec blocks.
5
+ // this evaluates exactly that slice and throws on anything else that could
6
+ // change which files a pod compiles, so a podspec it cannot establish is
7
+ // reported instead of guessed. ENV holds what use_react_native! sets (new
8
+ // architecture on) and use_hermes() is true, the
9
+ // static Hermes configuration `pod install` evaluates without overrides.
10
+ import fs from 'node:fs'
11
+ import path from 'node:path'
12
+
13
+ export class UnsupportedPodspec extends Error {}
14
+
15
+ // a podspec helper raised: CocoaPods aborts the install, so it is never recovered into an opaque value
16
+ class PodspecRaised extends UnsupportedPodspec {}
17
+
18
+ // a Ruby exception inside an evaluated helper, rescued by a begin or def rescue clause
19
+ class RubyError extends Error {}
20
+
21
+ class ReturnSignal {
22
+ constructor(readonly value: Value) {}
23
+ }
24
+
25
+ class BreakSignal {}
26
+
27
+ const recoverable = (error: unknown): error is UnsupportedPodspec =>
28
+ error instanceof UnsupportedPodspec && !(error instanceof PodspecRaised)
29
+
30
+ interface Tok {
31
+ t: 'str' | 'tpl' | 'id' | 'sym' | 'num' | 'op' | 'nl' | 'exec' | 're'
32
+ v: string
33
+ line: number
34
+ // an interpolated string: its literal pieces and the tokens of each #{...}
35
+ parts?: (string | Tok[])[]
36
+ }
37
+
38
+ const OPS = [
39
+ '<<=',
40
+ '||=',
41
+ '&&=',
42
+ '**',
43
+ '==',
44
+ '!=',
45
+ '>=',
46
+ '<=',
47
+ '&&',
48
+ '||',
49
+ '=>',
50
+ '+=',
51
+ '-=',
52
+ '=~',
53
+ '::',
54
+ '&.',
55
+ '<<',
56
+ '..',
57
+ ]
58
+
59
+ function tokenize(src: string, file: string): Tok[] {
60
+ const toks: Tok[] = []
61
+ const heredocs: string[] = []
62
+ let i = 0
63
+ let line = 1
64
+ const fail = (message: string): never => {
65
+ throw new UnsupportedPodspec(`${file}:${line}: ${message}`)
66
+ }
67
+ const push = (t: Tok['t'], v: string) => toks.push({ t, v, line })
68
+ while (i < src.length) {
69
+ const c = src[i]!
70
+ if (c === '\n') {
71
+ push('nl', '\n')
72
+ i++
73
+ line++
74
+ for (const id of heredocs.splice(0)) {
75
+ for (;;) {
76
+ const end = src.indexOf('\n', i)
77
+ const text = src.slice(i, end === -1 ? src.length : end)
78
+ i = end === -1 ? src.length : end + 1
79
+ line++
80
+ if (text.trim() === id || end === -1) break
81
+ }
82
+ }
83
+ continue
84
+ }
85
+ if (c === ' ' || c === '\t' || c === '\r') {
86
+ i++
87
+ continue
88
+ }
89
+ if (c === '\\' && src[i + 1] === '\n') {
90
+ i += 2
91
+ line++
92
+ continue
93
+ }
94
+ if (c === '#') {
95
+ while (i < src.length && src[i] !== '\n') i++
96
+ continue
97
+ }
98
+ if (c === "'" || c === '"') {
99
+ let j = i + 1
100
+ let value = ''
101
+ const parts: (string | Tok[])[] = []
102
+ for (; j < src.length && src[j] !== c; j++) {
103
+ if (src[j] === '\\') {
104
+ j++
105
+ const escaped = src[j]!
106
+ value +=
107
+ c === '"' && escaped === 'n'
108
+ ? '\n'
109
+ : c === '"' && escaped === 't'
110
+ ? '\t'
111
+ : escaped === c || escaped === '\\'
112
+ ? escaped
113
+ : c === '"'
114
+ ? escaped
115
+ : `\\${escaped}`
116
+ } else if (c === '"' && src[j] === '#' && src[j + 1] === '{') {
117
+ parts.push(value)
118
+ value = ''
119
+ const start = j + 2
120
+ let depth = 0
121
+ for (; j < src.length; j++) {
122
+ if (src[j] === '{') depth++
123
+ else if (src[j] === '}' && --depth === 0) break
124
+ }
125
+ parts.push(tokenize(src.slice(start, j), file))
126
+ } else value += src[j]
127
+ if (src[j] === '\n') line++
128
+ }
129
+ if (j >= src.length) fail('unterminated string')
130
+ if (parts.length > 0) {
131
+ parts.push(value)
132
+ toks.push({ t: 'tpl', v: '', line, parts })
133
+ } else push('str', value)
134
+ i = j + 1
135
+ continue
136
+ }
137
+ const heredoc = /^<<[-~]?(["']?)([A-Z_][A-Z0-9_]*)\1/.exec(src.slice(i, i + 64))
138
+ if (heredoc) {
139
+ heredocs.push(heredoc[2]!)
140
+ push('tpl', 'heredoc')
141
+ i += heredoc[0].length
142
+ continue
143
+ }
144
+ if (c === '`') {
145
+ const end = src.indexOf('`', i + 1)
146
+ if (end === -1) fail('unterminated command')
147
+ push('exec', src.slice(i + 1, end))
148
+ i = end + 1
149
+ continue
150
+ }
151
+ if (c === '%' && src[i + 1] === 'r' && src[i + 2] === '{') {
152
+ const end = src.indexOf('}', i + 3)
153
+ if (end === -1) fail('unterminated regular expression')
154
+ push('re', src.slice(i + 3, end))
155
+ i = end + 1
156
+ continue
157
+ }
158
+ if (/^%[wWiIqQr]/.test(src.slice(i, i + 2))) fail('percent literal')
159
+ // a slash opens a regular expression where a value cannot end, else it divides
160
+ if (c === '/') {
161
+ const prev = toks[toks.length - 1]
162
+ const afterValue =
163
+ prev !== undefined &&
164
+ (prev.t === 'str' ||
165
+ prev.t === 'tpl' ||
166
+ prev.t === 'num' ||
167
+ prev.t === 'id' ||
168
+ (prev.t === 'op' && (prev.v === ')' || prev.v === ']')))
169
+ if (afterValue) fail('division')
170
+ let j = i + 1
171
+ while (j < src.length && src[j] !== '/') j += src[j] === '\\' ? 2 : 1
172
+ if (j >= src.length) fail('unterminated regular expression')
173
+ push('re', src.slice(i + 1, j))
174
+ i = j + 1
175
+ continue
176
+ }
177
+ const word = /^@?[A-Za-z_][A-Za-z0-9_]*/.exec(src.slice(i, i + 128))
178
+ if (word) {
179
+ let text = word[0]
180
+ const next = src[i + text.length]
181
+ if ((next === '?' || next === '!') && src[i + text.length + 1] !== '=') text += next
182
+ push('id', text)
183
+ i += text.length
184
+ continue
185
+ }
186
+ const symbol = /^:([A-Za-z_][A-Za-z0-9_]*[?!]?)(?!=)/.exec(src.slice(i, i + 128))
187
+ if (symbol && !/[A-Za-z0-9_:]/.test(src[i - 1] ?? ' ')) {
188
+ push('sym', symbol[1]!)
189
+ i += symbol[0].length
190
+ continue
191
+ }
192
+ const num = /^[0-9][0-9_.]*/.exec(src.slice(i, i + 32))
193
+ if (num) {
194
+ push('num', num[0])
195
+ i += num[0].length
196
+ continue
197
+ }
198
+ const op = OPS.find((candidate) => src.startsWith(candidate, i))
199
+ if (op) {
200
+ push('op', op)
201
+ i += op.length
202
+ continue
203
+ }
204
+ push('op', c)
205
+ i++
206
+ }
207
+ return toks
208
+ }
209
+
210
+ type Stmt = { line: number } & (
211
+ | {
212
+ k: 'if'
213
+ unless: boolean
214
+ branches: { cond: Tok[]; body: Stmt[] }[]
215
+ other: Stmt[] | null
216
+ }
217
+ | { k: 'do'; head: Tok[]; params: string[]; body: Stmt[] }
218
+ | { k: 'begin'; body: Stmt[]; rescue: Stmt[][]; rest: Stmt[][] }
219
+ | { k: 'module'; name: string; body: Stmt[] }
220
+ | { k: 'def'; name: string; params: string[]; body: Stmt[] }
221
+ | { k: 'expr'; toks: Tok[]; modifier: { unless: boolean; toks: Tok[] } | null }
222
+ )
223
+
224
+ const BLOCK_KEYWORDS = new Set(['case', 'while', 'until', 'class', 'for'])
225
+ const CONTINUES = new Set([
226
+ ',',
227
+ '+',
228
+ '-',
229
+ '=',
230
+ '||',
231
+ '&&',
232
+ '(',
233
+ '[',
234
+ '{',
235
+ '.',
236
+ '=>',
237
+ '<<',
238
+ '?',
239
+ ':',
240
+ '+=',
241
+ '-=',
242
+ '||=',
243
+ '==',
244
+ '!=',
245
+ '&.',
246
+ '*',
247
+ '|',
248
+ ])
249
+
250
+ class Parser {
251
+ i = 0
252
+ constructor(
253
+ readonly toks: Tok[],
254
+ readonly file: string,
255
+ ) {}
256
+
257
+ fail(message: string): never {
258
+ throw new UnsupportedPodspec(
259
+ `${this.file}:${this.toks[this.i]?.line ?? 'end'}: ${message}`,
260
+ )
261
+ }
262
+
263
+ at(v: string) {
264
+ const tok = this.toks[this.i]
265
+ return tok?.t === 'id' && tok.v === v
266
+ }
267
+
268
+ body(): Stmt[] {
269
+ const out: Stmt[] = []
270
+ for (;;) {
271
+ while (
272
+ this.toks[this.i]?.t === 'nl' ||
273
+ (this.toks[this.i]?.t === 'op' && this.toks[this.i]!.v === ';')
274
+ )
275
+ this.i++
276
+ if (
277
+ this.i >= this.toks.length ||
278
+ this.at('end') ||
279
+ this.at('else') ||
280
+ this.at('elsif') ||
281
+ this.at('rescue') ||
282
+ this.at('ensure')
283
+ )
284
+ return out
285
+ out.push(this.statement())
286
+ }
287
+ }
288
+
289
+ expectEnd() {
290
+ if (!this.at('end')) this.fail('expected end')
291
+ this.i++
292
+ }
293
+
294
+ statement(): Stmt {
295
+ const tok = this.toks[this.i]!
296
+ if (tok.t === 'id' && (tok.v === 'if' || tok.v === 'unless')) {
297
+ this.i++
298
+ const branches: { cond: Tok[]; body: Stmt[] }[] = []
299
+ let other: Stmt[] | null = null
300
+ branches.push({ cond: this.condition(), body: this.thenBody() })
301
+ for (;;) {
302
+ if (this.at('elsif')) {
303
+ this.i++
304
+ branches.push({ cond: this.condition(), body: this.thenBody() })
305
+ } else if (this.at('else')) {
306
+ this.i++
307
+ other = this.body()
308
+ } else break
309
+ }
310
+ this.expectEnd()
311
+ return { k: 'if', unless: tok.v === 'unless', branches, other, line: tok.line }
312
+ }
313
+ if (tok.t === 'id' && tok.v === 'begin') {
314
+ // every clause of a begin block is kept: which one runs depends on a raised error
315
+ this.i++
316
+ const stmt = this.protectedBody(tok.line)
317
+ this.expectEnd()
318
+ return stmt
319
+ }
320
+ if (tok.t === 'id' && tok.v === 'module') {
321
+ const name = this.toks[this.i + 1]
322
+ if (name?.t !== 'id' || !/^[A-Z]/.test(name.v)) this.fail('unsupported module name')
323
+ this.i += 2
324
+ const body = this.body()
325
+ this.expectEnd()
326
+ return { k: 'module', name: name!.v, body, line: tok.line }
327
+ }
328
+ if (tok.t === 'id' && tok.v === 'def') {
329
+ this.i++
330
+ if (this.at('self') && this.toks[this.i + 1]?.v === '.') this.i += 2
331
+ const name = this.toks[this.i]
332
+ if (name?.t !== 'id') this.fail('unsupported method name')
333
+ this.i++
334
+ const params: string[] = []
335
+ if (this.toks[this.i]?.v === '(') {
336
+ this.i++
337
+ while (this.toks[this.i]?.v !== ')') {
338
+ const param = this.toks[this.i]
339
+ if (param?.t !== 'id') this.fail('unsupported method parameter')
340
+ params.push(param!.v)
341
+ this.i++
342
+ if (this.toks[this.i]?.v === ',') this.i++
343
+ }
344
+ this.i++
345
+ }
346
+ const stmt = this.protectedBody(tok.line)
347
+ this.expectEnd()
348
+ return { k: 'def', name: name!.v, params, body: [stmt], line: tok.line }
349
+ }
350
+ if (tok.t === 'id' && BLOCK_KEYWORDS.has(tok.v)) this.fail(`unsupported ${tok.v}`)
351
+ return this.simple()
352
+ }
353
+
354
+ // a body and the rescue, else and ensure clauses that follow it
355
+ protectedBody(line: number): Extract<Stmt, { k: 'begin' }> {
356
+ const body = this.body()
357
+ const rescue: Stmt[][] = []
358
+ const rest: Stmt[][] = []
359
+ while (this.at('rescue') || this.at('else') || this.at('ensure')) {
360
+ const clause = this.toks[this.i]!
361
+ this.i++
362
+ if (clause.v === 'rescue')
363
+ while (this.toks[this.i] && this.toks[this.i]!.t !== 'nl') this.i++
364
+ ;(clause.v === 'rescue' ? rescue : rest).push(this.body())
365
+ }
366
+ return { k: 'begin', body, rescue, rest, line }
367
+ }
368
+
369
+ thenBody() {
370
+ if (this.at('then')) this.i++
371
+ return this.body()
372
+ }
373
+
374
+ condition(): Tok[] {
375
+ const cond = this.simple(true)
376
+ if (cond.k !== 'expr') this.fail('unsupported condition')
377
+ return cond.toks
378
+ }
379
+
380
+ // one statement's tokens, up to its newline; a trailing do-block is parsed
381
+ simple(untilThen = false): Stmt {
382
+ const line = this.toks[this.i]?.line ?? 0
383
+ const toks: Tok[] = []
384
+ let depth = 0
385
+ for (;;) {
386
+ const tok = this.toks[this.i]
387
+ if (!tok) break
388
+ if (tok.t === 'op' && '([{'.includes(tok.v) && tok.v.length === 1) depth++
389
+ if (tok.t === 'op' && ')]}'.includes(tok.v) && tok.v.length === 1) depth--
390
+ if (untilThen && depth === 0 && tok.t === 'id' && tok.v === 'then') break
391
+ if (tok.t === 'nl' || (tok.t === 'op' && tok.v === ';')) {
392
+ if (depth > 0) {
393
+ this.i++
394
+ continue
395
+ }
396
+ let ahead = this.i
397
+ while (this.toks[ahead]?.t === 'nl') ahead++
398
+ const nextTok = this.toks[ahead]
399
+ const last = toks[toks.length - 1]
400
+ const lastOp = last?.t === 'op' && CONTINUES.has(last.v)
401
+ if (
402
+ tok.t === 'nl' &&
403
+ (lastOp || (nextTok?.t === 'op' && (nextTok.v === '.' || nextTok.v === '&.')))
404
+ ) {
405
+ this.i++
406
+ continue
407
+ }
408
+ break
409
+ }
410
+ if (tok.t === 'id' && tok.v === 'do' && depth === 0) {
411
+ this.i++
412
+ const params: string[] = []
413
+ if (this.toks[this.i]?.t === 'op' && this.toks[this.i]!.v === '|') {
414
+ this.i++
415
+ while (!(this.toks[this.i]?.t === 'op' && this.toks[this.i]!.v === '|')) {
416
+ const param = this.toks[this.i]
417
+ if (!param) this.fail('unterminated block parameters')
418
+ if (param!.t === 'id') params.push(param!.v)
419
+ this.i++
420
+ }
421
+ this.i++
422
+ }
423
+ const body = this.body()
424
+ this.expectEnd()
425
+ return { k: 'do', head: toks, params, body, line }
426
+ }
427
+ if (
428
+ tok.t === 'id' &&
429
+ (tok.v === 'if' || tok.v === 'unless') &&
430
+ depth === 0 &&
431
+ toks.length > 0
432
+ ) {
433
+ const last = toks[toks.length - 1]!
434
+ if (last.t === 'op' && last.v === '=') {
435
+ // `local = if ... end`: parsed for its syntax, evaluated as opaque
436
+ this.statement()
437
+ toks.push({ t: 'exec', v: `${tok.v} expression`, line: tok.line })
438
+ continue
439
+ }
440
+ if (last.t === 'op' && CONTINUES.has(last.v))
441
+ this.fail(`unsupported ${tok.v} expression`)
442
+ this.i++
443
+ const cond = this.simple()
444
+ if (cond.k !== 'expr') this.fail('unsupported modifier')
445
+ return {
446
+ k: 'expr',
447
+ toks,
448
+ modifier: { unless: tok.v === 'unless', toks: cond.toks },
449
+ line,
450
+ }
451
+ }
452
+ if (tok.t === 'id' && BLOCK_KEYWORDS.has(tok.v) && toks.length === 0)
453
+ this.fail(`unsupported ${tok.v}`)
454
+ toks.push(tok)
455
+ this.i++
456
+ }
457
+ return { k: 'expr', toks, modifier: null, line }
458
+ }
459
+ }
460
+
461
+ function parse(src: string, file: string): Stmt[] {
462
+ const parser = new Parser(tokenize(src, file), file)
463
+ const body = parser.body()
464
+ if (parser.i < parser.toks.length) parser.fail(`unexpected ${parser.toks[parser.i]!.v}`)
465
+ return body
466
+ }
467
+
468
+ // expressions
469
+
470
+ type Node =
471
+ | { k: 'lit'; v: Value }
472
+ | { k: 'var'; name: string }
473
+ | { k: 'call'; name: string; args: Node[] }
474
+ | { k: 'method'; recv: Node; name: string; args: Node[]; block?: Block }
475
+ | { k: 'assign'; target: Node; value: Node }
476
+ | { k: 'blockpass'; name: string }
477
+ | { k: 'index'; recv: Node; index: Node }
478
+ | { k: 'bin'; op: string; l: Node; r: Node }
479
+ | { k: 'not'; e: Node }
480
+ | { k: 'tern'; c: Node; a: Node; b: Node }
481
+ | { k: 'arr'; items: Node[] }
482
+ | { k: 'hash'; pairs: [Node, Node][] }
483
+ | { k: 'interp'; parts: (string | Node)[] }
484
+ | { k: 'fail'; why: string }
485
+
486
+ interface Block {
487
+ params: string[]
488
+ body: Node
489
+ }
490
+
491
+ type Value =
492
+ | string
493
+ | number
494
+ | boolean
495
+ | null
496
+ | Value[]
497
+ | Map<string, Value>
498
+ | Spec
499
+ | Opaque
500
+ | Lambda
501
+ | RegExp
502
+
503
+ // a local helper defined with `name = lambda do |args| ... end`. its body is never
504
+ // run: it is accepted only when it cannot reach spec membership, and its calls
505
+ // return values that are not established.
506
+ class Lambda {}
507
+
508
+ class Opaque {
509
+ constructor(readonly why: string) {}
510
+ }
511
+
512
+ class Spec {
513
+ attrs = new Map<string, Value>()
514
+ subspecs: Spec[] = []
515
+ constructor(
516
+ readonly kind: 'spec' | 'test' | 'app',
517
+ readonly fullName: string,
518
+ ) {}
519
+ }
520
+
521
+ const FUNCTIONS = new Set(['use_hermes', 'use_third_party_jsc', 'podspec_sources'])
522
+
523
+ class ExprParser {
524
+ i = 0
525
+ depth = 0
526
+ constructor(
527
+ readonly toks: Tok[],
528
+ readonly file: string,
529
+ ) {}
530
+
531
+ peek(): Tok | undefined {
532
+ while (this.depth > 0 && this.toks[this.i]?.t === 'nl') this.i++
533
+ return this.toks[this.i]
534
+ }
535
+
536
+ isOp(v: string) {
537
+ const tok = this.peek()
538
+ return tok?.t === 'op' && tok.v === v
539
+ }
540
+
541
+ eatOp(v: string) {
542
+ if (!this.isOp(v)) return false
543
+ this.i++
544
+ return true
545
+ }
546
+
547
+ skipNl() {
548
+ while (this.toks[this.i]?.t === 'nl') this.i++
549
+ }
550
+
551
+ fail(why: string): never {
552
+ throw new UnsupportedPodspec(
553
+ `${this.file}:${this.toks[this.i]?.line ?? 'end'}: ${why}`,
554
+ )
555
+ }
556
+
557
+ expect(v: string) {
558
+ if (!this.eatOp(v)) this.fail(`expected ${v}`)
559
+ }
560
+
561
+ done() {
562
+ this.skipNl()
563
+ if (this.i < this.toks.length) this.fail(`unexpected ${this.toks[this.i]!.v}`)
564
+ }
565
+
566
+ expr(): Node {
567
+ const c = this.or()
568
+ if (this.isOp('=') && (c.k === 'var' || c.k === 'index')) {
569
+ this.i++
570
+ this.skipNl()
571
+ return { k: 'assign', target: c, value: this.expr() }
572
+ }
573
+ if (this.isOp('?')) {
574
+ this.i++
575
+ this.skipNl()
576
+ const a = this.expr()
577
+ this.skipNl()
578
+ this.expect(':')
579
+ this.skipNl()
580
+ return { k: 'tern', c, a, b: this.expr() }
581
+ }
582
+ return c
583
+ }
584
+
585
+ binary(ops: string[], next: () => Node): Node {
586
+ let l = next()
587
+ for (;;) {
588
+ const tok = this.peek()
589
+ if (tok?.t !== 'op' || !ops.includes(tok.v)) return l
590
+ this.i++
591
+ this.skipNl()
592
+ l = { k: 'bin', op: tok.v, l, r: next() }
593
+ }
594
+ }
595
+
596
+ or = (): Node => this.binary(['||'], this.and)
597
+ and = (): Node => this.binary(['&&'], this.eq)
598
+ eq = (): Node => this.binary(['==', '!='], this.shift)
599
+ shift = (): Node => this.binary(['<<'], this.add)
600
+ add = (): Node => this.binary(['+', '-'], this.unary)
601
+
602
+ unary = (): Node => {
603
+ if (this.eatOp('!')) return { k: 'not', e: this.unary() }
604
+ const tok = this.peek()
605
+ if (tok?.t === 'id' && tok.v === 'not') {
606
+ this.i++
607
+ return { k: 'not', e: this.unary() }
608
+ }
609
+ return this.postfix()
610
+ }
611
+
612
+ args(close: string): Node[] {
613
+ const args: Node[] = []
614
+ this.depth++
615
+ while (!this.isOp(close)) {
616
+ const tok = this.peek()
617
+ const after = this.toks[this.i + 1]
618
+ if (
619
+ tok &&
620
+ (tok.t === 'id' || tok.t === 'str') &&
621
+ after?.t === 'op' &&
622
+ after.v === ':'
623
+ ) {
624
+ this.fail('keyword arguments')
625
+ }
626
+ if (this.isOp('&') && this.toks[this.i + 1]?.t === 'sym') {
627
+ args.push({ k: 'blockpass', name: this.toks[this.i + 1]!.v })
628
+ this.i += 2
629
+ } else args.push(this.expr())
630
+ if (!this.eatOp(',')) break
631
+ }
632
+ this.expect(close)
633
+ this.depth--
634
+ return args
635
+ }
636
+
637
+ postfix(): Node {
638
+ let node = this.primary()
639
+ for (;;) {
640
+ const tok = this.peek()
641
+ if (tok?.t !== 'op') return node
642
+ if (tok.v === '.' || tok.v === '&.') {
643
+ this.i++
644
+ const name = this.toks[this.i]
645
+ if (name?.t !== 'id') this.fail('expected method name')
646
+ this.i++
647
+ let args: Node[] = []
648
+ const open = this.toks[this.i]
649
+ if (open?.t === 'op' && open.v === '(') {
650
+ this.i++
651
+ args = this.args(')')
652
+ }
653
+ node = { k: 'method', recv: node, name: name!.v, args }
654
+ const brace = this.toks[this.i]
655
+ if (brace?.t === 'op' && brace.v === '{') {
656
+ this.i++
657
+ this.depth++
658
+ const params: string[] = []
659
+ if (this.eatOp('|')) {
660
+ while (!this.isOp('|')) {
661
+ const param = this.toks[this.i]
662
+ if (param?.t !== 'id') this.fail('unsupported block parameter')
663
+ params.push(param!.v)
664
+ this.i++
665
+ this.eatOp(',')
666
+ }
667
+ this.i++
668
+ }
669
+ node.block = { params, body: this.expr() }
670
+ this.expect('}')
671
+ this.depth--
672
+ }
673
+ } else if (tok.v === '[') {
674
+ this.i++
675
+ this.depth++
676
+ const index = this.expr()
677
+ this.expect(']')
678
+ this.depth--
679
+ node = { k: 'index', recv: node, index }
680
+ } else return node
681
+ }
682
+ }
683
+
684
+ primary(): Node {
685
+ const tok = this.peek()
686
+ if (!tok) return this.fail('unexpected end')
687
+ this.i++
688
+ switch (tok.t) {
689
+ case 'sym':
690
+ return { k: 'lit', v: tok.v }
691
+ case 'str': {
692
+ // adjacent string literals are one string
693
+ let value = tok.v
694
+ while (this.toks[this.i]?.t === 'str') value += this.toks[this.i++]!.v
695
+ return { k: 'lit', v: value }
696
+ }
697
+ case 're':
698
+ return {
699
+ k: 'lit',
700
+ v: new RegExp(tok.v.replaceAll('\\A', '^').replaceAll('\\z', '$')),
701
+ }
702
+ case 'tpl':
703
+ return tok.parts
704
+ ? {
705
+ k: 'interp',
706
+ parts: tok.parts.map((part) =>
707
+ typeof part === 'string' ? part : parseExpression(part, this.file),
708
+ ),
709
+ }
710
+ : { k: 'fail', why: 'heredoc' }
711
+ case 'exec':
712
+ return { k: 'fail', why: 'shell command' }
713
+ case 'num':
714
+ return /^\d+$/.test(tok.v)
715
+ ? { k: 'lit', v: Number(tok.v) }
716
+ : { k: 'fail', why: 'number' }
717
+ case 'nl':
718
+ return this.fail('unexpected newline')
719
+ case 'id': {
720
+ if (tok.v === 'nil') return { k: 'lit', v: null }
721
+ if (tok.v === 'true') return { k: 'lit', v: true }
722
+ if (tok.v === 'false') return { k: 'lit', v: false }
723
+ const open = this.toks[this.i]
724
+ if (open?.t === 'op' && open.v === '(' && !/^[A-Z]/.test(tok.v)) {
725
+ this.i++
726
+ return { k: 'call', name: tok.v, args: this.args(')') }
727
+ }
728
+ if (FUNCTIONS.has(tok.v)) return { k: 'call', name: tok.v, args: [] }
729
+ let name = tok.v
730
+ while (
731
+ /^[A-Z]/.test(name) &&
732
+ this.toks[this.i]?.v === '::' &&
733
+ this.toks[this.i + 1]?.t === 'id'
734
+ ) {
735
+ name += `::${this.toks[this.i + 1]!.v}`
736
+ this.i += 2
737
+ }
738
+ return { k: 'var', name }
739
+ }
740
+ case 'op':
741
+ if (tok.v === '(') {
742
+ this.depth++
743
+ const inner = this.expr()
744
+ this.expect(')')
745
+ this.depth--
746
+ return inner
747
+ }
748
+ if (tok.v === '[') return { k: 'arr', items: this.args(']') }
749
+ if (tok.v === '{') {
750
+ const pairs: [Node, Node][] = []
751
+ this.depth++
752
+ while (!this.isOp('}')) {
753
+ const label = this.peek()
754
+ const colon = this.toks[this.i + 1]
755
+ let key: Node
756
+ if (label?.t === 'id' && colon?.t === 'op' && colon.v === ':') {
757
+ key = { k: 'lit', v: label.v }
758
+ this.i += 2
759
+ } else {
760
+ key = this.expr()
761
+ this.expect('=>')
762
+ }
763
+ pairs.push([key, this.expr()])
764
+ if (!this.eatOp(',')) break
765
+ }
766
+ this.expect('}')
767
+ this.depth--
768
+ return { k: 'hash', pairs }
769
+ }
770
+ if (tok.v === '::') return this.fail('top-level constant')
771
+ return this.fail(`unexpected ${tok.v}`)
772
+ }
773
+ }
774
+ }
775
+
776
+ function parseExpression(toks: Tok[], file: string): Node {
777
+ const parser = new ExprParser(toks, file)
778
+ const node = parser.expr()
779
+ parser.done()
780
+ return node
781
+ }
782
+
783
+ // split a top-level comma list: `a = 'x', 'y'` assigns an array
784
+ function splitCommas(toks: Tok[]): Tok[][] {
785
+ const parts: Tok[][] = [[]]
786
+ let depth = 0
787
+ for (const tok of toks) {
788
+ if (tok.t === 'op' && tok.v.length === 1 && '([{'.includes(tok.v)) depth++
789
+ if (tok.t === 'op' && tok.v.length === 1 && ')]}'.includes(tok.v)) depth--
790
+ if (tok.t === 'op' && tok.v === ',' && depth === 0) parts.push([])
791
+ else parts[parts.length - 1]!.push(tok)
792
+ }
793
+ while (parts.length > 1 && parts[parts.length - 1]!.every((tok) => tok.t === 'nl'))
794
+ parts.pop()
795
+ return parts
796
+ }
797
+
798
+ class Scope {
799
+ vars = new Map<string, Value>()
800
+ constructor(readonly parent?: Scope) {}
801
+
802
+ find(name: string): Scope | undefined {
803
+ return this.vars.has(name) ? this : this.parent?.find(name)
804
+ }
805
+
806
+ get(name: string): Value | undefined {
807
+ return this.find(name)?.vars.get(name)
808
+ }
809
+
810
+ set(name: string, value: Value) {
811
+ ;(this.find(name) ?? this).vars.set(name, value)
812
+ }
813
+ }
814
+
815
+ const MEMBERSHIP_WORDS = new Set([
816
+ 'source_files',
817
+ 'exclude_files',
818
+ 'subspec',
819
+ 'test_spec',
820
+ 'app_spec',
821
+ 'module_name',
822
+ 'header_dir',
823
+ 'default_subspec',
824
+ 'default_subspecs',
825
+ 'pod_target_xcconfig',
826
+ 'name',
827
+ 'resolve_use_frameworks',
828
+ ])
829
+ const MUTATORS = new Set([
830
+ 'append',
831
+ 'push',
832
+ 'concat',
833
+ 'merge!',
834
+ 'delete',
835
+ 'unshift',
836
+ 'insert',
837
+ 'clear',
838
+ 'replace',
839
+ 'uniq!',
840
+ 'flatten!',
841
+ 'map!',
842
+ ])
843
+ const PLATFORMS = new Set(['ios', 'osx', 'macos', 'tvos', 'visionos', 'watchos'])
844
+ // add_nitrogen_files appends nitrogen's generated sources, which the Nitro compile
845
+ // collects itself, so it leaves the membership read here unchanged
846
+ const SPEC_HELPERS = new Set([
847
+ 'add_nitrogen_files',
848
+ 'install_modules_dependencies',
849
+ 'add_dependency',
850
+ 'add_rn_third_party_dependencies',
851
+ 'add_rncore_dependency',
852
+ 'depend_on_js_engine',
853
+ 'mark_as_react_native_build',
854
+ ])
855
+
856
+ const truthy = (value: Value) => value !== null && value !== false
857
+
858
+ function flatten(stmts: Stmt[]): Tok[] {
859
+ return stmts.flatMap((stmt) =>
860
+ stmt.k === 'expr'
861
+ ? [...stmt.toks, ...(stmt.modifier?.toks ?? [])]
862
+ : stmt.k === 'begin'
863
+ ? flatten([...stmt.body, ...stmt.rescue.flat(), ...stmt.rest.flat()])
864
+ : stmt.k === 'module' || stmt.k === 'def'
865
+ ? flatten(stmt.body)
866
+ : stmt.k === 'do'
867
+ ? [...stmt.head, ...flatten(stmt.body)]
868
+ : [
869
+ ...stmt.branches.flatMap((branch) => [
870
+ ...branch.cond,
871
+ ...flatten(branch.body),
872
+ ]),
873
+ ...flatten(stmt.other ?? []),
874
+ ],
875
+ )
876
+ }
877
+
878
+ interface RubyModule {
879
+ methods: Map<string, Extract<Stmt, { k: 'def' }>>
880
+ ivars: Map<string, Value>
881
+ }
882
+
883
+ const STDLIB = new Set(['json', 'fileutils', 'digest', 'open-uri', 'uri'])
884
+
885
+ class Evaluator {
886
+ // what every method body sees: ENV holds what use_react_native! sets
887
+ constants = new Scope()
888
+ modules = new Map<string, RubyModule>()
889
+ required = new Set<string>()
890
+ // the file being evaluated, which require_relative resolves against
891
+ current: string
892
+ self: RubyModule | null = null
893
+ calls = 0
894
+
895
+ constructor(
896
+ readonly file: string,
897
+ // the Podfile's directory: Pod::Config.instance.installation_root
898
+ readonly installationRoot: string | null,
899
+ ) {
900
+ this.current = file
901
+ }
902
+
903
+ fail(why: string, line?: number): never {
904
+ throw new UnsupportedPodspec(`${this.file}${line ? `:${line}` : ''}: ${why}`)
905
+ }
906
+
907
+ value(scope: Scope, toks: Tok[]): Value {
908
+ const parts = splitCommas(toks)
909
+ if (parts.length > 1) {
910
+ // a trailing comma continues onto the next line, so Ruby reads
911
+ // `a.x = 'v',\n a.y = z` as x = ['v', (a.y = z)]
912
+ return parts.map((part) => {
913
+ const receiver = part[0]?.t === 'id' ? scope.get(part[0].v) : undefined
914
+ if (receiver instanceof Spec && part[1]?.v === '.' && part[3]?.v === '=') {
915
+ this.runSpecStatement(scope, receiver, part, part[0]!.line)
916
+ return this.value(scope, part.slice(4))
917
+ }
918
+ return this.value(scope, part)
919
+ })
920
+ }
921
+ return this.ev(scope, parseExpression(toks, this.file))
922
+ }
923
+
924
+ tryValue(scope: Scope, toks: Tok[]): Value {
925
+ try {
926
+ return this.value(scope, toks)
927
+ } catch (error) {
928
+ if (recoverable(error)) return new Opaque(error.message)
929
+ throw error
930
+ }
931
+ }
932
+
933
+ ev(scope: Scope, node: Node): Value {
934
+ switch (node.k) {
935
+ case 'lit':
936
+ return node.v
937
+ case 'fail':
938
+ return this.fail(node.why)
939
+ case 'interp':
940
+ return node.parts
941
+ .map((part) => {
942
+ if (typeof part === 'string') return part
943
+ const value = this.ev(scope, part)
944
+ if (typeof value === 'string') return value
945
+ if (value === null) return ''
946
+ if (typeof value === 'boolean') return String(value)
947
+ return this.fail('interpolated value')
948
+ })
949
+ .join('')
950
+ case 'assign': {
951
+ const value = this.ev(scope, node.value)
952
+ const { target } = node
953
+ if (target.k === 'var' && target.name.startsWith('@'))
954
+ this.module().ivars.set(target.name, value)
955
+ else if (target.k === 'var') scope.set(target.name, value)
956
+ else if (target.k === 'index') {
957
+ const recv = this.ev(scope, target.recv)
958
+ const index = this.ev(scope, target.index)
959
+ if (!(recv instanceof Map) || typeof index !== 'string')
960
+ return this.fail('index assignment')
961
+ recv.set(index, value)
962
+ } else return this.fail('assignment target')
963
+ return value
964
+ }
965
+ case 'blockpass':
966
+ return this.fail('block argument')
967
+ case 'var': {
968
+ if (node.name.startsWith('@')) return this.module().ivars.get(node.name) ?? null
969
+ const value = scope.get(node.name)
970
+ const helper = value === undefined ? this.self?.methods.get(node.name) : undefined
971
+ if (helper) return this.callDef(this.self!, helper, [])
972
+ if (value === undefined) return this.fail(`unknown name ${node.name}`)
973
+ if (value instanceof Opaque)
974
+ return this.fail(`${node.name} is not established: ${value.why}`)
975
+ return value
976
+ }
977
+ case 'arr':
978
+ return node.items.map((item) => this.ev(scope, item))
979
+ case 'hash': {
980
+ const map = new Map<string, Value>()
981
+ for (const [key, value] of node.pairs) {
982
+ const k = this.ev(scope, key)
983
+ if (typeof k !== 'string') this.fail('hash key')
984
+ map.set(k, this.ev(scope, value))
985
+ }
986
+ return map
987
+ }
988
+ case 'not':
989
+ return !truthy(this.ev(scope, node.e))
990
+ case 'tern':
991
+ return truthy(this.ev(scope, node.c))
992
+ ? this.ev(scope, node.a)
993
+ : this.ev(scope, node.b)
994
+ case 'index': {
995
+ const recv = this.ev(scope, node.recv)
996
+ const index = this.ev(scope, node.index)
997
+ if (recv instanceof Map && typeof index === 'string')
998
+ return recv.get(index) ?? null
999
+ if (Array.isArray(recv) && typeof index === 'number') return recv[index] ?? null
1000
+ return this.fail('index')
1001
+ }
1002
+ case 'call': {
1003
+ if (node.name === 'use_hermes') return true
1004
+ if (node.name === 'use_third_party_jsc') return false
1005
+ // the React Native pod scripts that define these helpers are always loaded
1006
+ const probed = node.args[0]
1007
+ if (
1008
+ node.name === 'defined?' &&
1009
+ (probed?.k === 'var' || probed?.k === 'call') &&
1010
+ SPEC_HELPERS.has(probed.name)
1011
+ )
1012
+ return true
1013
+ if (
1014
+ node.name === 'defined?' &&
1015
+ node.args.length === 1 &&
1016
+ node.args[0]!.k === 'var' &&
1017
+ node.args[0]!.name.startsWith('@')
1018
+ )
1019
+ return this.module().ivars.has(node.args[0]!.name) ? true : null
1020
+ if (node.name === 'podspec_sources') {
1021
+ if (!node.args[0]) return this.fail('podspec_sources without sources')
1022
+ return this.ev(scope, node.args[0])
1023
+ }
1024
+ const helper = this.self?.methods.get(node.name)
1025
+ if (helper)
1026
+ return this.callDef(
1027
+ this.self!,
1028
+ helper,
1029
+ node.args.map((arg) => this.ev(scope, arg)),
1030
+ )
1031
+ return this.fail(`call to ${node.name}`)
1032
+ }
1033
+ case 'bin': {
1034
+ if (node.op === '||' || node.op === '&&') {
1035
+ const l = this.ev(scope, node.l)
1036
+ return truthy(l) === (node.op === '||') ? l : this.ev(scope, node.r)
1037
+ }
1038
+ const l = this.ev(scope, node.l)
1039
+ const r = this.ev(scope, node.r)
1040
+ if (node.op === '==' || node.op === '!=') {
1041
+ if (
1042
+ Array.isArray(l) &&
1043
+ Array.isArray(r) &&
1044
+ [...l, ...r].every((v) => typeof v === 'string')
1045
+ )
1046
+ return (
1047
+ (l.length === r.length && l.every((v, index) => v === r[index])) ===
1048
+ (node.op === '==')
1049
+ )
1050
+ if (typeof l === 'object' && l !== null) this.fail('object comparison')
1051
+ return (l === r) === (node.op === '==')
1052
+ }
1053
+ if (node.op === '+' && typeof l === 'string' && typeof r === 'string')
1054
+ return l + r
1055
+ if (Array.isArray(l) && Array.isArray(r)) {
1056
+ if (node.op === '+') return [...l, ...r]
1057
+ if (node.op === '-') return l.filter((item) => !r.includes(item))
1058
+ if (node.op === '<<') this.fail('array append of an array')
1059
+ }
1060
+ if (node.op === '<<' && Array.isArray(l)) {
1061
+ l.push(r)
1062
+ return l
1063
+ }
1064
+ return this.fail(`operator ${node.op}`)
1065
+ }
1066
+ case 'method': {
1067
+ if (
1068
+ node.recv.k === 'var' &&
1069
+ node.name === 'call' &&
1070
+ scope.get(node.recv.name) instanceof Lambda
1071
+ ) {
1072
+ for (const arg of node.args) {
1073
+ if (arg.k === 'var' && scope.get(arg.name) instanceof Spec)
1074
+ this.fail(`${node.recv.name} receives the spec`)
1075
+ }
1076
+ return new Opaque(`${node.recv.name} is a helper whose result is not evaluated`)
1077
+ }
1078
+ if (node.recv.k === 'var') {
1079
+ const helperModule = this.modules.get(node.recv.name)
1080
+ const helper = helperModule?.methods.get(node.name)
1081
+ if (helperModule && helper)
1082
+ return this.callDef(
1083
+ helperModule,
1084
+ helper,
1085
+ node.args.map((arg) => this.ev(scope, arg)),
1086
+ )
1087
+ if (
1088
+ node.recv.name === 'File' ||
1089
+ node.recv.name === 'Dir' ||
1090
+ node.recv.name === 'JSON'
1091
+ )
1092
+ return this.system(
1093
+ node.recv.name,
1094
+ node.name,
1095
+ node.args.map((arg) => this.ev(scope, arg)),
1096
+ )
1097
+ }
1098
+ // the Podfile's installation root, which CocoaPods installs into
1099
+ if (
1100
+ node.name === 'installation_root' &&
1101
+ node.recv.k === 'method' &&
1102
+ node.recv.name === 'instance' &&
1103
+ node.recv.recv.k === 'var' &&
1104
+ node.recv.recv.name === 'Pod::Config'
1105
+ ) {
1106
+ if (this.installationRoot === null)
1107
+ return this.fail('Pod::Config.installation_root needs the app root')
1108
+ return this.installationRoot
1109
+ }
1110
+ if (node.name === 'is_a?' && node.args[0]?.k === 'var') {
1111
+ const recv = this.ev(scope, node.recv)
1112
+ const kind = node.args[0].name
1113
+ if (kind === 'Hash') return recv instanceof Map
1114
+ if (kind === 'Array') return Array.isArray(recv)
1115
+ if (kind === 'String') return typeof recv === 'string'
1116
+ return this.fail(`is_a?(${kind})`)
1117
+ }
1118
+ const recv = this.ev(scope, node.recv)
1119
+ const last = node.args[node.args.length - 1]
1120
+ const block: Block | undefined =
1121
+ node.block ??
1122
+ (last?.k === 'blockpass'
1123
+ ? {
1124
+ params: ['item'],
1125
+ body: {
1126
+ k: 'method',
1127
+ recv: { k: 'var', name: 'item' },
1128
+ name: last.name,
1129
+ args: [],
1130
+ },
1131
+ }
1132
+ : undefined)
1133
+ const args = (last?.k === 'blockpass' ? node.args.slice(0, -1) : node.args).map(
1134
+ (arg) => this.ev(scope, arg),
1135
+ )
1136
+ if (node.name === 'nil?' && args.length === 0) return recv === null
1137
+ if (node.name === 'to_s' && args.length === 0 && recv === null) return ''
1138
+ if (typeof recv === 'string' || Array.isArray(recv) || recv instanceof Map) {
1139
+ const result = this.builtin(scope, recv, node.name, args, block)
1140
+ if (result !== undefined) return result
1141
+ }
1142
+ if (Array.isArray(recv)) {
1143
+ if (node.name === 'append' || node.name === 'push') {
1144
+ recv.push(...args)
1145
+ return recv
1146
+ }
1147
+ if (
1148
+ node.name === 'concat' &&
1149
+ args.every((arg): arg is Value[] => Array.isArray(arg))
1150
+ ) {
1151
+ recv.push(...args.flat())
1152
+ return recv
1153
+ }
1154
+ }
1155
+ return this.fail(`method ${node.name}`)
1156
+ }
1157
+ }
1158
+ }
1159
+
1160
+ module(): RubyModule {
1161
+ return this.self ?? this.fail('instance variable outside a module')
1162
+ }
1163
+
1164
+ // File, Dir and JSON class methods: the filesystem is read as CocoaPods would
1165
+ system(receiver: string, name: string, args: Value[]): Value {
1166
+ const strs = args.filter((arg): arg is string => typeof arg === 'string')
1167
+ if (strs.length !== args.length) this.fail(`${receiver}.${name} arguments`)
1168
+ const [first, second] = strs
1169
+ if (receiver === 'JSON' && name === 'parse' && first !== undefined && !second) {
1170
+ const json = (value: unknown): Value => {
1171
+ if (typeof value === 'string' || typeof value === 'boolean' || value === null)
1172
+ return value
1173
+ if (Array.isArray(value)) return value.map(json)
1174
+ if (typeof value !== 'object') return new Opaque('a JSON number')
1175
+ return new Map(Object.entries(value).map(([k, v]) => [k, json(v)]))
1176
+ }
1177
+ let parsed: unknown
1178
+ try {
1179
+ parsed = JSON.parse(first)
1180
+ } catch (error) {
1181
+ throw new RubyError(String(error))
1182
+ }
1183
+ return json(parsed)
1184
+ }
1185
+ if (receiver === 'File' && name === 'join') return strs.join('/').replace(/\/+/g, '/')
1186
+ if (first === undefined) return this.fail(`${receiver}.${name}`)
1187
+ if (receiver === 'File' && name === 'expand_path')
1188
+ return path.resolve(second ?? process.cwd(), first)
1189
+ if (receiver === 'File' && name === 'dirname') return path.dirname(first)
1190
+ if (receiver === 'File' && name === 'basename') return path.basename(first)
1191
+ if (receiver === 'File' && name === 'read') {
1192
+ try {
1193
+ return fs.readFileSync(first, 'utf8')
1194
+ } catch (error) {
1195
+ throw new RubyError(String(error))
1196
+ }
1197
+ }
1198
+ if (receiver === 'File' && name === 'realpath') {
1199
+ try {
1200
+ return fs.realpathSync(first)
1201
+ } catch (error) {
1202
+ throw new RubyError(String(error))
1203
+ }
1204
+ }
1205
+ const stat = fs.statSync(first, { throwIfNoEntry: false })
1206
+ if (name === 'exist?') return stat !== undefined
1207
+ if (name === 'file?') return stat?.isFile() ?? false
1208
+ if (name === 'directory?') return stat?.isDirectory() ?? false
1209
+ return this.fail(`${receiver}.${name}`)
1210
+ }
1211
+
1212
+ yieldBlock(scope: Scope, block: Block, values: Value[]): Value {
1213
+ const inner = new Scope(scope)
1214
+ block.params.forEach((param, index) => inner.vars.set(param, values[index] ?? null))
1215
+ return this.ev(inner, block.body)
1216
+ }
1217
+
1218
+ // String, Array and Hash methods; undefined when the method is not one this evaluates
1219
+ builtin(
1220
+ scope: Scope,
1221
+ recv: string | Value[] | Map<string, Value>,
1222
+ name: string,
1223
+ args: Value[],
1224
+ block: Block | undefined,
1225
+ ): Value | undefined {
1226
+ if (name === 'empty?')
1227
+ return typeof recv === 'string'
1228
+ ? recv === ''
1229
+ : Array.isArray(recv)
1230
+ ? recv.length === 0
1231
+ : recv.size === 0
1232
+ if (name === 'dup')
1233
+ return typeof recv === 'string'
1234
+ ? recv
1235
+ : Array.isArray(recv)
1236
+ ? [...recv]
1237
+ : new Map(recv)
1238
+ if (typeof recv === 'string') {
1239
+ if (name === 'to_s') return recv
1240
+ if (name === 'strip') return recv.trim()
1241
+ if (name === 'split' && typeof args[0] === 'string') return recv.split(args[0])
1242
+ const [pattern, replacement] = args
1243
+ if (name === 'gsub' && pattern instanceof RegExp && typeof replacement === 'string')
1244
+ return recv.replace(new RegExp(pattern.source, 'g'), (...found) =>
1245
+ replacement.replace(/\\(\d)/g, (_, group) => found[Number(group)] ?? ''),
1246
+ )
1247
+ if (name === 'upcase') return recv.toUpperCase()
1248
+ if (name === 'downcase') return recv.toLowerCase()
1249
+ if (name === 'match' && pattern instanceof RegExp) {
1250
+ const found = recv.match(pattern)
1251
+ return found ? [...found].map((group) => group ?? null) : null
1252
+ }
1253
+ if (name === 'match?' && pattern instanceof RegExp) return pattern.test(recv)
1254
+ return undefined
1255
+ }
1256
+ if (recv instanceof Map) {
1257
+ if (name === 'key?' && typeof args[0] === 'string') return recv.has(args[0])
1258
+ if (name === 'keys') return [...recv.keys()]
1259
+ if (name === 'dig' && args.every((arg): arg is string => typeof arg === 'string')) {
1260
+ let found: Value = recv
1261
+ for (const key of args) {
1262
+ if (!(found instanceof Map)) return null
1263
+ found = found.get(key) ?? null
1264
+ }
1265
+ return found
1266
+ }
1267
+ if (name === 'select' && block)
1268
+ return new Map(
1269
+ [...recv.entries()].filter(([k, v]) =>
1270
+ truthy(this.yieldBlock(scope, block, [k, v])),
1271
+ ),
1272
+ )
1273
+ return undefined
1274
+ }
1275
+ if (name === 'include?' && args.length === 1) return recv.includes(args[0]!)
1276
+ if (name === 'sort' && recv.every((item) => typeof item === 'string'))
1277
+ return [...recv].sort()
1278
+ if (
1279
+ name === 'join' &&
1280
+ typeof args[0] === 'string' &&
1281
+ recv.every((item) => typeof item === 'string')
1282
+ )
1283
+ return recv.join(args[0])
1284
+ if (!block) return undefined
1285
+ const run = (item: Value[]) => this.yieldBlock(scope, block, item)
1286
+ if (name === 'map') return recv.map((item) => run([item]))
1287
+ if (name === 'select') return recv.filter((item) => truthy(run([item])))
1288
+ if (name === 'reject') return recv.filter((item) => !truthy(run([item])))
1289
+ if (name === 'find') return recv.find((item) => truthy(run([item]))) ?? null
1290
+ return undefined
1291
+ }
1292
+
1293
+ callDef(mod: RubyModule, def: Extract<Stmt, { k: 'def' }>, args: Value[]): Value {
1294
+ if (args.length !== def.params.length)
1295
+ this.fail(
1296
+ `${def.name} takes ${def.params.length} arguments, got ${args.length}`,
1297
+ def.line,
1298
+ )
1299
+ const scope = new Scope(this.constants)
1300
+ def.params.forEach((param, index) => scope.vars.set(param, args[index]!))
1301
+ const outer = this.self
1302
+ this.self = mod
1303
+ this.calls++
1304
+ try {
1305
+ return this.exec(scope, def.body)
1306
+ } catch (error) {
1307
+ if (error instanceof ReturnSignal) return error.value
1308
+ if (error instanceof RubyError && this.calls === 1)
1309
+ throw new PodspecRaised(`${this.file}: ${def.name} raised: ${error.message}`)
1310
+ throw error
1311
+ } finally {
1312
+ this.calls--
1313
+ this.self = outer
1314
+ }
1315
+ }
1316
+
1317
+ // statements with Ruby's own semantics, for the helper modules a podspec requires
1318
+ exec(scope: Scope, stmts: Stmt[]): Value {
1319
+ let last: Value = null
1320
+ for (const stmt of stmts) last = this.execOne(scope, stmt)
1321
+ return last
1322
+ }
1323
+
1324
+ execOne(scope: Scope, stmt: Stmt): Value {
1325
+ switch (stmt.k) {
1326
+ case 'module': {
1327
+ const mod = this.modules.get(stmt.name) ?? {
1328
+ methods: new Map(),
1329
+ ivars: new Map(),
1330
+ }
1331
+ this.modules.set(stmt.name, mod)
1332
+ const outer = this.self
1333
+ this.self = mod
1334
+ try {
1335
+ this.exec(new Scope(this.constants), stmt.body)
1336
+ } finally {
1337
+ this.self = outer
1338
+ }
1339
+ return null
1340
+ }
1341
+ case 'def':
1342
+ this.module().methods.set(stmt.name, stmt)
1343
+ return null
1344
+ case 'if': {
1345
+ for (const [index, branch] of stmt.branches.entries()) {
1346
+ if (truthy(this.value(scope, branch.cond)) !== (stmt.unless && index === 0))
1347
+ return this.exec(scope, branch.body)
1348
+ }
1349
+ return stmt.other ? this.exec(scope, stmt.other) : null
1350
+ }
1351
+ case 'begin': {
1352
+ if (stmt.rest.length > 0 || stmt.rescue.length > 1)
1353
+ return this.fail('else, ensure or several rescue clauses', stmt.line)
1354
+ try {
1355
+ return this.exec(scope, stmt.body)
1356
+ } catch (error) {
1357
+ if (!(error instanceof RubyError) || stmt.rescue.length === 0) throw error
1358
+ return this.exec(scope, stmt.rescue[0]!)
1359
+ }
1360
+ }
1361
+ case 'do': {
1362
+ const { head } = stmt
1363
+ if (head.length === 1 && head[0]?.v === 'loop') {
1364
+ // an endless Ruby loop that never breaks would hang CocoaPods too; bound it
1365
+ for (let round = 0; round < 10_000; round++) {
1366
+ try {
1367
+ this.exec(new Scope(scope), stmt.body)
1368
+ } catch (error) {
1369
+ if (error instanceof BreakSignal) return null
1370
+ throw error
1371
+ }
1372
+ }
1373
+ return this.fail('loop without break', stmt.line)
1374
+ }
1375
+ if (
1376
+ head.length < 3 ||
1377
+ head[head.length - 1]?.v !== 'each' ||
1378
+ head[head.length - 2]?.v !== '.'
1379
+ )
1380
+ return this.fail(`block ${head.map((tok) => tok.v).join(' ')}`, stmt.line)
1381
+ const collection = this.value(scope, head.slice(0, -2))
1382
+ if (!Array.isArray(collection) && !(collection instanceof Map))
1383
+ return this.fail('each on a non-collection', stmt.line)
1384
+ const entries: Value[][] =
1385
+ collection instanceof Map
1386
+ ? [...collection.entries()]
1387
+ : collection.map((item) => [item])
1388
+ for (const entry of entries) {
1389
+ const loop = new Scope(scope)
1390
+ stmt.params.forEach((param, index) =>
1391
+ loop.vars.set(param, entry[index] ?? null),
1392
+ )
1393
+ this.exec(loop, stmt.body)
1394
+ }
1395
+ return null
1396
+ }
1397
+ case 'expr': {
1398
+ const { toks } = stmt
1399
+ if (stmt.modifier) {
1400
+ if (truthy(this.value(scope, stmt.modifier.toks)) === stmt.modifier.unless)
1401
+ return null
1402
+ }
1403
+ const first = toks[0]
1404
+ if (first?.t === 'id' && first.v === 'break' && toks.length === 1)
1405
+ throw new BreakSignal()
1406
+ if (first?.t === 'id' && first.v === 'return')
1407
+ throw new ReturnSignal(
1408
+ toks.length > 1 ? this.value(scope, toks.slice(1)) : null,
1409
+ )
1410
+ if (first?.t === 'id' && first.v === 'raise')
1411
+ throw new RubyError(
1412
+ toks
1413
+ .filter((tok) => tok.t === 'str')
1414
+ .map((tok) => tok.v)
1415
+ .join(''),
1416
+ )
1417
+ if (
1418
+ first?.t === 'id' &&
1419
+ (first.v === 'require' || first.v === 'require_relative')
1420
+ ) {
1421
+ this.requireFile(
1422
+ scope,
1423
+ toks.slice(1),
1424
+ stmt.line,
1425
+ first.v === 'require_relative',
1426
+ )
1427
+ return null
1428
+ }
1429
+ // every method here is already callable on the module
1430
+ if (first?.v === 'module_function' && toks.length === 1) return null
1431
+ // CocoaPods' console output has no effect on what a podspec compiles
1432
+ if (toks[0]?.v === 'Pod' && toks[1]?.v === '::' && toks[2]?.v === 'UI')
1433
+ return null
1434
+ return this.value(scope, toks)
1435
+ }
1436
+ }
1437
+ }
1438
+
1439
+ requireFile(scope: Scope, toks: Tok[], line: number, relative = false) {
1440
+ const target = this.value(scope, toks)
1441
+ if (typeof target !== 'string') this.fail('require target', line)
1442
+ // the standard library only supplies calls this evaluation refuses or never makes
1443
+ if (!relative && STDLIB.has(target)) return
1444
+ const name = target.endsWith('.rb') ? target : `${target}.rb`
1445
+ const file = relative ? path.resolve(path.dirname(this.current), name) : name
1446
+ if (!path.isAbsolute(file) || !fs.existsSync(file))
1447
+ this.fail(`require ${target}`, line)
1448
+ if (this.required.has(file)) return
1449
+ this.required.add(file)
1450
+ const outer = this.current
1451
+ this.current = file
1452
+ try {
1453
+ this.exec(new Scope(this.constants), parse(fs.readFileSync(file, 'utf8'), file))
1454
+ } finally {
1455
+ this.current = outer
1456
+ }
1457
+ }
1458
+
1459
+ opaque(scope: Scope, stmts: Stmt[], why: string) {
1460
+ const toks = flatten(stmts)
1461
+ for (const [index, tok] of toks.entries()) {
1462
+ if (tok.t !== 'id') continue
1463
+ if (MEMBERSHIP_WORDS.has(tok.v) || tok.v === 'SWIFT_VERSION') {
1464
+ this.fail(`${why}, and the code it guards sets ${tok.v}`, tok.line)
1465
+ }
1466
+ const next = toks[index + 1]
1467
+ const after = toks[index + 2]
1468
+ const mutated =
1469
+ next?.t === 'op' &&
1470
+ (['=', '+=', '||=', '-=', '<<', '['].includes(next.v) ||
1471
+ (next.v === '.' && after?.t === 'id' && MUTATORS.has(after.v)))
1472
+ const current = scope.get(tok.v)
1473
+ if (mutated && current !== undefined && !(current instanceof Spec))
1474
+ scope.set(tok.v, new Opaque(why))
1475
+ }
1476
+ }
1477
+
1478
+ run(scope: Scope, stmts: Stmt[]) {
1479
+ for (const stmt of stmts) {
1480
+ if (stmt.k === 'if') this.runIf(scope, stmt)
1481
+ else if (stmt.k === 'begin') this.opaque(scope, [stmt], 'begin block')
1482
+ else if (stmt.k === 'module' || stmt.k === 'def')
1483
+ this.fail(`${stmt.k} in a podspec`, stmt.line)
1484
+ else if (stmt.k === 'do') this.runBlock(scope, stmt)
1485
+ else this.runExpr(scope, stmt)
1486
+ }
1487
+ }
1488
+
1489
+ runIf(scope: Scope, stmt: Extract<Stmt, { k: 'if' }>) {
1490
+ for (const [index, branch] of stmt.branches.entries()) {
1491
+ let taken: boolean
1492
+ try {
1493
+ taken = truthy(this.value(scope, branch.cond)) !== (stmt.unless && index === 0)
1494
+ } catch (error) {
1495
+ if (!recoverable(error)) throw error
1496
+ this.opaque(scope, [stmt], error.message)
1497
+ return
1498
+ }
1499
+ if (taken) {
1500
+ this.run(scope, branch.body)
1501
+ return
1502
+ }
1503
+ }
1504
+ if (stmt.other) this.run(scope, stmt.other)
1505
+ }
1506
+
1507
+ runBlock(scope: Scope, stmt: Extract<Stmt, { k: 'do' }>) {
1508
+ const { head } = stmt
1509
+ const inner = new Scope(scope)
1510
+ const text = head.map((tok) => tok.v).join(' ')
1511
+ if (text === 'Pod :: Spec . new') {
1512
+ const spec = new Spec('spec', '')
1513
+ inner.vars.set(stmt.params[0] ?? 'spec', spec)
1514
+ this.run(inner, stmt.body)
1515
+ this.roots.push(spec)
1516
+ return
1517
+ }
1518
+ const receiver = head[0]?.t === 'id' ? scope.get(head[0].v) : undefined
1519
+ if (receiver instanceof Spec && head[1]?.v === '.' && head[2]?.t === 'id') {
1520
+ const kind = head[2].v
1521
+ if (kind === 'subspec' || kind === 'test_spec' || kind === 'app_spec') {
1522
+ const name = this.value(scope, head.slice(3))
1523
+ if (typeof name !== 'string') this.fail('subspec name', stmt.line)
1524
+ const spec = new Spec(
1525
+ kind === 'subspec' ? 'spec' : kind === 'test_spec' ? 'test' : 'app',
1526
+ `${String(receiver.attrs.get('name') ?? '')}/${name}`,
1527
+ )
1528
+ spec.attrs.set('name', name)
1529
+ receiver.subspecs.push(spec)
1530
+ if (kind === 'subspec') {
1531
+ if (stmt.params[0]) inner.vars.set(stmt.params[0], spec)
1532
+ this.run(inner, stmt.body)
1533
+ }
1534
+ return
1535
+ }
1536
+ this.fail(`block call ${kind} on the spec`, stmt.line)
1537
+ }
1538
+ if (
1539
+ head.length >= 3 &&
1540
+ head[head.length - 2]?.v === '.' &&
1541
+ head[head.length - 1]?.v === 'each'
1542
+ ) {
1543
+ let collection: Value
1544
+ try {
1545
+ collection = this.value(scope, head.slice(0, -2))
1546
+ } catch (error) {
1547
+ if (!recoverable(error)) throw error
1548
+ this.opaque(scope, [stmt], error.message)
1549
+ return
1550
+ }
1551
+ const entries: Value[][] =
1552
+ collection instanceof Map
1553
+ ? [...collection.entries()]
1554
+ : Array.isArray(collection)
1555
+ ? collection.map((item) => [item])
1556
+ : this.fail('each on a non-collection', stmt.line)
1557
+ for (const entry of entries) {
1558
+ const loop = new Scope(scope)
1559
+ for (const [index, param] of stmt.params.entries())
1560
+ loop.vars.set(param, entry[index] ?? null)
1561
+ this.run(loop, stmt.body)
1562
+ }
1563
+ return
1564
+ }
1565
+ if (
1566
+ head.length === 3 &&
1567
+ head[0]?.t === 'id' &&
1568
+ head[1]?.v === '=' &&
1569
+ head[2]?.v === 'lambda'
1570
+ ) {
1571
+ const body = flatten(stmt.body)
1572
+ body.forEach((tok, index) => {
1573
+ if (tok.t !== 'id' || stmt.params.includes(tok.v)) return
1574
+ const next = body[index + 1]
1575
+ const assigns =
1576
+ next?.t === 'op' && ['=', '+=', '-=', '||=', '<<'].includes(next.v)
1577
+ ? true
1578
+ : next?.v === '.' && MUTATORS.has(body[index + 2]?.v ?? '')
1579
+ if (MEMBERSHIP_WORDS.has(tok.v) || scope.get(tok.v) instanceof Spec)
1580
+ this.fail(
1581
+ `lambda ${head[0]!.v} reaches spec membership through ${tok.v}`,
1582
+ stmt.line,
1583
+ )
1584
+ if (assigns && scope.get(tok.v) !== undefined)
1585
+ this.fail(`lambda ${head[0]!.v} assigns the outer variable ${tok.v}`, stmt.line)
1586
+ })
1587
+ scope.set(head[0].v, new Lambda())
1588
+ return
1589
+ }
1590
+ this.fail(`unsupported block ${text}`, stmt.line)
1591
+ }
1592
+
1593
+ roots: Spec[] = []
1594
+
1595
+ runExpr(scope: Scope, stmt: Extract<Stmt, { k: 'expr' }>) {
1596
+ const { toks } = stmt
1597
+ if (stmt.modifier) {
1598
+ let condition: Value
1599
+ try {
1600
+ condition = this.value(scope, stmt.modifier.toks)
1601
+ } catch (error) {
1602
+ if (!recoverable(error)) throw error
1603
+ this.opaque(scope, [stmt], error.message)
1604
+ return
1605
+ }
1606
+ if (truthy(condition) === stmt.modifier.unless) return
1607
+ }
1608
+ const first = toks[0]
1609
+ if (!first) return
1610
+ const second = toks[1]
1611
+ if (first.t === 'id' && (first.v === 'require' || first.v === 'require_relative')) {
1612
+ this.requireFile(scope, toks.slice(1), stmt.line, first.v === 'require_relative')
1613
+ return
1614
+ }
1615
+ if (first.t === 'id' && first.v === 'raise' && !scope.get('raise'))
1616
+ throw new PodspecRaised(`${this.file}:${stmt.line}: the podspec raises`)
1617
+ const local = first.t === 'id' ? scope.get(first.v) : undefined
1618
+ if (local instanceof Spec && second?.v === '.') {
1619
+ this.runSpecStatement(scope, local, toks, stmt.line)
1620
+ return
1621
+ }
1622
+ if (
1623
+ first.t === 'id' &&
1624
+ second?.t === 'op' &&
1625
+ ['=', '+=', '||=', '-='].includes(second.v)
1626
+ ) {
1627
+ const rhs = toks.slice(2)
1628
+ const value = this.tryValue(scope, rhs)
1629
+ const old = scope.get(first.v)
1630
+ if (second.v === '=' || old === undefined) scope.set(first.v, value)
1631
+ else if (value instanceof Opaque || old instanceof Opaque)
1632
+ scope.set(first.v, value instanceof Opaque ? value : old)
1633
+ else if (second.v === '||=') scope.set(first.v, truthy(old) ? old : value)
1634
+ else if (typeof old === 'string' && typeof value === 'string' && second.v === '+=')
1635
+ scope.set(first.v, old + value)
1636
+ else if (Array.isArray(old) && Array.isArray(value))
1637
+ scope.set(
1638
+ first.v,
1639
+ second.v === '+='
1640
+ ? [...old, ...value]
1641
+ : old.filter((item) => !value.includes(item)),
1642
+ )
1643
+ else scope.set(first.v, new Opaque(`${first.v} ${second.v} on unsupported values`))
1644
+ return
1645
+ }
1646
+ if (local instanceof Lambda && second?.v === '.') {
1647
+ this.value(scope, toks)
1648
+ return
1649
+ }
1650
+ if (
1651
+ first.t === 'id' &&
1652
+ local !== undefined &&
1653
+ second?.t === 'op' &&
1654
+ (second.v === '<<' || second.v === '[' || second.v === '.')
1655
+ ) {
1656
+ const result = this.tryValue(scope, toks)
1657
+ if (result instanceof Opaque || second.v === '[')
1658
+ scope.set(
1659
+ first.v,
1660
+ new Opaque(
1661
+ second.v === '['
1662
+ ? `${first.v} is assigned by index`
1663
+ : result instanceof Opaque
1664
+ ? result.why
1665
+ : '',
1666
+ ),
1667
+ )
1668
+ return
1669
+ }
1670
+ if (first.t === 'id' && first.v === 'resolve_use_frameworks') return
1671
+ if (first.t === 'id' && SPEC_HELPERS.has(first.v)) return
1672
+ for (const tok of toks) {
1673
+ if (tok.t === 'id' && scope.get(tok.v) instanceof Spec)
1674
+ this.fail(
1675
+ `${first.v} receives the spec and is not a known podspec helper`,
1676
+ stmt.line,
1677
+ )
1678
+ }
1679
+ }
1680
+
1681
+ runSpecStatement(scope: Scope, spec: Spec, toks: Tok[], line: number) {
1682
+ const method = toks[2]
1683
+ if (method?.t !== 'id') this.fail('spec statement', line)
1684
+ const name = method!.v
1685
+ if (PLATFORMS.has(name)) {
1686
+ for (const tok of toks)
1687
+ if (
1688
+ tok.t === 'id' &&
1689
+ (tok.v === 'source_files' ||
1690
+ tok.v === 'exclude_files' ||
1691
+ tok.v === 'module_name' ||
1692
+ tok.v === 'header_dir' ||
1693
+ tok.v === 'vendored_frameworks' ||
1694
+ tok.v === 'vendored_libraries')
1695
+ )
1696
+ this.fail(`platform-specific ${tok.v}`, line)
1697
+ return
1698
+ }
1699
+ if (toks[3]?.t === 'op' && toks[3].v === '=') {
1700
+ const rhs = toks.slice(4)
1701
+ if (name === 'pod_target_xcconfig') {
1702
+ const versions = rhs.flatMap((tok, index) =>
1703
+ tok.t === 'str' &&
1704
+ tok.v === 'SWIFT_VERSION' &&
1705
+ rhs[index + 1]?.v === '=>' &&
1706
+ rhs[index + 2]?.t === 'str'
1707
+ ? [rhs[index + 2]!.v]
1708
+ : [],
1709
+ )
1710
+ const mentions = rhs.filter(
1711
+ (tok) => tok.t === 'str' && tok.v === 'SWIFT_VERSION',
1712
+ ).length
1713
+ if (
1714
+ mentions !== versions.length ||
1715
+ mentions > 1 ||
1716
+ (mentions === 1 &&
1717
+ rhs.some(
1718
+ (tok) =>
1719
+ (tok.t === 'op' && tok.v === '?') ||
1720
+ (tok.t === 'id' && tok.v.startsWith('merge')),
1721
+ ))
1722
+ ) {
1723
+ this.fail(
1724
+ 'SWIFT_VERSION is set in a form this evaluator cannot establish',
1725
+ line,
1726
+ )
1727
+ }
1728
+ if (versions[0]) spec.attrs.set('SWIFT_VERSION', versions[0])
1729
+ return
1730
+ }
1731
+ if (
1732
+ [
1733
+ 'source_files',
1734
+ 'exclude_files',
1735
+ 'name',
1736
+ 'module_name',
1737
+ 'header_dir',
1738
+ 'default_subspec',
1739
+ 'default_subspecs',
1740
+ 'vendored_frameworks',
1741
+ 'vendored_libraries',
1742
+ ].includes(name)
1743
+ )
1744
+ spec.attrs.set(name, this.tryValue(scope, rhs))
1745
+ return
1746
+ }
1747
+ if (MEMBERSHIP_WORDS.has(name) && name !== 'name')
1748
+ this.fail(`spec.${name} called as a method`, line)
1749
+ for (const tok of toks)
1750
+ if (tok.t === 'id' && (tok.v === 'source_files' || tok.v === 'exclude_files'))
1751
+ this.fail(`${tok.v} read inside a spec call`, line)
1752
+ }
1753
+ }
1754
+
1755
+ /** the root spec a podspec file defines, with its subspecs. */
1756
+ export function loadPodspec(file: string, appRoot: string | null = null): Spec {
1757
+ const evaluator = new Evaluator(
1758
+ file,
1759
+ appRoot === null ? null : path.join(appRoot, 'ios'),
1760
+ )
1761
+ const global = new Scope(evaluator.constants)
1762
+ evaluator.constants.vars.set(
1763
+ 'ENV',
1764
+ new Map([
1765
+ ['RCT_NEW_ARCH_ENABLED', '1'],
1766
+ ['RCT_FABRIC_ENABLED', '1'],
1767
+ ]),
1768
+ )
1769
+ global.vars.set('__dir__', path.dirname(path.resolve(file)))
1770
+ evaluator.run(global, parse(fs.readFileSync(file, 'utf8'), file))
1771
+ if (evaluator.roots.length !== 1)
1772
+ throw new UnsupportedPodspec(
1773
+ `${file}: expected one Pod::Spec, found ${evaluator.roots.length}`,
1774
+ )
1775
+ const root = evaluator.roots[0]!
1776
+ return root
1777
+ }
1778
+
1779
+ function strings(spec: Spec, attribute: string): string[] {
1780
+ const value = spec.attrs.get(attribute) ?? null
1781
+ if (value instanceof Opaque)
1782
+ throw new UnsupportedPodspec(
1783
+ `${spec.fullName || String(spec.attrs.get('name'))}.${attribute} is not established: ${value.why}`,
1784
+ )
1785
+ if (value === null) return []
1786
+ const list: Value[] = []
1787
+ const visit = (entry: Value) =>
1788
+ Array.isArray(entry) ? entry.forEach(visit) : list.push(entry)
1789
+ visit(value)
1790
+ if (!list.every((entry): entry is string => typeof entry === 'string'))
1791
+ throw new UnsupportedPodspec(`${attribute} is not a list of strings`)
1792
+ return list
1793
+ }
1794
+
1795
+ function text(spec: Spec, attribute: string): string | null {
1796
+ const value = spec.attrs.get(attribute) ?? null
1797
+ if (value instanceof Opaque)
1798
+ throw new UnsupportedPodspec(`${attribute} is not established: ${value.why}`)
1799
+ if (value !== null && typeof value !== 'string')
1800
+ throw new UnsupportedPodspec(`${attribute} is not a string`)
1801
+ return value
1802
+ }
1803
+
1804
+ export const podspecName = (spec: Spec) => text(spec, 'name') ?? ''
1805
+ export const podspecSwiftVersion = (spec: Spec) => text(spec, 'SWIFT_VERSION')
1806
+
1807
+ const c99 = (name: string) =>
1808
+ name
1809
+ .replace(/^([0-9])/, '_$1')
1810
+ .replace(/[^a-zA-Z0-9_]/g, '_')
1811
+ .replace(/_+/g, '_')
1812
+
1813
+ /** CocoaPods Specification#module_name: the module_name, else the header_dir or name as a C99 identifier. */
1814
+ export function podspecModuleName(spec: Spec): string {
1815
+ const moduleName = text(spec, 'module_name')
1816
+ if (moduleName) return moduleName
1817
+ const headerDir = text(spec, 'header_dir')
1818
+ if (headerDir) return c99(headerDir)
1819
+ return c99(podspecName(spec))
1820
+ }
1821
+
1822
+ /** the spec and every library subspec: the union an installation compiles once its dependents select them all. */
1823
+ export function podspecLibrarySpecs(spec: Spec): Spec[] {
1824
+ return [
1825
+ spec,
1826
+ ...spec.subspecs.filter((sub) => sub.kind === 'spec').flatMap(podspecLibrarySpecs),
1827
+ ]
1828
+ }
1829
+
1830
+ /**
1831
+ * the spec and the subspecs a dependency on it compiles (Specification#subspec_dependencies):
1832
+ * its default_subspecs when it names any, else every library subspec; test and app specs excluded.
1833
+ */
1834
+ export function podspecMembers(spec: Spec): Spec[] {
1835
+ const named = [
1836
+ ...strings(spec, 'default_subspec'),
1837
+ ...strings(spec, 'default_subspecs'),
1838
+ ]
1839
+ const selected =
1840
+ named.length > 0
1841
+ ? named.map((name) => podspecSubspec(spec, name))
1842
+ : spec.subspecs.filter((sub) => sub.kind === 'spec')
1843
+ return [spec, ...selected.flatMap(podspecMembers)]
1844
+ }
1845
+
1846
+ export function podspecSubspec(spec: Spec, name: string): Spec {
1847
+ const found = spec.subspecs.find(
1848
+ (sub) => sub.kind === 'spec' && sub.attrs.get('name') === name,
1849
+ )
1850
+ if (!found) throw new UnsupportedPodspec(`${podspecName(spec)} has no subspec ${name}`)
1851
+ return found
1852
+ }
1853
+
1854
+ /** whether the spec links prebuilt binaries through vendored_frameworks or vendored_libraries. */
1855
+ export const podspecLinksBinaries = (spec: Spec) =>
1856
+ strings(spec, 'vendored_frameworks').length +
1857
+ strings(spec, 'vendored_libraries').length >
1858
+ 0
1859
+
1860
+ export const podspecSourcePatterns = (spec: Spec) => strings(spec, 'source_files')
1861
+
1862
+ // the files CocoaPods' PathList matches: Dir.glob semantics emulated with
1863
+ // File.fnmatch(CASEFOLD | PATHNAME) over every file below the podspec directory
1864
+
1865
+ interface Tree {
1866
+ files: string[]
1867
+ dirs: Set<string>
1868
+ links: Set<string>
1869
+ }
1870
+
1871
+ const trees = new Map<string, Tree>()
1872
+
1873
+ function tree(directory: string): Tree {
1874
+ const cached = trees.get(directory)
1875
+ if (cached) return cached
1876
+ const result: Tree = { files: [], dirs: new Set(), links: new Set() }
1877
+ for (const entry of fs.readdirSync(directory, {
1878
+ recursive: true,
1879
+ withFileTypes: true,
1880
+ })) {
1881
+ const full = path.join(entry.parentPath, entry.name)
1882
+ const rel = path.relative(directory, full).split(path.sep).join('/')
1883
+ const link = entry.isSymbolicLink()
1884
+ if (link) result.links.add(rel)
1885
+ if (entry.isDirectory() || (link && fs.statSync(full).isDirectory()))
1886
+ result.dirs.add(rel.toLowerCase())
1887
+ else result.files.push(rel)
1888
+ }
1889
+ trees.set(directory, result)
1890
+ return result
1891
+ }
1892
+
1893
+ function braces(pattern: string): string[] {
1894
+ const sets = new Map<string, string[]>()
1895
+ const rewritten = pattern.replaceAll('/**/', '{/**/,/}')
1896
+ for (const [set] of rewritten.matchAll(/\{[^}]*\}/g)) {
1897
+ const values = set.replace(/[{}]/g, '').split(',')
1898
+ while (values.length && values[values.length - 1] === '') values.pop()
1899
+ sets.set(set, values)
1900
+ }
1901
+ let patterns = [rewritten]
1902
+ for (const [set, values] of sets)
1903
+ patterns = patterns.flatMap((old) =>
1904
+ values.map((value) => old.replaceAll(set, value)),
1905
+ )
1906
+ return patterns
1907
+ }
1908
+
1909
+ function fnmatch(pattern: string): RegExp {
1910
+ let source = ''
1911
+ let start = true
1912
+ for (let i = 0; i < pattern.length; i++) {
1913
+ const c = pattern[i]!
1914
+ if (c === '[') throw new UnsupportedPodspec(`character class in glob ${pattern}`)
1915
+ if (c === '*' && pattern[i + 1] === '*' && pattern[i + 2] === '/' && start) {
1916
+ source += '(?:(?!\\.)[^/]*/)*'
1917
+ i += 2
1918
+ continue
1919
+ }
1920
+ if (c === '*') {
1921
+ while (pattern[i + 1] === '*') i++
1922
+ source += (start ? '(?!\\.)' : '') + '[^/]*'
1923
+ } else if (c === '?') source += (start ? '(?!\\.)' : '') + '[^/]'
1924
+ else if (c === '\\')
1925
+ source += (pattern[++i] ?? '').replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
1926
+ else source += c.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
1927
+ start = c === '/'
1928
+ }
1929
+ return new RegExp(`^${source}$`, 'i')
1930
+ }
1931
+
1932
+ function relativeGlob(t: Tree, patterns: string[], dirPattern: string): string[] {
1933
+ const exact = new Set(t.files)
1934
+ return patterns.flatMap((pattern) => {
1935
+ if (exact.has(pattern)) return [pattern]
1936
+ let expanded = pattern
1937
+ if (t.dirs.has(pattern.toLowerCase().replace(/\/$/, '')))
1938
+ expanded += (pattern.endsWith('/') ? '' : '/') + dirPattern
1939
+ const matchers = braces(expanded).map(fnmatch)
1940
+ return t.files.filter((file) => matchers.some((matcher) => matcher.test(file)))
1941
+ })
1942
+ }
1943
+
1944
+ const SOURCE_EXTENSIONS =
1945
+ '*{.m,.mm,.i,.c,.cc,.cxx,.cpp,.c++,.swift,.h,.hh,.hpp,.ipp,.tpp,.hxx,.def}'
1946
+
1947
+ /**
1948
+ * CocoaPods' FileAccessor#source_files for one spec of the podspec in
1949
+ * `directory`: the files its source_files match minus its exclude_files, as
1950
+ * paths relative to `directory`.
1951
+ */
1952
+ export function podspecSourceFiles(directory: string, spec: Spec): string[] {
1953
+ const patterns = strings(spec, 'source_files')
1954
+ if (patterns.length === 0) return []
1955
+ const t = tree(directory)
1956
+ const excluded = new Set(relativeGlob(t, strings(spec, 'exclude_files'), '**/*'))
1957
+ const matched = [...new Set(relativeGlob(t, patterns, SOURCE_EXTENSIONS))].filter(
1958
+ (file) => !excluded.has(file),
1959
+ )
1960
+ const link = matched.find((file) => t.links.has(file))
1961
+ if (link)
1962
+ throw new UnsupportedPodspec(
1963
+ `${path.join(directory, link)} is a symbolic link in a podspec source list`,
1964
+ )
1965
+ return matched
1966
+ }