Skip to content

Commit

Permalink
chore(babel-preset-expo, metro-config): Move majority of babel plugin…
Browse files Browse the repository at this point in the history
…s to babel preset expo (#25461)

# Why

Metro's default design injects babel plugins across a number of
different transformation layers and files. This makes working with
Expo/React Native extremely confusing. This PR aims to move the majority
of babel-related logic to `babel-preset-expo`. This has the following
benefits:

- Babel has a standard plugin system, Metro does not, by offloading more
transformation to Babel we effectively enable a Babel-based plugin
architecture for Expo Metro users.
- By moving more of the options to Babel via the caller we can preserve
the caching behavior from before but with less fragmentation as we do
most config caching in Babel.
- Having most the transformations in one place makes it easier to reason
about how source must be transformed to work in Expo-supported runtimes.
This makes it easier to migrate to other tools like SWC by rewriting
babel-preset-expo, as opposed to by rewriting metro-transform-worker,
metro-babel-transformer, and metro-babel-preset-react-native.
- Fix ENG-10578

This PR also fixes a weird edge case where the import behavior works
differently when no babel config exists. We'll do another pass to unify
this logic in the future by passing the inlineRequires and transform
support as caller options.

<!--
Please describe the motivation for this PR, and link to relevant GitHub
issues, forums posts, or feature requests.
-->

# How

Consolidate our `transformer.babelTransformerPath` implementation and
move the additional babel plugins to `babel-preset-expo`.
We also drop the inlineRequires transform which is already applied in
the `metro-transform-worker` here
https://github.com/facebook/metro/blob/55b45becb1fbb4237ecc5fd0d2c81f199aefe09e/packages/metro-transform-worker/src/index.js#L293-L301
-- this also matches the upstream change
facebook/react-native#38771

# Test Plan

- Added new tests for the babel transforms.

---------

Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
  • Loading branch information
EvanBacon and expo-bot committed Nov 21, 2023
1 parent 7fa8dc1 commit bf2d187
Show file tree
Hide file tree
Showing 35 changed files with 593 additions and 538 deletions.
2 changes: 2 additions & 0 deletions packages/@expo/metro-config/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### 🛠 Breaking changes

- Moved `react-refresh` babel plugin from Metro to `babel-preset-expo`. ([#25461](https://github.com/expo/expo/pull/25461) by [@EvanBacon](https://github.com/EvanBacon))

### 🎉 New features

### 🐛 Bug fixes
Expand Down
4 changes: 1 addition & 3 deletions packages/@expo/metro-config/build/ExpoMetroConfig.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/@expo/metro-config/build/ExpoMetroConfig.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/@expo/metro-config/build/babel-core.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions packages/@expo/metro-config/build/babel-core.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/@expo/metro-config/build/babel-core.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions packages/@expo/metro-config/build/babel-transformer.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

268 changes: 60 additions & 208 deletions packages/@expo/metro-config/build/babel-transformer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/@expo/metro-config/build/babel-transformer.js.map

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions packages/@expo/metro-config/build/loadBabelConfig.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bf2d187

Please sign in to comment.