@@ -18,7 +18,10 @@ export function addFrameworkTarget(
1818 project : XcodeProject ,
1919 modRequest : ModProps < XcodeProject > ,
2020 options : ResolvedBrownfieldPluginIosConfig
21- ) : string | null {
21+ ) : {
22+ frameworkTargetUUID : string ;
23+ targetAlreadyExists : boolean ;
24+ } {
2225 const { frameworkName, bundleIdentifier } = options ;
2326
2427 // check if target already exists
@@ -28,7 +31,23 @@ export function addFrameworkTarget(
2831 `Framework target "${ frameworkName } " already exists, skipping creation`
2932 ) ;
3033
31- return null ;
34+ const frameworkTargetUUID = Object . entries (
35+ project . pbxNativeTargetSection ( )
36+ ) . find (
37+ ( [ _key , value ] ) =>
38+ ( value as any ) ?. productReference === existingTarget . productReference
39+ ) ?. [ 0 ] ;
40+
41+ if ( ! frameworkTargetUUID ) {
42+ throw new SourceModificationError (
43+ `Failed to find framework target UUID for ${ frameworkName } , although it can be resolved by name`
44+ ) ;
45+ }
46+
47+ return {
48+ frameworkTargetUUID,
49+ targetAlreadyExists : true ,
50+ } ;
3251 }
3352
3453 Logger . logDebug ( `Adding iOS framework target: ${ frameworkName } ` ) ;
@@ -130,7 +149,10 @@ export function addFrameworkTarget(
130149
131150 Logger . logInfo ( `Successfully added framework target: ${ frameworkName } ` ) ;
132151
133- return frameworkTarget . uuid ;
152+ return {
153+ frameworkTargetUUID : frameworkTarget . uuid ,
154+ targetAlreadyExists : false ,
155+ } ;
134156}
135157
136158/**
@@ -265,22 +287,24 @@ export function addExpoPre55ShellPatchScriptPhase(
265287 } ) ,
266288 }
267289 ) ;
290+ }
268291
269- // make sure the patch phase is after the expo configure phase,
270- // otherwise the patched file will be overwritten by the expo configure phase
292+ /**
293+ * Makes sure the patch expo modules provider phase is after the expo configure phase,
294+ * otherwise the patched file would be overwritten by the expo configure phase
295+ * @param project The Xcode project
296+ * @param frameworkTargetUUID The UUID of the framework target
297+ * @returns True if the build phases were modified, false otherwise
298+ */
299+ export function ensureExpoPre55ShellPatchScriptPhaseIsOrdered (
300+ project : XcodeProject ,
301+ frameworkTargetUUID : string
302+ ) {
303+ let modified = false ;
271304 const nativeTargetSection = project . pbxNativeTargetSection ( ) ;
272305
273- const brownfieldTarget = Object . entries ( nativeTargetSection ) . find (
274- ( [ _key , value ] ) =>
275- typeof value === 'object' &&
276- ( value as any ) ?. productType . includes (
277- 'com.apple.product-type.framework'
278- ) &&
279- ( value as any ) ?. name === frameworkName
280- ) ! [ 0 ] ;
281-
282306 const buildPhases : { value : string ; comment ?: string } [ ] =
283- nativeTargetSection [ brownfieldTarget ] . buildPhases ;
307+ nativeTargetSection [ frameworkTargetUUID ] . buildPhases ;
284308
285309 const expoConfigurePhaseIndex = buildPhases . findIndex (
286310 ( phase ) =>
@@ -301,9 +325,12 @@ export function addExpoPre55ShellPatchScriptPhase(
301325 1
302326 ) [ 0 ] ; // pop the element at patchExpoModulesProviderPhaseIndex
303327 buildPhases . splice ( expoConfigurePhaseIndex , 0 , element ) ; // insert the element at expoConfigurePhaseIndex ("after")
328+ modified = true ;
304329 }
305330
306- nativeTargetSection [ brownfieldTarget ] . buildPhases = buildPhases ;
331+ nativeTargetSection [ frameworkTargetUUID ] . buildPhases = buildPhases ;
307332
308333 project . writeSync ( ) ;
334+
335+ return modified ;
309336}
0 commit comments