1 | import type FastGlob from 'fast-glob';
|
2 | import {type Options as FastGlobOptions, type Entry} from 'fast-glob';
|
3 |
|
4 | export type GlobEntry = Entry;
|
5 |
|
6 | export type GlobTask = {
|
7 | readonly patterns: 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 type Options = {
|
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 | Glob patterns to look for ignore files, which are then used to ignore globbed files.
|
52 |
|
53 | This is a more generic form of the `gitignore` option, allowing you to find ignore files with a [compatible syntax](http://git-scm.com/docs/gitignore). For instance, this works with Babel's `.babelignore`, Prettier's `.prettierignore`, or ESLint's `.eslintignore` files.
|
54 |
|
55 | @default undefined
|
56 | */
|
57 | readonly ignoreFiles?: string | readonly string[];
|
58 |
|
59 | /**
|
60 | The current working directory in which to search.
|
61 |
|
62 | @default process.cwd()
|
63 | */
|
64 | readonly cwd?: URL | string;
|
65 | } & FastGlobOptionsWithoutCwd;
|
66 |
|
67 | export type GitignoreOptions = {
|
68 | readonly cwd?: URL | string;
|
69 | };
|
70 |
|
71 | export type GlobbyFilterFunction = (path: URL | string) => boolean;
|
72 |
|
73 | /**
|
74 | Find files and directories using glob patterns.
|
75 |
|
76 | 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()`.
|
77 |
|
78 | @param patterns - See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).
|
79 | @param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-3) in addition to the ones in this package.
|
80 | @returns The matching paths.
|
81 |
|
82 | @example
|
83 | ```
|
84 | import {globby} from 'globby';
|
85 |
|
86 | const paths = await globby(['*', '!cake']);
|
87 |
|
88 | console.log(paths);
|
89 | //=> ['unicorn', 'rainbow']
|
90 | ```
|
91 | */
|
92 | export function globby(
|
93 | patterns: string | readonly string[],
|
94 | options: Options & {objectMode: true}
|
95 | ): Promise<GlobEntry[]>;
|
96 | export function globby(
|
97 | patterns: string | readonly string[],
|
98 | options?: Options
|
99 | ): Promise<string[]>;
|
100 |
|
101 | /**
|
102 | Find files and directories using glob patterns.
|
103 |
|
104 | 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()`.
|
105 |
|
106 | @param patterns - See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).
|
107 | @param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-3) in addition to the ones in this package.
|
108 | @returns The matching paths.
|
109 | */
|
110 | export function globbySync(
|
111 | patterns: string | readonly string[],
|
112 | options: Options & {objectMode: true}
|
113 | ): GlobEntry[];
|
114 | export function globbySync(
|
115 | patterns: string | readonly string[],
|
116 | options?: Options
|
117 | ): string[];
|
118 |
|
119 | /**
|
120 | Find files and directories using glob patterns.
|
121 |
|
122 | 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()`.
|
123 |
|
124 | @param patterns - See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).
|
125 | @param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-3) in addition to the ones in this package.
|
126 | @returns The stream of matching paths.
|
127 |
|
128 | @example
|
129 | ```
|
130 | import {globbyStream} from 'globby';
|
131 |
|
132 | for await (const path of globbyStream('*.tmp')) {
|
133 | console.log(path);
|
134 | }
|
135 | ```
|
136 | */
|
137 | export function globbyStream(
|
138 | patterns: string | readonly string[],
|
139 | options?: Options
|
140 | ): NodeJS.ReadableStream;
|
141 |
|
142 | /**
|
143 | 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.
|
144 |
|
145 | @param patterns - See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).
|
146 | @param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-3) in addition to the ones in this package.
|
147 | @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.
|
148 | */
|
149 | export function generateGlobTasks(
|
150 | patterns: string | readonly string[],
|
151 | options?: Options
|
152 | ): Promise<GlobTask[]>;
|
153 |
|
154 | /**
|
155 | @see generateGlobTasks
|
156 |
|
157 | @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.
|
158 | */
|
159 | export function generateGlobTasksSync(
|
160 | patterns: string | readonly string[],
|
161 | options?: Options
|
162 | ): GlobTask[];
|
163 |
|
164 | /**
|
165 | Note that the options affect the results.
|
166 |
|
167 | This function is backed by [`fast-glob`](https://github.com/mrmlnc/fast-glob#isdynamicpatternpattern-options).
|
168 |
|
169 | @param patterns - See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).
|
170 | @param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-3).
|
171 | @returns Whether there are any special glob characters in the `patterns`.
|
172 | */
|
173 | export function isDynamicPattern(
|
174 | patterns: string | readonly string[],
|
175 | options?: FastGlobOptionsWithoutCwd & {
|
176 | /**
|
177 | The current working directory in which to search.
|
178 |
|
179 | @default process.cwd()
|
180 | */
|
181 | readonly cwd?: URL | string;
|
182 | }
|
183 | ): boolean;
|
184 |
|
185 | /**
|
186 | `.gitignore` files matched by the ignore config are not used for the resulting filter function.
|
187 |
|
188 | @returns A filter function indicating whether a given path is ignored via a `.gitignore` file.
|
189 |
|
190 | @example
|
191 | ```
|
192 | import {isGitIgnored} from 'globby';
|
193 |
|
194 | const isIgnored = await isGitIgnored();
|
195 |
|
196 | console.log(isIgnored('some/file'));
|
197 | ```
|
198 | */
|
199 | export function isGitIgnored(options?: GitignoreOptions): Promise<GlobbyFilterFunction>;
|
200 |
|
201 | /**
|
202 | @see isGitIgnored
|
203 |
|
204 | @returns A filter function indicating whether a given path is ignored via a `.gitignore` file.
|
205 | */
|
206 | export function isGitIgnoredSync(options?: GitignoreOptions): GlobbyFilterFunction;
|
207 |
|
208 | export function convertPathToPattern(source: string): FastGlob.Pattern;
|