Remove 'process' usage

Summary: Removed process, adbkit and electron usages that were still remaining. Verified changes by disabling the built-in module stubbing (will be cleaned up further later in this stack).

Reviewed By: aigoncharov

Differential Revision: D33019083

fbshipit-source-id: 8bfce31f4b5ed349cb4fd86d34c9b41b9b8b8360
This commit is contained in:
Michel Weststrate
2021-12-13 05:46:42 -08:00
committed by Facebook GitHub Bot
parent 3ef1923b29
commit ac9080abac
7 changed files with 62 additions and 52 deletions

View File

@@ -27,6 +27,7 @@ import {setupMenuBar} from './setupMenuBar';
import {FlipperServer, FlipperServerConfig} from 'flipper-common'; import {FlipperServer, FlipperServerConfig} from 'flipper-common';
import type {Icon, RenderHost} from 'flipper-ui-core'; import type {Icon, RenderHost} from 'flipper-ui-core';
import {getLocalIconUrl} from '../utils/icons'; import {getLocalIconUrl} from '../utils/icons';
import {getCPUUsage} from 'process';
export function initializeElectron( export function initializeElectron(
flipperServer: FlipperServer, flipperServer: FlipperServer,
@@ -202,6 +203,9 @@ export function initializeElectron(
} }
delete global.electronRequire.cache[resolvedPath]; delete global.electronRequire.cache[resolvedPath];
}, },
getPercentCPUUsage() {
return getCPUUsage().percentCPUUsage;
},
} as RenderHost; } as RenderHost;
setupMenuBar(); setupMenuBar();

View File

@@ -27,50 +27,50 @@ const uiSourceDirs = [
'flipper-common', 'flipper-common',
]; ];
const stubModules = new Set([ const stubModules = new Set<string>([
'fs', // 'fs',
'path', // 'path',
'crypto', // 'crypto',
'process', // 'process',
'os', // 'os',
'util', // 'util',
'child_process', // 'child_process',
'assert', // 'assert',
'adbkit', // TODO: factor out! // 'adbkit', // TODO: factor out!
'zlib', // 'zlib',
'events', // 'events',
'fs-extra', // 'fs-extra',
'archiver', // 'archiver',
'graceful-fs', // 'graceful-fs',
'stream', // 'stream',
'url', // 'url',
'node-fetch', // 'node-fetch',
'net', // 'net',
'vm', // 'vm',
'debug', // 'debug',
'lockfile', // 'lockfile',
'constants', // 'constants',
'https', // 'https',
'plugin-lib', // TODO: we only want the types? // 'plugin-lib', // TODO: we only want the types?
'flipper-plugin-lib', // 'flipper-plugin-lib',
'tar', // 'tar',
'minipass', // 'minipass',
'live-plugin-manager', // 'live-plugin-manager',
'decompress-tar', // 'decompress-tar',
'readable-stream', // 'readable-stream',
'archiver-utils', // 'archiver-utils',
'metro', // 'metro',
'decompress', // 'decompress',
'temp', // 'temp',
'tmp', // 'tmp',
'promisify-child-process', // 'promisify-child-process',
'jsdom', // 'jsdom',
'extract-zip', // 'extract-zip',
'yauzl', // 'yauzl',
'fd-slicer', // 'fd-slicer',
'envinfo', // 'envinfo',
'bser', // 'bser',
'fb-watchman', // 'fb-watchman',
// TODO fix me // TODO fix me
]); ]);

View File

@@ -18,7 +18,9 @@ async function start() {
console.error( console.error(
`[decapitate] Tried to electronRequire ${path}, this module is not available in the browser and will be stubbed`, `[decapitate] Tried to electronRequire ${path}, this module is not available in the browser and will be stubbed`,
); );
return {}; return {
default: {},
};
}; };
const logger = createDelegatedLogger(); const logger = createDelegatedLogger();

View File

@@ -104,6 +104,7 @@ export interface RenderHost {
// given the requested icon and proposed public url of the icon, rewrite it to a local icon if needed // given the requested icon and proposed public url of the icon, rewrite it to a local icon if needed
getLocalIconUrl?(icon: Icon, publicUrl: string): string; getLocalIconUrl?(icon: Icon, publicUrl: string): string;
unloadModule?(path: string): void; unloadModule?(path: string): void;
getPercentCPUUsage?(): number;
} }
export function getRenderHostInstance(): RenderHost { export function getRenderHostInstance(): RenderHost {

View File

@@ -24,7 +24,6 @@ import {
import produce from 'immer'; import produce from 'immer';
import BaseDevice from '../devices/BaseDevice'; import BaseDevice from '../devices/BaseDevice';
import {deconstructClientId} from 'flipper-common'; import {deconstructClientId} from 'flipper-common';
import {getCPUUsage} from 'process';
import {sideEffect} from '../utils/sideEffect'; import {sideEffect} from '../utils/sideEffect';
import {getSelectionInfo} from '../utils/info'; import {getSelectionInfo} from '../utils/info';
import type {SelectionInfo} from '../utils/info'; import type {SelectionInfo} from '../utils/info';
@@ -239,7 +238,7 @@ export default (store: Store, logger: Logger) => {
sdkVersion, sdkVersion,
isForeground: state.application.windowIsFocused, isForeground: state.application.windowIsFocused,
usedJSHeapSize: (window.performance as any).memory.usedJSHeapSize, usedJSHeapSize: (window.performance as any).memory.usedJSHeapSize,
cpuLoad: getCPUUsage().percentCPUUsage, cpuLoad: renderHost.getPercentCPUUsage?.() ?? 0,
}; };
// reset dropped frames counter // reset dropped frames counter

View File

@@ -20,7 +20,6 @@ import {
DataTableColumn, DataTableColumn,
Toolbar, Toolbar,
} from 'flipper-plugin'; } from 'flipper-plugin';
import adb from 'adbkit';
import TemperatureTable from './TemperatureTable'; import TemperatureTable from './TemperatureTable';
import {Button, Typography, Switch} from 'antd'; import {Button, Typography, Switch} from 'antd';
import {PlayCircleOutlined, PauseCircleOutlined} from '@ant-design/icons'; import {PlayCircleOutlined, PauseCircleOutlined} from '@ant-design/icons';

View File

@@ -9,9 +9,15 @@
import React from 'react'; import React from 'react';
import {FlipperDevicePlugin, Device, sleep} from 'flipper'; import {
FlipperDevicePlugin,
import {FlexColumn, Button, Toolbar, Panel} from 'flipper'; Device,
sleep,
FlexColumn,
Button,
Toolbar,
Panel,
} from 'flipper';
import { import {
Legend, Legend,
@@ -24,7 +30,6 @@ import {
Tooltip, Tooltip,
} from 'recharts'; } from 'recharts';
import adb from 'adbkit';
import {getFlipperLib} from 'flipper-plugin'; import {getFlipperLib} from 'flipper-plugin';
const PALETTE = [ const PALETTE = [