Skip to content

Commit

Permalink
breaking: Remove fallback flow for Metro config defaults (0.73) (#1972)
Browse files Browse the repository at this point in the history
Reverts #1896
  • Loading branch information
huntie committed Jul 19, 2023
1 parent aa9efcb commit 1fc7eba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 107 deletions.
87 changes: 0 additions & 87 deletions packages/cli-plugin-metro/src/tools/getDefaultMetroConfig.ts

This file was deleted.

38 changes: 18 additions & 20 deletions packages/cli-plugin-metro/src/tools/loadMetroConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fs from 'fs';
import path from 'path';
import {
ConfigT,
Expand All @@ -10,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};
Expand All @@ -20,6 +18,10 @@ export type ConfigLoadingContext = Pick<
'root' | 'reactNativePath' | 'platforms'
>;

declare global {
var __REACT_NATIVE_METRO_CONFIG_LOADED: boolean;
}

/**
* Get the config options to override based on RN CLI inputs.
*/
Expand Down Expand Up @@ -98,26 +100,22 @@ export default async function loadMetroConfig(

logger.debug(`Reading Metro config from ${projectConfig.filepath}`);

if (
!/['"']@react-native\/metro-config['"']/.test(
fs.readFileSync(projectConfig.filepath, 'utf8'),
)
) {
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' +
'https://github.com/facebook/react-native/blob/main/packages/react-native/template/metro.config.js',
);
logger.warn('Falling back to internal defaults.');
if (!global.__REACT_NATIVE_METRO_CONFIG_LOADED) {
const warning = `
=================================================================================================
const loadedConfig = await loadConfig(
{cwd: ctx.root, ...options},
// Provide React Native defaults on top of Metro defaults
getDefaultMetroConfig(ctx),
);
From React Native 0.73, your project's Metro config should extend '@react-native/metro-config'
or it will fail to build. Please copy the template at:
https://github.com/facebook/react-native/blob/main/packages/react-native/template/metro.config.js
This warning will be removed in future (https://github.com/facebook/metro/issues/1018).
=================================================================================================
`;

return mergeConfig(loadedConfig, overrideConfig);
for (const line of warning.trim().split('\n')) {
logger.warn(line);
}
}

return mergeConfig(
Expand Down

0 comments on commit 1fc7eba

Please sign in to comment.