From ee545ab0c7aefc6ed6efec2fa439079ada0c596d Mon Sep 17 00:00:00 2001 From: Alex Hunt Date: Tue, 3 Oct 2023 13:36:31 -0700 Subject: [PATCH] Fix start command exit behaviour (#39788) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Hotfix for exiting `npx react-native start` when a session is connected. Partially reverts D49422206. This lines back up with the original RN CLI and Expo implementations — explicitly calling `process.exit()`. We still aim to follow this up with graceful server shutdown. Changelog: [Internal] Reviewed By: lunaleaps Differential Revision: D49880226 --- .../src/commands/start/attachKeyHandlers.js | 17 ++++------------- .../src/commands/start/runServer.js | 1 - 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/packages/community-cli-plugin/src/commands/start/attachKeyHandlers.js b/packages/community-cli-plugin/src/commands/start/attachKeyHandlers.js index 7ac9a6cffbc75a..d33505ccb8d3e4 100644 --- a/packages/community-cli-plugin/src/commands/start/attachKeyHandlers.js +++ b/packages/community-cli-plugin/src/commands/start/attachKeyHandlers.js @@ -15,7 +15,6 @@ import {logger} from '@react-native-community/cli-tools'; import chalk from 'chalk'; import execa from 'execa'; import fetch from 'node-fetch'; -import readline from 'readline'; import {KeyPressHandler} from '../../utils/KeyPressHandler'; const CTRL_C = '\u0003'; @@ -23,13 +22,11 @@ const CTRL_D = '\u0004'; export default function attachKeyHandlers({ cliConfig, - serverInstance, devServerUrl, messageSocket, }: { cliConfig: Config, devServerUrl: string, - serverInstance: http$Server | https$Server, messageSocket: $ReadOnly<{ broadcast: (type: string, params?: Record | null) => void, ... @@ -40,10 +37,6 @@ export default function attachKeyHandlers({ return; } - readline.emitKeypressEvents(process.stdin); - // $FlowIgnore[prop-missing] - process.stdin.setRawMode(true); - const execaOptions = { env: {FORCE_COLOR: chalk.supportsColor ? 'true' : 'false'}, }; @@ -88,16 +81,14 @@ export default function attachKeyHandlers({ case CTRL_C: case CTRL_D: logger.info('Stopping server'); - listener?.({pause: true}); - serverInstance.close(() => { - process.emit('SIGINT'); - process.exit(); - }); + keyPressHandler.stopInterceptingKeyStrokes(); + process.emit('SIGINT'); + process.exit(); } }; const keyPressHandler = new KeyPressHandler(onPress); - const listener = keyPressHandler.createInteractionListener(); + keyPressHandler.createInteractionListener(); keyPressHandler.startInterceptingKeyStrokes(); logger.log( diff --git a/packages/community-cli-plugin/src/commands/start/runServer.js b/packages/community-cli-plugin/src/commands/start/runServer.js index 587f755501c69a..a7cc82a9b5c7c1 100644 --- a/packages/community-cli-plugin/src/commands/start/runServer.js +++ b/packages/community-cli-plugin/src/commands/start/runServer.js @@ -137,7 +137,6 @@ async function runServer( attachKeyHandlers({ cliConfig: ctx, devServerUrl, - serverInstance, messageSocket: messageSocketEndpoint, }); }