@socketsecurity/cli-with-sentry 1.0.76 → 1.0.78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.js +8 -6
- package/dist/constants.js.map +1 -1
- package/dist/tsconfig.dts.tsbuildinfo +1 -1
- package/dist/types/constants.d.mts +1 -0
- package/dist/types/constants.d.mts.map +1 -1
- package/dist/types/utils/fs.d.mts +1 -0
- package/dist/types/utils/fs.d.mts.map +1 -1
- package/dist/types/utils/glob.d.mts +1 -1
- package/dist/types/utils/glob.d.mts.map +1 -1
- package/dist/types/utils/npm-paths.d.mts +1 -1
- package/dist/types/utils/npm-paths.d.mts.map +1 -1
- package/dist/types/utils/path-resolve.d.mts +1 -1
- package/dist/types/utils/path-resolve.d.mts.map +1 -1
- package/dist/utils.js +42 -31
- package/dist/utils.js.map +1 -1
- package/dist/vendor.js +3741 -3922
- package/external/@socketsecurity/registry/external/fast-glob.js +7994 -0
- package/external/@socketsecurity/registry/external/streaming-iterables.js +326 -0
- package/external/@socketsecurity/registry/lib/fs.js +50 -12
- package/external/@socketsecurity/registry/lib/globs.js +9 -10
- package/external/@socketsecurity/registry/lib/npm.js +1 -1
- package/external/@socketsecurity/registry/lib/streams.js +37 -0
- package/package.json +6 -6
- package/external/@socketsecurity/registry/external/tinyglobby.js +0 -3888
- package/external/@socketsecurity/registry/lib/constants/ignore-globs.js +0 -41
|
@@ -1,3888 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const require$$0 = require('path')
|
|
4
|
-
const require$$0$1 = require('fs')
|
|
5
|
-
|
|
6
|
-
const dist$1 = {}
|
|
7
|
-
|
|
8
|
-
const dist = {}
|
|
9
|
-
|
|
10
|
-
const builder = {}
|
|
11
|
-
|
|
12
|
-
const apiBuilder = {}
|
|
13
|
-
|
|
14
|
-
const async = {}
|
|
15
|
-
|
|
16
|
-
const walker = {}
|
|
17
|
-
|
|
18
|
-
const utils$1 = {}
|
|
19
|
-
|
|
20
|
-
let hasRequiredUtils$1
|
|
21
|
-
function requireUtils$1() {
|
|
22
|
-
if (hasRequiredUtils$1) {
|
|
23
|
-
return utils$1
|
|
24
|
-
}
|
|
25
|
-
hasRequiredUtils$1 = 1
|
|
26
|
-
Object.defineProperty(utils$1, '__esModule', {
|
|
27
|
-
value: true
|
|
28
|
-
})
|
|
29
|
-
utils$1.normalizePath =
|
|
30
|
-
utils$1.isRootDirectory =
|
|
31
|
-
utils$1.convertSlashes =
|
|
32
|
-
utils$1.cleanPath =
|
|
33
|
-
void 0
|
|
34
|
-
const path_1 = require$$0
|
|
35
|
-
function cleanPath(path) {
|
|
36
|
-
let normalized = (0, path_1.normalize)(path)
|
|
37
|
-
// we have to remove the last path separator
|
|
38
|
-
// to account for / root path
|
|
39
|
-
if (
|
|
40
|
-
normalized.length > 1 &&
|
|
41
|
-
normalized[normalized.length - 1] === path_1.sep
|
|
42
|
-
) {
|
|
43
|
-
normalized = normalized.substring(0, normalized.length - 1)
|
|
44
|
-
}
|
|
45
|
-
return normalized
|
|
46
|
-
}
|
|
47
|
-
utils$1.cleanPath = cleanPath
|
|
48
|
-
const SLASHES_REGEX = /[\\/]/g
|
|
49
|
-
function convertSlashes(path, separator) {
|
|
50
|
-
return path.replace(SLASHES_REGEX, separator)
|
|
51
|
-
}
|
|
52
|
-
utils$1.convertSlashes = convertSlashes
|
|
53
|
-
function isRootDirectory(path) {
|
|
54
|
-
return path === '/' || /^[a-z]:\\$/i.test(path)
|
|
55
|
-
}
|
|
56
|
-
utils$1.isRootDirectory = isRootDirectory
|
|
57
|
-
function normalizePath(path, options) {
|
|
58
|
-
const { resolvePaths, normalizePath, pathSeparator } = options
|
|
59
|
-
const pathNeedsCleaning =
|
|
60
|
-
(process.platform === 'win32' && path.includes('/')) ||
|
|
61
|
-
path.startsWith('.')
|
|
62
|
-
if (resolvePaths) {
|
|
63
|
-
path = (0, path_1.resolve)(path)
|
|
64
|
-
}
|
|
65
|
-
if (normalizePath || pathNeedsCleaning) {
|
|
66
|
-
path = cleanPath(path)
|
|
67
|
-
}
|
|
68
|
-
if (path === '.') {
|
|
69
|
-
return ''
|
|
70
|
-
}
|
|
71
|
-
const needsSeperator = path[path.length - 1] !== pathSeparator
|
|
72
|
-
return convertSlashes(
|
|
73
|
-
needsSeperator ? path + pathSeparator : path,
|
|
74
|
-
pathSeparator
|
|
75
|
-
)
|
|
76
|
-
}
|
|
77
|
-
utils$1.normalizePath = normalizePath
|
|
78
|
-
return utils$1
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const joinPath = {}
|
|
82
|
-
|
|
83
|
-
let hasRequiredJoinPath
|
|
84
|
-
function requireJoinPath() {
|
|
85
|
-
if (hasRequiredJoinPath) {
|
|
86
|
-
return joinPath
|
|
87
|
-
}
|
|
88
|
-
hasRequiredJoinPath = 1
|
|
89
|
-
Object.defineProperty(joinPath, '__esModule', {
|
|
90
|
-
value: true
|
|
91
|
-
})
|
|
92
|
-
joinPath.build =
|
|
93
|
-
joinPath.joinDirectoryPath =
|
|
94
|
-
joinPath.joinPathWithBasePath =
|
|
95
|
-
void 0
|
|
96
|
-
const path_1 = require$$0
|
|
97
|
-
const utils_1 = requireUtils$1()
|
|
98
|
-
function joinPathWithBasePath(filename, directoryPath) {
|
|
99
|
-
return directoryPath + filename
|
|
100
|
-
}
|
|
101
|
-
joinPath.joinPathWithBasePath = joinPathWithBasePath
|
|
102
|
-
function joinPathWithRelativePath(root, options) {
|
|
103
|
-
return function (filename, directoryPath) {
|
|
104
|
-
const sameRoot = directoryPath.startsWith(root)
|
|
105
|
-
if (sameRoot) {
|
|
106
|
-
return directoryPath.replace(root, '') + filename
|
|
107
|
-
} else {
|
|
108
|
-
return (
|
|
109
|
-
(0, utils_1.convertSlashes)(
|
|
110
|
-
(0, path_1.relative)(root, directoryPath),
|
|
111
|
-
options.pathSeparator
|
|
112
|
-
) +
|
|
113
|
-
options.pathSeparator +
|
|
114
|
-
filename
|
|
115
|
-
)
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
function joinPath$1(filename) {
|
|
120
|
-
return filename
|
|
121
|
-
}
|
|
122
|
-
function joinDirectoryPath(filename, directoryPath, separator) {
|
|
123
|
-
return directoryPath + filename + separator
|
|
124
|
-
}
|
|
125
|
-
joinPath.joinDirectoryPath = joinDirectoryPath
|
|
126
|
-
function build(root, options) {
|
|
127
|
-
const { relativePaths, includeBasePath } = options
|
|
128
|
-
return relativePaths && root
|
|
129
|
-
? joinPathWithRelativePath(root, options)
|
|
130
|
-
: includeBasePath
|
|
131
|
-
? joinPathWithBasePath
|
|
132
|
-
: joinPath$1
|
|
133
|
-
}
|
|
134
|
-
joinPath.build = build
|
|
135
|
-
return joinPath
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const pushDirectory = {}
|
|
139
|
-
|
|
140
|
-
let hasRequiredPushDirectory
|
|
141
|
-
function requirePushDirectory() {
|
|
142
|
-
if (hasRequiredPushDirectory) {
|
|
143
|
-
return pushDirectory
|
|
144
|
-
}
|
|
145
|
-
hasRequiredPushDirectory = 1
|
|
146
|
-
Object.defineProperty(pushDirectory, '__esModule', {
|
|
147
|
-
value: true
|
|
148
|
-
})
|
|
149
|
-
pushDirectory.build = void 0
|
|
150
|
-
function pushDirectoryWithRelativePath(root) {
|
|
151
|
-
return function (directoryPath, paths) {
|
|
152
|
-
paths.push(directoryPath.substring(root.length) || '.')
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
function pushDirectoryFilterWithRelativePath(root) {
|
|
156
|
-
return function (directoryPath, paths, filters) {
|
|
157
|
-
const relativePath = directoryPath.substring(root.length) || '.'
|
|
158
|
-
if (filters.every(filter => filter(relativePath, true))) {
|
|
159
|
-
paths.push(relativePath)
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
const pushDirectory$1 = (directoryPath, paths) => {
|
|
164
|
-
paths.push(directoryPath || '.')
|
|
165
|
-
}
|
|
166
|
-
const pushDirectoryFilter = (directoryPath, paths, filters) => {
|
|
167
|
-
const path = directoryPath || '.'
|
|
168
|
-
if (filters.every(filter => filter(path, true))) {
|
|
169
|
-
paths.push(path)
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
const empty = () => {}
|
|
173
|
-
function build(root, options) {
|
|
174
|
-
const { includeDirs, filters, relativePaths } = options
|
|
175
|
-
if (!includeDirs) {
|
|
176
|
-
return empty
|
|
177
|
-
}
|
|
178
|
-
if (relativePaths) {
|
|
179
|
-
return filters && filters.length
|
|
180
|
-
? pushDirectoryFilterWithRelativePath(root)
|
|
181
|
-
: pushDirectoryWithRelativePath(root)
|
|
182
|
-
}
|
|
183
|
-
return filters && filters.length ? pushDirectoryFilter : pushDirectory$1
|
|
184
|
-
}
|
|
185
|
-
pushDirectory.build = build
|
|
186
|
-
return pushDirectory
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const pushFile = {}
|
|
190
|
-
|
|
191
|
-
let hasRequiredPushFile
|
|
192
|
-
function requirePushFile() {
|
|
193
|
-
if (hasRequiredPushFile) {
|
|
194
|
-
return pushFile
|
|
195
|
-
}
|
|
196
|
-
hasRequiredPushFile = 1
|
|
197
|
-
Object.defineProperty(pushFile, '__esModule', {
|
|
198
|
-
value: true
|
|
199
|
-
})
|
|
200
|
-
pushFile.build = void 0
|
|
201
|
-
const pushFileFilterAndCount = (filename, _paths, counts, filters) => {
|
|
202
|
-
if (filters.every(filter => filter(filename, false))) {
|
|
203
|
-
counts.files++
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
const pushFileFilter = (filename, paths, _counts, filters) => {
|
|
207
|
-
if (filters.every(filter => filter(filename, false))) {
|
|
208
|
-
paths.push(filename)
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
const pushFileCount = (_filename, _paths, counts, _filters) => {
|
|
212
|
-
counts.files++
|
|
213
|
-
}
|
|
214
|
-
const pushFile$1 = (filename, paths) => {
|
|
215
|
-
paths.push(filename)
|
|
216
|
-
}
|
|
217
|
-
const empty = () => {}
|
|
218
|
-
function build(options) {
|
|
219
|
-
const { excludeFiles, filters, onlyCounts } = options
|
|
220
|
-
if (excludeFiles) {
|
|
221
|
-
return empty
|
|
222
|
-
}
|
|
223
|
-
if (filters && filters.length) {
|
|
224
|
-
return onlyCounts ? pushFileFilterAndCount : pushFileFilter
|
|
225
|
-
} else if (onlyCounts) {
|
|
226
|
-
return pushFileCount
|
|
227
|
-
} else {
|
|
228
|
-
return pushFile$1
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
pushFile.build = build
|
|
232
|
-
return pushFile
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
const getArray = {}
|
|
236
|
-
|
|
237
|
-
let hasRequiredGetArray
|
|
238
|
-
function requireGetArray() {
|
|
239
|
-
if (hasRequiredGetArray) {
|
|
240
|
-
return getArray
|
|
241
|
-
}
|
|
242
|
-
hasRequiredGetArray = 1
|
|
243
|
-
Object.defineProperty(getArray, '__esModule', {
|
|
244
|
-
value: true
|
|
245
|
-
})
|
|
246
|
-
getArray.build = void 0
|
|
247
|
-
const getArray$1 = paths => {
|
|
248
|
-
return paths
|
|
249
|
-
}
|
|
250
|
-
const getArrayGroup = () => {
|
|
251
|
-
return [''].slice(0, 0)
|
|
252
|
-
}
|
|
253
|
-
function build(options) {
|
|
254
|
-
return options.group ? getArrayGroup : getArray$1
|
|
255
|
-
}
|
|
256
|
-
getArray.build = build
|
|
257
|
-
return getArray
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
const groupFiles = {}
|
|
261
|
-
|
|
262
|
-
let hasRequiredGroupFiles
|
|
263
|
-
function requireGroupFiles() {
|
|
264
|
-
if (hasRequiredGroupFiles) {
|
|
265
|
-
return groupFiles
|
|
266
|
-
}
|
|
267
|
-
hasRequiredGroupFiles = 1
|
|
268
|
-
Object.defineProperty(groupFiles, '__esModule', {
|
|
269
|
-
value: true
|
|
270
|
-
})
|
|
271
|
-
groupFiles.build = void 0
|
|
272
|
-
const groupFiles$1 = (groups, directory, files) => {
|
|
273
|
-
groups.push({
|
|
274
|
-
directory,
|
|
275
|
-
files,
|
|
276
|
-
dir: directory
|
|
277
|
-
})
|
|
278
|
-
}
|
|
279
|
-
const empty = () => {}
|
|
280
|
-
function build(options) {
|
|
281
|
-
return options.group ? groupFiles$1 : empty
|
|
282
|
-
}
|
|
283
|
-
groupFiles.build = build
|
|
284
|
-
return groupFiles
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
const resolveSymlink = {}
|
|
288
|
-
|
|
289
|
-
let hasRequiredResolveSymlink
|
|
290
|
-
function requireResolveSymlink() {
|
|
291
|
-
if (hasRequiredResolveSymlink) {
|
|
292
|
-
return resolveSymlink
|
|
293
|
-
}
|
|
294
|
-
hasRequiredResolveSymlink = 1
|
|
295
|
-
const __importDefault =
|
|
296
|
-
(this && this.__importDefault) ||
|
|
297
|
-
function (mod) {
|
|
298
|
-
return mod && mod.__esModule
|
|
299
|
-
? mod
|
|
300
|
-
: {
|
|
301
|
-
default: mod
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
Object.defineProperty(resolveSymlink, '__esModule', {
|
|
305
|
-
value: true
|
|
306
|
-
})
|
|
307
|
-
resolveSymlink.build = void 0
|
|
308
|
-
const fs_1 = __importDefault(require$$0$1)
|
|
309
|
-
const path_1 = require$$0
|
|
310
|
-
const resolveSymlinksAsync = function (path, state, callback) {
|
|
311
|
-
const {
|
|
312
|
-
queue,
|
|
313
|
-
options: { suppressErrors }
|
|
314
|
-
} = state
|
|
315
|
-
queue.enqueue()
|
|
316
|
-
fs_1.default.realpath(path, (error, resolvedPath) => {
|
|
317
|
-
if (error) {
|
|
318
|
-
return queue.dequeue(suppressErrors ? null : error, state)
|
|
319
|
-
}
|
|
320
|
-
fs_1.default.stat(resolvedPath, (error, stat) => {
|
|
321
|
-
if (error) {
|
|
322
|
-
return queue.dequeue(suppressErrors ? null : error, state)
|
|
323
|
-
}
|
|
324
|
-
if (stat.isDirectory() && isRecursive(path, resolvedPath, state)) {
|
|
325
|
-
return queue.dequeue(null, state)
|
|
326
|
-
}
|
|
327
|
-
callback(stat, resolvedPath)
|
|
328
|
-
queue.dequeue(null, state)
|
|
329
|
-
})
|
|
330
|
-
})
|
|
331
|
-
}
|
|
332
|
-
const resolveSymlinks = function (path, state, callback) {
|
|
333
|
-
const {
|
|
334
|
-
queue,
|
|
335
|
-
options: { suppressErrors }
|
|
336
|
-
} = state
|
|
337
|
-
queue.enqueue()
|
|
338
|
-
try {
|
|
339
|
-
const resolvedPath = fs_1.default.realpathSync(path)
|
|
340
|
-
const stat = fs_1.default.statSync(resolvedPath)
|
|
341
|
-
if (stat.isDirectory() && isRecursive(path, resolvedPath, state)) {
|
|
342
|
-
return
|
|
343
|
-
}
|
|
344
|
-
callback(stat, resolvedPath)
|
|
345
|
-
} catch (e) {
|
|
346
|
-
if (!suppressErrors) {
|
|
347
|
-
throw e
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
function build(options, isSynchronous) {
|
|
352
|
-
if (!options.resolveSymlinks || options.excludeSymlinks) {
|
|
353
|
-
return null
|
|
354
|
-
}
|
|
355
|
-
return isSynchronous ? resolveSymlinks : resolveSymlinksAsync
|
|
356
|
-
}
|
|
357
|
-
resolveSymlink.build = build
|
|
358
|
-
function isRecursive(path, resolved, state) {
|
|
359
|
-
if (state.options.useRealPaths) {
|
|
360
|
-
return isRecursiveUsingRealPaths(resolved, state)
|
|
361
|
-
}
|
|
362
|
-
let parent = (0, path_1.dirname)(path)
|
|
363
|
-
let depth = 1
|
|
364
|
-
while (parent !== state.root && depth < 2) {
|
|
365
|
-
const resolvedPath = state.symlinks.get(parent)
|
|
366
|
-
const isSameRoot =
|
|
367
|
-
!!resolvedPath &&
|
|
368
|
-
(resolvedPath === resolved ||
|
|
369
|
-
resolvedPath.startsWith(resolved) ||
|
|
370
|
-
resolved.startsWith(resolvedPath))
|
|
371
|
-
if (isSameRoot) {
|
|
372
|
-
depth++
|
|
373
|
-
} else {
|
|
374
|
-
parent = (0, path_1.dirname)(parent)
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
state.symlinks.set(path, resolved)
|
|
378
|
-
return depth > 1
|
|
379
|
-
}
|
|
380
|
-
function isRecursiveUsingRealPaths(resolved, state) {
|
|
381
|
-
return state.visited.includes(resolved + state.options.pathSeparator)
|
|
382
|
-
}
|
|
383
|
-
return resolveSymlink
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
const invokeCallback = {}
|
|
387
|
-
|
|
388
|
-
let hasRequiredInvokeCallback
|
|
389
|
-
function requireInvokeCallback() {
|
|
390
|
-
if (hasRequiredInvokeCallback) {
|
|
391
|
-
return invokeCallback
|
|
392
|
-
}
|
|
393
|
-
hasRequiredInvokeCallback = 1
|
|
394
|
-
Object.defineProperty(invokeCallback, '__esModule', {
|
|
395
|
-
value: true
|
|
396
|
-
})
|
|
397
|
-
invokeCallback.build = void 0
|
|
398
|
-
const onlyCountsSync = state => {
|
|
399
|
-
return state.counts
|
|
400
|
-
}
|
|
401
|
-
const groupsSync = state => {
|
|
402
|
-
return state.groups
|
|
403
|
-
}
|
|
404
|
-
const defaultSync = state => {
|
|
405
|
-
return state.paths
|
|
406
|
-
}
|
|
407
|
-
const limitFilesSync = state => {
|
|
408
|
-
return state.paths.slice(0, state.options.maxFiles)
|
|
409
|
-
}
|
|
410
|
-
const onlyCountsAsync = (state, error, callback) => {
|
|
411
|
-
report(error, callback, state.counts, state.options.suppressErrors)
|
|
412
|
-
return null
|
|
413
|
-
}
|
|
414
|
-
const defaultAsync = (state, error, callback) => {
|
|
415
|
-
report(error, callback, state.paths, state.options.suppressErrors)
|
|
416
|
-
return null
|
|
417
|
-
}
|
|
418
|
-
const limitFilesAsync = (state, error, callback) => {
|
|
419
|
-
report(
|
|
420
|
-
error,
|
|
421
|
-
callback,
|
|
422
|
-
state.paths.slice(0, state.options.maxFiles),
|
|
423
|
-
state.options.suppressErrors
|
|
424
|
-
)
|
|
425
|
-
return null
|
|
426
|
-
}
|
|
427
|
-
const groupsAsync = (state, error, callback) => {
|
|
428
|
-
report(error, callback, state.groups, state.options.suppressErrors)
|
|
429
|
-
return null
|
|
430
|
-
}
|
|
431
|
-
function report(error, callback, output, suppressErrors) {
|
|
432
|
-
if (error && !suppressErrors) {
|
|
433
|
-
callback(error, output)
|
|
434
|
-
} else {
|
|
435
|
-
callback(null, output)
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
function build(options, isSynchronous) {
|
|
439
|
-
const { onlyCounts, group, maxFiles } = options
|
|
440
|
-
if (onlyCounts) {
|
|
441
|
-
return isSynchronous ? onlyCountsSync : onlyCountsAsync
|
|
442
|
-
} else if (group) {
|
|
443
|
-
return isSynchronous ? groupsSync : groupsAsync
|
|
444
|
-
} else if (maxFiles) {
|
|
445
|
-
return isSynchronous ? limitFilesSync : limitFilesAsync
|
|
446
|
-
} else {
|
|
447
|
-
return isSynchronous ? defaultSync : defaultAsync
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
invokeCallback.build = build
|
|
451
|
-
return invokeCallback
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
const walkDirectory = {}
|
|
455
|
-
|
|
456
|
-
let hasRequiredWalkDirectory
|
|
457
|
-
function requireWalkDirectory() {
|
|
458
|
-
if (hasRequiredWalkDirectory) {
|
|
459
|
-
return walkDirectory
|
|
460
|
-
}
|
|
461
|
-
hasRequiredWalkDirectory = 1
|
|
462
|
-
const __importDefault =
|
|
463
|
-
(this && this.__importDefault) ||
|
|
464
|
-
function (mod) {
|
|
465
|
-
return mod && mod.__esModule
|
|
466
|
-
? mod
|
|
467
|
-
: {
|
|
468
|
-
default: mod
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
Object.defineProperty(walkDirectory, '__esModule', {
|
|
472
|
-
value: true
|
|
473
|
-
})
|
|
474
|
-
walkDirectory.build = void 0
|
|
475
|
-
const fs_1 = __importDefault(require$$0$1)
|
|
476
|
-
const readdirOpts = {
|
|
477
|
-
withFileTypes: true
|
|
478
|
-
}
|
|
479
|
-
const walkAsync = (
|
|
480
|
-
state,
|
|
481
|
-
crawlPath,
|
|
482
|
-
directoryPath,
|
|
483
|
-
currentDepth,
|
|
484
|
-
callback
|
|
485
|
-
) => {
|
|
486
|
-
if (currentDepth < 0) {
|
|
487
|
-
return state.queue.dequeue(null, state)
|
|
488
|
-
}
|
|
489
|
-
state.visited.push(crawlPath)
|
|
490
|
-
state.counts.directories++
|
|
491
|
-
state.queue.enqueue()
|
|
492
|
-
// Perf: Node >= 10 introduced withFileTypes that helps us
|
|
493
|
-
// skip an extra fs.stat call.
|
|
494
|
-
fs_1.default.readdir(
|
|
495
|
-
crawlPath || '.',
|
|
496
|
-
readdirOpts,
|
|
497
|
-
(error, entries = []) => {
|
|
498
|
-
callback(entries, directoryPath, currentDepth)
|
|
499
|
-
state.queue.dequeue(state.options.suppressErrors ? null : error, state)
|
|
500
|
-
}
|
|
501
|
-
)
|
|
502
|
-
}
|
|
503
|
-
const walkSync = (
|
|
504
|
-
state,
|
|
505
|
-
crawlPath,
|
|
506
|
-
directoryPath,
|
|
507
|
-
currentDepth,
|
|
508
|
-
callback
|
|
509
|
-
) => {
|
|
510
|
-
if (currentDepth < 0) {
|
|
511
|
-
return
|
|
512
|
-
}
|
|
513
|
-
state.visited.push(crawlPath)
|
|
514
|
-
state.counts.directories++
|
|
515
|
-
let entries = []
|
|
516
|
-
try {
|
|
517
|
-
entries = fs_1.default.readdirSync(crawlPath || '.', readdirOpts)
|
|
518
|
-
} catch (e) {
|
|
519
|
-
if (!state.options.suppressErrors) {
|
|
520
|
-
throw e
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
callback(entries, directoryPath, currentDepth)
|
|
524
|
-
}
|
|
525
|
-
function build(isSynchronous) {
|
|
526
|
-
return isSynchronous ? walkSync : walkAsync
|
|
527
|
-
}
|
|
528
|
-
walkDirectory.build = build
|
|
529
|
-
return walkDirectory
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
const queue = {}
|
|
533
|
-
|
|
534
|
-
let hasRequiredQueue
|
|
535
|
-
function requireQueue() {
|
|
536
|
-
if (hasRequiredQueue) {
|
|
537
|
-
return queue
|
|
538
|
-
}
|
|
539
|
-
hasRequiredQueue = 1
|
|
540
|
-
Object.defineProperty(queue, '__esModule', {
|
|
541
|
-
value: true
|
|
542
|
-
})
|
|
543
|
-
queue.Queue = void 0
|
|
544
|
-
/**
|
|
545
|
-
* This is a custom stateless queue to track concurrent async fs calls.
|
|
546
|
-
* It increments a counter whenever a call is queued and decrements it
|
|
547
|
-
* as soon as it completes. When the counter hits 0, it calls onQueueEmpty.
|
|
548
|
-
*/
|
|
549
|
-
class Queue {
|
|
550
|
-
onQueueEmpty
|
|
551
|
-
count = 0
|
|
552
|
-
constructor(onQueueEmpty) {
|
|
553
|
-
this.onQueueEmpty = onQueueEmpty
|
|
554
|
-
}
|
|
555
|
-
enqueue() {
|
|
556
|
-
this.count++
|
|
557
|
-
}
|
|
558
|
-
dequeue(error, output) {
|
|
559
|
-
if (--this.count <= 0 || error) {
|
|
560
|
-
this.onQueueEmpty(error, output)
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
queue.Queue = Queue
|
|
565
|
-
return queue
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
const counter = {}
|
|
569
|
-
|
|
570
|
-
let hasRequiredCounter
|
|
571
|
-
function requireCounter() {
|
|
572
|
-
if (hasRequiredCounter) {
|
|
573
|
-
return counter
|
|
574
|
-
}
|
|
575
|
-
hasRequiredCounter = 1
|
|
576
|
-
Object.defineProperty(counter, '__esModule', {
|
|
577
|
-
value: true
|
|
578
|
-
})
|
|
579
|
-
counter.Counter = void 0
|
|
580
|
-
class Counter {
|
|
581
|
-
_files = 0
|
|
582
|
-
_directories = 0
|
|
583
|
-
set files(num) {
|
|
584
|
-
this._files = num
|
|
585
|
-
}
|
|
586
|
-
get files() {
|
|
587
|
-
return this._files
|
|
588
|
-
}
|
|
589
|
-
set directories(num) {
|
|
590
|
-
this._directories = num
|
|
591
|
-
}
|
|
592
|
-
get directories() {
|
|
593
|
-
return this._directories
|
|
594
|
-
}
|
|
595
|
-
/**
|
|
596
|
-
* @deprecated use `directories` instead
|
|
597
|
-
*/
|
|
598
|
-
/* c8 ignore next 3 */
|
|
599
|
-
get dirs() {
|
|
600
|
-
return this._directories
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
counter.Counter = Counter
|
|
604
|
-
return counter
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
let hasRequiredWalker
|
|
608
|
-
function requireWalker() {
|
|
609
|
-
if (hasRequiredWalker) {
|
|
610
|
-
return walker
|
|
611
|
-
}
|
|
612
|
-
hasRequiredWalker = 1
|
|
613
|
-
const __createBinding =
|
|
614
|
-
(this && this.__createBinding) ||
|
|
615
|
-
(Object.create
|
|
616
|
-
? function (o, m, k, k2) {
|
|
617
|
-
if (k2 === undefined) {
|
|
618
|
-
k2 = k
|
|
619
|
-
}
|
|
620
|
-
let desc = Object.getOwnPropertyDescriptor(m, k)
|
|
621
|
-
if (
|
|
622
|
-
!desc ||
|
|
623
|
-
('get' in desc ? !m.__esModule : desc.writable || desc.configurable)
|
|
624
|
-
) {
|
|
625
|
-
desc = {
|
|
626
|
-
enumerable: true,
|
|
627
|
-
get: function () {
|
|
628
|
-
return m[k]
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
Object.defineProperty(o, k2, desc)
|
|
633
|
-
}
|
|
634
|
-
: function (o, m, k, k2) {
|
|
635
|
-
if (k2 === undefined) {
|
|
636
|
-
k2 = k
|
|
637
|
-
}
|
|
638
|
-
o[k2] = m[k]
|
|
639
|
-
})
|
|
640
|
-
const __setModuleDefault =
|
|
641
|
-
(this && this.__setModuleDefault) ||
|
|
642
|
-
(Object.create
|
|
643
|
-
? function (o, v) {
|
|
644
|
-
Object.defineProperty(o, 'default', {
|
|
645
|
-
enumerable: true,
|
|
646
|
-
value: v
|
|
647
|
-
})
|
|
648
|
-
}
|
|
649
|
-
: function (o, v) {
|
|
650
|
-
o['default'] = v
|
|
651
|
-
})
|
|
652
|
-
const __importStar =
|
|
653
|
-
(this && this.__importStar) ||
|
|
654
|
-
function (mod) {
|
|
655
|
-
if (mod && mod.__esModule) {
|
|
656
|
-
return mod
|
|
657
|
-
}
|
|
658
|
-
const result = {}
|
|
659
|
-
if (mod != null) {
|
|
660
|
-
for (var k in mod)
|
|
661
|
-
if (k !== 'default' && Object.prototype.hasOwnProperty.call(mod, k))
|
|
662
|
-
__createBinding(result, mod, k)
|
|
663
|
-
}
|
|
664
|
-
__setModuleDefault(result, mod)
|
|
665
|
-
return result
|
|
666
|
-
}
|
|
667
|
-
Object.defineProperty(walker, '__esModule', {
|
|
668
|
-
value: true
|
|
669
|
-
})
|
|
670
|
-
walker.Walker = void 0
|
|
671
|
-
const path_1 = require$$0
|
|
672
|
-
const utils_1 = requireUtils$1()
|
|
673
|
-
const joinPath = __importStar(requireJoinPath())
|
|
674
|
-
const pushDirectory = __importStar(requirePushDirectory())
|
|
675
|
-
const pushFile = __importStar(requirePushFile())
|
|
676
|
-
const getArray = __importStar(requireGetArray())
|
|
677
|
-
const groupFiles = __importStar(requireGroupFiles())
|
|
678
|
-
const resolveSymlink = __importStar(requireResolveSymlink())
|
|
679
|
-
const invokeCallback = __importStar(requireInvokeCallback())
|
|
680
|
-
const walkDirectory = __importStar(requireWalkDirectory())
|
|
681
|
-
const queue_1 = requireQueue()
|
|
682
|
-
const counter_1 = requireCounter()
|
|
683
|
-
class Walker {
|
|
684
|
-
root
|
|
685
|
-
isSynchronous
|
|
686
|
-
state
|
|
687
|
-
joinPath
|
|
688
|
-
pushDirectory
|
|
689
|
-
pushFile
|
|
690
|
-
getArray
|
|
691
|
-
groupFiles
|
|
692
|
-
resolveSymlink
|
|
693
|
-
walkDirectory
|
|
694
|
-
callbackInvoker
|
|
695
|
-
constructor(root, options, callback) {
|
|
696
|
-
this.isSynchronous = !callback
|
|
697
|
-
this.callbackInvoker = invokeCallback.build(options, this.isSynchronous)
|
|
698
|
-
this.root = (0, utils_1.normalizePath)(root, options)
|
|
699
|
-
this.state = {
|
|
700
|
-
root: (0, utils_1.isRootDirectory)(this.root)
|
|
701
|
-
? this.root
|
|
702
|
-
: this.root.slice(0, -1),
|
|
703
|
-
// Perf: we explicitly tell the compiler to optimize for String arrays
|
|
704
|
-
paths: [''].slice(0, 0),
|
|
705
|
-
groups: [],
|
|
706
|
-
counts: new counter_1.Counter(),
|
|
707
|
-
options,
|
|
708
|
-
queue: new queue_1.Queue((error, state) =>
|
|
709
|
-
this.callbackInvoker(state, error, callback)
|
|
710
|
-
),
|
|
711
|
-
symlinks: new Map(),
|
|
712
|
-
visited: [''].slice(0, 0)
|
|
713
|
-
}
|
|
714
|
-
/*
|
|
715
|
-
* Perf: We conditionally change functions according to options. This gives a slight
|
|
716
|
-
* performance boost. Since these functions are so small, they are automatically inlined
|
|
717
|
-
* by the javascript engine so there's no function call overhead (in most cases).
|
|
718
|
-
*/
|
|
719
|
-
this.joinPath = joinPath.build(this.root, options)
|
|
720
|
-
this.pushDirectory = pushDirectory.build(this.root, options)
|
|
721
|
-
this.pushFile = pushFile.build(options)
|
|
722
|
-
this.getArray = getArray.build(options)
|
|
723
|
-
this.groupFiles = groupFiles.build(options)
|
|
724
|
-
this.resolveSymlink = resolveSymlink.build(options, this.isSynchronous)
|
|
725
|
-
this.walkDirectory = walkDirectory.build(this.isSynchronous)
|
|
726
|
-
}
|
|
727
|
-
start() {
|
|
728
|
-
this.walkDirectory(
|
|
729
|
-
this.state,
|
|
730
|
-
this.root,
|
|
731
|
-
this.root,
|
|
732
|
-
this.state.options.maxDepth,
|
|
733
|
-
this.walk
|
|
734
|
-
)
|
|
735
|
-
return this.isSynchronous ? this.callbackInvoker(this.state, null) : null
|
|
736
|
-
}
|
|
737
|
-
walk = (entries, directoryPath, depth) => {
|
|
738
|
-
const {
|
|
739
|
-
paths,
|
|
740
|
-
options: {
|
|
741
|
-
filters,
|
|
742
|
-
resolveSymlinks,
|
|
743
|
-
excludeSymlinks,
|
|
744
|
-
exclude,
|
|
745
|
-
maxFiles,
|
|
746
|
-
signal,
|
|
747
|
-
useRealPaths,
|
|
748
|
-
pathSeparator
|
|
749
|
-
}
|
|
750
|
-
} = this.state
|
|
751
|
-
if ((signal && signal.aborted) || (maxFiles && paths.length > maxFiles)) {
|
|
752
|
-
return
|
|
753
|
-
}
|
|
754
|
-
this.pushDirectory(directoryPath, paths, filters)
|
|
755
|
-
const files = this.getArray(this.state.paths)
|
|
756
|
-
for (let i = 0; i < entries.length; ++i) {
|
|
757
|
-
const entry = entries[i]
|
|
758
|
-
if (
|
|
759
|
-
entry.isFile() ||
|
|
760
|
-
(entry.isSymbolicLink() && !resolveSymlinks && !excludeSymlinks)
|
|
761
|
-
) {
|
|
762
|
-
const filename = this.joinPath(entry.name, directoryPath)
|
|
763
|
-
this.pushFile(filename, files, this.state.counts, filters)
|
|
764
|
-
} else if (entry.isDirectory()) {
|
|
765
|
-
let path = joinPath.joinDirectoryPath(
|
|
766
|
-
entry.name,
|
|
767
|
-
directoryPath,
|
|
768
|
-
this.state.options.pathSeparator
|
|
769
|
-
)
|
|
770
|
-
if (exclude && exclude(entry.name, path)) {
|
|
771
|
-
continue
|
|
772
|
-
}
|
|
773
|
-
this.walkDirectory(this.state, path, path, depth - 1, this.walk)
|
|
774
|
-
} else if (entry.isSymbolicLink() && this.resolveSymlink) {
|
|
775
|
-
let path = joinPath.joinPathWithBasePath(entry.name, directoryPath)
|
|
776
|
-
this.resolveSymlink(path, this.state, (stat, resolvedPath) => {
|
|
777
|
-
if (stat.isDirectory()) {
|
|
778
|
-
resolvedPath = (0, utils_1.normalizePath)(
|
|
779
|
-
resolvedPath,
|
|
780
|
-
this.state.options
|
|
781
|
-
)
|
|
782
|
-
if (
|
|
783
|
-
exclude &&
|
|
784
|
-
exclude(
|
|
785
|
-
entry.name,
|
|
786
|
-
useRealPaths ? resolvedPath : path + pathSeparator
|
|
787
|
-
)
|
|
788
|
-
) {
|
|
789
|
-
return
|
|
790
|
-
}
|
|
791
|
-
this.walkDirectory(
|
|
792
|
-
this.state,
|
|
793
|
-
resolvedPath,
|
|
794
|
-
useRealPaths ? resolvedPath : path + pathSeparator,
|
|
795
|
-
depth - 1,
|
|
796
|
-
this.walk
|
|
797
|
-
)
|
|
798
|
-
} else {
|
|
799
|
-
resolvedPath = useRealPaths ? resolvedPath : path
|
|
800
|
-
const filename = (0, path_1.basename)(resolvedPath)
|
|
801
|
-
const directoryPath = (0, utils_1.normalizePath)(
|
|
802
|
-
(0, path_1.dirname)(resolvedPath),
|
|
803
|
-
this.state.options
|
|
804
|
-
)
|
|
805
|
-
resolvedPath = this.joinPath(filename, directoryPath)
|
|
806
|
-
this.pushFile(resolvedPath, files, this.state.counts, filters)
|
|
807
|
-
}
|
|
808
|
-
})
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
this.groupFiles(this.state.groups, directoryPath, files)
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
walker.Walker = Walker
|
|
815
|
-
return walker
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
let hasRequiredAsync
|
|
819
|
-
function requireAsync() {
|
|
820
|
-
if (hasRequiredAsync) {
|
|
821
|
-
return async
|
|
822
|
-
}
|
|
823
|
-
hasRequiredAsync = 1
|
|
824
|
-
Object.defineProperty(async, '__esModule', {
|
|
825
|
-
value: true
|
|
826
|
-
})
|
|
827
|
-
async.callback = async.promise = void 0
|
|
828
|
-
const walker_1 = requireWalker()
|
|
829
|
-
function promise(root, options) {
|
|
830
|
-
return new Promise((resolve, reject) => {
|
|
831
|
-
callback(root, options, (err, output) => {
|
|
832
|
-
if (err) {
|
|
833
|
-
return reject(err)
|
|
834
|
-
}
|
|
835
|
-
resolve(output)
|
|
836
|
-
})
|
|
837
|
-
})
|
|
838
|
-
}
|
|
839
|
-
async.promise = promise
|
|
840
|
-
function callback(root, options, callback) {
|
|
841
|
-
let walker = new walker_1.Walker(root, options, callback)
|
|
842
|
-
walker.start()
|
|
843
|
-
}
|
|
844
|
-
async.callback = callback
|
|
845
|
-
return async
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
const sync = {}
|
|
849
|
-
|
|
850
|
-
let hasRequiredSync
|
|
851
|
-
function requireSync() {
|
|
852
|
-
if (hasRequiredSync) {
|
|
853
|
-
return sync
|
|
854
|
-
}
|
|
855
|
-
hasRequiredSync = 1
|
|
856
|
-
Object.defineProperty(sync, '__esModule', {
|
|
857
|
-
value: true
|
|
858
|
-
})
|
|
859
|
-
sync.sync = void 0
|
|
860
|
-
const walker_1 = requireWalker()
|
|
861
|
-
function sync$1(root, options) {
|
|
862
|
-
const walker = new walker_1.Walker(root, options)
|
|
863
|
-
return walker.start()
|
|
864
|
-
}
|
|
865
|
-
sync.sync = sync$1
|
|
866
|
-
return sync
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
let hasRequiredApiBuilder
|
|
870
|
-
function requireApiBuilder() {
|
|
871
|
-
if (hasRequiredApiBuilder) {
|
|
872
|
-
return apiBuilder
|
|
873
|
-
}
|
|
874
|
-
hasRequiredApiBuilder = 1
|
|
875
|
-
Object.defineProperty(apiBuilder, '__esModule', {
|
|
876
|
-
value: true
|
|
877
|
-
})
|
|
878
|
-
apiBuilder.APIBuilder = void 0
|
|
879
|
-
const async_1 = requireAsync()
|
|
880
|
-
const sync_1 = requireSync()
|
|
881
|
-
class APIBuilder {
|
|
882
|
-
root
|
|
883
|
-
options
|
|
884
|
-
constructor(root, options) {
|
|
885
|
-
this.root = root
|
|
886
|
-
this.options = options
|
|
887
|
-
}
|
|
888
|
-
withPromise() {
|
|
889
|
-
return (0, async_1.promise)(this.root, this.options)
|
|
890
|
-
}
|
|
891
|
-
withCallback(cb) {
|
|
892
|
-
;(0, async_1.callback)(this.root, this.options, cb)
|
|
893
|
-
}
|
|
894
|
-
sync() {
|
|
895
|
-
return (0, sync_1.sync)(this.root, this.options)
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
apiBuilder.APIBuilder = APIBuilder
|
|
899
|
-
return apiBuilder
|
|
900
|
-
}
|
|
901
|
-
|
|
902
|
-
const utils = {}
|
|
903
|
-
|
|
904
|
-
let constants
|
|
905
|
-
let hasRequiredConstants
|
|
906
|
-
function requireConstants() {
|
|
907
|
-
if (hasRequiredConstants) {
|
|
908
|
-
return constants
|
|
909
|
-
}
|
|
910
|
-
hasRequiredConstants = 1
|
|
911
|
-
const WIN_SLASH = '\\\\/'
|
|
912
|
-
const WIN_NO_SLASH = `[^${WIN_SLASH}]`
|
|
913
|
-
|
|
914
|
-
/**
|
|
915
|
-
* Posix glob regex
|
|
916
|
-
*/
|
|
917
|
-
|
|
918
|
-
const DOT_LITERAL = '\\.'
|
|
919
|
-
const PLUS_LITERAL = '\\+'
|
|
920
|
-
const QMARK_LITERAL = '\\?'
|
|
921
|
-
const SLASH_LITERAL = '\\/'
|
|
922
|
-
const ONE_CHAR = '(?=.)'
|
|
923
|
-
const QMARK = '[^/]'
|
|
924
|
-
const END_ANCHOR = `(?:${SLASH_LITERAL}|$)`
|
|
925
|
-
const START_ANCHOR = `(?:^|${SLASH_LITERAL})`
|
|
926
|
-
const DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`
|
|
927
|
-
const NO_DOT = `(?!${DOT_LITERAL})`
|
|
928
|
-
const NO_DOTS = `(?!${START_ANCHOR}${DOTS_SLASH})`
|
|
929
|
-
const NO_DOT_SLASH = `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`
|
|
930
|
-
const NO_DOTS_SLASH = `(?!${DOTS_SLASH})`
|
|
931
|
-
const QMARK_NO_DOT = `[^.${SLASH_LITERAL}]`
|
|
932
|
-
const STAR = `${QMARK}*?`
|
|
933
|
-
const SEP = '/'
|
|
934
|
-
const POSIX_CHARS = {
|
|
935
|
-
DOT_LITERAL,
|
|
936
|
-
PLUS_LITERAL,
|
|
937
|
-
QMARK_LITERAL,
|
|
938
|
-
SLASH_LITERAL,
|
|
939
|
-
ONE_CHAR,
|
|
940
|
-
QMARK,
|
|
941
|
-
END_ANCHOR,
|
|
942
|
-
DOTS_SLASH,
|
|
943
|
-
NO_DOT,
|
|
944
|
-
NO_DOTS,
|
|
945
|
-
NO_DOT_SLASH,
|
|
946
|
-
NO_DOTS_SLASH,
|
|
947
|
-
QMARK_NO_DOT,
|
|
948
|
-
STAR,
|
|
949
|
-
START_ANCHOR,
|
|
950
|
-
SEP
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
/**
|
|
954
|
-
* Windows glob regex
|
|
955
|
-
*/
|
|
956
|
-
|
|
957
|
-
const WINDOWS_CHARS = {
|
|
958
|
-
...POSIX_CHARS,
|
|
959
|
-
SLASH_LITERAL: `[${WIN_SLASH}]`,
|
|
960
|
-
QMARK: WIN_NO_SLASH,
|
|
961
|
-
STAR: `${WIN_NO_SLASH}*?`,
|
|
962
|
-
DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`,
|
|
963
|
-
NO_DOT: `(?!${DOT_LITERAL})`,
|
|
964
|
-
NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
|
965
|
-
NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`,
|
|
966
|
-
NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
|
967
|
-
QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
|
|
968
|
-
START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
|
|
969
|
-
END_ANCHOR: `(?:[${WIN_SLASH}]|$)`,
|
|
970
|
-
SEP: '\\'
|
|
971
|
-
}
|
|
972
|
-
|
|
973
|
-
/**
|
|
974
|
-
* POSIX Bracket Regex
|
|
975
|
-
*/
|
|
976
|
-
|
|
977
|
-
const POSIX_REGEX_SOURCE = {
|
|
978
|
-
alnum: 'a-zA-Z0-9',
|
|
979
|
-
alpha: 'a-zA-Z',
|
|
980
|
-
ascii: '\\x00-\\x7F',
|
|
981
|
-
blank: ' \\t',
|
|
982
|
-
cntrl: '\\x00-\\x1F\\x7F',
|
|
983
|
-
digit: '0-9',
|
|
984
|
-
graph: '\\x21-\\x7E',
|
|
985
|
-
lower: 'a-z',
|
|
986
|
-
print: '\\x20-\\x7E ',
|
|
987
|
-
punct: '\\-!"#$%&\'()\\*+,./:;<=>?@[\\]^_`{|}~',
|
|
988
|
-
space: ' \\t\\r\\n\\v\\f',
|
|
989
|
-
upper: 'A-Z',
|
|
990
|
-
word: 'A-Za-z0-9_',
|
|
991
|
-
xdigit: 'A-Fa-f0-9'
|
|
992
|
-
}
|
|
993
|
-
constants = {
|
|
994
|
-
MAX_LENGTH: 1024 * 64,
|
|
995
|
-
POSIX_REGEX_SOURCE,
|
|
996
|
-
// regular expressions
|
|
997
|
-
REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
|
|
998
|
-
REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
|
|
999
|
-
REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
|
|
1000
|
-
REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
|
|
1001
|
-
REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
|
|
1002
|
-
REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
|
|
1003
|
-
// Replace globs with equivalent patterns to reduce parsing time.
|
|
1004
|
-
REPLACEMENTS: {
|
|
1005
|
-
'***': '*',
|
|
1006
|
-
'**/**': '**',
|
|
1007
|
-
'**/**/**': '**'
|
|
1008
|
-
},
|
|
1009
|
-
// Digits
|
|
1010
|
-
CHAR_0: 48,
|
|
1011
|
-
/* 0 */
|
|
1012
|
-
CHAR_9: 57,
|
|
1013
|
-
/* 9 */
|
|
1014
|
-
|
|
1015
|
-
// Alphabet chars.
|
|
1016
|
-
CHAR_UPPERCASE_A: 65,
|
|
1017
|
-
/* A */
|
|
1018
|
-
CHAR_LOWERCASE_A: 97,
|
|
1019
|
-
/* a */
|
|
1020
|
-
CHAR_UPPERCASE_Z: 90,
|
|
1021
|
-
/* Z */
|
|
1022
|
-
CHAR_LOWERCASE_Z: 122,
|
|
1023
|
-
/* z */
|
|
1024
|
-
|
|
1025
|
-
CHAR_LEFT_PARENTHESES: 40,
|
|
1026
|
-
/* ( */
|
|
1027
|
-
CHAR_RIGHT_PARENTHESES: 41,
|
|
1028
|
-
/* ) */
|
|
1029
|
-
|
|
1030
|
-
CHAR_ASTERISK: 42,
|
|
1031
|
-
/* * */
|
|
1032
|
-
|
|
1033
|
-
// Non-alphabetic chars.
|
|
1034
|
-
CHAR_AMPERSAND: 38,
|
|
1035
|
-
/* & */
|
|
1036
|
-
CHAR_AT: 64,
|
|
1037
|
-
/* @ */
|
|
1038
|
-
CHAR_BACKWARD_SLASH: 92,
|
|
1039
|
-
/* \ */
|
|
1040
|
-
CHAR_CARRIAGE_RETURN: 13,
|
|
1041
|
-
/* \r */
|
|
1042
|
-
CHAR_CIRCUMFLEX_ACCENT: 94,
|
|
1043
|
-
/* ^ */
|
|
1044
|
-
CHAR_COLON: 58,
|
|
1045
|
-
/* : */
|
|
1046
|
-
CHAR_COMMA: 44,
|
|
1047
|
-
/* , */
|
|
1048
|
-
CHAR_DOT: 46,
|
|
1049
|
-
/* . */
|
|
1050
|
-
CHAR_DOUBLE_QUOTE: 34,
|
|
1051
|
-
/* " */
|
|
1052
|
-
CHAR_EQUAL: 61,
|
|
1053
|
-
/* = */
|
|
1054
|
-
CHAR_EXCLAMATION_MARK: 33,
|
|
1055
|
-
/* ! */
|
|
1056
|
-
CHAR_FORM_FEED: 12,
|
|
1057
|
-
/* \f */
|
|
1058
|
-
CHAR_FORWARD_SLASH: 47,
|
|
1059
|
-
/* / */
|
|
1060
|
-
CHAR_GRAVE_ACCENT: 96,
|
|
1061
|
-
/* ` */
|
|
1062
|
-
CHAR_HASH: 35,
|
|
1063
|
-
/* # */
|
|
1064
|
-
CHAR_HYPHEN_MINUS: 45,
|
|
1065
|
-
/* - */
|
|
1066
|
-
CHAR_LEFT_ANGLE_BRACKET: 60,
|
|
1067
|
-
/* < */
|
|
1068
|
-
CHAR_LEFT_CURLY_BRACE: 123,
|
|
1069
|
-
/* { */
|
|
1070
|
-
CHAR_LEFT_SQUARE_BRACKET: 91,
|
|
1071
|
-
/* [ */
|
|
1072
|
-
CHAR_LINE_FEED: 10,
|
|
1073
|
-
/* \n */
|
|
1074
|
-
CHAR_NO_BREAK_SPACE: 160,
|
|
1075
|
-
/* \u00A0 */
|
|
1076
|
-
CHAR_PERCENT: 37,
|
|
1077
|
-
/* % */
|
|
1078
|
-
CHAR_PLUS: 43,
|
|
1079
|
-
/* + */
|
|
1080
|
-
CHAR_QUESTION_MARK: 63,
|
|
1081
|
-
/* ? */
|
|
1082
|
-
CHAR_RIGHT_ANGLE_BRACKET: 62,
|
|
1083
|
-
/* > */
|
|
1084
|
-
CHAR_RIGHT_CURLY_BRACE: 125,
|
|
1085
|
-
/* } */
|
|
1086
|
-
CHAR_RIGHT_SQUARE_BRACKET: 93,
|
|
1087
|
-
/* ] */
|
|
1088
|
-
CHAR_SEMICOLON: 59,
|
|
1089
|
-
/* ; */
|
|
1090
|
-
CHAR_SINGLE_QUOTE: 39,
|
|
1091
|
-
/* ' */
|
|
1092
|
-
CHAR_SPACE: 32,
|
|
1093
|
-
/* */
|
|
1094
|
-
CHAR_TAB: 9,
|
|
1095
|
-
/* \t */
|
|
1096
|
-
CHAR_UNDERSCORE: 95,
|
|
1097
|
-
/* _ */
|
|
1098
|
-
CHAR_VERTICAL_LINE: 124,
|
|
1099
|
-
/* | */
|
|
1100
|
-
CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279,
|
|
1101
|
-
/* \uFEFF */
|
|
1102
|
-
|
|
1103
|
-
/**
|
|
1104
|
-
* Create EXTGLOB_CHARS
|
|
1105
|
-
*/
|
|
1106
|
-
|
|
1107
|
-
extglobChars(chars) {
|
|
1108
|
-
return {
|
|
1109
|
-
'!': {
|
|
1110
|
-
type: 'negate',
|
|
1111
|
-
open: '(?:(?!(?:',
|
|
1112
|
-
close: `))${chars.STAR})`
|
|
1113
|
-
},
|
|
1114
|
-
'?': {
|
|
1115
|
-
type: 'qmark',
|
|
1116
|
-
open: '(?:',
|
|
1117
|
-
close: ')?'
|
|
1118
|
-
},
|
|
1119
|
-
'+': {
|
|
1120
|
-
type: 'plus',
|
|
1121
|
-
open: '(?:',
|
|
1122
|
-
close: ')+'
|
|
1123
|
-
},
|
|
1124
|
-
'*': {
|
|
1125
|
-
type: 'star',
|
|
1126
|
-
open: '(?:',
|
|
1127
|
-
close: ')*'
|
|
1128
|
-
},
|
|
1129
|
-
'@': {
|
|
1130
|
-
type: 'at',
|
|
1131
|
-
open: '(?:',
|
|
1132
|
-
close: ')'
|
|
1133
|
-
}
|
|
1134
|
-
}
|
|
1135
|
-
},
|
|
1136
|
-
/**
|
|
1137
|
-
* Create GLOB_CHARS
|
|
1138
|
-
*/
|
|
1139
|
-
|
|
1140
|
-
globChars(win32) {
|
|
1141
|
-
return win32 === true ? WINDOWS_CHARS : POSIX_CHARS
|
|
1142
|
-
}
|
|
1143
|
-
}
|
|
1144
|
-
return constants
|
|
1145
|
-
}
|
|
1146
|
-
|
|
1147
|
-
/*global navigator*/
|
|
1148
|
-
let hasRequiredUtils
|
|
1149
|
-
function requireUtils() {
|
|
1150
|
-
if (hasRequiredUtils) {
|
|
1151
|
-
return utils
|
|
1152
|
-
}
|
|
1153
|
-
hasRequiredUtils = 1
|
|
1154
|
-
;(function (exports) {
|
|
1155
|
-
const {
|
|
1156
|
-
REGEX_BACKSLASH,
|
|
1157
|
-
REGEX_REMOVE_BACKSLASH,
|
|
1158
|
-
REGEX_SPECIAL_CHARS,
|
|
1159
|
-
REGEX_SPECIAL_CHARS_GLOBAL
|
|
1160
|
-
} = /*@__PURE__*/ requireConstants()
|
|
1161
|
-
exports.isObject = val =>
|
|
1162
|
-
val !== null && typeof val === 'object' && !Array.isArray(val)
|
|
1163
|
-
exports.hasRegexChars = str => REGEX_SPECIAL_CHARS.test(str)
|
|
1164
|
-
exports.isRegexChar = str => str.length === 1 && exports.hasRegexChars(str)
|
|
1165
|
-
exports.escapeRegex = str => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, '\\$1')
|
|
1166
|
-
exports.toPosixSlashes = str => str.replace(REGEX_BACKSLASH, '/')
|
|
1167
|
-
exports.isWindows = () => {
|
|
1168
|
-
if (typeof navigator !== 'undefined' && navigator.platform) {
|
|
1169
|
-
const platform = navigator.platform.toLowerCase()
|
|
1170
|
-
return platform === 'win32' || platform === 'windows'
|
|
1171
|
-
}
|
|
1172
|
-
if (typeof process !== 'undefined' && process.platform) {
|
|
1173
|
-
return process.platform === 'win32'
|
|
1174
|
-
}
|
|
1175
|
-
return false
|
|
1176
|
-
}
|
|
1177
|
-
exports.removeBackslashes = str => {
|
|
1178
|
-
return str.replace(REGEX_REMOVE_BACKSLASH, match => {
|
|
1179
|
-
return match === '\\' ? '' : match
|
|
1180
|
-
})
|
|
1181
|
-
}
|
|
1182
|
-
exports.escapeLast = (input, char, lastIdx) => {
|
|
1183
|
-
const idx = input.lastIndexOf(char, lastIdx)
|
|
1184
|
-
if (idx === -1) {
|
|
1185
|
-
return input
|
|
1186
|
-
}
|
|
1187
|
-
if (input[idx - 1] === '\\') {
|
|
1188
|
-
return exports.escapeLast(input, char, idx - 1)
|
|
1189
|
-
}
|
|
1190
|
-
return `${input.slice(0, idx)}\\${input.slice(idx)}`
|
|
1191
|
-
}
|
|
1192
|
-
exports.removePrefix = (input, state = {}) => {
|
|
1193
|
-
let output = input
|
|
1194
|
-
if (output.startsWith('./')) {
|
|
1195
|
-
output = output.slice(2)
|
|
1196
|
-
state.prefix = './'
|
|
1197
|
-
}
|
|
1198
|
-
return output
|
|
1199
|
-
}
|
|
1200
|
-
exports.wrapOutput = (input, state = {}, options = {}) => {
|
|
1201
|
-
const prepend = options.contains ? '' : '^'
|
|
1202
|
-
const append = options.contains ? '' : '$'
|
|
1203
|
-
let output = `${prepend}(?:${input})${append}`
|
|
1204
|
-
if (state.negated === true) {
|
|
1205
|
-
output = `(?:^(?!${output}).*$)`
|
|
1206
|
-
}
|
|
1207
|
-
return output
|
|
1208
|
-
}
|
|
1209
|
-
exports.basename = (path, { windows } = {}) => {
|
|
1210
|
-
const segs = path.split(windows ? /[\\/]/ : '/')
|
|
1211
|
-
const last = segs[segs.length - 1]
|
|
1212
|
-
if (last === '') {
|
|
1213
|
-
return segs[segs.length - 2]
|
|
1214
|
-
}
|
|
1215
|
-
return last
|
|
1216
|
-
}
|
|
1217
|
-
})(utils)
|
|
1218
|
-
return utils
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
|
-
let scan_1
|
|
1222
|
-
let hasRequiredScan
|
|
1223
|
-
function requireScan() {
|
|
1224
|
-
if (hasRequiredScan) {
|
|
1225
|
-
return scan_1
|
|
1226
|
-
}
|
|
1227
|
-
hasRequiredScan = 1
|
|
1228
|
-
const utils = /*@__PURE__*/ requireUtils()
|
|
1229
|
-
const {
|
|
1230
|
-
CHAR_ASTERISK,
|
|
1231
|
-
/* * */
|
|
1232
|
-
CHAR_AT,
|
|
1233
|
-
/* @ */
|
|
1234
|
-
CHAR_BACKWARD_SLASH,
|
|
1235
|
-
/* \ */
|
|
1236
|
-
CHAR_COMMA,
|
|
1237
|
-
/* , */
|
|
1238
|
-
CHAR_DOT,
|
|
1239
|
-
/* . */
|
|
1240
|
-
CHAR_EXCLAMATION_MARK,
|
|
1241
|
-
/* ! */
|
|
1242
|
-
CHAR_FORWARD_SLASH,
|
|
1243
|
-
/* / */
|
|
1244
|
-
CHAR_LEFT_CURLY_BRACE,
|
|
1245
|
-
/* { */
|
|
1246
|
-
CHAR_LEFT_PARENTHESES,
|
|
1247
|
-
/* ( */
|
|
1248
|
-
CHAR_LEFT_SQUARE_BRACKET,
|
|
1249
|
-
/* [ */
|
|
1250
|
-
CHAR_PLUS,
|
|
1251
|
-
/* + */
|
|
1252
|
-
CHAR_QUESTION_MARK,
|
|
1253
|
-
/* ? */
|
|
1254
|
-
CHAR_RIGHT_CURLY_BRACE,
|
|
1255
|
-
/* } */
|
|
1256
|
-
CHAR_RIGHT_PARENTHESES,
|
|
1257
|
-
/* ) */
|
|
1258
|
-
CHAR_RIGHT_SQUARE_BRACKET /* ] */
|
|
1259
|
-
} = /*@__PURE__*/ requireConstants()
|
|
1260
|
-
const isPathSeparator = code => {
|
|
1261
|
-
return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH
|
|
1262
|
-
}
|
|
1263
|
-
const depth = token => {
|
|
1264
|
-
if (token.isPrefix !== true) {
|
|
1265
|
-
token.depth = token.isGlobstar ? Infinity : 1
|
|
1266
|
-
}
|
|
1267
|
-
}
|
|
1268
|
-
|
|
1269
|
-
/**
|
|
1270
|
-
* Quickly scans a glob pattern and returns an object with a handful of
|
|
1271
|
-
* useful properties, like `isGlob`, `path` (the leading non-glob, if it exists),
|
|
1272
|
-
* `glob` (the actual pattern), `negated` (true if the path starts with `!` but not
|
|
1273
|
-
* with `!(`) and `negatedExtglob` (true if the path starts with `!(`).
|
|
1274
|
-
*
|
|
1275
|
-
* ```js
|
|
1276
|
-
* const pm = require('picomatch');
|
|
1277
|
-
* console.log(pm.scan('foo/bar/*.js'));
|
|
1278
|
-
* { isGlob: true, input: 'foo/bar/*.js', base: 'foo/bar', glob: '*.js' }
|
|
1279
|
-
* ```
|
|
1280
|
-
* @param {String} `str`
|
|
1281
|
-
* @param {Object} `options`
|
|
1282
|
-
* @return {Object} Returns an object with tokens and regex source string.
|
|
1283
|
-
* @api public
|
|
1284
|
-
*/
|
|
1285
|
-
|
|
1286
|
-
const scan = (input, options) => {
|
|
1287
|
-
const opts = options || {}
|
|
1288
|
-
const length = input.length - 1
|
|
1289
|
-
const scanToEnd = opts.parts === true || opts.scanToEnd === true
|
|
1290
|
-
const slashes = []
|
|
1291
|
-
const tokens = []
|
|
1292
|
-
const parts = []
|
|
1293
|
-
let str = input
|
|
1294
|
-
let index = -1
|
|
1295
|
-
let start = 0
|
|
1296
|
-
let lastIndex = 0
|
|
1297
|
-
let isBrace = false
|
|
1298
|
-
let isBracket = false
|
|
1299
|
-
let isGlob = false
|
|
1300
|
-
let isExtglob = false
|
|
1301
|
-
let isGlobstar = false
|
|
1302
|
-
let braceEscaped = false
|
|
1303
|
-
let backslashes = false
|
|
1304
|
-
let negated = false
|
|
1305
|
-
let negatedExtglob = false
|
|
1306
|
-
let finished = false
|
|
1307
|
-
let braces = 0
|
|
1308
|
-
let prev
|
|
1309
|
-
let code
|
|
1310
|
-
let token = {
|
|
1311
|
-
value: '',
|
|
1312
|
-
depth: 0,
|
|
1313
|
-
isGlob: false
|
|
1314
|
-
}
|
|
1315
|
-
const eos = () => index >= length
|
|
1316
|
-
const peek = () => str.charCodeAt(index + 1)
|
|
1317
|
-
const advance = () => {
|
|
1318
|
-
prev = code
|
|
1319
|
-
return str.charCodeAt(++index)
|
|
1320
|
-
}
|
|
1321
|
-
while (index < length) {
|
|
1322
|
-
code = advance()
|
|
1323
|
-
let next
|
|
1324
|
-
if (code === CHAR_BACKWARD_SLASH) {
|
|
1325
|
-
backslashes = token.backslashes = true
|
|
1326
|
-
code = advance()
|
|
1327
|
-
if (code === CHAR_LEFT_CURLY_BRACE) {
|
|
1328
|
-
braceEscaped = true
|
|
1329
|
-
}
|
|
1330
|
-
continue
|
|
1331
|
-
}
|
|
1332
|
-
if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE) {
|
|
1333
|
-
braces++
|
|
1334
|
-
while (eos() !== true && (code = advance())) {
|
|
1335
|
-
if (code === CHAR_BACKWARD_SLASH) {
|
|
1336
|
-
backslashes = token.backslashes = true
|
|
1337
|
-
advance()
|
|
1338
|
-
continue
|
|
1339
|
-
}
|
|
1340
|
-
if (code === CHAR_LEFT_CURLY_BRACE) {
|
|
1341
|
-
braces++
|
|
1342
|
-
continue
|
|
1343
|
-
}
|
|
1344
|
-
if (
|
|
1345
|
-
braceEscaped !== true &&
|
|
1346
|
-
code === CHAR_DOT &&
|
|
1347
|
-
(code = advance()) === CHAR_DOT
|
|
1348
|
-
) {
|
|
1349
|
-
isBrace = token.isBrace = true
|
|
1350
|
-
isGlob = token.isGlob = true
|
|
1351
|
-
finished = true
|
|
1352
|
-
if (scanToEnd === true) {
|
|
1353
|
-
continue
|
|
1354
|
-
}
|
|
1355
|
-
break
|
|
1356
|
-
}
|
|
1357
|
-
if (braceEscaped !== true && code === CHAR_COMMA) {
|
|
1358
|
-
isBrace = token.isBrace = true
|
|
1359
|
-
isGlob = token.isGlob = true
|
|
1360
|
-
finished = true
|
|
1361
|
-
if (scanToEnd === true) {
|
|
1362
|
-
continue
|
|
1363
|
-
}
|
|
1364
|
-
break
|
|
1365
|
-
}
|
|
1366
|
-
if (code === CHAR_RIGHT_CURLY_BRACE) {
|
|
1367
|
-
braces--
|
|
1368
|
-
if (braces === 0) {
|
|
1369
|
-
braceEscaped = false
|
|
1370
|
-
isBrace = token.isBrace = true
|
|
1371
|
-
finished = true
|
|
1372
|
-
break
|
|
1373
|
-
}
|
|
1374
|
-
}
|
|
1375
|
-
}
|
|
1376
|
-
if (scanToEnd === true) {
|
|
1377
|
-
continue
|
|
1378
|
-
}
|
|
1379
|
-
break
|
|
1380
|
-
}
|
|
1381
|
-
if (code === CHAR_FORWARD_SLASH) {
|
|
1382
|
-
slashes.push(index)
|
|
1383
|
-
tokens.push(token)
|
|
1384
|
-
token = {
|
|
1385
|
-
value: '',
|
|
1386
|
-
depth: 0,
|
|
1387
|
-
isGlob: false
|
|
1388
|
-
}
|
|
1389
|
-
if (finished === true) {
|
|
1390
|
-
continue
|
|
1391
|
-
}
|
|
1392
|
-
if (prev === CHAR_DOT && index === start + 1) {
|
|
1393
|
-
start += 2
|
|
1394
|
-
continue
|
|
1395
|
-
}
|
|
1396
|
-
lastIndex = index + 1
|
|
1397
|
-
continue
|
|
1398
|
-
}
|
|
1399
|
-
if (opts.noext !== true) {
|
|
1400
|
-
const isExtglobChar =
|
|
1401
|
-
code === CHAR_PLUS ||
|
|
1402
|
-
code === CHAR_AT ||
|
|
1403
|
-
code === CHAR_ASTERISK ||
|
|
1404
|
-
code === CHAR_QUESTION_MARK ||
|
|
1405
|
-
code === CHAR_EXCLAMATION_MARK
|
|
1406
|
-
if (isExtglobChar === true && peek() === CHAR_LEFT_PARENTHESES) {
|
|
1407
|
-
isGlob = token.isGlob = true
|
|
1408
|
-
isExtglob = token.isExtglob = true
|
|
1409
|
-
finished = true
|
|
1410
|
-
if (code === CHAR_EXCLAMATION_MARK && index === start) {
|
|
1411
|
-
negatedExtglob = true
|
|
1412
|
-
}
|
|
1413
|
-
if (scanToEnd === true) {
|
|
1414
|
-
while (eos() !== true && (code = advance())) {
|
|
1415
|
-
if (code === CHAR_BACKWARD_SLASH) {
|
|
1416
|
-
backslashes = token.backslashes = true
|
|
1417
|
-
code = advance()
|
|
1418
|
-
continue
|
|
1419
|
-
}
|
|
1420
|
-
if (code === CHAR_RIGHT_PARENTHESES) {
|
|
1421
|
-
isGlob = token.isGlob = true
|
|
1422
|
-
finished = true
|
|
1423
|
-
break
|
|
1424
|
-
}
|
|
1425
|
-
}
|
|
1426
|
-
continue
|
|
1427
|
-
}
|
|
1428
|
-
break
|
|
1429
|
-
}
|
|
1430
|
-
}
|
|
1431
|
-
if (code === CHAR_ASTERISK) {
|
|
1432
|
-
if (prev === CHAR_ASTERISK) {
|
|
1433
|
-
isGlobstar = token.isGlobstar = true
|
|
1434
|
-
}
|
|
1435
|
-
isGlob = token.isGlob = true
|
|
1436
|
-
finished = true
|
|
1437
|
-
if (scanToEnd === true) {
|
|
1438
|
-
continue
|
|
1439
|
-
}
|
|
1440
|
-
break
|
|
1441
|
-
}
|
|
1442
|
-
if (code === CHAR_QUESTION_MARK) {
|
|
1443
|
-
isGlob = token.isGlob = true
|
|
1444
|
-
finished = true
|
|
1445
|
-
if (scanToEnd === true) {
|
|
1446
|
-
continue
|
|
1447
|
-
}
|
|
1448
|
-
break
|
|
1449
|
-
}
|
|
1450
|
-
if (code === CHAR_LEFT_SQUARE_BRACKET) {
|
|
1451
|
-
while (eos() !== true && (next = advance())) {
|
|
1452
|
-
if (next === CHAR_BACKWARD_SLASH) {
|
|
1453
|
-
backslashes = token.backslashes = true
|
|
1454
|
-
advance()
|
|
1455
|
-
continue
|
|
1456
|
-
}
|
|
1457
|
-
if (next === CHAR_RIGHT_SQUARE_BRACKET) {
|
|
1458
|
-
isBracket = token.isBracket = true
|
|
1459
|
-
isGlob = token.isGlob = true
|
|
1460
|
-
finished = true
|
|
1461
|
-
break
|
|
1462
|
-
}
|
|
1463
|
-
}
|
|
1464
|
-
if (scanToEnd === true) {
|
|
1465
|
-
continue
|
|
1466
|
-
}
|
|
1467
|
-
break
|
|
1468
|
-
}
|
|
1469
|
-
if (
|
|
1470
|
-
opts.nonegate !== true &&
|
|
1471
|
-
code === CHAR_EXCLAMATION_MARK &&
|
|
1472
|
-
index === start
|
|
1473
|
-
) {
|
|
1474
|
-
negated = token.negated = true
|
|
1475
|
-
start++
|
|
1476
|
-
continue
|
|
1477
|
-
}
|
|
1478
|
-
if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
|
|
1479
|
-
isGlob = token.isGlob = true
|
|
1480
|
-
if (scanToEnd === true) {
|
|
1481
|
-
while (eos() !== true && (code = advance())) {
|
|
1482
|
-
if (code === CHAR_LEFT_PARENTHESES) {
|
|
1483
|
-
backslashes = token.backslashes = true
|
|
1484
|
-
code = advance()
|
|
1485
|
-
continue
|
|
1486
|
-
}
|
|
1487
|
-
if (code === CHAR_RIGHT_PARENTHESES) {
|
|
1488
|
-
finished = true
|
|
1489
|
-
break
|
|
1490
|
-
}
|
|
1491
|
-
}
|
|
1492
|
-
continue
|
|
1493
|
-
}
|
|
1494
|
-
break
|
|
1495
|
-
}
|
|
1496
|
-
if (isGlob === true) {
|
|
1497
|
-
finished = true
|
|
1498
|
-
if (scanToEnd === true) {
|
|
1499
|
-
continue
|
|
1500
|
-
}
|
|
1501
|
-
break
|
|
1502
|
-
}
|
|
1503
|
-
}
|
|
1504
|
-
if (opts.noext === true) {
|
|
1505
|
-
isExtglob = false
|
|
1506
|
-
isGlob = false
|
|
1507
|
-
}
|
|
1508
|
-
let base = str
|
|
1509
|
-
let prefix = ''
|
|
1510
|
-
let glob = ''
|
|
1511
|
-
if (start > 0) {
|
|
1512
|
-
prefix = str.slice(0, start)
|
|
1513
|
-
str = str.slice(start)
|
|
1514
|
-
lastIndex -= start
|
|
1515
|
-
}
|
|
1516
|
-
if (base && isGlob === true && lastIndex > 0) {
|
|
1517
|
-
base = str.slice(0, lastIndex)
|
|
1518
|
-
glob = str.slice(lastIndex)
|
|
1519
|
-
} else if (isGlob === true) {
|
|
1520
|
-
base = ''
|
|
1521
|
-
glob = str
|
|
1522
|
-
} else {
|
|
1523
|
-
base = str
|
|
1524
|
-
}
|
|
1525
|
-
if (base && base !== '' && base !== '/' && base !== str) {
|
|
1526
|
-
if (isPathSeparator(base.charCodeAt(base.length - 1))) {
|
|
1527
|
-
base = base.slice(0, -1)
|
|
1528
|
-
}
|
|
1529
|
-
}
|
|
1530
|
-
if (opts.unescape === true) {
|
|
1531
|
-
if (glob) {
|
|
1532
|
-
glob = utils.removeBackslashes(glob)
|
|
1533
|
-
}
|
|
1534
|
-
if (base && backslashes === true) {
|
|
1535
|
-
base = utils.removeBackslashes(base)
|
|
1536
|
-
}
|
|
1537
|
-
}
|
|
1538
|
-
const state = {
|
|
1539
|
-
prefix,
|
|
1540
|
-
input,
|
|
1541
|
-
start,
|
|
1542
|
-
base,
|
|
1543
|
-
glob,
|
|
1544
|
-
isBrace,
|
|
1545
|
-
isBracket,
|
|
1546
|
-
isGlob,
|
|
1547
|
-
isExtglob,
|
|
1548
|
-
isGlobstar,
|
|
1549
|
-
negated,
|
|
1550
|
-
negatedExtglob
|
|
1551
|
-
}
|
|
1552
|
-
if (opts.tokens === true) {
|
|
1553
|
-
state.maxDepth = 0
|
|
1554
|
-
if (!isPathSeparator(code)) {
|
|
1555
|
-
tokens.push(token)
|
|
1556
|
-
}
|
|
1557
|
-
state.tokens = tokens
|
|
1558
|
-
}
|
|
1559
|
-
if (opts.parts === true || opts.tokens === true) {
|
|
1560
|
-
let prevIndex
|
|
1561
|
-
for (let idx = 0; idx < slashes.length; idx++) {
|
|
1562
|
-
const n = prevIndex ? prevIndex + 1 : start
|
|
1563
|
-
const i = slashes[idx]
|
|
1564
|
-
const value = input.slice(n, i)
|
|
1565
|
-
if (opts.tokens) {
|
|
1566
|
-
if (idx === 0 && start !== 0) {
|
|
1567
|
-
tokens[idx].isPrefix = true
|
|
1568
|
-
tokens[idx].value = prefix
|
|
1569
|
-
} else {
|
|
1570
|
-
tokens[idx].value = value
|
|
1571
|
-
}
|
|
1572
|
-
depth(tokens[idx])
|
|
1573
|
-
state.maxDepth += tokens[idx].depth
|
|
1574
|
-
}
|
|
1575
|
-
if (idx !== 0 || value !== '') {
|
|
1576
|
-
parts.push(value)
|
|
1577
|
-
}
|
|
1578
|
-
prevIndex = i
|
|
1579
|
-
}
|
|
1580
|
-
if (prevIndex && prevIndex + 1 < input.length) {
|
|
1581
|
-
const value = input.slice(prevIndex + 1)
|
|
1582
|
-
parts.push(value)
|
|
1583
|
-
if (opts.tokens) {
|
|
1584
|
-
tokens[tokens.length - 1].value = value
|
|
1585
|
-
depth(tokens[tokens.length - 1])
|
|
1586
|
-
state.maxDepth += tokens[tokens.length - 1].depth
|
|
1587
|
-
}
|
|
1588
|
-
}
|
|
1589
|
-
state.slashes = slashes
|
|
1590
|
-
state.parts = parts
|
|
1591
|
-
}
|
|
1592
|
-
return state
|
|
1593
|
-
}
|
|
1594
|
-
scan_1 = scan
|
|
1595
|
-
return scan_1
|
|
1596
|
-
}
|
|
1597
|
-
|
|
1598
|
-
let parse_1
|
|
1599
|
-
let hasRequiredParse
|
|
1600
|
-
function requireParse() {
|
|
1601
|
-
if (hasRequiredParse) {
|
|
1602
|
-
return parse_1
|
|
1603
|
-
}
|
|
1604
|
-
hasRequiredParse = 1
|
|
1605
|
-
const constants = /*@__PURE__*/ requireConstants()
|
|
1606
|
-
const utils = /*@__PURE__*/ requireUtils()
|
|
1607
|
-
|
|
1608
|
-
/**
|
|
1609
|
-
* Constants
|
|
1610
|
-
*/
|
|
1611
|
-
|
|
1612
|
-
const {
|
|
1613
|
-
MAX_LENGTH,
|
|
1614
|
-
POSIX_REGEX_SOURCE,
|
|
1615
|
-
REGEX_NON_SPECIAL_CHARS,
|
|
1616
|
-
REGEX_SPECIAL_CHARS_BACKREF,
|
|
1617
|
-
REPLACEMENTS
|
|
1618
|
-
} = constants
|
|
1619
|
-
|
|
1620
|
-
/**
|
|
1621
|
-
* Helpers
|
|
1622
|
-
*/
|
|
1623
|
-
|
|
1624
|
-
const expandRange = (args, options) => {
|
|
1625
|
-
if (typeof options.expandRange === 'function') {
|
|
1626
|
-
return options.expandRange(...args, options)
|
|
1627
|
-
}
|
|
1628
|
-
args.sort()
|
|
1629
|
-
const value = `[${args.join('-')}]`
|
|
1630
|
-
try {
|
|
1631
|
-
/* eslint-disable-next-line no-new */
|
|
1632
|
-
new RegExp(value)
|
|
1633
|
-
} catch (ex) {
|
|
1634
|
-
return args.map(v => utils.escapeRegex(v)).join('..')
|
|
1635
|
-
}
|
|
1636
|
-
return value
|
|
1637
|
-
}
|
|
1638
|
-
|
|
1639
|
-
/**
|
|
1640
|
-
* Create the message for a syntax error
|
|
1641
|
-
*/
|
|
1642
|
-
|
|
1643
|
-
const syntaxError = (type, char) => {
|
|
1644
|
-
return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`
|
|
1645
|
-
}
|
|
1646
|
-
|
|
1647
|
-
/**
|
|
1648
|
-
* Parse the given input string.
|
|
1649
|
-
* @param {String} input
|
|
1650
|
-
* @param {Object} options
|
|
1651
|
-
* @return {Object}
|
|
1652
|
-
*/
|
|
1653
|
-
|
|
1654
|
-
const parse = (input, options) => {
|
|
1655
|
-
if (typeof input !== 'string') {
|
|
1656
|
-
throw new TypeError('Expected a string')
|
|
1657
|
-
}
|
|
1658
|
-
input = REPLACEMENTS[input] || input
|
|
1659
|
-
const opts = {
|
|
1660
|
-
...options
|
|
1661
|
-
}
|
|
1662
|
-
const max =
|
|
1663
|
-
typeof opts.maxLength === 'number'
|
|
1664
|
-
? Math.min(MAX_LENGTH, opts.maxLength)
|
|
1665
|
-
: MAX_LENGTH
|
|
1666
|
-
let len = input.length
|
|
1667
|
-
if (len > max) {
|
|
1668
|
-
throw new SyntaxError(
|
|
1669
|
-
`Input length: ${len}, exceeds maximum allowed length: ${max}`
|
|
1670
|
-
)
|
|
1671
|
-
}
|
|
1672
|
-
const bos = {
|
|
1673
|
-
type: 'bos',
|
|
1674
|
-
value: '',
|
|
1675
|
-
output: opts.prepend || ''
|
|
1676
|
-
}
|
|
1677
|
-
const tokens = [bos]
|
|
1678
|
-
const capture = opts.capture ? '' : '?:'
|
|
1679
|
-
|
|
1680
|
-
// create constants based on platform, for windows or posix
|
|
1681
|
-
const PLATFORM_CHARS = constants.globChars(opts.windows)
|
|
1682
|
-
const EXTGLOB_CHARS = constants.extglobChars(PLATFORM_CHARS)
|
|
1683
|
-
const {
|
|
1684
|
-
DOT_LITERAL,
|
|
1685
|
-
PLUS_LITERAL,
|
|
1686
|
-
SLASH_LITERAL,
|
|
1687
|
-
ONE_CHAR,
|
|
1688
|
-
DOTS_SLASH,
|
|
1689
|
-
NO_DOT,
|
|
1690
|
-
NO_DOT_SLASH,
|
|
1691
|
-
NO_DOTS_SLASH,
|
|
1692
|
-
QMARK,
|
|
1693
|
-
QMARK_NO_DOT,
|
|
1694
|
-
STAR,
|
|
1695
|
-
START_ANCHOR
|
|
1696
|
-
} = PLATFORM_CHARS
|
|
1697
|
-
const globstar = opts => {
|
|
1698
|
-
return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`
|
|
1699
|
-
}
|
|
1700
|
-
const nodot = opts.dot ? '' : NO_DOT
|
|
1701
|
-
const qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT
|
|
1702
|
-
let star = opts.bash === true ? globstar(opts) : STAR
|
|
1703
|
-
if (opts.capture) {
|
|
1704
|
-
star = `(${star})`
|
|
1705
|
-
}
|
|
1706
|
-
|
|
1707
|
-
// minimatch options support
|
|
1708
|
-
if (typeof opts.noext === 'boolean') {
|
|
1709
|
-
opts.noextglob = opts.noext
|
|
1710
|
-
}
|
|
1711
|
-
const state = {
|
|
1712
|
-
input,
|
|
1713
|
-
index: -1,
|
|
1714
|
-
start: 0,
|
|
1715
|
-
dot: opts.dot === true,
|
|
1716
|
-
consumed: '',
|
|
1717
|
-
output: '',
|
|
1718
|
-
prefix: '',
|
|
1719
|
-
backtrack: false,
|
|
1720
|
-
negated: false,
|
|
1721
|
-
brackets: 0,
|
|
1722
|
-
braces: 0,
|
|
1723
|
-
parens: 0,
|
|
1724
|
-
quotes: 0,
|
|
1725
|
-
globstar: false,
|
|
1726
|
-
tokens
|
|
1727
|
-
}
|
|
1728
|
-
input = utils.removePrefix(input, state)
|
|
1729
|
-
len = input.length
|
|
1730
|
-
const extglobs = []
|
|
1731
|
-
const braces = []
|
|
1732
|
-
const stack = []
|
|
1733
|
-
let prev = bos
|
|
1734
|
-
let value
|
|
1735
|
-
|
|
1736
|
-
/**
|
|
1737
|
-
* Tokenizing helpers
|
|
1738
|
-
*/
|
|
1739
|
-
|
|
1740
|
-
const eos = () => state.index === len - 1
|
|
1741
|
-
const peek = (state.peek = (n = 1) => input[state.index + n])
|
|
1742
|
-
const advance = (state.advance = () => input[++state.index] || '')
|
|
1743
|
-
const remaining = () => input.slice(state.index + 1)
|
|
1744
|
-
const consume = (value = '', num = 0) => {
|
|
1745
|
-
state.consumed += value
|
|
1746
|
-
state.index += num
|
|
1747
|
-
}
|
|
1748
|
-
const append = token => {
|
|
1749
|
-
state.output += token.output != null ? token.output : token.value
|
|
1750
|
-
consume(token.value)
|
|
1751
|
-
}
|
|
1752
|
-
const negate = () => {
|
|
1753
|
-
let count = 1
|
|
1754
|
-
while (peek() === '!' && (peek(2) !== '(' || peek(3) === '?')) {
|
|
1755
|
-
advance()
|
|
1756
|
-
state.start++
|
|
1757
|
-
count++
|
|
1758
|
-
}
|
|
1759
|
-
if (count % 2 === 0) {
|
|
1760
|
-
return false
|
|
1761
|
-
}
|
|
1762
|
-
state.negated = true
|
|
1763
|
-
state.start++
|
|
1764
|
-
return true
|
|
1765
|
-
}
|
|
1766
|
-
const increment = type => {
|
|
1767
|
-
state[type]++
|
|
1768
|
-
stack.push(type)
|
|
1769
|
-
}
|
|
1770
|
-
const decrement = type => {
|
|
1771
|
-
state[type]--
|
|
1772
|
-
stack.pop()
|
|
1773
|
-
}
|
|
1774
|
-
|
|
1775
|
-
/**
|
|
1776
|
-
* Push tokens onto the tokens array. This helper speeds up
|
|
1777
|
-
* tokenizing by 1) helping us avoid backtracking as much as possible,
|
|
1778
|
-
* and 2) helping us avoid creating extra tokens when consecutive
|
|
1779
|
-
* characters are plain text. This improves performance and simplifies
|
|
1780
|
-
* lookbehinds.
|
|
1781
|
-
*/
|
|
1782
|
-
|
|
1783
|
-
const push = tok => {
|
|
1784
|
-
if (prev.type === 'globstar') {
|
|
1785
|
-
const isBrace =
|
|
1786
|
-
state.braces > 0 && (tok.type === 'comma' || tok.type === 'brace')
|
|
1787
|
-
const isExtglob =
|
|
1788
|
-
tok.extglob === true ||
|
|
1789
|
-
(extglobs.length && (tok.type === 'pipe' || tok.type === 'paren'))
|
|
1790
|
-
if (
|
|
1791
|
-
tok.type !== 'slash' &&
|
|
1792
|
-
tok.type !== 'paren' &&
|
|
1793
|
-
!isBrace &&
|
|
1794
|
-
!isExtglob
|
|
1795
|
-
) {
|
|
1796
|
-
state.output = state.output.slice(0, -prev.output.length)
|
|
1797
|
-
prev.type = 'star'
|
|
1798
|
-
prev.value = '*'
|
|
1799
|
-
prev.output = star
|
|
1800
|
-
state.output += prev.output
|
|
1801
|
-
}
|
|
1802
|
-
}
|
|
1803
|
-
if (extglobs.length && tok.type !== 'paren') {
|
|
1804
|
-
extglobs[extglobs.length - 1].inner += tok.value
|
|
1805
|
-
}
|
|
1806
|
-
if (tok.value || tok.output) {
|
|
1807
|
-
append(tok)
|
|
1808
|
-
}
|
|
1809
|
-
if (prev && prev.type === 'text' && tok.type === 'text') {
|
|
1810
|
-
prev.output = (prev.output || prev.value) + tok.value
|
|
1811
|
-
prev.value += tok.value
|
|
1812
|
-
return
|
|
1813
|
-
}
|
|
1814
|
-
tok.prev = prev
|
|
1815
|
-
tokens.push(tok)
|
|
1816
|
-
prev = tok
|
|
1817
|
-
}
|
|
1818
|
-
const extglobOpen = (type, value) => {
|
|
1819
|
-
const token = {
|
|
1820
|
-
...EXTGLOB_CHARS[value],
|
|
1821
|
-
conditions: 1,
|
|
1822
|
-
inner: ''
|
|
1823
|
-
}
|
|
1824
|
-
token.prev = prev
|
|
1825
|
-
token.parens = state.parens
|
|
1826
|
-
token.output = state.output
|
|
1827
|
-
const output = (opts.capture ? '(' : '') + token.open
|
|
1828
|
-
increment('parens')
|
|
1829
|
-
push({
|
|
1830
|
-
type,
|
|
1831
|
-
value,
|
|
1832
|
-
output: state.output ? '' : ONE_CHAR
|
|
1833
|
-
})
|
|
1834
|
-
push({
|
|
1835
|
-
type: 'paren',
|
|
1836
|
-
extglob: true,
|
|
1837
|
-
value: advance(),
|
|
1838
|
-
output
|
|
1839
|
-
})
|
|
1840
|
-
extglobs.push(token)
|
|
1841
|
-
}
|
|
1842
|
-
const extglobClose = token => {
|
|
1843
|
-
let output = token.close + (opts.capture ? ')' : '')
|
|
1844
|
-
let rest
|
|
1845
|
-
if (token.type === 'negate') {
|
|
1846
|
-
let extglobStar = star
|
|
1847
|
-
if (
|
|
1848
|
-
token.inner &&
|
|
1849
|
-
token.inner.length > 1 &&
|
|
1850
|
-
token.inner.includes('/')
|
|
1851
|
-
) {
|
|
1852
|
-
extglobStar = globstar(opts)
|
|
1853
|
-
}
|
|
1854
|
-
if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) {
|
|
1855
|
-
output = token.close = `)$))${extglobStar}`
|
|
1856
|
-
}
|
|
1857
|
-
if (
|
|
1858
|
-
token.inner.includes('*') &&
|
|
1859
|
-
(rest = remaining()) &&
|
|
1860
|
-
/^\.[^\\/.]+$/.test(rest)
|
|
1861
|
-
) {
|
|
1862
|
-
// Any non-magical string (`.ts`) or even nested expression (`.{ts,tsx}`) can follow after the closing parenthesis.
|
|
1863
|
-
// In this case, we need to parse the string and use it in the output of the original pattern.
|
|
1864
|
-
// Suitable patterns: `/!(*.d).ts`, `/!(*.d).{ts,tsx}`, `**/!(*-dbg).@(js)`.
|
|
1865
|
-
//
|
|
1866
|
-
// Disabling the `fastpaths` option due to a problem with parsing strings as `.ts` in the pattern like `**/!(*.d).ts`.
|
|
1867
|
-
const expression = parse(rest, {
|
|
1868
|
-
...options,
|
|
1869
|
-
fastpaths: false
|
|
1870
|
-
}).output
|
|
1871
|
-
output = token.close = `)${expression})${extglobStar})`
|
|
1872
|
-
}
|
|
1873
|
-
if (token.prev.type === 'bos') {
|
|
1874
|
-
state.negatedExtglob = true
|
|
1875
|
-
}
|
|
1876
|
-
}
|
|
1877
|
-
push({
|
|
1878
|
-
type: 'paren',
|
|
1879
|
-
extglob: true,
|
|
1880
|
-
value,
|
|
1881
|
-
output
|
|
1882
|
-
})
|
|
1883
|
-
decrement('parens')
|
|
1884
|
-
}
|
|
1885
|
-
|
|
1886
|
-
/**
|
|
1887
|
-
* Fast paths
|
|
1888
|
-
*/
|
|
1889
|
-
|
|
1890
|
-
if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) {
|
|
1891
|
-
let backslashes = false
|
|
1892
|
-
let output = input.replace(
|
|
1893
|
-
REGEX_SPECIAL_CHARS_BACKREF,
|
|
1894
|
-
(m, esc, chars, first, rest, index) => {
|
|
1895
|
-
if (first === '\\') {
|
|
1896
|
-
backslashes = true
|
|
1897
|
-
return m
|
|
1898
|
-
}
|
|
1899
|
-
if (first === '?') {
|
|
1900
|
-
if (esc) {
|
|
1901
|
-
return esc + first + (rest ? QMARK.repeat(rest.length) : '')
|
|
1902
|
-
}
|
|
1903
|
-
if (index === 0) {
|
|
1904
|
-
return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : '')
|
|
1905
|
-
}
|
|
1906
|
-
return QMARK.repeat(chars.length)
|
|
1907
|
-
}
|
|
1908
|
-
if (first === '.') {
|
|
1909
|
-
return DOT_LITERAL.repeat(chars.length)
|
|
1910
|
-
}
|
|
1911
|
-
if (first === '*') {
|
|
1912
|
-
if (esc) {
|
|
1913
|
-
return esc + first + (rest ? star : '')
|
|
1914
|
-
}
|
|
1915
|
-
return star
|
|
1916
|
-
}
|
|
1917
|
-
return esc ? m : `\\${m}`
|
|
1918
|
-
}
|
|
1919
|
-
)
|
|
1920
|
-
if (backslashes === true) {
|
|
1921
|
-
if (opts.unescape === true) {
|
|
1922
|
-
output = output.replace(/\\/g, '')
|
|
1923
|
-
} else {
|
|
1924
|
-
output = output.replace(/\\+/g, m => {
|
|
1925
|
-
return m.length % 2 === 0 ? '\\\\' : m ? '\\' : ''
|
|
1926
|
-
})
|
|
1927
|
-
}
|
|
1928
|
-
}
|
|
1929
|
-
if (output === input && opts.contains === true) {
|
|
1930
|
-
state.output = input
|
|
1931
|
-
return state
|
|
1932
|
-
}
|
|
1933
|
-
state.output = utils.wrapOutput(output, state, options)
|
|
1934
|
-
return state
|
|
1935
|
-
}
|
|
1936
|
-
|
|
1937
|
-
/**
|
|
1938
|
-
* Tokenize input until we reach end-of-string
|
|
1939
|
-
*/
|
|
1940
|
-
|
|
1941
|
-
while (!eos()) {
|
|
1942
|
-
value = advance()
|
|
1943
|
-
if (value === '\u0000') {
|
|
1944
|
-
continue
|
|
1945
|
-
}
|
|
1946
|
-
|
|
1947
|
-
/**
|
|
1948
|
-
* Escaped characters
|
|
1949
|
-
*/
|
|
1950
|
-
|
|
1951
|
-
if (value === '\\') {
|
|
1952
|
-
const next = peek()
|
|
1953
|
-
if (next === '/' && opts.bash !== true) {
|
|
1954
|
-
continue
|
|
1955
|
-
}
|
|
1956
|
-
if (next === '.' || next === ';') {
|
|
1957
|
-
continue
|
|
1958
|
-
}
|
|
1959
|
-
if (!next) {
|
|
1960
|
-
value += '\\'
|
|
1961
|
-
push({
|
|
1962
|
-
type: 'text',
|
|
1963
|
-
value
|
|
1964
|
-
})
|
|
1965
|
-
continue
|
|
1966
|
-
}
|
|
1967
|
-
|
|
1968
|
-
// collapse slashes to reduce potential for exploits
|
|
1969
|
-
const match = /^\\+/.exec(remaining())
|
|
1970
|
-
let slashes = 0
|
|
1971
|
-
if (match && match[0].length > 2) {
|
|
1972
|
-
slashes = match[0].length
|
|
1973
|
-
state.index += slashes
|
|
1974
|
-
if (slashes % 2 !== 0) {
|
|
1975
|
-
value += '\\'
|
|
1976
|
-
}
|
|
1977
|
-
}
|
|
1978
|
-
if (opts.unescape === true) {
|
|
1979
|
-
value = advance()
|
|
1980
|
-
} else {
|
|
1981
|
-
value += advance()
|
|
1982
|
-
}
|
|
1983
|
-
if (state.brackets === 0) {
|
|
1984
|
-
push({
|
|
1985
|
-
type: 'text',
|
|
1986
|
-
value
|
|
1987
|
-
})
|
|
1988
|
-
continue
|
|
1989
|
-
}
|
|
1990
|
-
}
|
|
1991
|
-
|
|
1992
|
-
/**
|
|
1993
|
-
* If we're inside a regex character class, continue
|
|
1994
|
-
* until we reach the closing bracket.
|
|
1995
|
-
*/
|
|
1996
|
-
|
|
1997
|
-
if (
|
|
1998
|
-
state.brackets > 0 &&
|
|
1999
|
-
(value !== ']' || prev.value === '[' || prev.value === '[^')
|
|
2000
|
-
) {
|
|
2001
|
-
if (opts.posix !== false && value === ':') {
|
|
2002
|
-
const inner = new Set(prev.value.slice(1))
|
|
2003
|
-
if (inner.has('[')) {
|
|
2004
|
-
prev.posix = true
|
|
2005
|
-
if (inner.has(':')) {
|
|
2006
|
-
const idx = prev.value.lastIndexOf('[')
|
|
2007
|
-
const pre = prev.value.slice(0, idx)
|
|
2008
|
-
const rest = prev.value.slice(idx + 2)
|
|
2009
|
-
const posix = POSIX_REGEX_SOURCE[rest]
|
|
2010
|
-
if (posix) {
|
|
2011
|
-
prev.value = pre + posix
|
|
2012
|
-
state.backtrack = true
|
|
2013
|
-
advance()
|
|
2014
|
-
if (!bos.output && tokens.indexOf(prev) === 1) {
|
|
2015
|
-
bos.output = ONE_CHAR
|
|
2016
|
-
}
|
|
2017
|
-
continue
|
|
2018
|
-
}
|
|
2019
|
-
}
|
|
2020
|
-
}
|
|
2021
|
-
}
|
|
2022
|
-
if (
|
|
2023
|
-
(value === '[' && peek() !== ':') ||
|
|
2024
|
-
(value === '-' && peek() === ']')
|
|
2025
|
-
) {
|
|
2026
|
-
value = `\\${value}`
|
|
2027
|
-
}
|
|
2028
|
-
if (value === ']' && (prev.value === '[' || prev.value === '[^')) {
|
|
2029
|
-
value = `\\${value}`
|
|
2030
|
-
}
|
|
2031
|
-
if (opts.posix === true && value === '!' && prev.value === '[') {
|
|
2032
|
-
value = '^'
|
|
2033
|
-
}
|
|
2034
|
-
prev.value += value
|
|
2035
|
-
append({
|
|
2036
|
-
value
|
|
2037
|
-
})
|
|
2038
|
-
continue
|
|
2039
|
-
}
|
|
2040
|
-
|
|
2041
|
-
/**
|
|
2042
|
-
* If we're inside a quoted string, continue
|
|
2043
|
-
* until we reach the closing double quote.
|
|
2044
|
-
*/
|
|
2045
|
-
|
|
2046
|
-
if (state.quotes === 1 && value !== '"') {
|
|
2047
|
-
value = utils.escapeRegex(value)
|
|
2048
|
-
prev.value += value
|
|
2049
|
-
append({
|
|
2050
|
-
value
|
|
2051
|
-
})
|
|
2052
|
-
continue
|
|
2053
|
-
}
|
|
2054
|
-
|
|
2055
|
-
/**
|
|
2056
|
-
* Double quotes
|
|
2057
|
-
*/
|
|
2058
|
-
|
|
2059
|
-
if (value === '"') {
|
|
2060
|
-
state.quotes = state.quotes === 1 ? 0 : 1
|
|
2061
|
-
if (opts.keepQuotes === true) {
|
|
2062
|
-
push({
|
|
2063
|
-
type: 'text',
|
|
2064
|
-
value
|
|
2065
|
-
})
|
|
2066
|
-
}
|
|
2067
|
-
continue
|
|
2068
|
-
}
|
|
2069
|
-
|
|
2070
|
-
/**
|
|
2071
|
-
* Parentheses
|
|
2072
|
-
*/
|
|
2073
|
-
|
|
2074
|
-
if (value === '(') {
|
|
2075
|
-
increment('parens')
|
|
2076
|
-
push({
|
|
2077
|
-
type: 'paren',
|
|
2078
|
-
value
|
|
2079
|
-
})
|
|
2080
|
-
continue
|
|
2081
|
-
}
|
|
2082
|
-
if (value === ')') {
|
|
2083
|
-
if (state.parens === 0 && opts.strictBrackets === true) {
|
|
2084
|
-
throw new SyntaxError(syntaxError('opening', '('))
|
|
2085
|
-
}
|
|
2086
|
-
const extglob = extglobs[extglobs.length - 1]
|
|
2087
|
-
if (extglob && state.parens === extglob.parens + 1) {
|
|
2088
|
-
extglobClose(extglobs.pop())
|
|
2089
|
-
continue
|
|
2090
|
-
}
|
|
2091
|
-
push({
|
|
2092
|
-
type: 'paren',
|
|
2093
|
-
value,
|
|
2094
|
-
output: state.parens ? ')' : '\\)'
|
|
2095
|
-
})
|
|
2096
|
-
decrement('parens')
|
|
2097
|
-
continue
|
|
2098
|
-
}
|
|
2099
|
-
|
|
2100
|
-
/**
|
|
2101
|
-
* Square brackets
|
|
2102
|
-
*/
|
|
2103
|
-
|
|
2104
|
-
if (value === '[') {
|
|
2105
|
-
if (opts.nobracket === true || !remaining().includes(']')) {
|
|
2106
|
-
if (opts.nobracket !== true && opts.strictBrackets === true) {
|
|
2107
|
-
throw new SyntaxError(syntaxError('closing', ']'))
|
|
2108
|
-
}
|
|
2109
|
-
value = `\\${value}`
|
|
2110
|
-
} else {
|
|
2111
|
-
increment('brackets')
|
|
2112
|
-
}
|
|
2113
|
-
push({
|
|
2114
|
-
type: 'bracket',
|
|
2115
|
-
value
|
|
2116
|
-
})
|
|
2117
|
-
continue
|
|
2118
|
-
}
|
|
2119
|
-
if (value === ']') {
|
|
2120
|
-
if (
|
|
2121
|
-
opts.nobracket === true ||
|
|
2122
|
-
(prev && prev.type === 'bracket' && prev.value.length === 1)
|
|
2123
|
-
) {
|
|
2124
|
-
push({
|
|
2125
|
-
type: 'text',
|
|
2126
|
-
value,
|
|
2127
|
-
output: `\\${value}`
|
|
2128
|
-
})
|
|
2129
|
-
continue
|
|
2130
|
-
}
|
|
2131
|
-
if (state.brackets === 0) {
|
|
2132
|
-
if (opts.strictBrackets === true) {
|
|
2133
|
-
throw new SyntaxError(syntaxError('opening', '['))
|
|
2134
|
-
}
|
|
2135
|
-
push({
|
|
2136
|
-
type: 'text',
|
|
2137
|
-
value,
|
|
2138
|
-
output: `\\${value}`
|
|
2139
|
-
})
|
|
2140
|
-
continue
|
|
2141
|
-
}
|
|
2142
|
-
decrement('brackets')
|
|
2143
|
-
const prevValue = prev.value.slice(1)
|
|
2144
|
-
if (
|
|
2145
|
-
prev.posix !== true &&
|
|
2146
|
-
prevValue[0] === '^' &&
|
|
2147
|
-
!prevValue.includes('/')
|
|
2148
|
-
) {
|
|
2149
|
-
value = `/${value}`
|
|
2150
|
-
}
|
|
2151
|
-
prev.value += value
|
|
2152
|
-
append({
|
|
2153
|
-
value
|
|
2154
|
-
})
|
|
2155
|
-
|
|
2156
|
-
// when literal brackets are explicitly disabled
|
|
2157
|
-
// assume we should match with a regex character class
|
|
2158
|
-
if (opts.literalBrackets === false || utils.hasRegexChars(prevValue)) {
|
|
2159
|
-
continue
|
|
2160
|
-
}
|
|
2161
|
-
const escaped = utils.escapeRegex(prev.value)
|
|
2162
|
-
state.output = state.output.slice(0, -prev.value.length)
|
|
2163
|
-
|
|
2164
|
-
// when literal brackets are explicitly enabled
|
|
2165
|
-
// assume we should escape the brackets to match literal characters
|
|
2166
|
-
if (opts.literalBrackets === true) {
|
|
2167
|
-
state.output += escaped
|
|
2168
|
-
prev.value = escaped
|
|
2169
|
-
continue
|
|
2170
|
-
}
|
|
2171
|
-
|
|
2172
|
-
// when the user specifies nothing, try to match both
|
|
2173
|
-
prev.value = `(${capture}${escaped}|${prev.value})`
|
|
2174
|
-
state.output += prev.value
|
|
2175
|
-
continue
|
|
2176
|
-
}
|
|
2177
|
-
|
|
2178
|
-
/**
|
|
2179
|
-
* Braces
|
|
2180
|
-
*/
|
|
2181
|
-
|
|
2182
|
-
if (value === '{' && opts.nobrace !== true) {
|
|
2183
|
-
increment('braces')
|
|
2184
|
-
const open = {
|
|
2185
|
-
type: 'brace',
|
|
2186
|
-
value,
|
|
2187
|
-
output: '(',
|
|
2188
|
-
outputIndex: state.output.length,
|
|
2189
|
-
tokensIndex: state.tokens.length
|
|
2190
|
-
}
|
|
2191
|
-
braces.push(open)
|
|
2192
|
-
push(open)
|
|
2193
|
-
continue
|
|
2194
|
-
}
|
|
2195
|
-
if (value === '}') {
|
|
2196
|
-
const brace = braces[braces.length - 1]
|
|
2197
|
-
if (opts.nobrace === true || !brace) {
|
|
2198
|
-
push({
|
|
2199
|
-
type: 'text',
|
|
2200
|
-
value,
|
|
2201
|
-
output: value
|
|
2202
|
-
})
|
|
2203
|
-
continue
|
|
2204
|
-
}
|
|
2205
|
-
let output = ')'
|
|
2206
|
-
if (brace.dots === true) {
|
|
2207
|
-
const arr = tokens.slice()
|
|
2208
|
-
const range = []
|
|
2209
|
-
for (let i = arr.length - 1; i >= 0; i--) {
|
|
2210
|
-
tokens.pop()
|
|
2211
|
-
if (arr[i].type === 'brace') {
|
|
2212
|
-
break
|
|
2213
|
-
}
|
|
2214
|
-
if (arr[i].type !== 'dots') {
|
|
2215
|
-
range.unshift(arr[i].value)
|
|
2216
|
-
}
|
|
2217
|
-
}
|
|
2218
|
-
output = expandRange(range, opts)
|
|
2219
|
-
state.backtrack = true
|
|
2220
|
-
}
|
|
2221
|
-
if (brace.comma !== true && brace.dots !== true) {
|
|
2222
|
-
const out = state.output.slice(0, brace.outputIndex)
|
|
2223
|
-
const toks = state.tokens.slice(brace.tokensIndex)
|
|
2224
|
-
brace.value = brace.output = '\\{'
|
|
2225
|
-
value = output = '\\}'
|
|
2226
|
-
state.output = out
|
|
2227
|
-
for (const t of toks) {
|
|
2228
|
-
state.output += t.output || t.value
|
|
2229
|
-
}
|
|
2230
|
-
}
|
|
2231
|
-
push({
|
|
2232
|
-
type: 'brace',
|
|
2233
|
-
value,
|
|
2234
|
-
output
|
|
2235
|
-
})
|
|
2236
|
-
decrement('braces')
|
|
2237
|
-
braces.pop()
|
|
2238
|
-
continue
|
|
2239
|
-
}
|
|
2240
|
-
|
|
2241
|
-
/**
|
|
2242
|
-
* Pipes
|
|
2243
|
-
*/
|
|
2244
|
-
|
|
2245
|
-
if (value === '|') {
|
|
2246
|
-
if (extglobs.length > 0) {
|
|
2247
|
-
extglobs[extglobs.length - 1].conditions++
|
|
2248
|
-
}
|
|
2249
|
-
push({
|
|
2250
|
-
type: 'text',
|
|
2251
|
-
value
|
|
2252
|
-
})
|
|
2253
|
-
continue
|
|
2254
|
-
}
|
|
2255
|
-
|
|
2256
|
-
/**
|
|
2257
|
-
* Commas
|
|
2258
|
-
*/
|
|
2259
|
-
|
|
2260
|
-
if (value === ',') {
|
|
2261
|
-
let output = value
|
|
2262
|
-
const brace = braces[braces.length - 1]
|
|
2263
|
-
if (brace && stack[stack.length - 1] === 'braces') {
|
|
2264
|
-
brace.comma = true
|
|
2265
|
-
output = '|'
|
|
2266
|
-
}
|
|
2267
|
-
push({
|
|
2268
|
-
type: 'comma',
|
|
2269
|
-
value,
|
|
2270
|
-
output
|
|
2271
|
-
})
|
|
2272
|
-
continue
|
|
2273
|
-
}
|
|
2274
|
-
|
|
2275
|
-
/**
|
|
2276
|
-
* Slashes
|
|
2277
|
-
*/
|
|
2278
|
-
|
|
2279
|
-
if (value === '/') {
|
|
2280
|
-
// if the beginning of the glob is "./", advance the start
|
|
2281
|
-
// to the current index, and don't add the "./" characters
|
|
2282
|
-
// to the state. This greatly simplifies lookbehinds when
|
|
2283
|
-
// checking for BOS characters like "!" and "." (not "./")
|
|
2284
|
-
if (prev.type === 'dot' && state.index === state.start + 1) {
|
|
2285
|
-
state.start = state.index + 1
|
|
2286
|
-
state.consumed = ''
|
|
2287
|
-
state.output = ''
|
|
2288
|
-
tokens.pop()
|
|
2289
|
-
prev = bos // reset "prev" to the first token
|
|
2290
|
-
continue
|
|
2291
|
-
}
|
|
2292
|
-
push({
|
|
2293
|
-
type: 'slash',
|
|
2294
|
-
value,
|
|
2295
|
-
output: SLASH_LITERAL
|
|
2296
|
-
})
|
|
2297
|
-
continue
|
|
2298
|
-
}
|
|
2299
|
-
|
|
2300
|
-
/**
|
|
2301
|
-
* Dots
|
|
2302
|
-
*/
|
|
2303
|
-
|
|
2304
|
-
if (value === '.') {
|
|
2305
|
-
if (state.braces > 0 && prev.type === 'dot') {
|
|
2306
|
-
if (prev.value === '.') {
|
|
2307
|
-
prev.output = DOT_LITERAL
|
|
2308
|
-
}
|
|
2309
|
-
const brace = braces[braces.length - 1]
|
|
2310
|
-
prev.type = 'dots'
|
|
2311
|
-
prev.output += value
|
|
2312
|
-
prev.value += value
|
|
2313
|
-
brace.dots = true
|
|
2314
|
-
continue
|
|
2315
|
-
}
|
|
2316
|
-
if (
|
|
2317
|
-
state.braces + state.parens === 0 &&
|
|
2318
|
-
prev.type !== 'bos' &&
|
|
2319
|
-
prev.type !== 'slash'
|
|
2320
|
-
) {
|
|
2321
|
-
push({
|
|
2322
|
-
type: 'text',
|
|
2323
|
-
value,
|
|
2324
|
-
output: DOT_LITERAL
|
|
2325
|
-
})
|
|
2326
|
-
continue
|
|
2327
|
-
}
|
|
2328
|
-
push({
|
|
2329
|
-
type: 'dot',
|
|
2330
|
-
value,
|
|
2331
|
-
output: DOT_LITERAL
|
|
2332
|
-
})
|
|
2333
|
-
continue
|
|
2334
|
-
}
|
|
2335
|
-
|
|
2336
|
-
/**
|
|
2337
|
-
* Question marks
|
|
2338
|
-
*/
|
|
2339
|
-
|
|
2340
|
-
if (value === '?') {
|
|
2341
|
-
const isGroup = prev && prev.value === '('
|
|
2342
|
-
if (
|
|
2343
|
-
!isGroup &&
|
|
2344
|
-
opts.noextglob !== true &&
|
|
2345
|
-
peek() === '(' &&
|
|
2346
|
-
peek(2) !== '?'
|
|
2347
|
-
) {
|
|
2348
|
-
extglobOpen('qmark', value)
|
|
2349
|
-
continue
|
|
2350
|
-
}
|
|
2351
|
-
if (prev && prev.type === 'paren') {
|
|
2352
|
-
const next = peek()
|
|
2353
|
-
let output = value
|
|
2354
|
-
if (
|
|
2355
|
-
(prev.value === '(' && !/[!=<:]/.test(next)) ||
|
|
2356
|
-
(next === '<' && !/<([!=]|\w+>)/.test(remaining()))
|
|
2357
|
-
) {
|
|
2358
|
-
output = `\\${value}`
|
|
2359
|
-
}
|
|
2360
|
-
push({
|
|
2361
|
-
type: 'text',
|
|
2362
|
-
value,
|
|
2363
|
-
output
|
|
2364
|
-
})
|
|
2365
|
-
continue
|
|
2366
|
-
}
|
|
2367
|
-
if (
|
|
2368
|
-
opts.dot !== true &&
|
|
2369
|
-
(prev.type === 'slash' || prev.type === 'bos')
|
|
2370
|
-
) {
|
|
2371
|
-
push({
|
|
2372
|
-
type: 'qmark',
|
|
2373
|
-
value,
|
|
2374
|
-
output: QMARK_NO_DOT
|
|
2375
|
-
})
|
|
2376
|
-
continue
|
|
2377
|
-
}
|
|
2378
|
-
push({
|
|
2379
|
-
type: 'qmark',
|
|
2380
|
-
value,
|
|
2381
|
-
output: QMARK
|
|
2382
|
-
})
|
|
2383
|
-
continue
|
|
2384
|
-
}
|
|
2385
|
-
|
|
2386
|
-
/**
|
|
2387
|
-
* Exclamation
|
|
2388
|
-
*/
|
|
2389
|
-
|
|
2390
|
-
if (value === '!') {
|
|
2391
|
-
if (opts.noextglob !== true && peek() === '(') {
|
|
2392
|
-
if (peek(2) !== '?' || !/[!=<:]/.test(peek(3))) {
|
|
2393
|
-
extglobOpen('negate', value)
|
|
2394
|
-
continue
|
|
2395
|
-
}
|
|
2396
|
-
}
|
|
2397
|
-
if (opts.nonegate !== true && state.index === 0) {
|
|
2398
|
-
negate()
|
|
2399
|
-
continue
|
|
2400
|
-
}
|
|
2401
|
-
}
|
|
2402
|
-
|
|
2403
|
-
/**
|
|
2404
|
-
* Plus
|
|
2405
|
-
*/
|
|
2406
|
-
|
|
2407
|
-
if (value === '+') {
|
|
2408
|
-
if (opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
|
|
2409
|
-
extglobOpen('plus', value)
|
|
2410
|
-
continue
|
|
2411
|
-
}
|
|
2412
|
-
if ((prev && prev.value === '(') || opts.regex === false) {
|
|
2413
|
-
push({
|
|
2414
|
-
type: 'plus',
|
|
2415
|
-
value,
|
|
2416
|
-
output: PLUS_LITERAL
|
|
2417
|
-
})
|
|
2418
|
-
continue
|
|
2419
|
-
}
|
|
2420
|
-
if (
|
|
2421
|
-
(prev &&
|
|
2422
|
-
(prev.type === 'bracket' ||
|
|
2423
|
-
prev.type === 'paren' ||
|
|
2424
|
-
prev.type === 'brace')) ||
|
|
2425
|
-
state.parens > 0
|
|
2426
|
-
) {
|
|
2427
|
-
push({
|
|
2428
|
-
type: 'plus',
|
|
2429
|
-
value
|
|
2430
|
-
})
|
|
2431
|
-
continue
|
|
2432
|
-
}
|
|
2433
|
-
push({
|
|
2434
|
-
type: 'plus',
|
|
2435
|
-
value: PLUS_LITERAL
|
|
2436
|
-
})
|
|
2437
|
-
continue
|
|
2438
|
-
}
|
|
2439
|
-
|
|
2440
|
-
/**
|
|
2441
|
-
* Plain text
|
|
2442
|
-
*/
|
|
2443
|
-
|
|
2444
|
-
if (value === '@') {
|
|
2445
|
-
if (opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
|
|
2446
|
-
push({
|
|
2447
|
-
type: 'at',
|
|
2448
|
-
extglob: true,
|
|
2449
|
-
value,
|
|
2450
|
-
output: ''
|
|
2451
|
-
})
|
|
2452
|
-
continue
|
|
2453
|
-
}
|
|
2454
|
-
push({
|
|
2455
|
-
type: 'text',
|
|
2456
|
-
value
|
|
2457
|
-
})
|
|
2458
|
-
continue
|
|
2459
|
-
}
|
|
2460
|
-
|
|
2461
|
-
/**
|
|
2462
|
-
* Plain text
|
|
2463
|
-
*/
|
|
2464
|
-
|
|
2465
|
-
if (value !== '*') {
|
|
2466
|
-
if (value === '$' || value === '^') {
|
|
2467
|
-
value = `\\${value}`
|
|
2468
|
-
}
|
|
2469
|
-
const match = REGEX_NON_SPECIAL_CHARS.exec(remaining())
|
|
2470
|
-
if (match) {
|
|
2471
|
-
value += match[0]
|
|
2472
|
-
state.index += match[0].length
|
|
2473
|
-
}
|
|
2474
|
-
push({
|
|
2475
|
-
type: 'text',
|
|
2476
|
-
value
|
|
2477
|
-
})
|
|
2478
|
-
continue
|
|
2479
|
-
}
|
|
2480
|
-
|
|
2481
|
-
/**
|
|
2482
|
-
* Stars
|
|
2483
|
-
*/
|
|
2484
|
-
|
|
2485
|
-
if (prev && (prev.type === 'globstar' || prev.star === true)) {
|
|
2486
|
-
prev.type = 'star'
|
|
2487
|
-
prev.star = true
|
|
2488
|
-
prev.value += value
|
|
2489
|
-
prev.output = star
|
|
2490
|
-
state.backtrack = true
|
|
2491
|
-
state.globstar = true
|
|
2492
|
-
consume(value)
|
|
2493
|
-
continue
|
|
2494
|
-
}
|
|
2495
|
-
let rest = remaining()
|
|
2496
|
-
if (opts.noextglob !== true && /^\([^?]/.test(rest)) {
|
|
2497
|
-
extglobOpen('star', value)
|
|
2498
|
-
continue
|
|
2499
|
-
}
|
|
2500
|
-
if (prev.type === 'star') {
|
|
2501
|
-
if (opts.noglobstar === true) {
|
|
2502
|
-
consume(value)
|
|
2503
|
-
continue
|
|
2504
|
-
}
|
|
2505
|
-
const prior = prev.prev
|
|
2506
|
-
const before = prior.prev
|
|
2507
|
-
const isStart = prior.type === 'slash' || prior.type === 'bos'
|
|
2508
|
-
const afterStar =
|
|
2509
|
-
before && (before.type === 'star' || before.type === 'globstar')
|
|
2510
|
-
if (opts.bash === true && (!isStart || (rest[0] && rest[0] !== '/'))) {
|
|
2511
|
-
push({
|
|
2512
|
-
type: 'star',
|
|
2513
|
-
value,
|
|
2514
|
-
output: ''
|
|
2515
|
-
})
|
|
2516
|
-
continue
|
|
2517
|
-
}
|
|
2518
|
-
const isBrace =
|
|
2519
|
-
state.braces > 0 && (prior.type === 'comma' || prior.type === 'brace')
|
|
2520
|
-
const isExtglob =
|
|
2521
|
-
extglobs.length && (prior.type === 'pipe' || prior.type === 'paren')
|
|
2522
|
-
if (!isStart && prior.type !== 'paren' && !isBrace && !isExtglob) {
|
|
2523
|
-
push({
|
|
2524
|
-
type: 'star',
|
|
2525
|
-
value,
|
|
2526
|
-
output: ''
|
|
2527
|
-
})
|
|
2528
|
-
continue
|
|
2529
|
-
}
|
|
2530
|
-
|
|
2531
|
-
// strip consecutive `/**/`
|
|
2532
|
-
while (rest.slice(0, 3) === '/**') {
|
|
2533
|
-
const after = input[state.index + 4]
|
|
2534
|
-
if (after && after !== '/') {
|
|
2535
|
-
break
|
|
2536
|
-
}
|
|
2537
|
-
rest = rest.slice(3)
|
|
2538
|
-
consume('/**', 3)
|
|
2539
|
-
}
|
|
2540
|
-
if (prior.type === 'bos' && eos()) {
|
|
2541
|
-
prev.type = 'globstar'
|
|
2542
|
-
prev.value += value
|
|
2543
|
-
prev.output = globstar(opts)
|
|
2544
|
-
state.output = prev.output
|
|
2545
|
-
state.globstar = true
|
|
2546
|
-
consume(value)
|
|
2547
|
-
continue
|
|
2548
|
-
}
|
|
2549
|
-
if (
|
|
2550
|
-
prior.type === 'slash' &&
|
|
2551
|
-
prior.prev.type !== 'bos' &&
|
|
2552
|
-
!afterStar &&
|
|
2553
|
-
eos()
|
|
2554
|
-
) {
|
|
2555
|
-
state.output = state.output.slice(
|
|
2556
|
-
0,
|
|
2557
|
-
-(prior.output + prev.output).length
|
|
2558
|
-
)
|
|
2559
|
-
prior.output = `(?:${prior.output}`
|
|
2560
|
-
prev.type = 'globstar'
|
|
2561
|
-
prev.output = globstar(opts) + (opts.strictSlashes ? ')' : '|$)')
|
|
2562
|
-
prev.value += value
|
|
2563
|
-
state.globstar = true
|
|
2564
|
-
state.output += prior.output + prev.output
|
|
2565
|
-
consume(value)
|
|
2566
|
-
continue
|
|
2567
|
-
}
|
|
2568
|
-
if (
|
|
2569
|
-
prior.type === 'slash' &&
|
|
2570
|
-
prior.prev.type !== 'bos' &&
|
|
2571
|
-
rest[0] === '/'
|
|
2572
|
-
) {
|
|
2573
|
-
const end = rest[1] !== void 0 ? '|$' : ''
|
|
2574
|
-
state.output = state.output.slice(
|
|
2575
|
-
0,
|
|
2576
|
-
-(prior.output + prev.output).length
|
|
2577
|
-
)
|
|
2578
|
-
prior.output = `(?:${prior.output}`
|
|
2579
|
-
prev.type = 'globstar'
|
|
2580
|
-
prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`
|
|
2581
|
-
prev.value += value
|
|
2582
|
-
state.output += prior.output + prev.output
|
|
2583
|
-
state.globstar = true
|
|
2584
|
-
consume(value + advance())
|
|
2585
|
-
push({
|
|
2586
|
-
type: 'slash',
|
|
2587
|
-
value: '/',
|
|
2588
|
-
output: ''
|
|
2589
|
-
})
|
|
2590
|
-
continue
|
|
2591
|
-
}
|
|
2592
|
-
if (prior.type === 'bos' && rest[0] === '/') {
|
|
2593
|
-
prev.type = 'globstar'
|
|
2594
|
-
prev.value += value
|
|
2595
|
-
prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`
|
|
2596
|
-
state.output = prev.output
|
|
2597
|
-
state.globstar = true
|
|
2598
|
-
consume(value + advance())
|
|
2599
|
-
push({
|
|
2600
|
-
type: 'slash',
|
|
2601
|
-
value: '/',
|
|
2602
|
-
output: ''
|
|
2603
|
-
})
|
|
2604
|
-
continue
|
|
2605
|
-
}
|
|
2606
|
-
|
|
2607
|
-
// remove single star from output
|
|
2608
|
-
state.output = state.output.slice(0, -prev.output.length)
|
|
2609
|
-
|
|
2610
|
-
// reset previous token to globstar
|
|
2611
|
-
prev.type = 'globstar'
|
|
2612
|
-
prev.output = globstar(opts)
|
|
2613
|
-
prev.value += value
|
|
2614
|
-
|
|
2615
|
-
// reset output with globstar
|
|
2616
|
-
state.output += prev.output
|
|
2617
|
-
state.globstar = true
|
|
2618
|
-
consume(value)
|
|
2619
|
-
continue
|
|
2620
|
-
}
|
|
2621
|
-
const token = {
|
|
2622
|
-
type: 'star',
|
|
2623
|
-
value,
|
|
2624
|
-
output: star
|
|
2625
|
-
}
|
|
2626
|
-
if (opts.bash === true) {
|
|
2627
|
-
token.output = '.*?'
|
|
2628
|
-
if (prev.type === 'bos' || prev.type === 'slash') {
|
|
2629
|
-
token.output = nodot + token.output
|
|
2630
|
-
}
|
|
2631
|
-
push(token)
|
|
2632
|
-
continue
|
|
2633
|
-
}
|
|
2634
|
-
if (
|
|
2635
|
-
prev &&
|
|
2636
|
-
(prev.type === 'bracket' || prev.type === 'paren') &&
|
|
2637
|
-
opts.regex === true
|
|
2638
|
-
) {
|
|
2639
|
-
token.output = value
|
|
2640
|
-
push(token)
|
|
2641
|
-
continue
|
|
2642
|
-
}
|
|
2643
|
-
if (
|
|
2644
|
-
state.index === state.start ||
|
|
2645
|
-
prev.type === 'slash' ||
|
|
2646
|
-
prev.type === 'dot'
|
|
2647
|
-
) {
|
|
2648
|
-
if (prev.type === 'dot') {
|
|
2649
|
-
state.output += NO_DOT_SLASH
|
|
2650
|
-
prev.output += NO_DOT_SLASH
|
|
2651
|
-
} else if (opts.dot === true) {
|
|
2652
|
-
state.output += NO_DOTS_SLASH
|
|
2653
|
-
prev.output += NO_DOTS_SLASH
|
|
2654
|
-
} else {
|
|
2655
|
-
state.output += nodot
|
|
2656
|
-
prev.output += nodot
|
|
2657
|
-
}
|
|
2658
|
-
if (peek() !== '*') {
|
|
2659
|
-
state.output += ONE_CHAR
|
|
2660
|
-
prev.output += ONE_CHAR
|
|
2661
|
-
}
|
|
2662
|
-
}
|
|
2663
|
-
push(token)
|
|
2664
|
-
}
|
|
2665
|
-
while (state.brackets > 0) {
|
|
2666
|
-
if (opts.strictBrackets === true) {
|
|
2667
|
-
throw new SyntaxError(syntaxError('closing', ']'))
|
|
2668
|
-
}
|
|
2669
|
-
state.output = utils.escapeLast(state.output, '[')
|
|
2670
|
-
decrement('brackets')
|
|
2671
|
-
}
|
|
2672
|
-
while (state.parens > 0) {
|
|
2673
|
-
if (opts.strictBrackets === true) {
|
|
2674
|
-
throw new SyntaxError(syntaxError('closing', ')'))
|
|
2675
|
-
}
|
|
2676
|
-
state.output = utils.escapeLast(state.output, '(')
|
|
2677
|
-
decrement('parens')
|
|
2678
|
-
}
|
|
2679
|
-
while (state.braces > 0) {
|
|
2680
|
-
if (opts.strictBrackets === true) {
|
|
2681
|
-
throw new SyntaxError(syntaxError('closing', '}'))
|
|
2682
|
-
}
|
|
2683
|
-
state.output = utils.escapeLast(state.output, '{')
|
|
2684
|
-
decrement('braces')
|
|
2685
|
-
}
|
|
2686
|
-
if (
|
|
2687
|
-
opts.strictSlashes !== true &&
|
|
2688
|
-
(prev.type === 'star' || prev.type === 'bracket')
|
|
2689
|
-
) {
|
|
2690
|
-
push({
|
|
2691
|
-
type: 'maybe_slash',
|
|
2692
|
-
value: '',
|
|
2693
|
-
output: `${SLASH_LITERAL}?`
|
|
2694
|
-
})
|
|
2695
|
-
}
|
|
2696
|
-
|
|
2697
|
-
// rebuild the output if we had to backtrack at any point
|
|
2698
|
-
if (state.backtrack === true) {
|
|
2699
|
-
state.output = ''
|
|
2700
|
-
for (const token of state.tokens) {
|
|
2701
|
-
state.output += token.output != null ? token.output : token.value
|
|
2702
|
-
if (token.suffix) {
|
|
2703
|
-
state.output += token.suffix
|
|
2704
|
-
}
|
|
2705
|
-
}
|
|
2706
|
-
}
|
|
2707
|
-
return state
|
|
2708
|
-
}
|
|
2709
|
-
|
|
2710
|
-
/**
|
|
2711
|
-
* Fast paths for creating regular expressions for common glob patterns.
|
|
2712
|
-
* This can significantly speed up processing and has very little downside
|
|
2713
|
-
* impact when none of the fast paths match.
|
|
2714
|
-
*/
|
|
2715
|
-
|
|
2716
|
-
parse.fastpaths = (input, options) => {
|
|
2717
|
-
const opts = {
|
|
2718
|
-
...options
|
|
2719
|
-
}
|
|
2720
|
-
const max =
|
|
2721
|
-
typeof opts.maxLength === 'number'
|
|
2722
|
-
? Math.min(MAX_LENGTH, opts.maxLength)
|
|
2723
|
-
: MAX_LENGTH
|
|
2724
|
-
const len = input.length
|
|
2725
|
-
if (len > max) {
|
|
2726
|
-
throw new SyntaxError(
|
|
2727
|
-
`Input length: ${len}, exceeds maximum allowed length: ${max}`
|
|
2728
|
-
)
|
|
2729
|
-
}
|
|
2730
|
-
input = REPLACEMENTS[input] || input
|
|
2731
|
-
|
|
2732
|
-
// create constants based on platform, for windows or posix
|
|
2733
|
-
const {
|
|
2734
|
-
DOT_LITERAL,
|
|
2735
|
-
SLASH_LITERAL,
|
|
2736
|
-
ONE_CHAR,
|
|
2737
|
-
DOTS_SLASH,
|
|
2738
|
-
NO_DOT,
|
|
2739
|
-
NO_DOTS,
|
|
2740
|
-
NO_DOTS_SLASH,
|
|
2741
|
-
STAR,
|
|
2742
|
-
START_ANCHOR
|
|
2743
|
-
} = constants.globChars(opts.windows)
|
|
2744
|
-
const nodot = opts.dot ? NO_DOTS : NO_DOT
|
|
2745
|
-
const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT
|
|
2746
|
-
const capture = opts.capture ? '' : '?:'
|
|
2747
|
-
const state = {
|
|
2748
|
-
negated: false,
|
|
2749
|
-
prefix: ''
|
|
2750
|
-
}
|
|
2751
|
-
let star = opts.bash === true ? '.*?' : STAR
|
|
2752
|
-
if (opts.capture) {
|
|
2753
|
-
star = `(${star})`
|
|
2754
|
-
}
|
|
2755
|
-
const globstar = opts => {
|
|
2756
|
-
if (opts.noglobstar === true) {
|
|
2757
|
-
return star
|
|
2758
|
-
}
|
|
2759
|
-
return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`
|
|
2760
|
-
}
|
|
2761
|
-
const create = str => {
|
|
2762
|
-
switch (str) {
|
|
2763
|
-
case '*':
|
|
2764
|
-
return `${nodot}${ONE_CHAR}${star}`
|
|
2765
|
-
case '.*':
|
|
2766
|
-
return `${DOT_LITERAL}${ONE_CHAR}${star}`
|
|
2767
|
-
case '*.*':
|
|
2768
|
-
return `${nodot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`
|
|
2769
|
-
case '*/*':
|
|
2770
|
-
return `${nodot}${star}${SLASH_LITERAL}${ONE_CHAR}${slashDot}${star}`
|
|
2771
|
-
case '**':
|
|
2772
|
-
return nodot + globstar(opts)
|
|
2773
|
-
case '**/*':
|
|
2774
|
-
return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${ONE_CHAR}${star}`
|
|
2775
|
-
case '**/*.*':
|
|
2776
|
-
return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`
|
|
2777
|
-
case '**/.*':
|
|
2778
|
-
return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`
|
|
2779
|
-
default: {
|
|
2780
|
-
const match = /^(.*?)\.(\w+)$/.exec(str)
|
|
2781
|
-
if (!match) {
|
|
2782
|
-
return
|
|
2783
|
-
}
|
|
2784
|
-
const source = create(match[1])
|
|
2785
|
-
if (!source) {
|
|
2786
|
-
return
|
|
2787
|
-
}
|
|
2788
|
-
return source + DOT_LITERAL + match[2]
|
|
2789
|
-
}
|
|
2790
|
-
}
|
|
2791
|
-
}
|
|
2792
|
-
const output = utils.removePrefix(input, state)
|
|
2793
|
-
let source = create(output)
|
|
2794
|
-
if (source && opts.strictSlashes !== true) {
|
|
2795
|
-
source += `${SLASH_LITERAL}?`
|
|
2796
|
-
}
|
|
2797
|
-
return source
|
|
2798
|
-
}
|
|
2799
|
-
parse_1 = parse
|
|
2800
|
-
return parse_1
|
|
2801
|
-
}
|
|
2802
|
-
|
|
2803
|
-
let picomatch_1$1
|
|
2804
|
-
let hasRequiredPicomatch$1
|
|
2805
|
-
function requirePicomatch$1() {
|
|
2806
|
-
if (hasRequiredPicomatch$1) {
|
|
2807
|
-
return picomatch_1$1
|
|
2808
|
-
}
|
|
2809
|
-
hasRequiredPicomatch$1 = 1
|
|
2810
|
-
const scan = /*@__PURE__*/ requireScan()
|
|
2811
|
-
const parse = /*@__PURE__*/ requireParse()
|
|
2812
|
-
const utils = /*@__PURE__*/ requireUtils()
|
|
2813
|
-
const constants = /*@__PURE__*/ requireConstants()
|
|
2814
|
-
const isObject = val => val && typeof val === 'object' && !Array.isArray(val)
|
|
2815
|
-
|
|
2816
|
-
/**
|
|
2817
|
-
* Creates a matcher function from one or more glob patterns. The
|
|
2818
|
-
* returned function takes a string to match as its first argument,
|
|
2819
|
-
* and returns true if the string is a match. The returned matcher
|
|
2820
|
-
* function also takes a boolean as the second argument that, when true,
|
|
2821
|
-
* returns an object with additional information.
|
|
2822
|
-
*
|
|
2823
|
-
* ```js
|
|
2824
|
-
* const picomatch = require('picomatch');
|
|
2825
|
-
* // picomatch(glob[, options]);
|
|
2826
|
-
*
|
|
2827
|
-
* const isMatch = picomatch('*.!(*a)');
|
|
2828
|
-
* console.log(isMatch('a.a')); //=> false
|
|
2829
|
-
* console.log(isMatch('a.b')); //=> true
|
|
2830
|
-
* ```
|
|
2831
|
-
* @name picomatch
|
|
2832
|
-
* @param {String|Array} `globs` One or more glob patterns.
|
|
2833
|
-
* @param {Object=} `options`
|
|
2834
|
-
* @return {Function=} Returns a matcher function.
|
|
2835
|
-
* @api public
|
|
2836
|
-
*/
|
|
2837
|
-
|
|
2838
|
-
const picomatch = (glob, options, returnState = false) => {
|
|
2839
|
-
if (Array.isArray(glob)) {
|
|
2840
|
-
const fns = glob.map(input => picomatch(input, options, returnState))
|
|
2841
|
-
const arrayMatcher = str => {
|
|
2842
|
-
for (const isMatch of fns) {
|
|
2843
|
-
const state = isMatch(str)
|
|
2844
|
-
if (state) {
|
|
2845
|
-
return state
|
|
2846
|
-
}
|
|
2847
|
-
}
|
|
2848
|
-
return false
|
|
2849
|
-
}
|
|
2850
|
-
return arrayMatcher
|
|
2851
|
-
}
|
|
2852
|
-
const isState = isObject(glob) && glob.tokens && glob.input
|
|
2853
|
-
if (glob === '' || (typeof glob !== 'string' && !isState)) {
|
|
2854
|
-
throw new TypeError('Expected pattern to be a non-empty string')
|
|
2855
|
-
}
|
|
2856
|
-
const opts = options || {}
|
|
2857
|
-
const posix = opts.windows
|
|
2858
|
-
const regex = isState
|
|
2859
|
-
? picomatch.compileRe(glob, options)
|
|
2860
|
-
: picomatch.makeRe(glob, options, false, true)
|
|
2861
|
-
const state = regex.state
|
|
2862
|
-
delete regex.state
|
|
2863
|
-
let isIgnored = () => false
|
|
2864
|
-
if (opts.ignore) {
|
|
2865
|
-
const ignoreOpts = {
|
|
2866
|
-
...options,
|
|
2867
|
-
ignore: null,
|
|
2868
|
-
onMatch: null,
|
|
2869
|
-
onResult: null
|
|
2870
|
-
}
|
|
2871
|
-
isIgnored = picomatch(opts.ignore, ignoreOpts, returnState)
|
|
2872
|
-
}
|
|
2873
|
-
const matcher = (input, returnObject = false) => {
|
|
2874
|
-
const { isMatch, match, output } = picomatch.test(input, regex, options, {
|
|
2875
|
-
glob,
|
|
2876
|
-
posix
|
|
2877
|
-
})
|
|
2878
|
-
const result = {
|
|
2879
|
-
glob,
|
|
2880
|
-
state,
|
|
2881
|
-
regex,
|
|
2882
|
-
posix,
|
|
2883
|
-
input,
|
|
2884
|
-
output,
|
|
2885
|
-
match,
|
|
2886
|
-
isMatch
|
|
2887
|
-
}
|
|
2888
|
-
if (typeof opts.onResult === 'function') {
|
|
2889
|
-
opts.onResult(result)
|
|
2890
|
-
}
|
|
2891
|
-
if (isMatch === false) {
|
|
2892
|
-
result.isMatch = false
|
|
2893
|
-
return returnObject ? result : false
|
|
2894
|
-
}
|
|
2895
|
-
if (isIgnored(input)) {
|
|
2896
|
-
if (typeof opts.onIgnore === 'function') {
|
|
2897
|
-
opts.onIgnore(result)
|
|
2898
|
-
}
|
|
2899
|
-
result.isMatch = false
|
|
2900
|
-
return returnObject ? result : false
|
|
2901
|
-
}
|
|
2902
|
-
if (typeof opts.onMatch === 'function') {
|
|
2903
|
-
opts.onMatch(result)
|
|
2904
|
-
}
|
|
2905
|
-
return returnObject ? result : true
|
|
2906
|
-
}
|
|
2907
|
-
if (returnState) {
|
|
2908
|
-
matcher.state = state
|
|
2909
|
-
}
|
|
2910
|
-
return matcher
|
|
2911
|
-
}
|
|
2912
|
-
|
|
2913
|
-
/**
|
|
2914
|
-
* Test `input` with the given `regex`. This is used by the main
|
|
2915
|
-
* `picomatch()` function to test the input string.
|
|
2916
|
-
*
|
|
2917
|
-
* ```js
|
|
2918
|
-
* const picomatch = require('picomatch');
|
|
2919
|
-
* // picomatch.test(input, regex[, options]);
|
|
2920
|
-
*
|
|
2921
|
-
* console.log(picomatch.test('foo/bar', /^(?:([^/]*?)\/([^/]*?))$/));
|
|
2922
|
-
* // { isMatch: true, match: [ 'foo/', 'foo', 'bar' ], output: 'foo/bar' }
|
|
2923
|
-
* ```
|
|
2924
|
-
* @param {String} `input` String to test.
|
|
2925
|
-
* @param {RegExp} `regex`
|
|
2926
|
-
* @return {Object} Returns an object with matching info.
|
|
2927
|
-
* @api public
|
|
2928
|
-
*/
|
|
2929
|
-
|
|
2930
|
-
picomatch.test = (input, regex, options, { glob, posix } = {}) => {
|
|
2931
|
-
if (typeof input !== 'string') {
|
|
2932
|
-
throw new TypeError('Expected input to be a string')
|
|
2933
|
-
}
|
|
2934
|
-
if (input === '') {
|
|
2935
|
-
return {
|
|
2936
|
-
isMatch: false,
|
|
2937
|
-
output: ''
|
|
2938
|
-
}
|
|
2939
|
-
}
|
|
2940
|
-
const opts = options || {}
|
|
2941
|
-
const format = opts.format || (posix ? utils.toPosixSlashes : null)
|
|
2942
|
-
let match = input === glob
|
|
2943
|
-
let output = match && format ? format(input) : input
|
|
2944
|
-
if (match === false) {
|
|
2945
|
-
output = format ? format(input) : input
|
|
2946
|
-
match = output === glob
|
|
2947
|
-
}
|
|
2948
|
-
if (match === false || opts.capture === true) {
|
|
2949
|
-
if (opts.matchBase === true || opts.basename === true) {
|
|
2950
|
-
match = picomatch.matchBase(input, regex, options, posix)
|
|
2951
|
-
} else {
|
|
2952
|
-
match = regex.exec(output)
|
|
2953
|
-
}
|
|
2954
|
-
}
|
|
2955
|
-
return {
|
|
2956
|
-
isMatch: Boolean(match),
|
|
2957
|
-
match,
|
|
2958
|
-
output
|
|
2959
|
-
}
|
|
2960
|
-
}
|
|
2961
|
-
|
|
2962
|
-
/**
|
|
2963
|
-
* Match the basename of a filepath.
|
|
2964
|
-
*
|
|
2965
|
-
* ```js
|
|
2966
|
-
* const picomatch = require('picomatch');
|
|
2967
|
-
* // picomatch.matchBase(input, glob[, options]);
|
|
2968
|
-
* console.log(picomatch.matchBase('foo/bar.js', '*.js'); // true
|
|
2969
|
-
* ```
|
|
2970
|
-
* @param {String} `input` String to test.
|
|
2971
|
-
* @param {RegExp|String} `glob` Glob pattern or regex created by [.makeRe](#makeRe).
|
|
2972
|
-
* @return {Boolean}
|
|
2973
|
-
* @api public
|
|
2974
|
-
*/
|
|
2975
|
-
|
|
2976
|
-
picomatch.matchBase = (input, glob, options) => {
|
|
2977
|
-
const regex =
|
|
2978
|
-
glob instanceof RegExp ? glob : picomatch.makeRe(glob, options)
|
|
2979
|
-
return regex.test(utils.basename(input))
|
|
2980
|
-
}
|
|
2981
|
-
|
|
2982
|
-
/**
|
|
2983
|
-
* Returns true if **any** of the given glob `patterns` match the specified `string`.
|
|
2984
|
-
*
|
|
2985
|
-
* ```js
|
|
2986
|
-
* const picomatch = require('picomatch');
|
|
2987
|
-
* // picomatch.isMatch(string, patterns[, options]);
|
|
2988
|
-
*
|
|
2989
|
-
* console.log(picomatch.isMatch('a.a', ['b.*', '*.a'])); //=> true
|
|
2990
|
-
* console.log(picomatch.isMatch('a.a', 'b.*')); //=> false
|
|
2991
|
-
* ```
|
|
2992
|
-
* @param {String|Array} str The string to test.
|
|
2993
|
-
* @param {String|Array} patterns One or more glob patterns to use for matching.
|
|
2994
|
-
* @param {Object} [options] See available [options](#options).
|
|
2995
|
-
* @return {Boolean} Returns true if any patterns match `str`
|
|
2996
|
-
* @api public
|
|
2997
|
-
*/
|
|
2998
|
-
|
|
2999
|
-
picomatch.isMatch = (str, patterns, options) =>
|
|
3000
|
-
picomatch(patterns, options)(str)
|
|
3001
|
-
|
|
3002
|
-
/**
|
|
3003
|
-
* Parse a glob pattern to create the source string for a regular
|
|
3004
|
-
* expression.
|
|
3005
|
-
*
|
|
3006
|
-
* ```js
|
|
3007
|
-
* const picomatch = require('picomatch');
|
|
3008
|
-
* const result = picomatch.parse(pattern[, options]);
|
|
3009
|
-
* ```
|
|
3010
|
-
* @param {String} `pattern`
|
|
3011
|
-
* @param {Object} `options`
|
|
3012
|
-
* @return {Object} Returns an object with useful properties and output to be used as a regex source string.
|
|
3013
|
-
* @api public
|
|
3014
|
-
*/
|
|
3015
|
-
|
|
3016
|
-
picomatch.parse = (pattern, options) => {
|
|
3017
|
-
if (Array.isArray(pattern)) {
|
|
3018
|
-
return pattern.map(p => picomatch.parse(p, options))
|
|
3019
|
-
}
|
|
3020
|
-
return parse(pattern, {
|
|
3021
|
-
...options,
|
|
3022
|
-
fastpaths: false
|
|
3023
|
-
})
|
|
3024
|
-
}
|
|
3025
|
-
|
|
3026
|
-
/**
|
|
3027
|
-
* Scan a glob pattern to separate the pattern into segments.
|
|
3028
|
-
*
|
|
3029
|
-
* ```js
|
|
3030
|
-
* const picomatch = require('picomatch');
|
|
3031
|
-
* // picomatch.scan(input[, options]);
|
|
3032
|
-
*
|
|
3033
|
-
* const result = picomatch.scan('!./foo/*.js');
|
|
3034
|
-
* console.log(result);
|
|
3035
|
-
* { prefix: '!./',
|
|
3036
|
-
* input: '!./foo/*.js',
|
|
3037
|
-
* start: 3,
|
|
3038
|
-
* base: 'foo',
|
|
3039
|
-
* glob: '*.js',
|
|
3040
|
-
* isBrace: false,
|
|
3041
|
-
* isBracket: false,
|
|
3042
|
-
* isGlob: true,
|
|
3043
|
-
* isExtglob: false,
|
|
3044
|
-
* isGlobstar: false,
|
|
3045
|
-
* negated: true }
|
|
3046
|
-
* ```
|
|
3047
|
-
* @param {String} `input` Glob pattern to scan.
|
|
3048
|
-
* @param {Object} `options`
|
|
3049
|
-
* @return {Object} Returns an object with
|
|
3050
|
-
* @api public
|
|
3051
|
-
*/
|
|
3052
|
-
|
|
3053
|
-
picomatch.scan = (input, options) => scan(input, options)
|
|
3054
|
-
|
|
3055
|
-
/**
|
|
3056
|
-
* Compile a regular expression from the `state` object returned by the
|
|
3057
|
-
* [parse()](#parse) method.
|
|
3058
|
-
*
|
|
3059
|
-
* @param {Object} `state`
|
|
3060
|
-
* @param {Object} `options`
|
|
3061
|
-
* @param {Boolean} `returnOutput` Intended for implementors, this argument allows you to return the raw output from the parser.
|
|
3062
|
-
* @param {Boolean} `returnState` Adds the state to a `state` property on the returned regex. Useful for implementors and debugging.
|
|
3063
|
-
* @return {RegExp}
|
|
3064
|
-
* @api public
|
|
3065
|
-
*/
|
|
3066
|
-
|
|
3067
|
-
picomatch.compileRe = (
|
|
3068
|
-
state,
|
|
3069
|
-
options,
|
|
3070
|
-
returnOutput = false,
|
|
3071
|
-
returnState = false
|
|
3072
|
-
) => {
|
|
3073
|
-
if (returnOutput === true) {
|
|
3074
|
-
return state.output
|
|
3075
|
-
}
|
|
3076
|
-
const opts = options || {}
|
|
3077
|
-
const prepend = opts.contains ? '' : '^'
|
|
3078
|
-
const append = opts.contains ? '' : '$'
|
|
3079
|
-
let source = `${prepend}(?:${state.output})${append}`
|
|
3080
|
-
if (state && state.negated === true) {
|
|
3081
|
-
source = `^(?!${source}).*$`
|
|
3082
|
-
}
|
|
3083
|
-
const regex = picomatch.toRegex(source, options)
|
|
3084
|
-
if (returnState === true) {
|
|
3085
|
-
regex.state = state
|
|
3086
|
-
}
|
|
3087
|
-
return regex
|
|
3088
|
-
}
|
|
3089
|
-
|
|
3090
|
-
/**
|
|
3091
|
-
* Create a regular expression from a parsed glob pattern.
|
|
3092
|
-
*
|
|
3093
|
-
* ```js
|
|
3094
|
-
* const picomatch = require('picomatch');
|
|
3095
|
-
* const state = picomatch.parse('*.js');
|
|
3096
|
-
* // picomatch.compileRe(state[, options]);
|
|
3097
|
-
*
|
|
3098
|
-
* console.log(picomatch.compileRe(state));
|
|
3099
|
-
* //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
|
|
3100
|
-
* ```
|
|
3101
|
-
* @param {String} `state` The object returned from the `.parse` method.
|
|
3102
|
-
* @param {Object} `options`
|
|
3103
|
-
* @param {Boolean} `returnOutput` Implementors may use this argument to return the compiled output, instead of a regular expression. This is not exposed on the options to prevent end-users from mutating the result.
|
|
3104
|
-
* @param {Boolean} `returnState` Implementors may use this argument to return the state from the parsed glob with the returned regular expression.
|
|
3105
|
-
* @return {RegExp} Returns a regex created from the given pattern.
|
|
3106
|
-
* @api public
|
|
3107
|
-
*/
|
|
3108
|
-
|
|
3109
|
-
picomatch.makeRe = (
|
|
3110
|
-
input,
|
|
3111
|
-
options = {},
|
|
3112
|
-
returnOutput = false,
|
|
3113
|
-
returnState = false
|
|
3114
|
-
) => {
|
|
3115
|
-
if (!input || typeof input !== 'string') {
|
|
3116
|
-
throw new TypeError('Expected a non-empty string')
|
|
3117
|
-
}
|
|
3118
|
-
let parsed = {
|
|
3119
|
-
negated: false,
|
|
3120
|
-
fastpaths: true
|
|
3121
|
-
}
|
|
3122
|
-
if (options.fastpaths !== false && (input[0] === '.' || input[0] === '*')) {
|
|
3123
|
-
parsed.output = parse.fastpaths(input, options)
|
|
3124
|
-
}
|
|
3125
|
-
if (!parsed.output) {
|
|
3126
|
-
parsed = parse(input, options)
|
|
3127
|
-
}
|
|
3128
|
-
return picomatch.compileRe(parsed, options, returnOutput, returnState)
|
|
3129
|
-
}
|
|
3130
|
-
|
|
3131
|
-
/**
|
|
3132
|
-
* Create a regular expression from the given regex source string.
|
|
3133
|
-
*
|
|
3134
|
-
* ```js
|
|
3135
|
-
* const picomatch = require('picomatch');
|
|
3136
|
-
* // picomatch.toRegex(source[, options]);
|
|
3137
|
-
*
|
|
3138
|
-
* const { output } = picomatch.parse('*.js');
|
|
3139
|
-
* console.log(picomatch.toRegex(output));
|
|
3140
|
-
* //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
|
|
3141
|
-
* ```
|
|
3142
|
-
* @param {String} `source` Regular expression source string.
|
|
3143
|
-
* @param {Object} `options`
|
|
3144
|
-
* @return {RegExp}
|
|
3145
|
-
* @api public
|
|
3146
|
-
*/
|
|
3147
|
-
|
|
3148
|
-
picomatch.toRegex = (source, options) => {
|
|
3149
|
-
try {
|
|
3150
|
-
const opts = options || {}
|
|
3151
|
-
return new RegExp(source, opts.flags || (opts.nocase ? 'i' : ''))
|
|
3152
|
-
} catch (err) {
|
|
3153
|
-
if (options && options.debug === true) {
|
|
3154
|
-
throw err
|
|
3155
|
-
}
|
|
3156
|
-
return /$^/
|
|
3157
|
-
}
|
|
3158
|
-
}
|
|
3159
|
-
|
|
3160
|
-
/**
|
|
3161
|
-
* Picomatch constants.
|
|
3162
|
-
* @return {Object}
|
|
3163
|
-
*/
|
|
3164
|
-
|
|
3165
|
-
picomatch.constants = constants
|
|
3166
|
-
|
|
3167
|
-
/**
|
|
3168
|
-
* Expose "picomatch"
|
|
3169
|
-
*/
|
|
3170
|
-
|
|
3171
|
-
picomatch_1$1 = picomatch
|
|
3172
|
-
return picomatch_1$1
|
|
3173
|
-
}
|
|
3174
|
-
|
|
3175
|
-
let picomatch_1
|
|
3176
|
-
let hasRequiredPicomatch
|
|
3177
|
-
function requirePicomatch() {
|
|
3178
|
-
if (hasRequiredPicomatch) {
|
|
3179
|
-
return picomatch_1
|
|
3180
|
-
}
|
|
3181
|
-
hasRequiredPicomatch = 1
|
|
3182
|
-
const pico = /*@__PURE__*/ requirePicomatch$1()
|
|
3183
|
-
const utils = /*@__PURE__*/ requireUtils()
|
|
3184
|
-
function picomatch(glob, options, returnState = false) {
|
|
3185
|
-
// default to os.platform()
|
|
3186
|
-
if (
|
|
3187
|
-
options &&
|
|
3188
|
-
(options.windows === null || options.windows === undefined)
|
|
3189
|
-
) {
|
|
3190
|
-
// don't mutate the original options object
|
|
3191
|
-
options = {
|
|
3192
|
-
...options,
|
|
3193
|
-
windows: utils.isWindows()
|
|
3194
|
-
}
|
|
3195
|
-
}
|
|
3196
|
-
return pico(glob, options, returnState)
|
|
3197
|
-
}
|
|
3198
|
-
Object.assign(picomatch, pico)
|
|
3199
|
-
picomatch_1 = picomatch
|
|
3200
|
-
return picomatch_1
|
|
3201
|
-
}
|
|
3202
|
-
|
|
3203
|
-
let hasRequiredBuilder
|
|
3204
|
-
function requireBuilder() {
|
|
3205
|
-
if (hasRequiredBuilder) {
|
|
3206
|
-
return builder
|
|
3207
|
-
}
|
|
3208
|
-
hasRequiredBuilder = 1
|
|
3209
|
-
Object.defineProperty(builder, '__esModule', {
|
|
3210
|
-
value: true
|
|
3211
|
-
})
|
|
3212
|
-
builder.Builder = void 0
|
|
3213
|
-
const path_1 = require$$0
|
|
3214
|
-
const api_builder_1 = requireApiBuilder()
|
|
3215
|
-
let pm = null
|
|
3216
|
-
/* c8 ignore next 6 */
|
|
3217
|
-
try {
|
|
3218
|
-
require.resolve('picomatch')
|
|
3219
|
-
pm = /*@__PURE__*/ requirePicomatch()
|
|
3220
|
-
} catch (_e) {
|
|
3221
|
-
// do nothing
|
|
3222
|
-
}
|
|
3223
|
-
class Builder {
|
|
3224
|
-
globCache = {}
|
|
3225
|
-
options = {
|
|
3226
|
-
maxDepth: Infinity,
|
|
3227
|
-
suppressErrors: true,
|
|
3228
|
-
pathSeparator: path_1.sep,
|
|
3229
|
-
filters: []
|
|
3230
|
-
}
|
|
3231
|
-
globFunction
|
|
3232
|
-
constructor(options) {
|
|
3233
|
-
this.options = {
|
|
3234
|
-
...this.options,
|
|
3235
|
-
...options
|
|
3236
|
-
}
|
|
3237
|
-
this.globFunction = this.options.globFunction
|
|
3238
|
-
}
|
|
3239
|
-
group() {
|
|
3240
|
-
this.options.group = true
|
|
3241
|
-
return this
|
|
3242
|
-
}
|
|
3243
|
-
withPathSeparator(separator) {
|
|
3244
|
-
this.options.pathSeparator = separator
|
|
3245
|
-
return this
|
|
3246
|
-
}
|
|
3247
|
-
withBasePath() {
|
|
3248
|
-
this.options.includeBasePath = true
|
|
3249
|
-
return this
|
|
3250
|
-
}
|
|
3251
|
-
withRelativePaths() {
|
|
3252
|
-
this.options.relativePaths = true
|
|
3253
|
-
return this
|
|
3254
|
-
}
|
|
3255
|
-
withDirs() {
|
|
3256
|
-
this.options.includeDirs = true
|
|
3257
|
-
return this
|
|
3258
|
-
}
|
|
3259
|
-
withMaxDepth(depth) {
|
|
3260
|
-
this.options.maxDepth = depth
|
|
3261
|
-
return this
|
|
3262
|
-
}
|
|
3263
|
-
withMaxFiles(limit) {
|
|
3264
|
-
this.options.maxFiles = limit
|
|
3265
|
-
return this
|
|
3266
|
-
}
|
|
3267
|
-
withFullPaths() {
|
|
3268
|
-
this.options.resolvePaths = true
|
|
3269
|
-
this.options.includeBasePath = true
|
|
3270
|
-
return this
|
|
3271
|
-
}
|
|
3272
|
-
withErrors() {
|
|
3273
|
-
this.options.suppressErrors = false
|
|
3274
|
-
return this
|
|
3275
|
-
}
|
|
3276
|
-
withSymlinks({ resolvePaths = true } = {}) {
|
|
3277
|
-
this.options.resolveSymlinks = true
|
|
3278
|
-
this.options.useRealPaths = resolvePaths
|
|
3279
|
-
return this.withFullPaths()
|
|
3280
|
-
}
|
|
3281
|
-
withAbortSignal(signal) {
|
|
3282
|
-
this.options.signal = signal
|
|
3283
|
-
return this
|
|
3284
|
-
}
|
|
3285
|
-
normalize() {
|
|
3286
|
-
this.options.normalizePath = true
|
|
3287
|
-
return this
|
|
3288
|
-
}
|
|
3289
|
-
filter(predicate) {
|
|
3290
|
-
this.options.filters.push(predicate)
|
|
3291
|
-
return this
|
|
3292
|
-
}
|
|
3293
|
-
onlyDirs() {
|
|
3294
|
-
this.options.excludeFiles = true
|
|
3295
|
-
this.options.includeDirs = true
|
|
3296
|
-
return this
|
|
3297
|
-
}
|
|
3298
|
-
exclude(predicate) {
|
|
3299
|
-
this.options.exclude = predicate
|
|
3300
|
-
return this
|
|
3301
|
-
}
|
|
3302
|
-
onlyCounts() {
|
|
3303
|
-
this.options.onlyCounts = true
|
|
3304
|
-
return this
|
|
3305
|
-
}
|
|
3306
|
-
crawl(root) {
|
|
3307
|
-
return new api_builder_1.APIBuilder(root || '.', this.options)
|
|
3308
|
-
}
|
|
3309
|
-
withGlobFunction(fn) {
|
|
3310
|
-
// cast this since we don't have the new type params yet
|
|
3311
|
-
this.globFunction = fn
|
|
3312
|
-
return this
|
|
3313
|
-
}
|
|
3314
|
-
/**
|
|
3315
|
-
* @deprecated Pass options using the constructor instead:
|
|
3316
|
-
* ```ts
|
|
3317
|
-
* new fdir(options).crawl("/path/to/root");
|
|
3318
|
-
* ```
|
|
3319
|
-
* This method will be removed in v7.0
|
|
3320
|
-
*/
|
|
3321
|
-
/* c8 ignore next 4 */
|
|
3322
|
-
crawlWithOptions(root, options) {
|
|
3323
|
-
this.options = {
|
|
3324
|
-
...this.options,
|
|
3325
|
-
...options
|
|
3326
|
-
}
|
|
3327
|
-
return new api_builder_1.APIBuilder(root || '.', this.options)
|
|
3328
|
-
}
|
|
3329
|
-
glob(...patterns) {
|
|
3330
|
-
if (this.globFunction) {
|
|
3331
|
-
return this.globWithOptions(patterns)
|
|
3332
|
-
}
|
|
3333
|
-
return this.globWithOptions(patterns, {
|
|
3334
|
-
dot: true
|
|
3335
|
-
})
|
|
3336
|
-
}
|
|
3337
|
-
globWithOptions(patterns, ...options) {
|
|
3338
|
-
const globFn = this.globFunction || pm
|
|
3339
|
-
/* c8 ignore next 5 */
|
|
3340
|
-
if (!globFn) {
|
|
3341
|
-
throw new Error('Please specify a glob function to use glob matching.')
|
|
3342
|
-
}
|
|
3343
|
-
let isMatch = this.globCache[patterns.join('\0')]
|
|
3344
|
-
if (!isMatch) {
|
|
3345
|
-
isMatch = globFn(patterns, ...options)
|
|
3346
|
-
this.globCache[patterns.join('\0')] = isMatch
|
|
3347
|
-
}
|
|
3348
|
-
this.options.filters.push(path => isMatch(path))
|
|
3349
|
-
return this
|
|
3350
|
-
}
|
|
3351
|
-
}
|
|
3352
|
-
builder.Builder = Builder
|
|
3353
|
-
return builder
|
|
3354
|
-
}
|
|
3355
|
-
|
|
3356
|
-
const types = {}
|
|
3357
|
-
|
|
3358
|
-
let hasRequiredTypes
|
|
3359
|
-
function requireTypes() {
|
|
3360
|
-
if (hasRequiredTypes) {
|
|
3361
|
-
return types
|
|
3362
|
-
}
|
|
3363
|
-
hasRequiredTypes = 1
|
|
3364
|
-
Object.defineProperty(types, '__esModule', {
|
|
3365
|
-
value: true
|
|
3366
|
-
})
|
|
3367
|
-
return types
|
|
3368
|
-
}
|
|
3369
|
-
|
|
3370
|
-
let hasRequiredDist$1
|
|
3371
|
-
function requireDist$1() {
|
|
3372
|
-
if (hasRequiredDist$1) {
|
|
3373
|
-
return dist
|
|
3374
|
-
}
|
|
3375
|
-
hasRequiredDist$1 = 1
|
|
3376
|
-
;(function (exports) {
|
|
3377
|
-
const __createBinding =
|
|
3378
|
-
(this && this.__createBinding) ||
|
|
3379
|
-
(Object.create
|
|
3380
|
-
? function (o, m, k, k2) {
|
|
3381
|
-
if (k2 === undefined) {
|
|
3382
|
-
k2 = k
|
|
3383
|
-
}
|
|
3384
|
-
let desc = Object.getOwnPropertyDescriptor(m, k)
|
|
3385
|
-
if (
|
|
3386
|
-
!desc ||
|
|
3387
|
-
('get' in desc
|
|
3388
|
-
? !m.__esModule
|
|
3389
|
-
: desc.writable || desc.configurable)
|
|
3390
|
-
) {
|
|
3391
|
-
desc = {
|
|
3392
|
-
enumerable: true,
|
|
3393
|
-
get: function () {
|
|
3394
|
-
return m[k]
|
|
3395
|
-
}
|
|
3396
|
-
}
|
|
3397
|
-
}
|
|
3398
|
-
Object.defineProperty(o, k2, desc)
|
|
3399
|
-
}
|
|
3400
|
-
: function (o, m, k, k2) {
|
|
3401
|
-
if (k2 === undefined) {
|
|
3402
|
-
k2 = k
|
|
3403
|
-
}
|
|
3404
|
-
o[k2] = m[k]
|
|
3405
|
-
})
|
|
3406
|
-
const __exportStar =
|
|
3407
|
-
(this && this.__exportStar) ||
|
|
3408
|
-
function (m, exports) {
|
|
3409
|
-
for (const p in m) {
|
|
3410
|
-
if (
|
|
3411
|
-
p !== 'default' &&
|
|
3412
|
-
!Object.prototype.hasOwnProperty.call(exports, p)
|
|
3413
|
-
)
|
|
3414
|
-
__createBinding(exports, m, p)
|
|
3415
|
-
}
|
|
3416
|
-
}
|
|
3417
|
-
Object.defineProperty(exports, '__esModule', {
|
|
3418
|
-
value: true
|
|
3419
|
-
})
|
|
3420
|
-
exports.fdir = void 0
|
|
3421
|
-
const builder_1 = requireBuilder()
|
|
3422
|
-
Object.defineProperty(exports, 'fdir', {
|
|
3423
|
-
enumerable: true,
|
|
3424
|
-
get: function () {
|
|
3425
|
-
return builder_1.Builder
|
|
3426
|
-
}
|
|
3427
|
-
})
|
|
3428
|
-
__exportStar(requireTypes(), exports)
|
|
3429
|
-
})(dist)
|
|
3430
|
-
return dist
|
|
3431
|
-
}
|
|
3432
|
-
|
|
3433
|
-
let hasRequiredDist
|
|
3434
|
-
function requireDist() {
|
|
3435
|
-
if (hasRequiredDist) {
|
|
3436
|
-
return dist$1
|
|
3437
|
-
}
|
|
3438
|
-
hasRequiredDist = 1
|
|
3439
|
-
//#region rolldown:runtime
|
|
3440
|
-
const __create = Object.create
|
|
3441
|
-
const __defProp = Object.defineProperty
|
|
3442
|
-
const __getOwnPropDesc = Object.getOwnPropertyDescriptor
|
|
3443
|
-
const __getOwnPropNames = Object.getOwnPropertyNames
|
|
3444
|
-
const __getProtoOf = Object.getPrototypeOf
|
|
3445
|
-
const __hasOwnProp = Object.prototype.hasOwnProperty
|
|
3446
|
-
const __copyProps = (to, from, except, desc) => {
|
|
3447
|
-
if ((from && typeof from === 'object') || typeof from === 'function') {
|
|
3448
|
-
for (
|
|
3449
|
-
var keys = __getOwnPropNames(from), i = 0, n = keys.length, key;
|
|
3450
|
-
i < n;
|
|
3451
|
-
i++
|
|
3452
|
-
) {
|
|
3453
|
-
key = keys[i]
|
|
3454
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
3455
|
-
__defProp(to, key, {
|
|
3456
|
-
get: (k => from[k]).bind(null, key),
|
|
3457
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
3458
|
-
})
|
|
3459
|
-
}
|
|
3460
|
-
}
|
|
3461
|
-
return to
|
|
3462
|
-
}
|
|
3463
|
-
const __toESM = (mod, isNodeMode, target) => (
|
|
3464
|
-
(target = mod != null ? __create(__getProtoOf(mod)) : {}),
|
|
3465
|
-
__copyProps(
|
|
3466
|
-
!mod || !mod.__esModule
|
|
3467
|
-
? __defProp(target, 'default', {
|
|
3468
|
-
value: mod,
|
|
3469
|
-
enumerable: true
|
|
3470
|
-
})
|
|
3471
|
-
: target,
|
|
3472
|
-
mod
|
|
3473
|
-
)
|
|
3474
|
-
)
|
|
3475
|
-
|
|
3476
|
-
//#endregion
|
|
3477
|
-
const path = __toESM(require$$0)
|
|
3478
|
-
const fdir = __toESM(requireDist$1())
|
|
3479
|
-
const picomatch = __toESM(/*@__PURE__*/ requirePicomatch())
|
|
3480
|
-
|
|
3481
|
-
//#region src/utils.ts
|
|
3482
|
-
const ONLY_PARENT_DIRECTORIES = /^(\/?\.\.)+$/
|
|
3483
|
-
function getPartialMatcher(patterns, options) {
|
|
3484
|
-
const patternsCount = patterns.length
|
|
3485
|
-
const patternsParts = Array(patternsCount)
|
|
3486
|
-
const regexes = Array(patternsCount)
|
|
3487
|
-
for (let i = 0; i < patternsCount; i++) {
|
|
3488
|
-
const parts = splitPattern(patterns[i])
|
|
3489
|
-
patternsParts[i] = parts
|
|
3490
|
-
const partsCount = parts.length
|
|
3491
|
-
const partRegexes = Array(partsCount)
|
|
3492
|
-
for (let j = 0; j < partsCount; j++) {
|
|
3493
|
-
partRegexes[j] = picomatch.default.makeRe(parts[j], options)
|
|
3494
|
-
}
|
|
3495
|
-
regexes[i] = partRegexes
|
|
3496
|
-
}
|
|
3497
|
-
return input => {
|
|
3498
|
-
const inputParts = input.split('/')
|
|
3499
|
-
if (inputParts[0] === '..' && ONLY_PARENT_DIRECTORIES.test(input)) {
|
|
3500
|
-
return true
|
|
3501
|
-
}
|
|
3502
|
-
for (let i = 0; i < patterns.length; i++) {
|
|
3503
|
-
const patternParts = patternsParts[i]
|
|
3504
|
-
const regex = regexes[i]
|
|
3505
|
-
const inputPatternCount = inputParts.length
|
|
3506
|
-
const minParts = Math.min(inputPatternCount, patternParts.length)
|
|
3507
|
-
let j = 0
|
|
3508
|
-
while (j < minParts) {
|
|
3509
|
-
const part = patternParts[j]
|
|
3510
|
-
if (part.includes('/')) {
|
|
3511
|
-
return true
|
|
3512
|
-
}
|
|
3513
|
-
const match = regex[j].test(inputParts[j])
|
|
3514
|
-
if (!match) {
|
|
3515
|
-
break
|
|
3516
|
-
}
|
|
3517
|
-
if (part === '**') {
|
|
3518
|
-
return true
|
|
3519
|
-
}
|
|
3520
|
-
j++
|
|
3521
|
-
}
|
|
3522
|
-
if (j === inputPatternCount) {
|
|
3523
|
-
return true
|
|
3524
|
-
}
|
|
3525
|
-
}
|
|
3526
|
-
return false
|
|
3527
|
-
}
|
|
3528
|
-
}
|
|
3529
|
-
const splitPatternOptions = {
|
|
3530
|
-
parts: true
|
|
3531
|
-
}
|
|
3532
|
-
function splitPattern(path$2) {
|
|
3533
|
-
let _result$parts
|
|
3534
|
-
const result = picomatch.default.scan(path$2, splitPatternOptions)
|
|
3535
|
-
return (
|
|
3536
|
-
(_result$parts = result.parts) === null || _result$parts === void 0
|
|
3537
|
-
? void 0
|
|
3538
|
-
: _result$parts.length
|
|
3539
|
-
)
|
|
3540
|
-
? result.parts
|
|
3541
|
-
: [path$2]
|
|
3542
|
-
}
|
|
3543
|
-
const isWin = process.platform === 'win32'
|
|
3544
|
-
const ESCAPED_WIN32_BACKSLASHES = /\\(?![()[\]{}!+@])/g
|
|
3545
|
-
function convertPosixPathToPattern(path$2) {
|
|
3546
|
-
return escapePosixPath(path$2)
|
|
3547
|
-
}
|
|
3548
|
-
function convertWin32PathToPattern(path$2) {
|
|
3549
|
-
return escapeWin32Path(path$2).replace(ESCAPED_WIN32_BACKSLASHES, '/')
|
|
3550
|
-
}
|
|
3551
|
-
const convertPathToPattern = isWin
|
|
3552
|
-
? convertWin32PathToPattern
|
|
3553
|
-
: convertPosixPathToPattern
|
|
3554
|
-
const POSIX_UNESCAPED_GLOB_SYMBOLS =
|
|
3555
|
-
/(?<!\\)([()[\]{}*?|]|^!|[!+@](?=\()|\\(?![()[\]{}!*+?@|]))/g
|
|
3556
|
-
const WIN32_UNESCAPED_GLOB_SYMBOLS = /(?<!\\)([()[\]{}]|^!|[!+@](?=\())/g
|
|
3557
|
-
const escapePosixPath = path$2 =>
|
|
3558
|
-
path$2.replace(POSIX_UNESCAPED_GLOB_SYMBOLS, '\\$&')
|
|
3559
|
-
const escapeWin32Path = path$2 =>
|
|
3560
|
-
path$2.replace(WIN32_UNESCAPED_GLOB_SYMBOLS, '\\$&')
|
|
3561
|
-
const escapePath = isWin ? escapeWin32Path : escapePosixPath
|
|
3562
|
-
function isDynamicPattern(pattern, options) {
|
|
3563
|
-
if (
|
|
3564
|
-
(options === null || options === void 0
|
|
3565
|
-
? void 0
|
|
3566
|
-
: options.caseSensitiveMatch) === false
|
|
3567
|
-
) {
|
|
3568
|
-
return true
|
|
3569
|
-
}
|
|
3570
|
-
const scan = picomatch.default.scan(pattern)
|
|
3571
|
-
return scan.isGlob || scan.negated
|
|
3572
|
-
}
|
|
3573
|
-
function log(...tasks) {
|
|
3574
|
-
console.log(`[tinyglobby ${new Date().toLocaleTimeString('es')}]`, ...tasks)
|
|
3575
|
-
}
|
|
3576
|
-
|
|
3577
|
-
//#endregion
|
|
3578
|
-
//#region src/index.ts
|
|
3579
|
-
const PARENT_DIRECTORY = /^(\/?\.\.)+/
|
|
3580
|
-
const ESCAPING_BACKSLASHES = /\\(?=[()[\]{}!*+?@|])/g
|
|
3581
|
-
const BACKSLASHES = /\\/g
|
|
3582
|
-
function normalizePattern(pattern, expandDirectories, cwd, props, isIgnore) {
|
|
3583
|
-
let result = pattern
|
|
3584
|
-
if (pattern.endsWith('/')) {
|
|
3585
|
-
result = pattern.slice(0, -1)
|
|
3586
|
-
}
|
|
3587
|
-
if (!result.endsWith('*') && expandDirectories) {
|
|
3588
|
-
result += '/**'
|
|
3589
|
-
}
|
|
3590
|
-
const escapedCwd = escapePath(cwd)
|
|
3591
|
-
if (path.default.isAbsolute(result.replace(ESCAPING_BACKSLASHES, ''))) {
|
|
3592
|
-
result = path.posix.relative(escapedCwd, result)
|
|
3593
|
-
} else {
|
|
3594
|
-
result = path.posix.normalize(result)
|
|
3595
|
-
}
|
|
3596
|
-
const parentDirectoryMatch = PARENT_DIRECTORY.exec(result)
|
|
3597
|
-
const parts = splitPattern(result)
|
|
3598
|
-
if (
|
|
3599
|
-
parentDirectoryMatch === null || parentDirectoryMatch === void 0
|
|
3600
|
-
? void 0
|
|
3601
|
-
: parentDirectoryMatch[0]
|
|
3602
|
-
) {
|
|
3603
|
-
const n = (parentDirectoryMatch[0].length + 1) / 3
|
|
3604
|
-
let i = 0
|
|
3605
|
-
const cwdParts = escapedCwd.split('/')
|
|
3606
|
-
while (i < n && parts[i + n] === cwdParts[cwdParts.length + i - n]) {
|
|
3607
|
-
result =
|
|
3608
|
-
result.slice(0, (n - i - 1) * 3) +
|
|
3609
|
-
result.slice((n - i) * 3 + parts[i + n].length + 1) || '.'
|
|
3610
|
-
i++
|
|
3611
|
-
}
|
|
3612
|
-
const potentialRoot = path.posix.join(
|
|
3613
|
-
cwd,
|
|
3614
|
-
parentDirectoryMatch[0].slice(i * 3)
|
|
3615
|
-
)
|
|
3616
|
-
if (
|
|
3617
|
-
!potentialRoot.startsWith('.') &&
|
|
3618
|
-
props.root.length > potentialRoot.length
|
|
3619
|
-
) {
|
|
3620
|
-
props.root = potentialRoot
|
|
3621
|
-
props.depthOffset = -n + i
|
|
3622
|
-
}
|
|
3623
|
-
}
|
|
3624
|
-
if (!isIgnore && props.depthOffset >= 0) {
|
|
3625
|
-
let _props$commonPath
|
|
3626
|
-
;((_props$commonPath = props.commonPath) !== null &&
|
|
3627
|
-
_props$commonPath !== void 0) ||
|
|
3628
|
-
(props.commonPath = parts)
|
|
3629
|
-
const newCommonPath = []
|
|
3630
|
-
const length = Math.min(props.commonPath.length, parts.length)
|
|
3631
|
-
for (let i = 0; i < length; i++) {
|
|
3632
|
-
const part = parts[i]
|
|
3633
|
-
if (part === '**' && !parts[i + 1]) {
|
|
3634
|
-
newCommonPath.pop()
|
|
3635
|
-
break
|
|
3636
|
-
}
|
|
3637
|
-
if (
|
|
3638
|
-
part !== props.commonPath[i] ||
|
|
3639
|
-
isDynamicPattern(part) ||
|
|
3640
|
-
i === parts.length - 1
|
|
3641
|
-
) {
|
|
3642
|
-
break
|
|
3643
|
-
}
|
|
3644
|
-
newCommonPath.push(part)
|
|
3645
|
-
}
|
|
3646
|
-
props.depthOffset = newCommonPath.length
|
|
3647
|
-
props.commonPath = newCommonPath
|
|
3648
|
-
props.root =
|
|
3649
|
-
newCommonPath.length > 0
|
|
3650
|
-
? path.default.posix.join(cwd, ...newCommonPath)
|
|
3651
|
-
: cwd
|
|
3652
|
-
}
|
|
3653
|
-
return result
|
|
3654
|
-
}
|
|
3655
|
-
function processPatterns(
|
|
3656
|
-
{ patterns, ignore = [], expandDirectories = true },
|
|
3657
|
-
cwd,
|
|
3658
|
-
props
|
|
3659
|
-
) {
|
|
3660
|
-
if (typeof patterns === 'string') {
|
|
3661
|
-
patterns = [patterns]
|
|
3662
|
-
} else if (!patterns) {
|
|
3663
|
-
patterns = ['**/*']
|
|
3664
|
-
}
|
|
3665
|
-
if (typeof ignore === 'string') {
|
|
3666
|
-
ignore = [ignore]
|
|
3667
|
-
}
|
|
3668
|
-
const matchPatterns = []
|
|
3669
|
-
const ignorePatterns = []
|
|
3670
|
-
for (const pattern of ignore) {
|
|
3671
|
-
if (!pattern) {
|
|
3672
|
-
continue
|
|
3673
|
-
}
|
|
3674
|
-
if (pattern[0] !== '!' || pattern[1] === '(') {
|
|
3675
|
-
ignorePatterns.push(
|
|
3676
|
-
normalizePattern(pattern, expandDirectories, cwd, props, true)
|
|
3677
|
-
)
|
|
3678
|
-
}
|
|
3679
|
-
}
|
|
3680
|
-
for (const pattern of patterns) {
|
|
3681
|
-
if (!pattern) {
|
|
3682
|
-
continue
|
|
3683
|
-
}
|
|
3684
|
-
if (pattern[0] !== '!' || pattern[1] === '(') {
|
|
3685
|
-
matchPatterns.push(
|
|
3686
|
-
normalizePattern(pattern, expandDirectories, cwd, props, false)
|
|
3687
|
-
)
|
|
3688
|
-
} else if (pattern[1] !== '!' || pattern[2] === '(') {
|
|
3689
|
-
ignorePatterns.push(
|
|
3690
|
-
normalizePattern(
|
|
3691
|
-
pattern.slice(1),
|
|
3692
|
-
expandDirectories,
|
|
3693
|
-
cwd,
|
|
3694
|
-
props,
|
|
3695
|
-
true
|
|
3696
|
-
)
|
|
3697
|
-
)
|
|
3698
|
-
}
|
|
3699
|
-
}
|
|
3700
|
-
return {
|
|
3701
|
-
match: matchPatterns,
|
|
3702
|
-
ignore: ignorePatterns
|
|
3703
|
-
}
|
|
3704
|
-
}
|
|
3705
|
-
function getRelativePath(path$2, cwd, root) {
|
|
3706
|
-
return path.posix.relative(cwd, `${root}/${path$2}`) || '.'
|
|
3707
|
-
}
|
|
3708
|
-
function processPath(path$2, cwd, root, isDirectory, absolute) {
|
|
3709
|
-
const relativePath = absolute
|
|
3710
|
-
? path$2.slice(root === '/' ? 1 : root.length + 1) || '.'
|
|
3711
|
-
: path$2
|
|
3712
|
-
if (root === cwd) {
|
|
3713
|
-
return isDirectory && relativePath !== '.'
|
|
3714
|
-
? relativePath.slice(0, -1)
|
|
3715
|
-
: relativePath
|
|
3716
|
-
}
|
|
3717
|
-
return getRelativePath(relativePath, cwd, root)
|
|
3718
|
-
}
|
|
3719
|
-
function formatPaths(paths, cwd, root) {
|
|
3720
|
-
for (let i = paths.length - 1; i >= 0; i--) {
|
|
3721
|
-
const path$2 = paths[i]
|
|
3722
|
-
paths[i] =
|
|
3723
|
-
getRelativePath(path$2, cwd, root) +
|
|
3724
|
-
(!path$2 || path$2.endsWith('/') ? '/' : '')
|
|
3725
|
-
}
|
|
3726
|
-
return paths
|
|
3727
|
-
}
|
|
3728
|
-
function crawl(options, cwd, sync) {
|
|
3729
|
-
if (process.env.TINYGLOBBY_DEBUG) {
|
|
3730
|
-
options.debug = true
|
|
3731
|
-
}
|
|
3732
|
-
if (options.debug) {
|
|
3733
|
-
log('globbing with options:', options, 'cwd:', cwd)
|
|
3734
|
-
}
|
|
3735
|
-
if (Array.isArray(options.patterns) && options.patterns.length === 0) {
|
|
3736
|
-
return sync ? [] : Promise.resolve([])
|
|
3737
|
-
}
|
|
3738
|
-
const props = {
|
|
3739
|
-
root: cwd,
|
|
3740
|
-
commonPath: null,
|
|
3741
|
-
depthOffset: 0
|
|
3742
|
-
}
|
|
3743
|
-
const processed = processPatterns(options, cwd, props)
|
|
3744
|
-
const nocase = options.caseSensitiveMatch === false
|
|
3745
|
-
if (options.debug) {
|
|
3746
|
-
log('internal processing patterns:', processed)
|
|
3747
|
-
}
|
|
3748
|
-
const matcher = (0, picomatch.default)(processed.match, {
|
|
3749
|
-
dot: options.dot,
|
|
3750
|
-
nocase,
|
|
3751
|
-
ignore: processed.ignore
|
|
3752
|
-
})
|
|
3753
|
-
const ignore = (0, picomatch.default)(processed.ignore, {
|
|
3754
|
-
dot: options.dot,
|
|
3755
|
-
nocase
|
|
3756
|
-
})
|
|
3757
|
-
const partialMatcher = getPartialMatcher(processed.match, {
|
|
3758
|
-
dot: options.dot,
|
|
3759
|
-
nocase
|
|
3760
|
-
})
|
|
3761
|
-
const fdirOptions = {
|
|
3762
|
-
filters: [
|
|
3763
|
-
options.debug
|
|
3764
|
-
? (p, isDirectory) => {
|
|
3765
|
-
const path$2 = processPath(
|
|
3766
|
-
p,
|
|
3767
|
-
cwd,
|
|
3768
|
-
props.root,
|
|
3769
|
-
isDirectory,
|
|
3770
|
-
options.absolute
|
|
3771
|
-
)
|
|
3772
|
-
const matches = matcher(path$2)
|
|
3773
|
-
if (matches) {
|
|
3774
|
-
log(`matched ${path$2}`)
|
|
3775
|
-
}
|
|
3776
|
-
return matches
|
|
3777
|
-
}
|
|
3778
|
-
: (p, isDirectory) =>
|
|
3779
|
-
matcher(
|
|
3780
|
-
processPath(p, cwd, props.root, isDirectory, options.absolute)
|
|
3781
|
-
)
|
|
3782
|
-
],
|
|
3783
|
-
exclude: options.debug
|
|
3784
|
-
? (_, p) => {
|
|
3785
|
-
const relativePath = processPath(p, cwd, props.root, true, true)
|
|
3786
|
-
const skipped =
|
|
3787
|
-
(relativePath !== '.' && !partialMatcher(relativePath)) ||
|
|
3788
|
-
ignore(relativePath)
|
|
3789
|
-
if (skipped) {
|
|
3790
|
-
log(`skipped ${p}`)
|
|
3791
|
-
} else {
|
|
3792
|
-
log(`crawling ${p}`)
|
|
3793
|
-
}
|
|
3794
|
-
return skipped
|
|
3795
|
-
}
|
|
3796
|
-
: (_, p) => {
|
|
3797
|
-
const relativePath = processPath(p, cwd, props.root, true, true)
|
|
3798
|
-
return (
|
|
3799
|
-
(relativePath !== '.' && !partialMatcher(relativePath)) ||
|
|
3800
|
-
ignore(relativePath)
|
|
3801
|
-
)
|
|
3802
|
-
},
|
|
3803
|
-
pathSeparator: '/',
|
|
3804
|
-
relativePaths: true,
|
|
3805
|
-
resolveSymlinks: true
|
|
3806
|
-
}
|
|
3807
|
-
if (options.deep !== void 0) {
|
|
3808
|
-
fdirOptions.maxDepth = Math.round(options.deep - props.depthOffset)
|
|
3809
|
-
}
|
|
3810
|
-
if (options.absolute) {
|
|
3811
|
-
fdirOptions.relativePaths = false
|
|
3812
|
-
fdirOptions.resolvePaths = true
|
|
3813
|
-
fdirOptions.includeBasePath = true
|
|
3814
|
-
}
|
|
3815
|
-
if (options.followSymbolicLinks === false) {
|
|
3816
|
-
fdirOptions.resolveSymlinks = false
|
|
3817
|
-
fdirOptions.excludeSymlinks = true
|
|
3818
|
-
}
|
|
3819
|
-
if (options.onlyDirectories) {
|
|
3820
|
-
fdirOptions.excludeFiles = true
|
|
3821
|
-
fdirOptions.includeDirs = true
|
|
3822
|
-
} else if (options.onlyFiles === false) {
|
|
3823
|
-
fdirOptions.includeDirs = true
|
|
3824
|
-
}
|
|
3825
|
-
props.root = props.root.replace(BACKSLASHES, '')
|
|
3826
|
-
const root = props.root
|
|
3827
|
-
if (options.debug) {
|
|
3828
|
-
log('internal properties:', props)
|
|
3829
|
-
}
|
|
3830
|
-
const api = new fdir.fdir(fdirOptions).crawl(root)
|
|
3831
|
-
if (cwd === root || options.absolute) {
|
|
3832
|
-
return sync ? api.sync() : api.withPromise()
|
|
3833
|
-
}
|
|
3834
|
-
return sync
|
|
3835
|
-
? formatPaths(api.sync(), cwd, root)
|
|
3836
|
-
: api.withPromise().then(paths => formatPaths(paths, cwd, root))
|
|
3837
|
-
}
|
|
3838
|
-
async function glob(patternsOrOptions, options) {
|
|
3839
|
-
if (
|
|
3840
|
-
patternsOrOptions &&
|
|
3841
|
-
(options === null || options === void 0 ? void 0 : options.patterns)
|
|
3842
|
-
) {
|
|
3843
|
-
throw new Error('Cannot pass patterns as both an argument and an option')
|
|
3844
|
-
}
|
|
3845
|
-
const opts =
|
|
3846
|
-
Array.isArray(patternsOrOptions) || typeof patternsOrOptions === 'string'
|
|
3847
|
-
? {
|
|
3848
|
-
...options,
|
|
3849
|
-
patterns: patternsOrOptions
|
|
3850
|
-
}
|
|
3851
|
-
: patternsOrOptions
|
|
3852
|
-
const cwd = opts.cwd
|
|
3853
|
-
? path.default.resolve(opts.cwd).replace(BACKSLASHES, '/')
|
|
3854
|
-
: process.cwd().replace(BACKSLASHES, '/')
|
|
3855
|
-
return crawl(opts, cwd, false)
|
|
3856
|
-
}
|
|
3857
|
-
function globSync(patternsOrOptions, options) {
|
|
3858
|
-
if (
|
|
3859
|
-
patternsOrOptions &&
|
|
3860
|
-
(options === null || options === void 0 ? void 0 : options.patterns)
|
|
3861
|
-
) {
|
|
3862
|
-
throw new Error('Cannot pass patterns as both an argument and an option')
|
|
3863
|
-
}
|
|
3864
|
-
const opts =
|
|
3865
|
-
Array.isArray(patternsOrOptions) || typeof patternsOrOptions === 'string'
|
|
3866
|
-
? {
|
|
3867
|
-
...options,
|
|
3868
|
-
patterns: patternsOrOptions
|
|
3869
|
-
}
|
|
3870
|
-
: patternsOrOptions
|
|
3871
|
-
const cwd = opts.cwd
|
|
3872
|
-
? path.default.resolve(opts.cwd).replace(BACKSLASHES, '/')
|
|
3873
|
-
: process.cwd().replace(BACKSLASHES, '/')
|
|
3874
|
-
return crawl(opts, cwd, true)
|
|
3875
|
-
}
|
|
3876
|
-
|
|
3877
|
-
//#endregion
|
|
3878
|
-
dist$1.convertPathToPattern = convertPathToPattern
|
|
3879
|
-
dist$1.escapePath = escapePath
|
|
3880
|
-
dist$1.glob = glob
|
|
3881
|
-
dist$1.globSync = globSync
|
|
3882
|
-
dist$1.isDynamicPattern = isDynamicPattern
|
|
3883
|
-
return dist$1
|
|
3884
|
-
}
|
|
3885
|
-
|
|
3886
|
-
const distExports = /*@__PURE__*/ requireDist()
|
|
3887
|
-
|
|
3888
|
-
module.exports = distExports
|