From 94b1c9949a13684d0de4ccdf628bfcfc7cdd7bdb Mon Sep 17 00:00:00 2001 From: Alex Hunt Date: Tue, 18 Apr 2023 03:57:34 -0700 Subject: [PATCH] Drop internal base config merge in metro-config (#36777) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/36777 Changelog: [Internal] Remove internal merge of `getDefaultConfig` (Metro base defaults) from `react-native/metro-config`. This is unnecessary given the config loading setup of RN CLI and Expo CLI, which use (or replicate) Metro's [`loadConfig`](https://github.com/facebook/metro/blob/1e47cb5b3cc289530fb18e402891f9d2816611dd/packages/metro-config/src/loadConfig.js#L182-L190) function — which will itself apply defaults appropriately. This relates to a previously-breaking behaviour documented in the test plan of https://github.com/react-native-community/cli/pull/1896 (independently fixed and no longer load-bearing) (**read: no need to cherry pick this change**). https://pxl.cl/2B8NS While this has no effect under the fixed RN CLI setup, this is a worthwhile simplification to this package that better-aligns with current Metro tooling expectations. ## Notes - `getDefaultConfig` no longer returns `ConfigT` (full config), and instead returns `MetroConfig` (partial config). This is non-breaking with the expected API of a given `metro.config.js` file. Differential Revision: D44630645 fbshipit-source-id: e85247b145e87d7bac9eca0bcb90e85e6fec98ae --- packages/metro-config/index.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/metro-config/index.js b/packages/metro-config/index.js index c43b46a34b8cf9..e88df579040627 100644 --- a/packages/metro-config/index.js +++ b/packages/metro-config/index.js @@ -8,9 +8,9 @@ * @noformat */ -/*:: import type {ConfigT} from 'metro-config'; */ +/*:: import type {MetroConfig} from 'metro-config'; */ -const {getDefaultConfig: getBaseConfig, mergeConfig} = require('metro-config'); +const {mergeConfig} = require('metro-config'); const INTERNAL_CALLSITES_REGEX = new RegExp( [ @@ -37,8 +37,8 @@ const INTERNAL_CALLSITES_REGEX = new RegExp( */ function getDefaultConfig( projectRoot /*: string */ -) /*: ConfigT */ { - const config = { +) /*: MetroConfig */ { + return { resolver: { resolverMainFields: ['react-native', 'browser', 'main'], platforms: ['android', 'ios'], @@ -76,11 +76,6 @@ function getDefaultConfig( }, watchFolders: [], }; - - return mergeConfig( - getBaseConfig.getDefaultValues(projectRoot), - config, - ); } module.exports = {getDefaultConfig, mergeConfig};