@darkrymit/crunes-cli 0.8.5 → 0.10.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/dist/chunks/{add-CBHWFGCA.js → add-IT3IHBPO.js} +2 -2
- package/dist/chunks/add-MSX6XSU3.js +68 -0
- package/dist/chunks/{apply-J4YICV6H.js → apply-LOIJIPLR.js} +21 -12
- package/dist/chunks/{benchmark-AKKV7G32.js → benchmark-3IHFP3V2.js} +27 -18
- package/dist/chunks/{browse-JZFU52ET.js → browse-PHMBDREQ.js} +2 -2
- package/dist/chunks/chunk-2DNYVKBF.js +109 -0
- package/dist/chunks/chunk-2FI6KN3C.js +283 -0
- package/dist/chunks/chunk-2HM5Q52B.js +131 -0
- package/dist/chunks/{chunk-6MRZXASS.js → chunk-2Q3KLBE6.js} +16 -0
- package/dist/chunks/{chunk-ZJDKCC2Y.js → chunk-4GJMCFR6.js} +6 -3
- package/dist/chunks/chunk-55GTJG5I.js +1154 -0
- package/dist/chunks/chunk-6IC6ZJ74.js +9525 -0
- package/dist/chunks/chunk-7KYCYDAS.js +325 -0
- package/dist/chunks/chunk-DTOYFY3Z.js +578 -0
- package/dist/chunks/chunk-EO3CSXWK.js +70 -0
- package/dist/chunks/chunk-FIAFVIAN.js +79 -0
- package/dist/chunks/{chunk-J3GZ3DXD.js → chunk-GVMT55GH.js} +3 -2
- package/dist/chunks/chunk-H2OT7D6N.js +303 -0
- package/dist/chunks/{chunk-JOAL437H.js → chunk-I6MHDUCW.js} +16 -1
- package/dist/chunks/chunk-KSQDFE5N.js +85 -0
- package/dist/chunks/{chunk-BTIPUR5S.js → chunk-KUEMDPNG.js} +108 -91
- package/dist/chunks/{chunk-6XLT25GS.js → chunk-MIKWIFYR.js} +47 -0
- package/dist/chunks/{chunk-GTCPZ22N.js → chunk-MTJ2KW3V.js} +3 -1
- package/dist/chunks/chunk-MVCBPI4J.js +2354 -0
- package/dist/chunks/{chunk-T53L5CJW.js → chunk-PBGUKXT6.js} +2887 -1874
- package/dist/chunks/{chunk-KII6KW5Z.js → chunk-RVBAAXRY.js} +64 -44
- package/dist/chunks/chunk-SUCYDYMU.js +44 -0
- package/dist/chunks/chunk-UBCAZGLE.js +15 -0
- package/dist/chunks/{chunk-63H5VXZY.js → chunk-UEUUOAJY.js} +4 -1
- package/dist/chunks/chunk-VP7YLCQP.js +244 -0
- package/dist/chunks/{chunk-NDEYEYSU.js → chunk-WJII3LZK.js} +4 -3
- package/dist/chunks/chunk-XDMMSZIL.js +71 -0
- package/dist/chunks/chunk-YKIKJHYO.js +94 -0
- package/dist/chunks/{chunk-NYLRTAAA.js → chunk-YVN3VDRE.js} +1 -1
- package/dist/chunks/{clear-YBDIPEEH.js → clear-AT7HNUV4.js} +2 -2
- package/dist/chunks/{create-L6DJN4ME.js → create-DXW4YYLJ.js} +8 -8
- package/dist/chunks/create-LPLNCOW4.js +268 -0
- package/dist/chunks/{create-GPDE2YKL.js → create-Y4LHLWGL.js} +26 -18
- package/dist/chunks/{delete-LNOYM5KG.js → delete-2EXPFBFC.js} +2 -2
- package/dist/chunks/{delete-E4TEBRPX.js → delete-GKYA2W5Z.js} +4 -2
- package/dist/chunks/{delete-C4UJ7X5K.js → delete-MJAECXXV.js} +2 -2
- package/dist/chunks/disable-TITOSMXB.js +43 -0
- package/dist/chunks/doctor-R2Y6UAY4.js +208 -0
- package/dist/chunks/enable-LGTPDWPV.js +35 -0
- package/dist/chunks/{globals-H2WF344Y.js → globals-SNQFCHMP.js} +1 -1
- package/dist/chunks/{init-HU5OMHEH.js → init-KO2HLED5.js} +18 -8
- package/dist/chunks/install-7IRUAGSF.js +64 -0
- package/dist/chunks/{intro-36OLGNYN.js → intro-JNJ6A75J.js} +89 -21
- package/dist/chunks/{kill-2UG7PHUV.js → kill-TX3PC73P.js} +2 -1
- package/dist/chunks/{list-2JYMBMZC.js → list-BCCM3TLP.js} +12 -7
- package/dist/chunks/{list-4X3JFQGS.js → list-EHREZR6M.js} +2 -1
- package/dist/chunks/{list-U7PAYNAH.js → list-LC6HB3H3.js} +2 -2
- package/dist/chunks/list-MLKZE36K.js +92 -0
- package/dist/chunks/list-QVZKR3IE.js +62 -0
- package/dist/chunks/{list-7VHJIUDX.js → list-U4EMHQZT.js} +2 -2
- package/dist/chunks/{list-PTAWQYWG.js → list-V7VVD5AG.js} +2 -1
- package/dist/chunks/{list-A5WVDBWF.js → list-VA73WPK6.js} +2 -2
- package/dist/chunks/{manifest-7RVNKBOH.js → manifest-76MIEL2F.js} +3 -1
- package/dist/chunks/migrate-Y3EKMVP5.js +87 -0
- package/dist/chunks/{output-RJ6JSNY7.js → output-QN5CVJ62.js} +4 -1
- package/dist/chunks/{query-AW7WYILM.js → query-2US3CPYT.js} +2 -2
- package/dist/chunks/{registry-RG34DPD7.js → registry-IWP7JMNI.js} +2 -2
- package/dist/chunks/{remove-QUH2D3S5.js → remove-BCFTF23J.js} +2 -2
- package/dist/chunks/{repl-STBZC4P2.js → repl-2YWTHUWT.js} +4 -0
- package/dist/chunks/{repl-BPEWARN7.js → repl-5GDN3RAO.js} +99 -31
- package/dist/chunks/resolver-CA2A32AC.js +36 -0
- package/dist/chunks/run-WL3IZBXF.js +35 -0
- package/dist/chunks/rune-YA4TFHTB.js +283 -0
- package/dist/chunks/runner-QNZMBHQY.js +34 -0
- package/dist/chunks/{search-MSSDGJTF.js → search-B7IM7JRJ.js} +2 -2
- package/dist/chunks/shell-explain-LKBBP2BG.js +77 -0
- package/dist/chunks/trust-BFIDANXD.js +109 -0
- package/dist/chunks/uninstall-3MWZIZVA.js +58 -0
- package/dist/chunks/{unset-YASSMSE5.js → unset-P6IUF7SS.js} +2 -2
- package/dist/chunks/{update-KSC6VRMU.js → update-W4MJUTTW.js} +25 -19
- package/dist/chunks/{update-EWWDROKW.js → update-WXT7CHYA.js} +2 -2
- package/dist/chunks/{utils-3SJFSUSV.js → utils-B2QULX5J.js} +8 -4
- package/dist/chunks/{version-YG2M7HER.js → version-FLHI5KFS.js} +3 -3
- package/dist/cli.js +115 -70
- package/package.json +2 -2
- package/dist/chunks/chunk-ASZKAC24.js +0 -103
- package/dist/chunks/chunk-G3U4V32O.js +0 -46
- package/dist/chunks/chunk-GSA432UC.js +0 -90
- package/dist/chunks/chunk-WJRZN7BR.js +0 -77492
- package/dist/chunks/create-VYZRWRGQ.js +0 -170
- package/dist/chunks/disable-FGJ7VMPO.js +0 -47
- package/dist/chunks/doctor-7NWBJAH7.js +0 -53
- package/dist/chunks/enable-ZL6QOC2I.js +0 -47
- package/dist/chunks/install-FIYRMVLR.js +0 -57
- package/dist/chunks/list-AIYNOPNZ.js +0 -28
- package/dist/chunks/list-NZ5DHXJF.js +0 -111
- package/dist/chunks/resolver-36V72VKR.js +0 -28
- package/dist/chunks/run-IVL23SMW.js +0 -26
- package/dist/chunks/rune-XRREUL56.js +0 -186
- package/dist/chunks/uninstall-G56DZRFG.js +0 -49
|
@@ -0,0 +1,2354 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getSqlitePluginDir
|
|
3
|
+
} from "./chunk-GVMT55GH.js";
|
|
4
|
+
import {
|
|
5
|
+
getCachePluginDir
|
|
6
|
+
} from "./chunk-WJII3LZK.js";
|
|
7
|
+
import {
|
|
8
|
+
getLocalBase,
|
|
9
|
+
getProjectsJsonPath
|
|
10
|
+
} from "./chunk-2Q3KLBE6.js";
|
|
11
|
+
import {
|
|
12
|
+
__commonJS,
|
|
13
|
+
__toESM,
|
|
14
|
+
init_require_shim
|
|
15
|
+
} from "./chunk-TPK5AGRA.js";
|
|
16
|
+
|
|
17
|
+
// node_modules/picomatch/lib/constants.js
|
|
18
|
+
var require_constants = __commonJS({
|
|
19
|
+
"node_modules/picomatch/lib/constants.js"(exports, module) {
|
|
20
|
+
"use strict";
|
|
21
|
+
init_require_shim();
|
|
22
|
+
var WIN_SLASH = "\\\\/";
|
|
23
|
+
var WIN_NO_SLASH = `[^${WIN_SLASH}]`;
|
|
24
|
+
var DEFAULT_MAX_EXTGLOB_RECURSION = 0;
|
|
25
|
+
var DOT_LITERAL = "\\.";
|
|
26
|
+
var PLUS_LITERAL = "\\+";
|
|
27
|
+
var QMARK_LITERAL = "\\?";
|
|
28
|
+
var SLASH_LITERAL = "\\/";
|
|
29
|
+
var ONE_CHAR = "(?=.)";
|
|
30
|
+
var QMARK = "[^/]";
|
|
31
|
+
var END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
|
|
32
|
+
var START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
|
|
33
|
+
var DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
|
|
34
|
+
var NO_DOT = `(?!${DOT_LITERAL})`;
|
|
35
|
+
var NO_DOTS = `(?!${START_ANCHOR}${DOTS_SLASH})`;
|
|
36
|
+
var NO_DOT_SLASH = `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`;
|
|
37
|
+
var NO_DOTS_SLASH = `(?!${DOTS_SLASH})`;
|
|
38
|
+
var QMARK_NO_DOT = `[^.${SLASH_LITERAL}]`;
|
|
39
|
+
var STAR = `${QMARK}*?`;
|
|
40
|
+
var SEP = "/";
|
|
41
|
+
var POSIX_CHARS = {
|
|
42
|
+
DOT_LITERAL,
|
|
43
|
+
PLUS_LITERAL,
|
|
44
|
+
QMARK_LITERAL,
|
|
45
|
+
SLASH_LITERAL,
|
|
46
|
+
ONE_CHAR,
|
|
47
|
+
QMARK,
|
|
48
|
+
END_ANCHOR,
|
|
49
|
+
DOTS_SLASH,
|
|
50
|
+
NO_DOT,
|
|
51
|
+
NO_DOTS,
|
|
52
|
+
NO_DOT_SLASH,
|
|
53
|
+
NO_DOTS_SLASH,
|
|
54
|
+
QMARK_NO_DOT,
|
|
55
|
+
STAR,
|
|
56
|
+
START_ANCHOR,
|
|
57
|
+
SEP
|
|
58
|
+
};
|
|
59
|
+
var WINDOWS_CHARS = {
|
|
60
|
+
...POSIX_CHARS,
|
|
61
|
+
SLASH_LITERAL: `[${WIN_SLASH}]`,
|
|
62
|
+
QMARK: WIN_NO_SLASH,
|
|
63
|
+
STAR: `${WIN_NO_SLASH}*?`,
|
|
64
|
+
DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`,
|
|
65
|
+
NO_DOT: `(?!${DOT_LITERAL})`,
|
|
66
|
+
NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
|
67
|
+
NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`,
|
|
68
|
+
NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
|
69
|
+
QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
|
|
70
|
+
START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
|
|
71
|
+
END_ANCHOR: `(?:[${WIN_SLASH}]|$)`,
|
|
72
|
+
SEP: "\\"
|
|
73
|
+
};
|
|
74
|
+
var POSIX_REGEX_SOURCE = {
|
|
75
|
+
__proto__: null,
|
|
76
|
+
alnum: "a-zA-Z0-9",
|
|
77
|
+
alpha: "a-zA-Z",
|
|
78
|
+
ascii: "\\x00-\\x7F",
|
|
79
|
+
blank: " \\t",
|
|
80
|
+
cntrl: "\\x00-\\x1F\\x7F",
|
|
81
|
+
digit: "0-9",
|
|
82
|
+
graph: "\\x21-\\x7E",
|
|
83
|
+
lower: "a-z",
|
|
84
|
+
print: "\\x20-\\x7E ",
|
|
85
|
+
punct: "\\-!\"#$%&'()\\*+,./:;<=>?@[\\]^_`{|}~",
|
|
86
|
+
space: " \\t\\r\\n\\v\\f",
|
|
87
|
+
upper: "A-Z",
|
|
88
|
+
word: "A-Za-z0-9_",
|
|
89
|
+
xdigit: "A-Fa-f0-9"
|
|
90
|
+
};
|
|
91
|
+
module.exports = {
|
|
92
|
+
DEFAULT_MAX_EXTGLOB_RECURSION,
|
|
93
|
+
MAX_LENGTH: 1024 * 64,
|
|
94
|
+
POSIX_REGEX_SOURCE,
|
|
95
|
+
// regular expressions
|
|
96
|
+
REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
|
|
97
|
+
REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
|
|
98
|
+
REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
|
|
99
|
+
REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
|
|
100
|
+
REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
|
|
101
|
+
REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
|
|
102
|
+
// Replace globs with equivalent patterns to reduce parsing time.
|
|
103
|
+
REPLACEMENTS: {
|
|
104
|
+
__proto__: null,
|
|
105
|
+
"***": "*",
|
|
106
|
+
"**/**": "**",
|
|
107
|
+
"**/**/**": "**"
|
|
108
|
+
},
|
|
109
|
+
// Digits
|
|
110
|
+
CHAR_0: 48,
|
|
111
|
+
/* 0 */
|
|
112
|
+
CHAR_9: 57,
|
|
113
|
+
/* 9 */
|
|
114
|
+
// Alphabet chars.
|
|
115
|
+
CHAR_UPPERCASE_A: 65,
|
|
116
|
+
/* A */
|
|
117
|
+
CHAR_LOWERCASE_A: 97,
|
|
118
|
+
/* a */
|
|
119
|
+
CHAR_UPPERCASE_Z: 90,
|
|
120
|
+
/* Z */
|
|
121
|
+
CHAR_LOWERCASE_Z: 122,
|
|
122
|
+
/* z */
|
|
123
|
+
CHAR_LEFT_PARENTHESES: 40,
|
|
124
|
+
/* ( */
|
|
125
|
+
CHAR_RIGHT_PARENTHESES: 41,
|
|
126
|
+
/* ) */
|
|
127
|
+
CHAR_ASTERISK: 42,
|
|
128
|
+
/* * */
|
|
129
|
+
// Non-alphabetic chars.
|
|
130
|
+
CHAR_AMPERSAND: 38,
|
|
131
|
+
/* & */
|
|
132
|
+
CHAR_AT: 64,
|
|
133
|
+
/* @ */
|
|
134
|
+
CHAR_BACKWARD_SLASH: 92,
|
|
135
|
+
/* \ */
|
|
136
|
+
CHAR_CARRIAGE_RETURN: 13,
|
|
137
|
+
/* \r */
|
|
138
|
+
CHAR_CIRCUMFLEX_ACCENT: 94,
|
|
139
|
+
/* ^ */
|
|
140
|
+
CHAR_COLON: 58,
|
|
141
|
+
/* : */
|
|
142
|
+
CHAR_COMMA: 44,
|
|
143
|
+
/* , */
|
|
144
|
+
CHAR_DOT: 46,
|
|
145
|
+
/* . */
|
|
146
|
+
CHAR_DOUBLE_QUOTE: 34,
|
|
147
|
+
/* " */
|
|
148
|
+
CHAR_EQUAL: 61,
|
|
149
|
+
/* = */
|
|
150
|
+
CHAR_EXCLAMATION_MARK: 33,
|
|
151
|
+
/* ! */
|
|
152
|
+
CHAR_FORM_FEED: 12,
|
|
153
|
+
/* \f */
|
|
154
|
+
CHAR_FORWARD_SLASH: 47,
|
|
155
|
+
/* / */
|
|
156
|
+
CHAR_GRAVE_ACCENT: 96,
|
|
157
|
+
/* ` */
|
|
158
|
+
CHAR_HASH: 35,
|
|
159
|
+
/* # */
|
|
160
|
+
CHAR_HYPHEN_MINUS: 45,
|
|
161
|
+
/* - */
|
|
162
|
+
CHAR_LEFT_ANGLE_BRACKET: 60,
|
|
163
|
+
/* < */
|
|
164
|
+
CHAR_LEFT_CURLY_BRACE: 123,
|
|
165
|
+
/* { */
|
|
166
|
+
CHAR_LEFT_SQUARE_BRACKET: 91,
|
|
167
|
+
/* [ */
|
|
168
|
+
CHAR_LINE_FEED: 10,
|
|
169
|
+
/* \n */
|
|
170
|
+
CHAR_NO_BREAK_SPACE: 160,
|
|
171
|
+
/* \u00A0 */
|
|
172
|
+
CHAR_PERCENT: 37,
|
|
173
|
+
/* % */
|
|
174
|
+
CHAR_PLUS: 43,
|
|
175
|
+
/* + */
|
|
176
|
+
CHAR_QUESTION_MARK: 63,
|
|
177
|
+
/* ? */
|
|
178
|
+
CHAR_RIGHT_ANGLE_BRACKET: 62,
|
|
179
|
+
/* > */
|
|
180
|
+
CHAR_RIGHT_CURLY_BRACE: 125,
|
|
181
|
+
/* } */
|
|
182
|
+
CHAR_RIGHT_SQUARE_BRACKET: 93,
|
|
183
|
+
/* ] */
|
|
184
|
+
CHAR_SEMICOLON: 59,
|
|
185
|
+
/* ; */
|
|
186
|
+
CHAR_SINGLE_QUOTE: 39,
|
|
187
|
+
/* ' */
|
|
188
|
+
CHAR_SPACE: 32,
|
|
189
|
+
/* */
|
|
190
|
+
CHAR_TAB: 9,
|
|
191
|
+
/* \t */
|
|
192
|
+
CHAR_UNDERSCORE: 95,
|
|
193
|
+
/* _ */
|
|
194
|
+
CHAR_VERTICAL_LINE: 124,
|
|
195
|
+
/* | */
|
|
196
|
+
CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279,
|
|
197
|
+
/* \uFEFF */
|
|
198
|
+
/**
|
|
199
|
+
* Create EXTGLOB_CHARS
|
|
200
|
+
*/
|
|
201
|
+
extglobChars(chars) {
|
|
202
|
+
return {
|
|
203
|
+
"!": { type: "negate", open: "(?:(?!(?:", close: `))${chars.STAR})` },
|
|
204
|
+
"?": { type: "qmark", open: "(?:", close: ")?" },
|
|
205
|
+
"+": { type: "plus", open: "(?:", close: ")+" },
|
|
206
|
+
"*": { type: "star", open: "(?:", close: ")*" },
|
|
207
|
+
"@": { type: "at", open: "(?:", close: ")" }
|
|
208
|
+
};
|
|
209
|
+
},
|
|
210
|
+
/**
|
|
211
|
+
* Create GLOB_CHARS
|
|
212
|
+
*/
|
|
213
|
+
globChars(win32) {
|
|
214
|
+
return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
// node_modules/picomatch/lib/utils.js
|
|
221
|
+
var require_utils = __commonJS({
|
|
222
|
+
"node_modules/picomatch/lib/utils.js"(exports) {
|
|
223
|
+
"use strict";
|
|
224
|
+
init_require_shim();
|
|
225
|
+
var {
|
|
226
|
+
REGEX_BACKSLASH,
|
|
227
|
+
REGEX_REMOVE_BACKSLASH,
|
|
228
|
+
REGEX_SPECIAL_CHARS,
|
|
229
|
+
REGEX_SPECIAL_CHARS_GLOBAL
|
|
230
|
+
} = require_constants();
|
|
231
|
+
exports.isObject = (val) => val !== null && typeof val === "object" && !Array.isArray(val);
|
|
232
|
+
exports.hasRegexChars = (str) => REGEX_SPECIAL_CHARS.test(str);
|
|
233
|
+
exports.isRegexChar = (str) => str.length === 1 && exports.hasRegexChars(str);
|
|
234
|
+
exports.escapeRegex = (str) => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, "\\$1");
|
|
235
|
+
exports.toPosixSlashes = (str) => str.replace(REGEX_BACKSLASH, "/");
|
|
236
|
+
exports.isWindows = () => {
|
|
237
|
+
if (typeof navigator !== "undefined" && navigator.platform) {
|
|
238
|
+
const platform = navigator.platform.toLowerCase();
|
|
239
|
+
return platform === "win32" || platform === "windows";
|
|
240
|
+
}
|
|
241
|
+
if (typeof process !== "undefined" && process.platform) {
|
|
242
|
+
return process.platform === "win32";
|
|
243
|
+
}
|
|
244
|
+
return false;
|
|
245
|
+
};
|
|
246
|
+
exports.removeBackslashes = (str) => {
|
|
247
|
+
return str.replace(REGEX_REMOVE_BACKSLASH, (match) => {
|
|
248
|
+
return match === "\\" ? "" : match;
|
|
249
|
+
});
|
|
250
|
+
};
|
|
251
|
+
exports.escapeLast = (input, char, lastIdx) => {
|
|
252
|
+
const idx = input.lastIndexOf(char, lastIdx);
|
|
253
|
+
if (idx === -1) return input;
|
|
254
|
+
if (input[idx - 1] === "\\") return exports.escapeLast(input, char, idx - 1);
|
|
255
|
+
return `${input.slice(0, idx)}\\${input.slice(idx)}`;
|
|
256
|
+
};
|
|
257
|
+
exports.removePrefix = (input, state = {}) => {
|
|
258
|
+
let output = input;
|
|
259
|
+
if (output.startsWith("./")) {
|
|
260
|
+
output = output.slice(2);
|
|
261
|
+
state.prefix = "./";
|
|
262
|
+
}
|
|
263
|
+
return output;
|
|
264
|
+
};
|
|
265
|
+
exports.wrapOutput = (input, state = {}, options = {}) => {
|
|
266
|
+
const prepend = options.contains ? "" : "^";
|
|
267
|
+
const append = options.contains ? "" : "$";
|
|
268
|
+
let output = `${prepend}(?:${input})${append}`;
|
|
269
|
+
if (state.negated === true) {
|
|
270
|
+
output = `(?:^(?!${output}).*$)`;
|
|
271
|
+
}
|
|
272
|
+
return output;
|
|
273
|
+
};
|
|
274
|
+
exports.basename = (path3, { windows } = {}) => {
|
|
275
|
+
const segs = path3.split(windows ? /[\\/]/ : "/");
|
|
276
|
+
const last = segs[segs.length - 1];
|
|
277
|
+
if (last === "") {
|
|
278
|
+
return segs[segs.length - 2];
|
|
279
|
+
}
|
|
280
|
+
return last;
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
// node_modules/picomatch/lib/scan.js
|
|
286
|
+
var require_scan = __commonJS({
|
|
287
|
+
"node_modules/picomatch/lib/scan.js"(exports, module) {
|
|
288
|
+
"use strict";
|
|
289
|
+
init_require_shim();
|
|
290
|
+
var utils = require_utils();
|
|
291
|
+
var {
|
|
292
|
+
CHAR_ASTERISK,
|
|
293
|
+
/* * */
|
|
294
|
+
CHAR_AT,
|
|
295
|
+
/* @ */
|
|
296
|
+
CHAR_BACKWARD_SLASH,
|
|
297
|
+
/* \ */
|
|
298
|
+
CHAR_COMMA,
|
|
299
|
+
/* , */
|
|
300
|
+
CHAR_DOT,
|
|
301
|
+
/* . */
|
|
302
|
+
CHAR_EXCLAMATION_MARK,
|
|
303
|
+
/* ! */
|
|
304
|
+
CHAR_FORWARD_SLASH,
|
|
305
|
+
/* / */
|
|
306
|
+
CHAR_LEFT_CURLY_BRACE,
|
|
307
|
+
/* { */
|
|
308
|
+
CHAR_LEFT_PARENTHESES,
|
|
309
|
+
/* ( */
|
|
310
|
+
CHAR_LEFT_SQUARE_BRACKET,
|
|
311
|
+
/* [ */
|
|
312
|
+
CHAR_PLUS,
|
|
313
|
+
/* + */
|
|
314
|
+
CHAR_QUESTION_MARK,
|
|
315
|
+
/* ? */
|
|
316
|
+
CHAR_RIGHT_CURLY_BRACE,
|
|
317
|
+
/* } */
|
|
318
|
+
CHAR_RIGHT_PARENTHESES,
|
|
319
|
+
/* ) */
|
|
320
|
+
CHAR_RIGHT_SQUARE_BRACKET
|
|
321
|
+
/* ] */
|
|
322
|
+
} = require_constants();
|
|
323
|
+
var isPathSeparator = (code) => {
|
|
324
|
+
return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
|
|
325
|
+
};
|
|
326
|
+
var depth = (token) => {
|
|
327
|
+
if (token.isPrefix !== true) {
|
|
328
|
+
token.depth = token.isGlobstar ? Infinity : 1;
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
var scan = (input, options) => {
|
|
332
|
+
const opts = options || {};
|
|
333
|
+
const length = input.length - 1;
|
|
334
|
+
const scanToEnd = opts.parts === true || opts.scanToEnd === true;
|
|
335
|
+
const slashes = [];
|
|
336
|
+
const tokens = [];
|
|
337
|
+
const parts = [];
|
|
338
|
+
let str = input;
|
|
339
|
+
let index = -1;
|
|
340
|
+
let start = 0;
|
|
341
|
+
let lastIndex = 0;
|
|
342
|
+
let isBrace = false;
|
|
343
|
+
let isBracket = false;
|
|
344
|
+
let isGlob = false;
|
|
345
|
+
let isExtglob = false;
|
|
346
|
+
let isGlobstar = false;
|
|
347
|
+
let braceEscaped = false;
|
|
348
|
+
let backslashes = false;
|
|
349
|
+
let negated = false;
|
|
350
|
+
let negatedExtglob = false;
|
|
351
|
+
let finished = false;
|
|
352
|
+
let braces = 0;
|
|
353
|
+
let prev;
|
|
354
|
+
let code;
|
|
355
|
+
let token = { value: "", depth: 0, isGlob: false };
|
|
356
|
+
const eos = () => index >= length;
|
|
357
|
+
const peek = () => str.charCodeAt(index + 1);
|
|
358
|
+
const advance = () => {
|
|
359
|
+
prev = code;
|
|
360
|
+
return str.charCodeAt(++index);
|
|
361
|
+
};
|
|
362
|
+
while (index < length) {
|
|
363
|
+
code = advance();
|
|
364
|
+
let next;
|
|
365
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
366
|
+
backslashes = token.backslashes = true;
|
|
367
|
+
code = advance();
|
|
368
|
+
if (code === CHAR_LEFT_CURLY_BRACE) {
|
|
369
|
+
braceEscaped = true;
|
|
370
|
+
}
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE) {
|
|
374
|
+
braces++;
|
|
375
|
+
while (eos() !== true && (code = advance())) {
|
|
376
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
377
|
+
backslashes = token.backslashes = true;
|
|
378
|
+
advance();
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
if (code === CHAR_LEFT_CURLY_BRACE) {
|
|
382
|
+
braces++;
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
if (braceEscaped !== true && code === CHAR_DOT && (code = advance()) === CHAR_DOT) {
|
|
386
|
+
isBrace = token.isBrace = true;
|
|
387
|
+
isGlob = token.isGlob = true;
|
|
388
|
+
finished = true;
|
|
389
|
+
if (scanToEnd === true) {
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
break;
|
|
393
|
+
}
|
|
394
|
+
if (braceEscaped !== true && code === CHAR_COMMA) {
|
|
395
|
+
isBrace = token.isBrace = true;
|
|
396
|
+
isGlob = token.isGlob = true;
|
|
397
|
+
finished = true;
|
|
398
|
+
if (scanToEnd === true) {
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
break;
|
|
402
|
+
}
|
|
403
|
+
if (code === CHAR_RIGHT_CURLY_BRACE) {
|
|
404
|
+
braces--;
|
|
405
|
+
if (braces === 0) {
|
|
406
|
+
braceEscaped = false;
|
|
407
|
+
isBrace = token.isBrace = true;
|
|
408
|
+
finished = true;
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
if (scanToEnd === true) {
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
break;
|
|
417
|
+
}
|
|
418
|
+
if (code === CHAR_FORWARD_SLASH) {
|
|
419
|
+
slashes.push(index);
|
|
420
|
+
tokens.push(token);
|
|
421
|
+
token = { value: "", depth: 0, isGlob: false };
|
|
422
|
+
if (finished === true) continue;
|
|
423
|
+
if (prev === CHAR_DOT && index === start + 1) {
|
|
424
|
+
start += 2;
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
lastIndex = index + 1;
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
if (opts.noext !== true) {
|
|
431
|
+
const isExtglobChar = code === CHAR_PLUS || code === CHAR_AT || code === CHAR_ASTERISK || code === CHAR_QUESTION_MARK || code === CHAR_EXCLAMATION_MARK;
|
|
432
|
+
if (isExtglobChar === true && peek() === CHAR_LEFT_PARENTHESES) {
|
|
433
|
+
isGlob = token.isGlob = true;
|
|
434
|
+
isExtglob = token.isExtglob = true;
|
|
435
|
+
finished = true;
|
|
436
|
+
if (code === CHAR_EXCLAMATION_MARK && index === start) {
|
|
437
|
+
negatedExtglob = true;
|
|
438
|
+
}
|
|
439
|
+
if (scanToEnd === true) {
|
|
440
|
+
while (eos() !== true && (code = advance())) {
|
|
441
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
442
|
+
backslashes = token.backslashes = true;
|
|
443
|
+
code = advance();
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
if (code === CHAR_RIGHT_PARENTHESES) {
|
|
447
|
+
isGlob = token.isGlob = true;
|
|
448
|
+
finished = true;
|
|
449
|
+
break;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
continue;
|
|
453
|
+
}
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
if (code === CHAR_ASTERISK) {
|
|
458
|
+
if (prev === CHAR_ASTERISK) isGlobstar = token.isGlobstar = true;
|
|
459
|
+
isGlob = token.isGlob = true;
|
|
460
|
+
finished = true;
|
|
461
|
+
if (scanToEnd === true) {
|
|
462
|
+
continue;
|
|
463
|
+
}
|
|
464
|
+
break;
|
|
465
|
+
}
|
|
466
|
+
if (code === CHAR_QUESTION_MARK) {
|
|
467
|
+
isGlob = token.isGlob = true;
|
|
468
|
+
finished = true;
|
|
469
|
+
if (scanToEnd === true) {
|
|
470
|
+
continue;
|
|
471
|
+
}
|
|
472
|
+
break;
|
|
473
|
+
}
|
|
474
|
+
if (code === CHAR_LEFT_SQUARE_BRACKET) {
|
|
475
|
+
while (eos() !== true && (next = advance())) {
|
|
476
|
+
if (next === CHAR_BACKWARD_SLASH) {
|
|
477
|
+
backslashes = token.backslashes = true;
|
|
478
|
+
advance();
|
|
479
|
+
continue;
|
|
480
|
+
}
|
|
481
|
+
if (next === CHAR_RIGHT_SQUARE_BRACKET) {
|
|
482
|
+
isBracket = token.isBracket = true;
|
|
483
|
+
isGlob = token.isGlob = true;
|
|
484
|
+
finished = true;
|
|
485
|
+
break;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
if (scanToEnd === true) {
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
break;
|
|
492
|
+
}
|
|
493
|
+
if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) {
|
|
494
|
+
negated = token.negated = true;
|
|
495
|
+
start++;
|
|
496
|
+
continue;
|
|
497
|
+
}
|
|
498
|
+
if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
|
|
499
|
+
isGlob = token.isGlob = true;
|
|
500
|
+
if (scanToEnd === true) {
|
|
501
|
+
while (eos() !== true && (code = advance())) {
|
|
502
|
+
if (code === CHAR_LEFT_PARENTHESES) {
|
|
503
|
+
backslashes = token.backslashes = true;
|
|
504
|
+
code = advance();
|
|
505
|
+
continue;
|
|
506
|
+
}
|
|
507
|
+
if (code === CHAR_RIGHT_PARENTHESES) {
|
|
508
|
+
finished = true;
|
|
509
|
+
break;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
continue;
|
|
513
|
+
}
|
|
514
|
+
break;
|
|
515
|
+
}
|
|
516
|
+
if (isGlob === true) {
|
|
517
|
+
finished = true;
|
|
518
|
+
if (scanToEnd === true) {
|
|
519
|
+
continue;
|
|
520
|
+
}
|
|
521
|
+
break;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
if (opts.noext === true) {
|
|
525
|
+
isExtglob = false;
|
|
526
|
+
isGlob = false;
|
|
527
|
+
}
|
|
528
|
+
let base = str;
|
|
529
|
+
let prefix = "";
|
|
530
|
+
let glob = "";
|
|
531
|
+
if (start > 0) {
|
|
532
|
+
prefix = str.slice(0, start);
|
|
533
|
+
str = str.slice(start);
|
|
534
|
+
lastIndex -= start;
|
|
535
|
+
}
|
|
536
|
+
if (base && isGlob === true && lastIndex > 0) {
|
|
537
|
+
base = str.slice(0, lastIndex);
|
|
538
|
+
glob = str.slice(lastIndex);
|
|
539
|
+
} else if (isGlob === true) {
|
|
540
|
+
base = "";
|
|
541
|
+
glob = str;
|
|
542
|
+
} else {
|
|
543
|
+
base = str;
|
|
544
|
+
}
|
|
545
|
+
if (base && base !== "" && base !== "/" && base !== str) {
|
|
546
|
+
if (isPathSeparator(base.charCodeAt(base.length - 1))) {
|
|
547
|
+
base = base.slice(0, -1);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
if (opts.unescape === true) {
|
|
551
|
+
if (glob) glob = utils.removeBackslashes(glob);
|
|
552
|
+
if (base && backslashes === true) {
|
|
553
|
+
base = utils.removeBackslashes(base);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
const state = {
|
|
557
|
+
prefix,
|
|
558
|
+
input,
|
|
559
|
+
start,
|
|
560
|
+
base,
|
|
561
|
+
glob,
|
|
562
|
+
isBrace,
|
|
563
|
+
isBracket,
|
|
564
|
+
isGlob,
|
|
565
|
+
isExtglob,
|
|
566
|
+
isGlobstar,
|
|
567
|
+
negated,
|
|
568
|
+
negatedExtglob
|
|
569
|
+
};
|
|
570
|
+
if (opts.tokens === true) {
|
|
571
|
+
state.maxDepth = 0;
|
|
572
|
+
if (!isPathSeparator(code)) {
|
|
573
|
+
tokens.push(token);
|
|
574
|
+
}
|
|
575
|
+
state.tokens = tokens;
|
|
576
|
+
}
|
|
577
|
+
if (opts.parts === true || opts.tokens === true) {
|
|
578
|
+
let prevIndex;
|
|
579
|
+
for (let idx = 0; idx < slashes.length; idx++) {
|
|
580
|
+
const n = prevIndex ? prevIndex + 1 : start;
|
|
581
|
+
const i = slashes[idx];
|
|
582
|
+
const value = input.slice(n, i);
|
|
583
|
+
if (opts.tokens) {
|
|
584
|
+
if (idx === 0 && start !== 0) {
|
|
585
|
+
tokens[idx].isPrefix = true;
|
|
586
|
+
tokens[idx].value = prefix;
|
|
587
|
+
} else {
|
|
588
|
+
tokens[idx].value = value;
|
|
589
|
+
}
|
|
590
|
+
depth(tokens[idx]);
|
|
591
|
+
state.maxDepth += tokens[idx].depth;
|
|
592
|
+
}
|
|
593
|
+
if (idx !== 0 || value !== "") {
|
|
594
|
+
parts.push(value);
|
|
595
|
+
}
|
|
596
|
+
prevIndex = i;
|
|
597
|
+
}
|
|
598
|
+
if (prevIndex && prevIndex + 1 < input.length) {
|
|
599
|
+
const value = input.slice(prevIndex + 1);
|
|
600
|
+
parts.push(value);
|
|
601
|
+
if (opts.tokens) {
|
|
602
|
+
tokens[tokens.length - 1].value = value;
|
|
603
|
+
depth(tokens[tokens.length - 1]);
|
|
604
|
+
state.maxDepth += tokens[tokens.length - 1].depth;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
state.slashes = slashes;
|
|
608
|
+
state.parts = parts;
|
|
609
|
+
}
|
|
610
|
+
return state;
|
|
611
|
+
};
|
|
612
|
+
module.exports = scan;
|
|
613
|
+
}
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
// node_modules/picomatch/lib/parse.js
|
|
617
|
+
var require_parse = __commonJS({
|
|
618
|
+
"node_modules/picomatch/lib/parse.js"(exports, module) {
|
|
619
|
+
"use strict";
|
|
620
|
+
init_require_shim();
|
|
621
|
+
var constants = require_constants();
|
|
622
|
+
var utils = require_utils();
|
|
623
|
+
var {
|
|
624
|
+
MAX_LENGTH,
|
|
625
|
+
POSIX_REGEX_SOURCE,
|
|
626
|
+
REGEX_NON_SPECIAL_CHARS,
|
|
627
|
+
REGEX_SPECIAL_CHARS_BACKREF,
|
|
628
|
+
REPLACEMENTS
|
|
629
|
+
} = constants;
|
|
630
|
+
var expandRange = (args, options) => {
|
|
631
|
+
if (typeof options.expandRange === "function") {
|
|
632
|
+
return options.expandRange(...args, options);
|
|
633
|
+
}
|
|
634
|
+
args.sort();
|
|
635
|
+
const value = `[${args.join("-")}]`;
|
|
636
|
+
try {
|
|
637
|
+
new RegExp(value);
|
|
638
|
+
} catch (ex) {
|
|
639
|
+
return args.map((v) => utils.escapeRegex(v)).join("..");
|
|
640
|
+
}
|
|
641
|
+
return value;
|
|
642
|
+
};
|
|
643
|
+
var syntaxError = (type, char) => {
|
|
644
|
+
return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
|
|
645
|
+
};
|
|
646
|
+
var splitTopLevel = (input) => {
|
|
647
|
+
const parts = [];
|
|
648
|
+
let bracket = 0;
|
|
649
|
+
let paren = 0;
|
|
650
|
+
let quote = 0;
|
|
651
|
+
let value = "";
|
|
652
|
+
let escaped = false;
|
|
653
|
+
for (const ch of input) {
|
|
654
|
+
if (escaped === true) {
|
|
655
|
+
value += ch;
|
|
656
|
+
escaped = false;
|
|
657
|
+
continue;
|
|
658
|
+
}
|
|
659
|
+
if (ch === "\\") {
|
|
660
|
+
value += ch;
|
|
661
|
+
escaped = true;
|
|
662
|
+
continue;
|
|
663
|
+
}
|
|
664
|
+
if (ch === '"') {
|
|
665
|
+
quote = quote === 1 ? 0 : 1;
|
|
666
|
+
value += ch;
|
|
667
|
+
continue;
|
|
668
|
+
}
|
|
669
|
+
if (quote === 0) {
|
|
670
|
+
if (ch === "[") {
|
|
671
|
+
bracket++;
|
|
672
|
+
} else if (ch === "]" && bracket > 0) {
|
|
673
|
+
bracket--;
|
|
674
|
+
} else if (bracket === 0) {
|
|
675
|
+
if (ch === "(") {
|
|
676
|
+
paren++;
|
|
677
|
+
} else if (ch === ")" && paren > 0) {
|
|
678
|
+
paren--;
|
|
679
|
+
} else if (ch === "|" && paren === 0) {
|
|
680
|
+
parts.push(value);
|
|
681
|
+
value = "";
|
|
682
|
+
continue;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
value += ch;
|
|
687
|
+
}
|
|
688
|
+
parts.push(value);
|
|
689
|
+
return parts;
|
|
690
|
+
};
|
|
691
|
+
var isPlainBranch = (branch) => {
|
|
692
|
+
let escaped = false;
|
|
693
|
+
for (const ch of branch) {
|
|
694
|
+
if (escaped === true) {
|
|
695
|
+
escaped = false;
|
|
696
|
+
continue;
|
|
697
|
+
}
|
|
698
|
+
if (ch === "\\") {
|
|
699
|
+
escaped = true;
|
|
700
|
+
continue;
|
|
701
|
+
}
|
|
702
|
+
if (/[?*+@!()[\]{}]/.test(ch)) {
|
|
703
|
+
return false;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
return true;
|
|
707
|
+
};
|
|
708
|
+
var normalizeSimpleBranch = (branch) => {
|
|
709
|
+
let value = branch.trim();
|
|
710
|
+
let changed = true;
|
|
711
|
+
while (changed === true) {
|
|
712
|
+
changed = false;
|
|
713
|
+
if (/^@\([^\\()[\]{}|]+\)$/.test(value)) {
|
|
714
|
+
value = value.slice(2, -1);
|
|
715
|
+
changed = true;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
if (!isPlainBranch(value)) {
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
return value.replace(/\\(.)/g, "$1");
|
|
722
|
+
};
|
|
723
|
+
var hasRepeatedCharPrefixOverlap = (branches) => {
|
|
724
|
+
const values = branches.map(normalizeSimpleBranch).filter(Boolean);
|
|
725
|
+
for (let i = 0; i < values.length; i++) {
|
|
726
|
+
for (let j = i + 1; j < values.length; j++) {
|
|
727
|
+
const a = values[i];
|
|
728
|
+
const b = values[j];
|
|
729
|
+
const char = a[0];
|
|
730
|
+
if (!char || a !== char.repeat(a.length) || b !== char.repeat(b.length)) {
|
|
731
|
+
continue;
|
|
732
|
+
}
|
|
733
|
+
if (a === b || a.startsWith(b) || b.startsWith(a)) {
|
|
734
|
+
return true;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
return false;
|
|
739
|
+
};
|
|
740
|
+
var parseRepeatedExtglob = (pattern, requireEnd = true) => {
|
|
741
|
+
if (pattern[0] !== "+" && pattern[0] !== "*" || pattern[1] !== "(") {
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
744
|
+
let bracket = 0;
|
|
745
|
+
let paren = 0;
|
|
746
|
+
let quote = 0;
|
|
747
|
+
let escaped = false;
|
|
748
|
+
for (let i = 1; i < pattern.length; i++) {
|
|
749
|
+
const ch = pattern[i];
|
|
750
|
+
if (escaped === true) {
|
|
751
|
+
escaped = false;
|
|
752
|
+
continue;
|
|
753
|
+
}
|
|
754
|
+
if (ch === "\\") {
|
|
755
|
+
escaped = true;
|
|
756
|
+
continue;
|
|
757
|
+
}
|
|
758
|
+
if (ch === '"') {
|
|
759
|
+
quote = quote === 1 ? 0 : 1;
|
|
760
|
+
continue;
|
|
761
|
+
}
|
|
762
|
+
if (quote === 1) {
|
|
763
|
+
continue;
|
|
764
|
+
}
|
|
765
|
+
if (ch === "[") {
|
|
766
|
+
bracket++;
|
|
767
|
+
continue;
|
|
768
|
+
}
|
|
769
|
+
if (ch === "]" && bracket > 0) {
|
|
770
|
+
bracket--;
|
|
771
|
+
continue;
|
|
772
|
+
}
|
|
773
|
+
if (bracket > 0) {
|
|
774
|
+
continue;
|
|
775
|
+
}
|
|
776
|
+
if (ch === "(") {
|
|
777
|
+
paren++;
|
|
778
|
+
continue;
|
|
779
|
+
}
|
|
780
|
+
if (ch === ")") {
|
|
781
|
+
paren--;
|
|
782
|
+
if (paren === 0) {
|
|
783
|
+
if (requireEnd === true && i !== pattern.length - 1) {
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
786
|
+
return {
|
|
787
|
+
type: pattern[0],
|
|
788
|
+
body: pattern.slice(2, i),
|
|
789
|
+
end: i
|
|
790
|
+
};
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
};
|
|
795
|
+
var getStarExtglobSequenceOutput = (pattern) => {
|
|
796
|
+
let index = 0;
|
|
797
|
+
const chars = [];
|
|
798
|
+
while (index < pattern.length) {
|
|
799
|
+
const match = parseRepeatedExtglob(pattern.slice(index), false);
|
|
800
|
+
if (!match || match.type !== "*") {
|
|
801
|
+
return;
|
|
802
|
+
}
|
|
803
|
+
const branches = splitTopLevel(match.body).map((branch2) => branch2.trim());
|
|
804
|
+
if (branches.length !== 1) {
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
807
|
+
const branch = normalizeSimpleBranch(branches[0]);
|
|
808
|
+
if (!branch || branch.length !== 1) {
|
|
809
|
+
return;
|
|
810
|
+
}
|
|
811
|
+
chars.push(branch);
|
|
812
|
+
index += match.end + 1;
|
|
813
|
+
}
|
|
814
|
+
if (chars.length < 1) {
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
const source = chars.length === 1 ? utils.escapeRegex(chars[0]) : `[${chars.map((ch) => utils.escapeRegex(ch)).join("")}]`;
|
|
818
|
+
return `${source}*`;
|
|
819
|
+
};
|
|
820
|
+
var repeatedExtglobRecursion = (pattern) => {
|
|
821
|
+
let depth = 0;
|
|
822
|
+
let value = pattern.trim();
|
|
823
|
+
let match = parseRepeatedExtglob(value);
|
|
824
|
+
while (match) {
|
|
825
|
+
depth++;
|
|
826
|
+
value = match.body.trim();
|
|
827
|
+
match = parseRepeatedExtglob(value);
|
|
828
|
+
}
|
|
829
|
+
return depth;
|
|
830
|
+
};
|
|
831
|
+
var analyzeRepeatedExtglob = (body, options) => {
|
|
832
|
+
if (options.maxExtglobRecursion === false) {
|
|
833
|
+
return { risky: false };
|
|
834
|
+
}
|
|
835
|
+
const max = typeof options.maxExtglobRecursion === "number" ? options.maxExtglobRecursion : constants.DEFAULT_MAX_EXTGLOB_RECURSION;
|
|
836
|
+
const branches = splitTopLevel(body).map((branch) => branch.trim());
|
|
837
|
+
if (branches.length > 1) {
|
|
838
|
+
if (branches.some((branch) => branch === "") || branches.some((branch) => /^[*?]+$/.test(branch)) || hasRepeatedCharPrefixOverlap(branches)) {
|
|
839
|
+
return { risky: true };
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
for (const branch of branches) {
|
|
843
|
+
const safeOutput = getStarExtglobSequenceOutput(branch);
|
|
844
|
+
if (safeOutput) {
|
|
845
|
+
return { risky: true, safeOutput };
|
|
846
|
+
}
|
|
847
|
+
if (repeatedExtglobRecursion(branch) > max) {
|
|
848
|
+
return { risky: true };
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
return { risky: false };
|
|
852
|
+
};
|
|
853
|
+
var parse = (input, options) => {
|
|
854
|
+
if (typeof input !== "string") {
|
|
855
|
+
throw new TypeError("Expected a string");
|
|
856
|
+
}
|
|
857
|
+
input = REPLACEMENTS[input] || input;
|
|
858
|
+
const opts = { ...options };
|
|
859
|
+
const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
860
|
+
let len = input.length;
|
|
861
|
+
if (len > max) {
|
|
862
|
+
throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
|
863
|
+
}
|
|
864
|
+
const bos = { type: "bos", value: "", output: opts.prepend || "" };
|
|
865
|
+
const tokens = [bos];
|
|
866
|
+
const capture = opts.capture ? "" : "?:";
|
|
867
|
+
const PLATFORM_CHARS = constants.globChars(opts.windows);
|
|
868
|
+
const EXTGLOB_CHARS = constants.extglobChars(PLATFORM_CHARS);
|
|
869
|
+
const {
|
|
870
|
+
DOT_LITERAL,
|
|
871
|
+
PLUS_LITERAL,
|
|
872
|
+
SLASH_LITERAL,
|
|
873
|
+
ONE_CHAR,
|
|
874
|
+
DOTS_SLASH,
|
|
875
|
+
NO_DOT,
|
|
876
|
+
NO_DOT_SLASH,
|
|
877
|
+
NO_DOTS_SLASH,
|
|
878
|
+
QMARK,
|
|
879
|
+
QMARK_NO_DOT,
|
|
880
|
+
STAR,
|
|
881
|
+
START_ANCHOR
|
|
882
|
+
} = PLATFORM_CHARS;
|
|
883
|
+
const globstar = (opts2) => {
|
|
884
|
+
return `(${capture}(?:(?!${START_ANCHOR}${opts2.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
|
|
885
|
+
};
|
|
886
|
+
const nodot = opts.dot ? "" : NO_DOT;
|
|
887
|
+
const qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT;
|
|
888
|
+
let star = opts.bash === true ? globstar(opts) : STAR;
|
|
889
|
+
if (opts.capture) {
|
|
890
|
+
star = `(${star})`;
|
|
891
|
+
}
|
|
892
|
+
if (typeof opts.noext === "boolean") {
|
|
893
|
+
opts.noextglob = opts.noext;
|
|
894
|
+
}
|
|
895
|
+
const state = {
|
|
896
|
+
input,
|
|
897
|
+
index: -1,
|
|
898
|
+
start: 0,
|
|
899
|
+
dot: opts.dot === true,
|
|
900
|
+
consumed: "",
|
|
901
|
+
output: "",
|
|
902
|
+
prefix: "",
|
|
903
|
+
backtrack: false,
|
|
904
|
+
negated: false,
|
|
905
|
+
brackets: 0,
|
|
906
|
+
braces: 0,
|
|
907
|
+
parens: 0,
|
|
908
|
+
quotes: 0,
|
|
909
|
+
globstar: false,
|
|
910
|
+
tokens
|
|
911
|
+
};
|
|
912
|
+
input = utils.removePrefix(input, state);
|
|
913
|
+
len = input.length;
|
|
914
|
+
const extglobs = [];
|
|
915
|
+
const braces = [];
|
|
916
|
+
const stack = [];
|
|
917
|
+
let prev = bos;
|
|
918
|
+
let value;
|
|
919
|
+
const eos = () => state.index === len - 1;
|
|
920
|
+
const peek = state.peek = (n = 1) => input[state.index + n];
|
|
921
|
+
const advance = state.advance = () => input[++state.index] || "";
|
|
922
|
+
const remaining = () => input.slice(state.index + 1);
|
|
923
|
+
const consume = (value2 = "", num = 0) => {
|
|
924
|
+
state.consumed += value2;
|
|
925
|
+
state.index += num;
|
|
926
|
+
};
|
|
927
|
+
const append = (token) => {
|
|
928
|
+
state.output += token.output != null ? token.output : token.value;
|
|
929
|
+
consume(token.value);
|
|
930
|
+
};
|
|
931
|
+
const negate = () => {
|
|
932
|
+
let count = 1;
|
|
933
|
+
while (peek() === "!" && (peek(2) !== "(" || peek(3) === "?")) {
|
|
934
|
+
advance();
|
|
935
|
+
state.start++;
|
|
936
|
+
count++;
|
|
937
|
+
}
|
|
938
|
+
if (count % 2 === 0) {
|
|
939
|
+
return false;
|
|
940
|
+
}
|
|
941
|
+
state.negated = true;
|
|
942
|
+
state.start++;
|
|
943
|
+
return true;
|
|
944
|
+
};
|
|
945
|
+
const increment = (type) => {
|
|
946
|
+
state[type]++;
|
|
947
|
+
stack.push(type);
|
|
948
|
+
};
|
|
949
|
+
const decrement = (type) => {
|
|
950
|
+
state[type]--;
|
|
951
|
+
stack.pop();
|
|
952
|
+
};
|
|
953
|
+
const push = (tok) => {
|
|
954
|
+
if (prev.type === "globstar") {
|
|
955
|
+
const isBrace = state.braces > 0 && (tok.type === "comma" || tok.type === "brace");
|
|
956
|
+
const isExtglob = tok.extglob === true || extglobs.length && (tok.type === "pipe" || tok.type === "paren");
|
|
957
|
+
if (tok.type !== "slash" && tok.type !== "paren" && !isBrace && !isExtglob) {
|
|
958
|
+
state.output = state.output.slice(0, -prev.output.length);
|
|
959
|
+
prev.type = "star";
|
|
960
|
+
prev.value = "*";
|
|
961
|
+
prev.output = star;
|
|
962
|
+
state.output += prev.output;
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
if (extglobs.length && tok.type !== "paren") {
|
|
966
|
+
extglobs[extglobs.length - 1].inner += tok.value;
|
|
967
|
+
}
|
|
968
|
+
if (tok.value || tok.output) append(tok);
|
|
969
|
+
if (prev && prev.type === "text" && tok.type === "text") {
|
|
970
|
+
prev.output = (prev.output || prev.value) + tok.value;
|
|
971
|
+
prev.value += tok.value;
|
|
972
|
+
return;
|
|
973
|
+
}
|
|
974
|
+
tok.prev = prev;
|
|
975
|
+
tokens.push(tok);
|
|
976
|
+
prev = tok;
|
|
977
|
+
};
|
|
978
|
+
const extglobOpen = (type, value2) => {
|
|
979
|
+
const token = { ...EXTGLOB_CHARS[value2], conditions: 1, inner: "" };
|
|
980
|
+
token.prev = prev;
|
|
981
|
+
token.parens = state.parens;
|
|
982
|
+
token.output = state.output;
|
|
983
|
+
token.startIndex = state.index;
|
|
984
|
+
token.tokensIndex = tokens.length;
|
|
985
|
+
const output = (opts.capture ? "(" : "") + token.open;
|
|
986
|
+
increment("parens");
|
|
987
|
+
push({ type, value: value2, output: state.output ? "" : ONE_CHAR });
|
|
988
|
+
push({ type: "paren", extglob: true, value: advance(), output });
|
|
989
|
+
extglobs.push(token);
|
|
990
|
+
};
|
|
991
|
+
const extglobClose = (token) => {
|
|
992
|
+
const literal = input.slice(token.startIndex, state.index + 1);
|
|
993
|
+
const body = input.slice(token.startIndex + 2, state.index);
|
|
994
|
+
const analysis = analyzeRepeatedExtglob(body, opts);
|
|
995
|
+
if ((token.type === "plus" || token.type === "star") && analysis.risky) {
|
|
996
|
+
const safeOutput = analysis.safeOutput ? (token.output ? "" : ONE_CHAR) + (opts.capture ? `(${analysis.safeOutput})` : analysis.safeOutput) : void 0;
|
|
997
|
+
const open = tokens[token.tokensIndex];
|
|
998
|
+
open.type = "text";
|
|
999
|
+
open.value = literal;
|
|
1000
|
+
open.output = safeOutput || utils.escapeRegex(literal);
|
|
1001
|
+
for (let i = token.tokensIndex + 1; i < tokens.length; i++) {
|
|
1002
|
+
tokens[i].value = "";
|
|
1003
|
+
tokens[i].output = "";
|
|
1004
|
+
delete tokens[i].suffix;
|
|
1005
|
+
}
|
|
1006
|
+
state.output = token.output + open.output;
|
|
1007
|
+
state.backtrack = true;
|
|
1008
|
+
push({ type: "paren", extglob: true, value, output: "" });
|
|
1009
|
+
decrement("parens");
|
|
1010
|
+
return;
|
|
1011
|
+
}
|
|
1012
|
+
let output = token.close + (opts.capture ? ")" : "");
|
|
1013
|
+
let rest;
|
|
1014
|
+
if (token.type === "negate") {
|
|
1015
|
+
let extglobStar = star;
|
|
1016
|
+
if (token.inner && token.inner.length > 1 && token.inner.includes("/")) {
|
|
1017
|
+
extglobStar = globstar(opts);
|
|
1018
|
+
}
|
|
1019
|
+
if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) {
|
|
1020
|
+
output = token.close = `)$))${extglobStar}`;
|
|
1021
|
+
}
|
|
1022
|
+
if (token.inner.includes("*") && (rest = remaining()) && /^\.[^\\/.]+$/.test(rest)) {
|
|
1023
|
+
const expression = parse(rest, { ...options, fastpaths: false }).output;
|
|
1024
|
+
output = token.close = `)${expression})${extglobStar})`;
|
|
1025
|
+
}
|
|
1026
|
+
if (token.prev.type === "bos") {
|
|
1027
|
+
state.negatedExtglob = true;
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
push({ type: "paren", extglob: true, value, output });
|
|
1031
|
+
decrement("parens");
|
|
1032
|
+
};
|
|
1033
|
+
if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) {
|
|
1034
|
+
let backslashes = false;
|
|
1035
|
+
let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
|
|
1036
|
+
if (first === "\\") {
|
|
1037
|
+
backslashes = true;
|
|
1038
|
+
return m;
|
|
1039
|
+
}
|
|
1040
|
+
if (first === "?") {
|
|
1041
|
+
if (esc) {
|
|
1042
|
+
return esc + first + (rest ? QMARK.repeat(rest.length) : "");
|
|
1043
|
+
}
|
|
1044
|
+
if (index === 0) {
|
|
1045
|
+
return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : "");
|
|
1046
|
+
}
|
|
1047
|
+
return QMARK.repeat(chars.length);
|
|
1048
|
+
}
|
|
1049
|
+
if (first === ".") {
|
|
1050
|
+
return DOT_LITERAL.repeat(chars.length);
|
|
1051
|
+
}
|
|
1052
|
+
if (first === "*") {
|
|
1053
|
+
if (esc) {
|
|
1054
|
+
return esc + first + (rest ? star : "");
|
|
1055
|
+
}
|
|
1056
|
+
return star;
|
|
1057
|
+
}
|
|
1058
|
+
return esc ? m : `\\${m}`;
|
|
1059
|
+
});
|
|
1060
|
+
if (backslashes === true) {
|
|
1061
|
+
if (opts.unescape === true) {
|
|
1062
|
+
output = output.replace(/\\/g, "");
|
|
1063
|
+
} else {
|
|
1064
|
+
output = output.replace(/\\+/g, (m) => {
|
|
1065
|
+
return m.length % 2 === 0 ? "\\\\" : m ? "\\" : "";
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
if (output === input && opts.contains === true) {
|
|
1070
|
+
state.output = input;
|
|
1071
|
+
return state;
|
|
1072
|
+
}
|
|
1073
|
+
state.output = utils.wrapOutput(output, state, options);
|
|
1074
|
+
return state;
|
|
1075
|
+
}
|
|
1076
|
+
while (!eos()) {
|
|
1077
|
+
value = advance();
|
|
1078
|
+
if (value === "\0") {
|
|
1079
|
+
continue;
|
|
1080
|
+
}
|
|
1081
|
+
if (value === "\\") {
|
|
1082
|
+
const next = peek();
|
|
1083
|
+
if (next === "/" && opts.bash !== true) {
|
|
1084
|
+
continue;
|
|
1085
|
+
}
|
|
1086
|
+
if (next === "." || next === ";") {
|
|
1087
|
+
continue;
|
|
1088
|
+
}
|
|
1089
|
+
if (!next) {
|
|
1090
|
+
value += "\\";
|
|
1091
|
+
push({ type: "text", value });
|
|
1092
|
+
continue;
|
|
1093
|
+
}
|
|
1094
|
+
const match = /^\\+/.exec(remaining());
|
|
1095
|
+
let slashes = 0;
|
|
1096
|
+
if (match && match[0].length > 2) {
|
|
1097
|
+
slashes = match[0].length;
|
|
1098
|
+
state.index += slashes;
|
|
1099
|
+
if (slashes % 2 !== 0) {
|
|
1100
|
+
value += "\\";
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
if (opts.unescape === true) {
|
|
1104
|
+
value = advance();
|
|
1105
|
+
} else {
|
|
1106
|
+
value += advance();
|
|
1107
|
+
}
|
|
1108
|
+
if (state.brackets === 0) {
|
|
1109
|
+
push({ type: "text", value });
|
|
1110
|
+
continue;
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
if (state.brackets > 0 && (value !== "]" || prev.value === "[" || prev.value === "[^")) {
|
|
1114
|
+
if (opts.posix !== false && value === ":") {
|
|
1115
|
+
const inner = prev.value.slice(1);
|
|
1116
|
+
if (inner.includes("[")) {
|
|
1117
|
+
prev.posix = true;
|
|
1118
|
+
if (inner.includes(":")) {
|
|
1119
|
+
const idx = prev.value.lastIndexOf("[");
|
|
1120
|
+
const pre = prev.value.slice(0, idx);
|
|
1121
|
+
const rest2 = prev.value.slice(idx + 2);
|
|
1122
|
+
const posix = POSIX_REGEX_SOURCE[rest2];
|
|
1123
|
+
if (posix) {
|
|
1124
|
+
prev.value = pre + posix;
|
|
1125
|
+
state.backtrack = true;
|
|
1126
|
+
advance();
|
|
1127
|
+
if (!bos.output && tokens.indexOf(prev) === 1) {
|
|
1128
|
+
bos.output = ONE_CHAR;
|
|
1129
|
+
}
|
|
1130
|
+
continue;
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
if (value === "[" && peek() !== ":" || value === "-" && peek() === "]") {
|
|
1136
|
+
value = `\\${value}`;
|
|
1137
|
+
}
|
|
1138
|
+
if (value === "]" && (prev.value === "[" || prev.value === "[^")) {
|
|
1139
|
+
value = `\\${value}`;
|
|
1140
|
+
}
|
|
1141
|
+
if (opts.posix === true && value === "!" && prev.value === "[") {
|
|
1142
|
+
value = "^";
|
|
1143
|
+
}
|
|
1144
|
+
prev.value += value;
|
|
1145
|
+
append({ value });
|
|
1146
|
+
continue;
|
|
1147
|
+
}
|
|
1148
|
+
if (state.quotes === 1 && value !== '"') {
|
|
1149
|
+
value = utils.escapeRegex(value);
|
|
1150
|
+
prev.value += value;
|
|
1151
|
+
append({ value });
|
|
1152
|
+
continue;
|
|
1153
|
+
}
|
|
1154
|
+
if (value === '"') {
|
|
1155
|
+
state.quotes = state.quotes === 1 ? 0 : 1;
|
|
1156
|
+
if (opts.keepQuotes === true) {
|
|
1157
|
+
push({ type: "text", value });
|
|
1158
|
+
}
|
|
1159
|
+
continue;
|
|
1160
|
+
}
|
|
1161
|
+
if (value === "(") {
|
|
1162
|
+
increment("parens");
|
|
1163
|
+
push({ type: "paren", value });
|
|
1164
|
+
continue;
|
|
1165
|
+
}
|
|
1166
|
+
if (value === ")") {
|
|
1167
|
+
if (state.parens === 0 && opts.strictBrackets === true) {
|
|
1168
|
+
throw new SyntaxError(syntaxError("opening", "("));
|
|
1169
|
+
}
|
|
1170
|
+
const extglob = extglobs[extglobs.length - 1];
|
|
1171
|
+
if (extglob && state.parens === extglob.parens + 1) {
|
|
1172
|
+
extglobClose(extglobs.pop());
|
|
1173
|
+
continue;
|
|
1174
|
+
}
|
|
1175
|
+
push({ type: "paren", value, output: state.parens ? ")" : "\\)" });
|
|
1176
|
+
decrement("parens");
|
|
1177
|
+
continue;
|
|
1178
|
+
}
|
|
1179
|
+
if (value === "[") {
|
|
1180
|
+
if (opts.nobracket === true || !remaining().includes("]")) {
|
|
1181
|
+
if (opts.nobracket !== true && opts.strictBrackets === true) {
|
|
1182
|
+
throw new SyntaxError(syntaxError("closing", "]"));
|
|
1183
|
+
}
|
|
1184
|
+
value = `\\${value}`;
|
|
1185
|
+
} else {
|
|
1186
|
+
increment("brackets");
|
|
1187
|
+
}
|
|
1188
|
+
push({ type: "bracket", value });
|
|
1189
|
+
continue;
|
|
1190
|
+
}
|
|
1191
|
+
if (value === "]") {
|
|
1192
|
+
if (opts.nobracket === true || prev && prev.type === "bracket" && prev.value.length === 1) {
|
|
1193
|
+
push({ type: "text", value, output: `\\${value}` });
|
|
1194
|
+
continue;
|
|
1195
|
+
}
|
|
1196
|
+
if (state.brackets === 0) {
|
|
1197
|
+
if (opts.strictBrackets === true) {
|
|
1198
|
+
throw new SyntaxError(syntaxError("opening", "["));
|
|
1199
|
+
}
|
|
1200
|
+
push({ type: "text", value, output: `\\${value}` });
|
|
1201
|
+
continue;
|
|
1202
|
+
}
|
|
1203
|
+
decrement("brackets");
|
|
1204
|
+
const prevValue = prev.value.slice(1);
|
|
1205
|
+
if (prev.posix !== true && prevValue[0] === "^" && !prevValue.includes("/")) {
|
|
1206
|
+
value = `/${value}`;
|
|
1207
|
+
}
|
|
1208
|
+
prev.value += value;
|
|
1209
|
+
append({ value });
|
|
1210
|
+
if (opts.literalBrackets === false || utils.hasRegexChars(prevValue)) {
|
|
1211
|
+
continue;
|
|
1212
|
+
}
|
|
1213
|
+
const escaped = utils.escapeRegex(prev.value);
|
|
1214
|
+
state.output = state.output.slice(0, -prev.value.length);
|
|
1215
|
+
if (opts.literalBrackets === true) {
|
|
1216
|
+
state.output += escaped;
|
|
1217
|
+
prev.value = escaped;
|
|
1218
|
+
continue;
|
|
1219
|
+
}
|
|
1220
|
+
prev.value = `(${capture}${escaped}|${prev.value})`;
|
|
1221
|
+
state.output += prev.value;
|
|
1222
|
+
continue;
|
|
1223
|
+
}
|
|
1224
|
+
if (value === "{" && opts.nobrace !== true) {
|
|
1225
|
+
increment("braces");
|
|
1226
|
+
const open = {
|
|
1227
|
+
type: "brace",
|
|
1228
|
+
value,
|
|
1229
|
+
output: "(",
|
|
1230
|
+
outputIndex: state.output.length,
|
|
1231
|
+
tokensIndex: state.tokens.length
|
|
1232
|
+
};
|
|
1233
|
+
braces.push(open);
|
|
1234
|
+
push(open);
|
|
1235
|
+
continue;
|
|
1236
|
+
}
|
|
1237
|
+
if (value === "}") {
|
|
1238
|
+
const brace = braces[braces.length - 1];
|
|
1239
|
+
if (opts.nobrace === true || !brace) {
|
|
1240
|
+
push({ type: "text", value, output: value });
|
|
1241
|
+
continue;
|
|
1242
|
+
}
|
|
1243
|
+
let output = ")";
|
|
1244
|
+
if (brace.dots === true) {
|
|
1245
|
+
const arr = tokens.slice();
|
|
1246
|
+
const range = [];
|
|
1247
|
+
for (let i = arr.length - 1; i >= 0; i--) {
|
|
1248
|
+
tokens.pop();
|
|
1249
|
+
if (arr[i].type === "brace") {
|
|
1250
|
+
break;
|
|
1251
|
+
}
|
|
1252
|
+
if (arr[i].type !== "dots") {
|
|
1253
|
+
range.unshift(arr[i].value);
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
output = expandRange(range, opts);
|
|
1257
|
+
state.backtrack = true;
|
|
1258
|
+
}
|
|
1259
|
+
if (brace.comma !== true && brace.dots !== true) {
|
|
1260
|
+
const out = state.output.slice(0, brace.outputIndex);
|
|
1261
|
+
const toks = state.tokens.slice(brace.tokensIndex);
|
|
1262
|
+
brace.value = brace.output = "\\{";
|
|
1263
|
+
value = output = "\\}";
|
|
1264
|
+
state.output = out;
|
|
1265
|
+
for (const t of toks) {
|
|
1266
|
+
state.output += t.output || t.value;
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
push({ type: "brace", value, output });
|
|
1270
|
+
decrement("braces");
|
|
1271
|
+
braces.pop();
|
|
1272
|
+
continue;
|
|
1273
|
+
}
|
|
1274
|
+
if (value === "|") {
|
|
1275
|
+
if (extglobs.length > 0) {
|
|
1276
|
+
extglobs[extglobs.length - 1].conditions++;
|
|
1277
|
+
}
|
|
1278
|
+
push({ type: "text", value });
|
|
1279
|
+
continue;
|
|
1280
|
+
}
|
|
1281
|
+
if (value === ",") {
|
|
1282
|
+
let output = value;
|
|
1283
|
+
const brace = braces[braces.length - 1];
|
|
1284
|
+
if (brace && stack[stack.length - 1] === "braces") {
|
|
1285
|
+
brace.comma = true;
|
|
1286
|
+
output = "|";
|
|
1287
|
+
}
|
|
1288
|
+
push({ type: "comma", value, output });
|
|
1289
|
+
continue;
|
|
1290
|
+
}
|
|
1291
|
+
if (value === "/") {
|
|
1292
|
+
if (prev.type === "dot" && state.index === state.start + 1) {
|
|
1293
|
+
state.start = state.index + 1;
|
|
1294
|
+
state.consumed = "";
|
|
1295
|
+
state.output = "";
|
|
1296
|
+
tokens.pop();
|
|
1297
|
+
prev = bos;
|
|
1298
|
+
continue;
|
|
1299
|
+
}
|
|
1300
|
+
push({ type: "slash", value, output: SLASH_LITERAL });
|
|
1301
|
+
continue;
|
|
1302
|
+
}
|
|
1303
|
+
if (value === ".") {
|
|
1304
|
+
if (state.braces > 0 && prev.type === "dot") {
|
|
1305
|
+
if (prev.value === ".") prev.output = DOT_LITERAL;
|
|
1306
|
+
const brace = braces[braces.length - 1];
|
|
1307
|
+
prev.type = "dots";
|
|
1308
|
+
prev.output += value;
|
|
1309
|
+
prev.value += value;
|
|
1310
|
+
brace.dots = true;
|
|
1311
|
+
continue;
|
|
1312
|
+
}
|
|
1313
|
+
if (state.braces + state.parens === 0 && prev.type !== "bos" && prev.type !== "slash") {
|
|
1314
|
+
push({ type: "text", value, output: DOT_LITERAL });
|
|
1315
|
+
continue;
|
|
1316
|
+
}
|
|
1317
|
+
push({ type: "dot", value, output: DOT_LITERAL });
|
|
1318
|
+
continue;
|
|
1319
|
+
}
|
|
1320
|
+
if (value === "?") {
|
|
1321
|
+
const isGroup = prev && prev.value === "(";
|
|
1322
|
+
if (!isGroup && opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
1323
|
+
extglobOpen("qmark", value);
|
|
1324
|
+
continue;
|
|
1325
|
+
}
|
|
1326
|
+
if (prev && prev.type === "paren") {
|
|
1327
|
+
const next = peek();
|
|
1328
|
+
let output = value;
|
|
1329
|
+
if (prev.value === "(" && !/[!=<:]/.test(next) || next === "<" && !/<([!=]|\w+>)/.test(remaining())) {
|
|
1330
|
+
output = `\\${value}`;
|
|
1331
|
+
}
|
|
1332
|
+
push({ type: "text", value, output });
|
|
1333
|
+
continue;
|
|
1334
|
+
}
|
|
1335
|
+
if (opts.dot !== true && (prev.type === "slash" || prev.type === "bos")) {
|
|
1336
|
+
push({ type: "qmark", value, output: QMARK_NO_DOT });
|
|
1337
|
+
continue;
|
|
1338
|
+
}
|
|
1339
|
+
push({ type: "qmark", value, output: QMARK });
|
|
1340
|
+
continue;
|
|
1341
|
+
}
|
|
1342
|
+
if (value === "!") {
|
|
1343
|
+
if (opts.noextglob !== true && peek() === "(") {
|
|
1344
|
+
if (peek(2) !== "?" || !/[!=<:]/.test(peek(3))) {
|
|
1345
|
+
extglobOpen("negate", value);
|
|
1346
|
+
continue;
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
if (opts.nonegate !== true && state.index === 0) {
|
|
1350
|
+
negate();
|
|
1351
|
+
continue;
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
if (value === "+") {
|
|
1355
|
+
if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
1356
|
+
extglobOpen("plus", value);
|
|
1357
|
+
continue;
|
|
1358
|
+
}
|
|
1359
|
+
if (prev && prev.value === "(" || opts.regex === false) {
|
|
1360
|
+
push({ type: "plus", value, output: PLUS_LITERAL });
|
|
1361
|
+
continue;
|
|
1362
|
+
}
|
|
1363
|
+
if (prev && (prev.type === "bracket" || prev.type === "paren" || prev.type === "brace") || state.parens > 0) {
|
|
1364
|
+
push({ type: "plus", value });
|
|
1365
|
+
continue;
|
|
1366
|
+
}
|
|
1367
|
+
push({ type: "plus", value: PLUS_LITERAL });
|
|
1368
|
+
continue;
|
|
1369
|
+
}
|
|
1370
|
+
if (value === "@") {
|
|
1371
|
+
if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
1372
|
+
push({ type: "at", extglob: true, value, output: "" });
|
|
1373
|
+
continue;
|
|
1374
|
+
}
|
|
1375
|
+
push({ type: "text", value });
|
|
1376
|
+
continue;
|
|
1377
|
+
}
|
|
1378
|
+
if (value !== "*") {
|
|
1379
|
+
if (value === "$" || value === "^") {
|
|
1380
|
+
value = `\\${value}`;
|
|
1381
|
+
}
|
|
1382
|
+
const match = REGEX_NON_SPECIAL_CHARS.exec(remaining());
|
|
1383
|
+
if (match) {
|
|
1384
|
+
value += match[0];
|
|
1385
|
+
state.index += match[0].length;
|
|
1386
|
+
}
|
|
1387
|
+
push({ type: "text", value });
|
|
1388
|
+
continue;
|
|
1389
|
+
}
|
|
1390
|
+
if (prev && (prev.type === "globstar" || prev.star === true)) {
|
|
1391
|
+
prev.type = "star";
|
|
1392
|
+
prev.star = true;
|
|
1393
|
+
prev.value += value;
|
|
1394
|
+
prev.output = star;
|
|
1395
|
+
state.backtrack = true;
|
|
1396
|
+
state.globstar = true;
|
|
1397
|
+
consume(value);
|
|
1398
|
+
continue;
|
|
1399
|
+
}
|
|
1400
|
+
let rest = remaining();
|
|
1401
|
+
if (opts.noextglob !== true && /^\([^?]/.test(rest)) {
|
|
1402
|
+
extglobOpen("star", value);
|
|
1403
|
+
continue;
|
|
1404
|
+
}
|
|
1405
|
+
if (prev.type === "star") {
|
|
1406
|
+
if (opts.noglobstar === true) {
|
|
1407
|
+
consume(value);
|
|
1408
|
+
continue;
|
|
1409
|
+
}
|
|
1410
|
+
const prior = prev.prev;
|
|
1411
|
+
const before = prior.prev;
|
|
1412
|
+
const isStart = prior.type === "slash" || prior.type === "bos";
|
|
1413
|
+
const afterStar = before && (before.type === "star" || before.type === "globstar");
|
|
1414
|
+
if (opts.bash === true && (!isStart || rest[0] && rest[0] !== "/")) {
|
|
1415
|
+
push({ type: "star", value, output: "" });
|
|
1416
|
+
continue;
|
|
1417
|
+
}
|
|
1418
|
+
const isBrace = state.braces > 0 && (prior.type === "comma" || prior.type === "brace");
|
|
1419
|
+
const isExtglob = extglobs.length && (prior.type === "pipe" || prior.type === "paren");
|
|
1420
|
+
if (!isStart && prior.type !== "paren" && !isBrace && !isExtglob) {
|
|
1421
|
+
push({ type: "star", value, output: "" });
|
|
1422
|
+
continue;
|
|
1423
|
+
}
|
|
1424
|
+
while (rest.slice(0, 3) === "/**") {
|
|
1425
|
+
const after = input[state.index + 4];
|
|
1426
|
+
if (after && after !== "/") {
|
|
1427
|
+
break;
|
|
1428
|
+
}
|
|
1429
|
+
rest = rest.slice(3);
|
|
1430
|
+
consume("/**", 3);
|
|
1431
|
+
}
|
|
1432
|
+
if (prior.type === "bos" && eos()) {
|
|
1433
|
+
prev.type = "globstar";
|
|
1434
|
+
prev.value += value;
|
|
1435
|
+
prev.output = globstar(opts);
|
|
1436
|
+
state.output = prev.output;
|
|
1437
|
+
state.globstar = true;
|
|
1438
|
+
consume(value);
|
|
1439
|
+
continue;
|
|
1440
|
+
}
|
|
1441
|
+
if (prior.type === "slash" && prior.prev.type !== "bos" && !afterStar && eos()) {
|
|
1442
|
+
state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
|
1443
|
+
prior.output = `(?:${prior.output}`;
|
|
1444
|
+
prev.type = "globstar";
|
|
1445
|
+
prev.output = globstar(opts) + (opts.strictSlashes ? ")" : "|$)");
|
|
1446
|
+
prev.value += value;
|
|
1447
|
+
state.globstar = true;
|
|
1448
|
+
state.output += prior.output + prev.output;
|
|
1449
|
+
consume(value);
|
|
1450
|
+
continue;
|
|
1451
|
+
}
|
|
1452
|
+
if (prior.type === "slash" && prior.prev.type !== "bos" && rest[0] === "/") {
|
|
1453
|
+
const end = rest[1] !== void 0 ? "|$" : "";
|
|
1454
|
+
state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
|
1455
|
+
prior.output = `(?:${prior.output}`;
|
|
1456
|
+
prev.type = "globstar";
|
|
1457
|
+
prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`;
|
|
1458
|
+
prev.value += value;
|
|
1459
|
+
state.output += prior.output + prev.output;
|
|
1460
|
+
state.globstar = true;
|
|
1461
|
+
consume(value + advance());
|
|
1462
|
+
push({ type: "slash", value: "/", output: "" });
|
|
1463
|
+
continue;
|
|
1464
|
+
}
|
|
1465
|
+
if (prior.type === "bos" && rest[0] === "/") {
|
|
1466
|
+
prev.type = "globstar";
|
|
1467
|
+
prev.value += value;
|
|
1468
|
+
prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`;
|
|
1469
|
+
state.output = prev.output;
|
|
1470
|
+
state.globstar = true;
|
|
1471
|
+
consume(value + advance());
|
|
1472
|
+
push({ type: "slash", value: "/", output: "" });
|
|
1473
|
+
continue;
|
|
1474
|
+
}
|
|
1475
|
+
state.output = state.output.slice(0, -prev.output.length);
|
|
1476
|
+
prev.type = "globstar";
|
|
1477
|
+
prev.output = globstar(opts);
|
|
1478
|
+
prev.value += value;
|
|
1479
|
+
state.output += prev.output;
|
|
1480
|
+
state.globstar = true;
|
|
1481
|
+
consume(value);
|
|
1482
|
+
continue;
|
|
1483
|
+
}
|
|
1484
|
+
const token = { type: "star", value, output: star };
|
|
1485
|
+
if (opts.bash === true) {
|
|
1486
|
+
token.output = ".*?";
|
|
1487
|
+
if (prev.type === "bos" || prev.type === "slash") {
|
|
1488
|
+
token.output = nodot + token.output;
|
|
1489
|
+
}
|
|
1490
|
+
push(token);
|
|
1491
|
+
continue;
|
|
1492
|
+
}
|
|
1493
|
+
if (prev && (prev.type === "bracket" || prev.type === "paren") && opts.regex === true) {
|
|
1494
|
+
token.output = value;
|
|
1495
|
+
push(token);
|
|
1496
|
+
continue;
|
|
1497
|
+
}
|
|
1498
|
+
if (state.index === state.start || prev.type === "slash" || prev.type === "dot") {
|
|
1499
|
+
if (prev.type === "dot") {
|
|
1500
|
+
state.output += NO_DOT_SLASH;
|
|
1501
|
+
prev.output += NO_DOT_SLASH;
|
|
1502
|
+
} else if (opts.dot === true) {
|
|
1503
|
+
state.output += NO_DOTS_SLASH;
|
|
1504
|
+
prev.output += NO_DOTS_SLASH;
|
|
1505
|
+
} else {
|
|
1506
|
+
state.output += nodot;
|
|
1507
|
+
prev.output += nodot;
|
|
1508
|
+
}
|
|
1509
|
+
if (peek() !== "*") {
|
|
1510
|
+
state.output += ONE_CHAR;
|
|
1511
|
+
prev.output += ONE_CHAR;
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
push(token);
|
|
1515
|
+
}
|
|
1516
|
+
while (state.brackets > 0) {
|
|
1517
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "]"));
|
|
1518
|
+
state.output = utils.escapeLast(state.output, "[");
|
|
1519
|
+
decrement("brackets");
|
|
1520
|
+
}
|
|
1521
|
+
while (state.parens > 0) {
|
|
1522
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", ")"));
|
|
1523
|
+
state.output = utils.escapeLast(state.output, "(");
|
|
1524
|
+
decrement("parens");
|
|
1525
|
+
}
|
|
1526
|
+
while (state.braces > 0) {
|
|
1527
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "}"));
|
|
1528
|
+
state.output = utils.escapeLast(state.output, "{");
|
|
1529
|
+
decrement("braces");
|
|
1530
|
+
}
|
|
1531
|
+
if (opts.strictSlashes !== true && (prev.type === "star" || prev.type === "bracket")) {
|
|
1532
|
+
push({ type: "maybe_slash", value: "", output: `${SLASH_LITERAL}?` });
|
|
1533
|
+
}
|
|
1534
|
+
if (state.backtrack === true) {
|
|
1535
|
+
state.output = "";
|
|
1536
|
+
for (const token of state.tokens) {
|
|
1537
|
+
state.output += token.output != null ? token.output : token.value;
|
|
1538
|
+
if (token.suffix) {
|
|
1539
|
+
state.output += token.suffix;
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
return state;
|
|
1544
|
+
};
|
|
1545
|
+
parse.fastpaths = (input, options) => {
|
|
1546
|
+
const opts = { ...options };
|
|
1547
|
+
const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
1548
|
+
const len = input.length;
|
|
1549
|
+
if (len > max) {
|
|
1550
|
+
throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
|
1551
|
+
}
|
|
1552
|
+
input = REPLACEMENTS[input] || input;
|
|
1553
|
+
const {
|
|
1554
|
+
DOT_LITERAL,
|
|
1555
|
+
SLASH_LITERAL,
|
|
1556
|
+
ONE_CHAR,
|
|
1557
|
+
DOTS_SLASH,
|
|
1558
|
+
NO_DOT,
|
|
1559
|
+
NO_DOTS,
|
|
1560
|
+
NO_DOTS_SLASH,
|
|
1561
|
+
STAR,
|
|
1562
|
+
START_ANCHOR
|
|
1563
|
+
} = constants.globChars(opts.windows);
|
|
1564
|
+
const nodot = opts.dot ? NO_DOTS : NO_DOT;
|
|
1565
|
+
const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
|
|
1566
|
+
const capture = opts.capture ? "" : "?:";
|
|
1567
|
+
const state = { negated: false, prefix: "" };
|
|
1568
|
+
let star = opts.bash === true ? ".*?" : STAR;
|
|
1569
|
+
if (opts.capture) {
|
|
1570
|
+
star = `(${star})`;
|
|
1571
|
+
}
|
|
1572
|
+
const globstar = (opts2) => {
|
|
1573
|
+
if (opts2.noglobstar === true) return star;
|
|
1574
|
+
return `(${capture}(?:(?!${START_ANCHOR}${opts2.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
|
|
1575
|
+
};
|
|
1576
|
+
const create = (str) => {
|
|
1577
|
+
switch (str) {
|
|
1578
|
+
case "*":
|
|
1579
|
+
return `${nodot}${ONE_CHAR}${star}`;
|
|
1580
|
+
case ".*":
|
|
1581
|
+
return `${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
1582
|
+
case "*.*":
|
|
1583
|
+
return `${nodot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
1584
|
+
case "*/*":
|
|
1585
|
+
return `${nodot}${star}${SLASH_LITERAL}${ONE_CHAR}${slashDot}${star}`;
|
|
1586
|
+
case "**":
|
|
1587
|
+
return nodot + globstar(opts);
|
|
1588
|
+
case "**/*":
|
|
1589
|
+
return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${ONE_CHAR}${star}`;
|
|
1590
|
+
case "**/*.*":
|
|
1591
|
+
return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
1592
|
+
case "**/.*":
|
|
1593
|
+
return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
1594
|
+
default: {
|
|
1595
|
+
const match = /^(.*?)\.(\w+)$/.exec(str);
|
|
1596
|
+
if (!match) return;
|
|
1597
|
+
const source2 = create(match[1]);
|
|
1598
|
+
if (!source2) return;
|
|
1599
|
+
return source2 + DOT_LITERAL + match[2];
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
};
|
|
1603
|
+
const output = utils.removePrefix(input, state);
|
|
1604
|
+
let source = create(output);
|
|
1605
|
+
if (source && opts.strictSlashes !== true) {
|
|
1606
|
+
source += `${SLASH_LITERAL}?`;
|
|
1607
|
+
}
|
|
1608
|
+
return source;
|
|
1609
|
+
};
|
|
1610
|
+
module.exports = parse;
|
|
1611
|
+
}
|
|
1612
|
+
});
|
|
1613
|
+
|
|
1614
|
+
// node_modules/picomatch/lib/picomatch.js
|
|
1615
|
+
var require_picomatch = __commonJS({
|
|
1616
|
+
"node_modules/picomatch/lib/picomatch.js"(exports, module) {
|
|
1617
|
+
"use strict";
|
|
1618
|
+
init_require_shim();
|
|
1619
|
+
var scan = require_scan();
|
|
1620
|
+
var parse = require_parse();
|
|
1621
|
+
var utils = require_utils();
|
|
1622
|
+
var constants = require_constants();
|
|
1623
|
+
var isObject = (val) => val && typeof val === "object" && !Array.isArray(val);
|
|
1624
|
+
var picomatch2 = (glob, options, returnState = false) => {
|
|
1625
|
+
if (Array.isArray(glob)) {
|
|
1626
|
+
const fns = glob.map((input) => picomatch2(input, options, returnState));
|
|
1627
|
+
const arrayMatcher = (str) => {
|
|
1628
|
+
for (const isMatch of fns) {
|
|
1629
|
+
const state2 = isMatch(str);
|
|
1630
|
+
if (state2) return state2;
|
|
1631
|
+
}
|
|
1632
|
+
return false;
|
|
1633
|
+
};
|
|
1634
|
+
return arrayMatcher;
|
|
1635
|
+
}
|
|
1636
|
+
const isState = isObject(glob) && glob.tokens && glob.input;
|
|
1637
|
+
if (glob === "" || typeof glob !== "string" && !isState) {
|
|
1638
|
+
throw new TypeError("Expected pattern to be a non-empty string");
|
|
1639
|
+
}
|
|
1640
|
+
const opts = options || {};
|
|
1641
|
+
const posix = opts.windows;
|
|
1642
|
+
const regex = isState ? picomatch2.compileRe(glob, options) : picomatch2.makeRe(glob, options, false, true);
|
|
1643
|
+
const state = regex.state;
|
|
1644
|
+
delete regex.state;
|
|
1645
|
+
let isIgnored = () => false;
|
|
1646
|
+
if (opts.ignore) {
|
|
1647
|
+
const ignoreOpts = { ...options, ignore: null, onMatch: null, onResult: null };
|
|
1648
|
+
isIgnored = picomatch2(opts.ignore, ignoreOpts, returnState);
|
|
1649
|
+
}
|
|
1650
|
+
const matcher = (input, returnObject = false) => {
|
|
1651
|
+
const { isMatch, match, output } = picomatch2.test(input, regex, options, { glob, posix });
|
|
1652
|
+
const result = { glob, state, regex, posix, input, output, match, isMatch };
|
|
1653
|
+
if (typeof opts.onResult === "function") {
|
|
1654
|
+
opts.onResult(result);
|
|
1655
|
+
}
|
|
1656
|
+
if (isMatch === false) {
|
|
1657
|
+
result.isMatch = false;
|
|
1658
|
+
return returnObject ? result : false;
|
|
1659
|
+
}
|
|
1660
|
+
if (isIgnored(input)) {
|
|
1661
|
+
if (typeof opts.onIgnore === "function") {
|
|
1662
|
+
opts.onIgnore(result);
|
|
1663
|
+
}
|
|
1664
|
+
result.isMatch = false;
|
|
1665
|
+
return returnObject ? result : false;
|
|
1666
|
+
}
|
|
1667
|
+
if (typeof opts.onMatch === "function") {
|
|
1668
|
+
opts.onMatch(result);
|
|
1669
|
+
}
|
|
1670
|
+
return returnObject ? result : true;
|
|
1671
|
+
};
|
|
1672
|
+
if (returnState) {
|
|
1673
|
+
matcher.state = state;
|
|
1674
|
+
}
|
|
1675
|
+
return matcher;
|
|
1676
|
+
};
|
|
1677
|
+
picomatch2.test = (input, regex, options, { glob, posix } = {}) => {
|
|
1678
|
+
if (typeof input !== "string") {
|
|
1679
|
+
throw new TypeError("Expected input to be a string");
|
|
1680
|
+
}
|
|
1681
|
+
if (input === "") {
|
|
1682
|
+
return { isMatch: false, output: "" };
|
|
1683
|
+
}
|
|
1684
|
+
const opts = options || {};
|
|
1685
|
+
const format = opts.format || (posix ? utils.toPosixSlashes : null);
|
|
1686
|
+
let match = input === glob;
|
|
1687
|
+
let output = match && format ? format(input) : input;
|
|
1688
|
+
if (match === false) {
|
|
1689
|
+
output = format ? format(input) : input;
|
|
1690
|
+
match = output === glob;
|
|
1691
|
+
}
|
|
1692
|
+
if (match === false || opts.capture === true) {
|
|
1693
|
+
if (opts.matchBase === true || opts.basename === true) {
|
|
1694
|
+
match = picomatch2.matchBase(input, regex, options, posix);
|
|
1695
|
+
} else {
|
|
1696
|
+
match = regex.exec(output);
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
return { isMatch: Boolean(match), match, output };
|
|
1700
|
+
};
|
|
1701
|
+
picomatch2.matchBase = (input, glob, options) => {
|
|
1702
|
+
const regex = glob instanceof RegExp ? glob : picomatch2.makeRe(glob, options);
|
|
1703
|
+
return regex.test(utils.basename(input));
|
|
1704
|
+
};
|
|
1705
|
+
picomatch2.isMatch = (str, patterns, options) => picomatch2(patterns, options)(str);
|
|
1706
|
+
picomatch2.parse = (pattern, options) => {
|
|
1707
|
+
if (Array.isArray(pattern)) return pattern.map((p) => picomatch2.parse(p, options));
|
|
1708
|
+
return parse(pattern, { ...options, fastpaths: false });
|
|
1709
|
+
};
|
|
1710
|
+
picomatch2.scan = (input, options) => scan(input, options);
|
|
1711
|
+
picomatch2.compileRe = (state, options, returnOutput = false, returnState = false) => {
|
|
1712
|
+
if (returnOutput === true) {
|
|
1713
|
+
return state.output;
|
|
1714
|
+
}
|
|
1715
|
+
const opts = options || {};
|
|
1716
|
+
const prepend = opts.contains ? "" : "^";
|
|
1717
|
+
const append = opts.contains ? "" : "$";
|
|
1718
|
+
let source = `${prepend}(?:${state.output})${append}`;
|
|
1719
|
+
if (state && state.negated === true) {
|
|
1720
|
+
source = `^(?!${source}).*$`;
|
|
1721
|
+
}
|
|
1722
|
+
const regex = picomatch2.toRegex(source, options);
|
|
1723
|
+
if (returnState === true) {
|
|
1724
|
+
regex.state = state;
|
|
1725
|
+
}
|
|
1726
|
+
return regex;
|
|
1727
|
+
};
|
|
1728
|
+
picomatch2.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
|
|
1729
|
+
if (!input || typeof input !== "string") {
|
|
1730
|
+
throw new TypeError("Expected a non-empty string");
|
|
1731
|
+
}
|
|
1732
|
+
let parsed = { negated: false, fastpaths: true };
|
|
1733
|
+
if (options.fastpaths !== false && (input[0] === "." || input[0] === "*")) {
|
|
1734
|
+
parsed.output = parse.fastpaths(input, options);
|
|
1735
|
+
}
|
|
1736
|
+
if (!parsed.output) {
|
|
1737
|
+
parsed = parse(input, options);
|
|
1738
|
+
}
|
|
1739
|
+
return picomatch2.compileRe(parsed, options, returnOutput, returnState);
|
|
1740
|
+
};
|
|
1741
|
+
picomatch2.toRegex = (source, options) => {
|
|
1742
|
+
try {
|
|
1743
|
+
const opts = options || {};
|
|
1744
|
+
return new RegExp(source, opts.flags || (opts.nocase ? "i" : ""));
|
|
1745
|
+
} catch (err) {
|
|
1746
|
+
if (options && options.debug === true) throw err;
|
|
1747
|
+
return /$^/;
|
|
1748
|
+
}
|
|
1749
|
+
};
|
|
1750
|
+
picomatch2.constants = constants;
|
|
1751
|
+
module.exports = picomatch2;
|
|
1752
|
+
}
|
|
1753
|
+
});
|
|
1754
|
+
|
|
1755
|
+
// node_modules/picomatch/index.js
|
|
1756
|
+
var require_picomatch2 = __commonJS({
|
|
1757
|
+
"node_modules/picomatch/index.js"(exports, module) {
|
|
1758
|
+
"use strict";
|
|
1759
|
+
init_require_shim();
|
|
1760
|
+
var pico = require_picomatch();
|
|
1761
|
+
var utils = require_utils();
|
|
1762
|
+
function picomatch2(glob, options, returnState = false) {
|
|
1763
|
+
if (options && (options.windows === null || options.windows === void 0)) {
|
|
1764
|
+
options = { ...options, windows: utils.isWindows() };
|
|
1765
|
+
}
|
|
1766
|
+
return pico(glob, options, returnState);
|
|
1767
|
+
}
|
|
1768
|
+
Object.assign(picomatch2, pico);
|
|
1769
|
+
module.exports = picomatch2;
|
|
1770
|
+
}
|
|
1771
|
+
});
|
|
1772
|
+
|
|
1773
|
+
// src/shared/match.js
|
|
1774
|
+
init_require_shim();
|
|
1775
|
+
var import_picomatch = __toESM(require_picomatch2(), 1);
|
|
1776
|
+
var isGlobMatch = (value, pattern) => import_picomatch.default.isMatch(value, pattern, { dot: true });
|
|
1777
|
+
function wildcardToRegex(pattern) {
|
|
1778
|
+
const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
1779
|
+
return new RegExp("^" + escaped.replace(/\*+/g, "[\\s\\S]*") + "$");
|
|
1780
|
+
}
|
|
1781
|
+
var isWildcardMatch = (value, patterns) => {
|
|
1782
|
+
const list = Array.isArray(patterns) ? patterns : [patterns];
|
|
1783
|
+
return list.some((p) => wildcardToRegex(p).test(value));
|
|
1784
|
+
};
|
|
1785
|
+
|
|
1786
|
+
// src/project/index.js
|
|
1787
|
+
init_require_shim();
|
|
1788
|
+
import { readFile, writeFile, mkdir } from "node:fs/promises";
|
|
1789
|
+
import { dirname } from "node:path";
|
|
1790
|
+
import { createHash } from "node:crypto";
|
|
1791
|
+
import path from "node:path";
|
|
1792
|
+
function shortHash(str) {
|
|
1793
|
+
return createHash("sha1").update(str).digest("hex").slice(0, 8);
|
|
1794
|
+
}
|
|
1795
|
+
async function ensureProjectIdentity(dir) {
|
|
1796
|
+
const localJsonPath = path.join(dir, ".crunes", "project.local.json");
|
|
1797
|
+
try {
|
|
1798
|
+
const raw = await readFile(localJsonPath, "utf8");
|
|
1799
|
+
return JSON.parse(raw);
|
|
1800
|
+
} catch {
|
|
1801
|
+
}
|
|
1802
|
+
let alias = path.basename(dir);
|
|
1803
|
+
try {
|
|
1804
|
+
const config = JSON.parse(await readFile(path.join(dir, ".crunes", "config.json"), "utf8"));
|
|
1805
|
+
if (typeof config.name === "string" && config.name.length > 0) alias = config.name;
|
|
1806
|
+
} catch {
|
|
1807
|
+
}
|
|
1808
|
+
const id = `${path.basename(dir).slice(0, 15)}-${shortHash(dir + "-" + Math.random())}`;
|
|
1809
|
+
const identity = { id, alias };
|
|
1810
|
+
await mkdir(path.join(dir, ".crunes"), { recursive: true });
|
|
1811
|
+
await writeFile(localJsonPath, JSON.stringify(identity, null, 2), "utf8");
|
|
1812
|
+
return identity;
|
|
1813
|
+
}
|
|
1814
|
+
async function loadProjects() {
|
|
1815
|
+
try {
|
|
1816
|
+
const raw = await readFile(getProjectsJsonPath(), "utf8");
|
|
1817
|
+
return JSON.parse(raw);
|
|
1818
|
+
} catch {
|
|
1819
|
+
return { format: "1", projects: {} };
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
async function upsertProject(id, projectDir) {
|
|
1823
|
+
const data = await loadProjects();
|
|
1824
|
+
let alias = path.basename(projectDir);
|
|
1825
|
+
try {
|
|
1826
|
+
const raw = await readFile(path.join(projectDir, ".crunes", "project.local.json"), "utf8");
|
|
1827
|
+
const parsed = JSON.parse(raw);
|
|
1828
|
+
if (typeof parsed.alias === "string" && parsed.alias.length > 0) alias = parsed.alias;
|
|
1829
|
+
} catch {
|
|
1830
|
+
}
|
|
1831
|
+
const existing = data.projects[id];
|
|
1832
|
+
data.projects[id] = {
|
|
1833
|
+
path: projectDir,
|
|
1834
|
+
alias,
|
|
1835
|
+
lastActiveAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1836
|
+
firstSeenAt: existing?.firstSeenAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
1837
|
+
};
|
|
1838
|
+
const p = getProjectsJsonPath();
|
|
1839
|
+
await mkdir(dirname(p), { recursive: true });
|
|
1840
|
+
await writeFile(p, JSON.stringify(data, null, 2), "utf8");
|
|
1841
|
+
}
|
|
1842
|
+
|
|
1843
|
+
// src/rune/api/utils.js
|
|
1844
|
+
init_require_shim();
|
|
1845
|
+
import os from "node:os";
|
|
1846
|
+
import path2 from "node:path";
|
|
1847
|
+
var VIRTUAL_STORE_PREFIXES = [
|
|
1848
|
+
"@global-plugin-cache",
|
|
1849
|
+
"@global-plugin-sqlite",
|
|
1850
|
+
"@local-cache",
|
|
1851
|
+
"@local-plugin-cache",
|
|
1852
|
+
"@local-sqlite",
|
|
1853
|
+
"@local-plugin-sqlite"
|
|
1854
|
+
];
|
|
1855
|
+
function parseVirtualStore(location) {
|
|
1856
|
+
for (const prefix of VIRTUAL_STORE_PREFIXES) {
|
|
1857
|
+
if (location === prefix) return { prefix, subpath: "" };
|
|
1858
|
+
if (location.startsWith(prefix + "/")) {
|
|
1859
|
+
const raw = location.slice(prefix.length + 1);
|
|
1860
|
+
const normalized = path2.normalize(raw).replace(/\\/g, "/");
|
|
1861
|
+
if (normalized.startsWith("..")) throw new RangeError(`subpath escapes virtual root: ${location}`);
|
|
1862
|
+
return { prefix, subpath: normalized };
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
return null;
|
|
1866
|
+
}
|
|
1867
|
+
function virtualStoreBase(prefix, { dir, pluginId }) {
|
|
1868
|
+
switch (prefix) {
|
|
1869
|
+
case "@global-plugin-cache":
|
|
1870
|
+
if (!pluginId) throw new Error("@global-plugin-cache requires a plugin context");
|
|
1871
|
+
return getCachePluginDir(pluginId);
|
|
1872
|
+
case "@global-plugin-sqlite":
|
|
1873
|
+
if (!pluginId) throw new Error("@global-plugin-sqlite requires a plugin context");
|
|
1874
|
+
return getSqlitePluginDir(pluginId);
|
|
1875
|
+
case "@local-cache":
|
|
1876
|
+
return path2.join(getLocalBase(dir), "caches", "project");
|
|
1877
|
+
case "@local-plugin-cache":
|
|
1878
|
+
if (!pluginId) throw new Error("@local-plugin-cache requires a plugin context");
|
|
1879
|
+
return path2.join(getLocalBase(dir), "caches", "plugins", pluginId);
|
|
1880
|
+
case "@local-sqlite":
|
|
1881
|
+
return path2.join(getLocalBase(dir), "sqlite", "project");
|
|
1882
|
+
case "@local-plugin-sqlite":
|
|
1883
|
+
if (!pluginId) throw new Error("@local-plugin-sqlite requires a plugin context");
|
|
1884
|
+
return path2.join(getLocalBase(dir), "sqlite", "plugins", pluginId);
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
function resolvePath(location, { dir, pluginDir = null, pluginId = null, storeDir = null } = {}) {
|
|
1888
|
+
if (location.startsWith("@plugin/")) {
|
|
1889
|
+
if (!pluginDir) throw new Error("@plugin/ paths are only available in plugin runes");
|
|
1890
|
+
return path2.join(pluginDir, location.slice("@plugin/".length));
|
|
1891
|
+
}
|
|
1892
|
+
if (location.startsWith("@project/")) {
|
|
1893
|
+
return path2.join(dir, location.slice("@project/".length));
|
|
1894
|
+
}
|
|
1895
|
+
const virtual = parseVirtualStore(location);
|
|
1896
|
+
if (virtual) {
|
|
1897
|
+
const base = virtualStoreBase(virtual.prefix, { dir, pluginId });
|
|
1898
|
+
return virtual.subpath ? path2.join(base, virtual.subpath) : base;
|
|
1899
|
+
}
|
|
1900
|
+
if (location === "~" || location.startsWith("~/") || location.startsWith("~\\")) {
|
|
1901
|
+
return path2.join(os.homedir(), location.slice(1));
|
|
1902
|
+
}
|
|
1903
|
+
if (path2.isAbsolute(location)) return location;
|
|
1904
|
+
return path2.resolve(dir, location);
|
|
1905
|
+
}
|
|
1906
|
+
function getAutoPermits({ pluginId = null, pluginDir = null } = {}) {
|
|
1907
|
+
const permits = [];
|
|
1908
|
+
if (!pluginDir) {
|
|
1909
|
+
permits.push(
|
|
1910
|
+
"fs.read:./.crunes/**",
|
|
1911
|
+
"cache.read:@local-cache/**",
|
|
1912
|
+
"cache.write:@local-cache/**",
|
|
1913
|
+
"sqlite.read:@local-sqlite/**",
|
|
1914
|
+
"sqlite.write:@local-sqlite/**",
|
|
1915
|
+
"fs.read:@local-sqlite/**",
|
|
1916
|
+
"fs.write:@local-sqlite/**"
|
|
1917
|
+
);
|
|
1918
|
+
}
|
|
1919
|
+
if (pluginDir) {
|
|
1920
|
+
permits.push("fs.read:@plugin/**", "fs.write:@plugin/**");
|
|
1921
|
+
}
|
|
1922
|
+
if (pluginId) {
|
|
1923
|
+
permits.push(
|
|
1924
|
+
"cache.read:@global-plugin-cache/**",
|
|
1925
|
+
"cache.write:@global-plugin-cache/**",
|
|
1926
|
+
"sqlite.read:@global-plugin-sqlite/**",
|
|
1927
|
+
"sqlite.write:@global-plugin-sqlite/**",
|
|
1928
|
+
"fs.read:@global-plugin-sqlite/**",
|
|
1929
|
+
"fs.write:@global-plugin-sqlite/**"
|
|
1930
|
+
);
|
|
1931
|
+
}
|
|
1932
|
+
return permits;
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1935
|
+
// src/rune/permissions/permissions.js
|
|
1936
|
+
init_require_shim();
|
|
1937
|
+
import os2 from "node:os";
|
|
1938
|
+
|
|
1939
|
+
// src/rune/permissions/permissions-http.js
|
|
1940
|
+
init_require_shim();
|
|
1941
|
+
function matchFetchPermission(value, patterns) {
|
|
1942
|
+
const vDoubleColon = value.indexOf("::");
|
|
1943
|
+
if (vDoubleColon === -1) return false;
|
|
1944
|
+
const valueMethod = value.slice(0, vDoubleColon).toUpperCase();
|
|
1945
|
+
const valueUrl = value.slice(vDoubleColon + 2);
|
|
1946
|
+
return patterns.some((pattern) => {
|
|
1947
|
+
const doubleColonIndex = pattern.indexOf("::");
|
|
1948
|
+
const left = doubleColonIndex === -1 ? "" : pattern.slice(0, doubleColonIndex);
|
|
1949
|
+
const right = doubleColonIndex === -1 ? pattern : pattern.slice(doubleColonIndex + 2);
|
|
1950
|
+
const patternMethods = left ? left.split(",").map((m) => m.trim().toUpperCase()) : ["GET"];
|
|
1951
|
+
const methodOk = patternMethods.includes("*") || patternMethods.includes(valueMethod);
|
|
1952
|
+
return methodOk && isGlobMatch(valueUrl, right);
|
|
1953
|
+
});
|
|
1954
|
+
}
|
|
1955
|
+
|
|
1956
|
+
// src/rune/permissions/permissions-env.js
|
|
1957
|
+
init_require_shim();
|
|
1958
|
+
function parseEnvPattern(pattern) {
|
|
1959
|
+
const body = pattern.startsWith("env.read:") ? pattern.slice(9) : pattern;
|
|
1960
|
+
const dColonIdx = body.indexOf("::");
|
|
1961
|
+
if (dColonIdx === -1) {
|
|
1962
|
+
return { sources: ["*"], keyPatterns: [body] };
|
|
1963
|
+
}
|
|
1964
|
+
const left = body.slice(0, dColonIdx);
|
|
1965
|
+
const right = body.slice(dColonIdx + 2);
|
|
1966
|
+
return {
|
|
1967
|
+
sources: left ? left.split(",").map((s) => s.trim()) : ["process"],
|
|
1968
|
+
keyPatterns: right.split(",").map((k) => k.trim())
|
|
1969
|
+
};
|
|
1970
|
+
}
|
|
1971
|
+
function matchEnvPermission(value, patterns) {
|
|
1972
|
+
const dColonIdx = value.indexOf("::");
|
|
1973
|
+
if (dColonIdx === -1) return false;
|
|
1974
|
+
const valueSource = value.slice(0, dColonIdx);
|
|
1975
|
+
const valueKey = value.slice(dColonIdx + 2);
|
|
1976
|
+
return patterns.some((pattern) => {
|
|
1977
|
+
const { sources, keyPatterns } = parseEnvPattern(pattern);
|
|
1978
|
+
const sourceOk = sources.includes("*") || sources.includes(valueSource);
|
|
1979
|
+
const keyOk = keyPatterns.some((pat) => isWildcardMatch(valueKey, pat));
|
|
1980
|
+
return sourceOk && keyOk;
|
|
1981
|
+
});
|
|
1982
|
+
}
|
|
1983
|
+
|
|
1984
|
+
// src/rune/permissions/permissions-store.js
|
|
1985
|
+
init_require_shim();
|
|
1986
|
+
function matchStorePermission(value, patterns) {
|
|
1987
|
+
const vDColon = value.indexOf("::");
|
|
1988
|
+
const valueLoc = vDColon >= 0 ? value.slice(0, vDColon) : value;
|
|
1989
|
+
const valueName = vDColon >= 0 ? value.slice(vDColon + 2) : null;
|
|
1990
|
+
const sub = (s) => s.startsWith("./") ? "__DOT__/" + s.slice(2) : s;
|
|
1991
|
+
return patterns.some((pattern) => {
|
|
1992
|
+
const dColonIdx = pattern.indexOf("::");
|
|
1993
|
+
const patLoc = dColonIdx !== -1 ? pattern.slice(0, dColonIdx) : pattern;
|
|
1994
|
+
const patName = dColonIdx !== -1 ? pattern.slice(dColonIdx + 2) : null;
|
|
1995
|
+
const nameOk = patName === "*" || patName == null || valueName != null && isWildcardMatch(valueName, patName);
|
|
1996
|
+
if (patLoc.startsWith("@") && patLoc.endsWith("/**")) {
|
|
1997
|
+
const bare = patLoc.slice(0, -3);
|
|
1998
|
+
return isGlobMatch(valueLoc, [patLoc, bare]) && nameOk;
|
|
1999
|
+
}
|
|
2000
|
+
return isGlobMatch(sub(valueLoc), sub(patLoc)) && nameOk;
|
|
2001
|
+
});
|
|
2002
|
+
}
|
|
2003
|
+
|
|
2004
|
+
// src/rune/permissions/permissions-ws.js
|
|
2005
|
+
init_require_shim();
|
|
2006
|
+
function matchWsPermission(url, patterns) {
|
|
2007
|
+
return isGlobMatch(url, patterns);
|
|
2008
|
+
}
|
|
2009
|
+
function matchWsServerPermission(value, patterns) {
|
|
2010
|
+
const colonIdx = value.indexOf(":");
|
|
2011
|
+
if (colonIdx === -1) return false;
|
|
2012
|
+
const valueHost = value.slice(0, colonIdx);
|
|
2013
|
+
const rest = value.slice(colonIdx + 1);
|
|
2014
|
+
const secondColon = rest.indexOf(":");
|
|
2015
|
+
const valuePort = secondColon === -1 ? rest : rest.slice(0, secondColon);
|
|
2016
|
+
const valuePath = secondColon !== -1 ? rest.slice(secondColon + 1) : null;
|
|
2017
|
+
return patterns.some((pattern) => {
|
|
2018
|
+
const patColonIdx = pattern.indexOf(":");
|
|
2019
|
+
if (patColonIdx === -1) return false;
|
|
2020
|
+
const patHost = pattern.slice(0, patColonIdx);
|
|
2021
|
+
const patRest = pattern.slice(patColonIdx + 1);
|
|
2022
|
+
const patSecondColon = patRest.indexOf(":");
|
|
2023
|
+
const patPort = patSecondColon === -1 ? patRest : patRest.slice(0, patSecondColon);
|
|
2024
|
+
const patPath = patSecondColon !== -1 ? patRest.slice(patSecondColon + 1) : null;
|
|
2025
|
+
const hostOk = patHost === "*" || patHost === valueHost;
|
|
2026
|
+
const portOk = patPort === "*" || patPort === valuePort;
|
|
2027
|
+
const pathOk = patPath === null ? valuePath === null : patPath === "*" ? valuePath !== null : patPath === valuePath;
|
|
2028
|
+
return hostOk && portOk && pathOk;
|
|
2029
|
+
});
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
// src/rune/permissions/permissions-http-server.js
|
|
2033
|
+
init_require_shim();
|
|
2034
|
+
var LOOPBACK = /* @__PURE__ */ new Set(["127.0.0.1", "localhost", "::1"]);
|
|
2035
|
+
function isLoopbackHost(host) {
|
|
2036
|
+
return LOOPBACK.has(host);
|
|
2037
|
+
}
|
|
2038
|
+
function matchHttpServerPermission(value, patterns) {
|
|
2039
|
+
const lastColon = value.lastIndexOf(":");
|
|
2040
|
+
if (lastColon === -1) return false;
|
|
2041
|
+
const valueHost = value.slice(0, lastColon);
|
|
2042
|
+
const valuePort = value.slice(lastColon + 1);
|
|
2043
|
+
return patterns.some((pattern) => {
|
|
2044
|
+
const lastPatColon = pattern.lastIndexOf(":");
|
|
2045
|
+
if (lastPatColon === -1) return false;
|
|
2046
|
+
const patHost = pattern.slice(0, lastPatColon);
|
|
2047
|
+
const patPort = pattern.slice(lastPatColon + 1);
|
|
2048
|
+
return (patHost === "*" || patHost === valueHost) && (patPort === "*" || patPort === valuePort);
|
|
2049
|
+
});
|
|
2050
|
+
}
|
|
2051
|
+
|
|
2052
|
+
// src/rune/permissions/permissions.js
|
|
2053
|
+
var PermissionError = class extends Error {
|
|
2054
|
+
/**
|
|
2055
|
+
* reason:
|
|
2056
|
+
* 'ungranted' — the value was checked and no grant matched
|
|
2057
|
+
* 'unscannable' — the command could not be classified, so it was denied
|
|
2058
|
+
* without ever being matched against grants
|
|
2059
|
+
*/
|
|
2060
|
+
constructor(capability, value, reason = "ungranted", details = {}) {
|
|
2061
|
+
const message = reason === "unscannable" ? `Cannot scan command: '${details.construct}' at offset ${details.offset} is not supported.` : `'${capability}:${value}' is not permitted.`;
|
|
2062
|
+
super(message);
|
|
2063
|
+
this.name = "PermissionError";
|
|
2064
|
+
this.capability = capability;
|
|
2065
|
+
this.value = value;
|
|
2066
|
+
this.reason = reason;
|
|
2067
|
+
if (reason === "unscannable") {
|
|
2068
|
+
this.construct = details.construct;
|
|
2069
|
+
this.offset = details.offset;
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
};
|
|
2073
|
+
var HOME = os2.homedir().replace(/\\/g, "/");
|
|
2074
|
+
var LOCAL_VIRTUAL_PREFIXES = /* @__PURE__ */ new Set([
|
|
2075
|
+
"@local-cache",
|
|
2076
|
+
"@local-plugin-cache",
|
|
2077
|
+
"@local-sqlite",
|
|
2078
|
+
"@local-plugin-sqlite"
|
|
2079
|
+
]);
|
|
2080
|
+
var ALL_VIRTUAL_PREFIXES = [
|
|
2081
|
+
"@global-plugin-cache",
|
|
2082
|
+
"@global-plugin-sqlite",
|
|
2083
|
+
"@local-cache",
|
|
2084
|
+
"@local-plugin-cache",
|
|
2085
|
+
"@local-sqlite",
|
|
2086
|
+
"@local-plugin-sqlite",
|
|
2087
|
+
"@plugin"
|
|
2088
|
+
];
|
|
2089
|
+
function expandPattern(perm, ctx) {
|
|
2090
|
+
const colonIdx = perm.indexOf(":");
|
|
2091
|
+
if (colonIdx === -1) return [perm];
|
|
2092
|
+
const cap = perm.slice(0, colonIdx);
|
|
2093
|
+
const isFs = cap === "fs.read" || cap === "fs.write" || cap === "fs.exists";
|
|
2094
|
+
const isStore = cap === "cache.read" || cap === "cache.write" || cap === "sqlite.read" || cap === "sqlite.write";
|
|
2095
|
+
if (!isFs && !isStore) return [perm];
|
|
2096
|
+
if (!ctx?.dir) return [perm];
|
|
2097
|
+
const { dir, pluginId = null, pluginDir = null } = ctx;
|
|
2098
|
+
const absDir = dir.replace(/\\/g, "/");
|
|
2099
|
+
if (isStore) {
|
|
2100
|
+
const rest = perm.slice(colonIdx + 1);
|
|
2101
|
+
const dColonIdx = rest.indexOf("::");
|
|
2102
|
+
const loc = dColonIdx === -1 ? rest : rest.slice(0, dColonIdx);
|
|
2103
|
+
const name = dColonIdx === -1 ? "" : "::" + rest.slice(dColonIdx + 2);
|
|
2104
|
+
return expandLocValue(loc, absDir, { pluginId, pluginDir }, dir).map((expandedLoc) => `${cap}:${expandedLoc}${name}`);
|
|
2105
|
+
}
|
|
2106
|
+
const value = perm.slice(colonIdx + 1);
|
|
2107
|
+
return expandLocValue(value, absDir, { pluginId, pluginDir }, dir).map((v) => `${cap}:${v}`);
|
|
2108
|
+
}
|
|
2109
|
+
function normalizeGitBashPath(p) {
|
|
2110
|
+
if (process.platform === "win32") {
|
|
2111
|
+
const m = p.match(/^\/([a-zA-Z])(\/|$)/);
|
|
2112
|
+
if (m) return `${m[1].toUpperCase()}:/${p.slice(3)}`;
|
|
2113
|
+
}
|
|
2114
|
+
return p;
|
|
2115
|
+
}
|
|
2116
|
+
function expandLocValue(value, absDir, { pluginId, pluginDir }, dir) {
|
|
2117
|
+
const v = value.replace(/\\/g, "/");
|
|
2118
|
+
if (v === "**" || v.startsWith("**/")) return [v];
|
|
2119
|
+
if (v.startsWith("~/")) return [v, HOME + v.slice(1)];
|
|
2120
|
+
if (v.startsWith("../")) return [v];
|
|
2121
|
+
const isAbsolute = v.startsWith("/") || /^[a-zA-Z]:/.test(v);
|
|
2122
|
+
if (isAbsolute) {
|
|
2123
|
+
if (v.startsWith(absDir + "/")) {
|
|
2124
|
+
const rel2 = v.slice(absDir.length + 1);
|
|
2125
|
+
return [v, `./${rel2}`, rel2, `@project/${rel2}`];
|
|
2126
|
+
}
|
|
2127
|
+
return [v];
|
|
2128
|
+
}
|
|
2129
|
+
if (v.startsWith("@project/")) {
|
|
2130
|
+
const rel2 = v.slice("@project/".length);
|
|
2131
|
+
return [v, `./${rel2}`, rel2, absDir + "/" + rel2];
|
|
2132
|
+
}
|
|
2133
|
+
const matchedPrefix = ALL_VIRTUAL_PREFIXES.find((p) => v === p || v.startsWith(p + "/"));
|
|
2134
|
+
if (matchedPrefix) {
|
|
2135
|
+
const suffix = v.slice(matchedPrefix.length);
|
|
2136
|
+
try {
|
|
2137
|
+
const base = resolvePath(matchedPrefix, { dir, pluginId, pluginDir }).replace(/\\/g, "/");
|
|
2138
|
+
const absResolved = base + suffix;
|
|
2139
|
+
if (LOCAL_VIRTUAL_PREFIXES.has(matchedPrefix)) {
|
|
2140
|
+
const rel2 = absResolved.slice(absDir.length + 1);
|
|
2141
|
+
return [v, absResolved, `./${rel2}`, rel2, `@project/${rel2}`];
|
|
2142
|
+
}
|
|
2143
|
+
return [v, absResolved];
|
|
2144
|
+
} catch {
|
|
2145
|
+
return [v];
|
|
2146
|
+
}
|
|
2147
|
+
}
|
|
2148
|
+
const hasDot = v.startsWith("./");
|
|
2149
|
+
const rel = hasDot ? v.slice(2) : v;
|
|
2150
|
+
const relIsGlob = rel === "**" || rel.startsWith("**/");
|
|
2151
|
+
return hasDot ? relIsGlob ? [`./${rel}`, absDir + "/" + rel, `@project/${rel}`] : [`./${rel}`, rel, absDir + "/" + rel, `@project/${rel}`] : [`./${rel}`, rel, absDir + "/" + rel, `@project/${rel}`];
|
|
2152
|
+
}
|
|
2153
|
+
function parseGlobPerm(value) {
|
|
2154
|
+
const dColonIdx = value.indexOf("::");
|
|
2155
|
+
return { cwd: value.slice(0, dColonIdx), pattern: value.slice(dColonIdx + 2) };
|
|
2156
|
+
}
|
|
2157
|
+
function matchGlobPermission(runtimePattern, runtimeAbsCwd, declaredValues, ctx) {
|
|
2158
|
+
const normCwd = runtimeAbsCwd.replace(/\\/g, "/");
|
|
2159
|
+
return declaredValues.some((val) => {
|
|
2160
|
+
const { cwd: declCwd, pattern: declPattern } = parseGlobPerm(val);
|
|
2161
|
+
if (declPattern !== "*" && declPattern !== runtimePattern) return false;
|
|
2162
|
+
try {
|
|
2163
|
+
const resolvedDeclCwd = resolvePath(declCwd, { dir: ctx.dir, pluginId: ctx.pluginId, pluginDir: ctx.pluginDir }).replace(/\\/g, "/");
|
|
2164
|
+
const sub = (s) => s.startsWith("./") ? "__DOT__/" + s.slice(2) : s;
|
|
2165
|
+
return isGlobMatch(sub(normCwd), [sub(resolvedDeclCwd)]);
|
|
2166
|
+
} catch {
|
|
2167
|
+
return false;
|
|
2168
|
+
}
|
|
2169
|
+
});
|
|
2170
|
+
}
|
|
2171
|
+
function normalizeFsPath(raw) {
|
|
2172
|
+
const val = normalizeGitBashPath(raw.replace(/\\/g, "/"));
|
|
2173
|
+
const v = val.startsWith("@project/") ? "./" + val.slice("@project/".length) : val;
|
|
2174
|
+
const isAbsolute = v.startsWith("/") || /^[a-zA-Z]:/.test(v);
|
|
2175
|
+
return !v.startsWith("./") && !v.startsWith("../") && !v.startsWith("@") && !v.startsWith("~/") && !isAbsolute ? `./${v}` : v;
|
|
2176
|
+
}
|
|
2177
|
+
function normalizePattern(perm) {
|
|
2178
|
+
if (perm === "*" || perm === "*:*") return "*";
|
|
2179
|
+
if (perm.startsWith("fs.glob:")) {
|
|
2180
|
+
const rest = perm.slice("fs.glob:".length);
|
|
2181
|
+
const dColonIdx = rest.indexOf("::");
|
|
2182
|
+
if (dColonIdx === -1) {
|
|
2183
|
+
return `fs.glob:.::${rest}`;
|
|
2184
|
+
}
|
|
2185
|
+
const rawCwd = rest.slice(0, dColonIdx);
|
|
2186
|
+
const pattern = rest.slice(dColonIdx + 2);
|
|
2187
|
+
return `fs.glob:${normalizeFsPath(rawCwd)}::${pattern}`;
|
|
2188
|
+
}
|
|
2189
|
+
if (perm.startsWith("fs.read:") || perm.startsWith("fs.write:") || perm.startsWith("fs.exists:")) {
|
|
2190
|
+
const [cap, ...rest] = perm.split(":");
|
|
2191
|
+
return `${cap}:${normalizeFsPath(rest.join(":"))}`;
|
|
2192
|
+
}
|
|
2193
|
+
if (perm.startsWith("cache.read:") || perm.startsWith("cache.write:") || perm.startsWith("sqlite.read:") || perm.startsWith("sqlite.write:")) {
|
|
2194
|
+
const colonIdx = perm.indexOf(":");
|
|
2195
|
+
const cap = perm.slice(0, colonIdx);
|
|
2196
|
+
const rest = perm.slice(colonIdx + 1);
|
|
2197
|
+
if (rest.startsWith("@")) return perm;
|
|
2198
|
+
const dColonIdx = rest.indexOf("::");
|
|
2199
|
+
const rawLoc = dColonIdx === -1 ? rest : rest.slice(0, dColonIdx);
|
|
2200
|
+
const rawName = dColonIdx !== -1 ? rest.slice(dColonIdx + 2) : null;
|
|
2201
|
+
let loc = rawLoc;
|
|
2202
|
+
if (!loc.startsWith("./") && !loc.startsWith("../") && !loc.startsWith("~/") && !loc.startsWith("/") && !/^[a-zA-Z]:/.test(loc)) {
|
|
2203
|
+
loc = "./" + loc;
|
|
2204
|
+
}
|
|
2205
|
+
if (rawName === null) return `${cap}:${loc}`;
|
|
2206
|
+
return `${cap}:${loc}::${rawName}`;
|
|
2207
|
+
}
|
|
2208
|
+
return perm;
|
|
2209
|
+
}
|
|
2210
|
+
function computeEffectivePermissions(pluginPerms, projectPerms, lifecycle) {
|
|
2211
|
+
const namespacePlugin = pluginPerms?.[lifecycle] || {};
|
|
2212
|
+
const namespaceProject = projectPerms?.[lifecycle];
|
|
2213
|
+
const pluginAllow = (namespacePlugin.allow ?? []).map(normalizePattern);
|
|
2214
|
+
const pluginDeny = (namespacePlugin.deny ?? []).map(normalizePattern);
|
|
2215
|
+
return {
|
|
2216
|
+
allow: namespaceProject?.allow ? namespaceProject.allow.map(normalizePattern) : pluginAllow,
|
|
2217
|
+
deny: [...pluginDeny, ...(namespaceProject?.deny ?? []).map(normalizePattern)]
|
|
2218
|
+
};
|
|
2219
|
+
}
|
|
2220
|
+
function makePermissionChecker(effective, ctx = null) {
|
|
2221
|
+
const hasWildcardAllow = (effective.allow ?? []).some((p) => p === "*" || p === "*:*");
|
|
2222
|
+
const hasWildcardDeny = (effective.deny ?? []).some((p) => p === "*" || p === "*:*");
|
|
2223
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
2224
|
+
const getBucket = (cap) => {
|
|
2225
|
+
if (!buckets.has(cap)) buckets.set(cap, { allow: [], deny: [] });
|
|
2226
|
+
return buckets.get(cap);
|
|
2227
|
+
};
|
|
2228
|
+
const capOf = (p) => {
|
|
2229
|
+
const i = p.indexOf(":");
|
|
2230
|
+
return i === -1 ? p : p.slice(0, i);
|
|
2231
|
+
};
|
|
2232
|
+
const globBucket = { allow: [], deny: [] };
|
|
2233
|
+
for (const p of effective.allow.map(normalizePattern)) {
|
|
2234
|
+
if (p === "*") continue;
|
|
2235
|
+
if (p.startsWith("fs.glob:")) {
|
|
2236
|
+
globBucket.allow.push(p.slice("fs.glob:".length));
|
|
2237
|
+
continue;
|
|
2238
|
+
}
|
|
2239
|
+
for (const expanded of expandPattern(p, ctx)) getBucket(capOf(expanded)).allow.push(expanded);
|
|
2240
|
+
}
|
|
2241
|
+
for (const p of effective.deny.map(normalizePattern)) {
|
|
2242
|
+
if (p === "*") continue;
|
|
2243
|
+
if (p.startsWith("fs.glob:")) {
|
|
2244
|
+
globBucket.deny.push(p.slice("fs.glob:".length));
|
|
2245
|
+
continue;
|
|
2246
|
+
}
|
|
2247
|
+
for (const expanded of expandPattern(p, ctx)) getBucket(capOf(expanded)).deny.push(expanded);
|
|
2248
|
+
}
|
|
2249
|
+
const pvs = (list, cap) => {
|
|
2250
|
+
const n = cap.length + 1;
|
|
2251
|
+
return list.reduce((acc, p) => {
|
|
2252
|
+
if (p.length > n) acc.push(p.slice(n));
|
|
2253
|
+
return acc;
|
|
2254
|
+
}, []);
|
|
2255
|
+
};
|
|
2256
|
+
const checkBatchAndThrow = (capability, value, matchFn) => {
|
|
2257
|
+
const b = buckets.get(capability) ?? { allow: [], deny: [] };
|
|
2258
|
+
const allowed = hasWildcardAllow || b.allow.length > 0 && matchFn(pvs(b.allow, capability));
|
|
2259
|
+
const denied = hasWildcardDeny || b.deny.length > 0 && matchFn(pvs(b.deny, capability));
|
|
2260
|
+
if (!allowed || denied) throw new PermissionError(capability, value);
|
|
2261
|
+
};
|
|
2262
|
+
const absDir = ctx?.dir?.replace(/\\/g, "/") ?? "";
|
|
2263
|
+
const globCtx = { pluginId: ctx?.pluginId ?? null, pluginDir: ctx?.pluginDir ?? null, dir: ctx?.dir ?? "" };
|
|
2264
|
+
return function checkPermission(capability, value, absCwd) {
|
|
2265
|
+
switch (capability) {
|
|
2266
|
+
case "fs.read":
|
|
2267
|
+
case "fs.write":
|
|
2268
|
+
case "fs.exists": {
|
|
2269
|
+
const sub = (s) => s.startsWith("./") ? "__DOT__/" + s.slice(2) : s;
|
|
2270
|
+
const v = sub(normalizeFsPath(value));
|
|
2271
|
+
checkBatchAndThrow(capability, value, (pvs2) => isGlobMatch(v, pvs2.map(sub)));
|
|
2272
|
+
return;
|
|
2273
|
+
}
|
|
2274
|
+
case "fs.glob": {
|
|
2275
|
+
const resolvedCwd = (absCwd ?? absDir).replace(/\\/g, "/");
|
|
2276
|
+
const allowed = hasWildcardAllow || globBucket.allow.length > 0 && matchGlobPermission(value, resolvedCwd, globBucket.allow, globCtx);
|
|
2277
|
+
const denied = hasWildcardDeny || globBucket.deny.length > 0 && matchGlobPermission(value, resolvedCwd, globBucket.deny, globCtx);
|
|
2278
|
+
if (!allowed || denied) throw new PermissionError(capability, value);
|
|
2279
|
+
return;
|
|
2280
|
+
}
|
|
2281
|
+
case "shell.run":
|
|
2282
|
+
case "shell.job.start":
|
|
2283
|
+
case "rune.run":
|
|
2284
|
+
case "rune.repl":
|
|
2285
|
+
case "rune.job.start":
|
|
2286
|
+
case "db.connect": {
|
|
2287
|
+
checkBatchAndThrow(capability, value, (pvs2) => isWildcardMatch(value.replace(/\\/g, "/"), pvs2));
|
|
2288
|
+
return;
|
|
2289
|
+
}
|
|
2290
|
+
// Capabilities whose value is always null — permission declared as bare capability name.
|
|
2291
|
+
case "rune.job.kill":
|
|
2292
|
+
case "rune.job.exists":
|
|
2293
|
+
case "rune.job.read":
|
|
2294
|
+
case "rune.job.write":
|
|
2295
|
+
case "shell.job.kill":
|
|
2296
|
+
case "shell.job.exists":
|
|
2297
|
+
case "shell.job.read":
|
|
2298
|
+
case "shell.job.write":
|
|
2299
|
+
case "notify.send": {
|
|
2300
|
+
const b = buckets.get(capability);
|
|
2301
|
+
const allowed = hasWildcardAllow || b?.allow.length > 0;
|
|
2302
|
+
const denied = hasWildcardDeny || b?.deny.length > 0;
|
|
2303
|
+
if (!allowed || denied) throw new PermissionError(capability, "");
|
|
2304
|
+
return;
|
|
2305
|
+
}
|
|
2306
|
+
case "http.fetch":
|
|
2307
|
+
checkBatchAndThrow(capability, value, (pvs2) => matchFetchPermission(value, pvs2));
|
|
2308
|
+
return;
|
|
2309
|
+
case "env.read":
|
|
2310
|
+
checkBatchAndThrow(capability, value, (pvs2) => matchEnvPermission(value, pvs2));
|
|
2311
|
+
return;
|
|
2312
|
+
case "sqlite.read":
|
|
2313
|
+
case "sqlite.write":
|
|
2314
|
+
case "cache.read":
|
|
2315
|
+
case "cache.write":
|
|
2316
|
+
checkBatchAndThrow(capability, value, (pvs2) => matchStorePermission(value, pvs2));
|
|
2317
|
+
return;
|
|
2318
|
+
case "ws.client":
|
|
2319
|
+
checkBatchAndThrow(capability, value, (pvs2) => matchWsPermission(value, pvs2));
|
|
2320
|
+
return;
|
|
2321
|
+
case "http.server": {
|
|
2322
|
+
const colonIdx = value.lastIndexOf(":");
|
|
2323
|
+
const host = colonIdx !== -1 ? value.slice(0, colonIdx) : value;
|
|
2324
|
+
if (isLoopbackHost(host)) return;
|
|
2325
|
+
checkBatchAndThrow(capability, value, (pvs2) => matchHttpServerPermission(value, pvs2));
|
|
2326
|
+
return;
|
|
2327
|
+
}
|
|
2328
|
+
case "ws.server": {
|
|
2329
|
+
const firstColon = value.indexOf(":");
|
|
2330
|
+
const host = firstColon !== -1 ? value.slice(0, firstColon) : value;
|
|
2331
|
+
if (isLoopbackHost(host)) return;
|
|
2332
|
+
checkBatchAndThrow(capability, value, (pvs2) => matchWsServerPermission(value, pvs2));
|
|
2333
|
+
return;
|
|
2334
|
+
}
|
|
2335
|
+
default:
|
|
2336
|
+
if (hasWildcardAllow && !hasWildcardDeny) return;
|
|
2337
|
+
throw new PermissionError(capability, value ?? "");
|
|
2338
|
+
}
|
|
2339
|
+
};
|
|
2340
|
+
}
|
|
2341
|
+
|
|
2342
|
+
export {
|
|
2343
|
+
require_picomatch2 as require_picomatch,
|
|
2344
|
+
isGlobMatch,
|
|
2345
|
+
isWildcardMatch,
|
|
2346
|
+
ensureProjectIdentity,
|
|
2347
|
+
upsertProject,
|
|
2348
|
+
resolvePath,
|
|
2349
|
+
getAutoPermits,
|
|
2350
|
+
parseEnvPattern,
|
|
2351
|
+
PermissionError,
|
|
2352
|
+
computeEffectivePermissions,
|
|
2353
|
+
makePermissionChecker
|
|
2354
|
+
};
|