UNPKG

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