xref: /expo/packages/@expo/cli/src/utils/env.ts (revision 9a348a4e)
18d307f52SEvan Baconimport { boolish, int, string } from 'getenv';
28d307f52SEvan Bacon
38d307f52SEvan Bacon// @expo/webpack-config -> expo-pwa -> @expo/image-utils: EXPO_IMAGE_UTILS_NO_SHARP
48d307f52SEvan Bacon
58d307f52SEvan Bacon// TODO: EXPO_CLI_USERNAME, EXPO_CLI_PASSWORD
68d307f52SEvan Bacon
78d307f52SEvan Baconclass Env {
8814b6fafSEvan Bacon  /** Enable profiling metrics */
9814b6fafSEvan Bacon  get EXPO_PROFILE() {
10814b6fafSEvan Bacon    return boolish('EXPO_PROFILE', false);
11814b6fafSEvan Bacon  }
12814b6fafSEvan Bacon
13814b6fafSEvan Bacon  /** Enable debug logging */
14814b6fafSEvan Bacon  get EXPO_DEBUG() {
15814b6fafSEvan Bacon    return boolish('EXPO_DEBUG', false);
16814b6fafSEvan Bacon  }
17814b6fafSEvan Bacon
18e32ccf9fSEvan Bacon  /** Disable all network requests */
19e32ccf9fSEvan Bacon  get EXPO_OFFLINE() {
20e32ccf9fSEvan Bacon    return boolish('EXPO_OFFLINE', false);
21e32ccf9fSEvan Bacon  }
22e32ccf9fSEvan Bacon
23814b6fafSEvan Bacon  /** Enable the beta version of Expo (TODO: Should this just be in the beta version of expo releases?) */
24814b6fafSEvan Bacon  get EXPO_BETA() {
25814b6fafSEvan Bacon    return boolish('EXPO_BETA', false);
26814b6fafSEvan Bacon  }
27814b6fafSEvan Bacon
28814b6fafSEvan Bacon  /** Enable staging API environment */
29814b6fafSEvan Bacon  get EXPO_STAGING() {
30814b6fafSEvan Bacon    return boolish('EXPO_STAGING', false);
31814b6fafSEvan Bacon  }
32814b6fafSEvan Bacon
33814b6fafSEvan Bacon  /** Enable local API environment */
34814b6fafSEvan Bacon  get EXPO_LOCAL() {
35814b6fafSEvan Bacon    return boolish('EXPO_LOCAL', false);
36814b6fafSEvan Bacon  }
37814b6fafSEvan Bacon
38814b6fafSEvan Bacon  /** Is running in non-interactive CI mode */
39814b6fafSEvan Bacon  get CI() {
40814b6fafSEvan Bacon    return boolish('CI', false);
41814b6fafSEvan Bacon  }
42814b6fafSEvan Bacon
43814b6fafSEvan Bacon  /** Disable telemetry (analytics) */
44814b6fafSEvan Bacon  get EXPO_NO_TELEMETRY() {
45814b6fafSEvan Bacon    return boolish('EXPO_NO_TELEMETRY', false);
46814b6fafSEvan Bacon  }
47814b6fafSEvan Bacon
48814b6fafSEvan Bacon  /** local directory to the universe repo for testing locally */
49814b6fafSEvan Bacon  get EXPO_UNIVERSE_DIR() {
50814b6fafSEvan Bacon    return string('EXPO_UNIVERSE_DIR', '');
51814b6fafSEvan Bacon  }
52814b6fafSEvan Bacon
53814b6fafSEvan Bacon  /** @deprecated Default Webpack host string */
54814b6fafSEvan Bacon  get WEB_HOST() {
55814b6fafSEvan Bacon    return string('WEB_HOST', '0.0.0.0');
56814b6fafSEvan Bacon  }
57814b6fafSEvan Bacon
58814b6fafSEvan Bacon  /** Skip warning users about a dirty git status */
59814b6fafSEvan Bacon  get EXPO_NO_GIT_STATUS() {
60814b6fafSEvan Bacon    return boolish('EXPO_NO_GIT_STATUS', false);
61814b6fafSEvan Bacon  }
628d307f52SEvan Bacon  /** Disable auto web setup */
638d307f52SEvan Bacon  get EXPO_NO_WEB_SETUP() {
648d307f52SEvan Bacon    return boolish('EXPO_NO_WEB_SETUP', false);
658d307f52SEvan Bacon  }
668d307f52SEvan Bacon  /** Disable auto TypeScript setup */
678d307f52SEvan Bacon  get EXPO_NO_TYPESCRIPT_SETUP() {
688d307f52SEvan Bacon    return boolish('EXPO_NO_TYPESCRIPT_SETUP', false);
698d307f52SEvan Bacon  }
708d307f52SEvan Bacon  /** Disable all API caches. Does not disable bundler caches. */
718d307f52SEvan Bacon  get EXPO_NO_CACHE() {
728d307f52SEvan Bacon    return boolish('EXPO_NO_CACHE', false);
738d307f52SEvan Bacon  }
74212e3a1aSEric Samelson  /** Disable the app select redirect page. */
75212e3a1aSEric Samelson  get EXPO_NO_REDIRECT_PAGE() {
76212e3a1aSEric Samelson    return boolish('EXPO_NO_REDIRECT_PAGE', false);
778d307f52SEvan Bacon  }
788d307f52SEvan Bacon  /** The React Metro port that's baked into react-native scripts and tools. */
798d307f52SEvan Bacon  get RCT_METRO_PORT() {
808d307f52SEvan Bacon    return int('RCT_METRO_PORT', 0);
818d307f52SEvan Bacon  }
82dc51e206SEvan Bacon  /** Skip validating the manifest during `export`. */
83dc51e206SEvan Bacon  get EXPO_SKIP_MANIFEST_VALIDATION_TOKEN(): boolean {
84*9a348a4eSEvan Bacon    return !!string('EXPO_SKIP_MANIFEST_VALIDATION_TOKEN', '');
85dc51e206SEvan Bacon  }
866d6b81f9SEvan Bacon
876d6b81f9SEvan Bacon  /** Public folder path relative to the project root. Default to `public` */
886d6b81f9SEvan Bacon  get EXPO_PUBLIC_FOLDER(): string {
896d6b81f9SEvan Bacon    return string('EXPO_PUBLIC_FOLDER', 'public');
906d6b81f9SEvan Bacon  }
91873c6c5aSEvan Bacon
92873c6c5aSEvan Bacon  /** Higher priority `$EDIOTR` variable for indicating which editor to use when pressing `o` in the Terminal UI. */
93873c6c5aSEvan Bacon  get EXPO_EDITOR(): string {
94873c6c5aSEvan Bacon    return string('EXPO_EDITOR', '');
95873c6c5aSEvan Bacon  }
969afd2165SEvan Bacon
97be2ffbefSEvan Bacon  /** Enable auto server root detection for Metro. This will change the server root to the workspace root. */
98be2ffbefSEvan Bacon  get EXPO_USE_METRO_WORKSPACE_ROOT(): boolean {
99be2ffbefSEvan Bacon    return boolish('EXPO_USE_METRO_WORKSPACE_ROOT', false);
100be2ffbefSEvan Bacon  }
101be2ffbefSEvan Bacon
1029afd2165SEvan Bacon  /**
1039afd2165SEvan Bacon   * Overwrite the dev server URL, disregarding the `--port`, `--host`, `--tunnel`, `--lan`, `--localhost` arguments.
1049afd2165SEvan Bacon   * This is useful for browser editors that require custom proxy URLs.
1059afd2165SEvan Bacon   */
1069afd2165SEvan Bacon  get EXPO_PACKAGER_PROXY_URL(): string {
1079afd2165SEvan Bacon    return string('EXPO_PACKAGER_PROXY_URL', '');
1089afd2165SEvan Bacon  }
1099afd2165SEvan Bacon
1109afd2165SEvan Bacon  /**
1115723d92eSEvan Bacon   * **Experimental** - Disable using `exp.direct` as the hostname for
1125723d92eSEvan Bacon   * `--tunnel` connections. This enables **https://** forwarding which
1135723d92eSEvan Bacon   * can be used to test universal links on iOS.
1145723d92eSEvan Bacon   *
1155723d92eSEvan Bacon   * This may cause issues with `expo-linking` and Expo Go.
1165723d92eSEvan Bacon   *
1175723d92eSEvan Bacon   * Select the exact subdomain by passing a string value that is not one of: `true`, `false`, `1`, `0`.
1185723d92eSEvan Bacon   */
1195723d92eSEvan Bacon  get EXPO_TUNNEL_SUBDOMAIN(): string | boolean {
1205723d92eSEvan Bacon    const subdomain = string('EXPO_TUNNEL_SUBDOMAIN', '');
1215723d92eSEvan Bacon    if (['0', 'false', ''].includes(subdomain)) {
1225723d92eSEvan Bacon      return false;
1235723d92eSEvan Bacon    } else if (['1', 'true'].includes(subdomain)) {
1245723d92eSEvan Bacon      return true;
1255723d92eSEvan Bacon    }
1265723d92eSEvan Bacon    return subdomain;
1275723d92eSEvan Bacon  }
1285723d92eSEvan Bacon
1295723d92eSEvan Bacon  /**
130ca84f1cdSEvan Bacon   * Force Expo CLI to use the [`resolver.resolverMainFields`](https://facebook.github.io/metro/docs/configuration/#resolvermainfields) from the project `metro.config.js` for all platforms.
131ca84f1cdSEvan Bacon   *
132ca84f1cdSEvan Bacon   * By default, Expo CLI will use `['browser', 'module', 'main']` (default for Webpack) for web and the user-defined main fields for other platforms.
133ca84f1cdSEvan Bacon   */
134ca84f1cdSEvan Bacon  get EXPO_METRO_NO_MAIN_FIELD_OVERRIDE(): boolean {
135ca84f1cdSEvan Bacon    return boolish('EXPO_METRO_NO_MAIN_FIELD_OVERRIDE', false);
136ca84f1cdSEvan Bacon  }
1378c8eefe0SEvan Bacon
1388c8eefe0SEvan Bacon  /**
1398c8eefe0SEvan Bacon   * HTTP/HTTPS proxy to connect to for network requests. Configures [https-proxy-agent](https://www.npmjs.com/package/https-proxy-agent).
1408c8eefe0SEvan Bacon   */
1418c8eefe0SEvan Bacon  get HTTP_PROXY(): string {
1428c8eefe0SEvan Bacon    return process.env.HTTP_PROXY || process.env.http_proxy || '';
1438c8eefe0SEvan Bacon  }
144d8009c4bSEvan Bacon
14533bd1a45SCedric van Putten  /** Use the network inspector by overriding the metro inspector proxy with a custom version */
14633bd1a45SCedric van Putten  get EXPO_NO_INSPECTOR_PROXY(): boolean {
14733bd1a45SCedric van Putten    return boolish('EXPO_NO_INSPECTOR_PROXY', false);
1485234fe38SCedric van Putten  }
1491117330aSMark Lawlor
15060d28ff6SEvan Bacon  /** Disable lazy bundling in Metro bundler. */
15160d28ff6SEvan Bacon  get EXPO_NO_METRO_LAZY() {
15260d28ff6SEvan Bacon    return boolish('EXPO_NO_METRO_LAZY', false);
15360d28ff6SEvan Bacon  }
1542fbedb18SEvan Bacon
1552fbedb18SEvan Bacon  /** Enable the unstable inverse dependency stack trace for Metro bundling errors. */
1562fbedb18SEvan Bacon  get EXPO_METRO_UNSTABLE_ERRORS() {
1572fbedb18SEvan Bacon    return boolish('EXPO_METRO_UNSTABLE_ERRORS', false);
1582fbedb18SEvan Bacon  }
1598d307f52SEvan Bacon}
1608d307f52SEvan Bacon
1618d307f52SEvan Baconexport const env = new Env();
162