123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- /// <reference types="node" />
- import { Minimatch } from 'minimatch';
- import Minipass from 'minipass';
- import { Path, PathScurry } from 'path-scurry';
- import { Ignore } from './ignore.js';
- import { Pattern } from './pattern.js';
- export type MatchSet = Minimatch['set'];
- export type GlobParts = Exclude<Minimatch['globParts'], undefined>;
- /**
- * A `GlobOptions` object may be provided to any of the exported methods, and
- * must be provided to the `Glob` constructor.
- *
- * All options are optional, boolean, and false by default, unless otherwise
- * noted.
- *
- * All resolved options are added to the Glob object as properties.
- *
- * If you are running many `glob` operations, you can pass a Glob object as the
- * `options` argument to a subsequent operation to share the previously loaded
- * cache.
- */
- export interface GlobOptions {
- /**
- * Set to true to always receive absolute paths for
- * matched files. This does _not_ make an extra system call to get
- * the realpath, it only does string path resolution.
- *
- * By default, when this option is not set, absolute paths are
- * returned for patterns that are absolute, and otherwise paths
- * are returned that are relative to the `cwd` setting.
- *
- * Conflicts with {@link withFileTypes}
- */
- absolute?: boolean;
- /**
- * Set to false to enable {@link windowsPathsNoEscape}
- *
- * @deprecated
- */
- allowWindowsEscape?: boolean;
- /**
- * The current working directory in which to search. Defaults to
- * `process.cwd()`.
- *
- * May be eiher a string path or a `file://` URL object or string.
- */
- cwd?: string | URL;
- /**
- * Include `.dot` files in normal matches and `globstar`
- * matches. Note that an explicit dot in a portion of the pattern
- * will always match dot files.
- */
- dot?: boolean;
- /**
- * Follow symlinked directories when expanding `**`
- * patterns. This can result in a lot of duplicate references in
- * the presence of cyclic links, and make performance quite bad.
- *
- * By default, a `**` in a pattern will follow 1 symbolic link if
- * it is not the first item in the pattern, or none if it is the
- * first item in the pattern, following the same behavior as Bash.
- */
- follow?: boolean;
- /**
- * A glob pattern or array of glob patterns to exclude from matches. To
- * ignore all children within a directory, as well as the entry itself,
- * append `/**'` to the ignore pattern.
- */
- ignore?: string | string[] | Ignore;
- /**
- * Add a `/` character to directory matches. Note that this requires
- * additional stat calls in some cases.
- */
- mark?: boolean;
- /**
- * Perform a basename-only match if the pattern does not contain any slash
- * characters. That is, `*.js` would be treated as equivalent to
- * `**\/*.js`, matching all js files in all directories.
- */
- matchBase?: boolean;
- /**
- * Do not expand `{a,b}` and `{1..3}` brace sets.
- */
- nobrace?: boolean;
- /**
- * Perform a case-insensitive match. This defaults to `true` on macOS and
- * Windows systems, and `false` on all others.
- *
- * **Note** `nocase` should only be explicitly set when it is
- * known that the filesystem's case sensitivity differs from the
- * platform default. If set `true` on case-sensitive file
- * systems, or `false` on case-insensitive file systems, then the
- * walk may return more or less results than expected.
- */
- nocase?: boolean;
- /**
- * Do not match directories, only files. (Note: to match
- * _only_ directories, put a `/` at the end of the pattern.)
- */
- nodir?: boolean;
- /**
- * Do not match "extglob" patterns such as `+(a|b)`.
- */
- noext?: boolean;
- /**
- * Do not match `**` against multiple filenames. (Ie, treat it as a normal
- * `*` instead.)
- *
- * Conflicts with {@link matchBase}
- */
- noglobstar?: boolean;
- /**
- * Defaults to value of `process.platform` if available, or `'linux'` if
- * not. Setting `platform:'win32'` on non-Windows systems may cause strange
- * behavior.
- */
- platform?: NodeJS.Platform;
- /**
- * Set to true to call `fs.realpath` on all of the
- * results. In the case of an entry that cannot be resolved, the
- * entry is omitted. This incurs a slight performance penalty, of
- * course, because of the added system calls.
- */
- realpath?: boolean;
- /**
- * A [PathScurry](http://npm.im/path-scurry) object used
- * to traverse the file system. If the `nocase` option is set
- * explicitly, then any provided `scurry` object must match this
- * setting.
- */
- scurry?: PathScurry;
- /**
- * An AbortSignal which will cancel the Glob walk when
- * triggered.
- */
- signal?: AbortSignal;
- /**
- * Use `\\` as a path separator _only_, and
- * _never_ as an escape character. If set, all `\\` characters are
- * replaced with `/` in the pattern.
- *
- * Note that this makes it **impossible** to match against paths
- * containing literal glob pattern characters, but allows matching
- * with patterns constructed using `path.join()` and
- * `path.resolve()` on Windows platforms, mimicking the (buggy!)
- * behavior of Glob v7 and before on Windows. Please use with
- * caution, and be mindful of [the caveat below about Windows
- * paths](#windows). (For legacy reasons, this is also set if
- * `allowWindowsEscape` is set to the exact value `false`.)
- */
- windowsPathsNoEscape?: boolean;
- /**
- * Return [PathScurry](http://npm.im/path-scurry)
- * `Path` objects instead of strings. These are similar to a
- * NodeJS `Dirent` object, but with additional methods and
- * properties.
- *
- * Conflicts with {@link absolute}
- */
- withFileTypes?: boolean;
- }
- export type GlobOptionsWithFileTypesTrue = GlobOptions & {
- withFileTypes: true;
- absolute?: false;
- };
- export type GlobOptionsWithFileTypesFalse = GlobOptions & {
- withFileTypes?: false;
- };
- export type GlobOptionsWithFileTypesUnset = GlobOptions & {
- withFileTypes?: undefined;
- };
- export type Result<Opts> = Opts extends GlobOptionsWithFileTypesTrue ? Path : Opts extends GlobOptionsWithFileTypesFalse ? string : Opts extends GlobOptionsWithFileTypesUnset ? string : string | Path;
- export type Results<Opts> = Result<Opts>[];
- export type FileTypes<Opts> = Opts extends GlobOptionsWithFileTypesTrue ? true : Opts extends GlobOptionsWithFileTypesFalse ? false : Opts extends GlobOptionsWithFileTypesUnset ? false : boolean;
- /**
- * An object that can perform glob pattern traversals.
- */
- export declare class Glob<Opts extends GlobOptions> implements GlobOptions {
- absolute: boolean;
- cwd: string;
- dot: boolean;
- follow: boolean;
- ignore?: Ignore;
- mark: boolean;
- matchBase: boolean;
- nobrace: boolean;
- nocase: boolean;
- nodir: boolean;
- noext: boolean;
- noglobstar: boolean;
- pattern: string[];
- platform: NodeJS.Platform;
- realpath: boolean;
- scurry: PathScurry;
- signal?: AbortSignal;
- windowsPathsNoEscape: boolean;
- withFileTypes: FileTypes<Opts>;
- /**
- * The options provided to the constructor.
- */
- opts: Opts;
- /**
- * An array of parsed immutable {@link Pattern} objects.
- */
- patterns: Pattern[];
- /**
- * All options are stored as properties on the `Glob` object.
- *
- * See {@link GlobOptions} for full options descriptions.
- *
- * Note that a previous `Glob` object can be passed as the
- * `GlobOptions` to another `Glob` instantiation to re-use settings
- * and caches with a new pattern.
- *
- * Traversal functions can be called multiple times to run the walk
- * again.
- */
- constructor(pattern: string | string[], opts: Opts);
- /**
- * Returns a Promise that resolves to the results array.
- */
- walk(): Promise<Results<Opts>>;
- /**
- * synchronous {@link Glob.walk}
- */
- walkSync(): Results<Opts>;
- /**
- * Stream results asynchronously.
- */
- stream(): Minipass<Result<Opts>, Result<Opts>>;
- /**
- * Stream results synchronously.
- */
- streamSync(): Minipass<Result<Opts>, Result<Opts>>;
- /**
- * Default sync iteration function. Returns a Generator that
- * iterates over the results.
- */
- iterateSync(): Generator<Result<Opts>, void, void>;
- [Symbol.iterator](): Generator<Result<Opts>, void, void>;
- /**
- * Default async iteration function. Returns an AsyncGenerator that
- * iterates over the results.
- */
- iterate(): AsyncGenerator<Result<Opts>, void, void>;
- [Symbol.asyncIterator](): AsyncGenerator<Result<Opts>, void, void>;
- }
|