diff --git a/packages/metro-config/.gitignore b/packages/metro-config/.gitignore new file mode 100644 index 00000000000000..40d93a0332c96d --- /dev/null +++ b/packages/metro-config/.gitignore @@ -0,0 +1,5 @@ +# Dependencies +/node_modules + +# Build output +/dist diff --git a/packages/metro-config/package.json b/packages/metro-config/package.json index 5b02773a5a0277..1dc4cf56abece1 100644 --- a/packages/metro-config/package.json +++ b/packages/metro-config/package.json @@ -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", diff --git a/packages/metro-config/index.js b/packages/metro-config/src/index.flow.js similarity index 85% rename from packages/metro-config/index.js rename to packages/metro-config/src/index.flow.js index 2abf2c8757d475..f976e0e726230e 100644 --- a/packages/metro-config/index.js +++ b/packages/metro-config/src/index.flow.js @@ -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 + * @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( [ @@ -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'], @@ -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), ); @@ -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}; diff --git a/packages/metro-config/src/index.js b/packages/metro-config/src/index.js new file mode 100644 index 00000000000000..b1cd97b5d4555d --- /dev/null +++ b/packages/metro-config/src/index.js @@ -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'; diff --git a/scripts/build/config.js b/scripts/build/config.js index a2014995b829d9..676fffb5c74b46 100644 --- a/scripts/build/config.js +++ b/scripts/build/config.js @@ -49,6 +49,10 @@ const buildConfig /*: BuildConfig */ = { target: 'node', emitTypeScriptDefs: true, }, + 'metro-config': { + target: 'node', + emitTypeScriptDefs: true, + }, }, };