Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli, metro-config): environment variable support #21983

Merged
merged 9 commits into from Apr 8, 2023

Conversation

EvanBacon
Copy link
Contributor

@EvanBacon EvanBacon commented Apr 4, 2023

Why

Expo supports the standard .env resolution.

  • It's nice to be able to use uncommitted values in your app, based on the environment. This feels very familiar to web developers.
  • Values that are prefixed with EXPO_PUBLIC_ will be inlined in the bundle when bundling normally (e.g. not for Node.js).
  • .env files are loaded into memory and applied to the process during a run. This also means that they're available in app.config.js.
  • During development-only, environment variables are exposed on the process.env object (non-enumerable) to ensure they're available between fast refresh updates.

How

  • Create new package @expo/env which is used to hydrate env variables in a unified way. I plan to open another PR in eas-cli which uses this package to fill in environment variables before uploading. NOTE: environment variables that are defined in eas.json are not available in Expo CLI when building locally, but are available in the cloud since they'll be on the process, this means they effectively emulate .env.production.
  • Update templates to gitignore local env files.
  • Add basic documentation to the versioned metro guide (more to come).

Test Plan

  • E2E rendering test
  • E2E Node.js rendering test
  • Unit tests for serializer
  • Tests for env package

Checklist

@expo-bot expo-bot added bot: suggestions ExpoBot has some suggestions bot: passed checks ExpoBot has nothing to complain about and removed bot: suggestions ExpoBot has some suggestions labels Apr 4, 2023
@EvanBacon EvanBacon force-pushed the @evanbacon/cli/custom-serializer branch from 160f537 to 3149b18 Compare April 6, 2023 01:43
@EvanBacon EvanBacon requested a review from byCedric April 6, 2023 01:58
@EvanBacon EvanBacon marked this pull request as ready for review April 6, 2023 01:58
Copy link
Member

@amandeepmittal amandeepmittal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some suggestions.

docs/pages/versions/unversioned/config/metro.mdx Outdated Show resolved Hide resolved
docs/pages/versions/unversioned/config/metro.mdx Outdated Show resolved Hide resolved
docs/pages/versions/unversioned/config/metro.mdx Outdated Show resolved Hide resolved
docs/pages/versions/unversioned/config/metro.mdx Outdated Show resolved Hide resolved
docs/pages/versions/unversioned/config/metro.mdx Outdated Show resolved Hide resolved

Envrionment variables prefixed with `EXPO_PUBLIC_` will be exposed to the app at build-time. For example, `EXPO_PUBLIC_API_KEY` will be available as `process.env.EXPO_PUBLIC_API_KEY`.

Envrionmnet variables will not be inlined in Node Modules.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does "inlined in Node Modules" mean here?

docs/pages/versions/unversioned/config/metro.mdx Outdated Show resolved Hide resolved
docs/pages/versions/unversioned/config/metro.mdx Outdated Show resolved Hide resolved
docs/pages/versions/unversioned/config/metro.mdx Outdated Show resolved Hide resolved
@EvanBacon EvanBacon requested a review from tsapeta as a code owner April 6, 2023 17:18
@expo-bot expo-bot added bot: suggestions ExpoBot has some suggestions bot: passed checks ExpoBot has nothing to complain about and removed bot: passed checks ExpoBot has nothing to complain about bot: suggestions ExpoBot has some suggestions labels Apr 6, 2023
@EvanBacon EvanBacon force-pushed the @evanbacon/cli/custom-serializer branch from 8c5868f to ec290ac Compare April 6, 2023 17:27
@EvanBacon EvanBacon merged commit 6a750d0 into main Apr 8, 2023
14 of 17 checks passed
@EvanBacon EvanBacon deleted the @evanbacon/cli/custom-serializer branch April 8, 2023 03:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: passed checks ExpoBot has nothing to complain about
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants