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
This commit is contained in:
Andrey Goncharov
2021-12-10 06:34:37 -08:00
committed by Facebook GitHub Bot
parent e458ae76f9
commit 9df3437683

View File

@@ -17,12 +17,12 @@ import {
sleep, sleep,
Toolbar, Toolbar,
path, path,
getFlipperLib,
} from 'flipper-plugin'; } from 'flipper-plugin';
import React from 'react'; import React from 'react';
import getPort from 'get-port'; import getPort from 'get-port';
import {Button, Select, message, Switch, Typography} from 'antd'; import {Button, message, Switch, Typography, Select} from 'antd';
import child_process from 'child_process'; import fs from 'fs/promises';
import fs from 'fs';
import {DevToolsEmbedder} from './DevToolsEmbedder'; import {DevToolsEmbedder} from './DevToolsEmbedder';
import {getInternalDevToolsModule} from './fb-stubs/getInternalDevToolsModule'; 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 CONNECTED = 'DevTools connected';
const DEV_TOOLS_PORT = 8097; // hardcoded in RN const DEV_TOOLS_PORT = 8097; // hardcoded in RN
function findGlobalDevTools(): Promise<string | undefined> { async function findGlobalDevTools(): Promise<string | undefined> {
return new Promise((resolve) => { try {
child_process.exec('npm root -g', (error, basePath) => { const {stdout: basePath} =
if (error) { await getFlipperLib().removeNodeAPI.childProcess.exec('npm root -g');
console.warn( const devToolsPath = path.join(
'Failed to find globally installed React DevTools: ' + error, basePath.trim(),
); 'react-devtools',
resolve(undefined); 'node_modules',
} else { 'react-devtools-core',
const devToolsPath = path.join( );
basePath.trim(), await fs.stat(devToolsPath);
'react-devtools', return devToolsPath;
'node_modules', } catch (error) {
'react-devtools-core', console.warn('Failed to find globally installed React DevTools: ' + error);
); return undefined;
fs.stat(devToolsPath, (err, stats) => { }
resolve(!err && stats ? devToolsPath : undefined);
});
}
});
});
} }
enum ConnectionStatus { enum ConnectionStatus {