1082815dcSEvan Bacon/**
2082815dcSEvan Bacon * These are the versioned first-party plugins with some of the future third-party plugins mixed in for legacy support.
3082815dcSEvan Bacon */
4082815dcSEvan Baconimport {
5082815dcSEvan Bacon  AndroidConfig,
6082815dcSEvan Bacon  ConfigPlugin,
7082815dcSEvan Bacon  IOSConfig,
8082815dcSEvan Bacon  StaticPlugin,
9082815dcSEvan Bacon  withPlugins,
10082815dcSEvan Bacon  withStaticPlugin,
11082815dcSEvan Bacon} from '@expo/config-plugins';
12082815dcSEvan Baconimport { ExpoConfig } from '@expo/config-types';
13082815dcSEvan Baconimport Debug from 'debug';
14082815dcSEvan Bacon
15082815dcSEvan Baconimport { withAndroidIcons } from './icons/withAndroidIcons';
16082815dcSEvan Baconimport { withIosIcons } from './icons/withIosIcons';
17082815dcSEvan Baconimport withAdMob from './unversioned/expo-ads-admob/expo-ads-admob';
18082815dcSEvan Baconimport withAppleAuthentication from './unversioned/expo-apple-authentication';
19082815dcSEvan Baconimport withBranch from './unversioned/expo-branch/expo-branch';
20082815dcSEvan Baconimport withContacts from './unversioned/expo-contacts';
21082815dcSEvan Baconimport withDocumentPicker from './unversioned/expo-document-picker';
22082815dcSEvan Baconimport withNavigationBar from './unversioned/expo-navigation-bar/expo-navigation-bar';
23082815dcSEvan Baconimport withNotifications from './unversioned/expo-notifications/expo-notifications';
24082815dcSEvan Baconimport withSplashScreen from './unversioned/expo-splash-screen/expo-splash-screen';
25082815dcSEvan Baconimport withSystemUI from './unversioned/expo-system-ui/expo-system-ui';
26082815dcSEvan Baconimport withUpdates from './unversioned/expo-updates';
27082815dcSEvan Baconimport withMaps from './unversioned/react-native-maps';
288a424bebSJames Ideimport { shouldSkipAutoPlugin } from '../getAutolinkedPackages';
29082815dcSEvan Bacon
30082815dcSEvan Baconconst debug = Debug('expo:prebuild-config');
31082815dcSEvan Bacon
32082815dcSEvan Bacon/**
33082815dcSEvan Bacon * Config plugin to apply all of the custom Expo iOS config plugins we support by default.
34a8773690SCedric van Putten * TODO: In the future most of this should go into versioned packages like expo-updates, etc...
35082815dcSEvan Bacon */
36082815dcSEvan Baconexport const withIosExpoPlugins: ConfigPlugin<{
37082815dcSEvan Bacon  bundleIdentifier: string;
38082815dcSEvan Bacon}> = (config, { bundleIdentifier }) => {
39082815dcSEvan Bacon  // Set the bundle ID ahead of time.
40082815dcSEvan Bacon  if (!config.ios) config.ios = {};
41082815dcSEvan Bacon  config.ios.bundleIdentifier = bundleIdentifier;
42082815dcSEvan Bacon
43082815dcSEvan Bacon  return withPlugins(config, [
44082815dcSEvan Bacon    [IOSConfig.BundleIdentifier.withBundleIdentifier, { bundleIdentifier }],
45082815dcSEvan Bacon    IOSConfig.Swift.withSwiftBridgingHeader,
46082815dcSEvan Bacon    IOSConfig.Swift.withNoopSwiftFile,
47082815dcSEvan Bacon    IOSConfig.Google.withGoogle,
48082815dcSEvan Bacon    IOSConfig.Name.withDisplayName,
49082815dcSEvan Bacon    IOSConfig.Name.withProductName,
50082815dcSEvan Bacon    IOSConfig.Orientation.withOrientation,
51082815dcSEvan Bacon    IOSConfig.RequiresFullScreen.withRequiresFullScreen,
52082815dcSEvan Bacon    IOSConfig.Scheme.withScheme,
53082815dcSEvan Bacon    IOSConfig.UsesNonExemptEncryption.withUsesNonExemptEncryption,
54082815dcSEvan Bacon    IOSConfig.Version.withBuildNumber,
55082815dcSEvan Bacon    IOSConfig.Version.withVersion,
56082815dcSEvan Bacon    IOSConfig.Google.withGoogleServicesFile,
57082815dcSEvan Bacon    IOSConfig.BuildProperties.withJsEnginePodfileProps,
58082815dcSEvan Bacon    // Entitlements
59082815dcSEvan Bacon    IOSConfig.Entitlements.withAssociatedDomains,
60082815dcSEvan Bacon    // XcodeProject
61082815dcSEvan Bacon    IOSConfig.DeviceFamily.withDeviceFamily,
62082815dcSEvan Bacon    IOSConfig.Bitcode.withBitcode,
63082815dcSEvan Bacon    IOSConfig.Locales.withLocales,
64082815dcSEvan Bacon    // Dangerous
65082815dcSEvan Bacon    withIosIcons,
66082815dcSEvan Bacon  ]);
67082815dcSEvan Bacon};
68082815dcSEvan Bacon
69082815dcSEvan Bacon/**
70082815dcSEvan Bacon * Config plugin to apply all of the custom Expo Android config plugins we support by default.
71a8773690SCedric van Putten * TODO: In the future most of this should go into versioned packages like expo-updates, etc...
72082815dcSEvan Bacon */
73082815dcSEvan Baconexport const withAndroidExpoPlugins: ConfigPlugin<{
74082815dcSEvan Bacon  package: string;
75082815dcSEvan Bacon}> = (config, props) => {
76082815dcSEvan Bacon  // Set the package name ahead of time.
77082815dcSEvan Bacon  if (!config.android) config.android = {};
78082815dcSEvan Bacon  config.android.package = props.package;
79082815dcSEvan Bacon
80082815dcSEvan Bacon  return withPlugins(config, [
81082815dcSEvan Bacon    // gradle.properties
82082815dcSEvan Bacon    AndroidConfig.BuildProperties.withJsEngineGradleProps,
83082815dcSEvan Bacon
84082815dcSEvan Bacon    // settings.gradle
85082815dcSEvan Bacon    AndroidConfig.Name.withNameSettingsGradle,
86082815dcSEvan Bacon
87082815dcSEvan Bacon    // project build.gradle
88082815dcSEvan Bacon    AndroidConfig.GoogleServices.withClassPath,
89082815dcSEvan Bacon
90082815dcSEvan Bacon    // app/build.gradle
91082815dcSEvan Bacon    AndroidConfig.GoogleServices.withApplyPlugin,
92082815dcSEvan Bacon    AndroidConfig.Package.withPackageGradle,
93082815dcSEvan Bacon    AndroidConfig.Version.withVersion,
94082815dcSEvan Bacon
95082815dcSEvan Bacon    // AndroidManifest.xml
96082815dcSEvan Bacon    AndroidConfig.AllowBackup.withAllowBackup,
97082815dcSEvan Bacon    AndroidConfig.WindowSoftInputMode.withWindowSoftInputMode,
98082815dcSEvan Bacon    // Note: The withAndroidIntentFilters plugin must appear before the withScheme
99082815dcSEvan Bacon    // plugin or withScheme will override the output of withAndroidIntentFilters.
100082815dcSEvan Bacon    AndroidConfig.IntentFilters.withAndroidIntentFilters,
101082815dcSEvan Bacon    AndroidConfig.Scheme.withScheme,
102082815dcSEvan Bacon    AndroidConfig.Orientation.withOrientation,
103082815dcSEvan Bacon    AndroidConfig.Permissions.withInternalBlockedPermissions,
104082815dcSEvan Bacon    AndroidConfig.Permissions.withPermissions,
105082815dcSEvan Bacon
106082815dcSEvan Bacon    // strings.xml
107082815dcSEvan Bacon    AndroidConfig.Name.withName,
108082815dcSEvan Bacon
109082815dcSEvan Bacon    // Dangerous -- these plugins run in reverse order.
110082815dcSEvan Bacon    AndroidConfig.GoogleServices.withGoogleServicesFile,
111082815dcSEvan Bacon
112082815dcSEvan Bacon    // Modify colors.xml and styles.xml
113082815dcSEvan Bacon    AndroidConfig.StatusBar.withStatusBar,
114082815dcSEvan Bacon    AndroidConfig.PrimaryColor.withPrimaryColor,
115082815dcSEvan Bacon
116082815dcSEvan Bacon    withAndroidIcons,
117082815dcSEvan Bacon    // If we renamed the package, we should also move it around and rename it in source files
118082815dcSEvan Bacon    // Added last to ensure this plugin runs first. Out of tree solutions will mistakenly resolve the package incorrectly otherwise.
119082815dcSEvan Bacon    AndroidConfig.Package.withPackageRefactor,
120082815dcSEvan Bacon  ]);
121082815dcSEvan Bacon};
122082815dcSEvan Bacon
123082815dcSEvan Bacon// Must keep in sync with `withVersionedExpoSDKPlugins`
124082815dcSEvan Baconconst versionedExpoSDKPackages: string[] = [
125082815dcSEvan Bacon  'react-native-maps',
126082815dcSEvan Bacon  'expo-ads-admob',
127082815dcSEvan Bacon  'expo-apple-authentication',
128082815dcSEvan Bacon  'expo-contacts',
129082815dcSEvan Bacon  'expo-notifications',
130082815dcSEvan Bacon  'expo-updates',
131082815dcSEvan Bacon  'expo-branch',
132082815dcSEvan Bacon  'expo-navigation-bar',
133082815dcSEvan Bacon  'expo-document-picker',
134082815dcSEvan Bacon  'expo-splash-screen',
135082815dcSEvan Bacon  'expo-system-ui',
136082815dcSEvan Bacon];
137082815dcSEvan Bacon
138*82ade864SWill Schurmanexport const withVersionedExpoSDKPlugins: ConfigPlugin = (config) => {
139082815dcSEvan Bacon  return withPlugins(config, [
140082815dcSEvan Bacon    withMaps,
141082815dcSEvan Bacon    withAdMob,
142082815dcSEvan Bacon    withAppleAuthentication,
143082815dcSEvan Bacon    withContacts,
144082815dcSEvan Bacon    withNotifications,
145*82ade864SWill Schurman    withUpdates,
146082815dcSEvan Bacon    withBranch,
147082815dcSEvan Bacon    withDocumentPicker,
148082815dcSEvan Bacon    // System UI must come before splash screen as they overlap
149082815dcSEvan Bacon    // and splash screen will warn about conflicting rules.
150082815dcSEvan Bacon    withSystemUI,
151082815dcSEvan Bacon    withSplashScreen,
152082815dcSEvan Bacon    withNavigationBar,
153082815dcSEvan Bacon  ]);
154082815dcSEvan Bacon};
155082815dcSEvan Bacon
156082815dcSEvan Baconexport function getAutoPlugins() {
157082815dcSEvan Bacon  return versionedExpoSDKPackages.concat(legacyExpoPlugins).concat(expoManagedVersionedPlugins);
158082815dcSEvan Bacon}
159082815dcSEvan Bacon
160082815dcSEvan Baconexport function getLegacyExpoPlugins() {
161082815dcSEvan Bacon  return legacyExpoPlugins;
162082815dcSEvan Bacon}
163082815dcSEvan Bacon
164082815dcSEvan Bacon// Expo managed packages that require extra update.
165082815dcSEvan Bacon// These get applied automatically to create parity with expo build in eas build.
166082815dcSEvan Baconconst legacyExpoPlugins = [
167082815dcSEvan Bacon  'expo-app-auth',
168082815dcSEvan Bacon  'expo-av',
169082815dcSEvan Bacon  'expo-background-fetch',
170082815dcSEvan Bacon  'expo-barcode-scanner',
171082815dcSEvan Bacon  'expo-brightness',
172082815dcSEvan Bacon  'expo-calendar',
173082815dcSEvan Bacon  'expo-camera',
174082815dcSEvan Bacon  'expo-cellular',
175082815dcSEvan Bacon  'expo-dev-menu',
176082815dcSEvan Bacon  'expo-dev-launcher',
177082815dcSEvan Bacon  'expo-dev-client',
178082815dcSEvan Bacon  'expo-image-picker',
179082815dcSEvan Bacon  'expo-file-system',
180082815dcSEvan Bacon  'expo-location',
181082815dcSEvan Bacon  'expo-media-library',
182082815dcSEvan Bacon  'expo-screen-orientation',
183082815dcSEvan Bacon  'expo-sensors',
184082815dcSEvan Bacon  'expo-task-manager',
185082815dcSEvan Bacon  'expo-local-authentication',
186082815dcSEvan Bacon];
187082815dcSEvan Bacon
188082815dcSEvan Bacon// Plugins that need to be automatically applied, but also get applied by expo-cli if the versioned plugin isn't available.
189082815dcSEvan Bacon// These are split up because the user doesn't need to be prompted to setup these packages.
190082815dcSEvan Baconconst expoManagedVersionedPlugins = [
191082815dcSEvan Bacon  'expo-firebase-analytics',
192082815dcSEvan Bacon  'expo-firebase-core',
193082815dcSEvan Bacon  'expo-google-sign-in',
194082815dcSEvan Bacon];
195082815dcSEvan Bacon
196082815dcSEvan Baconconst withOptionalLegacyPlugins: ConfigPlugin<(StaticPlugin | string)[]> = (config, plugins) => {
197082815dcSEvan Bacon  return plugins.reduce((prev, plugin) => {
198082815dcSEvan Bacon    if (shouldSkipAutoPlugin(config, plugin)) {
199082815dcSEvan Bacon      debug('Skipping unlinked auto plugin:', plugin);
200082815dcSEvan Bacon      return prev;
201082815dcSEvan Bacon    }
202082815dcSEvan Bacon
203082815dcSEvan Bacon    return withStaticPlugin(prev, {
204082815dcSEvan Bacon      // hide errors
205082815dcSEvan Bacon      _isLegacyPlugin: true,
206082815dcSEvan Bacon      plugin,
207082815dcSEvan Bacon      // If a plugin doesn't exist, do nothing.
208082815dcSEvan Bacon      fallback: (config) => config,
209082815dcSEvan Bacon    });
210082815dcSEvan Bacon  }, config);
211082815dcSEvan Bacon};
212082815dcSEvan Bacon
213082815dcSEvan Baconexport function withLegacyExpoPlugins(config: ExpoConfig) {
214082815dcSEvan Bacon  return withOptionalLegacyPlugins(config, [
215082815dcSEvan Bacon    ...new Set(expoManagedVersionedPlugins.concat(legacyExpoPlugins)),
216082815dcSEvan Bacon  ]);
217082815dcSEvan Bacon}
218