mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Fix tests and reland "[debugger-shell] add debug statements to debugger shell launching path" (#54978)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/54978 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: robhogan Differential Revision: D89765226 fbshipit-source-id: c330df6ed0dbb27b13df89cd2c544a821077dd3f
This commit is contained in:
1 parent
68aab492e1
commit
b45c8202e5
1 file changed
+34
-4
@@ -14,6 +14,7 @@ import {
|
||||
} from './private/LaunchUtils';
|
||||
|
||||
const {spawn} = require('cross-spawn');
|
||||
const debug = require('debug')('Metro:DebuggerShell');
|
||||
const path = require('path');
|
||||
|
||||
// The 'prebuilt' flavor will use the prebuilt shell binary (and the JavaScript embedded in it).
|
||||
@@ -31,6 +32,7 @@ async function unstable_spawnDebuggerShellWithArgs(
|
||||
mode = 'detached',
|
||||
flavor = process.env.RNDT_DEV === '1' ? 'dev' : 'prebuilt',
|
||||
prebuiltBinaryPath,
|
||||
silent = process.env.NODE_ENV === 'test',
|
||||
}: Readonly<{
|
||||
// In 'syncAndExit' mode, the current process will block until the spawned process exits, and then it will exit
|
||||
// with the same exit code as the spawned process.
|
||||
@@ -39,6 +41,7 @@ async function unstable_spawnDebuggerShellWithArgs(
|
||||
mode?: 'syncThenExit' | 'detached',
|
||||
flavor?: DebuggerShellFlavor,
|
||||
prebuiltBinaryPath?: ?string,
|
||||
silent?: boolean,
|
||||
}> = {},
|
||||
): Promise<void> {
|
||||
const [binaryPath, baseArgs] = getShellBinaryAndArgs(
|
||||
@@ -55,17 +58,26 @@ 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: string) => {
|
||||
debug('Debugger closed with code %s and signal %s', code, signal);
|
||||
if (code !== 0) {
|
||||
if (!silent) {
|
||||
console.error(
|
||||
'Debugger exited with non-zero code (code: %s, signal: %s)',
|
||||
code,
|
||||
signal,
|
||||
);
|
||||
}
|
||||
reject(
|
||||
new Error(
|
||||
`Failed to open debugger shell: exited with code ${code}`,
|
||||
@@ -73,11 +85,28 @@ async function unstable_spawnDebuggerShellWithArgs(
|
||||
);
|
||||
}
|
||||
});
|
||||
child.on('error', error => {
|
||||
debug('Debugger shell encountered error: %s', error);
|
||||
reject(error);
|
||||
});
|
||||
if (!silent) {
|
||||
child.stdout.on('data', data =>
|
||||
console.log('[debugger-shell stdout] ' + String(data)),
|
||||
);
|
||||
child.stderr.on('data', data =>
|
||||
console.warn('[debugger-shell stderr] ' + String(data)),
|
||||
);
|
||||
}
|
||||
child.unref();
|
||||
} else if (mode === 'syncThenExit') {
|
||||
child.on('close', function (code, signal) {
|
||||
if (code === null) {
|
||||
console.error('Debugger shell exited with signal', signal);
|
||||
debug('Debugger exited with code %s and signal %s', code, signal);
|
||||
if (code === null && !silent) {
|
||||
console.error(
|
||||
'Debugger exited with code %s and signal %s',
|
||||
code,
|
||||
signal,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
process.exit(code);
|
||||
@@ -85,6 +114,7 @@ async function unstable_spawnDebuggerShellWithArgs(
|
||||
|
||||
const handleTerminationSignal = function (signal: string) {
|
||||
process.on(signal, function signalHandler() {
|
||||
debug('Received signal %s. Killing debugger shell.', signal);
|
||||
if (!child.killed) {
|
||||
child.kill(signal);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user