raggrep 0.8.0 → 0.8.2
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 +28 -7
- package/dist/cli/main.js +1596 -146
- package/dist/cli/main.js.map +25 -16
- package/dist/domain/entities/searchResult.d.ts +11 -2
- package/dist/domain/services/index.d.ts +1 -0
- package/dist/domain/services/jsonPathExtractor.d.ts +29 -0
- package/dist/domain/services/jsonPathExtractor.test.d.ts +4 -0
- package/dist/index.js +1600 -143
- package/dist/index.js.map +23 -14
- package/dist/modules/data/json/index.d.ts +28 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var __toESM = (mod, isNodeMode, target) => {
|
|
|
15
15
|
});
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
18
19
|
var __export = (target, all) => {
|
|
19
20
|
for (var name in all)
|
|
20
21
|
__defProp(target, name, {
|
|
@@ -2548,44 +2549,10 @@ var init_queryIntent = __esm(() => {
|
|
|
2548
2549
|
});
|
|
2549
2550
|
|
|
2550
2551
|
// src/domain/services/chunking.ts
|
|
2551
|
-
function createLineBasedChunks(content, options = {}) {
|
|
2552
|
-
const {
|
|
2553
|
-
chunkSize = DEFAULT_CHUNK_SIZE,
|
|
2554
|
-
overlap = DEFAULT_OVERLAP,
|
|
2555
|
-
minLinesForMultipleChunks = chunkSize
|
|
2556
|
-
} = options;
|
|
2557
|
-
const lines = content.split(`
|
|
2558
|
-
`);
|
|
2559
|
-
const chunks = [];
|
|
2560
|
-
if (lines.length <= minLinesForMultipleChunks) {
|
|
2561
|
-
return [
|
|
2562
|
-
{
|
|
2563
|
-
content,
|
|
2564
|
-
startLine: 1,
|
|
2565
|
-
endLine: lines.length,
|
|
2566
|
-
type: "file"
|
|
2567
|
-
}
|
|
2568
|
-
];
|
|
2569
|
-
}
|
|
2570
|
-
for (let i = 0;i < lines.length; i += chunkSize - overlap) {
|
|
2571
|
-
const endIdx = Math.min(i + chunkSize, lines.length);
|
|
2572
|
-
chunks.push({
|
|
2573
|
-
content: lines.slice(i, endIdx).join(`
|
|
2574
|
-
`),
|
|
2575
|
-
startLine: i + 1,
|
|
2576
|
-
endLine: endIdx,
|
|
2577
|
-
type: "block"
|
|
2578
|
-
});
|
|
2579
|
-
if (endIdx >= lines.length)
|
|
2580
|
-
break;
|
|
2581
|
-
}
|
|
2582
|
-
return chunks;
|
|
2583
|
-
}
|
|
2584
2552
|
function generateChunkId(filepath, startLine, endLine) {
|
|
2585
2553
|
const safePath = filepath.replace(/[/\\]/g, "-").replace(/\./g, "_");
|
|
2586
2554
|
return `${safePath}-${startLine}-${endLine}`;
|
|
2587
2555
|
}
|
|
2588
|
-
var DEFAULT_CHUNK_SIZE = 30, DEFAULT_OVERLAP = 5;
|
|
2589
2556
|
|
|
2590
2557
|
// src/domain/services/queryLiteralParser.ts
|
|
2591
2558
|
function parseQueryLiterals(query) {
|
|
@@ -3453,6 +3420,63 @@ var init_lexicon2 = __esm(() => {
|
|
|
3453
3420
|
defaultLookupMap = buildLookupMap(DEFAULT_LEXICON);
|
|
3454
3421
|
});
|
|
3455
3422
|
|
|
3423
|
+
// src/domain/services/jsonPathExtractor.ts
|
|
3424
|
+
function extractJsonPaths(obj, fileBasename) {
|
|
3425
|
+
const paths = extractPathsRecursive(obj, fileBasename);
|
|
3426
|
+
return paths.map((path8) => ({
|
|
3427
|
+
value: path8,
|
|
3428
|
+
type: "identifier",
|
|
3429
|
+
matchType: "definition"
|
|
3430
|
+
}));
|
|
3431
|
+
}
|
|
3432
|
+
function extractPathsRecursive(obj, prefix) {
|
|
3433
|
+
const paths = [];
|
|
3434
|
+
if (obj === null || obj === undefined) {
|
|
3435
|
+
return paths;
|
|
3436
|
+
}
|
|
3437
|
+
if (Array.isArray(obj)) {
|
|
3438
|
+
obj.forEach((item, index) => {
|
|
3439
|
+
const indexedPrefix = `${prefix}[${index}]`;
|
|
3440
|
+
paths.push(indexedPrefix);
|
|
3441
|
+
if (item !== null && typeof item === "object") {
|
|
3442
|
+
paths.push(...extractPathsRecursive(item, indexedPrefix));
|
|
3443
|
+
}
|
|
3444
|
+
});
|
|
3445
|
+
} else if (typeof obj === "object") {
|
|
3446
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
3447
|
+
const fullPath = `${prefix}.${key}`;
|
|
3448
|
+
paths.push(fullPath);
|
|
3449
|
+
if (value !== null && typeof value === "object") {
|
|
3450
|
+
paths.push(...extractPathsRecursive(value, fullPath));
|
|
3451
|
+
}
|
|
3452
|
+
}
|
|
3453
|
+
}
|
|
3454
|
+
return paths;
|
|
3455
|
+
}
|
|
3456
|
+
function extractJsonKeywords(obj) {
|
|
3457
|
+
const keywords = new Set;
|
|
3458
|
+
const extract = (value, parentKey) => {
|
|
3459
|
+
if (value === null || value === undefined) {
|
|
3460
|
+
return;
|
|
3461
|
+
}
|
|
3462
|
+
if (typeof value === "string") {
|
|
3463
|
+
const words = value.replace(/([a-z])([A-Z])/g, "$1 $2").toLowerCase().split(/[\s_\-./]+/).filter((w) => w.length > 2);
|
|
3464
|
+
words.forEach((w) => keywords.add(w));
|
|
3465
|
+
} else if (Array.isArray(value)) {
|
|
3466
|
+
value.forEach((item) => extract(item));
|
|
3467
|
+
} else if (typeof value === "object") {
|
|
3468
|
+
for (const [key, val] of Object.entries(value)) {
|
|
3469
|
+
keywords.add(key.toLowerCase());
|
|
3470
|
+
const keyWords = key.replace(/([a-z])([A-Z])/g, "$1 $2").toLowerCase().split(/[\s_\-]+/).filter((w) => w.length > 2);
|
|
3471
|
+
keyWords.forEach((w) => keywords.add(w));
|
|
3472
|
+
extract(val, key);
|
|
3473
|
+
}
|
|
3474
|
+
}
|
|
3475
|
+
};
|
|
3476
|
+
extract(obj);
|
|
3477
|
+
return Array.from(keywords);
|
|
3478
|
+
}
|
|
3479
|
+
|
|
3456
3480
|
// src/domain/services/index.ts
|
|
3457
3481
|
var init_services = __esm(() => {
|
|
3458
3482
|
init_keywords();
|
|
@@ -4383,113 +4407,66 @@ function isJsonFile(filepath) {
|
|
|
4383
4407
|
const ext = path11.extname(filepath).toLowerCase();
|
|
4384
4408
|
return JSON_EXTENSIONS.includes(ext);
|
|
4385
4409
|
}
|
|
4386
|
-
function extractJsonKeys(obj, prefix = "") {
|
|
4387
|
-
const keys = [];
|
|
4388
|
-
if (obj === null || obj === undefined) {
|
|
4389
|
-
return keys;
|
|
4390
|
-
}
|
|
4391
|
-
if (Array.isArray(obj)) {
|
|
4392
|
-
obj.forEach((item, index) => {
|
|
4393
|
-
keys.push(...extractJsonKeys(item, `${prefix}[${index}]`));
|
|
4394
|
-
});
|
|
4395
|
-
} else if (typeof obj === "object") {
|
|
4396
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
4397
|
-
const fullKey = prefix ? `${prefix}.${key}` : key;
|
|
4398
|
-
keys.push(key);
|
|
4399
|
-
keys.push(...extractJsonKeys(value, fullKey));
|
|
4400
|
-
}
|
|
4401
|
-
}
|
|
4402
|
-
return keys;
|
|
4403
|
-
}
|
|
4404
|
-
function extractJsonKeywords(content) {
|
|
4405
|
-
try {
|
|
4406
|
-
const parsed = JSON.parse(content);
|
|
4407
|
-
const keys = extractJsonKeys(parsed);
|
|
4408
|
-
const stringValues = [];
|
|
4409
|
-
const extractStrings = (obj) => {
|
|
4410
|
-
if (typeof obj === "string") {
|
|
4411
|
-
const words = obj.replace(/([a-z])([A-Z])/g, "$1 $2").toLowerCase().split(/\s+/).filter((w) => w.length > 2);
|
|
4412
|
-
stringValues.push(...words);
|
|
4413
|
-
} else if (Array.isArray(obj)) {
|
|
4414
|
-
obj.forEach(extractStrings);
|
|
4415
|
-
} else if (obj && typeof obj === "object") {
|
|
4416
|
-
Object.values(obj).forEach(extractStrings);
|
|
4417
|
-
}
|
|
4418
|
-
};
|
|
4419
|
-
extractStrings(parsed);
|
|
4420
|
-
return [...new Set([...keys, ...stringValues])];
|
|
4421
|
-
} catch {
|
|
4422
|
-
return [];
|
|
4423
|
-
}
|
|
4424
|
-
}
|
|
4425
4410
|
|
|
4426
4411
|
class JsonModule {
|
|
4427
4412
|
id = "data/json";
|
|
4428
4413
|
name = "JSON Search";
|
|
4429
|
-
description = "JSON file search with
|
|
4430
|
-
version = "
|
|
4414
|
+
description = "JSON file search with literal-based key path indexing";
|
|
4415
|
+
version = "2.0.0";
|
|
4431
4416
|
supportsFile(filepath) {
|
|
4432
4417
|
return isJsonFile(filepath);
|
|
4433
4418
|
}
|
|
4434
|
-
embeddingConfig = null;
|
|
4435
4419
|
symbolicIndex = null;
|
|
4420
|
+
literalIndex = null;
|
|
4436
4421
|
pendingSummaries = new Map;
|
|
4422
|
+
pendingLiterals = new Map;
|
|
4437
4423
|
rootDir = "";
|
|
4438
4424
|
logger = undefined;
|
|
4439
4425
|
async initialize(config) {
|
|
4440
|
-
this.embeddingConfig = getEmbeddingConfigFromModule(config);
|
|
4441
4426
|
this.logger = config.options?.logger;
|
|
4442
|
-
if (this.logger) {
|
|
4443
|
-
this.embeddingConfig = {
|
|
4444
|
-
...this.embeddingConfig,
|
|
4445
|
-
logger: this.logger
|
|
4446
|
-
};
|
|
4447
|
-
}
|
|
4448
|
-
configureEmbeddings(this.embeddingConfig);
|
|
4449
4427
|
this.pendingSummaries.clear();
|
|
4428
|
+
this.pendingLiterals.clear();
|
|
4450
4429
|
}
|
|
4451
4430
|
async indexFile(filepath, content, ctx) {
|
|
4452
4431
|
if (!isJsonFile(filepath)) {
|
|
4453
4432
|
return null;
|
|
4454
4433
|
}
|
|
4455
4434
|
this.rootDir = ctx.rootDir;
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
}
|
|
4460
|
-
if (textChunks.length === 0) {
|
|
4435
|
+
let parsed;
|
|
4436
|
+
try {
|
|
4437
|
+
parsed = JSON.parse(content);
|
|
4438
|
+
} catch {
|
|
4461
4439
|
return null;
|
|
4462
4440
|
}
|
|
4463
|
-
const
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
const
|
|
4468
|
-
const
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
try {
|
|
4477
|
-
return JSON.parse(content);
|
|
4478
|
-
} catch {
|
|
4479
|
-
return {};
|
|
4441
|
+
const fileBasename = path11.basename(filepath, path11.extname(filepath));
|
|
4442
|
+
const jsonPathLiterals = extractJsonPaths(parsed, fileBasename);
|
|
4443
|
+
const lines = content.split(`
|
|
4444
|
+
`);
|
|
4445
|
+
const lineCount = lines.length;
|
|
4446
|
+
const chunkId = generateChunkId(filepath, 1, lineCount);
|
|
4447
|
+
const chunks = [
|
|
4448
|
+
{
|
|
4449
|
+
id: chunkId,
|
|
4450
|
+
content,
|
|
4451
|
+
startLine: 1,
|
|
4452
|
+
endLine: lineCount,
|
|
4453
|
+
type: "file"
|
|
4480
4454
|
}
|
|
4481
|
-
|
|
4455
|
+
];
|
|
4456
|
+
if (jsonPathLiterals.length > 0) {
|
|
4457
|
+
this.pendingLiterals.set(chunkId, {
|
|
4458
|
+
filepath,
|
|
4459
|
+
literals: jsonPathLiterals
|
|
4460
|
+
});
|
|
4461
|
+
}
|
|
4482
4462
|
const stats = await ctx.getFileStats(filepath);
|
|
4483
|
-
const currentConfig = getEmbeddingConfig();
|
|
4484
4463
|
const moduleData = {
|
|
4485
|
-
|
|
4486
|
-
embeddingModel: currentConfig.model,
|
|
4487
|
-
jsonKeys
|
|
4464
|
+
jsonPaths: jsonPathLiterals.map((l) => l.value)
|
|
4488
4465
|
};
|
|
4489
|
-
const keywords = extractJsonKeywords(
|
|
4466
|
+
const keywords = extractJsonKeywords(parsed);
|
|
4490
4467
|
const fileSummary = {
|
|
4491
4468
|
filepath,
|
|
4492
|
-
chunkCount:
|
|
4469
|
+
chunkCount: 1,
|
|
4493
4470
|
chunkTypes: ["file"],
|
|
4494
4471
|
keywords,
|
|
4495
4472
|
exports: [],
|
|
@@ -4512,7 +4489,24 @@ class JsonModule {
|
|
|
4512
4489
|
}
|
|
4513
4490
|
this.symbolicIndex.buildBM25Index();
|
|
4514
4491
|
await this.symbolicIndex.save();
|
|
4492
|
+
this.literalIndex = new LiteralIndex(indexDir, this.id);
|
|
4493
|
+
await this.literalIndex.initialize();
|
|
4494
|
+
const indexedFilepaths = new Set;
|
|
4495
|
+
for (const filepath of this.pendingSummaries.keys()) {
|
|
4496
|
+
indexedFilepaths.add(filepath);
|
|
4497
|
+
}
|
|
4498
|
+
for (const { filepath } of this.pendingLiterals.values()) {
|
|
4499
|
+
indexedFilepaths.add(filepath);
|
|
4500
|
+
}
|
|
4501
|
+
for (const filepath of indexedFilepaths) {
|
|
4502
|
+
this.literalIndex.removeFile(filepath);
|
|
4503
|
+
}
|
|
4504
|
+
for (const [chunkId, { filepath, literals }] of this.pendingLiterals) {
|
|
4505
|
+
this.literalIndex.addLiterals(chunkId, filepath, literals);
|
|
4506
|
+
}
|
|
4507
|
+
await this.literalIndex.save();
|
|
4515
4508
|
this.pendingSummaries.clear();
|
|
4509
|
+
this.pendingLiterals.clear();
|
|
4516
4510
|
}
|
|
4517
4511
|
async search(query, ctx, options = {}) {
|
|
4518
4512
|
const {
|
|
@@ -4520,8 +4514,15 @@ class JsonModule {
|
|
|
4520
4514
|
minScore = DEFAULT_MIN_SCORE3,
|
|
4521
4515
|
filePatterns
|
|
4522
4516
|
} = options;
|
|
4517
|
+
const { literals: queryLiterals, remainingQuery } = parseQueryLiterals(query);
|
|
4523
4518
|
const indexDir = getRaggrepDir(ctx.rootDir, ctx.config);
|
|
4524
4519
|
const symbolicIndex = new SymbolicIndex(indexDir, this.id);
|
|
4520
|
+
const literalIndex = new LiteralIndex(indexDir, this.id);
|
|
4521
|
+
let literalMatchMap = new Map;
|
|
4522
|
+
try {
|
|
4523
|
+
await literalIndex.initialize();
|
|
4524
|
+
literalMatchMap = literalIndex.buildMatchMap(queryLiterals);
|
|
4525
|
+
} catch {}
|
|
4525
4526
|
let allFiles;
|
|
4526
4527
|
try {
|
|
4527
4528
|
await symbolicIndex.initialize();
|
|
@@ -4541,25 +4542,16 @@ class JsonModule {
|
|
|
4541
4542
|
});
|
|
4542
4543
|
});
|
|
4543
4544
|
}
|
|
4544
|
-
const queryEmbedding = await getEmbedding(query);
|
|
4545
4545
|
const bm25Index = new BM25Index;
|
|
4546
4546
|
const allChunksData = [];
|
|
4547
4547
|
for (const filepath of filesToSearch) {
|
|
4548
4548
|
const fileIndex = await ctx.loadFileIndex(filepath);
|
|
4549
4549
|
if (!fileIndex)
|
|
4550
4550
|
continue;
|
|
4551
|
-
const
|
|
4552
|
-
if (!moduleData?.embeddings)
|
|
4553
|
-
continue;
|
|
4554
|
-
for (let i = 0;i < fileIndex.chunks.length; i++) {
|
|
4555
|
-
const chunk = fileIndex.chunks[i];
|
|
4556
|
-
const embedding = moduleData.embeddings[i];
|
|
4557
|
-
if (!embedding)
|
|
4558
|
-
continue;
|
|
4551
|
+
for (const chunk of fileIndex.chunks) {
|
|
4559
4552
|
allChunksData.push({
|
|
4560
4553
|
filepath: fileIndex.filepath,
|
|
4561
|
-
chunk
|
|
4562
|
-
embedding
|
|
4554
|
+
chunk
|
|
4563
4555
|
});
|
|
4564
4556
|
bm25Index.addDocuments([{ id: chunk.id, content: chunk.content }]);
|
|
4565
4557
|
}
|
|
@@ -4569,32 +4561,70 @@ class JsonModule {
|
|
|
4569
4561
|
for (const result of bm25Results) {
|
|
4570
4562
|
bm25Scores.set(result.id, normalizeScore(result.score, 3));
|
|
4571
4563
|
}
|
|
4572
|
-
const queryTerms = extractQueryTerms(query);
|
|
4573
4564
|
const results = [];
|
|
4574
|
-
|
|
4575
|
-
|
|
4565
|
+
const processedChunkIds = new Set;
|
|
4566
|
+
for (const { filepath, chunk } of allChunksData) {
|
|
4576
4567
|
const bm25Score = bm25Scores.get(chunk.id) || 0;
|
|
4577
|
-
const
|
|
4578
|
-
|
|
4568
|
+
const literalMatches = literalMatchMap.get(chunk.id) || [];
|
|
4569
|
+
const literalContribution = calculateLiteralContribution(literalMatches, bm25Score > 0);
|
|
4570
|
+
const baseScore = BM25_WEIGHT2 * bm25Score;
|
|
4571
|
+
const boostedScore = applyLiteralBoost(baseScore, literalMatches, bm25Score > 0);
|
|
4572
|
+
const literalBase = literalMatches.length > 0 && bm25Score === 0 ? LITERAL_SCORING_CONSTANTS.BASE_SCORE * LITERAL_WEIGHT : 0;
|
|
4573
|
+
const finalScore = boostedScore + literalBase;
|
|
4574
|
+
processedChunkIds.add(chunk.id);
|
|
4575
|
+
if (finalScore >= minScore || literalMatches.length > 0) {
|
|
4579
4576
|
results.push({
|
|
4580
4577
|
filepath,
|
|
4581
4578
|
chunk,
|
|
4582
|
-
score:
|
|
4579
|
+
score: finalScore,
|
|
4583
4580
|
moduleId: this.id,
|
|
4584
4581
|
context: {
|
|
4585
|
-
|
|
4586
|
-
|
|
4582
|
+
bm25Score,
|
|
4583
|
+
literalMultiplier: literalContribution.multiplier,
|
|
4584
|
+
literalMatchType: literalContribution.bestMatchType,
|
|
4585
|
+
literalConfidence: literalContribution.bestConfidence,
|
|
4586
|
+
literalMatchCount: literalContribution.matchCount
|
|
4587
4587
|
}
|
|
4588
4588
|
});
|
|
4589
4589
|
}
|
|
4590
4590
|
}
|
|
4591
|
+
for (const [chunkId, matches] of literalMatchMap) {
|
|
4592
|
+
if (processedChunkIds.has(chunkId)) {
|
|
4593
|
+
continue;
|
|
4594
|
+
}
|
|
4595
|
+
const filepath = matches[0]?.filepath;
|
|
4596
|
+
if (!filepath)
|
|
4597
|
+
continue;
|
|
4598
|
+
const fileIndex = await ctx.loadFileIndex(filepath);
|
|
4599
|
+
if (!fileIndex)
|
|
4600
|
+
continue;
|
|
4601
|
+
const chunk = fileIndex.chunks.find((c) => c.id === chunkId);
|
|
4602
|
+
if (!chunk)
|
|
4603
|
+
continue;
|
|
4604
|
+
const literalContribution = calculateLiteralContribution(matches, false);
|
|
4605
|
+
const score = LITERAL_SCORING_CONSTANTS.BASE_SCORE * literalContribution.multiplier;
|
|
4606
|
+
processedChunkIds.add(chunkId);
|
|
4607
|
+
results.push({
|
|
4608
|
+
filepath,
|
|
4609
|
+
chunk,
|
|
4610
|
+
score,
|
|
4611
|
+
moduleId: this.id,
|
|
4612
|
+
context: {
|
|
4613
|
+
bm25Score: 0,
|
|
4614
|
+
literalMultiplier: literalContribution.multiplier,
|
|
4615
|
+
literalMatchType: literalContribution.bestMatchType,
|
|
4616
|
+
literalConfidence: literalContribution.bestConfidence,
|
|
4617
|
+
literalMatchCount: literalContribution.matchCount,
|
|
4618
|
+
literalOnly: true
|
|
4619
|
+
}
|
|
4620
|
+
});
|
|
4621
|
+
}
|
|
4591
4622
|
results.sort((a, b) => b.score - a.score);
|
|
4592
4623
|
return results.slice(0, topK);
|
|
4593
4624
|
}
|
|
4594
4625
|
}
|
|
4595
|
-
var DEFAULT_MIN_SCORE3 = 0.
|
|
4626
|
+
var DEFAULT_MIN_SCORE3 = 0.1, DEFAULT_TOP_K3 = 10, BM25_WEIGHT2 = 0.4, LITERAL_WEIGHT = 0.6, JSON_EXTENSIONS, supportsFile2;
|
|
4596
4627
|
var init_json = __esm(() => {
|
|
4597
|
-
init_embeddings();
|
|
4598
4628
|
init_services();
|
|
4599
4629
|
init_config2();
|
|
4600
4630
|
init_storage();
|
|
@@ -4864,7 +4894,7 @@ ${section.content}` : section.content,
|
|
|
4864
4894
|
].includes(t))) {
|
|
4865
4895
|
docBoost = 0.05;
|
|
4866
4896
|
}
|
|
4867
|
-
const hybridScore =
|
|
4897
|
+
const hybridScore = SEMANTIC_WEIGHT2 * semanticScore + BM25_WEIGHT3 * bm25Score + docBoost;
|
|
4868
4898
|
if (hybridScore >= minScore || bm25Score > 0.3) {
|
|
4869
4899
|
results.push({
|
|
4870
4900
|
filepath,
|
|
@@ -4883,7 +4913,7 @@ ${section.content}` : section.content,
|
|
|
4883
4913
|
return results.slice(0, topK);
|
|
4884
4914
|
}
|
|
4885
4915
|
}
|
|
4886
|
-
var DEFAULT_MIN_SCORE4 = 0.15, DEFAULT_TOP_K4 = 10,
|
|
4916
|
+
var DEFAULT_MIN_SCORE4 = 0.15, DEFAULT_TOP_K4 = 10, SEMANTIC_WEIGHT2 = 0.7, BM25_WEIGHT3 = 0.3, MARKDOWN_EXTENSIONS, supportsFile3;
|
|
4887
4917
|
var init_markdown = __esm(() => {
|
|
4888
4918
|
init_embeddings();
|
|
4889
4919
|
init_services();
|
|
@@ -4893,6 +4923,212 @@ var init_markdown = __esm(() => {
|
|
|
4893
4923
|
supportsFile3 = isMarkdownFile;
|
|
4894
4924
|
});
|
|
4895
4925
|
|
|
4926
|
+
// node_modules/balanced-match/index.js
|
|
4927
|
+
var require_balanced_match = __commonJS((exports, module) => {
|
|
4928
|
+
module.exports = balanced;
|
|
4929
|
+
function balanced(a, b, str) {
|
|
4930
|
+
if (a instanceof RegExp)
|
|
4931
|
+
a = maybeMatch(a, str);
|
|
4932
|
+
if (b instanceof RegExp)
|
|
4933
|
+
b = maybeMatch(b, str);
|
|
4934
|
+
var r = range(a, b, str);
|
|
4935
|
+
return r && {
|
|
4936
|
+
start: r[0],
|
|
4937
|
+
end: r[1],
|
|
4938
|
+
pre: str.slice(0, r[0]),
|
|
4939
|
+
body: str.slice(r[0] + a.length, r[1]),
|
|
4940
|
+
post: str.slice(r[1] + b.length)
|
|
4941
|
+
};
|
|
4942
|
+
}
|
|
4943
|
+
function maybeMatch(reg, str) {
|
|
4944
|
+
var m = str.match(reg);
|
|
4945
|
+
return m ? m[0] : null;
|
|
4946
|
+
}
|
|
4947
|
+
balanced.range = range;
|
|
4948
|
+
function range(a, b, str) {
|
|
4949
|
+
var begs, beg, left, right, result;
|
|
4950
|
+
var ai = str.indexOf(a);
|
|
4951
|
+
var bi = str.indexOf(b, ai + 1);
|
|
4952
|
+
var i = ai;
|
|
4953
|
+
if (ai >= 0 && bi > 0) {
|
|
4954
|
+
if (a === b) {
|
|
4955
|
+
return [ai, bi];
|
|
4956
|
+
}
|
|
4957
|
+
begs = [];
|
|
4958
|
+
left = str.length;
|
|
4959
|
+
while (i >= 0 && !result) {
|
|
4960
|
+
if (i == ai) {
|
|
4961
|
+
begs.push(i);
|
|
4962
|
+
ai = str.indexOf(a, i + 1);
|
|
4963
|
+
} else if (begs.length == 1) {
|
|
4964
|
+
result = [begs.pop(), bi];
|
|
4965
|
+
} else {
|
|
4966
|
+
beg = begs.pop();
|
|
4967
|
+
if (beg < left) {
|
|
4968
|
+
left = beg;
|
|
4969
|
+
right = bi;
|
|
4970
|
+
}
|
|
4971
|
+
bi = str.indexOf(b, i + 1);
|
|
4972
|
+
}
|
|
4973
|
+
i = ai < bi && ai >= 0 ? ai : bi;
|
|
4974
|
+
}
|
|
4975
|
+
if (begs.length) {
|
|
4976
|
+
result = [left, right];
|
|
4977
|
+
}
|
|
4978
|
+
}
|
|
4979
|
+
return result;
|
|
4980
|
+
}
|
|
4981
|
+
});
|
|
4982
|
+
|
|
4983
|
+
// node_modules/brace-expansion/index.js
|
|
4984
|
+
var require_brace_expansion = __commonJS((exports, module) => {
|
|
4985
|
+
var balanced = require_balanced_match();
|
|
4986
|
+
module.exports = expandTop;
|
|
4987
|
+
var escSlash = "\x00SLASH" + Math.random() + "\x00";
|
|
4988
|
+
var escOpen = "\x00OPEN" + Math.random() + "\x00";
|
|
4989
|
+
var escClose = "\x00CLOSE" + Math.random() + "\x00";
|
|
4990
|
+
var escComma = "\x00COMMA" + Math.random() + "\x00";
|
|
4991
|
+
var escPeriod = "\x00PERIOD" + Math.random() + "\x00";
|
|
4992
|
+
function numeric(str) {
|
|
4993
|
+
return parseInt(str, 10) == str ? parseInt(str, 10) : str.charCodeAt(0);
|
|
4994
|
+
}
|
|
4995
|
+
function escapeBraces(str) {
|
|
4996
|
+
return str.split("\\\\").join(escSlash).split("\\{").join(escOpen).split("\\}").join(escClose).split("\\,").join(escComma).split("\\.").join(escPeriod);
|
|
4997
|
+
}
|
|
4998
|
+
function unescapeBraces(str) {
|
|
4999
|
+
return str.split(escSlash).join("\\").split(escOpen).join("{").split(escClose).join("}").split(escComma).join(",").split(escPeriod).join(".");
|
|
5000
|
+
}
|
|
5001
|
+
function parseCommaParts(str) {
|
|
5002
|
+
if (!str)
|
|
5003
|
+
return [""];
|
|
5004
|
+
var parts = [];
|
|
5005
|
+
var m = balanced("{", "}", str);
|
|
5006
|
+
if (!m)
|
|
5007
|
+
return str.split(",");
|
|
5008
|
+
var pre = m.pre;
|
|
5009
|
+
var body = m.body;
|
|
5010
|
+
var post = m.post;
|
|
5011
|
+
var p = pre.split(",");
|
|
5012
|
+
p[p.length - 1] += "{" + body + "}";
|
|
5013
|
+
var postParts = parseCommaParts(post);
|
|
5014
|
+
if (post.length) {
|
|
5015
|
+
p[p.length - 1] += postParts.shift();
|
|
5016
|
+
p.push.apply(p, postParts);
|
|
5017
|
+
}
|
|
5018
|
+
parts.push.apply(parts, p);
|
|
5019
|
+
return parts;
|
|
5020
|
+
}
|
|
5021
|
+
function expandTop(str) {
|
|
5022
|
+
if (!str)
|
|
5023
|
+
return [];
|
|
5024
|
+
if (str.substr(0, 2) === "{}") {
|
|
5025
|
+
str = "\\{\\}" + str.substr(2);
|
|
5026
|
+
}
|
|
5027
|
+
return expand(escapeBraces(str), true).map(unescapeBraces);
|
|
5028
|
+
}
|
|
5029
|
+
function embrace(str) {
|
|
5030
|
+
return "{" + str + "}";
|
|
5031
|
+
}
|
|
5032
|
+
function isPadded(el) {
|
|
5033
|
+
return /^-?0\d/.test(el);
|
|
5034
|
+
}
|
|
5035
|
+
function lte(i, y) {
|
|
5036
|
+
return i <= y;
|
|
5037
|
+
}
|
|
5038
|
+
function gte(i, y) {
|
|
5039
|
+
return i >= y;
|
|
5040
|
+
}
|
|
5041
|
+
function expand(str, isTop) {
|
|
5042
|
+
var expansions = [];
|
|
5043
|
+
var m = balanced("{", "}", str);
|
|
5044
|
+
if (!m)
|
|
5045
|
+
return [str];
|
|
5046
|
+
var pre = m.pre;
|
|
5047
|
+
var post = m.post.length ? expand(m.post, false) : [""];
|
|
5048
|
+
if (/\$$/.test(m.pre)) {
|
|
5049
|
+
for (var k = 0;k < post.length; k++) {
|
|
5050
|
+
var expansion = pre + "{" + m.body + "}" + post[k];
|
|
5051
|
+
expansions.push(expansion);
|
|
5052
|
+
}
|
|
5053
|
+
} else {
|
|
5054
|
+
var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
|
|
5055
|
+
var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
|
|
5056
|
+
var isSequence = isNumericSequence || isAlphaSequence;
|
|
5057
|
+
var isOptions = m.body.indexOf(",") >= 0;
|
|
5058
|
+
if (!isSequence && !isOptions) {
|
|
5059
|
+
if (m.post.match(/,(?!,).*\}/)) {
|
|
5060
|
+
str = m.pre + "{" + m.body + escClose + m.post;
|
|
5061
|
+
return expand(str);
|
|
5062
|
+
}
|
|
5063
|
+
return [str];
|
|
5064
|
+
}
|
|
5065
|
+
var n;
|
|
5066
|
+
if (isSequence) {
|
|
5067
|
+
n = m.body.split(/\.\./);
|
|
5068
|
+
} else {
|
|
5069
|
+
n = parseCommaParts(m.body);
|
|
5070
|
+
if (n.length === 1) {
|
|
5071
|
+
n = expand(n[0], false).map(embrace);
|
|
5072
|
+
if (n.length === 1) {
|
|
5073
|
+
return post.map(function(p) {
|
|
5074
|
+
return m.pre + n[0] + p;
|
|
5075
|
+
});
|
|
5076
|
+
}
|
|
5077
|
+
}
|
|
5078
|
+
}
|
|
5079
|
+
var N;
|
|
5080
|
+
if (isSequence) {
|
|
5081
|
+
var x = numeric(n[0]);
|
|
5082
|
+
var y = numeric(n[1]);
|
|
5083
|
+
var width = Math.max(n[0].length, n[1].length);
|
|
5084
|
+
var incr = n.length == 3 ? Math.abs(numeric(n[2])) : 1;
|
|
5085
|
+
var test = lte;
|
|
5086
|
+
var reverse = y < x;
|
|
5087
|
+
if (reverse) {
|
|
5088
|
+
incr *= -1;
|
|
5089
|
+
test = gte;
|
|
5090
|
+
}
|
|
5091
|
+
var pad = n.some(isPadded);
|
|
5092
|
+
N = [];
|
|
5093
|
+
for (var i = x;test(i, y); i += incr) {
|
|
5094
|
+
var c;
|
|
5095
|
+
if (isAlphaSequence) {
|
|
5096
|
+
c = String.fromCharCode(i);
|
|
5097
|
+
if (c === "\\")
|
|
5098
|
+
c = "";
|
|
5099
|
+
} else {
|
|
5100
|
+
c = String(i);
|
|
5101
|
+
if (pad) {
|
|
5102
|
+
var need = width - c.length;
|
|
5103
|
+
if (need > 0) {
|
|
5104
|
+
var z = new Array(need + 1).join("0");
|
|
5105
|
+
if (i < 0)
|
|
5106
|
+
c = "-" + z + c.slice(1);
|
|
5107
|
+
else
|
|
5108
|
+
c = z + c;
|
|
5109
|
+
}
|
|
5110
|
+
}
|
|
5111
|
+
}
|
|
5112
|
+
N.push(c);
|
|
5113
|
+
}
|
|
5114
|
+
} else {
|
|
5115
|
+
N = [];
|
|
5116
|
+
for (var j = 0;j < n.length; j++) {
|
|
5117
|
+
N.push.apply(N, expand(n[j], false));
|
|
5118
|
+
}
|
|
5119
|
+
}
|
|
5120
|
+
for (var j = 0;j < N.length; j++) {
|
|
5121
|
+
for (var k = 0;k < post.length; k++) {
|
|
5122
|
+
var expansion = pre + N[j] + post[k];
|
|
5123
|
+
if (!isTop || isSequence || expansion)
|
|
5124
|
+
expansions.push(expansion);
|
|
5125
|
+
}
|
|
5126
|
+
}
|
|
5127
|
+
}
|
|
5128
|
+
return expansions;
|
|
5129
|
+
}
|
|
5130
|
+
});
|
|
5131
|
+
|
|
4896
5132
|
// src/app/indexer/index.ts
|
|
4897
5133
|
init_config2();
|
|
4898
5134
|
import { glob } from "glob";
|
|
@@ -5873,7 +6109,1220 @@ async function getIndexStatus(rootDir) {
|
|
|
5873
6109
|
|
|
5874
6110
|
// src/app/search/index.ts
|
|
5875
6111
|
import * as fs8 from "fs/promises";
|
|
5876
|
-
import * as
|
|
6112
|
+
import * as path17 from "path";
|
|
6113
|
+
|
|
6114
|
+
// node_modules/minimatch/dist/esm/index.js
|
|
6115
|
+
var import_brace_expansion = __toESM(require_brace_expansion(), 1);
|
|
6116
|
+
|
|
6117
|
+
// node_modules/minimatch/dist/esm/assert-valid-pattern.js
|
|
6118
|
+
var MAX_PATTERN_LENGTH = 1024 * 64;
|
|
6119
|
+
var assertValidPattern = (pattern) => {
|
|
6120
|
+
if (typeof pattern !== "string") {
|
|
6121
|
+
throw new TypeError("invalid pattern");
|
|
6122
|
+
}
|
|
6123
|
+
if (pattern.length > MAX_PATTERN_LENGTH) {
|
|
6124
|
+
throw new TypeError("pattern is too long");
|
|
6125
|
+
}
|
|
6126
|
+
};
|
|
6127
|
+
|
|
6128
|
+
// node_modules/minimatch/dist/esm/brace-expressions.js
|
|
6129
|
+
var posixClasses = {
|
|
6130
|
+
"[:alnum:]": ["\\p{L}\\p{Nl}\\p{Nd}", true],
|
|
6131
|
+
"[:alpha:]": ["\\p{L}\\p{Nl}", true],
|
|
6132
|
+
"[:ascii:]": ["\\x" + "00-\\x" + "7f", false],
|
|
6133
|
+
"[:blank:]": ["\\p{Zs}\\t", true],
|
|
6134
|
+
"[:cntrl:]": ["\\p{Cc}", true],
|
|
6135
|
+
"[:digit:]": ["\\p{Nd}", true],
|
|
6136
|
+
"[:graph:]": ["\\p{Z}\\p{C}", true, true],
|
|
6137
|
+
"[:lower:]": ["\\p{Ll}", true],
|
|
6138
|
+
"[:print:]": ["\\p{C}", true],
|
|
6139
|
+
"[:punct:]": ["\\p{P}", true],
|
|
6140
|
+
"[:space:]": ["\\p{Z}\\t\\r\\n\\v\\f", true],
|
|
6141
|
+
"[:upper:]": ["\\p{Lu}", true],
|
|
6142
|
+
"[:word:]": ["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}", true],
|
|
6143
|
+
"[:xdigit:]": ["A-Fa-f0-9", false]
|
|
6144
|
+
};
|
|
6145
|
+
var braceEscape = (s) => s.replace(/[[\]\\-]/g, "\\$&");
|
|
6146
|
+
var regexpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
6147
|
+
var rangesToString = (ranges) => ranges.join("");
|
|
6148
|
+
var parseClass = (glob2, position) => {
|
|
6149
|
+
const pos = position;
|
|
6150
|
+
if (glob2.charAt(pos) !== "[") {
|
|
6151
|
+
throw new Error("not in a brace expression");
|
|
6152
|
+
}
|
|
6153
|
+
const ranges = [];
|
|
6154
|
+
const negs = [];
|
|
6155
|
+
let i = pos + 1;
|
|
6156
|
+
let sawStart = false;
|
|
6157
|
+
let uflag = false;
|
|
6158
|
+
let escaping = false;
|
|
6159
|
+
let negate = false;
|
|
6160
|
+
let endPos = pos;
|
|
6161
|
+
let rangeStart = "";
|
|
6162
|
+
WHILE:
|
|
6163
|
+
while (i < glob2.length) {
|
|
6164
|
+
const c = glob2.charAt(i);
|
|
6165
|
+
if ((c === "!" || c === "^") && i === pos + 1) {
|
|
6166
|
+
negate = true;
|
|
6167
|
+
i++;
|
|
6168
|
+
continue;
|
|
6169
|
+
}
|
|
6170
|
+
if (c === "]" && sawStart && !escaping) {
|
|
6171
|
+
endPos = i + 1;
|
|
6172
|
+
break;
|
|
6173
|
+
}
|
|
6174
|
+
sawStart = true;
|
|
6175
|
+
if (c === "\\") {
|
|
6176
|
+
if (!escaping) {
|
|
6177
|
+
escaping = true;
|
|
6178
|
+
i++;
|
|
6179
|
+
continue;
|
|
6180
|
+
}
|
|
6181
|
+
}
|
|
6182
|
+
if (c === "[" && !escaping) {
|
|
6183
|
+
for (const [cls, [unip, u, neg]] of Object.entries(posixClasses)) {
|
|
6184
|
+
if (glob2.startsWith(cls, i)) {
|
|
6185
|
+
if (rangeStart) {
|
|
6186
|
+
return ["$.", false, glob2.length - pos, true];
|
|
6187
|
+
}
|
|
6188
|
+
i += cls.length;
|
|
6189
|
+
if (neg)
|
|
6190
|
+
negs.push(unip);
|
|
6191
|
+
else
|
|
6192
|
+
ranges.push(unip);
|
|
6193
|
+
uflag = uflag || u;
|
|
6194
|
+
continue WHILE;
|
|
6195
|
+
}
|
|
6196
|
+
}
|
|
6197
|
+
}
|
|
6198
|
+
escaping = false;
|
|
6199
|
+
if (rangeStart) {
|
|
6200
|
+
if (c > rangeStart) {
|
|
6201
|
+
ranges.push(braceEscape(rangeStart) + "-" + braceEscape(c));
|
|
6202
|
+
} else if (c === rangeStart) {
|
|
6203
|
+
ranges.push(braceEscape(c));
|
|
6204
|
+
}
|
|
6205
|
+
rangeStart = "";
|
|
6206
|
+
i++;
|
|
6207
|
+
continue;
|
|
6208
|
+
}
|
|
6209
|
+
if (glob2.startsWith("-]", i + 1)) {
|
|
6210
|
+
ranges.push(braceEscape(c + "-"));
|
|
6211
|
+
i += 2;
|
|
6212
|
+
continue;
|
|
6213
|
+
}
|
|
6214
|
+
if (glob2.startsWith("-", i + 1)) {
|
|
6215
|
+
rangeStart = c;
|
|
6216
|
+
i += 2;
|
|
6217
|
+
continue;
|
|
6218
|
+
}
|
|
6219
|
+
ranges.push(braceEscape(c));
|
|
6220
|
+
i++;
|
|
6221
|
+
}
|
|
6222
|
+
if (endPos < i) {
|
|
6223
|
+
return ["", false, 0, false];
|
|
6224
|
+
}
|
|
6225
|
+
if (!ranges.length && !negs.length) {
|
|
6226
|
+
return ["$.", false, glob2.length - pos, true];
|
|
6227
|
+
}
|
|
6228
|
+
if (negs.length === 0 && ranges.length === 1 && /^\\?.$/.test(ranges[0]) && !negate) {
|
|
6229
|
+
const r = ranges[0].length === 2 ? ranges[0].slice(-1) : ranges[0];
|
|
6230
|
+
return [regexpEscape(r), false, endPos - pos, false];
|
|
6231
|
+
}
|
|
6232
|
+
const sranges = "[" + (negate ? "^" : "") + rangesToString(ranges) + "]";
|
|
6233
|
+
const snegs = "[" + (negate ? "" : "^") + rangesToString(negs) + "]";
|
|
6234
|
+
const comb = ranges.length && negs.length ? "(" + sranges + "|" + snegs + ")" : ranges.length ? sranges : snegs;
|
|
6235
|
+
return [comb, uflag, endPos - pos, true];
|
|
6236
|
+
};
|
|
6237
|
+
|
|
6238
|
+
// node_modules/minimatch/dist/esm/unescape.js
|
|
6239
|
+
var unescape = (s, { windowsPathsNoEscape = false } = {}) => {
|
|
6240
|
+
return windowsPathsNoEscape ? s.replace(/\[([^\/\\])\]/g, "$1") : s.replace(/((?!\\).|^)\[([^\/\\])\]/g, "$1$2").replace(/\\([^\/])/g, "$1");
|
|
6241
|
+
};
|
|
6242
|
+
|
|
6243
|
+
// node_modules/minimatch/dist/esm/ast.js
|
|
6244
|
+
var types = new Set(["!", "?", "+", "*", "@"]);
|
|
6245
|
+
var isExtglobType = (c) => types.has(c);
|
|
6246
|
+
var startNoTraversal = "(?!(?:^|/)\\.\\.?(?:$|/))";
|
|
6247
|
+
var startNoDot = "(?!\\.)";
|
|
6248
|
+
var addPatternStart = new Set(["[", "."]);
|
|
6249
|
+
var justDots = new Set(["..", "."]);
|
|
6250
|
+
var reSpecials = new Set("().*{}+?[]^$\\!");
|
|
6251
|
+
var regExpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
6252
|
+
var qmark = "[^/]";
|
|
6253
|
+
var star = qmark + "*?";
|
|
6254
|
+
var starNoEmpty = qmark + "+?";
|
|
6255
|
+
|
|
6256
|
+
class AST {
|
|
6257
|
+
type;
|
|
6258
|
+
#root;
|
|
6259
|
+
#hasMagic;
|
|
6260
|
+
#uflag = false;
|
|
6261
|
+
#parts = [];
|
|
6262
|
+
#parent;
|
|
6263
|
+
#parentIndex;
|
|
6264
|
+
#negs;
|
|
6265
|
+
#filledNegs = false;
|
|
6266
|
+
#options;
|
|
6267
|
+
#toString;
|
|
6268
|
+
#emptyExt = false;
|
|
6269
|
+
constructor(type, parent, options = {}) {
|
|
6270
|
+
this.type = type;
|
|
6271
|
+
if (type)
|
|
6272
|
+
this.#hasMagic = true;
|
|
6273
|
+
this.#parent = parent;
|
|
6274
|
+
this.#root = this.#parent ? this.#parent.#root : this;
|
|
6275
|
+
this.#options = this.#root === this ? options : this.#root.#options;
|
|
6276
|
+
this.#negs = this.#root === this ? [] : this.#root.#negs;
|
|
6277
|
+
if (type === "!" && !this.#root.#filledNegs)
|
|
6278
|
+
this.#negs.push(this);
|
|
6279
|
+
this.#parentIndex = this.#parent ? this.#parent.#parts.length : 0;
|
|
6280
|
+
}
|
|
6281
|
+
get hasMagic() {
|
|
6282
|
+
if (this.#hasMagic !== undefined)
|
|
6283
|
+
return this.#hasMagic;
|
|
6284
|
+
for (const p of this.#parts) {
|
|
6285
|
+
if (typeof p === "string")
|
|
6286
|
+
continue;
|
|
6287
|
+
if (p.type || p.hasMagic)
|
|
6288
|
+
return this.#hasMagic = true;
|
|
6289
|
+
}
|
|
6290
|
+
return this.#hasMagic;
|
|
6291
|
+
}
|
|
6292
|
+
toString() {
|
|
6293
|
+
if (this.#toString !== undefined)
|
|
6294
|
+
return this.#toString;
|
|
6295
|
+
if (!this.type) {
|
|
6296
|
+
return this.#toString = this.#parts.map((p) => String(p)).join("");
|
|
6297
|
+
} else {
|
|
6298
|
+
return this.#toString = this.type + "(" + this.#parts.map((p) => String(p)).join("|") + ")";
|
|
6299
|
+
}
|
|
6300
|
+
}
|
|
6301
|
+
#fillNegs() {
|
|
6302
|
+
if (this !== this.#root)
|
|
6303
|
+
throw new Error("should only call on root");
|
|
6304
|
+
if (this.#filledNegs)
|
|
6305
|
+
return this;
|
|
6306
|
+
this.toString();
|
|
6307
|
+
this.#filledNegs = true;
|
|
6308
|
+
let n;
|
|
6309
|
+
while (n = this.#negs.pop()) {
|
|
6310
|
+
if (n.type !== "!")
|
|
6311
|
+
continue;
|
|
6312
|
+
let p = n;
|
|
6313
|
+
let pp = p.#parent;
|
|
6314
|
+
while (pp) {
|
|
6315
|
+
for (let i = p.#parentIndex + 1;!pp.type && i < pp.#parts.length; i++) {
|
|
6316
|
+
for (const part of n.#parts) {
|
|
6317
|
+
if (typeof part === "string") {
|
|
6318
|
+
throw new Error("string part in extglob AST??");
|
|
6319
|
+
}
|
|
6320
|
+
part.copyIn(pp.#parts[i]);
|
|
6321
|
+
}
|
|
6322
|
+
}
|
|
6323
|
+
p = pp;
|
|
6324
|
+
pp = p.#parent;
|
|
6325
|
+
}
|
|
6326
|
+
}
|
|
6327
|
+
return this;
|
|
6328
|
+
}
|
|
6329
|
+
push(...parts) {
|
|
6330
|
+
for (const p of parts) {
|
|
6331
|
+
if (p === "")
|
|
6332
|
+
continue;
|
|
6333
|
+
if (typeof p !== "string" && !(p instanceof AST && p.#parent === this)) {
|
|
6334
|
+
throw new Error("invalid part: " + p);
|
|
6335
|
+
}
|
|
6336
|
+
this.#parts.push(p);
|
|
6337
|
+
}
|
|
6338
|
+
}
|
|
6339
|
+
toJSON() {
|
|
6340
|
+
const ret = this.type === null ? this.#parts.slice().map((p) => typeof p === "string" ? p : p.toJSON()) : [this.type, ...this.#parts.map((p) => p.toJSON())];
|
|
6341
|
+
if (this.isStart() && !this.type)
|
|
6342
|
+
ret.unshift([]);
|
|
6343
|
+
if (this.isEnd() && (this === this.#root || this.#root.#filledNegs && this.#parent?.type === "!")) {
|
|
6344
|
+
ret.push({});
|
|
6345
|
+
}
|
|
6346
|
+
return ret;
|
|
6347
|
+
}
|
|
6348
|
+
isStart() {
|
|
6349
|
+
if (this.#root === this)
|
|
6350
|
+
return true;
|
|
6351
|
+
if (!this.#parent?.isStart())
|
|
6352
|
+
return false;
|
|
6353
|
+
if (this.#parentIndex === 0)
|
|
6354
|
+
return true;
|
|
6355
|
+
const p = this.#parent;
|
|
6356
|
+
for (let i = 0;i < this.#parentIndex; i++) {
|
|
6357
|
+
const pp = p.#parts[i];
|
|
6358
|
+
if (!(pp instanceof AST && pp.type === "!")) {
|
|
6359
|
+
return false;
|
|
6360
|
+
}
|
|
6361
|
+
}
|
|
6362
|
+
return true;
|
|
6363
|
+
}
|
|
6364
|
+
isEnd() {
|
|
6365
|
+
if (this.#root === this)
|
|
6366
|
+
return true;
|
|
6367
|
+
if (this.#parent?.type === "!")
|
|
6368
|
+
return true;
|
|
6369
|
+
if (!this.#parent?.isEnd())
|
|
6370
|
+
return false;
|
|
6371
|
+
if (!this.type)
|
|
6372
|
+
return this.#parent?.isEnd();
|
|
6373
|
+
const pl = this.#parent ? this.#parent.#parts.length : 0;
|
|
6374
|
+
return this.#parentIndex === pl - 1;
|
|
6375
|
+
}
|
|
6376
|
+
copyIn(part) {
|
|
6377
|
+
if (typeof part === "string")
|
|
6378
|
+
this.push(part);
|
|
6379
|
+
else
|
|
6380
|
+
this.push(part.clone(this));
|
|
6381
|
+
}
|
|
6382
|
+
clone(parent) {
|
|
6383
|
+
const c = new AST(this.type, parent);
|
|
6384
|
+
for (const p of this.#parts) {
|
|
6385
|
+
c.copyIn(p);
|
|
6386
|
+
}
|
|
6387
|
+
return c;
|
|
6388
|
+
}
|
|
6389
|
+
static #parseAST(str, ast, pos, opt) {
|
|
6390
|
+
let escaping = false;
|
|
6391
|
+
let inBrace = false;
|
|
6392
|
+
let braceStart = -1;
|
|
6393
|
+
let braceNeg = false;
|
|
6394
|
+
if (ast.type === null) {
|
|
6395
|
+
let i2 = pos;
|
|
6396
|
+
let acc2 = "";
|
|
6397
|
+
while (i2 < str.length) {
|
|
6398
|
+
const c = str.charAt(i2++);
|
|
6399
|
+
if (escaping || c === "\\") {
|
|
6400
|
+
escaping = !escaping;
|
|
6401
|
+
acc2 += c;
|
|
6402
|
+
continue;
|
|
6403
|
+
}
|
|
6404
|
+
if (inBrace) {
|
|
6405
|
+
if (i2 === braceStart + 1) {
|
|
6406
|
+
if (c === "^" || c === "!") {
|
|
6407
|
+
braceNeg = true;
|
|
6408
|
+
}
|
|
6409
|
+
} else if (c === "]" && !(i2 === braceStart + 2 && braceNeg)) {
|
|
6410
|
+
inBrace = false;
|
|
6411
|
+
}
|
|
6412
|
+
acc2 += c;
|
|
6413
|
+
continue;
|
|
6414
|
+
} else if (c === "[") {
|
|
6415
|
+
inBrace = true;
|
|
6416
|
+
braceStart = i2;
|
|
6417
|
+
braceNeg = false;
|
|
6418
|
+
acc2 += c;
|
|
6419
|
+
continue;
|
|
6420
|
+
}
|
|
6421
|
+
if (!opt.noext && isExtglobType(c) && str.charAt(i2) === "(") {
|
|
6422
|
+
ast.push(acc2);
|
|
6423
|
+
acc2 = "";
|
|
6424
|
+
const ext = new AST(c, ast);
|
|
6425
|
+
i2 = AST.#parseAST(str, ext, i2, opt);
|
|
6426
|
+
ast.push(ext);
|
|
6427
|
+
continue;
|
|
6428
|
+
}
|
|
6429
|
+
acc2 += c;
|
|
6430
|
+
}
|
|
6431
|
+
ast.push(acc2);
|
|
6432
|
+
return i2;
|
|
6433
|
+
}
|
|
6434
|
+
let i = pos + 1;
|
|
6435
|
+
let part = new AST(null, ast);
|
|
6436
|
+
const parts = [];
|
|
6437
|
+
let acc = "";
|
|
6438
|
+
while (i < str.length) {
|
|
6439
|
+
const c = str.charAt(i++);
|
|
6440
|
+
if (escaping || c === "\\") {
|
|
6441
|
+
escaping = !escaping;
|
|
6442
|
+
acc += c;
|
|
6443
|
+
continue;
|
|
6444
|
+
}
|
|
6445
|
+
if (inBrace) {
|
|
6446
|
+
if (i === braceStart + 1) {
|
|
6447
|
+
if (c === "^" || c === "!") {
|
|
6448
|
+
braceNeg = true;
|
|
6449
|
+
}
|
|
6450
|
+
} else if (c === "]" && !(i === braceStart + 2 && braceNeg)) {
|
|
6451
|
+
inBrace = false;
|
|
6452
|
+
}
|
|
6453
|
+
acc += c;
|
|
6454
|
+
continue;
|
|
6455
|
+
} else if (c === "[") {
|
|
6456
|
+
inBrace = true;
|
|
6457
|
+
braceStart = i;
|
|
6458
|
+
braceNeg = false;
|
|
6459
|
+
acc += c;
|
|
6460
|
+
continue;
|
|
6461
|
+
}
|
|
6462
|
+
if (isExtglobType(c) && str.charAt(i) === "(") {
|
|
6463
|
+
part.push(acc);
|
|
6464
|
+
acc = "";
|
|
6465
|
+
const ext = new AST(c, part);
|
|
6466
|
+
part.push(ext);
|
|
6467
|
+
i = AST.#parseAST(str, ext, i, opt);
|
|
6468
|
+
continue;
|
|
6469
|
+
}
|
|
6470
|
+
if (c === "|") {
|
|
6471
|
+
part.push(acc);
|
|
6472
|
+
acc = "";
|
|
6473
|
+
parts.push(part);
|
|
6474
|
+
part = new AST(null, ast);
|
|
6475
|
+
continue;
|
|
6476
|
+
}
|
|
6477
|
+
if (c === ")") {
|
|
6478
|
+
if (acc === "" && ast.#parts.length === 0) {
|
|
6479
|
+
ast.#emptyExt = true;
|
|
6480
|
+
}
|
|
6481
|
+
part.push(acc);
|
|
6482
|
+
acc = "";
|
|
6483
|
+
ast.push(...parts, part);
|
|
6484
|
+
return i;
|
|
6485
|
+
}
|
|
6486
|
+
acc += c;
|
|
6487
|
+
}
|
|
6488
|
+
ast.type = null;
|
|
6489
|
+
ast.#hasMagic = undefined;
|
|
6490
|
+
ast.#parts = [str.substring(pos - 1)];
|
|
6491
|
+
return i;
|
|
6492
|
+
}
|
|
6493
|
+
static fromGlob(pattern, options = {}) {
|
|
6494
|
+
const ast = new AST(null, undefined, options);
|
|
6495
|
+
AST.#parseAST(pattern, ast, 0, options);
|
|
6496
|
+
return ast;
|
|
6497
|
+
}
|
|
6498
|
+
toMMPattern() {
|
|
6499
|
+
if (this !== this.#root)
|
|
6500
|
+
return this.#root.toMMPattern();
|
|
6501
|
+
const glob2 = this.toString();
|
|
6502
|
+
const [re, body, hasMagic, uflag] = this.toRegExpSource();
|
|
6503
|
+
const anyMagic = hasMagic || this.#hasMagic || this.#options.nocase && !this.#options.nocaseMagicOnly && glob2.toUpperCase() !== glob2.toLowerCase();
|
|
6504
|
+
if (!anyMagic) {
|
|
6505
|
+
return body;
|
|
6506
|
+
}
|
|
6507
|
+
const flags = (this.#options.nocase ? "i" : "") + (uflag ? "u" : "");
|
|
6508
|
+
return Object.assign(new RegExp(`^${re}$`, flags), {
|
|
6509
|
+
_src: re,
|
|
6510
|
+
_glob: glob2
|
|
6511
|
+
});
|
|
6512
|
+
}
|
|
6513
|
+
get options() {
|
|
6514
|
+
return this.#options;
|
|
6515
|
+
}
|
|
6516
|
+
toRegExpSource(allowDot) {
|
|
6517
|
+
const dot = allowDot ?? !!this.#options.dot;
|
|
6518
|
+
if (this.#root === this)
|
|
6519
|
+
this.#fillNegs();
|
|
6520
|
+
if (!this.type) {
|
|
6521
|
+
const noEmpty = this.isStart() && this.isEnd();
|
|
6522
|
+
const src = this.#parts.map((p) => {
|
|
6523
|
+
const [re, _, hasMagic, uflag] = typeof p === "string" ? AST.#parseGlob(p, this.#hasMagic, noEmpty) : p.toRegExpSource(allowDot);
|
|
6524
|
+
this.#hasMagic = this.#hasMagic || hasMagic;
|
|
6525
|
+
this.#uflag = this.#uflag || uflag;
|
|
6526
|
+
return re;
|
|
6527
|
+
}).join("");
|
|
6528
|
+
let start2 = "";
|
|
6529
|
+
if (this.isStart()) {
|
|
6530
|
+
if (typeof this.#parts[0] === "string") {
|
|
6531
|
+
const dotTravAllowed = this.#parts.length === 1 && justDots.has(this.#parts[0]);
|
|
6532
|
+
if (!dotTravAllowed) {
|
|
6533
|
+
const aps = addPatternStart;
|
|
6534
|
+
const needNoTrav = dot && aps.has(src.charAt(0)) || src.startsWith("\\.") && aps.has(src.charAt(2)) || src.startsWith("\\.\\.") && aps.has(src.charAt(4));
|
|
6535
|
+
const needNoDot = !dot && !allowDot && aps.has(src.charAt(0));
|
|
6536
|
+
start2 = needNoTrav ? startNoTraversal : needNoDot ? startNoDot : "";
|
|
6537
|
+
}
|
|
6538
|
+
}
|
|
6539
|
+
}
|
|
6540
|
+
let end = "";
|
|
6541
|
+
if (this.isEnd() && this.#root.#filledNegs && this.#parent?.type === "!") {
|
|
6542
|
+
end = "(?:$|\\/)";
|
|
6543
|
+
}
|
|
6544
|
+
const final2 = start2 + src + end;
|
|
6545
|
+
return [
|
|
6546
|
+
final2,
|
|
6547
|
+
unescape(src),
|
|
6548
|
+
this.#hasMagic = !!this.#hasMagic,
|
|
6549
|
+
this.#uflag
|
|
6550
|
+
];
|
|
6551
|
+
}
|
|
6552
|
+
const repeated = this.type === "*" || this.type === "+";
|
|
6553
|
+
const start = this.type === "!" ? "(?:(?!(?:" : "(?:";
|
|
6554
|
+
let body = this.#partsToRegExp(dot);
|
|
6555
|
+
if (this.isStart() && this.isEnd() && !body && this.type !== "!") {
|
|
6556
|
+
const s = this.toString();
|
|
6557
|
+
this.#parts = [s];
|
|
6558
|
+
this.type = null;
|
|
6559
|
+
this.#hasMagic = undefined;
|
|
6560
|
+
return [s, unescape(this.toString()), false, false];
|
|
6561
|
+
}
|
|
6562
|
+
let bodyDotAllowed = !repeated || allowDot || dot || !startNoDot ? "" : this.#partsToRegExp(true);
|
|
6563
|
+
if (bodyDotAllowed === body) {
|
|
6564
|
+
bodyDotAllowed = "";
|
|
6565
|
+
}
|
|
6566
|
+
if (bodyDotAllowed) {
|
|
6567
|
+
body = `(?:${body})(?:${bodyDotAllowed})*?`;
|
|
6568
|
+
}
|
|
6569
|
+
let final = "";
|
|
6570
|
+
if (this.type === "!" && this.#emptyExt) {
|
|
6571
|
+
final = (this.isStart() && !dot ? startNoDot : "") + starNoEmpty;
|
|
6572
|
+
} else {
|
|
6573
|
+
const close = this.type === "!" ? "))" + (this.isStart() && !dot && !allowDot ? startNoDot : "") + star + ")" : this.type === "@" ? ")" : this.type === "?" ? ")?" : this.type === "+" && bodyDotAllowed ? ")" : this.type === "*" && bodyDotAllowed ? `)?` : `)${this.type}`;
|
|
6574
|
+
final = start + body + close;
|
|
6575
|
+
}
|
|
6576
|
+
return [
|
|
6577
|
+
final,
|
|
6578
|
+
unescape(body),
|
|
6579
|
+
this.#hasMagic = !!this.#hasMagic,
|
|
6580
|
+
this.#uflag
|
|
6581
|
+
];
|
|
6582
|
+
}
|
|
6583
|
+
#partsToRegExp(dot) {
|
|
6584
|
+
return this.#parts.map((p) => {
|
|
6585
|
+
if (typeof p === "string") {
|
|
6586
|
+
throw new Error("string type in extglob ast??");
|
|
6587
|
+
}
|
|
6588
|
+
const [re, _, _hasMagic, uflag] = p.toRegExpSource(dot);
|
|
6589
|
+
this.#uflag = this.#uflag || uflag;
|
|
6590
|
+
return re;
|
|
6591
|
+
}).filter((p) => !(this.isStart() && this.isEnd()) || !!p).join("|");
|
|
6592
|
+
}
|
|
6593
|
+
static #parseGlob(glob2, hasMagic, noEmpty = false) {
|
|
6594
|
+
let escaping = false;
|
|
6595
|
+
let re = "";
|
|
6596
|
+
let uflag = false;
|
|
6597
|
+
for (let i = 0;i < glob2.length; i++) {
|
|
6598
|
+
const c = glob2.charAt(i);
|
|
6599
|
+
if (escaping) {
|
|
6600
|
+
escaping = false;
|
|
6601
|
+
re += (reSpecials.has(c) ? "\\" : "") + c;
|
|
6602
|
+
continue;
|
|
6603
|
+
}
|
|
6604
|
+
if (c === "\\") {
|
|
6605
|
+
if (i === glob2.length - 1) {
|
|
6606
|
+
re += "\\\\";
|
|
6607
|
+
} else {
|
|
6608
|
+
escaping = true;
|
|
6609
|
+
}
|
|
6610
|
+
continue;
|
|
6611
|
+
}
|
|
6612
|
+
if (c === "[") {
|
|
6613
|
+
const [src, needUflag, consumed, magic] = parseClass(glob2, i);
|
|
6614
|
+
if (consumed) {
|
|
6615
|
+
re += src;
|
|
6616
|
+
uflag = uflag || needUflag;
|
|
6617
|
+
i += consumed - 1;
|
|
6618
|
+
hasMagic = hasMagic || magic;
|
|
6619
|
+
continue;
|
|
6620
|
+
}
|
|
6621
|
+
}
|
|
6622
|
+
if (c === "*") {
|
|
6623
|
+
if (noEmpty && glob2 === "*")
|
|
6624
|
+
re += starNoEmpty;
|
|
6625
|
+
else
|
|
6626
|
+
re += star;
|
|
6627
|
+
hasMagic = true;
|
|
6628
|
+
continue;
|
|
6629
|
+
}
|
|
6630
|
+
if (c === "?") {
|
|
6631
|
+
re += qmark;
|
|
6632
|
+
hasMagic = true;
|
|
6633
|
+
continue;
|
|
6634
|
+
}
|
|
6635
|
+
re += regExpEscape(c);
|
|
6636
|
+
}
|
|
6637
|
+
return [re, unescape(glob2), !!hasMagic, uflag];
|
|
6638
|
+
}
|
|
6639
|
+
}
|
|
6640
|
+
|
|
6641
|
+
// node_modules/minimatch/dist/esm/escape.js
|
|
6642
|
+
var escape = (s, { windowsPathsNoEscape = false } = {}) => {
|
|
6643
|
+
return windowsPathsNoEscape ? s.replace(/[?*()[\]]/g, "[$&]") : s.replace(/[?*()[\]\\]/g, "\\$&");
|
|
6644
|
+
};
|
|
6645
|
+
|
|
6646
|
+
// node_modules/minimatch/dist/esm/index.js
|
|
6647
|
+
var minimatch = (p, pattern, options = {}) => {
|
|
6648
|
+
assertValidPattern(pattern);
|
|
6649
|
+
if (!options.nocomment && pattern.charAt(0) === "#") {
|
|
6650
|
+
return false;
|
|
6651
|
+
}
|
|
6652
|
+
return new Minimatch(pattern, options).match(p);
|
|
6653
|
+
};
|
|
6654
|
+
var starDotExtRE = /^\*+([^+@!?\*\[\(]*)$/;
|
|
6655
|
+
var starDotExtTest = (ext) => (f) => !f.startsWith(".") && f.endsWith(ext);
|
|
6656
|
+
var starDotExtTestDot = (ext) => (f) => f.endsWith(ext);
|
|
6657
|
+
var starDotExtTestNocase = (ext) => {
|
|
6658
|
+
ext = ext.toLowerCase();
|
|
6659
|
+
return (f) => !f.startsWith(".") && f.toLowerCase().endsWith(ext);
|
|
6660
|
+
};
|
|
6661
|
+
var starDotExtTestNocaseDot = (ext) => {
|
|
6662
|
+
ext = ext.toLowerCase();
|
|
6663
|
+
return (f) => f.toLowerCase().endsWith(ext);
|
|
6664
|
+
};
|
|
6665
|
+
var starDotStarRE = /^\*+\.\*+$/;
|
|
6666
|
+
var starDotStarTest = (f) => !f.startsWith(".") && f.includes(".");
|
|
6667
|
+
var starDotStarTestDot = (f) => f !== "." && f !== ".." && f.includes(".");
|
|
6668
|
+
var dotStarRE = /^\.\*+$/;
|
|
6669
|
+
var dotStarTest = (f) => f !== "." && f !== ".." && f.startsWith(".");
|
|
6670
|
+
var starRE = /^\*+$/;
|
|
6671
|
+
var starTest = (f) => f.length !== 0 && !f.startsWith(".");
|
|
6672
|
+
var starTestDot = (f) => f.length !== 0 && f !== "." && f !== "..";
|
|
6673
|
+
var qmarksRE = /^\?+([^+@!?\*\[\(]*)?$/;
|
|
6674
|
+
var qmarksTestNocase = ([$0, ext = ""]) => {
|
|
6675
|
+
const noext = qmarksTestNoExt([$0]);
|
|
6676
|
+
if (!ext)
|
|
6677
|
+
return noext;
|
|
6678
|
+
ext = ext.toLowerCase();
|
|
6679
|
+
return (f) => noext(f) && f.toLowerCase().endsWith(ext);
|
|
6680
|
+
};
|
|
6681
|
+
var qmarksTestNocaseDot = ([$0, ext = ""]) => {
|
|
6682
|
+
const noext = qmarksTestNoExtDot([$0]);
|
|
6683
|
+
if (!ext)
|
|
6684
|
+
return noext;
|
|
6685
|
+
ext = ext.toLowerCase();
|
|
6686
|
+
return (f) => noext(f) && f.toLowerCase().endsWith(ext);
|
|
6687
|
+
};
|
|
6688
|
+
var qmarksTestDot = ([$0, ext = ""]) => {
|
|
6689
|
+
const noext = qmarksTestNoExtDot([$0]);
|
|
6690
|
+
return !ext ? noext : (f) => noext(f) && f.endsWith(ext);
|
|
6691
|
+
};
|
|
6692
|
+
var qmarksTest = ([$0, ext = ""]) => {
|
|
6693
|
+
const noext = qmarksTestNoExt([$0]);
|
|
6694
|
+
return !ext ? noext : (f) => noext(f) && f.endsWith(ext);
|
|
6695
|
+
};
|
|
6696
|
+
var qmarksTestNoExt = ([$0]) => {
|
|
6697
|
+
const len = $0.length;
|
|
6698
|
+
return (f) => f.length === len && !f.startsWith(".");
|
|
6699
|
+
};
|
|
6700
|
+
var qmarksTestNoExtDot = ([$0]) => {
|
|
6701
|
+
const len = $0.length;
|
|
6702
|
+
return (f) => f.length === len && f !== "." && f !== "..";
|
|
6703
|
+
};
|
|
6704
|
+
var defaultPlatform = typeof process === "object" && process ? typeof process.env === "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix";
|
|
6705
|
+
var path16 = {
|
|
6706
|
+
win32: { sep: "\\" },
|
|
6707
|
+
posix: { sep: "/" }
|
|
6708
|
+
};
|
|
6709
|
+
var sep = defaultPlatform === "win32" ? path16.win32.sep : path16.posix.sep;
|
|
6710
|
+
minimatch.sep = sep;
|
|
6711
|
+
var GLOBSTAR = Symbol("globstar **");
|
|
6712
|
+
minimatch.GLOBSTAR = GLOBSTAR;
|
|
6713
|
+
var qmark2 = "[^/]";
|
|
6714
|
+
var star2 = qmark2 + "*?";
|
|
6715
|
+
var twoStarDot = "(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?";
|
|
6716
|
+
var twoStarNoDot = "(?:(?!(?:\\/|^)\\.).)*?";
|
|
6717
|
+
var filter = (pattern, options = {}) => (p) => minimatch(p, pattern, options);
|
|
6718
|
+
minimatch.filter = filter;
|
|
6719
|
+
var ext = (a, b = {}) => Object.assign({}, a, b);
|
|
6720
|
+
var defaults = (def) => {
|
|
6721
|
+
if (!def || typeof def !== "object" || !Object.keys(def).length) {
|
|
6722
|
+
return minimatch;
|
|
6723
|
+
}
|
|
6724
|
+
const orig = minimatch;
|
|
6725
|
+
const m = (p, pattern, options = {}) => orig(p, pattern, ext(def, options));
|
|
6726
|
+
return Object.assign(m, {
|
|
6727
|
+
Minimatch: class Minimatch extends orig.Minimatch {
|
|
6728
|
+
constructor(pattern, options = {}) {
|
|
6729
|
+
super(pattern, ext(def, options));
|
|
6730
|
+
}
|
|
6731
|
+
static defaults(options) {
|
|
6732
|
+
return orig.defaults(ext(def, options)).Minimatch;
|
|
6733
|
+
}
|
|
6734
|
+
},
|
|
6735
|
+
AST: class AST2 extends orig.AST {
|
|
6736
|
+
constructor(type, parent, options = {}) {
|
|
6737
|
+
super(type, parent, ext(def, options));
|
|
6738
|
+
}
|
|
6739
|
+
static fromGlob(pattern, options = {}) {
|
|
6740
|
+
return orig.AST.fromGlob(pattern, ext(def, options));
|
|
6741
|
+
}
|
|
6742
|
+
},
|
|
6743
|
+
unescape: (s, options = {}) => orig.unescape(s, ext(def, options)),
|
|
6744
|
+
escape: (s, options = {}) => orig.escape(s, ext(def, options)),
|
|
6745
|
+
filter: (pattern, options = {}) => orig.filter(pattern, ext(def, options)),
|
|
6746
|
+
defaults: (options) => orig.defaults(ext(def, options)),
|
|
6747
|
+
makeRe: (pattern, options = {}) => orig.makeRe(pattern, ext(def, options)),
|
|
6748
|
+
braceExpand: (pattern, options = {}) => orig.braceExpand(pattern, ext(def, options)),
|
|
6749
|
+
match: (list, pattern, options = {}) => orig.match(list, pattern, ext(def, options)),
|
|
6750
|
+
sep: orig.sep,
|
|
6751
|
+
GLOBSTAR
|
|
6752
|
+
});
|
|
6753
|
+
};
|
|
6754
|
+
minimatch.defaults = defaults;
|
|
6755
|
+
var braceExpand = (pattern, options = {}) => {
|
|
6756
|
+
assertValidPattern(pattern);
|
|
6757
|
+
if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) {
|
|
6758
|
+
return [pattern];
|
|
6759
|
+
}
|
|
6760
|
+
return import_brace_expansion.default(pattern);
|
|
6761
|
+
};
|
|
6762
|
+
minimatch.braceExpand = braceExpand;
|
|
6763
|
+
var makeRe = (pattern, options = {}) => new Minimatch(pattern, options).makeRe();
|
|
6764
|
+
minimatch.makeRe = makeRe;
|
|
6765
|
+
var match = (list, pattern, options = {}) => {
|
|
6766
|
+
const mm = new Minimatch(pattern, options);
|
|
6767
|
+
list = list.filter((f) => mm.match(f));
|
|
6768
|
+
if (mm.options.nonull && !list.length) {
|
|
6769
|
+
list.push(pattern);
|
|
6770
|
+
}
|
|
6771
|
+
return list;
|
|
6772
|
+
};
|
|
6773
|
+
minimatch.match = match;
|
|
6774
|
+
var globMagic = /[?*]|[+@!]\(.*?\)|\[|\]/;
|
|
6775
|
+
var regExpEscape2 = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
6776
|
+
|
|
6777
|
+
class Minimatch {
|
|
6778
|
+
options;
|
|
6779
|
+
set;
|
|
6780
|
+
pattern;
|
|
6781
|
+
windowsPathsNoEscape;
|
|
6782
|
+
nonegate;
|
|
6783
|
+
negate;
|
|
6784
|
+
comment;
|
|
6785
|
+
empty;
|
|
6786
|
+
preserveMultipleSlashes;
|
|
6787
|
+
partial;
|
|
6788
|
+
globSet;
|
|
6789
|
+
globParts;
|
|
6790
|
+
nocase;
|
|
6791
|
+
isWindows;
|
|
6792
|
+
platform;
|
|
6793
|
+
windowsNoMagicRoot;
|
|
6794
|
+
regexp;
|
|
6795
|
+
constructor(pattern, options = {}) {
|
|
6796
|
+
assertValidPattern(pattern);
|
|
6797
|
+
options = options || {};
|
|
6798
|
+
this.options = options;
|
|
6799
|
+
this.pattern = pattern;
|
|
6800
|
+
this.platform = options.platform || defaultPlatform;
|
|
6801
|
+
this.isWindows = this.platform === "win32";
|
|
6802
|
+
this.windowsPathsNoEscape = !!options.windowsPathsNoEscape || options.allowWindowsEscape === false;
|
|
6803
|
+
if (this.windowsPathsNoEscape) {
|
|
6804
|
+
this.pattern = this.pattern.replace(/\\/g, "/");
|
|
6805
|
+
}
|
|
6806
|
+
this.preserveMultipleSlashes = !!options.preserveMultipleSlashes;
|
|
6807
|
+
this.regexp = null;
|
|
6808
|
+
this.negate = false;
|
|
6809
|
+
this.nonegate = !!options.nonegate;
|
|
6810
|
+
this.comment = false;
|
|
6811
|
+
this.empty = false;
|
|
6812
|
+
this.partial = !!options.partial;
|
|
6813
|
+
this.nocase = !!this.options.nocase;
|
|
6814
|
+
this.windowsNoMagicRoot = options.windowsNoMagicRoot !== undefined ? options.windowsNoMagicRoot : !!(this.isWindows && this.nocase);
|
|
6815
|
+
this.globSet = [];
|
|
6816
|
+
this.globParts = [];
|
|
6817
|
+
this.set = [];
|
|
6818
|
+
this.make();
|
|
6819
|
+
}
|
|
6820
|
+
hasMagic() {
|
|
6821
|
+
if (this.options.magicalBraces && this.set.length > 1) {
|
|
6822
|
+
return true;
|
|
6823
|
+
}
|
|
6824
|
+
for (const pattern of this.set) {
|
|
6825
|
+
for (const part of pattern) {
|
|
6826
|
+
if (typeof part !== "string")
|
|
6827
|
+
return true;
|
|
6828
|
+
}
|
|
6829
|
+
}
|
|
6830
|
+
return false;
|
|
6831
|
+
}
|
|
6832
|
+
debug(..._) {}
|
|
6833
|
+
make() {
|
|
6834
|
+
const pattern = this.pattern;
|
|
6835
|
+
const options = this.options;
|
|
6836
|
+
if (!options.nocomment && pattern.charAt(0) === "#") {
|
|
6837
|
+
this.comment = true;
|
|
6838
|
+
return;
|
|
6839
|
+
}
|
|
6840
|
+
if (!pattern) {
|
|
6841
|
+
this.empty = true;
|
|
6842
|
+
return;
|
|
6843
|
+
}
|
|
6844
|
+
this.parseNegate();
|
|
6845
|
+
this.globSet = [...new Set(this.braceExpand())];
|
|
6846
|
+
if (options.debug) {
|
|
6847
|
+
this.debug = (...args) => console.error(...args);
|
|
6848
|
+
}
|
|
6849
|
+
this.debug(this.pattern, this.globSet);
|
|
6850
|
+
const rawGlobParts = this.globSet.map((s) => this.slashSplit(s));
|
|
6851
|
+
this.globParts = this.preprocess(rawGlobParts);
|
|
6852
|
+
this.debug(this.pattern, this.globParts);
|
|
6853
|
+
let set = this.globParts.map((s, _, __) => {
|
|
6854
|
+
if (this.isWindows && this.windowsNoMagicRoot) {
|
|
6855
|
+
const isUNC = s[0] === "" && s[1] === "" && (s[2] === "?" || !globMagic.test(s[2])) && !globMagic.test(s[3]);
|
|
6856
|
+
const isDrive = /^[a-z]:/i.test(s[0]);
|
|
6857
|
+
if (isUNC) {
|
|
6858
|
+
return [...s.slice(0, 4), ...s.slice(4).map((ss) => this.parse(ss))];
|
|
6859
|
+
} else if (isDrive) {
|
|
6860
|
+
return [s[0], ...s.slice(1).map((ss) => this.parse(ss))];
|
|
6861
|
+
}
|
|
6862
|
+
}
|
|
6863
|
+
return s.map((ss) => this.parse(ss));
|
|
6864
|
+
});
|
|
6865
|
+
this.debug(this.pattern, set);
|
|
6866
|
+
this.set = set.filter((s) => s.indexOf(false) === -1);
|
|
6867
|
+
if (this.isWindows) {
|
|
6868
|
+
for (let i = 0;i < this.set.length; i++) {
|
|
6869
|
+
const p = this.set[i];
|
|
6870
|
+
if (p[0] === "" && p[1] === "" && this.globParts[i][2] === "?" && typeof p[3] === "string" && /^[a-z]:$/i.test(p[3])) {
|
|
6871
|
+
p[2] = "?";
|
|
6872
|
+
}
|
|
6873
|
+
}
|
|
6874
|
+
}
|
|
6875
|
+
this.debug(this.pattern, this.set);
|
|
6876
|
+
}
|
|
6877
|
+
preprocess(globParts) {
|
|
6878
|
+
if (this.options.noglobstar) {
|
|
6879
|
+
for (let i = 0;i < globParts.length; i++) {
|
|
6880
|
+
for (let j = 0;j < globParts[i].length; j++) {
|
|
6881
|
+
if (globParts[i][j] === "**") {
|
|
6882
|
+
globParts[i][j] = "*";
|
|
6883
|
+
}
|
|
6884
|
+
}
|
|
6885
|
+
}
|
|
6886
|
+
}
|
|
6887
|
+
const { optimizationLevel = 1 } = this.options;
|
|
6888
|
+
if (optimizationLevel >= 2) {
|
|
6889
|
+
globParts = this.firstPhasePreProcess(globParts);
|
|
6890
|
+
globParts = this.secondPhasePreProcess(globParts);
|
|
6891
|
+
} else if (optimizationLevel >= 1) {
|
|
6892
|
+
globParts = this.levelOneOptimize(globParts);
|
|
6893
|
+
} else {
|
|
6894
|
+
globParts = this.adjascentGlobstarOptimize(globParts);
|
|
6895
|
+
}
|
|
6896
|
+
return globParts;
|
|
6897
|
+
}
|
|
6898
|
+
adjascentGlobstarOptimize(globParts) {
|
|
6899
|
+
return globParts.map((parts) => {
|
|
6900
|
+
let gs = -1;
|
|
6901
|
+
while ((gs = parts.indexOf("**", gs + 1)) !== -1) {
|
|
6902
|
+
let i = gs;
|
|
6903
|
+
while (parts[i + 1] === "**") {
|
|
6904
|
+
i++;
|
|
6905
|
+
}
|
|
6906
|
+
if (i !== gs) {
|
|
6907
|
+
parts.splice(gs, i - gs);
|
|
6908
|
+
}
|
|
6909
|
+
}
|
|
6910
|
+
return parts;
|
|
6911
|
+
});
|
|
6912
|
+
}
|
|
6913
|
+
levelOneOptimize(globParts) {
|
|
6914
|
+
return globParts.map((parts) => {
|
|
6915
|
+
parts = parts.reduce((set, part) => {
|
|
6916
|
+
const prev = set[set.length - 1];
|
|
6917
|
+
if (part === "**" && prev === "**") {
|
|
6918
|
+
return set;
|
|
6919
|
+
}
|
|
6920
|
+
if (part === "..") {
|
|
6921
|
+
if (prev && prev !== ".." && prev !== "." && prev !== "**") {
|
|
6922
|
+
set.pop();
|
|
6923
|
+
return set;
|
|
6924
|
+
}
|
|
6925
|
+
}
|
|
6926
|
+
set.push(part);
|
|
6927
|
+
return set;
|
|
6928
|
+
}, []);
|
|
6929
|
+
return parts.length === 0 ? [""] : parts;
|
|
6930
|
+
});
|
|
6931
|
+
}
|
|
6932
|
+
levelTwoFileOptimize(parts) {
|
|
6933
|
+
if (!Array.isArray(parts)) {
|
|
6934
|
+
parts = this.slashSplit(parts);
|
|
6935
|
+
}
|
|
6936
|
+
let didSomething = false;
|
|
6937
|
+
do {
|
|
6938
|
+
didSomething = false;
|
|
6939
|
+
if (!this.preserveMultipleSlashes) {
|
|
6940
|
+
for (let i = 1;i < parts.length - 1; i++) {
|
|
6941
|
+
const p = parts[i];
|
|
6942
|
+
if (i === 1 && p === "" && parts[0] === "")
|
|
6943
|
+
continue;
|
|
6944
|
+
if (p === "." || p === "") {
|
|
6945
|
+
didSomething = true;
|
|
6946
|
+
parts.splice(i, 1);
|
|
6947
|
+
i--;
|
|
6948
|
+
}
|
|
6949
|
+
}
|
|
6950
|
+
if (parts[0] === "." && parts.length === 2 && (parts[1] === "." || parts[1] === "")) {
|
|
6951
|
+
didSomething = true;
|
|
6952
|
+
parts.pop();
|
|
6953
|
+
}
|
|
6954
|
+
}
|
|
6955
|
+
let dd = 0;
|
|
6956
|
+
while ((dd = parts.indexOf("..", dd + 1)) !== -1) {
|
|
6957
|
+
const p = parts[dd - 1];
|
|
6958
|
+
if (p && p !== "." && p !== ".." && p !== "**") {
|
|
6959
|
+
didSomething = true;
|
|
6960
|
+
parts.splice(dd - 1, 2);
|
|
6961
|
+
dd -= 2;
|
|
6962
|
+
}
|
|
6963
|
+
}
|
|
6964
|
+
} while (didSomething);
|
|
6965
|
+
return parts.length === 0 ? [""] : parts;
|
|
6966
|
+
}
|
|
6967
|
+
firstPhasePreProcess(globParts) {
|
|
6968
|
+
let didSomething = false;
|
|
6969
|
+
do {
|
|
6970
|
+
didSomething = false;
|
|
6971
|
+
for (let parts of globParts) {
|
|
6972
|
+
let gs = -1;
|
|
6973
|
+
while ((gs = parts.indexOf("**", gs + 1)) !== -1) {
|
|
6974
|
+
let gss = gs;
|
|
6975
|
+
while (parts[gss + 1] === "**") {
|
|
6976
|
+
gss++;
|
|
6977
|
+
}
|
|
6978
|
+
if (gss > gs) {
|
|
6979
|
+
parts.splice(gs + 1, gss - gs);
|
|
6980
|
+
}
|
|
6981
|
+
let next = parts[gs + 1];
|
|
6982
|
+
const p = parts[gs + 2];
|
|
6983
|
+
const p2 = parts[gs + 3];
|
|
6984
|
+
if (next !== "..")
|
|
6985
|
+
continue;
|
|
6986
|
+
if (!p || p === "." || p === ".." || !p2 || p2 === "." || p2 === "..") {
|
|
6987
|
+
continue;
|
|
6988
|
+
}
|
|
6989
|
+
didSomething = true;
|
|
6990
|
+
parts.splice(gs, 1);
|
|
6991
|
+
const other = parts.slice(0);
|
|
6992
|
+
other[gs] = "**";
|
|
6993
|
+
globParts.push(other);
|
|
6994
|
+
gs--;
|
|
6995
|
+
}
|
|
6996
|
+
if (!this.preserveMultipleSlashes) {
|
|
6997
|
+
for (let i = 1;i < parts.length - 1; i++) {
|
|
6998
|
+
const p = parts[i];
|
|
6999
|
+
if (i === 1 && p === "" && parts[0] === "")
|
|
7000
|
+
continue;
|
|
7001
|
+
if (p === "." || p === "") {
|
|
7002
|
+
didSomething = true;
|
|
7003
|
+
parts.splice(i, 1);
|
|
7004
|
+
i--;
|
|
7005
|
+
}
|
|
7006
|
+
}
|
|
7007
|
+
if (parts[0] === "." && parts.length === 2 && (parts[1] === "." || parts[1] === "")) {
|
|
7008
|
+
didSomething = true;
|
|
7009
|
+
parts.pop();
|
|
7010
|
+
}
|
|
7011
|
+
}
|
|
7012
|
+
let dd = 0;
|
|
7013
|
+
while ((dd = parts.indexOf("..", dd + 1)) !== -1) {
|
|
7014
|
+
const p = parts[dd - 1];
|
|
7015
|
+
if (p && p !== "." && p !== ".." && p !== "**") {
|
|
7016
|
+
didSomething = true;
|
|
7017
|
+
const needDot = dd === 1 && parts[dd + 1] === "**";
|
|
7018
|
+
const splin = needDot ? ["."] : [];
|
|
7019
|
+
parts.splice(dd - 1, 2, ...splin);
|
|
7020
|
+
if (parts.length === 0)
|
|
7021
|
+
parts.push("");
|
|
7022
|
+
dd -= 2;
|
|
7023
|
+
}
|
|
7024
|
+
}
|
|
7025
|
+
}
|
|
7026
|
+
} while (didSomething);
|
|
7027
|
+
return globParts;
|
|
7028
|
+
}
|
|
7029
|
+
secondPhasePreProcess(globParts) {
|
|
7030
|
+
for (let i = 0;i < globParts.length - 1; i++) {
|
|
7031
|
+
for (let j = i + 1;j < globParts.length; j++) {
|
|
7032
|
+
const matched = this.partsMatch(globParts[i], globParts[j], !this.preserveMultipleSlashes);
|
|
7033
|
+
if (matched) {
|
|
7034
|
+
globParts[i] = [];
|
|
7035
|
+
globParts[j] = matched;
|
|
7036
|
+
break;
|
|
7037
|
+
}
|
|
7038
|
+
}
|
|
7039
|
+
}
|
|
7040
|
+
return globParts.filter((gs) => gs.length);
|
|
7041
|
+
}
|
|
7042
|
+
partsMatch(a, b, emptyGSMatch = false) {
|
|
7043
|
+
let ai = 0;
|
|
7044
|
+
let bi = 0;
|
|
7045
|
+
let result = [];
|
|
7046
|
+
let which = "";
|
|
7047
|
+
while (ai < a.length && bi < b.length) {
|
|
7048
|
+
if (a[ai] === b[bi]) {
|
|
7049
|
+
result.push(which === "b" ? b[bi] : a[ai]);
|
|
7050
|
+
ai++;
|
|
7051
|
+
bi++;
|
|
7052
|
+
} else if (emptyGSMatch && a[ai] === "**" && b[bi] === a[ai + 1]) {
|
|
7053
|
+
result.push(a[ai]);
|
|
7054
|
+
ai++;
|
|
7055
|
+
} else if (emptyGSMatch && b[bi] === "**" && a[ai] === b[bi + 1]) {
|
|
7056
|
+
result.push(b[bi]);
|
|
7057
|
+
bi++;
|
|
7058
|
+
} else if (a[ai] === "*" && b[bi] && (this.options.dot || !b[bi].startsWith(".")) && b[bi] !== "**") {
|
|
7059
|
+
if (which === "b")
|
|
7060
|
+
return false;
|
|
7061
|
+
which = "a";
|
|
7062
|
+
result.push(a[ai]);
|
|
7063
|
+
ai++;
|
|
7064
|
+
bi++;
|
|
7065
|
+
} else if (b[bi] === "*" && a[ai] && (this.options.dot || !a[ai].startsWith(".")) && a[ai] !== "**") {
|
|
7066
|
+
if (which === "a")
|
|
7067
|
+
return false;
|
|
7068
|
+
which = "b";
|
|
7069
|
+
result.push(b[bi]);
|
|
7070
|
+
ai++;
|
|
7071
|
+
bi++;
|
|
7072
|
+
} else {
|
|
7073
|
+
return false;
|
|
7074
|
+
}
|
|
7075
|
+
}
|
|
7076
|
+
return a.length === b.length && result;
|
|
7077
|
+
}
|
|
7078
|
+
parseNegate() {
|
|
7079
|
+
if (this.nonegate)
|
|
7080
|
+
return;
|
|
7081
|
+
const pattern = this.pattern;
|
|
7082
|
+
let negate = false;
|
|
7083
|
+
let negateOffset = 0;
|
|
7084
|
+
for (let i = 0;i < pattern.length && pattern.charAt(i) === "!"; i++) {
|
|
7085
|
+
negate = !negate;
|
|
7086
|
+
negateOffset++;
|
|
7087
|
+
}
|
|
7088
|
+
if (negateOffset)
|
|
7089
|
+
this.pattern = pattern.slice(negateOffset);
|
|
7090
|
+
this.negate = negate;
|
|
7091
|
+
}
|
|
7092
|
+
matchOne(file, pattern, partial = false) {
|
|
7093
|
+
const options = this.options;
|
|
7094
|
+
if (this.isWindows) {
|
|
7095
|
+
const fileDrive = typeof file[0] === "string" && /^[a-z]:$/i.test(file[0]);
|
|
7096
|
+
const fileUNC = !fileDrive && file[0] === "" && file[1] === "" && file[2] === "?" && /^[a-z]:$/i.test(file[3]);
|
|
7097
|
+
const patternDrive = typeof pattern[0] === "string" && /^[a-z]:$/i.test(pattern[0]);
|
|
7098
|
+
const patternUNC = !patternDrive && pattern[0] === "" && pattern[1] === "" && pattern[2] === "?" && typeof pattern[3] === "string" && /^[a-z]:$/i.test(pattern[3]);
|
|
7099
|
+
const fdi = fileUNC ? 3 : fileDrive ? 0 : undefined;
|
|
7100
|
+
const pdi = patternUNC ? 3 : patternDrive ? 0 : undefined;
|
|
7101
|
+
if (typeof fdi === "number" && typeof pdi === "number") {
|
|
7102
|
+
const [fd, pd] = [file[fdi], pattern[pdi]];
|
|
7103
|
+
if (fd.toLowerCase() === pd.toLowerCase()) {
|
|
7104
|
+
pattern[pdi] = fd;
|
|
7105
|
+
if (pdi > fdi) {
|
|
7106
|
+
pattern = pattern.slice(pdi);
|
|
7107
|
+
} else if (fdi > pdi) {
|
|
7108
|
+
file = file.slice(fdi);
|
|
7109
|
+
}
|
|
7110
|
+
}
|
|
7111
|
+
}
|
|
7112
|
+
}
|
|
7113
|
+
const { optimizationLevel = 1 } = this.options;
|
|
7114
|
+
if (optimizationLevel >= 2) {
|
|
7115
|
+
file = this.levelTwoFileOptimize(file);
|
|
7116
|
+
}
|
|
7117
|
+
this.debug("matchOne", this, { file, pattern });
|
|
7118
|
+
this.debug("matchOne", file.length, pattern.length);
|
|
7119
|
+
for (var fi = 0, pi = 0, fl = file.length, pl = pattern.length;fi < fl && pi < pl; fi++, pi++) {
|
|
7120
|
+
this.debug("matchOne loop");
|
|
7121
|
+
var p = pattern[pi];
|
|
7122
|
+
var f = file[fi];
|
|
7123
|
+
this.debug(pattern, p, f);
|
|
7124
|
+
if (p === false) {
|
|
7125
|
+
return false;
|
|
7126
|
+
}
|
|
7127
|
+
if (p === GLOBSTAR) {
|
|
7128
|
+
this.debug("GLOBSTAR", [pattern, p, f]);
|
|
7129
|
+
var fr = fi;
|
|
7130
|
+
var pr = pi + 1;
|
|
7131
|
+
if (pr === pl) {
|
|
7132
|
+
this.debug("** at the end");
|
|
7133
|
+
for (;fi < fl; fi++) {
|
|
7134
|
+
if (file[fi] === "." || file[fi] === ".." || !options.dot && file[fi].charAt(0) === ".")
|
|
7135
|
+
return false;
|
|
7136
|
+
}
|
|
7137
|
+
return true;
|
|
7138
|
+
}
|
|
7139
|
+
while (fr < fl) {
|
|
7140
|
+
var swallowee = file[fr];
|
|
7141
|
+
this.debug(`
|
|
7142
|
+
globstar while`, file, fr, pattern, pr, swallowee);
|
|
7143
|
+
if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
|
|
7144
|
+
this.debug("globstar found match!", fr, fl, swallowee);
|
|
7145
|
+
return true;
|
|
7146
|
+
} else {
|
|
7147
|
+
if (swallowee === "." || swallowee === ".." || !options.dot && swallowee.charAt(0) === ".") {
|
|
7148
|
+
this.debug("dot detected!", file, fr, pattern, pr);
|
|
7149
|
+
break;
|
|
7150
|
+
}
|
|
7151
|
+
this.debug("globstar swallow a segment, and continue");
|
|
7152
|
+
fr++;
|
|
7153
|
+
}
|
|
7154
|
+
}
|
|
7155
|
+
if (partial) {
|
|
7156
|
+
this.debug(`
|
|
7157
|
+
>>> no match, partial?`, file, fr, pattern, pr);
|
|
7158
|
+
if (fr === fl) {
|
|
7159
|
+
return true;
|
|
7160
|
+
}
|
|
7161
|
+
}
|
|
7162
|
+
return false;
|
|
7163
|
+
}
|
|
7164
|
+
let hit;
|
|
7165
|
+
if (typeof p === "string") {
|
|
7166
|
+
hit = f === p;
|
|
7167
|
+
this.debug("string match", p, f, hit);
|
|
7168
|
+
} else {
|
|
7169
|
+
hit = p.test(f);
|
|
7170
|
+
this.debug("pattern match", p, f, hit);
|
|
7171
|
+
}
|
|
7172
|
+
if (!hit)
|
|
7173
|
+
return false;
|
|
7174
|
+
}
|
|
7175
|
+
if (fi === fl && pi === pl) {
|
|
7176
|
+
return true;
|
|
7177
|
+
} else if (fi === fl) {
|
|
7178
|
+
return partial;
|
|
7179
|
+
} else if (pi === pl) {
|
|
7180
|
+
return fi === fl - 1 && file[fi] === "";
|
|
7181
|
+
} else {
|
|
7182
|
+
throw new Error("wtf?");
|
|
7183
|
+
}
|
|
7184
|
+
}
|
|
7185
|
+
braceExpand() {
|
|
7186
|
+
return braceExpand(this.pattern, this.options);
|
|
7187
|
+
}
|
|
7188
|
+
parse(pattern) {
|
|
7189
|
+
assertValidPattern(pattern);
|
|
7190
|
+
const options = this.options;
|
|
7191
|
+
if (pattern === "**")
|
|
7192
|
+
return GLOBSTAR;
|
|
7193
|
+
if (pattern === "")
|
|
7194
|
+
return "";
|
|
7195
|
+
let m;
|
|
7196
|
+
let fastTest = null;
|
|
7197
|
+
if (m = pattern.match(starRE)) {
|
|
7198
|
+
fastTest = options.dot ? starTestDot : starTest;
|
|
7199
|
+
} else if (m = pattern.match(starDotExtRE)) {
|
|
7200
|
+
fastTest = (options.nocase ? options.dot ? starDotExtTestNocaseDot : starDotExtTestNocase : options.dot ? starDotExtTestDot : starDotExtTest)(m[1]);
|
|
7201
|
+
} else if (m = pattern.match(qmarksRE)) {
|
|
7202
|
+
fastTest = (options.nocase ? options.dot ? qmarksTestNocaseDot : qmarksTestNocase : options.dot ? qmarksTestDot : qmarksTest)(m);
|
|
7203
|
+
} else if (m = pattern.match(starDotStarRE)) {
|
|
7204
|
+
fastTest = options.dot ? starDotStarTestDot : starDotStarTest;
|
|
7205
|
+
} else if (m = pattern.match(dotStarRE)) {
|
|
7206
|
+
fastTest = dotStarTest;
|
|
7207
|
+
}
|
|
7208
|
+
const re = AST.fromGlob(pattern, this.options).toMMPattern();
|
|
7209
|
+
if (fastTest && typeof re === "object") {
|
|
7210
|
+
Reflect.defineProperty(re, "test", { value: fastTest });
|
|
7211
|
+
}
|
|
7212
|
+
return re;
|
|
7213
|
+
}
|
|
7214
|
+
makeRe() {
|
|
7215
|
+
if (this.regexp || this.regexp === false)
|
|
7216
|
+
return this.regexp;
|
|
7217
|
+
const set = this.set;
|
|
7218
|
+
if (!set.length) {
|
|
7219
|
+
this.regexp = false;
|
|
7220
|
+
return this.regexp;
|
|
7221
|
+
}
|
|
7222
|
+
const options = this.options;
|
|
7223
|
+
const twoStar = options.noglobstar ? star2 : options.dot ? twoStarDot : twoStarNoDot;
|
|
7224
|
+
const flags = new Set(options.nocase ? ["i"] : []);
|
|
7225
|
+
let re = set.map((pattern) => {
|
|
7226
|
+
const pp = pattern.map((p) => {
|
|
7227
|
+
if (p instanceof RegExp) {
|
|
7228
|
+
for (const f of p.flags.split(""))
|
|
7229
|
+
flags.add(f);
|
|
7230
|
+
}
|
|
7231
|
+
return typeof p === "string" ? regExpEscape2(p) : p === GLOBSTAR ? GLOBSTAR : p._src;
|
|
7232
|
+
});
|
|
7233
|
+
pp.forEach((p, i) => {
|
|
7234
|
+
const next = pp[i + 1];
|
|
7235
|
+
const prev = pp[i - 1];
|
|
7236
|
+
if (p !== GLOBSTAR || prev === GLOBSTAR) {
|
|
7237
|
+
return;
|
|
7238
|
+
}
|
|
7239
|
+
if (prev === undefined) {
|
|
7240
|
+
if (next !== undefined && next !== GLOBSTAR) {
|
|
7241
|
+
pp[i + 1] = "(?:\\/|" + twoStar + "\\/)?" + next;
|
|
7242
|
+
} else {
|
|
7243
|
+
pp[i] = twoStar;
|
|
7244
|
+
}
|
|
7245
|
+
} else if (next === undefined) {
|
|
7246
|
+
pp[i - 1] = prev + "(?:\\/|" + twoStar + ")?";
|
|
7247
|
+
} else if (next !== GLOBSTAR) {
|
|
7248
|
+
pp[i - 1] = prev + "(?:\\/|\\/" + twoStar + "\\/)" + next;
|
|
7249
|
+
pp[i + 1] = GLOBSTAR;
|
|
7250
|
+
}
|
|
7251
|
+
});
|
|
7252
|
+
return pp.filter((p) => p !== GLOBSTAR).join("/");
|
|
7253
|
+
}).join("|");
|
|
7254
|
+
const [open, close] = set.length > 1 ? ["(?:", ")"] : ["", ""];
|
|
7255
|
+
re = "^" + open + re + close + "$";
|
|
7256
|
+
if (this.negate)
|
|
7257
|
+
re = "^(?!" + re + ").+$";
|
|
7258
|
+
try {
|
|
7259
|
+
this.regexp = new RegExp(re, [...flags].join(""));
|
|
7260
|
+
} catch (ex) {
|
|
7261
|
+
this.regexp = false;
|
|
7262
|
+
}
|
|
7263
|
+
return this.regexp;
|
|
7264
|
+
}
|
|
7265
|
+
slashSplit(p) {
|
|
7266
|
+
if (this.preserveMultipleSlashes) {
|
|
7267
|
+
return p.split("/");
|
|
7268
|
+
} else if (this.isWindows && /^\/\/[^\/]+/.test(p)) {
|
|
7269
|
+
return ["", ...p.split(/\/+/)];
|
|
7270
|
+
} else {
|
|
7271
|
+
return p.split(/\/+/);
|
|
7272
|
+
}
|
|
7273
|
+
}
|
|
7274
|
+
match(f, partial = this.partial) {
|
|
7275
|
+
this.debug("match", f, this.pattern);
|
|
7276
|
+
if (this.comment) {
|
|
7277
|
+
return false;
|
|
7278
|
+
}
|
|
7279
|
+
if (this.empty) {
|
|
7280
|
+
return f === "";
|
|
7281
|
+
}
|
|
7282
|
+
if (f === "/" && partial) {
|
|
7283
|
+
return true;
|
|
7284
|
+
}
|
|
7285
|
+
const options = this.options;
|
|
7286
|
+
if (this.isWindows) {
|
|
7287
|
+
f = f.split("\\").join("/");
|
|
7288
|
+
}
|
|
7289
|
+
const ff = this.slashSplit(f);
|
|
7290
|
+
this.debug(this.pattern, "split", ff);
|
|
7291
|
+
const set = this.set;
|
|
7292
|
+
this.debug(this.pattern, "set", set);
|
|
7293
|
+
let filename = ff[ff.length - 1];
|
|
7294
|
+
if (!filename) {
|
|
7295
|
+
for (let i = ff.length - 2;!filename && i >= 0; i--) {
|
|
7296
|
+
filename = ff[i];
|
|
7297
|
+
}
|
|
7298
|
+
}
|
|
7299
|
+
for (let i = 0;i < set.length; i++) {
|
|
7300
|
+
const pattern = set[i];
|
|
7301
|
+
let file = ff;
|
|
7302
|
+
if (options.matchBase && pattern.length === 1) {
|
|
7303
|
+
file = [filename];
|
|
7304
|
+
}
|
|
7305
|
+
const hit = this.matchOne(file, pattern, partial);
|
|
7306
|
+
if (hit) {
|
|
7307
|
+
if (options.flipNegate) {
|
|
7308
|
+
return true;
|
|
7309
|
+
}
|
|
7310
|
+
return !this.negate;
|
|
7311
|
+
}
|
|
7312
|
+
}
|
|
7313
|
+
if (options.flipNegate) {
|
|
7314
|
+
return false;
|
|
7315
|
+
}
|
|
7316
|
+
return this.negate;
|
|
7317
|
+
}
|
|
7318
|
+
static defaults(def) {
|
|
7319
|
+
return minimatch.defaults(def).Minimatch;
|
|
7320
|
+
}
|
|
7321
|
+
}
|
|
7322
|
+
minimatch.AST = AST;
|
|
7323
|
+
minimatch.Minimatch = Minimatch;
|
|
7324
|
+
minimatch.escape = escape;
|
|
7325
|
+
minimatch.unescape = unescape;
|
|
5877
7326
|
|
|
5878
7327
|
// src/types.ts
|
|
5879
7328
|
init_entities();
|
|
@@ -5881,7 +7330,7 @@ init_entities();
|
|
|
5881
7330
|
// src/app/search/index.ts
|
|
5882
7331
|
init_config2();
|
|
5883
7332
|
async function search(rootDir, query, options = {}) {
|
|
5884
|
-
rootDir =
|
|
7333
|
+
rootDir = path17.resolve(rootDir);
|
|
5885
7334
|
const ensureFresh = options.ensureFresh ?? DEFAULT_SEARCH_OPTIONS.ensureFresh;
|
|
5886
7335
|
if (ensureFresh) {
|
|
5887
7336
|
await ensureIndexFresh(rootDir, { quiet: true });
|
|
@@ -5920,7 +7369,15 @@ async function search(rootDir, query, options = {}) {
|
|
|
5920
7369
|
const normalizedFilters = options.pathFilter.map((p) => p.replace(/\\/g, "/").replace(/^\//, "").replace(/\/$/, ""));
|
|
5921
7370
|
filteredResults = allResults.filter((result) => {
|
|
5922
7371
|
const normalizedPath = result.filepath.replace(/\\/g, "/");
|
|
5923
|
-
return normalizedFilters.some((
|
|
7372
|
+
return normalizedFilters.some((filter2) => {
|
|
7373
|
+
const isGlobPattern = /[*?[\]{}!]/.test(filter2);
|
|
7374
|
+
if (isGlobPattern) {
|
|
7375
|
+
const pattern = filter2.startsWith("**/") ? filter2 : `**/${filter2}`;
|
|
7376
|
+
return minimatch(normalizedPath, pattern, { matchBase: true });
|
|
7377
|
+
} else {
|
|
7378
|
+
return normalizedPath.startsWith(filter2 + "/") || normalizedPath === filter2 || normalizedPath.startsWith("./" + filter2 + "/") || normalizedPath === "./" + filter2;
|
|
7379
|
+
}
|
|
7380
|
+
});
|
|
5924
7381
|
});
|
|
5925
7382
|
}
|
|
5926
7383
|
filteredResults.sort((a, b) => b.score - a.score);
|
|
@@ -5934,7 +7391,7 @@ function createSearchContext(rootDir, moduleId, config) {
|
|
|
5934
7391
|
config,
|
|
5935
7392
|
loadFileIndex: async (filepath) => {
|
|
5936
7393
|
const hasExtension = /\.[^./]+$/.test(filepath);
|
|
5937
|
-
const indexFilePath = hasExtension ?
|
|
7394
|
+
const indexFilePath = hasExtension ? path17.join(indexPath, filepath.replace(/\.[^.]+$/, ".json")) : path17.join(indexPath, filepath + ".json");
|
|
5938
7395
|
try {
|
|
5939
7396
|
const content = await fs8.readFile(indexFilePath, "utf-8");
|
|
5940
7397
|
return JSON.parse(content);
|
|
@@ -5946,7 +7403,7 @@ function createSearchContext(rootDir, moduleId, config) {
|
|
|
5946
7403
|
const files = [];
|
|
5947
7404
|
await traverseDirectory(indexPath, files, indexPath);
|
|
5948
7405
|
return files.filter((f) => f.endsWith(".json") && !f.endsWith("manifest.json")).map((f) => {
|
|
5949
|
-
const relative3 =
|
|
7406
|
+
const relative3 = path17.relative(indexPath, f);
|
|
5950
7407
|
return relative3.replace(/\.json$/, "");
|
|
5951
7408
|
});
|
|
5952
7409
|
}
|
|
@@ -5956,7 +7413,7 @@ async function traverseDirectory(dir, files, basePath) {
|
|
|
5956
7413
|
try {
|
|
5957
7414
|
const entries = await fs8.readdir(dir, { withFileTypes: true });
|
|
5958
7415
|
for (const entry of entries) {
|
|
5959
|
-
const fullPath =
|
|
7416
|
+
const fullPath = path17.join(dir, entry.name);
|
|
5960
7417
|
if (entry.isDirectory()) {
|
|
5961
7418
|
await traverseDirectory(fullPath, files, basePath);
|
|
5962
7419
|
} else if (entry.isFile()) {
|
|
@@ -6058,4 +7515,4 @@ export {
|
|
|
6058
7515
|
ConsoleLogger
|
|
6059
7516
|
};
|
|
6060
7517
|
|
|
6061
|
-
//# debugId=
|
|
7518
|
+
//# debugId=70C95E2CED98827164756E2164756E21
|