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(babel): add process.env.EXPO_OS #27509

Merged
merged 4 commits into from Mar 8, 2024
Merged

Conversation

EvanBacon
Copy link
Contributor

@EvanBacon EvanBacon commented Mar 7, 2024

Why

Add support for detecting the platform without needing to import react-native or react-native-web.

How

Add a babel plugin to replace process.env.EXPO_OS with the current caller.platform environment variable. Unlike Platform.OS which performs fake minifying ahead of time, this value cannot be used to remove unused require statements. We can fix this when we add tree shaking in the future.

This transform can be used in any node module and is not limited to application code, similar to NODE_ENV.

Test Plan

  • Added tests for the babel transforms and sanity tests for minification to better understand the limitations of code removal in Metro.

@expo-bot expo-bot added the bot: suggestions ExpoBot has some suggestions label Mar 7, 2024
Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
@expo-bot expo-bot added bot: passed checks ExpoBot has nothing to complain about and removed bot: suggestions ExpoBot has some suggestions labels Mar 7, 2024
Copy link
Member

@ide ide left a comment

Choose a reason for hiding this comment

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

Not going to block this PR but I think it would be better to come up with an alternative to using process.env (or process for that matter). This has nothing to do with the app process nor its environment. Something like "use os=ios" would perhaps be better, or import.meta.expoBuildConstants.TARGET_OS. Again, not to hold this up but using process.env for not-the-app-process's environment to me is an example where more clarity of mind was needed in JS conventions many years ago.

@EvanBacon
Copy link
Contributor Author

import.meta.env.EXPO_OS would be better, but we don't have any modules story atm.

@EvanBacon EvanBacon merged commit 91b7ef4 into main Mar 8, 2024
13 of 14 checks passed
@EvanBacon EvanBacon deleted the @evanbacon/babel/env-expo-os branch March 8, 2024 19:40
@brentvatne brentvatne added the published Changes from the PR have been published to npm label Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: fingerprint compatible bot: passed checks ExpoBot has nothing to complain about published Changes from the PR have been published to npm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants