From cc1666415f8773f799ddda6f4f7f83b8dc6205dd Mon Sep 17 00:00:00 2001 From: Rob Hogan Date: Tue, 11 Apr 2023 10:42:51 -0700 Subject: [PATCH] Re-export `metro-config`'s `resolveConfig` from `metro` Summary: `react-native-community/cli-plugin-metro` has a dependency on `mergeConfig`, `loadConfig` and `resolveConfig` from `metro-config`, here: https://github.com/react-native-community/cli/blob/v12.0.0-alpha.2/packages/cli-plugin-metro/src/tools/loadMetroConfig.ts#L3-L9 Otherwise, `cli-plugin-metro` only has build-time dependencies on `metro-config`. By exporting `resolveConfig` in addition to the other two (which we already re-export), we can remove the `metro-config` runtime dependency and use `metro` instead. That's a step closer to making `metro` a `peerDependency` of `cli-plugin-metro`, with version dictated by the host project's dependency, ultimately decoupling Metro from the CLI. Changelog: ``` * **[Feature]** Re-export `metro-config`'s `resolveConfig` from `metro`. ``` Reviewed By: hoxyq Differential Revision: D44870484 fbshipit-source-id: c38175cac5904b0b9540bab6b4c8e70d957d378e --- packages/metro/src/index.flow.js | 8 +++++++- packages/metro/types/index.d.ts | 5 ++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/metro/src/index.flow.js b/packages/metro/src/index.flow.js index b702e02f8d..7ee378a96f 100644 --- a/packages/metro/src/index.flow.js +++ b/packages/metro/src/index.flow.js @@ -38,7 +38,12 @@ const chalk = require('chalk'); const fs = require('fs'); const http = require('http'); const https = require('https'); -const {getDefaultConfig, loadConfig, mergeConfig} = require('metro-config'); +const { + getDefaultConfig, + loadConfig, + mergeConfig, + resolveConfig, +} = require('metro-config'); const {InspectorProxy} = require('metro-inspector-proxy'); const net = require('net'); const {parse} = require('url'); @@ -174,6 +179,7 @@ async function runMetro( exports.runMetro = runMetro; exports.loadConfig = loadConfig; exports.mergeConfig = mergeConfig; +exports.resolveConfig = resolveConfig; const createConnectMiddleware = async function ( config: ConfigT, diff --git a/packages/metro/types/index.d.ts b/packages/metro/types/index.d.ts index dfa1f592fa..234ff74bb7 100644 --- a/packages/metro/types/index.d.ts +++ b/packages/metro/types/index.d.ts @@ -19,7 +19,6 @@ import type {Server as HttpsServer} from 'https'; import type { ConfigT, InputConfigT, - loadConfig, MetroConfig, Middleware, } from 'metro-config'; @@ -30,6 +29,8 @@ import Yargs = require('yargs'); import type {default as MetroServer, ServerOptions} from './Server'; import type {OutputOptions, RequestOptions} from './shared/types'; +export {loadConfig, mergeConfig, resolveConfig} from 'metro-config'; + export {HttpServer, HttpsServer}; interface MetroMiddleWare { @@ -114,8 +115,6 @@ export function runMetro( options?: RunMetroOptions, ): Promise; -export {loadConfig}; - export function createConnectMiddleWare( config: ConfigT, options?: RunMetroOptions,