|
1 | 1 | import {IOptions as NodeGlobOptions} from 'glob';
|
2 | 2 | import {Options as FastGlobOptions} from 'fast-glob';
|
3 | 3 |
|
4 |
| -export type ExpandDirectoriesOption = |
5 |
| - | boolean |
6 |
| - | ReadonlyArray<string> |
7 |
| - | {files: ReadonlyArray<string>; extensions: ReadonlyArray<string>}; |
| 4 | +declare namespace globby { |
| 5 | + type ExpandDirectoriesOption = |
| 6 | + | boolean |
| 7 | + | ReadonlyArray<string> |
| 8 | + | {files: ReadonlyArray<string>; extensions: ReadonlyArray<string>}; |
8 | 9 |
|
9 |
| -export interface GlobbyOptions extends FastGlobOptions { |
| 10 | + interface GlobbyOptions extends FastGlobOptions { |
| 11 | + /** |
| 12 | + 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. |
| 13 | +
|
| 14 | + Note that if you set this option to `false`, you won't get back matched directories unless you set `onlyFiles: false`. |
| 15 | +
|
| 16 | + @default true |
| 17 | +
|
| 18 | + @example |
| 19 | + ``` |
| 20 | + import globby = require('globby'); |
| 21 | +
|
| 22 | + (async () => { |
| 23 | + const paths = await globby('images', { |
| 24 | + expandDirectories: { |
| 25 | + files: ['cat', 'unicorn', '*.jpg'], |
| 26 | + extensions: ['png'] |
| 27 | + } |
| 28 | + }); |
| 29 | + console.log(paths); |
| 30 | + //=> ['cat.png', 'unicorn.png', 'cow.jpg', 'rainbow.jpg'] |
| 31 | + })(); |
| 32 | + ``` |
| 33 | + */ |
| 34 | + readonly expandDirectories?: ExpandDirectoriesOption; |
| 35 | + |
| 36 | + /** |
| 37 | + Respect ignore patterns in `.gitignore` files that apply to the globbed files. |
| 38 | +
|
| 39 | + @default false |
| 40 | + */ |
| 41 | + readonly gitignore?: boolean; |
| 42 | + } |
| 43 | + |
| 44 | + interface GlobTask { |
| 45 | + readonly pattern: string; |
| 46 | + readonly options: globby.GlobbyOptions; |
| 47 | + } |
| 48 | + |
| 49 | + interface GitignoreOptions { |
| 50 | + readonly cwd?: string; |
| 51 | + readonly ignore?: ReadonlyArray<string>; |
| 52 | + } |
| 53 | + |
| 54 | + type FilterFunction = (path: string) => boolean; |
| 55 | +} |
| 56 | + |
| 57 | +interface Gitignore { |
10 | 58 | /**
|
11 |
| - * 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. |
12 |
| - * |
13 |
| - * Note that if you set this option to `false`, you won't get back matched directories unless you set `onlyFiles: false`. |
14 |
| - * |
15 |
| - * @default true |
16 |
| - * |
17 |
| - * @example |
18 |
| - * |
19 |
| - * import globby from 'globby'; |
20 |
| - * |
21 |
| - * (async () => { |
22 |
| - * const paths = await globby('images', { |
23 |
| - * expandDirectories: { |
24 |
| - * files: ['cat', 'unicorn', '*.jpg'], |
25 |
| - * extensions: ['png'] |
26 |
| - * } |
27 |
| - * }); |
28 |
| - * console.log(paths); |
29 |
| - * //=> ['cat.png', 'unicorn.png', 'cow.jpg', 'rainbow.jpg'] |
30 |
| - * })(); |
31 |
| - */ |
32 |
| - readonly expandDirectories?: ExpandDirectoriesOption; |
| 59 | + `.gitignore` files matched by the ignore config are not used for the resulting filter function. |
| 60 | +
|
| 61 | + @returns A `Promise` for a filter function indicating whether a given path is ignored via a `.gitignore` file. |
| 62 | +
|
| 63 | + @example |
| 64 | + ``` |
| 65 | + import {gitignore} from 'globby'; |
| 66 | +
|
| 67 | + (async () => { |
| 68 | + const isIgnored = await gitignore(); |
| 69 | + console.log(isIgnored('some/file')); |
| 70 | + })(); |
| 71 | + ``` |
| 72 | + */ |
| 73 | + (options?: globby.GitignoreOptions): Promise<globby.FilterFunction>; |
33 | 74 |
|
34 | 75 | /**
|
35 |
| - * Respect ignore patterns in `.gitignore` files that apply to the globbed files. |
36 |
| - * |
37 |
| - * @default false |
38 |
| - */ |
39 |
| - readonly gitignore?: boolean; |
| 76 | + @returns A filter function indicating whether a given path is ignored via a `.gitignore` file. |
| 77 | + */ |
| 78 | + sync(options?: globby.GitignoreOptions): globby.FilterFunction; |
40 | 79 | }
|
41 | 80 |
|
42 |
| -/** |
43 |
| - * @param patterns - See supported `minimatch` [patterns](https://github.com/isaacs/minimatch#usage). |
44 |
| - * @param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-1) in addition to the ones in this package. |
45 |
| - * @returns A `Promise<Array>` of matching paths. |
46 |
| - */ |
47 |
| -export default function globby( |
48 |
| - patterns: string | ReadonlyArray<string>, |
49 |
| - options?: GlobbyOptions |
50 |
| -): Promise<string[]>; |
51 |
| - |
52 |
| -/** |
53 |
| - * @param patterns - See supported `minimatch` [patterns](https://github.com/isaacs/minimatch#usage). |
54 |
| - * @param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-1) in addition to the ones in this package. |
55 |
| - * @returns An `Array` of matching paths. |
56 |
| - */ |
57 |
| -export function sync( |
58 |
| - patterns: string | ReadonlyArray<string>, |
59 |
| - options?: GlobbyOptions |
60 |
| -): string[]; |
61 |
| - |
62 |
| -export interface GlobTask { |
63 |
| - readonly pattern: string; |
64 |
| - readonly options: GlobbyOptions; |
65 |
| -} |
| 81 | +declare const globby: { |
| 82 | + /** |
| 83 | + @param patterns - See supported `minimatch` [patterns](https://github.com/isaacs/minimatch#usage). |
| 84 | + @param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-1) in addition to the ones in this package. |
| 85 | + @returns A `Promise<Array>` of matching paths. |
66 | 86 |
|
67 |
| -/** |
68 |
| - * 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. |
69 |
| - * |
70 |
| - * @param patterns - See supported `minimatch` [patterns](https://github.com/isaacs/minimatch#usage). |
71 |
| - * @param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-1) in addition to the ones in this package. |
72 |
| - * @returns An `Array<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. |
73 |
| - */ |
74 |
| -export function generateGlobTasks( |
75 |
| - patterns: string | ReadonlyArray<string>, |
76 |
| - options?: GlobbyOptions |
77 |
| -): GlobTask[]; |
78 |
| - |
79 |
| -/** |
80 |
| - * Note that the options affect the results. If `noext: true` is set, then `+(a|b)` will not be considered a magic pattern. If the pattern has a brace expansion, like `a/{b/c,x/y}`, then that is considered magical, unless `nobrace: true` is set. |
81 |
| - * |
82 |
| - * This function is backed by [`node-glob`](https://github.com/isaacs/node-glob#globhasmagicpattern-options). |
83 |
| - * |
84 |
| - * @param patterns - See supported `minimatch` [patterns](https://github.com/isaacs/minimatch#usage). |
85 |
| - * @param options - See the [`node-glob` options](https://github.com/isaacs/node-glob#globhasmagicpattern-options). |
86 |
| - * @returns A boolean of whether there are any special glob characters in the `patterns`. |
87 |
| - */ |
88 |
| -export function hasMagic( |
89 |
| - patterns: string | ReadonlyArray<string>, |
90 |
| - options?: NodeGlobOptions |
91 |
| -): boolean; |
92 |
| - |
93 |
| -export interface GitignoreOptions { |
94 |
| - readonly cwd?: string; |
95 |
| - readonly ignore?: ReadonlyArray<string>; |
96 |
| -} |
| 87 | + @example |
| 88 | + ``` |
| 89 | + import globby = require('globby'); |
97 | 90 |
|
98 |
| -export type FilterFunction = (path: string) => boolean; |
| 91 | + (async () => { |
| 92 | + const paths = await globby(['*', '!cake']); |
99 | 93 |
|
100 |
| -export interface Gitignore { |
101 |
| - (options?: GitignoreOptions): Promise<FilterFunction>; |
| 94 | + console.log(paths); |
| 95 | + //=> ['unicorn', 'rainbow'] |
| 96 | + })(); |
| 97 | + ``` |
| 98 | + */ |
| 99 | + ( |
| 100 | + patterns: string | ReadonlyArray<string>, |
| 101 | + options?: globby.GlobbyOptions |
| 102 | + ): Promise<string[]>; |
102 | 103 |
|
103 | 104 | /**
|
104 |
| - * @returns A filter function indicating whether a given path is ignored via a `.gitignore` file. |
105 |
| - */ |
106 |
| - sync(options?: GitignoreOptions): FilterFunction; |
107 |
| -} |
| 105 | + @param patterns - See supported `minimatch` [patterns](https://github.com/isaacs/minimatch#usage). |
| 106 | + @param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-1) in addition to the ones in this package. |
| 107 | + @returns An `Array` of matching paths. |
| 108 | + */ |
| 109 | + sync( |
| 110 | + patterns: string | ReadonlyArray<string>, |
| 111 | + options?: globby.GlobbyOptions |
| 112 | + ): string[]; |
| 113 | + |
| 114 | + /** |
| 115 | + 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. |
| 116 | +
|
| 117 | + @param patterns - See supported `minimatch` [patterns](https://github.com/isaacs/minimatch#usage). |
| 118 | + @param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-1) in addition to the ones in this package. |
| 119 | + @returns An `Array<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. |
| 120 | + */ |
| 121 | + generateGlobTasks( |
| 122 | + patterns: string | ReadonlyArray<string>, |
| 123 | + options?: globby.GlobbyOptions |
| 124 | + ): globby.GlobTask[]; |
| 125 | + |
| 126 | + /** |
| 127 | + Note that the options affect the results. If `noext: true` is set, then `+(a|b)` will not be considered a magic pattern. If the pattern has a brace expansion, like `a/{b/c,x/y}`, then that is considered magical, unless `nobrace: true` is set. |
| 128 | +
|
| 129 | + This function is backed by [`node-glob`](https://github.com/isaacs/node-glob#globhasmagicpattern-options). |
| 130 | +
|
| 131 | + @param patterns - See supported `minimatch` [patterns](https://github.com/isaacs/minimatch#usage). |
| 132 | + @param options - See the [`node-glob` options](https://github.com/isaacs/node-glob#globhasmagicpattern-options). |
| 133 | + @returns A boolean of whether there are any special glob characters in the `patterns`. |
| 134 | + */ |
| 135 | + hasMagic( |
| 136 | + patterns: string | ReadonlyArray<string>, |
| 137 | + options?: NodeGlobOptions |
| 138 | + ): boolean; |
| 139 | + |
| 140 | + readonly gitignore: Gitignore; |
| 141 | + |
| 142 | + // TODO: Remove this for the next major release |
| 143 | + default: typeof globby; |
| 144 | +}; |
108 | 145 |
|
109 |
| -/** |
110 |
| - * `.gitignore` files matched by the ignore config are not used for the resulting filter function. |
111 |
| - * |
112 |
| - * @returns A `Promise` for a filter function indicating whether a given path is ignored via a `.gitignore` file. |
113 |
| - * |
114 |
| - * @example |
115 |
| - * |
116 |
| - * import {gitignore} from 'globby'; |
117 |
| - * |
118 |
| - * (async () => { |
119 |
| - * const isIgnored = await gitignore(); |
120 |
| - * console.log(isIgnored('some/file')); |
121 |
| - * })(); |
122 |
| - */ |
123 |
| -export const gitignore: Gitignore; |
| 146 | +export = globby; |
0 commit comments