@shuiyangsuan/cli 0.0.4 → 0.0.9
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 +32 -32
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +3041 -0
- package/dist/cli.js.map +1 -0
- package/dist/config-D5i9xsXl.js +2753 -0
- package/dist/config-D5i9xsXl.js.map +1 -0
- package/dist/index.d.ts +14 -14
- package/dist/index.js +2 -8932
- package/package.json +11 -11
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,2753 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import * as nativeFs$1 from "fs";
|
|
3
|
+
import nativeFs, { existsSync, lstatSync, readFileSync, rm, unlink } from "fs";
|
|
4
|
+
import path, { basename, dirname, join, normalize, posix, relative, resolve, sep } from "path";
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
6
|
+
import { createRequire as createRequire$1 } from "module";
|
|
7
|
+
import { promisify } from "util";
|
|
8
|
+
|
|
9
|
+
//#region \0rolldown/runtime.js
|
|
10
|
+
var __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
20
|
+
key = keys[i];
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
22
|
+
__defProp(to, key, {
|
|
23
|
+
get: ((k) => from[k]).bind(null, key),
|
|
24
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return to;
|
|
30
|
+
};
|
|
31
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
32
|
+
value: mod,
|
|
33
|
+
enumerable: true
|
|
34
|
+
}) : target, mod));
|
|
35
|
+
var __require$1 = /* @__PURE__ */ createRequire(import.meta.url);
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region node_modules/.pnpm/fdir@6.5.0_picomatch@4.0.3/node_modules/fdir/dist/index.mjs
|
|
39
|
+
var __require = /* @__PURE__ */ createRequire$1(import.meta.url);
|
|
40
|
+
function cleanPath(path) {
|
|
41
|
+
let normalized = normalize(path);
|
|
42
|
+
if (normalized.length > 1 && normalized[normalized.length - 1] === sep) normalized = normalized.substring(0, normalized.length - 1);
|
|
43
|
+
return normalized;
|
|
44
|
+
}
|
|
45
|
+
const SLASHES_REGEX = /[\\/]/g;
|
|
46
|
+
function convertSlashes(path, separator) {
|
|
47
|
+
return path.replace(SLASHES_REGEX, separator);
|
|
48
|
+
}
|
|
49
|
+
const WINDOWS_ROOT_DIR_REGEX = /^[a-z]:[\\/]$/i;
|
|
50
|
+
function isRootDirectory(path) {
|
|
51
|
+
return path === "/" || WINDOWS_ROOT_DIR_REGEX.test(path);
|
|
52
|
+
}
|
|
53
|
+
function normalizePath(path, options) {
|
|
54
|
+
const { resolvePaths, normalizePath: normalizePath$1, pathSeparator } = options;
|
|
55
|
+
const pathNeedsCleaning = process.platform === "win32" && path.includes("/") || path.startsWith(".");
|
|
56
|
+
if (resolvePaths) path = resolve(path);
|
|
57
|
+
if (normalizePath$1 || pathNeedsCleaning) path = cleanPath(path);
|
|
58
|
+
if (path === ".") return "";
|
|
59
|
+
return convertSlashes(path[path.length - 1] !== pathSeparator ? path + pathSeparator : path, pathSeparator);
|
|
60
|
+
}
|
|
61
|
+
function joinPathWithBasePath(filename, directoryPath) {
|
|
62
|
+
return directoryPath + filename;
|
|
63
|
+
}
|
|
64
|
+
function joinPathWithRelativePath(root, options) {
|
|
65
|
+
return function(filename, directoryPath) {
|
|
66
|
+
if (directoryPath.startsWith(root)) return directoryPath.slice(root.length) + filename;
|
|
67
|
+
else return convertSlashes(relative(root, directoryPath), options.pathSeparator) + options.pathSeparator + filename;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function joinPath(filename) {
|
|
71
|
+
return filename;
|
|
72
|
+
}
|
|
73
|
+
function joinDirectoryPath(filename, directoryPath, separator) {
|
|
74
|
+
return directoryPath + filename + separator;
|
|
75
|
+
}
|
|
76
|
+
function build$7(root, options) {
|
|
77
|
+
const { relativePaths, includeBasePath } = options;
|
|
78
|
+
return relativePaths && root ? joinPathWithRelativePath(root, options) : includeBasePath ? joinPathWithBasePath : joinPath;
|
|
79
|
+
}
|
|
80
|
+
function pushDirectoryWithRelativePath(root) {
|
|
81
|
+
return function(directoryPath, paths) {
|
|
82
|
+
paths.push(directoryPath.substring(root.length) || ".");
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function pushDirectoryFilterWithRelativePath(root) {
|
|
86
|
+
return function(directoryPath, paths, filters) {
|
|
87
|
+
const relativePath = directoryPath.substring(root.length) || ".";
|
|
88
|
+
if (filters.every((filter) => filter(relativePath, true))) paths.push(relativePath);
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const pushDirectory = (directoryPath, paths) => {
|
|
92
|
+
paths.push(directoryPath || ".");
|
|
93
|
+
};
|
|
94
|
+
const pushDirectoryFilter = (directoryPath, paths, filters) => {
|
|
95
|
+
const path = directoryPath || ".";
|
|
96
|
+
if (filters.every((filter) => filter(path, true))) paths.push(path);
|
|
97
|
+
};
|
|
98
|
+
const empty$2 = () => {};
|
|
99
|
+
function build$6(root, options) {
|
|
100
|
+
const { includeDirs, filters, relativePaths } = options;
|
|
101
|
+
if (!includeDirs) return empty$2;
|
|
102
|
+
if (relativePaths) return filters && filters.length ? pushDirectoryFilterWithRelativePath(root) : pushDirectoryWithRelativePath(root);
|
|
103
|
+
return filters && filters.length ? pushDirectoryFilter : pushDirectory;
|
|
104
|
+
}
|
|
105
|
+
const pushFileFilterAndCount = (filename, _paths, counts, filters) => {
|
|
106
|
+
if (filters.every((filter) => filter(filename, false))) counts.files++;
|
|
107
|
+
};
|
|
108
|
+
const pushFileFilter = (filename, paths, _counts, filters) => {
|
|
109
|
+
if (filters.every((filter) => filter(filename, false))) paths.push(filename);
|
|
110
|
+
};
|
|
111
|
+
const pushFileCount = (_filename, _paths, counts, _filters) => {
|
|
112
|
+
counts.files++;
|
|
113
|
+
};
|
|
114
|
+
const pushFile = (filename, paths) => {
|
|
115
|
+
paths.push(filename);
|
|
116
|
+
};
|
|
117
|
+
const empty$1 = () => {};
|
|
118
|
+
function build$5(options) {
|
|
119
|
+
const { excludeFiles, filters, onlyCounts } = options;
|
|
120
|
+
if (excludeFiles) return empty$1;
|
|
121
|
+
if (filters && filters.length) return onlyCounts ? pushFileFilterAndCount : pushFileFilter;
|
|
122
|
+
else if (onlyCounts) return pushFileCount;
|
|
123
|
+
else return pushFile;
|
|
124
|
+
}
|
|
125
|
+
const getArray = (paths) => {
|
|
126
|
+
return paths;
|
|
127
|
+
};
|
|
128
|
+
const getArrayGroup = () => {
|
|
129
|
+
return [""].slice(0, 0);
|
|
130
|
+
};
|
|
131
|
+
function build$4(options) {
|
|
132
|
+
return options.group ? getArrayGroup : getArray;
|
|
133
|
+
}
|
|
134
|
+
const groupFiles = (groups, directory, files) => {
|
|
135
|
+
groups.push({
|
|
136
|
+
directory,
|
|
137
|
+
files,
|
|
138
|
+
dir: directory
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
const empty = () => {};
|
|
142
|
+
function build$3(options) {
|
|
143
|
+
return options.group ? groupFiles : empty;
|
|
144
|
+
}
|
|
145
|
+
const resolveSymlinksAsync = function(path, state, callback$1) {
|
|
146
|
+
const { queue, fs, options: { suppressErrors } } = state;
|
|
147
|
+
queue.enqueue();
|
|
148
|
+
fs.realpath(path, (error, resolvedPath) => {
|
|
149
|
+
if (error) return queue.dequeue(suppressErrors ? null : error, state);
|
|
150
|
+
fs.stat(resolvedPath, (error$1, stat) => {
|
|
151
|
+
if (error$1) return queue.dequeue(suppressErrors ? null : error$1, state);
|
|
152
|
+
if (stat.isDirectory() && isRecursive(path, resolvedPath, state)) return queue.dequeue(null, state);
|
|
153
|
+
callback$1(stat, resolvedPath);
|
|
154
|
+
queue.dequeue(null, state);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
const resolveSymlinks = function(path, state, callback$1) {
|
|
159
|
+
const { queue, fs, options: { suppressErrors } } = state;
|
|
160
|
+
queue.enqueue();
|
|
161
|
+
try {
|
|
162
|
+
const resolvedPath = fs.realpathSync(path);
|
|
163
|
+
const stat = fs.statSync(resolvedPath);
|
|
164
|
+
if (stat.isDirectory() && isRecursive(path, resolvedPath, state)) return;
|
|
165
|
+
callback$1(stat, resolvedPath);
|
|
166
|
+
} catch (e) {
|
|
167
|
+
if (!suppressErrors) throw e;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
function build$2(options, isSynchronous) {
|
|
171
|
+
if (!options.resolveSymlinks || options.excludeSymlinks) return null;
|
|
172
|
+
return isSynchronous ? resolveSymlinks : resolveSymlinksAsync;
|
|
173
|
+
}
|
|
174
|
+
function isRecursive(path, resolved, state) {
|
|
175
|
+
if (state.options.useRealPaths) return isRecursiveUsingRealPaths(resolved, state);
|
|
176
|
+
let parent = dirname(path);
|
|
177
|
+
let depth = 1;
|
|
178
|
+
while (parent !== state.root && depth < 2) {
|
|
179
|
+
const resolvedPath = state.symlinks.get(parent);
|
|
180
|
+
if (!!resolvedPath && (resolvedPath === resolved || resolvedPath.startsWith(resolved) || resolved.startsWith(resolvedPath))) depth++;
|
|
181
|
+
else parent = dirname(parent);
|
|
182
|
+
}
|
|
183
|
+
state.symlinks.set(path, resolved);
|
|
184
|
+
return depth > 1;
|
|
185
|
+
}
|
|
186
|
+
function isRecursiveUsingRealPaths(resolved, state) {
|
|
187
|
+
return state.visited.includes(resolved + state.options.pathSeparator);
|
|
188
|
+
}
|
|
189
|
+
const onlyCountsSync = (state) => {
|
|
190
|
+
return state.counts;
|
|
191
|
+
};
|
|
192
|
+
const groupsSync = (state) => {
|
|
193
|
+
return state.groups;
|
|
194
|
+
};
|
|
195
|
+
const defaultSync = (state) => {
|
|
196
|
+
return state.paths;
|
|
197
|
+
};
|
|
198
|
+
const limitFilesSync = (state) => {
|
|
199
|
+
return state.paths.slice(0, state.options.maxFiles);
|
|
200
|
+
};
|
|
201
|
+
const onlyCountsAsync = (state, error, callback$1) => {
|
|
202
|
+
report(error, callback$1, state.counts, state.options.suppressErrors);
|
|
203
|
+
return null;
|
|
204
|
+
};
|
|
205
|
+
const defaultAsync = (state, error, callback$1) => {
|
|
206
|
+
report(error, callback$1, state.paths, state.options.suppressErrors);
|
|
207
|
+
return null;
|
|
208
|
+
};
|
|
209
|
+
const limitFilesAsync = (state, error, callback$1) => {
|
|
210
|
+
report(error, callback$1, state.paths.slice(0, state.options.maxFiles), state.options.suppressErrors);
|
|
211
|
+
return null;
|
|
212
|
+
};
|
|
213
|
+
const groupsAsync = (state, error, callback$1) => {
|
|
214
|
+
report(error, callback$1, state.groups, state.options.suppressErrors);
|
|
215
|
+
return null;
|
|
216
|
+
};
|
|
217
|
+
function report(error, callback$1, output, suppressErrors) {
|
|
218
|
+
if (error && !suppressErrors) callback$1(error, output);
|
|
219
|
+
else callback$1(null, output);
|
|
220
|
+
}
|
|
221
|
+
function build$1(options, isSynchronous) {
|
|
222
|
+
const { onlyCounts, group, maxFiles } = options;
|
|
223
|
+
if (onlyCounts) return isSynchronous ? onlyCountsSync : onlyCountsAsync;
|
|
224
|
+
else if (group) return isSynchronous ? groupsSync : groupsAsync;
|
|
225
|
+
else if (maxFiles) return isSynchronous ? limitFilesSync : limitFilesAsync;
|
|
226
|
+
else return isSynchronous ? defaultSync : defaultAsync;
|
|
227
|
+
}
|
|
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
|
+
* This is a custom stateless queue to track concurrent async fs calls.
|
|
258
|
+
* It increments a counter whenever a call is queued and decrements it
|
|
259
|
+
* as soon as it completes. When the counter hits 0, it calls onQueueEmpty.
|
|
260
|
+
*/
|
|
261
|
+
var Queue = class {
|
|
262
|
+
count = 0;
|
|
263
|
+
constructor(onQueueEmpty) {
|
|
264
|
+
this.onQueueEmpty = onQueueEmpty;
|
|
265
|
+
}
|
|
266
|
+
enqueue() {
|
|
267
|
+
this.count++;
|
|
268
|
+
return this.count;
|
|
269
|
+
}
|
|
270
|
+
dequeue(error, output) {
|
|
271
|
+
if (this.onQueueEmpty && (--this.count <= 0 || error)) {
|
|
272
|
+
this.onQueueEmpty(error, output);
|
|
273
|
+
if (error) {
|
|
274
|
+
output.controller.abort();
|
|
275
|
+
this.onQueueEmpty = void 0;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
var Counter = class {
|
|
281
|
+
_files = 0;
|
|
282
|
+
_directories = 0;
|
|
283
|
+
set files(num) {
|
|
284
|
+
this._files = num;
|
|
285
|
+
}
|
|
286
|
+
get files() {
|
|
287
|
+
return this._files;
|
|
288
|
+
}
|
|
289
|
+
set directories(num) {
|
|
290
|
+
this._directories = num;
|
|
291
|
+
}
|
|
292
|
+
get directories() {
|
|
293
|
+
return this._directories;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* @deprecated use `directories` instead
|
|
297
|
+
*/
|
|
298
|
+
/* c8 ignore next 3 */
|
|
299
|
+
get dirs() {
|
|
300
|
+
return this._directories;
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
/**
|
|
304
|
+
* AbortController is not supported on Node 14 so we use this until we can drop
|
|
305
|
+
* support for Node 14.
|
|
306
|
+
*/
|
|
307
|
+
var Aborter = class {
|
|
308
|
+
aborted = false;
|
|
309
|
+
abort() {
|
|
310
|
+
this.aborted = true;
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
var Walker = class {
|
|
314
|
+
root;
|
|
315
|
+
isSynchronous;
|
|
316
|
+
state;
|
|
317
|
+
joinPath;
|
|
318
|
+
pushDirectory;
|
|
319
|
+
pushFile;
|
|
320
|
+
getArray;
|
|
321
|
+
groupFiles;
|
|
322
|
+
resolveSymlink;
|
|
323
|
+
walkDirectory;
|
|
324
|
+
callbackInvoker;
|
|
325
|
+
constructor(root, options, callback$1) {
|
|
326
|
+
this.isSynchronous = !callback$1;
|
|
327
|
+
this.callbackInvoker = build$1(options, this.isSynchronous);
|
|
328
|
+
this.root = normalizePath(root, options);
|
|
329
|
+
this.state = {
|
|
330
|
+
root: isRootDirectory(this.root) ? this.root : this.root.slice(0, -1),
|
|
331
|
+
paths: [""].slice(0, 0),
|
|
332
|
+
groups: [],
|
|
333
|
+
counts: new Counter(),
|
|
334
|
+
options,
|
|
335
|
+
queue: new Queue((error, state) => this.callbackInvoker(state, error, callback$1)),
|
|
336
|
+
symlinks: /* @__PURE__ */ new Map(),
|
|
337
|
+
visited: [""].slice(0, 0),
|
|
338
|
+
controller: new Aborter(),
|
|
339
|
+
fs: options.fs || nativeFs$1
|
|
340
|
+
};
|
|
341
|
+
this.joinPath = build$7(this.root, options);
|
|
342
|
+
this.pushDirectory = build$6(this.root, options);
|
|
343
|
+
this.pushFile = build$5(options);
|
|
344
|
+
this.getArray = build$4(options);
|
|
345
|
+
this.groupFiles = build$3(options);
|
|
346
|
+
this.resolveSymlink = build$2(options, this.isSynchronous);
|
|
347
|
+
this.walkDirectory = build(this.isSynchronous);
|
|
348
|
+
}
|
|
349
|
+
start() {
|
|
350
|
+
this.pushDirectory(this.root, this.state.paths, this.state.options.filters);
|
|
351
|
+
this.walkDirectory(this.state, this.root, this.root, this.state.options.maxDepth, this.walk);
|
|
352
|
+
return this.isSynchronous ? this.callbackInvoker(this.state, null) : null;
|
|
353
|
+
}
|
|
354
|
+
walk = (entries, directoryPath, depth) => {
|
|
355
|
+
const { paths, options: { filters, resolveSymlinks: resolveSymlinks$1, excludeSymlinks, exclude, maxFiles, signal, useRealPaths, pathSeparator }, controller } = this.state;
|
|
356
|
+
if (controller.aborted || signal && signal.aborted || maxFiles && paths.length > maxFiles) return;
|
|
357
|
+
const files = this.getArray(this.state.paths);
|
|
358
|
+
for (let i = 0; i < entries.length; ++i) {
|
|
359
|
+
const entry = entries[i];
|
|
360
|
+
if (entry.isFile() || entry.isSymbolicLink() && !resolveSymlinks$1 && !excludeSymlinks) {
|
|
361
|
+
const filename = this.joinPath(entry.name, directoryPath);
|
|
362
|
+
this.pushFile(filename, files, this.state.counts, filters);
|
|
363
|
+
} else if (entry.isDirectory()) {
|
|
364
|
+
let path = joinDirectoryPath(entry.name, directoryPath, this.state.options.pathSeparator);
|
|
365
|
+
if (exclude && exclude(entry.name, path)) continue;
|
|
366
|
+
this.pushDirectory(path, paths, filters);
|
|
367
|
+
this.walkDirectory(this.state, path, path, depth - 1, this.walk);
|
|
368
|
+
} else if (this.resolveSymlink && entry.isSymbolicLink()) {
|
|
369
|
+
let path = joinPathWithBasePath(entry.name, directoryPath);
|
|
370
|
+
this.resolveSymlink(path, this.state, (stat, resolvedPath) => {
|
|
371
|
+
if (stat.isDirectory()) {
|
|
372
|
+
resolvedPath = normalizePath(resolvedPath, this.state.options);
|
|
373
|
+
if (exclude && exclude(entry.name, useRealPaths ? resolvedPath : path + pathSeparator)) return;
|
|
374
|
+
this.walkDirectory(this.state, resolvedPath, useRealPaths ? resolvedPath : path + pathSeparator, depth - 1, this.walk);
|
|
375
|
+
} else {
|
|
376
|
+
resolvedPath = useRealPaths ? resolvedPath : path;
|
|
377
|
+
const filename = basename(resolvedPath);
|
|
378
|
+
const directoryPath$1 = normalizePath(dirname(resolvedPath), this.state.options);
|
|
379
|
+
resolvedPath = this.joinPath(filename, directoryPath$1);
|
|
380
|
+
this.pushFile(resolvedPath, files, this.state.counts, filters);
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
this.groupFiles(this.state.groups, directoryPath, files);
|
|
386
|
+
};
|
|
387
|
+
};
|
|
388
|
+
function promise(root, options) {
|
|
389
|
+
return new Promise((resolve$1, reject) => {
|
|
390
|
+
callback(root, options, (err, output) => {
|
|
391
|
+
if (err) return reject(err);
|
|
392
|
+
resolve$1(output);
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
function callback(root, options, callback$1) {
|
|
397
|
+
new Walker(root, options, callback$1).start();
|
|
398
|
+
}
|
|
399
|
+
function sync(root, options) {
|
|
400
|
+
return new Walker(root, options).start();
|
|
401
|
+
}
|
|
402
|
+
var APIBuilder = class {
|
|
403
|
+
constructor(root, options) {
|
|
404
|
+
this.root = root;
|
|
405
|
+
this.options = options;
|
|
406
|
+
}
|
|
407
|
+
withPromise() {
|
|
408
|
+
return promise(this.root, this.options);
|
|
409
|
+
}
|
|
410
|
+
withCallback(cb) {
|
|
411
|
+
callback(this.root, this.options, cb);
|
|
412
|
+
}
|
|
413
|
+
sync() {
|
|
414
|
+
return sync(this.root, this.options);
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
let pm = null;
|
|
418
|
+
/* c8 ignore next 6 */
|
|
419
|
+
try {
|
|
420
|
+
__require.resolve("picomatch");
|
|
421
|
+
pm = __require("picomatch");
|
|
422
|
+
} catch {}
|
|
423
|
+
var Builder = class {
|
|
424
|
+
globCache = {};
|
|
425
|
+
options = {
|
|
426
|
+
maxDepth: Infinity,
|
|
427
|
+
suppressErrors: true,
|
|
428
|
+
pathSeparator: sep,
|
|
429
|
+
filters: []
|
|
430
|
+
};
|
|
431
|
+
globFunction;
|
|
432
|
+
constructor(options) {
|
|
433
|
+
this.options = {
|
|
434
|
+
...this.options,
|
|
435
|
+
...options
|
|
436
|
+
};
|
|
437
|
+
this.globFunction = this.options.globFunction;
|
|
438
|
+
}
|
|
439
|
+
group() {
|
|
440
|
+
this.options.group = true;
|
|
441
|
+
return this;
|
|
442
|
+
}
|
|
443
|
+
withPathSeparator(separator) {
|
|
444
|
+
this.options.pathSeparator = separator;
|
|
445
|
+
return this;
|
|
446
|
+
}
|
|
447
|
+
withBasePath() {
|
|
448
|
+
this.options.includeBasePath = true;
|
|
449
|
+
return this;
|
|
450
|
+
}
|
|
451
|
+
withRelativePaths() {
|
|
452
|
+
this.options.relativePaths = true;
|
|
453
|
+
return this;
|
|
454
|
+
}
|
|
455
|
+
withDirs() {
|
|
456
|
+
this.options.includeDirs = true;
|
|
457
|
+
return this;
|
|
458
|
+
}
|
|
459
|
+
withMaxDepth(depth) {
|
|
460
|
+
this.options.maxDepth = depth;
|
|
461
|
+
return this;
|
|
462
|
+
}
|
|
463
|
+
withMaxFiles(limit) {
|
|
464
|
+
this.options.maxFiles = limit;
|
|
465
|
+
return this;
|
|
466
|
+
}
|
|
467
|
+
withFullPaths() {
|
|
468
|
+
this.options.resolvePaths = true;
|
|
469
|
+
this.options.includeBasePath = true;
|
|
470
|
+
return this;
|
|
471
|
+
}
|
|
472
|
+
withErrors() {
|
|
473
|
+
this.options.suppressErrors = false;
|
|
474
|
+
return this;
|
|
475
|
+
}
|
|
476
|
+
withSymlinks({ resolvePaths = true } = {}) {
|
|
477
|
+
this.options.resolveSymlinks = true;
|
|
478
|
+
this.options.useRealPaths = resolvePaths;
|
|
479
|
+
return this.withFullPaths();
|
|
480
|
+
}
|
|
481
|
+
withAbortSignal(signal) {
|
|
482
|
+
this.options.signal = signal;
|
|
483
|
+
return this;
|
|
484
|
+
}
|
|
485
|
+
normalize() {
|
|
486
|
+
this.options.normalizePath = true;
|
|
487
|
+
return this;
|
|
488
|
+
}
|
|
489
|
+
filter(predicate) {
|
|
490
|
+
this.options.filters.push(predicate);
|
|
491
|
+
return this;
|
|
492
|
+
}
|
|
493
|
+
onlyDirs() {
|
|
494
|
+
this.options.excludeFiles = true;
|
|
495
|
+
this.options.includeDirs = true;
|
|
496
|
+
return this;
|
|
497
|
+
}
|
|
498
|
+
exclude(predicate) {
|
|
499
|
+
this.options.exclude = predicate;
|
|
500
|
+
return this;
|
|
501
|
+
}
|
|
502
|
+
onlyCounts() {
|
|
503
|
+
this.options.onlyCounts = true;
|
|
504
|
+
return this;
|
|
505
|
+
}
|
|
506
|
+
crawl(root) {
|
|
507
|
+
return new APIBuilder(root || ".", this.options);
|
|
508
|
+
}
|
|
509
|
+
withGlobFunction(fn) {
|
|
510
|
+
this.globFunction = fn;
|
|
511
|
+
return this;
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* @deprecated Pass options using the constructor instead:
|
|
515
|
+
* ```ts
|
|
516
|
+
* new fdir(options).crawl("/path/to/root");
|
|
517
|
+
* ```
|
|
518
|
+
* This method will be removed in v7.0
|
|
519
|
+
*/
|
|
520
|
+
/* c8 ignore next 4 */
|
|
521
|
+
crawlWithOptions(root, options) {
|
|
522
|
+
this.options = {
|
|
523
|
+
...this.options,
|
|
524
|
+
...options
|
|
525
|
+
};
|
|
526
|
+
return new APIBuilder(root || ".", this.options);
|
|
527
|
+
}
|
|
528
|
+
glob(...patterns) {
|
|
529
|
+
if (this.globFunction) return this.globWithOptions(patterns);
|
|
530
|
+
return this.globWithOptions(patterns, ...[{ dot: true }]);
|
|
531
|
+
}
|
|
532
|
+
globWithOptions(patterns, ...options) {
|
|
533
|
+
const globFn = this.globFunction || pm;
|
|
534
|
+
/* c8 ignore next 5 */
|
|
535
|
+
if (!globFn) throw new Error("Please specify a glob function to use glob matching.");
|
|
536
|
+
var isMatch = this.globCache[patterns.join("\0")];
|
|
537
|
+
if (!isMatch) {
|
|
538
|
+
isMatch = globFn(patterns, ...options);
|
|
539
|
+
this.globCache[patterns.join("\0")] = isMatch;
|
|
540
|
+
}
|
|
541
|
+
this.options.filters.push((path) => isMatch(path));
|
|
542
|
+
return this;
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
//#endregion
|
|
547
|
+
//#region node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/lib/constants.js
|
|
548
|
+
var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
549
|
+
const WIN_SLASH = "\\\\/";
|
|
550
|
+
const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
|
|
551
|
+
/**
|
|
552
|
+
* Posix glob regex
|
|
553
|
+
*/
|
|
554
|
+
const DOT_LITERAL = "\\.";
|
|
555
|
+
const PLUS_LITERAL = "\\+";
|
|
556
|
+
const QMARK_LITERAL = "\\?";
|
|
557
|
+
const SLASH_LITERAL = "\\/";
|
|
558
|
+
const ONE_CHAR = "(?=.)";
|
|
559
|
+
const QMARK = "[^/]";
|
|
560
|
+
const END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
|
|
561
|
+
const START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
|
|
562
|
+
const DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
|
|
563
|
+
const POSIX_CHARS = {
|
|
564
|
+
DOT_LITERAL,
|
|
565
|
+
PLUS_LITERAL,
|
|
566
|
+
QMARK_LITERAL,
|
|
567
|
+
SLASH_LITERAL,
|
|
568
|
+
ONE_CHAR,
|
|
569
|
+
QMARK,
|
|
570
|
+
END_ANCHOR,
|
|
571
|
+
DOTS_SLASH,
|
|
572
|
+
NO_DOT: `(?!${DOT_LITERAL})`,
|
|
573
|
+
NO_DOTS: `(?!${START_ANCHOR}${DOTS_SLASH})`,
|
|
574
|
+
NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`,
|
|
575
|
+
NO_DOTS_SLASH: `(?!${DOTS_SLASH})`,
|
|
576
|
+
QMARK_NO_DOT: `[^.${SLASH_LITERAL}]`,
|
|
577
|
+
STAR: `${QMARK}*?`,
|
|
578
|
+
START_ANCHOR,
|
|
579
|
+
SEP: "/"
|
|
580
|
+
};
|
|
581
|
+
/**
|
|
582
|
+
* Windows glob regex
|
|
583
|
+
*/
|
|
584
|
+
const WINDOWS_CHARS = {
|
|
585
|
+
...POSIX_CHARS,
|
|
586
|
+
SLASH_LITERAL: `[${WIN_SLASH}]`,
|
|
587
|
+
QMARK: WIN_NO_SLASH,
|
|
588
|
+
STAR: `${WIN_NO_SLASH}*?`,
|
|
589
|
+
DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`,
|
|
590
|
+
NO_DOT: `(?!${DOT_LITERAL})`,
|
|
591
|
+
NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
|
592
|
+
NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`,
|
|
593
|
+
NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
|
594
|
+
QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
|
|
595
|
+
START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
|
|
596
|
+
END_ANCHOR: `(?:[${WIN_SLASH}]|$)`,
|
|
597
|
+
SEP: "\\"
|
|
598
|
+
};
|
|
599
|
+
/**
|
|
600
|
+
* POSIX Bracket Regex
|
|
601
|
+
*/
|
|
602
|
+
const POSIX_REGEX_SOURCE = {
|
|
603
|
+
alnum: "a-zA-Z0-9",
|
|
604
|
+
alpha: "a-zA-Z",
|
|
605
|
+
ascii: "\\x00-\\x7F",
|
|
606
|
+
blank: " \\t",
|
|
607
|
+
cntrl: "\\x00-\\x1F\\x7F",
|
|
608
|
+
digit: "0-9",
|
|
609
|
+
graph: "\\x21-\\x7E",
|
|
610
|
+
lower: "a-z",
|
|
611
|
+
print: "\\x20-\\x7E ",
|
|
612
|
+
punct: "\\-!\"#$%&'()\\*+,./:;<=>?@[\\]^_`{|}~",
|
|
613
|
+
space: " \\t\\r\\n\\v\\f",
|
|
614
|
+
upper: "A-Z",
|
|
615
|
+
word: "A-Za-z0-9_",
|
|
616
|
+
xdigit: "A-Fa-f0-9"
|
|
617
|
+
};
|
|
618
|
+
module.exports = {
|
|
619
|
+
MAX_LENGTH: 1024 * 64,
|
|
620
|
+
POSIX_REGEX_SOURCE,
|
|
621
|
+
REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
|
|
622
|
+
REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
|
|
623
|
+
REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
|
|
624
|
+
REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
|
|
625
|
+
REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
|
|
626
|
+
REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
|
|
627
|
+
REPLACEMENTS: {
|
|
628
|
+
__proto__: null,
|
|
629
|
+
"***": "*",
|
|
630
|
+
"**/**": "**",
|
|
631
|
+
"**/**/**": "**"
|
|
632
|
+
},
|
|
633
|
+
CHAR_0: 48,
|
|
634
|
+
CHAR_9: 57,
|
|
635
|
+
CHAR_UPPERCASE_A: 65,
|
|
636
|
+
CHAR_LOWERCASE_A: 97,
|
|
637
|
+
CHAR_UPPERCASE_Z: 90,
|
|
638
|
+
CHAR_LOWERCASE_Z: 122,
|
|
639
|
+
CHAR_LEFT_PARENTHESES: 40,
|
|
640
|
+
CHAR_RIGHT_PARENTHESES: 41,
|
|
641
|
+
CHAR_ASTERISK: 42,
|
|
642
|
+
CHAR_AMPERSAND: 38,
|
|
643
|
+
CHAR_AT: 64,
|
|
644
|
+
CHAR_BACKWARD_SLASH: 92,
|
|
645
|
+
CHAR_CARRIAGE_RETURN: 13,
|
|
646
|
+
CHAR_CIRCUMFLEX_ACCENT: 94,
|
|
647
|
+
CHAR_COLON: 58,
|
|
648
|
+
CHAR_COMMA: 44,
|
|
649
|
+
CHAR_DOT: 46,
|
|
650
|
+
CHAR_DOUBLE_QUOTE: 34,
|
|
651
|
+
CHAR_EQUAL: 61,
|
|
652
|
+
CHAR_EXCLAMATION_MARK: 33,
|
|
653
|
+
CHAR_FORM_FEED: 12,
|
|
654
|
+
CHAR_FORWARD_SLASH: 47,
|
|
655
|
+
CHAR_GRAVE_ACCENT: 96,
|
|
656
|
+
CHAR_HASH: 35,
|
|
657
|
+
CHAR_HYPHEN_MINUS: 45,
|
|
658
|
+
CHAR_LEFT_ANGLE_BRACKET: 60,
|
|
659
|
+
CHAR_LEFT_CURLY_BRACE: 123,
|
|
660
|
+
CHAR_LEFT_SQUARE_BRACKET: 91,
|
|
661
|
+
CHAR_LINE_FEED: 10,
|
|
662
|
+
CHAR_NO_BREAK_SPACE: 160,
|
|
663
|
+
CHAR_PERCENT: 37,
|
|
664
|
+
CHAR_PLUS: 43,
|
|
665
|
+
CHAR_QUESTION_MARK: 63,
|
|
666
|
+
CHAR_RIGHT_ANGLE_BRACKET: 62,
|
|
667
|
+
CHAR_RIGHT_CURLY_BRACE: 125,
|
|
668
|
+
CHAR_RIGHT_SQUARE_BRACKET: 93,
|
|
669
|
+
CHAR_SEMICOLON: 59,
|
|
670
|
+
CHAR_SINGLE_QUOTE: 39,
|
|
671
|
+
CHAR_SPACE: 32,
|
|
672
|
+
CHAR_TAB: 9,
|
|
673
|
+
CHAR_UNDERSCORE: 95,
|
|
674
|
+
CHAR_VERTICAL_LINE: 124,
|
|
675
|
+
CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279,
|
|
676
|
+
extglobChars(chars) {
|
|
677
|
+
return {
|
|
678
|
+
"!": {
|
|
679
|
+
type: "negate",
|
|
680
|
+
open: "(?:(?!(?:",
|
|
681
|
+
close: `))${chars.STAR})`
|
|
682
|
+
},
|
|
683
|
+
"?": {
|
|
684
|
+
type: "qmark",
|
|
685
|
+
open: "(?:",
|
|
686
|
+
close: ")?"
|
|
687
|
+
},
|
|
688
|
+
"+": {
|
|
689
|
+
type: "plus",
|
|
690
|
+
open: "(?:",
|
|
691
|
+
close: ")+"
|
|
692
|
+
},
|
|
693
|
+
"*": {
|
|
694
|
+
type: "star",
|
|
695
|
+
open: "(?:",
|
|
696
|
+
close: ")*"
|
|
697
|
+
},
|
|
698
|
+
"@": {
|
|
699
|
+
type: "at",
|
|
700
|
+
open: "(?:",
|
|
701
|
+
close: ")"
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
},
|
|
705
|
+
globChars(win32) {
|
|
706
|
+
return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
|
|
707
|
+
}
|
|
708
|
+
};
|
|
709
|
+
}));
|
|
710
|
+
|
|
711
|
+
//#endregion
|
|
712
|
+
//#region node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/lib/utils.js
|
|
713
|
+
var require_utils = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
714
|
+
const { REGEX_BACKSLASH, REGEX_REMOVE_BACKSLASH, REGEX_SPECIAL_CHARS, REGEX_SPECIAL_CHARS_GLOBAL } = require_constants();
|
|
715
|
+
exports.isObject = (val) => val !== null && typeof val === "object" && !Array.isArray(val);
|
|
716
|
+
exports.hasRegexChars = (str) => REGEX_SPECIAL_CHARS.test(str);
|
|
717
|
+
exports.isRegexChar = (str) => str.length === 1 && exports.hasRegexChars(str);
|
|
718
|
+
exports.escapeRegex = (str) => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, "\\$1");
|
|
719
|
+
exports.toPosixSlashes = (str) => str.replace(REGEX_BACKSLASH, "/");
|
|
720
|
+
exports.isWindows = () => {
|
|
721
|
+
if (typeof navigator !== "undefined" && navigator.platform) {
|
|
722
|
+
const platform = navigator.platform.toLowerCase();
|
|
723
|
+
return platform === "win32" || platform === "windows";
|
|
724
|
+
}
|
|
725
|
+
if (typeof process !== "undefined" && process.platform) return process.platform === "win32";
|
|
726
|
+
return false;
|
|
727
|
+
};
|
|
728
|
+
exports.removeBackslashes = (str) => {
|
|
729
|
+
return str.replace(REGEX_REMOVE_BACKSLASH, (match) => {
|
|
730
|
+
return match === "\\" ? "" : match;
|
|
731
|
+
});
|
|
732
|
+
};
|
|
733
|
+
exports.escapeLast = (input, char, lastIdx) => {
|
|
734
|
+
const idx = input.lastIndexOf(char, lastIdx);
|
|
735
|
+
if (idx === -1) return input;
|
|
736
|
+
if (input[idx - 1] === "\\") return exports.escapeLast(input, char, idx - 1);
|
|
737
|
+
return `${input.slice(0, idx)}\\${input.slice(idx)}`;
|
|
738
|
+
};
|
|
739
|
+
exports.removePrefix = (input, state = {}) => {
|
|
740
|
+
let output = input;
|
|
741
|
+
if (output.startsWith("./")) {
|
|
742
|
+
output = output.slice(2);
|
|
743
|
+
state.prefix = "./";
|
|
744
|
+
}
|
|
745
|
+
return output;
|
|
746
|
+
};
|
|
747
|
+
exports.wrapOutput = (input, state = {}, options = {}) => {
|
|
748
|
+
let output = `${options.contains ? "" : "^"}(?:${input})${options.contains ? "" : "$"}`;
|
|
749
|
+
if (state.negated === true) output = `(?:^(?!${output}).*$)`;
|
|
750
|
+
return output;
|
|
751
|
+
};
|
|
752
|
+
exports.basename = (path, { windows } = {}) => {
|
|
753
|
+
const segs = path.split(windows ? /[\\/]/ : "/");
|
|
754
|
+
const last = segs[segs.length - 1];
|
|
755
|
+
if (last === "") return segs[segs.length - 2];
|
|
756
|
+
return last;
|
|
757
|
+
};
|
|
758
|
+
}));
|
|
759
|
+
|
|
760
|
+
//#endregion
|
|
761
|
+
//#region node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/lib/scan.js
|
|
762
|
+
var require_scan = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
763
|
+
const utils = require_utils();
|
|
764
|
+
const { CHAR_ASTERISK, CHAR_AT, CHAR_BACKWARD_SLASH, CHAR_COMMA, CHAR_DOT, CHAR_EXCLAMATION_MARK, CHAR_FORWARD_SLASH, CHAR_LEFT_CURLY_BRACE, CHAR_LEFT_PARENTHESES, CHAR_LEFT_SQUARE_BRACKET, CHAR_PLUS, CHAR_QUESTION_MARK, CHAR_RIGHT_CURLY_BRACE, CHAR_RIGHT_PARENTHESES, CHAR_RIGHT_SQUARE_BRACKET } = require_constants();
|
|
765
|
+
const isPathSeparator = (code) => {
|
|
766
|
+
return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
|
|
767
|
+
};
|
|
768
|
+
const depth = (token) => {
|
|
769
|
+
if (token.isPrefix !== true) token.depth = token.isGlobstar ? Infinity : 1;
|
|
770
|
+
};
|
|
771
|
+
/**
|
|
772
|
+
* Quickly scans a glob pattern and returns an object with a handful of
|
|
773
|
+
* useful properties, like `isGlob`, `path` (the leading non-glob, if it exists),
|
|
774
|
+
* `glob` (the actual pattern), `negated` (true if the path starts with `!` but not
|
|
775
|
+
* with `!(`) and `negatedExtglob` (true if the path starts with `!(`).
|
|
776
|
+
*
|
|
777
|
+
* ```js
|
|
778
|
+
* const pm = require('picomatch');
|
|
779
|
+
* console.log(pm.scan('foo/bar/*.js'));
|
|
780
|
+
* { isGlob: true, input: 'foo/bar/*.js', base: 'foo/bar', glob: '*.js' }
|
|
781
|
+
* ```
|
|
782
|
+
* @param {String} `str`
|
|
783
|
+
* @param {Object} `options`
|
|
784
|
+
* @return {Object} Returns an object with tokens and regex source string.
|
|
785
|
+
* @api public
|
|
786
|
+
*/
|
|
787
|
+
const scan = (input, options) => {
|
|
788
|
+
const opts = options || {};
|
|
789
|
+
const length = input.length - 1;
|
|
790
|
+
const scanToEnd = opts.parts === true || opts.scanToEnd === true;
|
|
791
|
+
const slashes = [];
|
|
792
|
+
const tokens = [];
|
|
793
|
+
const parts = [];
|
|
794
|
+
let str = input;
|
|
795
|
+
let index = -1;
|
|
796
|
+
let start = 0;
|
|
797
|
+
let lastIndex = 0;
|
|
798
|
+
let isBrace = false;
|
|
799
|
+
let isBracket = false;
|
|
800
|
+
let isGlob = false;
|
|
801
|
+
let isExtglob = false;
|
|
802
|
+
let isGlobstar = false;
|
|
803
|
+
let braceEscaped = false;
|
|
804
|
+
let backslashes = false;
|
|
805
|
+
let negated = false;
|
|
806
|
+
let negatedExtglob = false;
|
|
807
|
+
let finished = false;
|
|
808
|
+
let braces = 0;
|
|
809
|
+
let prev;
|
|
810
|
+
let code;
|
|
811
|
+
let token = {
|
|
812
|
+
value: "",
|
|
813
|
+
depth: 0,
|
|
814
|
+
isGlob: false
|
|
815
|
+
};
|
|
816
|
+
const eos = () => index >= length;
|
|
817
|
+
const peek = () => str.charCodeAt(index + 1);
|
|
818
|
+
const advance = () => {
|
|
819
|
+
prev = code;
|
|
820
|
+
return str.charCodeAt(++index);
|
|
821
|
+
};
|
|
822
|
+
while (index < length) {
|
|
823
|
+
code = advance();
|
|
824
|
+
let next;
|
|
825
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
826
|
+
backslashes = token.backslashes = true;
|
|
827
|
+
code = advance();
|
|
828
|
+
if (code === CHAR_LEFT_CURLY_BRACE) braceEscaped = true;
|
|
829
|
+
continue;
|
|
830
|
+
}
|
|
831
|
+
if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE) {
|
|
832
|
+
braces++;
|
|
833
|
+
while (eos() !== true && (code = advance())) {
|
|
834
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
835
|
+
backslashes = token.backslashes = true;
|
|
836
|
+
advance();
|
|
837
|
+
continue;
|
|
838
|
+
}
|
|
839
|
+
if (code === CHAR_LEFT_CURLY_BRACE) {
|
|
840
|
+
braces++;
|
|
841
|
+
continue;
|
|
842
|
+
}
|
|
843
|
+
if (braceEscaped !== true && code === CHAR_DOT && (code = advance()) === CHAR_DOT) {
|
|
844
|
+
isBrace = token.isBrace = true;
|
|
845
|
+
isGlob = token.isGlob = true;
|
|
846
|
+
finished = true;
|
|
847
|
+
if (scanToEnd === true) continue;
|
|
848
|
+
break;
|
|
849
|
+
}
|
|
850
|
+
if (braceEscaped !== true && code === CHAR_COMMA) {
|
|
851
|
+
isBrace = token.isBrace = true;
|
|
852
|
+
isGlob = token.isGlob = true;
|
|
853
|
+
finished = true;
|
|
854
|
+
if (scanToEnd === true) continue;
|
|
855
|
+
break;
|
|
856
|
+
}
|
|
857
|
+
if (code === CHAR_RIGHT_CURLY_BRACE) {
|
|
858
|
+
braces--;
|
|
859
|
+
if (braces === 0) {
|
|
860
|
+
braceEscaped = false;
|
|
861
|
+
isBrace = token.isBrace = true;
|
|
862
|
+
finished = true;
|
|
863
|
+
break;
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
if (scanToEnd === true) continue;
|
|
868
|
+
break;
|
|
869
|
+
}
|
|
870
|
+
if (code === CHAR_FORWARD_SLASH) {
|
|
871
|
+
slashes.push(index);
|
|
872
|
+
tokens.push(token);
|
|
873
|
+
token = {
|
|
874
|
+
value: "",
|
|
875
|
+
depth: 0,
|
|
876
|
+
isGlob: false
|
|
877
|
+
};
|
|
878
|
+
if (finished === true) continue;
|
|
879
|
+
if (prev === CHAR_DOT && index === start + 1) {
|
|
880
|
+
start += 2;
|
|
881
|
+
continue;
|
|
882
|
+
}
|
|
883
|
+
lastIndex = index + 1;
|
|
884
|
+
continue;
|
|
885
|
+
}
|
|
886
|
+
if (opts.noext !== true) {
|
|
887
|
+
if ((code === CHAR_PLUS || code === CHAR_AT || code === CHAR_ASTERISK || code === CHAR_QUESTION_MARK || code === CHAR_EXCLAMATION_MARK) === true && peek() === CHAR_LEFT_PARENTHESES) {
|
|
888
|
+
isGlob = token.isGlob = true;
|
|
889
|
+
isExtglob = token.isExtglob = true;
|
|
890
|
+
finished = true;
|
|
891
|
+
if (code === CHAR_EXCLAMATION_MARK && index === start) negatedExtglob = true;
|
|
892
|
+
if (scanToEnd === true) {
|
|
893
|
+
while (eos() !== true && (code = advance())) {
|
|
894
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
895
|
+
backslashes = token.backslashes = true;
|
|
896
|
+
code = advance();
|
|
897
|
+
continue;
|
|
898
|
+
}
|
|
899
|
+
if (code === CHAR_RIGHT_PARENTHESES) {
|
|
900
|
+
isGlob = token.isGlob = true;
|
|
901
|
+
finished = true;
|
|
902
|
+
break;
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
continue;
|
|
906
|
+
}
|
|
907
|
+
break;
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
if (code === CHAR_ASTERISK) {
|
|
911
|
+
if (prev === CHAR_ASTERISK) isGlobstar = token.isGlobstar = true;
|
|
912
|
+
isGlob = token.isGlob = true;
|
|
913
|
+
finished = true;
|
|
914
|
+
if (scanToEnd === true) continue;
|
|
915
|
+
break;
|
|
916
|
+
}
|
|
917
|
+
if (code === CHAR_QUESTION_MARK) {
|
|
918
|
+
isGlob = token.isGlob = true;
|
|
919
|
+
finished = true;
|
|
920
|
+
if (scanToEnd === true) continue;
|
|
921
|
+
break;
|
|
922
|
+
}
|
|
923
|
+
if (code === CHAR_LEFT_SQUARE_BRACKET) {
|
|
924
|
+
while (eos() !== true && (next = advance())) {
|
|
925
|
+
if (next === CHAR_BACKWARD_SLASH) {
|
|
926
|
+
backslashes = token.backslashes = true;
|
|
927
|
+
advance();
|
|
928
|
+
continue;
|
|
929
|
+
}
|
|
930
|
+
if (next === CHAR_RIGHT_SQUARE_BRACKET) {
|
|
931
|
+
isBracket = token.isBracket = true;
|
|
932
|
+
isGlob = token.isGlob = true;
|
|
933
|
+
finished = true;
|
|
934
|
+
break;
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
if (scanToEnd === true) continue;
|
|
938
|
+
break;
|
|
939
|
+
}
|
|
940
|
+
if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) {
|
|
941
|
+
negated = token.negated = true;
|
|
942
|
+
start++;
|
|
943
|
+
continue;
|
|
944
|
+
}
|
|
945
|
+
if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
|
|
946
|
+
isGlob = token.isGlob = true;
|
|
947
|
+
if (scanToEnd === true) {
|
|
948
|
+
while (eos() !== true && (code = advance())) {
|
|
949
|
+
if (code === CHAR_LEFT_PARENTHESES) {
|
|
950
|
+
backslashes = token.backslashes = true;
|
|
951
|
+
code = advance();
|
|
952
|
+
continue;
|
|
953
|
+
}
|
|
954
|
+
if (code === CHAR_RIGHT_PARENTHESES) {
|
|
955
|
+
finished = true;
|
|
956
|
+
break;
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
continue;
|
|
960
|
+
}
|
|
961
|
+
break;
|
|
962
|
+
}
|
|
963
|
+
if (isGlob === true) {
|
|
964
|
+
finished = true;
|
|
965
|
+
if (scanToEnd === true) continue;
|
|
966
|
+
break;
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
if (opts.noext === true) {
|
|
970
|
+
isExtglob = false;
|
|
971
|
+
isGlob = false;
|
|
972
|
+
}
|
|
973
|
+
let base = str;
|
|
974
|
+
let prefix = "";
|
|
975
|
+
let glob = "";
|
|
976
|
+
if (start > 0) {
|
|
977
|
+
prefix = str.slice(0, start);
|
|
978
|
+
str = str.slice(start);
|
|
979
|
+
lastIndex -= start;
|
|
980
|
+
}
|
|
981
|
+
if (base && isGlob === true && lastIndex > 0) {
|
|
982
|
+
base = str.slice(0, lastIndex);
|
|
983
|
+
glob = str.slice(lastIndex);
|
|
984
|
+
} else if (isGlob === true) {
|
|
985
|
+
base = "";
|
|
986
|
+
glob = str;
|
|
987
|
+
} else base = str;
|
|
988
|
+
if (base && base !== "" && base !== "/" && base !== str) {
|
|
989
|
+
if (isPathSeparator(base.charCodeAt(base.length - 1))) base = base.slice(0, -1);
|
|
990
|
+
}
|
|
991
|
+
if (opts.unescape === true) {
|
|
992
|
+
if (glob) glob = utils.removeBackslashes(glob);
|
|
993
|
+
if (base && backslashes === true) base = utils.removeBackslashes(base);
|
|
994
|
+
}
|
|
995
|
+
const state = {
|
|
996
|
+
prefix,
|
|
997
|
+
input,
|
|
998
|
+
start,
|
|
999
|
+
base,
|
|
1000
|
+
glob,
|
|
1001
|
+
isBrace,
|
|
1002
|
+
isBracket,
|
|
1003
|
+
isGlob,
|
|
1004
|
+
isExtglob,
|
|
1005
|
+
isGlobstar,
|
|
1006
|
+
negated,
|
|
1007
|
+
negatedExtglob
|
|
1008
|
+
};
|
|
1009
|
+
if (opts.tokens === true) {
|
|
1010
|
+
state.maxDepth = 0;
|
|
1011
|
+
if (!isPathSeparator(code)) tokens.push(token);
|
|
1012
|
+
state.tokens = tokens;
|
|
1013
|
+
}
|
|
1014
|
+
if (opts.parts === true || opts.tokens === true) {
|
|
1015
|
+
let prevIndex;
|
|
1016
|
+
for (let idx = 0; idx < slashes.length; idx++) {
|
|
1017
|
+
const n = prevIndex ? prevIndex + 1 : start;
|
|
1018
|
+
const i = slashes[idx];
|
|
1019
|
+
const value = input.slice(n, i);
|
|
1020
|
+
if (opts.tokens) {
|
|
1021
|
+
if (idx === 0 && start !== 0) {
|
|
1022
|
+
tokens[idx].isPrefix = true;
|
|
1023
|
+
tokens[idx].value = prefix;
|
|
1024
|
+
} else tokens[idx].value = value;
|
|
1025
|
+
depth(tokens[idx]);
|
|
1026
|
+
state.maxDepth += tokens[idx].depth;
|
|
1027
|
+
}
|
|
1028
|
+
if (idx !== 0 || value !== "") parts.push(value);
|
|
1029
|
+
prevIndex = i;
|
|
1030
|
+
}
|
|
1031
|
+
if (prevIndex && prevIndex + 1 < input.length) {
|
|
1032
|
+
const value = input.slice(prevIndex + 1);
|
|
1033
|
+
parts.push(value);
|
|
1034
|
+
if (opts.tokens) {
|
|
1035
|
+
tokens[tokens.length - 1].value = value;
|
|
1036
|
+
depth(tokens[tokens.length - 1]);
|
|
1037
|
+
state.maxDepth += tokens[tokens.length - 1].depth;
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
state.slashes = slashes;
|
|
1041
|
+
state.parts = parts;
|
|
1042
|
+
}
|
|
1043
|
+
return state;
|
|
1044
|
+
};
|
|
1045
|
+
module.exports = scan;
|
|
1046
|
+
}));
|
|
1047
|
+
|
|
1048
|
+
//#endregion
|
|
1049
|
+
//#region node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/lib/parse.js
|
|
1050
|
+
var require_parse = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1051
|
+
const constants = require_constants();
|
|
1052
|
+
const utils = require_utils();
|
|
1053
|
+
/**
|
|
1054
|
+
* Constants
|
|
1055
|
+
*/
|
|
1056
|
+
const { MAX_LENGTH, POSIX_REGEX_SOURCE, REGEX_NON_SPECIAL_CHARS, REGEX_SPECIAL_CHARS_BACKREF, REPLACEMENTS } = constants;
|
|
1057
|
+
/**
|
|
1058
|
+
* Helpers
|
|
1059
|
+
*/
|
|
1060
|
+
const expandRange = (args, options) => {
|
|
1061
|
+
if (typeof options.expandRange === "function") return options.expandRange(...args, options);
|
|
1062
|
+
args.sort();
|
|
1063
|
+
const value = `[${args.join("-")}]`;
|
|
1064
|
+
try {
|
|
1065
|
+
new RegExp(value);
|
|
1066
|
+
} catch (ex) {
|
|
1067
|
+
return args.map((v) => utils.escapeRegex(v)).join("..");
|
|
1068
|
+
}
|
|
1069
|
+
return value;
|
|
1070
|
+
};
|
|
1071
|
+
/**
|
|
1072
|
+
* Create the message for a syntax error
|
|
1073
|
+
*/
|
|
1074
|
+
const syntaxError = (type, char) => {
|
|
1075
|
+
return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
|
|
1076
|
+
};
|
|
1077
|
+
/**
|
|
1078
|
+
* Parse the given input string.
|
|
1079
|
+
* @param {String} input
|
|
1080
|
+
* @param {Object} options
|
|
1081
|
+
* @return {Object}
|
|
1082
|
+
*/
|
|
1083
|
+
const parse = (input, options) => {
|
|
1084
|
+
if (typeof input !== "string") throw new TypeError("Expected a string");
|
|
1085
|
+
input = REPLACEMENTS[input] || input;
|
|
1086
|
+
const opts = { ...options };
|
|
1087
|
+
const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
1088
|
+
let len = input.length;
|
|
1089
|
+
if (len > max) throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
|
1090
|
+
const bos = {
|
|
1091
|
+
type: "bos",
|
|
1092
|
+
value: "",
|
|
1093
|
+
output: opts.prepend || ""
|
|
1094
|
+
};
|
|
1095
|
+
const tokens = [bos];
|
|
1096
|
+
const capture = opts.capture ? "" : "?:";
|
|
1097
|
+
const PLATFORM_CHARS = constants.globChars(opts.windows);
|
|
1098
|
+
const EXTGLOB_CHARS = constants.extglobChars(PLATFORM_CHARS);
|
|
1099
|
+
const { DOT_LITERAL, PLUS_LITERAL, SLASH_LITERAL, ONE_CHAR, DOTS_SLASH, NO_DOT, NO_DOT_SLASH, NO_DOTS_SLASH, QMARK, QMARK_NO_DOT, STAR, START_ANCHOR } = PLATFORM_CHARS;
|
|
1100
|
+
const globstar = (opts) => {
|
|
1101
|
+
return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
|
|
1102
|
+
};
|
|
1103
|
+
const nodot = opts.dot ? "" : NO_DOT;
|
|
1104
|
+
const qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT;
|
|
1105
|
+
let star = opts.bash === true ? globstar(opts) : STAR;
|
|
1106
|
+
if (opts.capture) star = `(${star})`;
|
|
1107
|
+
if (typeof opts.noext === "boolean") opts.noextglob = opts.noext;
|
|
1108
|
+
const state = {
|
|
1109
|
+
input,
|
|
1110
|
+
index: -1,
|
|
1111
|
+
start: 0,
|
|
1112
|
+
dot: opts.dot === true,
|
|
1113
|
+
consumed: "",
|
|
1114
|
+
output: "",
|
|
1115
|
+
prefix: "",
|
|
1116
|
+
backtrack: false,
|
|
1117
|
+
negated: false,
|
|
1118
|
+
brackets: 0,
|
|
1119
|
+
braces: 0,
|
|
1120
|
+
parens: 0,
|
|
1121
|
+
quotes: 0,
|
|
1122
|
+
globstar: false,
|
|
1123
|
+
tokens
|
|
1124
|
+
};
|
|
1125
|
+
input = utils.removePrefix(input, state);
|
|
1126
|
+
len = input.length;
|
|
1127
|
+
const extglobs = [];
|
|
1128
|
+
const braces = [];
|
|
1129
|
+
const stack = [];
|
|
1130
|
+
let prev = bos;
|
|
1131
|
+
let value;
|
|
1132
|
+
/**
|
|
1133
|
+
* Tokenizing helpers
|
|
1134
|
+
*/
|
|
1135
|
+
const eos = () => state.index === len - 1;
|
|
1136
|
+
const peek = state.peek = (n = 1) => input[state.index + n];
|
|
1137
|
+
const advance = state.advance = () => input[++state.index] || "";
|
|
1138
|
+
const remaining = () => input.slice(state.index + 1);
|
|
1139
|
+
const consume = (value = "", num = 0) => {
|
|
1140
|
+
state.consumed += value;
|
|
1141
|
+
state.index += num;
|
|
1142
|
+
};
|
|
1143
|
+
const append = (token) => {
|
|
1144
|
+
state.output += token.output != null ? token.output : token.value;
|
|
1145
|
+
consume(token.value);
|
|
1146
|
+
};
|
|
1147
|
+
const negate = () => {
|
|
1148
|
+
let count = 1;
|
|
1149
|
+
while (peek() === "!" && (peek(2) !== "(" || peek(3) === "?")) {
|
|
1150
|
+
advance();
|
|
1151
|
+
state.start++;
|
|
1152
|
+
count++;
|
|
1153
|
+
}
|
|
1154
|
+
if (count % 2 === 0) return false;
|
|
1155
|
+
state.negated = true;
|
|
1156
|
+
state.start++;
|
|
1157
|
+
return true;
|
|
1158
|
+
};
|
|
1159
|
+
const increment = (type) => {
|
|
1160
|
+
state[type]++;
|
|
1161
|
+
stack.push(type);
|
|
1162
|
+
};
|
|
1163
|
+
const decrement = (type) => {
|
|
1164
|
+
state[type]--;
|
|
1165
|
+
stack.pop();
|
|
1166
|
+
};
|
|
1167
|
+
/**
|
|
1168
|
+
* Push tokens onto the tokens array. This helper speeds up
|
|
1169
|
+
* tokenizing by 1) helping us avoid backtracking as much as possible,
|
|
1170
|
+
* and 2) helping us avoid creating extra tokens when consecutive
|
|
1171
|
+
* characters are plain text. This improves performance and simplifies
|
|
1172
|
+
* lookbehinds.
|
|
1173
|
+
*/
|
|
1174
|
+
const push = (tok) => {
|
|
1175
|
+
if (prev.type === "globstar") {
|
|
1176
|
+
const isBrace = state.braces > 0 && (tok.type === "comma" || tok.type === "brace");
|
|
1177
|
+
const isExtglob = tok.extglob === true || extglobs.length && (tok.type === "pipe" || tok.type === "paren");
|
|
1178
|
+
if (tok.type !== "slash" && tok.type !== "paren" && !isBrace && !isExtglob) {
|
|
1179
|
+
state.output = state.output.slice(0, -prev.output.length);
|
|
1180
|
+
prev.type = "star";
|
|
1181
|
+
prev.value = "*";
|
|
1182
|
+
prev.output = star;
|
|
1183
|
+
state.output += prev.output;
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
if (extglobs.length && tok.type !== "paren") extglobs[extglobs.length - 1].inner += tok.value;
|
|
1187
|
+
if (tok.value || tok.output) append(tok);
|
|
1188
|
+
if (prev && prev.type === "text" && tok.type === "text") {
|
|
1189
|
+
prev.output = (prev.output || prev.value) + tok.value;
|
|
1190
|
+
prev.value += tok.value;
|
|
1191
|
+
return;
|
|
1192
|
+
}
|
|
1193
|
+
tok.prev = prev;
|
|
1194
|
+
tokens.push(tok);
|
|
1195
|
+
prev = tok;
|
|
1196
|
+
};
|
|
1197
|
+
const extglobOpen = (type, value) => {
|
|
1198
|
+
const token = {
|
|
1199
|
+
...EXTGLOB_CHARS[value],
|
|
1200
|
+
conditions: 1,
|
|
1201
|
+
inner: ""
|
|
1202
|
+
};
|
|
1203
|
+
token.prev = prev;
|
|
1204
|
+
token.parens = state.parens;
|
|
1205
|
+
token.output = state.output;
|
|
1206
|
+
const output = (opts.capture ? "(" : "") + token.open;
|
|
1207
|
+
increment("parens");
|
|
1208
|
+
push({
|
|
1209
|
+
type,
|
|
1210
|
+
value,
|
|
1211
|
+
output: state.output ? "" : ONE_CHAR
|
|
1212
|
+
});
|
|
1213
|
+
push({
|
|
1214
|
+
type: "paren",
|
|
1215
|
+
extglob: true,
|
|
1216
|
+
value: advance(),
|
|
1217
|
+
output
|
|
1218
|
+
});
|
|
1219
|
+
extglobs.push(token);
|
|
1220
|
+
};
|
|
1221
|
+
const extglobClose = (token) => {
|
|
1222
|
+
let output = token.close + (opts.capture ? ")" : "");
|
|
1223
|
+
let rest;
|
|
1224
|
+
if (token.type === "negate") {
|
|
1225
|
+
let extglobStar = star;
|
|
1226
|
+
if (token.inner && token.inner.length > 1 && token.inner.includes("/")) extglobStar = globstar(opts);
|
|
1227
|
+
if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) output = token.close = `)$))${extglobStar}`;
|
|
1228
|
+
if (token.inner.includes("*") && (rest = remaining()) && /^\.[^\\/.]+$/.test(rest)) output = token.close = `)${parse(rest, {
|
|
1229
|
+
...options,
|
|
1230
|
+
fastpaths: false
|
|
1231
|
+
}).output})${extglobStar})`;
|
|
1232
|
+
if (token.prev.type === "bos") state.negatedExtglob = true;
|
|
1233
|
+
}
|
|
1234
|
+
push({
|
|
1235
|
+
type: "paren",
|
|
1236
|
+
extglob: true,
|
|
1237
|
+
value,
|
|
1238
|
+
output
|
|
1239
|
+
});
|
|
1240
|
+
decrement("parens");
|
|
1241
|
+
};
|
|
1242
|
+
/**
|
|
1243
|
+
* Fast paths
|
|
1244
|
+
*/
|
|
1245
|
+
if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) {
|
|
1246
|
+
let backslashes = false;
|
|
1247
|
+
let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
|
|
1248
|
+
if (first === "\\") {
|
|
1249
|
+
backslashes = true;
|
|
1250
|
+
return m;
|
|
1251
|
+
}
|
|
1252
|
+
if (first === "?") {
|
|
1253
|
+
if (esc) return esc + first + (rest ? QMARK.repeat(rest.length) : "");
|
|
1254
|
+
if (index === 0) return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : "");
|
|
1255
|
+
return QMARK.repeat(chars.length);
|
|
1256
|
+
}
|
|
1257
|
+
if (first === ".") return DOT_LITERAL.repeat(chars.length);
|
|
1258
|
+
if (first === "*") {
|
|
1259
|
+
if (esc) return esc + first + (rest ? star : "");
|
|
1260
|
+
return star;
|
|
1261
|
+
}
|
|
1262
|
+
return esc ? m : `\\${m}`;
|
|
1263
|
+
});
|
|
1264
|
+
if (backslashes === true) if (opts.unescape === true) output = output.replace(/\\/g, "");
|
|
1265
|
+
else output = output.replace(/\\+/g, (m) => {
|
|
1266
|
+
return m.length % 2 === 0 ? "\\\\" : m ? "\\" : "";
|
|
1267
|
+
});
|
|
1268
|
+
if (output === input && opts.contains === true) {
|
|
1269
|
+
state.output = input;
|
|
1270
|
+
return state;
|
|
1271
|
+
}
|
|
1272
|
+
state.output = utils.wrapOutput(output, state, options);
|
|
1273
|
+
return state;
|
|
1274
|
+
}
|
|
1275
|
+
/**
|
|
1276
|
+
* Tokenize input until we reach end-of-string
|
|
1277
|
+
*/
|
|
1278
|
+
while (!eos()) {
|
|
1279
|
+
value = advance();
|
|
1280
|
+
if (value === "\0") continue;
|
|
1281
|
+
/**
|
|
1282
|
+
* Escaped characters
|
|
1283
|
+
*/
|
|
1284
|
+
if (value === "\\") {
|
|
1285
|
+
const next = peek();
|
|
1286
|
+
if (next === "/" && opts.bash !== true) continue;
|
|
1287
|
+
if (next === "." || next === ";") continue;
|
|
1288
|
+
if (!next) {
|
|
1289
|
+
value += "\\";
|
|
1290
|
+
push({
|
|
1291
|
+
type: "text",
|
|
1292
|
+
value
|
|
1293
|
+
});
|
|
1294
|
+
continue;
|
|
1295
|
+
}
|
|
1296
|
+
const match = /^\\+/.exec(remaining());
|
|
1297
|
+
let slashes = 0;
|
|
1298
|
+
if (match && match[0].length > 2) {
|
|
1299
|
+
slashes = match[0].length;
|
|
1300
|
+
state.index += slashes;
|
|
1301
|
+
if (slashes % 2 !== 0) value += "\\";
|
|
1302
|
+
}
|
|
1303
|
+
if (opts.unescape === true) value = advance();
|
|
1304
|
+
else value += advance();
|
|
1305
|
+
if (state.brackets === 0) {
|
|
1306
|
+
push({
|
|
1307
|
+
type: "text",
|
|
1308
|
+
value
|
|
1309
|
+
});
|
|
1310
|
+
continue;
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
/**
|
|
1314
|
+
* If we're inside a regex character class, continue
|
|
1315
|
+
* until we reach the closing bracket.
|
|
1316
|
+
*/
|
|
1317
|
+
if (state.brackets > 0 && (value !== "]" || prev.value === "[" || prev.value === "[^")) {
|
|
1318
|
+
if (opts.posix !== false && value === ":") {
|
|
1319
|
+
const inner = prev.value.slice(1);
|
|
1320
|
+
if (inner.includes("[")) {
|
|
1321
|
+
prev.posix = true;
|
|
1322
|
+
if (inner.includes(":")) {
|
|
1323
|
+
const idx = prev.value.lastIndexOf("[");
|
|
1324
|
+
const pre = prev.value.slice(0, idx);
|
|
1325
|
+
const posix = POSIX_REGEX_SOURCE[prev.value.slice(idx + 2)];
|
|
1326
|
+
if (posix) {
|
|
1327
|
+
prev.value = pre + posix;
|
|
1328
|
+
state.backtrack = true;
|
|
1329
|
+
advance();
|
|
1330
|
+
if (!bos.output && tokens.indexOf(prev) === 1) bos.output = ONE_CHAR;
|
|
1331
|
+
continue;
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
if (value === "[" && peek() !== ":" || value === "-" && peek() === "]") value = `\\${value}`;
|
|
1337
|
+
if (value === "]" && (prev.value === "[" || prev.value === "[^")) value = `\\${value}`;
|
|
1338
|
+
if (opts.posix === true && value === "!" && prev.value === "[") value = "^";
|
|
1339
|
+
prev.value += value;
|
|
1340
|
+
append({ value });
|
|
1341
|
+
continue;
|
|
1342
|
+
}
|
|
1343
|
+
/**
|
|
1344
|
+
* If we're inside a quoted string, continue
|
|
1345
|
+
* until we reach the closing double quote.
|
|
1346
|
+
*/
|
|
1347
|
+
if (state.quotes === 1 && value !== "\"") {
|
|
1348
|
+
value = utils.escapeRegex(value);
|
|
1349
|
+
prev.value += value;
|
|
1350
|
+
append({ value });
|
|
1351
|
+
continue;
|
|
1352
|
+
}
|
|
1353
|
+
/**
|
|
1354
|
+
* Double quotes
|
|
1355
|
+
*/
|
|
1356
|
+
if (value === "\"") {
|
|
1357
|
+
state.quotes = state.quotes === 1 ? 0 : 1;
|
|
1358
|
+
if (opts.keepQuotes === true) push({
|
|
1359
|
+
type: "text",
|
|
1360
|
+
value
|
|
1361
|
+
});
|
|
1362
|
+
continue;
|
|
1363
|
+
}
|
|
1364
|
+
/**
|
|
1365
|
+
* Parentheses
|
|
1366
|
+
*/
|
|
1367
|
+
if (value === "(") {
|
|
1368
|
+
increment("parens");
|
|
1369
|
+
push({
|
|
1370
|
+
type: "paren",
|
|
1371
|
+
value
|
|
1372
|
+
});
|
|
1373
|
+
continue;
|
|
1374
|
+
}
|
|
1375
|
+
if (value === ")") {
|
|
1376
|
+
if (state.parens === 0 && opts.strictBrackets === true) throw new SyntaxError(syntaxError("opening", "("));
|
|
1377
|
+
const extglob = extglobs[extglobs.length - 1];
|
|
1378
|
+
if (extglob && state.parens === extglob.parens + 1) {
|
|
1379
|
+
extglobClose(extglobs.pop());
|
|
1380
|
+
continue;
|
|
1381
|
+
}
|
|
1382
|
+
push({
|
|
1383
|
+
type: "paren",
|
|
1384
|
+
value,
|
|
1385
|
+
output: state.parens ? ")" : "\\)"
|
|
1386
|
+
});
|
|
1387
|
+
decrement("parens");
|
|
1388
|
+
continue;
|
|
1389
|
+
}
|
|
1390
|
+
/**
|
|
1391
|
+
* Square brackets
|
|
1392
|
+
*/
|
|
1393
|
+
if (value === "[") {
|
|
1394
|
+
if (opts.nobracket === true || !remaining().includes("]")) {
|
|
1395
|
+
if (opts.nobracket !== true && opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "]"));
|
|
1396
|
+
value = `\\${value}`;
|
|
1397
|
+
} else increment("brackets");
|
|
1398
|
+
push({
|
|
1399
|
+
type: "bracket",
|
|
1400
|
+
value
|
|
1401
|
+
});
|
|
1402
|
+
continue;
|
|
1403
|
+
}
|
|
1404
|
+
if (value === "]") {
|
|
1405
|
+
if (opts.nobracket === true || prev && prev.type === "bracket" && prev.value.length === 1) {
|
|
1406
|
+
push({
|
|
1407
|
+
type: "text",
|
|
1408
|
+
value,
|
|
1409
|
+
output: `\\${value}`
|
|
1410
|
+
});
|
|
1411
|
+
continue;
|
|
1412
|
+
}
|
|
1413
|
+
if (state.brackets === 0) {
|
|
1414
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("opening", "["));
|
|
1415
|
+
push({
|
|
1416
|
+
type: "text",
|
|
1417
|
+
value,
|
|
1418
|
+
output: `\\${value}`
|
|
1419
|
+
});
|
|
1420
|
+
continue;
|
|
1421
|
+
}
|
|
1422
|
+
decrement("brackets");
|
|
1423
|
+
const prevValue = prev.value.slice(1);
|
|
1424
|
+
if (prev.posix !== true && prevValue[0] === "^" && !prevValue.includes("/")) value = `/${value}`;
|
|
1425
|
+
prev.value += value;
|
|
1426
|
+
append({ value });
|
|
1427
|
+
if (opts.literalBrackets === false || utils.hasRegexChars(prevValue)) continue;
|
|
1428
|
+
const escaped = utils.escapeRegex(prev.value);
|
|
1429
|
+
state.output = state.output.slice(0, -prev.value.length);
|
|
1430
|
+
if (opts.literalBrackets === true) {
|
|
1431
|
+
state.output += escaped;
|
|
1432
|
+
prev.value = escaped;
|
|
1433
|
+
continue;
|
|
1434
|
+
}
|
|
1435
|
+
prev.value = `(${capture}${escaped}|${prev.value})`;
|
|
1436
|
+
state.output += prev.value;
|
|
1437
|
+
continue;
|
|
1438
|
+
}
|
|
1439
|
+
/**
|
|
1440
|
+
* Braces
|
|
1441
|
+
*/
|
|
1442
|
+
if (value === "{" && opts.nobrace !== true) {
|
|
1443
|
+
increment("braces");
|
|
1444
|
+
const open = {
|
|
1445
|
+
type: "brace",
|
|
1446
|
+
value,
|
|
1447
|
+
output: "(",
|
|
1448
|
+
outputIndex: state.output.length,
|
|
1449
|
+
tokensIndex: state.tokens.length
|
|
1450
|
+
};
|
|
1451
|
+
braces.push(open);
|
|
1452
|
+
push(open);
|
|
1453
|
+
continue;
|
|
1454
|
+
}
|
|
1455
|
+
if (value === "}") {
|
|
1456
|
+
const brace = braces[braces.length - 1];
|
|
1457
|
+
if (opts.nobrace === true || !brace) {
|
|
1458
|
+
push({
|
|
1459
|
+
type: "text",
|
|
1460
|
+
value,
|
|
1461
|
+
output: value
|
|
1462
|
+
});
|
|
1463
|
+
continue;
|
|
1464
|
+
}
|
|
1465
|
+
let output = ")";
|
|
1466
|
+
if (brace.dots === true) {
|
|
1467
|
+
const arr = tokens.slice();
|
|
1468
|
+
const range = [];
|
|
1469
|
+
for (let i = arr.length - 1; i >= 0; i--) {
|
|
1470
|
+
tokens.pop();
|
|
1471
|
+
if (arr[i].type === "brace") break;
|
|
1472
|
+
if (arr[i].type !== "dots") range.unshift(arr[i].value);
|
|
1473
|
+
}
|
|
1474
|
+
output = expandRange(range, opts);
|
|
1475
|
+
state.backtrack = true;
|
|
1476
|
+
}
|
|
1477
|
+
if (brace.comma !== true && brace.dots !== true) {
|
|
1478
|
+
const out = state.output.slice(0, brace.outputIndex);
|
|
1479
|
+
const toks = state.tokens.slice(brace.tokensIndex);
|
|
1480
|
+
brace.value = brace.output = "\\{";
|
|
1481
|
+
value = output = "\\}";
|
|
1482
|
+
state.output = out;
|
|
1483
|
+
for (const t of toks) state.output += t.output || t.value;
|
|
1484
|
+
}
|
|
1485
|
+
push({
|
|
1486
|
+
type: "brace",
|
|
1487
|
+
value,
|
|
1488
|
+
output
|
|
1489
|
+
});
|
|
1490
|
+
decrement("braces");
|
|
1491
|
+
braces.pop();
|
|
1492
|
+
continue;
|
|
1493
|
+
}
|
|
1494
|
+
/**
|
|
1495
|
+
* Pipes
|
|
1496
|
+
*/
|
|
1497
|
+
if (value === "|") {
|
|
1498
|
+
if (extglobs.length > 0) extglobs[extglobs.length - 1].conditions++;
|
|
1499
|
+
push({
|
|
1500
|
+
type: "text",
|
|
1501
|
+
value
|
|
1502
|
+
});
|
|
1503
|
+
continue;
|
|
1504
|
+
}
|
|
1505
|
+
/**
|
|
1506
|
+
* Commas
|
|
1507
|
+
*/
|
|
1508
|
+
if (value === ",") {
|
|
1509
|
+
let output = value;
|
|
1510
|
+
const brace = braces[braces.length - 1];
|
|
1511
|
+
if (brace && stack[stack.length - 1] === "braces") {
|
|
1512
|
+
brace.comma = true;
|
|
1513
|
+
output = "|";
|
|
1514
|
+
}
|
|
1515
|
+
push({
|
|
1516
|
+
type: "comma",
|
|
1517
|
+
value,
|
|
1518
|
+
output
|
|
1519
|
+
});
|
|
1520
|
+
continue;
|
|
1521
|
+
}
|
|
1522
|
+
/**
|
|
1523
|
+
* Slashes
|
|
1524
|
+
*/
|
|
1525
|
+
if (value === "/") {
|
|
1526
|
+
if (prev.type === "dot" && state.index === state.start + 1) {
|
|
1527
|
+
state.start = state.index + 1;
|
|
1528
|
+
state.consumed = "";
|
|
1529
|
+
state.output = "";
|
|
1530
|
+
tokens.pop();
|
|
1531
|
+
prev = bos;
|
|
1532
|
+
continue;
|
|
1533
|
+
}
|
|
1534
|
+
push({
|
|
1535
|
+
type: "slash",
|
|
1536
|
+
value,
|
|
1537
|
+
output: SLASH_LITERAL
|
|
1538
|
+
});
|
|
1539
|
+
continue;
|
|
1540
|
+
}
|
|
1541
|
+
/**
|
|
1542
|
+
* Dots
|
|
1543
|
+
*/
|
|
1544
|
+
if (value === ".") {
|
|
1545
|
+
if (state.braces > 0 && prev.type === "dot") {
|
|
1546
|
+
if (prev.value === ".") prev.output = DOT_LITERAL;
|
|
1547
|
+
const brace = braces[braces.length - 1];
|
|
1548
|
+
prev.type = "dots";
|
|
1549
|
+
prev.output += value;
|
|
1550
|
+
prev.value += value;
|
|
1551
|
+
brace.dots = true;
|
|
1552
|
+
continue;
|
|
1553
|
+
}
|
|
1554
|
+
if (state.braces + state.parens === 0 && prev.type !== "bos" && prev.type !== "slash") {
|
|
1555
|
+
push({
|
|
1556
|
+
type: "text",
|
|
1557
|
+
value,
|
|
1558
|
+
output: DOT_LITERAL
|
|
1559
|
+
});
|
|
1560
|
+
continue;
|
|
1561
|
+
}
|
|
1562
|
+
push({
|
|
1563
|
+
type: "dot",
|
|
1564
|
+
value,
|
|
1565
|
+
output: DOT_LITERAL
|
|
1566
|
+
});
|
|
1567
|
+
continue;
|
|
1568
|
+
}
|
|
1569
|
+
/**
|
|
1570
|
+
* Question marks
|
|
1571
|
+
*/
|
|
1572
|
+
if (value === "?") {
|
|
1573
|
+
if (!(prev && prev.value === "(") && opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
1574
|
+
extglobOpen("qmark", value);
|
|
1575
|
+
continue;
|
|
1576
|
+
}
|
|
1577
|
+
if (prev && prev.type === "paren") {
|
|
1578
|
+
const next = peek();
|
|
1579
|
+
let output = value;
|
|
1580
|
+
if (prev.value === "(" && !/[!=<:]/.test(next) || next === "<" && !/<([!=]|\w+>)/.test(remaining())) output = `\\${value}`;
|
|
1581
|
+
push({
|
|
1582
|
+
type: "text",
|
|
1583
|
+
value,
|
|
1584
|
+
output
|
|
1585
|
+
});
|
|
1586
|
+
continue;
|
|
1587
|
+
}
|
|
1588
|
+
if (opts.dot !== true && (prev.type === "slash" || prev.type === "bos")) {
|
|
1589
|
+
push({
|
|
1590
|
+
type: "qmark",
|
|
1591
|
+
value,
|
|
1592
|
+
output: QMARK_NO_DOT
|
|
1593
|
+
});
|
|
1594
|
+
continue;
|
|
1595
|
+
}
|
|
1596
|
+
push({
|
|
1597
|
+
type: "qmark",
|
|
1598
|
+
value,
|
|
1599
|
+
output: QMARK
|
|
1600
|
+
});
|
|
1601
|
+
continue;
|
|
1602
|
+
}
|
|
1603
|
+
/**
|
|
1604
|
+
* Exclamation
|
|
1605
|
+
*/
|
|
1606
|
+
if (value === "!") {
|
|
1607
|
+
if (opts.noextglob !== true && peek() === "(") {
|
|
1608
|
+
if (peek(2) !== "?" || !/[!=<:]/.test(peek(3))) {
|
|
1609
|
+
extglobOpen("negate", value);
|
|
1610
|
+
continue;
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
if (opts.nonegate !== true && state.index === 0) {
|
|
1614
|
+
negate();
|
|
1615
|
+
continue;
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
/**
|
|
1619
|
+
* Plus
|
|
1620
|
+
*/
|
|
1621
|
+
if (value === "+") {
|
|
1622
|
+
if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
1623
|
+
extglobOpen("plus", value);
|
|
1624
|
+
continue;
|
|
1625
|
+
}
|
|
1626
|
+
if (prev && prev.value === "(" || opts.regex === false) {
|
|
1627
|
+
push({
|
|
1628
|
+
type: "plus",
|
|
1629
|
+
value,
|
|
1630
|
+
output: PLUS_LITERAL
|
|
1631
|
+
});
|
|
1632
|
+
continue;
|
|
1633
|
+
}
|
|
1634
|
+
if (prev && (prev.type === "bracket" || prev.type === "paren" || prev.type === "brace") || state.parens > 0) {
|
|
1635
|
+
push({
|
|
1636
|
+
type: "plus",
|
|
1637
|
+
value
|
|
1638
|
+
});
|
|
1639
|
+
continue;
|
|
1640
|
+
}
|
|
1641
|
+
push({
|
|
1642
|
+
type: "plus",
|
|
1643
|
+
value: PLUS_LITERAL
|
|
1644
|
+
});
|
|
1645
|
+
continue;
|
|
1646
|
+
}
|
|
1647
|
+
/**
|
|
1648
|
+
* Plain text
|
|
1649
|
+
*/
|
|
1650
|
+
if (value === "@") {
|
|
1651
|
+
if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
1652
|
+
push({
|
|
1653
|
+
type: "at",
|
|
1654
|
+
extglob: true,
|
|
1655
|
+
value,
|
|
1656
|
+
output: ""
|
|
1657
|
+
});
|
|
1658
|
+
continue;
|
|
1659
|
+
}
|
|
1660
|
+
push({
|
|
1661
|
+
type: "text",
|
|
1662
|
+
value
|
|
1663
|
+
});
|
|
1664
|
+
continue;
|
|
1665
|
+
}
|
|
1666
|
+
/**
|
|
1667
|
+
* Plain text
|
|
1668
|
+
*/
|
|
1669
|
+
if (value !== "*") {
|
|
1670
|
+
if (value === "$" || value === "^") value = `\\${value}`;
|
|
1671
|
+
const match = REGEX_NON_SPECIAL_CHARS.exec(remaining());
|
|
1672
|
+
if (match) {
|
|
1673
|
+
value += match[0];
|
|
1674
|
+
state.index += match[0].length;
|
|
1675
|
+
}
|
|
1676
|
+
push({
|
|
1677
|
+
type: "text",
|
|
1678
|
+
value
|
|
1679
|
+
});
|
|
1680
|
+
continue;
|
|
1681
|
+
}
|
|
1682
|
+
/**
|
|
1683
|
+
* Stars
|
|
1684
|
+
*/
|
|
1685
|
+
if (prev && (prev.type === "globstar" || prev.star === true)) {
|
|
1686
|
+
prev.type = "star";
|
|
1687
|
+
prev.star = true;
|
|
1688
|
+
prev.value += value;
|
|
1689
|
+
prev.output = star;
|
|
1690
|
+
state.backtrack = true;
|
|
1691
|
+
state.globstar = true;
|
|
1692
|
+
consume(value);
|
|
1693
|
+
continue;
|
|
1694
|
+
}
|
|
1695
|
+
let rest = remaining();
|
|
1696
|
+
if (opts.noextglob !== true && /^\([^?]/.test(rest)) {
|
|
1697
|
+
extglobOpen("star", value);
|
|
1698
|
+
continue;
|
|
1699
|
+
}
|
|
1700
|
+
if (prev.type === "star") {
|
|
1701
|
+
if (opts.noglobstar === true) {
|
|
1702
|
+
consume(value);
|
|
1703
|
+
continue;
|
|
1704
|
+
}
|
|
1705
|
+
const prior = prev.prev;
|
|
1706
|
+
const before = prior.prev;
|
|
1707
|
+
const isStart = prior.type === "slash" || prior.type === "bos";
|
|
1708
|
+
const afterStar = before && (before.type === "star" || before.type === "globstar");
|
|
1709
|
+
if (opts.bash === true && (!isStart || rest[0] && rest[0] !== "/")) {
|
|
1710
|
+
push({
|
|
1711
|
+
type: "star",
|
|
1712
|
+
value,
|
|
1713
|
+
output: ""
|
|
1714
|
+
});
|
|
1715
|
+
continue;
|
|
1716
|
+
}
|
|
1717
|
+
const isBrace = state.braces > 0 && (prior.type === "comma" || prior.type === "brace");
|
|
1718
|
+
const isExtglob = extglobs.length && (prior.type === "pipe" || prior.type === "paren");
|
|
1719
|
+
if (!isStart && prior.type !== "paren" && !isBrace && !isExtglob) {
|
|
1720
|
+
push({
|
|
1721
|
+
type: "star",
|
|
1722
|
+
value,
|
|
1723
|
+
output: ""
|
|
1724
|
+
});
|
|
1725
|
+
continue;
|
|
1726
|
+
}
|
|
1727
|
+
while (rest.slice(0, 3) === "/**") {
|
|
1728
|
+
const after = input[state.index + 4];
|
|
1729
|
+
if (after && after !== "/") break;
|
|
1730
|
+
rest = rest.slice(3);
|
|
1731
|
+
consume("/**", 3);
|
|
1732
|
+
}
|
|
1733
|
+
if (prior.type === "bos" && eos()) {
|
|
1734
|
+
prev.type = "globstar";
|
|
1735
|
+
prev.value += value;
|
|
1736
|
+
prev.output = globstar(opts);
|
|
1737
|
+
state.output = prev.output;
|
|
1738
|
+
state.globstar = true;
|
|
1739
|
+
consume(value);
|
|
1740
|
+
continue;
|
|
1741
|
+
}
|
|
1742
|
+
if (prior.type === "slash" && prior.prev.type !== "bos" && !afterStar && eos()) {
|
|
1743
|
+
state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
|
1744
|
+
prior.output = `(?:${prior.output}`;
|
|
1745
|
+
prev.type = "globstar";
|
|
1746
|
+
prev.output = globstar(opts) + (opts.strictSlashes ? ")" : "|$)");
|
|
1747
|
+
prev.value += value;
|
|
1748
|
+
state.globstar = true;
|
|
1749
|
+
state.output += prior.output + prev.output;
|
|
1750
|
+
consume(value);
|
|
1751
|
+
continue;
|
|
1752
|
+
}
|
|
1753
|
+
if (prior.type === "slash" && prior.prev.type !== "bos" && rest[0] === "/") {
|
|
1754
|
+
const end = rest[1] !== void 0 ? "|$" : "";
|
|
1755
|
+
state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
|
1756
|
+
prior.output = `(?:${prior.output}`;
|
|
1757
|
+
prev.type = "globstar";
|
|
1758
|
+
prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`;
|
|
1759
|
+
prev.value += value;
|
|
1760
|
+
state.output += prior.output + prev.output;
|
|
1761
|
+
state.globstar = true;
|
|
1762
|
+
consume(value + advance());
|
|
1763
|
+
push({
|
|
1764
|
+
type: "slash",
|
|
1765
|
+
value: "/",
|
|
1766
|
+
output: ""
|
|
1767
|
+
});
|
|
1768
|
+
continue;
|
|
1769
|
+
}
|
|
1770
|
+
if (prior.type === "bos" && rest[0] === "/") {
|
|
1771
|
+
prev.type = "globstar";
|
|
1772
|
+
prev.value += value;
|
|
1773
|
+
prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`;
|
|
1774
|
+
state.output = prev.output;
|
|
1775
|
+
state.globstar = true;
|
|
1776
|
+
consume(value + advance());
|
|
1777
|
+
push({
|
|
1778
|
+
type: "slash",
|
|
1779
|
+
value: "/",
|
|
1780
|
+
output: ""
|
|
1781
|
+
});
|
|
1782
|
+
continue;
|
|
1783
|
+
}
|
|
1784
|
+
state.output = state.output.slice(0, -prev.output.length);
|
|
1785
|
+
prev.type = "globstar";
|
|
1786
|
+
prev.output = globstar(opts);
|
|
1787
|
+
prev.value += value;
|
|
1788
|
+
state.output += prev.output;
|
|
1789
|
+
state.globstar = true;
|
|
1790
|
+
consume(value);
|
|
1791
|
+
continue;
|
|
1792
|
+
}
|
|
1793
|
+
const token = {
|
|
1794
|
+
type: "star",
|
|
1795
|
+
value,
|
|
1796
|
+
output: star
|
|
1797
|
+
};
|
|
1798
|
+
if (opts.bash === true) {
|
|
1799
|
+
token.output = ".*?";
|
|
1800
|
+
if (prev.type === "bos" || prev.type === "slash") token.output = nodot + token.output;
|
|
1801
|
+
push(token);
|
|
1802
|
+
continue;
|
|
1803
|
+
}
|
|
1804
|
+
if (prev && (prev.type === "bracket" || prev.type === "paren") && opts.regex === true) {
|
|
1805
|
+
token.output = value;
|
|
1806
|
+
push(token);
|
|
1807
|
+
continue;
|
|
1808
|
+
}
|
|
1809
|
+
if (state.index === state.start || prev.type === "slash" || prev.type === "dot") {
|
|
1810
|
+
if (prev.type === "dot") {
|
|
1811
|
+
state.output += NO_DOT_SLASH;
|
|
1812
|
+
prev.output += NO_DOT_SLASH;
|
|
1813
|
+
} else if (opts.dot === true) {
|
|
1814
|
+
state.output += NO_DOTS_SLASH;
|
|
1815
|
+
prev.output += NO_DOTS_SLASH;
|
|
1816
|
+
} else {
|
|
1817
|
+
state.output += nodot;
|
|
1818
|
+
prev.output += nodot;
|
|
1819
|
+
}
|
|
1820
|
+
if (peek() !== "*") {
|
|
1821
|
+
state.output += ONE_CHAR;
|
|
1822
|
+
prev.output += ONE_CHAR;
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
push(token);
|
|
1826
|
+
}
|
|
1827
|
+
while (state.brackets > 0) {
|
|
1828
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "]"));
|
|
1829
|
+
state.output = utils.escapeLast(state.output, "[");
|
|
1830
|
+
decrement("brackets");
|
|
1831
|
+
}
|
|
1832
|
+
while (state.parens > 0) {
|
|
1833
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", ")"));
|
|
1834
|
+
state.output = utils.escapeLast(state.output, "(");
|
|
1835
|
+
decrement("parens");
|
|
1836
|
+
}
|
|
1837
|
+
while (state.braces > 0) {
|
|
1838
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "}"));
|
|
1839
|
+
state.output = utils.escapeLast(state.output, "{");
|
|
1840
|
+
decrement("braces");
|
|
1841
|
+
}
|
|
1842
|
+
if (opts.strictSlashes !== true && (prev.type === "star" || prev.type === "bracket")) push({
|
|
1843
|
+
type: "maybe_slash",
|
|
1844
|
+
value: "",
|
|
1845
|
+
output: `${SLASH_LITERAL}?`
|
|
1846
|
+
});
|
|
1847
|
+
if (state.backtrack === true) {
|
|
1848
|
+
state.output = "";
|
|
1849
|
+
for (const token of state.tokens) {
|
|
1850
|
+
state.output += token.output != null ? token.output : token.value;
|
|
1851
|
+
if (token.suffix) state.output += token.suffix;
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
return state;
|
|
1855
|
+
};
|
|
1856
|
+
/**
|
|
1857
|
+
* Fast paths for creating regular expressions for common glob patterns.
|
|
1858
|
+
* This can significantly speed up processing and has very little downside
|
|
1859
|
+
* impact when none of the fast paths match.
|
|
1860
|
+
*/
|
|
1861
|
+
parse.fastpaths = (input, options) => {
|
|
1862
|
+
const opts = { ...options };
|
|
1863
|
+
const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
1864
|
+
const len = input.length;
|
|
1865
|
+
if (len > max) throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
|
1866
|
+
input = REPLACEMENTS[input] || input;
|
|
1867
|
+
const { DOT_LITERAL, SLASH_LITERAL, ONE_CHAR, DOTS_SLASH, NO_DOT, NO_DOTS, NO_DOTS_SLASH, STAR, START_ANCHOR } = constants.globChars(opts.windows);
|
|
1868
|
+
const nodot = opts.dot ? NO_DOTS : NO_DOT;
|
|
1869
|
+
const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
|
|
1870
|
+
const capture = opts.capture ? "" : "?:";
|
|
1871
|
+
const state = {
|
|
1872
|
+
negated: false,
|
|
1873
|
+
prefix: ""
|
|
1874
|
+
};
|
|
1875
|
+
let star = opts.bash === true ? ".*?" : STAR;
|
|
1876
|
+
if (opts.capture) star = `(${star})`;
|
|
1877
|
+
const globstar = (opts) => {
|
|
1878
|
+
if (opts.noglobstar === true) return star;
|
|
1879
|
+
return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
|
|
1880
|
+
};
|
|
1881
|
+
const create = (str) => {
|
|
1882
|
+
switch (str) {
|
|
1883
|
+
case "*": return `${nodot}${ONE_CHAR}${star}`;
|
|
1884
|
+
case ".*": return `${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
1885
|
+
case "*.*": return `${nodot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
1886
|
+
case "*/*": return `${nodot}${star}${SLASH_LITERAL}${ONE_CHAR}${slashDot}${star}`;
|
|
1887
|
+
case "**": return nodot + globstar(opts);
|
|
1888
|
+
case "**/*": return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${ONE_CHAR}${star}`;
|
|
1889
|
+
case "**/*.*": return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
1890
|
+
case "**/.*": return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
1891
|
+
default: {
|
|
1892
|
+
const match = /^(.*?)\.(\w+)$/.exec(str);
|
|
1893
|
+
if (!match) return;
|
|
1894
|
+
const source = create(match[1]);
|
|
1895
|
+
if (!source) return;
|
|
1896
|
+
return source + DOT_LITERAL + match[2];
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
};
|
|
1900
|
+
let source = create(utils.removePrefix(input, state));
|
|
1901
|
+
if (source && opts.strictSlashes !== true) source += `${SLASH_LITERAL}?`;
|
|
1902
|
+
return source;
|
|
1903
|
+
};
|
|
1904
|
+
module.exports = parse;
|
|
1905
|
+
}));
|
|
1906
|
+
|
|
1907
|
+
//#endregion
|
|
1908
|
+
//#region node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/lib/picomatch.js
|
|
1909
|
+
var require_picomatch$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1910
|
+
const scan = require_scan();
|
|
1911
|
+
const parse = require_parse();
|
|
1912
|
+
const utils = require_utils();
|
|
1913
|
+
const constants = require_constants();
|
|
1914
|
+
const isObject = (val) => val && typeof val === "object" && !Array.isArray(val);
|
|
1915
|
+
/**
|
|
1916
|
+
* Creates a matcher function from one or more glob patterns. The
|
|
1917
|
+
* returned function takes a string to match as its first argument,
|
|
1918
|
+
* and returns true if the string is a match. The returned matcher
|
|
1919
|
+
* function also takes a boolean as the second argument that, when true,
|
|
1920
|
+
* returns an object with additional information.
|
|
1921
|
+
*
|
|
1922
|
+
* ```js
|
|
1923
|
+
* const picomatch = require('picomatch');
|
|
1924
|
+
* // picomatch(glob[, options]);
|
|
1925
|
+
*
|
|
1926
|
+
* const isMatch = picomatch('*.!(*a)');
|
|
1927
|
+
* console.log(isMatch('a.a')); //=> false
|
|
1928
|
+
* console.log(isMatch('a.b')); //=> true
|
|
1929
|
+
* ```
|
|
1930
|
+
* @name picomatch
|
|
1931
|
+
* @param {String|Array} `globs` One or more glob patterns.
|
|
1932
|
+
* @param {Object=} `options`
|
|
1933
|
+
* @return {Function=} Returns a matcher function.
|
|
1934
|
+
* @api public
|
|
1935
|
+
*/
|
|
1936
|
+
const picomatch = (glob, options, returnState = false) => {
|
|
1937
|
+
if (Array.isArray(glob)) {
|
|
1938
|
+
const fns = glob.map((input) => picomatch(input, options, returnState));
|
|
1939
|
+
const arrayMatcher = (str) => {
|
|
1940
|
+
for (const isMatch of fns) {
|
|
1941
|
+
const state = isMatch(str);
|
|
1942
|
+
if (state) return state;
|
|
1943
|
+
}
|
|
1944
|
+
return false;
|
|
1945
|
+
};
|
|
1946
|
+
return arrayMatcher;
|
|
1947
|
+
}
|
|
1948
|
+
const isState = isObject(glob) && glob.tokens && glob.input;
|
|
1949
|
+
if (glob === "" || typeof glob !== "string" && !isState) throw new TypeError("Expected pattern to be a non-empty string");
|
|
1950
|
+
const opts = options || {};
|
|
1951
|
+
const posix = opts.windows;
|
|
1952
|
+
const regex = isState ? picomatch.compileRe(glob, options) : picomatch.makeRe(glob, options, false, true);
|
|
1953
|
+
const state = regex.state;
|
|
1954
|
+
delete regex.state;
|
|
1955
|
+
let isIgnored = () => false;
|
|
1956
|
+
if (opts.ignore) {
|
|
1957
|
+
const ignoreOpts = {
|
|
1958
|
+
...options,
|
|
1959
|
+
ignore: null,
|
|
1960
|
+
onMatch: null,
|
|
1961
|
+
onResult: null
|
|
1962
|
+
};
|
|
1963
|
+
isIgnored = picomatch(opts.ignore, ignoreOpts, returnState);
|
|
1964
|
+
}
|
|
1965
|
+
const matcher = (input, returnObject = false) => {
|
|
1966
|
+
const { isMatch, match, output } = picomatch.test(input, regex, options, {
|
|
1967
|
+
glob,
|
|
1968
|
+
posix
|
|
1969
|
+
});
|
|
1970
|
+
const result = {
|
|
1971
|
+
glob,
|
|
1972
|
+
state,
|
|
1973
|
+
regex,
|
|
1974
|
+
posix,
|
|
1975
|
+
input,
|
|
1976
|
+
output,
|
|
1977
|
+
match,
|
|
1978
|
+
isMatch
|
|
1979
|
+
};
|
|
1980
|
+
if (typeof opts.onResult === "function") opts.onResult(result);
|
|
1981
|
+
if (isMatch === false) {
|
|
1982
|
+
result.isMatch = false;
|
|
1983
|
+
return returnObject ? result : false;
|
|
1984
|
+
}
|
|
1985
|
+
if (isIgnored(input)) {
|
|
1986
|
+
if (typeof opts.onIgnore === "function") opts.onIgnore(result);
|
|
1987
|
+
result.isMatch = false;
|
|
1988
|
+
return returnObject ? result : false;
|
|
1989
|
+
}
|
|
1990
|
+
if (typeof opts.onMatch === "function") opts.onMatch(result);
|
|
1991
|
+
return returnObject ? result : true;
|
|
1992
|
+
};
|
|
1993
|
+
if (returnState) matcher.state = state;
|
|
1994
|
+
return matcher;
|
|
1995
|
+
};
|
|
1996
|
+
/**
|
|
1997
|
+
* Test `input` with the given `regex`. This is used by the main
|
|
1998
|
+
* `picomatch()` function to test the input string.
|
|
1999
|
+
*
|
|
2000
|
+
* ```js
|
|
2001
|
+
* const picomatch = require('picomatch');
|
|
2002
|
+
* // picomatch.test(input, regex[, options]);
|
|
2003
|
+
*
|
|
2004
|
+
* console.log(picomatch.test('foo/bar', /^(?:([^/]*?)\/([^/]*?))$/));
|
|
2005
|
+
* // { isMatch: true, match: [ 'foo/', 'foo', 'bar' ], output: 'foo/bar' }
|
|
2006
|
+
* ```
|
|
2007
|
+
* @param {String} `input` String to test.
|
|
2008
|
+
* @param {RegExp} `regex`
|
|
2009
|
+
* @return {Object} Returns an object with matching info.
|
|
2010
|
+
* @api public
|
|
2011
|
+
*/
|
|
2012
|
+
picomatch.test = (input, regex, options, { glob, posix } = {}) => {
|
|
2013
|
+
if (typeof input !== "string") throw new TypeError("Expected input to be a string");
|
|
2014
|
+
if (input === "") return {
|
|
2015
|
+
isMatch: false,
|
|
2016
|
+
output: ""
|
|
2017
|
+
};
|
|
2018
|
+
const opts = options || {};
|
|
2019
|
+
const format = opts.format || (posix ? utils.toPosixSlashes : null);
|
|
2020
|
+
let match = input === glob;
|
|
2021
|
+
let output = match && format ? format(input) : input;
|
|
2022
|
+
if (match === false) {
|
|
2023
|
+
output = format ? format(input) : input;
|
|
2024
|
+
match = output === glob;
|
|
2025
|
+
}
|
|
2026
|
+
if (match === false || opts.capture === true) if (opts.matchBase === true || opts.basename === true) match = picomatch.matchBase(input, regex, options, posix);
|
|
2027
|
+
else match = regex.exec(output);
|
|
2028
|
+
return {
|
|
2029
|
+
isMatch: Boolean(match),
|
|
2030
|
+
match,
|
|
2031
|
+
output
|
|
2032
|
+
};
|
|
2033
|
+
};
|
|
2034
|
+
/**
|
|
2035
|
+
* Match the basename of a filepath.
|
|
2036
|
+
*
|
|
2037
|
+
* ```js
|
|
2038
|
+
* const picomatch = require('picomatch');
|
|
2039
|
+
* // picomatch.matchBase(input, glob[, options]);
|
|
2040
|
+
* console.log(picomatch.matchBase('foo/bar.js', '*.js'); // true
|
|
2041
|
+
* ```
|
|
2042
|
+
* @param {String} `input` String to test.
|
|
2043
|
+
* @param {RegExp|String} `glob` Glob pattern or regex created by [.makeRe](#makeRe).
|
|
2044
|
+
* @return {Boolean}
|
|
2045
|
+
* @api public
|
|
2046
|
+
*/
|
|
2047
|
+
picomatch.matchBase = (input, glob, options) => {
|
|
2048
|
+
return (glob instanceof RegExp ? glob : picomatch.makeRe(glob, options)).test(utils.basename(input));
|
|
2049
|
+
};
|
|
2050
|
+
/**
|
|
2051
|
+
* Returns true if **any** of the given glob `patterns` match the specified `string`.
|
|
2052
|
+
*
|
|
2053
|
+
* ```js
|
|
2054
|
+
* const picomatch = require('picomatch');
|
|
2055
|
+
* // picomatch.isMatch(string, patterns[, options]);
|
|
2056
|
+
*
|
|
2057
|
+
* console.log(picomatch.isMatch('a.a', ['b.*', '*.a'])); //=> true
|
|
2058
|
+
* console.log(picomatch.isMatch('a.a', 'b.*')); //=> false
|
|
2059
|
+
* ```
|
|
2060
|
+
* @param {String|Array} str The string to test.
|
|
2061
|
+
* @param {String|Array} patterns One or more glob patterns to use for matching.
|
|
2062
|
+
* @param {Object} [options] See available [options](#options).
|
|
2063
|
+
* @return {Boolean} Returns true if any patterns match `str`
|
|
2064
|
+
* @api public
|
|
2065
|
+
*/
|
|
2066
|
+
picomatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str);
|
|
2067
|
+
/**
|
|
2068
|
+
* Parse a glob pattern to create the source string for a regular
|
|
2069
|
+
* expression.
|
|
2070
|
+
*
|
|
2071
|
+
* ```js
|
|
2072
|
+
* const picomatch = require('picomatch');
|
|
2073
|
+
* const result = picomatch.parse(pattern[, options]);
|
|
2074
|
+
* ```
|
|
2075
|
+
* @param {String} `pattern`
|
|
2076
|
+
* @param {Object} `options`
|
|
2077
|
+
* @return {Object} Returns an object with useful properties and output to be used as a regex source string.
|
|
2078
|
+
* @api public
|
|
2079
|
+
*/
|
|
2080
|
+
picomatch.parse = (pattern, options) => {
|
|
2081
|
+
if (Array.isArray(pattern)) return pattern.map((p) => picomatch.parse(p, options));
|
|
2082
|
+
return parse(pattern, {
|
|
2083
|
+
...options,
|
|
2084
|
+
fastpaths: false
|
|
2085
|
+
});
|
|
2086
|
+
};
|
|
2087
|
+
/**
|
|
2088
|
+
* Scan a glob pattern to separate the pattern into segments.
|
|
2089
|
+
*
|
|
2090
|
+
* ```js
|
|
2091
|
+
* const picomatch = require('picomatch');
|
|
2092
|
+
* // picomatch.scan(input[, options]);
|
|
2093
|
+
*
|
|
2094
|
+
* const result = picomatch.scan('!./foo/*.js');
|
|
2095
|
+
* console.log(result);
|
|
2096
|
+
* { prefix: '!./',
|
|
2097
|
+
* input: '!./foo/*.js',
|
|
2098
|
+
* start: 3,
|
|
2099
|
+
* base: 'foo',
|
|
2100
|
+
* glob: '*.js',
|
|
2101
|
+
* isBrace: false,
|
|
2102
|
+
* isBracket: false,
|
|
2103
|
+
* isGlob: true,
|
|
2104
|
+
* isExtglob: false,
|
|
2105
|
+
* isGlobstar: false,
|
|
2106
|
+
* negated: true }
|
|
2107
|
+
* ```
|
|
2108
|
+
* @param {String} `input` Glob pattern to scan.
|
|
2109
|
+
* @param {Object} `options`
|
|
2110
|
+
* @return {Object} Returns an object with
|
|
2111
|
+
* @api public
|
|
2112
|
+
*/
|
|
2113
|
+
picomatch.scan = (input, options) => scan(input, options);
|
|
2114
|
+
/**
|
|
2115
|
+
* Compile a regular expression from the `state` object returned by the
|
|
2116
|
+
* [parse()](#parse) method.
|
|
2117
|
+
*
|
|
2118
|
+
* @param {Object} `state`
|
|
2119
|
+
* @param {Object} `options`
|
|
2120
|
+
* @param {Boolean} `returnOutput` Intended for implementors, this argument allows you to return the raw output from the parser.
|
|
2121
|
+
* @param {Boolean} `returnState` Adds the state to a `state` property on the returned regex. Useful for implementors and debugging.
|
|
2122
|
+
* @return {RegExp}
|
|
2123
|
+
* @api public
|
|
2124
|
+
*/
|
|
2125
|
+
picomatch.compileRe = (state, options, returnOutput = false, returnState = false) => {
|
|
2126
|
+
if (returnOutput === true) return state.output;
|
|
2127
|
+
const opts = options || {};
|
|
2128
|
+
const prepend = opts.contains ? "" : "^";
|
|
2129
|
+
const append = opts.contains ? "" : "$";
|
|
2130
|
+
let source = `${prepend}(?:${state.output})${append}`;
|
|
2131
|
+
if (state && state.negated === true) source = `^(?!${source}).*$`;
|
|
2132
|
+
const regex = picomatch.toRegex(source, options);
|
|
2133
|
+
if (returnState === true) regex.state = state;
|
|
2134
|
+
return regex;
|
|
2135
|
+
};
|
|
2136
|
+
/**
|
|
2137
|
+
* Create a regular expression from a parsed glob pattern.
|
|
2138
|
+
*
|
|
2139
|
+
* ```js
|
|
2140
|
+
* const picomatch = require('picomatch');
|
|
2141
|
+
* const state = picomatch.parse('*.js');
|
|
2142
|
+
* // picomatch.compileRe(state[, options]);
|
|
2143
|
+
*
|
|
2144
|
+
* console.log(picomatch.compileRe(state));
|
|
2145
|
+
* //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
|
|
2146
|
+
* ```
|
|
2147
|
+
* @param {String} `state` The object returned from the `.parse` method.
|
|
2148
|
+
* @param {Object} `options`
|
|
2149
|
+
* @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.
|
|
2150
|
+
* @param {Boolean} `returnState` Implementors may use this argument to return the state from the parsed glob with the returned regular expression.
|
|
2151
|
+
* @return {RegExp} Returns a regex created from the given pattern.
|
|
2152
|
+
* @api public
|
|
2153
|
+
*/
|
|
2154
|
+
picomatch.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
|
|
2155
|
+
if (!input || typeof input !== "string") throw new TypeError("Expected a non-empty string");
|
|
2156
|
+
let parsed = {
|
|
2157
|
+
negated: false,
|
|
2158
|
+
fastpaths: true
|
|
2159
|
+
};
|
|
2160
|
+
if (options.fastpaths !== false && (input[0] === "." || input[0] === "*")) parsed.output = parse.fastpaths(input, options);
|
|
2161
|
+
if (!parsed.output) parsed = parse(input, options);
|
|
2162
|
+
return picomatch.compileRe(parsed, options, returnOutput, returnState);
|
|
2163
|
+
};
|
|
2164
|
+
/**
|
|
2165
|
+
* Create a regular expression from the given regex source string.
|
|
2166
|
+
*
|
|
2167
|
+
* ```js
|
|
2168
|
+
* const picomatch = require('picomatch');
|
|
2169
|
+
* // picomatch.toRegex(source[, options]);
|
|
2170
|
+
*
|
|
2171
|
+
* const { output } = picomatch.parse('*.js');
|
|
2172
|
+
* console.log(picomatch.toRegex(output));
|
|
2173
|
+
* //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
|
|
2174
|
+
* ```
|
|
2175
|
+
* @param {String} `source` Regular expression source string.
|
|
2176
|
+
* @param {Object} `options`
|
|
2177
|
+
* @return {RegExp}
|
|
2178
|
+
* @api public
|
|
2179
|
+
*/
|
|
2180
|
+
picomatch.toRegex = (source, options) => {
|
|
2181
|
+
try {
|
|
2182
|
+
const opts = options || {};
|
|
2183
|
+
return new RegExp(source, opts.flags || (opts.nocase ? "i" : ""));
|
|
2184
|
+
} catch (err) {
|
|
2185
|
+
if (options && options.debug === true) throw err;
|
|
2186
|
+
return /$^/;
|
|
2187
|
+
}
|
|
2188
|
+
};
|
|
2189
|
+
/**
|
|
2190
|
+
* Picomatch constants.
|
|
2191
|
+
* @return {Object}
|
|
2192
|
+
*/
|
|
2193
|
+
picomatch.constants = constants;
|
|
2194
|
+
/**
|
|
2195
|
+
* Expose "picomatch"
|
|
2196
|
+
*/
|
|
2197
|
+
module.exports = picomatch;
|
|
2198
|
+
}));
|
|
2199
|
+
|
|
2200
|
+
//#endregion
|
|
2201
|
+
//#region node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/index.js
|
|
2202
|
+
var require_picomatch = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2203
|
+
const pico = require_picomatch$1();
|
|
2204
|
+
const utils = require_utils();
|
|
2205
|
+
function picomatch(glob, options, returnState = false) {
|
|
2206
|
+
if (options && (options.windows === null || options.windows === void 0)) options = {
|
|
2207
|
+
...options,
|
|
2208
|
+
windows: utils.isWindows()
|
|
2209
|
+
};
|
|
2210
|
+
return pico(glob, options, returnState);
|
|
2211
|
+
}
|
|
2212
|
+
Object.assign(picomatch, pico);
|
|
2213
|
+
module.exports = picomatch;
|
|
2214
|
+
}));
|
|
2215
|
+
|
|
2216
|
+
//#endregion
|
|
2217
|
+
//#region node_modules/.pnpm/tinyglobby@0.2.15/node_modules/tinyglobby/dist/index.mjs
|
|
2218
|
+
var import_picomatch = /* @__PURE__ */ __toESM(require_picomatch(), 1);
|
|
2219
|
+
const isReadonlyArray = Array.isArray;
|
|
2220
|
+
const isWin = process.platform === "win32";
|
|
2221
|
+
const ONLY_PARENT_DIRECTORIES = /^(\/?\.\.)+$/;
|
|
2222
|
+
function getPartialMatcher(patterns, options = {}) {
|
|
2223
|
+
const patternsCount = patterns.length;
|
|
2224
|
+
const patternsParts = Array(patternsCount);
|
|
2225
|
+
const matchers = Array(patternsCount);
|
|
2226
|
+
const globstarEnabled = !options.noglobstar;
|
|
2227
|
+
for (let i = 0; i < patternsCount; i++) {
|
|
2228
|
+
const parts = splitPattern(patterns[i]);
|
|
2229
|
+
patternsParts[i] = parts;
|
|
2230
|
+
const partsCount = parts.length;
|
|
2231
|
+
const partMatchers = Array(partsCount);
|
|
2232
|
+
for (let j = 0; j < partsCount; j++) partMatchers[j] = (0, import_picomatch.default)(parts[j], options);
|
|
2233
|
+
matchers[i] = partMatchers;
|
|
2234
|
+
}
|
|
2235
|
+
return (input) => {
|
|
2236
|
+
const inputParts = input.split("/");
|
|
2237
|
+
if (inputParts[0] === ".." && ONLY_PARENT_DIRECTORIES.test(input)) return true;
|
|
2238
|
+
for (let i = 0; i < patterns.length; i++) {
|
|
2239
|
+
const patternParts = patternsParts[i];
|
|
2240
|
+
const matcher = matchers[i];
|
|
2241
|
+
const inputPatternCount = inputParts.length;
|
|
2242
|
+
const minParts = Math.min(inputPatternCount, patternParts.length);
|
|
2243
|
+
let j = 0;
|
|
2244
|
+
while (j < minParts) {
|
|
2245
|
+
const part = patternParts[j];
|
|
2246
|
+
if (part.includes("/")) return true;
|
|
2247
|
+
if (!matcher[j](inputParts[j])) break;
|
|
2248
|
+
if (globstarEnabled && part === "**") return true;
|
|
2249
|
+
j++;
|
|
2250
|
+
}
|
|
2251
|
+
if (j === inputPatternCount) return true;
|
|
2252
|
+
}
|
|
2253
|
+
return false;
|
|
2254
|
+
};
|
|
2255
|
+
}
|
|
2256
|
+
/* node:coverage ignore next 2 */
|
|
2257
|
+
const WIN32_ROOT_DIR = /^[A-Z]:\/$/i;
|
|
2258
|
+
const isRoot = isWin ? (p) => WIN32_ROOT_DIR.test(p) : (p) => p === "/";
|
|
2259
|
+
function buildFormat(cwd, root, absolute) {
|
|
2260
|
+
if (cwd === root || root.startsWith(`${cwd}/`)) {
|
|
2261
|
+
if (absolute) {
|
|
2262
|
+
const start = isRoot(cwd) ? cwd.length : cwd.length + 1;
|
|
2263
|
+
return (p, isDir) => p.slice(start, isDir ? -1 : void 0) || ".";
|
|
2264
|
+
}
|
|
2265
|
+
const prefix = root.slice(cwd.length + 1);
|
|
2266
|
+
if (prefix) return (p, isDir) => {
|
|
2267
|
+
if (p === ".") return prefix;
|
|
2268
|
+
const result = `${prefix}/${p}`;
|
|
2269
|
+
return isDir ? result.slice(0, -1) : result;
|
|
2270
|
+
};
|
|
2271
|
+
return (p, isDir) => isDir && p !== "." ? p.slice(0, -1) : p;
|
|
2272
|
+
}
|
|
2273
|
+
if (absolute) return (p) => posix.relative(cwd, p) || ".";
|
|
2274
|
+
return (p) => posix.relative(cwd, `${root}/${p}`) || ".";
|
|
2275
|
+
}
|
|
2276
|
+
function buildRelative(cwd, root) {
|
|
2277
|
+
if (root.startsWith(`${cwd}/`)) {
|
|
2278
|
+
const prefix = root.slice(cwd.length + 1);
|
|
2279
|
+
return (p) => `${prefix}/${p}`;
|
|
2280
|
+
}
|
|
2281
|
+
return (p) => {
|
|
2282
|
+
const result = posix.relative(cwd, `${root}/${p}`);
|
|
2283
|
+
if (p.endsWith("/") && result !== "") return `${result}/`;
|
|
2284
|
+
return result || ".";
|
|
2285
|
+
};
|
|
2286
|
+
}
|
|
2287
|
+
const splitPatternOptions = { parts: true };
|
|
2288
|
+
function splitPattern(path$1) {
|
|
2289
|
+
var _result$parts;
|
|
2290
|
+
const result = import_picomatch.default.scan(path$1, splitPatternOptions);
|
|
2291
|
+
return ((_result$parts = result.parts) === null || _result$parts === void 0 ? void 0 : _result$parts.length) ? result.parts : [path$1];
|
|
2292
|
+
}
|
|
2293
|
+
const POSIX_UNESCAPED_GLOB_SYMBOLS = /(?<!\\)([()[\]{}*?|]|^!|[!+@](?=\()|\\(?![()[\]{}!*+?@|]))/g;
|
|
2294
|
+
const WIN32_UNESCAPED_GLOB_SYMBOLS = /(?<!\\)([()[\]{}]|^!|[!+@](?=\())/g;
|
|
2295
|
+
const escapePosixPath = (path$1) => path$1.replace(POSIX_UNESCAPED_GLOB_SYMBOLS, "\\$&");
|
|
2296
|
+
const escapeWin32Path = (path$1) => path$1.replace(WIN32_UNESCAPED_GLOB_SYMBOLS, "\\$&");
|
|
2297
|
+
/**
|
|
2298
|
+
* Escapes a path's special characters depending on the platform.
|
|
2299
|
+
* @see {@link https://superchupu.dev/tinyglobby/documentation#escapePath}
|
|
2300
|
+
*/
|
|
2301
|
+
/* node:coverage ignore next */
|
|
2302
|
+
const escapePath = isWin ? escapeWin32Path : escapePosixPath;
|
|
2303
|
+
/**
|
|
2304
|
+
* Checks if a pattern has dynamic parts.
|
|
2305
|
+
*
|
|
2306
|
+
* Has a few minor differences with [`fast-glob`](https://github.com/mrmlnc/fast-glob) for better accuracy:
|
|
2307
|
+
*
|
|
2308
|
+
* - Doesn't necessarily return `false` on patterns that include `\`.
|
|
2309
|
+
* - Returns `true` if the pattern includes parentheses, regardless of them representing one single pattern or not.
|
|
2310
|
+
* - Returns `true` for unfinished glob extensions i.e. `(h`, `+(h`.
|
|
2311
|
+
* - Returns `true` for unfinished brace expansions as long as they include `,` or `..`.
|
|
2312
|
+
*
|
|
2313
|
+
* @see {@link https://superchupu.dev/tinyglobby/documentation#isDynamicPattern}
|
|
2314
|
+
*/
|
|
2315
|
+
function isDynamicPattern(pattern, options) {
|
|
2316
|
+
if ((options === null || options === void 0 ? void 0 : options.caseSensitiveMatch) === false) return true;
|
|
2317
|
+
const scan = import_picomatch.default.scan(pattern);
|
|
2318
|
+
return scan.isGlob || scan.negated;
|
|
2319
|
+
}
|
|
2320
|
+
function log$1(...tasks) {
|
|
2321
|
+
console.log(`[tinyglobby ${(/* @__PURE__ */ new Date()).toLocaleTimeString("es")}]`, ...tasks);
|
|
2322
|
+
}
|
|
2323
|
+
const PARENT_DIRECTORY = /^(\/?\.\.)+/;
|
|
2324
|
+
const ESCAPING_BACKSLASHES = /\\(?=[()[\]{}!*+?@|])/g;
|
|
2325
|
+
const BACKSLASHES = /\\/g;
|
|
2326
|
+
function normalizePattern(pattern, expandDirectories, cwd, props, isIgnore) {
|
|
2327
|
+
let result = pattern;
|
|
2328
|
+
if (pattern.endsWith("/")) result = pattern.slice(0, -1);
|
|
2329
|
+
if (!result.endsWith("*") && expandDirectories) result += "/**";
|
|
2330
|
+
const escapedCwd = escapePath(cwd);
|
|
2331
|
+
if (path.isAbsolute(result.replace(ESCAPING_BACKSLASHES, ""))) result = posix.relative(escapedCwd, result);
|
|
2332
|
+
else result = posix.normalize(result);
|
|
2333
|
+
const parentDirectoryMatch = PARENT_DIRECTORY.exec(result);
|
|
2334
|
+
const parts = splitPattern(result);
|
|
2335
|
+
if (parentDirectoryMatch === null || parentDirectoryMatch === void 0 ? void 0 : parentDirectoryMatch[0]) {
|
|
2336
|
+
const n = (parentDirectoryMatch[0].length + 1) / 3;
|
|
2337
|
+
let i = 0;
|
|
2338
|
+
const cwdParts = escapedCwd.split("/");
|
|
2339
|
+
while (i < n && parts[i + n] === cwdParts[cwdParts.length + i - n]) {
|
|
2340
|
+
result = result.slice(0, (n - i - 1) * 3) + result.slice((n - i) * 3 + parts[i + n].length + 1) || ".";
|
|
2341
|
+
i++;
|
|
2342
|
+
}
|
|
2343
|
+
const potentialRoot = posix.join(cwd, parentDirectoryMatch[0].slice(i * 3));
|
|
2344
|
+
if (!potentialRoot.startsWith(".") && props.root.length > potentialRoot.length) {
|
|
2345
|
+
props.root = potentialRoot;
|
|
2346
|
+
props.depthOffset = -n + i;
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2349
|
+
if (!isIgnore && props.depthOffset >= 0) {
|
|
2350
|
+
var _props$commonPath;
|
|
2351
|
+
(_props$commonPath = props.commonPath) !== null && _props$commonPath !== void 0 || (props.commonPath = parts);
|
|
2352
|
+
const newCommonPath = [];
|
|
2353
|
+
const length = Math.min(props.commonPath.length, parts.length);
|
|
2354
|
+
for (let i = 0; i < length; i++) {
|
|
2355
|
+
const part = parts[i];
|
|
2356
|
+
if (part === "**" && !parts[i + 1]) {
|
|
2357
|
+
newCommonPath.pop();
|
|
2358
|
+
break;
|
|
2359
|
+
}
|
|
2360
|
+
if (part !== props.commonPath[i] || isDynamicPattern(part) || i === parts.length - 1) break;
|
|
2361
|
+
newCommonPath.push(part);
|
|
2362
|
+
}
|
|
2363
|
+
props.depthOffset = newCommonPath.length;
|
|
2364
|
+
props.commonPath = newCommonPath;
|
|
2365
|
+
props.root = newCommonPath.length > 0 ? posix.join(cwd, ...newCommonPath) : cwd;
|
|
2366
|
+
}
|
|
2367
|
+
return result;
|
|
2368
|
+
}
|
|
2369
|
+
function processPatterns({ patterns = ["**/*"], ignore = [], expandDirectories = true }, cwd, props) {
|
|
2370
|
+
if (typeof patterns === "string") patterns = [patterns];
|
|
2371
|
+
if (typeof ignore === "string") ignore = [ignore];
|
|
2372
|
+
const matchPatterns = [];
|
|
2373
|
+
const ignorePatterns = [];
|
|
2374
|
+
for (const pattern of ignore) {
|
|
2375
|
+
if (!pattern) continue;
|
|
2376
|
+
if (pattern[0] !== "!" || pattern[1] === "(") ignorePatterns.push(normalizePattern(pattern, expandDirectories, cwd, props, true));
|
|
2377
|
+
}
|
|
2378
|
+
for (const pattern of patterns) {
|
|
2379
|
+
if (!pattern) continue;
|
|
2380
|
+
if (pattern[0] !== "!" || pattern[1] === "(") matchPatterns.push(normalizePattern(pattern, expandDirectories, cwd, props, false));
|
|
2381
|
+
else if (pattern[1] !== "!" || pattern[2] === "(") ignorePatterns.push(normalizePattern(pattern.slice(1), expandDirectories, cwd, props, true));
|
|
2382
|
+
}
|
|
2383
|
+
return {
|
|
2384
|
+
match: matchPatterns,
|
|
2385
|
+
ignore: ignorePatterns
|
|
2386
|
+
};
|
|
2387
|
+
}
|
|
2388
|
+
function formatPaths(paths, relative) {
|
|
2389
|
+
for (let i = paths.length - 1; i >= 0; i--) {
|
|
2390
|
+
const path$1 = paths[i];
|
|
2391
|
+
paths[i] = relative(path$1);
|
|
2392
|
+
}
|
|
2393
|
+
return paths;
|
|
2394
|
+
}
|
|
2395
|
+
function normalizeCwd(cwd) {
|
|
2396
|
+
if (!cwd) return process.cwd().replace(BACKSLASHES, "/");
|
|
2397
|
+
if (cwd instanceof URL) return fileURLToPath(cwd).replace(BACKSLASHES, "/");
|
|
2398
|
+
return path.resolve(cwd).replace(BACKSLASHES, "/");
|
|
2399
|
+
}
|
|
2400
|
+
function getCrawler(patterns, inputOptions = {}) {
|
|
2401
|
+
const options = process.env.TINYGLOBBY_DEBUG ? {
|
|
2402
|
+
...inputOptions,
|
|
2403
|
+
debug: true
|
|
2404
|
+
} : inputOptions;
|
|
2405
|
+
const cwd = normalizeCwd(options.cwd);
|
|
2406
|
+
if (options.debug) log$1("globbing with:", {
|
|
2407
|
+
patterns,
|
|
2408
|
+
options,
|
|
2409
|
+
cwd
|
|
2410
|
+
});
|
|
2411
|
+
if (Array.isArray(patterns) && patterns.length === 0) return [{
|
|
2412
|
+
sync: () => [],
|
|
2413
|
+
withPromise: async () => []
|
|
2414
|
+
}, false];
|
|
2415
|
+
const props = {
|
|
2416
|
+
root: cwd,
|
|
2417
|
+
commonPath: null,
|
|
2418
|
+
depthOffset: 0
|
|
2419
|
+
};
|
|
2420
|
+
const processed = processPatterns({
|
|
2421
|
+
...options,
|
|
2422
|
+
patterns
|
|
2423
|
+
}, cwd, props);
|
|
2424
|
+
if (options.debug) log$1("internal processing patterns:", processed);
|
|
2425
|
+
const matchOptions = {
|
|
2426
|
+
dot: options.dot,
|
|
2427
|
+
nobrace: options.braceExpansion === false,
|
|
2428
|
+
nocase: options.caseSensitiveMatch === false,
|
|
2429
|
+
noextglob: options.extglob === false,
|
|
2430
|
+
noglobstar: options.globstar === false,
|
|
2431
|
+
posix: true
|
|
2432
|
+
};
|
|
2433
|
+
const matcher = (0, import_picomatch.default)(processed.match, {
|
|
2434
|
+
...matchOptions,
|
|
2435
|
+
ignore: processed.ignore
|
|
2436
|
+
});
|
|
2437
|
+
const ignore = (0, import_picomatch.default)(processed.ignore, matchOptions);
|
|
2438
|
+
const partialMatcher = getPartialMatcher(processed.match, matchOptions);
|
|
2439
|
+
const format = buildFormat(cwd, props.root, options.absolute);
|
|
2440
|
+
const formatExclude = options.absolute ? format : buildFormat(cwd, props.root, true);
|
|
2441
|
+
const fdirOptions = {
|
|
2442
|
+
filters: [options.debug ? (p, isDirectory) => {
|
|
2443
|
+
const path$1 = format(p, isDirectory);
|
|
2444
|
+
const matches = matcher(path$1);
|
|
2445
|
+
if (matches) log$1(`matched ${path$1}`);
|
|
2446
|
+
return matches;
|
|
2447
|
+
} : (p, isDirectory) => matcher(format(p, isDirectory))],
|
|
2448
|
+
exclude: options.debug ? (_, p) => {
|
|
2449
|
+
const relativePath = formatExclude(p, true);
|
|
2450
|
+
const skipped = relativePath !== "." && !partialMatcher(relativePath) || ignore(relativePath);
|
|
2451
|
+
if (skipped) log$1(`skipped ${p}`);
|
|
2452
|
+
else log$1(`crawling ${p}`);
|
|
2453
|
+
return skipped;
|
|
2454
|
+
} : (_, p) => {
|
|
2455
|
+
const relativePath = formatExclude(p, true);
|
|
2456
|
+
return relativePath !== "." && !partialMatcher(relativePath) || ignore(relativePath);
|
|
2457
|
+
},
|
|
2458
|
+
fs: options.fs ? {
|
|
2459
|
+
readdir: options.fs.readdir || nativeFs.readdir,
|
|
2460
|
+
readdirSync: options.fs.readdirSync || nativeFs.readdirSync,
|
|
2461
|
+
realpath: options.fs.realpath || nativeFs.realpath,
|
|
2462
|
+
realpathSync: options.fs.realpathSync || nativeFs.realpathSync,
|
|
2463
|
+
stat: options.fs.stat || nativeFs.stat,
|
|
2464
|
+
statSync: options.fs.statSync || nativeFs.statSync
|
|
2465
|
+
} : void 0,
|
|
2466
|
+
pathSeparator: "/",
|
|
2467
|
+
relativePaths: true,
|
|
2468
|
+
resolveSymlinks: true,
|
|
2469
|
+
signal: options.signal
|
|
2470
|
+
};
|
|
2471
|
+
if (options.deep !== void 0) fdirOptions.maxDepth = Math.round(options.deep - props.depthOffset);
|
|
2472
|
+
if (options.absolute) {
|
|
2473
|
+
fdirOptions.relativePaths = false;
|
|
2474
|
+
fdirOptions.resolvePaths = true;
|
|
2475
|
+
fdirOptions.includeBasePath = true;
|
|
2476
|
+
}
|
|
2477
|
+
if (options.followSymbolicLinks === false) {
|
|
2478
|
+
fdirOptions.resolveSymlinks = false;
|
|
2479
|
+
fdirOptions.excludeSymlinks = true;
|
|
2480
|
+
}
|
|
2481
|
+
if (options.onlyDirectories) {
|
|
2482
|
+
fdirOptions.excludeFiles = true;
|
|
2483
|
+
fdirOptions.includeDirs = true;
|
|
2484
|
+
} else if (options.onlyFiles === false) fdirOptions.includeDirs = true;
|
|
2485
|
+
props.root = props.root.replace(BACKSLASHES, "");
|
|
2486
|
+
const root = props.root;
|
|
2487
|
+
if (options.debug) log$1("internal properties:", props);
|
|
2488
|
+
const relative = cwd !== root && !options.absolute && buildRelative(cwd, props.root);
|
|
2489
|
+
return [new Builder(fdirOptions).crawl(root), relative];
|
|
2490
|
+
}
|
|
2491
|
+
async function glob(patternsOrOptions, options) {
|
|
2492
|
+
if (patternsOrOptions && (options === null || options === void 0 ? void 0 : options.patterns)) throw new Error("Cannot pass patterns as both an argument and an option");
|
|
2493
|
+
const isModern = isReadonlyArray(patternsOrOptions) || typeof patternsOrOptions === "string";
|
|
2494
|
+
const opts = isModern ? options : patternsOrOptions;
|
|
2495
|
+
const [crawler, relative] = getCrawler(isModern ? patternsOrOptions : patternsOrOptions.patterns, opts);
|
|
2496
|
+
if (!relative) return crawler.withPromise();
|
|
2497
|
+
return formatPaths(await crawler.withPromise(), relative);
|
|
2498
|
+
}
|
|
2499
|
+
|
|
2500
|
+
//#endregion
|
|
2501
|
+
//#region src/utils/file.ts
|
|
2502
|
+
const unlinkAsync = promisify(unlink);
|
|
2503
|
+
const rmAsync = promisify(rm);
|
|
2504
|
+
/**
|
|
2505
|
+
* 检查路径是否为目录
|
|
2506
|
+
*/
|
|
2507
|
+
function isDirectory(path) {
|
|
2508
|
+
try {
|
|
2509
|
+
return lstatSync(path).isDirectory();
|
|
2510
|
+
} catch {
|
|
2511
|
+
return false;
|
|
2512
|
+
}
|
|
2513
|
+
}
|
|
2514
|
+
/**
|
|
2515
|
+
* 删除单个文件
|
|
2516
|
+
*/
|
|
2517
|
+
async function deleteFile(filePath) {
|
|
2518
|
+
await unlinkAsync(filePath);
|
|
2519
|
+
}
|
|
2520
|
+
/**
|
|
2521
|
+
* 删除目录(递归)
|
|
2522
|
+
*/
|
|
2523
|
+
async function deleteDir(dirPath) {
|
|
2524
|
+
await rmAsync(dirPath, {
|
|
2525
|
+
recursive: true,
|
|
2526
|
+
force: true
|
|
2527
|
+
});
|
|
2528
|
+
}
|
|
2529
|
+
|
|
2530
|
+
//#endregion
|
|
2531
|
+
//#region src/utils/logger.ts
|
|
2532
|
+
/**
|
|
2533
|
+
* 日志工具函数
|
|
2534
|
+
*/
|
|
2535
|
+
const colors = {
|
|
2536
|
+
reset: "\x1B[0m",
|
|
2537
|
+
red: "\x1B[31m",
|
|
2538
|
+
green: "\x1B[32m",
|
|
2539
|
+
yellow: "\x1B[33m",
|
|
2540
|
+
blue: "\x1B[34m",
|
|
2541
|
+
cyan: "\x1B[36m"
|
|
2542
|
+
};
|
|
2543
|
+
/**
|
|
2544
|
+
* 普通输出
|
|
2545
|
+
*/
|
|
2546
|
+
function log(message = "") {
|
|
2547
|
+
console.log(message);
|
|
2548
|
+
}
|
|
2549
|
+
/**
|
|
2550
|
+
* 成功消息(绿色)
|
|
2551
|
+
*/
|
|
2552
|
+
function success(message) {
|
|
2553
|
+
console.log(`${colors.green}${message}${colors.reset}`);
|
|
2554
|
+
}
|
|
2555
|
+
/**
|
|
2556
|
+
* 错误消息(红色)
|
|
2557
|
+
*/
|
|
2558
|
+
function error(message) {
|
|
2559
|
+
console.error(`${colors.red}${message}${colors.reset}`);
|
|
2560
|
+
}
|
|
2561
|
+
/**
|
|
2562
|
+
* 警告消息(黄色)
|
|
2563
|
+
*/
|
|
2564
|
+
function warn(message) {
|
|
2565
|
+
console.warn(`${colors.yellow}${message}${colors.reset}`);
|
|
2566
|
+
}
|
|
2567
|
+
/**
|
|
2568
|
+
* 信息消息(蓝色)
|
|
2569
|
+
*/
|
|
2570
|
+
function info(message) {
|
|
2571
|
+
console.info(`${colors.blue}${message}${colors.reset}`);
|
|
2572
|
+
}
|
|
2573
|
+
|
|
2574
|
+
//#endregion
|
|
2575
|
+
//#region src/commands/delete.ts
|
|
2576
|
+
/**
|
|
2577
|
+
* 执行删除操作(编程模式)
|
|
2578
|
+
* @param patterns - 文件或文件夹路径/模式
|
|
2579
|
+
* @param config - CLI 配置
|
|
2580
|
+
* @param options - 删除选项
|
|
2581
|
+
* @returns 删除结果
|
|
2582
|
+
* @example
|
|
2583
|
+
* ```ts
|
|
2584
|
+
* import { executeDelete } from '@shuiyangsuan/cli';
|
|
2585
|
+
*
|
|
2586
|
+
* const result = await executeDelete(['node_modules', 'dist'], config, { force: true, verbose: true });
|
|
2587
|
+
* console.log(`删除了 ${result.deletedCount} 个文件`);
|
|
2588
|
+
* ```
|
|
2589
|
+
*/
|
|
2590
|
+
async function executeDelete(patterns, config, options = {}) {
|
|
2591
|
+
const result = {
|
|
2592
|
+
deletedCount: 0,
|
|
2593
|
+
failedCount: 0,
|
|
2594
|
+
deletedFiles: [],
|
|
2595
|
+
errors: []
|
|
2596
|
+
};
|
|
2597
|
+
try {
|
|
2598
|
+
const finalOptions = {
|
|
2599
|
+
...config,
|
|
2600
|
+
...options
|
|
2601
|
+
};
|
|
2602
|
+
let targetPatterns = patterns;
|
|
2603
|
+
if (targetPatterns.length === 0) if (finalOptions.useDefaults && config.defaultPatterns && config.defaultPatterns.length > 0) targetPatterns = [...config.defaultPatterns];
|
|
2604
|
+
else if (config.defaultPatterns && config.defaultPatterns.length > 0) targetPatterns = [...config.defaultPatterns];
|
|
2605
|
+
else throw new Error("请指定要删除的文件或文件夹,或在配置文件中设置 defaultPatterns");
|
|
2606
|
+
else if (finalOptions.useDefaults && config.defaultPatterns && config.defaultPatterns.length > 0) targetPatterns = [...config.defaultPatterns, ...patterns];
|
|
2607
|
+
const filesToDelete = await collectFilesToDelete(targetPatterns, finalOptions);
|
|
2608
|
+
if (filesToDelete.length === 0) {
|
|
2609
|
+
warn("没有找到匹配的文件或文件夹");
|
|
2610
|
+
return result;
|
|
2611
|
+
}
|
|
2612
|
+
if (finalOptions.dryRun || finalOptions.verbose) {
|
|
2613
|
+
info(`\n📋 将要删除 ${filesToDelete.length} 个项目:\n`);
|
|
2614
|
+
filesToDelete.forEach((file, index) => {
|
|
2615
|
+
log(` ${index + 1}. ${file}`);
|
|
2616
|
+
});
|
|
2617
|
+
log("");
|
|
2618
|
+
}
|
|
2619
|
+
if (finalOptions.dryRun) {
|
|
2620
|
+
info("🔍 预览模式 - 没有实际删除任何文件");
|
|
2621
|
+
return result;
|
|
2622
|
+
}
|
|
2623
|
+
if (!finalOptions.force) {
|
|
2624
|
+
const rl = (await import("readline")).createInterface({
|
|
2625
|
+
input: process.stdin,
|
|
2626
|
+
output: process.stdout
|
|
2627
|
+
});
|
|
2628
|
+
const answer = await new Promise((resolve) => {
|
|
2629
|
+
rl.question("⚠️ 确定要删除这些文件吗?(yes/no): ", (ans) => {
|
|
2630
|
+
rl.close();
|
|
2631
|
+
resolve(ans);
|
|
2632
|
+
});
|
|
2633
|
+
});
|
|
2634
|
+
if (answer.toLowerCase() !== "yes" && answer.toLowerCase() !== "y") {
|
|
2635
|
+
info("❌ 已取消删除操作");
|
|
2636
|
+
return result;
|
|
2637
|
+
}
|
|
2638
|
+
}
|
|
2639
|
+
let deletedCount = 0;
|
|
2640
|
+
let failedCount = 0;
|
|
2641
|
+
const deleteTasks = filesToDelete.map(async (file) => {
|
|
2642
|
+
try {
|
|
2643
|
+
if (isDirectory(file)) await deleteDir(file);
|
|
2644
|
+
else await deleteFile(file);
|
|
2645
|
+
deletedCount++;
|
|
2646
|
+
result.deletedFiles.push(file);
|
|
2647
|
+
if (finalOptions.verbose) success(`✓ 已删除:${file}`);
|
|
2648
|
+
} catch (err) {
|
|
2649
|
+
failedCount++;
|
|
2650
|
+
const errorMsg = `✗ 删除失败:${file} - ${err.message}`;
|
|
2651
|
+
error(errorMsg);
|
|
2652
|
+
result.errors.push(errorMsg);
|
|
2653
|
+
}
|
|
2654
|
+
});
|
|
2655
|
+
await Promise.all(deleteTasks);
|
|
2656
|
+
log("");
|
|
2657
|
+
success(`✅ 删除完成:成功 ${deletedCount} 个,失败 ${failedCount} 个`);
|
|
2658
|
+
result.deletedCount = deletedCount;
|
|
2659
|
+
result.failedCount = failedCount;
|
|
2660
|
+
if (failedCount > 0) throw new Error(`部分文件删除失败:共失败 ${failedCount} 个`);
|
|
2661
|
+
return result;
|
|
2662
|
+
} catch (err) {
|
|
2663
|
+
error(`删除过程中出错:${err.message}`);
|
|
2664
|
+
result.errors.push(err.message);
|
|
2665
|
+
throw err;
|
|
2666
|
+
}
|
|
2667
|
+
}
|
|
2668
|
+
/**
|
|
2669
|
+
* 注册 delete 命令到 CLI
|
|
2670
|
+
* @param program - Commander 程序实例
|
|
2671
|
+
* @param config - CLI 配置
|
|
2672
|
+
*/
|
|
2673
|
+
function deleteCommand(program, config) {
|
|
2674
|
+
program.command("delete").alias("rm").alias("del").description("删除文件和文件夹,支持 glob 模式匹配").argument("[patterns...]", "要删除的文件或文件夹路径/模式", []).option("-f, --force", "强制删除,不提示确认", config.force).option("-n, --dry-run", "预览模式,仅显示将要删除的内容", config.dryRun).option("-v, --verbose", "详细输出模式", config.verbose).option("-d, --use-defaults", "使用配置文件中的默认模式").action(async (patterns, options) => {
|
|
2675
|
+
try {
|
|
2676
|
+
await executeDelete(patterns, config, options);
|
|
2677
|
+
} catch {
|
|
2678
|
+
process.exit(1);
|
|
2679
|
+
}
|
|
2680
|
+
});
|
|
2681
|
+
}
|
|
2682
|
+
/**
|
|
2683
|
+
* 收集要删除的文件列表
|
|
2684
|
+
* @param patterns - 文件或文件夹路径/模式
|
|
2685
|
+
* @param options - 删除选项
|
|
2686
|
+
* @returns 匹配的文件路径列表
|
|
2687
|
+
*/
|
|
2688
|
+
async function collectFilesToDelete(patterns, _options) {
|
|
2689
|
+
const filesToDelete = /* @__PURE__ */ new Set();
|
|
2690
|
+
const matchTasks = patterns.map((pattern) => {
|
|
2691
|
+
const absolutePath = resolve(pattern);
|
|
2692
|
+
if (existsSync(absolutePath)) {
|
|
2693
|
+
filesToDelete.add(absolutePath);
|
|
2694
|
+
return Promise.resolve();
|
|
2695
|
+
}
|
|
2696
|
+
return glob(pattern, {
|
|
2697
|
+
cwd: process.cwd(),
|
|
2698
|
+
absolute: true,
|
|
2699
|
+
dot: true,
|
|
2700
|
+
onlyFiles: false,
|
|
2701
|
+
ignore: ["**/.git/**"]
|
|
2702
|
+
}).then((matchedFiles) => {
|
|
2703
|
+
matchedFiles.forEach((file) => filesToDelete.add(file));
|
|
2704
|
+
}).catch((err) => {
|
|
2705
|
+
warn(`glob 匹配失败 (${pattern}): ${err.message}`);
|
|
2706
|
+
});
|
|
2707
|
+
});
|
|
2708
|
+
await Promise.all(matchTasks);
|
|
2709
|
+
return Array.from(filesToDelete);
|
|
2710
|
+
}
|
|
2711
|
+
|
|
2712
|
+
//#endregion
|
|
2713
|
+
//#region src/config/index.ts
|
|
2714
|
+
const CONFIG_FILES = [
|
|
2715
|
+
".clirc.json",
|
|
2716
|
+
"cli.config.js",
|
|
2717
|
+
"cli.config.ts",
|
|
2718
|
+
".cli.config.mts",
|
|
2719
|
+
"cli.config.json"
|
|
2720
|
+
];
|
|
2721
|
+
/**
|
|
2722
|
+
* 读取配置文件
|
|
2723
|
+
* @returns 配置对象
|
|
2724
|
+
*/
|
|
2725
|
+
async function readConfig() {
|
|
2726
|
+
const cwd = process.cwd();
|
|
2727
|
+
for (const configFile of CONFIG_FILES) {
|
|
2728
|
+
const configPath = join(cwd, configFile);
|
|
2729
|
+
if (!existsSync(configPath)) continue;
|
|
2730
|
+
try {
|
|
2731
|
+
let config;
|
|
2732
|
+
if (configFile.endsWith(".json")) {
|
|
2733
|
+
const content = readFileSync(configPath, "utf-8");
|
|
2734
|
+
config = JSON.parse(content);
|
|
2735
|
+
} else {
|
|
2736
|
+
const module = await import(configPath);
|
|
2737
|
+
config = module.default || module;
|
|
2738
|
+
}
|
|
2739
|
+
return config;
|
|
2740
|
+
} catch (err) {
|
|
2741
|
+
console.warn(`读取配置文件失败 (${configFile}): ${err.message}`);
|
|
2742
|
+
}
|
|
2743
|
+
}
|
|
2744
|
+
return {
|
|
2745
|
+
force: false,
|
|
2746
|
+
dryRun: false,
|
|
2747
|
+
verbose: false
|
|
2748
|
+
};
|
|
2749
|
+
}
|
|
2750
|
+
|
|
2751
|
+
//#endregion
|
|
2752
|
+
export { __commonJSMin as a, executeDelete as i, collectFilesToDelete as n, __require$1 as o, deleteCommand as r, __toESM as s, readConfig as t };
|
|
2753
|
+
//# sourceMappingURL=config-D5i9xsXl.js.map
|