1/// <reference types="node" resolution-mode="require"/> 2import { Minimatch } from 'minimatch'; 3import { Minipass } from 'minipass'; 4import { FSOption, Path, PathScurry } from 'path-scurry'; 5import { IgnoreLike } from './ignore.js'; 6import { Pattern } from './pattern.js'; 7export type MatchSet = Minimatch['set']; 8export type GlobParts = Exclude<Minimatch['globParts'], undefined>; 9/** 10 * A `GlobOptions` object may be provided to any of the exported methods, and 11 * must be provided to the `Glob` constructor. 12 * 13 * All options are optional, boolean, and false by default, unless otherwise 14 * noted. 15 * 16 * All resolved options are added to the Glob object as properties. 17 * 18 * If you are running many `glob` operations, you can pass a Glob object as the 19 * `options` argument to a subsequent operation to share the previously loaded 20 * cache. 21 */ 22export interface GlobOptions { 23 /** 24 * Set to `true` to always receive absolute paths for 25 * matched files. Set to `false` to always return relative paths. 26 * 27 * When this option is not set, absolute paths are returned for patterns 28 * that are absolute, and otherwise paths are returned that are relative 29 * to the `cwd` setting. 30 * 31 * This does _not_ make an extra system call to get 32 * the realpath, it only does string path resolution. 33 * 34 * Conflicts with {@link withFileTypes} 35 */ 36 absolute?: boolean; 37 /** 38 * Set to false to enable {@link windowsPathsNoEscape} 39 * 40 * @deprecated 41 */ 42 allowWindowsEscape?: boolean; 43 /** 44 * The current working directory in which to search. Defaults to 45 * `process.cwd()`. 46 * 47 * May be eiher a string path or a `file://` URL object or string. 48 */ 49 cwd?: string | URL; 50 /** 51 * Include `.dot` files in normal matches and `globstar` 52 * matches. Note that an explicit dot in a portion of the pattern 53 * will always match dot files. 54 */ 55 dot?: boolean; 56 /** 57 * Prepend all relative path strings with `./` (or `.\` on Windows). 58 * 59 * Without this option, returned relative paths are "bare", so instead of 60 * returning `'./foo/bar'`, they are returned as `'foo/bar'`. 61 * 62 * Relative patterns starting with `'../'` are not prepended with `./`, even 63 * if this option is set. 64 */ 65 dotRelative?: boolean; 66 /** 67 * Follow symlinked directories when expanding `**` 68 * patterns. This can result in a lot of duplicate references in 69 * the presence of cyclic links, and make performance quite bad. 70 * 71 * By default, a `**` in a pattern will follow 1 symbolic link if 72 * it is not the first item in the pattern, or none if it is the 73 * first item in the pattern, following the same behavior as Bash. 74 */ 75 follow?: boolean; 76 /** 77 * string or string[], or an object with `ignore` and `ignoreChildren` 78 * methods. 79 * 80 * If a string or string[] is provided, then this is treated as a glob 81 * pattern or array of glob patterns to exclude from matches. To ignore all 82 * children within a directory, as well as the entry itself, append `'/**'` 83 * to the ignore pattern. 84 * 85 * **Note** `ignore` patterns are _always_ in `dot:true` mode, regardless of 86 * any other settings. 87 * 88 * If an object is provided that has `ignored(path)` and/or 89 * `childrenIgnored(path)` methods, then these methods will be called to 90 * determine whether any Path is a match or if its children should be 91 * traversed, respectively. 92 */ 93 ignore?: string | string[] | IgnoreLike; 94 /** 95 * Treat brace expansion like `{a,b}` as a "magic" pattern. Has no 96 * effect if {@link nobrace} is set. 97 * 98 * Only has effect on the {@link hasMagic} function. 99 */ 100 magicalBraces?: boolean; 101 /** 102 * Add a `/` character to directory matches. Note that this requires 103 * additional stat calls in some cases. 104 */ 105 mark?: boolean; 106 /** 107 * Perform a basename-only match if the pattern does not contain any slash 108 * characters. That is, `*.js` would be treated as equivalent to 109 * `**\/*.js`, matching all js files in all directories. 110 */ 111 matchBase?: boolean; 112 /** 113 * Limit the directory traversal to a given depth below the cwd. 114 * Note that this does NOT prevent traversal to sibling folders, 115 * root patterns, and so on. It only limits the maximum folder depth 116 * that the walk will descend, relative to the cwd. 117 */ 118 maxDepth?: number; 119 /** 120 * Do not expand `{a,b}` and `{1..3}` brace sets. 121 */ 122 nobrace?: boolean; 123 /** 124 * Perform a case-insensitive match. This defaults to `true` on macOS and 125 * Windows systems, and `false` on all others. 126 * 127 * **Note** `nocase` should only be explicitly set when it is 128 * known that the filesystem's case sensitivity differs from the 129 * platform default. If set `true` on case-sensitive file 130 * systems, or `false` on case-insensitive file systems, then the 131 * walk may return more or less results than expected. 132 */ 133 nocase?: boolean; 134 /** 135 * Do not match directories, only files. (Note: to match 136 * _only_ directories, put a `/` at the end of the pattern.) 137 */ 138 nodir?: boolean; 139 /** 140 * Do not match "extglob" patterns such as `+(a|b)`. 141 */ 142 noext?: boolean; 143 /** 144 * Do not match `**` against multiple filenames. (Ie, treat it as a normal 145 * `*` instead.) 146 * 147 * Conflicts with {@link matchBase} 148 */ 149 noglobstar?: boolean; 150 /** 151 * Defaults to value of `process.platform` if available, or `'linux'` if 152 * not. Setting `platform:'win32'` on non-Windows systems may cause strange 153 * behavior. 154 */ 155 platform?: NodeJS.Platform; 156 /** 157 * Set to true to call `fs.realpath` on all of the 158 * results. In the case of an entry that cannot be resolved, the 159 * entry is omitted. This incurs a slight performance penalty, of 160 * course, because of the added system calls. 161 */ 162 realpath?: boolean; 163 /** 164 * 165 * A string path resolved against the `cwd` option, which 166 * is used as the starting point for absolute patterns that start 167 * with `/`, (but not drive letters or UNC paths on Windows). 168 * 169 * Note that this _doesn't_ necessarily limit the walk to the 170 * `root` directory, and doesn't affect the cwd starting point for 171 * non-absolute patterns. A pattern containing `..` will still be 172 * able to traverse out of the root directory, if it is not an 173 * actual root directory on the filesystem, and any non-absolute 174 * patterns will be matched in the `cwd`. For example, the 175 * pattern `/../*` with `{root:'/some/path'}` will return all 176 * files in `/some`, not all files in `/some/path`. The pattern 177 * `*` with `{root:'/some/path'}` will return all the entries in 178 * the cwd, not the entries in `/some/path`. 179 * 180 * To start absolute and non-absolute patterns in the same 181 * path, you can use `{root:''}`. However, be aware that on 182 * Windows systems, a pattern like `x:/*` or `//host/share/*` will 183 * _always_ start in the `x:/` or `//host/share` directory, 184 * regardless of the `root` setting. 185 */ 186 root?: string; 187 /** 188 * A [PathScurry](http://npm.im/path-scurry) object used 189 * to traverse the file system. If the `nocase` option is set 190 * explicitly, then any provided `scurry` object must match this 191 * setting. 192 */ 193 scurry?: PathScurry; 194 /** 195 * Call `lstat()` on all entries, whether required or not to determine 196 * if it's a valid match. When used with {@link withFileTypes}, this means 197 * that matches will include data such as modified time, permissions, and 198 * so on. Note that this will incur a performance cost due to the added 199 * system calls. 200 */ 201 stat?: boolean; 202 /** 203 * An AbortSignal which will cancel the Glob walk when 204 * triggered. 205 */ 206 signal?: AbortSignal; 207 /** 208 * Use `\\` as a path separator _only_, and 209 * _never_ as an escape character. If set, all `\\` characters are 210 * replaced with `/` in the pattern. 211 * 212 * Note that this makes it **impossible** to match against paths 213 * containing literal glob pattern characters, but allows matching 214 * with patterns constructed using `path.join()` and 215 * `path.resolve()` on Windows platforms, mimicking the (buggy!) 216 * behavior of Glob v7 and before on Windows. Please use with 217 * caution, and be mindful of [the caveat below about Windows 218 * paths](#windows). (For legacy reasons, this is also set if 219 * `allowWindowsEscape` is set to the exact value `false`.) 220 */ 221 windowsPathsNoEscape?: boolean; 222 /** 223 * Return [PathScurry](http://npm.im/path-scurry) 224 * `Path` objects instead of strings. These are similar to a 225 * NodeJS `Dirent` object, but with additional methods and 226 * properties. 227 * 228 * Conflicts with {@link absolute} 229 */ 230 withFileTypes?: boolean; 231 /** 232 * An fs implementation to override some or all of the defaults. See 233 * http://npm.im/path-scurry for details about what can be overridden. 234 */ 235 fs?: FSOption; 236 /** 237 * Just passed along to Minimatch. Note that this makes all pattern 238 * matching operations slower and *extremely* noisy. 239 */ 240 debug?: boolean; 241 /** 242 * Return `/` delimited paths, even on Windows. 243 * 244 * On posix systems, this has no effect. But, on Windows, it means that 245 * paths will be `/` delimited, and absolute paths will be their full 246 * resolved UNC forms, eg instead of `'C:\\foo\\bar'`, it would return 247 * `'//?/C:/foo/bar'` 248 */ 249 posix?: boolean; 250} 251export type GlobOptionsWithFileTypesTrue = GlobOptions & { 252 withFileTypes: true; 253 absolute?: undefined; 254 mark?: undefined; 255 posix?: undefined; 256}; 257export type GlobOptionsWithFileTypesFalse = GlobOptions & { 258 withFileTypes?: false; 259}; 260export type GlobOptionsWithFileTypesUnset = GlobOptions & { 261 withFileTypes?: undefined; 262}; 263export type Result<Opts> = Opts extends GlobOptionsWithFileTypesTrue ? Path : Opts extends GlobOptionsWithFileTypesFalse ? string : Opts extends GlobOptionsWithFileTypesUnset ? string : string | Path; 264export type Results<Opts> = Result<Opts>[]; 265export type FileTypes<Opts> = Opts extends GlobOptionsWithFileTypesTrue ? true : Opts extends GlobOptionsWithFileTypesFalse ? false : Opts extends GlobOptionsWithFileTypesUnset ? false : boolean; 266/** 267 * An object that can perform glob pattern traversals. 268 */ 269export declare class Glob<Opts extends GlobOptions> implements GlobOptions { 270 absolute?: boolean; 271 cwd: string; 272 root?: string; 273 dot: boolean; 274 dotRelative: boolean; 275 follow: boolean; 276 ignore?: string | string[] | IgnoreLike; 277 magicalBraces: boolean; 278 mark?: boolean; 279 matchBase: boolean; 280 maxDepth: number; 281 nobrace: boolean; 282 nocase: boolean; 283 nodir: boolean; 284 noext: boolean; 285 noglobstar: boolean; 286 pattern: string[]; 287 platform: NodeJS.Platform; 288 realpath: boolean; 289 scurry: PathScurry; 290 stat: boolean; 291 signal?: AbortSignal; 292 windowsPathsNoEscape: boolean; 293 withFileTypes: FileTypes<Opts>; 294 /** 295 * The options provided to the constructor. 296 */ 297 opts: Opts; 298 /** 299 * An array of parsed immutable {@link Pattern} objects. 300 */ 301 patterns: Pattern[]; 302 /** 303 * All options are stored as properties on the `Glob` object. 304 * 305 * See {@link GlobOptions} for full options descriptions. 306 * 307 * Note that a previous `Glob` object can be passed as the 308 * `GlobOptions` to another `Glob` instantiation to re-use settings 309 * and caches with a new pattern. 310 * 311 * Traversal functions can be called multiple times to run the walk 312 * again. 313 */ 314 constructor(pattern: string | string[], opts: Opts); 315 /** 316 * Returns a Promise that resolves to the results array. 317 */ 318 walk(): Promise<Results<Opts>>; 319 /** 320 * synchronous {@link Glob.walk} 321 */ 322 walkSync(): Results<Opts>; 323 /** 324 * Stream results asynchronously. 325 */ 326 stream(): Minipass<Result<Opts>, Result<Opts>>; 327 /** 328 * Stream results synchronously. 329 */ 330 streamSync(): Minipass<Result<Opts>, Result<Opts>>; 331 /** 332 * Default sync iteration function. Returns a Generator that 333 * iterates over the results. 334 */ 335 iterateSync(): Generator<Result<Opts>, void, void>; 336 [Symbol.iterator](): Generator<Result<Opts>, void, void>; 337 /** 338 * Default async iteration function. Returns an AsyncGenerator that 339 * iterates over the results. 340 */ 341 iterate(): AsyncGenerator<Result<Opts>, void, void>; 342 [Symbol.asyncIterator](): AsyncGenerator<Result<Opts>, void, void>; 343} 344//# sourceMappingURL=glob.d.ts.map