Skip to content

Commit 9733b6f

Browse files
authored
Update remote debugging page title (#2083)
1 parent 18ee170 commit 9733b6f

File tree

5 files changed

+100
-1
lines changed

5 files changed

+100
-1
lines changed

packages/cli-debugger-ui/src/ui/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<head>
1010
<meta charset="utf-8" />
1111
<link rel="icon" href="data:;base64,iVBORw0KGgo=" />
12-
<title>React Native Debugger</title>
12+
<title>React Native Remote Debugging (Deprecated)</title>
1313
<script src="./index.js"></script>
1414
</head>
1515
<body>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its 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+
import http from 'http';
8+
import {launchDebugger, logger} from '@react-native-community/cli-tools';
9+
import {exec} from 'child_process';
10+
11+
function launchDefaultDebugger(
12+
host: string | undefined,
13+
port: number,
14+
args = '',
15+
) {
16+
const hostname = host || 'localhost';
17+
const debuggerURL = `http://${hostname}:${port}/debugger-ui${args}`;
18+
logger.info('Launching Dev Tools...');
19+
launchDebugger(debuggerURL);
20+
}
21+
22+
function escapePath(pathname: string) {
23+
// " Can escape paths with spaces in OS X, Windows, and *nix
24+
return `"${pathname}"`;
25+
}
26+
27+
type LaunchDevToolsOptions = {
28+
host?: string;
29+
port: number;
30+
watchFolders: ReadonlyArray<string>;
31+
};
32+
33+
function launchDevTools(
34+
{host, port, watchFolders}: LaunchDevToolsOptions,
35+
isDebuggerConnected: () => boolean,
36+
) {
37+
// Explicit config always wins
38+
const customDebugger = process.env.REACT_DEBUGGER;
39+
if (customDebugger) {
40+
startCustomDebugger({watchFolders, customDebugger});
41+
} else if (!isDebuggerConnected()) {
42+
// Debugger is not yet open; we need to open a session
43+
launchDefaultDebugger(host, port);
44+
}
45+
}
46+
47+
function startCustomDebugger({
48+
watchFolders,
49+
customDebugger,
50+
}: {
51+
watchFolders: ReadonlyArray<string>;
52+
customDebugger: string;
53+
}) {
54+
const folders = watchFolders.map(escapePath).join(' ');
55+
const command = `${customDebugger} ${folders}`;
56+
logger.info('Starting custom debugger by executing:', command);
57+
exec(command, function (error) {
58+
if (error !== null) {
59+
logger.error('Error while starting custom debugger:', error.stack || '');
60+
}
61+
});
62+
}
63+
64+
export default function getDevToolsMiddleware(
65+
options: LaunchDevToolsOptions,
66+
isDebuggerConnected: () => boolean,
67+
) {
68+
return function devToolsMiddleware(
69+
_req: http.IncomingMessage,
70+
res: http.ServerResponse,
71+
) {
72+
launchDevTools(options, isDebuggerConnected);
73+
res.end('OK');
74+
};
75+
}

packages/cli-server-api/src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import nocache from 'nocache';
77
import serveStatic from 'serve-static';
88
import {debuggerUIMiddleware} from '@react-native-community/cli-debugger-ui';
99

10+
import devToolsMiddleware from './devToolsMiddleware';
1011
import indexPageMiddleware from './indexPageMiddleware';
1112
import openStackFrameInEditorMiddleware from './openStackFrameInEditorMiddleware';
1213
import openURLMiddleware from './openURLMiddleware';
@@ -19,6 +20,7 @@ import createDebuggerProxyEndpoint from './websocket/createDebuggerProxyEndpoint
1920
import createMessageSocketEndpoint from './websocket/createMessageSocketEndpoint';
2021
import createEventsSocketEndpoint from './websocket/createEventsSocketEndpoint';
2122

23+
export {devToolsMiddleware};
2224
export {indexPageMiddleware};
2325
export {openStackFrameInEditorMiddleware};
2426
export {openURLMiddleware};
@@ -35,6 +37,7 @@ type MiddlewareOptions = {
3537

3638
export function createDevServerMiddleware(options: MiddlewareOptions) {
3739
const debuggerProxyEndpoint = createDebuggerProxyEndpoint();
40+
const isDebuggerConnected = debuggerProxyEndpoint.isDebuggerConnected;
3841

3942
const messageSocketEndpoint = createMessageSocketEndpoint();
4043
const broadcast = messageSocketEndpoint.broadcast;
@@ -47,6 +50,10 @@ export function createDevServerMiddleware(options: MiddlewareOptions) {
4750
.use(compression())
4851
.use(nocache())
4952
.use('/debugger-ui', debuggerUIMiddleware())
53+
.use(
54+
'/launch-js-devtools',
55+
devToolsMiddleware(options, isDebuggerConnected),
56+
)
5057
.use('/open-stack-frame', openStackFrameInEditorMiddleware(options))
5158
.use('/open-url', openURLMiddleware)
5259
.use('/status', statusPageMiddleware)

packages/cli-tools/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export {default as isPackagerRunning} from './isPackagerRunning';
33
export {default as getDefaultUserTerminal} from './getDefaultUserTerminal';
44
export {fetch, fetchToTemp} from './fetch';
55
export {default as launchDefaultBrowser} from './launchDefaultBrowser';
6+
export {default as launchDebugger} from './launchDebugger';
67
export {default as launchEditor} from './launchEditor';
78
export * as version from './releaseChecker';
89
export {default as resolveNodeModuleDir} from './resolveNodeModuleDir';
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its 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+
* @format
8+
*/
9+
10+
import launchDefaultBrowser from './launchDefaultBrowser';
11+
12+
async function launchDebugger(url: string) {
13+
return launchDefaultBrowser(url);
14+
}
15+
16+
export default launchDebugger;

0 commit comments

Comments
 (0)