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.
- package/.eslintrc.js +2 -0
- package/README.md +244 -0
- package/android/build.gradle +22 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsLogger.kt +98 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsReceiver.kt +136 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsRemoteViewsProvider.kt +72 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsWidgetProvider.kt +47 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsWidgetSync.kt +78 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsWidgetUpdateReceiver.kt +30 -0
- package/android/src/main/java/expo/modules/targets/extension/ExpoTargetsExtensionModule.kt +27 -0
- package/android/src/main/java/expo/modules/targets/messages/ExpoTargetsMessagesModule.kt +40 -0
- package/android/src/main/java/expo/modules/targets/storage/ExpoTargetsStorageModule.kt +119 -0
- package/app.plugin.js +1 -0
- package/build/metro/src/index.d.ts +2 -0
- package/build/metro/src/index.d.ts.map +1 -0
- package/build/metro/src/index.js +6 -0
- package/build/metro/src/index.js.map +1 -0
- package/build/metro/src/withTargetsMetro.d.ts +6 -0
- package/build/metro/src/withTargetsMetro.d.ts.map +1 -0
- package/build/metro/src/withTargetsMetro.js +171 -0
- package/build/metro/src/withTargetsMetro.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidColors.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withAndroidColors.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidColors.js +56 -0
- package/build/plugin/src/android/config-plugins/withAndroidColors.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidManifest.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withAndroidManifest.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidManifest.js +70 -0
- package/build/plugin/src/android/config-plugins/withAndroidManifest.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidModule.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withAndroidModule.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidModule.js +41 -0
- package/build/plugin/src/android/config-plugins/withAndroidModule.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidResources.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withAndroidResources.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidResources.js +75 -0
- package/build/plugin/src/android/config-plugins/withAndroidResources.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidTarget.d.ts +28 -0
- package/build/plugin/src/android/config-plugins/withAndroidTarget.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidTarget.js +28 -0
- package/build/plugin/src/android/config-plugins/withAndroidTarget.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withGradleModule.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withGradleModule.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withGradleModule.js +86 -0
- package/build/plugin/src/android/config-plugins/withGradleModule.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withGradleSettings.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withGradleSettings.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withGradleSettings.js +23 -0
- package/build/plugin/src/android/config-plugins/withGradleSettings.js.map +1 -0
- package/build/plugin/src/android/withAndroidAppBuildGradle.d.ts +7 -0
- package/build/plugin/src/android/withAndroidAppBuildGradle.d.ts.map +1 -0
- package/build/plugin/src/android/withAndroidAppBuildGradle.js +31 -0
- package/build/plugin/src/android/withAndroidAppBuildGradle.js.map +1 -0
- package/build/plugin/src/android/withAndroidKotlinGradleProperty.d.ts +3 -0
- package/build/plugin/src/android/withAndroidKotlinGradleProperty.d.ts.map +1 -0
- package/build/plugin/src/android/withAndroidKotlinGradleProperty.js +24 -0
- package/build/plugin/src/android/withAndroidKotlinGradleProperty.js.map +1 -0
- package/build/plugin/src/android/withAndroidProjectKotlinVersion.d.ts +3 -0
- package/build/plugin/src/android/withAndroidProjectKotlinVersion.d.ts.map +1 -0
- package/build/plugin/src/android/withAndroidProjectKotlinVersion.js +27 -0
- package/build/plugin/src/android/withAndroidProjectKotlinVersion.js.map +1 -0
- package/build/plugin/src/android/withAndroidTarget.d.ts +10 -0
- package/build/plugin/src/android/withAndroidTarget.d.ts.map +1 -0
- package/build/plugin/src/android/withAndroidTarget.js +22 -0
- package/build/plugin/src/android/withAndroidTarget.js.map +1 -0
- package/build/plugin/src/android/withAndroidWidget.d.ts +13 -0
- package/build/plugin/src/android/withAndroidWidget.d.ts.map +1 -0
- package/build/plugin/src/android/withAndroidWidget.js +564 -0
- package/build/plugin/src/android/withAndroidWidget.js.map +1 -0
- package/build/plugin/src/config.d.ts +141 -0
- package/build/plugin/src/config.d.ts.map +1 -0
- package/build/plugin/src/config.js +54 -0
- package/build/plugin/src/config.js.map +1 -0
- package/build/plugin/src/index.d.ts +9 -0
- package/build/plugin/src/index.d.ts.map +1 -0
- package/build/plugin/src/index.js +11 -0
- package/build/plugin/src/index.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withEntitlements.d.ts +11 -0
- package/build/plugin/src/ios/config-plugins/withEntitlements.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withEntitlements.js +49 -0
- package/build/plugin/src/ios/config-plugins/withEntitlements.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIOSTarget.d.ts +17 -0
- package/build/plugin/src/ios/config-plugins/withIOSTarget.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIOSTarget.js +152 -0
- package/build/plugin/src/ios/config-plugins/withIOSTarget.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIosColorset.d.ts +8 -0
- package/build/plugin/src/ios/config-plugins/withIosColorset.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIosColorset.js +25 -0
- package/build/plugin/src/ios/config-plugins/withIosColorset.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIosStickerPack.d.ts +8 -0
- package/build/plugin/src/ios/config-plugins/withIosStickerPack.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIosStickerPack.js +52 -0
- package/build/plugin/src/ios/config-plugins/withIosStickerPack.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withPodfile.d.ts +12 -0
- package/build/plugin/src/ios/config-plugins/withPodfile.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withPodfile.js +162 -0
- package/build/plugin/src/ios/config-plugins/withPodfile.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withXcodeChanges.d.ts +15 -0
- package/build/plugin/src/ios/config-plugins/withXcodeChanges.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withXcodeChanges.js +646 -0
- package/build/plugin/src/ios/config-plugins/withXcodeChanges.js.map +1 -0
- package/build/plugin/src/ios/target.d.ts +41 -0
- package/build/plugin/src/ios/target.d.ts.map +1 -0
- package/build/plugin/src/ios/target.js +574 -0
- package/build/plugin/src/ios/target.js.map +1 -0
- package/build/plugin/src/ios/utils/asset.d.ts +60 -0
- package/build/plugin/src/ios/utils/asset.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/asset.js +375 -0
- package/build/plugin/src/ios/utils/asset.js.map +1 -0
- package/build/plugin/src/ios/utils/file.d.ts +33 -0
- package/build/plugin/src/ios/utils/file.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/file.js +88 -0
- package/build/plugin/src/ios/utils/file.js.map +1 -0
- package/build/plugin/src/ios/utils/index.d.ts +12 -0
- package/build/plugin/src/ios/utils/index.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/index.js +38 -0
- package/build/plugin/src/ios/utils/index.js.map +1 -0
- package/build/plugin/src/ios/utils/paths.d.ts +128 -0
- package/build/plugin/src/ios/utils/paths.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/paths.js +141 -0
- package/build/plugin/src/ios/utils/paths.js.map +1 -0
- package/build/plugin/src/ios/utils/plist.d.ts +29 -0
- package/build/plugin/src/ios/utils/plist.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/plist.js +114 -0
- package/build/plugin/src/ios/utils/plist.js.map +1 -0
- package/build/plugin/src/ios/utils/podfile.d.ts +82 -0
- package/build/plugin/src/ios/utils/podfile.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/podfile.js +408 -0
- package/build/plugin/src/ios/utils/podfile.js.map +1 -0
- package/build/plugin/src/ios/utils/reactNativeSwift.d.ts +11 -0
- package/build/plugin/src/ios/utils/reactNativeSwift.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/reactNativeSwift.js +263 -0
- package/build/plugin/src/ios/utils/reactNativeSwift.js.map +1 -0
- package/build/plugin/src/ios/utils/xcode.d.ts +185 -0
- package/build/plugin/src/ios/utils/xcode.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/xcode.js +706 -0
- package/build/plugin/src/ios/utils/xcode.js.map +1 -0
- package/build/plugin/src/logger.d.ts +10 -0
- package/build/plugin/src/logger.d.ts.map +1 -0
- package/build/plugin/src/logger.js +62 -0
- package/build/plugin/src/logger.js.map +1 -0
- package/build/plugin/src/parseTargetConfig.d.ts +3 -0
- package/build/plugin/src/parseTargetConfig.d.ts.map +1 -0
- package/build/plugin/src/parseTargetConfig.js +113 -0
- package/build/plugin/src/parseTargetConfig.js.map +1 -0
- package/build/plugin/src/withTargetsDir.d.ts +6 -0
- package/build/plugin/src/withTargetsDir.d.ts.map +1 -0
- package/build/plugin/src/withTargetsDir.js +90 -0
- package/build/plugin/src/withTargetsDir.js.map +1 -0
- package/build/src/Target.d.ts +43 -0
- package/build/src/Target.d.ts.map +1 -0
- package/build/src/Target.js +128 -0
- package/build/src/Target.js.map +1 -0
- package/build/src/index.d.ts +9 -0
- package/build/src/index.d.ts.map +1 -0
- package/build/src/index.js +27 -0
- package/build/src/index.js.map +1 -0
- package/build/src/modules/extension/index.d.ts +18 -0
- package/build/src/modules/extension/index.d.ts.map +1 -0
- package/build/src/modules/extension/index.js +44 -0
- package/build/src/modules/extension/index.js.map +1 -0
- package/build/src/modules/messages/index.d.ts +40 -0
- package/build/src/modules/messages/index.d.ts.map +1 -0
- package/build/src/modules/messages/index.js +94 -0
- package/build/src/modules/messages/index.js.map +1 -0
- package/build/src/modules/storage/index.d.ts +16 -0
- package/build/src/modules/storage/index.d.ts.map +1 -0
- package/build/src/modules/storage/index.js +122 -0
- package/build/src/modules/storage/index.js.map +1 -0
- package/expo-module.config.json +17 -0
- package/ios/ExpoTargetsExtension.podspec +23 -0
- package/ios/ExpoTargetsExtensionModule.swift +181 -0
- package/ios/ExpoTargetsMessages.podspec +23 -0
- package/ios/ExpoTargetsMessagesModule.swift +267 -0
- package/ios/ExpoTargetsStorage.podspec +23 -0
- package/ios/ExpoTargetsStorageModule.swift +91 -0
- package/ios/Tests/.swiftlint.yml +52 -0
- package/ios/Tests/Helpers/MockExtensionContext.swift +58 -0
- package/ios/Tests/Helpers/MockUserDefaults.swift +70 -0
- package/ios/Tests/Helpers/MockWidgetCenter.swift +71 -0
- package/ios/Tests/Helpers/TestHelpers.swift +90 -0
- package/ios/Tests/Integration/TargetIntegrationTests.swift +478 -0
- package/ios/Tests/Main/AllTests.swift +80 -0
- package/ios/Tests/Package.swift +66 -0
- package/ios/Tests/Performance/StoragePerformanceTests.swift +461 -0
- package/ios/Tests/Unit/Extension/ExpoTargetsExtensionModuleTests.swift +501 -0
- package/ios/Tests/Unit/Storage/ExpoTargetsStorageModuleTests.swift +578 -0
- package/ios/Tests/Unit/Template/ShareExtensionTemplateTests.swift +421 -0
- package/ios/Tests/XCTestPlan.xctestplan +87 -0
- package/metro/src/index.ts +1 -0
- package/metro/src/withTargetsMetro.ts +247 -0
- package/metro/tsconfig.build.json +9 -0
- package/package.json +74 -0
- package/plugin/src/android/withAndroidAppBuildGradle.ts +34 -0
- package/plugin/src/android/withAndroidTarget.ts +26 -0
- package/plugin/src/android/withAndroidWidget.ts +778 -0
- package/plugin/src/config.ts +255 -0
- package/plugin/src/index.ts +19 -0
- package/plugin/src/ios/config-plugins/withEntitlements.ts +69 -0
- package/plugin/src/ios/config-plugins/withIOSTarget.ts +179 -0
- package/plugin/src/ios/config-plugins/withIosColorset.ts +29 -0
- package/plugin/src/ios/config-plugins/withIosStickerPack.ts +65 -0
- package/plugin/src/ios/config-plugins/withPodfile.ts +238 -0
- package/plugin/src/ios/config-plugins/withXcodeChanges.ts +891 -0
- package/plugin/src/ios/target.ts +668 -0
- package/plugin/src/ios/templates/MessagesViewController.swift +120 -0
- package/plugin/src/ios/templates/ReactNativeViewController.swift +240 -0
- package/plugin/src/ios/templates/action-extension-data.swift +106 -0
- package/plugin/src/ios/templates/clip-extension-data.swift +28 -0
- package/plugin/src/ios/templates/messages-extension-data.swift +28 -0
- package/plugin/src/ios/templates/share-extension-data.swift +113 -0
- package/plugin/src/ios/utils/asset.ts +490 -0
- package/plugin/src/ios/utils/file.ts +80 -0
- package/plugin/src/ios/utils/index.ts +12 -0
- package/plugin/src/ios/utils/paths.ts +253 -0
- package/plugin/src/ios/utils/plist.ts +101 -0
- package/plugin/src/ios/utils/podfile.ts +534 -0
- package/plugin/src/ios/utils/reactNativeSwift.ts +283 -0
- package/plugin/src/ios/utils/xcode.ts +989 -0
- package/plugin/src/logger.ts +63 -0
- package/plugin/src/parseTargetConfig.ts +115 -0
- package/plugin/src/types/normalize-colors.d.ts +3 -0
- package/plugin/src/withTargetsDir.ts +120 -0
- package/plugin/tsconfig.build.json +9 -0
- package/plugin/tsconfig.json +9 -0
- package/src/Target.ts +239 -0
- package/src/index.ts +52 -0
- package/src/modules/extension/index.ts +54 -0
- package/src/modules/messages/index.ts +124 -0
- package/src/modules/storage/index.ts +126 -0
- package/tsconfig.json +8 -0
|
@@ -0,0 +1,989 @@
|
|
|
1
|
+
import { IOSConfig } from '@expo/config-plugins';
|
|
2
|
+
import type { XcodeProject } from '@expo/config-plugins';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
import * as File from './file';
|
|
6
|
+
import * as Paths from './paths';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* High-level utilities for Xcode project manipulation in expo-targets.
|
|
10
|
+
* Wraps IOSConfig.XcodeUtils for consistency and extends with target-specific operations.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// Re-export commonly used utilities from IOSConfig.XcodeUtils
|
|
14
|
+
export const {
|
|
15
|
+
ensureGroupRecursively,
|
|
16
|
+
addResourceFileToGroup,
|
|
17
|
+
addBuildSourceFileToGroup,
|
|
18
|
+
getProjectName,
|
|
19
|
+
getApplicationNativeTarget,
|
|
20
|
+
} = IOSConfig.XcodeUtils;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Target creation result from xcode library
|
|
24
|
+
*/
|
|
25
|
+
interface XcodeTarget {
|
|
26
|
+
uuid: string;
|
|
27
|
+
pbxNativeTarget?: any;
|
|
28
|
+
target?: any;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Check if target already has a specific build phase type
|
|
33
|
+
*/
|
|
34
|
+
export function hasBuildPhase({
|
|
35
|
+
project,
|
|
36
|
+
targetUuid,
|
|
37
|
+
phaseType,
|
|
38
|
+
}: {
|
|
39
|
+
project: XcodeProject;
|
|
40
|
+
targetUuid: string;
|
|
41
|
+
phaseType: string;
|
|
42
|
+
}): boolean {
|
|
43
|
+
const xcodeProject = project as any;
|
|
44
|
+
const target = xcodeProject.hash.project.objects.PBXNativeTarget[targetUuid];
|
|
45
|
+
|
|
46
|
+
if (!target || !target.buildPhases) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const phaseSection = xcodeProject.hash.project.objects[phaseType];
|
|
51
|
+
if (!phaseSection) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return target.buildPhases.some((phase: any) => {
|
|
56
|
+
const phaseUuid = phase.value;
|
|
57
|
+
return phaseSection[phaseUuid] !== undefined;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Remove build phases of a specific type from target
|
|
63
|
+
*/
|
|
64
|
+
export function removeBuildPhases({
|
|
65
|
+
project,
|
|
66
|
+
targetUuid,
|
|
67
|
+
phaseType,
|
|
68
|
+
}: {
|
|
69
|
+
project: XcodeProject;
|
|
70
|
+
targetUuid: string;
|
|
71
|
+
phaseType: string;
|
|
72
|
+
}): void {
|
|
73
|
+
const xcodeProject = project as any;
|
|
74
|
+
const target = xcodeProject.hash.project.objects.PBXNativeTarget[targetUuid];
|
|
75
|
+
|
|
76
|
+
if (!target || !target.buildPhases) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const phaseSection = xcodeProject.hash.project.objects[phaseType];
|
|
81
|
+
if (!phaseSection) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Find matching phase UUIDs
|
|
86
|
+
const phasesToRemove: string[] = [];
|
|
87
|
+
target.buildPhases.forEach((phase: any) => {
|
|
88
|
+
const phaseUuid = phase.value;
|
|
89
|
+
if (phaseSection[phaseUuid]) {
|
|
90
|
+
phasesToRemove.push(phaseUuid);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// Remove phases from target's buildPhases array
|
|
95
|
+
target.buildPhases = target.buildPhases.filter(
|
|
96
|
+
(phase: any) => !phasesToRemove.includes(phase.value)
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
// Remove phase objects and comments from section
|
|
100
|
+
phasesToRemove.forEach((phaseUuid) => {
|
|
101
|
+
delete phaseSection[phaseUuid];
|
|
102
|
+
delete phaseSection[`${phaseUuid}_comment`];
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Check if target dependency already exists
|
|
108
|
+
*/
|
|
109
|
+
export function hasTargetDependency({
|
|
110
|
+
project,
|
|
111
|
+
mainTargetUuid,
|
|
112
|
+
dependentTargetUuid,
|
|
113
|
+
}: {
|
|
114
|
+
project: XcodeProject;
|
|
115
|
+
mainTargetUuid: string;
|
|
116
|
+
dependentTargetUuid: string;
|
|
117
|
+
}): boolean {
|
|
118
|
+
const xcodeProject = project as any;
|
|
119
|
+
const mainTarget =
|
|
120
|
+
xcodeProject.hash.project.objects.PBXNativeTarget[mainTargetUuid];
|
|
121
|
+
|
|
122
|
+
if (!mainTarget || !mainTarget.dependencies) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const dependencies = xcodeProject.hash.project.objects.PBXTargetDependency;
|
|
127
|
+
if (!dependencies) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return mainTarget.dependencies.some((dep: any) => {
|
|
132
|
+
const depUuid = dep.value;
|
|
133
|
+
const dependency = dependencies[depUuid];
|
|
134
|
+
return dependency && dependency.target === dependentTargetUuid;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Add target dependency from main app to extension/clip target.
|
|
140
|
+
* Ensures PBXTargetDependency and PBXContainerItemProxy sections exist.
|
|
141
|
+
*/
|
|
142
|
+
export function addTargetDependency({
|
|
143
|
+
project,
|
|
144
|
+
mainTargetUuid,
|
|
145
|
+
dependentTargetUuid,
|
|
146
|
+
}: {
|
|
147
|
+
project: XcodeProject;
|
|
148
|
+
mainTargetUuid: string;
|
|
149
|
+
dependentTargetUuid: string;
|
|
150
|
+
}): void {
|
|
151
|
+
// Check if dependency already exists
|
|
152
|
+
if (hasTargetDependency({ project, mainTargetUuid, dependentTargetUuid })) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const xcodeProject = project as any;
|
|
157
|
+
|
|
158
|
+
// Ensure required sections exist
|
|
159
|
+
if (!xcodeProject.hash.project.objects['PBXTargetDependency']) {
|
|
160
|
+
xcodeProject.hash.project.objects['PBXTargetDependency'] = {};
|
|
161
|
+
}
|
|
162
|
+
if (!xcodeProject.hash.project.objects['PBXContainerItemProxy']) {
|
|
163
|
+
xcodeProject.hash.project.objects['PBXContainerItemProxy'] = {};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
xcodeProject.addTargetDependency(mainTargetUuid, [dependentTargetUuid]);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Configure embed settings for app extension.
|
|
171
|
+
* Consolidates all app extensions into a SINGLE "Embed App Extensions" phase.
|
|
172
|
+
*/
|
|
173
|
+
export function configureAppExtensionEmbed({
|
|
174
|
+
project,
|
|
175
|
+
targetProductName,
|
|
176
|
+
}: {
|
|
177
|
+
project: XcodeProject;
|
|
178
|
+
targetProductName: string;
|
|
179
|
+
}): void {
|
|
180
|
+
const xcodeProject = project as any;
|
|
181
|
+
const buildFileSection = xcodeProject.hash.project.objects.PBXBuildFile;
|
|
182
|
+
const fileRefSection = xcodeProject.hash.project.objects.PBXFileReference;
|
|
183
|
+
const targetFileName = `${targetProductName}.appex`;
|
|
184
|
+
|
|
185
|
+
const ensureAttributes = (buildFile: any) => {
|
|
186
|
+
const desired = ['RemoveHeadersOnCopy', 'CodeSignOnCopy'];
|
|
187
|
+
if (!buildFile.settings || !Array.isArray(buildFile.settings.ATTRIBUTES)) {
|
|
188
|
+
buildFile.settings = { ATTRIBUTES: desired };
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
const attrs: string[] = buildFile.settings.ATTRIBUTES;
|
|
192
|
+
desired.forEach((attr) => {
|
|
193
|
+
if (!attrs.includes(attr)) attrs.push(attr);
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
// Find and configure the PBXBuildFile for the extension (global scan)
|
|
198
|
+
let foundBuildFile = false;
|
|
199
|
+
for (const buildFileKey in buildFileSection) {
|
|
200
|
+
if (buildFileKey.endsWith('_comment')) continue;
|
|
201
|
+
|
|
202
|
+
const buildFile = buildFileSection[buildFileKey];
|
|
203
|
+
if (buildFile?.fileRef) {
|
|
204
|
+
const fileRef = fileRefSection[buildFile.fileRef];
|
|
205
|
+
const refPath = fileRef?.path?.replace(/"/g, '');
|
|
206
|
+
const refName = fileRef?.name?.replace(/"/g, '');
|
|
207
|
+
|
|
208
|
+
if (refPath === targetFileName || refName === targetFileName) {
|
|
209
|
+
ensureAttributes(buildFile);
|
|
210
|
+
foundBuildFile = true;
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (!foundBuildFile) {
|
|
217
|
+
console.warn(
|
|
218
|
+
`[expo-targets] Could not find PBXBuildFile for ${targetProductName}.appex`
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Find or create a SINGLE "Embed App Extensions" phase
|
|
223
|
+
const copyFilesPhases =
|
|
224
|
+
xcodeProject.hash.project.objects.PBXCopyFilesBuildPhase;
|
|
225
|
+
|
|
226
|
+
// Step 1: Find existing "Embed App Extensions" phase (with proper name)
|
|
227
|
+
let primaryPhaseKey: string | null = null;
|
|
228
|
+
let primaryPhase: any = null;
|
|
229
|
+
|
|
230
|
+
for (const phaseKey in copyFilesPhases) {
|
|
231
|
+
if (phaseKey.endsWith('_comment')) continue;
|
|
232
|
+
const phase = copyFilesPhases[phaseKey];
|
|
233
|
+
if (
|
|
234
|
+
phase?.dstSubfolderSpec === 13 &&
|
|
235
|
+
(phase.name === '"Embed App Extensions"' ||
|
|
236
|
+
copyFilesPhases[`${phaseKey}_comment`] === 'Embed App Extensions')
|
|
237
|
+
) {
|
|
238
|
+
primaryPhaseKey = phaseKey;
|
|
239
|
+
primaryPhase = phase;
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// Step 2: Consolidate - find all extension embedding phases and merge into primary
|
|
245
|
+
const phasesToMerge: string[] = [];
|
|
246
|
+
const extensionBuildFiles: Set<string> = new Set();
|
|
247
|
+
|
|
248
|
+
for (const phaseKey in copyFilesPhases) {
|
|
249
|
+
if (phaseKey.endsWith('_comment') || phaseKey === primaryPhaseKey) continue;
|
|
250
|
+
const phase = copyFilesPhases[phaseKey];
|
|
251
|
+
|
|
252
|
+
if (phase?.dstSubfolderSpec === 13 && phase.files) {
|
|
253
|
+
// Check if this phase contains any .appex files
|
|
254
|
+
let hasAppExtension = false;
|
|
255
|
+
phase.files.forEach((file: any) => {
|
|
256
|
+
const buildFileKey = file.value;
|
|
257
|
+
const buildFile = buildFileSection?.[buildFileKey];
|
|
258
|
+
if (!buildFile?.fileRef) return;
|
|
259
|
+
const fileRef = fileRefSection?.[buildFile.fileRef];
|
|
260
|
+
const refPath = fileRef?.path?.replace(/"/g, '');
|
|
261
|
+
const refName = fileRef?.name?.replace(/"/g, '');
|
|
262
|
+
if (refPath?.endsWith('.appex') || refName?.endsWith('.appex')) {
|
|
263
|
+
hasAppExtension = true;
|
|
264
|
+
extensionBuildFiles.add(buildFileKey);
|
|
265
|
+
ensureAttributes(buildFile);
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
if (hasAppExtension) {
|
|
270
|
+
if (primaryPhaseKey) {
|
|
271
|
+
phasesToMerge.push(phaseKey);
|
|
272
|
+
} else {
|
|
273
|
+
// Use this as the primary phase
|
|
274
|
+
primaryPhaseKey = phaseKey;
|
|
275
|
+
primaryPhase = phase;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// Step 3: If we found a primary phase, merge all extensions into it
|
|
282
|
+
if (primaryPhaseKey && primaryPhase) {
|
|
283
|
+
// Rename to standard name
|
|
284
|
+
primaryPhase.name = '"Embed App Extensions"';
|
|
285
|
+
copyFilesPhases[`${primaryPhaseKey}_comment`] = 'Embed App Extensions';
|
|
286
|
+
|
|
287
|
+
// Merge build files from other phases
|
|
288
|
+
if (!primaryPhase.files) {
|
|
289
|
+
primaryPhase.files = [];
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const existingFiles = new Set(primaryPhase.files.map((f: any) => f.value));
|
|
293
|
+
|
|
294
|
+
phasesToMerge.forEach((phaseKey) => {
|
|
295
|
+
const phase = copyFilesPhases[phaseKey];
|
|
296
|
+
if (phase?.files) {
|
|
297
|
+
phase.files.forEach((file: any) => {
|
|
298
|
+
const buildFileKey = file.value;
|
|
299
|
+
if (
|
|
300
|
+
extensionBuildFiles.has(buildFileKey) &&
|
|
301
|
+
!existingFiles.has(buildFileKey)
|
|
302
|
+
) {
|
|
303
|
+
primaryPhase.files.push(file);
|
|
304
|
+
existingFiles.add(buildFileKey);
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
// Step 4: Remove duplicate phases (mark for deletion by removing from main app build phases)
|
|
311
|
+
if (phasesToMerge.length > 0) {
|
|
312
|
+
// Get the main app target by finding the first application target
|
|
313
|
+
const nativeTargets = xcodeProject.hash.project.objects.PBXNativeTarget;
|
|
314
|
+
let mainAppTarget: any = null;
|
|
315
|
+
|
|
316
|
+
for (const targetKey in nativeTargets) {
|
|
317
|
+
if (targetKey.endsWith('_comment')) continue;
|
|
318
|
+
const target = nativeTargets[targetKey];
|
|
319
|
+
if (target?.productType === '"com.apple.product-type.application"') {
|
|
320
|
+
mainAppTarget = target;
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (mainAppTarget?.buildPhases) {
|
|
326
|
+
mainAppTarget.buildPhases = mainAppTarget.buildPhases.filter(
|
|
327
|
+
(phase: any) => !phasesToMerge.includes(phase.value)
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Configure embed settings for App Clip.
|
|
336
|
+
* Creates "Embed App Clips" phase with proper settings.
|
|
337
|
+
*/
|
|
338
|
+
export function configureAppClipEmbed({
|
|
339
|
+
project,
|
|
340
|
+
mainTargetUuid,
|
|
341
|
+
target,
|
|
342
|
+
targetProductName,
|
|
343
|
+
}: {
|
|
344
|
+
project: XcodeProject;
|
|
345
|
+
mainTargetUuid: string;
|
|
346
|
+
target: XcodeTarget;
|
|
347
|
+
targetProductName: string;
|
|
348
|
+
}): void {
|
|
349
|
+
const xcodeProject = project as any;
|
|
350
|
+
|
|
351
|
+
// Get the App Clip product reference
|
|
352
|
+
const appClipFileRef =
|
|
353
|
+
target.pbxNativeTarget?.productReference || target.target?.productReference;
|
|
354
|
+
|
|
355
|
+
if (!appClipFileRef) {
|
|
356
|
+
console.warn(
|
|
357
|
+
`[expo-targets] Could not find product reference for ${targetProductName}.app`
|
|
358
|
+
);
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// Create Copy Files build phase for App Clips
|
|
363
|
+
const embedPhaseResult = xcodeProject.addBuildPhase(
|
|
364
|
+
[],
|
|
365
|
+
'PBXCopyFilesBuildPhase',
|
|
366
|
+
'Embed App Clips',
|
|
367
|
+
mainTargetUuid
|
|
368
|
+
);
|
|
369
|
+
|
|
370
|
+
const embedPhaseUuid = embedPhaseResult?.uuid || embedPhaseResult;
|
|
371
|
+
|
|
372
|
+
if (!embedPhaseUuid) {
|
|
373
|
+
console.warn(`[expo-targets] Failed to create Embed App Clips phase`);
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
const copyFilesPhases =
|
|
378
|
+
xcodeProject.hash.project.objects.PBXCopyFilesBuildPhase;
|
|
379
|
+
const phase = copyFilesPhases[embedPhaseUuid];
|
|
380
|
+
|
|
381
|
+
if (!phase) {
|
|
382
|
+
console.warn(
|
|
383
|
+
`[expo-targets] Could not find phase object for UUID: ${embedPhaseUuid}`
|
|
384
|
+
);
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// Configure phase for App Clips
|
|
389
|
+
phase.dstPath = '"$(CONTENTS_FOLDER_PATH)/AppClips"';
|
|
390
|
+
phase.dstSubfolderSpec = 16;
|
|
391
|
+
phase.name = '"Embed App Clips"';
|
|
392
|
+
|
|
393
|
+
// Create a PBXBuildFile for the App Clip
|
|
394
|
+
const buildFileUuid = xcodeProject.generateUuid();
|
|
395
|
+
const buildFileSection = xcodeProject.hash.project.objects.PBXBuildFile;
|
|
396
|
+
|
|
397
|
+
buildFileSection[buildFileUuid] = {
|
|
398
|
+
isa: 'PBXBuildFile',
|
|
399
|
+
fileRef: appClipFileRef,
|
|
400
|
+
settings: {
|
|
401
|
+
ATTRIBUTES: ['RemoveHeadersOnCopy'],
|
|
402
|
+
},
|
|
403
|
+
};
|
|
404
|
+
buildFileSection[`${buildFileUuid}_comment`] =
|
|
405
|
+
`${targetProductName}.app in Embed App Clips`;
|
|
406
|
+
|
|
407
|
+
// Add the build file to the phase
|
|
408
|
+
if (!phase.files) {
|
|
409
|
+
phase.files = [];
|
|
410
|
+
}
|
|
411
|
+
phase.files.push({
|
|
412
|
+
value: buildFileUuid,
|
|
413
|
+
comment: `${targetProductName}.app in Embed App Clips`,
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Set product type for a native target.
|
|
419
|
+
* Useful for App Clips which need special product type after creation.
|
|
420
|
+
*/
|
|
421
|
+
export function setProductType({
|
|
422
|
+
target,
|
|
423
|
+
productType,
|
|
424
|
+
}: {
|
|
425
|
+
target: XcodeTarget;
|
|
426
|
+
productType: string;
|
|
427
|
+
}): void {
|
|
428
|
+
const nativeTarget = target.pbxNativeTarget || target.target;
|
|
429
|
+
if (nativeTarget) {
|
|
430
|
+
nativeTarget.productType = productType;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Apply build settings to all configurations of a target.
|
|
436
|
+
*/
|
|
437
|
+
export function applyBuildSettings({
|
|
438
|
+
project,
|
|
439
|
+
target,
|
|
440
|
+
buildSettings,
|
|
441
|
+
verbose = false,
|
|
442
|
+
logger,
|
|
443
|
+
}: {
|
|
444
|
+
project: XcodeProject;
|
|
445
|
+
target: XcodeTarget;
|
|
446
|
+
buildSettings: Record<string, string | string[]>;
|
|
447
|
+
verbose?: boolean;
|
|
448
|
+
logger?: { log: (message: string) => void };
|
|
449
|
+
}): void {
|
|
450
|
+
const xcodeProject = project as any;
|
|
451
|
+
|
|
452
|
+
const targetBuildConfigId =
|
|
453
|
+
target.pbxNativeTarget?.buildConfigurationList ||
|
|
454
|
+
target.target?.buildConfigurationList;
|
|
455
|
+
|
|
456
|
+
const buildConfigList =
|
|
457
|
+
xcodeProject.pbxXCConfigurationList()[targetBuildConfigId];
|
|
458
|
+
|
|
459
|
+
if (!buildConfigList?.buildConfigurations) {
|
|
460
|
+
if (logger) {
|
|
461
|
+
logger.log('No build configurations found for target');
|
|
462
|
+
} else {
|
|
463
|
+
console.warn(`[expo-targets] No build configurations found for target`);
|
|
464
|
+
}
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
buildConfigList.buildConfigurations.forEach((config: any) => {
|
|
469
|
+
const configSection =
|
|
470
|
+
xcodeProject.pbxXCBuildConfigurationSection()[config.value];
|
|
471
|
+
const configName = configSection?.name;
|
|
472
|
+
|
|
473
|
+
if (verbose) {
|
|
474
|
+
if (logger) {
|
|
475
|
+
logger.log(` Configuring ${configName} build settings`);
|
|
476
|
+
} else {
|
|
477
|
+
console.log(
|
|
478
|
+
`[expo-targets] Configuring ${configName} build settings`
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
if (configSection?.buildSettings) {
|
|
484
|
+
Object.entries(buildSettings).forEach(([key, value]) => {
|
|
485
|
+
configSection.buildSettings[key] = value;
|
|
486
|
+
if (
|
|
487
|
+
verbose &&
|
|
488
|
+
(key === 'SWIFT_VERSION' || key === 'IPHONEOS_DEPLOYMENT_TARGET')
|
|
489
|
+
) {
|
|
490
|
+
if (logger) {
|
|
491
|
+
logger.log(` Set ${key}=${value} to ${configName}`);
|
|
492
|
+
} else {
|
|
493
|
+
console.log(
|
|
494
|
+
`[expo-targets] Set ${key}=${value} to ${configName}`
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Remove a build setting from all configurations of a target.
|
|
505
|
+
*/
|
|
506
|
+
export function removeBuildSetting({
|
|
507
|
+
project,
|
|
508
|
+
target,
|
|
509
|
+
settingKey,
|
|
510
|
+
verbose = false,
|
|
511
|
+
logger,
|
|
512
|
+
}: {
|
|
513
|
+
project: XcodeProject;
|
|
514
|
+
target: XcodeTarget;
|
|
515
|
+
settingKey: string;
|
|
516
|
+
verbose?: boolean;
|
|
517
|
+
logger?: { log: (message: string) => void };
|
|
518
|
+
}): void {
|
|
519
|
+
const xcodeProject = project as any;
|
|
520
|
+
|
|
521
|
+
const targetBuildConfigId =
|
|
522
|
+
target.pbxNativeTarget?.buildConfigurationList ||
|
|
523
|
+
target.target?.buildConfigurationList;
|
|
524
|
+
|
|
525
|
+
const buildConfigList =
|
|
526
|
+
xcodeProject.pbxXCConfigurationList()[targetBuildConfigId];
|
|
527
|
+
|
|
528
|
+
if (!buildConfigList?.buildConfigurations) return;
|
|
529
|
+
|
|
530
|
+
buildConfigList.buildConfigurations.forEach((config: any) => {
|
|
531
|
+
const configSection =
|
|
532
|
+
xcodeProject.pbxXCBuildConfigurationSection()[config.value];
|
|
533
|
+
|
|
534
|
+
if (configSection?.buildSettings?.[settingKey]) {
|
|
535
|
+
delete configSection.buildSettings[settingKey];
|
|
536
|
+
if (verbose) {
|
|
537
|
+
if (logger) {
|
|
538
|
+
logger.log(` Removed ${settingKey} from ${configSection.name}`);
|
|
539
|
+
} else {
|
|
540
|
+
console.log(
|
|
541
|
+
`[expo-targets] Removed ${settingKey} from ${configSection.name}`
|
|
542
|
+
);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Get build settings from the main app target.
|
|
551
|
+
*/
|
|
552
|
+
export function getMainAppBuildSettings({
|
|
553
|
+
project,
|
|
554
|
+
mainTarget,
|
|
555
|
+
}: {
|
|
556
|
+
project: XcodeProject;
|
|
557
|
+
mainTarget: { uuid: string; target: any };
|
|
558
|
+
}): Record<string, any> {
|
|
559
|
+
const xcodeProject = project as any;
|
|
560
|
+
|
|
561
|
+
const mainTargetBuildConfigId = mainTarget.target?.buildConfigurationList;
|
|
562
|
+
const mainBuildConfigList =
|
|
563
|
+
xcodeProject.pbxXCConfigurationList()[mainTargetBuildConfigId];
|
|
564
|
+
const mainBuildConfig = mainBuildConfigList?.buildConfigurations?.[0]?.value;
|
|
565
|
+
|
|
566
|
+
return mainBuildConfig
|
|
567
|
+
? xcodeProject.pbxXCBuildConfigurationSection()[mainBuildConfig]
|
|
568
|
+
?.buildSettings || {}
|
|
569
|
+
: {};
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Find a target UUID by its product name.
|
|
574
|
+
*/
|
|
575
|
+
export function findTargetByProductName({
|
|
576
|
+
project,
|
|
577
|
+
productName,
|
|
578
|
+
}: {
|
|
579
|
+
project: XcodeProject;
|
|
580
|
+
productName: string;
|
|
581
|
+
}): string | undefined {
|
|
582
|
+
const xcodeProject = project as any;
|
|
583
|
+
const pbxNativeTargetSection =
|
|
584
|
+
xcodeProject.hash.project.objects.PBXNativeTarget || {};
|
|
585
|
+
|
|
586
|
+
for (const key in pbxNativeTargetSection) {
|
|
587
|
+
if (key.endsWith('_comment')) continue;
|
|
588
|
+
const target = pbxNativeTargetSection[key];
|
|
589
|
+
if (target?.name === productName) {
|
|
590
|
+
return key;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
return undefined;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* Find all target UUIDs with a given product name (detects duplicates)
|
|
599
|
+
*/
|
|
600
|
+
export function findAllTargetsByProductName({
|
|
601
|
+
project,
|
|
602
|
+
productName,
|
|
603
|
+
}: {
|
|
604
|
+
project: XcodeProject;
|
|
605
|
+
productName: string;
|
|
606
|
+
}): string[] {
|
|
607
|
+
const xcodeProject = project as any;
|
|
608
|
+
const pbxNativeTargetSection =
|
|
609
|
+
xcodeProject.hash.project.objects.PBXNativeTarget || {};
|
|
610
|
+
const matchingTargets: string[] = [];
|
|
611
|
+
|
|
612
|
+
for (const key in pbxNativeTargetSection) {
|
|
613
|
+
if (key.endsWith('_comment')) continue;
|
|
614
|
+
const target = pbxNativeTargetSection[key];
|
|
615
|
+
if (target?.name === productName) {
|
|
616
|
+
matchingTargets.push(key);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
return matchingTargets;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Remove duplicate targets with the same product name, keeping only the first one
|
|
625
|
+
*/
|
|
626
|
+
export function removeDuplicateTargets({
|
|
627
|
+
project,
|
|
628
|
+
productName,
|
|
629
|
+
}: {
|
|
630
|
+
project: XcodeProject;
|
|
631
|
+
productName: string;
|
|
632
|
+
}): number {
|
|
633
|
+
const allTargets = findAllTargetsByProductName({ project, productName });
|
|
634
|
+
|
|
635
|
+
if (allTargets.length <= 1) {
|
|
636
|
+
return 0;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
const xcodeProject = project as any;
|
|
640
|
+
const [keepTarget, ...duplicates] = allTargets;
|
|
641
|
+
|
|
642
|
+
console.log(
|
|
643
|
+
`[expo-targets] Found ${allTargets.length} targets named "${productName}", removing ${duplicates.length} duplicate(s)`
|
|
644
|
+
);
|
|
645
|
+
|
|
646
|
+
duplicates.forEach((targetUuid) => {
|
|
647
|
+
// Remove from PBXNativeTarget section
|
|
648
|
+
const pbxNativeTargetSection =
|
|
649
|
+
xcodeProject.hash.project.objects.PBXNativeTarget;
|
|
650
|
+
if (pbxNativeTargetSection) {
|
|
651
|
+
delete pbxNativeTargetSection[targetUuid];
|
|
652
|
+
delete pbxNativeTargetSection[`${targetUuid}_comment`];
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
// Remove from project targets list
|
|
656
|
+
const project = xcodeProject.hash.project.objects.PBXProject;
|
|
657
|
+
for (const projectKey in project) {
|
|
658
|
+
if (projectKey.endsWith('_comment')) continue;
|
|
659
|
+
const projectObj = project[projectKey];
|
|
660
|
+
if (projectObj?.targets) {
|
|
661
|
+
projectObj.targets = projectObj.targets.filter(
|
|
662
|
+
(t: any) => t.value !== targetUuid
|
|
663
|
+
);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
// Remove build configuration list
|
|
668
|
+
const target =
|
|
669
|
+
xcodeProject.hash.project.objects.PBXNativeTarget?.[targetUuid];
|
|
670
|
+
if (target?.buildConfigurationList) {
|
|
671
|
+
const configListUuid = target.buildConfigurationList;
|
|
672
|
+
const configListSection =
|
|
673
|
+
xcodeProject.hash.project.objects.XCConfigurationList;
|
|
674
|
+
if (configListSection) {
|
|
675
|
+
delete configListSection[configListUuid];
|
|
676
|
+
delete configListSection[`${configListUuid}_comment`];
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
console.log(`[expo-targets] Removed duplicate target: ${targetUuid}`);
|
|
681
|
+
});
|
|
682
|
+
|
|
683
|
+
return duplicates.length;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* Add Assets.xcassets to a target's Resources build phase if it exists.
|
|
688
|
+
*/
|
|
689
|
+
export function addTargetAssets({
|
|
690
|
+
platformProjectRoot,
|
|
691
|
+
targetName,
|
|
692
|
+
targetUuid,
|
|
693
|
+
xcodeProject,
|
|
694
|
+
isStickers,
|
|
695
|
+
}: {
|
|
696
|
+
platformProjectRoot: string;
|
|
697
|
+
targetName: string;
|
|
698
|
+
targetUuid: string;
|
|
699
|
+
xcodeProject: any;
|
|
700
|
+
isStickers?: boolean;
|
|
701
|
+
}): void {
|
|
702
|
+
const targetProductName = Paths.sanitizeTargetName(targetName);
|
|
703
|
+
const assetsPath = Paths.getAssetsXcassetsPath({
|
|
704
|
+
platformProjectRoot,
|
|
705
|
+
targetName,
|
|
706
|
+
isStickers,
|
|
707
|
+
});
|
|
708
|
+
// Get the actual group directory name (includes 'Target' suffix)
|
|
709
|
+
const targetGroupPath = Paths.getTargetGroupPath({
|
|
710
|
+
platformProjectRoot,
|
|
711
|
+
targetName,
|
|
712
|
+
});
|
|
713
|
+
const targetDirName = path.basename(targetGroupPath);
|
|
714
|
+
|
|
715
|
+
if (File.isDirectory(assetsPath)) {
|
|
716
|
+
const assetsFolderName = isStickers
|
|
717
|
+
? 'Stickers.xcassets'
|
|
718
|
+
: 'Assets.xcassets';
|
|
719
|
+
console.log(
|
|
720
|
+
`[expo-targets] Found ${assetsFolderName}, adding to ${targetProductName}...`
|
|
721
|
+
);
|
|
722
|
+
|
|
723
|
+
// Add Assets.xcassets as a resource file
|
|
724
|
+
const relativePath = path.relative(platformProjectRoot, assetsPath);
|
|
725
|
+
|
|
726
|
+
addResourceFileToGroup({
|
|
727
|
+
filepath: relativePath,
|
|
728
|
+
groupName: targetDirName,
|
|
729
|
+
project: xcodeProject,
|
|
730
|
+
isBuildFile: true,
|
|
731
|
+
verbose: true,
|
|
732
|
+
targetUuid,
|
|
733
|
+
});
|
|
734
|
+
|
|
735
|
+
console.log(
|
|
736
|
+
`[expo-targets] ✓ Added ${assetsFolderName} to ${targetProductName} Resources build phase`
|
|
737
|
+
);
|
|
738
|
+
} else {
|
|
739
|
+
const assetsFolderName = isStickers
|
|
740
|
+
? 'Stickers.xcassets'
|
|
741
|
+
: 'Assets.xcassets';
|
|
742
|
+
console.log(
|
|
743
|
+
`[expo-targets] ${assetsFolderName} directory not found at: ${assetsPath}`
|
|
744
|
+
);
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
/**
|
|
749
|
+
* ============================================================================
|
|
750
|
+
* NEW: Virtual Group Helpers for Reference-in-Place
|
|
751
|
+
* ============================================================================
|
|
752
|
+
* These functions create and manage the "expo:targets" virtual group in Xcode,
|
|
753
|
+
* which contains references to files outside the ios/ directory.
|
|
754
|
+
*/
|
|
755
|
+
|
|
756
|
+
/**
|
|
757
|
+
* Ensure the virtual "expo:targets" group exists in Xcode.
|
|
758
|
+
* This group contains references to files outside ios/ directory.
|
|
759
|
+
* Returns the UUID of the expo:targets group.
|
|
760
|
+
*/
|
|
761
|
+
export function ensureExpoTargetsGroup({
|
|
762
|
+
project,
|
|
763
|
+
}: {
|
|
764
|
+
project: XcodeProject;
|
|
765
|
+
}): string {
|
|
766
|
+
const xcodeProject = project as any;
|
|
767
|
+
|
|
768
|
+
// Get the root project object
|
|
769
|
+
const rootObject = xcodeProject.hash.project.rootObject;
|
|
770
|
+
const projectObject =
|
|
771
|
+
xcodeProject.hash.project.objects.PBXProject[rootObject];
|
|
772
|
+
|
|
773
|
+
// Get the main group UUID from the project object
|
|
774
|
+
const mainGroupUuid = projectObject.mainGroup;
|
|
775
|
+
const mainGroup = xcodeProject.hash.project.objects.PBXGroup[mainGroupUuid];
|
|
776
|
+
|
|
777
|
+
// Check if expo:targets already exists
|
|
778
|
+
const existingGroup = Object.entries(
|
|
779
|
+
xcodeProject.hash.project.objects.PBXGroup
|
|
780
|
+
).find(([_, group]: [string, any]) => group.name === '"expo:targets"');
|
|
781
|
+
|
|
782
|
+
if (existingGroup) {
|
|
783
|
+
return existingGroup[0];
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
// Create new virtual group
|
|
787
|
+
const groupUuid = xcodeProject.generateUuid();
|
|
788
|
+
xcodeProject.hash.project.objects.PBXGroup[groupUuid] = {
|
|
789
|
+
isa: 'PBXGroup',
|
|
790
|
+
children: [],
|
|
791
|
+
name: '"expo:targets"',
|
|
792
|
+
sourceTree: '"<group>"',
|
|
793
|
+
};
|
|
794
|
+
xcodeProject.hash.project.objects.PBXGroup[`${groupUuid}_comment`] =
|
|
795
|
+
'expo:targets';
|
|
796
|
+
|
|
797
|
+
// Add to main group
|
|
798
|
+
if (!mainGroup.children) {
|
|
799
|
+
mainGroup.children = [];
|
|
800
|
+
}
|
|
801
|
+
mainGroup.children.push({
|
|
802
|
+
value: groupUuid,
|
|
803
|
+
comment: 'expo:targets',
|
|
804
|
+
});
|
|
805
|
+
|
|
806
|
+
return groupUuid;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
/**
|
|
810
|
+
* Add target subfolder to expo:targets virtual group.
|
|
811
|
+
* Returns the group UUID for the target.
|
|
812
|
+
*/
|
|
813
|
+
export function addTargetToVirtualGroup({
|
|
814
|
+
project,
|
|
815
|
+
targetName,
|
|
816
|
+
virtualGroupUuid,
|
|
817
|
+
}: {
|
|
818
|
+
project: XcodeProject;
|
|
819
|
+
targetName: string;
|
|
820
|
+
virtualGroupUuid: string;
|
|
821
|
+
}): string {
|
|
822
|
+
const xcodeProject = project as any;
|
|
823
|
+
|
|
824
|
+
// Check if target group already exists
|
|
825
|
+
const virtualGroup =
|
|
826
|
+
xcodeProject.hash.project.objects.PBXGroup[virtualGroupUuid];
|
|
827
|
+
if (virtualGroup && virtualGroup.children) {
|
|
828
|
+
const existingTarget = virtualGroup.children.find(
|
|
829
|
+
(child: any) => child.comment === targetName
|
|
830
|
+
);
|
|
831
|
+
if (existingTarget) {
|
|
832
|
+
return existingTarget.value;
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
const targetGroupUuid = xcodeProject.generateUuid();
|
|
837
|
+
|
|
838
|
+
xcodeProject.hash.project.objects.PBXGroup[targetGroupUuid] = {
|
|
839
|
+
isa: 'PBXGroup',
|
|
840
|
+
children: [],
|
|
841
|
+
name: `"${targetName}"`,
|
|
842
|
+
sourceTree: '"<group>"',
|
|
843
|
+
};
|
|
844
|
+
xcodeProject.hash.project.objects.PBXGroup[`${targetGroupUuid}_comment`] =
|
|
845
|
+
targetName;
|
|
846
|
+
|
|
847
|
+
// Add to virtual group
|
|
848
|
+
if (!virtualGroup.children) {
|
|
849
|
+
virtualGroup.children = [];
|
|
850
|
+
}
|
|
851
|
+
virtualGroup.children.push({
|
|
852
|
+
value: targetGroupUuid,
|
|
853
|
+
comment: targetName,
|
|
854
|
+
});
|
|
855
|
+
|
|
856
|
+
return targetGroupUuid;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
/**
|
|
860
|
+
* Add file reference to group, pointing to external path.
|
|
861
|
+
* Returns the file reference UUID.
|
|
862
|
+
*/
|
|
863
|
+
export function addExternalFileReference({
|
|
864
|
+
project,
|
|
865
|
+
groupUuid,
|
|
866
|
+
filePath,
|
|
867
|
+
fileName,
|
|
868
|
+
fileType,
|
|
869
|
+
}: {
|
|
870
|
+
project: XcodeProject;
|
|
871
|
+
groupUuid: string;
|
|
872
|
+
filePath: string;
|
|
873
|
+
fileName: string;
|
|
874
|
+
fileType?: string;
|
|
875
|
+
}): string {
|
|
876
|
+
const xcodeProject = project as any;
|
|
877
|
+
|
|
878
|
+
// Determine file type
|
|
879
|
+
let lastKnownFileType = fileType || 'sourcecode.swift';
|
|
880
|
+
if (fileName.endsWith('.xcassets')) {
|
|
881
|
+
lastKnownFileType = 'folder.assetcatalog';
|
|
882
|
+
} else if (fileName.endsWith('.swift')) {
|
|
883
|
+
lastKnownFileType = 'sourcecode.swift';
|
|
884
|
+
} else if (fileName.endsWith('.h')) {
|
|
885
|
+
lastKnownFileType = 'sourcecode.c.h';
|
|
886
|
+
} else if (fileName.endsWith('.m')) {
|
|
887
|
+
lastKnownFileType = 'sourcecode.c.objc';
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
const fileRefUuid = xcodeProject.generateUuid();
|
|
891
|
+
|
|
892
|
+
xcodeProject.hash.project.objects.PBXFileReference[fileRefUuid] = {
|
|
893
|
+
isa: 'PBXFileReference',
|
|
894
|
+
lastKnownFileType,
|
|
895
|
+
name: `"${fileName}"`,
|
|
896
|
+
path: `"${filePath}"`,
|
|
897
|
+
sourceTree: '"<group>"',
|
|
898
|
+
};
|
|
899
|
+
xcodeProject.hash.project.objects.PBXFileReference[`${fileRefUuid}_comment`] =
|
|
900
|
+
fileName;
|
|
901
|
+
|
|
902
|
+
// Add to group
|
|
903
|
+
const group = xcodeProject.hash.project.objects.PBXGroup[groupUuid];
|
|
904
|
+
if (!group.children) {
|
|
905
|
+
group.children = [];
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
// Check if file already exists in group
|
|
909
|
+
const existingFile = group.children.find(
|
|
910
|
+
(child: any) => child.comment === fileName
|
|
911
|
+
);
|
|
912
|
+
if (!existingFile) {
|
|
913
|
+
group.children.push({
|
|
914
|
+
value: fileRefUuid,
|
|
915
|
+
comment: fileName,
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
return fileRefUuid;
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
/**
|
|
923
|
+
* Add file to specific build phase by file reference UUID.
|
|
924
|
+
*/
|
|
925
|
+
export function addFileToBuildPhase({
|
|
926
|
+
project,
|
|
927
|
+
targetUuid,
|
|
928
|
+
fileRefUuid,
|
|
929
|
+
phaseType,
|
|
930
|
+
}: {
|
|
931
|
+
project: XcodeProject;
|
|
932
|
+
targetUuid: string;
|
|
933
|
+
fileRefUuid: string;
|
|
934
|
+
phaseType:
|
|
935
|
+
| 'PBXSourcesBuildPhase'
|
|
936
|
+
| 'PBXResourcesBuildPhase'
|
|
937
|
+
| 'PBXFrameworksBuildPhase';
|
|
938
|
+
}): void {
|
|
939
|
+
const xcodeProject = project as any;
|
|
940
|
+
const target = xcodeProject.hash.project.objects.PBXNativeTarget[targetUuid];
|
|
941
|
+
|
|
942
|
+
if (!target || !target.buildPhases) {
|
|
943
|
+
throw new Error(`Target ${targetUuid} not found or has no build phases`);
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
// Find the build phase
|
|
947
|
+
const phaseUuid = target.buildPhases.find((phase: any) => {
|
|
948
|
+
const phaseObj = xcodeProject.hash.project.objects[phaseType][phase.value];
|
|
949
|
+
return phaseObj !== undefined;
|
|
950
|
+
})?.value;
|
|
951
|
+
|
|
952
|
+
if (!phaseUuid) {
|
|
953
|
+
throw new Error(
|
|
954
|
+
`Build phase ${phaseType} not found for target ${targetUuid}`
|
|
955
|
+
);
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
const phase = xcodeProject.hash.project.objects[phaseType][phaseUuid];
|
|
959
|
+
|
|
960
|
+
// Check if file already exists in build phase
|
|
961
|
+
if (phase.files) {
|
|
962
|
+
const existingFile = phase.files.find((file: any) => {
|
|
963
|
+
const buildFile =
|
|
964
|
+
xcodeProject.hash.project.objects.PBXBuildFile[file.value];
|
|
965
|
+
return buildFile && buildFile.fileRef === fileRefUuid;
|
|
966
|
+
});
|
|
967
|
+
if (existingFile) {
|
|
968
|
+
return; // Already added
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
// Create PBXBuildFile
|
|
973
|
+
const buildFileUuid = xcodeProject.generateUuid();
|
|
974
|
+
xcodeProject.hash.project.objects.PBXBuildFile[buildFileUuid] = {
|
|
975
|
+
isa: 'PBXBuildFile',
|
|
976
|
+
fileRef: fileRefUuid,
|
|
977
|
+
};
|
|
978
|
+
xcodeProject.hash.project.objects.PBXBuildFile[`${buildFileUuid}_comment`] =
|
|
979
|
+
`Referenced file in ${phaseType}`;
|
|
980
|
+
|
|
981
|
+
// Add to phase
|
|
982
|
+
if (!phase.files) {
|
|
983
|
+
phase.files = [];
|
|
984
|
+
}
|
|
985
|
+
phase.files.push({
|
|
986
|
+
value: buildFileUuid,
|
|
987
|
+
comment: `Referenced file`,
|
|
988
|
+
});
|
|
989
|
+
}
|