-
-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathindex.test-d.ts
More file actions
240 lines (206 loc) · 7.44 KB
/
index.test-d.ts
File metadata and controls
240 lines (206 loc) · 7.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
import {type Buffer} from 'node:buffer';
import {expectType} from 'tsd';
import {
type GlobTask,
type GlobEntry,
type GlobbyStream,
type GlobbyEntryStream,
type GlobbyFilterFunction,
globby,
globbySync,
globbyStream,
generateGlobTasks,
generateGlobTasksSync,
isDynamicPattern,
isGitIgnored,
isGitIgnoredSync,
} from './index.js';
const __dirname = '';
// Globby
expectType<Promise<string[]>>(globby('*.tmp'));
expectType<Promise<string[]>>(globby(['a.tmp', '*.tmp', '!{c,d,e}.tmp']));
expectType<Promise<string[]>>(globby('*.tmp', {expandDirectories: false}));
expectType<Promise<string[]>>(globby('*.tmp', {expandDirectories: ['a*', 'b*']}));
expectType<Promise<string[]>>(globby('*.tmp', {
expandDirectories: {
files: ['a', 'b'],
extensions: ['tmp'],
},
}));
expectType<Promise<string[]>>(globby('*.tmp', {gitignore: true}));
expectType<Promise<string[]>>(globby('*.tmp', {ignore: ['**/b.tmp']}));
expectType<Promise<GlobEntry[]>>(globby('*.tmp', {objectMode: true}));
expectType<Promise<GlobEntry[]>>(globby('*.tmp', {stats: true}));
// Globby (sync)
expectType<string[]>(globbySync('*.tmp'));
expectType<string[]>(globbySync(['a.tmp', '*.tmp', '!{c,d,e}.tmp']));
expectType<string[]>(globbySync('*.tmp', {expandDirectories: false}));
expectType<string[]>(globbySync('*.tmp', {expandDirectories: ['a*', 'b*']}));
expectType<string[]>(globbySync('*.tmp', {
expandDirectories: {
files: ['a', 'b'],
extensions: ['tmp'],
},
}));
expectType<string[]>(globbySync('*.tmp', {gitignore: true}));
expectType<string[]>(globbySync('*.tmp', {ignore: ['**/b.tmp']}));
expectType<GlobEntry[]>(globbySync('*.tmp', {objectMode: true}));
expectType<GlobEntry[]>(globbySync('*.tmp', {stats: true}));
// Globby (stream)
expectType<GlobbyStream>(globbyStream('*.tmp'));
expectType<GlobbyStream>(globbyStream(['a.tmp', '*.tmp', '!{c,d,e}.tmp']));
expectType<GlobbyStream>(globbyStream('*.tmp', {expandDirectories: false}));
expectType<GlobbyStream>(globbyStream('*.tmp', {expandDirectories: ['a*', 'b*']}));
expectType<GlobbyStream>(globbyStream('*.tmp', {
expandDirectories: {
files: ['a', 'b'],
extensions: ['tmp'],
},
}));
expectType<GlobbyStream>(globbyStream('*.tmp', {gitignore: true}));
expectType<GlobbyStream>(globbyStream('*.tmp', {ignore: ['**/b.tmp']}));
expectType<GlobbyEntryStream>(globbyStream('*.tmp', {objectMode: true}));
expectType<GlobbyEntryStream>(globbyStream('*.tmp', {stats: true}));
expectType<GlobbyEntryStream>(globbyStream('*.tmp', {objectMode: true, gitignore: true}));
expectType<GlobbyEntryStream>(globbyStream('*.tmp', {stats: true, gitignore: true}));
// eslint-disable-next-line unicorn/prefer-top-level-await
(async () => {
const streamResult = [];
for await (const path of globbyStream('*.tmp')) {
streamResult.push(path);
}
// With the GlobbyStream interface, we can properly type the result as string[]
expectType<string[]>(streamResult);
})();
// eslint-disable-next-line unicorn/prefer-top-level-await
(async () => {
const streamResult = [];
for await (const entry of globbyStream('*.tmp', {objectMode: true})) {
streamResult.push(entry);
}
expectType<GlobEntry[]>(streamResult);
})();
// eslint-disable-next-line unicorn/prefer-top-level-await
(async () => {
const streamResult = [];
for await (const entry of globbyStream('*.tmp', {stats: true})) {
streamResult.push(entry);
}
expectType<GlobEntry[]>(streamResult);
})();
// GenerateGlobTasks
expectType<Promise<GlobTask[]>>(generateGlobTasks('*.tmp'));
expectType<Promise<GlobTask[]>>(generateGlobTasks(['a.tmp', '*.tmp', '!{c,d,e}.tmp']));
expectType<Promise<GlobTask[]>>(generateGlobTasks('*.tmp', {expandDirectories: false}));
expectType<Promise<GlobTask[]>>(generateGlobTasks('*.tmp', {expandDirectories: ['a*', 'b*']}));
expectType<Promise<GlobTask[]>>(generateGlobTasks('*.tmp', {
expandDirectories: {
files: ['a', 'b'],
extensions: ['tmp'],
},
}));
expectType<Promise<GlobTask[]>>(generateGlobTasks('*.tmp', {gitignore: true}));
expectType<Promise<GlobTask[]>>(generateGlobTasks('*.tmp', {ignore: ['**/b.tmp']}));
// GenerateGlobTasksSync
expectType<GlobTask[]>(generateGlobTasksSync('*.tmp'));
expectType<GlobTask[]>(generateGlobTasksSync(['a.tmp', '*.tmp', '!{c,d,e}.tmp']));
expectType<GlobTask[]>(generateGlobTasksSync('*.tmp', {expandDirectories: false}));
expectType<GlobTask[]>(generateGlobTasksSync('*.tmp', {expandDirectories: ['a*', 'b*']}));
expectType<GlobTask[]>(generateGlobTasksSync('*.tmp', {
expandDirectories: {
files: ['a', 'b'],
extensions: ['tmp'],
},
}));
expectType<GlobTask[]>(generateGlobTasksSync('*.tmp', {gitignore: true}));
expectType<GlobTask[]>(generateGlobTasksSync('*.tmp', {ignore: ['**/b.tmp']}));
// IsDynamicPattern
expectType<boolean>(isDynamicPattern('**'));
expectType<boolean>(isDynamicPattern(['**', 'path1', 'path2']));
expectType<boolean>(isDynamicPattern(['**', 'path1', 'path2'], {extglob: false}));
expectType<boolean>(isDynamicPattern(['**'], {cwd: new URL('file:///path/to/cwd')}));
expectType<boolean>(isDynamicPattern(['**'], {cwd: __dirname}));
// IsGitIgnored
expectType<Promise<GlobbyFilterFunction>>(isGitIgnored());
expectType<Promise<GlobbyFilterFunction>>(isGitIgnored({
cwd: __dirname,
}));
expectType<Promise<GlobbyFilterFunction>>(isGitIgnored({
cwd: new URL('file:///path/to/cwd'),
}));
// Supported option: suppressErrors
expectType<Promise<GlobbyFilterFunction>>(isGitIgnored({
suppressErrors: true,
}));
// Supported option: deep
expectType<Promise<GlobbyFilterFunction>>(isGitIgnored({
deep: 2,
}));
// Supported option: ignore
expectType<Promise<GlobbyFilterFunction>>(isGitIgnored({
ignore: ['**/node_modules'],
}));
// Supported option: followSymbolicLinks
expectType<Promise<GlobbyFilterFunction>>(isGitIgnored({
followSymbolicLinks: false,
}));
// Supported option: concurrency
expectType<Promise<GlobbyFilterFunction>>(isGitIgnored({
concurrency: 4,
}));
// Supported option: throwErrorOnBrokenSymbolicLink
expectType<Promise<GlobbyFilterFunction>>(isGitIgnored({
throwErrorOnBrokenSymbolicLink: false,
}));
// Multiple supported options combined
expectType<Promise<GlobbyFilterFunction>>(isGitIgnored({
cwd: __dirname,
suppressErrors: true,
deep: 1,
ignore: ['**/node_modules', '**/dist'],
followSymbolicLinks: false,
concurrency: 8,
throwErrorOnBrokenSymbolicLink: false,
}));
// IsGitIgnoredSync
expectType<GlobbyFilterFunction>(isGitIgnoredSync());
expectType<GlobbyFilterFunction>(isGitIgnoredSync({
cwd: __dirname,
}));
expectType<GlobbyFilterFunction>(isGitIgnoredSync({
cwd: new URL('file:///path/to/cwd'),
}));
// Supported option: suppressErrors (sync)
expectType<GlobbyFilterFunction>(isGitIgnoredSync({
suppressErrors: true,
}));
// Supported option: deep (sync)
expectType<GlobbyFilterFunction>(isGitIgnoredSync({
deep: 2,
}));
// Supported option: ignore (sync)
expectType<GlobbyFilterFunction>(isGitIgnoredSync({
ignore: ['**/node_modules'],
}));
// Supported option: followSymbolicLinks (sync)
expectType<GlobbyFilterFunction>(isGitIgnoredSync({
followSymbolicLinks: false,
}));
// Supported option: concurrency (sync)
expectType<GlobbyFilterFunction>(isGitIgnoredSync({
concurrency: 4,
}));
// Supported option: throwErrorOnBrokenSymbolicLink (sync)
expectType<GlobbyFilterFunction>(isGitIgnoredSync({
throwErrorOnBrokenSymbolicLink: true,
}));
// Multiple supported options combined (sync)
expectType<GlobbyFilterFunction>(isGitIgnoredSync({
cwd: __dirname,
suppressErrors: true,
deep: 1,
ignore: ['**/node_modules', '**/dist'],
followSymbolicLinks: false,
concurrency: 4,
throwErrorOnBrokenSymbolicLink: false,
}));