Remove fs usage from Navigator plugin
Reviewed By: mweststrate Differential Revision: D33019873 fbshipit-source-id: 6d48971dc04161b64fdd32ac4e658b56aa98b7ec
This commit is contained in:
committed by
Facebook GitHub Bot
parent
d003a7c1a5
commit
3f771c05dd
@@ -167,8 +167,9 @@ export interface FlipperLib {
|
||||
},
|
||||
): Promise<string | undefined>;
|
||||
paths: {
|
||||
homePath: string;
|
||||
appPath: string;
|
||||
homePath: string;
|
||||
staticPath: string;
|
||||
tempPath: string;
|
||||
};
|
||||
environmentInfo: {
|
||||
|
||||
@@ -407,6 +407,7 @@ export function createMockFlipperLib(options?: StartPluginOptions): FlipperLib {
|
||||
paths: {
|
||||
appPath: process.cwd(),
|
||||
homePath: `/dev/null`,
|
||||
staticPath: process.cwd(),
|
||||
tempPath: `/dev/null`,
|
||||
},
|
||||
environmentInfo: {
|
||||
|
||||
@@ -74,6 +74,7 @@ export function initializeFlipperLibImplementation(
|
||||
paths: {
|
||||
appPath: renderHost.serverConfig.paths.appPath,
|
||||
homePath: renderHost.serverConfig.paths.homePath,
|
||||
staticPath: renderHost.serverConfig.paths.staticPath,
|
||||
tempPath: renderHost.serverConfig.paths.tempPath,
|
||||
},
|
||||
environmentInfo: {
|
||||
|
||||
@@ -7,18 +7,10 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import fs from 'fs';
|
||||
import {path} from 'flipper-plugin';
|
||||
import {AppMatchPattern} from '../types';
|
||||
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) => {
|
||||
if (selectedApp == null) {
|
||||
return null;
|
||||
@@ -31,7 +23,7 @@ export const getAppMatchPatterns = (
|
||||
selectedApp: string | null,
|
||||
device: Device,
|
||||
) => {
|
||||
return new Promise<Array<AppMatchPattern>>((resolve, reject) => {
|
||||
return new Promise<Array<AppMatchPattern>>(async (resolve, reject) => {
|
||||
const appName = extractAppNameFromSelectedApp(selectedApp);
|
||||
if (appName === 'Facebook') {
|
||||
let filename: string;
|
||||
@@ -42,14 +34,14 @@ export const getAppMatchPatterns = (
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
const patternsFilePath = path.join(getPatternsBasePath(), filename);
|
||||
fs.readFile(patternsFilePath, (err, data) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(JSON.parse(data.toString()));
|
||||
}
|
||||
});
|
||||
const patternsFilePath = path.join(
|
||||
getFlipperLib().paths.staticPath,
|
||||
'facebook',
|
||||
filename,
|
||||
);
|
||||
const patternsFileContentString =
|
||||
await getFlipperLib().remoteServerContext.fs.readFile(patternsFilePath);
|
||||
return JSON.parse(patternsFileContentString);
|
||||
} else if (appName != null) {
|
||||
console.log('No rule for app ' + appName);
|
||||
resolve([]);
|
||||
|
||||
Reference in New Issue
Block a user