Skip to content

Commit

Permalink
Restore base config merge in metro-config (#38092)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #38092

Reverts #36777.

This is motivated by reducing user friction when the widespread assumption is for `react-native/metro-config` to export a complete Metro config, as with Expo/rnx-kit, and like previously understood uses of `metro-config`. See facebook/metro#1010 (comment) for further notes.

Fixes:
- facebook/metro#1010
- #38069
- kristerkari/react-native-svg-transformer#276

Note that we do not intend for `react-native/metro-config` to directly export `assetExts` etc — these can be accessed on the `resolver` property from the full config object.

Changelog: [General][Changed] `react-native/metro-config` now includes all base config values from `metro-config`

Reviewed By: robhogan

Differential Revision: D47055973

fbshipit-source-id: 5ad23cc9700397110de5c0e81c7d76299761ef0a
  • Loading branch information
huntie authored and kelset committed Jun 28, 2023
1 parent 69705a4 commit 78c1a7e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/metro-config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* @noformat
*/

/*:: import type {MetroConfig} from 'metro-config'; */
/*:: import type {ConfigT} from 'metro-config'; */

const {mergeConfig} = require('metro-config');
const {getDefaultConfig: getBaseConfig, mergeConfig} = require('metro-config');

const INTERNAL_CALLSITES_REGEX = new RegExp(
[
Expand Down Expand Up @@ -38,8 +38,8 @@ const INTERNAL_CALLSITES_REGEX = new RegExp(

function getDefaultConfig(
projectRoot /*: string */
) /*: MetroConfig */ {
return {
) /*: ConfigT */ {
const config = {
resolver: {
resolverMainFields: ['react-native', 'browser', 'main'],
platforms: ['android', 'ios'],
Expand Down Expand Up @@ -77,6 +77,11 @@ function getDefaultConfig(
},
watchFolders: [],
};

return mergeConfig(
getBaseConfig.getDefaultValues(projectRoot),
config,
);
}

module.exports = {getDefaultConfig, mergeConfig};

0 comments on commit 78c1a7e

Please sign in to comment.