@@ -21,13 +21,16 @@ if (enableHermes === null) {
2121 throw new Error ( 'Invalid engine' ) ;
2222}
2323
24+ // Optional iOS version argument, defaults to '15.1' due to Cocoa SDK V9 and RN 0.81.0 requirement
25+ const iosVersion = args [ 'ios-version' ] || '15.1' ;
26+
2427debug . log ( 'Patching Podfile' , args [ 'pod-file' ] ) ;
25- const content = fs . readFileSync ( args [ 'pod-file' ] , 'utf8' ) ;
28+ let content = fs . readFileSync ( args [ 'pod-file' ] , 'utf8' ) ;
2629
2730const isHermesEnabled = content . includes ( ':hermes_enabled => true,' ) ;
2831const shouldPatch = enableHermes !== isHermesEnabled ;
2932if ( shouldPatch ) {
30- const patched = content . replace (
33+ content = content . replace (
3134 / : h e r m e s _ e n a b l e d .* / ,
3235 enableHermes ? ':hermes_enabled => true,' : ':hermes_enabled => false,' ,
3336 ) ;
@@ -36,7 +39,34 @@ if (shouldPatch) {
3639 } else {
3740 debug . log ( 'Patching Podfile for JSC' ) ;
3841 }
39- fs . writeFileSync ( args [ 'pod-file' ] , patched ) ;
42+ }
43+
44+ // Patch iOS version
45+ const platformPattern = / p l a t f o r m : i o s , ( m i n _ i o s _ v e r s i o n _ s u p p o r t e d | [ ' " ] [ 0 - 9 . ] + [ ' " ] ) / ;
46+ const currentMatch = content . match ( platformPattern ) ;
47+
48+ if ( currentMatch ) {
49+ const currentValue = currentMatch [ 1 ] ;
50+ const shouldPatchVersion = currentValue === 'min_ios_version_supported' ||
51+ currentValue !== `'${ iosVersion } '` ;
52+
53+ if ( shouldPatchVersion ) {
54+ content = content . replace (
55+ platformPattern ,
56+ `platform :ios, '${ iosVersion } '`
57+ ) ;
58+ debug . log ( `Patching iOS version to ${ iosVersion } (was: ${ currentValue } )` ) ;
59+ } else {
60+ debug . log ( `iOS version already set to ${ iosVersion } ` ) ;
61+ }
62+ } else {
63+ debug . log ( 'Warning: Could not find platform :ios line to patch' ) ;
64+ }
65+
66+ // Write the file if any changes were made
67+ if ( shouldPatch || currentMatch ) {
68+ fs . writeFileSync ( args [ 'pod-file' ] , content ) ;
69+ debug . log ( 'Podfile patched successfully!' ) ;
4070} else {
4171 debug . log ( 'Podfile is already patched!' ) ;
4272}
0 commit comments