docs-ready 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-7YN54Y4Y.js +21 -0
- package/dist/chunk-7YN54Y4Y.js.map +1 -0
- package/dist/generate-56HFRN5I.js +2193 -0
- package/dist/generate-56HFRN5I.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +226 -0
- package/dist/index.js.map +1 -0
- package/package.json +65 -0
- package/templates/config.yaml.tmpl +31 -0
|
@@ -0,0 +1,2193 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
log,
|
|
4
|
+
spinner
|
|
5
|
+
} from "./chunk-7YN54Y4Y.js";
|
|
6
|
+
|
|
7
|
+
// src/cli/commands/generate.ts
|
|
8
|
+
import fs3 from "fs/promises";
|
|
9
|
+
import path5 from "path";
|
|
10
|
+
|
|
11
|
+
// src/core/config.ts
|
|
12
|
+
import fs from "fs/promises";
|
|
13
|
+
import path from "path";
|
|
14
|
+
import YAML from "yaml";
|
|
15
|
+
var DEFAULTS = {
|
|
16
|
+
docs: {
|
|
17
|
+
dir: "./docs",
|
|
18
|
+
include: ["**/*.md", "**/*.mdx"],
|
|
19
|
+
exclude: ["**/node_modules/**", "**/_*"]
|
|
20
|
+
},
|
|
21
|
+
generate: {
|
|
22
|
+
llms_txt: true,
|
|
23
|
+
llms_full_txt: true,
|
|
24
|
+
ai_context: true,
|
|
25
|
+
output_dir: "./build"
|
|
26
|
+
},
|
|
27
|
+
guard: {
|
|
28
|
+
npm_packages: [],
|
|
29
|
+
github_releases: [],
|
|
30
|
+
endpoints: [],
|
|
31
|
+
readme_scans: [],
|
|
32
|
+
workflow: {
|
|
33
|
+
enabled: true,
|
|
34
|
+
schedule: "0 9 */3 * *",
|
|
35
|
+
create_issues: true,
|
|
36
|
+
labels: ["ai-context-review", "documentation"]
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
deploy: {
|
|
40
|
+
platform: "none",
|
|
41
|
+
cors: { enabled: true, origins: ["*"] }
|
|
42
|
+
},
|
|
43
|
+
validate: {
|
|
44
|
+
max_tokens: 15e4,
|
|
45
|
+
check_links: true,
|
|
46
|
+
check_coverage: true,
|
|
47
|
+
coverage_threshold: 0.95
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var CONFIG_FILES = [
|
|
51
|
+
{ name: ".docs-ready.yaml", parser: "yaml" },
|
|
52
|
+
{ name: ".docs-ready.yml", parser: "yaml" },
|
|
53
|
+
{ name: ".docs-ready.json", parser: "json" },
|
|
54
|
+
{ name: ".docs-ready.toml", parser: "toml" }
|
|
55
|
+
];
|
|
56
|
+
async function loadConfig(dir, configPath) {
|
|
57
|
+
let raw;
|
|
58
|
+
if (configPath) {
|
|
59
|
+
const content = await fs.readFile(configPath, "utf-8");
|
|
60
|
+
raw = parseConfig(content, configPath);
|
|
61
|
+
} else {
|
|
62
|
+
for (const { name, parser } of CONFIG_FILES) {
|
|
63
|
+
const fullPath = path.join(dir, name);
|
|
64
|
+
try {
|
|
65
|
+
const content = await fs.readFile(fullPath, "utf-8");
|
|
66
|
+
if (parser === "toml") {
|
|
67
|
+
throw new Error("TOML support requires a TOML parser. Use .yaml or .json instead.");
|
|
68
|
+
}
|
|
69
|
+
raw = parseConfig(content, fullPath);
|
|
70
|
+
break;
|
|
71
|
+
} catch (err) {
|
|
72
|
+
if (err.code === "ENOENT") continue;
|
|
73
|
+
throw err;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (!raw) {
|
|
78
|
+
throw new Error(
|
|
79
|
+
"No config file found. Run `docs-ready init` to create one, or create .docs-ready.yaml manually."
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
validate(raw);
|
|
83
|
+
return applyDefaults(raw);
|
|
84
|
+
}
|
|
85
|
+
function parseConfig(content, filePath) {
|
|
86
|
+
if (filePath.endsWith(".json")) {
|
|
87
|
+
return JSON.parse(content);
|
|
88
|
+
}
|
|
89
|
+
const parsed = YAML.parse(content);
|
|
90
|
+
if (parsed === null || typeof parsed !== "object") {
|
|
91
|
+
throw new Error(`Failed to parse config file: ${filePath}`);
|
|
92
|
+
}
|
|
93
|
+
return parsed;
|
|
94
|
+
}
|
|
95
|
+
function validate(raw) {
|
|
96
|
+
const missing = [];
|
|
97
|
+
if (!raw.title || typeof raw.title !== "string") missing.push("title");
|
|
98
|
+
if (!raw.description || typeof raw.description !== "string") missing.push("description");
|
|
99
|
+
if (!raw.url || typeof raw.url !== "string") missing.push("url");
|
|
100
|
+
if (missing.length > 0) {
|
|
101
|
+
throw new Error(
|
|
102
|
+
`Missing required config fields: ${missing.join(", ")}. Add them to your .docs-ready.yaml file.`
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function applyDefaults(raw) {
|
|
107
|
+
const docs = raw.docs;
|
|
108
|
+
const generate = raw.generate;
|
|
109
|
+
const guard = raw.guard;
|
|
110
|
+
const deploy = raw.deploy;
|
|
111
|
+
const validateConf = raw.validate;
|
|
112
|
+
const guardWorkflow = guard?.workflow ?? {};
|
|
113
|
+
return {
|
|
114
|
+
title: raw.title,
|
|
115
|
+
description: raw.description,
|
|
116
|
+
url: raw.url,
|
|
117
|
+
docs: {
|
|
118
|
+
dir: docs?.dir ?? DEFAULTS.docs.dir,
|
|
119
|
+
include: docs?.include ?? DEFAULTS.docs.include,
|
|
120
|
+
exclude: docs?.exclude ?? DEFAULTS.docs.exclude
|
|
121
|
+
},
|
|
122
|
+
generate: {
|
|
123
|
+
llms_txt: generate?.llms_txt ?? DEFAULTS.generate.llms_txt,
|
|
124
|
+
llms_full_txt: generate?.llms_full_txt ?? DEFAULTS.generate.llms_full_txt,
|
|
125
|
+
ai_context: generate?.ai_context ?? DEFAULTS.generate.ai_context,
|
|
126
|
+
output_dir: generate?.output_dir ?? DEFAULTS.generate.output_dir,
|
|
127
|
+
sections: generate?.sections,
|
|
128
|
+
ai_context_config: generate?.ai_context_config
|
|
129
|
+
},
|
|
130
|
+
guard: {
|
|
131
|
+
npm_packages: guard?.npm_packages ?? DEFAULTS.guard.npm_packages,
|
|
132
|
+
github_releases: guard?.github_releases ?? DEFAULTS.guard.github_releases,
|
|
133
|
+
endpoints: guard?.endpoints ?? DEFAULTS.guard.endpoints,
|
|
134
|
+
readme_scans: guard?.readme_scans ?? DEFAULTS.guard.readme_scans,
|
|
135
|
+
workflow: {
|
|
136
|
+
enabled: guardWorkflow.enabled ?? DEFAULTS.guard.workflow.enabled,
|
|
137
|
+
schedule: guardWorkflow.schedule ?? DEFAULTS.guard.workflow.schedule,
|
|
138
|
+
create_issues: guardWorkflow.create_issues ?? DEFAULTS.guard.workflow.create_issues,
|
|
139
|
+
labels: guardWorkflow.labels ?? DEFAULTS.guard.workflow.labels
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
deploy: {
|
|
143
|
+
platform: deploy?.platform ?? DEFAULTS.deploy.platform,
|
|
144
|
+
cors: {
|
|
145
|
+
enabled: deploy?.cors?.enabled ?? DEFAULTS.deploy.cors.enabled,
|
|
146
|
+
origins: deploy?.cors?.origins ?? DEFAULTS.deploy.cors.origins
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
validate: {
|
|
150
|
+
max_tokens: validateConf?.max_tokens ?? DEFAULTS.validate.max_tokens,
|
|
151
|
+
check_links: validateConf?.check_links ?? DEFAULTS.validate.check_links,
|
|
152
|
+
check_coverage: validateConf?.check_coverage ?? DEFAULTS.validate.check_coverage,
|
|
153
|
+
coverage_threshold: validateConf?.coverage_threshold ?? DEFAULTS.validate.coverage_threshold
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// src/core/scanner.ts
|
|
159
|
+
import fs2 from "fs/promises";
|
|
160
|
+
import path2 from "path";
|
|
161
|
+
import matter from "gray-matter";
|
|
162
|
+
import { glob } from "glob";
|
|
163
|
+
async function scanDocs(docsDir, options) {
|
|
164
|
+
const resolvedDir = path2.resolve(docsDir);
|
|
165
|
+
const allFiles = [];
|
|
166
|
+
for (const pattern of options.include) {
|
|
167
|
+
const matches = await glob(pattern, {
|
|
168
|
+
cwd: resolvedDir,
|
|
169
|
+
ignore: options.exclude,
|
|
170
|
+
nodir: true,
|
|
171
|
+
absolute: false
|
|
172
|
+
});
|
|
173
|
+
allFiles.push(...matches);
|
|
174
|
+
}
|
|
175
|
+
const uniqueFiles = [...new Set(allFiles)];
|
|
176
|
+
const pages = [];
|
|
177
|
+
for (const relativePath of uniqueFiles) {
|
|
178
|
+
const filePath = path2.join(resolvedDir, relativePath);
|
|
179
|
+
const raw = await fs2.readFile(filePath, "utf-8");
|
|
180
|
+
const { data: frontmatter, content } = matter(raw);
|
|
181
|
+
const title = resolveTitle(frontmatter, content, relativePath);
|
|
182
|
+
const description = frontmatter.description ?? null;
|
|
183
|
+
pages.push({
|
|
184
|
+
filePath,
|
|
185
|
+
relativePath: relativePath.replace(/\\/g, "/"),
|
|
186
|
+
title,
|
|
187
|
+
description,
|
|
188
|
+
frontmatter,
|
|
189
|
+
content
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
pages.sort((a, b) => {
|
|
193
|
+
const posA = a.frontmatter.sidebar_position ?? Infinity;
|
|
194
|
+
const posB = b.frontmatter.sidebar_position ?? Infinity;
|
|
195
|
+
if (posA !== posB) return posA - posB;
|
|
196
|
+
return a.relativePath.localeCompare(b.relativePath);
|
|
197
|
+
});
|
|
198
|
+
return pages;
|
|
199
|
+
}
|
|
200
|
+
function resolveTitle(frontmatter, content, relativePath) {
|
|
201
|
+
if (typeof frontmatter.title === "string" && frontmatter.title.trim()) {
|
|
202
|
+
return frontmatter.title.trim();
|
|
203
|
+
}
|
|
204
|
+
const h1Match = content.match(/^#\s+(.+)$/m);
|
|
205
|
+
if (h1Match) {
|
|
206
|
+
return h1Match[1].trim();
|
|
207
|
+
}
|
|
208
|
+
const basename = path2.basename(relativePath, path2.extname(relativePath));
|
|
209
|
+
return basename.charAt(0).toUpperCase() + basename.slice(1).replace(/[-_]/g, " ");
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// src/generate/llms-txt.ts
|
|
213
|
+
import path4 from "path";
|
|
214
|
+
|
|
215
|
+
// node_modules/balanced-match/dist/esm/index.js
|
|
216
|
+
var balanced = (a, b, str) => {
|
|
217
|
+
const ma = a instanceof RegExp ? maybeMatch(a, str) : a;
|
|
218
|
+
const mb = b instanceof RegExp ? maybeMatch(b, str) : b;
|
|
219
|
+
const r = ma !== null && mb != null && range(ma, mb, str);
|
|
220
|
+
return r && {
|
|
221
|
+
start: r[0],
|
|
222
|
+
end: r[1],
|
|
223
|
+
pre: str.slice(0, r[0]),
|
|
224
|
+
body: str.slice(r[0] + ma.length, r[1]),
|
|
225
|
+
post: str.slice(r[1] + mb.length)
|
|
226
|
+
};
|
|
227
|
+
};
|
|
228
|
+
var maybeMatch = (reg, str) => {
|
|
229
|
+
const m = str.match(reg);
|
|
230
|
+
return m ? m[0] : null;
|
|
231
|
+
};
|
|
232
|
+
var range = (a, b, str) => {
|
|
233
|
+
let begs, beg, left, right = void 0, result;
|
|
234
|
+
let ai = str.indexOf(a);
|
|
235
|
+
let bi = str.indexOf(b, ai + 1);
|
|
236
|
+
let i = ai;
|
|
237
|
+
if (ai >= 0 && bi > 0) {
|
|
238
|
+
if (a === b) {
|
|
239
|
+
return [ai, bi];
|
|
240
|
+
}
|
|
241
|
+
begs = [];
|
|
242
|
+
left = str.length;
|
|
243
|
+
while (i >= 0 && !result) {
|
|
244
|
+
if (i === ai) {
|
|
245
|
+
begs.push(i);
|
|
246
|
+
ai = str.indexOf(a, i + 1);
|
|
247
|
+
} else if (begs.length === 1) {
|
|
248
|
+
const r = begs.pop();
|
|
249
|
+
if (r !== void 0)
|
|
250
|
+
result = [r, bi];
|
|
251
|
+
} else {
|
|
252
|
+
beg = begs.pop();
|
|
253
|
+
if (beg !== void 0 && beg < left) {
|
|
254
|
+
left = beg;
|
|
255
|
+
right = bi;
|
|
256
|
+
}
|
|
257
|
+
bi = str.indexOf(b, i + 1);
|
|
258
|
+
}
|
|
259
|
+
i = ai < bi && ai >= 0 ? ai : bi;
|
|
260
|
+
}
|
|
261
|
+
if (begs.length && right !== void 0) {
|
|
262
|
+
result = [left, right];
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return result;
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
// node_modules/brace-expansion/dist/esm/index.js
|
|
269
|
+
var escSlash = "\0SLASH" + Math.random() + "\0";
|
|
270
|
+
var escOpen = "\0OPEN" + Math.random() + "\0";
|
|
271
|
+
var escClose = "\0CLOSE" + Math.random() + "\0";
|
|
272
|
+
var escComma = "\0COMMA" + Math.random() + "\0";
|
|
273
|
+
var escPeriod = "\0PERIOD" + Math.random() + "\0";
|
|
274
|
+
var escSlashPattern = new RegExp(escSlash, "g");
|
|
275
|
+
var escOpenPattern = new RegExp(escOpen, "g");
|
|
276
|
+
var escClosePattern = new RegExp(escClose, "g");
|
|
277
|
+
var escCommaPattern = new RegExp(escComma, "g");
|
|
278
|
+
var escPeriodPattern = new RegExp(escPeriod, "g");
|
|
279
|
+
var slashPattern = /\\\\/g;
|
|
280
|
+
var openPattern = /\\{/g;
|
|
281
|
+
var closePattern = /\\}/g;
|
|
282
|
+
var commaPattern = /\\,/g;
|
|
283
|
+
var periodPattern = /\\\./g;
|
|
284
|
+
var EXPANSION_MAX = 1e5;
|
|
285
|
+
function numeric(str) {
|
|
286
|
+
return !isNaN(str) ? parseInt(str, 10) : str.charCodeAt(0);
|
|
287
|
+
}
|
|
288
|
+
function escapeBraces(str) {
|
|
289
|
+
return str.replace(slashPattern, escSlash).replace(openPattern, escOpen).replace(closePattern, escClose).replace(commaPattern, escComma).replace(periodPattern, escPeriod);
|
|
290
|
+
}
|
|
291
|
+
function unescapeBraces(str) {
|
|
292
|
+
return str.replace(escSlashPattern, "\\").replace(escOpenPattern, "{").replace(escClosePattern, "}").replace(escCommaPattern, ",").replace(escPeriodPattern, ".");
|
|
293
|
+
}
|
|
294
|
+
function parseCommaParts(str) {
|
|
295
|
+
if (!str) {
|
|
296
|
+
return [""];
|
|
297
|
+
}
|
|
298
|
+
const parts = [];
|
|
299
|
+
const m = balanced("{", "}", str);
|
|
300
|
+
if (!m) {
|
|
301
|
+
return str.split(",");
|
|
302
|
+
}
|
|
303
|
+
const { pre, body, post } = m;
|
|
304
|
+
const p = pre.split(",");
|
|
305
|
+
p[p.length - 1] += "{" + body + "}";
|
|
306
|
+
const postParts = parseCommaParts(post);
|
|
307
|
+
if (post.length) {
|
|
308
|
+
;
|
|
309
|
+
p[p.length - 1] += postParts.shift();
|
|
310
|
+
p.push.apply(p, postParts);
|
|
311
|
+
}
|
|
312
|
+
parts.push.apply(parts, p);
|
|
313
|
+
return parts;
|
|
314
|
+
}
|
|
315
|
+
function expand(str, options = {}) {
|
|
316
|
+
if (!str) {
|
|
317
|
+
return [];
|
|
318
|
+
}
|
|
319
|
+
const { max = EXPANSION_MAX } = options;
|
|
320
|
+
if (str.slice(0, 2) === "{}") {
|
|
321
|
+
str = "\\{\\}" + str.slice(2);
|
|
322
|
+
}
|
|
323
|
+
return expand_(escapeBraces(str), max, true).map(unescapeBraces);
|
|
324
|
+
}
|
|
325
|
+
function embrace(str) {
|
|
326
|
+
return "{" + str + "}";
|
|
327
|
+
}
|
|
328
|
+
function isPadded(el) {
|
|
329
|
+
return /^-?0\d/.test(el);
|
|
330
|
+
}
|
|
331
|
+
function lte(i, y) {
|
|
332
|
+
return i <= y;
|
|
333
|
+
}
|
|
334
|
+
function gte(i, y) {
|
|
335
|
+
return i >= y;
|
|
336
|
+
}
|
|
337
|
+
function expand_(str, max, isTop) {
|
|
338
|
+
const expansions = [];
|
|
339
|
+
const m = balanced("{", "}", str);
|
|
340
|
+
if (!m)
|
|
341
|
+
return [str];
|
|
342
|
+
const pre = m.pre;
|
|
343
|
+
const post = m.post.length ? expand_(m.post, max, false) : [""];
|
|
344
|
+
if (/\$$/.test(m.pre)) {
|
|
345
|
+
for (let k = 0; k < post.length && k < max; k++) {
|
|
346
|
+
const expansion = pre + "{" + m.body + "}" + post[k];
|
|
347
|
+
expansions.push(expansion);
|
|
348
|
+
}
|
|
349
|
+
} else {
|
|
350
|
+
const isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
|
|
351
|
+
const isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
|
|
352
|
+
const isSequence = isNumericSequence || isAlphaSequence;
|
|
353
|
+
const isOptions = m.body.indexOf(",") >= 0;
|
|
354
|
+
if (!isSequence && !isOptions) {
|
|
355
|
+
if (m.post.match(/,(?!,).*\}/)) {
|
|
356
|
+
str = m.pre + "{" + m.body + escClose + m.post;
|
|
357
|
+
return expand_(str, max, true);
|
|
358
|
+
}
|
|
359
|
+
return [str];
|
|
360
|
+
}
|
|
361
|
+
let n;
|
|
362
|
+
if (isSequence) {
|
|
363
|
+
n = m.body.split(/\.\./);
|
|
364
|
+
} else {
|
|
365
|
+
n = parseCommaParts(m.body);
|
|
366
|
+
if (n.length === 1 && n[0] !== void 0) {
|
|
367
|
+
n = expand_(n[0], max, false).map(embrace);
|
|
368
|
+
if (n.length === 1) {
|
|
369
|
+
return post.map((p) => m.pre + n[0] + p);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
let N;
|
|
374
|
+
if (isSequence && n[0] !== void 0 && n[1] !== void 0) {
|
|
375
|
+
const x = numeric(n[0]);
|
|
376
|
+
const y = numeric(n[1]);
|
|
377
|
+
const width = Math.max(n[0].length, n[1].length);
|
|
378
|
+
let incr = n.length === 3 && n[2] !== void 0 ? Math.max(Math.abs(numeric(n[2])), 1) : 1;
|
|
379
|
+
let test = lte;
|
|
380
|
+
const reverse = y < x;
|
|
381
|
+
if (reverse) {
|
|
382
|
+
incr *= -1;
|
|
383
|
+
test = gte;
|
|
384
|
+
}
|
|
385
|
+
const pad = n.some(isPadded);
|
|
386
|
+
N = [];
|
|
387
|
+
for (let i = x; test(i, y); i += incr) {
|
|
388
|
+
let c;
|
|
389
|
+
if (isAlphaSequence) {
|
|
390
|
+
c = String.fromCharCode(i);
|
|
391
|
+
if (c === "\\") {
|
|
392
|
+
c = "";
|
|
393
|
+
}
|
|
394
|
+
} else {
|
|
395
|
+
c = String(i);
|
|
396
|
+
if (pad) {
|
|
397
|
+
const need = width - c.length;
|
|
398
|
+
if (need > 0) {
|
|
399
|
+
const z = new Array(need + 1).join("0");
|
|
400
|
+
if (i < 0) {
|
|
401
|
+
c = "-" + z + c.slice(1);
|
|
402
|
+
} else {
|
|
403
|
+
c = z + c;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
N.push(c);
|
|
409
|
+
}
|
|
410
|
+
} else {
|
|
411
|
+
N = [];
|
|
412
|
+
for (let j = 0; j < n.length; j++) {
|
|
413
|
+
N.push.apply(N, expand_(n[j], max, false));
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
for (let j = 0; j < N.length; j++) {
|
|
417
|
+
for (let k = 0; k < post.length && expansions.length < max; k++) {
|
|
418
|
+
const expansion = pre + N[j] + post[k];
|
|
419
|
+
if (!isTop || isSequence || expansion) {
|
|
420
|
+
expansions.push(expansion);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return expansions;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// node_modules/minimatch/dist/esm/assert-valid-pattern.js
|
|
429
|
+
var MAX_PATTERN_LENGTH = 1024 * 64;
|
|
430
|
+
var assertValidPattern = (pattern) => {
|
|
431
|
+
if (typeof pattern !== "string") {
|
|
432
|
+
throw new TypeError("invalid pattern");
|
|
433
|
+
}
|
|
434
|
+
if (pattern.length > MAX_PATTERN_LENGTH) {
|
|
435
|
+
throw new TypeError("pattern is too long");
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
// node_modules/minimatch/dist/esm/brace-expressions.js
|
|
440
|
+
var posixClasses = {
|
|
441
|
+
"[:alnum:]": ["\\p{L}\\p{Nl}\\p{Nd}", true],
|
|
442
|
+
"[:alpha:]": ["\\p{L}\\p{Nl}", true],
|
|
443
|
+
"[:ascii:]": ["\\x00-\\x7f", false],
|
|
444
|
+
"[:blank:]": ["\\p{Zs}\\t", true],
|
|
445
|
+
"[:cntrl:]": ["\\p{Cc}", true],
|
|
446
|
+
"[:digit:]": ["\\p{Nd}", true],
|
|
447
|
+
"[:graph:]": ["\\p{Z}\\p{C}", true, true],
|
|
448
|
+
"[:lower:]": ["\\p{Ll}", true],
|
|
449
|
+
"[:print:]": ["\\p{C}", true],
|
|
450
|
+
"[:punct:]": ["\\p{P}", true],
|
|
451
|
+
"[:space:]": ["\\p{Z}\\t\\r\\n\\v\\f", true],
|
|
452
|
+
"[:upper:]": ["\\p{Lu}", true],
|
|
453
|
+
"[:word:]": ["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}", true],
|
|
454
|
+
"[:xdigit:]": ["A-Fa-f0-9", false]
|
|
455
|
+
};
|
|
456
|
+
var braceEscape = (s) => s.replace(/[[\]\\-]/g, "\\$&");
|
|
457
|
+
var regexpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
458
|
+
var rangesToString = (ranges) => ranges.join("");
|
|
459
|
+
var parseClass = (glob2, position) => {
|
|
460
|
+
const pos = position;
|
|
461
|
+
if (glob2.charAt(pos) !== "[") {
|
|
462
|
+
throw new Error("not in a brace expression");
|
|
463
|
+
}
|
|
464
|
+
const ranges = [];
|
|
465
|
+
const negs = [];
|
|
466
|
+
let i = pos + 1;
|
|
467
|
+
let sawStart = false;
|
|
468
|
+
let uflag = false;
|
|
469
|
+
let escaping = false;
|
|
470
|
+
let negate = false;
|
|
471
|
+
let endPos = pos;
|
|
472
|
+
let rangeStart = "";
|
|
473
|
+
WHILE: while (i < glob2.length) {
|
|
474
|
+
const c = glob2.charAt(i);
|
|
475
|
+
if ((c === "!" || c === "^") && i === pos + 1) {
|
|
476
|
+
negate = true;
|
|
477
|
+
i++;
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
if (c === "]" && sawStart && !escaping) {
|
|
481
|
+
endPos = i + 1;
|
|
482
|
+
break;
|
|
483
|
+
}
|
|
484
|
+
sawStart = true;
|
|
485
|
+
if (c === "\\") {
|
|
486
|
+
if (!escaping) {
|
|
487
|
+
escaping = true;
|
|
488
|
+
i++;
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
if (c === "[" && !escaping) {
|
|
493
|
+
for (const [cls, [unip, u, neg]] of Object.entries(posixClasses)) {
|
|
494
|
+
if (glob2.startsWith(cls, i)) {
|
|
495
|
+
if (rangeStart) {
|
|
496
|
+
return ["$.", false, glob2.length - pos, true];
|
|
497
|
+
}
|
|
498
|
+
i += cls.length;
|
|
499
|
+
if (neg)
|
|
500
|
+
negs.push(unip);
|
|
501
|
+
else
|
|
502
|
+
ranges.push(unip);
|
|
503
|
+
uflag = uflag || u;
|
|
504
|
+
continue WHILE;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
escaping = false;
|
|
509
|
+
if (rangeStart) {
|
|
510
|
+
if (c > rangeStart) {
|
|
511
|
+
ranges.push(braceEscape(rangeStart) + "-" + braceEscape(c));
|
|
512
|
+
} else if (c === rangeStart) {
|
|
513
|
+
ranges.push(braceEscape(c));
|
|
514
|
+
}
|
|
515
|
+
rangeStart = "";
|
|
516
|
+
i++;
|
|
517
|
+
continue;
|
|
518
|
+
}
|
|
519
|
+
if (glob2.startsWith("-]", i + 1)) {
|
|
520
|
+
ranges.push(braceEscape(c + "-"));
|
|
521
|
+
i += 2;
|
|
522
|
+
continue;
|
|
523
|
+
}
|
|
524
|
+
if (glob2.startsWith("-", i + 1)) {
|
|
525
|
+
rangeStart = c;
|
|
526
|
+
i += 2;
|
|
527
|
+
continue;
|
|
528
|
+
}
|
|
529
|
+
ranges.push(braceEscape(c));
|
|
530
|
+
i++;
|
|
531
|
+
}
|
|
532
|
+
if (endPos < i) {
|
|
533
|
+
return ["", false, 0, false];
|
|
534
|
+
}
|
|
535
|
+
if (!ranges.length && !negs.length) {
|
|
536
|
+
return ["$.", false, glob2.length - pos, true];
|
|
537
|
+
}
|
|
538
|
+
if (negs.length === 0 && ranges.length === 1 && /^\\?.$/.test(ranges[0]) && !negate) {
|
|
539
|
+
const r = ranges[0].length === 2 ? ranges[0].slice(-1) : ranges[0];
|
|
540
|
+
return [regexpEscape(r), false, endPos - pos, false];
|
|
541
|
+
}
|
|
542
|
+
const sranges = "[" + (negate ? "^" : "") + rangesToString(ranges) + "]";
|
|
543
|
+
const snegs = "[" + (negate ? "" : "^") + rangesToString(negs) + "]";
|
|
544
|
+
const comb = ranges.length && negs.length ? "(" + sranges + "|" + snegs + ")" : ranges.length ? sranges : snegs;
|
|
545
|
+
return [comb, uflag, endPos - pos, true];
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
// node_modules/minimatch/dist/esm/unescape.js
|
|
549
|
+
var unescape = (s, { windowsPathsNoEscape = false, magicalBraces = true } = {}) => {
|
|
550
|
+
if (magicalBraces) {
|
|
551
|
+
return windowsPathsNoEscape ? s.replace(/\[([^/\\])\]/g, "$1") : s.replace(/((?!\\).|^)\[([^/\\])\]/g, "$1$2").replace(/\\([^/])/g, "$1");
|
|
552
|
+
}
|
|
553
|
+
return windowsPathsNoEscape ? s.replace(/\[([^/\\{}])\]/g, "$1") : s.replace(/((?!\\).|^)\[([^/\\{}])\]/g, "$1$2").replace(/\\([^/{}])/g, "$1");
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
// node_modules/minimatch/dist/esm/ast.js
|
|
557
|
+
var _a;
|
|
558
|
+
var types = /* @__PURE__ */ new Set(["!", "?", "+", "*", "@"]);
|
|
559
|
+
var isExtglobType = (c) => types.has(c);
|
|
560
|
+
var isExtglobAST = (c) => isExtglobType(c.type);
|
|
561
|
+
var adoptionMap = /* @__PURE__ */ new Map([
|
|
562
|
+
["!", ["@"]],
|
|
563
|
+
["?", ["?", "@"]],
|
|
564
|
+
["@", ["@"]],
|
|
565
|
+
["*", ["*", "+", "?", "@"]],
|
|
566
|
+
["+", ["+", "@"]]
|
|
567
|
+
]);
|
|
568
|
+
var adoptionWithSpaceMap = /* @__PURE__ */ new Map([
|
|
569
|
+
["!", ["?"]],
|
|
570
|
+
["@", ["?"]],
|
|
571
|
+
["+", ["?", "*"]]
|
|
572
|
+
]);
|
|
573
|
+
var adoptionAnyMap = /* @__PURE__ */ new Map([
|
|
574
|
+
["!", ["?", "@"]],
|
|
575
|
+
["?", ["?", "@"]],
|
|
576
|
+
["@", ["?", "@"]],
|
|
577
|
+
["*", ["*", "+", "?", "@"]],
|
|
578
|
+
["+", ["+", "@", "?", "*"]]
|
|
579
|
+
]);
|
|
580
|
+
var usurpMap = /* @__PURE__ */ new Map([
|
|
581
|
+
["!", /* @__PURE__ */ new Map([["!", "@"]])],
|
|
582
|
+
[
|
|
583
|
+
"?",
|
|
584
|
+
/* @__PURE__ */ new Map([
|
|
585
|
+
["*", "*"],
|
|
586
|
+
["+", "*"]
|
|
587
|
+
])
|
|
588
|
+
],
|
|
589
|
+
[
|
|
590
|
+
"@",
|
|
591
|
+
/* @__PURE__ */ new Map([
|
|
592
|
+
["!", "!"],
|
|
593
|
+
["?", "?"],
|
|
594
|
+
["@", "@"],
|
|
595
|
+
["*", "*"],
|
|
596
|
+
["+", "+"]
|
|
597
|
+
])
|
|
598
|
+
],
|
|
599
|
+
[
|
|
600
|
+
"+",
|
|
601
|
+
/* @__PURE__ */ new Map([
|
|
602
|
+
["?", "*"],
|
|
603
|
+
["*", "*"]
|
|
604
|
+
])
|
|
605
|
+
]
|
|
606
|
+
]);
|
|
607
|
+
var startNoTraversal = "(?!(?:^|/)\\.\\.?(?:$|/))";
|
|
608
|
+
var startNoDot = "(?!\\.)";
|
|
609
|
+
var addPatternStart = /* @__PURE__ */ new Set(["[", "."]);
|
|
610
|
+
var justDots = /* @__PURE__ */ new Set(["..", "."]);
|
|
611
|
+
var reSpecials = new Set("().*{}+?[]^$\\!");
|
|
612
|
+
var regExpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
613
|
+
var qmark = "[^/]";
|
|
614
|
+
var star = qmark + "*?";
|
|
615
|
+
var starNoEmpty = qmark + "+?";
|
|
616
|
+
var ID = 0;
|
|
617
|
+
var AST = class {
|
|
618
|
+
type;
|
|
619
|
+
#root;
|
|
620
|
+
#hasMagic;
|
|
621
|
+
#uflag = false;
|
|
622
|
+
#parts = [];
|
|
623
|
+
#parent;
|
|
624
|
+
#parentIndex;
|
|
625
|
+
#negs;
|
|
626
|
+
#filledNegs = false;
|
|
627
|
+
#options;
|
|
628
|
+
#toString;
|
|
629
|
+
// set to true if it's an extglob with no children
|
|
630
|
+
// (which really means one child of '')
|
|
631
|
+
#emptyExt = false;
|
|
632
|
+
id = ++ID;
|
|
633
|
+
get depth() {
|
|
634
|
+
return (this.#parent?.depth ?? -1) + 1;
|
|
635
|
+
}
|
|
636
|
+
[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
|
|
637
|
+
return {
|
|
638
|
+
"@@type": "AST",
|
|
639
|
+
id: this.id,
|
|
640
|
+
type: this.type,
|
|
641
|
+
root: this.#root.id,
|
|
642
|
+
parent: this.#parent?.id,
|
|
643
|
+
depth: this.depth,
|
|
644
|
+
partsLength: this.#parts.length,
|
|
645
|
+
parts: this.#parts
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
constructor(type, parent, options = {}) {
|
|
649
|
+
this.type = type;
|
|
650
|
+
if (type)
|
|
651
|
+
this.#hasMagic = true;
|
|
652
|
+
this.#parent = parent;
|
|
653
|
+
this.#root = this.#parent ? this.#parent.#root : this;
|
|
654
|
+
this.#options = this.#root === this ? options : this.#root.#options;
|
|
655
|
+
this.#negs = this.#root === this ? [] : this.#root.#negs;
|
|
656
|
+
if (type === "!" && !this.#root.#filledNegs)
|
|
657
|
+
this.#negs.push(this);
|
|
658
|
+
this.#parentIndex = this.#parent ? this.#parent.#parts.length : 0;
|
|
659
|
+
}
|
|
660
|
+
get hasMagic() {
|
|
661
|
+
if (this.#hasMagic !== void 0)
|
|
662
|
+
return this.#hasMagic;
|
|
663
|
+
for (const p of this.#parts) {
|
|
664
|
+
if (typeof p === "string")
|
|
665
|
+
continue;
|
|
666
|
+
if (p.type || p.hasMagic)
|
|
667
|
+
return this.#hasMagic = true;
|
|
668
|
+
}
|
|
669
|
+
return this.#hasMagic;
|
|
670
|
+
}
|
|
671
|
+
// reconstructs the pattern
|
|
672
|
+
toString() {
|
|
673
|
+
return this.#toString !== void 0 ? this.#toString : !this.type ? this.#toString = this.#parts.map((p) => String(p)).join("") : this.#toString = this.type + "(" + this.#parts.map((p) => String(p)).join("|") + ")";
|
|
674
|
+
}
|
|
675
|
+
#fillNegs() {
|
|
676
|
+
if (this !== this.#root)
|
|
677
|
+
throw new Error("should only call on root");
|
|
678
|
+
if (this.#filledNegs)
|
|
679
|
+
return this;
|
|
680
|
+
this.toString();
|
|
681
|
+
this.#filledNegs = true;
|
|
682
|
+
let n;
|
|
683
|
+
while (n = this.#negs.pop()) {
|
|
684
|
+
if (n.type !== "!")
|
|
685
|
+
continue;
|
|
686
|
+
let p = n;
|
|
687
|
+
let pp = p.#parent;
|
|
688
|
+
while (pp) {
|
|
689
|
+
for (let i = p.#parentIndex + 1; !pp.type && i < pp.#parts.length; i++) {
|
|
690
|
+
for (const part of n.#parts) {
|
|
691
|
+
if (typeof part === "string") {
|
|
692
|
+
throw new Error("string part in extglob AST??");
|
|
693
|
+
}
|
|
694
|
+
part.copyIn(pp.#parts[i]);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
p = pp;
|
|
698
|
+
pp = p.#parent;
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
return this;
|
|
702
|
+
}
|
|
703
|
+
push(...parts) {
|
|
704
|
+
for (const p of parts) {
|
|
705
|
+
if (p === "")
|
|
706
|
+
continue;
|
|
707
|
+
if (typeof p !== "string" && !(p instanceof _a && p.#parent === this)) {
|
|
708
|
+
throw new Error("invalid part: " + p);
|
|
709
|
+
}
|
|
710
|
+
this.#parts.push(p);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
toJSON() {
|
|
714
|
+
const ret = this.type === null ? this.#parts.slice().map((p) => typeof p === "string" ? p : p.toJSON()) : [this.type, ...this.#parts.map((p) => p.toJSON())];
|
|
715
|
+
if (this.isStart() && !this.type)
|
|
716
|
+
ret.unshift([]);
|
|
717
|
+
if (this.isEnd() && (this === this.#root || this.#root.#filledNegs && this.#parent?.type === "!")) {
|
|
718
|
+
ret.push({});
|
|
719
|
+
}
|
|
720
|
+
return ret;
|
|
721
|
+
}
|
|
722
|
+
isStart() {
|
|
723
|
+
if (this.#root === this)
|
|
724
|
+
return true;
|
|
725
|
+
if (!this.#parent?.isStart())
|
|
726
|
+
return false;
|
|
727
|
+
if (this.#parentIndex === 0)
|
|
728
|
+
return true;
|
|
729
|
+
const p = this.#parent;
|
|
730
|
+
for (let i = 0; i < this.#parentIndex; i++) {
|
|
731
|
+
const pp = p.#parts[i];
|
|
732
|
+
if (!(pp instanceof _a && pp.type === "!")) {
|
|
733
|
+
return false;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
return true;
|
|
737
|
+
}
|
|
738
|
+
isEnd() {
|
|
739
|
+
if (this.#root === this)
|
|
740
|
+
return true;
|
|
741
|
+
if (this.#parent?.type === "!")
|
|
742
|
+
return true;
|
|
743
|
+
if (!this.#parent?.isEnd())
|
|
744
|
+
return false;
|
|
745
|
+
if (!this.type)
|
|
746
|
+
return this.#parent?.isEnd();
|
|
747
|
+
const pl = this.#parent ? this.#parent.#parts.length : 0;
|
|
748
|
+
return this.#parentIndex === pl - 1;
|
|
749
|
+
}
|
|
750
|
+
copyIn(part) {
|
|
751
|
+
if (typeof part === "string")
|
|
752
|
+
this.push(part);
|
|
753
|
+
else
|
|
754
|
+
this.push(part.clone(this));
|
|
755
|
+
}
|
|
756
|
+
clone(parent) {
|
|
757
|
+
const c = new _a(this.type, parent);
|
|
758
|
+
for (const p of this.#parts) {
|
|
759
|
+
c.copyIn(p);
|
|
760
|
+
}
|
|
761
|
+
return c;
|
|
762
|
+
}
|
|
763
|
+
static #parseAST(str, ast, pos, opt, extDepth) {
|
|
764
|
+
const maxDepth = opt.maxExtglobRecursion ?? 2;
|
|
765
|
+
let escaping = false;
|
|
766
|
+
let inBrace = false;
|
|
767
|
+
let braceStart = -1;
|
|
768
|
+
let braceNeg = false;
|
|
769
|
+
if (ast.type === null) {
|
|
770
|
+
let i2 = pos;
|
|
771
|
+
let acc2 = "";
|
|
772
|
+
while (i2 < str.length) {
|
|
773
|
+
const c = str.charAt(i2++);
|
|
774
|
+
if (escaping || c === "\\") {
|
|
775
|
+
escaping = !escaping;
|
|
776
|
+
acc2 += c;
|
|
777
|
+
continue;
|
|
778
|
+
}
|
|
779
|
+
if (inBrace) {
|
|
780
|
+
if (i2 === braceStart + 1) {
|
|
781
|
+
if (c === "^" || c === "!") {
|
|
782
|
+
braceNeg = true;
|
|
783
|
+
}
|
|
784
|
+
} else if (c === "]" && !(i2 === braceStart + 2 && braceNeg)) {
|
|
785
|
+
inBrace = false;
|
|
786
|
+
}
|
|
787
|
+
acc2 += c;
|
|
788
|
+
continue;
|
|
789
|
+
} else if (c === "[") {
|
|
790
|
+
inBrace = true;
|
|
791
|
+
braceStart = i2;
|
|
792
|
+
braceNeg = false;
|
|
793
|
+
acc2 += c;
|
|
794
|
+
continue;
|
|
795
|
+
}
|
|
796
|
+
const doRecurse = !opt.noext && isExtglobType(c) && str.charAt(i2) === "(" && extDepth <= maxDepth;
|
|
797
|
+
if (doRecurse) {
|
|
798
|
+
ast.push(acc2);
|
|
799
|
+
acc2 = "";
|
|
800
|
+
const ext2 = new _a(c, ast);
|
|
801
|
+
i2 = _a.#parseAST(str, ext2, i2, opt, extDepth + 1);
|
|
802
|
+
ast.push(ext2);
|
|
803
|
+
continue;
|
|
804
|
+
}
|
|
805
|
+
acc2 += c;
|
|
806
|
+
}
|
|
807
|
+
ast.push(acc2);
|
|
808
|
+
return i2;
|
|
809
|
+
}
|
|
810
|
+
let i = pos + 1;
|
|
811
|
+
let part = new _a(null, ast);
|
|
812
|
+
const parts = [];
|
|
813
|
+
let acc = "";
|
|
814
|
+
while (i < str.length) {
|
|
815
|
+
const c = str.charAt(i++);
|
|
816
|
+
if (escaping || c === "\\") {
|
|
817
|
+
escaping = !escaping;
|
|
818
|
+
acc += c;
|
|
819
|
+
continue;
|
|
820
|
+
}
|
|
821
|
+
if (inBrace) {
|
|
822
|
+
if (i === braceStart + 1) {
|
|
823
|
+
if (c === "^" || c === "!") {
|
|
824
|
+
braceNeg = true;
|
|
825
|
+
}
|
|
826
|
+
} else if (c === "]" && !(i === braceStart + 2 && braceNeg)) {
|
|
827
|
+
inBrace = false;
|
|
828
|
+
}
|
|
829
|
+
acc += c;
|
|
830
|
+
continue;
|
|
831
|
+
} else if (c === "[") {
|
|
832
|
+
inBrace = true;
|
|
833
|
+
braceStart = i;
|
|
834
|
+
braceNeg = false;
|
|
835
|
+
acc += c;
|
|
836
|
+
continue;
|
|
837
|
+
}
|
|
838
|
+
const doRecurse = !opt.noext && isExtglobType(c) && str.charAt(i) === "(" && /* c8 ignore start - the maxDepth is sufficient here */
|
|
839
|
+
(extDepth <= maxDepth || ast && ast.#canAdoptType(c));
|
|
840
|
+
if (doRecurse) {
|
|
841
|
+
const depthAdd = ast && ast.#canAdoptType(c) ? 0 : 1;
|
|
842
|
+
part.push(acc);
|
|
843
|
+
acc = "";
|
|
844
|
+
const ext2 = new _a(c, part);
|
|
845
|
+
part.push(ext2);
|
|
846
|
+
i = _a.#parseAST(str, ext2, i, opt, extDepth + depthAdd);
|
|
847
|
+
continue;
|
|
848
|
+
}
|
|
849
|
+
if (c === "|") {
|
|
850
|
+
part.push(acc);
|
|
851
|
+
acc = "";
|
|
852
|
+
parts.push(part);
|
|
853
|
+
part = new _a(null, ast);
|
|
854
|
+
continue;
|
|
855
|
+
}
|
|
856
|
+
if (c === ")") {
|
|
857
|
+
if (acc === "" && ast.#parts.length === 0) {
|
|
858
|
+
ast.#emptyExt = true;
|
|
859
|
+
}
|
|
860
|
+
part.push(acc);
|
|
861
|
+
acc = "";
|
|
862
|
+
ast.push(...parts, part);
|
|
863
|
+
return i;
|
|
864
|
+
}
|
|
865
|
+
acc += c;
|
|
866
|
+
}
|
|
867
|
+
ast.type = null;
|
|
868
|
+
ast.#hasMagic = void 0;
|
|
869
|
+
ast.#parts = [str.substring(pos - 1)];
|
|
870
|
+
return i;
|
|
871
|
+
}
|
|
872
|
+
#canAdoptWithSpace(child) {
|
|
873
|
+
return this.#canAdopt(child, adoptionWithSpaceMap);
|
|
874
|
+
}
|
|
875
|
+
#canAdopt(child, map = adoptionMap) {
|
|
876
|
+
if (!child || typeof child !== "object" || child.type !== null || child.#parts.length !== 1 || this.type === null) {
|
|
877
|
+
return false;
|
|
878
|
+
}
|
|
879
|
+
const gc = child.#parts[0];
|
|
880
|
+
if (!gc || typeof gc !== "object" || gc.type === null) {
|
|
881
|
+
return false;
|
|
882
|
+
}
|
|
883
|
+
return this.#canAdoptType(gc.type, map);
|
|
884
|
+
}
|
|
885
|
+
#canAdoptType(c, map = adoptionAnyMap) {
|
|
886
|
+
return !!map.get(this.type)?.includes(c);
|
|
887
|
+
}
|
|
888
|
+
#adoptWithSpace(child, index) {
|
|
889
|
+
const gc = child.#parts[0];
|
|
890
|
+
const blank = new _a(null, gc, this.options);
|
|
891
|
+
blank.#parts.push("");
|
|
892
|
+
gc.push(blank);
|
|
893
|
+
this.#adopt(child, index);
|
|
894
|
+
}
|
|
895
|
+
#adopt(child, index) {
|
|
896
|
+
const gc = child.#parts[0];
|
|
897
|
+
this.#parts.splice(index, 1, ...gc.#parts);
|
|
898
|
+
for (const p of gc.#parts) {
|
|
899
|
+
if (typeof p === "object")
|
|
900
|
+
p.#parent = this;
|
|
901
|
+
}
|
|
902
|
+
this.#toString = void 0;
|
|
903
|
+
}
|
|
904
|
+
#canUsurpType(c) {
|
|
905
|
+
const m = usurpMap.get(this.type);
|
|
906
|
+
return !!m?.has(c);
|
|
907
|
+
}
|
|
908
|
+
#canUsurp(child) {
|
|
909
|
+
if (!child || typeof child !== "object" || child.type !== null || child.#parts.length !== 1 || this.type === null || this.#parts.length !== 1) {
|
|
910
|
+
return false;
|
|
911
|
+
}
|
|
912
|
+
const gc = child.#parts[0];
|
|
913
|
+
if (!gc || typeof gc !== "object" || gc.type === null) {
|
|
914
|
+
return false;
|
|
915
|
+
}
|
|
916
|
+
return this.#canUsurpType(gc.type);
|
|
917
|
+
}
|
|
918
|
+
#usurp(child) {
|
|
919
|
+
const m = usurpMap.get(this.type);
|
|
920
|
+
const gc = child.#parts[0];
|
|
921
|
+
const nt = m?.get(gc.type);
|
|
922
|
+
if (!nt)
|
|
923
|
+
return false;
|
|
924
|
+
this.#parts = gc.#parts;
|
|
925
|
+
for (const p of this.#parts) {
|
|
926
|
+
if (typeof p === "object") {
|
|
927
|
+
p.#parent = this;
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
this.type = nt;
|
|
931
|
+
this.#toString = void 0;
|
|
932
|
+
this.#emptyExt = false;
|
|
933
|
+
}
|
|
934
|
+
static fromGlob(pattern, options = {}) {
|
|
935
|
+
const ast = new _a(null, void 0, options);
|
|
936
|
+
_a.#parseAST(pattern, ast, 0, options, 0);
|
|
937
|
+
return ast;
|
|
938
|
+
}
|
|
939
|
+
// returns the regular expression if there's magic, or the unescaped
|
|
940
|
+
// string if not.
|
|
941
|
+
toMMPattern() {
|
|
942
|
+
if (this !== this.#root)
|
|
943
|
+
return this.#root.toMMPattern();
|
|
944
|
+
const glob2 = this.toString();
|
|
945
|
+
const [re, body, hasMagic, uflag] = this.toRegExpSource();
|
|
946
|
+
const anyMagic = hasMagic || this.#hasMagic || this.#options.nocase && !this.#options.nocaseMagicOnly && glob2.toUpperCase() !== glob2.toLowerCase();
|
|
947
|
+
if (!anyMagic) {
|
|
948
|
+
return body;
|
|
949
|
+
}
|
|
950
|
+
const flags = (this.#options.nocase ? "i" : "") + (uflag ? "u" : "");
|
|
951
|
+
return Object.assign(new RegExp(`^${re}$`, flags), {
|
|
952
|
+
_src: re,
|
|
953
|
+
_glob: glob2
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
get options() {
|
|
957
|
+
return this.#options;
|
|
958
|
+
}
|
|
959
|
+
// returns the string match, the regexp source, whether there's magic
|
|
960
|
+
// in the regexp (so a regular expression is required) and whether or
|
|
961
|
+
// not the uflag is needed for the regular expression (for posix classes)
|
|
962
|
+
// TODO: instead of injecting the start/end at this point, just return
|
|
963
|
+
// the BODY of the regexp, along with the start/end portions suitable
|
|
964
|
+
// for binding the start/end in either a joined full-path makeRe context
|
|
965
|
+
// (where we bind to (^|/), or a standalone matchPart context (where
|
|
966
|
+
// we bind to ^, and not /). Otherwise slashes get duped!
|
|
967
|
+
//
|
|
968
|
+
// In part-matching mode, the start is:
|
|
969
|
+
// - if not isStart: nothing
|
|
970
|
+
// - if traversal possible, but not allowed: ^(?!\.\.?$)
|
|
971
|
+
// - if dots allowed or not possible: ^
|
|
972
|
+
// - if dots possible and not allowed: ^(?!\.)
|
|
973
|
+
// end is:
|
|
974
|
+
// - if not isEnd(): nothing
|
|
975
|
+
// - else: $
|
|
976
|
+
//
|
|
977
|
+
// In full-path matching mode, we put the slash at the START of the
|
|
978
|
+
// pattern, so start is:
|
|
979
|
+
// - if first pattern: same as part-matching mode
|
|
980
|
+
// - if not isStart(): nothing
|
|
981
|
+
// - if traversal possible, but not allowed: /(?!\.\.?(?:$|/))
|
|
982
|
+
// - if dots allowed or not possible: /
|
|
983
|
+
// - if dots possible and not allowed: /(?!\.)
|
|
984
|
+
// end is:
|
|
985
|
+
// - if last pattern, same as part-matching mode
|
|
986
|
+
// - else nothing
|
|
987
|
+
//
|
|
988
|
+
// Always put the (?:$|/) on negated tails, though, because that has to be
|
|
989
|
+
// there to bind the end of the negated pattern portion, and it's easier to
|
|
990
|
+
// just stick it in now rather than try to inject it later in the middle of
|
|
991
|
+
// the pattern.
|
|
992
|
+
//
|
|
993
|
+
// We can just always return the same end, and leave it up to the caller
|
|
994
|
+
// to know whether it's going to be used joined or in parts.
|
|
995
|
+
// And, if the start is adjusted slightly, can do the same there:
|
|
996
|
+
// - if not isStart: nothing
|
|
997
|
+
// - if traversal possible, but not allowed: (?:/|^)(?!\.\.?$)
|
|
998
|
+
// - if dots allowed or not possible: (?:/|^)
|
|
999
|
+
// - if dots possible and not allowed: (?:/|^)(?!\.)
|
|
1000
|
+
//
|
|
1001
|
+
// But it's better to have a simpler binding without a conditional, for
|
|
1002
|
+
// performance, so probably better to return both start options.
|
|
1003
|
+
//
|
|
1004
|
+
// Then the caller just ignores the end if it's not the first pattern,
|
|
1005
|
+
// and the start always gets applied.
|
|
1006
|
+
//
|
|
1007
|
+
// But that's always going to be $ if it's the ending pattern, or nothing,
|
|
1008
|
+
// so the caller can just attach $ at the end of the pattern when building.
|
|
1009
|
+
//
|
|
1010
|
+
// So the todo is:
|
|
1011
|
+
// - better detect what kind of start is needed
|
|
1012
|
+
// - return both flavors of starting pattern
|
|
1013
|
+
// - attach $ at the end of the pattern when creating the actual RegExp
|
|
1014
|
+
//
|
|
1015
|
+
// Ah, but wait, no, that all only applies to the root when the first pattern
|
|
1016
|
+
// is not an extglob. If the first pattern IS an extglob, then we need all
|
|
1017
|
+
// that dot prevention biz to live in the extglob portions, because eg
|
|
1018
|
+
// +(*|.x*) can match .xy but not .yx.
|
|
1019
|
+
//
|
|
1020
|
+
// So, return the two flavors if it's #root and the first child is not an
|
|
1021
|
+
// AST, otherwise leave it to the child AST to handle it, and there,
|
|
1022
|
+
// use the (?:^|/) style of start binding.
|
|
1023
|
+
//
|
|
1024
|
+
// Even simplified further:
|
|
1025
|
+
// - Since the start for a join is eg /(?!\.) and the start for a part
|
|
1026
|
+
// is ^(?!\.), we can just prepend (?!\.) to the pattern (either root
|
|
1027
|
+
// or start or whatever) and prepend ^ or / at the Regexp construction.
|
|
1028
|
+
toRegExpSource(allowDot) {
|
|
1029
|
+
const dot = allowDot ?? !!this.#options.dot;
|
|
1030
|
+
if (this.#root === this) {
|
|
1031
|
+
this.#flatten();
|
|
1032
|
+
this.#fillNegs();
|
|
1033
|
+
}
|
|
1034
|
+
if (!isExtglobAST(this)) {
|
|
1035
|
+
const noEmpty = this.isStart() && this.isEnd() && !this.#parts.some((s) => typeof s !== "string");
|
|
1036
|
+
const src = this.#parts.map((p) => {
|
|
1037
|
+
const [re, _, hasMagic, uflag] = typeof p === "string" ? _a.#parseGlob(p, this.#hasMagic, noEmpty) : p.toRegExpSource(allowDot);
|
|
1038
|
+
this.#hasMagic = this.#hasMagic || hasMagic;
|
|
1039
|
+
this.#uflag = this.#uflag || uflag;
|
|
1040
|
+
return re;
|
|
1041
|
+
}).join("");
|
|
1042
|
+
let start2 = "";
|
|
1043
|
+
if (this.isStart()) {
|
|
1044
|
+
if (typeof this.#parts[0] === "string") {
|
|
1045
|
+
const dotTravAllowed = this.#parts.length === 1 && justDots.has(this.#parts[0]);
|
|
1046
|
+
if (!dotTravAllowed) {
|
|
1047
|
+
const aps = addPatternStart;
|
|
1048
|
+
const needNoTrav = (
|
|
1049
|
+
// dots are allowed, and the pattern starts with [ or .
|
|
1050
|
+
dot && aps.has(src.charAt(0)) || // the pattern starts with \., and then [ or .
|
|
1051
|
+
src.startsWith("\\.") && aps.has(src.charAt(2)) || // the pattern starts with \.\., and then [ or .
|
|
1052
|
+
src.startsWith("\\.\\.") && aps.has(src.charAt(4))
|
|
1053
|
+
);
|
|
1054
|
+
const needNoDot = !dot && !allowDot && aps.has(src.charAt(0));
|
|
1055
|
+
start2 = needNoTrav ? startNoTraversal : needNoDot ? startNoDot : "";
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
let end = "";
|
|
1060
|
+
if (this.isEnd() && this.#root.#filledNegs && this.#parent?.type === "!") {
|
|
1061
|
+
end = "(?:$|\\/)";
|
|
1062
|
+
}
|
|
1063
|
+
const final2 = start2 + src + end;
|
|
1064
|
+
return [
|
|
1065
|
+
final2,
|
|
1066
|
+
unescape(src),
|
|
1067
|
+
this.#hasMagic = !!this.#hasMagic,
|
|
1068
|
+
this.#uflag
|
|
1069
|
+
];
|
|
1070
|
+
}
|
|
1071
|
+
const repeated = this.type === "*" || this.type === "+";
|
|
1072
|
+
const start = this.type === "!" ? "(?:(?!(?:" : "(?:";
|
|
1073
|
+
let body = this.#partsToRegExp(dot);
|
|
1074
|
+
if (this.isStart() && this.isEnd() && !body && this.type !== "!") {
|
|
1075
|
+
const s = this.toString();
|
|
1076
|
+
const me = this;
|
|
1077
|
+
me.#parts = [s];
|
|
1078
|
+
me.type = null;
|
|
1079
|
+
me.#hasMagic = void 0;
|
|
1080
|
+
return [s, unescape(this.toString()), false, false];
|
|
1081
|
+
}
|
|
1082
|
+
let bodyDotAllowed = !repeated || allowDot || dot || !startNoDot ? "" : this.#partsToRegExp(true);
|
|
1083
|
+
if (bodyDotAllowed === body) {
|
|
1084
|
+
bodyDotAllowed = "";
|
|
1085
|
+
}
|
|
1086
|
+
if (bodyDotAllowed) {
|
|
1087
|
+
body = `(?:${body})(?:${bodyDotAllowed})*?`;
|
|
1088
|
+
}
|
|
1089
|
+
let final = "";
|
|
1090
|
+
if (this.type === "!" && this.#emptyExt) {
|
|
1091
|
+
final = (this.isStart() && !dot ? startNoDot : "") + starNoEmpty;
|
|
1092
|
+
} else {
|
|
1093
|
+
const close = this.type === "!" ? (
|
|
1094
|
+
// !() must match something,but !(x) can match ''
|
|
1095
|
+
"))" + (this.isStart() && !dot && !allowDot ? startNoDot : "") + star + ")"
|
|
1096
|
+
) : this.type === "@" ? ")" : this.type === "?" ? ")?" : this.type === "+" && bodyDotAllowed ? ")" : this.type === "*" && bodyDotAllowed ? `)?` : `)${this.type}`;
|
|
1097
|
+
final = start + body + close;
|
|
1098
|
+
}
|
|
1099
|
+
return [
|
|
1100
|
+
final,
|
|
1101
|
+
unescape(body),
|
|
1102
|
+
this.#hasMagic = !!this.#hasMagic,
|
|
1103
|
+
this.#uflag
|
|
1104
|
+
];
|
|
1105
|
+
}
|
|
1106
|
+
#flatten() {
|
|
1107
|
+
if (!isExtglobAST(this)) {
|
|
1108
|
+
for (const p of this.#parts) {
|
|
1109
|
+
if (typeof p === "object") {
|
|
1110
|
+
p.#flatten();
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
} else {
|
|
1114
|
+
let iterations = 0;
|
|
1115
|
+
let done = false;
|
|
1116
|
+
do {
|
|
1117
|
+
done = true;
|
|
1118
|
+
for (let i = 0; i < this.#parts.length; i++) {
|
|
1119
|
+
const c = this.#parts[i];
|
|
1120
|
+
if (typeof c === "object") {
|
|
1121
|
+
c.#flatten();
|
|
1122
|
+
if (this.#canAdopt(c)) {
|
|
1123
|
+
done = false;
|
|
1124
|
+
this.#adopt(c, i);
|
|
1125
|
+
} else if (this.#canAdoptWithSpace(c)) {
|
|
1126
|
+
done = false;
|
|
1127
|
+
this.#adoptWithSpace(c, i);
|
|
1128
|
+
} else if (this.#canUsurp(c)) {
|
|
1129
|
+
done = false;
|
|
1130
|
+
this.#usurp(c);
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
} while (!done && ++iterations < 10);
|
|
1135
|
+
}
|
|
1136
|
+
this.#toString = void 0;
|
|
1137
|
+
}
|
|
1138
|
+
#partsToRegExp(dot) {
|
|
1139
|
+
return this.#parts.map((p) => {
|
|
1140
|
+
if (typeof p === "string") {
|
|
1141
|
+
throw new Error("string type in extglob ast??");
|
|
1142
|
+
}
|
|
1143
|
+
const [re, _, _hasMagic, uflag] = p.toRegExpSource(dot);
|
|
1144
|
+
this.#uflag = this.#uflag || uflag;
|
|
1145
|
+
return re;
|
|
1146
|
+
}).filter((p) => !(this.isStart() && this.isEnd()) || !!p).join("|");
|
|
1147
|
+
}
|
|
1148
|
+
static #parseGlob(glob2, hasMagic, noEmpty = false) {
|
|
1149
|
+
let escaping = false;
|
|
1150
|
+
let re = "";
|
|
1151
|
+
let uflag = false;
|
|
1152
|
+
let inStar = false;
|
|
1153
|
+
for (let i = 0; i < glob2.length; i++) {
|
|
1154
|
+
const c = glob2.charAt(i);
|
|
1155
|
+
if (escaping) {
|
|
1156
|
+
escaping = false;
|
|
1157
|
+
re += (reSpecials.has(c) ? "\\" : "") + c;
|
|
1158
|
+
continue;
|
|
1159
|
+
}
|
|
1160
|
+
if (c === "*") {
|
|
1161
|
+
if (inStar)
|
|
1162
|
+
continue;
|
|
1163
|
+
inStar = true;
|
|
1164
|
+
re += noEmpty && /^[*]+$/.test(glob2) ? starNoEmpty : star;
|
|
1165
|
+
hasMagic = true;
|
|
1166
|
+
continue;
|
|
1167
|
+
} else {
|
|
1168
|
+
inStar = false;
|
|
1169
|
+
}
|
|
1170
|
+
if (c === "\\") {
|
|
1171
|
+
if (i === glob2.length - 1) {
|
|
1172
|
+
re += "\\\\";
|
|
1173
|
+
} else {
|
|
1174
|
+
escaping = true;
|
|
1175
|
+
}
|
|
1176
|
+
continue;
|
|
1177
|
+
}
|
|
1178
|
+
if (c === "[") {
|
|
1179
|
+
const [src, needUflag, consumed, magic] = parseClass(glob2, i);
|
|
1180
|
+
if (consumed) {
|
|
1181
|
+
re += src;
|
|
1182
|
+
uflag = uflag || needUflag;
|
|
1183
|
+
i += consumed - 1;
|
|
1184
|
+
hasMagic = hasMagic || magic;
|
|
1185
|
+
continue;
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
if (c === "?") {
|
|
1189
|
+
re += qmark;
|
|
1190
|
+
hasMagic = true;
|
|
1191
|
+
continue;
|
|
1192
|
+
}
|
|
1193
|
+
re += regExpEscape(c);
|
|
1194
|
+
}
|
|
1195
|
+
return [re, unescape(glob2), !!hasMagic, uflag];
|
|
1196
|
+
}
|
|
1197
|
+
};
|
|
1198
|
+
_a = AST;
|
|
1199
|
+
|
|
1200
|
+
// node_modules/minimatch/dist/esm/escape.js
|
|
1201
|
+
var escape = (s, { windowsPathsNoEscape = false, magicalBraces = false } = {}) => {
|
|
1202
|
+
if (magicalBraces) {
|
|
1203
|
+
return windowsPathsNoEscape ? s.replace(/[?*()[\]{}]/g, "[$&]") : s.replace(/[?*()[\]\\{}]/g, "\\$&");
|
|
1204
|
+
}
|
|
1205
|
+
return windowsPathsNoEscape ? s.replace(/[?*()[\]]/g, "[$&]") : s.replace(/[?*()[\]\\]/g, "\\$&");
|
|
1206
|
+
};
|
|
1207
|
+
|
|
1208
|
+
// node_modules/minimatch/dist/esm/index.js
|
|
1209
|
+
var minimatch = (p, pattern, options = {}) => {
|
|
1210
|
+
assertValidPattern(pattern);
|
|
1211
|
+
if (!options.nocomment && pattern.charAt(0) === "#") {
|
|
1212
|
+
return false;
|
|
1213
|
+
}
|
|
1214
|
+
return new Minimatch(pattern, options).match(p);
|
|
1215
|
+
};
|
|
1216
|
+
var starDotExtRE = /^\*+([^+@!?*[(]*)$/;
|
|
1217
|
+
var starDotExtTest = (ext2) => (f) => !f.startsWith(".") && f.endsWith(ext2);
|
|
1218
|
+
var starDotExtTestDot = (ext2) => (f) => f.endsWith(ext2);
|
|
1219
|
+
var starDotExtTestNocase = (ext2) => {
|
|
1220
|
+
ext2 = ext2.toLowerCase();
|
|
1221
|
+
return (f) => !f.startsWith(".") && f.toLowerCase().endsWith(ext2);
|
|
1222
|
+
};
|
|
1223
|
+
var starDotExtTestNocaseDot = (ext2) => {
|
|
1224
|
+
ext2 = ext2.toLowerCase();
|
|
1225
|
+
return (f) => f.toLowerCase().endsWith(ext2);
|
|
1226
|
+
};
|
|
1227
|
+
var starDotStarRE = /^\*+\.\*+$/;
|
|
1228
|
+
var starDotStarTest = (f) => !f.startsWith(".") && f.includes(".");
|
|
1229
|
+
var starDotStarTestDot = (f) => f !== "." && f !== ".." && f.includes(".");
|
|
1230
|
+
var dotStarRE = /^\.\*+$/;
|
|
1231
|
+
var dotStarTest = (f) => f !== "." && f !== ".." && f.startsWith(".");
|
|
1232
|
+
var starRE = /^\*+$/;
|
|
1233
|
+
var starTest = (f) => f.length !== 0 && !f.startsWith(".");
|
|
1234
|
+
var starTestDot = (f) => f.length !== 0 && f !== "." && f !== "..";
|
|
1235
|
+
var qmarksRE = /^\?+([^+@!?*[(]*)?$/;
|
|
1236
|
+
var qmarksTestNocase = ([$0, ext2 = ""]) => {
|
|
1237
|
+
const noext = qmarksTestNoExt([$0]);
|
|
1238
|
+
if (!ext2)
|
|
1239
|
+
return noext;
|
|
1240
|
+
ext2 = ext2.toLowerCase();
|
|
1241
|
+
return (f) => noext(f) && f.toLowerCase().endsWith(ext2);
|
|
1242
|
+
};
|
|
1243
|
+
var qmarksTestNocaseDot = ([$0, ext2 = ""]) => {
|
|
1244
|
+
const noext = qmarksTestNoExtDot([$0]);
|
|
1245
|
+
if (!ext2)
|
|
1246
|
+
return noext;
|
|
1247
|
+
ext2 = ext2.toLowerCase();
|
|
1248
|
+
return (f) => noext(f) && f.toLowerCase().endsWith(ext2);
|
|
1249
|
+
};
|
|
1250
|
+
var qmarksTestDot = ([$0, ext2 = ""]) => {
|
|
1251
|
+
const noext = qmarksTestNoExtDot([$0]);
|
|
1252
|
+
return !ext2 ? noext : (f) => noext(f) && f.endsWith(ext2);
|
|
1253
|
+
};
|
|
1254
|
+
var qmarksTest = ([$0, ext2 = ""]) => {
|
|
1255
|
+
const noext = qmarksTestNoExt([$0]);
|
|
1256
|
+
return !ext2 ? noext : (f) => noext(f) && f.endsWith(ext2);
|
|
1257
|
+
};
|
|
1258
|
+
var qmarksTestNoExt = ([$0]) => {
|
|
1259
|
+
const len = $0.length;
|
|
1260
|
+
return (f) => f.length === len && !f.startsWith(".");
|
|
1261
|
+
};
|
|
1262
|
+
var qmarksTestNoExtDot = ([$0]) => {
|
|
1263
|
+
const len = $0.length;
|
|
1264
|
+
return (f) => f.length === len && f !== "." && f !== "..";
|
|
1265
|
+
};
|
|
1266
|
+
var defaultPlatform = typeof process === "object" && process ? typeof process.env === "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix";
|
|
1267
|
+
var path3 = {
|
|
1268
|
+
win32: { sep: "\\" },
|
|
1269
|
+
posix: { sep: "/" }
|
|
1270
|
+
};
|
|
1271
|
+
var sep = defaultPlatform === "win32" ? path3.win32.sep : path3.posix.sep;
|
|
1272
|
+
minimatch.sep = sep;
|
|
1273
|
+
var GLOBSTAR = /* @__PURE__ */ Symbol("globstar **");
|
|
1274
|
+
minimatch.GLOBSTAR = GLOBSTAR;
|
|
1275
|
+
var qmark2 = "[^/]";
|
|
1276
|
+
var star2 = qmark2 + "*?";
|
|
1277
|
+
var twoStarDot = "(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?";
|
|
1278
|
+
var twoStarNoDot = "(?:(?!(?:\\/|^)\\.).)*?";
|
|
1279
|
+
var filter = (pattern, options = {}) => (p) => minimatch(p, pattern, options);
|
|
1280
|
+
minimatch.filter = filter;
|
|
1281
|
+
var ext = (a, b = {}) => Object.assign({}, a, b);
|
|
1282
|
+
var defaults = (def) => {
|
|
1283
|
+
if (!def || typeof def !== "object" || !Object.keys(def).length) {
|
|
1284
|
+
return minimatch;
|
|
1285
|
+
}
|
|
1286
|
+
const orig = minimatch;
|
|
1287
|
+
const m = (p, pattern, options = {}) => orig(p, pattern, ext(def, options));
|
|
1288
|
+
return Object.assign(m, {
|
|
1289
|
+
Minimatch: class Minimatch extends orig.Minimatch {
|
|
1290
|
+
constructor(pattern, options = {}) {
|
|
1291
|
+
super(pattern, ext(def, options));
|
|
1292
|
+
}
|
|
1293
|
+
static defaults(options) {
|
|
1294
|
+
return orig.defaults(ext(def, options)).Minimatch;
|
|
1295
|
+
}
|
|
1296
|
+
},
|
|
1297
|
+
AST: class AST extends orig.AST {
|
|
1298
|
+
/* c8 ignore start */
|
|
1299
|
+
constructor(type, parent, options = {}) {
|
|
1300
|
+
super(type, parent, ext(def, options));
|
|
1301
|
+
}
|
|
1302
|
+
/* c8 ignore stop */
|
|
1303
|
+
static fromGlob(pattern, options = {}) {
|
|
1304
|
+
return orig.AST.fromGlob(pattern, ext(def, options));
|
|
1305
|
+
}
|
|
1306
|
+
},
|
|
1307
|
+
unescape: (s, options = {}) => orig.unescape(s, ext(def, options)),
|
|
1308
|
+
escape: (s, options = {}) => orig.escape(s, ext(def, options)),
|
|
1309
|
+
filter: (pattern, options = {}) => orig.filter(pattern, ext(def, options)),
|
|
1310
|
+
defaults: (options) => orig.defaults(ext(def, options)),
|
|
1311
|
+
makeRe: (pattern, options = {}) => orig.makeRe(pattern, ext(def, options)),
|
|
1312
|
+
braceExpand: (pattern, options = {}) => orig.braceExpand(pattern, ext(def, options)),
|
|
1313
|
+
match: (list, pattern, options = {}) => orig.match(list, pattern, ext(def, options)),
|
|
1314
|
+
sep: orig.sep,
|
|
1315
|
+
GLOBSTAR
|
|
1316
|
+
});
|
|
1317
|
+
};
|
|
1318
|
+
minimatch.defaults = defaults;
|
|
1319
|
+
var braceExpand = (pattern, options = {}) => {
|
|
1320
|
+
assertValidPattern(pattern);
|
|
1321
|
+
if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) {
|
|
1322
|
+
return [pattern];
|
|
1323
|
+
}
|
|
1324
|
+
return expand(pattern, { max: options.braceExpandMax });
|
|
1325
|
+
};
|
|
1326
|
+
minimatch.braceExpand = braceExpand;
|
|
1327
|
+
var makeRe = (pattern, options = {}) => new Minimatch(pattern, options).makeRe();
|
|
1328
|
+
minimatch.makeRe = makeRe;
|
|
1329
|
+
var match = (list, pattern, options = {}) => {
|
|
1330
|
+
const mm = new Minimatch(pattern, options);
|
|
1331
|
+
list = list.filter((f) => mm.match(f));
|
|
1332
|
+
if (mm.options.nonull && !list.length) {
|
|
1333
|
+
list.push(pattern);
|
|
1334
|
+
}
|
|
1335
|
+
return list;
|
|
1336
|
+
};
|
|
1337
|
+
minimatch.match = match;
|
|
1338
|
+
var globMagic = /[?*]|[+@!]\(.*?\)|\[|\]/;
|
|
1339
|
+
var regExpEscape2 = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
1340
|
+
var Minimatch = class {
|
|
1341
|
+
options;
|
|
1342
|
+
set;
|
|
1343
|
+
pattern;
|
|
1344
|
+
windowsPathsNoEscape;
|
|
1345
|
+
nonegate;
|
|
1346
|
+
negate;
|
|
1347
|
+
comment;
|
|
1348
|
+
empty;
|
|
1349
|
+
preserveMultipleSlashes;
|
|
1350
|
+
partial;
|
|
1351
|
+
globSet;
|
|
1352
|
+
globParts;
|
|
1353
|
+
nocase;
|
|
1354
|
+
isWindows;
|
|
1355
|
+
platform;
|
|
1356
|
+
windowsNoMagicRoot;
|
|
1357
|
+
maxGlobstarRecursion;
|
|
1358
|
+
regexp;
|
|
1359
|
+
constructor(pattern, options = {}) {
|
|
1360
|
+
assertValidPattern(pattern);
|
|
1361
|
+
options = options || {};
|
|
1362
|
+
this.options = options;
|
|
1363
|
+
this.maxGlobstarRecursion = options.maxGlobstarRecursion ?? 200;
|
|
1364
|
+
this.pattern = pattern;
|
|
1365
|
+
this.platform = options.platform || defaultPlatform;
|
|
1366
|
+
this.isWindows = this.platform === "win32";
|
|
1367
|
+
const awe = "allowWindowsEscape";
|
|
1368
|
+
this.windowsPathsNoEscape = !!options.windowsPathsNoEscape || options[awe] === false;
|
|
1369
|
+
if (this.windowsPathsNoEscape) {
|
|
1370
|
+
this.pattern = this.pattern.replace(/\\/g, "/");
|
|
1371
|
+
}
|
|
1372
|
+
this.preserveMultipleSlashes = !!options.preserveMultipleSlashes;
|
|
1373
|
+
this.regexp = null;
|
|
1374
|
+
this.negate = false;
|
|
1375
|
+
this.nonegate = !!options.nonegate;
|
|
1376
|
+
this.comment = false;
|
|
1377
|
+
this.empty = false;
|
|
1378
|
+
this.partial = !!options.partial;
|
|
1379
|
+
this.nocase = !!this.options.nocase;
|
|
1380
|
+
this.windowsNoMagicRoot = options.windowsNoMagicRoot !== void 0 ? options.windowsNoMagicRoot : !!(this.isWindows && this.nocase);
|
|
1381
|
+
this.globSet = [];
|
|
1382
|
+
this.globParts = [];
|
|
1383
|
+
this.set = [];
|
|
1384
|
+
this.make();
|
|
1385
|
+
}
|
|
1386
|
+
hasMagic() {
|
|
1387
|
+
if (this.options.magicalBraces && this.set.length > 1) {
|
|
1388
|
+
return true;
|
|
1389
|
+
}
|
|
1390
|
+
for (const pattern of this.set) {
|
|
1391
|
+
for (const part of pattern) {
|
|
1392
|
+
if (typeof part !== "string")
|
|
1393
|
+
return true;
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
return false;
|
|
1397
|
+
}
|
|
1398
|
+
debug(..._) {
|
|
1399
|
+
}
|
|
1400
|
+
make() {
|
|
1401
|
+
const pattern = this.pattern;
|
|
1402
|
+
const options = this.options;
|
|
1403
|
+
if (!options.nocomment && pattern.charAt(0) === "#") {
|
|
1404
|
+
this.comment = true;
|
|
1405
|
+
return;
|
|
1406
|
+
}
|
|
1407
|
+
if (!pattern) {
|
|
1408
|
+
this.empty = true;
|
|
1409
|
+
return;
|
|
1410
|
+
}
|
|
1411
|
+
this.parseNegate();
|
|
1412
|
+
this.globSet = [...new Set(this.braceExpand())];
|
|
1413
|
+
if (options.debug) {
|
|
1414
|
+
this.debug = (...args) => console.error(...args);
|
|
1415
|
+
}
|
|
1416
|
+
this.debug(this.pattern, this.globSet);
|
|
1417
|
+
const rawGlobParts = this.globSet.map((s) => this.slashSplit(s));
|
|
1418
|
+
this.globParts = this.preprocess(rawGlobParts);
|
|
1419
|
+
this.debug(this.pattern, this.globParts);
|
|
1420
|
+
let set = this.globParts.map((s, _, __) => {
|
|
1421
|
+
if (this.isWindows && this.windowsNoMagicRoot) {
|
|
1422
|
+
const isUNC = s[0] === "" && s[1] === "" && (s[2] === "?" || !globMagic.test(s[2])) && !globMagic.test(s[3]);
|
|
1423
|
+
const isDrive = /^[a-z]:/i.test(s[0]);
|
|
1424
|
+
if (isUNC) {
|
|
1425
|
+
return [
|
|
1426
|
+
...s.slice(0, 4),
|
|
1427
|
+
...s.slice(4).map((ss) => this.parse(ss))
|
|
1428
|
+
];
|
|
1429
|
+
} else if (isDrive) {
|
|
1430
|
+
return [s[0], ...s.slice(1).map((ss) => this.parse(ss))];
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
return s.map((ss) => this.parse(ss));
|
|
1434
|
+
});
|
|
1435
|
+
this.debug(this.pattern, set);
|
|
1436
|
+
this.set = set.filter((s) => s.indexOf(false) === -1);
|
|
1437
|
+
if (this.isWindows) {
|
|
1438
|
+
for (let i = 0; i < this.set.length; i++) {
|
|
1439
|
+
const p = this.set[i];
|
|
1440
|
+
if (p[0] === "" && p[1] === "" && this.globParts[i][2] === "?" && typeof p[3] === "string" && /^[a-z]:$/i.test(p[3])) {
|
|
1441
|
+
p[2] = "?";
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
this.debug(this.pattern, this.set);
|
|
1446
|
+
}
|
|
1447
|
+
// various transforms to equivalent pattern sets that are
|
|
1448
|
+
// faster to process in a filesystem walk. The goal is to
|
|
1449
|
+
// eliminate what we can, and push all ** patterns as far
|
|
1450
|
+
// to the right as possible, even if it increases the number
|
|
1451
|
+
// of patterns that we have to process.
|
|
1452
|
+
preprocess(globParts) {
|
|
1453
|
+
if (this.options.noglobstar) {
|
|
1454
|
+
for (const partset of globParts) {
|
|
1455
|
+
for (let j = 0; j < partset.length; j++) {
|
|
1456
|
+
if (partset[j] === "**") {
|
|
1457
|
+
partset[j] = "*";
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
const { optimizationLevel = 1 } = this.options;
|
|
1463
|
+
if (optimizationLevel >= 2) {
|
|
1464
|
+
globParts = this.firstPhasePreProcess(globParts);
|
|
1465
|
+
globParts = this.secondPhasePreProcess(globParts);
|
|
1466
|
+
} else if (optimizationLevel >= 1) {
|
|
1467
|
+
globParts = this.levelOneOptimize(globParts);
|
|
1468
|
+
} else {
|
|
1469
|
+
globParts = this.adjascentGlobstarOptimize(globParts);
|
|
1470
|
+
}
|
|
1471
|
+
return globParts;
|
|
1472
|
+
}
|
|
1473
|
+
// just get rid of adjascent ** portions
|
|
1474
|
+
adjascentGlobstarOptimize(globParts) {
|
|
1475
|
+
return globParts.map((parts) => {
|
|
1476
|
+
let gs = -1;
|
|
1477
|
+
while (-1 !== (gs = parts.indexOf("**", gs + 1))) {
|
|
1478
|
+
let i = gs;
|
|
1479
|
+
while (parts[i + 1] === "**") {
|
|
1480
|
+
i++;
|
|
1481
|
+
}
|
|
1482
|
+
if (i !== gs) {
|
|
1483
|
+
parts.splice(gs, i - gs);
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
return parts;
|
|
1487
|
+
});
|
|
1488
|
+
}
|
|
1489
|
+
// get rid of adjascent ** and resolve .. portions
|
|
1490
|
+
levelOneOptimize(globParts) {
|
|
1491
|
+
return globParts.map((parts) => {
|
|
1492
|
+
parts = parts.reduce((set, part) => {
|
|
1493
|
+
const prev = set[set.length - 1];
|
|
1494
|
+
if (part === "**" && prev === "**") {
|
|
1495
|
+
return set;
|
|
1496
|
+
}
|
|
1497
|
+
if (part === "..") {
|
|
1498
|
+
if (prev && prev !== ".." && prev !== "." && prev !== "**") {
|
|
1499
|
+
set.pop();
|
|
1500
|
+
return set;
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
set.push(part);
|
|
1504
|
+
return set;
|
|
1505
|
+
}, []);
|
|
1506
|
+
return parts.length === 0 ? [""] : parts;
|
|
1507
|
+
});
|
|
1508
|
+
}
|
|
1509
|
+
levelTwoFileOptimize(parts) {
|
|
1510
|
+
if (!Array.isArray(parts)) {
|
|
1511
|
+
parts = this.slashSplit(parts);
|
|
1512
|
+
}
|
|
1513
|
+
let didSomething = false;
|
|
1514
|
+
do {
|
|
1515
|
+
didSomething = false;
|
|
1516
|
+
if (!this.preserveMultipleSlashes) {
|
|
1517
|
+
for (let i = 1; i < parts.length - 1; i++) {
|
|
1518
|
+
const p = parts[i];
|
|
1519
|
+
if (i === 1 && p === "" && parts[0] === "")
|
|
1520
|
+
continue;
|
|
1521
|
+
if (p === "." || p === "") {
|
|
1522
|
+
didSomething = true;
|
|
1523
|
+
parts.splice(i, 1);
|
|
1524
|
+
i--;
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
if (parts[0] === "." && parts.length === 2 && (parts[1] === "." || parts[1] === "")) {
|
|
1528
|
+
didSomething = true;
|
|
1529
|
+
parts.pop();
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
let dd = 0;
|
|
1533
|
+
while (-1 !== (dd = parts.indexOf("..", dd + 1))) {
|
|
1534
|
+
const p = parts[dd - 1];
|
|
1535
|
+
if (p && p !== "." && p !== ".." && p !== "**" && !(this.isWindows && /^[a-z]:$/i.test(p))) {
|
|
1536
|
+
didSomething = true;
|
|
1537
|
+
parts.splice(dd - 1, 2);
|
|
1538
|
+
dd -= 2;
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
} while (didSomething);
|
|
1542
|
+
return parts.length === 0 ? [""] : parts;
|
|
1543
|
+
}
|
|
1544
|
+
// First phase: single-pattern processing
|
|
1545
|
+
// <pre> is 1 or more portions
|
|
1546
|
+
// <rest> is 1 or more portions
|
|
1547
|
+
// <p> is any portion other than ., .., '', or **
|
|
1548
|
+
// <e> is . or ''
|
|
1549
|
+
//
|
|
1550
|
+
// **/.. is *brutal* for filesystem walking performance, because
|
|
1551
|
+
// it effectively resets the recursive walk each time it occurs,
|
|
1552
|
+
// and ** cannot be reduced out by a .. pattern part like a regexp
|
|
1553
|
+
// or most strings (other than .., ., and '') can be.
|
|
1554
|
+
//
|
|
1555
|
+
// <pre>/**/../<p>/<p>/<rest> -> {<pre>/../<p>/<p>/<rest>,<pre>/**/<p>/<p>/<rest>}
|
|
1556
|
+
// <pre>/<e>/<rest> -> <pre>/<rest>
|
|
1557
|
+
// <pre>/<p>/../<rest> -> <pre>/<rest>
|
|
1558
|
+
// **/**/<rest> -> **/<rest>
|
|
1559
|
+
//
|
|
1560
|
+
// **/*/<rest> -> */**/<rest> <== not valid because ** doesn't follow
|
|
1561
|
+
// this WOULD be allowed if ** did follow symlinks, or * didn't
|
|
1562
|
+
firstPhasePreProcess(globParts) {
|
|
1563
|
+
let didSomething = false;
|
|
1564
|
+
do {
|
|
1565
|
+
didSomething = false;
|
|
1566
|
+
for (let parts of globParts) {
|
|
1567
|
+
let gs = -1;
|
|
1568
|
+
while (-1 !== (gs = parts.indexOf("**", gs + 1))) {
|
|
1569
|
+
let gss = gs;
|
|
1570
|
+
while (parts[gss + 1] === "**") {
|
|
1571
|
+
gss++;
|
|
1572
|
+
}
|
|
1573
|
+
if (gss > gs) {
|
|
1574
|
+
parts.splice(gs + 1, gss - gs);
|
|
1575
|
+
}
|
|
1576
|
+
let next = parts[gs + 1];
|
|
1577
|
+
const p = parts[gs + 2];
|
|
1578
|
+
const p2 = parts[gs + 3];
|
|
1579
|
+
if (next !== "..")
|
|
1580
|
+
continue;
|
|
1581
|
+
if (!p || p === "." || p === ".." || !p2 || p2 === "." || p2 === "..") {
|
|
1582
|
+
continue;
|
|
1583
|
+
}
|
|
1584
|
+
didSomething = true;
|
|
1585
|
+
parts.splice(gs, 1);
|
|
1586
|
+
const other = parts.slice(0);
|
|
1587
|
+
other[gs] = "**";
|
|
1588
|
+
globParts.push(other);
|
|
1589
|
+
gs--;
|
|
1590
|
+
}
|
|
1591
|
+
if (!this.preserveMultipleSlashes) {
|
|
1592
|
+
for (let i = 1; i < parts.length - 1; i++) {
|
|
1593
|
+
const p = parts[i];
|
|
1594
|
+
if (i === 1 && p === "" && parts[0] === "")
|
|
1595
|
+
continue;
|
|
1596
|
+
if (p === "." || p === "") {
|
|
1597
|
+
didSomething = true;
|
|
1598
|
+
parts.splice(i, 1);
|
|
1599
|
+
i--;
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
if (parts[0] === "." && parts.length === 2 && (parts[1] === "." || parts[1] === "")) {
|
|
1603
|
+
didSomething = true;
|
|
1604
|
+
parts.pop();
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
let dd = 0;
|
|
1608
|
+
while (-1 !== (dd = parts.indexOf("..", dd + 1))) {
|
|
1609
|
+
const p = parts[dd - 1];
|
|
1610
|
+
if (p && p !== "." && p !== ".." && p !== "**") {
|
|
1611
|
+
didSomething = true;
|
|
1612
|
+
const needDot = dd === 1 && parts[dd + 1] === "**";
|
|
1613
|
+
const splin = needDot ? ["."] : [];
|
|
1614
|
+
parts.splice(dd - 1, 2, ...splin);
|
|
1615
|
+
if (parts.length === 0)
|
|
1616
|
+
parts.push("");
|
|
1617
|
+
dd -= 2;
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
} while (didSomething);
|
|
1622
|
+
return globParts;
|
|
1623
|
+
}
|
|
1624
|
+
// second phase: multi-pattern dedupes
|
|
1625
|
+
// {<pre>/*/<rest>,<pre>/<p>/<rest>} -> <pre>/*/<rest>
|
|
1626
|
+
// {<pre>/<rest>,<pre>/<rest>} -> <pre>/<rest>
|
|
1627
|
+
// {<pre>/**/<rest>,<pre>/<rest>} -> <pre>/**/<rest>
|
|
1628
|
+
//
|
|
1629
|
+
// {<pre>/**/<rest>,<pre>/**/<p>/<rest>} -> <pre>/**/<rest>
|
|
1630
|
+
// ^-- not valid because ** doens't follow symlinks
|
|
1631
|
+
secondPhasePreProcess(globParts) {
|
|
1632
|
+
for (let i = 0; i < globParts.length - 1; i++) {
|
|
1633
|
+
for (let j = i + 1; j < globParts.length; j++) {
|
|
1634
|
+
const matched = this.partsMatch(globParts[i], globParts[j], !this.preserveMultipleSlashes);
|
|
1635
|
+
if (matched) {
|
|
1636
|
+
globParts[i] = [];
|
|
1637
|
+
globParts[j] = matched;
|
|
1638
|
+
break;
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
return globParts.filter((gs) => gs.length);
|
|
1643
|
+
}
|
|
1644
|
+
partsMatch(a, b, emptyGSMatch = false) {
|
|
1645
|
+
let ai = 0;
|
|
1646
|
+
let bi = 0;
|
|
1647
|
+
let result = [];
|
|
1648
|
+
let which = "";
|
|
1649
|
+
while (ai < a.length && bi < b.length) {
|
|
1650
|
+
if (a[ai] === b[bi]) {
|
|
1651
|
+
result.push(which === "b" ? b[bi] : a[ai]);
|
|
1652
|
+
ai++;
|
|
1653
|
+
bi++;
|
|
1654
|
+
} else if (emptyGSMatch && a[ai] === "**" && b[bi] === a[ai + 1]) {
|
|
1655
|
+
result.push(a[ai]);
|
|
1656
|
+
ai++;
|
|
1657
|
+
} else if (emptyGSMatch && b[bi] === "**" && a[ai] === b[bi + 1]) {
|
|
1658
|
+
result.push(b[bi]);
|
|
1659
|
+
bi++;
|
|
1660
|
+
} else if (a[ai] === "*" && b[bi] && (this.options.dot || !b[bi].startsWith(".")) && b[bi] !== "**") {
|
|
1661
|
+
if (which === "b")
|
|
1662
|
+
return false;
|
|
1663
|
+
which = "a";
|
|
1664
|
+
result.push(a[ai]);
|
|
1665
|
+
ai++;
|
|
1666
|
+
bi++;
|
|
1667
|
+
} else if (b[bi] === "*" && a[ai] && (this.options.dot || !a[ai].startsWith(".")) && a[ai] !== "**") {
|
|
1668
|
+
if (which === "a")
|
|
1669
|
+
return false;
|
|
1670
|
+
which = "b";
|
|
1671
|
+
result.push(b[bi]);
|
|
1672
|
+
ai++;
|
|
1673
|
+
bi++;
|
|
1674
|
+
} else {
|
|
1675
|
+
return false;
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
return a.length === b.length && result;
|
|
1679
|
+
}
|
|
1680
|
+
parseNegate() {
|
|
1681
|
+
if (this.nonegate)
|
|
1682
|
+
return;
|
|
1683
|
+
const pattern = this.pattern;
|
|
1684
|
+
let negate = false;
|
|
1685
|
+
let negateOffset = 0;
|
|
1686
|
+
for (let i = 0; i < pattern.length && pattern.charAt(i) === "!"; i++) {
|
|
1687
|
+
negate = !negate;
|
|
1688
|
+
negateOffset++;
|
|
1689
|
+
}
|
|
1690
|
+
if (negateOffset)
|
|
1691
|
+
this.pattern = pattern.slice(negateOffset);
|
|
1692
|
+
this.negate = negate;
|
|
1693
|
+
}
|
|
1694
|
+
// set partial to true to test if, for example,
|
|
1695
|
+
// "/a/b" matches the start of "/*/b/*/d"
|
|
1696
|
+
// Partial means, if you run out of file before you run
|
|
1697
|
+
// out of pattern, then that's fine, as long as all
|
|
1698
|
+
// the parts match.
|
|
1699
|
+
matchOne(file, pattern, partial = false) {
|
|
1700
|
+
let fileStartIndex = 0;
|
|
1701
|
+
let patternStartIndex = 0;
|
|
1702
|
+
if (this.isWindows) {
|
|
1703
|
+
const fileDrive = typeof file[0] === "string" && /^[a-z]:$/i.test(file[0]);
|
|
1704
|
+
const fileUNC = !fileDrive && file[0] === "" && file[1] === "" && file[2] === "?" && /^[a-z]:$/i.test(file[3]);
|
|
1705
|
+
const patternDrive = typeof pattern[0] === "string" && /^[a-z]:$/i.test(pattern[0]);
|
|
1706
|
+
const patternUNC = !patternDrive && pattern[0] === "" && pattern[1] === "" && pattern[2] === "?" && typeof pattern[3] === "string" && /^[a-z]:$/i.test(pattern[3]);
|
|
1707
|
+
const fdi = fileUNC ? 3 : fileDrive ? 0 : void 0;
|
|
1708
|
+
const pdi = patternUNC ? 3 : patternDrive ? 0 : void 0;
|
|
1709
|
+
if (typeof fdi === "number" && typeof pdi === "number") {
|
|
1710
|
+
const [fd, pd] = [
|
|
1711
|
+
file[fdi],
|
|
1712
|
+
pattern[pdi]
|
|
1713
|
+
];
|
|
1714
|
+
if (fd.toLowerCase() === pd.toLowerCase()) {
|
|
1715
|
+
pattern[pdi] = fd;
|
|
1716
|
+
patternStartIndex = pdi;
|
|
1717
|
+
fileStartIndex = fdi;
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
const { optimizationLevel = 1 } = this.options;
|
|
1722
|
+
if (optimizationLevel >= 2) {
|
|
1723
|
+
file = this.levelTwoFileOptimize(file);
|
|
1724
|
+
}
|
|
1725
|
+
if (pattern.includes(GLOBSTAR)) {
|
|
1726
|
+
return this.#matchGlobstar(file, pattern, partial, fileStartIndex, patternStartIndex);
|
|
1727
|
+
}
|
|
1728
|
+
return this.#matchOne(file, pattern, partial, fileStartIndex, patternStartIndex);
|
|
1729
|
+
}
|
|
1730
|
+
#matchGlobstar(file, pattern, partial, fileIndex, patternIndex) {
|
|
1731
|
+
const firstgs = pattern.indexOf(GLOBSTAR, patternIndex);
|
|
1732
|
+
const lastgs = pattern.lastIndexOf(GLOBSTAR);
|
|
1733
|
+
const [head, body, tail] = partial ? [
|
|
1734
|
+
pattern.slice(patternIndex, firstgs),
|
|
1735
|
+
pattern.slice(firstgs + 1),
|
|
1736
|
+
[]
|
|
1737
|
+
] : [
|
|
1738
|
+
pattern.slice(patternIndex, firstgs),
|
|
1739
|
+
pattern.slice(firstgs + 1, lastgs),
|
|
1740
|
+
pattern.slice(lastgs + 1)
|
|
1741
|
+
];
|
|
1742
|
+
if (head.length) {
|
|
1743
|
+
const fileHead = file.slice(fileIndex, fileIndex + head.length);
|
|
1744
|
+
if (!this.#matchOne(fileHead, head, partial, 0, 0)) {
|
|
1745
|
+
return false;
|
|
1746
|
+
}
|
|
1747
|
+
fileIndex += head.length;
|
|
1748
|
+
patternIndex += head.length;
|
|
1749
|
+
}
|
|
1750
|
+
let fileTailMatch = 0;
|
|
1751
|
+
if (tail.length) {
|
|
1752
|
+
if (tail.length + fileIndex > file.length)
|
|
1753
|
+
return false;
|
|
1754
|
+
let tailStart = file.length - tail.length;
|
|
1755
|
+
if (this.#matchOne(file, tail, partial, tailStart, 0)) {
|
|
1756
|
+
fileTailMatch = tail.length;
|
|
1757
|
+
} else {
|
|
1758
|
+
if (file[file.length - 1] !== "" || fileIndex + tail.length === file.length) {
|
|
1759
|
+
return false;
|
|
1760
|
+
}
|
|
1761
|
+
tailStart--;
|
|
1762
|
+
if (!this.#matchOne(file, tail, partial, tailStart, 0)) {
|
|
1763
|
+
return false;
|
|
1764
|
+
}
|
|
1765
|
+
fileTailMatch = tail.length + 1;
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
if (!body.length) {
|
|
1769
|
+
let sawSome = !!fileTailMatch;
|
|
1770
|
+
for (let i2 = fileIndex; i2 < file.length - fileTailMatch; i2++) {
|
|
1771
|
+
const f = String(file[i2]);
|
|
1772
|
+
sawSome = true;
|
|
1773
|
+
if (f === "." || f === ".." || !this.options.dot && f.startsWith(".")) {
|
|
1774
|
+
return false;
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
return partial || sawSome;
|
|
1778
|
+
}
|
|
1779
|
+
const bodySegments = [[[], 0]];
|
|
1780
|
+
let currentBody = bodySegments[0];
|
|
1781
|
+
let nonGsParts = 0;
|
|
1782
|
+
const nonGsPartsSums = [0];
|
|
1783
|
+
for (const b of body) {
|
|
1784
|
+
if (b === GLOBSTAR) {
|
|
1785
|
+
nonGsPartsSums.push(nonGsParts);
|
|
1786
|
+
currentBody = [[], 0];
|
|
1787
|
+
bodySegments.push(currentBody);
|
|
1788
|
+
} else {
|
|
1789
|
+
currentBody[0].push(b);
|
|
1790
|
+
nonGsParts++;
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
let i = bodySegments.length - 1;
|
|
1794
|
+
const fileLength = file.length - fileTailMatch;
|
|
1795
|
+
for (const b of bodySegments) {
|
|
1796
|
+
b[1] = fileLength - (nonGsPartsSums[i--] + b[0].length);
|
|
1797
|
+
}
|
|
1798
|
+
return !!this.#matchGlobStarBodySections(file, bodySegments, fileIndex, 0, partial, 0, !!fileTailMatch);
|
|
1799
|
+
}
|
|
1800
|
+
// return false for "nope, not matching"
|
|
1801
|
+
// return null for "not matching, cannot keep trying"
|
|
1802
|
+
#matchGlobStarBodySections(file, bodySegments, fileIndex, bodyIndex, partial, globStarDepth, sawTail) {
|
|
1803
|
+
const bs = bodySegments[bodyIndex];
|
|
1804
|
+
if (!bs) {
|
|
1805
|
+
for (let i = fileIndex; i < file.length; i++) {
|
|
1806
|
+
sawTail = true;
|
|
1807
|
+
const f = file[i];
|
|
1808
|
+
if (f === "." || f === ".." || !this.options.dot && f.startsWith(".")) {
|
|
1809
|
+
return false;
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
return sawTail;
|
|
1813
|
+
}
|
|
1814
|
+
const [body, after] = bs;
|
|
1815
|
+
while (fileIndex <= after) {
|
|
1816
|
+
const m = this.#matchOne(file.slice(0, fileIndex + body.length), body, partial, fileIndex, 0);
|
|
1817
|
+
if (m && globStarDepth < this.maxGlobstarRecursion) {
|
|
1818
|
+
const sub = this.#matchGlobStarBodySections(file, bodySegments, fileIndex + body.length, bodyIndex + 1, partial, globStarDepth + 1, sawTail);
|
|
1819
|
+
if (sub !== false) {
|
|
1820
|
+
return sub;
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
const f = file[fileIndex];
|
|
1824
|
+
if (f === "." || f === ".." || !this.options.dot && f.startsWith(".")) {
|
|
1825
|
+
return false;
|
|
1826
|
+
}
|
|
1827
|
+
fileIndex++;
|
|
1828
|
+
}
|
|
1829
|
+
return partial || null;
|
|
1830
|
+
}
|
|
1831
|
+
#matchOne(file, pattern, partial, fileIndex, patternIndex) {
|
|
1832
|
+
let fi;
|
|
1833
|
+
let pi;
|
|
1834
|
+
let pl;
|
|
1835
|
+
let fl;
|
|
1836
|
+
for (fi = fileIndex, pi = patternIndex, fl = file.length, pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {
|
|
1837
|
+
this.debug("matchOne loop");
|
|
1838
|
+
let p = pattern[pi];
|
|
1839
|
+
let f = file[fi];
|
|
1840
|
+
this.debug(pattern, p, f);
|
|
1841
|
+
if (p === false || p === GLOBSTAR) {
|
|
1842
|
+
return false;
|
|
1843
|
+
}
|
|
1844
|
+
let hit;
|
|
1845
|
+
if (typeof p === "string") {
|
|
1846
|
+
hit = f === p;
|
|
1847
|
+
this.debug("string match", p, f, hit);
|
|
1848
|
+
} else {
|
|
1849
|
+
hit = p.test(f);
|
|
1850
|
+
this.debug("pattern match", p, f, hit);
|
|
1851
|
+
}
|
|
1852
|
+
if (!hit)
|
|
1853
|
+
return false;
|
|
1854
|
+
}
|
|
1855
|
+
if (fi === fl && pi === pl) {
|
|
1856
|
+
return true;
|
|
1857
|
+
} else if (fi === fl) {
|
|
1858
|
+
return partial;
|
|
1859
|
+
} else if (pi === pl) {
|
|
1860
|
+
return fi === fl - 1 && file[fi] === "";
|
|
1861
|
+
} else {
|
|
1862
|
+
throw new Error("wtf?");
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
braceExpand() {
|
|
1866
|
+
return braceExpand(this.pattern, this.options);
|
|
1867
|
+
}
|
|
1868
|
+
parse(pattern) {
|
|
1869
|
+
assertValidPattern(pattern);
|
|
1870
|
+
const options = this.options;
|
|
1871
|
+
if (pattern === "**")
|
|
1872
|
+
return GLOBSTAR;
|
|
1873
|
+
if (pattern === "")
|
|
1874
|
+
return "";
|
|
1875
|
+
let m;
|
|
1876
|
+
let fastTest = null;
|
|
1877
|
+
if (m = pattern.match(starRE)) {
|
|
1878
|
+
fastTest = options.dot ? starTestDot : starTest;
|
|
1879
|
+
} else if (m = pattern.match(starDotExtRE)) {
|
|
1880
|
+
fastTest = (options.nocase ? options.dot ? starDotExtTestNocaseDot : starDotExtTestNocase : options.dot ? starDotExtTestDot : starDotExtTest)(m[1]);
|
|
1881
|
+
} else if (m = pattern.match(qmarksRE)) {
|
|
1882
|
+
fastTest = (options.nocase ? options.dot ? qmarksTestNocaseDot : qmarksTestNocase : options.dot ? qmarksTestDot : qmarksTest)(m);
|
|
1883
|
+
} else if (m = pattern.match(starDotStarRE)) {
|
|
1884
|
+
fastTest = options.dot ? starDotStarTestDot : starDotStarTest;
|
|
1885
|
+
} else if (m = pattern.match(dotStarRE)) {
|
|
1886
|
+
fastTest = dotStarTest;
|
|
1887
|
+
}
|
|
1888
|
+
const re = AST.fromGlob(pattern, this.options).toMMPattern();
|
|
1889
|
+
if (fastTest && typeof re === "object") {
|
|
1890
|
+
Reflect.defineProperty(re, "test", { value: fastTest });
|
|
1891
|
+
}
|
|
1892
|
+
return re;
|
|
1893
|
+
}
|
|
1894
|
+
makeRe() {
|
|
1895
|
+
if (this.regexp || this.regexp === false)
|
|
1896
|
+
return this.regexp;
|
|
1897
|
+
const set = this.set;
|
|
1898
|
+
if (!set.length) {
|
|
1899
|
+
this.regexp = false;
|
|
1900
|
+
return this.regexp;
|
|
1901
|
+
}
|
|
1902
|
+
const options = this.options;
|
|
1903
|
+
const twoStar = options.noglobstar ? star2 : options.dot ? twoStarDot : twoStarNoDot;
|
|
1904
|
+
const flags = new Set(options.nocase ? ["i"] : []);
|
|
1905
|
+
let re = set.map((pattern) => {
|
|
1906
|
+
const pp = pattern.map((p) => {
|
|
1907
|
+
if (p instanceof RegExp) {
|
|
1908
|
+
for (const f of p.flags.split(""))
|
|
1909
|
+
flags.add(f);
|
|
1910
|
+
}
|
|
1911
|
+
return typeof p === "string" ? regExpEscape2(p) : p === GLOBSTAR ? GLOBSTAR : p._src;
|
|
1912
|
+
});
|
|
1913
|
+
pp.forEach((p, i) => {
|
|
1914
|
+
const next = pp[i + 1];
|
|
1915
|
+
const prev = pp[i - 1];
|
|
1916
|
+
if (p !== GLOBSTAR || prev === GLOBSTAR) {
|
|
1917
|
+
return;
|
|
1918
|
+
}
|
|
1919
|
+
if (prev === void 0) {
|
|
1920
|
+
if (next !== void 0 && next !== GLOBSTAR) {
|
|
1921
|
+
pp[i + 1] = "(?:\\/|" + twoStar + "\\/)?" + next;
|
|
1922
|
+
} else {
|
|
1923
|
+
pp[i] = twoStar;
|
|
1924
|
+
}
|
|
1925
|
+
} else if (next === void 0) {
|
|
1926
|
+
pp[i - 1] = prev + "(?:\\/|\\/" + twoStar + ")?";
|
|
1927
|
+
} else if (next !== GLOBSTAR) {
|
|
1928
|
+
pp[i - 1] = prev + "(?:\\/|\\/" + twoStar + "\\/)" + next;
|
|
1929
|
+
pp[i + 1] = GLOBSTAR;
|
|
1930
|
+
}
|
|
1931
|
+
});
|
|
1932
|
+
const filtered = pp.filter((p) => p !== GLOBSTAR);
|
|
1933
|
+
if (this.partial && filtered.length >= 1) {
|
|
1934
|
+
const prefixes = [];
|
|
1935
|
+
for (let i = 1; i <= filtered.length; i++) {
|
|
1936
|
+
prefixes.push(filtered.slice(0, i).join("/"));
|
|
1937
|
+
}
|
|
1938
|
+
return "(?:" + prefixes.join("|") + ")";
|
|
1939
|
+
}
|
|
1940
|
+
return filtered.join("/");
|
|
1941
|
+
}).join("|");
|
|
1942
|
+
const [open, close] = set.length > 1 ? ["(?:", ")"] : ["", ""];
|
|
1943
|
+
re = "^" + open + re + close + "$";
|
|
1944
|
+
if (this.partial) {
|
|
1945
|
+
re = "^(?:\\/|" + open + re.slice(1, -1) + close + ")$";
|
|
1946
|
+
}
|
|
1947
|
+
if (this.negate)
|
|
1948
|
+
re = "^(?!" + re + ").+$";
|
|
1949
|
+
try {
|
|
1950
|
+
this.regexp = new RegExp(re, [...flags].join(""));
|
|
1951
|
+
} catch {
|
|
1952
|
+
this.regexp = false;
|
|
1953
|
+
}
|
|
1954
|
+
return this.regexp;
|
|
1955
|
+
}
|
|
1956
|
+
slashSplit(p) {
|
|
1957
|
+
if (this.preserveMultipleSlashes) {
|
|
1958
|
+
return p.split("/");
|
|
1959
|
+
} else if (this.isWindows && /^\/\/[^/]+/.test(p)) {
|
|
1960
|
+
return ["", ...p.split(/\/+/)];
|
|
1961
|
+
} else {
|
|
1962
|
+
return p.split(/\/+/);
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
match(f, partial = this.partial) {
|
|
1966
|
+
this.debug("match", f, this.pattern);
|
|
1967
|
+
if (this.comment) {
|
|
1968
|
+
return false;
|
|
1969
|
+
}
|
|
1970
|
+
if (this.empty) {
|
|
1971
|
+
return f === "";
|
|
1972
|
+
}
|
|
1973
|
+
if (f === "/" && partial) {
|
|
1974
|
+
return true;
|
|
1975
|
+
}
|
|
1976
|
+
const options = this.options;
|
|
1977
|
+
if (this.isWindows) {
|
|
1978
|
+
f = f.split("\\").join("/");
|
|
1979
|
+
}
|
|
1980
|
+
const ff = this.slashSplit(f);
|
|
1981
|
+
this.debug(this.pattern, "split", ff);
|
|
1982
|
+
const set = this.set;
|
|
1983
|
+
this.debug(this.pattern, "set", set);
|
|
1984
|
+
let filename = ff[ff.length - 1];
|
|
1985
|
+
if (!filename) {
|
|
1986
|
+
for (let i = ff.length - 2; !filename && i >= 0; i--) {
|
|
1987
|
+
filename = ff[i];
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
for (const pattern of set) {
|
|
1991
|
+
let file = ff;
|
|
1992
|
+
if (options.matchBase && pattern.length === 1) {
|
|
1993
|
+
file = [filename];
|
|
1994
|
+
}
|
|
1995
|
+
const hit = this.matchOne(file, pattern, partial);
|
|
1996
|
+
if (hit) {
|
|
1997
|
+
if (options.flipNegate) {
|
|
1998
|
+
return true;
|
|
1999
|
+
}
|
|
2000
|
+
return !this.negate;
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
if (options.flipNegate) {
|
|
2004
|
+
return false;
|
|
2005
|
+
}
|
|
2006
|
+
return this.negate;
|
|
2007
|
+
}
|
|
2008
|
+
static defaults(def) {
|
|
2009
|
+
return minimatch.defaults(def).Minimatch;
|
|
2010
|
+
}
|
|
2011
|
+
};
|
|
2012
|
+
minimatch.AST = AST;
|
|
2013
|
+
minimatch.Minimatch = Minimatch;
|
|
2014
|
+
minimatch.escape = escape;
|
|
2015
|
+
minimatch.unescape = unescape;
|
|
2016
|
+
|
|
2017
|
+
// src/generate/llms-txt.ts
|
|
2018
|
+
function generateLlmsTxt(pages, config) {
|
|
2019
|
+
const lines = [];
|
|
2020
|
+
lines.push(`# ${config.title}`);
|
|
2021
|
+
lines.push("");
|
|
2022
|
+
lines.push(`> ${config.description}`);
|
|
2023
|
+
lines.push("");
|
|
2024
|
+
if (config.sections && config.sections.length > 0) {
|
|
2025
|
+
const assigned = /* @__PURE__ */ new Set();
|
|
2026
|
+
for (const section of config.sections) {
|
|
2027
|
+
const matched = pages.filter(
|
|
2028
|
+
(page) => section.patterns.some((pattern) => minimatch(page.relativePath, pattern))
|
|
2029
|
+
);
|
|
2030
|
+
if (matched.length === 0) continue;
|
|
2031
|
+
lines.push(`## ${section.title}`);
|
|
2032
|
+
lines.push("");
|
|
2033
|
+
for (const page of matched) {
|
|
2034
|
+
lines.push(formatEntry(page, config.url));
|
|
2035
|
+
assigned.add(page.relativePath);
|
|
2036
|
+
}
|
|
2037
|
+
lines.push("");
|
|
2038
|
+
}
|
|
2039
|
+
const ungrouped = pages.filter((p) => !assigned.has(p.relativePath));
|
|
2040
|
+
if (ungrouped.length > 0) {
|
|
2041
|
+
lines.push("## Optional");
|
|
2042
|
+
lines.push("");
|
|
2043
|
+
for (const page of ungrouped) {
|
|
2044
|
+
lines.push(formatEntry(page, config.url));
|
|
2045
|
+
}
|
|
2046
|
+
lines.push("");
|
|
2047
|
+
}
|
|
2048
|
+
} else {
|
|
2049
|
+
const groups = groupByDirectory(pages);
|
|
2050
|
+
for (const [dir, groupPages] of groups) {
|
|
2051
|
+
const sectionTitle = dir === "." ? "General" : dir.charAt(0).toUpperCase() + dir.slice(1).replace(/[-_]/g, " ");
|
|
2052
|
+
lines.push(`## ${sectionTitle}`);
|
|
2053
|
+
lines.push("");
|
|
2054
|
+
for (const page of groupPages) {
|
|
2055
|
+
lines.push(formatEntry(page, config.url));
|
|
2056
|
+
}
|
|
2057
|
+
lines.push("");
|
|
2058
|
+
}
|
|
2059
|
+
}
|
|
2060
|
+
return lines.join("\n").trimEnd() + "\n";
|
|
2061
|
+
}
|
|
2062
|
+
function formatEntry(page, baseUrl) {
|
|
2063
|
+
const url = pageUrl(page, baseUrl);
|
|
2064
|
+
const desc = page.description ?? extractFirstParagraph(page.content);
|
|
2065
|
+
if (desc) {
|
|
2066
|
+
return `- [${page.title}](${url}): ${desc}`;
|
|
2067
|
+
}
|
|
2068
|
+
return `- [${page.title}](${url})`;
|
|
2069
|
+
}
|
|
2070
|
+
function pageUrl(page, baseUrl) {
|
|
2071
|
+
const normalized = baseUrl.replace(/\/$/, "");
|
|
2072
|
+
const slug = page.relativePath.replace(/\.mdx?$/, "").replace(/\/index$/, "").replace(/^README$/i, "");
|
|
2073
|
+
if (!slug) return normalized + "/";
|
|
2074
|
+
return `${normalized}/${slug}`;
|
|
2075
|
+
}
|
|
2076
|
+
function extractFirstParagraph(content) {
|
|
2077
|
+
const lines = content.split("\n");
|
|
2078
|
+
for (const line of lines) {
|
|
2079
|
+
const trimmed = line.trim();
|
|
2080
|
+
if (!trimmed) continue;
|
|
2081
|
+
if (trimmed.startsWith("#")) continue;
|
|
2082
|
+
if (trimmed.startsWith("```")) continue;
|
|
2083
|
+
if (trimmed.startsWith("<")) continue;
|
|
2084
|
+
if (trimmed.startsWith("import ")) continue;
|
|
2085
|
+
return trimmed.length > 120 ? trimmed.slice(0, 117) + "..." : trimmed;
|
|
2086
|
+
}
|
|
2087
|
+
return null;
|
|
2088
|
+
}
|
|
2089
|
+
function groupByDirectory(pages) {
|
|
2090
|
+
const groups = /* @__PURE__ */ new Map();
|
|
2091
|
+
for (const page of pages) {
|
|
2092
|
+
const dir = path4.dirname(page.relativePath);
|
|
2093
|
+
const topDir = dir === "." ? "." : dir.split("/")[0];
|
|
2094
|
+
if (!groups.has(topDir)) {
|
|
2095
|
+
groups.set(topDir, []);
|
|
2096
|
+
}
|
|
2097
|
+
groups.get(topDir).push(page);
|
|
2098
|
+
}
|
|
2099
|
+
return groups;
|
|
2100
|
+
}
|
|
2101
|
+
|
|
2102
|
+
// src/utils/mdx-clean.ts
|
|
2103
|
+
function cleanMdx(content) {
|
|
2104
|
+
let result = content;
|
|
2105
|
+
result = result.replace(/^\uFEFF/, "");
|
|
2106
|
+
result = result.replace(/^import\s+.*$/gm, "");
|
|
2107
|
+
result = result.replace(/<([A-Z]\w*)[^>]*>[\s\S]*?<\/\1>/g, "");
|
|
2108
|
+
result = result.replace(/^[ \t]*<[A-Z]\w*[^>]*\/>\s*$/gm, "");
|
|
2109
|
+
result = result.replace(
|
|
2110
|
+
/^:::(\w+)(?:[^\S\n]+(.+))?\n([\s\S]*?)^:::\s*$/gm,
|
|
2111
|
+
(_match, type, title, body) => {
|
|
2112
|
+
const label = title ?? type.charAt(0).toUpperCase() + type.slice(1);
|
|
2113
|
+
const trimmedBody = body.trim();
|
|
2114
|
+
return `> **${label}:** ${trimmedBody}`;
|
|
2115
|
+
}
|
|
2116
|
+
);
|
|
2117
|
+
result = result.replace(/\n{3,}/g, "\n\n");
|
|
2118
|
+
return result.trim() + "\n";
|
|
2119
|
+
}
|
|
2120
|
+
|
|
2121
|
+
// src/generate/llms-full.ts
|
|
2122
|
+
function generateLlmsFullTxt(pages) {
|
|
2123
|
+
const sections = [];
|
|
2124
|
+
for (const page of pages) {
|
|
2125
|
+
const cleaned = cleanMdx(page.content);
|
|
2126
|
+
sections.push(`## ${page.title}
|
|
2127
|
+
|
|
2128
|
+
${cleaned}`);
|
|
2129
|
+
}
|
|
2130
|
+
return sections.join("\n\n").trimEnd() + "\n";
|
|
2131
|
+
}
|
|
2132
|
+
|
|
2133
|
+
// src/utils/tokens.ts
|
|
2134
|
+
function estimateTokens(content) {
|
|
2135
|
+
return Math.ceil(content.length / 4);
|
|
2136
|
+
}
|
|
2137
|
+
function formatTokens(count) {
|
|
2138
|
+
if (count >= 1e3) {
|
|
2139
|
+
return `~${(count / 1e3).toFixed(1)}K tokens`;
|
|
2140
|
+
}
|
|
2141
|
+
return `~${count} tokens`;
|
|
2142
|
+
}
|
|
2143
|
+
|
|
2144
|
+
// src/cli/commands/generate.ts
|
|
2145
|
+
async function generateCommand(options = {}) {
|
|
2146
|
+
const cwd = process.cwd();
|
|
2147
|
+
const config = await loadConfig(cwd);
|
|
2148
|
+
const spin = spinner("Scanning documentation...");
|
|
2149
|
+
spin.start();
|
|
2150
|
+
const docsDir = path5.resolve(cwd, config.docs.dir);
|
|
2151
|
+
const pages = await scanDocs(docsDir, {
|
|
2152
|
+
include: config.docs.include,
|
|
2153
|
+
exclude: config.docs.exclude
|
|
2154
|
+
});
|
|
2155
|
+
spin.stop();
|
|
2156
|
+
if (pages.length === 0) {
|
|
2157
|
+
log.warn(`No documentation files found in ${config.docs.dir}`);
|
|
2158
|
+
return;
|
|
2159
|
+
}
|
|
2160
|
+
log.info(`Found ${pages.length} documentation pages`);
|
|
2161
|
+
const outputDir = path5.resolve(cwd, config.generate.output_dir);
|
|
2162
|
+
if (config.generate.llms_txt && options.only !== "llms-full") {
|
|
2163
|
+
const llmsTxt = generateLlmsTxt(pages, {
|
|
2164
|
+
title: config.title,
|
|
2165
|
+
description: config.description,
|
|
2166
|
+
url: config.url,
|
|
2167
|
+
sections: config.generate.sections
|
|
2168
|
+
});
|
|
2169
|
+
if (options.dryRun) {
|
|
2170
|
+
log.info("[dry-run] Would write llms.txt");
|
|
2171
|
+
log.dim(` ${llmsTxt.length} chars, ${formatTokens(estimateTokens(llmsTxt))}`);
|
|
2172
|
+
} else {
|
|
2173
|
+
await fs3.mkdir(outputDir, { recursive: true });
|
|
2174
|
+
await fs3.writeFile(path5.join(outputDir, "llms.txt"), llmsTxt, "utf-8");
|
|
2175
|
+
log.success(`Generated llms.txt (${formatTokens(estimateTokens(llmsTxt))})`);
|
|
2176
|
+
}
|
|
2177
|
+
}
|
|
2178
|
+
if (config.generate.llms_full_txt && options.only !== "llms-txt") {
|
|
2179
|
+
const llmsFullTxt = generateLlmsFullTxt(pages);
|
|
2180
|
+
if (options.dryRun) {
|
|
2181
|
+
log.info("[dry-run] Would write llms-full.txt");
|
|
2182
|
+
log.dim(` ${llmsFullTxt.length} chars, ${formatTokens(estimateTokens(llmsFullTxt))}`);
|
|
2183
|
+
} else {
|
|
2184
|
+
await fs3.mkdir(outputDir, { recursive: true });
|
|
2185
|
+
await fs3.writeFile(path5.join(outputDir, "llms-full.txt"), llmsFullTxt, "utf-8");
|
|
2186
|
+
log.success(`Generated llms-full.txt (${formatTokens(estimateTokens(llmsFullTxt))})`);
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
export {
|
|
2191
|
+
generateCommand
|
|
2192
|
+
};
|
|
2193
|
+
//# sourceMappingURL=generate-56HFRN5I.js.map
|