Skip to content

Commit

Permalink
Move react-native-babel-transformer and react-native-babel-preset fro…
Browse files Browse the repository at this point in the history
…m Metro to React Native repo

Summary:
Changelog: [General][Changed] - Move react-native-babel-transformer and react-native-babel-preset from Metro to React Native repo.

This diff does the following:
- Move `metro/packages/metro-react-native-babel-preset` to `react-native/packages/react-native-babel-preset`.
- Move `metro/packages/metro-react-native-babel-transformer` to `react-native/packages/react-native-babel-transformer`.

Differential Revision: D46977466

fbshipit-source-id: 1bd989facf3c8c70321ee23f6f2bffd93e3fe356
  • Loading branch information
dmytrorykun authored and facebook-github-bot committed Jul 6, 2023
1 parent af73a75 commit e2ed418
Show file tree
Hide file tree
Showing 13 changed files with 829 additions and 56 deletions.
6 changes: 6 additions & 0 deletions packages/react-native-babel-preset/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
**/__mocks__/
**/__tests__/
/build/
/src.real/
/types/
yarn.lock
41 changes: 41 additions & 0 deletions packages/react-native-babel-preset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# metro-react-native-babel-preset

Babel presets for [React Native](https://reactnative.dev) applications. React Native itself uses this Babel preset by default when transforming your app's source code.

If you wish to use a custom Babel configuration by writing a `babel.config.js` file in your project's root directory, you must specify all the plugins necessary to transform your code. React Native does not apply its default Babel configuration in this case. So, to make your life easier, you can use this preset to get the default configuration and then specify more plugins that run before it.

## Usage

As mentioned above, you only need to use this preset if you are writing a custom `babel.config.js` file.

### Installation

Install `metro-react-native-babel-preset` in your app:

with `npm`:

```sh
npm i metro-react-native-babel-preset --save-dev
```

or with `yarn`:

```sh
yarn add -D metro-react-native-babel-preset
```

### Configuring Babel

Then, create a file called `babel.config.js` in your project's root directory. The existence of this `babel.config.js` file will tell React Native to use your custom Babel configuration instead of its own. Then load this preset:

```
{
"presets": ["module:metro-react-native-babel-preset"]
}
```

You can further customize your Babel configuration by specifying plugins and other options. See [Babel's `babel.config.js` documentation](https://babeljs.io/docs/en/config-files/) to learn more.

## Help and Support

If you get stuck configuring Babel, please ask a question on Stack Overflow or find a consultant for help. If you discover a bug, please open up an issue.
67 changes: 67 additions & 0 deletions packages/react-native-babel-preset/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"name": "metro-react-native-babel-preset",
"version": "0.76.7",
"description": "Babel preset for React Native applications",
"main": "src/index.js",
"repository": {
"type": "git",
"url": "[email protected]:facebook/metro.git"
},
"scripts": {
"prepare-release": "test -d build && rm -rf src.real && mv src src.real && mv build src",
"cleanup-release": "test ! -e build && mv src build && mv src.real src"
},
"keywords": [
"babel",
"preset",
"react-native"
],
"license": "MIT",
"dependencies": {
"@babel/core": "^7.20.0",
"@babel/plugin-proposal-async-generator-functions": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.18.0",
"@babel/plugin-proposal-export-default-from": "^7.0.0",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.0",
"@babel/plugin-proposal-numeric-separator": "^7.0.0",
"@babel/plugin-proposal-object-rest-spread": "^7.20.0",
"@babel/plugin-proposal-optional-catch-binding": "^7.0.0",
"@babel/plugin-proposal-optional-chaining": "^7.20.0",
"@babel/plugin-syntax-dynamic-import": "^7.8.0",
"@babel/plugin-syntax-export-default-from": "^7.0.0",
"@babel/plugin-syntax-flow": "^7.18.0",
"@babel/plugin-syntax-nullish-coalescing-operator": "^7.0.0",
"@babel/plugin-syntax-optional-chaining": "^7.0.0",
"@babel/plugin-transform-arrow-functions": "^7.0.0",
"@babel/plugin-transform-async-to-generator": "^7.20.0",
"@babel/plugin-transform-block-scoping": "^7.0.0",
"@babel/plugin-transform-classes": "^7.0.0",
"@babel/plugin-transform-computed-properties": "^7.0.0",
"@babel/plugin-transform-destructuring": "^7.20.0",
"@babel/plugin-transform-flow-strip-types": "^7.20.0",
"@babel/plugin-transform-function-name": "^7.0.0",
"@babel/plugin-transform-literals": "^7.0.0",
"@babel/plugin-transform-modules-commonjs": "^7.0.0",
"@babel/plugin-transform-named-capturing-groups-regex": "^7.0.0",
"@babel/plugin-transform-parameters": "^7.0.0",
"@babel/plugin-transform-react-display-name": "^7.0.0",
"@babel/plugin-transform-react-jsx": "^7.0.0",
"@babel/plugin-transform-react-jsx-self": "^7.0.0",
"@babel/plugin-transform-react-jsx-source": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/plugin-transform-shorthand-properties": "^7.0.0",
"@babel/plugin-transform-spread": "^7.0.0",
"@babel/plugin-transform-sticky-regex": "^7.0.0",
"@babel/plugin-transform-typescript": "^7.5.0",
"@babel/plugin-transform-unicode-regex": "^7.0.0",
"@babel/template": "^7.0.0",
"babel-plugin-transform-flow-enums": "^0.0.2",
"react-refresh": "^0.4.0"
},
"peerDependencies": {
"@babel/core": "*"
},
"engines": {
"node": ">=18"
}
}
17 changes: 17 additions & 0 deletions packages/react-native-babel-preset/src/configs/hmr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @oncall react_native
*/

'use strict';

module.exports = function () {
return {
plugins: [require('react-refresh/babel')],
};
};
93 changes: 93 additions & 0 deletions packages/react-native-babel-preset/src/configs/lazy-imports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @oncall react_native
*/

// This is the set of modules that React Native publicly exports and that we
// want to require lazily. Keep this list in sync with
// react-native/index.js (though having extra entries here is fairly harmless).

'use strict';

module.exports = new Set([
'AccessibilityInfo',
'ActivityIndicator',
'Button',
'DatePickerIOS',
'DrawerLayoutAndroid',
'FlatList',
'Image',
'ImageBackground',
'InputAccessoryView',
'KeyboardAvoidingView',
'Modal',
'Pressable',
'ProgressBarAndroid',
'ProgressViewIOS',
'SafeAreaView',
'ScrollView',
'SectionList',
'Slider',
'Switch',
'RefreshControl',
'StatusBar',
'Text',
'TextInput',
'Touchable',
'TouchableHighlight',
'TouchableNativeFeedback',
'TouchableOpacity',
'TouchableWithoutFeedback',
'View',
'VirtualizedList',
'VirtualizedSectionList',

// APIs
'ActionSheetIOS',
'Alert',
'Animated',
'Appearance',
'AppRegistry',
'AppState',
'AsyncStorage',
'BackHandler',
'Clipboard',
'DeviceInfo',
'Dimensions',
'Easing',
'ReactNative',
'I18nManager',
'InteractionManager',
'Keyboard',
'LayoutAnimation',
'Linking',
'LogBox',
'NativeEventEmitter',
'PanResponder',
'PermissionsAndroid',
'PixelRatio',
'PushNotificationIOS',
'Settings',
'Share',
'StyleSheet',
'Systrace',
'ToastAndroid',
'TVEventHandler',
'UIManager',
'ReactNative',
'UTFSequence',
'Vibration',

// Plugins
'RCTDeviceEventEmitter',
'RCTNativeAppEventEmitter',
'NativeModules',
'Platform',
'processColor',
'requireNativeComponent',
]);
Loading

0 comments on commit e2ed418

Please sign in to comment.