Skip to content

Commit

Permalink
feat(babel): rewrite babel-preset-expo to use TypeScript (#24328)
Browse files Browse the repository at this point in the history
# Why

I found that if we increase the complexity and logic in our babel
preset, then we can easily get to 30% faster web builds. Before doing
this I'd like to ensure we have a better foundation to build against.

This PR converts babel-preset-expo to TypeScript and drops some safely
unused features.

## Plans

- We'll use the caller to determine if a module should be compiled for
Node.js, if so, we'll use a much cheaper babel plugin.
- We'll add an additional caller parameter to detect if the module is
inside the node_modules folder, if so, then we'll use a cheaper babel
plugin. We'll also add the ability to allow certain node modules to be
transpiled as application code.
- The first version of this will be rolled out behind a flag to ensure
we aren't breaking apps, since apps will more than likely break, as most
React Native modules are shipped untranspiled.
  - Perhaps it makes sense to roll this out as a web-only feature.

# Test Plan

Tests should keep passing.

---------

Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
  • Loading branch information
EvanBacon and expo-bot committed Sep 12, 2023
1 parent 4aaacb0 commit 1e7a47e
Show file tree
Hide file tree
Showing 23 changed files with 334 additions and 192 deletions.
2 changes: 2 additions & 0 deletions packages/babel-preset-expo/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @generated by expo-module-scripts
module.exports = require('expo-module-scripts/eslintrc.base.js');
12 changes: 11 additions & 1 deletion packages/babel-preset-expo/.npmignore
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
__tests__/
# @generated by expo-module-scripts

# Exclude all top-level hidden directories by convention
/.*/

__mocks__
__tests__

/babel.config.js
/android/src/androidTest/
/android/src/test/
5 changes: 5 additions & 0 deletions packages/babel-preset-expo/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@

### 🛠 Breaking changes

- Remove experimental native Webpack support. ([#24328](https://github.com/expo/expo/pull/24328) by [@EvanBacon](https://github.com/EvanBacon))

### 🎉 New features

### 🐛 Bug fixes

### 💡 Others

- Drop warning for invalid property `useTransformReactJsxExperimental`. ([#24328](https://github.com/expo/expo/pull/24328) by [@EvanBacon](https://github.com/EvanBacon))
- Re-write in TypeScript. ([#24328](https://github.com/expo/expo/pull/24328) by [@EvanBacon](https://github.com/EvanBacon))

## 9.6.2 — 2023-09-04

_This version does not introduce any user-facing changes._
Expand Down

This file was deleted.

This file was deleted.

11 changes: 11 additions & 0 deletions packages/babel-preset-expo/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = function (api) {
api.cache(true);
return {
// Only transpile our source code
include(filename) {
// Ignore tests and the `unknown` name used in tests
return !filename.match(/samples/) && filename.match(/src\/(.*)\.tsx?/);
},
presets: ['@expo/babel-preset-cli'],
};
};
19 changes: 19 additions & 0 deletions packages/babel-preset-expo/build/index.d.ts

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

150 changes: 150 additions & 0 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.

2 changes: 2 additions & 0 deletions packages/babel-preset-expo/build/lazyImports.d.ts

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

5 changes: 5 additions & 0 deletions packages/babel-preset-expo/build/lazyImports.js

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

10 changes: 10 additions & 0 deletions packages/babel-preset-expo/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const path = require('path');

module.exports = {
testEnvironment: 'node',
testRegex: '/__tests__/.*(test|spec)\\.[jt]sx?$',
watchPlugins: ['jest-watch-typeahead/filename', 'jest-watch-typeahead/testname'],
clearMocks: true,
rootDir: path.resolve(__dirname),
displayName: require('./package').name,
};
2 changes: 1 addition & 1 deletion packages/babel-preset-expo/lazy-imports-blacklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
*/
'use strict';

module.exports = new Set(['expo', 'expo-asset', 'expo-task-manager']);
module.exports = require('./build/lazyImports').lazyImports;
25 changes: 11 additions & 14 deletions packages/babel-preset-expo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@
"name": "babel-preset-expo",
"version": "9.6.2",
"description": "The Babel preset for Expo projects",
"main": "index.js",
"main": "build/index.js",
"files": [
"index.js",
"lazy-imports-blacklist.js",
"plugins"
"build",
"lazy-imports-blacklist.js"
],

"scripts": {
"jest": "jest",
"lint": "eslint .",
"test": "jest --watch"
"build": "expo-module build",
"clean": "expo-module clean",
"lint": "expo-module lint",
"test": "expo-module test",
"prepare": "expo-module prepare",
"prepublishOnly": "expo-module prepublishOnly",
"expo-module": "expo-module"
},
"repository": {
"type": "git",
Expand All @@ -37,13 +41,6 @@
"eslintConfig": {
"extends": "universe/node"
},
"jest": {
"testEnvironment": "node",
"testPathIgnorePatterns": [
"<rootDir>/node_modules/",
"<rootDir>/__tests__/samples/"
]
},
"dependencies": {
"@babel/plugin-proposal-decorators": "^7.12.9",
"@babel/plugin-proposal-export-namespace-from": "^7.18.9",
Expand Down
52 changes: 0 additions & 52 deletions packages/babel-preset-expo/plugins/disable-ambiguous-requires.js

This file was deleted.

0 comments on commit 1e7a47e

Please sign in to comment.