@@ -12,6 +12,7 @@ import {
1212 spinner ,
1313} from '@rnef/tools' ;
1414import type { ApplePlatform } from '../types/index.js' ;
15+ import runCodegen from './codegen.js' ;
1516
1617const podErrorHelpMessage = `Please make sure your environment is correctly set up.
1718Learn more at: ${ color . dim ( 'https://cocoapods.org/' ) }
@@ -21,7 +22,8 @@ export async function installPodsIfNeeded(
2122 projectRoot : string ,
2223 platformName : ApplePlatform ,
2324 sourceDir : string ,
24- newArch : boolean
25+ newArch : boolean ,
26+ reactNativePath : string
2527) {
2628 const podsPath = path . join ( sourceDir , 'Pods' ) ;
2729 const podfilePath = path . join ( sourceDir , 'Podfile' ) ;
@@ -40,6 +42,7 @@ export async function installPodsIfNeeded(
4042 : true ;
4143
4244 if ( ! podsDirExists || hashChanged ) {
45+ await runCodegen ( { projectRoot, platformName, reactNativePath } ) ;
4346 await installPods ( { projectRoot, sourceDir, podfilePath, newArch } ) ;
4447 cacheManager . set (
4548 cacheKey ,
@@ -64,7 +67,8 @@ const calculateCurrentHash = ({
6467 podfile = fs . readFileSync ( podfilePath , 'utf-8' ) ;
6568 } catch {
6669 throw new RnefError (
67- `No Podfile found at: ${ podfilePath } . ${ podErrorHelpMessage } `
70+ `No Podfile found at: ${ podfilePath } .
71+ ${ podErrorHelpMessage } `
6872 ) ;
6973 }
7074
@@ -104,7 +108,6 @@ async function runPodInstall(options: {
104108
105109 const command = options . useBundler ? 'bundle' : 'pod' ;
106110 const args = options . useBundler ? [ 'exec' , 'pod' , 'install' ] : [ 'install' ] ;
107-
108111 try {
109112 await spawn ( command , args , {
110113 env : {
@@ -117,8 +120,9 @@ async function runPodInstall(options: {
117120 cwd : options . sourceDir ,
118121 } ) ;
119122 } catch ( error ) {
120- const stderr = ( error as SubprocessError ) . stderr ;
121-
123+ loader . stop ( 'Failed: Installing CocoaPods dependencies' , 1 ) ;
124+ const stderr =
125+ ( error as SubprocessError ) . stderr || ( error as SubprocessError ) . output ;
122126 /**
123127 * If CocoaPods failed due to repo being out of date, it will
124128 * include the update command in the error message.
@@ -135,26 +139,15 @@ async function runPodInstall(options: {
135139 useBundler : options . useBundler ,
136140 } ) ;
137141 } else {
138- if ( options . useBundler ) {
139- // If for any reason the installing with bundler failed, try with pure `pod install`
140- await runPodInstall ( {
141- shouldHandleRepoUpdate : false ,
142- sourceDir : options . sourceDir ,
143- newArch : options . newArch ,
144- useBundler : false ,
145- } ) ;
146- } else {
147- loader . stop ( 'CocoaPods installation failed. ' , 1 ) ;
148-
149- throw new RnefError (
150- `CocoaPods installation failed. ${ podErrorHelpMessage } ` ,
151- { cause : stderr }
152- ) ;
153- }
142+ throw new RnefError (
143+ `CocoaPods installation failed.
144+ ${ podErrorHelpMessage } `,
145+ { cause : stderr }
146+ ) ;
154147 }
155148 }
156149
157- loader . stop ( 'CocoaPods installed successfully. ' ) ;
150+ loader . stop ( 'Installed CocoaPods dependencies successfully' ) ;
158151}
159152
160153async function runPodUpdate ( cwd : string , useBundler : boolean ) {
@@ -169,10 +162,11 @@ async function runPodUpdate(cwd: string, useBundler: boolean) {
169162 } catch ( error ) {
170163 const stderr =
171164 ( error as SubprocessError ) . stderr || ( error as SubprocessError ) . stdout ;
172- loader . stop ( ) ;
165+ loader . stop ( 'Failed: Updating CocoaPods repositories' , 1 ) ;
173166
174167 throw new RnefError (
175- `Failed to update CocoaPods repositories for iOS project. ${ podErrorHelpMessage } ` ,
168+ `Failed to update CocoaPods repositories for iOS project.
169+ ${ podErrorHelpMessage } `,
176170 { cause : stderr }
177171 ) ;
178172 }
@@ -194,6 +188,9 @@ async function installPods(options: {
194188 options . sourceDir ,
195189 options . projectRoot
196190 ) ;
191+ if ( ! useBundler ) {
192+ logger . info ( 'Unable to use Ruby bundler, falling back to "pod install"' ) ;
193+ }
197194 await runPodInstall ( {
198195 sourceDir : options . sourceDir ,
199196 newArch : options . newArch ,
@@ -210,10 +207,18 @@ async function validatePodCommand(sourceDir: string) {
210207 try {
211208 await spawn ( 'pod' , [ '--version' ] , { cwd : sourceDir } ) ;
212209 } catch ( error ) {
210+ const cause = ( error as SubprocessError ) . cause ;
211+ if ( cause instanceof Error && cause . message . includes ( 'ENOENT' ) ) {
212+ throw new RnefError (
213+ `The "pod" command is not available.
214+ ${ podErrorHelpMessage } `
215+ ) ;
216+ }
213217 const stderr =
214218 ( error as SubprocessError ) . stderr || ( error as SubprocessError ) . stdout ;
215219 throw new RnefError (
216- `CocoaPods "pod" command failed. ${ podErrorHelpMessage } ` ,
220+ `CocoaPods "pod" command failed.
221+ ${ podErrorHelpMessage } `,
217222 { cause : stderr }
218223 ) ;
219224 }
@@ -260,14 +265,15 @@ skipping Ruby Gems installation.`
260265 } catch ( error ) {
261266 const stderr =
262267 ( error as SubprocessError ) . stderr || ( error as SubprocessError ) . stdout ;
263- loader . stop ( 'Ruby Gems installation failed. ' , 1 ) ;
268+ loader . stop ( 'Failed: Installing Ruby Gems ' , 1 ) ;
264269 throw new RnefError (
265- `Failed to install Ruby Gems with "bundle install". ${ podErrorHelpMessage } ` ,
270+ `Failed to install Ruby Gems with "bundle install".
271+ ${ podErrorHelpMessage } `,
266272 { cause : stderr }
267273 ) ;
268274 }
269275
270- loader . stop ( 'Installed Ruby Gems. ' ) ;
276+ loader . stop ( 'Installed Ruby Gems' ) ;
271277 return true ;
272278}
273279
0 commit comments