expo-targets 0.1.0

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 (231) hide show
  1. package/.eslintrc.js +2 -0
  2. package/README.md +244 -0
  3. package/android/build.gradle +22 -0
  4. package/android/src/main/java/expo/modules/targets/ExpoTargetsLogger.kt +98 -0
  5. package/android/src/main/java/expo/modules/targets/ExpoTargetsReceiver.kt +136 -0
  6. package/android/src/main/java/expo/modules/targets/ExpoTargetsRemoteViewsProvider.kt +72 -0
  7. package/android/src/main/java/expo/modules/targets/ExpoTargetsWidgetProvider.kt +47 -0
  8. package/android/src/main/java/expo/modules/targets/ExpoTargetsWidgetSync.kt +78 -0
  9. package/android/src/main/java/expo/modules/targets/ExpoTargetsWidgetUpdateReceiver.kt +30 -0
  10. package/android/src/main/java/expo/modules/targets/extension/ExpoTargetsExtensionModule.kt +27 -0
  11. package/android/src/main/java/expo/modules/targets/messages/ExpoTargetsMessagesModule.kt +40 -0
  12. package/android/src/main/java/expo/modules/targets/storage/ExpoTargetsStorageModule.kt +119 -0
  13. package/app.plugin.js +1 -0
  14. package/build/metro/src/index.d.ts +2 -0
  15. package/build/metro/src/index.d.ts.map +1 -0
  16. package/build/metro/src/index.js +6 -0
  17. package/build/metro/src/index.js.map +1 -0
  18. package/build/metro/src/withTargetsMetro.d.ts +6 -0
  19. package/build/metro/src/withTargetsMetro.d.ts.map +1 -0
  20. package/build/metro/src/withTargetsMetro.js +171 -0
  21. package/build/metro/src/withTargetsMetro.js.map +1 -0
  22. package/build/plugin/src/android/config-plugins/withAndroidColors.d.ts +7 -0
  23. package/build/plugin/src/android/config-plugins/withAndroidColors.d.ts.map +1 -0
  24. package/build/plugin/src/android/config-plugins/withAndroidColors.js +56 -0
  25. package/build/plugin/src/android/config-plugins/withAndroidColors.js.map +1 -0
  26. package/build/plugin/src/android/config-plugins/withAndroidManifest.d.ts +7 -0
  27. package/build/plugin/src/android/config-plugins/withAndroidManifest.d.ts.map +1 -0
  28. package/build/plugin/src/android/config-plugins/withAndroidManifest.js +70 -0
  29. package/build/plugin/src/android/config-plugins/withAndroidManifest.js.map +1 -0
  30. package/build/plugin/src/android/config-plugins/withAndroidModule.d.ts +7 -0
  31. package/build/plugin/src/android/config-plugins/withAndroidModule.d.ts.map +1 -0
  32. package/build/plugin/src/android/config-plugins/withAndroidModule.js +41 -0
  33. package/build/plugin/src/android/config-plugins/withAndroidModule.js.map +1 -0
  34. package/build/plugin/src/android/config-plugins/withAndroidResources.d.ts +7 -0
  35. package/build/plugin/src/android/config-plugins/withAndroidResources.d.ts.map +1 -0
  36. package/build/plugin/src/android/config-plugins/withAndroidResources.js +75 -0
  37. package/build/plugin/src/android/config-plugins/withAndroidResources.js.map +1 -0
  38. package/build/plugin/src/android/config-plugins/withAndroidTarget.d.ts +28 -0
  39. package/build/plugin/src/android/config-plugins/withAndroidTarget.d.ts.map +1 -0
  40. package/build/plugin/src/android/config-plugins/withAndroidTarget.js +28 -0
  41. package/build/plugin/src/android/config-plugins/withAndroidTarget.js.map +1 -0
  42. package/build/plugin/src/android/config-plugins/withGradleModule.d.ts +7 -0
  43. package/build/plugin/src/android/config-plugins/withGradleModule.d.ts.map +1 -0
  44. package/build/plugin/src/android/config-plugins/withGradleModule.js +86 -0
  45. package/build/plugin/src/android/config-plugins/withGradleModule.js.map +1 -0
  46. package/build/plugin/src/android/config-plugins/withGradleSettings.d.ts +7 -0
  47. package/build/plugin/src/android/config-plugins/withGradleSettings.d.ts.map +1 -0
  48. package/build/plugin/src/android/config-plugins/withGradleSettings.js +23 -0
  49. package/build/plugin/src/android/config-plugins/withGradleSettings.js.map +1 -0
  50. package/build/plugin/src/android/withAndroidAppBuildGradle.d.ts +7 -0
  51. package/build/plugin/src/android/withAndroidAppBuildGradle.d.ts.map +1 -0
  52. package/build/plugin/src/android/withAndroidAppBuildGradle.js +31 -0
  53. package/build/plugin/src/android/withAndroidAppBuildGradle.js.map +1 -0
  54. package/build/plugin/src/android/withAndroidKotlinGradleProperty.d.ts +3 -0
  55. package/build/plugin/src/android/withAndroidKotlinGradleProperty.d.ts.map +1 -0
  56. package/build/plugin/src/android/withAndroidKotlinGradleProperty.js +24 -0
  57. package/build/plugin/src/android/withAndroidKotlinGradleProperty.js.map +1 -0
  58. package/build/plugin/src/android/withAndroidProjectKotlinVersion.d.ts +3 -0
  59. package/build/plugin/src/android/withAndroidProjectKotlinVersion.d.ts.map +1 -0
  60. package/build/plugin/src/android/withAndroidProjectKotlinVersion.js +27 -0
  61. package/build/plugin/src/android/withAndroidProjectKotlinVersion.js.map +1 -0
  62. package/build/plugin/src/android/withAndroidTarget.d.ts +10 -0
  63. package/build/plugin/src/android/withAndroidTarget.d.ts.map +1 -0
  64. package/build/plugin/src/android/withAndroidTarget.js +22 -0
  65. package/build/plugin/src/android/withAndroidTarget.js.map +1 -0
  66. package/build/plugin/src/android/withAndroidWidget.d.ts +13 -0
  67. package/build/plugin/src/android/withAndroidWidget.d.ts.map +1 -0
  68. package/build/plugin/src/android/withAndroidWidget.js +564 -0
  69. package/build/plugin/src/android/withAndroidWidget.js.map +1 -0
  70. package/build/plugin/src/config.d.ts +141 -0
  71. package/build/plugin/src/config.d.ts.map +1 -0
  72. package/build/plugin/src/config.js +54 -0
  73. package/build/plugin/src/config.js.map +1 -0
  74. package/build/plugin/src/index.d.ts +9 -0
  75. package/build/plugin/src/index.d.ts.map +1 -0
  76. package/build/plugin/src/index.js +11 -0
  77. package/build/plugin/src/index.js.map +1 -0
  78. package/build/plugin/src/ios/config-plugins/withEntitlements.d.ts +11 -0
  79. package/build/plugin/src/ios/config-plugins/withEntitlements.d.ts.map +1 -0
  80. package/build/plugin/src/ios/config-plugins/withEntitlements.js +49 -0
  81. package/build/plugin/src/ios/config-plugins/withEntitlements.js.map +1 -0
  82. package/build/plugin/src/ios/config-plugins/withIOSTarget.d.ts +17 -0
  83. package/build/plugin/src/ios/config-plugins/withIOSTarget.d.ts.map +1 -0
  84. package/build/plugin/src/ios/config-plugins/withIOSTarget.js +152 -0
  85. package/build/plugin/src/ios/config-plugins/withIOSTarget.js.map +1 -0
  86. package/build/plugin/src/ios/config-plugins/withIosColorset.d.ts +8 -0
  87. package/build/plugin/src/ios/config-plugins/withIosColorset.d.ts.map +1 -0
  88. package/build/plugin/src/ios/config-plugins/withIosColorset.js +25 -0
  89. package/build/plugin/src/ios/config-plugins/withIosColorset.js.map +1 -0
  90. package/build/plugin/src/ios/config-plugins/withIosStickerPack.d.ts +8 -0
  91. package/build/plugin/src/ios/config-plugins/withIosStickerPack.d.ts.map +1 -0
  92. package/build/plugin/src/ios/config-plugins/withIosStickerPack.js +52 -0
  93. package/build/plugin/src/ios/config-plugins/withIosStickerPack.js.map +1 -0
  94. package/build/plugin/src/ios/config-plugins/withPodfile.d.ts +12 -0
  95. package/build/plugin/src/ios/config-plugins/withPodfile.d.ts.map +1 -0
  96. package/build/plugin/src/ios/config-plugins/withPodfile.js +162 -0
  97. package/build/plugin/src/ios/config-plugins/withPodfile.js.map +1 -0
  98. package/build/plugin/src/ios/config-plugins/withXcodeChanges.d.ts +15 -0
  99. package/build/plugin/src/ios/config-plugins/withXcodeChanges.d.ts.map +1 -0
  100. package/build/plugin/src/ios/config-plugins/withXcodeChanges.js +646 -0
  101. package/build/plugin/src/ios/config-plugins/withXcodeChanges.js.map +1 -0
  102. package/build/plugin/src/ios/target.d.ts +41 -0
  103. package/build/plugin/src/ios/target.d.ts.map +1 -0
  104. package/build/plugin/src/ios/target.js +574 -0
  105. package/build/plugin/src/ios/target.js.map +1 -0
  106. package/build/plugin/src/ios/utils/asset.d.ts +60 -0
  107. package/build/plugin/src/ios/utils/asset.d.ts.map +1 -0
  108. package/build/plugin/src/ios/utils/asset.js +375 -0
  109. package/build/plugin/src/ios/utils/asset.js.map +1 -0
  110. package/build/plugin/src/ios/utils/file.d.ts +33 -0
  111. package/build/plugin/src/ios/utils/file.d.ts.map +1 -0
  112. package/build/plugin/src/ios/utils/file.js +88 -0
  113. package/build/plugin/src/ios/utils/file.js.map +1 -0
  114. package/build/plugin/src/ios/utils/index.d.ts +12 -0
  115. package/build/plugin/src/ios/utils/index.d.ts.map +1 -0
  116. package/build/plugin/src/ios/utils/index.js +38 -0
  117. package/build/plugin/src/ios/utils/index.js.map +1 -0
  118. package/build/plugin/src/ios/utils/paths.d.ts +128 -0
  119. package/build/plugin/src/ios/utils/paths.d.ts.map +1 -0
  120. package/build/plugin/src/ios/utils/paths.js +141 -0
  121. package/build/plugin/src/ios/utils/paths.js.map +1 -0
  122. package/build/plugin/src/ios/utils/plist.d.ts +29 -0
  123. package/build/plugin/src/ios/utils/plist.d.ts.map +1 -0
  124. package/build/plugin/src/ios/utils/plist.js +114 -0
  125. package/build/plugin/src/ios/utils/plist.js.map +1 -0
  126. package/build/plugin/src/ios/utils/podfile.d.ts +82 -0
  127. package/build/plugin/src/ios/utils/podfile.d.ts.map +1 -0
  128. package/build/plugin/src/ios/utils/podfile.js +408 -0
  129. package/build/plugin/src/ios/utils/podfile.js.map +1 -0
  130. package/build/plugin/src/ios/utils/reactNativeSwift.d.ts +11 -0
  131. package/build/plugin/src/ios/utils/reactNativeSwift.d.ts.map +1 -0
  132. package/build/plugin/src/ios/utils/reactNativeSwift.js +263 -0
  133. package/build/plugin/src/ios/utils/reactNativeSwift.js.map +1 -0
  134. package/build/plugin/src/ios/utils/xcode.d.ts +185 -0
  135. package/build/plugin/src/ios/utils/xcode.d.ts.map +1 -0
  136. package/build/plugin/src/ios/utils/xcode.js +706 -0
  137. package/build/plugin/src/ios/utils/xcode.js.map +1 -0
  138. package/build/plugin/src/logger.d.ts +10 -0
  139. package/build/plugin/src/logger.d.ts.map +1 -0
  140. package/build/plugin/src/logger.js +62 -0
  141. package/build/plugin/src/logger.js.map +1 -0
  142. package/build/plugin/src/parseTargetConfig.d.ts +3 -0
  143. package/build/plugin/src/parseTargetConfig.d.ts.map +1 -0
  144. package/build/plugin/src/parseTargetConfig.js +113 -0
  145. package/build/plugin/src/parseTargetConfig.js.map +1 -0
  146. package/build/plugin/src/withTargetsDir.d.ts +6 -0
  147. package/build/plugin/src/withTargetsDir.d.ts.map +1 -0
  148. package/build/plugin/src/withTargetsDir.js +90 -0
  149. package/build/plugin/src/withTargetsDir.js.map +1 -0
  150. package/build/src/Target.d.ts +43 -0
  151. package/build/src/Target.d.ts.map +1 -0
  152. package/build/src/Target.js +128 -0
  153. package/build/src/Target.js.map +1 -0
  154. package/build/src/index.d.ts +9 -0
  155. package/build/src/index.d.ts.map +1 -0
  156. package/build/src/index.js +27 -0
  157. package/build/src/index.js.map +1 -0
  158. package/build/src/modules/extension/index.d.ts +18 -0
  159. package/build/src/modules/extension/index.d.ts.map +1 -0
  160. package/build/src/modules/extension/index.js +44 -0
  161. package/build/src/modules/extension/index.js.map +1 -0
  162. package/build/src/modules/messages/index.d.ts +40 -0
  163. package/build/src/modules/messages/index.d.ts.map +1 -0
  164. package/build/src/modules/messages/index.js +94 -0
  165. package/build/src/modules/messages/index.js.map +1 -0
  166. package/build/src/modules/storage/index.d.ts +16 -0
  167. package/build/src/modules/storage/index.d.ts.map +1 -0
  168. package/build/src/modules/storage/index.js +122 -0
  169. package/build/src/modules/storage/index.js.map +1 -0
  170. package/expo-module.config.json +17 -0
  171. package/ios/ExpoTargetsExtension.podspec +23 -0
  172. package/ios/ExpoTargetsExtensionModule.swift +181 -0
  173. package/ios/ExpoTargetsMessages.podspec +23 -0
  174. package/ios/ExpoTargetsMessagesModule.swift +267 -0
  175. package/ios/ExpoTargetsStorage.podspec +23 -0
  176. package/ios/ExpoTargetsStorageModule.swift +91 -0
  177. package/ios/Tests/.swiftlint.yml +52 -0
  178. package/ios/Tests/Helpers/MockExtensionContext.swift +58 -0
  179. package/ios/Tests/Helpers/MockUserDefaults.swift +70 -0
  180. package/ios/Tests/Helpers/MockWidgetCenter.swift +71 -0
  181. package/ios/Tests/Helpers/TestHelpers.swift +90 -0
  182. package/ios/Tests/Integration/TargetIntegrationTests.swift +478 -0
  183. package/ios/Tests/Main/AllTests.swift +80 -0
  184. package/ios/Tests/Package.swift +66 -0
  185. package/ios/Tests/Performance/StoragePerformanceTests.swift +461 -0
  186. package/ios/Tests/Unit/Extension/ExpoTargetsExtensionModuleTests.swift +501 -0
  187. package/ios/Tests/Unit/Storage/ExpoTargetsStorageModuleTests.swift +578 -0
  188. package/ios/Tests/Unit/Template/ShareExtensionTemplateTests.swift +421 -0
  189. package/ios/Tests/XCTestPlan.xctestplan +87 -0
  190. package/metro/src/index.ts +1 -0
  191. package/metro/src/withTargetsMetro.ts +247 -0
  192. package/metro/tsconfig.build.json +9 -0
  193. package/package.json +74 -0
  194. package/plugin/src/android/withAndroidAppBuildGradle.ts +34 -0
  195. package/plugin/src/android/withAndroidTarget.ts +26 -0
  196. package/plugin/src/android/withAndroidWidget.ts +778 -0
  197. package/plugin/src/config.ts +255 -0
  198. package/plugin/src/index.ts +19 -0
  199. package/plugin/src/ios/config-plugins/withEntitlements.ts +69 -0
  200. package/plugin/src/ios/config-plugins/withIOSTarget.ts +179 -0
  201. package/plugin/src/ios/config-plugins/withIosColorset.ts +29 -0
  202. package/plugin/src/ios/config-plugins/withIosStickerPack.ts +65 -0
  203. package/plugin/src/ios/config-plugins/withPodfile.ts +238 -0
  204. package/plugin/src/ios/config-plugins/withXcodeChanges.ts +891 -0
  205. package/plugin/src/ios/target.ts +668 -0
  206. package/plugin/src/ios/templates/MessagesViewController.swift +120 -0
  207. package/plugin/src/ios/templates/ReactNativeViewController.swift +240 -0
  208. package/plugin/src/ios/templates/action-extension-data.swift +106 -0
  209. package/plugin/src/ios/templates/clip-extension-data.swift +28 -0
  210. package/plugin/src/ios/templates/messages-extension-data.swift +28 -0
  211. package/plugin/src/ios/templates/share-extension-data.swift +113 -0
  212. package/plugin/src/ios/utils/asset.ts +490 -0
  213. package/plugin/src/ios/utils/file.ts +80 -0
  214. package/plugin/src/ios/utils/index.ts +12 -0
  215. package/plugin/src/ios/utils/paths.ts +253 -0
  216. package/plugin/src/ios/utils/plist.ts +101 -0
  217. package/plugin/src/ios/utils/podfile.ts +534 -0
  218. package/plugin/src/ios/utils/reactNativeSwift.ts +283 -0
  219. package/plugin/src/ios/utils/xcode.ts +989 -0
  220. package/plugin/src/logger.ts +63 -0
  221. package/plugin/src/parseTargetConfig.ts +115 -0
  222. package/plugin/src/types/normalize-colors.d.ts +3 -0
  223. package/plugin/src/withTargetsDir.ts +120 -0
  224. package/plugin/tsconfig.build.json +9 -0
  225. package/plugin/tsconfig.json +9 -0
  226. package/src/Target.ts +239 -0
  227. package/src/index.ts +52 -0
  228. package/src/modules/extension/index.ts +54 -0
  229. package/src/modules/messages/index.ts +124 -0
  230. package/src/modules/storage/index.ts +126 -0
  231. package/tsconfig.json +8 -0
