@@ -6,44 +6,47 @@ const BROWNFIELD_POD_HOOK_MARKER_START =
66 '# >>> react-native-brownfield expo phase ordering >>>' ;
77const BROWNFIELD_POD_HOOK_MARKER_END =
88 '# <<< react-native-brownfield expo phase ordering <<<' ;
9+ const BROWNFIELD_POST_INTEGRATE_REQUIRE = `require File.join(File.dirname(\`node --print "require.resolve('@callstack/react-native-brownfield/package.json')"\`), "scripts/react_native_brownfield_post_integrate")` ;
10+ const REACT_NATIVE_PODS_REQUIRE_REGEX =
11+ / ^ r e q u i r e F i l e \. j o i n \( F i l e \. d i r n a m e \( ` n o d e - - p r i n t " r e q u i r e \. r e s o l v e \( ' r e a c t - n a t i v e \/ p a c k a g e \. j s o n ' \) " ` \) , " s c r i p t s \/ r e a c t _ n a t i v e _ p o d s " \) \s * $ / m;
912
10- function ensureExpoPhaseOrderingHook ( podfile : string ) : string {
11- if ( podfile . includes ( BROWNFIELD_POD_HOOK_MARKER_START ) ) {
13+ function ensureBrownfieldPostIntegrateRequire ( podfile : string ) : string {
14+ if ( podfile . includes ( 'scripts/react_native_brownfield_post_integrate' ) ) {
1215 return podfile ;
1316 }
1417
18+ const reactNativePodsRequireMatch = podfile . match (
19+ REACT_NATIVE_PODS_REQUIRE_REGEX
20+ ) ;
21+ if ( reactNativePodsRequireMatch ) {
22+ const requireLine = reactNativePodsRequireMatch [ 0 ] ;
23+ return podfile . replace (
24+ requireLine ,
25+ `${ requireLine } \n${ BROWNFIELD_POST_INTEGRATE_REQUIRE } \n`
26+ ) ;
27+ }
28+
29+ return `${ BROWNFIELD_POST_INTEGRATE_REQUIRE } \n\n${ podfile } ` ;
30+ }
31+
32+ function ensureExpoPhaseOrderingHook ( podfile : string ) : string {
33+ let modifiedPodfile = ensureBrownfieldPostIntegrateRequire ( podfile ) ;
34+
35+ if ( modifiedPodfile . includes ( BROWNFIELD_POD_HOOK_MARKER_START ) ) {
36+ return modifiedPodfile ;
37+ }
38+
1539 const hook = `
1640${ BROWNFIELD_POD_HOOK_MARKER_START }
17- def reorder_brownfield_expo_patch_phase!(installer)
18- projects = installer.aggregate_targets.map(&:user_project).compact.uniq
19- projects.each do |project|
20- modified = false
21-
22- project.native_targets.each do |target|
23- phases = target.build_phases
24- expo_idx = phases.index { |p| p.respond_to?(:name) && p.name == '[Expo] Configure project' }
25- patch_idx = phases.index { |p| p.respond_to?(:name) && p.name == 'Patch ExpoModulesProvider' }
26-
27- next if expo_idx.nil? || patch_idx.nil?
28- next if patch_idx > expo_idx
29-
30- patch = phases.delete_at(patch_idx)
31- expo_idx = phases.index { |p| p.respond_to?(:name) && p.name == '[Expo] Configure project' }
32- phases.insert(expo_idx + 1, patch)
33- modified = true
34- end
35-
36- project.save if modified
37- end
38- end
39-
4041post_integrate do |installer|
41- reorder_brownfield_expo_patch_phase! (installer)
42+ react_native_brownfield_post_integrate (installer)
4243end
4344${ BROWNFIELD_POD_HOOK_MARKER_END }
4445` ;
4546
46- return `${ podfile . trimEnd ( ) } \n\n${ hook } \n` ;
47+ modifiedPodfile = `${ modifiedPodfile . trimEnd ( ) } \n\n${ hook } \n` ;
48+
49+ return modifiedPodfile ;
4750}
4851
4952/**
0 commit comments