diff --git a/flow-typed/environment/node.js b/flow-typed/environment/node.js index eecaceb1f40557..abe6be1ddbe9d0 100644 --- a/flow-typed/environment/node.js +++ b/flow-typed/environment/node.js @@ -21,6 +21,12 @@ interface ErrnoError extends Error { syscall?: string; } +type Node$Conditional = T extends true + ? IfTrue + : T extends false + ? IfFalse + : IfTrue | IfFalse; + type buffer$NonBufferEncoding = | 'hex' | 'HEX' @@ -1594,6 +1600,71 @@ declare module 'fs' { flags?: number, ): void; + declare type GlobOptions = $ReadOnly<{ + /** + * Current working directory. + * @default process.cwd() + */ + cwd?: string | void, + /** + * `true` if the glob should return paths as `Dirent`s, `false` otherwise. + * @default false + * @since v22.2.0 + */ + withFileTypes?: WithFileTypes, + /** + * Function to filter out files/directories or a + * list of glob patterns to be excluded. If a function is provided, return + * `true` to exclude the item, `false` to include it. + * @default undefined + */ + exclude?: + | ((fileName: Node$Conditional) => boolean) + | $ReadOnlyArray, + ... + }>; + + /** + * Retrieves the files matching the specified pattern. + * + * ```js + * import { glob } from 'node:fs'; + * + * glob('*.js', (err, matches) => { + * if (err) throw err; + * console.log(matches); + * }); + * ``` + * @since v22.0.0 + */ + declare function glob( + pattern: string | $ReadOnlyArray, + callback: (err: ?ErrnoError, matches: Array) => void, + ): void; + + declare function glob( + pattern: string | $ReadOnlyArray, + options: GlobOptions, + callback: ( + err: ?ErrnoError, + matches: Node$Conditional, Array>, + ) => void, + ): void; + + /** + * ```js + * import { globSync } from 'node:fs'; + * + * console.log(globSync('*.js')); + * ``` + * @since v22.0.0 + * @returns paths of files that match the pattern. + */ + declare function globSync( + pattern: string | $ReadOnlyArray, + options?: GlobOptions, + ): Node$Conditional, Array>; + declare var F_OK: number; declare var R_OK: number; declare var W_OK: number; @@ -1725,6 +1796,14 @@ declare module 'fs' { atime: number | string | Date, mtime: number | string | Date, ): Promise, + glob( + pattern: string | $ReadOnlyArray, + options?: GlobOptions, + ): Node$Conditional< + WithFileTypes, + AsyncIterator, + AsyncIterator, + >, lchmod(path: FSPromisePath, mode: number): Promise, lchown(path: FSPromisePath, uid: number, guid: number): Promise, link(existingPath: FSPromisePath, newPath: FSPromisePath): Promise,