poof 2.2.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +165 -227
- package/dist/cli.mjs +842 -0
- package/dist/index.mjs +1854 -0
- package/dist/spawn-rm/worker.mjs +41 -0
- package/package.json +19 -57
- package/dist/index.js +0 -9
- package/lib/index.js +0 -4
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,1854 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { spawn } from 'node:child_process';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { setTimeout } from 'node:timers/promises';
|
|
8
|
+
|
|
9
|
+
const isEnabled = (namespace) => (process.env.DEBUG ?? "").split(",").some((pattern) => {
|
|
10
|
+
const trimmed = pattern.trim();
|
|
11
|
+
if (trimmed.endsWith("*")) {
|
|
12
|
+
return namespace.startsWith(trimmed.slice(0, -1));
|
|
13
|
+
}
|
|
14
|
+
return namespace === trimmed;
|
|
15
|
+
});
|
|
16
|
+
const noop = (..._args) => {
|
|
17
|
+
};
|
|
18
|
+
const createDebug = (namespace) => {
|
|
19
|
+
if (!isEnabled(namespace)) {
|
|
20
|
+
return noop;
|
|
21
|
+
}
|
|
22
|
+
return (...args) => {
|
|
23
|
+
console.error(`${(/* @__PURE__ */ new Date()).toISOString()} ${namespace}`, ...args);
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function getDefaultExportFromCjs (x) {
|
|
28
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
var utils = {};
|
|
32
|
+
|
|
33
|
+
var constants;
|
|
34
|
+
var hasRequiredConstants;
|
|
35
|
+
|
|
36
|
+
function requireConstants () {
|
|
37
|
+
if (hasRequiredConstants) return constants;
|
|
38
|
+
hasRequiredConstants = 1;
|
|
39
|
+
const WIN_SLASH = "\\\\/";
|
|
40
|
+
const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
|
|
41
|
+
const DOT_LITERAL = "\\.";
|
|
42
|
+
const PLUS_LITERAL = "\\+";
|
|
43
|
+
const QMARK_LITERAL = "\\?";
|
|
44
|
+
const SLASH_LITERAL = "\\/";
|
|
45
|
+
const ONE_CHAR = "(?=.)";
|
|
46
|
+
const QMARK = "[^/]";
|
|
47
|
+
const END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
|
|
48
|
+
const START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
|
|
49
|
+
const DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
|
|
50
|
+
const NO_DOT = `(?!${DOT_LITERAL})`;
|
|
51
|
+
const NO_DOTS = `(?!${START_ANCHOR}${DOTS_SLASH})`;
|
|
52
|
+
const NO_DOT_SLASH = `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`;
|
|
53
|
+
const NO_DOTS_SLASH = `(?!${DOTS_SLASH})`;
|
|
54
|
+
const QMARK_NO_DOT = `[^.${SLASH_LITERAL}]`;
|
|
55
|
+
const STAR = `${QMARK}*?`;
|
|
56
|
+
const SEP = "/";
|
|
57
|
+
const POSIX_CHARS = {
|
|
58
|
+
DOT_LITERAL,
|
|
59
|
+
PLUS_LITERAL,
|
|
60
|
+
QMARK_LITERAL,
|
|
61
|
+
SLASH_LITERAL,
|
|
62
|
+
ONE_CHAR,
|
|
63
|
+
QMARK,
|
|
64
|
+
END_ANCHOR,
|
|
65
|
+
DOTS_SLASH,
|
|
66
|
+
NO_DOT,
|
|
67
|
+
NO_DOTS,
|
|
68
|
+
NO_DOT_SLASH,
|
|
69
|
+
NO_DOTS_SLASH,
|
|
70
|
+
QMARK_NO_DOT,
|
|
71
|
+
STAR,
|
|
72
|
+
START_ANCHOR,
|
|
73
|
+
SEP
|
|
74
|
+
};
|
|
75
|
+
const WINDOWS_CHARS = {
|
|
76
|
+
...POSIX_CHARS,
|
|
77
|
+
SLASH_LITERAL: `[${WIN_SLASH}]`,
|
|
78
|
+
QMARK: WIN_NO_SLASH,
|
|
79
|
+
STAR: `${WIN_NO_SLASH}*?`,
|
|
80
|
+
DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`,
|
|
81
|
+
NO_DOT: `(?!${DOT_LITERAL})`,
|
|
82
|
+
NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
|
83
|
+
NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`,
|
|
84
|
+
NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
|
85
|
+
QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
|
|
86
|
+
START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
|
|
87
|
+
END_ANCHOR: `(?:[${WIN_SLASH}]|$)`,
|
|
88
|
+
SEP: "\\"
|
|
89
|
+
};
|
|
90
|
+
const POSIX_REGEX_SOURCE = {
|
|
91
|
+
alnum: "a-zA-Z0-9",
|
|
92
|
+
alpha: "a-zA-Z",
|
|
93
|
+
ascii: "\\x00-\\x7F",
|
|
94
|
+
blank: " \\t",
|
|
95
|
+
cntrl: "\\x00-\\x1F\\x7F",
|
|
96
|
+
digit: "0-9",
|
|
97
|
+
graph: "\\x21-\\x7E",
|
|
98
|
+
lower: "a-z",
|
|
99
|
+
print: "\\x20-\\x7E ",
|
|
100
|
+
punct: "\\-!\"#$%&'()\\*+,./:;<=>?@[\\]^_`{|}~",
|
|
101
|
+
space: " \\t\\r\\n\\v\\f",
|
|
102
|
+
upper: "A-Z",
|
|
103
|
+
word: "A-Za-z0-9_",
|
|
104
|
+
xdigit: "A-Fa-f0-9"
|
|
105
|
+
};
|
|
106
|
+
constants = {
|
|
107
|
+
MAX_LENGTH: 1024 * 64,
|
|
108
|
+
POSIX_REGEX_SOURCE,
|
|
109
|
+
// regular expressions
|
|
110
|
+
REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
|
|
111
|
+
REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
|
|
112
|
+
REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
|
|
113
|
+
REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
|
|
114
|
+
REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
|
|
115
|
+
REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
|
|
116
|
+
// Replace globs with equivalent patterns to reduce parsing time.
|
|
117
|
+
REPLACEMENTS: {
|
|
118
|
+
__proto__: null,
|
|
119
|
+
"***": "*",
|
|
120
|
+
"**/**": "**",
|
|
121
|
+
"**/**/**": "**"
|
|
122
|
+
},
|
|
123
|
+
// Digits
|
|
124
|
+
CHAR_0: 48,
|
|
125
|
+
/* 0 */
|
|
126
|
+
CHAR_9: 57,
|
|
127
|
+
/* 9 */
|
|
128
|
+
// Alphabet chars.
|
|
129
|
+
CHAR_UPPERCASE_A: 65,
|
|
130
|
+
/* A */
|
|
131
|
+
CHAR_LOWERCASE_A: 97,
|
|
132
|
+
/* a */
|
|
133
|
+
CHAR_UPPERCASE_Z: 90,
|
|
134
|
+
/* Z */
|
|
135
|
+
CHAR_LOWERCASE_Z: 122,
|
|
136
|
+
/* z */
|
|
137
|
+
CHAR_LEFT_PARENTHESES: 40,
|
|
138
|
+
/* ( */
|
|
139
|
+
CHAR_RIGHT_PARENTHESES: 41,
|
|
140
|
+
/* ) */
|
|
141
|
+
CHAR_ASTERISK: 42,
|
|
142
|
+
/* * */
|
|
143
|
+
// Non-alphabetic chars.
|
|
144
|
+
CHAR_AMPERSAND: 38,
|
|
145
|
+
/* & */
|
|
146
|
+
CHAR_AT: 64,
|
|
147
|
+
/* @ */
|
|
148
|
+
CHAR_BACKWARD_SLASH: 92,
|
|
149
|
+
/* \ */
|
|
150
|
+
CHAR_CARRIAGE_RETURN: 13,
|
|
151
|
+
/* \r */
|
|
152
|
+
CHAR_CIRCUMFLEX_ACCENT: 94,
|
|
153
|
+
/* ^ */
|
|
154
|
+
CHAR_COLON: 58,
|
|
155
|
+
/* : */
|
|
156
|
+
CHAR_COMMA: 44,
|
|
157
|
+
/* , */
|
|
158
|
+
CHAR_DOT: 46,
|
|
159
|
+
/* . */
|
|
160
|
+
CHAR_DOUBLE_QUOTE: 34,
|
|
161
|
+
/* " */
|
|
162
|
+
CHAR_EQUAL: 61,
|
|
163
|
+
/* = */
|
|
164
|
+
CHAR_EXCLAMATION_MARK: 33,
|
|
165
|
+
/* ! */
|
|
166
|
+
CHAR_FORM_FEED: 12,
|
|
167
|
+
/* \f */
|
|
168
|
+
CHAR_FORWARD_SLASH: 47,
|
|
169
|
+
/* / */
|
|
170
|
+
CHAR_GRAVE_ACCENT: 96,
|
|
171
|
+
/* ` */
|
|
172
|
+
CHAR_HASH: 35,
|
|
173
|
+
/* # */
|
|
174
|
+
CHAR_HYPHEN_MINUS: 45,
|
|
175
|
+
/* - */
|
|
176
|
+
CHAR_LEFT_ANGLE_BRACKET: 60,
|
|
177
|
+
/* < */
|
|
178
|
+
CHAR_LEFT_CURLY_BRACE: 123,
|
|
179
|
+
/* { */
|
|
180
|
+
CHAR_LEFT_SQUARE_BRACKET: 91,
|
|
181
|
+
/* [ */
|
|
182
|
+
CHAR_LINE_FEED: 10,
|
|
183
|
+
/* \n */
|
|
184
|
+
CHAR_NO_BREAK_SPACE: 160,
|
|
185
|
+
/* \u00A0 */
|
|
186
|
+
CHAR_PERCENT: 37,
|
|
187
|
+
/* % */
|
|
188
|
+
CHAR_PLUS: 43,
|
|
189
|
+
/* + */
|
|
190
|
+
CHAR_QUESTION_MARK: 63,
|
|
191
|
+
/* ? */
|
|
192
|
+
CHAR_RIGHT_ANGLE_BRACKET: 62,
|
|
193
|
+
/* > */
|
|
194
|
+
CHAR_RIGHT_CURLY_BRACE: 125,
|
|
195
|
+
/* } */
|
|
196
|
+
CHAR_RIGHT_SQUARE_BRACKET: 93,
|
|
197
|
+
/* ] */
|
|
198
|
+
CHAR_SEMICOLON: 59,
|
|
199
|
+
/* ; */
|
|
200
|
+
CHAR_SINGLE_QUOTE: 39,
|
|
201
|
+
/* ' */
|
|
202
|
+
CHAR_SPACE: 32,
|
|
203
|
+
/* */
|
|
204
|
+
CHAR_TAB: 9,
|
|
205
|
+
/* \t */
|
|
206
|
+
CHAR_UNDERSCORE: 95,
|
|
207
|
+
/* _ */
|
|
208
|
+
CHAR_VERTICAL_LINE: 124,
|
|
209
|
+
/* | */
|
|
210
|
+
CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279,
|
|
211
|
+
/* \uFEFF */
|
|
212
|
+
/**
|
|
213
|
+
* Create EXTGLOB_CHARS
|
|
214
|
+
*/
|
|
215
|
+
extglobChars(chars) {
|
|
216
|
+
return {
|
|
217
|
+
"!": { type: "negate", open: "(?:(?!(?:", close: `))${chars.STAR})` },
|
|
218
|
+
"?": { type: "qmark", open: "(?:", close: ")?" },
|
|
219
|
+
"+": { type: "plus", open: "(?:", close: ")+" },
|
|
220
|
+
"*": { type: "star", open: "(?:", close: ")*" },
|
|
221
|
+
"@": { type: "at", open: "(?:", close: ")" }
|
|
222
|
+
};
|
|
223
|
+
},
|
|
224
|
+
/**
|
|
225
|
+
* Create GLOB_CHARS
|
|
226
|
+
*/
|
|
227
|
+
globChars(win32) {
|
|
228
|
+
return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
return constants;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
var hasRequiredUtils;
|
|
235
|
+
|
|
236
|
+
function requireUtils () {
|
|
237
|
+
if (hasRequiredUtils) return utils;
|
|
238
|
+
hasRequiredUtils = 1;
|
|
239
|
+
(function (exports$1) {
|
|
240
|
+
const {
|
|
241
|
+
REGEX_BACKSLASH,
|
|
242
|
+
REGEX_REMOVE_BACKSLASH,
|
|
243
|
+
REGEX_SPECIAL_CHARS,
|
|
244
|
+
REGEX_SPECIAL_CHARS_GLOBAL
|
|
245
|
+
} = /*@__PURE__*/ requireConstants();
|
|
246
|
+
exports$1.isObject = (val) => val !== null && typeof val === "object" && !Array.isArray(val);
|
|
247
|
+
exports$1.hasRegexChars = (str) => REGEX_SPECIAL_CHARS.test(str);
|
|
248
|
+
exports$1.isRegexChar = (str) => str.length === 1 && exports$1.hasRegexChars(str);
|
|
249
|
+
exports$1.escapeRegex = (str) => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, "\\$1");
|
|
250
|
+
exports$1.toPosixSlashes = (str) => str.replace(REGEX_BACKSLASH, "/");
|
|
251
|
+
exports$1.isWindows = () => {
|
|
252
|
+
if (typeof navigator !== "undefined" && navigator.platform) {
|
|
253
|
+
const platform = navigator.platform.toLowerCase();
|
|
254
|
+
return platform === "win32" || platform === "windows";
|
|
255
|
+
}
|
|
256
|
+
if (typeof process !== "undefined" && process.platform) {
|
|
257
|
+
return process.platform === "win32";
|
|
258
|
+
}
|
|
259
|
+
return false;
|
|
260
|
+
};
|
|
261
|
+
exports$1.removeBackslashes = (str) => {
|
|
262
|
+
return str.replace(REGEX_REMOVE_BACKSLASH, (match) => {
|
|
263
|
+
return match === "\\" ? "" : match;
|
|
264
|
+
});
|
|
265
|
+
};
|
|
266
|
+
exports$1.escapeLast = (input, char, lastIdx) => {
|
|
267
|
+
const idx = input.lastIndexOf(char, lastIdx);
|
|
268
|
+
if (idx === -1) return input;
|
|
269
|
+
if (input[idx - 1] === "\\") return exports$1.escapeLast(input, char, idx - 1);
|
|
270
|
+
return `${input.slice(0, idx)}\\${input.slice(idx)}`;
|
|
271
|
+
};
|
|
272
|
+
exports$1.removePrefix = (input, state = {}) => {
|
|
273
|
+
let output = input;
|
|
274
|
+
if (output.startsWith("./")) {
|
|
275
|
+
output = output.slice(2);
|
|
276
|
+
state.prefix = "./";
|
|
277
|
+
}
|
|
278
|
+
return output;
|
|
279
|
+
};
|
|
280
|
+
exports$1.wrapOutput = (input, state = {}, options = {}) => {
|
|
281
|
+
const prepend = options.contains ? "" : "^";
|
|
282
|
+
const append = options.contains ? "" : "$";
|
|
283
|
+
let output = `${prepend}(?:${input})${append}`;
|
|
284
|
+
if (state.negated === true) {
|
|
285
|
+
output = `(?:^(?!${output}).*$)`;
|
|
286
|
+
}
|
|
287
|
+
return output;
|
|
288
|
+
};
|
|
289
|
+
exports$1.basename = (path, { windows } = {}) => {
|
|
290
|
+
const segs = path.split(windows ? /[\\/]/ : "/");
|
|
291
|
+
const last = segs[segs.length - 1];
|
|
292
|
+
if (last === "") {
|
|
293
|
+
return segs[segs.length - 2];
|
|
294
|
+
}
|
|
295
|
+
return last;
|
|
296
|
+
};
|
|
297
|
+
} (utils));
|
|
298
|
+
return utils;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
var scan_1;
|
|
302
|
+
var hasRequiredScan;
|
|
303
|
+
|
|
304
|
+
function requireScan () {
|
|
305
|
+
if (hasRequiredScan) return scan_1;
|
|
306
|
+
hasRequiredScan = 1;
|
|
307
|
+
const utils = /*@__PURE__*/ requireUtils();
|
|
308
|
+
const {
|
|
309
|
+
CHAR_ASTERISK,
|
|
310
|
+
/* * */
|
|
311
|
+
CHAR_AT,
|
|
312
|
+
/* @ */
|
|
313
|
+
CHAR_BACKWARD_SLASH,
|
|
314
|
+
/* \ */
|
|
315
|
+
CHAR_COMMA,
|
|
316
|
+
/* , */
|
|
317
|
+
CHAR_DOT,
|
|
318
|
+
/* . */
|
|
319
|
+
CHAR_EXCLAMATION_MARK,
|
|
320
|
+
/* ! */
|
|
321
|
+
CHAR_FORWARD_SLASH,
|
|
322
|
+
/* / */
|
|
323
|
+
CHAR_LEFT_CURLY_BRACE,
|
|
324
|
+
/* { */
|
|
325
|
+
CHAR_LEFT_PARENTHESES,
|
|
326
|
+
/* ( */
|
|
327
|
+
CHAR_LEFT_SQUARE_BRACKET,
|
|
328
|
+
/* [ */
|
|
329
|
+
CHAR_PLUS,
|
|
330
|
+
/* + */
|
|
331
|
+
CHAR_QUESTION_MARK,
|
|
332
|
+
/* ? */
|
|
333
|
+
CHAR_RIGHT_CURLY_BRACE,
|
|
334
|
+
/* } */
|
|
335
|
+
CHAR_RIGHT_PARENTHESES,
|
|
336
|
+
/* ) */
|
|
337
|
+
CHAR_RIGHT_SQUARE_BRACKET
|
|
338
|
+
/* ] */
|
|
339
|
+
} = /*@__PURE__*/ requireConstants();
|
|
340
|
+
const isPathSeparator = (code) => {
|
|
341
|
+
return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
|
|
342
|
+
};
|
|
343
|
+
const depth = (token) => {
|
|
344
|
+
if (token.isPrefix !== true) {
|
|
345
|
+
token.depth = token.isGlobstar ? Infinity : 1;
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
const scan = (input, options) => {
|
|
349
|
+
const opts = options || {};
|
|
350
|
+
const length = input.length - 1;
|
|
351
|
+
const scanToEnd = opts.parts === true || opts.scanToEnd === true;
|
|
352
|
+
const slashes = [];
|
|
353
|
+
const tokens = [];
|
|
354
|
+
const parts = [];
|
|
355
|
+
let str = input;
|
|
356
|
+
let index = -1;
|
|
357
|
+
let start = 0;
|
|
358
|
+
let lastIndex = 0;
|
|
359
|
+
let isBrace = false;
|
|
360
|
+
let isBracket = false;
|
|
361
|
+
let isGlob = false;
|
|
362
|
+
let isExtglob = false;
|
|
363
|
+
let isGlobstar = false;
|
|
364
|
+
let braceEscaped = false;
|
|
365
|
+
let backslashes = false;
|
|
366
|
+
let negated = false;
|
|
367
|
+
let negatedExtglob = false;
|
|
368
|
+
let finished = false;
|
|
369
|
+
let braces = 0;
|
|
370
|
+
let prev;
|
|
371
|
+
let code;
|
|
372
|
+
let token = { value: "", depth: 0, isGlob: false };
|
|
373
|
+
const eos = () => index >= length;
|
|
374
|
+
const peek = () => str.charCodeAt(index + 1);
|
|
375
|
+
const advance = () => {
|
|
376
|
+
prev = code;
|
|
377
|
+
return str.charCodeAt(++index);
|
|
378
|
+
};
|
|
379
|
+
while (index < length) {
|
|
380
|
+
code = advance();
|
|
381
|
+
let next;
|
|
382
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
383
|
+
backslashes = token.backslashes = true;
|
|
384
|
+
code = advance();
|
|
385
|
+
if (code === CHAR_LEFT_CURLY_BRACE) {
|
|
386
|
+
braceEscaped = true;
|
|
387
|
+
}
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE) {
|
|
391
|
+
braces++;
|
|
392
|
+
while (eos() !== true && (code = advance())) {
|
|
393
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
394
|
+
backslashes = token.backslashes = true;
|
|
395
|
+
advance();
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
if (code === CHAR_LEFT_CURLY_BRACE) {
|
|
399
|
+
braces++;
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
if (braceEscaped !== true && code === CHAR_DOT && (code = advance()) === CHAR_DOT) {
|
|
403
|
+
isBrace = token.isBrace = true;
|
|
404
|
+
isGlob = token.isGlob = true;
|
|
405
|
+
finished = true;
|
|
406
|
+
if (scanToEnd === true) {
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
if (braceEscaped !== true && code === CHAR_COMMA) {
|
|
412
|
+
isBrace = token.isBrace = true;
|
|
413
|
+
isGlob = token.isGlob = true;
|
|
414
|
+
finished = true;
|
|
415
|
+
if (scanToEnd === true) {
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
break;
|
|
419
|
+
}
|
|
420
|
+
if (code === CHAR_RIGHT_CURLY_BRACE) {
|
|
421
|
+
braces--;
|
|
422
|
+
if (braces === 0) {
|
|
423
|
+
braceEscaped = false;
|
|
424
|
+
isBrace = token.isBrace = true;
|
|
425
|
+
finished = true;
|
|
426
|
+
break;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
if (scanToEnd === true) {
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
break;
|
|
434
|
+
}
|
|
435
|
+
if (code === CHAR_FORWARD_SLASH) {
|
|
436
|
+
slashes.push(index);
|
|
437
|
+
tokens.push(token);
|
|
438
|
+
token = { value: "", depth: 0, isGlob: false };
|
|
439
|
+
if (finished === true) continue;
|
|
440
|
+
if (prev === CHAR_DOT && index === start + 1) {
|
|
441
|
+
start += 2;
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
lastIndex = index + 1;
|
|
445
|
+
continue;
|
|
446
|
+
}
|
|
447
|
+
if (opts.noext !== true) {
|
|
448
|
+
const isExtglobChar = code === CHAR_PLUS || code === CHAR_AT || code === CHAR_ASTERISK || code === CHAR_QUESTION_MARK || code === CHAR_EXCLAMATION_MARK;
|
|
449
|
+
if (isExtglobChar === true && peek() === CHAR_LEFT_PARENTHESES) {
|
|
450
|
+
isGlob = token.isGlob = true;
|
|
451
|
+
isExtglob = token.isExtglob = true;
|
|
452
|
+
finished = true;
|
|
453
|
+
if (code === CHAR_EXCLAMATION_MARK && index === start) {
|
|
454
|
+
negatedExtglob = true;
|
|
455
|
+
}
|
|
456
|
+
if (scanToEnd === true) {
|
|
457
|
+
while (eos() !== true && (code = advance())) {
|
|
458
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
459
|
+
backslashes = token.backslashes = true;
|
|
460
|
+
code = advance();
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
if (code === CHAR_RIGHT_PARENTHESES) {
|
|
464
|
+
isGlob = token.isGlob = true;
|
|
465
|
+
finished = true;
|
|
466
|
+
break;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
break;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
if (code === CHAR_ASTERISK) {
|
|
475
|
+
if (prev === CHAR_ASTERISK) isGlobstar = token.isGlobstar = true;
|
|
476
|
+
isGlob = token.isGlob = true;
|
|
477
|
+
finished = true;
|
|
478
|
+
if (scanToEnd === true) {
|
|
479
|
+
continue;
|
|
480
|
+
}
|
|
481
|
+
break;
|
|
482
|
+
}
|
|
483
|
+
if (code === CHAR_QUESTION_MARK) {
|
|
484
|
+
isGlob = token.isGlob = true;
|
|
485
|
+
finished = true;
|
|
486
|
+
if (scanToEnd === true) {
|
|
487
|
+
continue;
|
|
488
|
+
}
|
|
489
|
+
break;
|
|
490
|
+
}
|
|
491
|
+
if (code === CHAR_LEFT_SQUARE_BRACKET) {
|
|
492
|
+
while (eos() !== true && (next = advance())) {
|
|
493
|
+
if (next === CHAR_BACKWARD_SLASH) {
|
|
494
|
+
backslashes = token.backslashes = true;
|
|
495
|
+
advance();
|
|
496
|
+
continue;
|
|
497
|
+
}
|
|
498
|
+
if (next === CHAR_RIGHT_SQUARE_BRACKET) {
|
|
499
|
+
isBracket = token.isBracket = true;
|
|
500
|
+
isGlob = token.isGlob = true;
|
|
501
|
+
finished = true;
|
|
502
|
+
break;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
if (scanToEnd === true) {
|
|
506
|
+
continue;
|
|
507
|
+
}
|
|
508
|
+
break;
|
|
509
|
+
}
|
|
510
|
+
if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) {
|
|
511
|
+
negated = token.negated = true;
|
|
512
|
+
start++;
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
|
|
516
|
+
isGlob = token.isGlob = true;
|
|
517
|
+
if (scanToEnd === true) {
|
|
518
|
+
while (eos() !== true && (code = advance())) {
|
|
519
|
+
if (code === CHAR_LEFT_PARENTHESES) {
|
|
520
|
+
backslashes = token.backslashes = true;
|
|
521
|
+
code = advance();
|
|
522
|
+
continue;
|
|
523
|
+
}
|
|
524
|
+
if (code === CHAR_RIGHT_PARENTHESES) {
|
|
525
|
+
finished = true;
|
|
526
|
+
break;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
continue;
|
|
530
|
+
}
|
|
531
|
+
break;
|
|
532
|
+
}
|
|
533
|
+
if (isGlob === true) {
|
|
534
|
+
finished = true;
|
|
535
|
+
if (scanToEnd === true) {
|
|
536
|
+
continue;
|
|
537
|
+
}
|
|
538
|
+
break;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
if (opts.noext === true) {
|
|
542
|
+
isExtglob = false;
|
|
543
|
+
isGlob = false;
|
|
544
|
+
}
|
|
545
|
+
let base = str;
|
|
546
|
+
let prefix = "";
|
|
547
|
+
let glob = "";
|
|
548
|
+
if (start > 0) {
|
|
549
|
+
prefix = str.slice(0, start);
|
|
550
|
+
str = str.slice(start);
|
|
551
|
+
lastIndex -= start;
|
|
552
|
+
}
|
|
553
|
+
if (base && isGlob === true && lastIndex > 0) {
|
|
554
|
+
base = str.slice(0, lastIndex);
|
|
555
|
+
glob = str.slice(lastIndex);
|
|
556
|
+
} else if (isGlob === true) {
|
|
557
|
+
base = "";
|
|
558
|
+
glob = str;
|
|
559
|
+
} else {
|
|
560
|
+
base = str;
|
|
561
|
+
}
|
|
562
|
+
if (base && base !== "" && base !== "/" && base !== str) {
|
|
563
|
+
if (isPathSeparator(base.charCodeAt(base.length - 1))) {
|
|
564
|
+
base = base.slice(0, -1);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
if (opts.unescape === true) {
|
|
568
|
+
if (glob) glob = utils.removeBackslashes(glob);
|
|
569
|
+
if (base && backslashes === true) {
|
|
570
|
+
base = utils.removeBackslashes(base);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
const state = {
|
|
574
|
+
prefix,
|
|
575
|
+
input,
|
|
576
|
+
start,
|
|
577
|
+
base,
|
|
578
|
+
glob,
|
|
579
|
+
isBrace,
|
|
580
|
+
isBracket,
|
|
581
|
+
isGlob,
|
|
582
|
+
isExtglob,
|
|
583
|
+
isGlobstar,
|
|
584
|
+
negated,
|
|
585
|
+
negatedExtglob
|
|
586
|
+
};
|
|
587
|
+
if (opts.tokens === true) {
|
|
588
|
+
state.maxDepth = 0;
|
|
589
|
+
if (!isPathSeparator(code)) {
|
|
590
|
+
tokens.push(token);
|
|
591
|
+
}
|
|
592
|
+
state.tokens = tokens;
|
|
593
|
+
}
|
|
594
|
+
if (opts.parts === true || opts.tokens === true) {
|
|
595
|
+
let prevIndex;
|
|
596
|
+
for (let idx = 0; idx < slashes.length; idx++) {
|
|
597
|
+
const n = prevIndex ? prevIndex + 1 : start;
|
|
598
|
+
const i = slashes[idx];
|
|
599
|
+
const value = input.slice(n, i);
|
|
600
|
+
if (opts.tokens) {
|
|
601
|
+
if (idx === 0 && start !== 0) {
|
|
602
|
+
tokens[idx].isPrefix = true;
|
|
603
|
+
tokens[idx].value = prefix;
|
|
604
|
+
} else {
|
|
605
|
+
tokens[idx].value = value;
|
|
606
|
+
}
|
|
607
|
+
depth(tokens[idx]);
|
|
608
|
+
state.maxDepth += tokens[idx].depth;
|
|
609
|
+
}
|
|
610
|
+
if (idx !== 0 || value !== "") {
|
|
611
|
+
parts.push(value);
|
|
612
|
+
}
|
|
613
|
+
prevIndex = i;
|
|
614
|
+
}
|
|
615
|
+
if (prevIndex && prevIndex + 1 < input.length) {
|
|
616
|
+
const value = input.slice(prevIndex + 1);
|
|
617
|
+
parts.push(value);
|
|
618
|
+
if (opts.tokens) {
|
|
619
|
+
tokens[tokens.length - 1].value = value;
|
|
620
|
+
depth(tokens[tokens.length - 1]);
|
|
621
|
+
state.maxDepth += tokens[tokens.length - 1].depth;
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
state.slashes = slashes;
|
|
625
|
+
state.parts = parts;
|
|
626
|
+
}
|
|
627
|
+
return state;
|
|
628
|
+
};
|
|
629
|
+
scan_1 = scan;
|
|
630
|
+
return scan_1;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
var parse_1;
|
|
634
|
+
var hasRequiredParse;
|
|
635
|
+
|
|
636
|
+
function requireParse () {
|
|
637
|
+
if (hasRequiredParse) return parse_1;
|
|
638
|
+
hasRequiredParse = 1;
|
|
639
|
+
const constants = /*@__PURE__*/ requireConstants();
|
|
640
|
+
const utils = /*@__PURE__*/ requireUtils();
|
|
641
|
+
const {
|
|
642
|
+
MAX_LENGTH,
|
|
643
|
+
POSIX_REGEX_SOURCE,
|
|
644
|
+
REGEX_NON_SPECIAL_CHARS,
|
|
645
|
+
REGEX_SPECIAL_CHARS_BACKREF,
|
|
646
|
+
REPLACEMENTS
|
|
647
|
+
} = constants;
|
|
648
|
+
const expandRange = (args, options) => {
|
|
649
|
+
if (typeof options.expandRange === "function") {
|
|
650
|
+
return options.expandRange(...args, options);
|
|
651
|
+
}
|
|
652
|
+
args.sort();
|
|
653
|
+
const value = `[${args.join("-")}]`;
|
|
654
|
+
try {
|
|
655
|
+
new RegExp(value);
|
|
656
|
+
} catch (ex) {
|
|
657
|
+
return args.map((v) => utils.escapeRegex(v)).join("..");
|
|
658
|
+
}
|
|
659
|
+
return value;
|
|
660
|
+
};
|
|
661
|
+
const syntaxError = (type, char) => {
|
|
662
|
+
return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
|
|
663
|
+
};
|
|
664
|
+
const parse = (input, options) => {
|
|
665
|
+
if (typeof input !== "string") {
|
|
666
|
+
throw new TypeError("Expected a string");
|
|
667
|
+
}
|
|
668
|
+
input = REPLACEMENTS[input] || input;
|
|
669
|
+
const opts = { ...options };
|
|
670
|
+
const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
671
|
+
let len = input.length;
|
|
672
|
+
if (len > max) {
|
|
673
|
+
throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
|
674
|
+
}
|
|
675
|
+
const bos = { type: "bos", value: "", output: opts.prepend || "" };
|
|
676
|
+
const tokens = [bos];
|
|
677
|
+
const capture = opts.capture ? "" : "?:";
|
|
678
|
+
const PLATFORM_CHARS = constants.globChars(opts.windows);
|
|
679
|
+
const EXTGLOB_CHARS = constants.extglobChars(PLATFORM_CHARS);
|
|
680
|
+
const {
|
|
681
|
+
DOT_LITERAL,
|
|
682
|
+
PLUS_LITERAL,
|
|
683
|
+
SLASH_LITERAL,
|
|
684
|
+
ONE_CHAR,
|
|
685
|
+
DOTS_SLASH,
|
|
686
|
+
NO_DOT,
|
|
687
|
+
NO_DOT_SLASH,
|
|
688
|
+
NO_DOTS_SLASH,
|
|
689
|
+
QMARK,
|
|
690
|
+
QMARK_NO_DOT,
|
|
691
|
+
STAR,
|
|
692
|
+
START_ANCHOR
|
|
693
|
+
} = PLATFORM_CHARS;
|
|
694
|
+
const globstar = (opts2) => {
|
|
695
|
+
return `(${capture}(?:(?!${START_ANCHOR}${opts2.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
|
|
696
|
+
};
|
|
697
|
+
const nodot = opts.dot ? "" : NO_DOT;
|
|
698
|
+
const qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT;
|
|
699
|
+
let star = opts.bash === true ? globstar(opts) : STAR;
|
|
700
|
+
if (opts.capture) {
|
|
701
|
+
star = `(${star})`;
|
|
702
|
+
}
|
|
703
|
+
if (typeof opts.noext === "boolean") {
|
|
704
|
+
opts.noextglob = opts.noext;
|
|
705
|
+
}
|
|
706
|
+
const state = {
|
|
707
|
+
input,
|
|
708
|
+
index: -1,
|
|
709
|
+
start: 0,
|
|
710
|
+
dot: opts.dot === true,
|
|
711
|
+
consumed: "",
|
|
712
|
+
output: "",
|
|
713
|
+
prefix: "",
|
|
714
|
+
backtrack: false,
|
|
715
|
+
negated: false,
|
|
716
|
+
brackets: 0,
|
|
717
|
+
braces: 0,
|
|
718
|
+
parens: 0,
|
|
719
|
+
quotes: 0,
|
|
720
|
+
globstar: false,
|
|
721
|
+
tokens
|
|
722
|
+
};
|
|
723
|
+
input = utils.removePrefix(input, state);
|
|
724
|
+
len = input.length;
|
|
725
|
+
const extglobs = [];
|
|
726
|
+
const braces = [];
|
|
727
|
+
const stack = [];
|
|
728
|
+
let prev = bos;
|
|
729
|
+
let value;
|
|
730
|
+
const eos = () => state.index === len - 1;
|
|
731
|
+
const peek = state.peek = (n = 1) => input[state.index + n];
|
|
732
|
+
const advance = state.advance = () => input[++state.index] || "";
|
|
733
|
+
const remaining = () => input.slice(state.index + 1);
|
|
734
|
+
const consume = (value2 = "", num = 0) => {
|
|
735
|
+
state.consumed += value2;
|
|
736
|
+
state.index += num;
|
|
737
|
+
};
|
|
738
|
+
const append = (token) => {
|
|
739
|
+
state.output += token.output != null ? token.output : token.value;
|
|
740
|
+
consume(token.value);
|
|
741
|
+
};
|
|
742
|
+
const negate = () => {
|
|
743
|
+
let count = 1;
|
|
744
|
+
while (peek() === "!" && (peek(2) !== "(" || peek(3) === "?")) {
|
|
745
|
+
advance();
|
|
746
|
+
state.start++;
|
|
747
|
+
count++;
|
|
748
|
+
}
|
|
749
|
+
if (count % 2 === 0) {
|
|
750
|
+
return false;
|
|
751
|
+
}
|
|
752
|
+
state.negated = true;
|
|
753
|
+
state.start++;
|
|
754
|
+
return true;
|
|
755
|
+
};
|
|
756
|
+
const increment = (type) => {
|
|
757
|
+
state[type]++;
|
|
758
|
+
stack.push(type);
|
|
759
|
+
};
|
|
760
|
+
const decrement = (type) => {
|
|
761
|
+
state[type]--;
|
|
762
|
+
stack.pop();
|
|
763
|
+
};
|
|
764
|
+
const push = (tok) => {
|
|
765
|
+
if (prev.type === "globstar") {
|
|
766
|
+
const isBrace = state.braces > 0 && (tok.type === "comma" || tok.type === "brace");
|
|
767
|
+
const isExtglob = tok.extglob === true || extglobs.length && (tok.type === "pipe" || tok.type === "paren");
|
|
768
|
+
if (tok.type !== "slash" && tok.type !== "paren" && !isBrace && !isExtglob) {
|
|
769
|
+
state.output = state.output.slice(0, -prev.output.length);
|
|
770
|
+
prev.type = "star";
|
|
771
|
+
prev.value = "*";
|
|
772
|
+
prev.output = star;
|
|
773
|
+
state.output += prev.output;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
if (extglobs.length && tok.type !== "paren") {
|
|
777
|
+
extglobs[extglobs.length - 1].inner += tok.value;
|
|
778
|
+
}
|
|
779
|
+
if (tok.value || tok.output) append(tok);
|
|
780
|
+
if (prev && prev.type === "text" && tok.type === "text") {
|
|
781
|
+
prev.output = (prev.output || prev.value) + tok.value;
|
|
782
|
+
prev.value += tok.value;
|
|
783
|
+
return;
|
|
784
|
+
}
|
|
785
|
+
tok.prev = prev;
|
|
786
|
+
tokens.push(tok);
|
|
787
|
+
prev = tok;
|
|
788
|
+
};
|
|
789
|
+
const extglobOpen = (type, value2) => {
|
|
790
|
+
const token = { ...EXTGLOB_CHARS[value2], conditions: 1, inner: "" };
|
|
791
|
+
token.prev = prev;
|
|
792
|
+
token.parens = state.parens;
|
|
793
|
+
token.output = state.output;
|
|
794
|
+
const output = (opts.capture ? "(" : "") + token.open;
|
|
795
|
+
increment("parens");
|
|
796
|
+
push({ type, value: value2, output: state.output ? "" : ONE_CHAR });
|
|
797
|
+
push({ type: "paren", extglob: true, value: advance(), output });
|
|
798
|
+
extglobs.push(token);
|
|
799
|
+
};
|
|
800
|
+
const extglobClose = (token) => {
|
|
801
|
+
let output = token.close + (opts.capture ? ")" : "");
|
|
802
|
+
let rest;
|
|
803
|
+
if (token.type === "negate") {
|
|
804
|
+
let extglobStar = star;
|
|
805
|
+
if (token.inner && token.inner.length > 1 && token.inner.includes("/")) {
|
|
806
|
+
extglobStar = globstar(opts);
|
|
807
|
+
}
|
|
808
|
+
if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) {
|
|
809
|
+
output = token.close = `)$))${extglobStar}`;
|
|
810
|
+
}
|
|
811
|
+
if (token.inner.includes("*") && (rest = remaining()) && /^\.[^\\/.]+$/.test(rest)) {
|
|
812
|
+
const expression = parse(rest, { ...options, fastpaths: false }).output;
|
|
813
|
+
output = token.close = `)${expression})${extglobStar})`;
|
|
814
|
+
}
|
|
815
|
+
if (token.prev.type === "bos") {
|
|
816
|
+
state.negatedExtglob = true;
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
push({ type: "paren", extglob: true, value, output });
|
|
820
|
+
decrement("parens");
|
|
821
|
+
};
|
|
822
|
+
if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) {
|
|
823
|
+
let backslashes = false;
|
|
824
|
+
let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
|
|
825
|
+
if (first === "\\") {
|
|
826
|
+
backslashes = true;
|
|
827
|
+
return m;
|
|
828
|
+
}
|
|
829
|
+
if (first === "?") {
|
|
830
|
+
if (esc) {
|
|
831
|
+
return esc + first + (rest ? QMARK.repeat(rest.length) : "");
|
|
832
|
+
}
|
|
833
|
+
if (index === 0) {
|
|
834
|
+
return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : "");
|
|
835
|
+
}
|
|
836
|
+
return QMARK.repeat(chars.length);
|
|
837
|
+
}
|
|
838
|
+
if (first === ".") {
|
|
839
|
+
return DOT_LITERAL.repeat(chars.length);
|
|
840
|
+
}
|
|
841
|
+
if (first === "*") {
|
|
842
|
+
if (esc) {
|
|
843
|
+
return esc + first + (rest ? star : "");
|
|
844
|
+
}
|
|
845
|
+
return star;
|
|
846
|
+
}
|
|
847
|
+
return esc ? m : `\\${m}`;
|
|
848
|
+
});
|
|
849
|
+
if (backslashes === true) {
|
|
850
|
+
if (opts.unescape === true) {
|
|
851
|
+
output = output.replace(/\\/g, "");
|
|
852
|
+
} else {
|
|
853
|
+
output = output.replace(/\\+/g, (m) => {
|
|
854
|
+
return m.length % 2 === 0 ? "\\\\" : m ? "\\" : "";
|
|
855
|
+
});
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
if (output === input && opts.contains === true) {
|
|
859
|
+
state.output = input;
|
|
860
|
+
return state;
|
|
861
|
+
}
|
|
862
|
+
state.output = utils.wrapOutput(output, state, options);
|
|
863
|
+
return state;
|
|
864
|
+
}
|
|
865
|
+
while (!eos()) {
|
|
866
|
+
value = advance();
|
|
867
|
+
if (value === "\0") {
|
|
868
|
+
continue;
|
|
869
|
+
}
|
|
870
|
+
if (value === "\\") {
|
|
871
|
+
const next = peek();
|
|
872
|
+
if (next === "/" && opts.bash !== true) {
|
|
873
|
+
continue;
|
|
874
|
+
}
|
|
875
|
+
if (next === "." || next === ";") {
|
|
876
|
+
continue;
|
|
877
|
+
}
|
|
878
|
+
if (!next) {
|
|
879
|
+
value += "\\";
|
|
880
|
+
push({ type: "text", value });
|
|
881
|
+
continue;
|
|
882
|
+
}
|
|
883
|
+
const match = /^\\+/.exec(remaining());
|
|
884
|
+
let slashes = 0;
|
|
885
|
+
if (match && match[0].length > 2) {
|
|
886
|
+
slashes = match[0].length;
|
|
887
|
+
state.index += slashes;
|
|
888
|
+
if (slashes % 2 !== 0) {
|
|
889
|
+
value += "\\";
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
if (opts.unescape === true) {
|
|
893
|
+
value = advance();
|
|
894
|
+
} else {
|
|
895
|
+
value += advance();
|
|
896
|
+
}
|
|
897
|
+
if (state.brackets === 0) {
|
|
898
|
+
push({ type: "text", value });
|
|
899
|
+
continue;
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
if (state.brackets > 0 && (value !== "]" || prev.value === "[" || prev.value === "[^")) {
|
|
903
|
+
if (opts.posix !== false && value === ":") {
|
|
904
|
+
const inner = prev.value.slice(1);
|
|
905
|
+
if (inner.includes("[")) {
|
|
906
|
+
prev.posix = true;
|
|
907
|
+
if (inner.includes(":")) {
|
|
908
|
+
const idx = prev.value.lastIndexOf("[");
|
|
909
|
+
const pre = prev.value.slice(0, idx);
|
|
910
|
+
const rest2 = prev.value.slice(idx + 2);
|
|
911
|
+
const posix = POSIX_REGEX_SOURCE[rest2];
|
|
912
|
+
if (posix) {
|
|
913
|
+
prev.value = pre + posix;
|
|
914
|
+
state.backtrack = true;
|
|
915
|
+
advance();
|
|
916
|
+
if (!bos.output && tokens.indexOf(prev) === 1) {
|
|
917
|
+
bos.output = ONE_CHAR;
|
|
918
|
+
}
|
|
919
|
+
continue;
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
if (value === "[" && peek() !== ":" || value === "-" && peek() === "]") {
|
|
925
|
+
value = `\\${value}`;
|
|
926
|
+
}
|
|
927
|
+
if (value === "]" && (prev.value === "[" || prev.value === "[^")) {
|
|
928
|
+
value = `\\${value}`;
|
|
929
|
+
}
|
|
930
|
+
if (opts.posix === true && value === "!" && prev.value === "[") {
|
|
931
|
+
value = "^";
|
|
932
|
+
}
|
|
933
|
+
prev.value += value;
|
|
934
|
+
append({ value });
|
|
935
|
+
continue;
|
|
936
|
+
}
|
|
937
|
+
if (state.quotes === 1 && value !== '"') {
|
|
938
|
+
value = utils.escapeRegex(value);
|
|
939
|
+
prev.value += value;
|
|
940
|
+
append({ value });
|
|
941
|
+
continue;
|
|
942
|
+
}
|
|
943
|
+
if (value === '"') {
|
|
944
|
+
state.quotes = state.quotes === 1 ? 0 : 1;
|
|
945
|
+
if (opts.keepQuotes === true) {
|
|
946
|
+
push({ type: "text", value });
|
|
947
|
+
}
|
|
948
|
+
continue;
|
|
949
|
+
}
|
|
950
|
+
if (value === "(") {
|
|
951
|
+
increment("parens");
|
|
952
|
+
push({ type: "paren", value });
|
|
953
|
+
continue;
|
|
954
|
+
}
|
|
955
|
+
if (value === ")") {
|
|
956
|
+
if (state.parens === 0 && opts.strictBrackets === true) {
|
|
957
|
+
throw new SyntaxError(syntaxError("opening", "("));
|
|
958
|
+
}
|
|
959
|
+
const extglob = extglobs[extglobs.length - 1];
|
|
960
|
+
if (extglob && state.parens === extglob.parens + 1) {
|
|
961
|
+
extglobClose(extglobs.pop());
|
|
962
|
+
continue;
|
|
963
|
+
}
|
|
964
|
+
push({ type: "paren", value, output: state.parens ? ")" : "\\)" });
|
|
965
|
+
decrement("parens");
|
|
966
|
+
continue;
|
|
967
|
+
}
|
|
968
|
+
if (value === "[") {
|
|
969
|
+
if (opts.nobracket === true || !remaining().includes("]")) {
|
|
970
|
+
if (opts.nobracket !== true && opts.strictBrackets === true) {
|
|
971
|
+
throw new SyntaxError(syntaxError("closing", "]"));
|
|
972
|
+
}
|
|
973
|
+
value = `\\${value}`;
|
|
974
|
+
} else {
|
|
975
|
+
increment("brackets");
|
|
976
|
+
}
|
|
977
|
+
push({ type: "bracket", value });
|
|
978
|
+
continue;
|
|
979
|
+
}
|
|
980
|
+
if (value === "]") {
|
|
981
|
+
if (opts.nobracket === true || prev && prev.type === "bracket" && prev.value.length === 1) {
|
|
982
|
+
push({ type: "text", value, output: `\\${value}` });
|
|
983
|
+
continue;
|
|
984
|
+
}
|
|
985
|
+
if (state.brackets === 0) {
|
|
986
|
+
if (opts.strictBrackets === true) {
|
|
987
|
+
throw new SyntaxError(syntaxError("opening", "["));
|
|
988
|
+
}
|
|
989
|
+
push({ type: "text", value, output: `\\${value}` });
|
|
990
|
+
continue;
|
|
991
|
+
}
|
|
992
|
+
decrement("brackets");
|
|
993
|
+
const prevValue = prev.value.slice(1);
|
|
994
|
+
if (prev.posix !== true && prevValue[0] === "^" && !prevValue.includes("/")) {
|
|
995
|
+
value = `/${value}`;
|
|
996
|
+
}
|
|
997
|
+
prev.value += value;
|
|
998
|
+
append({ value });
|
|
999
|
+
if (opts.literalBrackets === false || utils.hasRegexChars(prevValue)) {
|
|
1000
|
+
continue;
|
|
1001
|
+
}
|
|
1002
|
+
const escaped = utils.escapeRegex(prev.value);
|
|
1003
|
+
state.output = state.output.slice(0, -prev.value.length);
|
|
1004
|
+
if (opts.literalBrackets === true) {
|
|
1005
|
+
state.output += escaped;
|
|
1006
|
+
prev.value = escaped;
|
|
1007
|
+
continue;
|
|
1008
|
+
}
|
|
1009
|
+
prev.value = `(${capture}${escaped}|${prev.value})`;
|
|
1010
|
+
state.output += prev.value;
|
|
1011
|
+
continue;
|
|
1012
|
+
}
|
|
1013
|
+
if (value === "{" && opts.nobrace !== true) {
|
|
1014
|
+
increment("braces");
|
|
1015
|
+
const open = {
|
|
1016
|
+
type: "brace",
|
|
1017
|
+
value,
|
|
1018
|
+
output: "(",
|
|
1019
|
+
outputIndex: state.output.length,
|
|
1020
|
+
tokensIndex: state.tokens.length
|
|
1021
|
+
};
|
|
1022
|
+
braces.push(open);
|
|
1023
|
+
push(open);
|
|
1024
|
+
continue;
|
|
1025
|
+
}
|
|
1026
|
+
if (value === "}") {
|
|
1027
|
+
const brace = braces[braces.length - 1];
|
|
1028
|
+
if (opts.nobrace === true || !brace) {
|
|
1029
|
+
push({ type: "text", value, output: value });
|
|
1030
|
+
continue;
|
|
1031
|
+
}
|
|
1032
|
+
let output = ")";
|
|
1033
|
+
if (brace.dots === true) {
|
|
1034
|
+
const arr = tokens.slice();
|
|
1035
|
+
const range = [];
|
|
1036
|
+
for (let i = arr.length - 1; i >= 0; i--) {
|
|
1037
|
+
tokens.pop();
|
|
1038
|
+
if (arr[i].type === "brace") {
|
|
1039
|
+
break;
|
|
1040
|
+
}
|
|
1041
|
+
if (arr[i].type !== "dots") {
|
|
1042
|
+
range.unshift(arr[i].value);
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
output = expandRange(range, opts);
|
|
1046
|
+
state.backtrack = true;
|
|
1047
|
+
}
|
|
1048
|
+
if (brace.comma !== true && brace.dots !== true) {
|
|
1049
|
+
const out = state.output.slice(0, brace.outputIndex);
|
|
1050
|
+
const toks = state.tokens.slice(brace.tokensIndex);
|
|
1051
|
+
brace.value = brace.output = "\\{";
|
|
1052
|
+
value = output = "\\}";
|
|
1053
|
+
state.output = out;
|
|
1054
|
+
for (const t of toks) {
|
|
1055
|
+
state.output += t.output || t.value;
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
push({ type: "brace", value, output });
|
|
1059
|
+
decrement("braces");
|
|
1060
|
+
braces.pop();
|
|
1061
|
+
continue;
|
|
1062
|
+
}
|
|
1063
|
+
if (value === "|") {
|
|
1064
|
+
if (extglobs.length > 0) {
|
|
1065
|
+
extglobs[extglobs.length - 1].conditions++;
|
|
1066
|
+
}
|
|
1067
|
+
push({ type: "text", value });
|
|
1068
|
+
continue;
|
|
1069
|
+
}
|
|
1070
|
+
if (value === ",") {
|
|
1071
|
+
let output = value;
|
|
1072
|
+
const brace = braces[braces.length - 1];
|
|
1073
|
+
if (brace && stack[stack.length - 1] === "braces") {
|
|
1074
|
+
brace.comma = true;
|
|
1075
|
+
output = "|";
|
|
1076
|
+
}
|
|
1077
|
+
push({ type: "comma", value, output });
|
|
1078
|
+
continue;
|
|
1079
|
+
}
|
|
1080
|
+
if (value === "/") {
|
|
1081
|
+
if (prev.type === "dot" && state.index === state.start + 1) {
|
|
1082
|
+
state.start = state.index + 1;
|
|
1083
|
+
state.consumed = "";
|
|
1084
|
+
state.output = "";
|
|
1085
|
+
tokens.pop();
|
|
1086
|
+
prev = bos;
|
|
1087
|
+
continue;
|
|
1088
|
+
}
|
|
1089
|
+
push({ type: "slash", value, output: SLASH_LITERAL });
|
|
1090
|
+
continue;
|
|
1091
|
+
}
|
|
1092
|
+
if (value === ".") {
|
|
1093
|
+
if (state.braces > 0 && prev.type === "dot") {
|
|
1094
|
+
if (prev.value === ".") prev.output = DOT_LITERAL;
|
|
1095
|
+
const brace = braces[braces.length - 1];
|
|
1096
|
+
prev.type = "dots";
|
|
1097
|
+
prev.output += value;
|
|
1098
|
+
prev.value += value;
|
|
1099
|
+
brace.dots = true;
|
|
1100
|
+
continue;
|
|
1101
|
+
}
|
|
1102
|
+
if (state.braces + state.parens === 0 && prev.type !== "bos" && prev.type !== "slash") {
|
|
1103
|
+
push({ type: "text", value, output: DOT_LITERAL });
|
|
1104
|
+
continue;
|
|
1105
|
+
}
|
|
1106
|
+
push({ type: "dot", value, output: DOT_LITERAL });
|
|
1107
|
+
continue;
|
|
1108
|
+
}
|
|
1109
|
+
if (value === "?") {
|
|
1110
|
+
const isGroup = prev && prev.value === "(";
|
|
1111
|
+
if (!isGroup && opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
1112
|
+
extglobOpen("qmark", value);
|
|
1113
|
+
continue;
|
|
1114
|
+
}
|
|
1115
|
+
if (prev && prev.type === "paren") {
|
|
1116
|
+
const next = peek();
|
|
1117
|
+
let output = value;
|
|
1118
|
+
if (prev.value === "(" && !/[!=<:]/.test(next) || next === "<" && !/<([!=]|\w+>)/.test(remaining())) {
|
|
1119
|
+
output = `\\${value}`;
|
|
1120
|
+
}
|
|
1121
|
+
push({ type: "text", value, output });
|
|
1122
|
+
continue;
|
|
1123
|
+
}
|
|
1124
|
+
if (opts.dot !== true && (prev.type === "slash" || prev.type === "bos")) {
|
|
1125
|
+
push({ type: "qmark", value, output: QMARK_NO_DOT });
|
|
1126
|
+
continue;
|
|
1127
|
+
}
|
|
1128
|
+
push({ type: "qmark", value, output: QMARK });
|
|
1129
|
+
continue;
|
|
1130
|
+
}
|
|
1131
|
+
if (value === "!") {
|
|
1132
|
+
if (opts.noextglob !== true && peek() === "(") {
|
|
1133
|
+
if (peek(2) !== "?" || !/[!=<:]/.test(peek(3))) {
|
|
1134
|
+
extglobOpen("negate", value);
|
|
1135
|
+
continue;
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
if (opts.nonegate !== true && state.index === 0) {
|
|
1139
|
+
negate();
|
|
1140
|
+
continue;
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
if (value === "+") {
|
|
1144
|
+
if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
1145
|
+
extglobOpen("plus", value);
|
|
1146
|
+
continue;
|
|
1147
|
+
}
|
|
1148
|
+
if (prev && prev.value === "(" || opts.regex === false) {
|
|
1149
|
+
push({ type: "plus", value, output: PLUS_LITERAL });
|
|
1150
|
+
continue;
|
|
1151
|
+
}
|
|
1152
|
+
if (prev && (prev.type === "bracket" || prev.type === "paren" || prev.type === "brace") || state.parens > 0) {
|
|
1153
|
+
push({ type: "plus", value });
|
|
1154
|
+
continue;
|
|
1155
|
+
}
|
|
1156
|
+
push({ type: "plus", value: PLUS_LITERAL });
|
|
1157
|
+
continue;
|
|
1158
|
+
}
|
|
1159
|
+
if (value === "@") {
|
|
1160
|
+
if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
1161
|
+
push({ type: "at", extglob: true, value, output: "" });
|
|
1162
|
+
continue;
|
|
1163
|
+
}
|
|
1164
|
+
push({ type: "text", value });
|
|
1165
|
+
continue;
|
|
1166
|
+
}
|
|
1167
|
+
if (value !== "*") {
|
|
1168
|
+
if (value === "$" || value === "^") {
|
|
1169
|
+
value = `\\${value}`;
|
|
1170
|
+
}
|
|
1171
|
+
const match = REGEX_NON_SPECIAL_CHARS.exec(remaining());
|
|
1172
|
+
if (match) {
|
|
1173
|
+
value += match[0];
|
|
1174
|
+
state.index += match[0].length;
|
|
1175
|
+
}
|
|
1176
|
+
push({ type: "text", value });
|
|
1177
|
+
continue;
|
|
1178
|
+
}
|
|
1179
|
+
if (prev && (prev.type === "globstar" || prev.star === true)) {
|
|
1180
|
+
prev.type = "star";
|
|
1181
|
+
prev.star = true;
|
|
1182
|
+
prev.value += value;
|
|
1183
|
+
prev.output = star;
|
|
1184
|
+
state.backtrack = true;
|
|
1185
|
+
state.globstar = true;
|
|
1186
|
+
consume(value);
|
|
1187
|
+
continue;
|
|
1188
|
+
}
|
|
1189
|
+
let rest = remaining();
|
|
1190
|
+
if (opts.noextglob !== true && /^\([^?]/.test(rest)) {
|
|
1191
|
+
extglobOpen("star", value);
|
|
1192
|
+
continue;
|
|
1193
|
+
}
|
|
1194
|
+
if (prev.type === "star") {
|
|
1195
|
+
if (opts.noglobstar === true) {
|
|
1196
|
+
consume(value);
|
|
1197
|
+
continue;
|
|
1198
|
+
}
|
|
1199
|
+
const prior = prev.prev;
|
|
1200
|
+
const before = prior.prev;
|
|
1201
|
+
const isStart = prior.type === "slash" || prior.type === "bos";
|
|
1202
|
+
const afterStar = before && (before.type === "star" || before.type === "globstar");
|
|
1203
|
+
if (opts.bash === true && (!isStart || rest[0] && rest[0] !== "/")) {
|
|
1204
|
+
push({ type: "star", value, output: "" });
|
|
1205
|
+
continue;
|
|
1206
|
+
}
|
|
1207
|
+
const isBrace = state.braces > 0 && (prior.type === "comma" || prior.type === "brace");
|
|
1208
|
+
const isExtglob = extglobs.length && (prior.type === "pipe" || prior.type === "paren");
|
|
1209
|
+
if (!isStart && prior.type !== "paren" && !isBrace && !isExtglob) {
|
|
1210
|
+
push({ type: "star", value, output: "" });
|
|
1211
|
+
continue;
|
|
1212
|
+
}
|
|
1213
|
+
while (rest.slice(0, 3) === "/**") {
|
|
1214
|
+
const after = input[state.index + 4];
|
|
1215
|
+
if (after && after !== "/") {
|
|
1216
|
+
break;
|
|
1217
|
+
}
|
|
1218
|
+
rest = rest.slice(3);
|
|
1219
|
+
consume("/**", 3);
|
|
1220
|
+
}
|
|
1221
|
+
if (prior.type === "bos" && eos()) {
|
|
1222
|
+
prev.type = "globstar";
|
|
1223
|
+
prev.value += value;
|
|
1224
|
+
prev.output = globstar(opts);
|
|
1225
|
+
state.output = prev.output;
|
|
1226
|
+
state.globstar = true;
|
|
1227
|
+
consume(value);
|
|
1228
|
+
continue;
|
|
1229
|
+
}
|
|
1230
|
+
if (prior.type === "slash" && prior.prev.type !== "bos" && !afterStar && eos()) {
|
|
1231
|
+
state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
|
1232
|
+
prior.output = `(?:${prior.output}`;
|
|
1233
|
+
prev.type = "globstar";
|
|
1234
|
+
prev.output = globstar(opts) + (opts.strictSlashes ? ")" : "|$)");
|
|
1235
|
+
prev.value += value;
|
|
1236
|
+
state.globstar = true;
|
|
1237
|
+
state.output += prior.output + prev.output;
|
|
1238
|
+
consume(value);
|
|
1239
|
+
continue;
|
|
1240
|
+
}
|
|
1241
|
+
if (prior.type === "slash" && prior.prev.type !== "bos" && rest[0] === "/") {
|
|
1242
|
+
const end = rest[1] !== void 0 ? "|$" : "";
|
|
1243
|
+
state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
|
1244
|
+
prior.output = `(?:${prior.output}`;
|
|
1245
|
+
prev.type = "globstar";
|
|
1246
|
+
prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`;
|
|
1247
|
+
prev.value += value;
|
|
1248
|
+
state.output += prior.output + prev.output;
|
|
1249
|
+
state.globstar = true;
|
|
1250
|
+
consume(value + advance());
|
|
1251
|
+
push({ type: "slash", value: "/", output: "" });
|
|
1252
|
+
continue;
|
|
1253
|
+
}
|
|
1254
|
+
if (prior.type === "bos" && rest[0] === "/") {
|
|
1255
|
+
prev.type = "globstar";
|
|
1256
|
+
prev.value += value;
|
|
1257
|
+
prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`;
|
|
1258
|
+
state.output = prev.output;
|
|
1259
|
+
state.globstar = true;
|
|
1260
|
+
consume(value + advance());
|
|
1261
|
+
push({ type: "slash", value: "/", output: "" });
|
|
1262
|
+
continue;
|
|
1263
|
+
}
|
|
1264
|
+
state.output = state.output.slice(0, -prev.output.length);
|
|
1265
|
+
prev.type = "globstar";
|
|
1266
|
+
prev.output = globstar(opts);
|
|
1267
|
+
prev.value += value;
|
|
1268
|
+
state.output += prev.output;
|
|
1269
|
+
state.globstar = true;
|
|
1270
|
+
consume(value);
|
|
1271
|
+
continue;
|
|
1272
|
+
}
|
|
1273
|
+
const token = { type: "star", value, output: star };
|
|
1274
|
+
if (opts.bash === true) {
|
|
1275
|
+
token.output = ".*?";
|
|
1276
|
+
if (prev.type === "bos" || prev.type === "slash") {
|
|
1277
|
+
token.output = nodot + token.output;
|
|
1278
|
+
}
|
|
1279
|
+
push(token);
|
|
1280
|
+
continue;
|
|
1281
|
+
}
|
|
1282
|
+
if (prev && (prev.type === "bracket" || prev.type === "paren") && opts.regex === true) {
|
|
1283
|
+
token.output = value;
|
|
1284
|
+
push(token);
|
|
1285
|
+
continue;
|
|
1286
|
+
}
|
|
1287
|
+
if (state.index === state.start || prev.type === "slash" || prev.type === "dot") {
|
|
1288
|
+
if (prev.type === "dot") {
|
|
1289
|
+
state.output += NO_DOT_SLASH;
|
|
1290
|
+
prev.output += NO_DOT_SLASH;
|
|
1291
|
+
} else if (opts.dot === true) {
|
|
1292
|
+
state.output += NO_DOTS_SLASH;
|
|
1293
|
+
prev.output += NO_DOTS_SLASH;
|
|
1294
|
+
} else {
|
|
1295
|
+
state.output += nodot;
|
|
1296
|
+
prev.output += nodot;
|
|
1297
|
+
}
|
|
1298
|
+
if (peek() !== "*") {
|
|
1299
|
+
state.output += ONE_CHAR;
|
|
1300
|
+
prev.output += ONE_CHAR;
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
push(token);
|
|
1304
|
+
}
|
|
1305
|
+
while (state.brackets > 0) {
|
|
1306
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "]"));
|
|
1307
|
+
state.output = utils.escapeLast(state.output, "[");
|
|
1308
|
+
decrement("brackets");
|
|
1309
|
+
}
|
|
1310
|
+
while (state.parens > 0) {
|
|
1311
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", ")"));
|
|
1312
|
+
state.output = utils.escapeLast(state.output, "(");
|
|
1313
|
+
decrement("parens");
|
|
1314
|
+
}
|
|
1315
|
+
while (state.braces > 0) {
|
|
1316
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "}"));
|
|
1317
|
+
state.output = utils.escapeLast(state.output, "{");
|
|
1318
|
+
decrement("braces");
|
|
1319
|
+
}
|
|
1320
|
+
if (opts.strictSlashes !== true && (prev.type === "star" || prev.type === "bracket")) {
|
|
1321
|
+
push({ type: "maybe_slash", value: "", output: `${SLASH_LITERAL}?` });
|
|
1322
|
+
}
|
|
1323
|
+
if (state.backtrack === true) {
|
|
1324
|
+
state.output = "";
|
|
1325
|
+
for (const token of state.tokens) {
|
|
1326
|
+
state.output += token.output != null ? token.output : token.value;
|
|
1327
|
+
if (token.suffix) {
|
|
1328
|
+
state.output += token.suffix;
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
return state;
|
|
1333
|
+
};
|
|
1334
|
+
parse.fastpaths = (input, options) => {
|
|
1335
|
+
const opts = { ...options };
|
|
1336
|
+
const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
1337
|
+
const len = input.length;
|
|
1338
|
+
if (len > max) {
|
|
1339
|
+
throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
|
1340
|
+
}
|
|
1341
|
+
input = REPLACEMENTS[input] || input;
|
|
1342
|
+
const {
|
|
1343
|
+
DOT_LITERAL,
|
|
1344
|
+
SLASH_LITERAL,
|
|
1345
|
+
ONE_CHAR,
|
|
1346
|
+
DOTS_SLASH,
|
|
1347
|
+
NO_DOT,
|
|
1348
|
+
NO_DOTS,
|
|
1349
|
+
NO_DOTS_SLASH,
|
|
1350
|
+
STAR,
|
|
1351
|
+
START_ANCHOR
|
|
1352
|
+
} = constants.globChars(opts.windows);
|
|
1353
|
+
const nodot = opts.dot ? NO_DOTS : NO_DOT;
|
|
1354
|
+
const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
|
|
1355
|
+
const capture = opts.capture ? "" : "?:";
|
|
1356
|
+
const state = { negated: false, prefix: "" };
|
|
1357
|
+
let star = opts.bash === true ? ".*?" : STAR;
|
|
1358
|
+
if (opts.capture) {
|
|
1359
|
+
star = `(${star})`;
|
|
1360
|
+
}
|
|
1361
|
+
const globstar = (opts2) => {
|
|
1362
|
+
if (opts2.noglobstar === true) return star;
|
|
1363
|
+
return `(${capture}(?:(?!${START_ANCHOR}${opts2.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
|
|
1364
|
+
};
|
|
1365
|
+
const create = (str) => {
|
|
1366
|
+
switch (str) {
|
|
1367
|
+
case "*":
|
|
1368
|
+
return `${nodot}${ONE_CHAR}${star}`;
|
|
1369
|
+
case ".*":
|
|
1370
|
+
return `${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
1371
|
+
case "*.*":
|
|
1372
|
+
return `${nodot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
1373
|
+
case "*/*":
|
|
1374
|
+
return `${nodot}${star}${SLASH_LITERAL}${ONE_CHAR}${slashDot}${star}`;
|
|
1375
|
+
case "**":
|
|
1376
|
+
return nodot + globstar(opts);
|
|
1377
|
+
case "**/*":
|
|
1378
|
+
return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${ONE_CHAR}${star}`;
|
|
1379
|
+
case "**/*.*":
|
|
1380
|
+
return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
1381
|
+
case "**/.*":
|
|
1382
|
+
return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
1383
|
+
default: {
|
|
1384
|
+
const match = /^(.*?)\.(\w+)$/.exec(str);
|
|
1385
|
+
if (!match) return;
|
|
1386
|
+
const source2 = create(match[1]);
|
|
1387
|
+
if (!source2) return;
|
|
1388
|
+
return source2 + DOT_LITERAL + match[2];
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
};
|
|
1392
|
+
const output = utils.removePrefix(input, state);
|
|
1393
|
+
let source = create(output);
|
|
1394
|
+
if (source && opts.strictSlashes !== true) {
|
|
1395
|
+
source += `${SLASH_LITERAL}?`;
|
|
1396
|
+
}
|
|
1397
|
+
return source;
|
|
1398
|
+
};
|
|
1399
|
+
parse_1 = parse;
|
|
1400
|
+
return parse_1;
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
var picomatch_1$1;
|
|
1404
|
+
var hasRequiredPicomatch$1;
|
|
1405
|
+
|
|
1406
|
+
function requirePicomatch$1 () {
|
|
1407
|
+
if (hasRequiredPicomatch$1) return picomatch_1$1;
|
|
1408
|
+
hasRequiredPicomatch$1 = 1;
|
|
1409
|
+
const scan = /*@__PURE__*/ requireScan();
|
|
1410
|
+
const parse = /*@__PURE__*/ requireParse();
|
|
1411
|
+
const utils = /*@__PURE__*/ requireUtils();
|
|
1412
|
+
const constants = /*@__PURE__*/ requireConstants();
|
|
1413
|
+
const isObject = (val) => val && typeof val === "object" && !Array.isArray(val);
|
|
1414
|
+
const picomatch = (glob, options, returnState = false) => {
|
|
1415
|
+
if (Array.isArray(glob)) {
|
|
1416
|
+
const fns = glob.map((input) => picomatch(input, options, returnState));
|
|
1417
|
+
const arrayMatcher = (str) => {
|
|
1418
|
+
for (const isMatch of fns) {
|
|
1419
|
+
const state2 = isMatch(str);
|
|
1420
|
+
if (state2) return state2;
|
|
1421
|
+
}
|
|
1422
|
+
return false;
|
|
1423
|
+
};
|
|
1424
|
+
return arrayMatcher;
|
|
1425
|
+
}
|
|
1426
|
+
const isState = isObject(glob) && glob.tokens && glob.input;
|
|
1427
|
+
if (glob === "" || typeof glob !== "string" && !isState) {
|
|
1428
|
+
throw new TypeError("Expected pattern to be a non-empty string");
|
|
1429
|
+
}
|
|
1430
|
+
const opts = options || {};
|
|
1431
|
+
const posix = opts.windows;
|
|
1432
|
+
const regex = isState ? picomatch.compileRe(glob, options) : picomatch.makeRe(glob, options, false, true);
|
|
1433
|
+
const state = regex.state;
|
|
1434
|
+
delete regex.state;
|
|
1435
|
+
let isIgnored = () => false;
|
|
1436
|
+
if (opts.ignore) {
|
|
1437
|
+
const ignoreOpts = { ...options, ignore: null, onMatch: null, onResult: null };
|
|
1438
|
+
isIgnored = picomatch(opts.ignore, ignoreOpts, returnState);
|
|
1439
|
+
}
|
|
1440
|
+
const matcher = (input, returnObject = false) => {
|
|
1441
|
+
const { isMatch, match, output } = picomatch.test(input, regex, options, { glob, posix });
|
|
1442
|
+
const result = { glob, state, regex, posix, input, output, match, isMatch };
|
|
1443
|
+
if (typeof opts.onResult === "function") {
|
|
1444
|
+
opts.onResult(result);
|
|
1445
|
+
}
|
|
1446
|
+
if (isMatch === false) {
|
|
1447
|
+
result.isMatch = false;
|
|
1448
|
+
return returnObject ? result : false;
|
|
1449
|
+
}
|
|
1450
|
+
if (isIgnored(input)) {
|
|
1451
|
+
if (typeof opts.onIgnore === "function") {
|
|
1452
|
+
opts.onIgnore(result);
|
|
1453
|
+
}
|
|
1454
|
+
result.isMatch = false;
|
|
1455
|
+
return returnObject ? result : false;
|
|
1456
|
+
}
|
|
1457
|
+
if (typeof opts.onMatch === "function") {
|
|
1458
|
+
opts.onMatch(result);
|
|
1459
|
+
}
|
|
1460
|
+
return returnObject ? result : true;
|
|
1461
|
+
};
|
|
1462
|
+
if (returnState) {
|
|
1463
|
+
matcher.state = state;
|
|
1464
|
+
}
|
|
1465
|
+
return matcher;
|
|
1466
|
+
};
|
|
1467
|
+
picomatch.test = (input, regex, options, { glob, posix } = {}) => {
|
|
1468
|
+
if (typeof input !== "string") {
|
|
1469
|
+
throw new TypeError("Expected input to be a string");
|
|
1470
|
+
}
|
|
1471
|
+
if (input === "") {
|
|
1472
|
+
return { isMatch: false, output: "" };
|
|
1473
|
+
}
|
|
1474
|
+
const opts = options || {};
|
|
1475
|
+
const format = opts.format || (posix ? utils.toPosixSlashes : null);
|
|
1476
|
+
let match = input === glob;
|
|
1477
|
+
let output = match && format ? format(input) : input;
|
|
1478
|
+
if (match === false) {
|
|
1479
|
+
output = format ? format(input) : input;
|
|
1480
|
+
match = output === glob;
|
|
1481
|
+
}
|
|
1482
|
+
if (match === false || opts.capture === true) {
|
|
1483
|
+
if (opts.matchBase === true || opts.basename === true) {
|
|
1484
|
+
match = picomatch.matchBase(input, regex, options, posix);
|
|
1485
|
+
} else {
|
|
1486
|
+
match = regex.exec(output);
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
return { isMatch: Boolean(match), match, output };
|
|
1490
|
+
};
|
|
1491
|
+
picomatch.matchBase = (input, glob, options) => {
|
|
1492
|
+
const regex = glob instanceof RegExp ? glob : picomatch.makeRe(glob, options);
|
|
1493
|
+
return regex.test(utils.basename(input));
|
|
1494
|
+
};
|
|
1495
|
+
picomatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str);
|
|
1496
|
+
picomatch.parse = (pattern, options) => {
|
|
1497
|
+
if (Array.isArray(pattern)) return pattern.map((p) => picomatch.parse(p, options));
|
|
1498
|
+
return parse(pattern, { ...options, fastpaths: false });
|
|
1499
|
+
};
|
|
1500
|
+
picomatch.scan = (input, options) => scan(input, options);
|
|
1501
|
+
picomatch.compileRe = (state, options, returnOutput = false, returnState = false) => {
|
|
1502
|
+
if (returnOutput === true) {
|
|
1503
|
+
return state.output;
|
|
1504
|
+
}
|
|
1505
|
+
const opts = options || {};
|
|
1506
|
+
const prepend = opts.contains ? "" : "^";
|
|
1507
|
+
const append = opts.contains ? "" : "$";
|
|
1508
|
+
let source = `${prepend}(?:${state.output})${append}`;
|
|
1509
|
+
if (state && state.negated === true) {
|
|
1510
|
+
source = `^(?!${source}).*$`;
|
|
1511
|
+
}
|
|
1512
|
+
const regex = picomatch.toRegex(source, options);
|
|
1513
|
+
if (returnState === true) {
|
|
1514
|
+
regex.state = state;
|
|
1515
|
+
}
|
|
1516
|
+
return regex;
|
|
1517
|
+
};
|
|
1518
|
+
picomatch.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
|
|
1519
|
+
if (!input || typeof input !== "string") {
|
|
1520
|
+
throw new TypeError("Expected a non-empty string");
|
|
1521
|
+
}
|
|
1522
|
+
let parsed = { negated: false, fastpaths: true };
|
|
1523
|
+
if (options.fastpaths !== false && (input[0] === "." || input[0] === "*")) {
|
|
1524
|
+
parsed.output = parse.fastpaths(input, options);
|
|
1525
|
+
}
|
|
1526
|
+
if (!parsed.output) {
|
|
1527
|
+
parsed = parse(input, options);
|
|
1528
|
+
}
|
|
1529
|
+
return picomatch.compileRe(parsed, options, returnOutput, returnState);
|
|
1530
|
+
};
|
|
1531
|
+
picomatch.toRegex = (source, options) => {
|
|
1532
|
+
try {
|
|
1533
|
+
const opts = options || {};
|
|
1534
|
+
return new RegExp(source, opts.flags || (opts.nocase ? "i" : ""));
|
|
1535
|
+
} catch (err) {
|
|
1536
|
+
if (options && options.debug === true) throw err;
|
|
1537
|
+
return /$^/;
|
|
1538
|
+
}
|
|
1539
|
+
};
|
|
1540
|
+
picomatch.constants = constants;
|
|
1541
|
+
picomatch_1$1 = picomatch;
|
|
1542
|
+
return picomatch_1$1;
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1545
|
+
var picomatch_1;
|
|
1546
|
+
var hasRequiredPicomatch;
|
|
1547
|
+
|
|
1548
|
+
function requirePicomatch () {
|
|
1549
|
+
if (hasRequiredPicomatch) return picomatch_1;
|
|
1550
|
+
hasRequiredPicomatch = 1;
|
|
1551
|
+
const pico = /*@__PURE__*/ requirePicomatch$1();
|
|
1552
|
+
const utils = /*@__PURE__*/ requireUtils();
|
|
1553
|
+
function picomatch(glob, options, returnState = false) {
|
|
1554
|
+
if (options && (options.windows === null || options.windows === void 0)) {
|
|
1555
|
+
options = { ...options, windows: utils.isWindows() };
|
|
1556
|
+
}
|
|
1557
|
+
return pico(glob, options, returnState);
|
|
1558
|
+
}
|
|
1559
|
+
Object.assign(picomatch, pico);
|
|
1560
|
+
picomatch_1 = picomatch;
|
|
1561
|
+
return picomatch_1;
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
var picomatchExports = /*@__PURE__*/ requirePicomatch();
|
|
1565
|
+
var picomatch = /*@__PURE__*/getDefaultExportFromCjs(picomatchExports);
|
|
1566
|
+
|
|
1567
|
+
const concurrentMap = async (items, concurrency, callback) => {
|
|
1568
|
+
const pending = /* @__PURE__ */ new Set();
|
|
1569
|
+
let index = 0;
|
|
1570
|
+
for await (const item of items) {
|
|
1571
|
+
const currentIndex = index;
|
|
1572
|
+
index += 1;
|
|
1573
|
+
const p = callback(item, currentIndex);
|
|
1574
|
+
pending.add(p);
|
|
1575
|
+
p.then(() => {
|
|
1576
|
+
pending.delete(p);
|
|
1577
|
+
}, () => {
|
|
1578
|
+
});
|
|
1579
|
+
if (pending.size >= concurrency) {
|
|
1580
|
+
await Promise.race(pending);
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
await Promise.all(pending);
|
|
1584
|
+
};
|
|
1585
|
+
|
|
1586
|
+
const glob = async (root, globPattern, options) => {
|
|
1587
|
+
const includeDot = options?.dot ?? false;
|
|
1588
|
+
const isMatch = picomatch(globPattern, { dot: includeDot });
|
|
1589
|
+
const isRecursive = globPattern.includes("**");
|
|
1590
|
+
const results = [];
|
|
1591
|
+
const rootPrefix = root.length + 1;
|
|
1592
|
+
const crawl = async (directory) => {
|
|
1593
|
+
const entries = await fs.readdir(directory, { withFileTypes: true });
|
|
1594
|
+
const subdirectories = [];
|
|
1595
|
+
for (const entry of entries) {
|
|
1596
|
+
const fullPath = `${directory}/${entry.name}`;
|
|
1597
|
+
const relativePath = fullPath.slice(rootPrefix);
|
|
1598
|
+
if (isMatch(relativePath)) {
|
|
1599
|
+
results.push(fullPath);
|
|
1600
|
+
continue;
|
|
1601
|
+
}
|
|
1602
|
+
if (entry.isDirectory() && isRecursive) {
|
|
1603
|
+
if (!includeDot && entry.name.startsWith(".")) {
|
|
1604
|
+
continue;
|
|
1605
|
+
}
|
|
1606
|
+
subdirectories.push(crawl(fullPath));
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
await Promise.all(subdirectories);
|
|
1610
|
+
};
|
|
1611
|
+
await crawl(root);
|
|
1612
|
+
return results;
|
|
1613
|
+
};
|
|
1614
|
+
|
|
1615
|
+
const debug$2 = createDebug("poof:resolve");
|
|
1616
|
+
const toPosix = path.sep === "\\" ? (filePath) => filePath.replaceAll("\\", "/") : (filePath) => filePath;
|
|
1617
|
+
const GLOB_CONCURRENCY = 50;
|
|
1618
|
+
const validatePath = (target, cwd, dangerous) => {
|
|
1619
|
+
const absoluteTarget = path.resolve(target);
|
|
1620
|
+
const { root } = path.parse(absoluteTarget);
|
|
1621
|
+
if (absoluteTarget === root) {
|
|
1622
|
+
throw new Error(`Refusing to delete root directory: ${absoluteTarget}`);
|
|
1623
|
+
}
|
|
1624
|
+
if (!dangerous) {
|
|
1625
|
+
const normalizedCwd = toPosix(path.resolve(cwd));
|
|
1626
|
+
const normalizedTarget = toPosix(absoluteTarget);
|
|
1627
|
+
const isOutside = !normalizedTarget.startsWith(`${normalizedCwd}/`) && normalizedTarget !== normalizedCwd;
|
|
1628
|
+
if (isOutside) {
|
|
1629
|
+
throw new Error(
|
|
1630
|
+
`Refusing to delete path outside cwd. Pass { dangerous: true } to allow: ${absoluteTarget}`
|
|
1631
|
+
);
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
};
|
|
1635
|
+
const resolvePatterns = async (patterns, cwd, dangerous = false) => {
|
|
1636
|
+
const files = [];
|
|
1637
|
+
const notFound = [];
|
|
1638
|
+
await concurrentMap(patterns, GLOB_CONCURRENCY, async (pattern) => {
|
|
1639
|
+
const posixPattern = toPosix(pattern);
|
|
1640
|
+
const fullPattern = path.isAbsolute(pattern) ? posixPattern : path.posix.join(toPosix(cwd), posixPattern);
|
|
1641
|
+
const scanned = picomatch.scan(fullPattern);
|
|
1642
|
+
debug$2(`pattern ${pattern} -> fullPattern ${fullPattern} (isGlob: ${scanned.isGlob})`);
|
|
1643
|
+
const pathToValidate = scanned.isGlob ? scanned.base || cwd : fullPattern;
|
|
1644
|
+
validatePath(pathToValidate, cwd, dangerous);
|
|
1645
|
+
if (!scanned.isGlob) {
|
|
1646
|
+
await fs.access(fullPattern).then(
|
|
1647
|
+
() => {
|
|
1648
|
+
debug$2(`explicit path exists: ${fullPattern}`);
|
|
1649
|
+
files.push(fullPattern);
|
|
1650
|
+
},
|
|
1651
|
+
() => {
|
|
1652
|
+
debug$2(`explicit path not found: ${pattern}`);
|
|
1653
|
+
notFound.push(pattern);
|
|
1654
|
+
}
|
|
1655
|
+
);
|
|
1656
|
+
return;
|
|
1657
|
+
}
|
|
1658
|
+
let root = scanned.base || toPosix(cwd);
|
|
1659
|
+
if (root.endsWith("/")) {
|
|
1660
|
+
root = root.slice(0, -1);
|
|
1661
|
+
}
|
|
1662
|
+
const descendIntoDotDirectories = /^\.[^\\/.]|[{,]\.[^\\/.]/.test(scanned.glob);
|
|
1663
|
+
const globStart = performance.now();
|
|
1664
|
+
const matches = await glob(root, scanned.glob, { dot: descendIntoDotDirectories });
|
|
1665
|
+
debug$2(`glob pattern=${pattern} files=${matches.length} time=${(performance.now() - globStart).toFixed(2)}ms`);
|
|
1666
|
+
for (const match of matches) {
|
|
1667
|
+
files.push(match);
|
|
1668
|
+
}
|
|
1669
|
+
});
|
|
1670
|
+
return {
|
|
1671
|
+
files,
|
|
1672
|
+
notFound
|
|
1673
|
+
};
|
|
1674
|
+
};
|
|
1675
|
+
|
|
1676
|
+
const debug$1 = createDebug("poof:rm");
|
|
1677
|
+
const rmWorkerPath = fileURLToPath(import.meta.resolve("#rm-worker"));
|
|
1678
|
+
const startRmWorker = () => {
|
|
1679
|
+
debug$1(`spawning background rm process: ${rmWorkerPath}`);
|
|
1680
|
+
const child = spawn(process.execPath, [rmWorkerPath], {
|
|
1681
|
+
detached: true,
|
|
1682
|
+
stdio: ["pipe", "ignore", "ignore"],
|
|
1683
|
+
windowsHide: true
|
|
1684
|
+
});
|
|
1685
|
+
const stdin = child.stdin;
|
|
1686
|
+
child.unref();
|
|
1687
|
+
debug$1(`background rm process started (pid: ${child.pid})`);
|
|
1688
|
+
return {
|
|
1689
|
+
/**
|
|
1690
|
+
* Stream path to child process (null-delimited for filenames with newlines).
|
|
1691
|
+
*
|
|
1692
|
+
* Backpressure handling is critical here for three reasons:
|
|
1693
|
+
* 1. Instant exit: Without it, end() blocks until child consumes the ~64KB pipe buffer,
|
|
1694
|
+
* causing the CLI to hang at exit instead of returning instantly.
|
|
1695
|
+
* 2. Data safety: We only rename files at the pace we can communicate to the cleaner.
|
|
1696
|
+
* If parent crashes, orphaned temp files are limited to what's in the pipe, not
|
|
1697
|
+
* unbounded paths sitting in Node.js memory.
|
|
1698
|
+
* 3. Memory: Large directories (monorepo node_modules) can have 500k+ files.
|
|
1699
|
+
* Buffering all paths in memory risks OOM in constrained environments.
|
|
1700
|
+
*/
|
|
1701
|
+
write(filePath) {
|
|
1702
|
+
debug$1(`queue for deletion: ${filePath}`);
|
|
1703
|
+
const canContinue = stdin.write(`${filePath}\0`);
|
|
1704
|
+
if (!canContinue) {
|
|
1705
|
+
debug$1("backpressure - waiting for drain");
|
|
1706
|
+
return new Promise((resolve) => {
|
|
1707
|
+
stdin.once("drain", resolve);
|
|
1708
|
+
});
|
|
1709
|
+
}
|
|
1710
|
+
},
|
|
1711
|
+
/**
|
|
1712
|
+
* Signal end of paths and wait for buffer to flush to OS pipe.
|
|
1713
|
+
* After this resolves, all paths are in the kernel pipe buffer and the
|
|
1714
|
+
* detached child will continue cleanup even after parent exits.
|
|
1715
|
+
*/
|
|
1716
|
+
end: () => new Promise((resolve, reject) => {
|
|
1717
|
+
debug$1("ending stdin stream");
|
|
1718
|
+
stdin.end(
|
|
1719
|
+
(error) => error ? reject(error) : resolve()
|
|
1720
|
+
);
|
|
1721
|
+
})
|
|
1722
|
+
};
|
|
1723
|
+
};
|
|
1724
|
+
|
|
1725
|
+
const RETRY_COUNT = 3;
|
|
1726
|
+
const isWindows = process.platform === "win32";
|
|
1727
|
+
const windowsLockingCodes = /* @__PURE__ */ new Set(["EBUSY", "EPERM"]);
|
|
1728
|
+
const isWindowsLockingError = (error) => isWindows && windowsLockingCodes.has(error.code ?? "");
|
|
1729
|
+
const withRetry = async (operation, shouldRetry) => {
|
|
1730
|
+
let lastError;
|
|
1731
|
+
for (let attempt = 0; attempt < RETRY_COUNT; attempt += 1) {
|
|
1732
|
+
try {
|
|
1733
|
+
return await operation();
|
|
1734
|
+
} catch (error) {
|
|
1735
|
+
lastError = error;
|
|
1736
|
+
if (attempt < RETRY_COUNT - 1 && shouldRetry(error)) {
|
|
1737
|
+
await setTimeout(100 * (attempt + 1));
|
|
1738
|
+
continue;
|
|
1739
|
+
}
|
|
1740
|
+
throw error;
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
throw lastError;
|
|
1744
|
+
};
|
|
1745
|
+
|
|
1746
|
+
const debug = createDebug("poof:rename");
|
|
1747
|
+
const RENAME_CONCURRENCY = 100;
|
|
1748
|
+
const poof = async (patterns, options) => {
|
|
1749
|
+
const patternArray = Array.isArray(patterns) ? patterns : [patterns];
|
|
1750
|
+
const cwd = options?.cwd ?? process.cwd();
|
|
1751
|
+
debug(`patterns: ${JSON.stringify(patternArray)}, cwd: ${cwd}`);
|
|
1752
|
+
const resolveStart = performance.now();
|
|
1753
|
+
const { files, notFound } = await resolvePatterns(patternArray, cwd, options?.dangerous ?? false);
|
|
1754
|
+
debug(`resolve files=${files.length} time=${(performance.now() - resolveStart).toFixed(2)}ms`);
|
|
1755
|
+
const filesToDelete = files;
|
|
1756
|
+
const errors = notFound.map((pattern) => {
|
|
1757
|
+
const error = new Error(`Path not found: ${pattern}`);
|
|
1758
|
+
error.code = "ENOENT";
|
|
1759
|
+
return {
|
|
1760
|
+
path: pattern,
|
|
1761
|
+
error
|
|
1762
|
+
};
|
|
1763
|
+
});
|
|
1764
|
+
if (options?.dry) {
|
|
1765
|
+
return {
|
|
1766
|
+
deleted: files,
|
|
1767
|
+
errors
|
|
1768
|
+
};
|
|
1769
|
+
}
|
|
1770
|
+
const deleted = [];
|
|
1771
|
+
if (filesToDelete.length > 0) {
|
|
1772
|
+
const renameStart = performance.now();
|
|
1773
|
+
const id = `poof-${crypto.randomUUID()}`;
|
|
1774
|
+
const tempDir = path.join(os.tmpdir(), id);
|
|
1775
|
+
let tempDirCreated;
|
|
1776
|
+
const rmWriter = startRmWorker();
|
|
1777
|
+
const renamedParents = [];
|
|
1778
|
+
await concurrentMap(filesToDelete, RENAME_CONCURRENCY, async (target, index) => {
|
|
1779
|
+
const baseName = path.basename(target);
|
|
1780
|
+
if (!tempDirCreated) {
|
|
1781
|
+
tempDirCreated = fs.mkdir(tempDir).then(() => {
|
|
1782
|
+
debug(`temp dir created: ${tempDir}`);
|
|
1783
|
+
});
|
|
1784
|
+
}
|
|
1785
|
+
await tempDirCreated;
|
|
1786
|
+
const destinationPath = path.join(tempDir, `${index}-${baseName}`);
|
|
1787
|
+
debug(`rename ${target} -> ${destinationPath}`);
|
|
1788
|
+
try {
|
|
1789
|
+
await withRetry(() => fs.rename(target, destinationPath), isWindowsLockingError);
|
|
1790
|
+
renamedParents.push(target);
|
|
1791
|
+
return;
|
|
1792
|
+
} catch (error) {
|
|
1793
|
+
const { code } = error;
|
|
1794
|
+
debug(`rename failed: ${target} (code=${code})`);
|
|
1795
|
+
if (code === "ENOENT") {
|
|
1796
|
+
renamedParents.push(target);
|
|
1797
|
+
return;
|
|
1798
|
+
}
|
|
1799
|
+
if (code !== "EXDEV") {
|
|
1800
|
+
errors.push({
|
|
1801
|
+
path: target,
|
|
1802
|
+
error
|
|
1803
|
+
});
|
|
1804
|
+
return;
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
const fallbackPath = path.join(path.dirname(target), `.${id}-${index}-${baseName}`);
|
|
1808
|
+
try {
|
|
1809
|
+
await withRetry(() => fs.rename(target, fallbackPath), isWindowsLockingError);
|
|
1810
|
+
await rmWriter.write(fallbackPath);
|
|
1811
|
+
renamedParents.push(target);
|
|
1812
|
+
} catch (fallbackError) {
|
|
1813
|
+
const { code } = fallbackError;
|
|
1814
|
+
if (code === "ENOENT") {
|
|
1815
|
+
renamedParents.push(target);
|
|
1816
|
+
return;
|
|
1817
|
+
}
|
|
1818
|
+
errors.push({
|
|
1819
|
+
path: target,
|
|
1820
|
+
error: fallbackError
|
|
1821
|
+
});
|
|
1822
|
+
}
|
|
1823
|
+
});
|
|
1824
|
+
debug(`rename files=${renamedParents.length} time=${(performance.now() - renameStart).toFixed(2)}ms`);
|
|
1825
|
+
const spawnStart = performance.now();
|
|
1826
|
+
if (tempDirCreated) {
|
|
1827
|
+
await rmWriter.write(tempDir);
|
|
1828
|
+
}
|
|
1829
|
+
await rmWriter.end();
|
|
1830
|
+
debug(`spawn time=${(performance.now() - spawnStart).toFixed(2)}ms`);
|
|
1831
|
+
const renamedSet = new Set(renamedParents);
|
|
1832
|
+
for (const file of files) {
|
|
1833
|
+
if (renamedSet.has(file)) {
|
|
1834
|
+
deleted.push(file);
|
|
1835
|
+
continue;
|
|
1836
|
+
}
|
|
1837
|
+
let dir = file;
|
|
1838
|
+
while (dir.includes("/")) {
|
|
1839
|
+
dir = dir.slice(0, Math.max(0, dir.lastIndexOf("/")));
|
|
1840
|
+
if (renamedSet.has(dir)) {
|
|
1841
|
+
deleted.push(file);
|
|
1842
|
+
break;
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
debug(`deleted ${deleted.length} files, ${errors.length} errors`);
|
|
1848
|
+
return {
|
|
1849
|
+
deleted,
|
|
1850
|
+
errors
|
|
1851
|
+
};
|
|
1852
|
+
};
|
|
1853
|
+
|
|
1854
|
+
export { poof as default };
|