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,247 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import type { MetroConfig } from 'metro-config';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
|
|
5
|
+
interface TargetConfig {
|
|
6
|
+
name: string;
|
|
7
|
+
type?: string;
|
|
8
|
+
platforms?: string[];
|
|
9
|
+
entry?: string;
|
|
10
|
+
excludedPackages?: string[];
|
|
11
|
+
ios?: Record<string, any>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface TargetEntryPoint {
|
|
15
|
+
targetName: string;
|
|
16
|
+
entryPath: string;
|
|
17
|
+
excludedPackages?: string[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function scanTargetsDirectory(projectRoot: string): TargetEntryPoint[] {
|
|
21
|
+
console.log(`[expo-targets-metro] 🔍 Scanning targets directory...`);
|
|
22
|
+
console.log(`[expo-targets-metro] Project root: ${projectRoot}`);
|
|
23
|
+
|
|
24
|
+
const targetsDir = path.join(projectRoot, 'targets');
|
|
25
|
+
console.log(`[expo-targets-metro] Targets dir: ${targetsDir}`);
|
|
26
|
+
|
|
27
|
+
const entryPoints: TargetEntryPoint[] = [];
|
|
28
|
+
|
|
29
|
+
if (!fs.existsSync(targetsDir)) {
|
|
30
|
+
console.log(`[expo-targets-metro] ⚠️ Targets directory does not exist`);
|
|
31
|
+
return entryPoints;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const targetDirs = fs.readdirSync(targetsDir, { withFileTypes: true });
|
|
35
|
+
console.log(
|
|
36
|
+
`[expo-targets-metro] Found ${targetDirs.length} items in targets directory`
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
for (const dir of targetDirs) {
|
|
40
|
+
if (!dir.isDirectory()) {
|
|
41
|
+
console.log(
|
|
42
|
+
`[expo-targets-metro] ⏭ Skipping non-directory: ${dir.name}`
|
|
43
|
+
);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
console.log(`[expo-targets-metro] 📁 Checking target: ${dir.name}`);
|
|
48
|
+
const configPath = path.join(
|
|
49
|
+
targetsDir,
|
|
50
|
+
dir.name,
|
|
51
|
+
'expo-target.config.json'
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
if (!fs.existsSync(configPath)) {
|
|
55
|
+
console.log(
|
|
56
|
+
`[expo-targets-metro] ⚠️ No config found at: ${configPath}`
|
|
57
|
+
);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
const configContent = fs.readFileSync(configPath, 'utf-8');
|
|
63
|
+
const config: TargetConfig = JSON.parse(configContent);
|
|
64
|
+
console.log(
|
|
65
|
+
`[expo-targets-metro] ✅ Config loaded: name="${config.name}", entry="${config.entry}"`
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
// Check if config has entry field
|
|
69
|
+
if (config.entry) {
|
|
70
|
+
const entryPath = path.resolve(projectRoot, config.entry);
|
|
71
|
+
console.log(
|
|
72
|
+
`[expo-targets-metro] 📝 Resolved entry path: ${entryPath}`
|
|
73
|
+
);
|
|
74
|
+
console.log(
|
|
75
|
+
`[expo-targets-metro] 📝 Entry exists: ${fs.existsSync(entryPath)}`
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
entryPoints.push({
|
|
79
|
+
targetName: config.name || dir.name,
|
|
80
|
+
entryPath,
|
|
81
|
+
excludedPackages: config.excludedPackages,
|
|
82
|
+
});
|
|
83
|
+
} else {
|
|
84
|
+
console.log(`[expo-targets-metro] ⏭ No entry field in config`);
|
|
85
|
+
}
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.warn(
|
|
88
|
+
`[expo-targets-metro] Failed to parse config for ${dir.name}:`,
|
|
89
|
+
error
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
console.log(
|
|
95
|
+
`[expo-targets-metro] 📊 Total entry points found: ${entryPoints.length}`
|
|
96
|
+
);
|
|
97
|
+
return entryPoints;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function withTargetsMetro(
|
|
101
|
+
metroConfig: MetroConfig,
|
|
102
|
+
options?: {
|
|
103
|
+
projectRoot?: string;
|
|
104
|
+
targets?: string[];
|
|
105
|
+
}
|
|
106
|
+
): MetroConfig {
|
|
107
|
+
console.log(`\n[expo-targets-metro] 🚀 Initializing Metro configuration...`);
|
|
108
|
+
const projectRoot = options?.projectRoot || process.cwd();
|
|
109
|
+
console.log(`[expo-targets-metro] 📂 Using project root: ${projectRoot}`);
|
|
110
|
+
|
|
111
|
+
const targetEntryPoints = scanTargetsDirectory(projectRoot);
|
|
112
|
+
|
|
113
|
+
if (targetEntryPoints.length > 0) {
|
|
114
|
+
console.log(
|
|
115
|
+
`\n[expo-targets-metro] ✅ Found ${targetEntryPoints.length} target(s) with React Native entry points:`
|
|
116
|
+
);
|
|
117
|
+
targetEntryPoints.forEach((t) => {
|
|
118
|
+
console.log(` - ${t.targetName}: ${t.entryPath}`);
|
|
119
|
+
});
|
|
120
|
+
} else {
|
|
121
|
+
console.log(
|
|
122
|
+
`\n[expo-targets-metro] ⚠️ No targets with React Native entry points found`
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Create a map for quick lookup of target names to bundle roots and entry paths
|
|
127
|
+
const targetMap = new Map<
|
|
128
|
+
string,
|
|
129
|
+
{ bundleRoot: string; entryPath: string }
|
|
130
|
+
>();
|
|
131
|
+
targetEntryPoints.forEach((target) => {
|
|
132
|
+
// Calculate the bundle root that would be used in ReactNativeViewController
|
|
133
|
+
// e.g., "./targets/rn-share/index.tsx" -> "targets/rn-share/index"
|
|
134
|
+
const relativeEntry = path.relative(projectRoot, target.entryPath);
|
|
135
|
+
const bundleRoot = relativeEntry.replace(/\.(tsx?|jsx?)$/, '');
|
|
136
|
+
|
|
137
|
+
targetMap.set(target.targetName, {
|
|
138
|
+
bundleRoot,
|
|
139
|
+
entryPath: target.entryPath,
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
console.log(
|
|
143
|
+
`[expo-targets-metro] 📌 Registered: ${target.targetName} -> "${bundleRoot}"`
|
|
144
|
+
);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const originalGetTransformOptions =
|
|
148
|
+
metroConfig.transformer?.getTransformOptions;
|
|
149
|
+
const originalRewriteRequestUrl = metroConfig.server?.rewriteRequestUrl;
|
|
150
|
+
|
|
151
|
+
console.log(
|
|
152
|
+
`[expo-targets-metro] 🔧 Setting up URL rewriting for target entry points...`
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
...metroConfig,
|
|
157
|
+
resolver: {
|
|
158
|
+
...metroConfig.resolver,
|
|
159
|
+
// Keep custom resolver for initial module resolution
|
|
160
|
+
resolveRequest: (context, moduleName, platform) => {
|
|
161
|
+
// Check if module matches any target bundle root
|
|
162
|
+
const normalizedModuleName = moduleName.replace(/^\.\//, '');
|
|
163
|
+
|
|
164
|
+
for (const [
|
|
165
|
+
targetName,
|
|
166
|
+
{ bundleRoot, entryPath },
|
|
167
|
+
] of targetMap.entries()) {
|
|
168
|
+
if (
|
|
169
|
+
normalizedModuleName === bundleRoot ||
|
|
170
|
+
normalizedModuleName.startsWith(bundleRoot)
|
|
171
|
+
) {
|
|
172
|
+
console.log(
|
|
173
|
+
`[expo-targets-metro] ✅ Resolved "${moduleName}" -> "${entryPath}"`
|
|
174
|
+
);
|
|
175
|
+
return {
|
|
176
|
+
type: 'sourceFile',
|
|
177
|
+
filePath: entryPath,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Fall back to default resolver
|
|
183
|
+
return context.resolveRequest(context, moduleName, platform);
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
server: {
|
|
187
|
+
...metroConfig.server,
|
|
188
|
+
rewriteRequestUrl: (url: string) => {
|
|
189
|
+
// Apply original URL rewrite first
|
|
190
|
+
const rewrittenUrl = originalRewriteRequestUrl
|
|
191
|
+
? originalRewriteRequestUrl(url)
|
|
192
|
+
: url;
|
|
193
|
+
|
|
194
|
+
// Check for target query parameter
|
|
195
|
+
const targetMatch = rewrittenUrl.match(/[?&]target=([^&]+)/);
|
|
196
|
+
|
|
197
|
+
if (targetMatch) {
|
|
198
|
+
const targetName = targetMatch[1];
|
|
199
|
+
const targetInfo = targetMap.get(targetName);
|
|
200
|
+
|
|
201
|
+
if (targetInfo) {
|
|
202
|
+
console.log(
|
|
203
|
+
`[expo-targets-metro] 🔄 Rewriting URL for target: ${targetName}`
|
|
204
|
+
);
|
|
205
|
+
// Keep the bundle root in the URL but flag it as a target bundle
|
|
206
|
+
return rewrittenUrl.replace(
|
|
207
|
+
'index.bundle',
|
|
208
|
+
`index.${targetName}.bundle`
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return rewrittenUrl;
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
transformer: {
|
|
217
|
+
...metroConfig.transformer,
|
|
218
|
+
getTransformOptions: async (
|
|
219
|
+
entryPoints: readonly string[],
|
|
220
|
+
options: any,
|
|
221
|
+
getDependenciesOf: any
|
|
222
|
+
) => {
|
|
223
|
+
console.log(
|
|
224
|
+
`[expo-targets-metro] 🔄 Transform requested for entry points:`,
|
|
225
|
+
entryPoints
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
const transformOptions = originalGetTransformOptions
|
|
229
|
+
? await originalGetTransformOptions(
|
|
230
|
+
entryPoints,
|
|
231
|
+
options,
|
|
232
|
+
getDependenciesOf
|
|
233
|
+
)
|
|
234
|
+
: {};
|
|
235
|
+
|
|
236
|
+
return {
|
|
237
|
+
...transformOptions,
|
|
238
|
+
transform: {
|
|
239
|
+
...transformOptions.transform,
|
|
240
|
+
experimentalImportSupport: false,
|
|
241
|
+
inlineRequires: true,
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "expo-targets",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Expo config plugin for Apple targets and Android app extensions",
|
|
5
|
+
"main": "build/src/index.js",
|
|
6
|
+
"types": "build/src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./build/src/index.js",
|
|
10
|
+
"require": "./build/src/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./metro": {
|
|
13
|
+
"import": "./metro/build/index.js",
|
|
14
|
+
"require": "./metro/build/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./plugin": {
|
|
17
|
+
"import": "./plugin/build/index.js",
|
|
18
|
+
"require": "./plugin/build/index.js",
|
|
19
|
+
"types": "./plugin/build/index.d.ts"
|
|
20
|
+
},
|
|
21
|
+
"./app.plugin.js": {
|
|
22
|
+
"import": "./app.plugin.js",
|
|
23
|
+
"require": "./app.plugin.js"
|
|
24
|
+
},
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "bun run build:main && bun run build:plugin && bun run build:metro",
|
|
29
|
+
"build:main": "tsc",
|
|
30
|
+
"build:plugin": "tsc --project plugin/tsconfig.build.json && bun run copy:templates",
|
|
31
|
+
"build:metro": "tsc --project metro/tsconfig.build.json",
|
|
32
|
+
"copy:templates": "mkdir -p plugin/build/ios/templates && cp plugin/src/ios/templates/*.swift plugin/build/ios/templates/",
|
|
33
|
+
"clean": "rm -rf build plugin/build metro/build",
|
|
34
|
+
"prepare": "bun run build",
|
|
35
|
+
"lint": "eslint src --ext .ts,.tsx"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@babel/parser": "^7.25.0",
|
|
39
|
+
"@babel/traverse": "^7.25.0",
|
|
40
|
+
"@babel/types": "^7.25.0",
|
|
41
|
+
"@expo/config-plugins": "^8.0.0",
|
|
42
|
+
"@expo/config-types": "^52.0.0",
|
|
43
|
+
"@expo/plist": "^0.1.0",
|
|
44
|
+
"@react-native/normalize-colors": "^0.79.2",
|
|
45
|
+
"debug": "^4.3.4",
|
|
46
|
+
"glob": "^10.4.2",
|
|
47
|
+
"xcode": "3.0.1"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"expo-module-scripts": "^4.1.7",
|
|
51
|
+
"typescript": "~5.3.3",
|
|
52
|
+
"@react-native-community/cli": "^16.0.0"
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"expo": "*",
|
|
56
|
+
"expo-constants": "*"
|
|
57
|
+
},
|
|
58
|
+
"keywords": [
|
|
59
|
+
"expo",
|
|
60
|
+
"expo-plugin",
|
|
61
|
+
"ios",
|
|
62
|
+
"widget",
|
|
63
|
+
"app-clip",
|
|
64
|
+
"imessage",
|
|
65
|
+
"apple-targets"
|
|
66
|
+
],
|
|
67
|
+
"repository": {
|
|
68
|
+
"type": "git",
|
|
69
|
+
"url": "https://github.com/csark0812/expo-targets"
|
|
70
|
+
},
|
|
71
|
+
"author": "Christopher Sarkissian",
|
|
72
|
+
"homepage": "https://github.com/csark0812/expo-targets#readme",
|
|
73
|
+
"license": "MIT"
|
|
74
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ConfigPlugin, withAppBuildGradle } from '@expo/config-plugins';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Ensures the Android app's build.gradle namespace matches the package name
|
|
5
|
+
* from app.json to prevent R and BuildConfig resolution errors.
|
|
6
|
+
*/
|
|
7
|
+
export const withAndroidAppBuildGradle: ConfigPlugin = (config) => {
|
|
8
|
+
const packageName = config.android?.package;
|
|
9
|
+
|
|
10
|
+
if (!packageName) {
|
|
11
|
+
return config;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return withAppBuildGradle(config, (config) => {
|
|
15
|
+
const { modResults } = config;
|
|
16
|
+
let contents = modResults.contents;
|
|
17
|
+
|
|
18
|
+
// Ensure namespace matches package name
|
|
19
|
+
// This handles cases where prebuild might not have set it correctly
|
|
20
|
+
const namespaceRegex = /namespace\s+["']([^"']+)["']/;
|
|
21
|
+
const match = contents.match(namespaceRegex);
|
|
22
|
+
|
|
23
|
+
if (match && match[1] !== packageName) {
|
|
24
|
+
// Replace incorrect namespace with correct package name
|
|
25
|
+
contents = contents.replace(namespaceRegex, `namespace "${packageName}"`);
|
|
26
|
+
console.log(
|
|
27
|
+
`[expo-targets] Fixed Android namespace: ${match[1]} -> ${packageName}`
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
modResults.contents = contents;
|
|
32
|
+
return config;
|
|
33
|
+
});
|
|
34
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ConfigPlugin } from '@expo/config-plugins';
|
|
2
|
+
|
|
3
|
+
import { withAndroidWidget } from './withAndroidWidget';
|
|
4
|
+
import type { TargetConfig } from '../config';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Main orchestrator for Android target configuration.
|
|
8
|
+
* Routes to specific implementation based on target type.
|
|
9
|
+
*/
|
|
10
|
+
export const withAndroidTarget: ConfigPlugin<
|
|
11
|
+
TargetConfig & { directory: string }
|
|
12
|
+
> = (config, targetConfig) => {
|
|
13
|
+
if (!targetConfig.platforms?.includes('android')) {
|
|
14
|
+
return config;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
switch (targetConfig.type) {
|
|
18
|
+
case 'widget':
|
|
19
|
+
return withAndroidWidget(config, targetConfig);
|
|
20
|
+
default:
|
|
21
|
+
console.warn(
|
|
22
|
+
`[expo-targets] Android support for ${targetConfig.type} coming later`
|
|
23
|
+
);
|
|
24
|
+
return config;
|
|
25
|
+
}
|
|
26
|
+
};
|