xref: /expo/packages/@expo/cli/src/utils/env.ts (revision c7b9eeee)
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  /** Enable auto server root detection for Metro. This will change the server root to the workspace root. */
93  get EXPO_USE_METRO_WORKSPACE_ROOT(): boolean {
94    return boolish('EXPO_USE_METRO_WORKSPACE_ROOT', false);
95  }
96
97  /**
98   * Overwrite the dev server URL, disregarding the `--port`, `--host`, `--tunnel`, `--lan`, `--localhost` arguments.
99   * This is useful for browser editors that require custom proxy URLs.
100   */
101  get EXPO_PACKAGER_PROXY_URL(): string {
102    return string('EXPO_PACKAGER_PROXY_URL', '');
103  }
104
105  /**
106   * **Experimental** - Disable using `exp.direct` as the hostname for
107   * `--tunnel` connections. This enables **https://** forwarding which
108   * can be used to test universal links on iOS.
109   *
110   * This may cause issues with `expo-linking` and Expo Go.
111   *
112   * Select the exact subdomain by passing a string value that is not one of: `true`, `false`, `1`, `0`.
113   */
114  get EXPO_TUNNEL_SUBDOMAIN(): string | boolean {
115    const subdomain = string('EXPO_TUNNEL_SUBDOMAIN', '');
116    if (['0', 'false', ''].includes(subdomain)) {
117      return false;
118    } else if (['1', 'true'].includes(subdomain)) {
119      return true;
120    }
121    return subdomain;
122  }
123
124  /**
125   * 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.
126   *
127   * By default, Expo CLI will use `['browser', 'module', 'main']` (default for Webpack) for web and the user-defined main fields for other platforms.
128   */
129  get EXPO_METRO_NO_MAIN_FIELD_OVERRIDE(): boolean {
130    return boolish('EXPO_METRO_NO_MAIN_FIELD_OVERRIDE', false);
131  }
132
133  /**
134   * HTTP/HTTPS proxy to connect to for network requests. Configures [https-proxy-agent](https://www.npmjs.com/package/https-proxy-agent).
135   */
136  get HTTP_PROXY(): string {
137    return process.env.HTTP_PROXY || process.env.http_proxy || '';
138  }
139
140  /** **Experimental:** Prevent Metro from using the `compilerOptions.paths` feature from `tsconfig.json` (or `jsconfig.json`) to enable import aliases. */
141  get EXPO_USE_PATH_ALIASES(): boolean {
142    return boolish('EXPO_USE_PATH_ALIASES', false);
143  }
144}
145
146export const env = new Env();
147