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

fix(babel): fix unused platform code removal #25171

Merged
merged 8 commits into from Nov 8, 2023

Conversation

EvanBacon
Copy link
Contributor

Why

Metro applies this plugin too but it does it after the imports have been transformed which breaks the plugin. Here, we'll apply it before the commonjs transform, in production, to ensure Platform.OS is replaced with a string literal and __DEV__ is converted to a boolean.
Applying early also means that web can be transformed before the react-native-web transform mutates the import.

Test Plan

  • Added new tests for the plugin.

Checklist

@expo-bot expo-bot added the bot: suggestions ExpoBot has some suggestions label Nov 1, 2023
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 Nov 2, 2023
EvanBacon added a commit that referenced this pull request Nov 6, 2023
# Why

Tests were technically failing, this fixes them. Related
#25171
packages/babel-preset-expo/src/index.ts Show resolved Hide resolved
@@ -98,6 +98,21 @@ function babelPresetExpo(api: ConfigAPI, options: BabelPresetExpoOptions = {}):
extraPlugins.push(require('@babel/plugin-transform-parameters'));
}

if (!isDev && hasModule('metro-transform-plugins')) {
Copy link
Member

Choose a reason for hiding this comment

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

Why should this not run in development, too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't do any minification in development to keep things fast, might change in the future but right now it doesn't provide much benefit.

@EvanBacon EvanBacon merged commit 4d37ee9 into main Nov 8, 2023
8 checks passed
@EvanBacon EvanBacon deleted the @evanbacon/babel/fix-platform-shaking branch November 8, 2023 04:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: fingerprint changed bot: passed checks ExpoBot has nothing to complain about
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants