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,63 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
|
|
3
|
+
// Module-level flag to prevent duplicate "Found X target(s)" logs
|
|
4
|
+
let hasLoggedTargetCount = false;
|
|
5
|
+
|
|
6
|
+
export class Logger {
|
|
7
|
+
private debug: boolean;
|
|
8
|
+
|
|
9
|
+
constructor(debug: boolean = false) {
|
|
10
|
+
this.debug = debug;
|
|
11
|
+
// Reset flag when debug is enabled to allow full logging
|
|
12
|
+
if (debug) {
|
|
13
|
+
hasLoggedTargetCount = false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
log(message: string): void {
|
|
18
|
+
if (this.debug) {
|
|
19
|
+
console.log(`[expo-targets] ${message}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
logSparse(success: boolean, message: string, detail?: string): void {
|
|
24
|
+
// Prevent duplicate "Found X target(s)" logs across multiple plugin invocations
|
|
25
|
+
if (
|
|
26
|
+
!this.debug &&
|
|
27
|
+
message.startsWith('Found') &&
|
|
28
|
+
message.includes('target(s)')
|
|
29
|
+
) {
|
|
30
|
+
if (hasLoggedTargetCount) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
hasLoggedTargetCount = true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!this.debug) {
|
|
37
|
+
// Match Expo's style: green checkmark + message + dimmed detail
|
|
38
|
+
const symbol = success ? chalk.green('✔') : '✖';
|
|
39
|
+
const detailStr = detail ? chalk.dim(` | ${detail}`) : '';
|
|
40
|
+
console.log(`${symbol} ${message}${detailStr}`);
|
|
41
|
+
} else {
|
|
42
|
+
console.log(`[expo-targets] ${message}${detail ? ` - ${detail}` : ''}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
warn(message: string): void {
|
|
47
|
+
if (this.debug) {
|
|
48
|
+
console.warn(`[expo-targets] ${message}`);
|
|
49
|
+
} else {
|
|
50
|
+
const symbol = '⚠';
|
|
51
|
+
console.warn(`${symbol} ${message}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
error(message: string): void {
|
|
56
|
+
console.error(`[expo-targets] ${message}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Reset flag for testing / new processes
|
|
61
|
+
export function resetLoggerState(): void {
|
|
62
|
+
hasLoggedTargetCount = false;
|
|
63
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import * as parser from '@babel/parser';
|
|
2
|
+
import traverse from '@babel/traverse';
|
|
3
|
+
import * as t from '@babel/types';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
|
|
7
|
+
import type { TargetConfig } from './config';
|
|
8
|
+
|
|
9
|
+
export function parseTargetConfigFromFile(filePath: string): TargetConfig {
|
|
10
|
+
const code = fs.readFileSync(filePath, 'utf-8');
|
|
11
|
+
const directoryName = path.basename(path.dirname(filePath));
|
|
12
|
+
|
|
13
|
+
const ast = parser.parse(code, {
|
|
14
|
+
sourceType: 'module',
|
|
15
|
+
plugins: ['typescript', 'jsx'],
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
let targetConfig: TargetConfig | null = null;
|
|
19
|
+
|
|
20
|
+
traverse(ast, {
|
|
21
|
+
CallExpression(path) {
|
|
22
|
+
const { node } = path;
|
|
23
|
+
|
|
24
|
+
if (
|
|
25
|
+
t.isIdentifier(node.callee) &&
|
|
26
|
+
node.callee.name === 'defineTarget' &&
|
|
27
|
+
node.arguments.length > 0
|
|
28
|
+
) {
|
|
29
|
+
const firstArg = node.arguments[0];
|
|
30
|
+
|
|
31
|
+
if (t.isObjectExpression(firstArg)) {
|
|
32
|
+
targetConfig = evaluateObjectExpression(firstArg);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (!targetConfig) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
`No defineTarget() call found in ${filePath}. Make sure you export a target using defineTarget().`
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Cast to any to work with discriminated union
|
|
45
|
+
const config = targetConfig as any;
|
|
46
|
+
|
|
47
|
+
// Validate name is specified
|
|
48
|
+
if (!config.name) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Target in ${filePath} must specify 'name' property in defineTarget() configuration.`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Validate platforms array
|
|
55
|
+
if (
|
|
56
|
+
!config.platforms ||
|
|
57
|
+
!Array.isArray(config.platforms) ||
|
|
58
|
+
config.platforms.length === 0
|
|
59
|
+
) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
`Target '${config.name}' must specify platforms array (e.g., platforms: ['ios'])`
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return config as TargetConfig;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function evaluateObjectExpression(node: t.ObjectExpression): any {
|
|
69
|
+
const obj: any = {};
|
|
70
|
+
|
|
71
|
+
for (const prop of node.properties) {
|
|
72
|
+
if (t.isObjectProperty(prop) && t.isIdentifier(prop.key)) {
|
|
73
|
+
const key = prop.key.name;
|
|
74
|
+
obj[key] = evaluateNode(prop.value);
|
|
75
|
+
} else if (t.isObjectProperty(prop) && t.isStringLiteral(prop.key)) {
|
|
76
|
+
const key = prop.key.value;
|
|
77
|
+
obj[key] = evaluateNode(prop.value);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return obj;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function evaluateNode(node: t.Node): any {
|
|
85
|
+
if (t.isStringLiteral(node)) {
|
|
86
|
+
return node.value;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (t.isNumericLiteral(node)) {
|
|
90
|
+
return node.value;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (t.isBooleanLiteral(node)) {
|
|
94
|
+
return node.value;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (t.isNullLiteral(node)) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (t.isObjectExpression(node)) {
|
|
102
|
+
return evaluateObjectExpression(node);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (t.isArrayExpression(node)) {
|
|
106
|
+
return node.elements.map((el) => (el ? evaluateNode(el) : null));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (t.isTemplateLiteral(node) && node.expressions.length === 0) {
|
|
110
|
+
return node.quasis[0].value.cooked;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
console.warn(`[expo-targets] Unable to evaluate node type: ${node.type}`);
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { ConfigPlugin } from '@expo/config-plugins';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { globSync } from 'glob';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
|
|
6
|
+
import { withAndroidTarget } from './android/withAndroidTarget';
|
|
7
|
+
import { withIOSTarget } from './ios/config-plugins/withIOSTarget';
|
|
8
|
+
import { Logger } from './logger';
|
|
9
|
+
|
|
10
|
+
export const withTargetsDir: ConfigPlugin<{
|
|
11
|
+
targetsRoot?: string;
|
|
12
|
+
debug?: boolean;
|
|
13
|
+
}> = (config, options) => {
|
|
14
|
+
const targetsRoot = options?.targetsRoot || './targets';
|
|
15
|
+
const debug = options?.debug ?? false;
|
|
16
|
+
const logger = new Logger(debug);
|
|
17
|
+
const projectRoot = config._internal!.projectRoot;
|
|
18
|
+
|
|
19
|
+
// Look for expo-target.config files (supports .js, .ts, or .json)
|
|
20
|
+
const targetConfigFiles = globSync(
|
|
21
|
+
`${targetsRoot}/*/expo-target.config.@(js|ts|json)`,
|
|
22
|
+
{
|
|
23
|
+
cwd: projectRoot,
|
|
24
|
+
absolute: true,
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
if (targetConfigFiles.length > 0) {
|
|
29
|
+
logger.logSparse(true, `Found ${targetConfigFiles.length} target(s)`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Collect target configs for runtime access
|
|
33
|
+
const targetConfigs: any[] = [];
|
|
34
|
+
|
|
35
|
+
targetConfigFiles.forEach((targetPath) => {
|
|
36
|
+
let evaluatedConfig = require(targetPath);
|
|
37
|
+
|
|
38
|
+
// Handle ES module default export (export default config)
|
|
39
|
+
if (evaluatedConfig && evaluatedConfig.default) {
|
|
40
|
+
evaluatedConfig = evaluatedConfig.default;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Handle function exports (like app.config.js)
|
|
44
|
+
if (typeof evaluatedConfig === 'function') {
|
|
45
|
+
evaluatedConfig = evaluatedConfig(config);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const targetDirName = path.basename(path.dirname(targetPath));
|
|
49
|
+
const targetDirectory = path.relative(
|
|
50
|
+
projectRoot,
|
|
51
|
+
path.dirname(targetPath)
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
// Validate name is specified
|
|
55
|
+
if (!evaluatedConfig.name) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
`Target in ${targetDirName} must specify 'name' property in expo-target.config`
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const targetName = evaluatedConfig.name;
|
|
62
|
+
|
|
63
|
+
logger.log(
|
|
64
|
+
`Processing ${targetDirName}: type=${evaluatedConfig.type}, name=${targetName}`
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const supportsIOS = evaluatedConfig.platforms.includes('ios');
|
|
68
|
+
const supportsAndroid = evaluatedConfig.platforms.includes('android');
|
|
69
|
+
|
|
70
|
+
logger.log(
|
|
71
|
+
`${targetDirName}: iOS=${supportsIOS}, Android=${supportsAndroid}`
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
// Resolve appGroup (inherit from main app if not specified)
|
|
75
|
+
let appGroup = evaluatedConfig.appGroup;
|
|
76
|
+
if (!appGroup) {
|
|
77
|
+
const mainAppGroups =
|
|
78
|
+
config.ios?.entitlements?.['com.apple.security.application-groups'];
|
|
79
|
+
if (Array.isArray(mainAppGroups) && mainAppGroups.length > 0) {
|
|
80
|
+
appGroup = mainAppGroups[0];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (supportsIOS && evaluatedConfig.ios) {
|
|
85
|
+
config = withIOSTarget(config, {
|
|
86
|
+
...evaluatedConfig.ios,
|
|
87
|
+
type: evaluatedConfig.type,
|
|
88
|
+
name: targetName,
|
|
89
|
+
displayName: evaluatedConfig.displayName,
|
|
90
|
+
appGroup: evaluatedConfig.appGroup,
|
|
91
|
+
entry: evaluatedConfig.entry,
|
|
92
|
+
excludedPackages: evaluatedConfig.excludedPackages,
|
|
93
|
+
directory: targetDirectory,
|
|
94
|
+
configPath: targetPath,
|
|
95
|
+
logger,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (supportsAndroid) {
|
|
100
|
+
config = withAndroidTarget(config, {
|
|
101
|
+
...evaluatedConfig,
|
|
102
|
+
directory: targetDirectory,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Store full config for runtime access (with resolved appGroup)
|
|
107
|
+
targetConfigs.push({
|
|
108
|
+
...evaluatedConfig,
|
|
109
|
+
appGroup,
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// Inject target configs into expo config for runtime access
|
|
114
|
+
config.extra = {
|
|
115
|
+
...config.extra,
|
|
116
|
+
targets: targetConfigs,
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
return config;
|
|
120
|
+
};
|
package/src/Target.ts
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import Constants from 'expo-constants';
|
|
2
|
+
import { AppRegistry, ComponentProvider } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { Extension, type SharedData } from './modules/extension';
|
|
5
|
+
import {
|
|
6
|
+
Messages,
|
|
7
|
+
type PresentationStyle,
|
|
8
|
+
type MessageLayout,
|
|
9
|
+
type ConversationInfo,
|
|
10
|
+
} from './modules/messages';
|
|
11
|
+
import { AppGroupStorage, getTargetsConfigFromBundle } from './modules/storage';
|
|
12
|
+
import type {
|
|
13
|
+
TargetConfig,
|
|
14
|
+
ExtensionType,
|
|
15
|
+
ReactNativeCompatibleType,
|
|
16
|
+
} from '../plugin/src/config';
|
|
17
|
+
|
|
18
|
+
export interface BaseTarget {
|
|
19
|
+
name: string;
|
|
20
|
+
type: ExtensionType;
|
|
21
|
+
appGroup: string;
|
|
22
|
+
storage: AppGroupStorage;
|
|
23
|
+
config: TargetConfig;
|
|
24
|
+
setData(data: Record<string, any>): void;
|
|
25
|
+
getData<T extends Record<string, any>>(): T;
|
|
26
|
+
refresh(): void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface ExtensionTarget extends BaseTarget {
|
|
30
|
+
type: ReactNativeCompatibleType;
|
|
31
|
+
close: () => void;
|
|
32
|
+
openHostApp: (path?: string) => void;
|
|
33
|
+
getSharedData: () => SharedData | null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface MessagesExtensionTarget
|
|
37
|
+
extends Omit<ExtensionTarget, 'close'> {
|
|
38
|
+
type: 'messages';
|
|
39
|
+
getPresentationStyle: () => PresentationStyle | null;
|
|
40
|
+
requestPresentationStyle: (style: PresentationStyle) => void;
|
|
41
|
+
sendMessage: (layout: MessageLayout) => void;
|
|
42
|
+
sendUpdate: (layout: MessageLayout, sessionId: string) => void;
|
|
43
|
+
createSession: () => string | null;
|
|
44
|
+
getConversationInfo: () => ConversationInfo | null;
|
|
45
|
+
addEventListener: (
|
|
46
|
+
eventName: 'onPresentationStyleChange',
|
|
47
|
+
listener: (style: PresentationStyle) => void
|
|
48
|
+
) => { remove: () => void };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface NonExtensionTarget extends BaseTarget {
|
|
52
|
+
close?: undefined;
|
|
53
|
+
openHostApp?: undefined;
|
|
54
|
+
getSharedData?: undefined;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type Target =
|
|
58
|
+
| ExtensionTarget
|
|
59
|
+
| MessagesExtensionTarget
|
|
60
|
+
| NonExtensionTarget;
|
|
61
|
+
|
|
62
|
+
function getTargetConfig(targetName: string): TargetConfig | null {
|
|
63
|
+
const expoConfig = Constants.expoConfig;
|
|
64
|
+
|
|
65
|
+
// Try expo config first (works in main app)
|
|
66
|
+
let targets = (expoConfig?.extra?.targets as TargetConfig[]) || [];
|
|
67
|
+
|
|
68
|
+
// Fallback to Info.plist for extensions
|
|
69
|
+
if (targets.length === 0) {
|
|
70
|
+
const bundleTargets = getTargetsConfigFromBundle();
|
|
71
|
+
if (bundleTargets) {
|
|
72
|
+
console.log(
|
|
73
|
+
'[expo-targets] Loaded targets config from bundle Info.plist'
|
|
74
|
+
);
|
|
75
|
+
targets = bundleTargets as TargetConfig[];
|
|
76
|
+
} else {
|
|
77
|
+
console.warn(
|
|
78
|
+
'[expo-targets] No targets config found in expo config or bundle'
|
|
79
|
+
);
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const target = targets.find((t) => t.name === targetName);
|
|
85
|
+
|
|
86
|
+
if (!target) {
|
|
87
|
+
console.warn(`[expo-targets] Target "${targetName}" not found`);
|
|
88
|
+
console.warn(
|
|
89
|
+
`[expo-targets] Available targets: ${targets.map((t) => t.name).join(', ')}`
|
|
90
|
+
);
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return target;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function getTargetAppGroup(
|
|
98
|
+
targetName: string,
|
|
99
|
+
config?: TargetConfig
|
|
100
|
+
): string | null {
|
|
101
|
+
const targetConfig = config || getTargetConfig(targetName);
|
|
102
|
+
if (!targetConfig) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return targetConfig.appGroup || null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const EXTENSION_TYPES: Set<ReactNativeCompatibleType> = new Set([
|
|
110
|
+
'share',
|
|
111
|
+
'action',
|
|
112
|
+
'clip',
|
|
113
|
+
'messages',
|
|
114
|
+
]);
|
|
115
|
+
|
|
116
|
+
function isExtensionType(
|
|
117
|
+
type: ExtensionType
|
|
118
|
+
): type is ReactNativeCompatibleType {
|
|
119
|
+
return EXTENSION_TYPES.has(type as ReactNativeCompatibleType);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Function overloads for better type inference
|
|
123
|
+
export function createTarget<T extends 'messages'>(
|
|
124
|
+
targetName: string,
|
|
125
|
+
componentFunc?: React.ComponentType<any>
|
|
126
|
+
): MessagesExtensionTarget;
|
|
127
|
+
export function createTarget<
|
|
128
|
+
T extends Exclude<ReactNativeCompatibleType, 'messages'>,
|
|
129
|
+
>(
|
|
130
|
+
targetName: string,
|
|
131
|
+
componentFunc?: React.ComponentType<any>
|
|
132
|
+
): ExtensionTarget;
|
|
133
|
+
export function createTarget<
|
|
134
|
+
T extends Exclude<ExtensionType, ReactNativeCompatibleType>,
|
|
135
|
+
>(
|
|
136
|
+
targetName: string,
|
|
137
|
+
componentFunc?: React.ComponentType<any>
|
|
138
|
+
): NonExtensionTarget;
|
|
139
|
+
export function createTarget(
|
|
140
|
+
targetName: string,
|
|
141
|
+
componentFunc?: React.ComponentType<any>
|
|
142
|
+
): Target;
|
|
143
|
+
export function createTarget<T extends ExtensionType = ExtensionType>(
|
|
144
|
+
targetName: string,
|
|
145
|
+
componentFunc?: React.ComponentType<any>
|
|
146
|
+
): Target {
|
|
147
|
+
const config = getTargetConfig(targetName);
|
|
148
|
+
if (!config) {
|
|
149
|
+
throw new Error(
|
|
150
|
+
`Target "${targetName}" not found. Ensure it's defined in app.json under "extra.targets"`
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (componentFunc && 'entry' in config && config.entry) {
|
|
155
|
+
let qualifiedComponent = componentFunc;
|
|
156
|
+
|
|
157
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
158
|
+
try {
|
|
159
|
+
const { withDevTools } = require('expo/src/launch/withDevTools');
|
|
160
|
+
qualifiedComponent = withDevTools(componentFunc);
|
|
161
|
+
} catch (error) {
|
|
162
|
+
console.warn(
|
|
163
|
+
'[expo-targets] Could not load withDevTools, using component as-is'
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
AppRegistry.registerComponent(targetName, () => qualifiedComponent);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const appGroup = getTargetAppGroup(targetName, config);
|
|
172
|
+
if (!appGroup) {
|
|
173
|
+
throw new Error(
|
|
174
|
+
`App Group not configured for target "${targetName}". Add "appGroup" to your target config.`
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const storage = new AppGroupStorage(appGroup);
|
|
179
|
+
const baseTarget: BaseTarget = {
|
|
180
|
+
name: targetName,
|
|
181
|
+
type: config.type,
|
|
182
|
+
appGroup,
|
|
183
|
+
storage,
|
|
184
|
+
config,
|
|
185
|
+
setData(data: Record<string, any>) {
|
|
186
|
+
storage.setData(data);
|
|
187
|
+
},
|
|
188
|
+
getData<T extends Record<string, any>>(): T {
|
|
189
|
+
return storage.getData<T>();
|
|
190
|
+
},
|
|
191
|
+
refresh() {
|
|
192
|
+
storage.refresh(targetName);
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
if (isExtensionType(config.type)) {
|
|
197
|
+
const extension = new Extension();
|
|
198
|
+
|
|
199
|
+
if (config.type === 'messages') {
|
|
200
|
+
const messages = new Messages();
|
|
201
|
+
const messagesTarget: MessagesExtensionTarget = {
|
|
202
|
+
...baseTarget,
|
|
203
|
+
type: 'messages',
|
|
204
|
+
openHostApp: (path?: string) => extension.openHostApp(path),
|
|
205
|
+
getSharedData: () => extension.getSharedData(),
|
|
206
|
+
getPresentationStyle: () => messages.getPresentationStyle(),
|
|
207
|
+
requestPresentationStyle: (style: PresentationStyle) =>
|
|
208
|
+
messages.requestPresentationStyle(style),
|
|
209
|
+
sendMessage: (layout: MessageLayout) => messages.sendMessage(layout),
|
|
210
|
+
sendUpdate: (layout: MessageLayout, sessionId: string) =>
|
|
211
|
+
messages.sendUpdate(layout, sessionId),
|
|
212
|
+
createSession: () => messages.createSession(),
|
|
213
|
+
getConversationInfo: () => messages.getConversationInfo(),
|
|
214
|
+
addEventListener: (
|
|
215
|
+
eventName: 'onPresentationStyleChange',
|
|
216
|
+
listener: (style: PresentationStyle) => void
|
|
217
|
+
) => messages.addEventListener(eventName, listener),
|
|
218
|
+
};
|
|
219
|
+
return messagesTarget as any;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const extensionTarget: ExtensionTarget = {
|
|
223
|
+
...baseTarget,
|
|
224
|
+
type: config.type as ReactNativeCompatibleType,
|
|
225
|
+
close: () => extension.close(),
|
|
226
|
+
openHostApp: (path?: string) => extension.openHostApp(path),
|
|
227
|
+
getSharedData: () => extension.getSharedData(),
|
|
228
|
+
};
|
|
229
|
+
return extensionTarget as any;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const nonExtensionTarget: NonExtensionTarget = {
|
|
233
|
+
...baseTarget,
|
|
234
|
+
close: undefined,
|
|
235
|
+
openHostApp: undefined,
|
|
236
|
+
getSharedData: undefined,
|
|
237
|
+
};
|
|
238
|
+
return nonExtensionTarget as any;
|
|
239
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Target API
|
|
2
|
+
export { createTarget } from './Target';
|
|
3
|
+
export type {
|
|
4
|
+
Target,
|
|
5
|
+
ExtensionTarget,
|
|
6
|
+
MessagesExtensionTarget,
|
|
7
|
+
NonExtensionTarget,
|
|
8
|
+
BaseTarget,
|
|
9
|
+
} from './Target';
|
|
10
|
+
|
|
11
|
+
// Storage module
|
|
12
|
+
export {
|
|
13
|
+
AppGroupStorage,
|
|
14
|
+
refreshAllTargets,
|
|
15
|
+
clearSharedData,
|
|
16
|
+
} from './modules/storage';
|
|
17
|
+
|
|
18
|
+
// Extension module
|
|
19
|
+
export {
|
|
20
|
+
Extension,
|
|
21
|
+
close,
|
|
22
|
+
openHostApp,
|
|
23
|
+
getSharedData,
|
|
24
|
+
} from './modules/extension';
|
|
25
|
+
export type { SharedData } from './modules/extension';
|
|
26
|
+
|
|
27
|
+
// Messages module
|
|
28
|
+
export {
|
|
29
|
+
getPresentationStyle,
|
|
30
|
+
requestPresentationStyle,
|
|
31
|
+
sendMessage,
|
|
32
|
+
sendUpdate,
|
|
33
|
+
createSession,
|
|
34
|
+
getConversationInfo,
|
|
35
|
+
addEventListener as addMessagesEventListener,
|
|
36
|
+
} from './modules/messages';
|
|
37
|
+
export type {
|
|
38
|
+
PresentationStyle,
|
|
39
|
+
MessageLayout,
|
|
40
|
+
ConversationInfo,
|
|
41
|
+
SelectedMessage,
|
|
42
|
+
} from './modules/messages';
|
|
43
|
+
|
|
44
|
+
// Config types
|
|
45
|
+
export type {
|
|
46
|
+
TargetConfig,
|
|
47
|
+
IOSTargetConfig,
|
|
48
|
+
AndroidTargetConfig,
|
|
49
|
+
ExtensionType,
|
|
50
|
+
ReactNativeCompatibleType,
|
|
51
|
+
Color,
|
|
52
|
+
} from '../plugin/src/config';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { requireNativeModule } from 'expo-modules-core';
|
|
2
|
+
import { Platform } from 'react-native';
|
|
3
|
+
|
|
4
|
+
const ExpoTargetsExtensionModule = requireNativeModule('ExpoTargetsExtension');
|
|
5
|
+
|
|
6
|
+
export interface SharedData {
|
|
7
|
+
text?: string;
|
|
8
|
+
url?: string;
|
|
9
|
+
images?: string[];
|
|
10
|
+
webpageUrl?: string;
|
|
11
|
+
webpageTitle?: string;
|
|
12
|
+
preprocessedData?: any;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class Extension {
|
|
16
|
+
close() {
|
|
17
|
+
console.log('[Extension] close() called, platform:', Platform.OS);
|
|
18
|
+
if (Platform.OS === 'ios') {
|
|
19
|
+
console.log('[Extension] Calling native closeExtension()');
|
|
20
|
+
ExpoTargetsExtensionModule.closeExtension();
|
|
21
|
+
console.log('[Extension] Native closeExtension() returned');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
openHostApp(path: string = '') {
|
|
26
|
+
if (Platform.OS === 'ios') {
|
|
27
|
+
ExpoTargetsExtensionModule.openHostApp(path);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
getSharedData(): SharedData | null {
|
|
32
|
+
if (Platform.OS === 'ios') {
|
|
33
|
+
return ExpoTargetsExtensionModule.getSharedData();
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const close = () => {
|
|
40
|
+
const ext = new Extension();
|
|
41
|
+
ext.close();
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const openHostApp = (path: string = '') => {
|
|
45
|
+
const ext = new Extension();
|
|
46
|
+
ext.openHostApp(path);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const getSharedData = (): SharedData | null => {
|
|
50
|
+
const ext = new Extension();
|
|
51
|
+
return ext.getSharedData();
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export type { SharedData as ExtensionSharedData };
|