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