Skip to content

Commit

Permalink
feat: add withFileTypes in FileSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
fu1996 committed Mar 18, 2023
1 parent ca76a47 commit b7ca4f6
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 23 deletions.
10 changes: 9 additions & 1 deletion lib/Resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,18 @@ const {
* @param {T=} result
*/

/** @typedef {function((NodeJS.ErrnoException | null)=, (string | Buffer)[] | IDirent[]=): void} DirentArrayCallback */

/**
* @typedef {Object} ReaddirOptions
* @property {BufferEncoding | null} [encoding]
* @property {boolean} [withFileTypes=false]
*/

/**
* @typedef {Object} FileSystem
* @property {(function(string, FileSystemCallback<Buffer | string>): void) & function(string, object, FileSystemCallback<Buffer | string>): void} readFile
* @property {(function(string, FileSystemCallback<(Buffer | string)[] | FileSystemDirent[]>): void) & function(string, object, FileSystemCallback<(Buffer | string)[] | FileSystemDirent[]>): void} readdir
* @property {function(string, (ReaddirOptions | BufferEncoding | null | DirentArrayCallback)=, DirentArrayCallback=): void} readdir
* @property {((function(string, FileSystemCallback<object>): void) & function(string, object, FileSystemCallback<object>): void)=} readJson
* @property {(function(string, FileSystemCallback<Buffer | string>): void) & function(string, object, FileSystemCallback<Buffer | string>): void} readlink
* @property {(function(string, FileSystemCallback<FileSystemStats>): void) & function(string, object, FileSystemCallback<Buffer | string>): void=} lstat
Expand Down
85 changes: 63 additions & 22 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,30 @@ declare class CachedInputFileSystem {
): void;
};
statSync: (arg0: string, arg1?: object) => FileSystemStats;
readdir: {
(
arg0: string,
arg1: FileSystemCallback<(string | Buffer)[] | FileSystemDirent[]>
): void;
(
arg0: string,
arg1: object,
arg2: FileSystemCallback<(string | Buffer)[] | FileSystemDirent[]>
): void;
};
readdir: (
arg0: string,
arg1?:
| null
| ((
arg0?: null | NodeJS.ErrnoException,
arg1?: (string | Buffer)[] | any[]
) => void)
| ReaddirOptions
| "ascii"
| "utf8"
| "utf-8"
| "utf16le"
| "ucs2"
| "ucs-2"
| "base64"
| "latin1"
| "binary"
| "hex",
arg2?: (
arg0?: null | NodeJS.ErrnoException,
arg1?: (string | Buffer)[] | any[]
) => void
) => void;
readdirSync: (
arg0: string,
arg1?: object
Expand Down Expand Up @@ -107,17 +120,30 @@ declare interface FileSystem {
arg2: FileSystemCallback<string | Buffer>
): void;
};
readdir: {
(
arg0: string,
arg1: FileSystemCallback<(string | Buffer)[] | FileSystemDirent[]>
): void;
(
arg0: string,
arg1: object,
arg2: FileSystemCallback<(string | Buffer)[] | FileSystemDirent[]>
): void;
};
readdir: (
arg0: string,
arg1?:
| null
| ((
arg0?: null | NodeJS.ErrnoException,
arg1?: (string | Buffer)[] | any[]
) => void)
| ReaddirOptions
| "ascii"
| "utf8"
| "utf-8"
| "utf16le"
| "ucs2"
| "ucs-2"
| "base64"
| "latin1"
| "binary"
| "hex",
arg2?: (
arg0?: null | NodeJS.ErrnoException,
arg1?: (string | Buffer)[] | any[]
) => void
) => void;
readJson?: {
(arg0: string, arg1: FileSystemCallback<object>): void;
(arg0: string, arg1: object, arg2: FileSystemCallback<object>): void;
Expand Down Expand Up @@ -185,6 +211,21 @@ declare interface PossibleFileSystemError {
path?: string;
syscall?: string;
}
declare interface ReaddirOptions {
encoding?:
| null
| "ascii"
| "utf8"
| "utf-8"
| "utf16le"
| "ucs2"
| "ucs-2"
| "base64"
| "latin1"
| "binary"
| "hex";
withFileTypes?: boolean;
}

/**
* Resolve context
Expand Down

0 comments on commit b7ca4f6

Please sign in to comment.