import { ExpoConfig , getConfig , ProjectTarget } from '@expo/config' ; import { MessageSocket , MetroDevServerOptions , prependMiddleware , runMetroDevServerAsync , } from '@expo/dev-server' ; import http from 'http' ; import { assertValidProjectRoot , ExpoUpdatesManifestHandler , getFreePortAsync , LoadingPageHandler , ManifestHandler , ProjectSettings , ProjectUtils , } from '../internal' ; export type StartOptions = { metroPort ? : number ; webpackPort ? : number ; isWebSocketsEnabled ? : boolean ; isRemoteReloadingEnabled ? : boolean ; devClient ? : boolean ; reset ? : boolean ; nonInteractive ? : boolean ; nonPersistent ? : boolean ; maxWorkers ? : number ; webOnly ? : boolean ; target ? : ProjectTarget ; platforms ? : ExpoConfig [ 'platforms' ] ; forceManifestType ? : 'expo-updates' | 'classic' ; } ; export async function startDevServerAsync ( projectRoot , startOptions ) { assertValidProjectRoot ( projectRoot ) ; let port ; if ( startOptions . metroPort != null ) { port = startOptions . metroPort ; } else { port = startOptions . devClient ? Number ( process . env . RCT_METRO_PORT ) || 8081 : await getFreePortAsync ( startOptions . metroPort || 19000 ) ; } await ProjectSettings . setPackagerInfoAsync ( projectRoot , { expoServerPort : port , packagerPort : port } ) ; const options = { port , logger : ProjectUtils . getLogger ( projectRoot ) , target : startOptions . target } ; if ( startOptions . reset ) { options . resetCache = true ; } if ( startOptions . maxWorkers != null ) { options . maxWorkers = startOptions . maxWorkers ; } const projectConfig = getConfig ( projectRoot , { skipSDKVersionRequirement : true } ) ; options . unversioned = ! projectConfig . exp . sdkVersion || projectConfig . exp . sdkVersion === 'UNVERSIONED' ; const { server , middleware , messageSocket } = await runMetroDevServerAsync ( projectRoot , options ) ; const useExpoUpdatesManifest = startOptions . forceManifestType === 'expo-updates' ; prependMiddleware ( middleware , useExpoUpdatesManifest ? ExpoUpdatesManifestHandler . getManifestHandler ( projectRoot ) : ManifestHandler . getManifestHandler ( projectRoot ) ) ; middleware . use ( LoadingPageHandler . getLoadingPageHandler ( projectRoot ) ) ; return [ server , middleware , messageSocket ] ; }