Skip to content

Commit 7f01ec0

Browse files
huntiefacebook-github-bot
authored andcommitted
Bump RN CLI, add @react-native/metro-config to template (facebook#36623)
Summary: Pull Request resolved: facebook#36623 Changelog: [General][Changed] - The default `metro.config.js` in apps now extends `react-native/metro-config`, and should be updated in existing apps. ~~`react-native/rn-get-polyfills.js` is removed and should be updated to `react-native/js-polyfills` in existing apps (this is part of the new default config).~~ #publish-packages-to-npm ## Context ### React Native Metro config → React Native repo (facebook#36502) We (the React Native team) are aiming to relocate the default Metro config for React Native out of `react-native-community/cli-plugin-metro` and **into the React Native repo + app template** as a new `react-native/metro-config` package. This is the first (and minimum viable) phase we can ship to separate the release process of Metro from RN CLI in order to reduce coupling and iterate faster for our users. **See full motivation, design, and test plan (which previewed the CLI bump) here: facebook#36502 ## Changes NOTE: This PR is pending the inclusion of a bump to `react-native-community/cli`, and will be sequenced after react-native-community/cli#1875 is merged. - Upgrade `react-native-community/cli` to `11.0.0`, upgrade all `metro` packages to `0.76.0` (version distributed in this CLI release). - Update the `metro.config.js` file in `packages/react-native/template/`. - Now merges defaults from `react-native/metro-config`, and can be used with CLI >= 11.0.0. - Update the `metro.config.js` files for `packages/react-native/` and `packages/rn-tester/` (these are integration test locations). - Now merges defaults from `react-native/metro-config`, and can be used with CLI >= 11.0.0. Changes to `react-native/metro-config` — `0.72.1` (prepared but not depended on yet): - Export `mergeConfig` util (removing direct `metro-config` dependency in consuming projects). - Explicitly depend on `metro-react-native-babel-transformer` and `metro-runtime` (transitively included today). Reviewed By: cortinico, blakef Differential Revision: D44099691 fbshipit-source-id: a1a9820af1cd9ad8fb279b8af356f570886b9dee
1 parent 6668e7b commit 7f01ec0

File tree

11 files changed

+274
-267
lines changed

11 files changed

+274
-267
lines changed

jest/preprocessor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ const nodeFiles = new RegExp(
3030
// Babel here.
3131
const nodeOptions = babelRegisterOnly.config([nodeFiles]);
3232

33-
const transformer = require('metro-react-native-babel-transformer');
3433
module.exports = {
3534
process(src /*: string */, file /*: string */) /*: {code: string, ...} */ {
3635
if (nodeFiles.test(file)) {
@@ -43,6 +42,7 @@ module.exports = {
4342
});
4443
}
4544

45+
const transformer = require('metro-react-native-babel-transformer');
4646
const {ast} = transformer.transform({
4747
filename: file,
4848
options: {

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"@definitelytyped/dtslint": "^0.0.127",
5858
"@jest/create-cache-key-function": "^29.2.1",
5959
"@reactions/component": "^2.0.2",
60+
"@react-native/metro-config": "^0.72.0",
6061
"@types/react": "^18.0.18",
6162
"@typescript-eslint/parser": "^5.30.5",
6263
"async": "^3.2.2",
@@ -83,9 +84,9 @@
8384
"jest": "^29.2.1",
8485
"jest-junit": "^10.0.0",
8586
"jscodeshift": "^0.14.0",
86-
"metro-babel-register": "0.75.1",
87-
"metro-memory-fs": "0.75.1",
88-
"metro-react-native-babel-transformer": "0.75.1",
87+
"metro-babel-register": "0.76.0",
88+
"metro-memory-fs": "0.76.0",
89+
"metro-react-native-babel-transformer": "0.76.0",
8990
"mkdirp": "^0.5.1",
9091
"mock-fs": "^5.1.4",
9192
"prettier": "^2.4.1",

packages/metro-config/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,4 @@ function getDefaultConfig(
8383
);
8484
}
8585

86-
module.exports = {getDefaultConfig};
86+
module.exports = {getDefaultConfig, mergeConfig};

packages/metro-config/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@react-native/metro-config",
3-
"version": "0.72.0",
3+
"version": "0.72.1",
44
"description": "Metro configuration for React Native.",
55
"repository": {
66
"type": "git",
@@ -11,6 +11,8 @@
1111
"exports": "./index.js",
1212
"dependencies": {
1313
"@react-native/js-polyfills": "^0.72.1",
14-
"metro-config": "0.75.1"
14+
"metro-config": "0.76.0",
15+
"metro-react-native-babel-transformer": "0.76.0",
16+
"metro-runtime": "0.76.0"
1517
}
1618
}

packages/react-native/metro.config.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99

1010
'use strict';
1111

12+
const {getDefaultConfig} = require('@react-native/metro-config');
13+
const {mergeConfig} = require('metro-config');
1214
const path = require('path');
13-
const getPolyfills = require('./rn-get-polyfills');
1415

1516
/**
1617
* This cli config is needed for development purposes, e.g. for running
1718
* integration tests during local development or on CI services.
1819
*/
19-
module.exports = {
20+
const config = {
2021
// Make Metro able to resolve required packages that might be imported from /packages/react-native
2122
watchFolders: [
2223
path.resolve(__dirname, '../../node_modules'),
@@ -31,7 +32,6 @@ module.exports = {
3132
'react-native': __dirname,
3233
},
3334
},
34-
serializer: {
35-
getPolyfills,
36-
},
3735
};
36+
37+
module.exports = mergeConfig(getDefaultConfig(__dirname), config);

packages/react-native/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@
7979
},
8080
"dependencies": {
8181
"@jest/create-cache-key-function": "^29.2.1",
82-
"@react-native-community/cli": "11.0.0-alpha.2",
83-
"@react-native-community/cli-platform-android": "11.0.0-alpha.2",
84-
"@react-native-community/cli-platform-ios": "11.0.0-alpha.2",
82+
"@react-native-community/cli": "11.0.0",
83+
"@react-native-community/cli-platform-android": "11.0.0",
84+
"@react-native-community/cli-platform-ios": "11.0.0",
8585
"@react-native/assets-registry": "^0.72.0",
8686
"@react-native/codegen": "^0.72.3",
8787
"@react-native/gradle-plugin": "^0.72.5",
@@ -98,8 +98,9 @@
9898
"jest-environment-node": "^29.2.1",
9999
"jsc-android": "^250231.0.0",
100100
"memoize-one": "^5.0.0",
101-
"metro-runtime": "0.75.1",
102-
"metro-source-map": "0.75.1",
101+
"metro-react-native-babel-transformer": "0.76.0",
102+
"metro-runtime": "0.76.0",
103+
"metro-source-map": "0.76.0",
103104
"mkdirp": "^0.5.1",
104105
"nullthrows": "^1.1.1",
105106
"pretty-format": "^26.5.2",
Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1+
const {getDefaultConfig} = require('@react-native/metro-config');
2+
const {mergeConfig} = require('metro-config');
3+
14
/**
2-
* Metro configuration for React Native
3-
* https://github.com/facebook/react-native
5+
* Metro configuration
6+
* https://facebook.github.io/metro/docs/configuration
47
*
5-
* @format
8+
* @type {import('metro-config').MetroConfig}
69
*/
10+
const config = {};
711

8-
module.exports = {
9-
transformer: {
10-
getTransformOptions: async () => ({
11-
transform: {
12-
experimentalImportSupport: false,
13-
inlineRequires: true,
14-
},
15-
}),
16-
},
17-
};
12+
module.exports = mergeConfig(getDefaultConfig(__dirname), config);

packages/react-native/template/package.json

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,21 @@
1818
"@babel/preset-env": "^7.20.0",
1919
"@babel/runtime": "^7.12.5",
2020
"@react-native/eslint-config": "^0.72.1",
21+
"@react-native/metro-config": "^0.72.0",
2122
"@tsconfig/react-native": "^2.0.2",
23+
"@types/metro-config": "^0.76.1",
2224
"@types/react": "^18.0.24",
2325
"@types/react-test-renderer": "^18.0.0",
2426
"babel-jest": "^29.2.1",
2527
"eslint": "^8.19.0",
2628
"jest": "^29.2.1",
27-
"metro-react-native-babel-preset": "0.75.1",
29+
"metro-config": "0.76.0",
30+
"metro-react-native-babel-preset": "0.76.0",
2831
"prettier": "^2.4.1",
2932
"react-test-renderer": "18.2.0",
3033
"typescript": "4.8.4"
3134
},
3235
"engines": {
3336
"node": ">=16"
34-
},
35-
"overrides": {
36-
"@react-native-community/cli": "11.0.0-alpha.0",
37-
"@react-native-community/cli-platform-android": "11.0.0-alpha.0",
38-
"@react-native-community/cli-platform-ios": "11.0.0-alpha.0",
39-
"@react-native-community/cli-plugin-metro": "11.0.0-alpha.0"
40-
},
41-
"resolutions": {
42-
"@react-native-community/cli": "11.0.0-alpha.0",
43-
"@react-native-community/cli-platform-android": "11.0.0-alpha.0",
44-
"@react-native-community/cli-platform-ios": "11.0.0-alpha.0",
45-
"@react-native-community/cli-plugin-metro": "11.0.0-alpha.0"
4637
}
4738
}

packages/rn-tester/metro.config.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99

1010
'use strict';
1111

12+
const {getDefaultConfig} = require('@react-native/metro-config');
13+
const {mergeConfig} = require('metro-config');
1214
const path = require('path');
13-
const getPolyfills = require('../react-native/rn-get-polyfills');
1415

1516
/**
1617
* This cli config is needed for development purposes, e.g. for running
1718
* integration tests during local development or on CI services.
19+
*
20+
* @type {import('metro-config').MetroConfig}
1821
*/
19-
module.exports = {
22+
const config = {
2023
// Make Metro able to resolve required external dependencies
2124
watchFolders: [
2225
path.resolve(__dirname, '../../node_modules'),
@@ -32,7 +35,6 @@ module.exports = {
3235
'react-native': path.resolve(__dirname, '../react-native'),
3336
},
3437
},
35-
serializer: {
36-
getPolyfills,
37-
},
3838
};
39+
40+
module.exports = mergeConfig(getDefaultConfig(__dirname), config);

packages/rn-tester/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
"clean-ios": "rm -rf build/generated/ios Pods Podfile.lock"
2121
},
2222
"dependencies": {
23+
"flow-enums-runtime": "^0.0.5",
2324
"invariant": "^2.2.4",
24-
"nullthrows": "^1.1.1",
25-
"flow-enums-runtime": "^0.0.5"
25+
"nullthrows": "^1.1.1"
2626
},
2727
"peerDependencies": {
2828
"react": "18.2.0",

0 commit comments

Comments
 (0)