-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move metro-inspector-proxy into dev-middleware (#39045)
Summary: Pull Request resolved: #39045 ## Context RFC: Decoupling Flipper from React Native core: react-native-community/discussions-and-proposals#641 ## Changes - Relocates `metro-inspector-proxy` source from the Metro repo into the React Native repo as part of the `react-native/dev-middleware` package. - Drops the `runInspectorProxy` entry point. - Attaches the Inspector Proxy to the `createDevMiddleware()` API as the new integration point for this functionality. - Documents migrated endpoints + usage of `createDevMiddleware()` in README. Changelog: [Internal] Metro changelog: None (`metro-inspector-proxy` is now an internal component of `react-native`, covered in the [release notes for 0.78.1](https://github.com/facebook/metro/releases/tag/v0.78.1)) Reviewed By: motiz88, blakef Differential Revision: D48066213 fbshipit-source-id: 2d83d766f487eb53e2a22eea35f0338bf9d2445a
- Loading branch information
1 parent
d1e2cbb
commit 1c60329
Showing
10 changed files
with
1,133 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* 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 | ||
*/ | ||
|
||
// https://github.com/visionmedia/debug | ||
// https://www.npmjs.com/package/debug | ||
|
||
declare module 'debug' { | ||
declare module.exports: (namespace: string) => (...Array<mixed>) => void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,82 @@ | ||
# @react-native/dev-middleware | ||
|
||
![https://img.shields.io/npm/v/@react-native/dev-middleware?color=brightgreen&label=npm%20package](https://www.npmjs.com/package/@react-native/dev-middleware) | ||
![npm package](https://img.shields.io/npm/v/@react-native/dev-middleware?color=brightgreen&label=npm%20package) | ||
|
||
Dev server middleware supporting core React Native development features. This package is preconfigured in all React Native projects. | ||
|
||
## Endpoints | ||
## Usage | ||
|
||
### `/open-debugger` | ||
Middleware can be attached to a dev server (e.g. [Metro](https://facebook.github.io/metro/docs/getting-started)) using the `createDevMiddleware` API. | ||
|
||
```js | ||
import { createDevMiddleware } from '@react-native/dev-middleware'; | ||
|
||
function myDevServerImpl(args) { | ||
... | ||
|
||
const {middleware, websocketEndpoints} = createDevMiddleware({ | ||
host: args.host, | ||
port: metroConfig.server.port, | ||
projectRoot: metroConfig.projectRoot, | ||
logger, | ||
}); | ||
|
||
await Metro.runServer(metroConfig, { | ||
host: args.host, | ||
..., | ||
unstable_extraMiddleware: [ | ||
middleware, | ||
// Optionally extend with additional HTTP middleware | ||
], | ||
websocketEndpoints: { | ||
...websocketEndpoints, | ||
// Optionally extend with additional WebSocket endpoints | ||
}, | ||
}); | ||
} | ||
``` | ||
|
||
## Included middleware | ||
|
||
`@react-native/dev-middleware` is designed for integrators such as [`@expo/dev-server`](https://www.npmjs.com/package/@expo/dev-server) and [`@react-native/community-cli-plugin`](https://github.com/facebook/react-native/tree/main/packages/community-cli-plugin). It provides a common default implementation for core React Native dev server responsibilities. | ||
|
||
We intend to keep this to a narrow set of functionality, based around: | ||
|
||
- **Debugging** — The [Chrome DevTools protocol (CDP)](https://chromedevtools.github.io/devtools-protocol/) endpoints supported by React Native, including the Inspector Proxy, which facilitates connections with multiple devices. | ||
- **Dev actions** — Endpoints implementing core [Dev Menu](https://reactnative.dev/docs/debugging#accessing-the-dev-menu) actions, e.g. reloading the app, opening the debugger frontend. | ||
|
||
### HTTP endpoints | ||
|
||
<small>`DevMiddlewareAPI.middleware`</small> | ||
|
||
These are exposed as a [`connect`](https://www.npmjs.com/package/connect) middleware handler, assignable to `Metro.runServer` or other compatible HTTP servers. | ||
|
||
#### GET `/json/list`, `/json` ([CDP](https://chromedevtools.github.io/devtools-protocol/#endpoints)) | ||
|
||
Returns the list of available WebSocket targets for all connected React Native app sessions. | ||
|
||
#### GET `/json/version` ([CDP](https://chromedevtools.github.io/devtools-protocol/#endpoints)) | ||
|
||
Returns version metadata used by Chrome DevTools. | ||
|
||
#### POST `/open-debugger` | ||
|
||
Open the JavaScript debugger for a given CDP target (direct Hermes debugging). | ||
|
||
<details> | ||
<summary>Example</summary> | ||
|
||
curl -X POST 'http://localhost:8081/open-debugger?appId=com.meta.RNTester' | ||
</details> | ||
|
||
### WebSocket endpoints | ||
|
||
<small>`DevMiddlewareAPI.websocketEndpoints`</small> | ||
|
||
#### `/inspector/device` | ||
|
||
WebSocket handler for registering device connections. | ||
|
||
#### `/inspector/debug` | ||
|
||
WebSocket handler that proxies CDP messages to/from the corresponding device. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.