@callstack/react-native-brownfield 2.2.0 → 3.0.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (230) hide show
  1. package/ReactBrownfield.podspec +4 -0
  2. package/ios/BrownfieldBundlePathResolver.swift +21 -0
  3. package/ios/ExpoHostRuntime.swift +140 -0
  4. package/ios/JSBundleLoadObserver.swift +38 -0
  5. package/ios/Notification+Brownfield.swift +12 -0
  6. package/ios/ReactNativeBrownfield.swift +78 -112
  7. package/ios/ReactNativeHostRuntime.swift +138 -0
  8. package/lib/commonjs/expo-config-plugin/android/constants.js +2 -0
  9. package/lib/commonjs/expo-config-plugin/android/constants.js.map +1 -0
  10. package/lib/commonjs/expo-config-plugin/android/gradleHelpers.js +2 -0
  11. package/lib/commonjs/expo-config-plugin/android/gradleHelpers.js.map +1 -0
  12. package/lib/commonjs/expo-config-plugin/android/index.js +2 -0
  13. package/lib/commonjs/expo-config-plugin/android/index.js.map +1 -0
  14. package/lib/commonjs/expo-config-plugin/android/withAndroidModuleFiles.js +2 -0
  15. package/lib/commonjs/expo-config-plugin/android/withAndroidModuleFiles.js.map +1 -0
  16. package/lib/commonjs/expo-config-plugin/android/withBrownfieldAndroid.js +2 -0
  17. package/lib/commonjs/expo-config-plugin/android/withBrownfieldAndroid.js.map +1 -0
  18. package/lib/commonjs/expo-config-plugin/app.plugin.js +2 -0
  19. package/lib/commonjs/expo-config-plugin/app.plugin.js.map +1 -0
  20. package/lib/commonjs/expo-config-plugin/errors/SourceModificationError.js +2 -0
  21. package/lib/commonjs/expo-config-plugin/errors/SourceModificationError.js.map +1 -0
  22. package/lib/commonjs/expo-config-plugin/index.js +2 -0
  23. package/lib/commonjs/expo-config-plugin/index.js.map +1 -0
  24. package/lib/commonjs/expo-config-plugin/ios/index.js +2 -0
  25. package/lib/commonjs/expo-config-plugin/ios/index.js.map +1 -0
  26. package/lib/commonjs/expo-config-plugin/ios/podfileHelpers.js +8 -0
  27. package/lib/commonjs/expo-config-plugin/ios/podfileHelpers.js.map +1 -0
  28. package/lib/commonjs/expo-config-plugin/ios/withBrownfieldIos.js +2 -0
  29. package/lib/commonjs/expo-config-plugin/ios/withBrownfieldIos.js.map +1 -0
  30. package/lib/commonjs/expo-config-plugin/ios/withIosFrameworkFiles.js +2 -0
  31. package/lib/commonjs/expo-config-plugin/ios/withIosFrameworkFiles.js.map +1 -0
  32. package/lib/commonjs/expo-config-plugin/ios/xcodeHelpers.js +2 -0
  33. package/lib/commonjs/expo-config-plugin/ios/xcodeHelpers.js.map +1 -0
  34. package/lib/commonjs/expo-config-plugin/logging.js +2 -0
  35. package/lib/commonjs/expo-config-plugin/logging.js.map +1 -0
  36. package/lib/commonjs/expo-config-plugin/template/android/AndroidManifest.xml +4 -0
  37. package/lib/commonjs/expo-config-plugin/template/android/ReactNativeHostManager.kt +54 -0
  38. package/lib/commonjs/expo-config-plugin/template/android/build.gradle.kts +90 -0
  39. package/lib/commonjs/expo-config-plugin/template/android/consumer-rules.pro +0 -0
  40. package/lib/commonjs/expo-config-plugin/template/android/gradle.properties +8 -0
  41. package/lib/commonjs/expo-config-plugin/template/android/proguard-rules.pro +21 -0
  42. package/lib/commonjs/expo-config-plugin/template/engine.js +2 -0
  43. package/lib/commonjs/expo-config-plugin/template/engine.js.map +1 -0
  44. package/lib/commonjs/expo-config-plugin/template/ios/FrameworkInterface.swift +13 -0
  45. package/lib/commonjs/expo-config-plugin/template/ios/Info.plist +22 -0
  46. package/lib/commonjs/expo-config-plugin/template/ios/PodfileTargetBlock.rb +5 -0
  47. package/lib/commonjs/expo-config-plugin/template/ios/patchExpoPre55.sh +20 -0
  48. package/lib/commonjs/expo-config-plugin/types/BrownfieldPluginConfig.js +2 -0
  49. package/lib/commonjs/expo-config-plugin/types/BrownfieldPluginConfig.js.map +1 -0
  50. package/lib/commonjs/expo-config-plugin/types/RenderedTemplateFile.js +2 -0
  51. package/lib/commonjs/expo-config-plugin/types/RenderedTemplateFile.js.map +1 -0
  52. package/lib/commonjs/expo-config-plugin/types/android/BrownfieldPluginAndroidConfig.js +2 -0
  53. package/lib/commonjs/expo-config-plugin/types/android/BrownfieldPluginAndroidConfig.js.map +1 -0
  54. package/lib/commonjs/expo-config-plugin/types/index.js +2 -0
  55. package/lib/commonjs/expo-config-plugin/types/index.js.map +1 -0
  56. package/lib/commonjs/expo-config-plugin/types/ios/BrownfieldPluginIosConfig.js +2 -0
  57. package/lib/commonjs/expo-config-plugin/types/ios/BrownfieldPluginIosConfig.js.map +1 -0
  58. package/lib/commonjs/expo-config-plugin/withBrownfield.js +2 -0
  59. package/lib/commonjs/expo-config-plugin/withBrownfield.js.map +1 -0
  60. package/lib/commonjs/scripts/brownfield.js +0 -0
  61. package/lib/module/expo-config-plugin/android/constants.js +2 -0
  62. package/lib/module/expo-config-plugin/android/constants.js.map +1 -0
  63. package/lib/module/expo-config-plugin/android/gradleHelpers.js +2 -0
  64. package/lib/module/expo-config-plugin/android/gradleHelpers.js.map +1 -0
  65. package/lib/module/expo-config-plugin/android/index.js +2 -0
  66. package/lib/module/expo-config-plugin/android/index.js.map +1 -0
  67. package/lib/module/expo-config-plugin/android/withAndroidModuleFiles.js +2 -0
  68. package/lib/module/expo-config-plugin/android/withAndroidModuleFiles.js.map +1 -0
  69. package/lib/module/expo-config-plugin/android/withBrownfieldAndroid.js +2 -0
  70. package/lib/module/expo-config-plugin/android/withBrownfieldAndroid.js.map +1 -0
  71. package/lib/module/expo-config-plugin/app.plugin.js +2 -0
  72. package/lib/module/expo-config-plugin/app.plugin.js.map +1 -0
  73. package/lib/module/expo-config-plugin/errors/SourceModificationError.js +2 -0
  74. package/lib/module/expo-config-plugin/errors/SourceModificationError.js.map +1 -0
  75. package/lib/module/expo-config-plugin/index.js +2 -0
  76. package/lib/module/expo-config-plugin/index.js.map +1 -0
  77. package/lib/module/expo-config-plugin/ios/index.js +2 -0
  78. package/lib/module/expo-config-plugin/ios/index.js.map +1 -0
  79. package/lib/module/expo-config-plugin/ios/podfileHelpers.js +8 -0
  80. package/lib/module/expo-config-plugin/ios/podfileHelpers.js.map +1 -0
  81. package/lib/module/expo-config-plugin/ios/withBrownfieldIos.js +2 -0
  82. package/lib/module/expo-config-plugin/ios/withBrownfieldIos.js.map +1 -0
  83. package/lib/module/expo-config-plugin/ios/withIosFrameworkFiles.js +2 -0
  84. package/lib/module/expo-config-plugin/ios/withIosFrameworkFiles.js.map +1 -0
  85. package/lib/module/expo-config-plugin/ios/xcodeHelpers.js +2 -0
  86. package/lib/module/expo-config-plugin/ios/xcodeHelpers.js.map +1 -0
  87. package/lib/module/expo-config-plugin/logging.js +2 -0
  88. package/lib/module/expo-config-plugin/logging.js.map +1 -0
  89. package/lib/module/expo-config-plugin/template/android/AndroidManifest.xml +4 -0
  90. package/lib/module/expo-config-plugin/template/android/ReactNativeHostManager.kt +54 -0
  91. package/lib/module/expo-config-plugin/template/android/build.gradle.kts +90 -0
  92. package/lib/module/expo-config-plugin/template/android/consumer-rules.pro +0 -0
  93. package/lib/module/expo-config-plugin/template/android/gradle.properties +8 -0
  94. package/lib/module/expo-config-plugin/template/android/proguard-rules.pro +21 -0
  95. package/lib/module/expo-config-plugin/template/engine.js +2 -0
  96. package/lib/module/expo-config-plugin/template/engine.js.map +1 -0
  97. package/lib/module/expo-config-plugin/template/ios/FrameworkInterface.swift +13 -0
  98. package/lib/module/expo-config-plugin/template/ios/Info.plist +22 -0
  99. package/lib/module/expo-config-plugin/template/ios/PodfileTargetBlock.rb +5 -0
  100. package/lib/module/expo-config-plugin/template/ios/patchExpoPre55.sh +20 -0
  101. package/lib/module/expo-config-plugin/types/BrownfieldPluginConfig.js +2 -0
  102. package/lib/module/expo-config-plugin/types/BrownfieldPluginConfig.js.map +1 -0
  103. package/lib/module/expo-config-plugin/types/RenderedTemplateFile.js +2 -0
  104. package/lib/module/expo-config-plugin/types/RenderedTemplateFile.js.map +1 -0
  105. package/lib/module/expo-config-plugin/types/android/BrownfieldPluginAndroidConfig.js +2 -0
  106. package/lib/module/expo-config-plugin/types/android/BrownfieldPluginAndroidConfig.js.map +1 -0
  107. package/lib/module/expo-config-plugin/types/index.js +2 -0
  108. package/lib/module/expo-config-plugin/types/index.js.map +1 -0
  109. package/lib/module/expo-config-plugin/types/ios/BrownfieldPluginIosConfig.js +2 -0
  110. package/lib/module/expo-config-plugin/types/ios/BrownfieldPluginIosConfig.js.map +1 -0
  111. package/lib/module/expo-config-plugin/withBrownfield.js +2 -0
  112. package/lib/module/expo-config-plugin/withBrownfield.js.map +1 -0
  113. package/lib/typescript/commonjs/src/expo-config-plugin/android/constants.d.ts +3 -0
  114. package/lib/typescript/commonjs/src/expo-config-plugin/android/constants.d.ts.map +1 -0
  115. package/lib/typescript/commonjs/src/expo-config-plugin/android/gradleHelpers.d.ts +14 -0
  116. package/lib/typescript/commonjs/src/expo-config-plugin/android/gradleHelpers.d.ts.map +1 -0
  117. package/lib/typescript/commonjs/src/expo-config-plugin/android/index.d.ts +4 -0
  118. package/lib/typescript/commonjs/src/expo-config-plugin/android/index.d.ts.map +1 -0
  119. package/lib/typescript/commonjs/src/expo-config-plugin/android/withAndroidModuleFiles.d.ts +24 -0
  120. package/lib/typescript/commonjs/src/expo-config-plugin/android/withAndroidModuleFiles.d.ts.map +1 -0
  121. package/lib/typescript/commonjs/src/expo-config-plugin/android/withBrownfieldAndroid.d.ts +13 -0
  122. package/lib/typescript/commonjs/src/expo-config-plugin/android/withBrownfieldAndroid.d.ts.map +1 -0
  123. package/lib/typescript/commonjs/src/expo-config-plugin/app.plugin.d.ts +9 -0
  124. package/lib/typescript/commonjs/src/expo-config-plugin/app.plugin.d.ts.map +1 -0
  125. package/lib/typescript/commonjs/src/expo-config-plugin/errors/SourceModificationError.d.ts +3 -0
  126. package/lib/typescript/commonjs/src/expo-config-plugin/errors/SourceModificationError.d.ts.map +1 -0
  127. package/lib/typescript/commonjs/src/expo-config-plugin/index.d.ts +7 -0
  128. package/lib/typescript/commonjs/src/expo-config-plugin/index.d.ts.map +1 -0
  129. package/lib/typescript/commonjs/src/expo-config-plugin/ios/index.d.ts +5 -0
  130. package/lib/typescript/commonjs/src/expo-config-plugin/ios/index.d.ts.map +1 -0
  131. package/lib/typescript/commonjs/src/expo-config-plugin/ios/podfileHelpers.d.ts +8 -0
  132. package/lib/typescript/commonjs/src/expo-config-plugin/ios/podfileHelpers.d.ts.map +1 -0
  133. package/lib/typescript/commonjs/src/expo-config-plugin/ios/withBrownfieldIos.d.ts +14 -0
  134. package/lib/typescript/commonjs/src/expo-config-plugin/ios/withBrownfieldIos.d.ts.map +1 -0
  135. package/lib/typescript/commonjs/src/expo-config-plugin/ios/withIosFrameworkFiles.d.ts +19 -0
  136. package/lib/typescript/commonjs/src/expo-config-plugin/ios/withIosFrameworkFiles.d.ts.map +1 -0
  137. package/lib/typescript/commonjs/src/expo-config-plugin/ios/xcodeHelpers.d.ts +33 -0
  138. package/lib/typescript/commonjs/src/expo-config-plugin/ios/xcodeHelpers.d.ts.map +1 -0
  139. package/lib/typescript/commonjs/src/expo-config-plugin/logging.d.ts +9 -0
  140. package/lib/typescript/commonjs/src/expo-config-plugin/logging.d.ts.map +1 -0
  141. package/lib/typescript/commonjs/src/expo-config-plugin/template/engine.d.ts +9 -0
  142. package/lib/typescript/commonjs/src/expo-config-plugin/template/engine.d.ts.map +1 -0
  143. package/lib/typescript/commonjs/src/expo-config-plugin/types/BrownfieldPluginConfig.d.ts +53 -0
  144. package/lib/typescript/commonjs/src/expo-config-plugin/types/BrownfieldPluginConfig.d.ts.map +1 -0
  145. package/lib/typescript/commonjs/src/expo-config-plugin/types/RenderedTemplateFile.d.ts +5 -0
  146. package/lib/typescript/commonjs/src/expo-config-plugin/types/RenderedTemplateFile.d.ts.map +1 -0
  147. package/lib/typescript/commonjs/src/expo-config-plugin/types/android/BrownfieldPluginAndroidConfig.d.ts +50 -0
  148. package/lib/typescript/commonjs/src/expo-config-plugin/types/android/BrownfieldPluginAndroidConfig.d.ts.map +1 -0
  149. package/lib/typescript/commonjs/src/expo-config-plugin/types/index.d.ts +5 -0
  150. package/lib/typescript/commonjs/src/expo-config-plugin/types/index.d.ts.map +1 -0
  151. package/lib/typescript/commonjs/src/expo-config-plugin/types/ios/BrownfieldPluginIosConfig.d.ts +36 -0
  152. package/lib/typescript/commonjs/src/expo-config-plugin/types/ios/BrownfieldPluginIosConfig.d.ts.map +1 -0
  153. package/lib/typescript/commonjs/src/expo-config-plugin/withBrownfield.d.ts +5 -0
  154. package/lib/typescript/commonjs/src/expo-config-plugin/withBrownfield.d.ts.map +1 -0
  155. package/lib/typescript/module/src/expo-config-plugin/android/constants.d.ts +3 -0
  156. package/lib/typescript/module/src/expo-config-plugin/android/constants.d.ts.map +1 -0
  157. package/lib/typescript/module/src/expo-config-plugin/android/gradleHelpers.d.ts +14 -0
  158. package/lib/typescript/module/src/expo-config-plugin/android/gradleHelpers.d.ts.map +1 -0
  159. package/lib/typescript/module/src/expo-config-plugin/android/index.d.ts +4 -0
  160. package/lib/typescript/module/src/expo-config-plugin/android/index.d.ts.map +1 -0
  161. package/lib/typescript/module/src/expo-config-plugin/android/withAndroidModuleFiles.d.ts +24 -0
  162. package/lib/typescript/module/src/expo-config-plugin/android/withAndroidModuleFiles.d.ts.map +1 -0
  163. package/lib/typescript/module/src/expo-config-plugin/android/withBrownfieldAndroid.d.ts +13 -0
  164. package/lib/typescript/module/src/expo-config-plugin/android/withBrownfieldAndroid.d.ts.map +1 -0
  165. package/lib/typescript/module/src/expo-config-plugin/app.plugin.d.ts +9 -0
  166. package/lib/typescript/module/src/expo-config-plugin/app.plugin.d.ts.map +1 -0
  167. package/lib/typescript/module/src/expo-config-plugin/errors/SourceModificationError.d.ts +3 -0
  168. package/lib/typescript/module/src/expo-config-plugin/errors/SourceModificationError.d.ts.map +1 -0
  169. package/lib/typescript/module/src/expo-config-plugin/index.d.ts +7 -0
  170. package/lib/typescript/module/src/expo-config-plugin/index.d.ts.map +1 -0
  171. package/lib/typescript/module/src/expo-config-plugin/ios/index.d.ts +5 -0
  172. package/lib/typescript/module/src/expo-config-plugin/ios/index.d.ts.map +1 -0
  173. package/lib/typescript/module/src/expo-config-plugin/ios/podfileHelpers.d.ts +8 -0
  174. package/lib/typescript/module/src/expo-config-plugin/ios/podfileHelpers.d.ts.map +1 -0
  175. package/lib/typescript/module/src/expo-config-plugin/ios/withBrownfieldIos.d.ts +14 -0
  176. package/lib/typescript/module/src/expo-config-plugin/ios/withBrownfieldIos.d.ts.map +1 -0
  177. package/lib/typescript/module/src/expo-config-plugin/ios/withIosFrameworkFiles.d.ts +19 -0
  178. package/lib/typescript/module/src/expo-config-plugin/ios/withIosFrameworkFiles.d.ts.map +1 -0
  179. package/lib/typescript/module/src/expo-config-plugin/ios/xcodeHelpers.d.ts +33 -0
  180. package/lib/typescript/module/src/expo-config-plugin/ios/xcodeHelpers.d.ts.map +1 -0
  181. package/lib/typescript/module/src/expo-config-plugin/logging.d.ts +9 -0
  182. package/lib/typescript/module/src/expo-config-plugin/logging.d.ts.map +1 -0
  183. package/lib/typescript/module/src/expo-config-plugin/template/engine.d.ts +9 -0
  184. package/lib/typescript/module/src/expo-config-plugin/template/engine.d.ts.map +1 -0
  185. package/lib/typescript/module/src/expo-config-plugin/types/BrownfieldPluginConfig.d.ts +53 -0
  186. package/lib/typescript/module/src/expo-config-plugin/types/BrownfieldPluginConfig.d.ts.map +1 -0
  187. package/lib/typescript/module/src/expo-config-plugin/types/RenderedTemplateFile.d.ts +5 -0
  188. package/lib/typescript/module/src/expo-config-plugin/types/RenderedTemplateFile.d.ts.map +1 -0
  189. package/lib/typescript/module/src/expo-config-plugin/types/android/BrownfieldPluginAndroidConfig.d.ts +50 -0
  190. package/lib/typescript/module/src/expo-config-plugin/types/android/BrownfieldPluginAndroidConfig.d.ts.map +1 -0
  191. package/lib/typescript/module/src/expo-config-plugin/types/index.d.ts +5 -0
  192. package/lib/typescript/module/src/expo-config-plugin/types/index.d.ts.map +1 -0
  193. package/lib/typescript/module/src/expo-config-plugin/types/ios/BrownfieldPluginIosConfig.d.ts +36 -0
  194. package/lib/typescript/module/src/expo-config-plugin/types/ios/BrownfieldPluginIosConfig.d.ts.map +1 -0
  195. package/lib/typescript/module/src/expo-config-plugin/withBrownfield.d.ts +5 -0
  196. package/lib/typescript/module/src/expo-config-plugin/withBrownfield.d.ts.map +1 -0
  197. package/package.json +20 -7
  198. package/scripts/react_native_brownfield_post_integrate.rb +22 -0
  199. package/src/expo-config-plugin/android/constants.ts +2 -0
  200. package/src/expo-config-plugin/android/gradleHelpers.ts +72 -0
  201. package/src/expo-config-plugin/android/index.ts +6 -0
  202. package/src/expo-config-plugin/android/withAndroidModuleFiles.ts +139 -0
  203. package/src/expo-config-plugin/android/withBrownfieldAndroid.ts +48 -0
  204. package/src/expo-config-plugin/app.plugin.ts +10 -0
  205. package/src/expo-config-plugin/errors/SourceModificationError.ts +1 -0
  206. package/src/expo-config-plugin/index.ts +8 -0
  207. package/src/expo-config-plugin/ios/index.ts +7 -0
  208. package/src/expo-config-plugin/ios/podfileHelpers.ts +107 -0
  209. package/src/expo-config-plugin/ios/withBrownfieldIos.ts +94 -0
  210. package/src/expo-config-plugin/ios/withIosFrameworkFiles.ts +91 -0
  211. package/src/expo-config-plugin/ios/xcodeHelpers.ts +433 -0
  212. package/src/expo-config-plugin/logging.ts +29 -0
  213. package/src/expo-config-plugin/template/android/AndroidManifest.xml +4 -0
  214. package/src/expo-config-plugin/template/android/ReactNativeHostManager.kt +54 -0
  215. package/src/expo-config-plugin/template/android/build.gradle.kts +90 -0
  216. package/src/expo-config-plugin/template/android/consumer-rules.pro +0 -0
  217. package/src/expo-config-plugin/template/android/gradle.properties +8 -0
  218. package/src/expo-config-plugin/template/android/proguard-rules.pro +21 -0
  219. package/src/expo-config-plugin/template/engine.ts +26 -0
  220. package/src/expo-config-plugin/template/ios/FrameworkInterface.swift +13 -0
  221. package/src/expo-config-plugin/template/ios/Info.plist +22 -0
  222. package/src/expo-config-plugin/template/ios/PodfileTargetBlock.rb +5 -0
  223. package/src/expo-config-plugin/template/ios/patchExpoPre55.sh +20 -0
  224. package/src/expo-config-plugin/types/BrownfieldPluginConfig.ts +67 -0
  225. package/src/expo-config-plugin/types/RenderedTemplateFile.ts +4 -0
  226. package/src/expo-config-plugin/types/android/BrownfieldPluginAndroidConfig.ts +58 -0
  227. package/src/expo-config-plugin/types/index.ts +6 -0
  228. package/src/expo-config-plugin/types/ios/BrownfieldPluginIosConfig.ts +41 -0
  229. package/src/expo-config-plugin/withBrownfield.ts +112 -0
  230. package/CHANGELOG.md +0 -41
