From 9df3437683c77cbe1fb87aa23c129ee71c3bfc18 Mon Sep 17 00:00:00 2001 From: Andrey Goncharov Date: Fri, 10 Dec 2021 06:34:37 -0800 Subject: [PATCH] Remove child_process from Tracery and ReactDevTools Summary: Changelog: Remove child_process usage from ReactDevTools plugin Reviewed By: mweststrate Differential Revision: D32881744 fbshipit-source-id: c80c3f7589a2787c4b5916ff1eb9f28d4af79700 --- .../plugins/public/reactdevtools/index.tsx | 43 ++++++++----------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/desktop/plugins/public/reactdevtools/index.tsx b/desktop/plugins/public/reactdevtools/index.tsx index 8dc2fab99..511a55793 100644 --- a/desktop/plugins/public/reactdevtools/index.tsx +++ b/desktop/plugins/public/reactdevtools/index.tsx @@ -17,12 +17,12 @@ import { sleep, Toolbar, path, + getFlipperLib, } from 'flipper-plugin'; import React from 'react'; import getPort from 'get-port'; -import {Button, Select, message, Switch, Typography} from 'antd'; -import child_process from 'child_process'; -import fs from 'fs'; +import {Button, message, Switch, Typography, Select} from 'antd'; +import fs from 'fs/promises'; import {DevToolsEmbedder} from './DevToolsEmbedder'; import {getInternalDevToolsModule} from './fb-stubs/getInternalDevToolsModule'; @@ -30,27 +30,22 @@ const DEV_TOOLS_NODE_ID = 'reactdevtools-out-of-react-node'; const CONNECTED = 'DevTools connected'; const DEV_TOOLS_PORT = 8097; // hardcoded in RN -function findGlobalDevTools(): Promise { - return new Promise((resolve) => { - child_process.exec('npm root -g', (error, basePath) => { - if (error) { - console.warn( - 'Failed to find globally installed React DevTools: ' + error, - ); - resolve(undefined); - } else { - const devToolsPath = path.join( - basePath.trim(), - 'react-devtools', - 'node_modules', - 'react-devtools-core', - ); - fs.stat(devToolsPath, (err, stats) => { - resolve(!err && stats ? devToolsPath : undefined); - }); - } - }); - }); +async function findGlobalDevTools(): Promise { + try { + const {stdout: basePath} = + await getFlipperLib().removeNodeAPI.childProcess.exec('npm root -g'); + const devToolsPath = path.join( + basePath.trim(), + 'react-devtools', + 'node_modules', + 'react-devtools-core', + ); + await fs.stat(devToolsPath); + return devToolsPath; + } catch (error) { + console.warn('Failed to find globally installed React DevTools: ' + error); + return undefined; + } } enum ConnectionStatus {