Skip to content

Commit 321f7db

Browse files
huntiefacebook-github-bot
authored andcommitted
Add 'j' to debug key handler (#39256)
Summary: Pull Request resolved: #39256 ## Context RFC: Decoupling Flipper from React Native core: react-native-community/discussions-and-proposals#641 ## Changes - Adds `j` key handler to open JS debugger (mirroring Expo CLI). - Updates `isDevServerRunning` to consider server scheme and host. - Reorders key prompts. Changelog: [General][Changed] Add 'j' to debug key trigger from CLI Reviewed By: motiz88 Differential Revision: D48873335 fbshipit-source-id: e3f208522c19857c565fa73f8b81d646a7e4ff31
1 parent f688a2d commit 321f7db

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

packages/community-cli-plugin/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"metro": "0.78.0",
3232
"metro-config": "0.78.0",
3333
"metro-core": "0.78.0",
34+
"node-fetch": "^2.2.0",
3435
"readline": "^1.3.0"
3536
},
3637
"devDependencies": {

packages/community-cli-plugin/src/commands/start/attachKeyHandlers.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,25 @@ import {
1717
} from '@react-native-community/cli-tools';
1818
import chalk from 'chalk';
1919
import execa from 'execa';
20+
import fetch from 'node-fetch';
2021
import readline from 'readline';
2122
import {KeyPressHandler} from '../../utils/KeyPressHandler';
2223

2324
const CTRL_C = '\u0003';
2425
const CTRL_Z = '\u0026';
2526

26-
export default function attachKeyHandlers(
27+
export default function attachKeyHandlers({
28+
cliConfig,
29+
devServerUrl,
30+
messageSocket,
31+
}: {
2732
cliConfig: Config,
33+
devServerUrl: string,
2834
messageSocket: $ReadOnly<{
2935
broadcast: (type: string, params?: Record<string, mixed> | null) => void,
3036
...
3137
}>,
32-
) {
38+
}) {
3339
if (process.stdin.isTTY !== true) {
3440
logger.debug('Interactive mode is not supported in this environment');
3541
return;
@@ -77,6 +83,9 @@ export default function attachKeyHandlers(
7783
execaOptions,
7884
).stdout?.pipe(process.stdout);
7985
break;
86+
case 'j':
87+
await fetch(devServerUrl + '/open-debugger', {method: 'POST'});
88+
break;
8089
case CTRL_Z:
8190
process.emit('SIGTSTP', 'SIGTSTP');
8291
break;
@@ -93,10 +102,11 @@ export default function attachKeyHandlers(
93102
logger.log(
94103
'\n' +
95104
[
96-
`${chalk.bold('r')} - reload app`,
97-
`${chalk.bold('d')} - open Dev Menu`,
98105
`${chalk.bold('i')} - run on iOS`,
99106
`${chalk.bold('a')} - run on Android`,
107+
`${chalk.bold('d')} - open Dev Menu`,
108+
`${chalk.bold('j')} - open debugger`,
109+
`${chalk.bold('r')} - reload app`,
100110
].join('\n'),
101111
);
102112
}

packages/community-cli-plugin/src/commands/start/runServer.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,17 @@ async function runServer(
6868
server: {port},
6969
watchFolders,
7070
} = metroConfig;
71+
const scheme = args.https === true ? 'https' : 'http';
72+
const devServerUrl = `${scheme}://${host}:${port}`;
7173

7274
logger.info(`Welcome to React Native v${ctx.reactNativeVersion}`);
7375

74-
const serverStatus = await isDevServerRunning(host, port, projectRoot);
76+
const serverStatus = await isDevServerRunning(
77+
scheme,
78+
host,
79+
port,
80+
projectRoot,
81+
);
7582

7683
if (serverStatus === 'matched_server_running') {
7784
logger.info(
@@ -124,7 +131,11 @@ async function runServer(
124131
}
125132
if (args.interactive && event.type === 'dep_graph_loaded') {
126133
logger.info('Dev server ready');
127-
attachKeyHandlers(ctx, messageSocketEndpoint);
134+
attachKeyHandlers({
135+
cliConfig: ctx,
136+
devServerUrl,
137+
messageSocket: messageSocketEndpoint,
138+
});
128139
}
129140
},
130141
};

packages/community-cli-plugin/src/utils/isDevServerRunning.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import fetch from 'node-fetch';
2323
* - `unknown`: An error was encountered; attempt server creation anyway.
2424
*/
2525
export default async function isDevServerRunning(
26+
scheme: string,
2627
host: string,
2728
port: number,
2829
projectRoot: string,
@@ -34,7 +35,7 @@ export default async function isDevServerRunning(
3435
return 'not_running';
3536
}
3637

37-
const statusResponse = await fetch(`http://localhost:${port}/status`);
38+
const statusResponse = await fetch(`${scheme}://${host}:${port}/status`);
3839
const body = await statusResponse.text();
3940

4041
return body === 'packager-status:running' &&

0 commit comments

Comments
 (0)