xref: /expo/packages/@expo/cli/src/utils/env.ts (revision 023bc8ea)
1import { boolish, int, string } from 'getenv';
2
3// @expo/webpack-config -> expo-pwa -> @expo/image-utils: EXPO_IMAGE_UTILS_NO_SHARP
4
5// TODO: EXPO_CLI_USERNAME, EXPO_CLI_PASSWORD
6
7class Env {
8  /** Enable profiling metrics */
9  get EXPO_PROFILE() {
10    return boolish('EXPO_PROFILE', false);
11  }
12
13  /** Enable debug logging */
14  get EXPO_DEBUG() {
15    return boolish('EXPO_DEBUG', false);
16  }
17
18  /** Enable the beta version of Expo (TODO: Should this just be in the beta version of expo releases?) */
19  get EXPO_BETA() {
20    return boolish('EXPO_BETA', false);
21  }
22
23  /** Enable staging API environment */
24  get EXPO_STAGING() {
25    return boolish('EXPO_STAGING', false);
26  }
27
28  /** Enable local API environment */
29  get EXPO_LOCAL() {
30    return boolish('EXPO_LOCAL', false);
31  }
32
33  /** Is running in non-interactive CI mode */
34  get CI() {
35    return boolish('CI', false);
36  }
37
38  /** Disable telemetry (analytics) */
39  get EXPO_NO_TELEMETRY() {
40    return boolish('EXPO_NO_TELEMETRY', false);
41  }
42
43  /** local directory to the universe repo for testing locally */
44  get EXPO_UNIVERSE_DIR() {
45    return string('EXPO_UNIVERSE_DIR', '');
46  }
47
48  /** @deprecated Default Webpack host string */
49  get WEB_HOST() {
50    return string('WEB_HOST', '0.0.0.0');
51  }
52
53  /** Skip warning users about a dirty git status */
54  get EXPO_NO_GIT_STATUS() {
55    return boolish('EXPO_NO_GIT_STATUS', false);
56  }
57  /** Disable auto web setup */
58  get EXPO_NO_WEB_SETUP() {
59    return boolish('EXPO_NO_WEB_SETUP', false);
60  }
61  /** Disable auto TypeScript setup */
62  get EXPO_NO_TYPESCRIPT_SETUP() {
63    return boolish('EXPO_NO_TYPESCRIPT_SETUP', false);
64  }
65  /** Disable all API caches. Does not disable bundler caches. */
66  get EXPO_NO_CACHE() {
67    return boolish('EXPO_NO_CACHE', false);
68  }
69  /** Disable the app select redirect page. */
70  get EXPO_NO_REDIRECT_PAGE() {
71    return boolish('EXPO_NO_REDIRECT_PAGE', false);
72  }
73  /** The React Metro port that's baked into react-native scripts and tools. */
74  get RCT_METRO_PORT() {
75    return int('RCT_METRO_PORT', 0);
76  }
77  /** Skip validating the manifest during `export`. */
78  get EXPO_SKIP_MANIFEST_VALIDATION_TOKEN(): boolean {
79    return !!string('EXPO_SKIP_MANIFEST_VALIDATION_TOKEN');
80  }
81
82  /** Public folder path relative to the project root. Default to `public` */
83  get EXPO_PUBLIC_FOLDER(): string {
84    return string('EXPO_PUBLIC_FOLDER', 'public');
85  }
86
87  /** Higher priority `$EDIOTR` variable for indicating which editor to use when pressing `o` in the Terminal UI. */
88  get EXPO_EDITOR(): string {
89    return string('EXPO_EDITOR', '');
90  }
91
92  /**
93   * Overwrite the dev server URL, disregarding the `--port`, `--host`, `--tunnel`, `--lan`, `--localhost` arguments.
94   * This is useful for browser editors that require custom proxy URLs.
95   *
96   * The URL will not be used verbatim unless `EXPO_NO_DEFAULT_PORT=true` is also set,
97   * otherwise a `:80` port will be added for Android support.
98   */
99  get EXPO_PACKAGER_PROXY_URL(): string {
100    return string('EXPO_PACKAGER_PROXY_URL', '');
101  }
102
103  /**
104   * Disable the enforced `:80` port when using custom dev server URLs.
105   * This can break the incomplete Android WebSocket implementation but allows
106   * `EXPO_PACKAGER_PROXY_URL` to work as expected.
107   */
108  get EXPO_NO_DEFAULT_PORT(): boolean {
109    return boolish('EXPO_NO_DEFAULT_PORT', false);
110  }
111
112  /**
113   * **Experimental** - Disable using `exp.direct` as the hostname for
114   * `--tunnel` connections. This enables **https://** forwarding which
115   * can be used to test universal links on iOS.
116   *
117   * This may cause issues with `expo-linking` and Expo Go.
118   *
119   * Select the exact subdomain by passing a string value that is not one of: `true`, `false`, `1`, `0`.
120   */
121  get EXPO_TUNNEL_SUBDOMAIN(): string | boolean {
122    const subdomain = string('EXPO_TUNNEL_SUBDOMAIN', '');
123    if (['0', 'false', ''].includes(subdomain)) {
124      return false;
125    } else if (['1', 'true'].includes(subdomain)) {
126      return true;
127    }
128    return subdomain;
129  }
130
131  /**
132   * 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.
133   *
134   * By default, Expo CLI will use `['browser', 'module', 'main']` (default for Webpack) for web and the user-defined main fields for other platforms.
135   */
136  get EXPO_METRO_NO_MAIN_FIELD_OVERRIDE(): boolean {
137    return boolish('EXPO_METRO_NO_MAIN_FIELD_OVERRIDE', false);
138  }
139
140  /**
141   * HTTP/HTTPS proxy to connect to for network requests. Configures [https-proxy-agent](https://www.npmjs.com/package/https-proxy-agent).
142   */
143  get HTTP_PROXY(): string {
144    return process.env.HTTP_PROXY || process.env.http_proxy || '';
145  }
146}
147
148export const env = new Env();
149