@@ -0,0 +1,107 @@
1
+ import { SourceModificationError } from '../errors/SourceModificationError';
2
+ import { Logger } from '../logging';
3
+ import { renderTemplate } from '../template/engine';
4
+
5
+ const BROWNFIELD_POD_HOOK_MARKER_START =
6
+ '# >>> react-native-brownfield expo phase ordering >>>';
7
+ const BROWNFIELD_POD_HOOK_MARKER_END =
8
+ '# <<< 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
+ /^require File\.join\(File\.dirname\(`node --print "require\.resolve\('react-native\/package\.json'\)"`\), "scripts\/react_native_pods"\)\s*$/m;
12
+
13
+ function ensureBrownfieldPostIntegrateRequire(podfile: string): string {
14
+ if (podfile.includes('scripts/react_native_brownfield_post_integrate')) {
15
+ return podfile;
16
+ }
17
+
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
+
39
+ const hook = `
40
+ ${BROWNFIELD_POD_HOOK_MARKER_START}
41
+ post_integrate do |installer|
42
+ react_native_brownfield_post_integrate(installer)
43
+ end
44
+ ${BROWNFIELD_POD_HOOK_MARKER_END}
45
+ `;
46
+
47
+ modifiedPodfile = `${modifiedPodfile.trimEnd()}\n\n${hook}\n`;
48
+
49
+ return modifiedPodfile;
50
+ }
51
+
52
+ /**
53
+ * Modifies the Podfile to include the Brownfield framework target
54
+ * @param podfile The original Podfile content
55
+ * @param frameworkName The name of the framework target to add
56
+ * @returns The modified Podfile content
57
+ */
58
+ export function modifyPodfile(
59
+ podfile: string,
60
+ frameworkName: string,
61
+ isExpoPre55: boolean
62
+ ): string {
63
+ // check if the framework target is already included
64
+ if (podfile.includes(`target '${frameworkName}'`)) {
65
+ Logger.logDebug(
66
+ `Framework target "${frameworkName}" already in Podfile, skipping modification`
67
+ );
68
+ return podfile;
69
+ }
70
+
71
+ Logger.logDebug(`Modifying Podfile for framework: ${frameworkName}`);
72
+
73
+ // insert the framework target after the main target's "do"
74
+ const frameworkTargetBlock = renderTemplate('ios', 'PodfileTargetBlock.rb', {
75
+ '{{FRAMEWORK_NAME}}': frameworkName,
76
+ });
77
+
78
+ // find insertion point after the first target's content begins, before the end of the target block
79
+ const mainTargetMatch = podfile.match(
80
+ /(target\s+['"][^'"]+['"]\s+do\s*\n)([\s\S]*?)(^end\s*$)/m
81
+ );
82
+
83
+ if (!mainTargetMatch) {
84
+ throw new SourceModificationError(
85
+ 'Could not find main target in Podfile. Please manually add the framework target.'
86
+ );
87
+ }
88
+
89
+ const [, targetStart, targetContent] = mainTargetMatch;
90
+ const insertIndex =
91
+ podfile.indexOf(mainTargetMatch[0]) +
92
+ targetStart.length +
93
+ targetContent.length;
94
+
95
+ let modifiedPodfile =
96
+ podfile.slice(0, insertIndex) +
97
+ frameworkTargetBlock +
98
+ podfile.slice(insertIndex);
99
+
100
+ Logger.logDebug(`Added framework target "${frameworkName}" to Podfile`);
101
+
102
+ if (isExpoPre55) {
103
+ modifiedPodfile = ensureExpoPhaseOrderingHook(modifiedPodfile);
104
+ }
105
+
106
+ return modifiedPodfile;
107
+ }
@@ -0,0 +1,94 @@
1
+ import {
2
+ withXcodeProject,
3
+ withPodfile,
4
+ type ConfigPlugin,
5
+ } from '@expo/config-plugins';
6
+
7
+ import {
8
+ addExpoPre55ShellPatchScriptPhase,
9
+ addFrameworkTarget,
10
+ addSourceFilesBuildPhase,
11
+ copyBundleReactNativePhase,
12
+ } from './xcodeHelpers';
13
+ import { modifyPodfile } from './podfileHelpers';
14
+ import { withIosFrameworkFiles } from './withIosFrameworkFiles';
15
+ import type { ResolvedBrownfieldPluginConfigWithIos } from '../types';
16
+ import { Logger } from '../logging';
17
+
18
+ /**
19
+ * iOS Config Plugin for integration with @callstack/react-native-brownfield.
20
+ *
21
+ * This plugin:
22
+ * 1. Creates a new Framework target in the Xcode project
23
+ * 2. Configures the Podfile to include the framework target
24
+ * 3. Adds necessary build configuration
25
+ * 4. Adds script phase to patch `ExpoModulesProvider.swift`
26
+ * 5. Adds the "Bundle React Native code and images" phase of Expo app target to the framework target
27
+ */
28
+ export const withBrownfieldIos: ConfigPlugin<
29
+ ResolvedBrownfieldPluginConfigWithIos
30
+ > = (config, props) => {
31
+ const expoMajor = config.sdkVersion
32
+ ? parseInt(config.sdkVersion.split('.')[0], 10)
33
+ : -1;
34
+ const isExpoPre55 = expoMajor < 55;
35
+ // Step 1: modify the Xcode project to add framework target &
36
+ config = withXcodeProject(config, (xcodeConfig) => {
37
+ const { modResults: project, modRequest } = xcodeConfig;
38
+
39
+ const { frameworkTargetUUID, targetAlreadyExists } = addFrameworkTarget(
40
+ project,
41
+ modRequest,
42
+ props.ios
43
+ );
44
+
45
+ if (targetAlreadyExists) {
46
+ Logger.logDebug(
47
+ `Skipping further Xcode modifications as framework target was already present`
48
+ );
49
+
50
+ return xcodeConfig;
51
+ }
52
+
53
+ // copy the "Bundle React Native code and images" build phase from the main target to the framework target
54
+ copyBundleReactNativePhase(project, frameworkTargetUUID);
55
+
56
+ // for Expo SDK versions < 55, add a script phase to patch ExpoModulesProvider.swift
57
+ if (isExpoPre55) {
58
+ Logger.logDebug(
59
+ `Adding ExpoModulesProvider patch phase for Expo SDK ${config.sdkVersion}`
60
+ );
61
+
62
+ addExpoPre55ShellPatchScriptPhase(modRequest, project, {
63
+ frameworkName: props.ios.frameworkName,
64
+ frameworkTargetUUID: frameworkTargetUUID,
65
+ });
66
+ } else {
67
+ Logger.logDebug(
68
+ `Skipping ExpoModulesProvider patch phase for Expo SDK ${config.sdkVersion}`
69
+ );
70
+ }
71
+
72
+ addSourceFilesBuildPhase(project, frameworkTargetUUID, props.ios);
73
+
74
+ return xcodeConfig;
75
+ });
76
+
77
+ // Step 2: modify Podfile to include the framework target
78
+ config = withPodfile(config, (podfileConfig) => {
79
+ const { frameworkName } = props.ios;
80
+
81
+ podfileConfig.modResults.contents = modifyPodfile(
82
+ podfileConfig.modResults.contents,
83
+ frameworkName,
84
+ isExpoPre55
85
+ );
86
+
87
+ return podfileConfig;
88
+ });
89
+
90
+ // Step 3: create the iOS framework files using dangerous mod
91
+ config = withIosFrameworkFiles(config, props);
92
+
93
+ return config;
94
+ };
@@ -0,0 +1,91 @@
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
+
4
+ import { withDangerousMod, type ConfigPlugin } from '@expo/config-plugins';
5
+
6
+ import type {
7
+ RenderedTemplateFile,
8
+ ResolvedBrownfieldPluginConfigWithIos,
9
+ } from '../types';
10
+ import { Logger } from '../logging';
11
+ import { renderTemplate } from '../template/engine';
12
+
13
+ /**
14
+ * Returns rendered source files for the iOS framework
15
+ * @param ios The iOS Brownfield plugin configuration
16
+ * @returns The list of framework source files
17
+ */
18
+ export function getFrameworkSourceFiles(
19
+ ios: ResolvedBrownfieldPluginConfigWithIos['ios']
20
+ ): RenderedTemplateFile[] {
21
+ return [
22
+ {
23
+ relativePath: `${ios.frameworkName}.swift`,
24
+ content: renderTemplate('ios', 'FrameworkInterface.swift', {}),
25
+ },
26
+ {
27
+ relativePath: 'Info.plist',
28
+ content: renderTemplate('ios', 'Info.plist', {
29
+ '{{BUNDLE_IDENTIFIER}}': ios.bundleIdentifier,
30
+ }),
31
+ },
32
+ ];
33
+ }
34
+
35
+ /**
36
+ * Creates the iOS framework directory structure and files
37
+ * @param iosDir The root iOS directory path
38
+ * @param config The resolved Brownfield plugin configuration
39
+ */
40
+ export function createIosFramework(
41
+ iosDir: string,
42
+ config: ResolvedBrownfieldPluginConfigWithIos
43
+ ) {
44
+ const { ios } = config;
45
+ const frameworkDir = path.join(iosDir, ios.frameworkName);
46
+
47
+ // check if framework directory if it exists
48
+ if (fs.existsSync(frameworkDir)) {
49
+ Logger.logDebug(`Framework directory already exists: ${frameworkDir}`);
50
+
51
+ return;
52
+ }
53
+
54
+ Logger.logDebug(`Creating iOS framework in: ${frameworkDir}`);
55
+
56
+ // create framework directory
57
+ if (!fs.existsSync(frameworkDir)) {
58
+ fs.mkdirSync(frameworkDir, { recursive: true });
59
+
60
+ Logger.logDebug(`Created directory: ${frameworkDir}`);
61
+ }
62
+
63
+ // write files
64
+ for (const file of getFrameworkSourceFiles(ios)) {
65
+ const filePath = path.join(frameworkDir, file.relativePath);
66
+
67
+ fs.writeFileSync(filePath, file.content, 'utf8');
68
+ }
69
+
70
+ Logger.logDebug(
71
+ `iOS framework "${ios.frameworkName}" files created at ${frameworkDir}`
72
+ );
73
+ }
74
+
75
+ /**
76
+ * Dangerous mod that creates the iOS framework directory and files
77
+ */
78
+ export const withIosFrameworkFiles: ConfigPlugin<
79
+ ResolvedBrownfieldPluginConfigWithIos
80
+ > = (config, props) => {
81
+ return withDangerousMod(config, [
82
+ 'ios',
83
+ async (dangerousConfig) => {
84
+ const iosDir = path.join(dangerousConfig.modRequest.projectRoot, 'ios');
85
+
86
+ createIosFramework(iosDir, props);
87
+
88
+ return dangerousConfig;
89
+ },
90
+ ]);
91
+ };