UNPKG

3.78 kBTypeScriptView Raw
1/**
2 * Single-use utility classes to provide functionality to the {@link Glob}
3 * methods.
4 *
5 * @module
6 */
7import { Minipass } from 'minipass';
8import { Path } from 'path-scurry';
9import { IgnoreLike } from './ignore.js';
10import { Pattern } from './pattern.js';
11import { Processor } from './processor.js';
12export interface GlobWalkerOpts {
13 absolute?: boolean;
14 allowWindowsEscape?: boolean;
15 cwd?: string | URL;
16 dot?: boolean;
17 dotRelative?: boolean;
18 follow?: boolean;
19 ignore?: string | string[] | IgnoreLike;
20 mark?: boolean;
21 matchBase?: boolean;
22 maxDepth?: number;
23 nobrace?: boolean;
24 nocase?: boolean;
25 nodir?: boolean;
26 noext?: boolean;
27 noglobstar?: boolean;
28 platform?: NodeJS.Platform;
29 posix?: boolean;
30 realpath?: boolean;
31 root?: string;
32 stat?: boolean;
33 signal?: AbortSignal;
34 windowsPathsNoEscape?: boolean;
35 withFileTypes?: boolean;
36 includeChildMatches?: boolean;
37}
38export type GWOFileTypesTrue = GlobWalkerOpts & {
39 withFileTypes: true;
40};
41export type GWOFileTypesFalse = GlobWalkerOpts & {
42 withFileTypes: false;
43};
44export type GWOFileTypesUnset = GlobWalkerOpts & {
45 withFileTypes?: undefined;
46};
47export type Result<O extends GlobWalkerOpts> = O extends GWOFileTypesTrue ? Path : O extends GWOFileTypesFalse ? string : O extends GWOFileTypesUnset ? string : Path | string;
48export type Matches<O extends GlobWalkerOpts> = O extends GWOFileTypesTrue ? Set<Path> : O extends GWOFileTypesFalse ? Set<string> : O extends GWOFileTypesUnset ? Set<string> : Set<Path | string>;
49export type MatchStream<O extends GlobWalkerOpts> = Minipass<Result<O>, Result<O>>;
50/**
51 * basic walking utilities that all the glob walker types use
52 */
53export declare abstract class GlobUtil<O extends GlobWalkerOpts = GlobWalkerOpts> {
54 #private;
55 path: Path;
56 patterns: Pattern[];
57 opts: O;
58 seen: Set<Path>;
59 paused: boolean;
60 aborted: boolean;
61 signal?: AbortSignal;
62 maxDepth: number;
63 includeChildMatches: boolean;
64 constructor(patterns: Pattern[], path: Path, opts: O);
65 pause(): void;
66 resume(): void;
67 onResume(fn: () => any): void;
68 matchCheck(e: Path, ifDir: boolean): Promise<Path | undefined>;
69 matchCheckTest(e: Path | undefined, ifDir: boolean): Path | undefined;
70 matchCheckSync(e: Path, ifDir: boolean): Path | undefined;
71 abstract matchEmit(p: Result<O>): void;
72 abstract matchEmit(p: string | Path): void;
73 matchFinish(e: Path, absolute: boolean): void;
74 match(e: Path, absolute: boolean, ifDir: boolean): Promise<void>;
75 matchSync(e: Path, absolute: boolean, ifDir: boolean): void;
76 walkCB(target: Path, patterns: Pattern[], cb: () => any): void;
77 walkCB2(target: Path, patterns: Pattern[], processor: Processor, cb: () => any): any;
78 walkCB3(target: Path, entries: Path[], processor: Processor, cb: () => any): void;
79 walkCBSync(target: Path, patterns: Pattern[], cb: () => any): void;
80 walkCB2Sync(target: Path, patterns: Pattern[], processor: Processor, cb: () => any): any;
81 walkCB3Sync(target: Path, entries: Path[], processor: Processor, cb: () => any): void;
82}
83export declare class GlobWalker<O extends GlobWalkerOpts = GlobWalkerOpts> extends GlobUtil<O> {
84 matches: Set<Result<O>>;
85 constructor(patterns: Pattern[], path: Path, opts: O);
86 matchEmit(e: Result<O>): void;
87 walk(): Promise<Set<Result<O>>>;
88 walkSync(): Set<Result<O>>;
89}
90export declare class GlobStream<O extends GlobWalkerOpts = GlobWalkerOpts> extends GlobUtil<O> {
91 results: Minipass<Result<O>, Result<O>>;
92 constructor(patterns: Pattern[], path: Path, opts: O);
93 matchEmit(e: Result<O>): void;
94 stream(): MatchStream<O>;
95 streamSync(): MatchStream<O>;
96}
97//# sourceMappingURL=walker.d.ts.map
\No newline at end of file