@r_masseater/wism 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -4
- package/dist/{app-ie0u061Q.mjs → app-CpjqcXHR.mjs} +45 -30
- package/dist/app-CpjqcXHR.mjs.map +1 -0
- package/dist/{cli-BPVyh-qS.mjs → cli-BD4VKg7i.mjs} +2 -2
- package/dist/{cli-BPVyh-qS.mjs.map → cli-BD4VKg7i.mjs.map} +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/define-Dvnt_9zv.mjs +6 -0
- package/dist/define-Dvnt_9zv.mjs.map +1 -0
- package/dist/index.d.mts +6 -4
- package/dist/index.mjs +3 -1
- package/dist/presets.d.mts +48 -0
- package/dist/presets.mjs +2608 -0
- package/dist/presets.mjs.map +1 -0
- package/package.json +20 -11
- package/skills/lint-presets/SKILL.md +65 -0
- package/skills/lint-structure/SKILL.md +3 -3
- package/dist/app-ie0u061Q.mjs.map +0 -1
package/dist/presets.mjs
ADDED
|
@@ -0,0 +1,2608 @@
|
|
|
1
|
+
import { n as defineRule, t as definePlugin } from "./define-Dvnt_9zv.mjs";
|
|
2
|
+
import { Array as Array$1, Equal, Option, Record, String as String$1, pipe } from "effect";
|
|
3
|
+
// src/entities/kind/model/layers.ts
|
|
4
|
+
const listed = (pick) => (layers) => (layer) => Array$1.contains(pick(layers) ?? [], layer);
|
|
5
|
+
const isSliced = listed((layers) => layers.sliced);
|
|
6
|
+
const isSegmented = listed((layers) => layers.segmented);
|
|
7
|
+
const isParted = (layers) => (layer) => isSliced(layers)(layer) || isSegmented(layers)(layer);
|
|
8
|
+
const isLayer = listed((layers) => layers.order);
|
|
9
|
+
// src/entities/kind/model/presets.ts
|
|
10
|
+
const FSD_LAYERS = [
|
|
11
|
+
"app",
|
|
12
|
+
"pages",
|
|
13
|
+
"widgets",
|
|
14
|
+
"features",
|
|
15
|
+
"entities",
|
|
16
|
+
"shared"
|
|
17
|
+
];
|
|
18
|
+
const SLICED = [
|
|
19
|
+
"pages",
|
|
20
|
+
"widgets",
|
|
21
|
+
"features",
|
|
22
|
+
"entities"
|
|
23
|
+
];
|
|
24
|
+
const SCRIPTS = ["**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}"];
|
|
25
|
+
const RUST = ["**/*.rs"];
|
|
26
|
+
const pathsOf$1 = ({ paths }) => Option.match(Option.fromUndefinedOr(paths), {
|
|
27
|
+
onNone: () => ({}),
|
|
28
|
+
onSome: (value) => ({ paths: value })
|
|
29
|
+
});
|
|
30
|
+
const workspace = (options = {}) => ({
|
|
31
|
+
name: "workspace",
|
|
32
|
+
marker: "package.json",
|
|
33
|
+
...pathsOf$1(options),
|
|
34
|
+
placements: [{
|
|
35
|
+
files: SCRIPTS,
|
|
36
|
+
allow: [
|
|
37
|
+
"src/**",
|
|
38
|
+
"bin/**",
|
|
39
|
+
"*.config.{ts,mts,js,mjs}",
|
|
40
|
+
"alchemy.*.ts",
|
|
41
|
+
"*.d.{ts,mts,cts}"
|
|
42
|
+
],
|
|
43
|
+
message: "sits outside src/. Put every module of a workspace under src/ in an FSD layer; only bin/, *.config.ts, alchemy.*.ts and *.d.ts may stay at the workspace root."
|
|
44
|
+
}],
|
|
45
|
+
layers: {
|
|
46
|
+
dir: "src",
|
|
47
|
+
files: SCRIPTS,
|
|
48
|
+
order: FSD_LAYERS,
|
|
49
|
+
sliced: SLICED,
|
|
50
|
+
segmented: ["shared"],
|
|
51
|
+
entries: ["index.*"],
|
|
52
|
+
open: ["shared/lib/**", "shared/ui/**"],
|
|
53
|
+
cross: "@x"
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
const rustCrate = (options = {}) => ({
|
|
57
|
+
name: "crate",
|
|
58
|
+
marker: "Cargo.toml",
|
|
59
|
+
...pathsOf$1(options),
|
|
60
|
+
placements: [{
|
|
61
|
+
files: RUST,
|
|
62
|
+
allow: [
|
|
63
|
+
"src/**",
|
|
64
|
+
"build.rs",
|
|
65
|
+
"benches/**",
|
|
66
|
+
"tests/**"
|
|
67
|
+
],
|
|
68
|
+
message: "sits outside src/. Put every module of a crate under src/ in an FSD layer; only build.rs, benches/ and tests/ may stay outside."
|
|
69
|
+
}],
|
|
70
|
+
layers: {
|
|
71
|
+
dir: "src",
|
|
72
|
+
files: RUST,
|
|
73
|
+
order: FSD_LAYERS,
|
|
74
|
+
sliced: SLICED,
|
|
75
|
+
segmented: ["shared"],
|
|
76
|
+
loose: [
|
|
77
|
+
"lib.rs",
|
|
78
|
+
"main.rs",
|
|
79
|
+
"bin/**"
|
|
80
|
+
],
|
|
81
|
+
moduleFiles: true
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
const skill = (options = {}) => ({
|
|
85
|
+
name: "skill",
|
|
86
|
+
marker: "SKILL.md",
|
|
87
|
+
...pathsOf$1(options),
|
|
88
|
+
placements: [{
|
|
89
|
+
files: ["**"],
|
|
90
|
+
allow: [
|
|
91
|
+
"SKILL.md",
|
|
92
|
+
"usecases/**",
|
|
93
|
+
"references/**",
|
|
94
|
+
"scripts/**",
|
|
95
|
+
"assets/**"
|
|
96
|
+
],
|
|
97
|
+
message: "is not part of an Agent Skill's layout. A skill holds SKILL.md, usecases/, references/, scripts/ and assets/."
|
|
98
|
+
}]
|
|
99
|
+
});
|
|
100
|
+
const EXTENSION = ".";
|
|
101
|
+
const BACKSLASH = "\\";
|
|
102
|
+
const NONE = 0;
|
|
103
|
+
const ONE$2 = 1;
|
|
104
|
+
String$1.replaceAll(BACKSLASH, "/");
|
|
105
|
+
const segments = (path) => String$1.split(path, "/");
|
|
106
|
+
const joinAll = (parts) => Array$1.join(parts, "/");
|
|
107
|
+
const join = (directory) => (name) => Array$1.join(Array$1.filter([directory, name], String$1.isNonEmpty), "/");
|
|
108
|
+
const parent = (path) => joinAll(Array$1.dropRight(segments(path), ONE$2));
|
|
109
|
+
const ancestors = (path) => {
|
|
110
|
+
const parts = Array$1.dropRight(segments(path), ONE$2);
|
|
111
|
+
return pipe(Array$1.range(NONE, parts.length), Array$1.reverse, Array$1.map((count) => joinAll(Array$1.take(parts, count))));
|
|
112
|
+
};
|
|
113
|
+
const baseName = (path) => pipe(segments(path), Array$1.filter(String$1.isNonEmpty), Array$1.last, Option.getOrElse(() => ""));
|
|
114
|
+
const stem = (name) => pipe(String$1.split(name, EXTENSION), Array$1.head, Option.getOrElse(() => name));
|
|
115
|
+
const afterPrefix = (prefix) => (text) => pipe(Option.liftPredicate(text, String$1.startsWith(prefix)), Option.map(String$1.slice(prefix.length)));
|
|
116
|
+
const below = (directory) => (path) => pipe(Option.liftPredicate(path, () => String$1.isEmpty(directory)), Option.orElse(() => afterPrefix(`${directory}/`)(path)));
|
|
117
|
+
// ../../node_modules/.pnpm/balanced-match@4.0.4/node_modules/balanced-match/dist/esm/index.js
|
|
118
|
+
const balanced = (a, b, str) => {
|
|
119
|
+
const ma = a instanceof RegExp ? maybeMatch(a, str) : a;
|
|
120
|
+
const mb = b instanceof RegExp ? maybeMatch(b, str) : b;
|
|
121
|
+
const r = ma !== null && mb != null && range(ma, mb, str);
|
|
122
|
+
return r && {
|
|
123
|
+
start: r[0],
|
|
124
|
+
end: r[1],
|
|
125
|
+
pre: str.slice(0, r[0]),
|
|
126
|
+
body: str.slice(r[0] + ma.length, r[1]),
|
|
127
|
+
post: str.slice(r[1] + mb.length)
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
const maybeMatch = (reg, str) => {
|
|
131
|
+
const m = str.match(reg);
|
|
132
|
+
return m ? m[0] : null;
|
|
133
|
+
};
|
|
134
|
+
const range = (a, b, str) => {
|
|
135
|
+
let begs, beg, left, right = void 0, result;
|
|
136
|
+
let ai = str.indexOf(a);
|
|
137
|
+
let bi = str.indexOf(b, ai + 1);
|
|
138
|
+
let i = ai;
|
|
139
|
+
if (ai >= 0 && bi > 0) {
|
|
140
|
+
if (a === b) return [ai, bi];
|
|
141
|
+
begs = [];
|
|
142
|
+
left = str.length;
|
|
143
|
+
while (i >= 0 && !result) {
|
|
144
|
+
if (i === ai) {
|
|
145
|
+
begs.push(i);
|
|
146
|
+
ai = str.indexOf(a, i + 1);
|
|
147
|
+
} else if (begs.length === 1) {
|
|
148
|
+
const r = begs.pop();
|
|
149
|
+
if (r !== void 0) result = [r, bi];
|
|
150
|
+
} else {
|
|
151
|
+
beg = begs.pop();
|
|
152
|
+
if (beg !== void 0 && beg < left) {
|
|
153
|
+
left = beg;
|
|
154
|
+
right = bi;
|
|
155
|
+
}
|
|
156
|
+
bi = str.indexOf(b, i + 1);
|
|
157
|
+
}
|
|
158
|
+
i = ai < bi && ai >= 0 ? ai : bi;
|
|
159
|
+
}
|
|
160
|
+
if (begs.length && right !== void 0) result = [left, right];
|
|
161
|
+
}
|
|
162
|
+
return result;
|
|
163
|
+
};
|
|
164
|
+
// ../../node_modules/.pnpm/brace-expansion@5.0.12/node_modules/brace-expansion/dist/esm/index.js
|
|
165
|
+
const escSlash = "\0SLASH" + Math.random() + "\0";
|
|
166
|
+
const escOpen = "\0OPEN" + Math.random() + "\0";
|
|
167
|
+
const escClose = "\0CLOSE" + Math.random() + "\0";
|
|
168
|
+
const escComma = "\0COMMA" + Math.random() + "\0";
|
|
169
|
+
const escPeriod = "\0PERIOD" + Math.random() + "\0";
|
|
170
|
+
const escSlashPattern = new RegExp(escSlash, "g");
|
|
171
|
+
const escOpenPattern = new RegExp(escOpen, "g");
|
|
172
|
+
const escClosePattern = new RegExp(escClose, "g");
|
|
173
|
+
const escCommaPattern = new RegExp(escComma, "g");
|
|
174
|
+
const escPeriodPattern = new RegExp(escPeriod, "g");
|
|
175
|
+
const slashPattern = /\\\\/g;
|
|
176
|
+
const openPattern = /\\{/g;
|
|
177
|
+
const closePattern = /\\}/g;
|
|
178
|
+
const commaPattern = /\\,/g;
|
|
179
|
+
const periodPattern = /\\\./g;
|
|
180
|
+
const EXPANSION_MAX = 1e5;
|
|
181
|
+
const EXPANSION_MAX_LENGTH = 4e6;
|
|
182
|
+
const EXPANSION_MAX_DEPTH = 1e3;
|
|
183
|
+
const EXPANSION_MAX_REWRITES = 1e3;
|
|
184
|
+
function numeric(str) {
|
|
185
|
+
return !isNaN(str) ? parseInt(str, 10) : str.charCodeAt(0);
|
|
186
|
+
}
|
|
187
|
+
function escapeBraces(str) {
|
|
188
|
+
return str.replace(slashPattern, escSlash).replace(openPattern, escOpen).replace(closePattern, escClose).replace(commaPattern, escComma).replace(periodPattern, escPeriod);
|
|
189
|
+
}
|
|
190
|
+
function unescapeBraces(str) {
|
|
191
|
+
return str.replace(escSlashPattern, "\\").replace(escOpenPattern, "{").replace(escClosePattern, "}").replace(escCommaPattern, ",").replace(escPeriodPattern, ".");
|
|
192
|
+
}
|
|
193
|
+
function pushAll(target, items) {
|
|
194
|
+
for (let i = 0; i < items.length; i++) target.push(items[i]);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Basically just str.split(","), but handling cases
|
|
198
|
+
* where we have nested braced sections, which should be
|
|
199
|
+
* treated as individual members, like {a,{b,c},d}
|
|
200
|
+
*/
|
|
201
|
+
function parseCommaParts(str) {
|
|
202
|
+
const parts = [];
|
|
203
|
+
let carry = "";
|
|
204
|
+
for (;;) {
|
|
205
|
+
const m = balanced("{", "}", str);
|
|
206
|
+
if (!m) {
|
|
207
|
+
const tail = str.split(",");
|
|
208
|
+
tail[0] = carry + tail[0];
|
|
209
|
+
pushAll(parts, tail);
|
|
210
|
+
return parts;
|
|
211
|
+
}
|
|
212
|
+
const { pre, body, post } = m;
|
|
213
|
+
const p = pre.split(",");
|
|
214
|
+
p[0] = carry + p[0];
|
|
215
|
+
p[p.length - 1] += "{" + body + "}";
|
|
216
|
+
if (!post.length) {
|
|
217
|
+
pushAll(parts, p);
|
|
218
|
+
return parts;
|
|
219
|
+
}
|
|
220
|
+
carry = p.pop();
|
|
221
|
+
pushAll(parts, p);
|
|
222
|
+
str = post;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
function expand(str, options = {}) {
|
|
226
|
+
if (!str) return [];
|
|
227
|
+
const { max = EXPANSION_MAX, maxLength = EXPANSION_MAX_LENGTH, maxDepth = EXPANSION_MAX_DEPTH, maxRewrites = EXPANSION_MAX_REWRITES } = options;
|
|
228
|
+
if (str.slice(0, 2) === "{}") str = "\\{\\}" + str.slice(2);
|
|
229
|
+
return expand_(escapeBraces(str), max, maxLength, maxDepth, 0, maxRewrites, true).map(unescapeBraces);
|
|
230
|
+
}
|
|
231
|
+
function embrace(str) {
|
|
232
|
+
return "{" + str + "}";
|
|
233
|
+
}
|
|
234
|
+
function isPadded(el) {
|
|
235
|
+
return /^-?0\d/.test(el);
|
|
236
|
+
}
|
|
237
|
+
function lte(i, y) {
|
|
238
|
+
return i <= y;
|
|
239
|
+
}
|
|
240
|
+
function gte(i, y) {
|
|
241
|
+
return i >= y;
|
|
242
|
+
}
|
|
243
|
+
function combine(acc, pre, values, max, maxLength, dropEmpties) {
|
|
244
|
+
const out = [];
|
|
245
|
+
let length = 0;
|
|
246
|
+
for (let a = 0; a < acc.length; a++) for (let v = 0; v < values.length; v++) {
|
|
247
|
+
if (out.length >= max) return out;
|
|
248
|
+
const expansion = acc[a] + pre + values[v];
|
|
249
|
+
if (dropEmpties && !expansion) continue;
|
|
250
|
+
if (length + expansion.length > maxLength) return out;
|
|
251
|
+
out.push(expansion);
|
|
252
|
+
length += expansion.length;
|
|
253
|
+
}
|
|
254
|
+
return out;
|
|
255
|
+
}
|
|
256
|
+
function expandSequence(body, isAlphaSequence, max, maxLength) {
|
|
257
|
+
const n = body.split(/\.\./);
|
|
258
|
+
const N = [];
|
|
259
|
+
/* c8 ignore start */
|
|
260
|
+
if (n[0] === void 0 || n[1] === void 0) return N;
|
|
261
|
+
/* c8 ignore stop */
|
|
262
|
+
const x = numeric(n[0]);
|
|
263
|
+
const y = numeric(n[1]);
|
|
264
|
+
const width = Math.max(n[0].length, n[1].length);
|
|
265
|
+
let incr = n.length === 3 && n[2] !== void 0 ? Math.max(Math.abs(numeric(n[2])), 1) : 1;
|
|
266
|
+
let test = lte;
|
|
267
|
+
if (y < x) {
|
|
268
|
+
incr *= -1;
|
|
269
|
+
test = gte;
|
|
270
|
+
}
|
|
271
|
+
const pad = n.some(isPadded);
|
|
272
|
+
let length = 0;
|
|
273
|
+
for (let i = x; test(i, y) && N.length < max; i += incr) {
|
|
274
|
+
let c;
|
|
275
|
+
if (isAlphaSequence) {
|
|
276
|
+
c = String.fromCharCode(i);
|
|
277
|
+
if (c === "\\") c = "";
|
|
278
|
+
} else {
|
|
279
|
+
c = String(i);
|
|
280
|
+
if (pad) {
|
|
281
|
+
const need = width - c.length;
|
|
282
|
+
if (need > 0) {
|
|
283
|
+
const z = new Array(need + 1).join("0");
|
|
284
|
+
if (i < 0) c = "-" + z + c.slice(1);
|
|
285
|
+
else c = z + c;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (length + c.length > maxLength) break;
|
|
290
|
+
N.push(c);
|
|
291
|
+
length += c.length;
|
|
292
|
+
}
|
|
293
|
+
return N;
|
|
294
|
+
}
|
|
295
|
+
function expand_(str, max, maxLength, maxDepth, depth, maxRewrites, isTop) {
|
|
296
|
+
if (depth > maxDepth) return [str];
|
|
297
|
+
let acc = [""];
|
|
298
|
+
let rewrites = 0;
|
|
299
|
+
let dropEmpties = false;
|
|
300
|
+
let firstGroup = true;
|
|
301
|
+
for (;;) {
|
|
302
|
+
const m = balanced("{", "}", str);
|
|
303
|
+
if (!m) return combine(acc, str, [""], max, maxLength, dropEmpties);
|
|
304
|
+
const pre = m.pre;
|
|
305
|
+
if (/\$$/.test(pre)) {
|
|
306
|
+
acc = combine(acc, pre + "{" + m.body + "}", [""], max, maxLength, dropEmpties && !m.post.length);
|
|
307
|
+
firstGroup = false;
|
|
308
|
+
if (!m.post.length) break;
|
|
309
|
+
str = m.post;
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
const isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
|
|
313
|
+
const isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
|
|
314
|
+
const isSequence = isNumericSequence || isAlphaSequence;
|
|
315
|
+
const isOptions = m.body.indexOf(",") >= 0;
|
|
316
|
+
if (!isSequence && !isOptions) {
|
|
317
|
+
if (rewrites < maxRewrites && m.post.match(/,(?!,).*\}/)) {
|
|
318
|
+
rewrites++;
|
|
319
|
+
str = m.pre + "{" + m.body + escClose + m.post;
|
|
320
|
+
isTop = true;
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
return combine(acc, pre + "{" + m.body + "}" + m.post, [""], max, maxLength, dropEmpties);
|
|
324
|
+
}
|
|
325
|
+
if (firstGroup) {
|
|
326
|
+
dropEmpties = isTop && !isSequence;
|
|
327
|
+
firstGroup = false;
|
|
328
|
+
}
|
|
329
|
+
let values;
|
|
330
|
+
if (isSequence) values = expandSequence(m.body, isAlphaSequence, max, maxLength);
|
|
331
|
+
else {
|
|
332
|
+
let n = parseCommaParts(m.body);
|
|
333
|
+
if (n.length === 1 && n[0] !== void 0) {
|
|
334
|
+
n = expand_(n[0], max, maxLength, maxDepth, depth + 1, maxRewrites, false).map(embrace);
|
|
335
|
+
/* c8 ignore start */
|
|
336
|
+
if (n.length === 1) {
|
|
337
|
+
acc = combine(acc, pre + n[0], [""], max, maxLength, dropEmpties && !m.post.length);
|
|
338
|
+
if (!m.post.length) break;
|
|
339
|
+
str = m.post;
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
let dropsEmpties = dropEmpties && !m.post.length && !pre;
|
|
344
|
+
for (let d = 0; dropsEmpties && d < acc.length; d++) if (acc[d]) dropsEmpties = false;
|
|
345
|
+
values = [];
|
|
346
|
+
let valuesLength = 0;
|
|
347
|
+
outer: for (let j = 0; j < n.length; j++) {
|
|
348
|
+
const expanded = expand_(n[j], max, maxLength, maxDepth, depth + 1, maxRewrites, false);
|
|
349
|
+
for (let k = 0; k < expanded.length; k++) {
|
|
350
|
+
const v = expanded[k];
|
|
351
|
+
if (dropsEmpties && !v) continue;
|
|
352
|
+
if (values.length >= max || valuesLength + v.length > maxLength) break outer;
|
|
353
|
+
values.push(v);
|
|
354
|
+
valuesLength += v.length;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
acc = combine(acc, pre, values, max, maxLength, dropEmpties && !m.post.length);
|
|
359
|
+
if (!m.post.length) break;
|
|
360
|
+
str = m.post;
|
|
361
|
+
}
|
|
362
|
+
return acc;
|
|
363
|
+
}
|
|
364
|
+
// ../../node_modules/.pnpm/@isaacs+nonrecursive-glob-match@1.1.0/node_modules/@isaacs/nonrecursive-glob-match/dist/esm/numeric-range.js
|
|
365
|
+
const digit = (a, b) => a === b ? {
|
|
366
|
+
t: "lit",
|
|
367
|
+
ch: String(a)
|
|
368
|
+
} : {
|
|
369
|
+
t: "class",
|
|
370
|
+
re: new RegExp(`^[${a}-${b}]$`)
|
|
371
|
+
};
|
|
372
|
+
const prefix = (d, alts) => alts.map((s) => [digit(d, d), ...s]);
|
|
373
|
+
const fixed = (a, b) => {
|
|
374
|
+
if (!a) return [[]];
|
|
375
|
+
let lo = +a[0];
|
|
376
|
+
let hi = +b[0];
|
|
377
|
+
const ra = a.slice(1);
|
|
378
|
+
const rb = b.slice(1);
|
|
379
|
+
if (lo === hi) return prefix(lo, fixed(ra, rb));
|
|
380
|
+
const zeros = "0".repeat(ra.length);
|
|
381
|
+
const nines = "9".repeat(ra.length);
|
|
382
|
+
const out = [];
|
|
383
|
+
if (ra !== zeros) out.push(...prefix(lo++, fixed(ra, nines)));
|
|
384
|
+
const last = rb === nines ? [] : prefix(hi--, fixed(zeros, rb));
|
|
385
|
+
if (lo <= hi) out.push([digit(lo, hi), ...Array.from(ra, () => digit(0, 9))]);
|
|
386
|
+
out.push(...last);
|
|
387
|
+
return out;
|
|
388
|
+
};
|
|
389
|
+
const nonneg = (a, b, width) => {
|
|
390
|
+
if (width) return fixed(String(a).padStart(width, "0"), String(b).padStart(width, "0"));
|
|
391
|
+
const out = [];
|
|
392
|
+
for (let len = String(a).length; len <= String(b).length; len++) {
|
|
393
|
+
const lo = Math.max(a, len === 1 ? 0 : 10 ** (len - 1));
|
|
394
|
+
const hi = Math.min(b, 10 ** len - 1);
|
|
395
|
+
out.push(...fixed(String(lo), String(hi)));
|
|
396
|
+
}
|
|
397
|
+
return out;
|
|
398
|
+
};
|
|
399
|
+
/**
|
|
400
|
+
* The strings that the bash brace expansion `{lo..hi}` makes, as
|
|
401
|
+
* the alternatives of an `@(...)` extglob. Each one is a sequence of
|
|
402
|
+
* digits and digit classes, so there are only a few of them, even for
|
|
403
|
+
* a large range.
|
|
404
|
+
*
|
|
405
|
+
* If either end has a leading zero, such as `{01..10}`, each number
|
|
406
|
+
* has leading zeros to make it as long as the longer end, counting a
|
|
407
|
+
* `-` sign. So `{-05..3}` makes `-05` to `-01`, then `000` to `003`.
|
|
408
|
+
*
|
|
409
|
+
* Returns undefined if either end is not a safe integer.
|
|
410
|
+
*/
|
|
411
|
+
const numericRange = (loStr, hiStr) => {
|
|
412
|
+
let lo = Number(loStr);
|
|
413
|
+
let hi = Number(hiStr);
|
|
414
|
+
if (!Number.isSafeInteger(lo) || !Number.isSafeInteger(hi)) return;
|
|
415
|
+
if (lo > hi) [lo, hi] = [hi, lo];
|
|
416
|
+
const width = /^-?0\d/.test(loStr) || /^-?0\d/.test(hiStr) ? Math.max(loStr.length, hiStr.length) : 0;
|
|
417
|
+
const out = [];
|
|
418
|
+
if (lo < 0) {
|
|
419
|
+
const neg = nonneg(Math.max(-hi, 1), -lo, width && width - 1);
|
|
420
|
+
out.push(...neg.map((s) => [{
|
|
421
|
+
t: "lit",
|
|
422
|
+
ch: "-"
|
|
423
|
+
}, ...s]));
|
|
424
|
+
}
|
|
425
|
+
if (hi >= 0) out.push(...nonneg(Math.max(lo, 0), hi, width));
|
|
426
|
+
return out;
|
|
427
|
+
};
|
|
428
|
+
// ../../node_modules/.pnpm/@isaacs+nonrecursive-glob-match@1.1.0/node_modules/@isaacs/nonrecursive-glob-match/dist/esm/parse-class.js
|
|
429
|
+
const posixClasses = {
|
|
430
|
+
"[:alnum:]": ["\\p{L}\\p{Nl}\\p{Nd}"],
|
|
431
|
+
"[:alpha:]": ["\\p{L}\\p{Nl}"],
|
|
432
|
+
"[:ascii:]": ["\\x00-\\x7f"],
|
|
433
|
+
"[:blank:]": ["\\p{Zs}\\t"],
|
|
434
|
+
"[:cntrl:]": ["\\p{Cc}"],
|
|
435
|
+
"[:digit:]": ["\\p{Nd}"],
|
|
436
|
+
"[:graph:]": ["\\p{Z}\\p{C}", true],
|
|
437
|
+
"[:lower:]": ["\\p{Ll}"],
|
|
438
|
+
"[:print:]": ["\\p{C}", true],
|
|
439
|
+
"[:punct:]": ["\\p{P}\\p{S}"],
|
|
440
|
+
"[:space:]": ["\\p{Z}\\t\\r\\n\\v\\f"],
|
|
441
|
+
"[:upper:]": ["\\p{Lu}"],
|
|
442
|
+
"[:word:]": ["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}"],
|
|
443
|
+
"[:xdigit:]": ["A-Fa-f0-9"]
|
|
444
|
+
};
|
|
445
|
+
const braceEscape = (s) => s.replace(/[[\]\\-]/g, "\\$&");
|
|
446
|
+
const noMatch = /$./;
|
|
447
|
+
const parseClass = (glob, position, nocase = false, form) => {
|
|
448
|
+
const norm = (c) => {
|
|
449
|
+
const n = form ? c.normalize(form) : c;
|
|
450
|
+
return [...n].length === 1 ? n : c;
|
|
451
|
+
};
|
|
452
|
+
const pos = position;
|
|
453
|
+
/* c8 ignore start */
|
|
454
|
+
if (glob.charAt(pos) !== "[") throw new Error("not in a brace expression");
|
|
455
|
+
/* c8 ignore stop */
|
|
456
|
+
const ranges = [];
|
|
457
|
+
const negs = [];
|
|
458
|
+
let i = pos + 1;
|
|
459
|
+
let sawStart = false;
|
|
460
|
+
let escaping = false;
|
|
461
|
+
let negate = false;
|
|
462
|
+
let endPos = pos;
|
|
463
|
+
let rangeStart = "";
|
|
464
|
+
WHILE: while (i < glob.length) {
|
|
465
|
+
const c = String.fromCodePoint(glob.codePointAt(i));
|
|
466
|
+
if ((c === "!" || c === "^") && i === pos + 1) {
|
|
467
|
+
negate = true;
|
|
468
|
+
i++;
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
if (c === "]" && sawStart && !escaping) {
|
|
472
|
+
endPos = i + 1;
|
|
473
|
+
break;
|
|
474
|
+
}
|
|
475
|
+
sawStart = true;
|
|
476
|
+
if (c === "\\") {
|
|
477
|
+
if (!escaping) {
|
|
478
|
+
escaping = true;
|
|
479
|
+
i++;
|
|
480
|
+
continue;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
if (c === "[" && !escaping) {
|
|
484
|
+
for (const [cls, [unip, neg]] of Object.entries(posixClasses)) if (glob.startsWith(cls, i)) {
|
|
485
|
+
if (rangeStart) return [noMatch, glob.length - pos];
|
|
486
|
+
i += cls.length;
|
|
487
|
+
if (neg) negs.push(unip);
|
|
488
|
+
else ranges.push(unip);
|
|
489
|
+
continue WHILE;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
escaping = false;
|
|
493
|
+
const n = norm(c);
|
|
494
|
+
if (rangeStart) {
|
|
495
|
+
if (n.codePointAt(0) > rangeStart.codePointAt(0)) ranges.push(braceEscape(rangeStart) + "-" + braceEscape(n));
|
|
496
|
+
else if (n === rangeStart) ranges.push(braceEscape(n));
|
|
497
|
+
rangeStart = "";
|
|
498
|
+
i += c.length;
|
|
499
|
+
continue;
|
|
500
|
+
}
|
|
501
|
+
if (glob.startsWith("-]", i + c.length)) {
|
|
502
|
+
ranges.push(braceEscape(n + "-"));
|
|
503
|
+
i += c.length + 1;
|
|
504
|
+
continue;
|
|
505
|
+
}
|
|
506
|
+
if (glob.startsWith("-", i + c.length)) {
|
|
507
|
+
rangeStart = n;
|
|
508
|
+
i += c.length + 1;
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
ranges.push(braceEscape(n));
|
|
512
|
+
i += c.length;
|
|
513
|
+
}
|
|
514
|
+
if (endPos < i) return [noMatch, 0];
|
|
515
|
+
if (!ranges.length && !negs.length) return [noMatch, glob.length - pos];
|
|
516
|
+
const sranges = "[" + (negate ? "^" : "") + ranges.join("") + "]";
|
|
517
|
+
const snegs = "[" + (negate ? "" : "^") + negs.join("") + "]";
|
|
518
|
+
const comb = "^" + (ranges.length && negs.length ? "(" + sranges + "|" + snegs + ")" : ranges.length ? sranges : snegs);
|
|
519
|
+
return [new RegExp(comb, nocase ? "iu" : "u"), endPos - pos];
|
|
520
|
+
};
|
|
521
|
+
// ../../node_modules/.pnpm/@isaacs+nonrecursive-glob-match@1.1.0/node_modules/@isaacs/nonrecursive-glob-match/dist/esm/index.js
|
|
522
|
+
const MATCH = {
|
|
523
|
+
t: "match",
|
|
524
|
+
id: 0
|
|
525
|
+
};
|
|
526
|
+
const extTypes = "!?+*@";
|
|
527
|
+
const lit = (ch) => ({
|
|
528
|
+
t: "lit",
|
|
529
|
+
ch
|
|
530
|
+
});
|
|
531
|
+
const reEscape = (s) => s.replace(/[\\^$.*+?()[\]{}|/]/g, "\\$&");
|
|
532
|
+
const newFoldRe = (s) => new RegExp(`^${reEscape(s)}$`, "iu");
|
|
533
|
+
const foldCache = /* @__PURE__ */ new Map();
|
|
534
|
+
const foldRe = (ch) => {
|
|
535
|
+
let re = foldCache.get(ch);
|
|
536
|
+
if (!re) {
|
|
537
|
+
re = newFoldRe(ch);
|
|
538
|
+
if (foldCache.size >= 1e3) foldCache.clear();
|
|
539
|
+
foldCache.set(ch, re);
|
|
540
|
+
}
|
|
541
|
+
return re;
|
|
542
|
+
};
|
|
543
|
+
const litMatch = (l, c) => {
|
|
544
|
+
if (c === l.ch) return true;
|
|
545
|
+
if (!l.re) return false;
|
|
546
|
+
const code = c.charCodeAt(0);
|
|
547
|
+
if (code >= 128) return l.re.test(c);
|
|
548
|
+
const ascii = l.ascii ??= /* @__PURE__ */ new Uint8Array(128);
|
|
549
|
+
ascii[code] ||= l.re.test(c) ? 1 : 2;
|
|
550
|
+
return ascii[code] === 1;
|
|
551
|
+
};
|
|
552
|
+
const tokenize = (p, nocase, noext, form, mark) => {
|
|
553
|
+
const toks = [];
|
|
554
|
+
for (let i = 0; i < p.length;) {
|
|
555
|
+
const c = String.fromCodePoint(p.codePointAt(i));
|
|
556
|
+
if (mark) {
|
|
557
|
+
const m = c === "\\" && p.startsWith(mark, i + 1) ? 1 : 0;
|
|
558
|
+
if (m || c === mark) {
|
|
559
|
+
const start = i + m + mark.length;
|
|
560
|
+
const end = p.indexOf(mark, start);
|
|
561
|
+
const r = /^(-?\d+)\.\.(-?\d+)$/.exec(p.slice(start, end));
|
|
562
|
+
const alts = end !== -1 && r && numericRange(r[1], r[2]);
|
|
563
|
+
if (alts) {
|
|
564
|
+
toks.push({
|
|
565
|
+
t: "ext",
|
|
566
|
+
type: "@",
|
|
567
|
+
alts
|
|
568
|
+
});
|
|
569
|
+
i = end + mark.length;
|
|
570
|
+
continue;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
if (c === "\\") {
|
|
575
|
+
const e = p.codePointAt(i + 1);
|
|
576
|
+
const ch = e === void 0 ? c : String.fromCodePoint(e);
|
|
577
|
+
toks.push(lit(ch));
|
|
578
|
+
i += 1 + ch.length;
|
|
579
|
+
continue;
|
|
580
|
+
}
|
|
581
|
+
if (c === "[") {
|
|
582
|
+
const [re, consumed] = parseClass(p, i, nocase, form);
|
|
583
|
+
if (consumed) {
|
|
584
|
+
toks.push({
|
|
585
|
+
t: "class",
|
|
586
|
+
re
|
|
587
|
+
});
|
|
588
|
+
i += consumed;
|
|
589
|
+
continue;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
if (!noext && extTypes.includes(c) && p[i + 1] === "(") {
|
|
593
|
+
toks.push({
|
|
594
|
+
t: "open",
|
|
595
|
+
type: c
|
|
596
|
+
});
|
|
597
|
+
i += 2;
|
|
598
|
+
continue;
|
|
599
|
+
}
|
|
600
|
+
toks.push(!noext && c === "|" ? { t: "bar" } : !noext && c === ")" ? { t: "close" } : c === "*" ? { t: "star" } : c === "?" ? { t: "any" } : lit(c));
|
|
601
|
+
i += c.length;
|
|
602
|
+
}
|
|
603
|
+
return toks;
|
|
604
|
+
};
|
|
605
|
+
const pair = (toks) => {
|
|
606
|
+
const pairs = /* @__PURE__ */ new Map();
|
|
607
|
+
const stack = [];
|
|
608
|
+
toks.forEach((tok, i) => {
|
|
609
|
+
if (tok.t === "open") stack.push(i);
|
|
610
|
+
else if (tok.t === "close" && stack.length) pairs.set(stack.pop(), i);
|
|
611
|
+
});
|
|
612
|
+
return pairs;
|
|
613
|
+
};
|
|
614
|
+
const build = (toks, pairs, start, end, top) => {
|
|
615
|
+
let seq = [];
|
|
616
|
+
const alts = [seq];
|
|
617
|
+
for (let i = start; i < end; i++) {
|
|
618
|
+
const tok = toks[i];
|
|
619
|
+
const close = pairs.get(i);
|
|
620
|
+
if (tok.t === "open" && close !== void 0) {
|
|
621
|
+
const sub = build(toks, pairs, i + 1, close, false);
|
|
622
|
+
seq.push({
|
|
623
|
+
t: "ext",
|
|
624
|
+
type: tok.type,
|
|
625
|
+
alts: sub
|
|
626
|
+
});
|
|
627
|
+
i = close;
|
|
628
|
+
} else if (tok.t === "bar" && !top) alts.push(seq = []);
|
|
629
|
+
else if (tok.t === "open") seq.push(lit(tok.type), lit("("));
|
|
630
|
+
else if (tok.t === "bar") seq.push(lit("|"));
|
|
631
|
+
else if (tok.t === "close") seq.push(lit(")"));
|
|
632
|
+
else seq.push(tok);
|
|
633
|
+
}
|
|
634
|
+
return alts;
|
|
635
|
+
};
|
|
636
|
+
const normalize = (items, form) => {
|
|
637
|
+
const out = [];
|
|
638
|
+
let run = "";
|
|
639
|
+
const flush = () => {
|
|
640
|
+
for (const ch of run.normalize(form)) out.push(lit(ch));
|
|
641
|
+
run = "";
|
|
642
|
+
};
|
|
643
|
+
for (const it of items) {
|
|
644
|
+
if (it.t === "lit") {
|
|
645
|
+
run += it.ch;
|
|
646
|
+
continue;
|
|
647
|
+
}
|
|
648
|
+
flush();
|
|
649
|
+
out.push(it.t === "ext" ? {
|
|
650
|
+
...it,
|
|
651
|
+
alts: it.alts.map((a) => normalize(a, form))
|
|
652
|
+
} : it);
|
|
653
|
+
}
|
|
654
|
+
flush();
|
|
655
|
+
return out;
|
|
656
|
+
};
|
|
657
|
+
const compile$1 = (items, nocase) => {
|
|
658
|
+
let id = 1;
|
|
659
|
+
const split = (out) => ({
|
|
660
|
+
t: "split",
|
|
661
|
+
id: id++,
|
|
662
|
+
out
|
|
663
|
+
});
|
|
664
|
+
const seq = (items, next) => items.reduceRight((next, it) => item(it, next), next);
|
|
665
|
+
const item = (it, next) => {
|
|
666
|
+
switch (it.t) {
|
|
667
|
+
case "lit":
|
|
668
|
+
const re = nocase ? foldRe(it.ch) : void 0;
|
|
669
|
+
return {
|
|
670
|
+
t: "lit",
|
|
671
|
+
id: id++,
|
|
672
|
+
ch: it.ch,
|
|
673
|
+
re,
|
|
674
|
+
next
|
|
675
|
+
};
|
|
676
|
+
case "any":
|
|
677
|
+
case "star": return {
|
|
678
|
+
t: it.t,
|
|
679
|
+
id: id++,
|
|
680
|
+
next
|
|
681
|
+
};
|
|
682
|
+
case "class": return {
|
|
683
|
+
t: "class",
|
|
684
|
+
id: id++,
|
|
685
|
+
re: it.re,
|
|
686
|
+
next
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
const alts = (next) => it.alts.map((a) => seq(a, next));
|
|
690
|
+
switch (it.type) {
|
|
691
|
+
case "@": return split(alts(next));
|
|
692
|
+
case "?": return split([next, ...alts(next)]);
|
|
693
|
+
case "!": return {
|
|
694
|
+
t: "neg",
|
|
695
|
+
id: id++,
|
|
696
|
+
sub: split(alts(MATCH)),
|
|
697
|
+
next
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
const after = split([]);
|
|
701
|
+
const entry = split(alts(after));
|
|
702
|
+
after.out.push(next, entry);
|
|
703
|
+
return it.type === "*" ? after : entry;
|
|
704
|
+
};
|
|
705
|
+
return [seq(items, MATCH), id];
|
|
706
|
+
};
|
|
707
|
+
const show = (start) => {
|
|
708
|
+
const lines = [];
|
|
709
|
+
const seen = /* @__PURE__ */ new Set();
|
|
710
|
+
const ref = (n) => n.t === "match" ? "match" : String(n.id);
|
|
711
|
+
const walk = (n, indent) => {
|
|
712
|
+
if (n.t === "match" || seen.has(n)) return;
|
|
713
|
+
seen.add(n);
|
|
714
|
+
const line = (desc) => lines.push(`${indent}${n.id}: ${desc}`);
|
|
715
|
+
switch (n.t) {
|
|
716
|
+
case "split":
|
|
717
|
+
line(`split -> ${n.out.map(ref).join(", ")}`);
|
|
718
|
+
for (const o of n.out) walk(o, indent);
|
|
719
|
+
return;
|
|
720
|
+
case "neg":
|
|
721
|
+
line(`!(${ref(n.sub)}) -> ${ref(n.next)}`);
|
|
722
|
+
walk(n.sub, indent + " ");
|
|
723
|
+
return walk(n.next, indent);
|
|
724
|
+
case "lit":
|
|
725
|
+
line(`${JSON.stringify(n.ch)} -> ${ref(n.next)}`);
|
|
726
|
+
break;
|
|
727
|
+
case "class":
|
|
728
|
+
line(`${n.re} -> ${ref(n.next)}`);
|
|
729
|
+
break;
|
|
730
|
+
default: line(`${n.t === "any" ? "?" : "*"} -> ${ref(n.next)}`);
|
|
731
|
+
}
|
|
732
|
+
walk(n.next, indent);
|
|
733
|
+
};
|
|
734
|
+
walk(start, "");
|
|
735
|
+
return [`start -> ${ref(start)}`, ...lines].join("\n");
|
|
736
|
+
};
|
|
737
|
+
var State = class {
|
|
738
|
+
gen;
|
|
739
|
+
threads = [];
|
|
740
|
+
match = false;
|
|
741
|
+
runs = [];
|
|
742
|
+
ids = [];
|
|
743
|
+
constructor(gen) {
|
|
744
|
+
this.gen = gen;
|
|
745
|
+
}
|
|
746
|
+
get dead() {
|
|
747
|
+
return !this.threads.length && !this.match && !this.runs.length;
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
const sameState = (a, b) => {
|
|
751
|
+
if (a.ids.length !== b.ids.length) return false;
|
|
752
|
+
if (a.runs.length !== b.runs.length) return false;
|
|
753
|
+
if (a.ids.some((id, i) => id !== b.ids[i])) return false;
|
|
754
|
+
return a.runs.every((r) => b.runs.some((o) => o.neg === r.neg && sameState(o.state, r.state)));
|
|
755
|
+
};
|
|
756
|
+
const marks = (size) => ({
|
|
757
|
+
has: new Float64Array(size),
|
|
758
|
+
seen: new Float64Array(size),
|
|
759
|
+
gen: 0
|
|
760
|
+
});
|
|
761
|
+
var Sim = class {
|
|
762
|
+
dots;
|
|
763
|
+
dotStart;
|
|
764
|
+
#marks;
|
|
765
|
+
constructor(dots, dotStart, marks) {
|
|
766
|
+
this.dots = dots;
|
|
767
|
+
this.dotStart = dotStart;
|
|
768
|
+
this.#marks = marks;
|
|
769
|
+
}
|
|
770
|
+
state() {
|
|
771
|
+
return new State(++this.#marks.gen);
|
|
772
|
+
}
|
|
773
|
+
done(state) {
|
|
774
|
+
state.ids = state.threads.map((n) => n.id).sort((a, b) => a - b);
|
|
775
|
+
if (state.match) state.ids.unshift(MATCH.id);
|
|
776
|
+
return state;
|
|
777
|
+
}
|
|
778
|
+
#visit(state, node) {
|
|
779
|
+
const { seen } = this.#marks;
|
|
780
|
+
if (seen[node.id] === state.gen) return false;
|
|
781
|
+
seen[node.id] = state.gen;
|
|
782
|
+
return true;
|
|
783
|
+
}
|
|
784
|
+
#addThread(state, node) {
|
|
785
|
+
const { has } = this.#marks;
|
|
786
|
+
if (has[node.id] === state.gen) return false;
|
|
787
|
+
has[node.id] = state.gen;
|
|
788
|
+
state.threads.push(node);
|
|
789
|
+
return true;
|
|
790
|
+
}
|
|
791
|
+
restricted(i, top) {
|
|
792
|
+
return top && (this.dots || this.dotStart && i === 0);
|
|
793
|
+
}
|
|
794
|
+
add(state, node, i, top) {
|
|
795
|
+
switch (node.t) {
|
|
796
|
+
case "split":
|
|
797
|
+
if (!this.#visit(state, node)) return;
|
|
798
|
+
for (const o of node.out) this.add(state, o, i, top);
|
|
799
|
+
return;
|
|
800
|
+
case "neg":
|
|
801
|
+
if (!this.#visit(state, node)) return;
|
|
802
|
+
const sub = this.state();
|
|
803
|
+
this.add(sub, node.sub, i, false);
|
|
804
|
+
this.done(sub);
|
|
805
|
+
return this.addRun(state, {
|
|
806
|
+
t: "run",
|
|
807
|
+
neg: node,
|
|
808
|
+
state: sub
|
|
809
|
+
}, i, top);
|
|
810
|
+
case "star":
|
|
811
|
+
if (this.restricted(i, top)) return;
|
|
812
|
+
if (this.#addThread(state, node)) this.add(state, node.next, i, top);
|
|
813
|
+
return;
|
|
814
|
+
case "match":
|
|
815
|
+
state.match = true;
|
|
816
|
+
return;
|
|
817
|
+
default: this.#addThread(state, node);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
addRun(state, run, i, top) {
|
|
821
|
+
for (const r of state.runs) if (r.neg === run.neg && sameState(r.state, run.state)) return;
|
|
822
|
+
state.runs.push(run);
|
|
823
|
+
if (!run.state.match) this.add(state, run.neg.next, i, top);
|
|
824
|
+
}
|
|
825
|
+
step(state, c, i, top) {
|
|
826
|
+
const next = this.state();
|
|
827
|
+
for (const th of state.threads) switch (th.t) {
|
|
828
|
+
case "lit":
|
|
829
|
+
if (litMatch(th, c)) this.add(next, th.next, i + 1, top);
|
|
830
|
+
break;
|
|
831
|
+
case "any":
|
|
832
|
+
if (!this.restricted(i, top)) this.add(next, th.next, i + 1, top);
|
|
833
|
+
break;
|
|
834
|
+
case "class":
|
|
835
|
+
if (!this.restricted(i, top) && th.re.test(c)) this.add(next, th.next, i + 1, top);
|
|
836
|
+
break;
|
|
837
|
+
case "star": if (!this.restricted(i, top)) this.add(next, th, i + 1, top);
|
|
838
|
+
}
|
|
839
|
+
if (!this.restricted(i, top)) for (const run of state.runs) {
|
|
840
|
+
if (run.state.dead) {
|
|
841
|
+
this.addRun(next, run, i + 1, top);
|
|
842
|
+
continue;
|
|
843
|
+
}
|
|
844
|
+
const sub = this.step(run.state, c, i, false);
|
|
845
|
+
this.addRun(next, {
|
|
846
|
+
t: "run",
|
|
847
|
+
neg: run.neg,
|
|
848
|
+
state: sub
|
|
849
|
+
}, i + 1, top);
|
|
850
|
+
}
|
|
851
|
+
return this.done(next);
|
|
852
|
+
}
|
|
853
|
+
};
|
|
854
|
+
const stateKey = (state) => {
|
|
855
|
+
const ids = state.ids.join();
|
|
856
|
+
if (!state.runs.length) return ids;
|
|
857
|
+
return `${ids}|${state.runs.map((r) => `${r.neg.id}(${stateKey(r.state)})`).sort().join("|")}`;
|
|
858
|
+
};
|
|
859
|
+
const DFA_BUDGET = 1 << 18;
|
|
860
|
+
var Dfa = class {
|
|
861
|
+
#start;
|
|
862
|
+
#states = /* @__PURE__ */ new Map();
|
|
863
|
+
#size = 0;
|
|
864
|
+
#plain;
|
|
865
|
+
#dotStart;
|
|
866
|
+
#sim;
|
|
867
|
+
#dotSim;
|
|
868
|
+
constructor(start, marks) {
|
|
869
|
+
this.#start = start;
|
|
870
|
+
this.#sim = new Sim(false, false, marks);
|
|
871
|
+
this.#dotSim = new Sim(false, true, marks);
|
|
872
|
+
}
|
|
873
|
+
#make(state) {
|
|
874
|
+
return {
|
|
875
|
+
state,
|
|
876
|
+
match: state.match,
|
|
877
|
+
dead: state.dead,
|
|
878
|
+
next: /* @__PURE__ */ new Map()
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
#intern(state) {
|
|
882
|
+
const key = stateKey(state);
|
|
883
|
+
const found = this.#states.get(key);
|
|
884
|
+
if (found) return found;
|
|
885
|
+
if (this.#size > DFA_BUDGET) this.#clear();
|
|
886
|
+
const d = this.#make(state);
|
|
887
|
+
this.#states.set(key, d);
|
|
888
|
+
this.#size += key.length + 1;
|
|
889
|
+
return d;
|
|
890
|
+
}
|
|
891
|
+
#clear() {
|
|
892
|
+
this.#states.clear();
|
|
893
|
+
this.#size = 0;
|
|
894
|
+
this.#plain = void 0;
|
|
895
|
+
this.#dotStart = void 0;
|
|
896
|
+
}
|
|
897
|
+
start(dotStart) {
|
|
898
|
+
if (dotStart) {
|
|
899
|
+
if (this.#dotStart) return this.#dotStart;
|
|
900
|
+
const state = this.#dotSim.state();
|
|
901
|
+
this.#dotSim.add(state, this.#start, 0, true);
|
|
902
|
+
return this.#dotStart = this.#make(this.#dotSim.done(state));
|
|
903
|
+
}
|
|
904
|
+
if (this.#plain) return this.#plain;
|
|
905
|
+
const state = this.#sim.state();
|
|
906
|
+
this.#sim.add(state, this.#start, 0, true);
|
|
907
|
+
return this.#plain = this.#intern(this.#sim.done(state));
|
|
908
|
+
}
|
|
909
|
+
next(d, c) {
|
|
910
|
+
const code = c.charCodeAt(0);
|
|
911
|
+
const found = code < 128 ? void 0 : d.next.get(c);
|
|
912
|
+
if (found) return found;
|
|
913
|
+
const n = d === this.#dotStart ? this.#intern(this.#dotSim.step(d.state, c, 0, true)) : this.#intern(this.#sim.step(d.state, c, 1, true));
|
|
914
|
+
if (code < 128) {
|
|
915
|
+
if (!d.ascii) {
|
|
916
|
+
d.ascii = new Array(128);
|
|
917
|
+
this.#size += 128;
|
|
918
|
+
}
|
|
919
|
+
d.ascii[code] = n;
|
|
920
|
+
} else d.next.set(c, n);
|
|
921
|
+
this.#size++;
|
|
922
|
+
return n;
|
|
923
|
+
}
|
|
924
|
+
};
|
|
925
|
+
const linear = (start) => {
|
|
926
|
+
const nodes = [];
|
|
927
|
+
for (let n = start; n.t !== "match"; n = n.next) {
|
|
928
|
+
if (n.t === "split" || n.t === "neg") return void 0;
|
|
929
|
+
nodes.push(n);
|
|
930
|
+
}
|
|
931
|
+
return nodes;
|
|
932
|
+
};
|
|
933
|
+
const testLinear = (nodes, chars, start, end) => {
|
|
934
|
+
let ni = 0;
|
|
935
|
+
let ci = start;
|
|
936
|
+
let starNi = -1;
|
|
937
|
+
let starCi = 0;
|
|
938
|
+
while (ci < end) {
|
|
939
|
+
const n = nodes[ni];
|
|
940
|
+
if (n?.t === "star") {
|
|
941
|
+
starNi = ni++;
|
|
942
|
+
starCi = ci;
|
|
943
|
+
continue;
|
|
944
|
+
}
|
|
945
|
+
const c = chars[ci];
|
|
946
|
+
if (n && (n.t === "any" || n.t === "lit" && litMatch(n, c) || n.t === "class" && n.re.test(c))) {
|
|
947
|
+
ni++;
|
|
948
|
+
ci++;
|
|
949
|
+
continue;
|
|
950
|
+
}
|
|
951
|
+
if (starNi === -1) return false;
|
|
952
|
+
ni = starNi + 1;
|
|
953
|
+
ci = ++starCi;
|
|
954
|
+
}
|
|
955
|
+
while (nodes[ni]?.t === "star") ni++;
|
|
956
|
+
return ni === nodes.length;
|
|
957
|
+
};
|
|
958
|
+
const lengths = (items) => {
|
|
959
|
+
let min = 0;
|
|
960
|
+
let max = 0;
|
|
961
|
+
for (const it of items) {
|
|
962
|
+
const [lo, hi] = itemLengths(it);
|
|
963
|
+
min += lo;
|
|
964
|
+
max += hi;
|
|
965
|
+
}
|
|
966
|
+
return [min, max];
|
|
967
|
+
};
|
|
968
|
+
const itemLengths = (it) => {
|
|
969
|
+
if (it.t === "star") return [0, Infinity];
|
|
970
|
+
if (it.t !== "ext") return [1, 1];
|
|
971
|
+
if (it.type === "!") return [0, Infinity];
|
|
972
|
+
const alts = it.alts.map(lengths);
|
|
973
|
+
const min = Math.min(...alts.map((a) => a[0]));
|
|
974
|
+
const max = Math.max(...alts.map((a) => a[1]));
|
|
975
|
+
const loop = max === 0 ? 0 : Infinity;
|
|
976
|
+
return it.type === "@" ? [min, max] : it.type === "?" ? [0, max] : it.type === "*" ? [0, loop] : [min, loop];
|
|
977
|
+
};
|
|
978
|
+
const hasAffix = (lits, chars, start) => {
|
|
979
|
+
for (let j = 0; j < lits.length; j++) if (!litMatch(lits[j], chars[start + j])) return false;
|
|
980
|
+
return true;
|
|
981
|
+
};
|
|
982
|
+
const slashOrSurrogate = /[/\ud800-\udfff]/;
|
|
983
|
+
const surrogate = /[\ud800-\udfff]/;
|
|
984
|
+
const codePoints = (s) => surrogate.test(s) ? [...s] : s;
|
|
985
|
+
const noSlash = (s) => {
|
|
986
|
+
if (s.includes("/")) throw new Error("can only match a single path portion, got: " + s);
|
|
987
|
+
};
|
|
988
|
+
var Matcher = class {
|
|
989
|
+
pattern;
|
|
990
|
+
options;
|
|
991
|
+
#start;
|
|
992
|
+
#size;
|
|
993
|
+
#marks;
|
|
994
|
+
#dotsSim;
|
|
995
|
+
#literal;
|
|
996
|
+
#literalFold = false;
|
|
997
|
+
#literalRe;
|
|
998
|
+
#linear;
|
|
999
|
+
#wild = false;
|
|
1000
|
+
#min = 0;
|
|
1001
|
+
#max = Infinity;
|
|
1002
|
+
#prefix = [];
|
|
1003
|
+
#suffix = [];
|
|
1004
|
+
#prefixStr;
|
|
1005
|
+
#suffixStr;
|
|
1006
|
+
#affix = false;
|
|
1007
|
+
#dfa;
|
|
1008
|
+
#form;
|
|
1009
|
+
constructor(pattern, options = {}) {
|
|
1010
|
+
if (pattern.includes("/")) throw new Error("can only match a single path portion, got pattern: " + pattern);
|
|
1011
|
+
this.pattern = pattern;
|
|
1012
|
+
this.options = options;
|
|
1013
|
+
const { nocase = false, noext = false, normalize: n } = options;
|
|
1014
|
+
this.#form = n === true ? "NFC" : n || void 0;
|
|
1015
|
+
const literal = /^[?*+@]\(\)$/.test(pattern);
|
|
1016
|
+
const toks = tokenize(pattern, nocase, noext || literal, this.#form, options.rangeMark);
|
|
1017
|
+
let [items] = build(toks, pair(toks), 0, toks.length, true);
|
|
1018
|
+
if (this.#form) items = normalize(items, this.#form);
|
|
1019
|
+
const [start, size] = compile$1(items, nocase);
|
|
1020
|
+
this.#start = start;
|
|
1021
|
+
this.#size = size;
|
|
1022
|
+
if (items.every((it) => it.t === "lit")) {
|
|
1023
|
+
this.#literal = items.map((it) => it.ch).join("");
|
|
1024
|
+
this.#literalFold = nocase;
|
|
1025
|
+
} else {
|
|
1026
|
+
const lit = (it) => it.t !== "lit" ? void 0 : nocase ? {
|
|
1027
|
+
ch: it.ch,
|
|
1028
|
+
re: foldRe(it.ch)
|
|
1029
|
+
} : { ch: it.ch };
|
|
1030
|
+
for (const it of items) {
|
|
1031
|
+
const l = lit(it);
|
|
1032
|
+
if (!l) break;
|
|
1033
|
+
this.#prefix.push(l);
|
|
1034
|
+
}
|
|
1035
|
+
for (let j = items.length - 1; j >= 0; j--) {
|
|
1036
|
+
const l = lit(items[j]);
|
|
1037
|
+
if (!l) break;
|
|
1038
|
+
this.#suffix.unshift(l);
|
|
1039
|
+
}
|
|
1040
|
+
this.#affix = !!(this.#prefix.length || this.#suffix.length);
|
|
1041
|
+
if (!nocase) {
|
|
1042
|
+
this.#prefixStr = this.#prefix.map((l) => l.ch).join("");
|
|
1043
|
+
this.#suffixStr = this.#suffix.map((l) => l.ch).join("");
|
|
1044
|
+
}
|
|
1045
|
+
this.#linear = linear(this.#start)?.slice(this.#prefix.length, -this.#suffix.length || void 0);
|
|
1046
|
+
this.#wild = !!this.#linear?.every((n) => n.t === "star" || n.t === "any");
|
|
1047
|
+
const [min, max] = lengths(items);
|
|
1048
|
+
this.#min = min;
|
|
1049
|
+
this.#max = max;
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
test(s) {
|
|
1053
|
+
if (this.#form) {
|
|
1054
|
+
noSlash(s);
|
|
1055
|
+
return this.#test(s.normalize(this.#form));
|
|
1056
|
+
}
|
|
1057
|
+
if (slashOrSurrogate.test(s)) {
|
|
1058
|
+
noSlash(s);
|
|
1059
|
+
return this.#test(s, [...s]);
|
|
1060
|
+
}
|
|
1061
|
+
return this.#test(s, s);
|
|
1062
|
+
}
|
|
1063
|
+
/**
|
|
1064
|
+
* The same as {@link Matcher#test}, but the string is not checked
|
|
1065
|
+
* for `/` chars, so the result for a string that has one is not
|
|
1066
|
+
* defined. Only use it for a string that is known to be one path
|
|
1067
|
+
* portion, such as a part of a path that was split on `/`. It can
|
|
1068
|
+
* be faster, because some patterns do not need to look at each char
|
|
1069
|
+
* of the string.
|
|
1070
|
+
*/
|
|
1071
|
+
testUnchecked(s) {
|
|
1072
|
+
return this.#test(this.#form ? s.normalize(this.#form) : s);
|
|
1073
|
+
}
|
|
1074
|
+
#test(s, chars) {
|
|
1075
|
+
if (this.#literal !== void 0) return this.#literalFold ? (this.#literalRe ??= newFoldRe(this.#literal)).test(s) : s === this.#literal;
|
|
1076
|
+
const min = this.#min;
|
|
1077
|
+
const max = this.#max;
|
|
1078
|
+
if (chars === void 0) {
|
|
1079
|
+
const most = s.length;
|
|
1080
|
+
const least = most + 1 >> 1;
|
|
1081
|
+
if (most < min || least > max) return false;
|
|
1082
|
+
if (least < min || most > max) chars = codePoints(s);
|
|
1083
|
+
}
|
|
1084
|
+
if (chars !== void 0 && (chars.length < min || chars.length > max)) return false;
|
|
1085
|
+
const prefix = this.#prefix.length;
|
|
1086
|
+
if (this.#affix) {
|
|
1087
|
+
if (this.#prefixStr !== void 0 && this.#suffixStr !== void 0) {
|
|
1088
|
+
if (!s.startsWith(this.#prefixStr) || !s.endsWith(this.#suffixStr)) return false;
|
|
1089
|
+
} else {
|
|
1090
|
+
chars ??= codePoints(s);
|
|
1091
|
+
const end = chars.length - this.#suffix.length;
|
|
1092
|
+
if (!hasAffix(this.#prefix, chars, 0) || !hasAffix(this.#suffix, chars, end)) return false;
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
const dotStart = !this.options.dot && s.startsWith(".");
|
|
1096
|
+
if (this.#linear) {
|
|
1097
|
+
if (s === "." || s === "..") return false;
|
|
1098
|
+
if (dotStart && !prefix) return false;
|
|
1099
|
+
if (this.#wild) return true;
|
|
1100
|
+
chars ??= codePoints(s);
|
|
1101
|
+
const end = chars.length - this.#suffix.length;
|
|
1102
|
+
return testLinear(this.#linear, chars, prefix, end);
|
|
1103
|
+
}
|
|
1104
|
+
chars ??= codePoints(s);
|
|
1105
|
+
if (s === "." || s === "..") {
|
|
1106
|
+
this.#marks ??= marks(this.#size);
|
|
1107
|
+
const sim = this.#dotsSim ??= new Sim(true, false, this.#marks);
|
|
1108
|
+
const start = sim.state();
|
|
1109
|
+
sim.add(start, this.#start, 0, true);
|
|
1110
|
+
let state = sim.done(start);
|
|
1111
|
+
for (let i = 0; i < chars.length; i++) state = sim.step(state, chars[i], i, true);
|
|
1112
|
+
return state.match;
|
|
1113
|
+
}
|
|
1114
|
+
this.#marks ??= marks(this.#size);
|
|
1115
|
+
const dfa = this.#dfa ??= new Dfa(this.#start, this.#marks);
|
|
1116
|
+
let d = dfa.start(dotStart);
|
|
1117
|
+
const str = chars === s;
|
|
1118
|
+
for (let i = 0; i < chars.length; i++) {
|
|
1119
|
+
if (d.dead) return false;
|
|
1120
|
+
const code = str ? s.charCodeAt(i) : chars[i].charCodeAt(0);
|
|
1121
|
+
d = d.ascii?.[code] ?? dfa.next(d, chars[i]);
|
|
1122
|
+
}
|
|
1123
|
+
return d.match;
|
|
1124
|
+
}
|
|
1125
|
+
/** a readable listing of the state machine */
|
|
1126
|
+
toString() {
|
|
1127
|
+
return show(this.#start);
|
|
1128
|
+
}
|
|
1129
|
+
};
|
|
1130
|
+
// ../../node_modules/.pnpm/minimatch@11.0.9/node_modules/minimatch/dist/esm/assert-valid-pattern.js
|
|
1131
|
+
const MAX_PATTERN_LENGTH = 65536;
|
|
1132
|
+
const assertValidPattern = (pattern) => {
|
|
1133
|
+
if (typeof pattern !== "string") throw new TypeError("invalid pattern");
|
|
1134
|
+
if (pattern.length > MAX_PATTERN_LENGTH) throw new TypeError("pattern is too long");
|
|
1135
|
+
};
|
|
1136
|
+
// ../../node_modules/.pnpm/minimatch@11.0.9/node_modules/minimatch/dist/esm/escape.js
|
|
1137
|
+
/**
|
|
1138
|
+
* Escape all magic characters in a glob pattern.
|
|
1139
|
+
*
|
|
1140
|
+
* If the {@link MinimatchOptions.windowsPathsNoEscape}
|
|
1141
|
+
* option is used, then characters are escaped by wrapping in `[]`, because
|
|
1142
|
+
* a magic character wrapped in a character class can only be satisfied by
|
|
1143
|
+
* that exact character. In this mode, `\` is _not_ escaped, because it is
|
|
1144
|
+
* not interpreted as a magic character, but instead as a path separator.
|
|
1145
|
+
*
|
|
1146
|
+
* If the {@link MinimatchOptions.magicalBraces} option is used,
|
|
1147
|
+
* then braces (`{` and `}`) will be escaped.
|
|
1148
|
+
*
|
|
1149
|
+
* A leading `#` or `!` is escaped as well, so that the result is never a
|
|
1150
|
+
* comment or a negated pattern. In `windowsPathsNoEscape` mode, a leading
|
|
1151
|
+
* `!` is written as `@(!)`, because `[!` starts a negated class.
|
|
1152
|
+
*/
|
|
1153
|
+
const escape = (s, { windowsPathsNoEscape = false, magicalBraces = false } = {}) => {
|
|
1154
|
+
const e = magicalBraces ? windowsPathsNoEscape ? s.replace(/[?*()[\]{}]/g, "[$&]") : s.replace(/[?*()[\]\\{}]/g, "\\$&") : windowsPathsNoEscape ? s.replace(/[?*()[\]]/g, "[$&]") : s.replace(/[?*()[\]\\]/g, "\\$&");
|
|
1155
|
+
const c = e.charAt(0);
|
|
1156
|
+
if (c === "#") return (windowsPathsNoEscape ? "[#]" : "\\#") + e.slice(1);
|
|
1157
|
+
if (c === "!") return (windowsPathsNoEscape ? "@(!)" : "\\!") + e.slice(1);
|
|
1158
|
+
return e;
|
|
1159
|
+
};
|
|
1160
|
+
// ../../node_modules/.pnpm/minimatch@11.0.9/node_modules/minimatch/dist/esm/unescape.js
|
|
1161
|
+
/**
|
|
1162
|
+
* Un-escape a string that has been escaped with {@link escape}.
|
|
1163
|
+
*
|
|
1164
|
+
* If the {@link MinimatchOptions.windowsPathsNoEscape} option is used, then
|
|
1165
|
+
* square-bracket escapes are removed, but not backslash escapes.
|
|
1166
|
+
*
|
|
1167
|
+
* For example, it will turn the string `'[*]'` into `*`, but it will not
|
|
1168
|
+
* turn `'\\*'` into `'*'`, because `\` is a path separator in
|
|
1169
|
+
* `windowsPathsNoEscape` mode.
|
|
1170
|
+
*
|
|
1171
|
+
* When `windowsPathsNoEscape` is not set, then both square-bracket escapes and
|
|
1172
|
+
* backslash escapes are removed.
|
|
1173
|
+
*
|
|
1174
|
+
* Slashes (and backslashes in `windowsPathsNoEscape` mode) cannot be escaped
|
|
1175
|
+
* or unescaped.
|
|
1176
|
+
*
|
|
1177
|
+
* When `magicalBraces` is not set, escapes of braces (`{` and `}`) will not be
|
|
1178
|
+
* unescaped.
|
|
1179
|
+
*/
|
|
1180
|
+
const unescape = (s, { windowsPathsNoEscape = false, magicalBraces = true } = {}) => {
|
|
1181
|
+
if (windowsPathsNoEscape && s.startsWith("@(!)")) return "!" + unescape(s.slice(4), {
|
|
1182
|
+
windowsPathsNoEscape,
|
|
1183
|
+
magicalBraces
|
|
1184
|
+
});
|
|
1185
|
+
if (magicalBraces) return windowsPathsNoEscape ? s.replace(/\[([^/\\])\]/g, "$1") : s.replace(/((?!\\).|^)\[([^/\\])\]/g, "$1$2").replace(/\\([^/])/g, "$1");
|
|
1186
|
+
return windowsPathsNoEscape ? s.replace(/\[([^/\\{}])\]/g, "$1") : s.replace(/((?!\\).|^)\[([^/\\{}])\]/g, "$1$2").replace(/\\([^/{}])/g, "$1");
|
|
1187
|
+
};
|
|
1188
|
+
// ../../node_modules/.pnpm/minimatch@11.0.9/node_modules/minimatch/dist/esm/index.js
|
|
1189
|
+
const DEFAULT_BRACE_EXPAND_MAX = 1e5;
|
|
1190
|
+
const DEFAULT_GLOB_STAR_RECURSION_MAX = 200;
|
|
1191
|
+
const AWE_KEY = "allowWindowsEscape";
|
|
1192
|
+
const minimatch = (p, pattern, options) => {
|
|
1193
|
+
assertValidPattern(pattern);
|
|
1194
|
+
if (!options?.nocomment && pattern.charAt(0) === "#") return false;
|
|
1195
|
+
return cachedMinimatch(pattern, options).match(p);
|
|
1196
|
+
};
|
|
1197
|
+
let cache = /* @__PURE__ */ new Map();
|
|
1198
|
+
let oldCache = /* @__PURE__ */ new Map();
|
|
1199
|
+
let cacheSize = 0;
|
|
1200
|
+
let cacheTotalWeight = 0;
|
|
1201
|
+
const cacheMax = 256;
|
|
1202
|
+
const cacheMaxWeight = 32768;
|
|
1203
|
+
const cacheMaxEntryWeight = 4096;
|
|
1204
|
+
const cacheWeight = (mm) => {
|
|
1205
|
+
let w = mm.pattern.length;
|
|
1206
|
+
for (const s of mm.globSet) {
|
|
1207
|
+
w += s.length + 1;
|
|
1208
|
+
if (w > cacheMaxEntryWeight) break;
|
|
1209
|
+
}
|
|
1210
|
+
return w;
|
|
1211
|
+
};
|
|
1212
|
+
const tri = (v) => v === void 0 ? 0 : v ? 2 : 1;
|
|
1213
|
+
const booleanWeights = new Map(Object.keys({
|
|
1214
|
+
nobrace: 0,
|
|
1215
|
+
nocomment: 0,
|
|
1216
|
+
nonegate: 0,
|
|
1217
|
+
noglobstar: 0,
|
|
1218
|
+
noext: 0,
|
|
1219
|
+
nonull: 0,
|
|
1220
|
+
partial: 0,
|
|
1221
|
+
dot: 0,
|
|
1222
|
+
nocase: 0,
|
|
1223
|
+
nocaseMagicOnly: 0,
|
|
1224
|
+
magicalBraces: 0,
|
|
1225
|
+
matchBase: 0,
|
|
1226
|
+
flipNegate: 0,
|
|
1227
|
+
preserveMultipleSlashes: 0,
|
|
1228
|
+
windowsNoMagicRoot: 0
|
|
1229
|
+
}).map((k, i) => [k, 24 * 3 ** i]));
|
|
1230
|
+
const optionsKey = (o) => {
|
|
1231
|
+
let n = 0;
|
|
1232
|
+
let wpe = false;
|
|
1233
|
+
for (const k in o) {
|
|
1234
|
+
const v = o[k];
|
|
1235
|
+
switch (k) {
|
|
1236
|
+
case "windowsPathsNoEscape":
|
|
1237
|
+
if (v) wpe = true;
|
|
1238
|
+
break;
|
|
1239
|
+
case AWE_KEY:
|
|
1240
|
+
if (v === false) wpe = true;
|
|
1241
|
+
break;
|
|
1242
|
+
case "platform": {
|
|
1243
|
+
const p = v || defaultPlatform;
|
|
1244
|
+
if (p === defaultPlatform) break;
|
|
1245
|
+
if (p === "darwin") n += 3;
|
|
1246
|
+
else if (p === "win32") n += 6;
|
|
1247
|
+
else if (p === "linux") n += 9;
|
|
1248
|
+
else return JSON.stringify(o);
|
|
1249
|
+
break;
|
|
1250
|
+
}
|
|
1251
|
+
case "optimizationLevel":
|
|
1252
|
+
if (v === void 0) break;
|
|
1253
|
+
n += v >= 2 ? 1 : v >= 1 ? 0 : 2;
|
|
1254
|
+
break;
|
|
1255
|
+
case "braceExpandMax":
|
|
1256
|
+
if (v !== void 0 && v !== DEFAULT_BRACE_EXPAND_MAX) return JSON.stringify(o);
|
|
1257
|
+
break;
|
|
1258
|
+
case "maxGlobstarRecursion":
|
|
1259
|
+
if (v !== void 0 && v !== DEFAULT_GLOB_STAR_RECURSION_MAX) return JSON.stringify(o);
|
|
1260
|
+
break;
|
|
1261
|
+
case "normalize":
|
|
1262
|
+
if (v !== void 0) return JSON.stringify(o);
|
|
1263
|
+
break;
|
|
1264
|
+
default: n += (booleanWeights.get(k) ?? 0) * tri(v);
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
return wpe ? n + 12 : n;
|
|
1268
|
+
};
|
|
1269
|
+
const copyOptions = (o) => {
|
|
1270
|
+
const copy = {};
|
|
1271
|
+
for (const k in o) copy[k] = o[k];
|
|
1272
|
+
return copy;
|
|
1273
|
+
};
|
|
1274
|
+
const cachedMinimatch = (pattern, options) => {
|
|
1275
|
+
const key = options ? optionsKey(options) : 0;
|
|
1276
|
+
let mm = cache.get(key)?.get(pattern);
|
|
1277
|
+
if (mm) return mm;
|
|
1278
|
+
mm = oldCache.get(key)?.get(pattern) ?? new Minimatch(pattern, copyOptions(options));
|
|
1279
|
+
const weight = cacheWeight(mm);
|
|
1280
|
+
if (weight > cacheMaxEntryWeight) return mm;
|
|
1281
|
+
if (cacheSize >= cacheMax || cacheTotalWeight + weight > cacheMaxWeight) {
|
|
1282
|
+
oldCache = cache;
|
|
1283
|
+
cache = /* @__PURE__ */ new Map();
|
|
1284
|
+
cacheSize = 0;
|
|
1285
|
+
cacheTotalWeight = 0;
|
|
1286
|
+
}
|
|
1287
|
+
let byPattern = cache.get(key);
|
|
1288
|
+
if (!byPattern) cache.set(key, byPattern = /* @__PURE__ */ new Map());
|
|
1289
|
+
byPattern.set(pattern, mm);
|
|
1290
|
+
cacheSize++;
|
|
1291
|
+
cacheTotalWeight += weight;
|
|
1292
|
+
return mm;
|
|
1293
|
+
};
|
|
1294
|
+
/* c8 ignore start */
|
|
1295
|
+
const defaultPlatform = typeof process === "object" && process ? process.env?.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix";
|
|
1296
|
+
const path = {
|
|
1297
|
+
win32: { sep: "\\" },
|
|
1298
|
+
posix: { sep: "/" }
|
|
1299
|
+
};
|
|
1300
|
+
minimatch.sep = defaultPlatform === "win32" ? path.win32.sep : path.posix.sep;
|
|
1301
|
+
const GLOBSTAR = Symbol("globstar **");
|
|
1302
|
+
minimatch.GLOBSTAR = GLOBSTAR;
|
|
1303
|
+
const filter = (pattern, options) => {
|
|
1304
|
+
let mm;
|
|
1305
|
+
return (p) => (mm ??= cachedMinimatch(pattern, options)).match(p);
|
|
1306
|
+
};
|
|
1307
|
+
minimatch.filter = filter;
|
|
1308
|
+
const ext = (a, b = {}) => Object.assign({}, a, b);
|
|
1309
|
+
const defaults = (def) => {
|
|
1310
|
+
if (!def || typeof def !== "object" || !Object.keys(def).length) return minimatch;
|
|
1311
|
+
const orig = minimatch;
|
|
1312
|
+
const m = (p, pattern, options = {}) => orig(p, pattern, ext(def, options));
|
|
1313
|
+
return Object.assign(m, {
|
|
1314
|
+
Minimatch: class Minimatch extends orig.Minimatch {
|
|
1315
|
+
constructor(pattern, options = {}) {
|
|
1316
|
+
super(pattern, ext(def, options));
|
|
1317
|
+
}
|
|
1318
|
+
static defaults(options) {
|
|
1319
|
+
return orig.defaults(ext(def, options)).Minimatch;
|
|
1320
|
+
}
|
|
1321
|
+
},
|
|
1322
|
+
unescape: (s, options = {}) => orig.unescape(s, ext(def, options)),
|
|
1323
|
+
escape: (s, options = {}) => orig.escape(s, ext(def, options)),
|
|
1324
|
+
filter: (pattern, options = {}) => orig.filter(pattern, ext(def, options)),
|
|
1325
|
+
defaults: (options) => orig.defaults(ext(def, options)),
|
|
1326
|
+
braceExpand: (pattern, options = {}) => orig.braceExpand(pattern, ext(def, options)),
|
|
1327
|
+
match: (list, pattern, options = {}) => orig.match(list, pattern, ext(def, options)),
|
|
1328
|
+
sep: orig.sep,
|
|
1329
|
+
GLOBSTAR
|
|
1330
|
+
});
|
|
1331
|
+
};
|
|
1332
|
+
minimatch.defaults = defaults;
|
|
1333
|
+
const braceExpand = (pattern, options = {}) => {
|
|
1334
|
+
assertValidPattern(pattern);
|
|
1335
|
+
if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) return [pattern];
|
|
1336
|
+
let p = pattern.replace(/\\\\/g, "\\\\\\\\");
|
|
1337
|
+
if (options.windowsPathsNoEscape || options[AWE_KEY] === false) p = p.replace(/\[([{}])\]/g, "[\\$1]");
|
|
1338
|
+
return expand(p, { max: options.braceExpandMax });
|
|
1339
|
+
};
|
|
1340
|
+
minimatch.braceExpand = braceExpand;
|
|
1341
|
+
const RANGE_MIN = 100;
|
|
1342
|
+
const rangeRe = /(?<![\\$])\{(-?\d+)\.\.(-?\d+)\}/g;
|
|
1343
|
+
const inRepeatOrNegExt = (portion, mark) => {
|
|
1344
|
+
const stack = [];
|
|
1345
|
+
for (let i = 0; i < portion.length; i++) {
|
|
1346
|
+
const c = portion.charAt(i);
|
|
1347
|
+
if (c === "\\") i++;
|
|
1348
|
+
else if (c === mark) {
|
|
1349
|
+
if (stack.some((t) => t !== "@" && t !== "?")) return true;
|
|
1350
|
+
} else if (portion.charAt(i + 1) === "(" && "!?+*@".includes(c)) {
|
|
1351
|
+
stack.push(c);
|
|
1352
|
+
i++;
|
|
1353
|
+
} else if (c === ")") stack.pop();
|
|
1354
|
+
}
|
|
1355
|
+
return false;
|
|
1356
|
+
};
|
|
1357
|
+
const match = (list, pattern, options = {}) => {
|
|
1358
|
+
const mm = new Minimatch(pattern, options);
|
|
1359
|
+
list = list.filter((f) => mm.match(f));
|
|
1360
|
+
if (mm.options.nonull && !list.length) list.push(pattern);
|
|
1361
|
+
return list;
|
|
1362
|
+
};
|
|
1363
|
+
minimatch.match = match;
|
|
1364
|
+
const globMagic = /[?*]|[+@!]\(.*?\)|\[|\]/;
|
|
1365
|
+
const classEnd = (pattern, start) => {
|
|
1366
|
+
let i = start + 1;
|
|
1367
|
+
if (pattern.charAt(i) === "!" || pattern.charAt(i) === "^") i++;
|
|
1368
|
+
let sawStart = false;
|
|
1369
|
+
for (; i < pattern.length; i++) {
|
|
1370
|
+
const c = pattern.charAt(i);
|
|
1371
|
+
if (c === "]" && sawStart) return i;
|
|
1372
|
+
sawStart = true;
|
|
1373
|
+
if (c === "\\") i++;
|
|
1374
|
+
}
|
|
1375
|
+
return -1;
|
|
1376
|
+
};
|
|
1377
|
+
const literal = (pattern, noext) => {
|
|
1378
|
+
if (!noext && (pattern === "+()" || pattern === "@()")) return pattern;
|
|
1379
|
+
let lit = "";
|
|
1380
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
1381
|
+
const c = pattern.charAt(i);
|
|
1382
|
+
if (c === "\\") lit += pattern.charAt(++i) || c;
|
|
1383
|
+
else if (c === "*" || c === "?") return;
|
|
1384
|
+
else if (c === "[") {
|
|
1385
|
+
const close = classEnd(pattern, i);
|
|
1386
|
+
if (close === -1) {
|
|
1387
|
+
lit += c;
|
|
1388
|
+
continue;
|
|
1389
|
+
}
|
|
1390
|
+
let body = pattern.slice(i + 1, close);
|
|
1391
|
+
if (body.startsWith("\\")) body = body.slice(1);
|
|
1392
|
+
if ([...body].length !== 1 || "!^".includes(pattern.charAt(i + 1))) return;
|
|
1393
|
+
lit += body;
|
|
1394
|
+
i = close;
|
|
1395
|
+
} else if (!noext && "+@!".includes(c) && pattern.charAt(i + 1) === "(" && pattern.includes(")", i + 2)) return;
|
|
1396
|
+
else lit += c;
|
|
1397
|
+
}
|
|
1398
|
+
return lit;
|
|
1399
|
+
};
|
|
1400
|
+
const MAX_EXTGLOBS = 256;
|
|
1401
|
+
const extglobCount = (pattern) => {
|
|
1402
|
+
let n = 0;
|
|
1403
|
+
for (let i = 0; i < pattern.length - 1; i++) {
|
|
1404
|
+
const c = pattern.charAt(i);
|
|
1405
|
+
if (c === "\\") i++;
|
|
1406
|
+
else if ("+@!?*".includes(c) && pattern.charAt(i + 1) === "(") {
|
|
1407
|
+
n++;
|
|
1408
|
+
i++;
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
return n;
|
|
1412
|
+
};
|
|
1413
|
+
const assertValidExtglobs = (pattern) => {
|
|
1414
|
+
if (extglobCount(pattern) > MAX_EXTGLOBS) throw new TypeError("pattern has too many extglobs");
|
|
1415
|
+
};
|
|
1416
|
+
const extSafe = (pattern) => {
|
|
1417
|
+
if (/^[?*+@]\(\)$/.test(pattern) || pattern.includes("[:")) return false;
|
|
1418
|
+
let depth = 0;
|
|
1419
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
1420
|
+
const c = pattern.charAt(i);
|
|
1421
|
+
if (c === "\\") {
|
|
1422
|
+
if (++i === pattern.length) return false;
|
|
1423
|
+
} else if (c === "[") {
|
|
1424
|
+
const close = classEnd(pattern, i);
|
|
1425
|
+
if (close !== -1) i = close;
|
|
1426
|
+
} else if ("+@!?*".includes(c) && pattern.charAt(i + 1) === "(") {
|
|
1427
|
+
depth++;
|
|
1428
|
+
i++;
|
|
1429
|
+
} else if (c === ")") {
|
|
1430
|
+
if (!depth--) return false;
|
|
1431
|
+
} else if (c === "|" && !depth) return false;
|
|
1432
|
+
}
|
|
1433
|
+
return !depth;
|
|
1434
|
+
};
|
|
1435
|
+
let lastSplit;
|
|
1436
|
+
let lastChecked;
|
|
1437
|
+
const portionMatch = (p, f) => typeof p === "string" ? f === p : f !== "" && p.testUnchecked(f);
|
|
1438
|
+
const endIndex = (p, last, lastStart, prev, prevStart) => portionMatch(p, last) ? lastStart : prev !== void 0 && portionMatch(p, prev) ? prevStart : -1;
|
|
1439
|
+
const isDots = (p) => p === "." || p === "..";
|
|
1440
|
+
const isDrive = (p) => typeof p === "string" && /^[a-z]:$/i.test(p);
|
|
1441
|
+
const isLongUNC = (p) => typeof p === "string" && /^unc$/i.test(p);
|
|
1442
|
+
const uncHost = (p) => {
|
|
1443
|
+
if (p[0] !== "" || p[1] !== "") return -1;
|
|
1444
|
+
const h = p[2] !== "?" ? 2 : isLongUNC(p[3]) ? 4 : -1;
|
|
1445
|
+
const host = p[h];
|
|
1446
|
+
const share = p[h + 1];
|
|
1447
|
+
return h !== -1 && host !== void 0 && host !== "" && host !== GLOBSTAR && share !== void 0 && share !== "" && share !== GLOBSTAR ? h : -1;
|
|
1448
|
+
};
|
|
1449
|
+
const walkable = (p, dot) => !isDots(p) && (dot || !p.startsWith("."));
|
|
1450
|
+
const dotPortion = (f, start, end, dot, sep) => {
|
|
1451
|
+
for (let k = start; k < end;) {
|
|
1452
|
+
if (f.charCodeAt(k) === 46) {
|
|
1453
|
+
if (!dot) return true;
|
|
1454
|
+
const n = f.charCodeAt(k + 1) === 46 ? k + 2 : k + 1;
|
|
1455
|
+
if (n >= end || isSep(f.charCodeAt(n), sep)) return true;
|
|
1456
|
+
}
|
|
1457
|
+
const s = nextSep(f, k, sep);
|
|
1458
|
+
if (s === -1) return false;
|
|
1459
|
+
k = s + 1;
|
|
1460
|
+
while (k < end && isSep(f.charCodeAt(k), sep)) k++;
|
|
1461
|
+
}
|
|
1462
|
+
return false;
|
|
1463
|
+
};
|
|
1464
|
+
const isSep = (c, sep) => sep === "/" ? c === 47 : sep === "\\" ? c === 92 : c === 47 || c === 92;
|
|
1465
|
+
const nextSep = (f, from, sep) => {
|
|
1466
|
+
if (sep !== "both") return f.indexOf(sep, from);
|
|
1467
|
+
const s = f.indexOf("/", from);
|
|
1468
|
+
const b = f.indexOf("\\", from);
|
|
1469
|
+
return s === -1 ? b : b === -1 ? s : Math.min(s, b);
|
|
1470
|
+
};
|
|
1471
|
+
const lastSep = (f, from, sep) => sep !== "both" ? f.lastIndexOf(sep, from) : Math.max(f.lastIndexOf("/", from), f.lastIndexOf("\\", from));
|
|
1472
|
+
const PENDING = {};
|
|
1473
|
+
var Minimatch = class {
|
|
1474
|
+
options;
|
|
1475
|
+
set;
|
|
1476
|
+
pattern;
|
|
1477
|
+
windowsPathsNoEscape;
|
|
1478
|
+
nonegate;
|
|
1479
|
+
negate;
|
|
1480
|
+
comment;
|
|
1481
|
+
empty;
|
|
1482
|
+
preserveMultipleSlashes;
|
|
1483
|
+
partial;
|
|
1484
|
+
globSet;
|
|
1485
|
+
globParts;
|
|
1486
|
+
nocase;
|
|
1487
|
+
isWindows;
|
|
1488
|
+
platform;
|
|
1489
|
+
windowsNoMagicRoot;
|
|
1490
|
+
maxGlobstarRecursion;
|
|
1491
|
+
#endCheck;
|
|
1492
|
+
#literalCheck;
|
|
1493
|
+
#level2;
|
|
1494
|
+
#form;
|
|
1495
|
+
#literals = [];
|
|
1496
|
+
#shapes = [];
|
|
1497
|
+
#endRows = [];
|
|
1498
|
+
#matchers = /* @__PURE__ */ new Map();
|
|
1499
|
+
#pending = false;
|
|
1500
|
+
#rangeMark;
|
|
1501
|
+
#globstarParts = /* @__PURE__ */ new WeakMap();
|
|
1502
|
+
constructor(pattern, options = {}) {
|
|
1503
|
+
assertValidPattern(pattern);
|
|
1504
|
+
options = options || {};
|
|
1505
|
+
this.options = options;
|
|
1506
|
+
this.maxGlobstarRecursion = options.maxGlobstarRecursion ?? DEFAULT_GLOB_STAR_RECURSION_MAX;
|
|
1507
|
+
this.pattern = pattern;
|
|
1508
|
+
this.platform = options.platform || defaultPlatform;
|
|
1509
|
+
this.isWindows = this.platform === "win32";
|
|
1510
|
+
this.windowsPathsNoEscape = !!options.windowsPathsNoEscape || options[AWE_KEY] === false;
|
|
1511
|
+
if (this.windowsPathsNoEscape) this.pattern = this.pattern.replace(/\\/g, "/");
|
|
1512
|
+
this.preserveMultipleSlashes = !!options.preserveMultipleSlashes;
|
|
1513
|
+
this.negate = false;
|
|
1514
|
+
this.nonegate = !!options.nonegate;
|
|
1515
|
+
this.comment = false;
|
|
1516
|
+
this.empty = false;
|
|
1517
|
+
this.partial = !!options.partial;
|
|
1518
|
+
this.nocase = !!this.options.nocase;
|
|
1519
|
+
this.windowsNoMagicRoot = options.windowsNoMagicRoot !== void 0 ? options.windowsNoMagicRoot : !!(this.isWindows && this.nocase);
|
|
1520
|
+
this.globSet = [];
|
|
1521
|
+
this.globParts = [];
|
|
1522
|
+
this.set = [];
|
|
1523
|
+
this.#endCheck = !this.preserveMultipleSlashes;
|
|
1524
|
+
this.#level2 = (options.optimizationLevel ?? 1) >= 2;
|
|
1525
|
+
const n = options.normalize;
|
|
1526
|
+
this.#form = n === true ? "NFC" : n || void 0;
|
|
1527
|
+
this.make();
|
|
1528
|
+
const drives = this.set.map((row) => this.#rootIndex(row));
|
|
1529
|
+
this.#endRows = this.set.map((row, r) => this.#endCheck && row.length - 1 > drives[r]);
|
|
1530
|
+
this.#literals = this.set.map((row, r) => {
|
|
1531
|
+
const end = this.#endRows[r] ? row.length - 1 : row.length;
|
|
1532
|
+
const lits = row.slice(drives[r] + 1, end).filter((p) => typeof p === "string" && !!p);
|
|
1533
|
+
return [...new Set(lits)];
|
|
1534
|
+
});
|
|
1535
|
+
this.#literalCheck = this.#literals.some((l) => l.length);
|
|
1536
|
+
this.#shapes = this.set.map((row, r) => {
|
|
1537
|
+
const [p0, p1, p2] = row;
|
|
1538
|
+
if (this.#endRows[r] && row.length === 2) {
|
|
1539
|
+
if (p0 === GLOBSTAR && p1 !== GLOBSTAR) return "tail";
|
|
1540
|
+
}
|
|
1541
|
+
if (this.#endRows[r] && options.matchBase && row.length === 1 && p0 !== GLOBSTAR && p0 !== "") return "base";
|
|
1542
|
+
if (!this.#endCheck || drives[r] !== -1) return void 0;
|
|
1543
|
+
if (row.length === 3 && p0 === GLOBSTAR && p2 === GLOBSTAR && p1 !== GLOBSTAR && p1 !== "" && this.maxGlobstarRecursion > 0) return "mid";
|
|
1544
|
+
if (row.length === 2 && p1 === GLOBSTAR && p0 !== GLOBSTAR && p0 !== "") return "head";
|
|
1545
|
+
});
|
|
1546
|
+
}
|
|
1547
|
+
#norm(p) {
|
|
1548
|
+
return this.#form ? p.normalize(this.#form) : p;
|
|
1549
|
+
}
|
|
1550
|
+
#rootIndex(row) {
|
|
1551
|
+
if (!this.isWindows) return -1;
|
|
1552
|
+
if (isDrive(row[0])) return 0;
|
|
1553
|
+
if (row[0] === "" && row[1] === "" && row[2] === "?" && isDrive(row[3])) return 3;
|
|
1554
|
+
const h = uncHost(row);
|
|
1555
|
+
return h === -1 ? -1 : h + 1;
|
|
1556
|
+
}
|
|
1557
|
+
hasMagic() {
|
|
1558
|
+
if (this.options.magicalBraces && this.set.length > 1) return true;
|
|
1559
|
+
for (const pattern of this.set) for (const part of pattern) if (typeof part !== "string") return true;
|
|
1560
|
+
return false;
|
|
1561
|
+
}
|
|
1562
|
+
make() {
|
|
1563
|
+
const pattern = this.pattern;
|
|
1564
|
+
const options = this.options;
|
|
1565
|
+
if (!options.nocomment && pattern.charAt(0) === "#") {
|
|
1566
|
+
this.comment = true;
|
|
1567
|
+
return;
|
|
1568
|
+
}
|
|
1569
|
+
if (!pattern) {
|
|
1570
|
+
this.empty = true;
|
|
1571
|
+
return;
|
|
1572
|
+
}
|
|
1573
|
+
this.parseNegate();
|
|
1574
|
+
this.globSet = [...new Set(this.#expandBraces())];
|
|
1575
|
+
const rawGlobParts = this.globSet.map((s) => this.#slashSplit(s));
|
|
1576
|
+
this.globParts = this.preprocess(rawGlobParts);
|
|
1577
|
+
this.#pending = true;
|
|
1578
|
+
let set = this.globParts.map((s, _, __) => {
|
|
1579
|
+
if (this.isWindows && this.windowsNoMagicRoot) {
|
|
1580
|
+
const n = s[2] === "?" && isLongUNC(s[3]) ? 6 : 4;
|
|
1581
|
+
const isUNC = s[0] === "" && s[1] === "" && (s[2] === "?" || !globMagic.test(s[2])) && s.slice(3, n).every((p) => !globMagic.test(p));
|
|
1582
|
+
const isDrive = /^[a-z]:/i.test(s[0]);
|
|
1583
|
+
if (isUNC) return [...s.slice(0, n).map((p) => this.#norm(p)), ...s.slice(n).map((ss) => this.parse(ss))];
|
|
1584
|
+
else if (isDrive) return [this.#norm(s[0]), ...s.slice(1).map((ss) => this.parse(ss))];
|
|
1585
|
+
}
|
|
1586
|
+
return s.map((ss) => this.parse(ss));
|
|
1587
|
+
});
|
|
1588
|
+
this.set = set.filter((s) => s.indexOf(false) === -1);
|
|
1589
|
+
if (this.isWindows) for (let i = 0; i < this.set.length; i++) {
|
|
1590
|
+
const p = this.set[i];
|
|
1591
|
+
if (p[0] === "" && p[1] === "" && this.globParts[i][2] === "?" && (isDrive(p[3]) || isLongUNC(this.globParts[i][3]))) {
|
|
1592
|
+
if (isLongUNC(this.globParts[i][3])) p[3] = "UNC";
|
|
1593
|
+
p[2] = "?";
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
if (!options.noext) this.mergeRows();
|
|
1597
|
+
this.#pending = false;
|
|
1598
|
+
this.set.forEach((row, i) => {
|
|
1599
|
+
for (let k = 0; k < row.length; k++) if (row[k] === PENDING) row[k] = this.parse(this.globParts[i][k]);
|
|
1600
|
+
});
|
|
1601
|
+
}
|
|
1602
|
+
mergeRows() {
|
|
1603
|
+
let merged = true;
|
|
1604
|
+
while (merged) {
|
|
1605
|
+
merged = false;
|
|
1606
|
+
if (this.set.length < 2) return;
|
|
1607
|
+
let keys = this.#mergeKeys();
|
|
1608
|
+
const len = Math.max(0, ...this.set.map((r) => r.length));
|
|
1609
|
+
for (let k = 0; k < len; k++) {
|
|
1610
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1611
|
+
const R = this.set.length + 1;
|
|
1612
|
+
this.set.forEach((row, i) => {
|
|
1613
|
+
if (!(row[k] instanceof Matcher || row[k] === PENDING) || !extSafe(this.globParts[i][k])) return;
|
|
1614
|
+
const { pre, suf } = keys[i];
|
|
1615
|
+
const key = pre[k] * R + suf[k + 1];
|
|
1616
|
+
const g = groups.get(key);
|
|
1617
|
+
if (g) g.push(i);
|
|
1618
|
+
else groups.set(key, [i]);
|
|
1619
|
+
});
|
|
1620
|
+
const drop = /* @__PURE__ */ new Set();
|
|
1621
|
+
for (const g of groups.values()) {
|
|
1622
|
+
if (g.length < 2) continue;
|
|
1623
|
+
const [first, ...rest] = g;
|
|
1624
|
+
const glob = `@(${g.map((i) => this.globParts[i][k]).join("|")})`;
|
|
1625
|
+
if (extglobCount(glob) > MAX_EXTGLOBS) continue;
|
|
1626
|
+
this.globParts[first][k] = glob;
|
|
1627
|
+
this.set[first][k] = this.parse(glob);
|
|
1628
|
+
for (const i of rest) drop.add(i);
|
|
1629
|
+
}
|
|
1630
|
+
if (drop.size) {
|
|
1631
|
+
merged = true;
|
|
1632
|
+
this.set = this.set.filter((_, i) => !drop.has(i));
|
|
1633
|
+
this.globParts = this.globParts.filter((_, i) => !drop.has(i));
|
|
1634
|
+
if (this.set.length < 2) return;
|
|
1635
|
+
keys = this.#mergeKeys();
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
#mergeKeys() {
|
|
1641
|
+
const partIds = /* @__PURE__ */ new Map();
|
|
1642
|
+
const ids = this.globParts.map((parts) => parts.map((s) => {
|
|
1643
|
+
let id = partIds.get(s);
|
|
1644
|
+
if (id === void 0) partIds.set(s, id = partIds.size);
|
|
1645
|
+
return id;
|
|
1646
|
+
}));
|
|
1647
|
+
const P = partIds.size;
|
|
1648
|
+
const len = Math.max(0, ...ids.map((r) => r.length));
|
|
1649
|
+
const keys = ids.map((r) => ({
|
|
1650
|
+
pre: [0],
|
|
1651
|
+
suf: new Array(r.length + 1).fill(0)
|
|
1652
|
+
}));
|
|
1653
|
+
for (let k = 0; k < len; k++) {
|
|
1654
|
+
const m = /* @__PURE__ */ new Map();
|
|
1655
|
+
ids.forEach((r, i) => {
|
|
1656
|
+
if (k >= r.length) return;
|
|
1657
|
+
const { pre } = keys[i];
|
|
1658
|
+
const key = pre[k] * P + r[k];
|
|
1659
|
+
let id = m.get(key);
|
|
1660
|
+
if (id === void 0) m.set(key, id = m.size + 1);
|
|
1661
|
+
pre.push(id);
|
|
1662
|
+
});
|
|
1663
|
+
}
|
|
1664
|
+
for (let k = len - 1; k >= 0; k--) {
|
|
1665
|
+
const m = /* @__PURE__ */ new Map();
|
|
1666
|
+
ids.forEach((r, i) => {
|
|
1667
|
+
if (k >= r.length) return;
|
|
1668
|
+
const { suf } = keys[i];
|
|
1669
|
+
const key = suf[k + 1] * P + r[k];
|
|
1670
|
+
let id = m.get(key);
|
|
1671
|
+
if (id === void 0) m.set(key, id = m.size + 1);
|
|
1672
|
+
suf[k] = id;
|
|
1673
|
+
});
|
|
1674
|
+
}
|
|
1675
|
+
return keys;
|
|
1676
|
+
}
|
|
1677
|
+
preprocess(globParts) {
|
|
1678
|
+
if (this.options.noglobstar) {
|
|
1679
|
+
for (const partset of globParts) for (let j = 0; j < partset.length; j++) if (partset[j] === "**") partset[j] = "*";
|
|
1680
|
+
}
|
|
1681
|
+
const { optimizationLevel = 1 } = this.options;
|
|
1682
|
+
if (optimizationLevel >= 2) {
|
|
1683
|
+
globParts = this.firstPhasePreProcess(globParts);
|
|
1684
|
+
globParts = this.secondPhasePreProcess(globParts);
|
|
1685
|
+
} else if (optimizationLevel >= 1) globParts = this.levelOneOptimize(globParts);
|
|
1686
|
+
else globParts = this.adjascentGlobstarOptimize(globParts);
|
|
1687
|
+
return globParts;
|
|
1688
|
+
}
|
|
1689
|
+
adjascentGlobstarOptimize(globParts) {
|
|
1690
|
+
return globParts.map((parts) => {
|
|
1691
|
+
let gs = -1;
|
|
1692
|
+
while (-1 !== (gs = parts.indexOf("**", gs + 1))) {
|
|
1693
|
+
let i = gs;
|
|
1694
|
+
while (parts[i + 1] === "**") i++;
|
|
1695
|
+
if (i !== gs) parts.splice(gs, i - gs);
|
|
1696
|
+
}
|
|
1697
|
+
return parts;
|
|
1698
|
+
});
|
|
1699
|
+
}
|
|
1700
|
+
levelOneOptimize(globParts) {
|
|
1701
|
+
return globParts.map((parts) => {
|
|
1702
|
+
const root = this.#rootIndex(parts) + 1;
|
|
1703
|
+
parts = parts.reduce((set, part) => {
|
|
1704
|
+
const prev = set[set.length - 1];
|
|
1705
|
+
if (part === "**" && prev === "**") return set;
|
|
1706
|
+
if (part === "..") {
|
|
1707
|
+
if (set.length > root && prev && prev !== ".." && prev !== "." && prev !== "**") {
|
|
1708
|
+
set.pop();
|
|
1709
|
+
return set;
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
set.push(part);
|
|
1713
|
+
return set;
|
|
1714
|
+
}, []);
|
|
1715
|
+
return parts.length === 0 ? [""] : parts;
|
|
1716
|
+
});
|
|
1717
|
+
}
|
|
1718
|
+
#canMatch(f) {
|
|
1719
|
+
const sep = !this.isWindows || !f.includes("\\") ? "/" : f.includes("/") ? "both" : "\\";
|
|
1720
|
+
let ends = this.#endCheck ? 0 : -1;
|
|
1721
|
+
let last = "";
|
|
1722
|
+
let lastStart = 0;
|
|
1723
|
+
let prev;
|
|
1724
|
+
let prevStart = 0;
|
|
1725
|
+
const dot = !!this.options.dot;
|
|
1726
|
+
ROWS: for (let r = 0; r < this.set.length; r++) {
|
|
1727
|
+
const row = this.set[r];
|
|
1728
|
+
const p = row[row.length - 1];
|
|
1729
|
+
let end = ends !== -1 && this.#endRows[r] && p !== GLOBSTAR;
|
|
1730
|
+
if (end && ends === 0) {
|
|
1731
|
+
const i = lastSep(f, f.length, sep);
|
|
1732
|
+
lastStart = i + 1;
|
|
1733
|
+
last = f.slice(lastStart);
|
|
1734
|
+
if (last === "" && i >= 0) {
|
|
1735
|
+
let j = i;
|
|
1736
|
+
while (j > 0 && isSep(f.charCodeAt(j - 1), sep)) j--;
|
|
1737
|
+
prevStart = j === 0 ? 0 : lastSep(f, j - 1, sep) + 1;
|
|
1738
|
+
prev = f.slice(prevStart, j);
|
|
1739
|
+
}
|
|
1740
|
+
const resolves = this.#level2 && (isDots(last) || last === "" && prev !== void 0 && isDots(prev));
|
|
1741
|
+
ends = resolves ? -1 : 1;
|
|
1742
|
+
end = !resolves;
|
|
1743
|
+
}
|
|
1744
|
+
let tailStart = -1;
|
|
1745
|
+
if (end && typeof p === "string") {
|
|
1746
|
+
tailStart = endIndex(p, last, lastStart, prev, prevStart);
|
|
1747
|
+
if (tailStart === -1) continue;
|
|
1748
|
+
}
|
|
1749
|
+
if (this.#literalCheck) {
|
|
1750
|
+
for (const l of this.#literals[r]) if (!f.includes(l)) continue ROWS;
|
|
1751
|
+
}
|
|
1752
|
+
if (end && typeof p === "object") {
|
|
1753
|
+
tailStart = endIndex(p, last, lastStart, prev, prevStart);
|
|
1754
|
+
if (tailStart === -1) continue;
|
|
1755
|
+
}
|
|
1756
|
+
const shape = this.#shapes[r];
|
|
1757
|
+
if (shape === "base" && end) return "yes";
|
|
1758
|
+
if (shape === "tail" && end) {
|
|
1759
|
+
if (this.#level2 && dotPortion(f, 0, tailStart, true, sep)) return "maybe";
|
|
1760
|
+
if (!dotPortion(f, 0, tailStart, dot, sep)) return "yes";
|
|
1761
|
+
continue;
|
|
1762
|
+
}
|
|
1763
|
+
if (shape === "mid" || shape === "head") {
|
|
1764
|
+
const m = this.#walk(f, row, shape === "head", dot, sep);
|
|
1765
|
+
if (m !== "no") return m;
|
|
1766
|
+
continue;
|
|
1767
|
+
}
|
|
1768
|
+
return "maybe";
|
|
1769
|
+
}
|
|
1770
|
+
return "no";
|
|
1771
|
+
}
|
|
1772
|
+
#matchShape(file, row, shape) {
|
|
1773
|
+
const dot = !!this.options.dot;
|
|
1774
|
+
const n = file.length;
|
|
1775
|
+
if (shape === "head") {
|
|
1776
|
+
if (n < 2 || !portionMatch(row[0], file[0])) return false;
|
|
1777
|
+
for (let i = 1; i < n; i++) if (!walkable(file[i], dot)) return false;
|
|
1778
|
+
return true;
|
|
1779
|
+
}
|
|
1780
|
+
const x = row[1];
|
|
1781
|
+
if (shape === "tail") {
|
|
1782
|
+
let t = n - 1;
|
|
1783
|
+
if (!portionMatch(x, file[t])) {
|
|
1784
|
+
if (file[t] !== "" || n === 1 || !portionMatch(x, file[--t])) return false;
|
|
1785
|
+
}
|
|
1786
|
+
for (let i = 0; i < t; i++) if (!walkable(file[i], dot)) return false;
|
|
1787
|
+
return true;
|
|
1788
|
+
}
|
|
1789
|
+
for (let k = 0; k < n; k++) {
|
|
1790
|
+
if (portionMatch(x, file[k]) && k + 1 < n) {
|
|
1791
|
+
let i = k + 1;
|
|
1792
|
+
while (i < n && walkable(file[i], dot)) i++;
|
|
1793
|
+
if (i === n) return true;
|
|
1794
|
+
}
|
|
1795
|
+
if (!walkable(file[k], dot)) return false;
|
|
1796
|
+
}
|
|
1797
|
+
return false;
|
|
1798
|
+
}
|
|
1799
|
+
#walk(f, row, head, dot, sep) {
|
|
1800
|
+
if (this.#level2 && dotPortion(f, 0, f.length, true, sep)) return "maybe";
|
|
1801
|
+
const x = row[head ? 0 : 1];
|
|
1802
|
+
let s = 0;
|
|
1803
|
+
for (let e = nextSep(f, s, sep); e !== -1; e = nextSep(f, s, sep)) {
|
|
1804
|
+
let next = e + 1;
|
|
1805
|
+
while (next < f.length && isSep(f.charCodeAt(next), sep)) next++;
|
|
1806
|
+
if ((typeof x === "string" ? e - s === x.length && f.startsWith(x, s) : e > s && x.testUnchecked(f.slice(s, e))) && !dotPortion(f, next, f.length, dot, sep)) return "yes";
|
|
1807
|
+
if (head || dotPortion(f, s, next, dot, sep)) return "no";
|
|
1808
|
+
s = next;
|
|
1809
|
+
}
|
|
1810
|
+
return "no";
|
|
1811
|
+
}
|
|
1812
|
+
#cachedSplit(f) {
|
|
1813
|
+
const last = lastSplit;
|
|
1814
|
+
return last?.f === f && last.isWindows === this.isWindows && last.preserveMultipleSlashes === this.preserveMultipleSlashes && last.normalize === this.#form ? last : void 0;
|
|
1815
|
+
}
|
|
1816
|
+
#split(f) {
|
|
1817
|
+
const { isWindows, preserveMultipleSlashes } = this;
|
|
1818
|
+
let parts = this.#slashSplit(isWindows ? f.split("\\").join("/") : f);
|
|
1819
|
+
const normalize = this.#form;
|
|
1820
|
+
if (normalize) parts = parts.map((p) => p.normalize(normalize));
|
|
1821
|
+
lastSplit = {
|
|
1822
|
+
f,
|
|
1823
|
+
isWindows,
|
|
1824
|
+
preserveMultipleSlashes,
|
|
1825
|
+
normalize,
|
|
1826
|
+
parts
|
|
1827
|
+
};
|
|
1828
|
+
return lastSplit;
|
|
1829
|
+
}
|
|
1830
|
+
#levelTwoFileOptimize(file) {
|
|
1831
|
+
const parts = [...file];
|
|
1832
|
+
let didSomething = false;
|
|
1833
|
+
do {
|
|
1834
|
+
didSomething = false;
|
|
1835
|
+
if (!this.preserveMultipleSlashes) {
|
|
1836
|
+
for (let i = 1; i < parts.length - 1; i++) {
|
|
1837
|
+
const p = parts[i];
|
|
1838
|
+
if (i === 1 && p === "" && parts[0] === "") continue;
|
|
1839
|
+
if (p === "." || p === "") {
|
|
1840
|
+
didSomething = true;
|
|
1841
|
+
parts.splice(i, 1);
|
|
1842
|
+
i--;
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
if (parts[0] === "." && parts.length === 2 && (parts[1] === "." || parts[1] === "")) {
|
|
1846
|
+
didSomething = true;
|
|
1847
|
+
parts.pop();
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
const root = this.#rootIndex(parts) + 1;
|
|
1851
|
+
let dd = root;
|
|
1852
|
+
while (-1 !== (dd = parts.indexOf("..", dd + 1))) {
|
|
1853
|
+
const p = parts[dd - 1];
|
|
1854
|
+
if (p && p !== "." && p !== ".." && p !== "**") {
|
|
1855
|
+
didSomething = true;
|
|
1856
|
+
parts.splice(dd - 1, 2);
|
|
1857
|
+
dd = Math.max(dd - 2, root);
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
} while (didSomething);
|
|
1861
|
+
return parts.length === 0 ? [""] : parts;
|
|
1862
|
+
}
|
|
1863
|
+
firstPhasePreProcess(globParts) {
|
|
1864
|
+
const { braceExpandMax = DEFAULT_BRACE_EXPAND_MAX } = this.options;
|
|
1865
|
+
let splitCells = 0;
|
|
1866
|
+
const maxSplitCells = 1e6;
|
|
1867
|
+
let didSomething = false;
|
|
1868
|
+
do {
|
|
1869
|
+
didSomething = false;
|
|
1870
|
+
for (let parts of globParts) {
|
|
1871
|
+
let gs = -1;
|
|
1872
|
+
while (-1 !== (gs = parts.indexOf("**", gs + 1))) {
|
|
1873
|
+
let gss = gs;
|
|
1874
|
+
while (parts[gss + 1] === "**") gss++;
|
|
1875
|
+
if (gss > gs) parts.splice(gs + 1, gss - gs);
|
|
1876
|
+
let next = parts[gs + 1];
|
|
1877
|
+
const p = parts[gs + 2];
|
|
1878
|
+
const p2 = parts[gs + 3];
|
|
1879
|
+
if (next !== "..") continue;
|
|
1880
|
+
if (!p || p === "." || p === ".." || !p2 || p2 === "." || p2 === "..") continue;
|
|
1881
|
+
const addedCells = parts.length - 1;
|
|
1882
|
+
if (globParts.length >= braceExpandMax || splitCells + addedCells > maxSplitCells) throw new RangeError(`optimizationLevel 2: too many patterns from '**/..'`);
|
|
1883
|
+
didSomething = true;
|
|
1884
|
+
parts.splice(gs, 1);
|
|
1885
|
+
const other = parts.slice(0);
|
|
1886
|
+
other[gs] = "**";
|
|
1887
|
+
splitCells += addedCells;
|
|
1888
|
+
globParts.push(other);
|
|
1889
|
+
gs--;
|
|
1890
|
+
}
|
|
1891
|
+
if (!this.preserveMultipleSlashes) {
|
|
1892
|
+
for (let i = 1; i < parts.length - 1; i++) {
|
|
1893
|
+
const p = parts[i];
|
|
1894
|
+
if (i === 1 && p === "" && parts[0] === "") continue;
|
|
1895
|
+
if (p === "." || p === "") {
|
|
1896
|
+
didSomething = true;
|
|
1897
|
+
parts.splice(i, 1);
|
|
1898
|
+
i--;
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
if (parts[0] === "." && parts.length === 2 && (parts[1] === "." || parts[1] === "")) {
|
|
1902
|
+
didSomething = true;
|
|
1903
|
+
parts.pop();
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
const root = this.#rootIndex(parts) + 1;
|
|
1907
|
+
let dd = root;
|
|
1908
|
+
while (-1 !== (dd = parts.indexOf("..", dd + 1))) {
|
|
1909
|
+
const p = parts[dd - 1];
|
|
1910
|
+
if (p && p !== "." && p !== ".." && p !== "**") {
|
|
1911
|
+
didSomething = true;
|
|
1912
|
+
const splin = dd === 1 && parts[dd + 1] === "**" ? ["."] : [];
|
|
1913
|
+
parts.splice(dd - 1, 2, ...splin);
|
|
1914
|
+
if (parts.length === 0) parts.push("");
|
|
1915
|
+
dd = Math.max(dd - 2, root);
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
} while (didSomething);
|
|
1920
|
+
return globParts;
|
|
1921
|
+
}
|
|
1922
|
+
secondPhasePreProcess(globParts) {
|
|
1923
|
+
const keys = /* @__PURE__ */ new Set();
|
|
1924
|
+
const rows = globParts.filter((parts) => {
|
|
1925
|
+
const key = parts.join("/");
|
|
1926
|
+
if (keys.has(key)) return false;
|
|
1927
|
+
keys.add(key);
|
|
1928
|
+
return true;
|
|
1929
|
+
});
|
|
1930
|
+
const stars = /* @__PURE__ */ new Map();
|
|
1931
|
+
for (const parts of rows) {
|
|
1932
|
+
const s = [];
|
|
1933
|
+
for (let i = 0; i < parts.length; i++) if (parts[i] === "*") s.push(i);
|
|
1934
|
+
if (s.length) stars.set(s.join(","), s);
|
|
1935
|
+
}
|
|
1936
|
+
if (!stars.size || rows.length * stars.size > 1e5) return rows;
|
|
1937
|
+
const { dot } = this.options;
|
|
1938
|
+
return rows.filter((parts) => {
|
|
1939
|
+
for (const s of stars.values()) {
|
|
1940
|
+
if (s[s.length - 1] >= parts.length) continue;
|
|
1941
|
+
const c = [...parts];
|
|
1942
|
+
let ok = true;
|
|
1943
|
+
let changed = false;
|
|
1944
|
+
for (const i of s) {
|
|
1945
|
+
const p = parts[i];
|
|
1946
|
+
if (p === "*") continue;
|
|
1947
|
+
if (!p || p === "**" || !dot && p.startsWith(".")) {
|
|
1948
|
+
ok = false;
|
|
1949
|
+
break;
|
|
1950
|
+
}
|
|
1951
|
+
c[i] = "*";
|
|
1952
|
+
changed = true;
|
|
1953
|
+
}
|
|
1954
|
+
if (ok && changed && keys.has(c.join("/"))) return false;
|
|
1955
|
+
}
|
|
1956
|
+
return true;
|
|
1957
|
+
});
|
|
1958
|
+
}
|
|
1959
|
+
parseNegate() {
|
|
1960
|
+
if (this.nonegate) return;
|
|
1961
|
+
const pattern = this.pattern;
|
|
1962
|
+
let negate = false;
|
|
1963
|
+
let negateOffset = 0;
|
|
1964
|
+
for (let i = 0; i < pattern.length && pattern.charAt(i) === "!"; i++) {
|
|
1965
|
+
negate = !negate;
|
|
1966
|
+
negateOffset++;
|
|
1967
|
+
}
|
|
1968
|
+
if (negateOffset) this.pattern = pattern.slice(negateOffset);
|
|
1969
|
+
this.negate = negate;
|
|
1970
|
+
}
|
|
1971
|
+
#matchRow(file, resolved, pattern, partial) {
|
|
1972
|
+
let fileStartIndex = 0;
|
|
1973
|
+
let patternStartIndex = 0;
|
|
1974
|
+
const fh = this.isWindows ? uncHost(resolved) : -1;
|
|
1975
|
+
const ph = fh === -1 ? -1 : uncHost(pattern);
|
|
1976
|
+
if (ph !== -1) {
|
|
1977
|
+
const host = pattern[ph];
|
|
1978
|
+
const share = pattern[ph + 1];
|
|
1979
|
+
if (typeof host !== "string" || typeof share !== "string") {
|
|
1980
|
+
fileStartIndex = fh;
|
|
1981
|
+
patternStartIndex = ph;
|
|
1982
|
+
} else if (resolved[fh].toLowerCase() === host.toLowerCase() && resolved[fh + 1].toLowerCase() === share.toLowerCase()) {
|
|
1983
|
+
fileStartIndex = fh + 2;
|
|
1984
|
+
patternStartIndex = ph + 2;
|
|
1985
|
+
}
|
|
1986
|
+
} else if (this.isWindows) {
|
|
1987
|
+
const fileDrive = typeof file[0] === "string" && /^[a-z]:$/i.test(file[0]);
|
|
1988
|
+
const fileUNC = !fileDrive && file[0] === "" && file[1] === "" && file[2] === "?" && /^[a-z]:$/i.test(file[3]);
|
|
1989
|
+
const patternDrive = typeof pattern[0] === "string" && /^[a-z]:$/i.test(pattern[0]);
|
|
1990
|
+
const patternUNC = !patternDrive && pattern[0] === "" && pattern[1] === "" && pattern[2] === "?" && typeof pattern[3] === "string" && /^[a-z]:$/i.test(pattern[3]);
|
|
1991
|
+
const fdi = fileUNC ? 3 : fileDrive ? 0 : void 0;
|
|
1992
|
+
const pdi = patternUNC ? 3 : patternDrive ? 0 : void 0;
|
|
1993
|
+
if (typeof fdi === "number" && typeof pdi === "number") {
|
|
1994
|
+
const [fd, pd] = [file[fdi], pattern[pdi]];
|
|
1995
|
+
if (fd.toLowerCase() === pd.toLowerCase()) {
|
|
1996
|
+
patternStartIndex = pdi + 1;
|
|
1997
|
+
fileStartIndex = fdi + 1;
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
file = resolved;
|
|
2002
|
+
if (pattern.includes(GLOBSTAR)) return this.#matchGlobstar(file, pattern, partial, fileStartIndex, patternStartIndex);
|
|
2003
|
+
return this.#matchOne(file, pattern, partial, fileStartIndex, patternStartIndex);
|
|
2004
|
+
}
|
|
2005
|
+
#matchGlobstar(file, pattern, partial, fileIndex, patternIndex) {
|
|
2006
|
+
const { head, body, tail, segments } = this.#getGlobstarParts(pattern, partial, patternIndex);
|
|
2007
|
+
if (head.length) {
|
|
2008
|
+
const headEnd = fileIndex + head.length;
|
|
2009
|
+
if (!this.#matchOne(file, head, partial, fileIndex, 0, headEnd)) return false;
|
|
2010
|
+
fileIndex += head.length;
|
|
2011
|
+
patternIndex += head.length;
|
|
2012
|
+
}
|
|
2013
|
+
let fileTailMatch = 0;
|
|
2014
|
+
if (tail.length) {
|
|
2015
|
+
if (tail.length + fileIndex > file.length) return false;
|
|
2016
|
+
let tailStart = file.length - tail.length;
|
|
2017
|
+
if (this.#matchOne(file, tail, partial, tailStart, 0)) fileTailMatch = tail.length;
|
|
2018
|
+
else {
|
|
2019
|
+
if (file[file.length - 1] !== "" || fileIndex + tail.length === file.length) return false;
|
|
2020
|
+
tailStart--;
|
|
2021
|
+
if (!this.#matchOne(file, tail, partial, tailStart, 0)) return false;
|
|
2022
|
+
fileTailMatch = tail.length + 1;
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
if (!body.length) {
|
|
2026
|
+
let sawSome = !!fileTailMatch;
|
|
2027
|
+
for (let i = fileIndex; i < file.length - fileTailMatch; i++) {
|
|
2028
|
+
const f = String(file[i]);
|
|
2029
|
+
sawSome = true;
|
|
2030
|
+
if (f === "." || f === ".." || !this.options.dot && f.startsWith(".")) return false;
|
|
2031
|
+
}
|
|
2032
|
+
return partial || sawSome;
|
|
2033
|
+
}
|
|
2034
|
+
return !!this.#matchGlobStarBodySections(file, segments, file.length - fileTailMatch, fileIndex, 0, partial, 0, !!fileTailMatch, /* @__PURE__ */ new Set());
|
|
2035
|
+
}
|
|
2036
|
+
#getGlobstarParts(pattern, partial, patternIndex) {
|
|
2037
|
+
let byStart = this.#globstarParts.get(pattern);
|
|
2038
|
+
if (!byStart) {
|
|
2039
|
+
byStart = [];
|
|
2040
|
+
this.#globstarParts.set(pattern, byStart);
|
|
2041
|
+
}
|
|
2042
|
+
const key = patternIndex * 2 + (partial ? 1 : 0);
|
|
2043
|
+
const found = byStart[key];
|
|
2044
|
+
if (found) return found;
|
|
2045
|
+
const firstgs = pattern.indexOf(GLOBSTAR, patternIndex);
|
|
2046
|
+
const lastgs = pattern.lastIndexOf(GLOBSTAR);
|
|
2047
|
+
const head = pattern.slice(patternIndex, firstgs);
|
|
2048
|
+
const body = pattern.slice(firstgs + 1, partial ? void 0 : lastgs);
|
|
2049
|
+
const tail = partial ? [] : pattern.slice(lastgs + 1);
|
|
2050
|
+
const segments = [[[], 0]];
|
|
2051
|
+
let current = segments[0];
|
|
2052
|
+
let nonGsParts = 0;
|
|
2053
|
+
const nonGsPartsSums = [0];
|
|
2054
|
+
for (const b of body) if (b === GLOBSTAR) {
|
|
2055
|
+
nonGsPartsSums.push(nonGsParts);
|
|
2056
|
+
current = [[], 0];
|
|
2057
|
+
segments.push(current);
|
|
2058
|
+
} else {
|
|
2059
|
+
current[0].push(b);
|
|
2060
|
+
nonGsParts++;
|
|
2061
|
+
}
|
|
2062
|
+
segments.forEach((b, i) => {
|
|
2063
|
+
b[1] = nonGsParts - nonGsPartsSums[i];
|
|
2064
|
+
});
|
|
2065
|
+
const parts = {
|
|
2066
|
+
head,
|
|
2067
|
+
body,
|
|
2068
|
+
tail,
|
|
2069
|
+
segments
|
|
2070
|
+
};
|
|
2071
|
+
byStart[key] = parts;
|
|
2072
|
+
return parts;
|
|
2073
|
+
}
|
|
2074
|
+
#matchGlobStarBodySections(file, bodySegments, fileLength, fileIndex, bodyIndex, partial, globStarDepth, sawTail, tried) {
|
|
2075
|
+
const bs = bodySegments[bodyIndex];
|
|
2076
|
+
if (!bs) {
|
|
2077
|
+
if (partial) return fileIndex >= fileLength || fileIndex === fileLength - 1 && file[fileIndex] === "";
|
|
2078
|
+
for (let i = fileIndex; i < fileLength; i++) {
|
|
2079
|
+
sawTail = true;
|
|
2080
|
+
const f = file[i];
|
|
2081
|
+
if (f === "." || f === ".." || !this.options.dot && f.startsWith(".")) return false;
|
|
2082
|
+
}
|
|
2083
|
+
return sawTail;
|
|
2084
|
+
}
|
|
2085
|
+
const [body, need] = bs;
|
|
2086
|
+
const after = partial ? fileLength : fileLength - need;
|
|
2087
|
+
while (fileIndex <= after) {
|
|
2088
|
+
const key = bodyIndex * (file.length + 1) + fileIndex;
|
|
2089
|
+
if (tried.has(key)) return false;
|
|
2090
|
+
tried.add(key);
|
|
2091
|
+
if (this.#matchOne(file, body, partial, fileIndex, 0, fileIndex + body.length) && globStarDepth < this.maxGlobstarRecursion) {
|
|
2092
|
+
const sub = this.#matchGlobStarBodySections(file, bodySegments, fileLength, fileIndex + body.length, bodyIndex + 1, partial, globStarDepth + 1, sawTail, tried);
|
|
2093
|
+
if (sub !== false) return sub;
|
|
2094
|
+
}
|
|
2095
|
+
if (fileIndex === after) break;
|
|
2096
|
+
const f = file[fileIndex];
|
|
2097
|
+
if (f === "." || f === ".." || !this.options.dot && f.startsWith(".")) return false;
|
|
2098
|
+
fileIndex++;
|
|
2099
|
+
}
|
|
2100
|
+
return partial || null;
|
|
2101
|
+
}
|
|
2102
|
+
#matchOne(file, pattern, partial, fileIndex, patternIndex, fileEnd = file.length) {
|
|
2103
|
+
let fi;
|
|
2104
|
+
let pi;
|
|
2105
|
+
let pl;
|
|
2106
|
+
let fl;
|
|
2107
|
+
for (fi = fileIndex, pi = patternIndex, fl = Math.min(fileEnd, file.length), pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {
|
|
2108
|
+
let p = pattern[pi];
|
|
2109
|
+
let f = file[fi];
|
|
2110
|
+
/* c8 ignore start */
|
|
2111
|
+
if (p === false || p === GLOBSTAR) return false;
|
|
2112
|
+
/* c8 ignore stop */
|
|
2113
|
+
if (!portionMatch(p, f)) return false;
|
|
2114
|
+
}
|
|
2115
|
+
if (fi === fl && pi === pl) return true;
|
|
2116
|
+
else if (fi === fl) return partial;
|
|
2117
|
+
else if (pi === pl) return fi === fl - 1 && file[fi] === "";
|
|
2118
|
+
else throw new Error("wtf?");
|
|
2119
|
+
/* c8 ignore stop */
|
|
2120
|
+
}
|
|
2121
|
+
braceExpand() {
|
|
2122
|
+
return braceExpand(this.pattern, this.options);
|
|
2123
|
+
}
|
|
2124
|
+
#expandBraces() {
|
|
2125
|
+
const { pattern } = this;
|
|
2126
|
+
if (this.options.nobrace) return this.braceExpand();
|
|
2127
|
+
let code = 57344;
|
|
2128
|
+
while (pattern.includes(String.fromCharCode(code))) if (++code > 63743) return this.braceExpand();
|
|
2129
|
+
const mark = String.fromCharCode(code);
|
|
2130
|
+
let found = false;
|
|
2131
|
+
const marked = pattern.replace(rangeRe, (m, lo, hi) => {
|
|
2132
|
+
const a = Number(lo);
|
|
2133
|
+
const b = Number(hi);
|
|
2134
|
+
if (!Number.isSafeInteger(a) || !Number.isSafeInteger(b) || Math.abs(a - b) + 1 < RANGE_MIN) return m;
|
|
2135
|
+
found = true;
|
|
2136
|
+
return `${mark}${lo}..${hi}${mark}`;
|
|
2137
|
+
});
|
|
2138
|
+
if (!found) return this.braceExpand();
|
|
2139
|
+
const set = braceExpand(marked, this.options);
|
|
2140
|
+
for (const p of set) for (const portion of p.split("/")) {
|
|
2141
|
+
const c = portion.indexOf("[");
|
|
2142
|
+
if (c !== -1 && c < portion.lastIndexOf(mark)) return this.braceExpand();
|
|
2143
|
+
if (!this.options.noext && inRepeatOrNegExt(portion, mark)) return this.braceExpand();
|
|
2144
|
+
}
|
|
2145
|
+
this.#rangeMark = mark;
|
|
2146
|
+
return set;
|
|
2147
|
+
}
|
|
2148
|
+
parse(pattern) {
|
|
2149
|
+
assertValidPattern(pattern);
|
|
2150
|
+
const options = this.options;
|
|
2151
|
+
if (pattern === "**") return GLOBSTAR;
|
|
2152
|
+
if (pattern === "") return "";
|
|
2153
|
+
const { nocase, nocaseMagicOnly, noext = false, dot, normalize } = options;
|
|
2154
|
+
const rangeMark = this.#rangeMark;
|
|
2155
|
+
const lit = rangeMark && pattern.includes(rangeMark) ? void 0 : literal(pattern, noext);
|
|
2156
|
+
if (lit !== void 0 && !(nocase && !nocaseMagicOnly && pattern.toUpperCase() !== pattern.toLowerCase())) return this.#norm(lit);
|
|
2157
|
+
if (this.#pending) return PENDING;
|
|
2158
|
+
let m = this.#matchers.get(pattern);
|
|
2159
|
+
if (!m) {
|
|
2160
|
+
if (!noext) assertValidExtglobs(pattern);
|
|
2161
|
+
m = new Matcher(pattern, {
|
|
2162
|
+
nocase,
|
|
2163
|
+
noext,
|
|
2164
|
+
dot,
|
|
2165
|
+
normalize,
|
|
2166
|
+
...rangeMark && { rangeMark }
|
|
2167
|
+
});
|
|
2168
|
+
this.#matchers.set(pattern, m);
|
|
2169
|
+
}
|
|
2170
|
+
return m;
|
|
2171
|
+
}
|
|
2172
|
+
#slashSplit(p) {
|
|
2173
|
+
if (this.preserveMultipleSlashes) return p.split("/");
|
|
2174
|
+
else if (this.isWindows && /^\/\/[^/]+/.test(p)) return ["", ...p.split(/\/+/)];
|
|
2175
|
+
else return p.split(/\/+/);
|
|
2176
|
+
}
|
|
2177
|
+
match(f, partial = this.partial) {
|
|
2178
|
+
if (this.comment) return false;
|
|
2179
|
+
if (this.empty) return f === "";
|
|
2180
|
+
if (f === "/" && partial) return true;
|
|
2181
|
+
const options = this.options;
|
|
2182
|
+
let split = this.#cachedSplit(f);
|
|
2183
|
+
if (!split) {
|
|
2184
|
+
if (!partial && !this.#form && (this.#endCheck || this.#literalCheck) && lastChecked !== f) {
|
|
2185
|
+
lastChecked = f;
|
|
2186
|
+
const can = this.#canMatch(f);
|
|
2187
|
+
if (can === "no") return options.flipNegate ? false : this.negate;
|
|
2188
|
+
if (can === "yes") return options.flipNegate ? true : !this.negate;
|
|
2189
|
+
}
|
|
2190
|
+
split = this.#split(f);
|
|
2191
|
+
}
|
|
2192
|
+
const ff = split.parts;
|
|
2193
|
+
const resolved = this.#level2 ? split.resolved ??= this.#levelTwoFileOptimize(ff) : ff;
|
|
2194
|
+
const set = this.set;
|
|
2195
|
+
let filename = ff[ff.length - 1];
|
|
2196
|
+
if (!filename) for (let i = ff.length - 2; !filename && i >= 0; i--) filename = ff[i];
|
|
2197
|
+
for (let r = 0; r < set.length; r++) {
|
|
2198
|
+
const pattern = set[r];
|
|
2199
|
+
const shape = partial ? void 0 : this.#shapes[r];
|
|
2200
|
+
if (shape === "base" ? portionMatch(pattern[0], filename) : shape ? this.#matchShape(resolved, pattern, shape) : options.matchBase && pattern.length === 1 ? this.#matchRow([filename], [filename], pattern, partial) : this.#matchRow(ff, resolved, pattern, partial)) {
|
|
2201
|
+
if (options.flipNegate) return true;
|
|
2202
|
+
return !this.negate;
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2205
|
+
if (options.flipNegate) return false;
|
|
2206
|
+
return this.negate;
|
|
2207
|
+
}
|
|
2208
|
+
static defaults(def) {
|
|
2209
|
+
return minimatch.defaults(def).Minimatch;
|
|
2210
|
+
}
|
|
2211
|
+
};
|
|
2212
|
+
/* c8 ignore stop */
|
|
2213
|
+
minimatch.Minimatch = Minimatch;
|
|
2214
|
+
minimatch.escape = escape;
|
|
2215
|
+
minimatch.unescape = unescape;
|
|
2216
|
+
// ../path-kit/src/entities/glob/model/glob.ts
|
|
2217
|
+
const NEGATION = "!";
|
|
2218
|
+
const matcher = (patterns) => {
|
|
2219
|
+
const compiled = pipe(patterns, Array$1.map((pattern) => new Minimatch(pattern, { dot: true })));
|
|
2220
|
+
return (path) => pipe(compiled, Array$1.some((glob) => glob.match(path)));
|
|
2221
|
+
};
|
|
2222
|
+
String$1.startsWith(NEGATION);
|
|
2223
|
+
String$1.slice(1);
|
|
2224
|
+
// src/shared/lib/memo.ts
|
|
2225
|
+
const memoize = (compute) => {
|
|
2226
|
+
const cache = /* @__PURE__ */ new Map();
|
|
2227
|
+
const store = (key) => {
|
|
2228
|
+
const value = compute(key);
|
|
2229
|
+
cache.set(key, value);
|
|
2230
|
+
return value;
|
|
2231
|
+
};
|
|
2232
|
+
return (key) => Option.getOrElse(Option.fromNullishOr(cache.get(key)), () => store(key));
|
|
2233
|
+
};
|
|
2234
|
+
// src/entities/layout/model/position.ts
|
|
2235
|
+
const ONE$1 = 1;
|
|
2236
|
+
const IGNORED = { type: "ignored" };
|
|
2237
|
+
const OUTSIDE = { type: "outside" };
|
|
2238
|
+
const ROOT = { type: "root" };
|
|
2239
|
+
const LOOSE = { type: "loose" };
|
|
2240
|
+
const layerAt = (layer, slice = Option.none(), inner = Option.none()) => ({
|
|
2241
|
+
type: "layer",
|
|
2242
|
+
layer,
|
|
2243
|
+
slice,
|
|
2244
|
+
inner
|
|
2245
|
+
});
|
|
2246
|
+
const globsOf = (layers) => ({
|
|
2247
|
+
files: matcher(layers.files),
|
|
2248
|
+
loose: matcher(layers.loose ?? []),
|
|
2249
|
+
entries: matcher(layers.entries ?? []),
|
|
2250
|
+
open: matcher(layers.open ?? [])
|
|
2251
|
+
});
|
|
2252
|
+
const sliceOf = (layer, tail, isSlice) => {
|
|
2253
|
+
const end = pipe(Array$1.range(ONE$1, tail.length - ONE$1), Array$1.findFirst((count) => isSlice(joinAll([layer, ...Array$1.take(tail, count)]))), Option.getOrElse(() => ONE$1));
|
|
2254
|
+
return {
|
|
2255
|
+
type: "layer",
|
|
2256
|
+
layer,
|
|
2257
|
+
slice: Option.some(joinAll(Array$1.take(tail, end))),
|
|
2258
|
+
inner: Option.some(joinAll(Array$1.drop(tail, end)))
|
|
2259
|
+
};
|
|
2260
|
+
};
|
|
2261
|
+
const locateSingle = ({ layers, globs }, single) => {
|
|
2262
|
+
if (globs.loose(single)) return ROOT;
|
|
2263
|
+
if (layers.moduleFiles !== true) return LOOSE;
|
|
2264
|
+
const name = stem(single);
|
|
2265
|
+
if (isLayer(layers)(name)) return layerAt(name);
|
|
2266
|
+
return {
|
|
2267
|
+
type: "unknownLayer",
|
|
2268
|
+
layer: name
|
|
2269
|
+
};
|
|
2270
|
+
};
|
|
2271
|
+
const locateParted = (scope, layer, tail) => {
|
|
2272
|
+
const [only, ...more] = tail;
|
|
2273
|
+
const modules = scope.layers.moduleFiles === true;
|
|
2274
|
+
if (Array$1.isReadonlyArrayNonEmpty(more) && modules) return layerAt(layer, Option.some(only), Option.some(joinAll(more)));
|
|
2275
|
+
if (Array$1.isReadonlyArrayNonEmpty(more)) return sliceOf(layer, tail, scope.isSlice);
|
|
2276
|
+
if (modules) return layerAt(layer, Option.some(stem(only)));
|
|
2277
|
+
return layerAt(layer, Option.some(stem(only)), Option.some(only));
|
|
2278
|
+
};
|
|
2279
|
+
const locateRest = (scope) => (rest) => {
|
|
2280
|
+
const [layer, ...tail] = segments(rest);
|
|
2281
|
+
if (!Array$1.isReadonlyArrayNonEmpty(tail)) return locateSingle(scope, layer);
|
|
2282
|
+
if (!isLayer(scope.layers)(layer)) return {
|
|
2283
|
+
type: "unknownLayer",
|
|
2284
|
+
layer
|
|
2285
|
+
};
|
|
2286
|
+
if (!isParted(scope.layers)(layer)) return layerAt(layer);
|
|
2287
|
+
return locateParted(scope, layer, tail);
|
|
2288
|
+
};
|
|
2289
|
+
const asLayer = (position) => pipe(Option.some(position), Option.filter((value) => value.type === "layer"));
|
|
2290
|
+
// src/entities/layout/model/layout.ts
|
|
2291
|
+
const ROOT_PATH = ".";
|
|
2292
|
+
const dirPath = (dir) => pipe(Option.some(dir), Option.filter(String$1.isNonEmpty), Option.getOrElse(() => ROOT_PATH));
|
|
2293
|
+
const markerDir = (marker) => (file) => pipe(Option.some(file), Option.filter((path) => baseName(path) === marker), Option.map((path) => parent(path)));
|
|
2294
|
+
const instancesOf = (files) => (kind) => {
|
|
2295
|
+
const wanted = Option.map(Option.fromNullishOr(kind.paths), matcher);
|
|
2296
|
+
const allowed = (dir) => Option.match(wanted, {
|
|
2297
|
+
onNone: () => true,
|
|
2298
|
+
onSome: (paths) => paths(dirPath(dir))
|
|
2299
|
+
});
|
|
2300
|
+
const instanceAt = (file) => pipe(markerDir(kind.marker)(file), Option.filter(allowed), Option.map((dir) => ({
|
|
2301
|
+
kind,
|
|
2302
|
+
dir
|
|
2303
|
+
})));
|
|
2304
|
+
return pipe(files, Array$1.map(instanceAt), Array$1.getSomes);
|
|
2305
|
+
};
|
|
2306
|
+
const globsByKind = (kinds) => {
|
|
2307
|
+
const globs = new Map(pipe(kinds, Array$1.map((kind) => Option.map(Option.fromNullishOr(kind.layers), (layers) => [kind, globsOf(layers)])), Array$1.getSomes));
|
|
2308
|
+
return (kind) => Option.fromNullishOr(globs.get(kind));
|
|
2309
|
+
};
|
|
2310
|
+
const entryDirsOf = (kinds, files) => {
|
|
2311
|
+
const entries = pipe(kinds, Array$1.map((kind) => Option.fromNullishOr(kind.layers)), Array$1.getSomes, Array$1.map((layers) => globsOf(layers).entries));
|
|
2312
|
+
const isEntryFile = (file) => pipe(entries, Array$1.some((entry) => entry(baseName(file))));
|
|
2313
|
+
const dirs = new Set(pipe(files, Array$1.filter(isEntryFile), Array$1.map((file) => parent(file))));
|
|
2314
|
+
return (dir) => dirs.has(dir);
|
|
2315
|
+
};
|
|
2316
|
+
const pathsOf = (files) => {
|
|
2317
|
+
const paths = /* @__PURE__ */ new Set([...files, ...pipe(files, Array$1.flatMap(ancestors))]);
|
|
2318
|
+
return (path) => paths.has(path);
|
|
2319
|
+
};
|
|
2320
|
+
const indexOf = (kinds, files) => {
|
|
2321
|
+
const instances = pipe(kinds, Array$1.flatMap(instancesOf(files)));
|
|
2322
|
+
return {
|
|
2323
|
+
instances,
|
|
2324
|
+
byDir: Array$1.groupBy(instances, ({ dir }) => dir),
|
|
2325
|
+
globsFor: globsByKind(kinds),
|
|
2326
|
+
isEntryDir: entryDirsOf(kinds, files),
|
|
2327
|
+
isPath: pathsOf(files)
|
|
2328
|
+
};
|
|
2329
|
+
};
|
|
2330
|
+
const ownersIn = ({ byDir }) => (file) => pipe(ancestors(file), Array$1.findFirst((dir) => Record.get(byDir, dir)), Option.getOrElse(() => []));
|
|
2331
|
+
const inner = (instance) => (path) => below(instance.dir)(path);
|
|
2332
|
+
const scopeOf = ({ isEntryDir }, instance) => (layers, globs) => {
|
|
2333
|
+
const base = join(instance.dir)(layers.dir);
|
|
2334
|
+
return locateRest({
|
|
2335
|
+
layers,
|
|
2336
|
+
globs,
|
|
2337
|
+
isSlice: (sub) => isEntryDir(join(base)(sub))
|
|
2338
|
+
});
|
|
2339
|
+
};
|
|
2340
|
+
const locateIn = (index) => (instance) => (path) => {
|
|
2341
|
+
const layerGlobs = index.globsFor(instance.kind);
|
|
2342
|
+
const layers = Option.fromNullishOr(instance.kind.layers);
|
|
2343
|
+
const within = inner(instance)(path);
|
|
2344
|
+
return pipe(Option.all({
|
|
2345
|
+
layers,
|
|
2346
|
+
layerGlobs,
|
|
2347
|
+
within
|
|
2348
|
+
}), Option.filter((found) => found.layerGlobs.files(found.within)), Option.map((found) => Option.match(below(found.layers.dir)(found.within), {
|
|
2349
|
+
onNone: () => OUTSIDE,
|
|
2350
|
+
onSome: scopeOf(index, instance)(found.layers, found.layerGlobs)
|
|
2351
|
+
})), Option.getOrElse(() => IGNORED));
|
|
2352
|
+
};
|
|
2353
|
+
const globMatches = ({ globsFor }, pick) => (instance) => (path) => pipe(globsFor(instance.kind), Option.exists((layerGlobs) => pick(layerGlobs)(path)));
|
|
2354
|
+
const perInstance = (locate) => {
|
|
2355
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
2356
|
+
const store = (instance) => {
|
|
2357
|
+
const located = memoize(locate(instance));
|
|
2358
|
+
cache.set(instance, located);
|
|
2359
|
+
return located;
|
|
2360
|
+
};
|
|
2361
|
+
return (instance) => Option.getOrElse(Option.fromNullishOr(cache.get(instance)), () => store(instance));
|
|
2362
|
+
};
|
|
2363
|
+
const makeLayout = (kinds) => (files) => {
|
|
2364
|
+
const index = indexOf(kinds, files);
|
|
2365
|
+
const owners = memoize(ownersIn(index));
|
|
2366
|
+
const locate = perInstance(locateIn(index));
|
|
2367
|
+
return {
|
|
2368
|
+
files,
|
|
2369
|
+
instances: index.instances,
|
|
2370
|
+
exists: (path) => String$1.isEmpty(path) || index.isPath(path),
|
|
2371
|
+
owners,
|
|
2372
|
+
inner,
|
|
2373
|
+
isEntry: globMatches(index, ({ entries }) => entries),
|
|
2374
|
+
isOpen: globMatches(index, ({ open }) => open),
|
|
2375
|
+
locate,
|
|
2376
|
+
located: memoize((path) => pipe(owners(path), Array$1.map((instance) => ({
|
|
2377
|
+
instance,
|
|
2378
|
+
position: locate(instance)(path)
|
|
2379
|
+
}))))
|
|
2380
|
+
};
|
|
2381
|
+
};
|
|
2382
|
+
// src/features/check-imports/model/imports.ts
|
|
2383
|
+
const LAYER_IMPORT = "layer-import";
|
|
2384
|
+
const CROSS_SLICE = "cross-slice";
|
|
2385
|
+
const PUBLIC_API = "public-api";
|
|
2386
|
+
const WILDCARD_EXPORT = "wildcard-export";
|
|
2387
|
+
const LINK_TARGET = "link-target";
|
|
2388
|
+
const MARKDOWN = /\.md$/iu;
|
|
2389
|
+
const SIBLING = ".";
|
|
2390
|
+
const NESTED = "/";
|
|
2391
|
+
const ONE = 1;
|
|
2392
|
+
const finding = (edge, rule, message) => ({
|
|
2393
|
+
path: edge.from,
|
|
2394
|
+
line: edge.line,
|
|
2395
|
+
column: edge.column,
|
|
2396
|
+
rule,
|
|
2397
|
+
message
|
|
2398
|
+
});
|
|
2399
|
+
const startsCross = (prefix, inner) => {
|
|
2400
|
+
const rest = String$1.slice(prefix.length)(inner);
|
|
2401
|
+
return String$1.startsWith(prefix)(inner) && (String$1.isEmpty(rest) || String$1.startsWith(SIBLING)(rest) || String$1.startsWith(NESTED)(rest));
|
|
2402
|
+
};
|
|
2403
|
+
const crossing = ({ layers, source, target }) => pipe(Option.all({
|
|
2404
|
+
cross: Option.fromNullishOr(layers.cross),
|
|
2405
|
+
slice: source.slice,
|
|
2406
|
+
inner: target.inner
|
|
2407
|
+
}), Option.exists(({ cross, slice, inner }) => startsCross(`${cross}/${slice}`, inner) || startsCross(`${cross}/${baseName(slice)}`, inner)));
|
|
2408
|
+
const otherSlice = ({ layers, source, target }) => isSliced(layers)(target.layer) && pipe(Option.all([source.slice, target.slice]), Option.exists(([from, to]) => from !== to)) && !crossing({
|
|
2409
|
+
layers,
|
|
2410
|
+
source,
|
|
2411
|
+
target
|
|
2412
|
+
});
|
|
2413
|
+
const indexIn = (layers, layer) => Array$1.findFirstIndex(layers.order, (name) => name === layer);
|
|
2414
|
+
const upward = ({ layers, edge, source, target }) => finding(edge, LAYER_IMPORT, `uses the ${target.layer} layer from the ${source.layer} layer (${edge.specifier}). A layer may only use the layers below it: ${Array$1.join(layers.order, ", ")}.`);
|
|
2415
|
+
const sideways = ({ edge, source, target }) => finding(edge, CROSS_SLICE, `uses the ${target.layer} slice ${Option.getOrElse(target.slice, () => "")} from the slice ${Option.getOrElse(source.slice, () => "")} (${edge.specifier}). Slices of one layer must not use each other; move what they share down a layer.`);
|
|
2416
|
+
const direction = (hop) => pipe(Option.all({
|
|
2417
|
+
from: indexIn(hop.layers, hop.source.layer),
|
|
2418
|
+
to: indexIn(hop.layers, hop.target.layer)
|
|
2419
|
+
}), Option.flatMap(({ from, to }) => {
|
|
2420
|
+
if (to < from) return Option.some(upward(hop));
|
|
2421
|
+
if (to === from && otherSlice(hop)) return Option.some(sideways(hop));
|
|
2422
|
+
return Option.none();
|
|
2423
|
+
}));
|
|
2424
|
+
const wildcardFinding = (layout, edge, { instance, position }) => pipe(asLayer(position), Option.filter(() => edge.wildcard && layout.isEntry(instance)(baseName(edge.from))), Option.map(() => finding(edge, WILDCARD_EXPORT, `re-exports everything from ${edge.specifier}. Name what the public API exports.`)));
|
|
2425
|
+
const restOf = (layout, layers, { instance, target }) => pipe(layout.inner(instance)(target), Option.flatMap(below(layers.dir)), Option.getOrElse(() => ""));
|
|
2426
|
+
const hidden = (layout, reach) => (to, layers) => pipe(to.inner, Option.exists((inner) => !(reach.from.layer === to.layer && Equal.equals(reach.from.slice, to.slice)) && isParted(layers)(to.layer) && !layout.isEntry(reach.instance)(inner) && !crossing({
|
|
2427
|
+
layers,
|
|
2428
|
+
source: reach.from,
|
|
2429
|
+
target: to
|
|
2430
|
+
}) && !layout.isOpen(reach.instance)(restOf(layout, layers, reach))));
|
|
2431
|
+
const targetOf = (layout, { instance, target }) => {
|
|
2432
|
+
const layers = Option.fromNullishOr(instance.kind.layers);
|
|
2433
|
+
const to = asLayer(layout.locate(instance)(target));
|
|
2434
|
+
return Option.all({
|
|
2435
|
+
layers,
|
|
2436
|
+
to
|
|
2437
|
+
});
|
|
2438
|
+
};
|
|
2439
|
+
const sliceName = ({ to }) => pipe(to.slice, Option.map((slice) => `${to.layer}/${slice}`));
|
|
2440
|
+
const publicApiFinding = (layout, edge, reach) => pipe(targetOf(layout, reach), Option.filter(({ layers, to }) => hidden(layout, reach)(to, layers)), Option.flatMap(sliceName), Option.map((slice) => finding(edge, PUBLIC_API, `reaches into ${slice} past its public API (${edge.specifier}). Import the slice's entry file instead.`)));
|
|
2441
|
+
const importFinding = (layout, edge, reach) => pipe(targetOf(layout, reach), Option.filter(() => Array$1.contains(layout.owners(reach.target), reach.instance)), Option.flatMap(({ layers, to }) => Option.orElse(direction({
|
|
2442
|
+
layers,
|
|
2443
|
+
edge,
|
|
2444
|
+
source: reach.from,
|
|
2445
|
+
target: to
|
|
2446
|
+
}), () => publicApiFinding(layout, edge, reach))));
|
|
2447
|
+
const fileFindings = (layout, edge, target) => pipe(layout.located(edge.from), Array$1.flatMap((located) => {
|
|
2448
|
+
const imported = pipe(asLayer(located.position), Option.flatMap((from) => importFinding(layout, edge, {
|
|
2449
|
+
instance: located.instance,
|
|
2450
|
+
from,
|
|
2451
|
+
target
|
|
2452
|
+
})));
|
|
2453
|
+
return Array$1.appendAll(Option.toArray(wildcardFinding(layout, edge, located)), Option.toArray(imported));
|
|
2454
|
+
}));
|
|
2455
|
+
const moduleTarget = (layers, target) => pipe(Array$1.head(target), Option.filter((layer) => isLayer(layers)(layer) && Option.isSome(Array$1.get(target, ONE))), Option.map((layer) => ({
|
|
2456
|
+
type: "layer",
|
|
2457
|
+
layer,
|
|
2458
|
+
slice: Option.filter(Array$1.get(target, ONE), () => isParted(layers)(layer)),
|
|
2459
|
+
inner: Option.none()
|
|
2460
|
+
})));
|
|
2461
|
+
const moduleHop = (edge, target) => (found) => pipe(moduleTarget(found.layers, target), Option.flatMap((to) => direction({
|
|
2462
|
+
...found,
|
|
2463
|
+
edge,
|
|
2464
|
+
target: to
|
|
2465
|
+
})));
|
|
2466
|
+
const moduleFindings = (layout, edge, target) => pipe(layout.located(edge.from), Array$1.flatMap(({ instance, position }) => {
|
|
2467
|
+
const layers = Option.fromNullishOr(instance.kind.layers);
|
|
2468
|
+
const source = asLayer(position);
|
|
2469
|
+
return pipe(Option.all({
|
|
2470
|
+
layers,
|
|
2471
|
+
source
|
|
2472
|
+
}), Option.flatMap(moduleHop(edge, target)), Option.toArray);
|
|
2473
|
+
}));
|
|
2474
|
+
const linkFindings = (layout, edge, target) => {
|
|
2475
|
+
if (layout.exists(target)) return [];
|
|
2476
|
+
return [finding(edge, LINK_TARGET, `links to ${edge.specifier}, where no file is tracked.`)];
|
|
2477
|
+
};
|
|
2478
|
+
const checkImports = (edges) => (layout) => pipe(edges, Array$1.flatMap((edge) => {
|
|
2479
|
+
if (edge.target.type === "module") return moduleFindings(layout, edge, edge.target.value);
|
|
2480
|
+
if (MARKDOWN.test(edge.from)) return linkFindings(layout, edge, edge.target.value);
|
|
2481
|
+
return fileFindings(layout, edge, edge.target.value);
|
|
2482
|
+
}));
|
|
2483
|
+
// src/shared/lib/finding.ts
|
|
2484
|
+
const FIRST = 1;
|
|
2485
|
+
const atFile = ({ path, rule, message }) => ({
|
|
2486
|
+
path,
|
|
2487
|
+
line: FIRST,
|
|
2488
|
+
column: FIRST,
|
|
2489
|
+
rule,
|
|
2490
|
+
message
|
|
2491
|
+
});
|
|
2492
|
+
// src/features/check-placement/model/placement.ts
|
|
2493
|
+
const PLACEMENT = "placement";
|
|
2494
|
+
const LOOSE_FILE = "loose-file";
|
|
2495
|
+
const LAYER_NAME = "layer-name";
|
|
2496
|
+
const compile = (kind) => pipe(kind.placements ?? [], Array$1.map((placement) => ({
|
|
2497
|
+
files: matcher(placement.files),
|
|
2498
|
+
allow: matcher(placement.allow),
|
|
2499
|
+
message: placement.message ?? `is not a place a ${kind.name} allows for this file.`
|
|
2500
|
+
})));
|
|
2501
|
+
const layersDir = (kind) => pipe(Option.fromNullishOr(kind.layers), Option.map(({ dir }) => dir), Option.getOrElse(() => ""));
|
|
2502
|
+
const layerMessage = (kind) => pipe(Option.fromNullishOr(kind.layers), Option.map(({ order }) => Array$1.join(order, ", ")), Option.getOrElse(() => ""), (names) => `is not a layer. Use one of ${names}.`);
|
|
2503
|
+
const looseMessage = (kind) => `sits directly in ${layersDir(kind)}/. Put it in a layer.`;
|
|
2504
|
+
const placementFindings = (compiled, path) => (within, kind) => pipe(compiled(kind), Array$1.filter((placement) => placement.files(within) && !placement.allow(within)), Array$1.map(({ message }) => atFile({
|
|
2505
|
+
path,
|
|
2506
|
+
rule: PLACEMENT,
|
|
2507
|
+
message
|
|
2508
|
+
})));
|
|
2509
|
+
const positionFindings = (path, { instance, position }) => {
|
|
2510
|
+
const { kind } = instance;
|
|
2511
|
+
if (position.type === "loose") return [atFile({
|
|
2512
|
+
path,
|
|
2513
|
+
rule: LOOSE_FILE,
|
|
2514
|
+
message: looseMessage(kind)
|
|
2515
|
+
})];
|
|
2516
|
+
if (position.type !== "unknownLayer") return [];
|
|
2517
|
+
const base = join(instance.dir)(join(layersDir(kind))(position.layer));
|
|
2518
|
+
const reported = Option.match(below(base)(path), {
|
|
2519
|
+
onNone: () => path,
|
|
2520
|
+
onSome: () => base
|
|
2521
|
+
});
|
|
2522
|
+
return [atFile({
|
|
2523
|
+
path: reported,
|
|
2524
|
+
rule: LAYER_NAME,
|
|
2525
|
+
message: layerMessage(kind)
|
|
2526
|
+
})];
|
|
2527
|
+
};
|
|
2528
|
+
const findingsAt = (layout, compiled) => (path) => pipe(layout.located(path), Array$1.flatMap((located) => {
|
|
2529
|
+
const own = (within) => Array$1.appendAll(placementFindings(compiled, path)(within, located.instance.kind), positionFindings(path, located));
|
|
2530
|
+
return Option.match(layout.inner(located.instance)(path), {
|
|
2531
|
+
onNone: () => [],
|
|
2532
|
+
onSome: own
|
|
2533
|
+
});
|
|
2534
|
+
}));
|
|
2535
|
+
const keyOf = ({ path, rule, message }) => `${path}\0${rule}\0${message}`;
|
|
2536
|
+
const checkPlacement = (layout) => {
|
|
2537
|
+
const compiled = new Map(pipe(layout.instances, Array$1.map(({ kind }) => [kind, compile(kind)])));
|
|
2538
|
+
const lookup = (kind) => compiled.get(kind) ?? [];
|
|
2539
|
+
const keyed = pipe(layout.files, Array$1.flatMap(findingsAt(layout, lookup)), Array$1.map((item) => [keyOf(item), item]));
|
|
2540
|
+
return [...new Map(keyed).values()];
|
|
2541
|
+
};
|
|
2542
|
+
// src/app/presets/preset.ts
|
|
2543
|
+
const STRUCTURE_PLUGIN = "structure";
|
|
2544
|
+
const DESCRIPTIONS = {
|
|
2545
|
+
[PLACEMENT]: "Each file sits where its kind allows",
|
|
2546
|
+
[LOOSE_FILE]: "No module sits directly in the layers directory",
|
|
2547
|
+
[LAYER_NAME]: "Each directory under the layers directory is a layer",
|
|
2548
|
+
[LAYER_IMPORT]: "A layer only uses the layers below it",
|
|
2549
|
+
[CROSS_SLICE]: "Slices of one layer do not use each other",
|
|
2550
|
+
[PUBLIC_API]: "Other slices are used through their entry file",
|
|
2551
|
+
[WILDCARD_EXPORT]: "An entry file names what it exports",
|
|
2552
|
+
[LINK_TARGET]: "A Markdown link points at a tracked file"
|
|
2553
|
+
};
|
|
2554
|
+
const ERROR = "error";
|
|
2555
|
+
const PRESETS = {
|
|
2556
|
+
fsd: [
|
|
2557
|
+
LAYER_NAME,
|
|
2558
|
+
LOOSE_FILE,
|
|
2559
|
+
LAYER_IMPORT,
|
|
2560
|
+
CROSS_SLICE,
|
|
2561
|
+
PUBLIC_API,
|
|
2562
|
+
WILDCARD_EXPORT
|
|
2563
|
+
],
|
|
2564
|
+
placement: [PLACEMENT],
|
|
2565
|
+
links: [LINK_TARGET]
|
|
2566
|
+
};
|
|
2567
|
+
const ALL = [
|
|
2568
|
+
"fsd",
|
|
2569
|
+
"placement",
|
|
2570
|
+
"links"
|
|
2571
|
+
];
|
|
2572
|
+
const analyze = (kinds) => {
|
|
2573
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
2574
|
+
const compute = (files, edges) => {
|
|
2575
|
+
const layout = makeLayout(kinds)(files);
|
|
2576
|
+
const grouped = Array$1.groupBy(Array$1.appendAll(checkPlacement(layout), checkImports(edges)(layout)), ({ rule }) => rule);
|
|
2577
|
+
cache.set(files, grouped);
|
|
2578
|
+
return grouped;
|
|
2579
|
+
};
|
|
2580
|
+
return (files, edges) => Option.getOrElse(Option.fromNullishOr(cache.get(files)), () => compute(files, edges));
|
|
2581
|
+
};
|
|
2582
|
+
const structurePlugin = (kinds) => {
|
|
2583
|
+
const findings = analyze(kinds);
|
|
2584
|
+
const ruleOf = (description, name) => defineRule({
|
|
2585
|
+
meta: { description },
|
|
2586
|
+
check: ({ files, edges, report }) => {
|
|
2587
|
+
for (const { path, line, column, message } of findings(files, edges)[name] ?? []) report({
|
|
2588
|
+
path,
|
|
2589
|
+
line,
|
|
2590
|
+
column,
|
|
2591
|
+
message
|
|
2592
|
+
});
|
|
2593
|
+
}
|
|
2594
|
+
});
|
|
2595
|
+
return definePlugin({ rules: pipe(DESCRIPTIONS, Record.map(ruleOf)) });
|
|
2596
|
+
};
|
|
2597
|
+
const rulesOf = (presets) => pipe(presets, Array$1.flatMap((name) => PRESETS[name]), Array$1.dedupe, Array$1.map((rule) => [`${STRUCTURE_PLUGIN}/${rule}`, ERROR]), Record.fromEntries);
|
|
2598
|
+
const structure = ({ kinds, presets = ALL, ignores }) => ({
|
|
2599
|
+
plugins: { [STRUCTURE_PLUGIN]: structurePlugin(kinds) },
|
|
2600
|
+
rules: rulesOf(presets),
|
|
2601
|
+
...Option.match(Option.fromNullishOr(ignores), {
|
|
2602
|
+
onNone: () => ({}),
|
|
2603
|
+
onSome: (value) => ({ ignores: value })
|
|
2604
|
+
})
|
|
2605
|
+
});
|
|
2606
|
+
export { FSD_LAYERS, PRESETS, STRUCTURE_PLUGIN, rustCrate, skill, structure, structurePlugin, workspace };
|
|
2607
|
+
|
|
2608
|
+
//# sourceMappingURL=presets.mjs.map
|