1import { getConfig, Platform, ProjectTarget } from '@expo/config'; 2 3import { bundleAsync, BundleOutput } from './fork-bundleAsync'; 4import { getEntryWithServerRoot } from '../start/server/middleware/ManifestMiddleware'; 5 6export type PublishOptions = { 7 releaseChannel?: string; 8 target?: ProjectTarget; 9 resetCache?: boolean; 10 maxWorkers?: number; 11}; 12 13// TODO: Reduce layers of indirection 14export async function createBundlesAsync( 15 projectRoot: string, 16 publishOptions: PublishOptions = {}, 17 bundleOptions: { platforms: Platform[]; dev?: boolean; minify?: boolean } 18): Promise<Partial<Record<Platform, BundleOutput>>> { 19 if (!bundleOptions.platforms.length) { 20 return {}; 21 } 22 const projectConfig = getConfig(projectRoot, { skipSDKVersionRequirement: true }); 23 const { exp } = projectConfig; 24 25 const bundles = await bundleAsync( 26 projectRoot, 27 exp, 28 { 29 // If not legacy, ignore the target option to prevent warnings from being thrown. 30 resetCache: publishOptions.resetCache, 31 maxWorkers: publishOptions.maxWorkers, 32 quiet: false, 33 }, 34 bundleOptions.platforms.map((platform: Platform) => ({ 35 platform, 36 entryPoint: getEntryWithServerRoot(projectRoot, projectConfig, platform), 37 minify: bundleOptions.minify, 38 dev: bundleOptions.dev, 39 })) 40 ); 41 42 // { ios: bundle, android: bundle } 43 return bundleOptions.platforms.reduce<Partial<Record<Platform, BundleOutput>>>( 44 (prev, platform, index) => ({ 45 ...prev, 46 [platform]: bundles[index], 47 }), 48 {} 49 ); 50} 51