From 73c6e8ee05f5d50bd075e1194aae974c2be51b2d Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Mon, 13 Dec 2021 05:46:42 -0800 Subject: [PATCH] Make flipper server debuggable Summary: This diffs adds debugging support to flipper server, by adding VSCode config for it Reviewed By: timur-valiev, aigoncharov Differential Revision: D32982874 fbshipit-source-id: 8e187ad05a05566a598db04b97e8b08e3de7e835 --- desktop/.vscode/launch.json | 27 ++++++++--------- .../flipper-server/src/startSocketServer.tsx | 7 ++++- .../src/flipperServerConnection.tsx | 4 +-- desktop/scripts/start-flipper-server.ts | 29 ++++++++++++++----- 4 files changed, 41 insertions(+), 26 deletions(-) diff --git a/desktop/.vscode/launch.json b/desktop/.vscode/launch.json index 1e757c7b1..9a569efdc 100644 --- a/desktop/.vscode/launch.json +++ b/desktop/.vscode/launch.json @@ -1,6 +1,14 @@ { "version": "0.2.0", "configurations": [ + { + "name": "Attach to Flipper Server", + "type": "node", + "request": "attach", + "port": 9229, + "sourceMaps": true, + "skipFiles": ["/**"] + }, { "name": "Attach to Running Renderer", "type": "chrome", @@ -21,10 +29,7 @@ "request": "launch", "name": "Launch Current Jest Suite", "program": "${workspaceFolder}/node_modules/.bin/jest", - "args": [ - "--runInBand", - "${relativeFile}" - ], + "args": ["--runInBand", "${relativeFile}"], "env": { "TZ": "Pacific/Pohnpei" } @@ -34,27 +39,19 @@ "cwd": "${fileDirname}", "request": "launch", "name": "Launch Current Script", - "args": [ - "${file}" - ], + "args": ["${file}"], "env": { "TS_NODE_FILES": "true" }, "protocol": "inspector", "internalConsoleOptions": "openOnSessionStart", - "runtimeArgs": [ - "--require", - "ts-node/register" - ] + "runtimeArgs": ["--require", "ts-node/register"] } ], "compounds": [ { "name": "Attach to All", - "configurations": [ - "Attach to Running Main", - "Attach to Running Renderer" - ] + "configurations": ["Attach to Running Main", "Attach to Running Renderer"] } ] } diff --git a/desktop/flipper-server/src/startSocketServer.tsx b/desktop/flipper-server/src/startSocketServer.tsx index 504a6f4ae..96d2ad73e 100644 --- a/desktop/flipper-server/src/startSocketServer.tsx +++ b/desktop/flipper-server/src/startSocketServer.tsx @@ -37,7 +37,12 @@ export function startSocketServer( .catch((error: any) => { if (connected) { // TODO: Serialize error - client.emit('exec-response-error', id, error.toString()); + // TODO: log if verbose console.warn('Failed to handle response', error); + client.emit( + 'exec-response-error', + id, + error.toString() + (error.stack ? `\n${error.stack}` : ''), + ); } }); }); diff --git a/desktop/flipper-ui-browser/src/flipperServerConnection.tsx b/desktop/flipper-ui-browser/src/flipperServerConnection.tsx index e3af1d1e2..0185c7ffc 100644 --- a/desktop/flipper-ui-browser/src/flipperServerConnection.tsx +++ b/desktop/flipper-ui-browser/src/flipperServerConnection.tsx @@ -12,7 +12,7 @@ import {FlipperServer} from 'flipper-common'; import {io, Socket} from 'socket.io-client'; const CONNECTION_TIMEOUT = 30 * 1000; -const EXEC_TIMOUT = 10 * 1000; +const EXEC_TIMOUT = 30 * 10 * 1000; export function createFlipperServer(): Promise { // TODO: polish this all! @@ -90,8 +90,8 @@ export function createFlipperServer(): Promise { close() {}, exec(command, ...args): any { if (connected) { + const id = ++requestId; return new Promise((resolve, reject) => { - const id = ++requestId; console.debug('exec >>>', id, command, args); pendingRequests.set(id, { diff --git a/desktop/scripts/start-flipper-server.ts b/desktop/scripts/start-flipper-server.ts index e503acc3f..e245b452b 100644 --- a/desktop/scripts/start-flipper-server.ts +++ b/desktop/scripts/start-flipper-server.ts @@ -54,6 +54,11 @@ const argv = yargs '[FB-internal only] Will force using public sources only, to be able to iterate quickly on the public version. If sources are checked out from GitHub this is already the default. Setting env var "FLIPPER_FORCE_PUBLIC_BUILD" is equivalent.', type: 'boolean', }, + build: { + describe: + 'Build the server without watching for changing or starting the service', + type: 'boolean', + }, }) .version('DEV') .help() @@ -113,13 +118,17 @@ let proc: child.ChildProcess | undefined; function launchServer() { console.log('⚙️ Launching flipper-server...'); - proc = child.spawn('node', [`../flipper-server/server.js`], { - cwd: serverDir, - env: { - ...process.env, + proc = child.spawn( + 'node', + ['--inspect=9229', `../flipper-server/server.js`], + { + cwd: serverDir, + env: { + ...process.env, + }, + stdio: 'inherit', }, - stdio: 'inherit', - }); + ); } async function restartServer() { @@ -173,6 +182,10 @@ async function startWatchChanges() { } (async () => { - await startWatchChanges(); - restartServer(); + if (argv['build']) { + await compileServerMain(); + } else { + await startWatchChanges(); + restartServer(); // builds and starts + } })();