Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

breaking: Remove fallback flow for Metro config defaults (0.73) #1972

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -97,26 +99,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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if this should be pinned (at least to a branch) so it remains accurate in the future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah fair. We don't have 0.73-stable yet — and the counter-risk is pointing to a stale copy. Will keep an eye on it.


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