Skip to content
Closed
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
5 changes: 5 additions & 0 deletions packages/metro-config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Dependencies
/node_modules

# Build output
/dist
8 changes: 7 additions & 1 deletion packages/metro-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@
"engines": {
"node": ">=18"
},
"exports": "./index.js",
"exports": {
".": "./src/index.js",
"./package.json": "./package.json"
},
"files": [
"dist"
],
"dependencies": {
"@react-native/metro-babel-transformer": "^0.74.0",
"@react-native/js-polyfills": "^0.74.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @noformat
* @flow strict-local
Copy link
Member

Choose a reason for hiding this comment

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

Ah my bad, let's loosen this to @flow so that CI passes.

* @format
* @oncall react_native
*/

/*:: import type {ConfigT} from 'metro-config'; */
import type {ConfigT} from 'metro-config';

const {getDefaultConfig: getBaseConfig, mergeConfig} = require('metro-config');
import {getDefaultConfig as getBaseConfig, mergeConfig} from 'metro-config';

const INTERNAL_CALLSITES_REGEX = new RegExp(
[
Expand All @@ -36,12 +37,12 @@ const INTERNAL_CALLSITES_REGEX = new RegExp(
].join('|'),
);

export {mergeConfig} from 'metro-config';

/**
* Get the base Metro configuration for a React Native project.
*/
function getDefaultConfig(
projectRoot /*: string */
) /*: ConfigT */ {
export function getDefaultConfig(projectRoot: string): ConfigT {
const config = {
resolver: {
resolverMainFields: ['react-native', 'browser', 'main'],
Expand All @@ -59,7 +60,7 @@ function getDefaultConfig(
port: Number(process.env.RCT_METRO_PORT) || 8081,
},
symbolicator: {
customizeFrame: (frame /*: $ReadOnly<{file: ?string, ...}>*/) => {
customizeFrame: (frame: $ReadOnly<{file: ?string, ...}>) => {
const collapse = Boolean(
frame.file && INTERNAL_CALLSITES_REGEX.test(frame.file),
);
Expand Down Expand Up @@ -88,10 +89,5 @@ function getDefaultConfig(
// Set global hook so that the CLI can detect when this config has been loaded
global.__REACT_NATIVE_METRO_CONFIG_LOADED = true;

return mergeConfig(
getBaseConfig.getDefaultValues(projectRoot),
config,
);
return mergeConfig(getBaseConfig.getDefaultValues(projectRoot), config);
}

module.exports = {getDefaultConfig, mergeConfig};
20 changes: 20 additions & 0 deletions packages/metro-config/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
* @oncall react_native
*/

/*::
export type * from './index.flow';
*/

if (!process.env.BUILD_EXCLUDE_BABEL_REGISTER) {
require('../../../scripts/build/babel-register').registerForMonorepo();
}

export * from './index.flow';
4 changes: 4 additions & 0 deletions scripts/build/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ const buildConfig /*: BuildConfig */ = {
target: 'node',
emitTypeScriptDefs: true,
},
'metro-config': {
target: 'node',
emitTypeScriptDefs: true,
},
},
};

Expand Down