From 1a61afddf77bd945d446a5688f9663dff2b8b782 Mon Sep 17 00:00:00 2001 From: Gabriel Donadel Date: Fri, 10 Nov 2023 04:45:51 -0800 Subject: [PATCH] Expose unstable_InspectorProxy and unstable_Device from dev-middleware (#41370) Summary: Recently, both `metro-inspector-proxy`(https://github.com/facebook/react-native/pull/39045) and `react-native-community/cli-plugin-metro`(https://github.com/facebook/react-native/pull/38795) were moved to this repo and in the process of moving these packages, the `exports` field inside package.json was added, only exporting the `index.js` file. The problem is that Expo CLI (and possibly other community packages) rely on functions and classes that are not exported in the `index.js` file, e.g. Importing the InspectorProxy class from `react-native/dev-middleware/dist/inspector-proxy/InspectorProxy`. Normally this wouldn't be a problem and we would just import from `dist/` but due to the `exports` field, attempting to import from any other file not specified on this field will result in a `ERR_PACKAGE_PATH_NOT_EXPORTED` error. As a short-term fix, we should create `unstable_`-prefixed exports of individual features Expo currently depends on. ## Changelog: [INTERNAL] [CHANGED] - Expose unstable_InspectorProxy and unstable_Device from `react-native/dev-middleware` Pull Request resolved: https://github.com/facebook/react-native/pull/41370 Test Plan: N / A Reviewed By: robhogan Differential Revision: D51163134 Pulled By: blakef fbshipit-source-id: e67adaedc4fc64131e4c9dd8383c9877b8202283 --- packages/dev-middleware/src/createDevMiddleware.js | 11 ++++++++++- packages/dev-middleware/src/index.flow.js | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/dev-middleware/src/createDevMiddleware.js b/packages/dev-middleware/src/createDevMiddleware.js index 1396a7b6bd02cf..12892521e32c67 100644 --- a/packages/dev-middleware/src/createDevMiddleware.js +++ b/packages/dev-middleware/src/createDevMiddleware.js @@ -59,6 +59,13 @@ type Options = $ReadOnly<{ * This is an unstable API with no semver guarantees. */ unstable_experiments?: ExperimentsConfig, + + /** + * An interface for using a modified inspector proxy implementation. + * + * This is an unstable API with no semver guarantees. + */ + unstable_InspectorProxy?: Class, }>; type DevMiddlewareAPI = $ReadOnly<{ @@ -73,10 +80,12 @@ export default function createDevMiddleware({ unstable_browserLauncher = DefaultBrowserLauncher, unstable_eventReporter, unstable_experiments: experimentConfig = {}, + unstable_InspectorProxy, }: Options): DevMiddlewareAPI { const experiments = getExperiments(experimentConfig); - const inspectorProxy = new InspectorProxy( + const InspectorProxyClass = unstable_InspectorProxy ?? InspectorProxy; + const inspectorProxy = new InspectorProxyClass( projectRoot, serverBaseUrl, unstable_eventReporter, diff --git a/packages/dev-middleware/src/index.flow.js b/packages/dev-middleware/src/index.flow.js index 4060a2bb2d4c4d..c662838fea10ce 100644 --- a/packages/dev-middleware/src/index.flow.js +++ b/packages/dev-middleware/src/index.flow.js @@ -13,3 +13,6 @@ export {default as createDevMiddleware} from './createDevMiddleware'; export type {BrowserLauncher, LaunchedBrowser} from './types/BrowserLauncher'; export type {EventReporter, ReportableEvent} from './types/EventReporter'; + +export {default as unstable_InspectorProxy} from './inspector-proxy/InspectorProxy'; +export {default as unstable_Device} from './inspector-proxy/Device';