Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 949
breaking: Update cli-plugin-metro to use defaults in app metro.config.js (RN 0.72)#1875
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
Merged
thymikee
merged 1 commit into
react-native-community:main
from
huntie:rn-metro-config-stack-1Mar 23, 2023
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17 packages/cli-plugin-metro/src/tools/__tests__/loadMetroConfig-test.ts
This file was deleted.
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,8 @@ | ||
| /** | ||
| * Configuration file of Metro. | ||
| */ | ||
| import path from 'path'; | ||
| import {ConfigT, InputConfigT, loadConfig} from 'metro-config'; | ||
| import type {Config} from '@react-native-community/cli-types'; | ||
| import {reactNativePlatformResolver} from './metroPlatformResolver'; | ||
| 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('|'), | ||
| ); | ||
| export type {Config}; | ||
| export type ConfigLoadingContext = Pick< | ||
| @@ -34,9 +11,9 @@ export type ConfigLoadingContext = Pick< | ||
| >; | ||
| /** | ||
| * Default configuration | ||
| * Get the config options to override based on RN CLI inputs. | ||
| */ | ||
| export const getDefaultConfig = (ctx: ConfigLoadingContext): InputConfigT => { | ||
| function getOverrideConfig(ctx: ConfigLoadingContext): InputConfigT { | ||
| const outOfTreePlatforms = Object.keys(ctx.platforms).filter( | ||
| (platform) => ctx.platforms[platform].npmPackageName, | ||
| ); | ||
| @@ -55,9 +32,7 @@ export const getDefaultConfig = (ctx: ConfigLoadingContext): InputConfigT => { | ||
| {}, | ||
| ), | ||
| ), | ||
| resolverMainFields: ['react-native', 'browser', 'main'], | ||
| platforms: [...Object.keys(ctx.platforms), 'native'], | ||
| unstable_conditionNames: ['import', 'require', 'react-native'], | ||
| }, | ||
| serializer: { | ||
| // We can include multiple copies of InitializeCore here because metro will | ||
| @@ -73,33 +48,9 @@ export const getDefaultConfig = (ctx: ConfigLoadingContext): InputConfigT => { | ||
| ), | ||
| ), | ||
| ], | ||
| getPolyfills: () => | ||
| require(path.join(ctx.reactNativePath, 'rn-get-polyfills'))(), | ||
| }, | ||
| server: { | ||
| port: Number(process.env.RCT_METRO_PORT) || 8081, | ||
| }, | ||
| symbolicator: { | ||
| customizeFrame: (frame) => { | ||
| const collapse = Boolean( | ||
| frame.file && INTERNAL_CALLSITES_REGEX.test(frame.file), | ||
| ); | ||
| return {collapse}; | ||
| }, | ||
| }, | ||
| transformer: { | ||
| allowOptionalDependencies: true, | ||
| babelTransformerPath: require.resolve( | ||
| 'metro-react-native-babel-transformer', | ||
| ), | ||
| assetRegistryPath: 'react-native/Libraries/Image/AssetRegistry', | ||
| asyncRequireModulePath: require.resolve( | ||
| 'metro-runtime/src/modules/asyncRequire', | ||
huntie marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| ), | ||
| }, | ||
| watchFolders: [], | ||
| }; | ||
| }; | ||
| } | ||
| export interface ConfigOptionsT { | ||
| maxWorkers?: number; | ||
| @@ -113,17 +64,18 @@ export interface ConfigOptionsT { | ||
| } | ||
| /** | ||
| * Loads Metro Config and applies `options` on top of the resolved config. | ||
| * Load Metro config. | ||
| * | ||
| * This allows the CLI to always overwrite the file settings. | ||
| * Allows the CLI to override certain defaults in the base `metro.config.js` | ||
| * based on dynamic user options in `ctx`. | ||
| */ | ||
| export default function loadMetroConfig( | ||
| ctx: ConfigLoadingContext, | ||
| options?: ConfigOptionsT, | ||
| ): Promise<ConfigT> { | ||
| const defaultConfig = {...getDefaultConfig(ctx)}; | ||
| const overrideConfig = getOverrideConfig(ctx); | ||
| if (options && options.reporter) { | ||
| defaultConfig.reporter = options.reporter; | ||
| overrideConfig.reporter = options.reporter; | ||
| } | ||
| return loadConfig({cwd: ctx.root, ...options}, defaultConfig); | ||
| return loadConfig({cwd: ctx.root, ...options}, overrideConfig); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's check if this is not used by Windows/macOS teams. cc @tido64@Saadnajmi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't find any references to this function in react-native-windows/-macos. Nor do we use it in rnx-kit. I'd say it's safe to remove it, but I'll let @Saadnajmi verify as well.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tido While this particular function isn't used, the answer is yes, this overall PR breaks RNW. :) All of our PRs are blocked because we test changes by creating a new app with the CLI and verifying it builds/bundles.
See: microsoft/react-native-windows#11437
We currently have a (hopefully temporary) workaround here: microsoft/react-native-windows#11438
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should've been fixed in: #1889. Is this still happening as in 11.0.1?