Skip to content

Commit

Permalink
feat(babel): write new inline Platform module plugin (#27533)
Browse files Browse the repository at this point in the history
# Why

- The upstream module has a lot of concessions for legacy features that
don't appear to be used anymore, like importing from a module named
`require("Platform")` (Haste).
- We also want to combine the dev inlining with our other inlines via
#27530
- I've also added correct handling for web, where we'll now remove the
`native` fallback option.
- Finally, I added support for `Platform["OS"]`.

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

# Test Plan

- Added a bunch of tests for the expected functionality.

# 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 Mar 13, 2024
1 parent 1ed1a49 commit e936f33
Show file tree
Hide file tree
Showing 12 changed files with 775 additions and 48 deletions.
3 changes: 3 additions & 0 deletions packages/babel-preset-expo/CHANGELOG.md
Expand Up @@ -6,12 +6,15 @@

### 🎉 New features

- Add faster `Platform.select` transform. ([#27533](https://github.com/expo/expo/pull/27533) by [@EvanBacon](https://github.com/EvanBacon))
- Minify `typeof window` in server and web contexts. ([#27530](https://github.com/expo/expo/pull/27530) by [@EvanBacon](https://github.com/EvanBacon))
- Add support for using `process.env.EXPO_OS` to detect the platform without platform shaking imports. ([#27509](https://github.com/expo/expo/pull/27509) by [@EvanBacon](https://github.com/EvanBacon))
- Add basic `react-server` support. ([#27264](https://github.com/expo/expo/pull/27264) by [@EvanBacon](https://github.com/EvanBacon))

### 🐛 Bug fixes

- Fix bug preventing reassignment of globals. ([#27533](https://github.com/expo/expo/pull/27533) by [@EvanBacon](https://github.com/EvanBacon))

### 💡 Others

- Disable color in snapshot tests in CI. ([#27301](https://github.com/expo/expo/pull/27301) by [@EvanBacon](https://github.com/EvanBacon))
Expand Down
12 changes: 12 additions & 0 deletions packages/babel-preset-expo/build/define-plugin.d.ts

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

140 changes: 140 additions & 0 deletions packages/babel-preset-expo/build/define-plugin.js

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

23 changes: 10 additions & 13 deletions packages/babel-preset-expo/build/index.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.

73 changes: 73 additions & 0 deletions packages/babel-preset-expo/build/minify-platform-select-plugin.js

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

1 change: 0 additions & 1 deletion packages/babel-preset-expo/package.json
Expand Up @@ -49,7 +49,6 @@
"@babel/preset-react": "^7.22.15",
"@react-native/babel-preset": "^0.73.18",
"babel-plugin-react-native-web": "~0.19.10",
"babel-plugin-transform-define": "^2.1.4",
"react-refresh": "0.14.0"
},
"devDependencies": {
Expand Down

0 comments on commit e936f33

Please sign in to comment.