@@ -9,32 +9,74 @@ podspec_dir = File.dirname(__FILE__)
99Pod ::Spec . new do |s |
1010
1111 is_expo_in_podfile = false
12- is_version_sufficient = false
1312 begin
1413 # Check Podfile for use_expo_modules!
1514 podfile_path = File . join ( Pod ::Config . instance . installation_root , 'Podfile' )
1615 if File . exist? ( podfile_path )
1716 podfile_content = File . read ( podfile_path )
1817 is_expo_in_podfile = podfile_content . include? ( 'use_expo_modules!' )
1918 end
20- # Check root package.json for Expo version >= 50
21- root_package_json_path = File . join ( podspec_dir , '..' , '..' , 'package.json' )
22- if File . exist? ( root_package_json_path )
23- pkg_json = JSON . parse ( File . read ( root_package_json_path ) )
24- expo_version_string = pkg_json [ 'dependencies' ] &.[]( 'expo' ) || pkg_json [ 'devDependencies' ] &.[]( 'expo' )
25- if expo_version_string
26- match = expo_version_string . match ( /\d +/ )
19+ rescue => e
20+ # Silently ignore errors during check
21+ end
22+
23+ # Determine final validity by checking Podfile presence AND Expo version
24+ valid_expo_project = false # Default
25+ if is_expo_in_podfile
26+ # Only check expo version if use_expo_modules! is present
27+ is_version_sufficient = false
28+ begin
29+ expo_version_str = `node --print \" require('expo/package.json').version\" ` . strip
30+ if expo_version_str && !expo_version_str . empty?
31+ match = expo_version_str . match ( /^\d +/ )
2732 if match
2833 major_version = match [ 0 ] . to_i
2934 is_version_sufficient = major_version >= 50
3035 end
3136 end
37+ rescue
38+ # Node command failed, version remains insufficient
3239 end
33- rescue => e
34- # Silently ignore errors during check
40+
41+ # Final check
42+ valid_expo_project = is_version_sufficient
3543 end
36- # Determine final validity
37- valid_expo_project = is_expo_in_podfile && is_version_sufficient
44+
45+ # Set platform based on whether it's a valid Expo project and if we can parse its target
46+ final_ios_deployment_target = '11.0' # Default target
47+
48+ if valid_expo_project
49+ # --- Try to find and parse ExpoModulesCore.podspec only if it's an Expo project ---
50+ parsed_expo_ios_target = nil
51+ expo_modules_core_podspec_path = begin
52+ package_json_path = `node -p "require.resolve('expo-modules-core/package.json')"` . strip
53+ File . join ( File . dirname ( package_json_path ) , 'ExpoModulesCore.podspec' ) if $?. success? && package_json_path && !package_json_path . empty?
54+ rescue
55+ nil
56+ end
57+
58+ if expo_modules_core_podspec_path && File . exist? ( expo_modules_core_podspec_path )
59+ begin
60+ content = File . read ( expo_modules_core_podspec_path )
61+ match = content . match ( /s\. platforms\s *=\s *\{ [\s \S ]*?:ios\s *=>\s *'([^\' ]+)'/ ) # Match within s.platforms hash
62+ if match && match [ 1 ]
63+ parsed_expo_ios_target = match [ 1 ]
64+ else
65+ match = content . match ( /s\. platform\s *=\s *:ios,\s *'([^\' ]+)'/ ) # Fallback to s.platform = :ios, 'version'
66+ if match && match [ 1 ]
67+ parsed_expo_ios_target = match [ 1 ]
68+ end
69+ end
70+ rescue => e
71+ # Pod::UI.warn "Failed to read or parse ExpoModulesCore.podspec content: #{e.message}"
72+ end
73+ end
74+ if parsed_expo_ios_target
75+ final_ios_deployment_target = parsed_expo_ios_target
76+ end
77+ end
78+
79+ s . platforms = { :ios => final_ios_deployment_target }
3880
3981 s . name = package [ 'name' ]
4082 s . version = package [ 'version' ]
@@ -45,8 +87,7 @@ Pod::Spec.new do |s|
4587 s . homepage = package [ 'homepage' ]
4688
4789 s . cocoapods_version = '>= 1.6.0'
48- # s.platform = :ios, "8.0"
49- # s.platforms = { :ios => "11.0" }
90+
5091 s . source = { :git => 'https://github.com/reactnativecn/react-native-update.git' , :tag => '#{s.version}' }
5192
5293 # Conditionally set source files
@@ -92,20 +133,26 @@ Pod::Spec.new do |s|
92133 # Conditionally add Expo subspec and check ExpoModulesCore version
93134 if valid_expo_project
94135 supports_bundle_url_final = false # Default
95- begin
96- # Check installed ExpoModulesCore version for bundle URL support
97- expo_core_package_json_path = File . join ( podspec_dir , '..' , 'expo-modules-core' , 'package.json' )
98- if File . exist? ( expo_core_package_json_path )
99- core_package_json = JSON . parse ( File . read ( expo_core_package_json_path ) )
100- installed_version_str = core_package_json [ 'version' ]
101- if installed_version_str
102- installed_version = Gem ::Version . new ( installed_version_str )
136+
137+ # 1. Try executing node to get the version string
138+ expo_modules_core_version_str = begin
139+ # Use node to directly require expo-modules-core/package.json and get its version
140+ `node --print \" require('expo-modules-core/package.json').version\" ` # Execute, keep raw output
141+ rescue
142+ # Node command failed (e.g., node not found, package not found). Return empty string.
143+ ''
144+ end
145+
146+ # 2. Process the obtained version string (if not empty)
147+ if expo_modules_core_version_str && !expo_modules_core_version_str . empty?
148+ begin
149+ # Compare versions using Gem::Version (handles trailing newline)
150+ installed_version = Gem ::Version . new ( expo_modules_core_version_str )
103151 target_version = Gem ::Version . new ( '1.12.0' )
104152 supports_bundle_url_final = installed_version >= target_version
105- end
106- end
107- rescue JSON ::ParserError , Errno ::ENOENT , ArgumentError , StandardError => e
108- # Pod::UI.warn "Could not check ExpoModulesCore version: #{e.message}"
153+ rescue ArgumentError
154+ # If Gem::Version fails parsing, supports_bundle_url_final remains false.
155+ end
109156 end
110157
111158 s . subspec 'Expo' do |ss |
0 commit comments