From 054d6e6b3d9603684ffef842ea68a55da879868f Mon Sep 17 00:00:00 2001 From: Alex Hunt Date: Tue, 30 May 2023 16:19:31 +0100 Subject: [PATCH] breaking: Remove fallback flow for Metro config defaults (0.73) Reverts https://github.com/react-native-community/cli/pull/1896 --- .../src/tools/getDefaultMetroConfig.ts | 87 ------------------- .../src/tools/loadMetroConfig.ts | 16 +--- 2 files changed, 3 insertions(+), 100 deletions(-) delete mode 100644 packages/cli-plugin-metro/src/tools/getDefaultMetroConfig.ts diff --git a/packages/cli-plugin-metro/src/tools/getDefaultMetroConfig.ts b/packages/cli-plugin-metro/src/tools/getDefaultMetroConfig.ts deleted file mode 100644 index 07e809853f..0000000000 --- a/packages/cli-plugin-metro/src/tools/getDefaultMetroConfig.ts +++ /dev/null @@ -1,87 +0,0 @@ -import type {InputConfigT} from 'metro-config'; -import path from 'path'; -import type {ConfigLoadingContext} from './loadMetroConfig'; - -/** - * This module reproduces defaults from the @react-native/metro-config package, - * used in ./loadMetroConfig.js to provide a soft upgrade process when upgrading - * to React Native 0.72. - * - * These values will be used when: - * - RN CLI 11.x or greater is present in a project (from React Native 0.72). - * - The project has not yet followed the upgrade instructions to update - * metro.config.js to extend '@react-native/metro-config'. - * - * Until we remove this file in a future release, updates should be made both - * here and in '@react-native/metro-config'. (Note: Updates to these values are - * generally rare.) - * - * TODO(@huntie): Remove this file in a future React Native release. - */ - -/** - * @deprecated (React Native 0.72.0) Defaults should be updated here and in - * https://github.com/facebook/react-native/tree/main/package/metro-config/index.js - */ -const INTERNAL_CALLSITES_REGEX = new RegExp( - [ - '/Libraries/Renderer/implementations/.+\\.js$', - '/Libraries/BatchedBridge/MessageQueue\\.js$', - '/Libraries/YellowBox/.+\\.js$', - '/Libraries/LogBox/.+\\.js$', - '/Libraries/Core/Timers/.+\\.js$', - '/Libraries/WebSocket/.+\\.js$', - '/Libraries/vendor/.+\\.js$', - '/node_modules/react-devtools-core/.+\\.js$', - '/node_modules/react-refresh/.+\\.js$', - '/node_modules/scheduler/.+\\.js$', - '/node_modules/event-target-shim/.+\\.js$', - '/node_modules/invariant/.+\\.js$', - '/node_modules/react-native/index.js$', - '/metro-runtime/.+\\.js$', - '^\\[native code\\]$', - ].join('|'), -); - -/** - * Get the static Metro config defaults for a React Native project. - * - * @deprecated (React Native 0.72.0) Defaults should be updated here and in - * https://github.com/facebook/react-native/tree/main/package/metro-config/index.js - */ -export default function getDefaultMetroConfig( - ctx: ConfigLoadingContext, -): InputConfigT { - return { - resolver: { - resolverMainFields: ['react-native', 'browser', 'main'], - unstable_conditionNames: ['require', 'react-native'], - }, - serializer: { - getPolyfills: () => - require(path.join(ctx.reactNativePath, 'rn-get-polyfills'))(), - }, - server: { - port: Number(process.env.RCT_METRO_PORT) || 8081, - }, - symbolicator: { - customizeFrame: (frame: {file?: string}) => { - const collapse = Boolean( - frame.file && INTERNAL_CALLSITES_REGEX.test(frame.file), - ); - return {collapse}; - }, - }, - transformer: { - allowOptionalDependencies: true, - assetRegistryPath: 'react-native/Libraries/Image/AssetRegistry', - asyncRequireModulePath: require.resolve( - 'metro-runtime/src/modules/asyncRequire', - ), - babelTransformerPath: require.resolve( - 'metro-react-native-babel-transformer', - ), - }, - watchFolders: [], - }; -} diff --git a/packages/cli-plugin-metro/src/tools/loadMetroConfig.ts b/packages/cli-plugin-metro/src/tools/loadMetroConfig.ts index 440c183d31..40a9e6a080 100644 --- a/packages/cli-plugin-metro/src/tools/loadMetroConfig.ts +++ b/packages/cli-plugin-metro/src/tools/loadMetroConfig.ts @@ -9,7 +9,6 @@ import { } from 'metro-config'; import {CLIError, logger} from '@react-native-community/cli-tools'; import type {Config} from '@react-native-community/cli-types'; -import getDefaultMetroConfig from './getDefaultMetroConfig'; import {reactNativePlatformResolver} from './metroPlatformResolver'; export type {Config}; @@ -101,20 +100,11 @@ export default async function loadMetroConfig( ) ) { logger.warn( - 'From React Native 0.72, your metro.config.js file should extend' + - "'@react-native/metro-config'. Please see the React Native 0.72 " + - 'changelog, or copy the template at:\n' + + 'From React Native 0.73, your metro.config.js file should extend' + + "'@react-native/metro-config' or it will fail to build. Please copy " + + 'the template at:\n' + 'https://github.com/facebook/react-native/blob/main/packages/react-native/template/metro.config.js', ); - logger.warn('Falling back to internal defaults.'); - - const loadedConfig = await loadConfig( - {cwd: ctx.root, ...options}, - // Provide React Native defaults on top of Metro defaults - getDefaultMetroConfig(ctx), - ); - - return mergeConfig(loadedConfig, overrideConfig); } return mergeConfig(