walker.d.ts 3.9 KB

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