@@ -21,6 +21,12 @@ interface ErrnoError extends Error {
2121 syscall ? : string ;
2222}
2323
24+ type Node$Conditional < T : boolean , IfTrue , IfFalse > = T extends true
25+ ? IfTrue
26+ : T extends false
27+ ? IfFalse
28+ : IfTrue | IfFalse ;
29+
2430type buffer$NonBufferEncoding =
2531 | 'hex'
2632 | 'HEX'
@@ -1594,6 +1600,71 @@ declare module 'fs' {
15941600 flags ?: number ,
15951601 ) : void ;
15961602
1603+ declare type GlobOptions < WithFileTypes : boolean > = $ReadOnly < {
1604+ /**
1605+ * Current working directory.
1606+ * @default process.cwd()
1607+ */
1608+ cwd ?: string | void ,
1609+ /**
1610+ * `true` if the glob should return paths as `Dirent`s, `false` otherwise.
1611+ * @default false
1612+ * @since v22.2.0
1613+ */
1614+ withFileTypes ?: WithFileTypes ,
1615+ /**
1616+ * Function to filter out files/directories or a
1617+ * list of glob patterns to be excluded. If a function is provided, return
1618+ * `true` to exclude the item, `false` to include it.
1619+ * @default undefined
1620+ */
1621+ exclude ?:
1622+ | ( ( fileName : Node$Conditional < WithFileTypes , Dirent, string > ) => boolean )
1623+ | $ReadOnlyArray < string> ,
1624+ ...
1625+ } > ;
1626+
1627+ /**
1628+ * Retrieves the files matching the specified pattern.
1629+ *
1630+ * ```js
1631+ * import { glob } from 'node:fs';
1632+ *
1633+ * glob('*.js', (err, matches) => {
1634+ * if (err) throw err;
1635+ * console.log(matches);
1636+ * });
1637+ * ```
1638+ * @since v22.0.0
1639+ */
1640+ declare function glob (
1641+ pattern : string | $ReadOnlyArray < string > ,
1642+ callback : ( err : ?ErrnoError , matches : Array < string > ) => void ,
1643+ ) : void ;
1644+
1645+ declare function glob < WithFileTypes : boolean = false > (
1646+ pattern : string | $ReadOnlyArray < string > ,
1647+ options : GlobOptions < WithFileTypes > ,
1648+ callback : (
1649+ err : ?ErrnoError ,
1650+ matches : Node$Conditional < WithFileTypes , Array < Dirent > , Array < string >> ,
1651+ ) = > void ,
1652+ ) : void ;
1653+
1654+ /**
1655+ * ```js
1656+ * import { globSync } from 'node:fs';
1657+ *
1658+ * console.log(globSync('*.js'));
1659+ * ```
1660+ * @since v22.0.0
1661+ * @returns paths of files that match the pattern.
1662+ */
1663+ declare function globSync < WithFileTypes : boolean = false > (
1664+ pattern : string | $ReadOnlyArray < string > ,
1665+ options ?: GlobOptions < WithFileTypes > ,
1666+ ) : Node$Conditional < WithFileTypes , Array < Dirent > , Array < string >> ;
1667+
15971668 declare var F_OK : number ;
15981669 declare var R_OK : number ;
15991670 declare var W_OK : number ;
@@ -1725,6 +1796,14 @@ declare module 'fs' {
17251796 atime : number | string | Date ,
17261797 mtime : number | string | Date ,
17271798 ) : Promise < void > ,
1799+ glob < WithFileTypes : boolean = false > (
1800+ pattern : string | $ReadOnlyArray < string > ,
1801+ options ?: GlobOptions < WithFileTypes > ,
1802+ ) : Node$Conditional <
1803+ WithFileTypes ,
1804+ AsyncIterator < Dirent > ,
1805+ AsyncIterator < string > ,
1806+ > ,
17281807 lchmod ( path : FSPromisePath , mode : number ) : Promise < void > ,
17291808 lchown ( path : FSPromisePath , uid : number , guid : number ) : Promise < void > ,
17301809 link ( existingPath : FSPromisePath , newPath : FSPromisePath ) : Promise < void > ,
0 commit comments