@react-native/dev-middleware 0.73.0 → 0.73.3
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.
- package/README.md +77 -3
- package/dist/createDevMiddleware.d.ts +53 -0
- package/dist/createDevMiddleware.js +53 -6
- package/dist/createDevMiddleware.js.flow +44 -15
- package/dist/index.d.ts +12 -0
- package/dist/index.flow.d.ts +14 -0
- package/dist/index.flow.js.flow +5 -2
- package/dist/index.js +14 -1
- package/dist/index.js.flow +1 -9
- package/dist/inspector-proxy/Device.d.ts +90 -0
- package/dist/inspector-proxy/Device.js +708 -0
- package/dist/inspector-proxy/Device.js.flow +97 -0
- package/dist/inspector-proxy/DeviceEventReporter.d.ts +53 -0
- package/dist/inspector-proxy/DeviceEventReporter.js +162 -0
- package/dist/inspector-proxy/DeviceEventReporter.js.flow +65 -0
- package/dist/inspector-proxy/InspectorProxy.d.ts +61 -0
- package/dist/inspector-proxy/InspectorProxy.js +212 -0
- package/dist/inspector-proxy/InspectorProxy.js.flow +65 -0
- package/dist/inspector-proxy/types.d.ts +78 -0
- package/dist/inspector-proxy/types.js +1 -0
- package/dist/inspector-proxy/types.js.flow +135 -0
- package/dist/middleware/openDebuggerMiddleware.d.ts +37 -0
- package/dist/middleware/openDebuggerMiddleware.js +78 -24
- package/dist/middleware/openDebuggerMiddleware.js.flow +15 -64
- package/dist/types/BrowserLauncher.d.ts +27 -0
- package/dist/types/BrowserLauncher.js +1 -0
- package/dist/types/BrowserLauncher.js.flow +31 -0
- package/dist/types/EventReporter.d.ts +69 -0
- package/dist/types/EventReporter.js +1 -0
- package/dist/types/EventReporter.js.flow +81 -0
- package/dist/types/Experiments.d.ts +25 -0
- package/dist/types/Experiments.js +1 -0
- package/dist/types/Experiments.js.flow +27 -0
- package/dist/types/Logger.d.ts +16 -0
- package/dist/utils/DefaultBrowserLauncher.d.ts +18 -0
- package/dist/utils/DefaultBrowserLauncher.js +77 -0
- package/dist/utils/DefaultBrowserLauncher.js.flow +20 -0
- package/dist/utils/getDevToolsFrontendUrl.d.ts +21 -0
- package/dist/utils/getDevToolsFrontendUrl.js +48 -0
- package/dist/utils/getDevToolsFrontendUrl.js.flow +21 -0
- package/package.json +6 -1
- package/dist/utils/getDevServerUrl.js +0 -37
- package/dist/utils/getDevServerUrl.js.flow +0 -32
- package/dist/utils/launchChromeDevTools.js +0 -44
- package/dist/utils/launchChromeDevTools.js.flow +0 -38
- package/dist/utils/launchDebuggerAppWindow.js +0 -58
- package/dist/utils/launchDebuggerAppWindow.js.flow +0 -56
- package/dist/utils/queryInspectorTargets.js +0 -35
- package/dist/utils/queryInspectorTargets.js.flow +0 -40
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
type SuccessResult<Props: { ... } | void = {}> = {
|
|
12
|
+
status: "success",
|
|
13
|
+
...Props,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type ErrorResult<ErrorT = mixed> = {
|
|
17
|
+
status: "error",
|
|
18
|
+
error: ErrorT,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
type CodedErrorResult<ErrorCode: string> = {
|
|
22
|
+
status: "coded_error",
|
|
23
|
+
errorCode: ErrorCode,
|
|
24
|
+
errorDetails?: string,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
type DebuggerSessionIDs = {
|
|
28
|
+
appId: string,
|
|
29
|
+
deviceName: string,
|
|
30
|
+
deviceId: string,
|
|
31
|
+
pageId: string | null,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type ReportableEvent =
|
|
35
|
+
| {
|
|
36
|
+
type: "launch_debugger_frontend",
|
|
37
|
+
launchType: "launch" | "redirect",
|
|
38
|
+
...
|
|
39
|
+
| SuccessResult<{ appId: string }>
|
|
40
|
+
| ErrorResult<mixed>
|
|
41
|
+
| CodedErrorResult<"NO_APPS_FOUND">,
|
|
42
|
+
}
|
|
43
|
+
| {
|
|
44
|
+
type: "connect_debugger_frontend",
|
|
45
|
+
...
|
|
46
|
+
| SuccessResult<{
|
|
47
|
+
...DebuggerSessionIDs,
|
|
48
|
+
frontendUserAgent: string | null,
|
|
49
|
+
}>
|
|
50
|
+
| ErrorResult<mixed>,
|
|
51
|
+
}
|
|
52
|
+
| {
|
|
53
|
+
type: "debugger_command",
|
|
54
|
+
protocol: "CDP",
|
|
55
|
+
// With some errors, the method might not be known
|
|
56
|
+
method: string | null,
|
|
57
|
+
requestOrigin: "proxy" | "debugger" | null,
|
|
58
|
+
responseOrigin: "proxy" | "device",
|
|
59
|
+
timeSinceStart: number | null,
|
|
60
|
+
...DebuggerSessionIDs,
|
|
61
|
+
frontendUserAgent: string | null,
|
|
62
|
+
...
|
|
63
|
+
| SuccessResult<void>
|
|
64
|
+
| CodedErrorResult<
|
|
65
|
+
| "TIMED_OUT"
|
|
66
|
+
| "DEVICE_DISCONNECTED"
|
|
67
|
+
| "DEBUGGER_DISCONNECTED"
|
|
68
|
+
| "UNMATCHED_REQUEST_ID"
|
|
69
|
+
| "PROTOCOL_ERROR",
|
|
70
|
+
>,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* A simple interface for logging events, to be implemented by integrators of
|
|
75
|
+
* `dev-middleware`.
|
|
76
|
+
*
|
|
77
|
+
* This is an unstable API with no semver guarantees.
|
|
78
|
+
*/
|
|
79
|
+
export interface EventReporter {
|
|
80
|
+
logEvent(event: ReportableEvent): void;
|
|
81
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export type Experiments = Readonly<{
|
|
12
|
+
/**
|
|
13
|
+
* Enables the use of the custom debugger frontend (@react-native/debugger-frontend)
|
|
14
|
+
* in the /open-debugger endpoint.
|
|
15
|
+
*/
|
|
16
|
+
enableCustomDebuggerFrontend: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Enables the handling of GET requests in the /open-debugger endpoint,
|
|
19
|
+
* in addition to POST requests. GET requests respond by redirecting to
|
|
20
|
+
* the debugger frontend, instead of opening it using the BrowserLauncher
|
|
21
|
+
* interface.
|
|
22
|
+
*/
|
|
23
|
+
enableOpenDebuggerRedirect: boolean;
|
|
24
|
+
}>;
|
|
25
|
+
export type ExperimentsConfig = Partial<Experiments>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export type Experiments = $ReadOnly<{
|
|
12
|
+
/**
|
|
13
|
+
* Enables the use of the custom debugger frontend (@react-native/debugger-frontend)
|
|
14
|
+
* in the /open-debugger endpoint.
|
|
15
|
+
*/
|
|
16
|
+
enableCustomDebuggerFrontend: boolean,
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Enables the handling of GET requests in the /open-debugger endpoint,
|
|
20
|
+
* in addition to POST requests. GET requests respond by redirecting to
|
|
21
|
+
* the debugger frontend, instead of opening it using the BrowserLauncher
|
|
22
|
+
* interface.
|
|
23
|
+
*/
|
|
24
|
+
enableOpenDebuggerRedirect: boolean,
|
|
25
|
+
}>;
|
|
26
|
+
|
|
27
|
+
export type ExperimentsConfig = Partial<Experiments>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
* @oncall react_native
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export type Logger = Readonly<{
|
|
13
|
+
error: (...message: Array<string>) => void;
|
|
14
|
+
info: (...message: Array<string>) => void;
|
|
15
|
+
warn: (...message: Array<string>) => void;
|
|
16
|
+
}>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
* @oncall react_native
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { BrowserLauncher } from "../types/BrowserLauncher";
|
|
13
|
+
/**
|
|
14
|
+
* Default `BrowserLauncher` implementation which opens URLs on the host
|
|
15
|
+
* machine.
|
|
16
|
+
*/
|
|
17
|
+
declare const DefaultBrowserLauncher: BrowserLauncher;
|
|
18
|
+
export default DefaultBrowserLauncher;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _fs = require("fs");
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
var _tempDir = _interopRequireDefault(require("temp-dir"));
|
|
10
|
+
function _interopRequireDefault(obj) {
|
|
11
|
+
return obj && obj.__esModule ? obj : { default: obj };
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
15
|
+
*
|
|
16
|
+
* This source code is licensed under the MIT license found in the
|
|
17
|
+
* LICENSE file in the root directory of this source tree.
|
|
18
|
+
*
|
|
19
|
+
*
|
|
20
|
+
* @format
|
|
21
|
+
* @oncall react_native
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const ChromeLauncher = require("chrome-launcher");
|
|
25
|
+
const { Launcher: EdgeLauncher } = require("chromium-edge-launcher");
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Default `BrowserLauncher` implementation which opens URLs on the host
|
|
29
|
+
* machine.
|
|
30
|
+
*/
|
|
31
|
+
const DefaultBrowserLauncher = {
|
|
32
|
+
/**
|
|
33
|
+
* Attempt to open the debugger frontend in a Google Chrome or Microsoft Edge
|
|
34
|
+
* app window.
|
|
35
|
+
*/
|
|
36
|
+
launchDebuggerAppWindow: async (url) => {
|
|
37
|
+
let browserType = "chrome";
|
|
38
|
+
let chromePath;
|
|
39
|
+
try {
|
|
40
|
+
// Locate Chrome installation path, will throw if not found
|
|
41
|
+
chromePath = ChromeLauncher.getChromePath();
|
|
42
|
+
} catch (e) {
|
|
43
|
+
browserType = "edge";
|
|
44
|
+
chromePath = EdgeLauncher.getFirstInstallation();
|
|
45
|
+
if (chromePath == null) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
"Unable to find a browser on the host to open the debugger. " +
|
|
48
|
+
"Supported browsers: Google Chrome, Microsoft Edge.\n" +
|
|
49
|
+
url
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const userDataDir = await createTempDir(
|
|
54
|
+
`react-native-debugger-frontend-${browserType}`
|
|
55
|
+
);
|
|
56
|
+
const launchedChrome = await ChromeLauncher.launch({
|
|
57
|
+
chromePath,
|
|
58
|
+
chromeFlags: [
|
|
59
|
+
`--app=${url}`,
|
|
60
|
+
`--user-data-dir=${userDataDir}`,
|
|
61
|
+
"--window-size=1200,600",
|
|
62
|
+
],
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
kill: async () => launchedChrome.kill(),
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
async function createTempDir(dirName) {
|
|
70
|
+
const tempDir = _path.default.join(_tempDir.default, dirName);
|
|
71
|
+
await _fs.promises.mkdir(tempDir, {
|
|
72
|
+
recursive: true,
|
|
73
|
+
});
|
|
74
|
+
return tempDir;
|
|
75
|
+
}
|
|
76
|
+
var _default = DefaultBrowserLauncher;
|
|
77
|
+
exports.default = _default;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
* @format
|
|
9
|
+
* @oncall react_native
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { BrowserLauncher } from "../types/BrowserLauncher";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Default `BrowserLauncher` implementation which opens URLs on the host
|
|
16
|
+
* machine.
|
|
17
|
+
*/
|
|
18
|
+
declare const DefaultBrowserLauncher: BrowserLauncher;
|
|
19
|
+
|
|
20
|
+
declare export default DefaultBrowserLauncher;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
* @oncall react_native
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { Experiments } from "../types/Experiments";
|
|
13
|
+
/**
|
|
14
|
+
* Construct the URL to Chrome DevTools connected to a given debugger target.
|
|
15
|
+
*/
|
|
16
|
+
declare function getDevToolsFrontendUrl(
|
|
17
|
+
webSocketDebuggerUrl: string,
|
|
18
|
+
devServerUrl: string,
|
|
19
|
+
experiments: Experiments
|
|
20
|
+
): string;
|
|
21
|
+
export default getDevToolsFrontendUrl;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.default = getDevToolsFrontendUrl;
|
|
7
|
+
/**
|
|
8
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
9
|
+
*
|
|
10
|
+
* This source code is licensed under the MIT license found in the
|
|
11
|
+
* LICENSE file in the root directory of this source tree.
|
|
12
|
+
*
|
|
13
|
+
*
|
|
14
|
+
* @format
|
|
15
|
+
* @oncall react_native
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The Chrome DevTools frontend revision to use. This should be set to the
|
|
20
|
+
* latest version known to be compatible with Hermes.
|
|
21
|
+
*
|
|
22
|
+
* Revision should be the full identifier from:
|
|
23
|
+
* https://chromium.googlesource.com/chromium/src.git
|
|
24
|
+
*/
|
|
25
|
+
const DEVTOOLS_FRONTEND_REV = "d9568d04d7dd79269c5a655d7ada69650c5a8336"; // Chrome 100.0.4896.75
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Construct the URL to Chrome DevTools connected to a given debugger target.
|
|
29
|
+
*/
|
|
30
|
+
function getDevToolsFrontendUrl(
|
|
31
|
+
webSocketDebuggerUrl,
|
|
32
|
+
devServerUrl,
|
|
33
|
+
experiments
|
|
34
|
+
) {
|
|
35
|
+
const scheme = new URL(webSocketDebuggerUrl).protocol.slice(0, -1);
|
|
36
|
+
const webSocketUrlWithoutProtocol = webSocketDebuggerUrl.replace(
|
|
37
|
+
/^wss?:\/\//,
|
|
38
|
+
""
|
|
39
|
+
);
|
|
40
|
+
if (experiments.enableCustomDebuggerFrontend) {
|
|
41
|
+
return `${`${devServerUrl}/debugger-frontend/rn_inspector.html`}?${scheme}=${encodeURIComponent(
|
|
42
|
+
webSocketUrlWithoutProtocol
|
|
43
|
+
)}&sources.hide_add_folder=true`;
|
|
44
|
+
}
|
|
45
|
+
return `${`https://chrome-devtools-frontend.appspot.com/serve_rev/@${DEVTOOLS_FRONTEND_REV}/devtools_app.html`}?panel=console&${scheme}=${encodeURIComponent(
|
|
46
|
+
webSocketUrlWithoutProtocol
|
|
47
|
+
)}`;
|
|
48
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
* @oncall react_native
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { Experiments } from "../types/Experiments";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Construct the URL to Chrome DevTools connected to a given debugger target.
|
|
16
|
+
*/
|
|
17
|
+
declare export default function getDevToolsFrontendUrl(
|
|
18
|
+
webSocketDebuggerUrl: string,
|
|
19
|
+
devServerUrl: string,
|
|
20
|
+
experiments: Experiments
|
|
21
|
+
): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native/dev-middleware",
|
|
3
|
-
"version": "0.73.
|
|
3
|
+
"version": "0.73.3",
|
|
4
4
|
"description": "Dev server middleware for React Native",
|
|
5
5
|
"keywords": ["react-native", "tools"],
|
|
6
6
|
"homepage": "https://github.com/facebook/react-native/tree/HEAD/packages/dev-middleware#readme",
|
|
@@ -14,9 +14,14 @@
|
|
|
14
14
|
"exports": { ".": "./dist/index.js", "./package.json": "./package.json" },
|
|
15
15
|
"files": ["dist"],
|
|
16
16
|
"dependencies": {
|
|
17
|
+
"@isaacs/ttlcache": "^1.4.1",
|
|
18
|
+
"@react-native/debugger-frontend": "^0.73.2",
|
|
17
19
|
"chrome-launcher": "^0.15.2",
|
|
20
|
+
"chromium-edge-launcher": "^1.0.0",
|
|
18
21
|
"connect": "^3.6.5",
|
|
22
|
+
"debug": "^2.2.0",
|
|
19
23
|
"node-fetch": "^2.2.0",
|
|
24
|
+
"serve-static": "^1.13.1",
|
|
20
25
|
"temp-dir": "^2.0.0"
|
|
21
26
|
},
|
|
22
27
|
"engines": { "node": ">=18" }
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true,
|
|
5
|
-
});
|
|
6
|
-
exports.default = getDevServerUrl;
|
|
7
|
-
var _net = _interopRequireDefault(require("net"));
|
|
8
|
-
var _tls = require("tls");
|
|
9
|
-
function _interopRequireDefault(obj) {
|
|
10
|
-
return obj && obj.__esModule ? obj : { default: obj };
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
|
-
*
|
|
15
|
-
* This source code is licensed under the MIT license found in the
|
|
16
|
-
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* @format
|
|
20
|
-
* @oncall react_native
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Get the base URL to address the current development server.
|
|
25
|
-
*/
|
|
26
|
-
function getDevServerUrl(req) {
|
|
27
|
-
const scheme =
|
|
28
|
-
req.socket instanceof _tls.TLSSocket && req.socket.encrypted === true
|
|
29
|
-
? "https"
|
|
30
|
-
: "http";
|
|
31
|
-
const { localAddress, localPort } = req.socket;
|
|
32
|
-
const address =
|
|
33
|
-
localAddress && _net.default.isIPv6(localAddress)
|
|
34
|
-
? `[${localAddress}]`
|
|
35
|
-
: localAddress;
|
|
36
|
-
return `${scheme}:${address}:${localPort}`;
|
|
37
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
* @flow strict
|
|
8
|
-
* @format
|
|
9
|
-
* @oncall react_native
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import type {IncomingMessage} from 'http';
|
|
13
|
-
|
|
14
|
-
import net from 'net';
|
|
15
|
-
import {TLSSocket} from 'tls';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Get the base URL to address the current development server.
|
|
19
|
-
*/
|
|
20
|
-
export default function getDevServerUrl(req: IncomingMessage): string {
|
|
21
|
-
const scheme =
|
|
22
|
-
req.socket instanceof TLSSocket && req.socket.encrypted === true
|
|
23
|
-
? 'https'
|
|
24
|
-
: 'http';
|
|
25
|
-
const {localAddress, localPort} = req.socket;
|
|
26
|
-
const address =
|
|
27
|
-
localAddress && net.isIPv6(localAddress)
|
|
28
|
-
? `[${localAddress}]`
|
|
29
|
-
: localAddress;
|
|
30
|
-
|
|
31
|
-
return `${scheme}:${address}:${localPort}`;
|
|
32
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true,
|
|
5
|
-
});
|
|
6
|
-
exports.default = launchChromeDevTools;
|
|
7
|
-
var _launchDebuggerAppWindow = _interopRequireDefault(
|
|
8
|
-
require("./launchDebuggerAppWindow")
|
|
9
|
-
);
|
|
10
|
-
function _interopRequireDefault(obj) {
|
|
11
|
-
return obj && obj.__esModule ? obj : { default: obj };
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
15
|
-
*
|
|
16
|
-
* This source code is licensed under the MIT license found in the
|
|
17
|
-
* LICENSE file in the root directory of this source tree.
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* @format
|
|
21
|
-
* @oncall react_native
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* The Chrome DevTools frontend revision to use. This should be set to the
|
|
26
|
-
* latest version known to be compatible with Hermes.
|
|
27
|
-
*
|
|
28
|
-
* Revision should be the full identifier from:
|
|
29
|
-
* https://chromium.googlesource.com/chromium/src.git
|
|
30
|
-
*/
|
|
31
|
-
const DEVTOOLS_FRONTEND_REV = "d9568d04d7dd79269c5a655d7ada69650c5a8336"; // Chrome 100.0.4896.75
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Attempt to launch Chrome DevTools on the host machine for a given CDP target.
|
|
35
|
-
*/
|
|
36
|
-
async function launchChromeDevTools(webSocketDebuggerUrl) {
|
|
37
|
-
const ws = webSocketDebuggerUrl.replace(/^ws:\/\//, "");
|
|
38
|
-
return (0, _launchDebuggerAppWindow.default)(
|
|
39
|
-
`${`https://chrome-devtools-frontend.appspot.com/serve_rev/@${DEVTOOLS_FRONTEND_REV}/devtools_app.html`}?panel=console&ws=${encodeURIComponent(
|
|
40
|
-
ws
|
|
41
|
-
)}`,
|
|
42
|
-
"open-debugger"
|
|
43
|
-
);
|
|
44
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
* @flow strict
|
|
8
|
-
* @format
|
|
9
|
-
* @oncall react_native
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import type {LaunchedChrome} from 'chrome-launcher';
|
|
13
|
-
|
|
14
|
-
import launchDebuggerAppWindow from './launchDebuggerAppWindow';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* The Chrome DevTools frontend revision to use. This should be set to the
|
|
18
|
-
* latest version known to be compatible with Hermes.
|
|
19
|
-
*
|
|
20
|
-
* Revision should be the full identifier from:
|
|
21
|
-
* https://chromium.googlesource.com/chromium/src.git
|
|
22
|
-
*/
|
|
23
|
-
const DEVTOOLS_FRONTEND_REV = 'd9568d04d7dd79269c5a655d7ada69650c5a8336'; // Chrome 100.0.4896.75
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Attempt to launch Chrome DevTools on the host machine for a given CDP target.
|
|
27
|
-
*/
|
|
28
|
-
export default async function launchChromeDevTools(
|
|
29
|
-
webSocketDebuggerUrl: string,
|
|
30
|
-
): Promise<LaunchedChrome> {
|
|
31
|
-
const urlBase = `https://chrome-devtools-frontend.appspot.com/serve_rev/@${DEVTOOLS_FRONTEND_REV}/devtools_app.html`;
|
|
32
|
-
const ws = webSocketDebuggerUrl.replace(/^ws:\/\//, '');
|
|
33
|
-
|
|
34
|
-
return launchDebuggerAppWindow(
|
|
35
|
-
`${urlBase}?panel=console&ws=${encodeURIComponent(ws)}`,
|
|
36
|
-
'open-debugger',
|
|
37
|
-
);
|
|
38
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true,
|
|
5
|
-
});
|
|
6
|
-
exports.default = launchDebuggerAppWindow;
|
|
7
|
-
var _fs = require("fs");
|
|
8
|
-
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
var _tempDir = _interopRequireDefault(require("temp-dir"));
|
|
10
|
-
function _interopRequireDefault(obj) {
|
|
11
|
-
return obj && obj.__esModule ? obj : { default: obj };
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
15
|
-
*
|
|
16
|
-
* This source code is licensed under the MIT license found in the
|
|
17
|
-
* LICENSE file in the root directory of this source tree.
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* @format
|
|
21
|
-
* @oncall react_native
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
const ChromeLauncher = require("chrome-launcher");
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Attempt to open a debugger frontend URL as a Google Chrome app window.
|
|
28
|
-
*/
|
|
29
|
-
async function launchDebuggerAppWindow(
|
|
30
|
-
url,
|
|
31
|
-
/**
|
|
32
|
-
* Used to construct the temp browser dir to preserve settings such as window
|
|
33
|
-
* position.
|
|
34
|
-
*/
|
|
35
|
-
intent
|
|
36
|
-
) {
|
|
37
|
-
const userDataDir = await createTempDir(`react-native-${intent}-${"chrome"}`);
|
|
38
|
-
try {
|
|
39
|
-
return ChromeLauncher.launch({
|
|
40
|
-
chromeFlags: [
|
|
41
|
-
`--app=${url}`,
|
|
42
|
-
`--user-data-dir=${userDataDir}`,
|
|
43
|
-
"--window-size=1200,600",
|
|
44
|
-
],
|
|
45
|
-
});
|
|
46
|
-
} catch (e) {
|
|
47
|
-
throw new Error(
|
|
48
|
-
"Unable to find a browser on the host to open the debugger. Supported browsers: Google Chrome"
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
async function createTempDir(dirName) {
|
|
53
|
-
const tempDir = _path.default.join(_tempDir.default, dirName);
|
|
54
|
-
await _fs.promises.mkdir(tempDir, {
|
|
55
|
-
recursive: true,
|
|
56
|
-
});
|
|
57
|
-
return tempDir;
|
|
58
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
* @flow strict
|
|
8
|
-
* @format
|
|
9
|
-
* @oncall react_native
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import type {LaunchedChrome} from 'chrome-launcher';
|
|
13
|
-
import {promises as fs} from 'fs';
|
|
14
|
-
import path from 'path';
|
|
15
|
-
import osTempDir from 'temp-dir';
|
|
16
|
-
|
|
17
|
-
const ChromeLauncher = require('chrome-launcher');
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Attempt to open a debugger frontend URL as a Google Chrome app window.
|
|
21
|
-
*/
|
|
22
|
-
export default async function launchDebuggerAppWindow(
|
|
23
|
-
url: string,
|
|
24
|
-
/**
|
|
25
|
-
* Used to construct the temp browser dir to preserve settings such as window
|
|
26
|
-
* position.
|
|
27
|
-
*/
|
|
28
|
-
intent: 'open-debugger',
|
|
29
|
-
): Promise<LaunchedChrome> {
|
|
30
|
-
const browserType = 'chrome';
|
|
31
|
-
const userDataDir = await createTempDir(
|
|
32
|
-
`react-native-${intent}-${browserType}`,
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
return ChromeLauncher.launch({
|
|
37
|
-
chromeFlags: [
|
|
38
|
-
`--app=${url}`,
|
|
39
|
-
`--user-data-dir=${userDataDir}`,
|
|
40
|
-
'--window-size=1200,600',
|
|
41
|
-
],
|
|
42
|
-
});
|
|
43
|
-
} catch (e) {
|
|
44
|
-
throw new Error(
|
|
45
|
-
'Unable to find a browser on the host to open the debugger. Supported browsers: Google Chrome',
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
async function createTempDir(dirName: string): Promise<string> {
|
|
51
|
-
const tempDir = path.join(osTempDir, dirName);
|
|
52
|
-
|
|
53
|
-
await fs.mkdir(tempDir, {recursive: true});
|
|
54
|
-
|
|
55
|
-
return tempDir;
|
|
56
|
-
}
|