Remove fs usage from Navigator plugin

Reviewed By: mweststrate

Differential Revision: D33019873

fbshipit-source-id: 6d48971dc04161b64fdd32ac4e658b56aa98b7ec
This commit is contained in:
Andrey Goncharov
2021-12-20 11:37:25 -08:00
committed by Facebook GitHub Bot
parent d003a7c1a5
commit 3f771c05dd
4 changed files with 13 additions and 18 deletions

View File

@@ -167,8 +167,9 @@ export interface FlipperLib {
}, },
): Promise<string | undefined>; ): Promise<string | undefined>;
paths: { paths: {
homePath: string;
appPath: string; appPath: string;
homePath: string;
staticPath: string;
tempPath: string; tempPath: string;
}; };
environmentInfo: { environmentInfo: {

View File

@@ -407,6 +407,7 @@ export function createMockFlipperLib(options?: StartPluginOptions): FlipperLib {
paths: { paths: {
appPath: process.cwd(), appPath: process.cwd(),
homePath: `/dev/null`, homePath: `/dev/null`,
staticPath: process.cwd(),
tempPath: `/dev/null`, tempPath: `/dev/null`,
}, },
environmentInfo: { environmentInfo: {

View File

@@ -74,6 +74,7 @@ export function initializeFlipperLibImplementation(
paths: { paths: {
appPath: renderHost.serverConfig.paths.appPath, appPath: renderHost.serverConfig.paths.appPath,
homePath: renderHost.serverConfig.paths.homePath, homePath: renderHost.serverConfig.paths.homePath,
staticPath: renderHost.serverConfig.paths.staticPath,
tempPath: renderHost.serverConfig.paths.tempPath, tempPath: renderHost.serverConfig.paths.tempPath,
}, },
environmentInfo: { environmentInfo: {

View File

@@ -7,18 +7,10 @@
* @format * @format
*/ */
import fs from 'fs';
import {path} from 'flipper-plugin'; import {path} from 'flipper-plugin';
import {AppMatchPattern} from '../types'; import {AppMatchPattern} from '../types';
import {Device, getFlipperLib} from 'flipper-plugin'; import {Device, getFlipperLib} from 'flipper-plugin';
let patternsPath: string | undefined;
function getPatternsBasePath() {
return (patternsPath =
patternsPath ?? path.join(getFlipperLib().paths.appPath, 'facebook'));
}
const extractAppNameFromSelectedApp = (selectedApp: string | null) => { const extractAppNameFromSelectedApp = (selectedApp: string | null) => {
if (selectedApp == null) { if (selectedApp == null) {
return null; return null;
@@ -31,7 +23,7 @@ export const getAppMatchPatterns = (
selectedApp: string | null, selectedApp: string | null,
device: Device, device: Device,
) => { ) => {
return new Promise<Array<AppMatchPattern>>((resolve, reject) => { return new Promise<Array<AppMatchPattern>>(async (resolve, reject) => {
const appName = extractAppNameFromSelectedApp(selectedApp); const appName = extractAppNameFromSelectedApp(selectedApp);
if (appName === 'Facebook') { if (appName === 'Facebook') {
let filename: string; let filename: string;
@@ -42,14 +34,14 @@ export const getAppMatchPatterns = (
} else { } else {
return; return;
} }
const patternsFilePath = path.join(getPatternsBasePath(), filename); const patternsFilePath = path.join(
fs.readFile(patternsFilePath, (err, data) => { getFlipperLib().paths.staticPath,
if (err) { 'facebook',
reject(err); filename,
} else { );
resolve(JSON.parse(data.toString())); const patternsFileContentString =
} await getFlipperLib().remoteServerContext.fs.readFile(patternsFilePath);
}); return JSON.parse(patternsFileContentString);
} else if (appName != null) { } else if (appName != null) {
console.log('No rule for app ' + appName); console.log('No rule for app ' + appName);
resolve([]); resolve([]);