Remove remaining Node imports from core
Summary: Removed remaining path / fs imports from Flipper core. `expand-tide` needed replacement too, but noticed that it never actually rewrites paths since all use cases were already using absolute paths, so removed it instead. Reviewed By: aigoncharov Differential Revision: D33017654 fbshipit-source-id: e12f66ef68b5f9e4279411c94445a2fb87249e9a
This commit is contained in:
committed by
Facebook GitHub Bot
parent
d95b15094f
commit
accef856fc
@@ -8,7 +8,6 @@
|
||||
*/
|
||||
|
||||
import * as React from 'react';
|
||||
import path from 'path';
|
||||
import {getLogger} from 'flipper-common';
|
||||
import {Store, MiddlewareAPI} from '../reducers';
|
||||
import {DeviceExport} from '../devices/BaseDevice';
|
||||
@@ -20,7 +19,6 @@ import {pluginKey} from '../utils/pluginKey';
|
||||
import {DevicePluginMap, ClientPluginMap} from '../plugin';
|
||||
import {default as BaseDevice} from '../devices/BaseDevice';
|
||||
import {default as ArchivedDevice} from '../devices/ArchivedDevice';
|
||||
import fs from 'fs-extra';
|
||||
import {v4 as uuidv4} from 'uuid';
|
||||
import {tryCatchReportPlatformFailures} from 'flipper-common';
|
||||
import {TestIdler} from './Idler';
|
||||
@@ -33,7 +31,7 @@ import {deconstructClientId} from 'flipper-common';
|
||||
import {processMessageQueue} from './messageQueue';
|
||||
import {getPluginTitle} from './pluginUtils';
|
||||
import {capture} from './screenshot';
|
||||
import {Dialog, Idler} from 'flipper-plugin';
|
||||
import {Dialog, getFlipperLib, Idler, path} from 'flipper-plugin';
|
||||
import {ClientQuery} from 'flipper-common';
|
||||
import ShareSheetExportUrl from '../chrome/ShareSheetExportUrl';
|
||||
import ShareSheetExportFile from '../chrome/ShareSheetExportFile';
|
||||
@@ -521,7 +519,10 @@ export const exportStoreToFile = (
|
||||
}> => {
|
||||
return exportStore(store, includeSupportDetails, idler, statusUpdate).then(
|
||||
async ({serializedString, fetchMetaDataErrors}) => {
|
||||
await fs.writeFile(exportFilePath, serializedString);
|
||||
await getFlipperLib().remoteServerContext.fs.writeFile(
|
||||
exportFilePath,
|
||||
serializedString,
|
||||
);
|
||||
store.dispatch(resetSupportFormV2State());
|
||||
return {fetchMetaDataErrors};
|
||||
},
|
||||
@@ -584,17 +585,17 @@ export function importDataToStore(source: string, data: string, store: Store) {
|
||||
}
|
||||
}
|
||||
|
||||
export const importFileToStore = (file: string, store: Store) => {
|
||||
fs.readFile(file, 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
console.error(
|
||||
`[exportData] importFileToStore for file ${file} failed:`,
|
||||
err,
|
||||
);
|
||||
return;
|
||||
}
|
||||
export const importFileToStore = async (file: string, store: Store) => {
|
||||
try {
|
||||
const data = await getFlipperLib().remoteServerContext.fs.readFile(file);
|
||||
importDataToStore(file, data, store);
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(
|
||||
`[exportData] importFileToStore for file ${file} failed:`,
|
||||
err,
|
||||
);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
export function canOpenDialog() {
|
||||
|
||||
@@ -7,15 +7,14 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import util from 'util';
|
||||
import {exec as execImport} from 'child_process';
|
||||
import {getFlipperLib} from 'flipper-plugin';
|
||||
|
||||
const cmd = 'klist --json';
|
||||
const endWith = '@THEFACEBOOK.COM';
|
||||
|
||||
export async function isFBEmployee(): Promise<boolean> {
|
||||
return util
|
||||
.promisify(execImport)(cmd)
|
||||
return getFlipperLib()
|
||||
.remoteServerContext.childProcess.exec(cmd)
|
||||
.then(
|
||||
(stdobj: {stderr: string; stdout: string}) => {
|
||||
const principal = String(JSON.parse(stdobj.stdout).principal);
|
||||
|
||||
@@ -7,17 +7,15 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import BaseDevice from '../devices/BaseDevice';
|
||||
import {reportPlatformFailures} from 'flipper-common';
|
||||
import expandTilde from 'expand-tilde';
|
||||
import {getRenderHostInstance} from '../RenderHost';
|
||||
import {getFlipperLib, path} from 'flipper-plugin';
|
||||
|
||||
export function getCaptureLocation() {
|
||||
return expandTilde(
|
||||
return (
|
||||
getRenderHostInstance().serverConfig.processConfig.screenCapturePath ||
|
||||
getRenderHostInstance().serverConfig.paths.desktopPath,
|
||||
getRenderHostInstance().serverConfig.paths.desktopPath
|
||||
);
|
||||
}
|
||||
|
||||
@@ -34,33 +32,14 @@ export async function capture(device: BaseDevice): Promise<string> {
|
||||
}
|
||||
const pngPath = path.join(getCaptureLocation(), getFileName('png'));
|
||||
return reportPlatformFailures(
|
||||
device.screenshot().then((buffer) => writeBufferToFile(pngPath, buffer)),
|
||||
// TODO: there is no reason to read the screenshot first, grab it over the websocket, than send it back
|
||||
// again to write in a file, probably easier to change screenshot api to `device.screenshot(): path`
|
||||
device
|
||||
.screenshot()
|
||||
.then((buffer) =>
|
||||
getFlipperLib().remoteServerContext.fs.writeFileBinary(pngPath, buffer),
|
||||
)
|
||||
.then(() => pngPath),
|
||||
'captureScreenshot',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a buffer to a specified file path.
|
||||
* Returns a Promise which resolves to the file path.
|
||||
*/
|
||||
export const writeBufferToFile = (
|
||||
filePath: string,
|
||||
buffer: Buffer,
|
||||
): Promise<string> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.writeFile(filePath, buffer, (err) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(filePath);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a Blob from a Buffer
|
||||
*/
|
||||
export const bufferToBlob = (buffer: Buffer): Blob => {
|
||||
return new Blob([buffer]);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user