peachsim 0.1.2411 → 0.1.2421

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 (146) hide show
  1. package/README.md +1 -1
  2. package/cli/catalog/content.ts +6 -3
  3. package/cli/catalog/meta.ts +63 -17
  4. package/cli/catalog/routes.ts +4 -0
  5. package/cli/cloud-box-artifact.ts +45 -24
  6. package/cli/cloud-client.ts +6 -2
  7. package/cli/command-registry.ts +3 -1
  8. package/cli/commands/control.ts +74 -55
  9. package/cli/commands/desktop.ts +3 -3
  10. package/cli/commands/electron.ts +7 -5
  11. package/cli/commands/kotlin.ts +8 -1
  12. package/cli/commands/platform.ts +5 -7
  13. package/cli/commands/profile.ts +2 -2
  14. package/cli/commands/settings.ts +90 -0
  15. package/cli/commands/shell-url.ts +18 -10
  16. package/cli/commands/swift.ts +3 -1
  17. package/cli/main.ts +6 -0
  18. package/cli/outbound-endpoints.ts +17 -15
  19. package/cli/settings-flags.ts +115 -0
  20. package/dist-lib/agent-daemon-client.cjs +1 -1
  21. package/dist-lib/agent-events.cjs +1 -1
  22. package/dist-lib/attached-projects.cjs +1 -1
  23. package/dist-lib/auth/shared-session.cjs +1 -1
  24. package/dist-lib/backend-origin.cjs +1 -1
  25. package/dist-lib/beta.cjs +1 -1
  26. package/dist-lib/beta.mjs +1 -1
  27. package/dist-lib/bridge-constants.cjs +1 -1
  28. package/dist-lib/bridge-contract-input.cjs +1 -1
  29. package/dist-lib/bridge-contract-input.mjs +1 -1
  30. package/dist-lib/bridge-contract.cjs +1 -1
  31. package/dist-lib/bridge-contract.mjs +1 -1
  32. package/dist-lib/bundle-channel.cjs +3706 -1818
  33. package/dist-lib/capture-contract.cjs +1 -1
  34. package/dist-lib/capture-contract.mjs +1 -1
  35. package/dist-lib/cloud-contract.cjs +1 -1
  36. package/dist-lib/cloud-contract.mjs +1 -1
  37. package/dist-lib/cloud-test-args.cjs +1 -1
  38. package/dist-lib/cloud-test-args.mjs +1 -1
  39. package/dist-lib/cloud.cjs +1 -1
  40. package/dist-lib/cloud.mjs +1 -1
  41. package/dist-lib/config.cjs +3 -7
  42. package/dist-lib/config.mjs +3 -7
  43. package/dist-lib/detox/index.cjs +4 -4
  44. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  45. package/dist-lib/expo-swift-bundle.cjs +17144 -15295
  46. package/dist-lib/expo-swift-metadata.cjs +1 -1
  47. package/dist-lib/expo-swift-metadata.mjs +1 -1
  48. package/dist-lib/home-paths.cjs +1 -1
  49. package/dist-lib/host/bridge-host.cjs +63288 -62269
  50. package/dist-lib/host/fetch-proxy-handler.cjs +1598 -211
  51. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  52. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  53. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  54. package/dist-lib/host/websocket-proxy.cjs +1 -1
  55. package/dist-lib/index.cjs +3007 -1512
  56. package/dist-lib/jump-to-source-babel.cjs +1 -1
  57. package/dist-lib/jump-to-source-native.cjs +1 -1
  58. package/dist-lib/kotlin-host.cjs +972 -246
  59. package/dist-lib/menu.cjs +1 -1
  60. package/dist-lib/menu.mjs +1 -1
  61. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  62. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  63. package/dist-lib/metro-production-bundle.cjs +1 -1
  64. package/dist-lib/metro-production-bundle.mjs +1 -1
  65. package/dist-lib/metro.cjs +1742 -247
  66. package/dist-lib/native-app-identity-project.cjs +40 -204
  67. package/dist-lib/native-app-identity-project.mjs +40 -204
  68. package/dist-lib/native-app-identity.cjs +1 -1
  69. package/dist-lib/native-app-identity.mjs +1 -1
  70. package/dist-lib/native-firebase-metadata.cjs +1 -1
  71. package/dist-lib/native-firebase-metadata.mjs +1 -1
  72. package/dist-lib/pdfium-raster.cjs +1 -1
  73. package/dist-lib/pdfium-raster.mjs +1 -1
  74. package/dist-lib/plist.cjs +1 -1
  75. package/dist-lib/plist.mjs +1 -1
  76. package/dist-lib/profiles.cjs +1 -1
  77. package/dist-lib/public-brand.cjs +1 -1
  78. package/dist-lib/public-origins-lib-esm.json +26 -24
  79. package/dist-lib/public-origins-lib.json +198 -117
  80. package/dist-lib/react-native-host-modules.cjs +1 -1
  81. package/dist-lib/react-native-host-modules.mjs +1 -1
  82. package/dist-lib/reap-browser.cjs +1 -1
  83. package/dist-lib/scripts/dev-server-scanner.cjs +2 -2
  84. package/dist-lib/sdk.cjs +1 -1
  85. package/dist-lib/sdk.mjs +1 -1
  86. package/dist-lib/skills.cjs +21765 -20511
  87. package/dist-lib/swift-compile.cjs +48 -228
  88. package/dist-lib/swift-compile.mjs +48 -228
  89. package/dist-lib/swift-package.cjs +1 -1
  90. package/dist-lib/swift-package.mjs +1 -1
  91. package/dist-lib/swift-submit.cjs +1 -1
  92. package/dist-lib/swift-submit.mjs +1 -1
  93. package/dist-lib/swift-toolchain.cjs +1 -199
  94. package/dist-lib/swift.cjs +1 -1
  95. package/dist-lib/vite-swift.cjs +227 -251
  96. package/dist-lib/vite.cjs +5240 -3788
  97. package/dist-lib/worklet-executable.cjs +1 -1
  98. package/dist-lib/worklet-executable.mjs +1 -1
  99. package/dist-types/packages/peach-engine/src/config.d.ts +1 -4
  100. package/dist-types/packages/peach-engine/src/engine/image-loader.d.ts +1 -0
  101. package/dist-types/packages/peach-engine/src/render-worker/compositor-gpu.d.ts +1 -0
  102. package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +4 -0
  103. package/dist-types/packages/peach-engine/src/render-worker/native-widgetContract.d.ts +5 -0
  104. package/kotlin/README.md +4 -3
  105. package/kotlin/sdk.tar.gz +0 -0
  106. package/kotlin/toolchain.json +3 -6
  107. package/package.json +1 -1
  108. package/runtime-companion.json +1 -1
  109. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CALayer.h +1 -43
  110. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CALayerContents.h +55 -0
  111. package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Modules/module.modulemap +3 -3
  112. package/sdk/ios/usr/include/ObjectiveC.apinotes +0 -24
  113. package/sdk/ios/usr/include/grp.h +93 -0
  114. package/sdk/ios/usr/include/netinet/tcp.h +299 -0
  115. package/sdk/ios/wasm/include/netinet/tcp.h +6 -0
  116. package/sdk/ios/wasm/include/stdlib.h +1 -0
  117. package/sdk/ios/wasm/include/unistd.h +2 -0
  118. package/skills/contrast/SKILL.md +1 -0
  119. package/skills/peach-setup/SKILL.md +11 -1
  120. package/src/android-bridge-dependencies.ts +1 -1
  121. package/src/app-config.ts +7 -0
  122. package/src/binaryen.lock.json +21 -0
  123. package/src/cocoapods-trunk.ts +52 -0
  124. package/src/config.ts +21 -31
  125. package/src/expo-native-workspace.ts +4 -0
  126. package/src/kotlin-host.ts +1 -1
  127. package/src/kotlin-sdk.ts +7 -7
  128. package/src/kotlin-toolchain.ts +28 -24
  129. package/src/kotlinSdkContract.ts +2 -2
  130. package/src/native-bundles.ts +5 -2
  131. package/src/native-static-libraries.ts +38 -5
  132. package/src/podfile-cocoapods.ts +1473 -0
  133. package/src/podspec-cocoapods.ts +331 -106
  134. package/src/podspec-ruby-stdlib.ts +134 -19
  135. package/src/podspec-ruby.ts +199 -46
  136. package/src/settingsContract.ts +74 -0
  137. package/src/swift-compile.ts +1 -1
  138. package/src/swift-compiler-digest.ts +1 -0
  139. package/src/swift-host.ts +107 -15
  140. package/src/swift-objc-compile.ts +5 -0
  141. package/src/swift-packages.ts +75 -0
  142. package/src/swift-shared-sdk.ts +19 -0
  143. package/src/swift-toolchain.ts +2 -201
  144. package/src/turbo-source.ts +7 -37
  145. package/src/wasm-optimize.ts +4 -27
  146. package/src/xcode-project.ts +22 -7
