8
8
getLoader ,
9
9
} from '@react-native-community/cli-tools' ;
10
10
import installPods from './installPods' ;
11
- import findPodfilePath from '../config/findPodfilePath' ;
12
11
import {
13
12
DependencyConfig ,
14
13
IOSDependencyConfig ,
@@ -61,7 +60,7 @@ export function generateMd5Hash(text: string) {
61
60
return createHash ( 'md5' ) . update ( text ) . digest ( 'hex' ) ;
62
61
}
63
62
64
- export function compareMd5Hashes ( hash1 : string , hash2 : string ) {
63
+ export function compareMd5Hashes ( hash1 ? : string , hash2 ? : string ) {
65
64
return hash1 === hash2 ;
66
65
}
67
66
@@ -91,12 +90,15 @@ async function install(
91
90
92
91
export default async function resolvePods (
93
92
root : string ,
93
+ sourceDir : string ,
94
94
nativeDependencies : NativeDependencies ,
95
95
platformName : ApplePlatform ,
96
96
options ?: ResolvePodsOptions ,
97
97
) {
98
98
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' ) ;
100
102
const platformFolderPath = podfilePath
101
103
? podfilePath . slice ( 0 , podfilePath . lastIndexOf ( '/' ) )
102
104
: path . join ( root , platformName ) ;
@@ -108,23 +110,44 @@ export default async function resolvePods(
108
110
) ;
109
111
const dependenciesString = dependenciesToString ( platformDependencies ) ;
110
112
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
+
111
127
const cachedDependenciesHash = cacheManager . get (
112
128
packageJson . name ,
113
129
'dependencies' ,
114
130
) ;
115
131
132
+ const isCacheValid =
133
+ cachedDependenciesHash === undefined &&
134
+ cachedPodfileHash === undefined &&
135
+ cachedPodfileLockHash === undefined ;
136
+
116
137
if ( options ?. forceInstall ) {
117
138
await install (
118
139
packageJson ,
119
140
cachedDependenciesHash ,
120
141
currentDependenciesHash ,
121
142
platformFolderPath ,
122
143
) ;
123
- } else if ( arePodsInstalled && cachedDependenciesHash === undefined ) {
144
+ } else if ( arePodsInstalled && isCacheValid ) {
124
145
cacheManager . set ( packageJson . name , 'dependencies' , currentDependenciesHash ) ;
125
146
} else if (
126
- ! cachedDependenciesHash ||
147
+ ! isCacheValid ||
127
148
! compareMd5Hashes ( currentDependenciesHash , cachedDependenciesHash ) ||
149
+ ! compareMd5Hashes ( currentPodfileHash , cachedPodfileHash ) ||
150
+ ! compareMd5Hashes ( currentPodfileLockHash , cachedPodfileLockHash ) ||
128
151
! arePodsInstalled
129
152
) {
130
153
const loader = getLoader ( 'Installing CocoaPods...' ) ;
0 commit comments