1import { ExpoAppManifest, getConfig } from '@expo/config';
2
3import { env } from '../utils/env';
4import { CommandError } from '../utils/errors';
5import { getResolvedLocalesAsync } from './getResolvedLocales';
6
7/** Get the public Expo manifest from the local project config. */
8export async function getPublicExpoManifestAsync(projectRoot: string): Promise<ExpoAppManifest> {
9  // Read the config in public mode which strips the `hooks`.
10  const { exp } = getConfig(projectRoot, {
11    isPublicConfig: true,
12    // This shouldn't be needed since the CLI is vendored in `expo`.
13    skipSDKVersionRequirement: true,
14  });
15
16  // Only allow projects to be published with UNVERSIONED if a correct token is set in env
17  if (exp.sdkVersion === 'UNVERSIONED' && !env.EXPO_SKIP_MANIFEST_VALIDATION_TOKEN) {
18    throw new CommandError('INVALID_OPTIONS', 'Cannot publish with sdkVersion UNVERSIONED.');
19  }
20
21  return {
22    ...exp,
23    locales: await getResolvedLocalesAsync(projectRoot, exp),
24    sdkVersion: exp.sdkVersion!,
25  };
26}
27