@@ -17,16 +17,40 @@ import {
17
17
  RObject,
18
18
  RString,
19
19
  RubyError,
20
+ RSymbol,
20
21
  str,
22
+ sym,
21
23
  UnsupportedRuby,
24
+ type Value,
22
25
  } from './podspec-ruby'
23
26
  import { defineVersionClass, installStdlib, toJson } from './podspec-ruby-stdlib'
27
+ import { NATIVE_GRAPH_SDK_VERSION } from './swift-objc-standin'
24
28
 
25
29
  const PRELUDE = String.raw`
26
30
  module Pod
27
31
  VERSION = '1.17.0'
28
32
  class Informative < StandardError; end
29
33
  class PlainInformative < StandardError; end
34
+
35
+ module Executable
36
+ def self.which(program)
37
+ program = program.to_s
38
+ paths = ENV.fetch('PATH') { '' }.split(File::PATH_SEPARATOR)
39
+ paths.unshift('./')
40
+ paths.uniq!
41
+ paths.each do |path|
42
+ bin = File.expand_path(program, path)
43
+ return bin if File.file?(bin) && File.executable?(bin)
44
+ end
45
+ nil
46
+ end
47
+
48
+ def self.which!(program)
49
+ which(program).tap do |bin|
50
+ raise Informative, "Unable to locate the executable '#{program}'" unless bin
51
+ end
52
+ end
53
+ end
30
54
  class Version < Gem::Version; end
31
55
 
32
56
  class Requirement
@@ -35,6 +59,9 @@ module Pod
35
59
  def self.create(input)
36
60
  input.is_a?(Requirement) ? input : new(input)
37
61
  end
62
+ def self.default
63
+ new('>= 0')
64
+ end
38
65
  def initialize(*requirements)
39
66
  requirements = requirements.flatten
40
67
  requirements.compact!
@@ -47,16 +74,136 @@ module Pod
47
74
  raise ArgumentError, "Illformed requirement [#{requirement.inspect}]" unless match
48
75
  [match[1] || '=', Version.new(match[2])]
49
76
  end
77
+ def none?
78
+ requirements == [['>=', Version.new('0')]]
79
+ end
80
+ def satisfied_by?(version)
81
+ requirements.all? do |op, rv|
82
+ case op
83
+ when '=' then version == rv
84
+ when '!=' then version != rv
85
+ when '>' then version > rv
86
+ when '<' then version < rv
87
+ when '>=' then version >= rv
88
+ when '<=' then version <= rv
89
+ when '~>' then version >= rv && version.release < rv.bump
90
+ end
91
+ end
92
+ end
93
+ def ==(other)
94
+ other.is_a?(Requirement) && requirements.sort_by(&:to_s) == other.requirements.sort_by(&:to_s)
95
+ end
96
+ def as_list
97
+ requirements.map { |op, version| "#{op} #{version}" }.sort
98
+ end
99
+ def prerelease?
100
+ requirements.any? { |_op, version| version.prerelease? }
101
+ end
50
102
  def to_s
51
- requirements.map { |op, version| "#{op} #{version}" }.join(', ')
103
+ as_list.join(', ')
52
104
  end
53
105
  end
54
106
 
55
107
  class Dependency
56
- attr_reader :name, :requirement
108
+ attr_accessor :name
109
+ attr_accessor :external_source
110
+ attr_accessor :podspec_repo
57
111
  def initialize(name = nil, *requirements)
112
+ if requirements.last.is_a?(Hash)
113
+ additional_params = requirements.pop.select { |_, v| !v.nil? }
114
+ additional_params = nil if additional_params.empty?
115
+ if additional_params && @podspec_repo = additional_params[:source]
116
+ additional_params.delete(:source)
117
+ unless additional_params.empty?
118
+ raise Informative, 'A dependency with a specified podspec repo may ' \
119
+ "not include other source parameters (#{name})."
120
+ end
121
+ elsif @external_source = additional_params
122
+ unless requirements.empty?
123
+ raise Informative, 'A dependency with an external source may not ' \
124
+ "specify version requirements (#{name})."
125
+ end
126
+ end
127
+ end
128
+ if requirements.length == 1 && requirements.first.is_a?(Requirement)
129
+ requirements = requirements.first
130
+ end
58
131
  @name = name
59
132
  @requirement = Requirement.create(requirements)
133
+ @specific_requirement ||= nil
134
+ @external_source ||= nil
135
+ end
136
+ def requirement
137
+ @specific_requirement || @requirement
138
+ end
139
+ def specific_version
140
+ @specific_version
141
+ end
142
+ def specific_version=(version)
143
+ @specific_version = version
144
+ @specific_requirement = Requirement.new(version)
145
+ end
146
+ def root_name
147
+ Specification.root_name(name)
148
+ end
149
+ def prerelease?
150
+ requirement.prerelease?
151
+ end
152
+ def external?
153
+ !@external_source.nil?
154
+ end
155
+ def local?
156
+ external_source[:path] if external_source
157
+ end
158
+ def to_root_dependency
159
+ dep = dup
160
+ dep.name = root_name
161
+ dep
162
+ end
163
+ def ==(other)
164
+ other.is_a?(Dependency) && name == other.name && external_source == other.external_source &&
165
+ podspec_repo == other.podspec_repo && requirement == other.requirement
166
+ end
167
+ alias_method :eql?, :==
168
+ def hash
169
+ name.hash ^ requirement.to_s.hash ^ external_source.hash
170
+ end
171
+ def <=>(other)
172
+ name <=> other.name
173
+ end
174
+ def to_s
175
+ version = ''
176
+ if external?
177
+ version += external_source_description(external_source)
178
+ elsif requirement != Requirement.default
179
+ version += requirement.to_s
180
+ end
181
+ result = name.dup
182
+ result += " (#{version})" unless version.empty?
183
+ result
184
+ end
185
+ def inspect
186
+ "<#{self.class} name=#{name} requirements=#{requirement} source=#{podspec_repo || 'nil'} external_source=#{external_source || 'nil'}>"
187
+ end
188
+ private
189
+ def external_source_description(source)
190
+ if source.key?(:git)
191
+ desc = "\`#{source[:git]}\`"
192
+ desc << ", commit \`#{source[:commit]}\`" if source[:commit]
193
+ desc << ", branch \`#{source[:branch]}\`" if source[:branch]
194
+ desc << ", tag \`#{source[:tag]}\`" if source[:tag]
195
+ elsif source.key?(:hg)
196
+ desc = "\`#{source[:hg]}\`"
197
+ elsif source.key?(:svn)
198
+ desc = "\`#{source[:svn]}\`"
199
+ elsif source.key?(:podspec)
200
+ desc = "\`#{source[:podspec]}\`"
201
+ elsif source.key?(:path)
202
+ desc = "\`#{source[:path]}\`"
203
+ else
204
+ desc = "\`#{source}\`"
205
+ end
206
+ "from #{desc}"
60
207
  end
61
208
  end
62
209
 
@@ -72,16 +219,55 @@ module Pod
72
219
  def to_sym
73
220
  name
74
221
  end
222
+ def self.string_name(symbolic_name)
223
+ case symbolic_name
224
+ when :ios then 'iOS'
225
+ when :osx then 'macOS'
226
+ when :watchos then 'watchOS'
227
+ when :tvos then 'tvOS'
228
+ when :visionos then 'visionOS'
229
+ else symbolic_name.to_s
230
+ end
231
+ end
232
+ def string_name
233
+ self.class.string_name(name)
234
+ end
235
+ def safe_string_name
236
+ string_name.tr(' ', '')
237
+ end
75
238
  def to_s
76
- name.to_s
239
+ s = self.class.string_name(name)
240
+ s += " #{deployment_target}" if deployment_target
241
+ s
242
+ end
243
+ def inspect
244
+ "#<#{self.class.name} name=#{name.inspect} deployment_target=#{deployment_target.to_s.inspect}>"
245
+ end
246
+ def hash
247
+ name.hash ^ deployment_target.hash
248
+ end
249
+ def eql?(other)
250
+ self == other
251
+ end
252
+ def supports?(other)
253
+ other = Platform.new(other) unless other.is_a?(Platform)
254
+ if other.deployment_target && deployment_target
255
+ (other.name == name) && (deployment_target >= other.deployment_target)
256
+ else
257
+ other.name == name
258
+ end
77
259
  end
78
260
  end
79
261
 
80
262
  class Config
81
263
  attr_accessor :installation_root, :podfile, :lockfile
264
+ alias_method :project_root, :installation_root
82
265
  def self.instance
83
266
  @instance ||= new
84
267
  end
268
+ def podfile_path
269
+ installation_root + 'Podfile'
270
+ end
85
271
  def sandbox_root
86
272
  installation_root + 'Pods'
87
273
  end
@@ -409,7 +595,7 @@ module Pod
409
595
  end
410
596
 
411
597
  def to_s
412
- specified_version = attributes_hash['version'] || ''
598
+ specified_version = root.attributes_hash['version'] || ''
413
599
  if name && !specified_version.to_s.empty?
414
600
  "#{name} (#{specified_version})"
415
601
  elsif name
@@ -798,109 +984,116 @@ function reactNativeScripts(app: string): string | null {
798
984
  return fs.existsSync(scripts) ? scripts : null
799
985
  }
800
986
 
987
+ type Host = Record<string, string | undefined>
988
+
989
+ // the toolchain and host a script probes are the ones Peach compiles against,
990
+ // on the arm64 darwin RUBY_PLATFORM the interpreter reports
991
+ const HOST_PROBES = new Map([
992
+ ['xcrun --sdk iphoneos --show-sdk-version', `${NATIVE_GRAPH_SDK_VERSION}\n`],
993
+ ['xcrun --sdk iphonesimulator --show-sdk-version', `${NATIVE_GRAPH_SDK_VERSION}\n`],
994
+ ['xcodebuild -version', `Xcode ${NATIVE_GRAPH_SDK_VERSION}\n`],
995
+ ['/usr/sbin/sysctl -n hw.optional.arm64 2>&1', '1\n'],
996
+ ])
997
+
801
998
  /**
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.
999
+ * an interpreter with cocoapods-core's Pod module and React Native's pod
1000
+ * helpers loaded for `app`, with `env` as ENV. evaluated Ruby may write only
1001
+ * inside `writable`.
805
1002
  */
806
- export function evaluatePodspec(
807
- file: string,
1003
+ export function cocoapodsInterpreter(
808
1004
  app: string,
809
- writable: string,
810
- env: Record<string, string | undefined>,
811
- ): unknown {
1005
+ writable: readonly string[],
1006
+ env: Host,
1007
+ ): { interp: Interpreter; pod: RModule } {
812
1008
  const interp = new Interpreter({
813
1009
  cwd: app,
814
1010
  env: new Map(
815
1011
  Object.entries(env).flatMap(([k, v]) => (v === undefined ? [] : [[k, v]])),
816
1012
  ),
817
- shell: (command, cwd) => nodeShell(command, cwd, interp.host.env),
1013
+ shell: (command, cwd) => {
1014
+ const probe = HOST_PROBES.get(command.trim())
1015
+ return probe === undefined
1016
+ ? nodeShell(command, cwd, interp.host.env, interp.host.writable)
1017
+ : { stdout: probe, status: 0 }
1018
+ },
818
1019
  loaded: new Set(),
819
- writable: [writable],
1020
+ writable: [...writable],
820
1021
  })
821
1022
  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
- },
1023
+ interp.evalString(PRELUDE, 'cocoapods-core')
1024
+ const pod = interp.object.consts.get('Pod')
1025
+ if (!(pod instanceof RModule)) throw new Error('the Pod prelude defines no Pod module')
1026
+ const call = (receiver: Value, name: string, args: Value[] = []) =>
1027
+ interp.callMethod(receiver, name, args, null, null, null, null)
1028
+ const executable = interp.defineModule('Executable', pod)
1029
+ interp.defineNative(
1030
+ executable,
1031
+ 'execute_command',
1032
+ (c) => {
1033
+ const [name, args] = c.args
1034
+ if (!(name instanceof RString) || name.s !== 'node' || !Array.isArray(args))
1035
+ throw new UnsupportedRuby(
1036
+ `Pod::Executable.execute_command(${c.args.map((a) => interp.toS(a)).join(', ')})`,
845
1037
  )
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,
1038
+ const result = spawnSync(
1039
+ 'node',
1040
+ args.map((a) => interp.toS(a)),
1041
+ { cwd: interp.host.cwd, env: childEnv(interp.host.env), encoding: 'utf8' },
901
1042
  )
902
- spec = interp.callMethod(specification, 'from_hash', [hash], null, null, null, null)
903
- } else {
1043
+ if (result.status !== 0 && c.args[2] !== false)
1044
+ return interp.raise(
1045
+ 'Pod::Informative',
1046
+ `node ${args.map((a) => interp.toS(a)).join(' ')}\n\n${result.stdout}${result.stderr}`,
1047
+ )
1048
+ return str(result.stdout ?? '')
1049
+ },
1050
+ true,
1051
+ )
1052
+ interp.defineNative(
1053
+ executable,
1054
+ 'capture_command',
1055
+ (c) => {
1056
+ const [name, args] = c.args
1057
+ const capture = c.kw?.get(sym('capture'))
1058
+ const mode = capture instanceof RSymbol ? capture.name : 'merge'
1059
+ if (!(name instanceof RString) || name.s !== 'node' || !Array.isArray(args))
1060
+ throw new UnsupportedRuby(
1061
+ `Pod::Executable.capture_command(${c.args.map((a) => interp.toS(a)).join(', ')})`,
1062
+ )
1063
+ const result = spawnSync(
1064
+ 'node',
1065
+ args.map((a) => interp.toS(a)),
1066
+ { cwd: interp.host.cwd, env: childEnv(interp.host.env), encoding: 'utf8' },
1067
+ )
1068
+ const status = new RObject(interp.classes.ProcessStatus!)
1069
+ status.data = result.status ?? 1
1070
+ const out = str(result.stdout ?? '')
1071
+ const err = str(result.stderr ?? '')
1072
+ if (mode === 'merge')
1073
+ return [str(`${result.stdout ?? ''}${result.stderr ?? ''}`), status]
1074
+ if (mode === 'both') return [out, err, status]
1075
+ if (mode === 'out') return [out, status]
1076
+ if (mode === 'err') return [err, status]
1077
+ return status
1078
+ },
1079
+ true,
1080
+ )
1081
+ const version = pod.consts.get('Version')
1082
+ if (version instanceof RModule) defineVersionClass(interp, version)
1083
+ const specification = interp.constIn(pod, 'Specification', null, '-')
1084
+ if (!(specification instanceof RModule)) throw new Error('no Pod::Specification')
1085
+ // Specification.from_file: a podspec evaluates with Pod as self, in its own directory.
1086
+ interp.defineNative(
1087
+ specification,
1088
+ 'from_file',
1089
+ (c) => {
1090
+ const file = path.resolve(interp.host.cwd, interp.toS(c.args[0] ?? null))
1091
+ const source = fs.readFileSync(file, 'utf8')
1092
+ if (file.endsWith('.json'))
1093
+ return call(specification, 'from_hash', [
1094
+ call(interp.object.consts.get('JSON') ?? null, 'parse', [str(source)]),
1095
+ ])
1096
+ const cwd = interp.host.cwd
904
1097
  interp.host.cwd = path.dirname(file)
905
1098
  const frame: Frame = {
906
1099
  ...interp.topFrame,
@@ -910,18 +1103,28 @@ export function evaluatePodspec(
910
1103
  file,
911
1104
  id: {},
912
1105
  }
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
- )
1106
+ const spec = interp.evalString(source, file, frame)
1107
+ interp.host.cwd = cwd
1108
+ if (!(spec instanceof RObject) || !interp.isA(spec, specification))
1109
+ throw new PodspecEvaluationError(`Invalid podspec file at path \`${file}\`.`)
1110
+ return spec
1111
+ },
1112
+ true,
1113
+ )
1114
+ const scripts = reactNativeScripts(app)
1115
+ if (scripts) requireFile(interp, 'require', scripts, null)
1116
+ const pathname = interp.object.consts.get('Pathname')
1117
+ if (!(pathname instanceof RModule)) throw new Error('no Pathname')
1118
+ call(call(interp.constIn(pod, 'Config', null, '-'), 'instance'), 'installation_root=', [
1119
+ call(pathname, 'new', [str(path.join(app, 'ios'))]),
1120
+ ])
1121
+ return { interp, pod }
1122
+ }
1123
+
1124
+ /** runs `body`, reporting Ruby failures against `file`. */
1125
+ export function rubyFailures<T>(file: string, body: () => T): T {
1126
+ try {
1127
+ return body()
925
1128
  } catch (error) {
926
1129
  if (error instanceof RubyError)
927
1130
  throw new PodspecEvaluationError(`${file}: ${error.message}`)
@@ -932,3 +1135,25 @@ export function evaluatePodspec(
932
1135
  throw error
933
1136
  }
934
1137
  }
1138
+
1139
+ /**
1140
+ * CocoaPods' evaluated attributes for the podspec (or `.podspec.json`) at
1141
+ * `file`, evaluated in `app`'s context with `env` as ENV. the podspec may
1142
+ * write only inside `writable`, its package.
1143
+ */
1144
+ export function evaluatePodspec(
1145
+ file: string,
1146
+ app: string,
1147
+ writable: string,
1148
+ env: Host,
1149
+ ): unknown {
1150
+ return rubyFailures(file, () => {
1151
+ const { interp, pod } = cocoapodsInterpreter(app, [writable], env)
1152
+ const call = (receiver: Value, name: string, args: Value[] = []) =>
1153
+ interp.callMethod(receiver, name, args, null, null, null, null)
1154
+ const spec = call(interp.constIn(pod, 'Specification', null, '-'), 'from_file', [
1155
+ str(file),
1156
+ ])
1157
+ return toJson(interp, call(pod, 'peach_evaluated', [spec]))
1158
+ })
1159
+ }