@@ -0,0 +1,706 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ var _a;
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.addFileToBuildPhase = exports.addExternalFileReference = exports.addTargetToVirtualGroup = exports.ensureExpoTargetsGroup = exports.addTargetAssets = exports.removeDuplicateTargets = exports.findAllTargetsByProductName = exports.findTargetByProductName = exports.getMainAppBuildSettings = exports.removeBuildSetting = exports.applyBuildSettings = exports.setProductType = exports.configureAppClipEmbed = exports.configureAppExtensionEmbed = exports.addTargetDependency = exports.hasTargetDependency = exports.removeBuildPhases = exports.hasBuildPhase = exports.getApplicationNativeTarget = exports.getProjectName = exports.addBuildSourceFileToGroup = exports.addResourceFileToGroup = exports.ensureGroupRecursively = void 0;
31
+ const config_plugins_1 = require("@expo/config-plugins");
32
+ const path_1 = __importDefault(require("path"));
33
+ const File = __importStar(require("./file"));
34
+ const Paths = __importStar(require("./paths"));
35
+ /**
36
+ * High-level utilities for Xcode project manipulation in expo-targets.
37
+ * Wraps IOSConfig.XcodeUtils for consistency and extends with target-specific operations.
38
+ */
39
+ // Re-export commonly used utilities from IOSConfig.XcodeUtils
40
+ _a = config_plugins_1.IOSConfig.XcodeUtils, exports.ensureGroupRecursively = _a.ensureGroupRecursively, exports.addResourceFileToGroup = _a.addResourceFileToGroup, exports.addBuildSourceFileToGroup = _a.addBuildSourceFileToGroup, exports.getProjectName = _a.getProjectName, exports.getApplicationNativeTarget = _a.getApplicationNativeTarget;
41
+ /**
42
+ * Check if target already has a specific build phase type
43
+ */
44
+ function hasBuildPhase({ project, targetUuid, phaseType, }) {
45
+ const xcodeProject = project;
46
+ const target = xcodeProject.hash.project.objects.PBXNativeTarget[targetUuid];
47
+ if (!target || !target.buildPhases) {
48
+ return false;
49
+ }
50
+ const phaseSection = xcodeProject.hash.project.objects[phaseType];
51
+ if (!phaseSection) {
52
+ return false;
53
+ }
54
+ return target.buildPhases.some((phase) => {
55
+ const phaseUuid = phase.value;
56
+ return phaseSection[phaseUuid] !== undefined;
57
+ });
58
+ }
59
+ exports.hasBuildPhase = hasBuildPhase;
60
+ /**
61
+ * Remove build phases of a specific type from target
62
+ */
63
+ function removeBuildPhases({ project, targetUuid, phaseType, }) {
64
+ const xcodeProject = project;
65
+ const target = xcodeProject.hash.project.objects.PBXNativeTarget[targetUuid];
66
+ if (!target || !target.buildPhases) {
67
+ return;
68
+ }
69
+ const phaseSection = xcodeProject.hash.project.objects[phaseType];
70
+ if (!phaseSection) {
71
+ return;
72
+ }
73
+ // Find matching phase UUIDs
74
+ const phasesToRemove = [];
75
+ target.buildPhases.forEach((phase) => {
76
+ const phaseUuid = phase.value;
77
+ if (phaseSection[phaseUuid]) {
78
+ phasesToRemove.push(phaseUuid);
79
+ }
80
+ });
81
+ // Remove phases from target's buildPhases array
82
+ target.buildPhases = target.buildPhases.filter((phase) => !phasesToRemove.includes(phase.value));
83
+ // Remove phase objects and comments from section
84
+ phasesToRemove.forEach((phaseUuid) => {
85
+ delete phaseSection[phaseUuid];
86
+ delete phaseSection[`${phaseUuid}_comment`];
87
+ });
88
+ }
89
+ exports.removeBuildPhases = removeBuildPhases;
90
+ /**
91
+ * Check if target dependency already exists
92
+ */
93
+ function hasTargetDependency({ project, mainTargetUuid, dependentTargetUuid, }) {
94
+ const xcodeProject = project;
95
+ const mainTarget = xcodeProject.hash.project.objects.PBXNativeTarget[mainTargetUuid];
96
+ if (!mainTarget || !mainTarget.dependencies) {
97
+ return false;
98
+ }
99
+ const dependencies = xcodeProject.hash.project.objects.PBXTargetDependency;
100
+ if (!dependencies) {
101
+ return false;
102
+ }
103
+ return mainTarget.dependencies.some((dep) => {
104
+ const depUuid = dep.value;
105
+ const dependency = dependencies[depUuid];
106
+ return dependency && dependency.target === dependentTargetUuid;
107
+ });
108
+ }
109
+ exports.hasTargetDependency = hasTargetDependency;
110
+ /**
111
+ * Add target dependency from main app to extension/clip target.
112
+ * Ensures PBXTargetDependency and PBXContainerItemProxy sections exist.
113
+ */
114
+ function addTargetDependency({ project, mainTargetUuid, dependentTargetUuid, }) {
115
+ // Check if dependency already exists
116
+ if (hasTargetDependency({ project, mainTargetUuid, dependentTargetUuid })) {
117
+ return;
118
+ }
119
+ const xcodeProject = project;
120
+ // Ensure required sections exist
121
+ if (!xcodeProject.hash.project.objects['PBXTargetDependency']) {
122
+ xcodeProject.hash.project.objects['PBXTargetDependency'] = {};
123
+ }
124
+ if (!xcodeProject.hash.project.objects['PBXContainerItemProxy']) {
125
+ xcodeProject.hash.project.objects['PBXContainerItemProxy'] = {};
126
+ }
127
+ xcodeProject.addTargetDependency(mainTargetUuid, [dependentTargetUuid]);
128
+ }
129
+ exports.addTargetDependency = addTargetDependency;
130
+ /**
131
+ * Configure embed settings for app extension.
132
+ * Consolidates all app extensions into a SINGLE "Embed App Extensions" phase.
133
+ */
134
+ function configureAppExtensionEmbed({ project, targetProductName, }) {
135
+ const xcodeProject = project;
136
+ const buildFileSection = xcodeProject.hash.project.objects.PBXBuildFile;
137
+ const fileRefSection = xcodeProject.hash.project.objects.PBXFileReference;
138
+ const targetFileName = `${targetProductName}.appex`;
139
+ const ensureAttributes = (buildFile) => {
140
+ const desired = ['RemoveHeadersOnCopy', 'CodeSignOnCopy'];
141
+ if (!buildFile.settings || !Array.isArray(buildFile.settings.ATTRIBUTES)) {
142
+ buildFile.settings = { ATTRIBUTES: desired };
143
+ return;
144
+ }
145
+ const attrs = buildFile.settings.ATTRIBUTES;
146
+ desired.forEach((attr) => {
147
+ if (!attrs.includes(attr))
148
+ attrs.push(attr);
149
+ });
150
+ };
151
+ // Find and configure the PBXBuildFile for the extension (global scan)
152
+ let foundBuildFile = false;
153
+ for (const buildFileKey in buildFileSection) {
154
+ if (buildFileKey.endsWith('_comment'))
155
+ continue;
156
+ const buildFile = buildFileSection[buildFileKey];
157
+ if (buildFile?.fileRef) {
158
+ const fileRef = fileRefSection[buildFile.fileRef];
159
+ const refPath = fileRef?.path?.replace(/"/g, '');
160
+ const refName = fileRef?.name?.replace(/"/g, '');
161
+ if (refPath === targetFileName || refName === targetFileName) {
162
+ ensureAttributes(buildFile);
163
+ foundBuildFile = true;
164
+ break;
165
+ }
166
+ }
167
+ }
168
+ if (!foundBuildFile) {
169
+ console.warn(`[expo-targets] Could not find PBXBuildFile for ${targetProductName}.appex`);
170
+ }
171
+ // Find or create a SINGLE "Embed App Extensions" phase
172
+ const copyFilesPhases = xcodeProject.hash.project.objects.PBXCopyFilesBuildPhase;
173
+ // Step 1: Find existing "Embed App Extensions" phase (with proper name)
174
+ let primaryPhaseKey = null;
175
+ let primaryPhase = null;
176
+ for (const phaseKey in copyFilesPhases) {
177
+ if (phaseKey.endsWith('_comment'))
178
+ continue;
179
+ const phase = copyFilesPhases[phaseKey];
180
+ if (phase?.dstSubfolderSpec === 13 &&
181
+ (phase.name === '"Embed App Extensions"' ||
182
+ copyFilesPhases[`${phaseKey}_comment`] === 'Embed App Extensions')) {
183
+ primaryPhaseKey = phaseKey;
184
+ primaryPhase = phase;
185
+ break;
186
+ }
187
+ }
188
+ // Step 2: Consolidate - find all extension embedding phases and merge into primary
189
+ const phasesToMerge = [];
190
+ const extensionBuildFiles = new Set();
191
+ for (const phaseKey in copyFilesPhases) {
192
+ if (phaseKey.endsWith('_comment') || phaseKey === primaryPhaseKey)
193
+ continue;
194
+ const phase = copyFilesPhases[phaseKey];
195
+ if (phase?.dstSubfolderSpec === 13 && phase.files) {
196
+ // Check if this phase contains any .appex files
197
+ let hasAppExtension = false;
198
+ phase.files.forEach((file) => {
199
+ const buildFileKey = file.value;
200
+ const buildFile = buildFileSection?.[buildFileKey];
201
+ if (!buildFile?.fileRef)
202
+ return;
203
+ const fileRef = fileRefSection?.[buildFile.fileRef];
204
+ const refPath = fileRef?.path?.replace(/"/g, '');
205
+ const refName = fileRef?.name?.replace(/"/g, '');
206
+ if (refPath?.endsWith('.appex') || refName?.endsWith('.appex')) {
207
+ hasAppExtension = true;
208
+ extensionBuildFiles.add(buildFileKey);
209
+ ensureAttributes(buildFile);
210
+ }
211
+ });
212
+ if (hasAppExtension) {
213
+ if (primaryPhaseKey) {
214
+ phasesToMerge.push(phaseKey);
215
+ }
216
+ else {
217
+ // Use this as the primary phase
218
+ primaryPhaseKey = phaseKey;
219
+ primaryPhase = phase;
220
+ }
221
+ }
222
+ }
223
+ }
224
+ // Step 3: If we found a primary phase, merge all extensions into it
225
+ if (primaryPhaseKey && primaryPhase) {
226
+ // Rename to standard name
227
+ primaryPhase.name = '"Embed App Extensions"';
228
+ copyFilesPhases[`${primaryPhaseKey}_comment`] = 'Embed App Extensions';
229
+ // Merge build files from other phases
230
+ if (!primaryPhase.files) {
231
+ primaryPhase.files = [];
232
+ }
233
+ const existingFiles = new Set(primaryPhase.files.map((f) => f.value));
234
+ phasesToMerge.forEach((phaseKey) => {
235
+ const phase = copyFilesPhases[phaseKey];
236
+ if (phase?.files) {
237
+ phase.files.forEach((file) => {
238
+ const buildFileKey = file.value;
239
+ if (extensionBuildFiles.has(buildFileKey) &&
240
+ !existingFiles.has(buildFileKey)) {
241
+ primaryPhase.files.push(file);
242
+ existingFiles.add(buildFileKey);
243
+ }
244
+ });
245
+ }
246
+ });
247
+ // Step 4: Remove duplicate phases (mark for deletion by removing from main app build phases)
248
+ if (phasesToMerge.length > 0) {
249
+ // Get the main app target by finding the first application target
250
+ const nativeTargets = xcodeProject.hash.project.objects.PBXNativeTarget;
251
+ let mainAppTarget = null;
252
+ for (const targetKey in nativeTargets) {
253
+ if (targetKey.endsWith('_comment'))
254
+ continue;
255
+ const target = nativeTargets[targetKey];
256
+ if (target?.productType === '"com.apple.product-type.application"') {
257
+ mainAppTarget = target;
258
+ break;
259
+ }
260
+ }
261
+ if (mainAppTarget?.buildPhases) {
262
+ mainAppTarget.buildPhases = mainAppTarget.buildPhases.filter((phase) => !phasesToMerge.includes(phase.value));
263
+ }
264
+ }
265
+ }
266
+ }
267
+ exports.configureAppExtensionEmbed = configureAppExtensionEmbed;
268
+ /**
269
+ * Configure embed settings for App Clip.
270
+ * Creates "Embed App Clips" phase with proper settings.
271
+ */
272
+ function configureAppClipEmbed({ project, mainTargetUuid, target, targetProductName, }) {
273
+ const xcodeProject = project;
274
+ // Get the App Clip product reference
275
+ const appClipFileRef = target.pbxNativeTarget?.productReference || target.target?.productReference;
276
+ if (!appClipFileRef) {
277
+ console.warn(`[expo-targets] Could not find product reference for ${targetProductName}.app`);
278
+ return;
279
+ }
280
+ // Create Copy Files build phase for App Clips
281
+ const embedPhaseResult = xcodeProject.addBuildPhase([], 'PBXCopyFilesBuildPhase', 'Embed App Clips', mainTargetUuid);
282
+ const embedPhaseUuid = embedPhaseResult?.uuid || embedPhaseResult;
283
+ if (!embedPhaseUuid) {
284
+ console.warn(`[expo-targets] Failed to create Embed App Clips phase`);
285
+ return;
286
+ }
287
+ const copyFilesPhases = xcodeProject.hash.project.objects.PBXCopyFilesBuildPhase;
288
+ const phase = copyFilesPhases[embedPhaseUuid];
289
+ if (!phase) {
290
+ console.warn(`[expo-targets] Could not find phase object for UUID: ${embedPhaseUuid}`);
291
+ return;
292
+ }
293
+ // Configure phase for App Clips
294
+ phase.dstPath = '"$(CONTENTS_FOLDER_PATH)/AppClips"';
295
+ phase.dstSubfolderSpec = 16;
296
+ phase.name = '"Embed App Clips"';
297
+ // Create a PBXBuildFile for the App Clip
298
+ const buildFileUuid = xcodeProject.generateUuid();
299
+ const buildFileSection = xcodeProject.hash.project.objects.PBXBuildFile;
300
+ buildFileSection[buildFileUuid] = {
301
+ isa: 'PBXBuildFile',
302
+ fileRef: appClipFileRef,
303
+ settings: {
304
+ ATTRIBUTES: ['RemoveHeadersOnCopy'],
305
+ },
306
+ };
307
+ buildFileSection[`${buildFileUuid}_comment`] =
308
+ `${targetProductName}.app in Embed App Clips`;
309
+ // Add the build file to the phase
310
+ if (!phase.files) {
311
+ phase.files = [];
312
+ }
313
+ phase.files.push({
314
+ value: buildFileUuid,
315
+ comment: `${targetProductName}.app in Embed App Clips`,
316
+ });
317
+ }
318
+ exports.configureAppClipEmbed = configureAppClipEmbed;
319
+ /**
320
+ * Set product type for a native target.
321
+ * Useful for App Clips which need special product type after creation.
322
+ */
323
+ function setProductType({ target, productType, }) {
324
+ const nativeTarget = target.pbxNativeTarget || target.target;
325
+ if (nativeTarget) {
326
+ nativeTarget.productType = productType;
327
+ }
328
+ }
329
+ exports.setProductType = setProductType;
330
+ /**
331
+ * Apply build settings to all configurations of a target.
332
+ */
333
+ function applyBuildSettings({ project, target, buildSettings, verbose = false, logger, }) {
334
+ const xcodeProject = project;
335
+ const targetBuildConfigId = target.pbxNativeTarget?.buildConfigurationList ||
336
+ target.target?.buildConfigurationList;
337
+ const buildConfigList = xcodeProject.pbxXCConfigurationList()[targetBuildConfigId];
338
+ if (!buildConfigList?.buildConfigurations) {
339
+ if (logger) {
340
+ logger.log('No build configurations found for target');
341
+ }
342
+ else {
343
+ console.warn(`[expo-targets] No build configurations found for target`);
344
+ }
345
+ return;
346
+ }
347
+ buildConfigList.buildConfigurations.forEach((config) => {
348
+ const configSection = xcodeProject.pbxXCBuildConfigurationSection()[config.value];
349
+ const configName = configSection?.name;
350
+ if (verbose) {
351
+ if (logger) {
352
+ logger.log(` Configuring ${configName} build settings`);
353
+ }
354
+ else {
355
+ console.log(`[expo-targets] Configuring ${configName} build settings`);
356
+ }
357
+ }
358
+ if (configSection?.buildSettings) {
359
+ Object.entries(buildSettings).forEach(([key, value]) => {
360
+ configSection.buildSettings[key] = value;
361
+ if (verbose &&
362
+ (key === 'SWIFT_VERSION' || key === 'IPHONEOS_DEPLOYMENT_TARGET')) {
363
+ if (logger) {
364
+ logger.log(` Set ${key}=${value} to ${configName}`);
365
+ }
366
+ else {
367
+ console.log(`[expo-targets] Set ${key}=${value} to ${configName}`);
368
+ }
369
+ }
370
+ });
371
+ }
372
+ });
373
+ }
374
+ exports.applyBuildSettings = applyBuildSettings;
375
+ /**
376
+ * Remove a build setting from all configurations of a target.
377
+ */
378
+ function removeBuildSetting({ project, target, settingKey, verbose = false, logger, }) {
379
+ const xcodeProject = project;
380
+ const targetBuildConfigId = target.pbxNativeTarget?.buildConfigurationList ||
381
+ target.target?.buildConfigurationList;
382
+ const buildConfigList = xcodeProject.pbxXCConfigurationList()[targetBuildConfigId];
383
+ if (!buildConfigList?.buildConfigurations)
384
+ return;
385
+ buildConfigList.buildConfigurations.forEach((config) => {
386
+ const configSection = xcodeProject.pbxXCBuildConfigurationSection()[config.value];
387
+ if (configSection?.buildSettings?.[settingKey]) {
388
+ delete configSection.buildSettings[settingKey];
389
+ if (verbose) {
390
+ if (logger) {
391
+ logger.log(` Removed ${settingKey} from ${configSection.name}`);
392
+ }
393
+ else {
394
+ console.log(`[expo-targets] Removed ${settingKey} from ${configSection.name}`);
395
+ }
396
+ }
397
+ }
398
+ });
399
+ }
400
+ exports.removeBuildSetting = removeBuildSetting;
401
+ /**
402
+ * Get build settings from the main app target.
403
+ */
404
+ function getMainAppBuildSettings({ project, mainTarget, }) {
405
+ const xcodeProject = project;
406
+ const mainTargetBuildConfigId = mainTarget.target?.buildConfigurationList;
407
+ const mainBuildConfigList = xcodeProject.pbxXCConfigurationList()[mainTargetBuildConfigId];
408
+ const mainBuildConfig = mainBuildConfigList?.buildConfigurations?.[0]?.value;
409
+ return mainBuildConfig
410
+ ? xcodeProject.pbxXCBuildConfigurationSection()[mainBuildConfig]
411
+ ?.buildSettings || {}
412
+ : {};
413
+ }
414
+ exports.getMainAppBuildSettings = getMainAppBuildSettings;
415
+ /**
416
+ * Find a target UUID by its product name.
417
+ */
418
+ function findTargetByProductName({ project, productName, }) {
419
+ const xcodeProject = project;
420
+ const pbxNativeTargetSection = xcodeProject.hash.project.objects.PBXNativeTarget || {};
421
+ for (const key in pbxNativeTargetSection) {
422
+ if (key.endsWith('_comment'))
423
+ continue;
424
+ const target = pbxNativeTargetSection[key];
425
+ if (target?.name === productName) {
426
+ return key;
427
+ }
428
+ }
429
+ return undefined;
430
+ }
431
+ exports.findTargetByProductName = findTargetByProductName;
432
+ /**
433
+ * Find all target UUIDs with a given product name (detects duplicates)
434
+ */
435
+ function findAllTargetsByProductName({ project, productName, }) {
436
+ const xcodeProject = project;
437
+ const pbxNativeTargetSection = xcodeProject.hash.project.objects.PBXNativeTarget || {};
438
+ const matchingTargets = [];
439
+ for (const key in pbxNativeTargetSection) {
440
+ if (key.endsWith('_comment'))
441
+ continue;
442
+ const target = pbxNativeTargetSection[key];
443
+ if (target?.name === productName) {
444
+ matchingTargets.push(key);
445
+ }
446
+ }
447
+ return matchingTargets;
448
+ }
449
+ exports.findAllTargetsByProductName = findAllTargetsByProductName;
450
+ /**
451
+ * Remove duplicate targets with the same product name, keeping only the first one
452
+ */
453
+ function removeDuplicateTargets({ project, productName, }) {
454
+ const allTargets = findAllTargetsByProductName({ project, productName });
455
+ if (allTargets.length <= 1) {
456
+ return 0;
457
+ }
458
+ const xcodeProject = project;
459
+ const [keepTarget, ...duplicates] = allTargets;
460
+ console.log(`[expo-targets] Found ${allTargets.length} targets named "${productName}", removing ${duplicates.length} duplicate(s)`);
461
+ duplicates.forEach((targetUuid) => {
462
+ // Remove from PBXNativeTarget section
463
+ const pbxNativeTargetSection = xcodeProject.hash.project.objects.PBXNativeTarget;
464
+ if (pbxNativeTargetSection) {
465
+ delete pbxNativeTargetSection[targetUuid];
466
+ delete pbxNativeTargetSection[`${targetUuid}_comment`];
467
+ }
468
+ // Remove from project targets list
469
+ const project = xcodeProject.hash.project.objects.PBXProject;
470
+ for (const projectKey in project) {
471
+ if (projectKey.endsWith('_comment'))
472
+ continue;
473
+ const projectObj = project[projectKey];
474
+ if (projectObj?.targets) {
475
+ projectObj.targets = projectObj.targets.filter((t) => t.value !== targetUuid);
476
+ }
477
+ }
478
+ // Remove build configuration list
479
+ const target = xcodeProject.hash.project.objects.PBXNativeTarget?.[targetUuid];
480
+ if (target?.buildConfigurationList) {
481
+ const configListUuid = target.buildConfigurationList;
482
+ const configListSection = xcodeProject.hash.project.objects.XCConfigurationList;
483
+ if (configListSection) {
484
+ delete configListSection[configListUuid];
485
+ delete configListSection[`${configListUuid}_comment`];
486
+ }
487
+ }
488
+ console.log(`[expo-targets] Removed duplicate target: ${targetUuid}`);
489
+ });
490
+ return duplicates.length;
491
+ }
492
+ exports.removeDuplicateTargets = removeDuplicateTargets;
493
+ /**
494
+ * Add Assets.xcassets to a target's Resources build phase if it exists.
495
+ */
496
+ function addTargetAssets({ platformProjectRoot, targetName, targetUuid, xcodeProject, isStickers, }) {
497
+ const targetProductName = Paths.sanitizeTargetName(targetName);
498
+ const assetsPath = Paths.getAssetsXcassetsPath({
499
+ platformProjectRoot,
500
+ targetName,
501
+ isStickers,
502
+ });
503
+ // Get the actual group directory name (includes 'Target' suffix)
504
+ const targetGroupPath = Paths.getTargetGroupPath({
505
+ platformProjectRoot,
506
+ targetName,
507
+ });
508
+ const targetDirName = path_1.default.basename(targetGroupPath);
509
+ if (File.isDirectory(assetsPath)) {
510
+ const assetsFolderName = isStickers
511
+ ? 'Stickers.xcassets'
512
+ : 'Assets.xcassets';
513
+ console.log(`[expo-targets] Found ${assetsFolderName}, adding to ${targetProductName}...`);
514
+ // Add Assets.xcassets as a resource file
515
+ const relativePath = path_1.default.relative(platformProjectRoot, assetsPath);
516
+ (0, exports.addResourceFileToGroup)({
517
+ filepath: relativePath,
518
+ groupName: targetDirName,
519
+ project: xcodeProject,
520
+ isBuildFile: true,
521
+ verbose: true,
522
+ targetUuid,
523
+ });
524
+ console.log(`[expo-targets] ✓ Added ${assetsFolderName} to ${targetProductName} Resources build phase`);
525
+ }
526
+ else {
527
+ const assetsFolderName = isStickers
528
+ ? 'Stickers.xcassets'
529
+ : 'Assets.xcassets';
530
+ console.log(`[expo-targets] ${assetsFolderName} directory not found at: ${assetsPath}`);
531
+ }
532
+ }
533
+ exports.addTargetAssets = addTargetAssets;
534
+ /**
535
+ * ============================================================================
536
+ * NEW: Virtual Group Helpers for Reference-in-Place
537
+ * ============================================================================
538
+ * These functions create and manage the "expo:targets" virtual group in Xcode,
539
+ * which contains references to files outside the ios/ directory.
540
+ */
541
+ /**
542
+ * Ensure the virtual "expo:targets" group exists in Xcode.
543
+ * This group contains references to files outside ios/ directory.
544
+ * Returns the UUID of the expo:targets group.
545
+ */
546
+ function ensureExpoTargetsGroup({ project, }) {
547
+ const xcodeProject = project;
548
+ // Get the root project object
549
+ const rootObject = xcodeProject.hash.project.rootObject;
550
+ const projectObject = xcodeProject.hash.project.objects.PBXProject[rootObject];
551
+ // Get the main group UUID from the project object
552
+ const mainGroupUuid = projectObject.mainGroup;
553
+ const mainGroup = xcodeProject.hash.project.objects.PBXGroup[mainGroupUuid];
554
+ // Check if expo:targets already exists
555
+ const existingGroup = Object.entries(xcodeProject.hash.project.objects.PBXGroup).find(([_, group]) => group.name === '"expo:targets"');
556
+ if (existingGroup) {
557
+ return existingGroup[0];
558
+ }
559
+ // Create new virtual group
560
+ const groupUuid = xcodeProject.generateUuid();
561
+ xcodeProject.hash.project.objects.PBXGroup[groupUuid] = {
562
+ isa: 'PBXGroup',
563
+ children: [],
564
+ name: '"expo:targets"',
565
+ sourceTree: '"<group>"',
566
+ };
567
+ xcodeProject.hash.project.objects.PBXGroup[`${groupUuid}_comment`] =
568
+ 'expo:targets';
569
+ // Add to main group
570
+ if (!mainGroup.children) {
571
+ mainGroup.children = [];
572
+ }
573
+ mainGroup.children.push({
574
+ value: groupUuid,
575
+ comment: 'expo:targets',
576
+ });
577
+ return groupUuid;
578
+ }
579
+ exports.ensureExpoTargetsGroup = ensureExpoTargetsGroup;
580
+ /**
581
+ * Add target subfolder to expo:targets virtual group.
582
+ * Returns the group UUID for the target.
583
+ */
584
+ function addTargetToVirtualGroup({ project, targetName, virtualGroupUuid, }) {
585
+ const xcodeProject = project;
586
+ // Check if target group already exists
587
+ const virtualGroup = xcodeProject.hash.project.objects.PBXGroup[virtualGroupUuid];
588
+ if (virtualGroup && virtualGroup.children) {
589
+ const existingTarget = virtualGroup.children.find((child) => child.comment === targetName);
590
+ if (existingTarget) {
591
+ return existingTarget.value;
592
+ }
593
+ }
594
+ const targetGroupUuid = xcodeProject.generateUuid();
595
+ xcodeProject.hash.project.objects.PBXGroup[targetGroupUuid] = {
596
+ isa: 'PBXGroup',
597
+ children: [],
598
+ name: `"${targetName}"`,
599
+ sourceTree: '"<group>"',
600
+ };
601
+ xcodeProject.hash.project.objects.PBXGroup[`${targetGroupUuid}_comment`] =
602
+ targetName;
603
+ // Add to virtual group
604
+ if (!virtualGroup.children) {
605
+ virtualGroup.children = [];
606
+ }
607
+ virtualGroup.children.push({
608
+ value: targetGroupUuid,
609
+ comment: targetName,
610
+ });
611
+ return targetGroupUuid;
612
+ }
613
+ exports.addTargetToVirtualGroup = addTargetToVirtualGroup;
614
+ /**
615
+ * Add file reference to group, pointing to external path.
616
+ * Returns the file reference UUID.
617
+ */
618
+ function addExternalFileReference({ project, groupUuid, filePath, fileName, fileType, }) {
619
+ const xcodeProject = project;
620
+ // Determine file type
621
+ let lastKnownFileType = fileType || 'sourcecode.swift';
622
+ if (fileName.endsWith('.xcassets')) {
623
+ lastKnownFileType = 'folder.assetcatalog';
624
+ }
625
+ else if (fileName.endsWith('.swift')) {
626
+ lastKnownFileType = 'sourcecode.swift';
627
+ }
628
+ else if (fileName.endsWith('.h')) {
629
+ lastKnownFileType = 'sourcecode.c.h';
630
+ }
631
+ else if (fileName.endsWith('.m')) {
632
+ lastKnownFileType = 'sourcecode.c.objc';
633
+ }
634
+ const fileRefUuid = xcodeProject.generateUuid();
635
+ xcodeProject.hash.project.objects.PBXFileReference[fileRefUuid] = {
636
+ isa: 'PBXFileReference',
637
+ lastKnownFileType,
638
+ name: `"${fileName}"`,
639
+ path: `"${filePath}"`,
640
+ sourceTree: '"<group>"',
641
+ };
642
+ xcodeProject.hash.project.objects.PBXFileReference[`${fileRefUuid}_comment`] =
643
+ fileName;
644
+ // Add to group
645
+ const group = xcodeProject.hash.project.objects.PBXGroup[groupUuid];
646
+ if (!group.children) {
647
+ group.children = [];
648
+ }
649
+ // Check if file already exists in group
650
+ const existingFile = group.children.find((child) => child.comment === fileName);
651
+ if (!existingFile) {
652
+ group.children.push({
653
+ value: fileRefUuid,
654
+ comment: fileName,
655
+ });
656
+ }
657
+ return fileRefUuid;
658
+ }
659
+ exports.addExternalFileReference = addExternalFileReference;
660
+ /**
661
+ * Add file to specific build phase by file reference UUID.
662
+ */
663
+ function addFileToBuildPhase({ project, targetUuid, fileRefUuid, phaseType, }) {
664
+ const xcodeProject = project;
665
+ const target = xcodeProject.hash.project.objects.PBXNativeTarget[targetUuid];
666
+ if (!target || !target.buildPhases) {
667
+ throw new Error(`Target ${targetUuid} not found or has no build phases`);
668
+ }
669
+ // Find the build phase
670
+ const phaseUuid = target.buildPhases.find((phase) => {
671
+ const phaseObj = xcodeProject.hash.project.objects[phaseType][phase.value];
672
+ return phaseObj !== undefined;
673
+ })?.value;
674
+ if (!phaseUuid) {
675
+ throw new Error(`Build phase ${phaseType} not found for target ${targetUuid}`);
676
+ }
677
+ const phase = xcodeProject.hash.project.objects[phaseType][phaseUuid];
678
+ // Check if file already exists in build phase
679
+ if (phase.files) {
680
+ const existingFile = phase.files.find((file) => {
681
+ const buildFile = xcodeProject.hash.project.objects.PBXBuildFile[file.value];
682
+ return buildFile && buildFile.fileRef === fileRefUuid;
683
+ });
684
+ if (existingFile) {
685
+ return; // Already added
686
+ }
687
+ }
688
+ // Create PBXBuildFile
689
+ const buildFileUuid = xcodeProject.generateUuid();
690
+ xcodeProject.hash.project.objects.PBXBuildFile[buildFileUuid] = {
691
+ isa: 'PBXBuildFile',
692
+ fileRef: fileRefUuid,
693
+ };
694
+ xcodeProject.hash.project.objects.PBXBuildFile[`${buildFileUuid}_comment`] =
695
+ `Referenced file in ${phaseType}`;
696
+ // Add to phase
697
+ if (!phase.files) {
698
+ phase.files = [];
699
+ }
700
+ phase.files.push({
701
+ value: buildFileUuid,
702
+ comment: `Referenced file`,
703
+ });
704
+ }
705
+ exports.addFileToBuildPhase = addFileToBuildPhase;
706
+ //# sourceMappingURL=xcode.js.map