Skip to content

Commit

Permalink
Expose unstable_InspectorProxy and unstable_Device from dev-middleware (
Browse files Browse the repository at this point in the history
facebook#41370)

Summary:
Recently, both `metro-inspector-proxy`(facebook#39045) and `react-native-community/cli-plugin-metro`(facebook#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: facebook#41370

Test Plan: N / A

Reviewed By: robhogan

Differential Revision: D51163134

Pulled By: blakef

fbshipit-source-id: e67adaedc4fc64131e4c9dd8383c9877b8202283
  • Loading branch information
gabrieldonadel authored and Othinn committed Jan 9, 2024
1 parent 9e9cf16 commit 876cf08
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/dev-middleware/src/createDevMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<InspectorProxy>,
}>;

type DevMiddlewareAPI = $ReadOnly<{
Expand All @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions packages/dev-middleware/src/index.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

0 comments on commit 876cf08

Please sign in to comment.