xref: /expo/packages/@expo/cli/src/utils/env.ts (revision dfd15ebd)
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  get EXPO_PACKAGER_PROXY_URL(): string {
97    return string('EXPO_PACKAGER_PROXY_URL', '');
98  }
99
100  /**
101   * **Experimental** - Disable using `exp.direct` as the hostname for
102   * `--tunnel` connections. This enables **https://** forwarding which
103   * can be used to test universal links on iOS.
104   *
105   * This may cause issues with `expo-linking` and Expo Go.
106   *
107   * Select the exact subdomain by passing a string value that is not one of: `true`, `false`, `1`, `0`.
108   */
109  get EXPO_TUNNEL_SUBDOMAIN(): string | boolean {
110    const subdomain = string('EXPO_TUNNEL_SUBDOMAIN', '');
111    if (['0', 'false', ''].includes(subdomain)) {
112      return false;
113    } else if (['1', 'true'].includes(subdomain)) {
114      return true;
115    }
116    return subdomain;
117  }
118
119  /**
120   * 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.
121   *
122   * By default, Expo CLI will use `['browser', 'module', 'main']` (default for Webpack) for web and the user-defined main fields for other platforms.
123   */
124  get EXPO_METRO_NO_MAIN_FIELD_OVERRIDE(): boolean {
125    return boolish('EXPO_METRO_NO_MAIN_FIELD_OVERRIDE', false);
126  }
127
128  /**
129   * HTTP/HTTPS proxy to connect to for network requests. Configures [https-proxy-agent](https://www.npmjs.com/package/https-proxy-agent).
130   */
131  get HTTP_PROXY(): string {
132    return process.env.HTTP_PROXY || process.env.http_proxy || '';
133  }
134}
135
136export const env = new Env();
137