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,6 +110,20 @@ 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't entirely rely on `dependencies` from `config`'s output.
114
+ const currentPodfileHash = generateMd5Hash (
115
+ fs . readFileSync ( podfilePath , 'utf8' ) ,
116
+ ) ;
117
+ const currentPodfileLockHash = generateMd5Hash (
118
+ fs . readFileSync ( podfileLockPath , 'utf8' ) ,
119
+ ) ;
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' ,
@@ -120,13 +136,17 @@ export default async function resolvePods(
120
136
currentDependenciesHash ,
121
137
platformFolderPath ,
122
138
) ;
123
- } else if ( arePodsInstalled && cachedDependenciesHash === undefined ) {
124
- cacheManager . set ( packageJson . name , 'dependencies' , currentDependenciesHash ) ;
125
139
} else if (
126
- ! cachedDependenciesHash ||
127
- ! compareMd5Hashes ( currentDependenciesHash , cachedDependenciesHash ) ||
128
- ! arePodsInstalled
140
+ arePodsInstalled &&
141
+ compareMd5Hashes ( currentDependenciesHash , cachedDependenciesHash ) &&
142
+ compareMd5Hashes ( currentPodfileHash , cachedPodfileHash ) &&
143
+ compareMd5Hashes ( currentPodfileLockHash , cachedPodfileLockHash )
129
144
) {
145
+ cacheManager . set ( packageJson . name , 'dependencies' , currentDependenciesHash ) ;
146
+ cacheManager . set ( packageJson . name , 'podfile' , currentPodfileHash ) ;
147
+ cacheManager . set ( packageJson . name , 'podfileLock' , currentPodfileLockHash ) ;
148
+ } else {
149
+ console . log ( 'eh' ) ;
130
150
const loader = getLoader ( 'Installing CocoaPods...' ) ;
131
151
try {
132
152
await installPods ( loader , {
@@ -139,6 +159,8 @@ export default async function resolvePods(
139
159
'dependencies' ,
140
160
currentDependenciesHash ,
141
161
) ;
162
+ cacheManager . set ( packageJson . name , 'podfile' , currentPodfileHash ) ;
163
+ cacheManager . set ( packageJson . name , 'podfileLock' , currentPodfileLockHash ) ;
142
164
loader . succeed ( ) ;
143
165
} catch {
144
166
loader . fail ( ) ;
0 commit comments