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  { skipValidation }: { skipValidation?: boolean } = {}
11): Promise<ExpoConfig & { locales: LocaleMap; sdkVersion: string }> {
12  // Read the config in public mode which strips the `hooks`.
13  const { exp } = getConfig(projectRoot, {
14    isPublicConfig: true,
15    // This shouldn't be needed since the CLI is vendored in `expo`.
16    skipSDKVersionRequirement: true,
17  });
18
19  // Only allow projects to be published with UNVERSIONED if a correct token is set in env
20  if (
21    !skipValidation &&
22    exp.sdkVersion === 'UNVERSIONED' &&
23    !env.EXPO_SKIP_MANIFEST_VALIDATION_TOKEN
24  ) {
25    throw new CommandError('INVALID_OPTIONS', 'Cannot publish with sdkVersion UNVERSIONED.');
26  }
27
28  return {
29    ...exp,
30    locales: await getResolvedLocalesAsync(projectRoot, exp),
31    sdkVersion: exp.sdkVersion!,
32  };
33}
34