|
| 1 | +import type { PluginOptions } from '../../types/config.js'; |
| 2 | +import { type Input, toDependency, toProductionDependency } from '../../util/input.js'; |
| 3 | +import { getPackageNameFromModuleSpecifier } from '../../util/modules.js'; |
| 4 | +import type { ExpoConfig } from './types.js'; |
| 5 | + |
| 6 | +// https://docs.expo.dev/versions/latest/config/app |
| 7 | + |
| 8 | +export const getDependencies = async (expoConfig: ExpoConfig, { manifest }: PluginOptions) => { |
| 9 | + const config = 'expo' in expoConfig ? expoConfig.expo : expoConfig; |
| 10 | + |
| 11 | + const platforms = config.platforms ?? ['ios', 'android']; |
| 12 | + |
| 13 | + const pluginPackages = |
| 14 | + (config.plugins |
| 15 | + ?.map(plugin => { |
| 16 | + const pluginName = Array.isArray(plugin) ? plugin[0] : plugin; |
| 17 | + return getPackageNameFromModuleSpecifier(pluginName); |
| 18 | + }) |
| 19 | + .filter(Boolean) as string[]) ?? []; |
| 20 | + |
| 21 | + const inputs = new Set<Input>(pluginPackages.map(toDependency)); |
| 22 | + |
| 23 | + const allowedPackages = ['expo-atlas', 'expo-dev-client']; |
| 24 | + const allowedProductionPackages = ['expo-insights']; |
| 25 | + |
| 26 | + const manifestDependencies = Object.keys(manifest.dependencies ?? {}); |
| 27 | + |
| 28 | + for (const pkg of allowedPackages) { |
| 29 | + if (manifestDependencies.includes(pkg)) { |
| 30 | + inputs.add(toDependency(pkg)); |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + for (const pkg of allowedProductionPackages) { |
| 35 | + if (manifestDependencies.includes(pkg)) { |
| 36 | + inputs.add(toProductionDependency(pkg)); |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + if (config.updates?.enabled !== false) { |
| 41 | + inputs.add(toProductionDependency('expo-updates')); |
| 42 | + } |
| 43 | + |
| 44 | + if (config.notification) { |
| 45 | + inputs.add(toProductionDependency('expo-notifications')); |
| 46 | + } |
| 47 | + |
| 48 | + const isExpoRouter = manifest.main === 'expo-router/entry'; |
| 49 | + |
| 50 | + // https://docs.expo.dev/router/installation/#setup-entry-point |
| 51 | + if (isExpoRouter) { |
| 52 | + inputs.add(toProductionDependency('expo-router')); |
| 53 | + } |
| 54 | + |
| 55 | + // https://docs.expo.dev/workflow/web/#install-web-dependencies |
| 56 | + if (platforms.includes('web')) { |
| 57 | + inputs.add(toProductionDependency('react-native-web')); |
| 58 | + inputs.add(toProductionDependency('react-dom')); |
| 59 | + |
| 60 | + // https://github.com/expo/expo/tree/main/packages/@expo/metro-runtime |
| 61 | + if (!isExpoRouter) { |
| 62 | + inputs.add(toDependency('@expo/metro-runtime')); |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + if ( |
| 67 | + (platforms.includes('android') && (config.userInterfaceStyle || config.android?.userInterfaceStyle)) || |
| 68 | + (platforms.includes('ios') && (config.backgroundColor || config.ios?.backgroundColor)) |
| 69 | + ) { |
| 70 | + inputs.add(toProductionDependency('expo-system-ui')); |
| 71 | + } |
| 72 | + |
| 73 | + if (platforms.includes('android') && config.androidNavigationBar) { |
| 74 | + inputs.add(toProductionDependency('expo-navigation-bar')); |
| 75 | + } |
| 76 | + |
| 77 | + return [...inputs]; |
| 78 | +}; |
0 commit comments