Implement fs.stat and fs.readlink
Summary: Fixes issue for the stackTraceMapper Reviewed By: aigoncharov Differential Revision: D32987161 fbshipit-source-id: 660f49a1bdf61b2fd2963874ef23dfd284f71128
This commit is contained in:
committed by
Facebook GitHub Bot
parent
af83523798
commit
34a1da3345
@@ -132,6 +132,21 @@ export type IOSDeviceParams = {
|
||||
state?: string;
|
||||
};
|
||||
|
||||
// Serializable subset of StatsBase from fs.d.ts
|
||||
export interface FSStatsLike {
|
||||
isFile: boolean;
|
||||
isDirectory: boolean;
|
||||
isSymbolicLink: boolean;
|
||||
mode: number;
|
||||
uid: number;
|
||||
gid: number;
|
||||
size: number;
|
||||
atimeMs: number;
|
||||
mtimeMs: number;
|
||||
ctimeMs: number;
|
||||
birthtimeMs: number;
|
||||
}
|
||||
|
||||
export type FlipperServerCommands = {
|
||||
'node-api-fs-access': (path: string, mode?: number) => Promise<void>;
|
||||
'node-api-fs-pathExists': (path: string, mode?: number) => Promise<boolean>;
|
||||
@@ -146,6 +161,8 @@ export type FlipperServerCommands = {
|
||||
dest: string,
|
||||
flags?: number,
|
||||
) => Promise<void>;
|
||||
'node-api-fs-stat': (path: string) => Promise<FSStatsLike>;
|
||||
'node-api-fs-readlink': (path: string) => Promise<string>;
|
||||
/**
|
||||
* @throws ExecError
|
||||
*/
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
RmOptions,
|
||||
fsConstants,
|
||||
EnvironmentInfo,
|
||||
FSStatsLike,
|
||||
} from 'flipper-common';
|
||||
|
||||
export type FileEncoding = 'utf-8' | 'base64';
|
||||
@@ -49,6 +50,7 @@ export type RemoteServerContext = {
|
||||
): Promise<ExecOut<string>>;
|
||||
};
|
||||
fs: {
|
||||
constants: typeof fsConstants;
|
||||
access(path: string, mode?: number): Promise<void>;
|
||||
pathExists(path: string, mode?: number): Promise<boolean>;
|
||||
unlink(path: string): Promise<void>;
|
||||
@@ -62,7 +64,8 @@ export type RemoteServerContext = {
|
||||
): Promise<void>;
|
||||
rm(path: string, options?: RmOptions): Promise<void>;
|
||||
copyFile(src: string, dest: string, flags?: number): Promise<void>;
|
||||
constants: typeof fsConstants;
|
||||
stat(path: string): Promise<FSStatsLike>;
|
||||
readlink(path: string): Promise<string>;
|
||||
};
|
||||
downloadFile(
|
||||
url: string,
|
||||
|
||||
@@ -413,6 +413,8 @@ export function createMockFlipperLib(options?: StartPluginOptions): FlipperLib {
|
||||
rm: jest.fn(),
|
||||
copyFile: jest.fn(),
|
||||
constants: fsConstants,
|
||||
stat: jest.fn(),
|
||||
readlink: jest.fn(),
|
||||
},
|
||||
downloadFile: jest.fn(),
|
||||
},
|
||||
|
||||
@@ -49,7 +49,7 @@ import {promises} from 'fs';
|
||||
// Electron 11 runs on Node 12 which does not support fs.promises.rm
|
||||
import rm from 'rimraf';
|
||||
|
||||
const {access, copyFile, mkdir, unlink} = promises;
|
||||
const {access, copyFile, mkdir, unlink, stat, readlink} = promises;
|
||||
|
||||
export const SERVICE_FLIPPER = 'flipper.oAuthToken';
|
||||
|
||||
@@ -239,6 +239,25 @@ export class FlipperServerImpl implements FlipperServer {
|
||||
),
|
||||
),
|
||||
'node-api-fs-copyFile': copyFile,
|
||||
'node-api-fs-stat': async (path) => {
|
||||
const stats = await stat(path);
|
||||
const {atimeMs, birthtimeMs, ctimeMs, gid, mode, mtimeMs, size, uid} =
|
||||
stats;
|
||||
return {
|
||||
atimeMs,
|
||||
birthtimeMs,
|
||||
ctimeMs,
|
||||
gid,
|
||||
mode,
|
||||
mtimeMs,
|
||||
size,
|
||||
uid,
|
||||
isDirectory: stats.isDirectory(),
|
||||
isFile: stats.isFile(),
|
||||
isSymbolicLink: stats.isSymbolicLink(),
|
||||
};
|
||||
},
|
||||
'node-api-fs-readlink': readlink,
|
||||
// TODO: Do we need API to cancel an active download?
|
||||
'download-file-start': commandDownloadFileStartFactory(
|
||||
this.emit.bind(this),
|
||||
|
||||
@@ -111,6 +111,10 @@ export function initializeFlipperLibImplementation(
|
||||
flags,
|
||||
),
|
||||
constants: fsConstants,
|
||||
stat: async (path: string) =>
|
||||
renderHost.flipperServer.exec('node-api-fs-stat', path),
|
||||
readlink: async (path: string) =>
|
||||
renderHost.flipperServer.exec('node-api-fs-readlink', path),
|
||||
},
|
||||
downloadFile: downloadFileFactory(renderHost),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user