Skip to content

Commit

Permalink
Merge pull request #374 from fu1996/feature-16780
Browse files Browse the repository at this point in the history
feat: add withFileTypes in FileSystem
  • Loading branch information
TheLarkInn committed Apr 14, 2023
2 parents ca76a47 + 114d565 commit 4efd8e3
Show file tree
Hide file tree
Showing 2 changed files with 75 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 | 'buffer'} [encoding]
* @property {boolean | undefined} [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 | undefined | 'buffer' | 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
88 changes: 66 additions & 22 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,31 @@ 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"
| "buffer",
arg2?: (
arg0?: null | NodeJS.ErrnoException,
arg1?: (string | Buffer)[] | any[]
) => void
) => void;
readdirSync: (
arg0: string,
arg1?: object
Expand Down Expand Up @@ -107,17 +121,31 @@ 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"
| "buffer",
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 +213,22 @@ declare interface PossibleFileSystemError {
path?: string;
syscall?: string;
}
declare interface ReaddirOptions {
encoding?:
| null
| "ascii"
| "utf8"
| "utf-8"
| "utf16le"
| "ucs2"
| "ucs-2"
| "base64"
| "latin1"
| "binary"
| "hex"
| "buffer";
withFileTypes?: boolean;
}

/**
* Resolve context
Expand Down

0 comments on commit 4efd8e3

Please sign in to comment.