-
-
Notifications
You must be signed in to change notification settings - Fork 482
/
Copy pathindex.ts
217 lines (208 loc) · 6 KB
/
index.ts
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
import { escape, unescape } from 'minimatch'
import Minipass from 'minipass'
import { Path } from 'path-scurry'
import type {
GlobOptions,
GlobOptionsWithFileTypesFalse,
GlobOptionsWithFileTypesTrue,
GlobOptionsWithFileTypesUnset,
} from './glob.js'
import { Glob } from './glob.js'
import { hasMagic } from './has-magic.js'
/**
* Syncronous form of {@link globStream}. Will read all the matches as fast as
* you consume them, even all in a single tick if you consume them immediately,
* but will still respond to backpressure if they're not consumed immediately.
*/
export function globStreamSync(
pattern: string | string[],
options: GlobOptionsWithFileTypesTrue
): Minipass<Path, Path>
export function globStreamSync(
pattern: string | string[],
options: GlobOptionsWithFileTypesFalse
): Minipass<string, string>
export function globStreamSync(
pattern: string | string[],
options: GlobOptionsWithFileTypesUnset
): Minipass<string, string>
export function globStreamSync(
pattern: string | string[],
options: GlobOptions
): Minipass<Path, Path> | Minipass<string, string>
export function globStreamSync(
pattern: string | string[],
options: GlobOptions = {}
) {
return new Glob(pattern, options).streamSync()
}
/**
* Return a stream that emits all the strings or `Path` objects and
* then emits `end` when completed.
*/
export function globStream(
pattern: string | string[],
options: GlobOptionsWithFileTypesFalse
): Minipass<string, string>
export function globStream(
pattern: string | string[],
options: GlobOptionsWithFileTypesTrue
): Minipass<Path, Path>
export function globStream(
pattern: string | string[],
options?: GlobOptionsWithFileTypesUnset | undefined
): Minipass<string, string>
export function globStream(
pattern: string | string[],
options: GlobOptions
): Minipass<Path, Path> | Minipass<string, string>
export function globStream(
pattern: string | string[],
options: GlobOptions = {}
) {
return new Glob(pattern, options).stream()
}
/**
* Synchronous form of {@link glob}
*/
export function globSync(
pattern: string | string[],
options: GlobOptionsWithFileTypesFalse
): string[]
export function globSync(
pattern: string | string[],
options: GlobOptionsWithFileTypesTrue
): Path[]
export function globSync(
pattern: string | string[],
options?: GlobOptionsWithFileTypesUnset | undefined
): string[]
export function globSync(
pattern: string | string[],
options: GlobOptions
): Path[] | string[]
export function globSync(
pattern: string | string[],
options: GlobOptions = {}
) {
return new Glob(pattern, options).walkSync()
}
/**
* Perform an asynchronous glob search for the pattern(s) specified. Returns
* [Path](https://isaacs.github.io/path-scurry/classes/PathBase) objects if the
* {@link withFileTypes} option is set to `true`. See {@link GlobOptions} for
* full option descriptions.
*/
export async function glob(
pattern: string | string[],
options?: GlobOptionsWithFileTypesUnset | undefined
): Promise<string[]>
export async function glob(
pattern: string | string[],
options: GlobOptionsWithFileTypesTrue
): Promise<Path[]>
export async function glob(
pattern: string | string[],
options: GlobOptionsWithFileTypesFalse
): Promise<string[]>
export async function glob(
pattern: string | string[],
options: GlobOptions
): Promise<Path[] | string[]>
export async function glob(
pattern: string | string[],
options: GlobOptions = {}
) {
return new Glob(pattern, options).walk()
}
/**
* Return a sync iterator for walking glob pattern matches.
*/
export function globIterateSync(
pattern: string | string[],
options?: GlobOptionsWithFileTypesUnset | undefined
): Generator<string, void, void>
export function globIterateSync(
pattern: string | string[],
options: GlobOptionsWithFileTypesTrue
): Generator<Path, void, void>
export function globIterateSync(
pattern: string | string[],
options: GlobOptionsWithFileTypesFalse
): Generator<string, void, void>
export function globIterateSync(
pattern: string | string[],
options: GlobOptions
): Generator<Path, void, void> | Generator<string, void, void>
export function globIterateSync(
pattern: string | string[],
options: GlobOptions = {}
) {
return new Glob(pattern, options).iterateSync()
}
/**
* Return an async iterator for walking glob pattern matches.
*/
export function globIterate(
pattern: string | string[],
options?: GlobOptionsWithFileTypesUnset | undefined
): AsyncGenerator<string, void, void>
export function globIterate(
pattern: string | string[],
options: GlobOptionsWithFileTypesTrue
): AsyncGenerator<Path, void, void>
export function globIterate(
pattern: string | string[],
options: GlobOptionsWithFileTypesFalse
): AsyncGenerator<string, void, void>
export function globIterate(
pattern: string | string[],
options: GlobOptions
): AsyncGenerator<Path, void, void> | AsyncGenerator<string, void, void>
export function globIterate(
pattern: string | string[],
options: GlobOptions = {}
) {
return new Glob(pattern, options).iterate()
}
// aliases: glob.sync.stream() glob.stream.sync() glob.sync() etc
export const streamSync = globStreamSync
export const stream = Object.assign(globStream, { sync: globStreamSync })
export const iterateSync = globIterateSync
export const iterate = Object.assign(globIterate, {
sync: globIterateSync,
})
export const sync = Object.assign(globSync, {
stream: globStreamSync,
iterate: globIterateSync,
})
/* c8 ignore start */
export { escape, unescape } from 'minimatch'
export { Glob } from './glob.js'
export type {
GlobOptions,
GlobOptionsWithFileTypesFalse,
GlobOptionsWithFileTypesTrue,
GlobOptionsWithFileTypesUnset,
} from './glob.js'
export { hasMagic } from './has-magic.js'
export type { IgnoreLike } from './ignore.js'
export type { MatchStream } from './walker.js'
/* c8 ignore stop */
export default Object.assign(glob, {
glob,
globSync,
sync,
globStream,
stream,
globStreamSync,
streamSync,
globIterate,
iterate,
globIterateSync,
iterateSync,
Glob,
hasMagic,
escape,
unescape,
})