@react-native/dev-middleware 0.74.0-nightly-20231105-d077239ff → 0.74.0-nightly-20231107-bc68794c6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,11 +9,11 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- import type { NextHandleFunction } from "connect";
13
12
  import type { BrowserLauncher } from "./types/BrowserLauncher";
14
13
  import type { EventReporter } from "./types/EventReporter";
15
14
  import type { ExperimentsConfig } from "./types/Experiments";
16
15
  import type { Logger } from "./types/Logger";
16
+ import type { NextHandleFunction } from "connect";
17
17
  type Options = Readonly<{
18
18
  projectRoot: string;
19
19
  /**
@@ -4,24 +4,24 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true,
5
5
  });
6
6
  exports.default = createDevMiddleware;
7
- var _debuggerFrontend = _interopRequireDefault(
8
- require("@react-native/debugger-frontend")
7
+ var _InspectorProxy = _interopRequireDefault(
8
+ require("./inspector-proxy/InspectorProxy")
9
9
  );
10
- var _connect = _interopRequireDefault(require("connect"));
11
- var _path = _interopRequireDefault(require("path"));
12
- var _serveStatic = _interopRequireDefault(require("serve-static"));
13
10
  var _deprecated_openFlipperMiddleware = _interopRequireDefault(
14
11
  require("./middleware/deprecated_openFlipperMiddleware")
15
12
  );
16
13
  var _openDebuggerMiddleware = _interopRequireDefault(
17
14
  require("./middleware/openDebuggerMiddleware")
18
15
  );
19
- var _InspectorProxy = _interopRequireDefault(
20
- require("./inspector-proxy/InspectorProxy")
21
- );
22
16
  var _DefaultBrowserLauncher = _interopRequireDefault(
23
17
  require("./utils/DefaultBrowserLauncher")
24
18
  );
19
+ var _debuggerFrontend = _interopRequireDefault(
20
+ require("@react-native/debugger-frontend")
21
+ );
22
+ var _connect = _interopRequireDefault(require("connect"));
23
+ var _path = _interopRequireDefault(require("path"));
24
+ var _serveStatic = _interopRequireDefault(require("serve-static"));
25
25
  function _interopRequireDefault(obj) {
26
26
  return obj && obj.__esModule ? obj : { default: obj };
27
27
  }
@@ -9,11 +9,11 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- import type { NextHandleFunction } from "connect";
13
12
  import type { BrowserLauncher } from "./types/BrowserLauncher";
14
13
  import type { EventReporter } from "./types/EventReporter";
15
14
  import type { ExperimentsConfig } from "./types/Experiments";
16
15
  import type { Logger } from "./types/Logger";
16
+ import type { NextHandleFunction } from "connect";
17
17
 
18
18
  type Options = $ReadOnly<{
19
19
  projectRoot: string,
@@ -36,7 +36,7 @@ declare class Device {
36
36
  _name: string;
37
37
  _app: string;
38
38
  _deviceSocket: WS;
39
- _pages: Array<Page>;
39
+ _pages: ReadonlyArray<Page>;
40
40
  _debuggerConnection: null | undefined | DebuggerInfo;
41
41
  _lastConnectedReactNativePage: null | undefined | Page;
42
42
  _isReloading: boolean;
@@ -54,7 +54,7 @@ declare class Device {
54
54
  );
55
55
  getName(): string;
56
56
  getApp(): string;
57
- getPagesList(): Array<Page>;
57
+ getPagesList(): ReadonlyArray<Page>;
58
58
  handleDebuggerConnection(
59
59
  socket: WS,
60
60
  pageId: string,
@@ -73,11 +73,11 @@ declare class Device {
73
73
  req: DebuggerRequest,
74
74
  debuggerInfo: DebuggerInfo,
75
75
  socket: WS
76
- ): boolean;
76
+ ): null | undefined | DebuggerRequest;
77
77
  _processDebuggerSetBreakpointByUrl(
78
78
  req: SetBreakpointByUrlRequest,
79
79
  debuggerInfo: DebuggerInfo
80
- ): void;
80
+ ): SetBreakpointByUrlRequest;
81
81
  _processDebuggerGetScriptSource(
82
82
  req: GetScriptSourceRequest,
83
83
  socket: WS
@@ -212,17 +212,17 @@ class Device {
212
212
  pageId: this._debuggerConnection?.pageId ?? null,
213
213
  frontendUserAgent: metadata.userAgent,
214
214
  });
215
- const handled = this._interceptMessageFromDebugger(
215
+ const processedReq = this._interceptMessageFromDebugger(
216
216
  debuggerRequest,
217
217
  debuggerInfo,
218
218
  socket
219
219
  );
220
- if (!handled) {
220
+ if (processedReq) {
221
221
  this._sendMessageToDevice({
222
222
  event: "wrappedEvent",
223
223
  payload: {
224
224
  pageId: this._mapToDevicePageId(pageId),
225
- wrappedEvent: JSON.stringify(debuggerRequest),
225
+ wrappedEvent: JSON.stringify(processedReq),
226
226
  },
227
227
  });
228
228
  }
@@ -546,39 +546,49 @@ class Device {
546
546
  // to be forwarded to the target).
547
547
  _interceptMessageFromDebugger(req, debuggerInfo, socket) {
548
548
  if (req.method === "Debugger.setBreakpointByUrl") {
549
- this._processDebuggerSetBreakpointByUrl(req, debuggerInfo);
549
+ return this._processDebuggerSetBreakpointByUrl(req, debuggerInfo);
550
550
  } else if (req.method === "Debugger.getScriptSource") {
551
551
  this._processDebuggerGetScriptSource(req, socket);
552
- return true;
552
+ return null;
553
553
  }
554
- return false;
554
+ return req;
555
555
  }
556
556
  _processDebuggerSetBreakpointByUrl(req, debuggerInfo) {
557
557
  // If we replaced Android emulator's address to localhost we need to change it back.
558
558
  if (debuggerInfo.originalSourceURLAddress != null) {
559
- if (req.params.url != null) {
560
- req.params.url = req.params.url.replace(
559
+ const processedReq = {
560
+ ...req,
561
+ params: {
562
+ ...req.params,
563
+ },
564
+ };
565
+ if (processedReq.params.url != null) {
566
+ processedReq.params.url = processedReq.params.url.replace(
561
567
  "localhost",
562
568
  debuggerInfo.originalSourceURLAddress
563
569
  );
564
570
  if (
565
- req.params.url &&
566
- req.params.url.startsWith(FILE_PREFIX) &&
571
+ processedReq.params.url &&
572
+ processedReq.params.url.startsWith(FILE_PREFIX) &&
567
573
  debuggerInfo.prependedFilePrefix
568
574
  ) {
569
575
  // Remove fake URL prefix if we modified URL in _processMessageFromDevice.
570
576
  // $FlowFixMe[incompatible-use]
571
- req.params.url = req.params.url.slice(FILE_PREFIX.length);
577
+ processedReq.params.url = processedReq.params.url.slice(
578
+ FILE_PREFIX.length
579
+ );
572
580
  }
573
581
  }
574
- if (req.params.urlRegex != null) {
575
- req.params.urlRegex = req.params.urlRegex.replace(
582
+ if (processedReq.params.urlRegex != null) {
583
+ processedReq.params.urlRegex = processedReq.params.urlRegex.replace(
576
584
  /localhost/g,
577
585
  // $FlowFixMe[incompatible-call]
578
586
  debuggerInfo.originalSourceURLAddress
579
587
  );
580
588
  }
589
+ return processedReq;
581
590
  }
591
+ return req;
582
592
  }
583
593
  _processDebuggerGetScriptSource(req, socket) {
584
594
  const sendSuccessResponse = (scriptSource) => {
@@ -42,7 +42,7 @@ declare export default class Device {
42
42
  _name: string;
43
43
  _app: string;
44
44
  _deviceSocket: WS;
45
- _pages: Array<Page>;
45
+ _pages: $ReadOnlyArray<Page>;
46
46
  _debuggerConnection: ?DebuggerInfo;
47
47
  _lastConnectedReactNativePage: ?Page;
48
48
  _isReloading: boolean;
@@ -60,7 +60,7 @@ declare export default class Device {
60
60
  ): void;
61
61
  getName(): string;
62
62
  getApp(): string;
63
- getPagesList(): Array<Page>;
63
+ getPagesList(): $ReadOnlyArray<Page>;
64
64
  handleDebuggerConnection(
65
65
  socket: WS,
66
66
  pageId: string,
@@ -81,11 +81,11 @@ declare export default class Device {
81
81
  req: DebuggerRequest,
82
82
  debuggerInfo: DebuggerInfo,
83
83
  socket: WS
84
- ): boolean;
84
+ ): ?DebuggerRequest;
85
85
  _processDebuggerSetBreakpointByUrl(
86
86
  req: SetBreakpointByUrlRequest,
87
87
  debuggerInfo: DebuggerInfo
88
- ): void;
88
+ ): SetBreakpointByUrlRequest;
89
89
  _processDebuggerGetScriptSource(
90
90
  req: GetScriptSourceRequest,
91
91
  socket: WS
@@ -9,6 +9,7 @@
9
9
  */
10
10
 
11
11
  import type { EventReporter } from "../types/EventReporter";
12
+
12
13
  import TTLCache from "@isaacs/ttlcache";
13
14
 
14
15
  type PendingCommand = {
@@ -9,17 +9,17 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
+ import type { EventReporter } from "../types/EventReporter";
13
+ import type { Experiments } from "../types/Experiments";
12
14
  import type {
13
15
  JsonPagesListResponse,
14
16
  JsonVersionResponse,
15
17
  Page,
16
18
  PageDescription,
17
19
  } from "./types";
18
- import type { EventReporter } from "../types/EventReporter";
19
- import type { Experiments } from "../types/Experiments";
20
20
  import type { IncomingMessage, ServerResponse } from "http";
21
- import WS from "ws";
22
21
  import Device from "./Device";
22
+ import WS from "ws";
23
23
  export interface InspectorProxyQueries {
24
24
  getPageDescriptions(): Array<PageDescription>;
25
25
  }
@@ -4,9 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true,
5
5
  });
