Skip to content

Commit

Permalink
feat(babel-preset-expo, expo-router): Add Expo Router babel features …
Browse files Browse the repository at this point in the history
…to babel-preset-expo (#24779)

# Why

- Reduce the boilerplate required for expo-router by moving the babel
plugin features to babel-preset-expo.
- Make the expo-constants Metro web support work without Expo Router.
- Keeping expo-router/babel around for now since it shouldn't cause any
harm, this will support if someone needs to use Expo Router v3 with Expo
SDK 49 in the future (which probably won't work anyways).
- Fix #23819

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

# How

- Move code from expo-router/babel.js to babel-preset-expo.
- Rewrite plugin to use TypeScript.
- Add tests.

<!--
How did you build this feature or fix this bug and why?
-->

# Test Plan

- Added tests for the new plugins.

<!--
Please describe how you tested this change and how a reviewer could
reproduce your test, especially if this PR does not include automated
tests! If possible, please also provide terminal output and/or
screenshots demonstrating your test/reproduction.
-->

# Checklist

<!--
Please check the appropriate items below if they apply to your diff.
This is required for changes to Expo modules.
-->

- [ ] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [ ] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [ ] This diff will work correctly for `npx expo prebuild` & EAS Build
(eg: updated a module plugin).

---------

Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
  • Loading branch information
EvanBacon and expo-bot committed Oct 12, 2023
1 parent 3afc3a9 commit 0175e87
Show file tree
Hide file tree
Showing 21 changed files with 1,180 additions and 76 deletions.
1 change: 1 addition & 0 deletions packages/@expo/metro-config/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### 🎉 New features

- Pass `projectRoot` to the Babel caller. ([#24779](https://github.com/expo/expo/pull/24779) by [@EvanBacon](https://github.com/EvanBacon))
- Automatically optimize transformations based on Hermes usage. ([#24672](https://github.com/expo/expo/pull/24672) by [@EvanBacon](https://github.com/EvanBacon))

### 🐛 Bug fixes
Expand Down
4 changes: 3 additions & 1 deletion 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.

Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ it(`passes the environment as isServer to the babel preset`, () => {
bundler: 'metro',
name: 'metro',
platform: 'ios',
projectRoot: expect.any(String),
},
cloneInputAst: false,
code: false,
Expand Down
3 changes: 3 additions & 0 deletions packages/@expo/metro-config/src/babel-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ const transform: BabelTransformer['transform'] = ({
// Pass the engine to babel so we can automatically transpile for the correct
// target environment.
engine: options.customTransformOptions?.engine,

// Provide the project root for accurately reading the Expo config.
projectRoot: options.projectRoot,
},
ast: true,

Expand Down
1 change: 1 addition & 0 deletions packages/babel-preset-expo/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### 🎉 New features

- Automatically optimize transformations based on Hermes usage. ([#24672](https://github.com/expo/expo/pull/24672) by [@EvanBacon](https://github.com/EvanBacon))
- Enable `expo-router` Babel features when available. ([#24779](https://github.com/expo/expo/pull/24779) by [@EvanBacon](https://github.com/EvanBacon))

### 🐛 Bug fixes

Expand Down
5 changes: 5 additions & 0 deletions packages/babel-preset-expo/build/common.d.ts

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

54 changes: 54 additions & 0 deletions packages/babel-preset-expo/build/common.js

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

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

149 changes: 149 additions & 0 deletions packages/babel-preset-expo/build/expo-inline-manifest-plugin.js

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

20 changes: 20 additions & 0 deletions packages/babel-preset-expo/build/expo-router-plugin.d.ts

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

0 comments on commit 0175e87

Please sign in to comment.