peachsim 0.1.2410 → 0.1.2412

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 (119) hide show
  1. package/README.md +2 -5
  2. package/cli/internal-child-contract.ts +0 -1
  3. package/cli/internal-child.ts +0 -6
  4. package/cli/outbound-endpoints.ts +0 -23
  5. package/dist-lib/agent-daemon-client.cjs +1 -1
  6. package/dist-lib/agent-events.cjs +1 -1
  7. package/dist-lib/attached-projects.cjs +1 -1
  8. package/dist-lib/auth/shared-session.cjs +1 -1
  9. package/dist-lib/backend-origin.cjs +1 -1
  10. package/dist-lib/beta.cjs +1 -1
  11. package/dist-lib/beta.mjs +1 -1
  12. package/dist-lib/bridge-constants.cjs +1 -1
  13. package/dist-lib/bridge-contract-input.cjs +1 -1
  14. package/dist-lib/bridge-contract-input.mjs +1 -1
  15. package/dist-lib/bridge-contract.cjs +1 -1
  16. package/dist-lib/bridge-contract.mjs +1 -1
  17. package/dist-lib/bundle-channel.cjs +10390 -4177
  18. package/dist-lib/capture-contract.cjs +1 -1
  19. package/dist-lib/capture-contract.mjs +1 -1
  20. package/dist-lib/cloud-contract.cjs +1 -1
  21. package/dist-lib/cloud-contract.mjs +1 -1
  22. package/dist-lib/cloud-test-args.cjs +1 -1
  23. package/dist-lib/cloud-test-args.mjs +1 -1
  24. package/dist-lib/cloud.cjs +1 -1
  25. package/dist-lib/cloud.mjs +1 -1
  26. package/dist-lib/config.cjs +1 -1
  27. package/dist-lib/config.mjs +1 -1
  28. package/dist-lib/detox/index.cjs +1 -1
  29. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  30. package/dist-lib/expo-swift-bundle.cjs +11656 -5443
  31. package/dist-lib/expo-swift-metadata.cjs +1 -1
  32. package/dist-lib/expo-swift-metadata.mjs +1 -1
  33. package/dist-lib/home-paths.cjs +1 -1
  34. package/dist-lib/host/bridge-host.cjs +12910 -6697
  35. package/dist-lib/host/fetch-proxy-handler.cjs +925 -151
  36. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  37. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  38. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  39. package/dist-lib/host/websocket-proxy.cjs +1 -1
  40. package/dist-lib/index.cjs +1018 -240
  41. package/dist-lib/jump-to-source-babel.cjs +1 -1
  42. package/dist-lib/jump-to-source-native.cjs +1 -1
  43. package/dist-lib/kotlin-host.cjs +1 -1
  44. package/dist-lib/menu.cjs +1 -1
  45. package/dist-lib/menu.mjs +1 -1
  46. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  47. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  48. package/dist-lib/metro-production-bundle.cjs +1 -1
  49. package/dist-lib/metro-production-bundle.mjs +1 -1
  50. package/dist-lib/metro.cjs +934 -156
  51. package/dist-lib/native-app-identity-project.cjs +9 -5
  52. package/dist-lib/native-app-identity-project.mjs +9 -5
  53. package/dist-lib/native-app-identity.cjs +1 -1
  54. package/dist-lib/native-app-identity.mjs +1 -1
  55. package/dist-lib/native-firebase-metadata.cjs +1 -1
  56. package/dist-lib/native-firebase-metadata.mjs +1 -1
  57. package/dist-lib/pdfium-raster.cjs +1 -1
  58. package/dist-lib/pdfium-raster.mjs +1 -1
  59. package/dist-lib/plist.cjs +1 -1
  60. package/dist-lib/plist.mjs +1 -1
  61. package/dist-lib/profiles.cjs +1 -1
  62. package/dist-lib/public-brand.cjs +1 -1
  63. package/dist-lib/public-origins-lib-esm.json +24 -24
  64. package/dist-lib/public-origins-lib.json +124 -104
  65. package/dist-lib/react-native-host-modules.cjs +1 -1
  66. package/dist-lib/react-native-host-modules.mjs +1 -1
  67. package/dist-lib/reap-browser.cjs +1 -1
  68. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  69. package/dist-lib/sdk.cjs +1 -1
  70. package/dist-lib/sdk.mjs +1 -1
  71. package/dist-lib/skills.cjs +14016 -7803
  72. package/dist-lib/swift-compile.cjs +62 -14
  73. package/dist-lib/swift-compile.mjs +62 -13
  74. package/dist-lib/swift-package.cjs +1 -1
  75. package/dist-lib/swift-package.mjs +1 -1
  76. package/dist-lib/swift-submit.cjs +1 -1
  77. package/dist-lib/swift-submit.mjs +1 -1
  78. package/dist-lib/swift-toolchain.cjs +1 -1
  79. package/dist-lib/swift.cjs +1 -1
  80. package/dist-lib/vite-swift.cjs +190 -36
  81. package/dist-lib/vite.cjs +3101 -2327
  82. package/dist-lib/worklet-executable.cjs +1 -1
  83. package/dist-lib/worklet-executable.mjs +1 -1
  84. package/dist-types/packages/peach-engine/src/engine/image-loader.d.ts +1 -0
  85. package/dist-types/packages/peach-engine/src/render-worker/compositor-gpu.d.ts +1 -0
  86. package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +4 -0
  87. package/dist-types/packages/peach-engine/src/render-worker/native-widgetContract.d.ts +5 -0
  88. package/kotlin/sdk.tar.gz +0 -0
  89. package/package.json +3 -3
  90. package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/ASWebAuthenticationSession.h +1 -1
  91. package/sdk/ios/System/Library/Frameworks/Photos.framework/Headers/PHAsset.h +1 -1
  92. package/sdk/ios/System/Library/Frameworks/Photos.framework/Headers/PHAssetResource.h +1 -1
  93. package/sdk/ios/System/Library/Frameworks/Photos.framework/Headers/PHChange.h +1 -1
  94. package/sdk/ios/System/Library/Frameworks/Photos.framework/Headers/PHFetchOptions.h +1 -1
  95. package/sdk/ios/System/Library/Frameworks/Photos.framework/Headers/PHFetchResult.h +1 -1
  96. package/sdk/ios/System/Library/Frameworks/Photos.framework/Headers/PHImageManager.h +2 -2
  97. package/sdk/ios/System/Library/Frameworks/Photos.framework/Headers/PHObject.h +1 -1
  98. package/sdk/ios/System/Library/Frameworks/Photos.framework/Headers/PHPhotoLibrary.h +2 -2
  99. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIDevice.h +1 -1
  100. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIVibrancyEffect.h +1 -1
  101. package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIVisualEffectView.h +1 -1
  102. package/sdk/ios/System/Library/Frameworks/UIKitActivity.framework/Headers/UIKitActivity.h +1 -1
  103. package/src/expo-native-workspace.ts +4 -0
  104. package/src/nitro-adapter.lock.json +262 -262
  105. package/src/nitro-superset.lock.json +4 -4
  106. package/src/podspec-cocoapods.ts +934 -0
  107. package/src/podspec-prism.ts +66 -0
  108. package/src/podspec-ruby-stdlib.ts +1121 -0
  109. package/src/podspec-ruby.ts +5175 -0
  110. package/src/podspec-sources.ts +25 -112
  111. package/src/swift-compile.ts +70 -12
  112. package/src/swift-distribution.lock.json +9 -8
  113. package/src/swift-host.ts +96 -19
  114. package/src/swift-objc-compile.ts +5 -0
  115. package/src/swift-packages.ts +46 -0
  116. package/src/turbo-runtime.lock.json +19 -19
  117. package/src/xcode-project.ts +17 -7
  118. package/cli/drivers/linux-cocoapods.lock.json +0 -303
  119. package/cli/drivers/linux-cocoapods.ts +0 -99
