From c00173fdb4bd9f852e8ca1908af46cec500887aa Mon Sep 17 00:00:00 2001 From: Vitali Zaidman Date: Mon, 22 Dec 2025 08:05:37 -0800 Subject: [PATCH] add debug statements to debugger shell launching path (#54929) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/54929 There's a bug in Node.JS: https://github.com/nodejs/node/issues/51018 where spawning a process on Windows with detached mode and unref will not actually inherit stdio. You need to manually pipe these to get to see stdout and stderr. It works well on MacOS though. Changelog: [Internal] Reviewed By: huntie Differential Revision: D88955169 fbshipit-source-id: cba661b13d8636d4d52122fe024f876300d4af1f --- .../debugger-shell/src/node/index.flow.js | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/packages/debugger-shell/src/node/index.flow.js b/packages/debugger-shell/src/node/index.flow.js index 7824db67a56..38d4ee6142b 100644 --- a/packages/debugger-shell/src/node/index.flow.js +++ b/packages/debugger-shell/src/node/index.flow.js @@ -14,6 +14,7 @@ import { } from './private/LaunchUtils'; const {spawn} = require('cross-spawn'); +const debug = require('debug')('Metro:Debugger:DebuggerShell'); const path = require('path'); // The 'prebuilt' flavor will use the prebuilt shell binary (and the JavaScript embedded in it). @@ -55,17 +56,24 @@ async function unstable_spawnDebuggerShellWithArgs( ...env } = process.env; const child = spawn(binaryPath, [...baseArgs, ...args], { - stdio: 'inherit', + stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true, detached: mode === 'detached', env, }); if (mode === 'detached') { child.on('spawn', () => { + debug('Debugger spawned in detached mode'); resolve(); }); - child.on('close', (code: number) => { + child.on('close', (code: number, signal) => { + debug('Debugger closed with code %s and signal %s', code, signal); if (code !== 0) { + console.error( + 'Debugger closed with code %s and signal %s', + code, + signal, + ); reject( new Error( `Failed to open debugger shell: exited with code ${code}`, @@ -73,11 +81,26 @@ async function unstable_spawnDebuggerShellWithArgs( ); } }); + child.on('error', error => { + debug('Debugger shell encountered error: %s', error); + reject(error); + }); + child.stdout.on('data', data => + console.debug('[DebuggerShell stdout] ' + String(data)), + ); + child.stderr.on('data', data => + console.debug('[DebuggerShell stderr] ' + String(data)), + ); child.unref(); } else if (mode === 'syncThenExit') { child.on('close', function (code, signal) { + debug('Debugger closed with code %s and signal %s', code, signal); if (code === null) { - console.error('Debugger shell exited with signal', signal); + console.error( + 'Debugger closed with code %s and signal %s', + code, + signal, + ); process.exit(1); } process.exit(code); @@ -85,6 +108,7 @@ async function unstable_spawnDebuggerShellWithArgs( const handleTerminationSignal = function (signal: string) { process.on(signal, function signalHandler() { + debug('The Signal %s received. killing debugger', signal); if (!child.killed) { child.kill(signal); }