|
1 | 1 | import path from 'node:path'; |
2 | 2 |
|
3 | 3 | import type { ModProps, XcodeProject } from '@expo/config-plugins'; |
| 4 | + |
4 | 5 | import { Logger } from '../logging'; |
5 | 6 | import type { ResolvedBrownfieldPluginIosConfig } from '../types'; |
6 | 7 | import { SourceModificationError } from '../errors/SourceModificationError'; |
@@ -264,4 +265,45 @@ export function addExpoPre55ShellPatchScriptPhase( |
264 | 265 | }), |
265 | 266 | } |
266 | 267 | ); |
| 268 | + |
| 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 |
| 271 | + const nativeTargetSection = project.pbxNativeTargetSection(); |
| 272 | + |
| 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 | + |
| 282 | + const buildPhases: { value: string; comment?: string }[] = |
| 283 | + nativeTargetSection[brownfieldTarget].buildPhases; |
| 284 | + |
| 285 | + const expoConfigurePhaseIndex = buildPhases.findIndex( |
| 286 | + (phase) => |
| 287 | + (phase as any)?.comment?.toLowerCase() === |
| 288 | + '[Expo] Configure project'.toLowerCase() |
| 289 | + ); |
| 290 | + |
| 291 | + const patchExpoModulesProviderPhaseIndex = buildPhases.findIndex( |
| 292 | + (phase) => |
| 293 | + (phase as any)?.comment?.toLowerCase() === |
| 294 | + 'Patch ExpoModulesProvider'.toLowerCase() |
| 295 | + ); |
| 296 | + |
| 297 | + // ensure patch expo modules provider phase is after expo configure phase |
| 298 | + if (patchExpoModulesProviderPhaseIndex < expoConfigurePhaseIndex) { |
| 299 | + const element = buildPhases.splice( |
| 300 | + patchExpoModulesProviderPhaseIndex, |
| 301 | + 1 |
| 302 | + )[0]; // pop the element at patchExpoModulesProviderPhaseIndex |
| 303 | + buildPhases.splice(expoConfigurePhaseIndex, 0, element); // insert the element at expoConfigurePhaseIndex ("after") |
| 304 | + } |
| 305 | + |
| 306 | + nativeTargetSection[brownfieldTarget].buildPhases = buildPhases; |
| 307 | + |
| 308 | + project.writeSync(); |
267 | 309 | } |
0 commit comments