@@ -0,0 +1,934 @@
1
+ // evaluates a podspec the way CocoaPods' Specification.from_file does, with
2
+ // React Native's pod helpers loaded, and returns the evaluated attributes
3
+ // Peach's native package compilers read. the Pod module below is cocoapods-core
4
+ // 1.17.0's specification DSL (MIT, Eloy Durán and the CocoaPods team), kept to
5
+ // the parts evaluation reaches and run by Peach's Ruby interpreter.
6
+ import { spawnSync } from 'node:child_process'
7
+ import fs from 'node:fs'
8
+ import { createRequire } from 'node:module'
9
+ import path from 'node:path'
10
+ import {
11
+ childEnv,
12
+ type Frame,
13
+ Interpreter,
14
+ nodeShell,
15
+ requireFile,
16
+ RModule,
17
+ RObject,
18
+ RString,
19
+ RubyError,
20
+ str,
21
+ UnsupportedRuby,
22
+ } from './podspec-ruby'
23
+ import { defineVersionClass, installStdlib, toJson } from './podspec-ruby-stdlib'
24
+
25
+ const PRELUDE = String.raw`
26
+ module Pod
27
+ VERSION = '1.17.0'
28
+ class Informative < StandardError; end
29
+ class PlainInformative < StandardError; end
30
+ class Version < Gem::Version; end
31
+
32
+ class Requirement
33
+ PATTERN = /\A\s*(=|!=|>|<|>=|<=|~>)?\s*([0-9]+(?:\.[0-9a-zA-Z]+)*(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?)\s*\z/
34
+ attr_reader :requirements
35
+ def self.create(input)
36
+ input.is_a?(Requirement) ? input : new(input)
37
+ end
38
+ def initialize(*requirements)
39
+ requirements = requirements.flatten
40
+ requirements.compact!
41
+ requirements.uniq!
42
+ @requirements = requirements.empty? ? [['>=', Version.new('0')]] : requirements.map { |r| parse(r) }
43
+ end
44
+ def parse(requirement)
45
+ return ['=', requirement] if requirement.is_a?(Version)
46
+ match = PATTERN.match(requirement.to_s)
47
+ raise ArgumentError, "Illformed requirement [#{requirement.inspect}]" unless match
48
+ [match[1] || '=', Version.new(match[2])]
49
+ end
50
+ def to_s
51
+ requirements.map { |op, version| "#{op} #{version}" }.join(', ')
52
+ end
53
+ end
54
+
55
+ class Dependency
56
+ attr_reader :name, :requirement
57
+ def initialize(name = nil, *requirements)
58
+ @name = name
59
+ @requirement = Requirement.create(requirements)
60
+ end
61
+ end
62
+
63
+ class Platform
64
+ attr_reader :name, :deployment_target
65
+ def initialize(name, deployment_target = nil)
66
+ @name = name.to_s == 'macos' ? :osx : name.to_sym
67
+ @deployment_target = deployment_target.nil? ? nil : Version.new(deployment_target)
68
+ end
69
+ def ==(other)
70
+ other.is_a?(Platform) && name == other.name && deployment_target == other.deployment_target
71
+ end
72
+ def to_sym
73
+ name
74
+ end
75
+ def to_s
76
+ name.to_s
77
+ end
78
+ end
79
+
80
+ class Config
81
+ attr_accessor :installation_root, :podfile, :lockfile
82
+ def self.instance
83
+ @instance ||= new
84
+ end
85
+ def sandbox_root
86
+ installation_root + 'Pods'
87
+ end
88
+ def project_pods_root
89
+ sandbox_root
90
+ end
91
+ def verbose?
92
+ false
93
+ end
94
+ def silent?
95
+ true
96
+ end
97
+ end
98
+
99
+ module UI
100
+ def self.puts(*args); end
101
+ def self.print(*args); end
102
+ def self.warn(*args); end
103
+ def self.notice(*args); end
104
+ def self.message(*args); yield if block_given?; end
105
+ def self.info(*args); yield if block_given?; end
106
+ def self.section(*args); yield if block_given?; end
107
+ def self.titled_section(*args); yield if block_given?; end
108
+ end
109
+ CoreUI = UI
110
+
111
+ class Specification
112
+ module DSL
113
+ PLATFORMS = [:osx, :ios, :tvos, :visionos, :watchos].freeze
114
+ SINGULAR = {
115
+ swift_versions: 'swift_version', authors: 'author', screenshots: 'screenshot', frameworks: 'framework',
116
+ weak_frameworks: 'weak_framework', libraries: 'library', compiler_flags: 'compiler_flag',
117
+ script_phases: 'script_phase', vendored_frameworks: 'vendored_framework', vendored_libraries: 'vendored_library',
118
+ on_demand_resources: 'on_demand_resource', resource_bundles: 'resource_bundle', resources: 'resource',
119
+ preserve_paths: 'preserve_path', default_subspecs: 'default_subspec'
120
+ }.freeze
121
+
122
+ class Attribute
123
+ attr_reader :name, :container, :types, :default_value
124
+ def initialize(name, options)
125
+ @name = name
126
+ @multi_platform = options.fetch(:multi_platform, true)
127
+ @root_only = options.fetch(:root_only, false)
128
+ @inherited = options.fetch(:inherited, @root_only)
129
+ @singularize = options.fetch(:singularize, false)
130
+ @container = options.fetch(:container, nil)
131
+ @default_value = options.fetch(:default_value, nil)
132
+ @types = options.fetch(:types, [String])
133
+ end
134
+ def multi_platform?
135
+ @multi_platform
136
+ end
137
+ def root_only?
138
+ @root_only
139
+ end
140
+ def inherited?
141
+ @inherited
142
+ end
143
+ def writer_name
144
+ "#{name}="
145
+ end
146
+ def writer_singular_form
147
+ "#{SINGULAR.fetch(name)}=" if @singularize
148
+ end
149
+ def default(platform = nil)
150
+ @default_value
151
+ end
152
+ end
153
+
154
+ def self.attributes
155
+ @attributes
156
+ end
157
+ def self.attribute(name, options = {})
158
+ @attributes ||= {}
159
+ @attributes[name] = Attribute.new(name, options)
160
+ end
161
+ def self.root_attribute(name, options = {})
162
+ options[:root_only] = true
163
+ options[:multi_platform] = false
164
+ attribute(name, options)
165
+ end
166
+
167
+ attribute :name, :inherited => false, :multi_platform => false
168
+ root_attribute :version
169
+ root_attribute :swift_versions, :container => Array, :singularize => true
170
+ root_attribute :cocoapods_version
171
+ root_attribute :authors, :types => [String, Array, Hash], :container => Hash, :singularize => true
172
+ root_attribute :social_media_url
173
+ root_attribute :license, :container => Hash
174
+ root_attribute :homepage
175
+ root_attribute :readme
176
+ root_attribute :changelog
177
+ root_attribute :source, :container => Hash
178
+ root_attribute :summary
179
+ root_attribute :description
180
+ root_attribute :screenshots, :singularize => true, :container => Array
181
+ root_attribute :documentation_url
182
+ root_attribute :prepare_command
183
+ root_attribute :static_framework, :types => [TrueClass, FalseClass], :default_value => false
184
+ root_attribute :deprecated, :types => [TrueClass, FalseClass], :default_value => false
185
+ root_attribute :deprecated_in_favor_of
186
+ attribute :platforms, :container => Hash, :multi_platform => false, :inherited => true
187
+ attribute :dependencies, :container => Hash, :inherited => true
188
+ attribute :info_plist, :container => Hash, :inherited => false
189
+ attribute :requires_arc, :types => [TrueClass, FalseClass, String, Array], :default_value => true, :inherited => true
190
+ attribute :frameworks, :container => Array, :singularize => true, :inherited => true
191
+ attribute :weak_frameworks, :container => Array, :singularize => true, :inherited => true
192
+ attribute :libraries, :container => Array, :singularize => true, :inherited => true
193
+ attribute :compiler_flags, :container => Array, :singularize => true, :inherited => true
194
+ attribute :pod_target_xcconfig, :container => Hash, :inherited => true
195
+ attribute :user_target_xcconfig, :container => Hash, :inherited => true
196
+ attribute :prefix_header_contents, :types => [Array, String], :inherited => true
197
+ attribute :prefix_header_file, :types => [TrueClass, FalseClass, String], :inherited => true
198
+ root_attribute :module_name
199
+ attribute :header_dir, :inherited => true
200
+ attribute :header_mappings_dir, :inherited => true
201
+ attribute :script_phases, :types => [Hash], :container => Array, :singularize => true
202
+ attribute :source_files, :container => Array
203
+ attribute :public_header_files, :container => Array
204
+ attribute :project_header_files, :container => Array
205
+ attribute :private_header_files, :container => Array
206
+ attribute :vendored_frameworks, :container => Array, :singularize => true
207
+ attribute :vendored_libraries, :container => Array, :singularize => true
208
+ attribute :on_demand_resources, :types => [String, Array, Hash], :container => Hash, :singularize => true
209
+ attribute :resource_bundles, :types => [String, Array], :container => Hash, :singularize => true
210
+ attribute :resources, :container => Array, :singularize => true
211
+ attribute :exclude_files, :container => Array
212
+ attribute :preserve_paths, :container => Array, :singularize => true
213
+ attribute :module_map, :types => [TrueClass, FalseClass, String], :root_only => true
214
+ attribute :test_type, :types => [Symbol, String], :multi_platform => false
215
+ attribute :requires_app_host, :types => [TrueClass, FalseClass], :default_value => false
216
+ attribute :app_host_name, :types => [String]
217
+ attribute :scheme, :types => [Hash], :container => Hash
218
+ root_attribute :default_subspecs, :container => Array, :types => [Array, String, Symbol], :singularize => true
219
+ attribute :xcconfig, :container => Hash, :inherited => true
220
+
221
+ class PlatformProxy
222
+ attr_accessor :spec
223
+ attr_reader :platform
224
+ def initialize(spec, platform)
225
+ @spec = spec
226
+ @platform = platform
227
+ end
228
+ def method_missing(meth, *args, &block)
229
+ attribute = attribute_for_method(meth)
230
+ raise NoMethodError, "undefined method '#{meth}' for #{self}" unless attribute
231
+ raise NoMethodError, "#{attribute} cannot be set per-platform" unless attribute.multi_platform?
232
+ spec.store_attribute(attribute.name, args.first, platform)
233
+ end
234
+ def respond_to_missing?(method, include_all)
235
+ attribute = attribute_for_method(method)
236
+ (attribute && attribute.multi_platform?) || false
237
+ end
238
+ def dependency(*args)
239
+ name, *version_requirements = args
240
+ platform_name = platform.to_s
241
+ platform_hash = spec.attributes_hash[platform_name] || {}
242
+ platform_hash['dependencies'] ||= {}
243
+ platform_hash['dependencies'][name] = version_requirements
244
+ spec.attributes_hash[platform_name] = platform_hash
245
+ end
246
+ def deployment_target=(value)
247
+ platform_name = platform.to_s
248
+ spec.attributes_hash['platforms'] ||= {}
249
+ spec.attributes_hash['platforms'][platform_name] = value
250
+ end
251
+ private
252
+ def attribute_for_method(method)
253
+ method = method.to_sym
254
+ Specification::DSL.attributes.values.find do |attribute|
255
+ if attribute.writer_name.to_sym == method
256
+ true
257
+ elsif attribute.writer_singular_form
258
+ attribute.writer_singular_form.to_sym == method
259
+ end
260
+ end
261
+ end
262
+ end
263
+ end
264
+
265
+ class Consumer
266
+ attr_reader :spec, :platform_name
267
+ def initialize(spec, platform)
268
+ @spec = spec
269
+ @platform_name = platform.respond_to?(:name) ? platform.name : platform
270
+ end
271
+
272
+ def self.spec_attr_accessor(attr_name)
273
+ define_method(attr_name) do
274
+ value_for_attribute(attr_name)
275
+ end
276
+ end
277
+
278
+ spec_attr_accessor :requires_arc
279
+ spec_attr_accessor :frameworks
280
+ spec_attr_accessor :weak_frameworks
281
+ spec_attr_accessor :libraries
282
+ spec_attr_accessor :compiler_flags
283
+ spec_attr_accessor :info_plist
284
+ spec_attr_accessor :prefix_header_contents
285
+ spec_attr_accessor :prefix_header_file
286
+ spec_attr_accessor :module_name
287
+ spec_attr_accessor :module_map
288
+ spec_attr_accessor :header_dir
289
+ spec_attr_accessor :header_mappings_dir
290
+ spec_attr_accessor :requires_app_host
291
+ spec_attr_accessor :app_host_name
292
+ spec_attr_accessor :source_files
293
+ spec_attr_accessor :public_header_files
294
+ spec_attr_accessor :project_header_files
295
+ spec_attr_accessor :private_header_files
296
+ spec_attr_accessor :vendored_frameworks
297
+ spec_attr_accessor :vendored_libraries
298
+ spec_attr_accessor :resources
299
+ spec_attr_accessor :exclude_files
300
+ spec_attr_accessor :preserve_paths
301
+
302
+ def pod_target_xcconfig
303
+ attr = Specification::DSL.attributes[:pod_target_xcconfig]
304
+ merge_values(attr, value_for_attribute(:xcconfig), value_for_attribute(:pod_target_xcconfig))
305
+ end
306
+
307
+ def user_target_xcconfig
308
+ attr = Specification::DSL.attributes[:user_target_xcconfig]
309
+ merge_values(attr, value_for_attribute(:xcconfig), value_for_attribute(:user_target_xcconfig))
310
+ end
311
+
312
+ def dependencies
313
+ value = value_for_attribute(:dependencies)
314
+ value.map do |name, requirements|
315
+ Dependency.new(name, requirements)
316
+ end
317
+ end
318
+
319
+ def value_for_attribute(attr_name)
320
+ attr = Specification::DSL.attributes[attr_name]
321
+ value = value_with_inheritance(spec, attr)
322
+ value = attr.default(platform_name) if value.nil?
323
+ value = attr.container.new if value.nil? && attr.container
324
+ value
325
+ end
326
+
327
+ def value_with_inheritance(the_spec, attr)
328
+ value = raw_value_for_attribute(the_spec, attr)
329
+ if the_spec.root? || !attr.inherited?
330
+ return value
331
+ end
332
+ parent_value = value_with_inheritance(the_spec.parent, attr)
333
+ merge_values(attr, parent_value, value)
334
+ end
335
+
336
+ def raw_value_for_attribute(the_spec, attr)
337
+ value = the_spec.attributes_hash[attr.name.to_s]
338
+ value = prepare_value(attr, value)
339
+ if attr.multi_platform?
340
+ if platform_hash = the_spec.attributes_hash[platform_name.to_s]
341
+ platform_value = platform_hash[attr.name.to_s]
342
+ platform_value = prepare_value(attr, platform_value)
343
+ value = merge_values(attr, value, platform_value)
344
+ end
345
+ end
346
+ value
347
+ end
348
+
349
+ def merge_values(attr, existing_value, new_value)
350
+ return existing_value if new_value.nil?
351
+ return new_value if existing_value.nil?
352
+ if attr.types.include?(TrueClass)
353
+ new_value.nil? ? existing_value : new_value
354
+ elsif attr.container == Array
355
+ r = [*existing_value] + [*new_value]
356
+ r.compact
357
+ elsif attr.container == Hash
358
+ existing_value.merge(new_value) do |_, old, new|
359
+ merge_hash_value(attr, old, new)
360
+ end
361
+ else
362
+ new_value
363
+ end
364
+ end
365
+
366
+ def prepare_value(attr, value)
367
+ if attr.container == Array
368
+ value = if value.is_a?(Hash)
369
+ [value]
370
+ else
371
+ [*value].compact
372
+ end
373
+ end
374
+ value
375
+ end
376
+
377
+ private
378
+
379
+ def merge_hash_value(attr, old, new)
380
+ if attr.name == :info_plist
381
+ new
382
+ elsif spec.non_library_specification? && [:pod_target_xcconfig, :user_target_xcconfig, :xcconfig].include?(attr.name)
383
+ new
384
+ elsif new.is_a?(Array) || old.is_a?(Array)
385
+ r = Array(old) + Array(new)
386
+ r.compact
387
+ else
388
+ old + ' ' + new
389
+ end
390
+ end
391
+ end
392
+
393
+ attr_reader :parent
394
+ attr_accessor :attributes_hash, :subspecs, :test_specification, :app_specification, :defined_in_file
395
+ alias_method :test_specification?, :test_specification
396
+ alias_method :app_specification?, :app_specification
397
+
398
+ def initialize(parent = nil, name = nil, test_specification = false, app_specification: false)
399
+ raise StandardError, "#{self} can not be both an app and test specification." if test_specification && app_specification
400
+ @attributes_hash = {}
401
+ @subspecs = []
402
+ @consumers = {}
403
+ @parent = parent
404
+ @test_specification = test_specification
405
+ @app_specification = app_specification
406
+ attributes_hash['name'] = name
407
+ attributes_hash['test_type'] = :unit if test_specification
408
+ yield self if block_given?
409
+ end
410
+
411
+ def to_s
412
+ specified_version = attributes_hash['version'] || ''
413
+ if name && !specified_version.to_s.empty?
414
+ "#{name} (#{specified_version})"
415
+ elsif name
416
+ name
417
+ else
418
+ 'No-name'
419
+ end
420
+ end
421
+
422
+ def inspect
423
+ "#<#{self.class.name} name=#{name.inspect}>"
424
+ end
425
+
426
+ def base_name
427
+ attributes_hash['name']
428
+ end
429
+
430
+ def name
431
+ parent ? "#{parent.name}/#{base_name}" : base_name
432
+ end
433
+
434
+ def name=(name)
435
+ attributes_hash['name'] = name
436
+ end
437
+
438
+ def root
439
+ parent ? parent.root : self
440
+ end
441
+
442
+ def root?
443
+ parent.nil?
444
+ end
445
+
446
+ def subspec?
447
+ !parent.nil?
448
+ end
449
+
450
+ def spec_type
451
+ return :test if test_specification?
452
+ return :app if app_specification?
453
+ :library
454
+ end
455
+
456
+ def library_specification?
457
+ !app_specification? && !test_specification?
458
+ end
459
+
460
+ def non_library_specification?
461
+ !library_specification?
462
+ end
463
+
464
+ def version
465
+ if root?
466
+ @version ||= Version.new(attributes_hash['version'])
467
+ else
468
+ @version ||= root.version
469
+ end
470
+ end
471
+
472
+ def requires_arc
473
+ attributes_hash['requires_arc']
474
+ end
475
+
476
+ def swift_version
477
+ swift_versions.last
478
+ end
479
+
480
+ def swift_versions
481
+ @swift_versions ||= begin
482
+ swift_versions = Array(attributes_hash['swift_versions']).dup
483
+ swift_versions << attributes_hash['swift_version'] unless attributes_hash['swift_version'].nil?
484
+ swift_versions.map { |swift_version| Version.new(swift_version) }.uniq.sort
485
+ end
486
+ end
487
+
488
+ def module_name
489
+ attributes_hash['module_name'] || name.split('/').first.gsub(/^([0-9])/, '_\1').gsub(/[^a-zA-Z0-9_]/, '_').gsub(/_+/, '_')
490
+ end
491
+
492
+ def homepage
493
+ attributes_hash['homepage']
494
+ end
495
+
496
+ def summary
497
+ attributes_hash['summary']
498
+ end
499
+
500
+ def source
501
+ value = attributes_hash['source']
502
+ value && value.is_a?(Hash) ? Specification.convert_keys_to_symbol(value) : value
503
+ end
504
+
505
+ def default_subspecs
506
+ value = Array(attributes_hash['default_subspecs'])
507
+ first = value.first
508
+ if first == :none || first == 'none'
509
+ first.to_sym
510
+ else
511
+ value
512
+ end
513
+ end
514
+
515
+ def dependencies(platform = nil)
516
+ if platform
517
+ consumer(platform).dependencies || []
518
+ else
519
+ available_platforms.map do |spec_platform|
520
+ consumer(spec_platform).dependencies
521
+ end.flatten.uniq
522
+ end
523
+ end
524
+
525
+ def consumer(platform)
526
+ platform = platform.to_sym
527
+ @consumers[platform] ||= Consumer.new(self, platform)
528
+ end
529
+
530
+ def subspec_by_name(relative_name, raise_if_missing = true, include_non_library_specifications = false)
531
+ if relative_name.nil? || relative_name == base_name
532
+ self
533
+ elsif relative_name.downcase == base_name.downcase
534
+ raise Informative, "Trying to access a '#{relative_name}' specification from '#{base_name}', which has a different case."
535
+ else
536
+ remainder = relative_name[base_name.size + 1..-1]
537
+ subspec_name = remainder.split('/').shift
538
+ subspec = subspecs.find { |s| s.base_name == subspec_name && (include_non_library_specifications || !s.non_library_specification?) }
539
+ unless subspec
540
+ if raise_if_missing
541
+ raise Informative, "Unable to find a specification named " \
542
+ "'#{relative_name}' in '#{name} (#{version})'."
543
+ else
544
+ return nil
545
+ end
546
+ end
547
+ subspec.subspec_by_name(remainder, raise_if_missing, include_non_library_specifications)
548
+ end
549
+ end
550
+
551
+ def available_platforms
552
+ names = supported_platform_names
553
+ names = DSL::PLATFORMS.map(&:to_s) if names.empty?
554
+ names.map { |name| Platform.new(name, deployment_target(name)) }
555
+ end
556
+
557
+ def supported_platform_names
558
+ spec = self
559
+ names = nil
560
+ until spec.nil?
561
+ if spec.attributes_hash['platforms']
562
+ spec_platforms = spec.attributes_hash['platforms'].keys
563
+ names = names.nil? ? spec_platforms : names & spec_platforms
564
+ end
565
+ spec = spec.parent
566
+ end
567
+ names || []
568
+ end
569
+
570
+ def deployment_target(platform_name)
571
+ result = platform_hash[platform_name.to_s]
572
+ result ||= parent.deployment_target(platform_name) if parent
573
+ result
574
+ end
575
+
576
+ def platform_hash
577
+ case value = attributes_hash['platforms']
578
+ when String
579
+ { value => nil }
580
+ when Array
581
+ result = {}
582
+ value.each { |a| result[a] = nil }
583
+ result
584
+ when Hash
585
+ value
586
+ else
587
+ {}
588
+ end
589
+ end
590
+
591
+ def store_attribute(name, value, platform_name = nil)
592
+ name = name.to_s
593
+ value = Specification.convert_keys_to_string(value) if value.is_a?(Hash)
594
+ value = value.strip_heredoc.strip if value.respond_to?(:strip_heredoc)
595
+ if platform_name
596
+ platform_name = platform_name.to_s
597
+ attributes_hash[platform_name] ||= {}
598
+ attributes_hash[platform_name][name] = value
599
+ else
600
+ attributes_hash[name] = value
601
+ end
602
+ end
603
+
604
+ def self.convert_keys_to_string(value, recursive: true)
605
+ return unless value
606
+ result = {}
607
+ value.each do |key, subvalue|
608
+ subvalue = Specification.convert_keys_to_string(subvalue) if recursive && subvalue.is_a?(Hash)
609
+ result[key.to_s] = subvalue
610
+ end
611
+ result
612
+ end
613
+
614
+ def self.convert_keys_to_symbol(value, recursive: true)
615
+ return unless value
616
+ result = {}
617
+ value.each do |key, subvalue|
618
+ subvalue = Specification.convert_keys_to_symbol(subvalue) if recursive && subvalue.is_a?(Hash)
619
+ result[key.to_sym] = subvalue
620
+ end
621
+ result
622
+ end
623
+
624
+ DSL.attributes.values.each do |a|
625
+ define_method(a.writer_name) do |value|
626
+ store_attribute(a.name, value)
627
+ end
628
+ if a.writer_singular_form
629
+ alias_method(a.writer_singular_form, a.writer_name)
630
+ end
631
+ end
632
+
633
+ def platform=(args)
634
+ name, deployment_target = args
635
+ name = :osx if name.to_s == 'macos'
636
+ attributes_hash['platforms'] = if name
637
+ { name.to_s => deployment_target }
638
+ else
639
+ {}
640
+ end
641
+ end
642
+
643
+ def deployment_target=(*_args)
644
+ raise Informative, 'The deployment target can be declared only per platform.'
645
+ end
646
+
647
+ def dependency(*args)
648
+ name, *version_requirements = args
649
+ if name == self.name
650
+ raise Informative, "A specification can't require itself as a subspec"
651
+ end
652
+ if @parent
653
+ composed_name = ''
654
+ @parent.name.split('/').each do |component|
655
+ composed_name << component
656
+ if name == composed_name
657
+ raise Informative, "A subspec can't require one of its parents specifications"
658
+ else
659
+ composed_name << '/'
660
+ end
661
+ end
662
+ end
663
+
664
+ configurations_option = version_requirements.find { |option| option.is_a?(Hash) && option.key?(:configurations) }
665
+ whitelisted_configurations = if configurations_option
666
+ version_requirements.delete(configurations_option)
667
+ Array(configurations_option.delete(:configurations)).map { |c| c.to_s.downcase }
668
+ end
669
+
670
+ dependency_options = version_requirements.reject { |req| req.is_a?(String) }
671
+ dependency_options.each do |dependency_option|
672
+ if dependency_option.is_a?(Hash)
673
+ if !dependency_option[:path].nil?
674
+ raise Informative, 'Podspecs cannot specify the source of dependencies. The :path option is not supported.'
675
+ elsif !dependency_option[:git].nil?
676
+ raise Informative, 'Podspecs cannot specify the source of dependencies. The :git option is not supported.'
677
+ end
678
+ end
679
+ raise Informative, "Unsupported version requirements. #{version_requirements.inspect} is not valid."
680
+ end
681
+
682
+ attributes_hash['dependencies'] ||= {}
683
+ attributes_hash['dependencies'][name] = version_requirements
684
+
685
+ unless whitelisted_configurations.nil?
686
+ attributes_hash['configuration_pod_whitelist'] ||= {}
687
+ attributes_hash['configuration_pod_whitelist'][name] = whitelisted_configurations
688
+ end
689
+ end
690
+
691
+ def dependency=(args)
692
+ raise Informative, "Cannot assign value to dependency."
693
+ end
694
+
695
+ def subspec(name, &block)
696
+ subspec = Specification.new(self, name, &block)
697
+ @subspecs << subspec
698
+ subspec
699
+ end
700
+
701
+ def test_spec(name = 'Tests', &block)
702
+ subspec = Specification.new(self, name, true, &block)
703
+ @subspecs << subspec
704
+ subspec
705
+ end
706
+
707
+ def app_spec(name = 'App', &block)
708
+ appspec = Specification.new(self, name, :app_specification => true, &block)
709
+ @subspecs << appspec
710
+ appspec
711
+ end
712
+
713
+ def ios
714
+ DSL::PlatformProxy.new(self, :ios)
715
+ end
716
+ def osx
717
+ DSL::PlatformProxy.new(self, :osx)
718
+ end
719
+ alias macos osx
720
+ def tvos
721
+ DSL::PlatformProxy.new(self, :tvos)
722
+ end
723
+ def visionos
724
+ DSL::PlatformProxy.new(self, :visionos)
725
+ end
726
+ def watchos
727
+ DSL::PlatformProxy.new(self, :watchos)
728
+ end
729
+
730
+ def to_hash
731
+ hash = attributes_hash.dup
732
+ if root? || available_platforms != parent.available_platforms
733
+ platforms = Hash[available_platforms.map { |p| [p.name.to_s, p.deployment_target && p.deployment_target.to_s] }]
734
+ hash['platforms'] = platforms
735
+ end
736
+ specs_by_type = subspecs.group_by(&:spec_type)
737
+ all_appspecs = specs_by_type[:app] || []
738
+ all_testspecs = specs_by_type[:test] || []
739
+ all_subspecs = specs_by_type[:library] || []
740
+ hash.delete('testspecs')
741
+ hash['testspecs'] = all_testspecs.map(&:to_hash) unless all_testspecs.empty?
742
+ hash.delete('appspecs')
743
+ hash['appspecs'] = all_appspecs.map(&:to_hash) unless all_appspecs.empty?
744
+ hash.delete('subspecs')
745
+ hash['subspecs'] = all_subspecs.map(&:to_hash) unless all_subspecs.empty?
746
+ hash.delete('swift_version')
747
+ hash['swift_version'] = swift_version.to_s unless swift_version.nil?
748
+ hash
749
+ end
750
+
751
+ def to_json(*a)
752
+ to_hash.to_json(*a)
753
+ end
754
+
755
+ def self.from_hash(hash, parent = nil, test_specification: false, app_specification: false)
756
+ attributes_hash = hash.dup
757
+ spec = Specification.new(parent, nil, test_specification, :app_specification => app_specification)
758
+ subspecs = attributes_hash.delete('subspecs')
759
+ testspecs = attributes_hash.delete('testspecs')
760
+ appspecs = attributes_hash.delete('appspecs')
761
+ spec.test_specification = !attributes_hash['test_type'].nil?
762
+ spec.attributes_hash = attributes_hash
763
+ spec.subspecs.concat((subspecs || []).map { |s| from_hash(s, spec, test_specification: false, app_specification: false) })
764
+ spec.subspecs.concat((testspecs || []).map { |s| from_hash(s, spec, test_specification: true, app_specification: false) })
765
+ spec.subspecs.concat((appspecs || []).map { |s| from_hash(s, spec, test_specification: false, app_specification: true) })
766
+ spec
767
+ end
768
+ end
769
+ Spec = Specification
770
+
771
+ def self.peach_evaluated(spec)
772
+ consumer = spec.consumer(:ios)
773
+ result = {'name' => spec.name.split('/').last}
774
+ %w[source_files exclude_files public_header_files private_header_files header_mappings_dir header_dir module_name vendored_frameworks vendored_libraries pod_target_xcconfig].each do |attribute|
775
+ value = consumer.public_send(attribute)
776
+ result[attribute] = value unless value.nil?
777
+ end
778
+ result['default_subspecs'] = spec.attributes_hash['default_subspecs'] if spec.attributes_hash.key?('default_subspecs')
779
+ result['dependencies'] = consumer.dependencies.to_h { |dependency| [dependency.name, dependency.requirement.requirements.map { |operator, version| "#{operator} #{version}" }] }
780
+ result['swift_versions'] = spec.swift_versions.map(&:to_s) if spec.swift_versions
781
+ result['subspecs'] = spec.subspecs.select(&:library_specification?).map { |child| peach_evaluated(child) }
782
+ result
783
+ end
784
+ end
785
+ `
786
+
787
+ export class PodspecEvaluationError extends Error {}
788
+
789
+ function reactNativeScripts(app: string): string | null {
790
+ const require = createRequire(path.join(app, 'package.json'))
791
+ let manifest: string
792
+ try {
793
+ manifest = require.resolve('react-native/package.json')
794
+ } catch {
795
+ return null
796
+ }
797
+ const scripts = path.join(path.dirname(manifest), 'scripts/react_native_pods.rb')
798
+ return fs.existsSync(scripts) ? scripts : null
799
+ }
800
+
801
+ /**
802
+ * CocoaPods' evaluated attributes for the podspec (or `.podspec.json`) at
803
+ * `file`, evaluated in `app`'s context with `env` as ENV. the podspec may
804
+ * write only inside `writable`, its package.
805
+ */
806
+ export function evaluatePodspec(
807
+ file: string,
808
+ app: string,
809
+ writable: string,
810
+ env: Record<string, string | undefined>,
811
+ ): unknown {
812
+ const interp = new Interpreter({
813
+ cwd: app,
814
+ env: new Map(
815
+ Object.entries(env).flatMap(([k, v]) => (v === undefined ? [] : [[k, v]])),
816
+ ),
817
+ shell: (command, cwd) => nodeShell(command, cwd, interp.host.env),
818
+ loaded: new Set(),
819
+ writable: [writable],
820
+ })
821
+ installStdlib(interp)
822
+ try {
823
+ interp.evalString(PRELUDE, 'cocoapods-core')
824
+ const pod = interp.object.consts.get('Pod')
825
+ if (!(pod instanceof RModule))
826
+ throw new Error('the Pod prelude defines no Pod module')
827
+ const executable = interp.defineModule('Executable', pod)
828
+ interp.defineNative(
829
+ executable,
830
+ 'execute_command',
831
+ (c) => {
832
+ const [name, args] = c.args
833
+ if (!(name instanceof RString) || name.s !== 'node' || !Array.isArray(args))
834
+ throw new UnsupportedRuby(
835
+ `Pod::Executable.execute_command(${c.args.map((a) => interp.toS(a)).join(', ')})`,
836
+ )
837
+ const result = spawnSync(
838
+ 'node',
839
+ args.map((a) => interp.toS(a)),
840
+ {
841
+ cwd: interp.host.cwd,
842
+ env: childEnv(interp.host.env),
843
+ encoding: 'utf8',
844
+ },
845
+ )
846
+ if (result.status !== 0 && c.args[2] !== false)
847
+ return interp.raise(
848
+ 'Pod::Informative',
849
+ `node ${args.map((a) => interp.toS(a)).join(' ')}\n\n${result.stdout}${result.stderr}`,
850
+ )
851
+ return str(result.stdout ?? '')
852
+ },
853
+ true,
854
+ )
855
+ const version = pod.consts.get('Version')
856
+ if (version instanceof RModule) defineVersionClass(interp, version)
857
+ const scripts = reactNativeScripts(app)
858
+ if (scripts) requireFile(interp, 'require', scripts, null)
859
+ const config = interp.callMethod(
860
+ interp.constIn(pod, 'Config', null, '-'),
861
+ 'instance',
862
+ [],
863
+ null,
864
+ null,
865
+ null,
866
+ null,
867
+ )
868
+ const pathname = interp.object.consts.get('Pathname')
869
+ if (!(pathname instanceof RModule)) throw new Error('no Pathname')
870
+ interp.callMethod(
871
+ config,
872
+ 'installation_root=',
873
+ [
874
+ interp.callMethod(
875
+ pathname,
876
+ 'new',
877
+ [str(path.join(app, 'ios'))],
878
+ null,
879
+ null,
880
+ null,
881
+ null,
882
+ ),
883
+ ],
884
+ null,
885
+ null,
886
+ null,
887
+ null,
888
+ )
889
+ const specification = interp.constIn(pod, 'Specification', null, '-')
890
+ const source = fs.readFileSync(file, 'utf8')
891
+ let spec
892
+ if (file.endsWith('.json')) {
893
+ const hash = interp.callMethod(
894
+ interp.object.consts.get('JSON') ?? null,
895
+ 'parse',
896
+ [str(source)],
897
+ null,
898
+ null,
899
+ null,
900
+ null,
901
+ )
902
+ spec = interp.callMethod(specification, 'from_hash', [hash], null, null, null, null)
903
+ } else {
904
+ interp.host.cwd = path.dirname(file)
905
+ const frame: Frame = {
906
+ ...interp.topFrame,
907
+ self: pod,
908
+ defTarget: pod,
909
+ cref: [interp.object, pod],
910
+ file,
911
+ id: {},
912
+ }
913
+ spec = interp.evalString(source, file, frame)
914
+ }
915
+ if (
916
+ !(spec instanceof RObject) ||
917
+ !interp.isA(spec, specification instanceof RModule ? specification : interp.object)
918
+ )
919
+ throw new PodspecEvaluationError(`Invalid podspec file at path \`${file}\`.`)
920
+ interp.host.cwd = app
921
+ return toJson(
922
+ interp,
923
+ interp.callMethod(pod, 'peach_evaluated', [spec], null, null, null, null),
924
+ )
925
+ } catch (error) {
926
+ if (error instanceof RubyError)
927
+ throw new PodspecEvaluationError(`${file}: ${error.message}`)
928
+ if (error instanceof UnsupportedRuby)
929
+ throw new PodspecEvaluationError(
930
+ `${file}: Peach does not evaluate ${error.message}`,
931
+ )
932
+ throw error
933
+ }
934
+ }