Skip to content

Commit eab2533

Browse files
committed
breaking: Update cli-plugin-metro to use defaults in app metro.config.js (RN 0.72)
1 parent 605c542 commit eab2533

File tree

3 files changed

+9
-75
lines changed

3 files changed

+9
-75
lines changed

packages/cli-plugin-metro/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ export type {MetroConfig} from 'metro-config';
22
export {
33
Config,
44
ConfigLoadingContext,
5-
getDefaultConfig,
65
default as loadMetroConfig,
76
} from './tools/loadMetroConfig';
87
export {

packages/cli-plugin-metro/src/tools/__tests__/loadMetroConfig-test.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 9 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,8 @@
1-
/**
2-
* Configuration file of Metro.
3-
*/
41
import path from 'path';
52
import {ConfigT, InputConfigT, loadConfig} from 'metro-config';
63
import type {Config} from '@react-native-community/cli-types';
74
import {reactNativePlatformResolver} from './metroPlatformResolver';
85

9-
const INTERNAL_CALLSITES_REGEX = new RegExp(
10-
[
11-
'/Libraries/Renderer/implementations/.+\\.js$',
12-
'/Libraries/BatchedBridge/MessageQueue\\.js$',
13-
'/Libraries/YellowBox/.+\\.js$',
14-
'/Libraries/LogBox/.+\\.js$',
15-
'/Libraries/Core/Timers/.+\\.js$',
16-
'/Libraries/WebSocket/.+\\.js$',
17-
'/Libraries/vendor/.+\\.js$',
18-
'/node_modules/react-devtools-core/.+\\.js$',
19-
'/node_modules/react-refresh/.+\\.js$',
20-
'/node_modules/scheduler/.+\\.js$',
21-
'/node_modules/event-target-shim/.+\\.js$',
22-
'/node_modules/invariant/.+\\.js$',
23-
'/node_modules/react-native/index.js$',
24-
'/metro-runtime/.+\\.js$',
25-
'^\\[native code\\]$',
26-
].join('|'),
27-
);
28-
296
export type {Config};
307

318
export type ConfigLoadingContext = Pick<
@@ -34,9 +11,9 @@ export type ConfigLoadingContext = Pick<
3411
>;
3512

3613
/**
37-
* Default configuration
14+
* Get the config options to override based on RN CLI inputs.
3815
*/
39-
export const getDefaultConfig = (ctx: ConfigLoadingContext): InputConfigT => {
16+
function getOverrideConfig(ctx: ConfigLoadingContext): InputConfigT {
4017
const outOfTreePlatforms = Object.keys(ctx.platforms).filter(
4118
(platform) => ctx.platforms[platform].npmPackageName,
4219
);
@@ -55,9 +32,7 @@ export const getDefaultConfig = (ctx: ConfigLoadingContext): InputConfigT => {
5532
{},
5633
),
5734
),
58-
resolverMainFields: ['react-native', 'browser', 'main'],
5935
platforms: [...Object.keys(ctx.platforms), 'native'],
60-
unstable_conditionNames: ['import', 'require', 'react-native'],
6136
},
6237
serializer: {
6338
// We can include multiple copies of InitializeCore here because metro will
@@ -73,33 +48,9 @@ export const getDefaultConfig = (ctx: ConfigLoadingContext): InputConfigT => {
7348
),
7449
),
7550
],
76-
getPolyfills: () =>
77-
require(path.join(ctx.reactNativePath, 'rn-get-polyfills'))(),
78-
},
79-
server: {
80-
port: Number(process.env.RCT_METRO_PORT) || 8081,
8151
},
82-
symbolicator: {
83-
customizeFrame: (frame) => {
84-
const collapse = Boolean(
85-
frame.file && INTERNAL_CALLSITES_REGEX.test(frame.file),
86-
);
87-
return {collapse};
88-
},
89-
},
90-
transformer: {
91-
allowOptionalDependencies: true,
92-
babelTransformerPath: require.resolve(
93-
'metro-react-native-babel-transformer',
94-
),
95-
assetRegistryPath: 'react-native/Libraries/Image/AssetRegistry',
96-
asyncRequireModulePath: require.resolve(
97-
'metro-runtime/src/modules/asyncRequire',
98-
),
99-
},
100-
watchFolders: [],
10152
};
102-
};
53+
}
10354

10455
export interface ConfigOptionsT {
10556
maxWorkers?: number;
@@ -113,17 +64,18 @@ export interface ConfigOptionsT {
11364
}
11465

11566
/**
116-
* Loads Metro Config and applies `options` on top of the resolved config.
67+
* Load Metro config.
11768
*
118-
* This allows the CLI to always overwrite the file settings.
69+
* Allows the CLI to override certain defaults in the base `metro.config.js`
70+
* based on dynamic user options in `ctx`.
11971
*/
12072
export default function loadMetroConfig(
12173
ctx: ConfigLoadingContext,
12274
options?: ConfigOptionsT,
12375
): Promise<ConfigT> {
124-
const defaultConfig = {...getDefaultConfig(ctx)};
76+
const overrideConfig = getOverrideConfig(ctx);
12577
if (options && options.reporter) {
126-
defaultConfig.reporter = options.reporter;
78+
overrideConfig.reporter = options.reporter;
12779
}
128-
return loadConfig({cwd: ctx.root, ...options}, defaultConfig);
80+
return loadConfig({cwd: ctx.root, ...options}, overrideConfig);
12981
}

0 commit comments

Comments
 (0)