@darkrymit/crunes-cli 0.8.5 → 0.9.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/{apply-J4YICV6H.js → apply-YY7MIM64.js} +9 -9
- package/dist/chunks/{benchmark-AKKV7G32.js → benchmark-BQNMULOO.js} +17 -14
- package/dist/chunks/{browse-JZFU52ET.js → browse-PHMBDREQ.js} +2 -2
- package/dist/chunks/{chunk-6MRZXASS.js → chunk-2Q3KLBE6.js} +16 -0
- package/dist/chunks/{chunk-KII6KW5Z.js → chunk-34F4ZURL.js} +40 -37
- package/dist/chunks/{chunk-ZJDKCC2Y.js → chunk-4GJMCFR6.js} +6 -3
- package/dist/chunks/chunk-CY6C6ADU.js +2787 -0
- package/dist/chunks/{chunk-J3GZ3DXD.js → chunk-GVMT55GH.js} +3 -2
- package/dist/chunks/{chunk-JOAL437H.js → chunk-I6MHDUCW.js} +16 -1
- package/dist/chunks/{chunk-6XLT25GS.js → chunk-MIKWIFYR.js} +47 -0
- package/dist/chunks/chunk-MRNZFUXZ.js +70 -0
- package/dist/chunks/{chunk-T53L5CJW.js → chunk-PBGUKXT6.js} +2887 -1874
- package/dist/chunks/chunk-QYRF3R35.js +154 -0
- package/dist/chunks/{chunk-BTIPUR5S.js → chunk-SNC7AOT7.js} +78 -12
- package/dist/chunks/{chunk-63H5VXZY.js → chunk-UEUUOAJY.js} +4 -1
- package/dist/chunks/{chunk-GTCPZ22N.js → chunk-VST6HAB6.js} +1 -1
- package/dist/chunks/{chunk-NDEYEYSU.js → chunk-WJII3LZK.js} +4 -3
- package/dist/chunks/chunk-X7PZN73N.js +44 -0
- package/dist/chunks/{chunk-NYLRTAAA.js → chunk-YVN3VDRE.js} +1 -1
- package/dist/chunks/{chunk-WJRZN7BR.js → chunk-YXCHIMLW.js} +843 -3027
- package/dist/chunks/{clear-YBDIPEEH.js → clear-AT7HNUV4.js} +2 -2
- package/dist/chunks/{create-GPDE2YKL.js → create-ET6DT5ZE.js} +22 -18
- package/dist/chunks/{create-VYZRWRGQ.js → create-LM7U3CJS.js} +22 -18
- package/dist/chunks/{create-L6DJN4ME.js → create-TLPM7HJE.js} +3 -3
- package/dist/chunks/{delete-LNOYM5KG.js → delete-5R3WBLVD.js} +5 -5
- package/dist/chunks/{delete-E4TEBRPX.js → delete-GKYA2W5Z.js} +4 -2
- package/dist/chunks/{delete-C4UJ7X5K.js → delete-U4STA2QZ.js} +5 -5
- package/dist/chunks/disable-TNTEIAKO.js +39 -0
- package/dist/chunks/doctor-VXAQYMTR.js +101 -0
- package/dist/chunks/enable-GUQCB4CU.js +31 -0
- package/dist/chunks/{globals-H2WF344Y.js → globals-SNQFCHMP.js} +1 -1
- package/dist/chunks/{init-HU5OMHEH.js → init-PJSCFOC6.js} +14 -8
- package/dist/chunks/{install-FIYRMVLR.js → install-4YP7FALO.js} +18 -16
- package/dist/chunks/{intro-36OLGNYN.js → intro-SA7MWV3Z.js} +50 -8
- package/dist/chunks/{kill-2UG7PHUV.js → kill-TX3PC73P.js} +2 -1
- package/dist/chunks/list-7R6NASFI.js +92 -0
- 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-AIYNOPNZ.js → list-OMMZAQ23.js} +2 -2
- 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/{list-2JYMBMZC.js → list-WKNPZZOV.js} +5 -4
- 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-K5DV5NAK.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-ZB3DIJ4K.js} +84 -26
- package/dist/chunks/resolver-QIYYFIDX.js +34 -0
- package/dist/chunks/run-22B65ZWZ.js +29 -0
- package/dist/chunks/rune-SYK4N642.js +425 -0
- package/dist/chunks/{search-MSSDGJTF.js → search-B7IM7JRJ.js} +2 -2
- package/dist/chunks/shell-explain-QLITLHW7.js +74 -0
- package/dist/chunks/{uninstall-G56DZRFG.js → uninstall-4WR5IHLC.js} +15 -11
- package/dist/chunks/{unset-YASSMSE5.js → unset-P6IUF7SS.js} +2 -2
- package/dist/chunks/{update-KSC6VRMU.js → update-ACLDK6E6.js} +19 -18
- 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-EULYWNXN.js} +2 -2
- package/dist/cli.js +92 -64
- package/package.json +1 -1
- package/dist/chunks/chunk-ASZKAC24.js +0 -103
- package/dist/chunks/chunk-GSA432UC.js +0 -90
- 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/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
|
@@ -0,0 +1,2787 @@
|
|
|
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 = (path4, { windows } = {}) => {
|
|
275
|
+
const segs = path4.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/rune/api/shell-resolve.js
|
|
1774
|
+
init_require_shim();
|
|
1775
|
+
import { existsSync } from "node:fs";
|
|
1776
|
+
import path from "node:path";
|
|
1777
|
+
var ShellResolutionError = class extends Error {
|
|
1778
|
+
constructor(message, { mode, tried }) {
|
|
1779
|
+
super(message);
|
|
1780
|
+
this.name = "ShellResolutionError";
|
|
1781
|
+
this.mode = mode;
|
|
1782
|
+
this.tried = tried;
|
|
1783
|
+
}
|
|
1784
|
+
};
|
|
1785
|
+
function isWslLauncher(candidate, env) {
|
|
1786
|
+
const systemRoot = (env.SystemRoot ?? "C:\\Windows").replace(/\\/g, "/").toLowerCase();
|
|
1787
|
+
const p = String(candidate).replace(/\\/g, "/").toLowerCase();
|
|
1788
|
+
return p.startsWith(`${systemRoot}/system32/`);
|
|
1789
|
+
}
|
|
1790
|
+
function bashCandidates(deps) {
|
|
1791
|
+
const { platform, env, pathDirs } = deps;
|
|
1792
|
+
if (platform !== "win32") {
|
|
1793
|
+
return ["/bin/bash", "/usr/bin/bash", ...pathDirs.map((d) => path.posix.join(d, "bash"))];
|
|
1794
|
+
}
|
|
1795
|
+
const out = [];
|
|
1796
|
+
if (env.ProgramFiles) out.push(path.win32.join(env.ProgramFiles, "Git", "bin", "bash.exe"));
|
|
1797
|
+
if (env["ProgramFiles(x86)"]) out.push(path.win32.join(env["ProgramFiles(x86)"], "Git", "bin", "bash.exe"));
|
|
1798
|
+
if (env.LOCALAPPDATA) out.push(path.win32.join(env.LOCALAPPDATA, "Programs", "Git", "bin", "bash.exe"));
|
|
1799
|
+
for (const dir of pathDirs) {
|
|
1800
|
+
const candidate = path.win32.join(dir, "bash.exe");
|
|
1801
|
+
if (isWslLauncher(candidate, env)) continue;
|
|
1802
|
+
out.push(candidate);
|
|
1803
|
+
}
|
|
1804
|
+
return out;
|
|
1805
|
+
}
|
|
1806
|
+
function findBash(deps) {
|
|
1807
|
+
const { env, exists } = deps;
|
|
1808
|
+
const tried = bashCandidates(deps);
|
|
1809
|
+
for (const candidate of tried) {
|
|
1810
|
+
if (exists(candidate)) return { path: candidate, tried };
|
|
1811
|
+
}
|
|
1812
|
+
const override = env.CRUNES_BASH;
|
|
1813
|
+
if (override && exists(override) && !isWslLauncher(override, env)) {
|
|
1814
|
+
return { path: override, tried: [...tried, override] };
|
|
1815
|
+
}
|
|
1816
|
+
return { path: null, tried: override ? [...tried, override] : tried };
|
|
1817
|
+
}
|
|
1818
|
+
function findSh(deps) {
|
|
1819
|
+
if (deps.platform === "win32") return null;
|
|
1820
|
+
return deps.exists("/bin/sh") ? "/bin/sh" : null;
|
|
1821
|
+
}
|
|
1822
|
+
function findCmd(deps) {
|
|
1823
|
+
if (deps.platform !== "win32") return null;
|
|
1824
|
+
return deps.env.ComSpec ?? "C:\\Windows\\System32\\cmd.exe";
|
|
1825
|
+
}
|
|
1826
|
+
var cached = null;
|
|
1827
|
+
function defaultDeps() {
|
|
1828
|
+
const sep = process.platform === "win32" ? ";" : ":";
|
|
1829
|
+
return {
|
|
1830
|
+
platform: process.platform,
|
|
1831
|
+
env: process.env,
|
|
1832
|
+
exists: (p) => {
|
|
1833
|
+
try {
|
|
1834
|
+
return existsSync(p);
|
|
1835
|
+
} catch {
|
|
1836
|
+
return false;
|
|
1837
|
+
}
|
|
1838
|
+
},
|
|
1839
|
+
pathDirs: (process.env.PATH ?? "").split(sep).filter(Boolean)
|
|
1840
|
+
};
|
|
1841
|
+
}
|
|
1842
|
+
function resolveShell(mode, deps = null) {
|
|
1843
|
+
const d = deps ?? defaultDeps();
|
|
1844
|
+
const useCache = deps === null;
|
|
1845
|
+
if (mode !== void 0 && mode !== "bash" && mode !== "cmd") {
|
|
1846
|
+
throw new ShellResolutionError(`Unknown shell mode: '${mode}'. Expected 'bash', 'cmd', or undefined.`, { mode, tried: [] });
|
|
1847
|
+
}
|
|
1848
|
+
if (useCache && cached && cached[String(mode)]) return cached[String(mode)];
|
|
1849
|
+
let result;
|
|
1850
|
+
if (mode === "bash") {
|
|
1851
|
+
const { path: bash, tried } = findBash(d);
|
|
1852
|
+
if (!bash) {
|
|
1853
|
+
throw new ShellResolutionError(
|
|
1854
|
+
`shell: 'bash' was requested but no bash was found. Tried:
|
|
1855
|
+
${tried.join("\n ")}
|
|
1856
|
+
Set CRUNES_BASH to an absolute bash path if it is installed elsewhere.`,
|
|
1857
|
+
{ mode, tried }
|
|
1858
|
+
);
|
|
1859
|
+
}
|
|
1860
|
+
result = { kind: "bash", path: bash };
|
|
1861
|
+
} else if (mode === "cmd") {
|
|
1862
|
+
const cmd = findCmd(d);
|
|
1863
|
+
if (!cmd) {
|
|
1864
|
+
throw new ShellResolutionError(`shell: 'cmd' is only available on Windows (platform is '${d.platform}').`, { mode, tried: [] });
|
|
1865
|
+
}
|
|
1866
|
+
result = { kind: "cmd", path: cmd };
|
|
1867
|
+
} else {
|
|
1868
|
+
const { path: bash, tried } = findBash(d);
|
|
1869
|
+
if (bash) {
|
|
1870
|
+
result = { kind: "bash", path: bash };
|
|
1871
|
+
} else {
|
|
1872
|
+
const sh = findSh(d);
|
|
1873
|
+
if (sh) {
|
|
1874
|
+
result = { kind: "sh", path: sh };
|
|
1875
|
+
} else {
|
|
1876
|
+
const cmd = findCmd(d);
|
|
1877
|
+
if (!cmd) {
|
|
1878
|
+
throw new ShellResolutionError(
|
|
1879
|
+
`No usable shell found. Tried bash:
|
|
1880
|
+
${tried.join("\n ")}
|
|
1881
|
+
then /bin/sh.`,
|
|
1882
|
+
{ mode, tried: [...tried, "/bin/sh"] }
|
|
1883
|
+
);
|
|
1884
|
+
}
|
|
1885
|
+
result = { kind: "cmd", path: cmd };
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
if (useCache) {
|
|
1890
|
+
cached ??= {};
|
|
1891
|
+
cached[String(mode)] = result;
|
|
1892
|
+
}
|
|
1893
|
+
return result;
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1896
|
+
// src/rune/permissions/shell-scan.js
|
|
1897
|
+
init_require_shim();
|
|
1898
|
+
var ScanRefusal = class extends Error {
|
|
1899
|
+
constructor(construct, offset) {
|
|
1900
|
+
super(`Cannot scan command: ${construct} at offset ${offset} is not supported.`);
|
|
1901
|
+
this.name = "ScanRefusal";
|
|
1902
|
+
this.construct = construct;
|
|
1903
|
+
this.offset = offset;
|
|
1904
|
+
}
|
|
1905
|
+
};
|
|
1906
|
+
var ASSIGNMENT_RE = /^[A-Za-z_][A-Za-z0-9_]*=/;
|
|
1907
|
+
var CONTROL_KEYWORDS = /* @__PURE__ */ new Set([
|
|
1908
|
+
"if",
|
|
1909
|
+
"then",
|
|
1910
|
+
"else",
|
|
1911
|
+
"elif",
|
|
1912
|
+
"fi",
|
|
1913
|
+
"while",
|
|
1914
|
+
"until",
|
|
1915
|
+
"do",
|
|
1916
|
+
"done",
|
|
1917
|
+
"for",
|
|
1918
|
+
"select",
|
|
1919
|
+
"case",
|
|
1920
|
+
"esac",
|
|
1921
|
+
"function"
|
|
1922
|
+
]);
|
|
1923
|
+
var NESTED_INTERPRETERS = /* @__PURE__ */ new Set(["sh", "bash", "zsh", "dash", "ksh"]);
|
|
1924
|
+
var CMD_METACHARACTERS = /[&|<>^%()]/;
|
|
1925
|
+
function guardCmdMode(cmd) {
|
|
1926
|
+
const m = CMD_METACHARACTERS.exec(cmd);
|
|
1927
|
+
if (m) throw new ScanRefusal("cmd metacharacter", m.index);
|
|
1928
|
+
}
|
|
1929
|
+
function matchDelimiter(src, from, open, close) {
|
|
1930
|
+
let depth = 1;
|
|
1931
|
+
let i = from;
|
|
1932
|
+
while (i < src.length) {
|
|
1933
|
+
const ch = src[i];
|
|
1934
|
+
if (ch === "\\") {
|
|
1935
|
+
i += 2;
|
|
1936
|
+
continue;
|
|
1937
|
+
}
|
|
1938
|
+
if (ch === "'") {
|
|
1939
|
+
const e = src.indexOf("'", i + 1);
|
|
1940
|
+
if (e === -1) return -1;
|
|
1941
|
+
i = e + 1;
|
|
1942
|
+
continue;
|
|
1943
|
+
}
|
|
1944
|
+
if (ch === '"') {
|
|
1945
|
+
const e = src.indexOf('"', i + 1);
|
|
1946
|
+
if (e === -1) return -1;
|
|
1947
|
+
i = e + 1;
|
|
1948
|
+
continue;
|
|
1949
|
+
}
|
|
1950
|
+
if (ch === open) depth++;
|
|
1951
|
+
else if (ch === close) {
|
|
1952
|
+
depth--;
|
|
1953
|
+
if (depth === 0) return i;
|
|
1954
|
+
}
|
|
1955
|
+
i++;
|
|
1956
|
+
}
|
|
1957
|
+
return -1;
|
|
1958
|
+
}
|
|
1959
|
+
function isOperatorStart(ch) {
|
|
1960
|
+
return ch === "|" || ch === "&" || ch === ";" || ch === "\n";
|
|
1961
|
+
}
|
|
1962
|
+
function tokenize(src, baseOffset) {
|
|
1963
|
+
const tokens = [];
|
|
1964
|
+
let i = 0;
|
|
1965
|
+
let buf = "";
|
|
1966
|
+
let bufStart = -1;
|
|
1967
|
+
let hadWord = false;
|
|
1968
|
+
const flush = () => {
|
|
1969
|
+
if (!hadWord) return;
|
|
1970
|
+
tokens.push({ type: "word", value: buf, offset: baseOffset + bufStart });
|
|
1971
|
+
buf = "";
|
|
1972
|
+
bufStart = -1;
|
|
1973
|
+
hadWord = false;
|
|
1974
|
+
};
|
|
1975
|
+
const begin = (at) => {
|
|
1976
|
+
if (!hadWord) {
|
|
1977
|
+
hadWord = true;
|
|
1978
|
+
bufStart = at;
|
|
1979
|
+
}
|
|
1980
|
+
};
|
|
1981
|
+
while (i < src.length) {
|
|
1982
|
+
const ch = src[i];
|
|
1983
|
+
if (ch === " " || ch === " ") {
|
|
1984
|
+
flush();
|
|
1985
|
+
i++;
|
|
1986
|
+
continue;
|
|
1987
|
+
}
|
|
1988
|
+
if (ch === "'") {
|
|
1989
|
+
const end = src.indexOf("'", i + 1);
|
|
1990
|
+
if (end === -1) throw new ScanRefusal("unterminated single quote", baseOffset + i);
|
|
1991
|
+
begin(i);
|
|
1992
|
+
buf += src.slice(i + 1, end);
|
|
1993
|
+
i = end + 1;
|
|
1994
|
+
continue;
|
|
1995
|
+
}
|
|
1996
|
+
if (ch === '"') {
|
|
1997
|
+
begin(i);
|
|
1998
|
+
let j = i + 1;
|
|
1999
|
+
let inner = "";
|
|
2000
|
+
let closed = false;
|
|
2001
|
+
while (j < src.length) {
|
|
2002
|
+
if (src[j] === "\\" && j + 1 < src.length) {
|
|
2003
|
+
inner += src[j + 1];
|
|
2004
|
+
j += 2;
|
|
2005
|
+
continue;
|
|
2006
|
+
}
|
|
2007
|
+
if (src[j] === '"') {
|
|
2008
|
+
closed = true;
|
|
2009
|
+
break;
|
|
2010
|
+
}
|
|
2011
|
+
inner += src[j];
|
|
2012
|
+
j++;
|
|
2013
|
+
}
|
|
2014
|
+
if (!closed) throw new ScanRefusal("unterminated double quote", baseOffset + i);
|
|
2015
|
+
if (inner.includes("$(") || inner.includes("`")) {
|
|
2016
|
+
const nested = tokenize(inner, baseOffset + i + 1);
|
|
2017
|
+
for (const t of nested) {
|
|
2018
|
+
if (t.type === "subst") tokens.push({ ...t, inCommandPosition: false });
|
|
2019
|
+
}
|
|
2020
|
+
buf += inner.replace(/\$\([^)]*\)|`[^`]*`/g, "");
|
|
2021
|
+
} else {
|
|
2022
|
+
buf += inner;
|
|
2023
|
+
}
|
|
2024
|
+
i = j + 1;
|
|
2025
|
+
continue;
|
|
2026
|
+
}
|
|
2027
|
+
if (ch === "\\" && i + 1 < src.length) {
|
|
2028
|
+
begin(i);
|
|
2029
|
+
buf += src[i + 1];
|
|
2030
|
+
i += 2;
|
|
2031
|
+
continue;
|
|
2032
|
+
}
|
|
2033
|
+
if (ch === "$" && src[i + 1] === "(" && src[i + 2] === "(") {
|
|
2034
|
+
throw new ScanRefusal("arithmetic expansion", baseOffset + i);
|
|
2035
|
+
}
|
|
2036
|
+
if (ch === "<" && src[i + 1] === "<") {
|
|
2037
|
+
throw new ScanRefusal("heredoc", baseOffset + i);
|
|
2038
|
+
}
|
|
2039
|
+
if ((ch === "<" || ch === ">") && src[i + 1] === "(") {
|
|
2040
|
+
throw new ScanRefusal("process substitution", baseOffset + i);
|
|
2041
|
+
}
|
|
2042
|
+
if (ch === "$" && src[i + 1] === "(") {
|
|
2043
|
+
const end = matchDelimiter(src, i + 2, "(", ")");
|
|
2044
|
+
if (end === -1) throw new ScanRefusal("unterminated command substitution", baseOffset + i);
|
|
2045
|
+
const wasInCommandPosition = !hadWord;
|
|
2046
|
+
flush();
|
|
2047
|
+
tokens.push({ type: "subst", src: src.slice(i + 2, end), offset: baseOffset + i + 2, inCommandPosition: wasInCommandPosition });
|
|
2048
|
+
i = end + 1;
|
|
2049
|
+
continue;
|
|
2050
|
+
}
|
|
2051
|
+
if (ch === "`") {
|
|
2052
|
+
const end = src.indexOf("`", i + 1);
|
|
2053
|
+
if (end === -1) throw new ScanRefusal("unterminated command substitution", baseOffset + i);
|
|
2054
|
+
const wasInCommandPosition = !hadWord;
|
|
2055
|
+
flush();
|
|
2056
|
+
tokens.push({ type: "subst", src: src.slice(i + 1, end), offset: baseOffset + i + 1, inCommandPosition: wasInCommandPosition });
|
|
2057
|
+
i = end + 1;
|
|
2058
|
+
continue;
|
|
2059
|
+
}
|
|
2060
|
+
if (ch === "(" && !hadWord) {
|
|
2061
|
+
const end = matchDelimiter(src, i + 1, "(", ")");
|
|
2062
|
+
if (end === -1) throw new ScanRefusal("unterminated subshell", baseOffset + i);
|
|
2063
|
+
flush();
|
|
2064
|
+
tokens.push({ type: "group", src: src.slice(i + 1, end), offset: baseOffset + i + 1 });
|
|
2065
|
+
i = end + 1;
|
|
2066
|
+
continue;
|
|
2067
|
+
}
|
|
2068
|
+
if (ch === ">" || ch === "<" || ch === "&" && src[i + 1] === ">") {
|
|
2069
|
+
let opLen = 1;
|
|
2070
|
+
let mode = ch === "<" ? "read" : "write";
|
|
2071
|
+
if (ch === "&") {
|
|
2072
|
+
opLen = 2;
|
|
2073
|
+
mode = "write";
|
|
2074
|
+
} else if (src[i + 1] === ">" || src[i + 1] === "|") opLen = 2;
|
|
2075
|
+
if (hadWord && /^\d+$/.test(buf) && (ch === ">" || ch === "<")) {
|
|
2076
|
+
buf = "";
|
|
2077
|
+
hadWord = false;
|
|
2078
|
+
bufStart = -1;
|
|
2079
|
+
} else {
|
|
2080
|
+
flush();
|
|
2081
|
+
}
|
|
2082
|
+
tokens.push({ type: "redirect", mode, offset: baseOffset + i });
|
|
2083
|
+
i += opLen;
|
|
2084
|
+
continue;
|
|
2085
|
+
}
|
|
2086
|
+
if (isOperatorStart(ch)) {
|
|
2087
|
+
flush();
|
|
2088
|
+
let op = ch;
|
|
2089
|
+
if (ch === "|" && src[i + 1] === "|" || ch === "&" && src[i + 1] === "&") op = ch + ch;
|
|
2090
|
+
tokens.push({ type: "op", value: op, offset: baseOffset + i });
|
|
2091
|
+
i += op.length;
|
|
2092
|
+
continue;
|
|
2093
|
+
}
|
|
2094
|
+
begin(i);
|
|
2095
|
+
buf += ch;
|
|
2096
|
+
i++;
|
|
2097
|
+
}
|
|
2098
|
+
flush();
|
|
2099
|
+
return tokens;
|
|
2100
|
+
}
|
|
2101
|
+
function splitSegments(tokens) {
|
|
2102
|
+
const segments = [];
|
|
2103
|
+
let current = [];
|
|
2104
|
+
for (const t of tokens) {
|
|
2105
|
+
if (t.type === "op") {
|
|
2106
|
+
segments.push(current);
|
|
2107
|
+
current = [];
|
|
2108
|
+
continue;
|
|
2109
|
+
}
|
|
2110
|
+
current.push(t);
|
|
2111
|
+
}
|
|
2112
|
+
segments.push(current);
|
|
2113
|
+
return segments.filter((s) => s.length > 0);
|
|
2114
|
+
}
|
|
2115
|
+
function stripAssignments(words) {
|
|
2116
|
+
let k = 0;
|
|
2117
|
+
while (k < words.length && ASSIGNMENT_RE.test(words[k].value)) k++;
|
|
2118
|
+
return words.slice(k);
|
|
2119
|
+
}
|
|
2120
|
+
function scanCommand(cmd, shellKind = "bash") {
|
|
2121
|
+
if (shellKind === "cmd") guardCmdMode(cmd);
|
|
2122
|
+
const commands = [];
|
|
2123
|
+
const redirects = [];
|
|
2124
|
+
collect(tokenize(cmd, 0), commands, redirects);
|
|
2125
|
+
return { commands, redirects };
|
|
2126
|
+
}
|
|
2127
|
+
function collect(tokens, commands, redirects) {
|
|
2128
|
+
for (const segment of splitSegments(tokens)) {
|
|
2129
|
+
const words = [];
|
|
2130
|
+
for (let k = 0; k < segment.length; k++) {
|
|
2131
|
+
const t = segment[k];
|
|
2132
|
+
if (t.type === "subst" || t.type === "group") {
|
|
2133
|
+
if (t.type === "subst" && t.inCommandPosition && words.length === 0) {
|
|
2134
|
+
throw new ScanRefusal("substitution in command position", t.offset);
|
|
2135
|
+
}
|
|
2136
|
+
collect(tokenize(t.src, t.offset), commands, redirects);
|
|
2137
|
+
continue;
|
|
2138
|
+
}
|
|
2139
|
+
if (t.type === "redirect") {
|
|
2140
|
+
const target = segment[k + 1];
|
|
2141
|
+
if (!target || target.type !== "word") throw new ScanRefusal("redirect without target", t.offset);
|
|
2142
|
+
if (target.value.startsWith("$")) throw new ScanRefusal("variable redirect target", target.offset);
|
|
2143
|
+
redirects.push({ mode: t.mode, target: target.value, offset: target.offset });
|
|
2144
|
+
k++;
|
|
2145
|
+
continue;
|
|
2146
|
+
}
|
|
2147
|
+
words.push(t);
|
|
2148
|
+
}
|
|
2149
|
+
const real = stripAssignments(words);
|
|
2150
|
+
if (real.length === 0) continue;
|
|
2151
|
+
const program = real[0].value;
|
|
2152
|
+
const args = real.slice(1).map((w) => w.value);
|
|
2153
|
+
if (program.startsWith("$")) throw new ScanRefusal("variable in command position", real[0].offset);
|
|
2154
|
+
if (CONTROL_KEYWORDS.has(program)) throw new ScanRefusal("control structure", real[0].offset);
|
|
2155
|
+
if (program === "eval") throw new ScanRefusal("eval", real[0].offset);
|
|
2156
|
+
if (program === "xargs") throw new ScanRefusal("xargs", real[0].offset);
|
|
2157
|
+
if (NESTED_INTERPRETERS.has(program) && args.includes("-c")) {
|
|
2158
|
+
throw new ScanRefusal("nested interpreter", real[0].offset);
|
|
2159
|
+
}
|
|
2160
|
+
if (program === "find" && args.some((a) => a === "-exec" || a === "-execdir" || a === "-ok")) {
|
|
2161
|
+
throw new ScanRefusal("find -exec", real[0].offset);
|
|
2162
|
+
}
|
|
2163
|
+
commands.push({ program, args, segment: [program, ...args].join(" "), offset: real[0].offset });
|
|
2164
|
+
}
|
|
2165
|
+
}
|
|
2166
|
+
|
|
2167
|
+
// src/shared/match.js
|
|
2168
|
+
init_require_shim();
|
|
2169
|
+
var import_picomatch = __toESM(require_picomatch2(), 1);
|
|
2170
|
+
var isGlobMatch = (value, pattern) => import_picomatch.default.isMatch(value, pattern, { dot: true });
|
|
2171
|
+
function wildcardToRegex(pattern) {
|
|
2172
|
+
const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
2173
|
+
return new RegExp("^" + escaped.replace(/\*+/g, "[\\s\\S]*") + "$");
|
|
2174
|
+
}
|
|
2175
|
+
var isWildcardMatch = (value, patterns) => {
|
|
2176
|
+
const list = Array.isArray(patterns) ? patterns : [patterns];
|
|
2177
|
+
return list.some((p) => wildcardToRegex(p).test(value));
|
|
2178
|
+
};
|
|
2179
|
+
|
|
2180
|
+
// src/rune/permissions/permissions.js
|
|
2181
|
+
init_require_shim();
|
|
2182
|
+
import os2 from "node:os";
|
|
2183
|
+
|
|
2184
|
+
// src/rune/api/utils.js
|
|
2185
|
+
init_require_shim();
|
|
2186
|
+
import os from "node:os";
|
|
2187
|
+
import path3 from "node:path";
|
|
2188
|
+
|
|
2189
|
+
// src/project/index.js
|
|
2190
|
+
init_require_shim();
|
|
2191
|
+
import { readFile, writeFile, mkdir } from "node:fs/promises";
|
|
2192
|
+
import { dirname } from "node:path";
|
|
2193
|
+
import { createHash } from "node:crypto";
|
|
2194
|
+
import path2 from "node:path";
|
|
2195
|
+
function shortHash(str) {
|
|
2196
|
+
return createHash("sha1").update(str).digest("hex").slice(0, 8);
|
|
2197
|
+
}
|
|
2198
|
+
async function ensureProjectIdentity(dir) {
|
|
2199
|
+
const localJsonPath = path2.join(dir, ".crunes", "project.local.json");
|
|
2200
|
+
try {
|
|
2201
|
+
const raw = await readFile(localJsonPath, "utf8");
|
|
2202
|
+
return JSON.parse(raw);
|
|
2203
|
+
} catch {
|
|
2204
|
+
}
|
|
2205
|
+
let alias = path2.basename(dir);
|
|
2206
|
+
try {
|
|
2207
|
+
const config = JSON.parse(await readFile(path2.join(dir, ".crunes", "config.json"), "utf8"));
|
|
2208
|
+
if (typeof config.name === "string" && config.name.length > 0) alias = config.name;
|
|
2209
|
+
} catch {
|
|
2210
|
+
}
|
|
2211
|
+
const id = `${path2.basename(dir).slice(0, 15)}-${shortHash(dir + "-" + Math.random())}`;
|
|
2212
|
+
const identity = { id, alias };
|
|
2213
|
+
await mkdir(path2.join(dir, ".crunes"), { recursive: true });
|
|
2214
|
+
await writeFile(localJsonPath, JSON.stringify(identity, null, 2), "utf8");
|
|
2215
|
+
return identity;
|
|
2216
|
+
}
|
|
2217
|
+
async function loadProjects() {
|
|
2218
|
+
try {
|
|
2219
|
+
const raw = await readFile(getProjectsJsonPath(), "utf8");
|
|
2220
|
+
return JSON.parse(raw);
|
|
2221
|
+
} catch {
|
|
2222
|
+
return { format: "1", projects: {} };
|
|
2223
|
+
}
|
|
2224
|
+
}
|
|
2225
|
+
async function upsertProject(id, projectDir) {
|
|
2226
|
+
const data = await loadProjects();
|
|
2227
|
+
let alias = path2.basename(projectDir);
|
|
2228
|
+
try {
|
|
2229
|
+
const raw = await readFile(path2.join(projectDir, ".crunes", "project.local.json"), "utf8");
|
|
2230
|
+
const parsed = JSON.parse(raw);
|
|
2231
|
+
if (typeof parsed.alias === "string" && parsed.alias.length > 0) alias = parsed.alias;
|
|
2232
|
+
} catch {
|
|
2233
|
+
}
|
|
2234
|
+
const existing = data.projects[id];
|
|
2235
|
+
data.projects[id] = {
|
|
2236
|
+
path: projectDir,
|
|
2237
|
+
alias,
|
|
2238
|
+
lastActiveAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2239
|
+
firstSeenAt: existing?.firstSeenAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
2240
|
+
};
|
|
2241
|
+
const p = getProjectsJsonPath();
|
|
2242
|
+
await mkdir(dirname(p), { recursive: true });
|
|
2243
|
+
await writeFile(p, JSON.stringify(data, null, 2), "utf8");
|
|
2244
|
+
}
|
|
2245
|
+
|
|
2246
|
+
// src/rune/api/utils.js
|
|
2247
|
+
var VIRTUAL_STORE_PREFIXES = [
|
|
2248
|
+
"@global-plugin-cache",
|
|
2249
|
+
"@global-plugin-sqlite",
|
|
2250
|
+
"@local-cache",
|
|
2251
|
+
"@local-plugin-cache",
|
|
2252
|
+
"@local-sqlite",
|
|
2253
|
+
"@local-plugin-sqlite"
|
|
2254
|
+
];
|
|
2255
|
+
function parseVirtualStore(location) {
|
|
2256
|
+
for (const prefix of VIRTUAL_STORE_PREFIXES) {
|
|
2257
|
+
if (location === prefix) return { prefix, subpath: "" };
|
|
2258
|
+
if (location.startsWith(prefix + "/")) {
|
|
2259
|
+
const raw = location.slice(prefix.length + 1);
|
|
2260
|
+
const normalized = path3.normalize(raw).replace(/\\/g, "/");
|
|
2261
|
+
if (normalized.startsWith("..")) throw new RangeError(`subpath escapes virtual root: ${location}`);
|
|
2262
|
+
return { prefix, subpath: normalized };
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
return null;
|
|
2266
|
+
}
|
|
2267
|
+
function virtualStoreBase(prefix, { dir, pluginId }) {
|
|
2268
|
+
switch (prefix) {
|
|
2269
|
+
case "@global-plugin-cache":
|
|
2270
|
+
if (!pluginId) throw new Error("@global-plugin-cache requires a plugin context");
|
|
2271
|
+
return getCachePluginDir(pluginId);
|
|
2272
|
+
case "@global-plugin-sqlite":
|
|
2273
|
+
if (!pluginId) throw new Error("@global-plugin-sqlite requires a plugin context");
|
|
2274
|
+
return getSqlitePluginDir(pluginId);
|
|
2275
|
+
case "@local-cache":
|
|
2276
|
+
return path3.join(getLocalBase(dir), "caches", "project");
|
|
2277
|
+
case "@local-plugin-cache":
|
|
2278
|
+
if (!pluginId) throw new Error("@local-plugin-cache requires a plugin context");
|
|
2279
|
+
return path3.join(getLocalBase(dir), "caches", "plugins", pluginId);
|
|
2280
|
+
case "@local-sqlite":
|
|
2281
|
+
return path3.join(getLocalBase(dir), "sqlite", "project");
|
|
2282
|
+
case "@local-plugin-sqlite":
|
|
2283
|
+
if (!pluginId) throw new Error("@local-plugin-sqlite requires a plugin context");
|
|
2284
|
+
return path3.join(getLocalBase(dir), "sqlite", "plugins", pluginId);
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2287
|
+
function resolvePath(location, { dir, pluginDir = null, pluginId = null, storeDir = null } = {}) {
|
|
2288
|
+
if (location.startsWith("@plugin/")) {
|
|
2289
|
+
if (!pluginDir) throw new Error("@plugin/ paths are only available in plugin runes");
|
|
2290
|
+
return path3.join(pluginDir, location.slice("@plugin/".length));
|
|
2291
|
+
}
|
|
2292
|
+
if (location.startsWith("@project/")) {
|
|
2293
|
+
return path3.join(dir, location.slice("@project/".length));
|
|
2294
|
+
}
|
|
2295
|
+
const virtual = parseVirtualStore(location);
|
|
2296
|
+
if (virtual) {
|
|
2297
|
+
const base = virtualStoreBase(virtual.prefix, { dir, pluginId });
|
|
2298
|
+
return virtual.subpath ? path3.join(base, virtual.subpath) : base;
|
|
2299
|
+
}
|
|
2300
|
+
if (location === "~" || location.startsWith("~/") || location.startsWith("~\\")) {
|
|
2301
|
+
return path3.join(os.homedir(), location.slice(1));
|
|
2302
|
+
}
|
|
2303
|
+
if (path3.isAbsolute(location)) return location;
|
|
2304
|
+
return path3.resolve(dir, location);
|
|
2305
|
+
}
|
|
2306
|
+
function getAutoPermits({ pluginId = null, pluginDir = null } = {}) {
|
|
2307
|
+
const permits = [];
|
|
2308
|
+
if (!pluginDir) {
|
|
2309
|
+
permits.push(
|
|
2310
|
+
"fs.read:./.crunes/**",
|
|
2311
|
+
"cache.read:@local-cache/**",
|
|
2312
|
+
"cache.write:@local-cache/**",
|
|
2313
|
+
"sqlite.read:@local-sqlite/**",
|
|
2314
|
+
"sqlite.write:@local-sqlite/**",
|
|
2315
|
+
"fs.read:@local-sqlite/**",
|
|
2316
|
+
"fs.write:@local-sqlite/**"
|
|
2317
|
+
);
|
|
2318
|
+
}
|
|
2319
|
+
if (pluginDir) {
|
|
2320
|
+
permits.push("fs.read:@plugin/**", "fs.write:@plugin/**");
|
|
2321
|
+
}
|
|
2322
|
+
if (pluginId) {
|
|
2323
|
+
permits.push(
|
|
2324
|
+
"cache.read:@global-plugin-cache/**",
|
|
2325
|
+
"cache.write:@global-plugin-cache/**",
|
|
2326
|
+
"sqlite.read:@global-plugin-sqlite/**",
|
|
2327
|
+
"sqlite.write:@global-plugin-sqlite/**",
|
|
2328
|
+
"fs.read:@global-plugin-sqlite/**",
|
|
2329
|
+
"fs.write:@global-plugin-sqlite/**"
|
|
2330
|
+
);
|
|
2331
|
+
}
|
|
2332
|
+
return permits;
|
|
2333
|
+
}
|
|
2334
|
+
|
|
2335
|
+
// src/rune/permissions/permissions-http.js
|
|
2336
|
+
init_require_shim();
|
|
2337
|
+
function matchFetchPermission(value, patterns) {
|
|
2338
|
+
const vDoubleColon = value.indexOf("::");
|
|
2339
|
+
if (vDoubleColon === -1) return false;
|
|
2340
|
+
const valueMethod = value.slice(0, vDoubleColon).toUpperCase();
|
|
2341
|
+
const valueUrl = value.slice(vDoubleColon + 2);
|
|
2342
|
+
return patterns.some((pattern) => {
|
|
2343
|
+
const doubleColonIndex = pattern.indexOf("::");
|
|
2344
|
+
const left = doubleColonIndex === -1 ? "" : pattern.slice(0, doubleColonIndex);
|
|
2345
|
+
const right = doubleColonIndex === -1 ? pattern : pattern.slice(doubleColonIndex + 2);
|
|
2346
|
+
const patternMethods = left ? left.split(",").map((m) => m.trim().toUpperCase()) : ["GET"];
|
|
2347
|
+
const methodOk = patternMethods.includes("*") || patternMethods.includes(valueMethod);
|
|
2348
|
+
return methodOk && isGlobMatch(valueUrl, right);
|
|
2349
|
+
});
|
|
2350
|
+
}
|
|
2351
|
+
|
|
2352
|
+
// src/rune/permissions/permissions-env.js
|
|
2353
|
+
init_require_shim();
|
|
2354
|
+
function parseEnvPattern(pattern) {
|
|
2355
|
+
const body = pattern.startsWith("env.read:") ? pattern.slice(9) : pattern;
|
|
2356
|
+
const dColonIdx = body.indexOf("::");
|
|
2357
|
+
if (dColonIdx === -1) {
|
|
2358
|
+
return { sources: ["*"], keyPatterns: [body] };
|
|
2359
|
+
}
|
|
2360
|
+
const left = body.slice(0, dColonIdx);
|
|
2361
|
+
const right = body.slice(dColonIdx + 2);
|
|
2362
|
+
return {
|
|
2363
|
+
sources: left ? left.split(",").map((s) => s.trim()) : ["process"],
|
|
2364
|
+
keyPatterns: right.split(",").map((k) => k.trim())
|
|
2365
|
+
};
|
|
2366
|
+
}
|
|
2367
|
+
function matchEnvPermission(value, patterns) {
|
|
2368
|
+
const dColonIdx = value.indexOf("::");
|
|
2369
|
+
if (dColonIdx === -1) return false;
|
|
2370
|
+
const valueSource = value.slice(0, dColonIdx);
|
|
2371
|
+
const valueKey = value.slice(dColonIdx + 2);
|
|
2372
|
+
return patterns.some((pattern) => {
|
|
2373
|
+
const { sources, keyPatterns } = parseEnvPattern(pattern);
|
|
2374
|
+
const sourceOk = sources.includes("*") || sources.includes(valueSource);
|
|
2375
|
+
const keyOk = keyPatterns.some((pat) => isWildcardMatch(valueKey, pat));
|
|
2376
|
+
return sourceOk && keyOk;
|
|
2377
|
+
});
|
|
2378
|
+
}
|
|
2379
|
+
|
|
2380
|
+
// src/rune/permissions/permissions-store.js
|
|
2381
|
+
init_require_shim();
|
|
2382
|
+
function matchStorePermission(value, patterns) {
|
|
2383
|
+
const vDColon = value.indexOf("::");
|
|
2384
|
+
const valueLoc = vDColon >= 0 ? value.slice(0, vDColon) : value;
|
|
2385
|
+
const valueName = vDColon >= 0 ? value.slice(vDColon + 2) : null;
|
|
2386
|
+
const sub = (s) => s.startsWith("./") ? "__DOT__/" + s.slice(2) : s;
|
|
2387
|
+
return patterns.some((pattern) => {
|
|
2388
|
+
const dColonIdx = pattern.indexOf("::");
|
|
2389
|
+
const patLoc = dColonIdx !== -1 ? pattern.slice(0, dColonIdx) : pattern;
|
|
2390
|
+
const patName = dColonIdx !== -1 ? pattern.slice(dColonIdx + 2) : null;
|
|
2391
|
+
const nameOk = patName === "*" || patName == null || valueName != null && isWildcardMatch(valueName, patName);
|
|
2392
|
+
if (patLoc.startsWith("@") && patLoc.endsWith("/**")) {
|
|
2393
|
+
const bare = patLoc.slice(0, -3);
|
|
2394
|
+
return isGlobMatch(valueLoc, [patLoc, bare]) && nameOk;
|
|
2395
|
+
}
|
|
2396
|
+
return isGlobMatch(sub(valueLoc), sub(patLoc)) && nameOk;
|
|
2397
|
+
});
|
|
2398
|
+
}
|
|
2399
|
+
|
|
2400
|
+
// src/rune/permissions/permissions-ws.js
|
|
2401
|
+
init_require_shim();
|
|
2402
|
+
function matchWsPermission(url, patterns) {
|
|
2403
|
+
return isGlobMatch(url, patterns);
|
|
2404
|
+
}
|
|
2405
|
+
function matchWsServerPermission(value, patterns) {
|
|
2406
|
+
const colonIdx = value.indexOf(":");
|
|
2407
|
+
if (colonIdx === -1) return false;
|
|
2408
|
+
const valueHost = value.slice(0, colonIdx);
|
|
2409
|
+
const rest = value.slice(colonIdx + 1);
|
|
2410
|
+
const secondColon = rest.indexOf(":");
|
|
2411
|
+
const valuePort = secondColon === -1 ? rest : rest.slice(0, secondColon);
|
|
2412
|
+
const valuePath = secondColon !== -1 ? rest.slice(secondColon + 1) : null;
|
|
2413
|
+
return patterns.some((pattern) => {
|
|
2414
|
+
const patColonIdx = pattern.indexOf(":");
|
|
2415
|
+
if (patColonIdx === -1) return false;
|
|
2416
|
+
const patHost = pattern.slice(0, patColonIdx);
|
|
2417
|
+
const patRest = pattern.slice(patColonIdx + 1);
|
|
2418
|
+
const patSecondColon = patRest.indexOf(":");
|
|
2419
|
+
const patPort = patSecondColon === -1 ? patRest : patRest.slice(0, patSecondColon);
|
|
2420
|
+
const patPath = patSecondColon !== -1 ? patRest.slice(patSecondColon + 1) : null;
|
|
2421
|
+
const hostOk = patHost === "*" || patHost === valueHost;
|
|
2422
|
+
const portOk = patPort === "*" || patPort === valuePort;
|
|
2423
|
+
const pathOk = patPath === null ? valuePath === null : patPath === "*" ? valuePath !== null : patPath === valuePath;
|
|
2424
|
+
return hostOk && portOk && pathOk;
|
|
2425
|
+
});
|
|
2426
|
+
}
|
|
2427
|
+
|
|
2428
|
+
// src/rune/permissions/permissions-http-server.js
|
|
2429
|
+
init_require_shim();
|
|
2430
|
+
var LOOPBACK = /* @__PURE__ */ new Set(["127.0.0.1", "localhost", "::1"]);
|
|
2431
|
+
function isLoopbackHost(host) {
|
|
2432
|
+
return LOOPBACK.has(host);
|
|
2433
|
+
}
|
|
2434
|
+
function matchHttpServerPermission(value, patterns) {
|
|
2435
|
+
const lastColon = value.lastIndexOf(":");
|
|
2436
|
+
if (lastColon === -1) return false;
|
|
2437
|
+
const valueHost = value.slice(0, lastColon);
|
|
2438
|
+
const valuePort = value.slice(lastColon + 1);
|
|
2439
|
+
return patterns.some((pattern) => {
|
|
2440
|
+
const lastPatColon = pattern.lastIndexOf(":");
|
|
2441
|
+
if (lastPatColon === -1) return false;
|
|
2442
|
+
const patHost = pattern.slice(0, lastPatColon);
|
|
2443
|
+
const patPort = pattern.slice(lastPatColon + 1);
|
|
2444
|
+
return (patHost === "*" || patHost === valueHost) && (patPort === "*" || patPort === valuePort);
|
|
2445
|
+
});
|
|
2446
|
+
}
|
|
2447
|
+
|
|
2448
|
+
// src/rune/permissions/permissions.js
|
|
2449
|
+
var PermissionError = class extends Error {
|
|
2450
|
+
/**
|
|
2451
|
+
* reason:
|
|
2452
|
+
* 'ungranted' — the value was checked and no grant matched
|
|
2453
|
+
* 'unscannable' — the command could not be classified, so it was denied
|
|
2454
|
+
* without ever being matched against grants
|
|
2455
|
+
*/
|
|
2456
|
+
constructor(capability, value, reason = "ungranted", details = {}) {
|
|
2457
|
+
const message = reason === "unscannable" ? `Cannot scan command: '${details.construct}' at offset ${details.offset} is not supported.` : `'${capability}:${value}' is not permitted.`;
|
|
2458
|
+
super(message);
|
|
2459
|
+
this.name = "PermissionError";
|
|
2460
|
+
this.capability = capability;
|
|
2461
|
+
this.value = value;
|
|
2462
|
+
this.reason = reason;
|
|
2463
|
+
if (reason === "unscannable") {
|
|
2464
|
+
this.construct = details.construct;
|
|
2465
|
+
this.offset = details.offset;
|
|
2466
|
+
}
|
|
2467
|
+
}
|
|
2468
|
+
};
|
|
2469
|
+
var HOME = os2.homedir().replace(/\\/g, "/");
|
|
2470
|
+
var LOCAL_VIRTUAL_PREFIXES = /* @__PURE__ */ new Set([
|
|
2471
|
+
"@local-cache",
|
|
2472
|
+
"@local-plugin-cache",
|
|
2473
|
+
"@local-sqlite",
|
|
2474
|
+
"@local-plugin-sqlite"
|
|
2475
|
+
]);
|
|
2476
|
+
var ALL_VIRTUAL_PREFIXES = [
|
|
2477
|
+
"@global-plugin-cache",
|
|
2478
|
+
"@global-plugin-sqlite",
|
|
2479
|
+
"@local-cache",
|
|
2480
|
+
"@local-plugin-cache",
|
|
2481
|
+
"@local-sqlite",
|
|
2482
|
+
"@local-plugin-sqlite",
|
|
2483
|
+
"@plugin"
|
|
2484
|
+
];
|
|
2485
|
+
function expandPattern(perm, ctx) {
|
|
2486
|
+
const colonIdx = perm.indexOf(":");
|
|
2487
|
+
if (colonIdx === -1) return [perm];
|
|
2488
|
+
const cap = perm.slice(0, colonIdx);
|
|
2489
|
+
const isFs = cap === "fs.read" || cap === "fs.write" || cap === "fs.exists";
|
|
2490
|
+
const isStore = cap === "cache.read" || cap === "cache.write" || cap === "sqlite.read" || cap === "sqlite.write";
|
|
2491
|
+
if (!isFs && !isStore) return [perm];
|
|
2492
|
+
if (!ctx?.dir) return [perm];
|
|
2493
|
+
const { dir, pluginId = null, pluginDir = null } = ctx;
|
|
2494
|
+
const absDir = dir.replace(/\\/g, "/");
|
|
2495
|
+
if (isStore) {
|
|
2496
|
+
const rest = perm.slice(colonIdx + 1);
|
|
2497
|
+
const dColonIdx = rest.indexOf("::");
|
|
2498
|
+
const loc = dColonIdx === -1 ? rest : rest.slice(0, dColonIdx);
|
|
2499
|
+
const name = dColonIdx === -1 ? "" : "::" + rest.slice(dColonIdx + 2);
|
|
2500
|
+
return expandLocValue(loc, absDir, { pluginId, pluginDir }, dir).map((expandedLoc) => `${cap}:${expandedLoc}${name}`);
|
|
2501
|
+
}
|
|
2502
|
+
const value = perm.slice(colonIdx + 1);
|
|
2503
|
+
return expandLocValue(value, absDir, { pluginId, pluginDir }, dir).map((v) => `${cap}:${v}`);
|
|
2504
|
+
}
|
|
2505
|
+
function normalizeGitBashPath(p) {
|
|
2506
|
+
if (process.platform === "win32") {
|
|
2507
|
+
const m = p.match(/^\/([a-zA-Z])(\/|$)/);
|
|
2508
|
+
if (m) return `${m[1].toUpperCase()}:/${p.slice(3)}`;
|
|
2509
|
+
}
|
|
2510
|
+
return p;
|
|
2511
|
+
}
|
|
2512
|
+
function expandLocValue(value, absDir, { pluginId, pluginDir }, dir) {
|
|
2513
|
+
const v = value.replace(/\\/g, "/");
|
|
2514
|
+
if (v === "**" || v.startsWith("**/")) return [v];
|
|
2515
|
+
if (v.startsWith("~/")) return [v, HOME + v.slice(1)];
|
|
2516
|
+
if (v.startsWith("../")) return [v];
|
|
2517
|
+
const isAbsolute = v.startsWith("/") || /^[a-zA-Z]:/.test(v);
|
|
2518
|
+
if (isAbsolute) {
|
|
2519
|
+
if (v.startsWith(absDir + "/")) {
|
|
2520
|
+
const rel2 = v.slice(absDir.length + 1);
|
|
2521
|
+
return [v, `./${rel2}`, rel2, `@project/${rel2}`];
|
|
2522
|
+
}
|
|
2523
|
+
return [v];
|
|
2524
|
+
}
|
|
2525
|
+
if (v.startsWith("@project/")) {
|
|
2526
|
+
const rel2 = v.slice("@project/".length);
|
|
2527
|
+
return [v, `./${rel2}`, rel2, absDir + "/" + rel2];
|
|
2528
|
+
}
|
|
2529
|
+
const matchedPrefix = ALL_VIRTUAL_PREFIXES.find((p) => v === p || v.startsWith(p + "/"));
|
|
2530
|
+
if (matchedPrefix) {
|
|
2531
|
+
const suffix = v.slice(matchedPrefix.length);
|
|
2532
|
+
try {
|
|
2533
|
+
const base = resolvePath(matchedPrefix, { dir, pluginId, pluginDir }).replace(/\\/g, "/");
|
|
2534
|
+
const absResolved = base + suffix;
|
|
2535
|
+
if (LOCAL_VIRTUAL_PREFIXES.has(matchedPrefix)) {
|
|
2536
|
+
const rel2 = absResolved.slice(absDir.length + 1);
|
|
2537
|
+
return [v, absResolved, `./${rel2}`, rel2, `@project/${rel2}`];
|
|
2538
|
+
}
|
|
2539
|
+
return [v, absResolved];
|
|
2540
|
+
} catch {
|
|
2541
|
+
return [v];
|
|
2542
|
+
}
|
|
2543
|
+
}
|
|
2544
|
+
const hasDot = v.startsWith("./");
|
|
2545
|
+
const rel = hasDot ? v.slice(2) : v;
|
|
2546
|
+
const relIsGlob = rel === "**" || rel.startsWith("**/");
|
|
2547
|
+
return hasDot ? relIsGlob ? [`./${rel}`, absDir + "/" + rel, `@project/${rel}`] : [`./${rel}`, rel, absDir + "/" + rel, `@project/${rel}`] : [`./${rel}`, rel, absDir + "/" + rel, `@project/${rel}`];
|
|
2548
|
+
}
|
|
2549
|
+
function parseGlobPerm(value) {
|
|
2550
|
+
const dColonIdx = value.indexOf("::");
|
|
2551
|
+
return { cwd: value.slice(0, dColonIdx), pattern: value.slice(dColonIdx + 2) };
|
|
2552
|
+
}
|
|
2553
|
+
function matchGlobPermission(runtimePattern, runtimeAbsCwd, declaredValues, ctx) {
|
|
2554
|
+
const normCwd = runtimeAbsCwd.replace(/\\/g, "/");
|
|
2555
|
+
return declaredValues.some((val) => {
|
|
2556
|
+
const { cwd: declCwd, pattern: declPattern } = parseGlobPerm(val);
|
|
2557
|
+
if (declPattern !== "*" && declPattern !== runtimePattern) return false;
|
|
2558
|
+
try {
|
|
2559
|
+
const resolvedDeclCwd = resolvePath(declCwd, { dir: ctx.dir, pluginId: ctx.pluginId, pluginDir: ctx.pluginDir }).replace(/\\/g, "/");
|
|
2560
|
+
const sub = (s) => s.startsWith("./") ? "__DOT__/" + s.slice(2) : s;
|
|
2561
|
+
return isGlobMatch(sub(normCwd), [sub(resolvedDeclCwd)]);
|
|
2562
|
+
} catch {
|
|
2563
|
+
return false;
|
|
2564
|
+
}
|
|
2565
|
+
});
|
|
2566
|
+
}
|
|
2567
|
+
function normalizeFsPath(raw) {
|
|
2568
|
+
const val = normalizeGitBashPath(raw.replace(/\\/g, "/"));
|
|
2569
|
+
const v = val.startsWith("@project/") ? "./" + val.slice("@project/".length) : val;
|
|
2570
|
+
const isAbsolute = v.startsWith("/") || /^[a-zA-Z]:/.test(v);
|
|
2571
|
+
return !v.startsWith("./") && !v.startsWith("../") && !v.startsWith("@") && !v.startsWith("~/") && !isAbsolute ? `./${v}` : v;
|
|
2572
|
+
}
|
|
2573
|
+
function normalizePattern(perm) {
|
|
2574
|
+
if (perm.startsWith("fs.glob:")) {
|
|
2575
|
+
const rest = perm.slice("fs.glob:".length);
|
|
2576
|
+
const dColonIdx = rest.indexOf("::");
|
|
2577
|
+
if (dColonIdx === -1) {
|
|
2578
|
+
return `fs.glob:.::${rest}`;
|
|
2579
|
+
}
|
|
2580
|
+
const rawCwd = rest.slice(0, dColonIdx);
|
|
2581
|
+
const pattern = rest.slice(dColonIdx + 2);
|
|
2582
|
+
return `fs.glob:${normalizeFsPath(rawCwd)}::${pattern}`;
|
|
2583
|
+
}
|
|
2584
|
+
if (perm.startsWith("fs.read:") || perm.startsWith("fs.write:") || perm.startsWith("fs.exists:")) {
|
|
2585
|
+
const [cap, ...rest] = perm.split(":");
|
|
2586
|
+
return `${cap}:${normalizeFsPath(rest.join(":"))}`;
|
|
2587
|
+
}
|
|
2588
|
+
if (perm.startsWith("cache.read:") || perm.startsWith("cache.write:") || perm.startsWith("sqlite.read:") || perm.startsWith("sqlite.write:")) {
|
|
2589
|
+
const colonIdx = perm.indexOf(":");
|
|
2590
|
+
const cap = perm.slice(0, colonIdx);
|
|
2591
|
+
const rest = perm.slice(colonIdx + 1);
|
|
2592
|
+
if (rest.startsWith("@")) return perm;
|
|
2593
|
+
const dColonIdx = rest.indexOf("::");
|
|
2594
|
+
const rawLoc = dColonIdx === -1 ? rest : rest.slice(0, dColonIdx);
|
|
2595
|
+
const rawName = dColonIdx !== -1 ? rest.slice(dColonIdx + 2) : null;
|
|
2596
|
+
let loc = rawLoc;
|
|
2597
|
+
if (!loc.startsWith("./") && !loc.startsWith("../") && !loc.startsWith("~/") && !loc.startsWith("/") && !/^[a-zA-Z]:/.test(loc)) {
|
|
2598
|
+
loc = "./" + loc;
|
|
2599
|
+
}
|
|
2600
|
+
if (rawName === null) return `${cap}:${loc}`;
|
|
2601
|
+
return `${cap}:${loc}::${rawName}`;
|
|
2602
|
+
}
|
|
2603
|
+
return perm;
|
|
2604
|
+
}
|
|
2605
|
+
function computeEffectivePermissions(pluginPerms, projectPerms, lifecycle) {
|
|
2606
|
+
const namespacePlugin = pluginPerms?.[lifecycle] || {};
|
|
2607
|
+
const namespaceProject = projectPerms?.[lifecycle];
|
|
2608
|
+
const pluginAllow = (namespacePlugin.allow ?? []).map(normalizePattern);
|
|
2609
|
+
const pluginDeny = (namespacePlugin.deny ?? []).map(normalizePattern);
|
|
2610
|
+
return {
|
|
2611
|
+
allow: namespaceProject?.allow ? namespaceProject.allow.map(normalizePattern) : pluginAllow,
|
|
2612
|
+
deny: [...pluginDeny, ...(namespaceProject?.deny ?? []).map(normalizePattern)]
|
|
2613
|
+
};
|
|
2614
|
+
}
|
|
2615
|
+
function makePermissionChecker(effective, ctx = null) {
|
|
2616
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
2617
|
+
const getBucket = (cap) => {
|
|
2618
|
+
if (!buckets.has(cap)) buckets.set(cap, { allow: [], deny: [] });
|
|
2619
|
+
return buckets.get(cap);
|
|
2620
|
+
};
|
|
2621
|
+
const capOf = (p) => {
|
|
2622
|
+
const i = p.indexOf(":");
|
|
2623
|
+
return i === -1 ? p : p.slice(0, i);
|
|
2624
|
+
};
|
|
2625
|
+
const globBucket = { allow: [], deny: [] };
|
|
2626
|
+
for (const p of effective.allow.map(normalizePattern)) {
|
|
2627
|
+
if (p.startsWith("fs.glob:")) {
|
|
2628
|
+
globBucket.allow.push(p.slice("fs.glob:".length));
|
|
2629
|
+
continue;
|
|
2630
|
+
}
|
|
2631
|
+
for (const expanded of expandPattern(p, ctx)) getBucket(capOf(expanded)).allow.push(expanded);
|
|
2632
|
+
}
|
|
2633
|
+
for (const p of effective.deny.map(normalizePattern)) {
|
|
2634
|
+
if (p.startsWith("fs.glob:")) {
|
|
2635
|
+
globBucket.deny.push(p.slice("fs.glob:".length));
|
|
2636
|
+
continue;
|
|
2637
|
+
}
|
|
2638
|
+
for (const expanded of expandPattern(p, ctx)) getBucket(capOf(expanded)).deny.push(expanded);
|
|
2639
|
+
}
|
|
2640
|
+
const pvs = (list, cap) => {
|
|
2641
|
+
const n = cap.length + 1;
|
|
2642
|
+
return list.reduce((acc, p) => {
|
|
2643
|
+
if (p.length > n) acc.push(p.slice(n));
|
|
2644
|
+
return acc;
|
|
2645
|
+
}, []);
|
|
2646
|
+
};
|
|
2647
|
+
const checkBatchAndThrow = (capability, value, matchFn) => {
|
|
2648
|
+
const b = buckets.get(capability) ?? { allow: [], deny: [] };
|
|
2649
|
+
const allowed = b.allow.length > 0 && matchFn(pvs(b.allow, capability));
|
|
2650
|
+
const denied = b.deny.length > 0 && matchFn(pvs(b.deny, capability));
|
|
2651
|
+
if (!allowed || denied) throw new PermissionError(capability, value);
|
|
2652
|
+
};
|
|
2653
|
+
const absDir = ctx?.dir?.replace(/\\/g, "/") ?? "";
|
|
2654
|
+
const globCtx = { pluginId: ctx?.pluginId ?? null, pluginDir: ctx?.pluginDir ?? null, dir: ctx?.dir ?? "" };
|
|
2655
|
+
return function checkPermission(capability, value, absCwd) {
|
|
2656
|
+
switch (capability) {
|
|
2657
|
+
case "fs.read":
|
|
2658
|
+
case "fs.write":
|
|
2659
|
+
case "fs.exists": {
|
|
2660
|
+
const sub = (s) => s.startsWith("./") ? "__DOT__/" + s.slice(2) : s;
|
|
2661
|
+
const v = sub(normalizeFsPath(value));
|
|
2662
|
+
checkBatchAndThrow(capability, value, (pvs2) => isGlobMatch(v, pvs2.map(sub)));
|
|
2663
|
+
return;
|
|
2664
|
+
}
|
|
2665
|
+
case "fs.glob": {
|
|
2666
|
+
const resolvedCwd = (absCwd ?? absDir).replace(/\\/g, "/");
|
|
2667
|
+
const allowed = globBucket.allow.length > 0 && matchGlobPermission(value, resolvedCwd, globBucket.allow, globCtx);
|
|
2668
|
+
const denied = globBucket.deny.length > 0 && matchGlobPermission(value, resolvedCwd, globBucket.deny, globCtx);
|
|
2669
|
+
if (!allowed || denied) throw new PermissionError(capability, value);
|
|
2670
|
+
return;
|
|
2671
|
+
}
|
|
2672
|
+
case "shell.run":
|
|
2673
|
+
case "shell.job.start":
|
|
2674
|
+
case "rune.run":
|
|
2675
|
+
case "rune.repl":
|
|
2676
|
+
case "rune.job.start":
|
|
2677
|
+
case "db.connect": {
|
|
2678
|
+
checkBatchAndThrow(capability, value, (pvs2) => isWildcardMatch(value.replace(/\\/g, "/"), pvs2));
|
|
2679
|
+
return;
|
|
2680
|
+
}
|
|
2681
|
+
// Capabilities whose value is always null — permission declared as bare capability name.
|
|
2682
|
+
case "rune.job.kill":
|
|
2683
|
+
case "rune.job.exists":
|
|
2684
|
+
case "rune.job.read":
|
|
2685
|
+
case "rune.job.write":
|
|
2686
|
+
case "shell.job.kill":
|
|
2687
|
+
case "shell.job.exists":
|
|
2688
|
+
case "shell.job.read":
|
|
2689
|
+
case "shell.job.write":
|
|
2690
|
+
case "notify.send": {
|
|
2691
|
+
const b = buckets.get(capability);
|
|
2692
|
+
if (!b?.allow.length || b.deny.length > 0) throw new PermissionError(capability, "");
|
|
2693
|
+
return;
|
|
2694
|
+
}
|
|
2695
|
+
case "http.fetch":
|
|
2696
|
+
checkBatchAndThrow(capability, value, (pvs2) => matchFetchPermission(value, pvs2));
|
|
2697
|
+
return;
|
|
2698
|
+
case "env.read":
|
|
2699
|
+
checkBatchAndThrow(capability, value, (pvs2) => matchEnvPermission(value, pvs2));
|
|
2700
|
+
return;
|
|
2701
|
+
case "sqlite.read":
|
|
2702
|
+
case "sqlite.write":
|
|
2703
|
+
case "cache.read":
|
|
2704
|
+
case "cache.write":
|
|
2705
|
+
checkBatchAndThrow(capability, value, (pvs2) => matchStorePermission(value, pvs2));
|
|
2706
|
+
return;
|
|
2707
|
+
case "ws.client":
|
|
2708
|
+
checkBatchAndThrow(capability, value, (pvs2) => matchWsPermission(value, pvs2));
|
|
2709
|
+
return;
|
|
2710
|
+
case "http.server": {
|
|
2711
|
+
const colonIdx = value.lastIndexOf(":");
|
|
2712
|
+
const host = colonIdx !== -1 ? value.slice(0, colonIdx) : value;
|
|
2713
|
+
if (isLoopbackHost(host)) return;
|
|
2714
|
+
checkBatchAndThrow(capability, value, (pvs2) => matchHttpServerPermission(value, pvs2));
|
|
2715
|
+
return;
|
|
2716
|
+
}
|
|
2717
|
+
case "ws.server": {
|
|
2718
|
+
const firstColon = value.indexOf(":");
|
|
2719
|
+
const host = firstColon !== -1 ? value.slice(0, firstColon) : value;
|
|
2720
|
+
if (isLoopbackHost(host)) return;
|
|
2721
|
+
checkBatchAndThrow(capability, value, (pvs2) => matchWsServerPermission(value, pvs2));
|
|
2722
|
+
return;
|
|
2723
|
+
}
|
|
2724
|
+
default:
|
|
2725
|
+
throw new PermissionError(capability, value ?? "");
|
|
2726
|
+
}
|
|
2727
|
+
};
|
|
2728
|
+
}
|
|
2729
|
+
|
|
2730
|
+
// src/rune/permissions/shell-check.js
|
|
2731
|
+
init_require_shim();
|
|
2732
|
+
var BUILTIN_ALLOWLIST = /* @__PURE__ */ new Set([
|
|
2733
|
+
"cd",
|
|
2734
|
+
"echo",
|
|
2735
|
+
"printf",
|
|
2736
|
+
"test",
|
|
2737
|
+
"[",
|
|
2738
|
+
"pwd",
|
|
2739
|
+
"true",
|
|
2740
|
+
"false",
|
|
2741
|
+
"export",
|
|
2742
|
+
"set",
|
|
2743
|
+
"unset",
|
|
2744
|
+
"shift",
|
|
2745
|
+
"read",
|
|
2746
|
+
":"
|
|
2747
|
+
]);
|
|
2748
|
+
function checkShellCommand(cmd, shellKind, checkPermission) {
|
|
2749
|
+
if (!checkPermission) return;
|
|
2750
|
+
let scanned;
|
|
2751
|
+
try {
|
|
2752
|
+
scanned = scanCommand(cmd, shellKind);
|
|
2753
|
+
} catch (e) {
|
|
2754
|
+
if (e instanceof ScanRefusal) {
|
|
2755
|
+
throw new PermissionError("shell.run", cmd, "unscannable", {
|
|
2756
|
+
construct: e.construct,
|
|
2757
|
+
offset: e.offset
|
|
2758
|
+
});
|
|
2759
|
+
}
|
|
2760
|
+
throw e;
|
|
2761
|
+
}
|
|
2762
|
+
for (const command of scanned.commands) {
|
|
2763
|
+
if (BUILTIN_ALLOWLIST.has(command.program)) continue;
|
|
2764
|
+
checkPermission("shell.run", command.segment);
|
|
2765
|
+
}
|
|
2766
|
+
for (const redirect of scanned.redirects) {
|
|
2767
|
+
checkPermission(redirect.mode === "write" ? "fs.write" : "fs.read", redirect.target);
|
|
2768
|
+
}
|
|
2769
|
+
}
|
|
2770
|
+
|
|
2771
|
+
export {
|
|
2772
|
+
require_picomatch2 as require_picomatch,
|
|
2773
|
+
ensureProjectIdentity,
|
|
2774
|
+
upsertProject,
|
|
2775
|
+
resolvePath,
|
|
2776
|
+
getAutoPermits,
|
|
2777
|
+
resolveShell,
|
|
2778
|
+
ScanRefusal,
|
|
2779
|
+
scanCommand,
|
|
2780
|
+
isGlobMatch,
|
|
2781
|
+
isWildcardMatch,
|
|
2782
|
+
parseEnvPattern,
|
|
2783
|
+
computeEffectivePermissions,
|
|
2784
|
+
makePermissionChecker,
|
|
2785
|
+
BUILTIN_ALLOWLIST,
|
|
2786
|
+
checkShellCommand
|
|
2787
|
+
};
|