Skip to content

Commit

Permalink
Re-export metro-config's resolveConfig from metro
Browse files Browse the repository at this point in the history
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
  • Loading branch information
robhogan authored and facebook-github-bot committed Apr 11, 2023
1 parent d0b8ea5 commit cc16664
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 7 additions & 1 deletion packages/metro/src/index.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions packages/metro/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import type {Server as HttpsServer} from 'https';
import type {
ConfigT,
InputConfigT,
loadConfig,
MetroConfig,
Middleware,
} from 'metro-config';
Expand All @@ -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 {
Expand Down Expand Up @@ -114,8 +115,6 @@ export function runMetro(
options?: RunMetroOptions,
): Promise<MetroServer>;

export {loadConfig};

export function createConnectMiddleWare(
config: ConfigT,
options?: RunMetroOptions,
Expand Down

0 comments on commit cc16664

Please sign in to comment.