1 | import {URL} from 'node:url'; // TODO: Remove this when https://github.com/DefinitelyTyped/DefinitelyTyped/issues/34960 is fixed.
|
2 | import {Options as FastGlobOptions, Entry} from 'fast-glob';
|
3 |
|
4 | export type GlobEntry = Entry;
|
5 |
|
6 | export interface GlobTask {
|
7 | readonly pattern: string;
|
8 | readonly options: Options;
|
9 | }
|
10 |
|
11 | export type ExpandDirectoriesOption =
|
12 | | boolean
|
13 | | readonly string[]
|
14 | | {files?: readonly string[]; extensions?: readonly string[]};
|
15 |
|
16 | type FastGlobOptionsWithoutCwd = Omit<FastGlobOptions, 'cwd'>;
|
17 |
|
18 | export interface Options extends FastGlobOptionsWithoutCwd {
|
19 | /**
|
20 | If set to `true`, `globby` will automatically glob directories for you. If you define an `Array` it will only glob files that matches the patterns inside the `Array`. You can also define an `Object` with `files` and `extensions` like in the example below.
|
21 |
|
22 | Note that if you set this option to `false`, you won't get back matched directories unless you set `onlyFiles: false`.
|
23 |
|
24 | @default true
|
25 |
|
26 | @example
|
27 | ```
|
28 | import {globby} from 'globby';
|
29 |
|
30 | const paths = await globby('images', {
|
31 | expandDirectories: {
|
32 | files: ['cat', 'unicorn', '*.jpg'],
|
33 | extensions: ['png']
|
34 | }
|
35 | });
|
36 |
|
37 | console.log(paths);
|
38 | //=> ['cat.png', 'unicorn.png', 'cow.jpg', 'rainbow.jpg']
|
39 | ```
|
40 | */
|
41 | readonly expandDirectories?: ExpandDirectoriesOption;
|
42 |
|
43 | /**
|
44 | Respect ignore patterns in `.gitignore` files that apply to the globbed files.
|
45 |
|
46 | @default false
|
47 | */
|
48 | readonly gitignore?: boolean;
|
49 |
|
50 | /**
|
51 | The current working directory in which to search.
|
52 |
|
53 | @default process.cwd()
|
54 | */
|
55 | readonly cwd?: URL | string;
|
56 | }
|
57 |
|
58 | export interface GitignoreOptions {
|
59 | readonly cwd?: URL | string;
|
60 | readonly ignore?: readonly string[];
|
61 | }
|
62 |
|
63 | export type GlobbyFilterFunction = (path: URL | string) => boolean;
|
64 |
|
65 | /**
|
66 | Find files and directories using glob patterns.
|
67 |
|
68 | Note that glob patterns can only contain forward-slashes, not backward-slashes, so if you want to construct a glob pattern from path components, you need to use `path.posix.join()` instead of `path.join()`.
|
69 |
|
70 | @param patterns - See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).
|
71 | @param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-3) in addition to the ones in this package.
|
72 | @returns The matching paths.
|
73 |
|
74 | @example
|
75 | ```
|
76 | import {globby} from 'globby';
|
77 |
|
78 | const paths = await globby(['*', '!cake']);
|
79 |
|
80 | console.log(paths);
|
81 | //=> ['unicorn', 'rainbow']
|
82 | ```
|
83 | */
|
84 | export function globby(
|
85 | patterns: string | readonly string[],
|
86 | options: Options & {objectMode: true}
|
87 | ): Promise<GlobEntry[]>;
|
88 | export function globby(
|
89 | patterns: string | readonly string[],
|
90 | options?: Options
|
91 | ): Promise<string[]>;
|
92 |
|
93 | /**
|
94 | Find files and directories using glob patterns.
|
95 |
|
96 | Note that glob patterns can only contain forward-slashes, not backward-slashes, so if you want to construct a glob pattern from path components, you need to use `path.posix.join()` instead of `path.join()`.
|
97 |
|
98 | @param patterns - See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).
|
99 | @param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-3) in addition to the ones in this package.
|
100 | @returns The matching paths.
|
101 | */
|
102 | export function globbySync(
|
103 | patterns: string | readonly string[],
|
104 | options: Options & {objectMode: true}
|
105 | ): GlobEntry[];
|
106 | export function globbySync(
|
107 | patterns: string | readonly string[],
|
108 | options?: Options
|
109 | ): string[];
|
110 |
|
111 | /**
|
112 | Find files and directories using glob patterns.
|
113 |
|
114 | Note that glob patterns can only contain forward-slashes, not backward-slashes, so if you want to construct a glob pattern from path components, you need to use `path.posix.join()` instead of `path.join()`.
|
115 |
|
116 | @param patterns - See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).
|
117 | @param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-3) in addition to the ones in this package.
|
118 | @returns The stream of matching paths.
|
119 |
|
120 | @example
|
121 | ```
|
122 | import {globbyStream} from 'globby';
|
123 |
|
124 | for await (const path of globbyStream('*.tmp')) {
|
125 | console.log(path);
|
126 | }
|
127 | ```
|
128 | */
|
129 | export function globbyStream(
|
130 | patterns: string | readonly string[],
|
131 | options?: Options
|
132 | ): NodeJS.ReadableStream;
|
133 |
|
134 | /**
|
135 | Note that you should avoid running the same tasks multiple times as they contain a file system cache. Instead, run this method each time to ensure file system changes are taken into consideration.
|
136 |
|
137 | @param patterns - See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).
|
138 | @param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-3) in addition to the ones in this package.
|
139 | @returns An object in the format `{pattern: string, options: object}`, which can be passed as arguments to [`fast-glob`](https://github.com/mrmlnc/fast-glob). This is useful for other globbing-related packages.
|
140 | */
|
141 | export function generateGlobTasks(
|
142 | patterns: string | readonly string[],
|
143 | options?: Options
|
144 | ): GlobTask[];
|
145 |
|
146 | /**
|
147 | Note that the options affect the results.
|
148 |
|
149 | This function is backed by [`fast-glob`](https://github.com/mrmlnc/fast-glob#isdynamicpatternpattern-options).
|
150 |
|
151 | @param patterns - See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).
|
152 | @param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-3).
|
153 | @returns Whether there are any special glob characters in the `patterns`.
|
154 | */
|
155 | export function isDynamicPattern(
|
156 | patterns: string | readonly string[],
|
157 | options?: FastGlobOptionsWithoutCwd & {
|
158 | /**
|
159 | The current working directory in which to search.
|
160 |
|
161 | @default process.cwd()
|
162 | */
|
163 | readonly cwd?: URL | string;
|
164 | }
|
165 | ): boolean;
|
166 |
|
167 | /**
|
168 | `.gitignore` files matched by the ignore config are not used for the resulting filter function.
|
169 |
|
170 | @returns A filter function indicating whether a given path is ignored via a `.gitignore` file.
|
171 |
|
172 | @example
|
173 | ```
|
174 | import {isGitIgnored} from 'globby';
|
175 |
|
176 | const isIgnored = await isGitIgnored();
|
177 |
|
178 | console.log(isIgnored('some/file'));
|
179 | ```
|
180 | */
|
181 | export function isGitIgnored(options?: GitignoreOptions): Promise<GlobbyFilterFunction>;
|
182 |
|
183 | /**
|
184 | @see isGitIgnored
|
185 |
|
186 | @returns A filter function indicating whether a given path is ignored via a `.gitignore` file.
|
187 | */
|
188 | export function isGitIgnoredSync(options?: GitignoreOptions): GlobbyFilterFunction;
|