Skip to content

Commit f4a44b8

Browse files
committed
fix: reorder build phases in iOS to first run patching after expo configure
1 parent 0989c60 commit f4a44b8

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

packages/react-native-brownfield/src/expo-config-plugin/ios/xcodeHelpers.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from 'node:path';
22

33
import type { ModProps, XcodeProject } from '@expo/config-plugins';
4+
45
import { Logger } from '../logging';
56
import type { ResolvedBrownfieldPluginIosConfig } from '../types';
67
import { SourceModificationError } from '../errors/SourceModificationError';
@@ -264,4 +265,45 @@ export function addExpoPre55ShellPatchScriptPhase(
264265
}),
265266
}
266267
);
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();
267309
}

packages/react-native-brownfield/src/expo-config-plugin/template/ios/patchExpoPre55.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@ if [ -f "$FILE" ]; then
1313

1414
# 2. Replace class visibility
1515
sed -i '' 's/public class ExpoModulesProvider/internal class ExpoModulesProvider/' "$FILE"
16+
17+
echo "Patched $FILE to hide Expo from public interface"
18+
echo "Contents of $FILE:"
19+
cat "$FILE"
1620
fi

0 commit comments

Comments
 (0)