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