6
6
  exports.default = void 0;
7
+ var _Device = _interopRequireDefault(require("./Device"));
7
8
  var _url = _interopRequireDefault(require("url"));
8
9
  var _ws = _interopRequireDefault(require("ws"));
9
- var _Device = _interopRequireDefault(require("./Device"));
10
10
  function _interopRequireDefault(obj) {
11
11
  return obj && obj.__esModule ? obj : { default: obj };
12
12
  }
@@ -9,18 +9,18 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
+ import type { EventReporter } from "../types/EventReporter";
13
+ import type { Experiments } from "../types/Experiments";
12
14
  import type {
13
15
  JsonPagesListResponse,
14
16
  JsonVersionResponse,
15
17
  Page,
16
18
  PageDescription,
17
19
  } from "./types";
18
- import type { EventReporter } from "../types/EventReporter";
19
- import type { Experiments } from "../types/Experiments";
20
20
  import type { IncomingMessage, ServerResponse } from "http";
21
21
 
22
- import WS from "ws";
23
22
  import Device from "./Device";
23
+ import WS from "ws";
24
24
 
25
25
  export interface InspectorProxyQueries {
26
26
  getPageDescriptions(): Array<PageDescription>;
@@ -9,18 +9,29 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- export type Page = { id: string; title: string; vm: string; app: string };
13
- export type WrappedEvent = {
12
+ export type Page = Readonly<{
13
+ id: string;
14
+ title: string;
15
+ vm: string;
16
+ app: string;
17
+ }>;
18
+ export type WrappedEvent = Readonly<{
14
19
  event: "wrappedEvent";
15
- payload: { pageId: string; wrappedEvent: string };
16
- };
17
- export type ConnectRequest = { event: "connect"; payload: { pageId: string } };
18
- export type DisconnectRequest = {
20
+ payload: Readonly<{ pageId: string; wrappedEvent: string }>;
21
+ }>;
22
+ export type ConnectRequest = Readonly<{
23
+ event: "connect";
24
+ payload: Readonly<{ pageId: string }>;
25
+ }>;
26
+ export type DisconnectRequest = Readonly<{
19
27
  event: "disconnect";
20
- payload: { pageId: string };
21
- };
28
+ payload: Readonly<{ pageId: string }>;
29
+ }>;
22
30
  export type GetPagesRequest = { event: "getPages" };
23
- export type GetPagesResponse = { event: "getPages"; payload: Array<Page> };
31
+ export type GetPagesResponse = {
32
+ event: "getPages";
33
+ payload: ReadonlyArray<Page>;
34
+ };
24
35
  export type MessageFromDevice =
25
36
  | GetPagesResponse
26
37
  | WrappedEvent
@@ -30,7 +41,7 @@ export type MessageToDevice =
30
41
  | WrappedEvent
31
42
  | ConnectRequest
32
43
  | DisconnectRequest;
33
- export type PageDescription = {
44
+ export type PageDescription = Readonly<{
34
45
  id: string;
35
46
  description: string;
36
47
  title: string;
@@ -38,42 +49,44 @@ export type PageDescription = {
38
49
  devtoolsFrontendUrl: string;
39
50
  type: string;
40
51
  webSocketDebuggerUrl: string;
41
- reactNative: { logicalDeviceId: string };
42
- };
43
- export type JsonPagesListResponse = Array<PageDescription>;
44
- export type JsonVersionResponse = {
52
+ deviceName: string;
53
+ vm: string;
54
+ reactNative: Readonly<{ logicalDeviceId: string }>;
55
+ }>;
56
+ export type JsonPagesListResponse = ReadonlyArray<PageDescription>;
57
+ export type JsonVersionResponse = Readonly<{
45
58
  Browser: string;
46
59
  "Protocol-Version": string;
47
- };
60
+ }>;
48
61
  /**
49
62
  * Types were exported from https://github.com/ChromeDevTools/devtools-protocol/blob/master/types/protocol.d.ts
50
63
  */
51
64
 
52
- export type SetBreakpointByUrlRequest = {
65
+ export type SetBreakpointByUrlRequest = Readonly<{
53
66
  id: number;
54
67
  method: "Debugger.setBreakpointByUrl";
55
- params: {
68
+ params: Readonly<{
56
69
  lineNumber: number;
57
70
  url?: string;
58
71
  urlRegex?: string;
59
72
  scriptHash?: string;
60
73
  columnNumber?: number;
61
74
  condition?: string;
62
- };
63
- };
64
- export type GetScriptSourceRequest = {
75
+ }>;
76
+ }>;
77
+ export type GetScriptSourceRequest = Readonly<{
65
78
  id: number;
66
79
  method: "Debugger.getScriptSource";
67
80
  params: { scriptId: string };
68
- };
69
- export type GetScriptSourceResponse = {
81
+ }>;
82
+ export type GetScriptSourceResponse = Readonly<{
70
83
  scriptSource: string;
71
84
  /**
72
85
  * Wasm bytecode.
73
86
  */
74
87
  bytecode?: string;
75
- };
76
- export type ErrorResponse = { error: { message: string } };
88
+ }>;
89
+ export type ErrorResponse = Readonly<{ error: Readonly<{ message: string }> }>;
77
90
  export type DebuggerRequest =
78
91
  | SetBreakpointByUrlRequest
79
92
  | GetScriptSourceRequest;
@@ -12,49 +12,43 @@
12
12
  // Page information received from the device. New page is created for
13
13
  // each new instance of VM and can appear when user reloads React Native
14
14
  // application.
15
- export type Page = {
15
+ export type Page = $ReadOnly<{
16
16
  id: string,
17
17
  title: string,
18
18
  vm: string,
19
19
  app: string,
20
- ...
21
- };
20
+ }>;
22
21
 
23
22
  // Chrome Debugger Protocol message/event passed between device and debugger.
24
- export type WrappedEvent = {
23
+ export type WrappedEvent = $ReadOnly<{
25
24
  event: "wrappedEvent",
26
- payload: {
25
+ payload: $ReadOnly<{
27
26
  pageId: string,
28
27
  wrappedEvent: string,
29
- ...
30
- },
31
- ...
32
- };
28
+ }>,
29
+ }>;
33
30
 
34
31
  // Request sent from Inspector Proxy to Device when new debugger is connected
35
32
  // to particular page.
36
- export type ConnectRequest = {
33
+ export type ConnectRequest = $ReadOnly<{
37
34
  event: "connect",
38
- payload: { pageId: string, ... },
39
- ...
40
- };
35
+ payload: $ReadOnly<{ pageId: string }>,
36
+ }>;
41
37
 
42
38
  // Request sent from Inspector Proxy to Device to notify that debugger is
43
39
  // disconnected.
44
- export type DisconnectRequest = {
40
+ export type DisconnectRequest = $ReadOnly<{
45
41
  event: "disconnect",
46
- payload: { pageId: string, ... },
47
- ...
48
- };
42
+ payload: $ReadOnly<{ pageId: string }>,
43
+ }>;
49
44
 
50
45
  // Request sent from Inspector Proxy to Device to get a list of pages.
51
- export type GetPagesRequest = { event: "getPages", ... };
46
+ export type GetPagesRequest = { event: "getPages" };
52
47
 
53
48
  // Response to GetPagesRequest containing a list of page infos.
54
49
  export type GetPagesResponse = {
55
50
  event: "getPages",
56
- payload: Array<Page>,
57
- ...
51
+ payload: $ReadOnlyArray<Page>,
58
52
  };
59
53
 
60
54
  // Union type for all possible messages sent from device to Inspector Proxy.
@@ -71,7 +65,7 @@ export type MessageToDevice =
71
65
  | DisconnectRequest;
72
66
 
73
67
  // Page description object that is sent in response to /json HTTP request from debugger.
74
- export type PageDescription = {
68
+ export type PageDescription = $ReadOnly<{
75
69
  id: string,
76
70
  description: string,
77
71
  title: string,
@@ -79,60 +73,61 @@ export type PageDescription = {
79
73
  devtoolsFrontendUrl: string,
80
74
  type: string,
81
75
  webSocketDebuggerUrl: string,
76
+ deviceName: string,
77
+ vm: string,
82
78
  // Metadata specific to React Native
83
- reactNative: {
79
+ reactNative: $ReadOnly<{
84
80
  logicalDeviceId: string,
85
- },
86
- ...
87
- };
88
- export type JsonPagesListResponse = Array<PageDescription>;
81
+ }>,
82
+ }>;
83
+
84
+ export type JsonPagesListResponse = $ReadOnlyArray<PageDescription>;
89
85
 
90
86
  // Response to /json/version HTTP request from the debugger specifying browser type and
91
87
  // Chrome protocol version.
92
- export type JsonVersionResponse = {
88
+ export type JsonVersionResponse = $ReadOnly<{
93
89
  Browser: string,
94
90
  "Protocol-Version": string,
95
- ...
96
- };
91
+ }>;
97
92
 
98
93
  /**
99
94
  * Types were exported from https://github.com/ChromeDevTools/devtools-protocol/blob/master/types/protocol.d.ts
100
95
  */
101
96
 
102
- export type SetBreakpointByUrlRequest = {
97
+ export type SetBreakpointByUrlRequest = $ReadOnly<{
103
98
  id: number,
104
99
  method: "Debugger.setBreakpointByUrl",
105
- params: {
100
+ params: $ReadOnly<{
106
101
  lineNumber: number,
107
102
  url?: string,
108
103
  urlRegex?: string,
109
104
  scriptHash?: string,
110
105
  columnNumber?: number,
111
106
  condition?: string,
112
- },
113
- };
107
+ }>,
108
+ }>;
114
109
 
115
- export type GetScriptSourceRequest = {
110
+ export type GetScriptSourceRequest = $ReadOnly<{
116
111
  id: number,
117
112
  method: "Debugger.getScriptSource",
118
113
  params: {
119
114
  scriptId: string,
120
115
  },
121
- };
116
+ }>;
122
117
 
123
- export type GetScriptSourceResponse = {
118
+ export type GetScriptSourceResponse = $ReadOnly<{
124
119
  scriptSource: string,
125
120
  /**
126
121
  * Wasm bytecode.
127
122
  */
128
123
  bytecode?: string,
129
- };
124
+ }>;
130
125
 
131
- export type ErrorResponse = {
132
- error: {
126
+ export type ErrorResponse = $ReadOnly<{
127
+ error: $ReadOnly<{
133
128
  message: string,
134
- },
135
- };
129
+ }>,
130
+ }>;
136
131
 
137
132
  export type DebuggerRequest =
138
133
  | SetBreakpointByUrlRequest
@@ -9,8 +9,8 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- import type { NextHandleFunction } from "connect";
13
12
  import type { Logger } from "../types/Logger";
13
+ import type { NextHandleFunction } from "connect";
14
14
  type Options = Readonly<{ logger?: Logger }>;
15
15
  /**
16
16
  * Open the legacy Flipper debugger (Hermes).
@@ -9,9 +9,8 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- import type { NextHandleFunction } from "connect";
13
12
  import type { Logger } from "../types/Logger";
14
-
13
+ import type { NextHandleFunction } from "connect";
15
14
  type Options = $ReadOnly<{
16
15
  logger?: Logger,
17
16
  }>;
@@ -9,12 +9,12 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- import type { NextHandleFunction } from "connect";
13
12
  import type { InspectorProxyQueries } from "../inspector-proxy/InspectorProxy";
14
13
  import type { BrowserLauncher } from "../types/BrowserLauncher";
15
14
  import type { EventReporter } from "../types/EventReporter";
16
15
  import type { Experiments } from "../types/Experiments";
17
16
  import type { Logger } from "../types/Logger";
17
+ import type { NextHandleFunction } from "connect";
18
18
  type Options = Readonly<{
19
19
  serverBaseUrl: string;
20
20
  logger?: Logger;
@@ -4,10 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true,
5
5
  });
6
6
  exports.default = openDebuggerMiddleware;
7
- var _url = _interopRequireDefault(require("url"));
8
7
  var _getDevToolsFrontendUrl = _interopRequireDefault(
9
8
  require("../utils/getDevToolsFrontendUrl")
10
9
  );
10
+ var _url = _interopRequireDefault(require("url"));
11
11
  function _interopRequireDefault(obj) {
12
12
  return obj && obj.__esModule ? obj : { default: obj };
13
13
  }
@@ -9,13 +9,12 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- import type { NextHandleFunction } from "connect";
13
12
  import type { InspectorProxyQueries } from "../inspector-proxy/InspectorProxy";
14
13
  import type { BrowserLauncher } from "../types/BrowserLauncher";
15
14
  import type { EventReporter } from "../types/EventReporter";
16
15
  import type { Experiments } from "../types/Experiments";
17
16
  import type { Logger } from "../types/Logger";
18
-
17
+ import type { NextHandleFunction } from "connect";
19
18
  type Options = $ReadOnly<{
20
19
  serverBaseUrl: string,
21
20
  logger?: Logger,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native/dev-middleware",
3
- "version": "0.74.0-nightly-20231105-d077239ff",
3
+ "version": "0.74.0-nightly-20231107-bc68794c6",
4
4
  "description": "Dev server middleware for React Native",
5
5
  "keywords": [
6
6
  "react-native",
@@ -23,7 +23,7 @@
23
23
  ],
24
24
  "dependencies": {
25
25
  "@isaacs/ttlcache": "^1.4.1",
26
- "@react-native/debugger-frontend": "0.74.0-nightly-20231105-d077239ff",
26
+ "@react-native/debugger-frontend": "0.74.0-nightly-20231107-bc68794c6",
27
27
  "chrome-launcher": "^0.15.2",
28
28
  "chromium-edge-launcher": "^1.0.0",
29
29
  "connect": "^3.6.5",