88 getLoader ,
99} from '@react-native-community/cli-tools' ;
1010import installPods from './installPods' ;
11- import findPodfilePath from '../config/findPodfilePath' ;
1211import {
1312 DependencyConfig ,
1413 IOSDependencyConfig ,
@@ -61,7 +60,7 @@ export function generateMd5Hash(text: string) {
6160 return createHash ( 'md5' ) . update ( text ) . digest ( 'hex' ) ;
6261}
6362
64- export function compareMd5Hashes ( hash1 : string , hash2 : string ) {
63+ export function compareMd5Hashes ( hash1 ? : string , hash2 ? : string ) {
6564 return hash1 === hash2 ;
6665}
6766
@@ -91,12 +90,15 @@ async function install(
9190
9291export default async function resolvePods (
9392 root : string ,
93+ sourceDir : string ,
9494 nativeDependencies : NativeDependencies ,
9595 platformName : ApplePlatform ,
9696 options ?: ResolvePodsOptions ,
9797) {
9898 const packageJson = getPackageJson ( root ) ;
99- const podfilePath = findPodfilePath ( root , platformName ) ;
99+ const podfilePath = path . join ( sourceDir , 'Podfile' ) ; // sourceDir is calculated based on Podfile location, see getProjectConfig()
100+
101+ const podfileLockPath = path . join ( sourceDir , 'Podfile.lock' ) ;
100102 const platformFolderPath = podfilePath
101103 ? podfilePath . slice ( 0 , podfilePath . lastIndexOf ( '/' ) )
102104 : path . join ( root , platformName ) ;
@@ -108,23 +110,44 @@ export default async function resolvePods(
108110 ) ;
109111 const dependenciesString = dependenciesToString ( platformDependencies ) ;
110112 const currentDependenciesHash = generateMd5Hash ( dependenciesString ) ;
113+ // Users can manually add dependencies to Podfile, so we can entirely rely on `dependencies` from `config`'s output.
114+ const currentPodfileHash = fs . existsSync ( podfilePath )
115+ ? generateMd5Hash ( fs . readFileSync ( podfilePath , 'utf8' ) )
116+ : undefined ;
117+ const currentPodfileLockHash = fs . existsSync ( podfileLockPath )
118+ ? generateMd5Hash ( fs . readFileSync ( podfileLockPath , 'utf8' ) )
119+ : undefined ;
120+
121+ const cachedPodfileHash = cacheManager . get ( packageJson . name , 'podfile' ) ;
122+ const cachedPodfileLockHash = cacheManager . get (
123+ packageJson . name ,
124+ 'podfileLock' ,
125+ ) ;
126+
111127 const cachedDependenciesHash = cacheManager . get (
112128 packageJson . name ,
113129 'dependencies' ,
114130 ) ;
115131
132+ const isCacheValid =
133+ cachedDependenciesHash === undefined &&
134+ cachedPodfileHash === undefined &&
135+ cachedPodfileLockHash === undefined ;
136+
116137 if ( options ?. forceInstall ) {
117138 await install (
118139 packageJson ,
119140 cachedDependenciesHash ,
120141 currentDependenciesHash ,
121142 platformFolderPath ,
122143 ) ;
123- } else if ( arePodsInstalled && cachedDependenciesHash === undefined ) {
144+ } else if ( arePodsInstalled && isCacheValid ) {
124145 cacheManager . set ( packageJson . name , 'dependencies' , currentDependenciesHash ) ;
125146 } else if (
126- ! cachedDependenciesHash ||
147+ ! isCacheValid ||
127148 ! compareMd5Hashes ( currentDependenciesHash , cachedDependenciesHash ) ||
149+ ! compareMd5Hashes ( currentPodfileHash , cachedPodfileHash ) ||
150+ ! compareMd5Hashes ( currentPodfileLockHash , cachedPodfileLockHash ) ||
128151 ! arePodsInstalled
129152 ) {
130153 const loader = getLoader ( 'Installing CocoaPods...' ) ;
0 commit comments