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/cli/main.js
CHANGED
|
@@ -16,6 +16,7 @@ var __toESM = (mod, isNodeMode, target) => {
|
|
|
16
16
|
});
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
19
20
|
var __export = (target, all) => {
|
|
20
21
|
for (var name in all)
|
|
21
22
|
__defProp(target, name, {
|
|
@@ -2642,44 +2643,10 @@ var init_queryIntent = __esm(() => {
|
|
|
2642
2643
|
});
|
|
2643
2644
|
|
|
2644
2645
|
// src/domain/services/chunking.ts
|
|
2645
|
-
function createLineBasedChunks(content, options = {}) {
|
|
2646
|
-
const {
|
|
2647
|
-
chunkSize = DEFAULT_CHUNK_SIZE,
|
|
2648
|
-
overlap = DEFAULT_OVERLAP,
|
|
2649
|
-
minLinesForMultipleChunks = chunkSize
|
|
2650
|
-
} = options;
|
|
2651
|
-
const lines = content.split(`
|
|
2652
|
-
`);
|
|
2653
|
-
const chunks = [];
|
|
2654
|
-
if (lines.length <= minLinesForMultipleChunks) {
|
|
2655
|
-
return [
|
|
2656
|
-
{
|
|
2657
|
-
content,
|
|
2658
|
-
startLine: 1,
|
|
2659
|
-
endLine: lines.length,
|
|
2660
|
-
type: "file"
|
|
2661
|
-
}
|
|
2662
|
-
];
|
|
2663
|
-
}
|
|
2664
|
-
for (let i = 0;i < lines.length; i += chunkSize - overlap) {
|
|
2665
|
-
const endIdx = Math.min(i + chunkSize, lines.length);
|
|
2666
|
-
chunks.push({
|
|
2667
|
-
content: lines.slice(i, endIdx).join(`
|
|
2668
|
-
`),
|
|
2669
|
-
startLine: i + 1,
|
|
2670
|
-
endLine: endIdx,
|
|
2671
|
-
type: "block"
|
|
2672
|
-
});
|
|
2673
|
-
if (endIdx >= lines.length)
|
|
2674
|
-
break;
|
|
2675
|
-
}
|
|
2676
|
-
return chunks;
|
|
2677
|
-
}
|
|
2678
2646
|
function generateChunkId(filepath, startLine, endLine) {
|
|
2679
2647
|
const safePath = filepath.replace(/[/\\]/g, "-").replace(/\./g, "_");
|
|
2680
2648
|
return `${safePath}-${startLine}-${endLine}`;
|
|
2681
2649
|
}
|
|
2682
|
-
var DEFAULT_CHUNK_SIZE = 30, DEFAULT_OVERLAP = 5;
|
|
2683
2650
|
|
|
2684
2651
|
// src/domain/services/queryLiteralParser.ts
|
|
2685
2652
|
function parseQueryLiterals(query) {
|
|
@@ -3547,6 +3514,63 @@ var init_lexicon2 = __esm(() => {
|
|
|
3547
3514
|
defaultLookupMap = buildLookupMap(DEFAULT_LEXICON);
|
|
3548
3515
|
});
|
|
3549
3516
|
|
|
3517
|
+
// src/domain/services/jsonPathExtractor.ts
|
|
3518
|
+
function extractJsonPaths(obj, fileBasename) {
|
|
3519
|
+
const paths = extractPathsRecursive(obj, fileBasename);
|
|
3520
|
+
return paths.map((path8) => ({
|
|
3521
|
+
value: path8,
|
|
3522
|
+
type: "identifier",
|
|
3523
|
+
matchType: "definition"
|
|
3524
|
+
}));
|
|
3525
|
+
}
|
|
3526
|
+
function extractPathsRecursive(obj, prefix) {
|
|
3527
|
+
const paths = [];
|
|
3528
|
+
if (obj === null || obj === undefined) {
|
|
3529
|
+
return paths;
|
|
3530
|
+
}
|
|
3531
|
+
if (Array.isArray(obj)) {
|
|
3532
|
+
obj.forEach((item, index) => {
|
|
3533
|
+
const indexedPrefix = `${prefix}[${index}]`;
|
|
3534
|
+
paths.push(indexedPrefix);
|
|
3535
|
+
if (item !== null && typeof item === "object") {
|
|
3536
|
+
paths.push(...extractPathsRecursive(item, indexedPrefix));
|
|
3537
|
+
}
|
|
3538
|
+
});
|
|
3539
|
+
} else if (typeof obj === "object") {
|
|
3540
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
3541
|
+
const fullPath = `${prefix}.${key}`;
|
|
3542
|
+
paths.push(fullPath);
|
|
3543
|
+
if (value !== null && typeof value === "object") {
|
|
3544
|
+
paths.push(...extractPathsRecursive(value, fullPath));
|
|
3545
|
+
}
|
|
3546
|
+
}
|
|
3547
|
+
}
|
|
3548
|
+
return paths;
|
|
3549
|
+
}
|
|
3550
|
+
function extractJsonKeywords(obj) {
|
|
3551
|
+
const keywords = new Set;
|
|
3552
|
+
const extract = (value, parentKey) => {
|
|
3553
|
+
if (value === null || value === undefined) {
|
|
3554
|
+
return;
|
|
3555
|
+
}
|
|
3556
|
+
if (typeof value === "string") {
|
|
3557
|
+
const words = value.replace(/([a-z])([A-Z])/g, "$1 $2").toLowerCase().split(/[\s_\-./]+/).filter((w) => w.length > 2);
|
|
3558
|
+
words.forEach((w) => keywords.add(w));
|
|
3559
|
+
} else if (Array.isArray(value)) {
|
|
3560
|
+
value.forEach((item) => extract(item));
|
|
3561
|
+
} else if (typeof value === "object") {
|
|
3562
|
+
for (const [key, val] of Object.entries(value)) {
|
|
3563
|
+
keywords.add(key.toLowerCase());
|
|
3564
|
+
const keyWords = key.replace(/([a-z])([A-Z])/g, "$1 $2").toLowerCase().split(/[\s_\-]+/).filter((w) => w.length > 2);
|
|
3565
|
+
keyWords.forEach((w) => keywords.add(w));
|
|
3566
|
+
extract(val, key);
|
|
3567
|
+
}
|
|
3568
|
+
}
|
|
3569
|
+
};
|
|
3570
|
+
extract(obj);
|
|
3571
|
+
return Array.from(keywords);
|
|
3572
|
+
}
|
|
3573
|
+
|
|
3550
3574
|
// src/domain/services/index.ts
|
|
3551
3575
|
var init_services = __esm(() => {
|
|
3552
3576
|
init_keywords();
|
|
@@ -4477,113 +4501,66 @@ function isJsonFile(filepath) {
|
|
|
4477
4501
|
const ext = path11.extname(filepath).toLowerCase();
|
|
4478
4502
|
return JSON_EXTENSIONS.includes(ext);
|
|
4479
4503
|
}
|
|
4480
|
-
function extractJsonKeys(obj, prefix = "") {
|
|
4481
|
-
const keys = [];
|
|
4482
|
-
if (obj === null || obj === undefined) {
|
|
4483
|
-
return keys;
|
|
4484
|
-
}
|
|
4485
|
-
if (Array.isArray(obj)) {
|
|
4486
|
-
obj.forEach((item, index) => {
|
|
4487
|
-
keys.push(...extractJsonKeys(item, `${prefix}[${index}]`));
|
|
4488
|
-
});
|
|
4489
|
-
} else if (typeof obj === "object") {
|
|
4490
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
4491
|
-
const fullKey = prefix ? `${prefix}.${key}` : key;
|
|
4492
|
-
keys.push(key);
|
|
4493
|
-
keys.push(...extractJsonKeys(value, fullKey));
|
|
4494
|
-
}
|
|
4495
|
-
}
|
|
4496
|
-
return keys;
|
|
4497
|
-
}
|
|
4498
|
-
function extractJsonKeywords(content) {
|
|
4499
|
-
try {
|
|
4500
|
-
const parsed = JSON.parse(content);
|
|
4501
|
-
const keys = extractJsonKeys(parsed);
|
|
4502
|
-
const stringValues = [];
|
|
4503
|
-
const extractStrings = (obj) => {
|
|
4504
|
-
if (typeof obj === "string") {
|
|
4505
|
-
const words = obj.replace(/([a-z])([A-Z])/g, "$1 $2").toLowerCase().split(/\s+/).filter((w) => w.length > 2);
|
|
4506
|
-
stringValues.push(...words);
|
|
4507
|
-
} else if (Array.isArray(obj)) {
|
|
4508
|
-
obj.forEach(extractStrings);
|
|
4509
|
-
} else if (obj && typeof obj === "object") {
|
|
4510
|
-
Object.values(obj).forEach(extractStrings);
|
|
4511
|
-
}
|
|
4512
|
-
};
|
|
4513
|
-
extractStrings(parsed);
|
|
4514
|
-
return [...new Set([...keys, ...stringValues])];
|
|
4515
|
-
} catch {
|
|
4516
|
-
return [];
|
|
4517
|
-
}
|
|
4518
|
-
}
|
|
4519
4504
|
|
|
4520
4505
|
class JsonModule {
|
|
4521
4506
|
id = "data/json";
|
|
4522
4507
|
name = "JSON Search";
|
|
4523
|
-
description = "JSON file search with
|
|
4524
|
-
version = "
|
|
4508
|
+
description = "JSON file search with literal-based key path indexing";
|
|
4509
|
+
version = "2.0.0";
|
|
4525
4510
|
supportsFile(filepath) {
|
|
4526
4511
|
return isJsonFile(filepath);
|
|
4527
4512
|
}
|
|
4528
|
-
embeddingConfig = null;
|
|
4529
4513
|
symbolicIndex = null;
|
|
4514
|
+
literalIndex = null;
|
|
4530
4515
|
pendingSummaries = new Map;
|
|
4516
|
+
pendingLiterals = new Map;
|
|
4531
4517
|
rootDir = "";
|
|
4532
4518
|
logger = undefined;
|
|
4533
4519
|
async initialize(config) {
|
|
4534
|
-
this.embeddingConfig = getEmbeddingConfigFromModule(config);
|
|
4535
4520
|
this.logger = config.options?.logger;
|
|
4536
|
-
if (this.logger) {
|
|
4537
|
-
this.embeddingConfig = {
|
|
4538
|
-
...this.embeddingConfig,
|
|
4539
|
-
logger: this.logger
|
|
4540
|
-
};
|
|
4541
|
-
}
|
|
4542
|
-
configureEmbeddings(this.embeddingConfig);
|
|
4543
4521
|
this.pendingSummaries.clear();
|
|
4522
|
+
this.pendingLiterals.clear();
|
|
4544
4523
|
}
|
|
4545
4524
|
async indexFile(filepath, content, ctx) {
|
|
4546
4525
|
if (!isJsonFile(filepath)) {
|
|
4547
4526
|
return null;
|
|
4548
4527
|
}
|
|
4549
4528
|
this.rootDir = ctx.rootDir;
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
}
|
|
4554
|
-
if (textChunks.length === 0) {
|
|
4529
|
+
let parsed;
|
|
4530
|
+
try {
|
|
4531
|
+
parsed = JSON.parse(content);
|
|
4532
|
+
} catch {
|
|
4555
4533
|
return null;
|
|
4556
4534
|
}
|
|
4557
|
-
const
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
const
|
|
4562
|
-
const
|
|
4563
|
-
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
try {
|
|
4571
|
-
return JSON.parse(content);
|
|
4572
|
-
} catch {
|
|
4573
|
-
return {};
|
|
4535
|
+
const fileBasename = path11.basename(filepath, path11.extname(filepath));
|
|
4536
|
+
const jsonPathLiterals = extractJsonPaths(parsed, fileBasename);
|
|
4537
|
+
const lines = content.split(`
|
|
4538
|
+
`);
|
|
4539
|
+
const lineCount = lines.length;
|
|
4540
|
+
const chunkId = generateChunkId(filepath, 1, lineCount);
|
|
4541
|
+
const chunks = [
|
|
4542
|
+
{
|
|
4543
|
+
id: chunkId,
|
|
4544
|
+
content,
|
|
4545
|
+
startLine: 1,
|
|
4546
|
+
endLine: lineCount,
|
|
4547
|
+
type: "file"
|
|
4574
4548
|
}
|
|
4575
|
-
|
|
4549
|
+
];
|
|
4550
|
+
if (jsonPathLiterals.length > 0) {
|
|
4551
|
+
this.pendingLiterals.set(chunkId, {
|
|
4552
|
+
filepath,
|
|
4553
|
+
literals: jsonPathLiterals
|
|
4554
|
+
});
|
|
4555
|
+
}
|
|
4576
4556
|
const stats = await ctx.getFileStats(filepath);
|
|
4577
|
-
const currentConfig = getEmbeddingConfig();
|
|
4578
4557
|
const moduleData = {
|
|
4579
|
-
|
|
4580
|
-
embeddingModel: currentConfig.model,
|
|
4581
|
-
jsonKeys
|
|
4558
|
+
jsonPaths: jsonPathLiterals.map((l) => l.value)
|
|
4582
4559
|
};
|
|
4583
|
-
const keywords = extractJsonKeywords(
|
|
4560
|
+
const keywords = extractJsonKeywords(parsed);
|
|
4584
4561
|
const fileSummary = {
|
|
4585
4562
|
filepath,
|
|
4586
|
-
chunkCount:
|
|
4563
|
+
chunkCount: 1,
|
|
4587
4564
|
chunkTypes: ["file"],
|
|
4588
4565
|
keywords,
|
|
4589
4566
|
exports: [],
|
|
@@ -4606,7 +4583,24 @@ class JsonModule {
|
|
|
4606
4583
|
}
|
|
4607
4584
|
this.symbolicIndex.buildBM25Index();
|
|
4608
4585
|
await this.symbolicIndex.save();
|
|
4586
|
+
this.literalIndex = new LiteralIndex(indexDir, this.id);
|
|
4587
|
+
await this.literalIndex.initialize();
|
|
4588
|
+
const indexedFilepaths = new Set;
|
|
4589
|
+
for (const filepath of this.pendingSummaries.keys()) {
|
|
4590
|
+
indexedFilepaths.add(filepath);
|
|
4591
|
+
}
|
|
4592
|
+
for (const { filepath } of this.pendingLiterals.values()) {
|
|
4593
|
+
indexedFilepaths.add(filepath);
|
|
4594
|
+
}
|
|
4595
|
+
for (const filepath of indexedFilepaths) {
|
|
4596
|
+
this.literalIndex.removeFile(filepath);
|
|
4597
|
+
}
|
|
4598
|
+
for (const [chunkId, { filepath, literals }] of this.pendingLiterals) {
|
|
4599
|
+
this.literalIndex.addLiterals(chunkId, filepath, literals);
|
|
4600
|
+
}
|
|
4601
|
+
await this.literalIndex.save();
|
|
4609
4602
|
this.pendingSummaries.clear();
|
|
4603
|
+
this.pendingLiterals.clear();
|
|
4610
4604
|
}
|
|
4611
4605
|
async search(query, ctx, options = {}) {
|
|
4612
4606
|
const {
|
|
@@ -4614,8 +4608,15 @@ class JsonModule {
|
|
|
4614
4608
|
minScore = DEFAULT_MIN_SCORE3,
|
|
4615
4609
|
filePatterns
|
|
4616
4610
|
} = options;
|
|
4611
|
+
const { literals: queryLiterals, remainingQuery } = parseQueryLiterals(query);
|
|
4617
4612
|
const indexDir = getRaggrepDir(ctx.rootDir, ctx.config);
|
|
4618
4613
|
const symbolicIndex = new SymbolicIndex(indexDir, this.id);
|
|
4614
|
+
const literalIndex = new LiteralIndex(indexDir, this.id);
|
|
4615
|
+
let literalMatchMap = new Map;
|
|
4616
|
+
try {
|
|
4617
|
+
await literalIndex.initialize();
|
|
4618
|
+
literalMatchMap = literalIndex.buildMatchMap(queryLiterals);
|
|
4619
|
+
} catch {}
|
|
4619
4620
|
let allFiles;
|
|
4620
4621
|
try {
|
|
4621
4622
|
await symbolicIndex.initialize();
|
|
@@ -4635,25 +4636,16 @@ class JsonModule {
|
|
|
4635
4636
|
});
|
|
4636
4637
|
});
|
|
4637
4638
|
}
|
|
4638
|
-
const queryEmbedding = await getEmbedding(query);
|
|
4639
4639
|
const bm25Index = new BM25Index;
|
|
4640
4640
|
const allChunksData = [];
|
|
4641
4641
|
for (const filepath of filesToSearch) {
|
|
4642
4642
|
const fileIndex = await ctx.loadFileIndex(filepath);
|
|
4643
4643
|
if (!fileIndex)
|
|
4644
4644
|
continue;
|
|
4645
|
-
const
|
|
4646
|
-
if (!moduleData?.embeddings)
|
|
4647
|
-
continue;
|
|
4648
|
-
for (let i = 0;i < fileIndex.chunks.length; i++) {
|
|
4649
|
-
const chunk = fileIndex.chunks[i];
|
|
4650
|
-
const embedding = moduleData.embeddings[i];
|
|
4651
|
-
if (!embedding)
|
|
4652
|
-
continue;
|
|
4645
|
+
for (const chunk of fileIndex.chunks) {
|
|
4653
4646
|
allChunksData.push({
|
|
4654
4647
|
filepath: fileIndex.filepath,
|
|
4655
|
-
chunk
|
|
4656
|
-
embedding
|
|
4648
|
+
chunk
|
|
4657
4649
|
});
|
|
4658
4650
|
bm25Index.addDocuments([{ id: chunk.id, content: chunk.content }]);
|
|
4659
4651
|
}
|
|
@@ -4663,32 +4655,70 @@ class JsonModule {
|
|
|
4663
4655
|
for (const result of bm25Results) {
|
|
4664
4656
|
bm25Scores.set(result.id, normalizeScore(result.score, 3));
|
|
4665
4657
|
}
|
|
4666
|
-
const queryTerms = extractQueryTerms(query);
|
|
4667
4658
|
const results = [];
|
|
4668
|
-
|
|
4669
|
-
|
|
4659
|
+
const processedChunkIds = new Set;
|
|
4660
|
+
for (const { filepath, chunk } of allChunksData) {
|
|
4670
4661
|
const bm25Score = bm25Scores.get(chunk.id) || 0;
|
|
4671
|
-
const
|
|
4672
|
-
|
|
4662
|
+
const literalMatches = literalMatchMap.get(chunk.id) || [];
|
|
4663
|
+
const literalContribution = calculateLiteralContribution(literalMatches, bm25Score > 0);
|
|
4664
|
+
const baseScore = BM25_WEIGHT2 * bm25Score;
|
|
4665
|
+
const boostedScore = applyLiteralBoost(baseScore, literalMatches, bm25Score > 0);
|
|
4666
|
+
const literalBase = literalMatches.length > 0 && bm25Score === 0 ? LITERAL_SCORING_CONSTANTS.BASE_SCORE * LITERAL_WEIGHT : 0;
|
|
4667
|
+
const finalScore = boostedScore + literalBase;
|
|
4668
|
+
processedChunkIds.add(chunk.id);
|
|
4669
|
+
if (finalScore >= minScore || literalMatches.length > 0) {
|
|
4673
4670
|
results.push({
|
|
4674
4671
|
filepath,
|
|
4675
4672
|
chunk,
|
|
4676
|
-
score:
|
|
4673
|
+
score: finalScore,
|
|
4677
4674
|
moduleId: this.id,
|
|
4678
4675
|
context: {
|
|
4679
|
-
|
|
4680
|
-
|
|
4676
|
+
bm25Score,
|
|
4677
|
+
literalMultiplier: literalContribution.multiplier,
|
|
4678
|
+
literalMatchType: literalContribution.bestMatchType,
|
|
4679
|
+
literalConfidence: literalContribution.bestConfidence,
|
|
4680
|
+
literalMatchCount: literalContribution.matchCount
|
|
4681
4681
|
}
|
|
4682
4682
|
});
|
|
4683
4683
|
}
|
|
4684
4684
|
}
|
|
4685
|
+
for (const [chunkId, matches] of literalMatchMap) {
|
|
4686
|
+
if (processedChunkIds.has(chunkId)) {
|
|
4687
|
+
continue;
|
|
4688
|
+
}
|
|
4689
|
+
const filepath = matches[0]?.filepath;
|
|
4690
|
+
if (!filepath)
|
|
4691
|
+
continue;
|
|
4692
|
+
const fileIndex = await ctx.loadFileIndex(filepath);
|
|
4693
|
+
if (!fileIndex)
|
|
4694
|
+
continue;
|
|
4695
|
+
const chunk = fileIndex.chunks.find((c) => c.id === chunkId);
|
|
4696
|
+
if (!chunk)
|
|
4697
|
+
continue;
|
|
4698
|
+
const literalContribution = calculateLiteralContribution(matches, false);
|
|
4699
|
+
const score = LITERAL_SCORING_CONSTANTS.BASE_SCORE * literalContribution.multiplier;
|
|
4700
|
+
processedChunkIds.add(chunkId);
|
|
4701
|
+
results.push({
|
|
4702
|
+
filepath,
|
|
4703
|
+
chunk,
|
|
4704
|
+
score,
|
|
4705
|
+
moduleId: this.id,
|
|
4706
|
+
context: {
|
|
4707
|
+
bm25Score: 0,
|
|
4708
|
+
literalMultiplier: literalContribution.multiplier,
|
|
4709
|
+
literalMatchType: literalContribution.bestMatchType,
|
|
4710
|
+
literalConfidence: literalContribution.bestConfidence,
|
|
4711
|
+
literalMatchCount: literalContribution.matchCount,
|
|
4712
|
+
literalOnly: true
|
|
4713
|
+
}
|
|
4714
|
+
});
|
|
4715
|
+
}
|
|
4685
4716
|
results.sort((a, b) => b.score - a.score);
|
|
4686
4717
|
return results.slice(0, topK);
|
|
4687
4718
|
}
|
|
4688
4719
|
}
|
|
4689
|
-
var DEFAULT_MIN_SCORE3 = 0.
|
|
4720
|
+
var DEFAULT_MIN_SCORE3 = 0.1, DEFAULT_TOP_K3 = 10, BM25_WEIGHT2 = 0.4, LITERAL_WEIGHT = 0.6, JSON_EXTENSIONS, supportsFile2;
|
|
4690
4721
|
var init_json = __esm(() => {
|
|
4691
|
-
init_embeddings();
|
|
4692
4722
|
init_services();
|
|
4693
4723
|
init_config2();
|
|
4694
4724
|
init_storage();
|
|
@@ -4958,7 +4988,7 @@ ${section.content}` : section.content,
|
|
|
4958
4988
|
].includes(t))) {
|
|
4959
4989
|
docBoost = 0.05;
|
|
4960
4990
|
}
|
|
4961
|
-
const hybridScore =
|
|
4991
|
+
const hybridScore = SEMANTIC_WEIGHT2 * semanticScore + BM25_WEIGHT3 * bm25Score + docBoost;
|
|
4962
4992
|
if (hybridScore >= minScore || bm25Score > 0.3) {
|
|
4963
4993
|
results.push({
|
|
4964
4994
|
filepath,
|
|
@@ -4977,7 +5007,7 @@ ${section.content}` : section.content,
|
|
|
4977
5007
|
return results.slice(0, topK);
|
|
4978
5008
|
}
|
|
4979
5009
|
}
|
|
4980
|
-
var DEFAULT_MIN_SCORE4 = 0.15, DEFAULT_TOP_K4 = 10,
|
|
5010
|
+
var DEFAULT_MIN_SCORE4 = 0.15, DEFAULT_TOP_K4 = 10, SEMANTIC_WEIGHT2 = 0.7, BM25_WEIGHT3 = 0.3, MARKDOWN_EXTENSIONS, supportsFile3;
|
|
4981
5011
|
var init_markdown = __esm(() => {
|
|
4982
5012
|
init_embeddings();
|
|
4983
5013
|
init_services();
|
|
@@ -6073,6 +6103,1401 @@ var init_indexer = __esm(() => {
|
|
|
6073
6103
|
DEFAULT_CONCURRENCY = getOptimalConcurrency();
|
|
6074
6104
|
});
|
|
6075
6105
|
|
|
6106
|
+
// node_modules/balanced-match/index.js
|
|
6107
|
+
var require_balanced_match = __commonJS((exports, module) => {
|
|
6108
|
+
module.exports = balanced;
|
|
6109
|
+
function balanced(a, b, str) {
|
|
6110
|
+
if (a instanceof RegExp)
|
|
6111
|
+
a = maybeMatch(a, str);
|
|
6112
|
+
if (b instanceof RegExp)
|
|
6113
|
+
b = maybeMatch(b, str);
|
|
6114
|
+
var r = range(a, b, str);
|
|
6115
|
+
return r && {
|
|
6116
|
+
start: r[0],
|
|
6117
|
+
end: r[1],
|
|
6118
|
+
pre: str.slice(0, r[0]),
|
|
6119
|
+
body: str.slice(r[0] + a.length, r[1]),
|
|
6120
|
+
post: str.slice(r[1] + b.length)
|
|
6121
|
+
};
|
|
6122
|
+
}
|
|
6123
|
+
function maybeMatch(reg, str) {
|
|
6124
|
+
var m = str.match(reg);
|
|
6125
|
+
return m ? m[0] : null;
|
|
6126
|
+
}
|
|
6127
|
+
balanced.range = range;
|
|
6128
|
+
function range(a, b, str) {
|
|
6129
|
+
var begs, beg, left, right, result;
|
|
6130
|
+
var ai = str.indexOf(a);
|
|
6131
|
+
var bi = str.indexOf(b, ai + 1);
|
|
6132
|
+
var i = ai;
|
|
6133
|
+
if (ai >= 0 && bi > 0) {
|
|
6134
|
+
if (a === b) {
|
|
6135
|
+
return [ai, bi];
|
|
6136
|
+
}
|
|
6137
|
+
begs = [];
|
|
6138
|
+
left = str.length;
|
|
6139
|
+
while (i >= 0 && !result) {
|
|
6140
|
+
if (i == ai) {
|
|
6141
|
+
begs.push(i);
|
|
6142
|
+
ai = str.indexOf(a, i + 1);
|
|
6143
|
+
} else if (begs.length == 1) {
|
|
6144
|
+
result = [begs.pop(), bi];
|
|
6145
|
+
} else {
|
|
6146
|
+
beg = begs.pop();
|
|
6147
|
+
if (beg < left) {
|
|
6148
|
+
left = beg;
|
|
6149
|
+
right = bi;
|
|
6150
|
+
}
|
|
6151
|
+
bi = str.indexOf(b, i + 1);
|
|
6152
|
+
}
|
|
6153
|
+
i = ai < bi && ai >= 0 ? ai : bi;
|
|
6154
|
+
}
|
|
6155
|
+
if (begs.length) {
|
|
6156
|
+
result = [left, right];
|
|
6157
|
+
}
|
|
6158
|
+
}
|
|
6159
|
+
return result;
|
|
6160
|
+
}
|
|
6161
|
+
});
|
|
6162
|
+
|
|
6163
|
+
// node_modules/brace-expansion/index.js
|
|
6164
|
+
var require_brace_expansion = __commonJS((exports, module) => {
|
|
6165
|
+
var balanced = require_balanced_match();
|
|
6166
|
+
module.exports = expandTop;
|
|
6167
|
+
var escSlash = "\x00SLASH" + Math.random() + "\x00";
|
|
6168
|
+
var escOpen = "\x00OPEN" + Math.random() + "\x00";
|
|
6169
|
+
var escClose = "\x00CLOSE" + Math.random() + "\x00";
|
|
6170
|
+
var escComma = "\x00COMMA" + Math.random() + "\x00";
|
|
6171
|
+
var escPeriod = "\x00PERIOD" + Math.random() + "\x00";
|
|
6172
|
+
function numeric(str) {
|
|
6173
|
+
return parseInt(str, 10) == str ? parseInt(str, 10) : str.charCodeAt(0);
|
|
6174
|
+
}
|
|
6175
|
+
function escapeBraces(str) {
|
|
6176
|
+
return str.split("\\\\").join(escSlash).split("\\{").join(escOpen).split("\\}").join(escClose).split("\\,").join(escComma).split("\\.").join(escPeriod);
|
|
6177
|
+
}
|
|
6178
|
+
function unescapeBraces(str) {
|
|
6179
|
+
return str.split(escSlash).join("\\").split(escOpen).join("{").split(escClose).join("}").split(escComma).join(",").split(escPeriod).join(".");
|
|
6180
|
+
}
|
|
6181
|
+
function parseCommaParts(str) {
|
|
6182
|
+
if (!str)
|
|
6183
|
+
return [""];
|
|
6184
|
+
var parts = [];
|
|
6185
|
+
var m = balanced("{", "}", str);
|
|
6186
|
+
if (!m)
|
|
6187
|
+
return str.split(",");
|
|
6188
|
+
var pre = m.pre;
|
|
6189
|
+
var body = m.body;
|
|
6190
|
+
var post = m.post;
|
|
6191
|
+
var p = pre.split(",");
|
|
6192
|
+
p[p.length - 1] += "{" + body + "}";
|
|
6193
|
+
var postParts = parseCommaParts(post);
|
|
6194
|
+
if (post.length) {
|
|
6195
|
+
p[p.length - 1] += postParts.shift();
|
|
6196
|
+
p.push.apply(p, postParts);
|
|
6197
|
+
}
|
|
6198
|
+
parts.push.apply(parts, p);
|
|
6199
|
+
return parts;
|
|
6200
|
+
}
|
|
6201
|
+
function expandTop(str) {
|
|
6202
|
+
if (!str)
|
|
6203
|
+
return [];
|
|
6204
|
+
if (str.substr(0, 2) === "{}") {
|
|
6205
|
+
str = "\\{\\}" + str.substr(2);
|
|
6206
|
+
}
|
|
6207
|
+
return expand(escapeBraces(str), true).map(unescapeBraces);
|
|
6208
|
+
}
|
|
6209
|
+
function embrace(str) {
|
|
6210
|
+
return "{" + str + "}";
|
|
6211
|
+
}
|
|
6212
|
+
function isPadded(el) {
|
|
6213
|
+
return /^-?0\d/.test(el);
|
|
6214
|
+
}
|
|
6215
|
+
function lte(i, y) {
|
|
6216
|
+
return i <= y;
|
|
6217
|
+
}
|
|
6218
|
+
function gte(i, y) {
|
|
6219
|
+
return i >= y;
|
|
6220
|
+
}
|
|
6221
|
+
function expand(str, isTop) {
|
|
6222
|
+
var expansions = [];
|
|
6223
|
+
var m = balanced("{", "}", str);
|
|
6224
|
+
if (!m)
|
|
6225
|
+
return [str];
|
|
6226
|
+
var pre = m.pre;
|
|
6227
|
+
var post = m.post.length ? expand(m.post, false) : [""];
|
|
6228
|
+
if (/\$$/.test(m.pre)) {
|
|
6229
|
+
for (var k = 0;k < post.length; k++) {
|
|
6230
|
+
var expansion = pre + "{" + m.body + "}" + post[k];
|
|
6231
|
+
expansions.push(expansion);
|
|
6232
|
+
}
|
|
6233
|
+
} else {
|
|
6234
|
+
var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
|
|
6235
|
+
var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
|
|
6236
|
+
var isSequence = isNumericSequence || isAlphaSequence;
|
|
6237
|
+
var isOptions = m.body.indexOf(",") >= 0;
|
|
6238
|
+
if (!isSequence && !isOptions) {
|
|
6239
|
+
if (m.post.match(/,(?!,).*\}/)) {
|
|
6240
|
+
str = m.pre + "{" + m.body + escClose + m.post;
|
|
6241
|
+
return expand(str);
|
|
6242
|
+
}
|
|
6243
|
+
return [str];
|
|
6244
|
+
}
|
|
6245
|
+
var n;
|
|
6246
|
+
if (isSequence) {
|
|
6247
|
+
n = m.body.split(/\.\./);
|
|
6248
|
+
} else {
|
|
6249
|
+
n = parseCommaParts(m.body);
|
|
6250
|
+
if (n.length === 1) {
|
|
6251
|
+
n = expand(n[0], false).map(embrace);
|
|
6252
|
+
if (n.length === 1) {
|
|
6253
|
+
return post.map(function(p) {
|
|
6254
|
+
return m.pre + n[0] + p;
|
|
6255
|
+
});
|
|
6256
|
+
}
|
|
6257
|
+
}
|
|
6258
|
+
}
|
|
6259
|
+
var N;
|
|
6260
|
+
if (isSequence) {
|
|
6261
|
+
var x = numeric(n[0]);
|
|
6262
|
+
var y = numeric(n[1]);
|
|
6263
|
+
var width = Math.max(n[0].length, n[1].length);
|
|
6264
|
+
var incr = n.length == 3 ? Math.abs(numeric(n[2])) : 1;
|
|
6265
|
+
var test = lte;
|
|
6266
|
+
var reverse = y < x;
|
|
6267
|
+
if (reverse) {
|
|
6268
|
+
incr *= -1;
|
|
6269
|
+
test = gte;
|
|
6270
|
+
}
|
|
6271
|
+
var pad = n.some(isPadded);
|
|
6272
|
+
N = [];
|
|
6273
|
+
for (var i = x;test(i, y); i += incr) {
|
|
6274
|
+
var c;
|
|
6275
|
+
if (isAlphaSequence) {
|
|
6276
|
+
c = String.fromCharCode(i);
|
|
6277
|
+
if (c === "\\")
|
|
6278
|
+
c = "";
|
|
6279
|
+
} else {
|
|
6280
|
+
c = String(i);
|
|
6281
|
+
if (pad) {
|
|
6282
|
+
var need = width - c.length;
|
|
6283
|
+
if (need > 0) {
|
|
6284
|
+
var z = new Array(need + 1).join("0");
|
|
6285
|
+
if (i < 0)
|
|
6286
|
+
c = "-" + z + c.slice(1);
|
|
6287
|
+
else
|
|
6288
|
+
c = z + c;
|
|
6289
|
+
}
|
|
6290
|
+
}
|
|
6291
|
+
}
|
|
6292
|
+
N.push(c);
|
|
6293
|
+
}
|
|
6294
|
+
} else {
|
|
6295
|
+
N = [];
|
|
6296
|
+
for (var j = 0;j < n.length; j++) {
|
|
6297
|
+
N.push.apply(N, expand(n[j], false));
|
|
6298
|
+
}
|
|
6299
|
+
}
|
|
6300
|
+
for (var j = 0;j < N.length; j++) {
|
|
6301
|
+
for (var k = 0;k < post.length; k++) {
|
|
6302
|
+
var expansion = pre + N[j] + post[k];
|
|
6303
|
+
if (!isTop || isSequence || expansion)
|
|
6304
|
+
expansions.push(expansion);
|
|
6305
|
+
}
|
|
6306
|
+
}
|
|
6307
|
+
}
|
|
6308
|
+
return expansions;
|
|
6309
|
+
}
|
|
6310
|
+
});
|
|
6311
|
+
|
|
6312
|
+
// node_modules/minimatch/dist/esm/assert-valid-pattern.js
|
|
6313
|
+
var MAX_PATTERN_LENGTH, assertValidPattern = (pattern) => {
|
|
6314
|
+
if (typeof pattern !== "string") {
|
|
6315
|
+
throw new TypeError("invalid pattern");
|
|
6316
|
+
}
|
|
6317
|
+
if (pattern.length > MAX_PATTERN_LENGTH) {
|
|
6318
|
+
throw new TypeError("pattern is too long");
|
|
6319
|
+
}
|
|
6320
|
+
};
|
|
6321
|
+
var init_assert_valid_pattern = __esm(() => {
|
|
6322
|
+
MAX_PATTERN_LENGTH = 1024 * 64;
|
|
6323
|
+
});
|
|
6324
|
+
|
|
6325
|
+
// node_modules/minimatch/dist/esm/brace-expressions.js
|
|
6326
|
+
var posixClasses, braceEscape = (s) => s.replace(/[[\]\\-]/g, "\\$&"), regexpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), rangesToString = (ranges) => ranges.join(""), parseClass = (glob2, position) => {
|
|
6327
|
+
const pos = position;
|
|
6328
|
+
if (glob2.charAt(pos) !== "[") {
|
|
6329
|
+
throw new Error("not in a brace expression");
|
|
6330
|
+
}
|
|
6331
|
+
const ranges = [];
|
|
6332
|
+
const negs = [];
|
|
6333
|
+
let i = pos + 1;
|
|
6334
|
+
let sawStart = false;
|
|
6335
|
+
let uflag = false;
|
|
6336
|
+
let escaping = false;
|
|
6337
|
+
let negate = false;
|
|
6338
|
+
let endPos = pos;
|
|
6339
|
+
let rangeStart = "";
|
|
6340
|
+
WHILE:
|
|
6341
|
+
while (i < glob2.length) {
|
|
6342
|
+
const c = glob2.charAt(i);
|
|
6343
|
+
if ((c === "!" || c === "^") && i === pos + 1) {
|
|
6344
|
+
negate = true;
|
|
6345
|
+
i++;
|
|
6346
|
+
continue;
|
|
6347
|
+
}
|
|
6348
|
+
if (c === "]" && sawStart && !escaping) {
|
|
6349
|
+
endPos = i + 1;
|
|
6350
|
+
break;
|
|
6351
|
+
}
|
|
6352
|
+
sawStart = true;
|
|
6353
|
+
if (c === "\\") {
|
|
6354
|
+
if (!escaping) {
|
|
6355
|
+
escaping = true;
|
|
6356
|
+
i++;
|
|
6357
|
+
continue;
|
|
6358
|
+
}
|
|
6359
|
+
}
|
|
6360
|
+
if (c === "[" && !escaping) {
|
|
6361
|
+
for (const [cls, [unip, u, neg]] of Object.entries(posixClasses)) {
|
|
6362
|
+
if (glob2.startsWith(cls, i)) {
|
|
6363
|
+
if (rangeStart) {
|
|
6364
|
+
return ["$.", false, glob2.length - pos, true];
|
|
6365
|
+
}
|
|
6366
|
+
i += cls.length;
|
|
6367
|
+
if (neg)
|
|
6368
|
+
negs.push(unip);
|
|
6369
|
+
else
|
|
6370
|
+
ranges.push(unip);
|
|
6371
|
+
uflag = uflag || u;
|
|
6372
|
+
continue WHILE;
|
|
6373
|
+
}
|
|
6374
|
+
}
|
|
6375
|
+
}
|
|
6376
|
+
escaping = false;
|
|
6377
|
+
if (rangeStart) {
|
|
6378
|
+
if (c > rangeStart) {
|
|
6379
|
+
ranges.push(braceEscape(rangeStart) + "-" + braceEscape(c));
|
|
6380
|
+
} else if (c === rangeStart) {
|
|
6381
|
+
ranges.push(braceEscape(c));
|
|
6382
|
+
}
|
|
6383
|
+
rangeStart = "";
|
|
6384
|
+
i++;
|
|
6385
|
+
continue;
|
|
6386
|
+
}
|
|
6387
|
+
if (glob2.startsWith("-]", i + 1)) {
|
|
6388
|
+
ranges.push(braceEscape(c + "-"));
|
|
6389
|
+
i += 2;
|
|
6390
|
+
continue;
|
|
6391
|
+
}
|
|
6392
|
+
if (glob2.startsWith("-", i + 1)) {
|
|
6393
|
+
rangeStart = c;
|
|
6394
|
+
i += 2;
|
|
6395
|
+
continue;
|
|
6396
|
+
}
|
|
6397
|
+
ranges.push(braceEscape(c));
|
|
6398
|
+
i++;
|
|
6399
|
+
}
|
|
6400
|
+
if (endPos < i) {
|
|
6401
|
+
return ["", false, 0, false];
|
|
6402
|
+
}
|
|
6403
|
+
if (!ranges.length && !negs.length) {
|
|
6404
|
+
return ["$.", false, glob2.length - pos, true];
|
|
6405
|
+
}
|
|
6406
|
+
if (negs.length === 0 && ranges.length === 1 && /^\\?.$/.test(ranges[0]) && !negate) {
|
|
6407
|
+
const r = ranges[0].length === 2 ? ranges[0].slice(-1) : ranges[0];
|
|
6408
|
+
return [regexpEscape(r), false, endPos - pos, false];
|
|
6409
|
+
}
|
|
6410
|
+
const sranges = "[" + (negate ? "^" : "") + rangesToString(ranges) + "]";
|
|
6411
|
+
const snegs = "[" + (negate ? "" : "^") + rangesToString(negs) + "]";
|
|
6412
|
+
const comb = ranges.length && negs.length ? "(" + sranges + "|" + snegs + ")" : ranges.length ? sranges : snegs;
|
|
6413
|
+
return [comb, uflag, endPos - pos, true];
|
|
6414
|
+
};
|
|
6415
|
+
var init_brace_expressions = __esm(() => {
|
|
6416
|
+
posixClasses = {
|
|
6417
|
+
"[:alnum:]": ["\\p{L}\\p{Nl}\\p{Nd}", true],
|
|
6418
|
+
"[:alpha:]": ["\\p{L}\\p{Nl}", true],
|
|
6419
|
+
"[:ascii:]": ["\\x" + "00-\\x" + "7f", false],
|
|
6420
|
+
"[:blank:]": ["\\p{Zs}\\t", true],
|
|
6421
|
+
"[:cntrl:]": ["\\p{Cc}", true],
|
|
6422
|
+
"[:digit:]": ["\\p{Nd}", true],
|
|
6423
|
+
"[:graph:]": ["\\p{Z}\\p{C}", true, true],
|
|
6424
|
+
"[:lower:]": ["\\p{Ll}", true],
|
|
6425
|
+
"[:print:]": ["\\p{C}", true],
|
|
6426
|
+
"[:punct:]": ["\\p{P}", true],
|
|
6427
|
+
"[:space:]": ["\\p{Z}\\t\\r\\n\\v\\f", true],
|
|
6428
|
+
"[:upper:]": ["\\p{Lu}", true],
|
|
6429
|
+
"[:word:]": ["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}", true],
|
|
6430
|
+
"[:xdigit:]": ["A-Fa-f0-9", false]
|
|
6431
|
+
};
|
|
6432
|
+
});
|
|
6433
|
+
|
|
6434
|
+
// node_modules/minimatch/dist/esm/unescape.js
|
|
6435
|
+
var unescape = (s, { windowsPathsNoEscape = false } = {}) => {
|
|
6436
|
+
return windowsPathsNoEscape ? s.replace(/\[([^\/\\])\]/g, "$1") : s.replace(/((?!\\).|^)\[([^\/\\])\]/g, "$1$2").replace(/\\([^\/])/g, "$1");
|
|
6437
|
+
};
|
|
6438
|
+
|
|
6439
|
+
// node_modules/minimatch/dist/esm/ast.js
|
|
6440
|
+
class AST {
|
|
6441
|
+
type;
|
|
6442
|
+
#root;
|
|
6443
|
+
#hasMagic;
|
|
6444
|
+
#uflag = false;
|
|
6445
|
+
#parts = [];
|
|
6446
|
+
#parent;
|
|
6447
|
+
#parentIndex;
|
|
6448
|
+
#negs;
|
|
6449
|
+
#filledNegs = false;
|
|
6450
|
+
#options;
|
|
6451
|
+
#toString;
|
|
6452
|
+
#emptyExt = false;
|
|
6453
|
+
constructor(type, parent, options = {}) {
|
|
6454
|
+
this.type = type;
|
|
6455
|
+
if (type)
|
|
6456
|
+
this.#hasMagic = true;
|
|
6457
|
+
this.#parent = parent;
|
|
6458
|
+
this.#root = this.#parent ? this.#parent.#root : this;
|
|
6459
|
+
this.#options = this.#root === this ? options : this.#root.#options;
|
|
6460
|
+
this.#negs = this.#root === this ? [] : this.#root.#negs;
|
|
6461
|
+
if (type === "!" && !this.#root.#filledNegs)
|
|
6462
|
+
this.#negs.push(this);
|
|
6463
|
+
this.#parentIndex = this.#parent ? this.#parent.#parts.length : 0;
|
|
6464
|
+
}
|
|
6465
|
+
get hasMagic() {
|
|
6466
|
+
if (this.#hasMagic !== undefined)
|
|
6467
|
+
return this.#hasMagic;
|
|
6468
|
+
for (const p of this.#parts) {
|
|
6469
|
+
if (typeof p === "string")
|
|
6470
|
+
continue;
|
|
6471
|
+
if (p.type || p.hasMagic)
|
|
6472
|
+
return this.#hasMagic = true;
|
|
6473
|
+
}
|
|
6474
|
+
return this.#hasMagic;
|
|
6475
|
+
}
|
|
6476
|
+
toString() {
|
|
6477
|
+
if (this.#toString !== undefined)
|
|
6478
|
+
return this.#toString;
|
|
6479
|
+
if (!this.type) {
|
|
6480
|
+
return this.#toString = this.#parts.map((p) => String(p)).join("");
|
|
6481
|
+
} else {
|
|
6482
|
+
return this.#toString = this.type + "(" + this.#parts.map((p) => String(p)).join("|") + ")";
|
|
6483
|
+
}
|
|
6484
|
+
}
|
|
6485
|
+
#fillNegs() {
|
|
6486
|
+
if (this !== this.#root)
|
|
6487
|
+
throw new Error("should only call on root");
|
|
6488
|
+
if (this.#filledNegs)
|
|
6489
|
+
return this;
|
|
6490
|
+
this.toString();
|
|
6491
|
+
this.#filledNegs = true;
|
|
6492
|
+
let n;
|
|
6493
|
+
while (n = this.#negs.pop()) {
|
|
6494
|
+
if (n.type !== "!")
|
|
6495
|
+
continue;
|
|
6496
|
+
let p = n;
|
|
6497
|
+
let pp = p.#parent;
|
|
6498
|
+
while (pp) {
|
|
6499
|
+
for (let i = p.#parentIndex + 1;!pp.type && i < pp.#parts.length; i++) {
|
|
6500
|
+
for (const part of n.#parts) {
|
|
6501
|
+
if (typeof part === "string") {
|
|
6502
|
+
throw new Error("string part in extglob AST??");
|
|
6503
|
+
}
|
|
6504
|
+
part.copyIn(pp.#parts[i]);
|
|
6505
|
+
}
|
|
6506
|
+
}
|
|
6507
|
+
p = pp;
|
|
6508
|
+
pp = p.#parent;
|
|
6509
|
+
}
|
|
6510
|
+
}
|
|
6511
|
+
return this;
|
|
6512
|
+
}
|
|
6513
|
+
push(...parts) {
|
|
6514
|
+
for (const p of parts) {
|
|
6515
|
+
if (p === "")
|
|
6516
|
+
continue;
|
|
6517
|
+
if (typeof p !== "string" && !(p instanceof AST && p.#parent === this)) {
|
|
6518
|
+
throw new Error("invalid part: " + p);
|
|
6519
|
+
}
|
|
6520
|
+
this.#parts.push(p);
|
|
6521
|
+
}
|
|
6522
|
+
}
|
|
6523
|
+
toJSON() {
|
|
6524
|
+
const ret = this.type === null ? this.#parts.slice().map((p) => typeof p === "string" ? p : p.toJSON()) : [this.type, ...this.#parts.map((p) => p.toJSON())];
|
|
6525
|
+
if (this.isStart() && !this.type)
|
|
6526
|
+
ret.unshift([]);
|
|
6527
|
+
if (this.isEnd() && (this === this.#root || this.#root.#filledNegs && this.#parent?.type === "!")) {
|
|
6528
|
+
ret.push({});
|
|
6529
|
+
}
|
|
6530
|
+
return ret;
|
|
6531
|
+
}
|
|
6532
|
+
isStart() {
|
|
6533
|
+
if (this.#root === this)
|
|
6534
|
+
return true;
|
|
6535
|
+
if (!this.#parent?.isStart())
|
|
6536
|
+
return false;
|
|
6537
|
+
if (this.#parentIndex === 0)
|
|
6538
|
+
return true;
|
|
6539
|
+
const p = this.#parent;
|
|
6540
|
+
for (let i = 0;i < this.#parentIndex; i++) {
|
|
6541
|
+
const pp = p.#parts[i];
|
|
6542
|
+
if (!(pp instanceof AST && pp.type === "!")) {
|
|
6543
|
+
return false;
|
|
6544
|
+
}
|
|
6545
|
+
}
|
|
6546
|
+
return true;
|
|
6547
|
+
}
|
|
6548
|
+
isEnd() {
|
|
6549
|
+
if (this.#root === this)
|
|
6550
|
+
return true;
|
|
6551
|
+
if (this.#parent?.type === "!")
|
|
6552
|
+
return true;
|
|
6553
|
+
if (!this.#parent?.isEnd())
|
|
6554
|
+
return false;
|
|
6555
|
+
if (!this.type)
|
|
6556
|
+
return this.#parent?.isEnd();
|
|
6557
|
+
const pl = this.#parent ? this.#parent.#parts.length : 0;
|
|
6558
|
+
return this.#parentIndex === pl - 1;
|
|
6559
|
+
}
|
|
6560
|
+
copyIn(part) {
|
|
6561
|
+
if (typeof part === "string")
|
|
6562
|
+
this.push(part);
|
|
6563
|
+
else
|
|
6564
|
+
this.push(part.clone(this));
|
|
6565
|
+
}
|
|
6566
|
+
clone(parent) {
|
|
6567
|
+
const c = new AST(this.type, parent);
|
|
6568
|
+
for (const p of this.#parts) {
|
|
6569
|
+
c.copyIn(p);
|
|
6570
|
+
}
|
|
6571
|
+
return c;
|
|
6572
|
+
}
|
|
6573
|
+
static #parseAST(str, ast, pos, opt) {
|
|
6574
|
+
let escaping = false;
|
|
6575
|
+
let inBrace = false;
|
|
6576
|
+
let braceStart = -1;
|
|
6577
|
+
let braceNeg = false;
|
|
6578
|
+
if (ast.type === null) {
|
|
6579
|
+
let i2 = pos;
|
|
6580
|
+
let acc2 = "";
|
|
6581
|
+
while (i2 < str.length) {
|
|
6582
|
+
const c = str.charAt(i2++);
|
|
6583
|
+
if (escaping || c === "\\") {
|
|
6584
|
+
escaping = !escaping;
|
|
6585
|
+
acc2 += c;
|
|
6586
|
+
continue;
|
|
6587
|
+
}
|
|
6588
|
+
if (inBrace) {
|
|
6589
|
+
if (i2 === braceStart + 1) {
|
|
6590
|
+
if (c === "^" || c === "!") {
|
|
6591
|
+
braceNeg = true;
|
|
6592
|
+
}
|
|
6593
|
+
} else if (c === "]" && !(i2 === braceStart + 2 && braceNeg)) {
|
|
6594
|
+
inBrace = false;
|
|
6595
|
+
}
|
|
6596
|
+
acc2 += c;
|
|
6597
|
+
continue;
|
|
6598
|
+
} else if (c === "[") {
|
|
6599
|
+
inBrace = true;
|
|
6600
|
+
braceStart = i2;
|
|
6601
|
+
braceNeg = false;
|
|
6602
|
+
acc2 += c;
|
|
6603
|
+
continue;
|
|
6604
|
+
}
|
|
6605
|
+
if (!opt.noext && isExtglobType(c) && str.charAt(i2) === "(") {
|
|
6606
|
+
ast.push(acc2);
|
|
6607
|
+
acc2 = "";
|
|
6608
|
+
const ext = new AST(c, ast);
|
|
6609
|
+
i2 = AST.#parseAST(str, ext, i2, opt);
|
|
6610
|
+
ast.push(ext);
|
|
6611
|
+
continue;
|
|
6612
|
+
}
|
|
6613
|
+
acc2 += c;
|
|
6614
|
+
}
|
|
6615
|
+
ast.push(acc2);
|
|
6616
|
+
return i2;
|
|
6617
|
+
}
|
|
6618
|
+
let i = pos + 1;
|
|
6619
|
+
let part = new AST(null, ast);
|
|
6620
|
+
const parts = [];
|
|
6621
|
+
let acc = "";
|
|
6622
|
+
while (i < str.length) {
|
|
6623
|
+
const c = str.charAt(i++);
|
|
6624
|
+
if (escaping || c === "\\") {
|
|
6625
|
+
escaping = !escaping;
|
|
6626
|
+
acc += c;
|
|
6627
|
+
continue;
|
|
6628
|
+
}
|
|
6629
|
+
if (inBrace) {
|
|
6630
|
+
if (i === braceStart + 1) {
|
|
6631
|
+
if (c === "^" || c === "!") {
|
|
6632
|
+
braceNeg = true;
|
|
6633
|
+
}
|
|
6634
|
+
} else if (c === "]" && !(i === braceStart + 2 && braceNeg)) {
|
|
6635
|
+
inBrace = false;
|
|
6636
|
+
}
|
|
6637
|
+
acc += c;
|
|
6638
|
+
continue;
|
|
6639
|
+
} else if (c === "[") {
|
|
6640
|
+
inBrace = true;
|
|
6641
|
+
braceStart = i;
|
|
6642
|
+
braceNeg = false;
|
|
6643
|
+
acc += c;
|
|
6644
|
+
continue;
|
|
6645
|
+
}
|
|
6646
|
+
if (isExtglobType(c) && str.charAt(i) === "(") {
|
|
6647
|
+
part.push(acc);
|
|
6648
|
+
acc = "";
|
|
6649
|
+
const ext = new AST(c, part);
|
|
6650
|
+
part.push(ext);
|
|
6651
|
+
i = AST.#parseAST(str, ext, i, opt);
|
|
6652
|
+
continue;
|
|
6653
|
+
}
|
|
6654
|
+
if (c === "|") {
|
|
6655
|
+
part.push(acc);
|
|
6656
|
+
acc = "";
|
|
6657
|
+
parts.push(part);
|
|
6658
|
+
part = new AST(null, ast);
|
|
6659
|
+
continue;
|
|
6660
|
+
}
|
|
6661
|
+
if (c === ")") {
|
|
6662
|
+
if (acc === "" && ast.#parts.length === 0) {
|
|
6663
|
+
ast.#emptyExt = true;
|
|
6664
|
+
}
|
|
6665
|
+
part.push(acc);
|
|
6666
|
+
acc = "";
|
|
6667
|
+
ast.push(...parts, part);
|
|
6668
|
+
return i;
|
|
6669
|
+
}
|
|
6670
|
+
acc += c;
|
|
6671
|
+
}
|
|
6672
|
+
ast.type = null;
|
|
6673
|
+
ast.#hasMagic = undefined;
|
|
6674
|
+
ast.#parts = [str.substring(pos - 1)];
|
|
6675
|
+
return i;
|
|
6676
|
+
}
|
|
6677
|
+
static fromGlob(pattern, options = {}) {
|
|
6678
|
+
const ast = new AST(null, undefined, options);
|
|
6679
|
+
AST.#parseAST(pattern, ast, 0, options);
|
|
6680
|
+
return ast;
|
|
6681
|
+
}
|
|
6682
|
+
toMMPattern() {
|
|
6683
|
+
if (this !== this.#root)
|
|
6684
|
+
return this.#root.toMMPattern();
|
|
6685
|
+
const glob2 = this.toString();
|
|
6686
|
+
const [re, body, hasMagic, uflag] = this.toRegExpSource();
|
|
6687
|
+
const anyMagic = hasMagic || this.#hasMagic || this.#options.nocase && !this.#options.nocaseMagicOnly && glob2.toUpperCase() !== glob2.toLowerCase();
|
|
6688
|
+
if (!anyMagic) {
|
|
6689
|
+
return body;
|
|
6690
|
+
}
|
|
6691
|
+
const flags = (this.#options.nocase ? "i" : "") + (uflag ? "u" : "");
|
|
6692
|
+
return Object.assign(new RegExp(`^${re}$`, flags), {
|
|
6693
|
+
_src: re,
|
|
6694
|
+
_glob: glob2
|
|
6695
|
+
});
|
|
6696
|
+
}
|
|
6697
|
+
get options() {
|
|
6698
|
+
return this.#options;
|
|
6699
|
+
}
|
|
6700
|
+
toRegExpSource(allowDot) {
|
|
6701
|
+
const dot = allowDot ?? !!this.#options.dot;
|
|
6702
|
+
if (this.#root === this)
|
|
6703
|
+
this.#fillNegs();
|
|
6704
|
+
if (!this.type) {
|
|
6705
|
+
const noEmpty = this.isStart() && this.isEnd();
|
|
6706
|
+
const src = this.#parts.map((p) => {
|
|
6707
|
+
const [re, _, hasMagic, uflag] = typeof p === "string" ? AST.#parseGlob(p, this.#hasMagic, noEmpty) : p.toRegExpSource(allowDot);
|
|
6708
|
+
this.#hasMagic = this.#hasMagic || hasMagic;
|
|
6709
|
+
this.#uflag = this.#uflag || uflag;
|
|
6710
|
+
return re;
|
|
6711
|
+
}).join("");
|
|
6712
|
+
let start2 = "";
|
|
6713
|
+
if (this.isStart()) {
|
|
6714
|
+
if (typeof this.#parts[0] === "string") {
|
|
6715
|
+
const dotTravAllowed = this.#parts.length === 1 && justDots.has(this.#parts[0]);
|
|
6716
|
+
if (!dotTravAllowed) {
|
|
6717
|
+
const aps = addPatternStart;
|
|
6718
|
+
const needNoTrav = dot && aps.has(src.charAt(0)) || src.startsWith("\\.") && aps.has(src.charAt(2)) || src.startsWith("\\.\\.") && aps.has(src.charAt(4));
|
|
6719
|
+
const needNoDot = !dot && !allowDot && aps.has(src.charAt(0));
|
|
6720
|
+
start2 = needNoTrav ? startNoTraversal : needNoDot ? startNoDot : "";
|
|
6721
|
+
}
|
|
6722
|
+
}
|
|
6723
|
+
}
|
|
6724
|
+
let end = "";
|
|
6725
|
+
if (this.isEnd() && this.#root.#filledNegs && this.#parent?.type === "!") {
|
|
6726
|
+
end = "(?:$|\\/)";
|
|
6727
|
+
}
|
|
6728
|
+
const final2 = start2 + src + end;
|
|
6729
|
+
return [
|
|
6730
|
+
final2,
|
|
6731
|
+
unescape(src),
|
|
6732
|
+
this.#hasMagic = !!this.#hasMagic,
|
|
6733
|
+
this.#uflag
|
|
6734
|
+
];
|
|
6735
|
+
}
|
|
6736
|
+
const repeated = this.type === "*" || this.type === "+";
|
|
6737
|
+
const start = this.type === "!" ? "(?:(?!(?:" : "(?:";
|
|
6738
|
+
let body = this.#partsToRegExp(dot);
|
|
6739
|
+
if (this.isStart() && this.isEnd() && !body && this.type !== "!") {
|
|
6740
|
+
const s = this.toString();
|
|
6741
|
+
this.#parts = [s];
|
|
6742
|
+
this.type = null;
|
|
6743
|
+
this.#hasMagic = undefined;
|
|
6744
|
+
return [s, unescape(this.toString()), false, false];
|
|
6745
|
+
}
|
|
6746
|
+
let bodyDotAllowed = !repeated || allowDot || dot || !startNoDot ? "" : this.#partsToRegExp(true);
|
|
6747
|
+
if (bodyDotAllowed === body) {
|
|
6748
|
+
bodyDotAllowed = "";
|
|
6749
|
+
}
|
|
6750
|
+
if (bodyDotAllowed) {
|
|
6751
|
+
body = `(?:${body})(?:${bodyDotAllowed})*?`;
|
|
6752
|
+
}
|
|
6753
|
+
let final = "";
|
|
6754
|
+
if (this.type === "!" && this.#emptyExt) {
|
|
6755
|
+
final = (this.isStart() && !dot ? startNoDot : "") + starNoEmpty;
|
|
6756
|
+
} else {
|
|
6757
|
+
const close = this.type === "!" ? "))" + (this.isStart() && !dot && !allowDot ? startNoDot : "") + star + ")" : this.type === "@" ? ")" : this.type === "?" ? ")?" : this.type === "+" && bodyDotAllowed ? ")" : this.type === "*" && bodyDotAllowed ? `)?` : `)${this.type}`;
|
|
6758
|
+
final = start + body + close;
|
|
6759
|
+
}
|
|
6760
|
+
return [
|
|
6761
|
+
final,
|
|
6762
|
+
unescape(body),
|
|
6763
|
+
this.#hasMagic = !!this.#hasMagic,
|
|
6764
|
+
this.#uflag
|
|
6765
|
+
];
|
|
6766
|
+
}
|
|
6767
|
+
#partsToRegExp(dot) {
|
|
6768
|
+
return this.#parts.map((p) => {
|
|
6769
|
+
if (typeof p === "string") {
|
|
6770
|
+
throw new Error("string type in extglob ast??");
|
|
6771
|
+
}
|
|
6772
|
+
const [re, _, _hasMagic, uflag] = p.toRegExpSource(dot);
|
|
6773
|
+
this.#uflag = this.#uflag || uflag;
|
|
6774
|
+
return re;
|
|
6775
|
+
}).filter((p) => !(this.isStart() && this.isEnd()) || !!p).join("|");
|
|
6776
|
+
}
|
|
6777
|
+
static #parseGlob(glob2, hasMagic, noEmpty = false) {
|
|
6778
|
+
let escaping = false;
|
|
6779
|
+
let re = "";
|
|
6780
|
+
let uflag = false;
|
|
6781
|
+
for (let i = 0;i < glob2.length; i++) {
|
|
6782
|
+
const c = glob2.charAt(i);
|
|
6783
|
+
if (escaping) {
|
|
6784
|
+
escaping = false;
|
|
6785
|
+
re += (reSpecials.has(c) ? "\\" : "") + c;
|
|
6786
|
+
continue;
|
|
6787
|
+
}
|
|
6788
|
+
if (c === "\\") {
|
|
6789
|
+
if (i === glob2.length - 1) {
|
|
6790
|
+
re += "\\\\";
|
|
6791
|
+
} else {
|
|
6792
|
+
escaping = true;
|
|
6793
|
+
}
|
|
6794
|
+
continue;
|
|
6795
|
+
}
|
|
6796
|
+
if (c === "[") {
|
|
6797
|
+
const [src, needUflag, consumed, magic] = parseClass(glob2, i);
|
|
6798
|
+
if (consumed) {
|
|
6799
|
+
re += src;
|
|
6800
|
+
uflag = uflag || needUflag;
|
|
6801
|
+
i += consumed - 1;
|
|
6802
|
+
hasMagic = hasMagic || magic;
|
|
6803
|
+
continue;
|
|
6804
|
+
}
|
|
6805
|
+
}
|
|
6806
|
+
if (c === "*") {
|
|
6807
|
+
if (noEmpty && glob2 === "*")
|
|
6808
|
+
re += starNoEmpty;
|
|
6809
|
+
else
|
|
6810
|
+
re += star;
|
|
6811
|
+
hasMagic = true;
|
|
6812
|
+
continue;
|
|
6813
|
+
}
|
|
6814
|
+
if (c === "?") {
|
|
6815
|
+
re += qmark;
|
|
6816
|
+
hasMagic = true;
|
|
6817
|
+
continue;
|
|
6818
|
+
}
|
|
6819
|
+
re += regExpEscape(c);
|
|
6820
|
+
}
|
|
6821
|
+
return [re, unescape(glob2), !!hasMagic, uflag];
|
|
6822
|
+
}
|
|
6823
|
+
}
|
|
6824
|
+
var types, isExtglobType = (c) => types.has(c), startNoTraversal = "(?!(?:^|/)\\.\\.?(?:$|/))", startNoDot = "(?!\\.)", addPatternStart, justDots, reSpecials, regExpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), qmark = "[^/]", star, starNoEmpty;
|
|
6825
|
+
var init_ast = __esm(() => {
|
|
6826
|
+
init_brace_expressions();
|
|
6827
|
+
types = new Set(["!", "?", "+", "*", "@"]);
|
|
6828
|
+
addPatternStart = new Set(["[", "."]);
|
|
6829
|
+
justDots = new Set(["..", "."]);
|
|
6830
|
+
reSpecials = new Set("().*{}+?[]^$\\!");
|
|
6831
|
+
star = qmark + "*?";
|
|
6832
|
+
starNoEmpty = qmark + "+?";
|
|
6833
|
+
});
|
|
6834
|
+
|
|
6835
|
+
// node_modules/minimatch/dist/esm/escape.js
|
|
6836
|
+
var escape = (s, { windowsPathsNoEscape = false } = {}) => {
|
|
6837
|
+
return windowsPathsNoEscape ? s.replace(/[?*()[\]]/g, "[$&]") : s.replace(/[?*()[\]\\]/g, "\\$&");
|
|
6838
|
+
};
|
|
6839
|
+
|
|
6840
|
+
// node_modules/minimatch/dist/esm/index.js
|
|
6841
|
+
class Minimatch {
|
|
6842
|
+
options;
|
|
6843
|
+
set;
|
|
6844
|
+
pattern;
|
|
6845
|
+
windowsPathsNoEscape;
|
|
6846
|
+
nonegate;
|
|
6847
|
+
negate;
|
|
6848
|
+
comment;
|
|
6849
|
+
empty;
|
|
6850
|
+
preserveMultipleSlashes;
|
|
6851
|
+
partial;
|
|
6852
|
+
globSet;
|
|
6853
|
+
globParts;
|
|
6854
|
+
nocase;
|
|
6855
|
+
isWindows;
|
|
6856
|
+
platform;
|
|
6857
|
+
windowsNoMagicRoot;
|
|
6858
|
+
regexp;
|
|
6859
|
+
constructor(pattern, options = {}) {
|
|
6860
|
+
assertValidPattern(pattern);
|
|
6861
|
+
options = options || {};
|
|
6862
|
+
this.options = options;
|
|
6863
|
+
this.pattern = pattern;
|
|
6864
|
+
this.platform = options.platform || defaultPlatform;
|
|
6865
|
+
this.isWindows = this.platform === "win32";
|
|
6866
|
+
this.windowsPathsNoEscape = !!options.windowsPathsNoEscape || options.allowWindowsEscape === false;
|
|
6867
|
+
if (this.windowsPathsNoEscape) {
|
|
6868
|
+
this.pattern = this.pattern.replace(/\\/g, "/");
|
|
6869
|
+
}
|
|
6870
|
+
this.preserveMultipleSlashes = !!options.preserveMultipleSlashes;
|
|
6871
|
+
this.regexp = null;
|
|
6872
|
+
this.negate = false;
|
|
6873
|
+
this.nonegate = !!options.nonegate;
|
|
6874
|
+
this.comment = false;
|
|
6875
|
+
this.empty = false;
|
|
6876
|
+
this.partial = !!options.partial;
|
|
6877
|
+
this.nocase = !!this.options.nocase;
|
|
6878
|
+
this.windowsNoMagicRoot = options.windowsNoMagicRoot !== undefined ? options.windowsNoMagicRoot : !!(this.isWindows && this.nocase);
|
|
6879
|
+
this.globSet = [];
|
|
6880
|
+
this.globParts = [];
|
|
6881
|
+
this.set = [];
|
|
6882
|
+
this.make();
|
|
6883
|
+
}
|
|
6884
|
+
hasMagic() {
|
|
6885
|
+
if (this.options.magicalBraces && this.set.length > 1) {
|
|
6886
|
+
return true;
|
|
6887
|
+
}
|
|
6888
|
+
for (const pattern of this.set) {
|
|
6889
|
+
for (const part of pattern) {
|
|
6890
|
+
if (typeof part !== "string")
|
|
6891
|
+
return true;
|
|
6892
|
+
}
|
|
6893
|
+
}
|
|
6894
|
+
return false;
|
|
6895
|
+
}
|
|
6896
|
+
debug(..._) {}
|
|
6897
|
+
make() {
|
|
6898
|
+
const pattern = this.pattern;
|
|
6899
|
+
const options = this.options;
|
|
6900
|
+
if (!options.nocomment && pattern.charAt(0) === "#") {
|
|
6901
|
+
this.comment = true;
|
|
6902
|
+
return;
|
|
6903
|
+
}
|
|
6904
|
+
if (!pattern) {
|
|
6905
|
+
this.empty = true;
|
|
6906
|
+
return;
|
|
6907
|
+
}
|
|
6908
|
+
this.parseNegate();
|
|
6909
|
+
this.globSet = [...new Set(this.braceExpand())];
|
|
6910
|
+
if (options.debug) {
|
|
6911
|
+
this.debug = (...args) => console.error(...args);
|
|
6912
|
+
}
|
|
6913
|
+
this.debug(this.pattern, this.globSet);
|
|
6914
|
+
const rawGlobParts = this.globSet.map((s) => this.slashSplit(s));
|
|
6915
|
+
this.globParts = this.preprocess(rawGlobParts);
|
|
6916
|
+
this.debug(this.pattern, this.globParts);
|
|
6917
|
+
let set = this.globParts.map((s, _, __) => {
|
|
6918
|
+
if (this.isWindows && this.windowsNoMagicRoot) {
|
|
6919
|
+
const isUNC = s[0] === "" && s[1] === "" && (s[2] === "?" || !globMagic.test(s[2])) && !globMagic.test(s[3]);
|
|
6920
|
+
const isDrive = /^[a-z]:/i.test(s[0]);
|
|
6921
|
+
if (isUNC) {
|
|
6922
|
+
return [...s.slice(0, 4), ...s.slice(4).map((ss) => this.parse(ss))];
|
|
6923
|
+
} else if (isDrive) {
|
|
6924
|
+
return [s[0], ...s.slice(1).map((ss) => this.parse(ss))];
|
|
6925
|
+
}
|
|
6926
|
+
}
|
|
6927
|
+
return s.map((ss) => this.parse(ss));
|
|
6928
|
+
});
|
|
6929
|
+
this.debug(this.pattern, set);
|
|
6930
|
+
this.set = set.filter((s) => s.indexOf(false) === -1);
|
|
6931
|
+
if (this.isWindows) {
|
|
6932
|
+
for (let i = 0;i < this.set.length; i++) {
|
|
6933
|
+
const p = this.set[i];
|
|
6934
|
+
if (p[0] === "" && p[1] === "" && this.globParts[i][2] === "?" && typeof p[3] === "string" && /^[a-z]:$/i.test(p[3])) {
|
|
6935
|
+
p[2] = "?";
|
|
6936
|
+
}
|
|
6937
|
+
}
|
|
6938
|
+
}
|
|
6939
|
+
this.debug(this.pattern, this.set);
|
|
6940
|
+
}
|
|
6941
|
+
preprocess(globParts) {
|
|
6942
|
+
if (this.options.noglobstar) {
|
|
6943
|
+
for (let i = 0;i < globParts.length; i++) {
|
|
6944
|
+
for (let j = 0;j < globParts[i].length; j++) {
|
|
6945
|
+
if (globParts[i][j] === "**") {
|
|
6946
|
+
globParts[i][j] = "*";
|
|
6947
|
+
}
|
|
6948
|
+
}
|
|
6949
|
+
}
|
|
6950
|
+
}
|
|
6951
|
+
const { optimizationLevel = 1 } = this.options;
|
|
6952
|
+
if (optimizationLevel >= 2) {
|
|
6953
|
+
globParts = this.firstPhasePreProcess(globParts);
|
|
6954
|
+
globParts = this.secondPhasePreProcess(globParts);
|
|
6955
|
+
} else if (optimizationLevel >= 1) {
|
|
6956
|
+
globParts = this.levelOneOptimize(globParts);
|
|
6957
|
+
} else {
|
|
6958
|
+
globParts = this.adjascentGlobstarOptimize(globParts);
|
|
6959
|
+
}
|
|
6960
|
+
return globParts;
|
|
6961
|
+
}
|
|
6962
|
+
adjascentGlobstarOptimize(globParts) {
|
|
6963
|
+
return globParts.map((parts) => {
|
|
6964
|
+
let gs = -1;
|
|
6965
|
+
while ((gs = parts.indexOf("**", gs + 1)) !== -1) {
|
|
6966
|
+
let i = gs;
|
|
6967
|
+
while (parts[i + 1] === "**") {
|
|
6968
|
+
i++;
|
|
6969
|
+
}
|
|
6970
|
+
if (i !== gs) {
|
|
6971
|
+
parts.splice(gs, i - gs);
|
|
6972
|
+
}
|
|
6973
|
+
}
|
|
6974
|
+
return parts;
|
|
6975
|
+
});
|
|
6976
|
+
}
|
|
6977
|
+
levelOneOptimize(globParts) {
|
|
6978
|
+
return globParts.map((parts) => {
|
|
6979
|
+
parts = parts.reduce((set, part) => {
|
|
6980
|
+
const prev = set[set.length - 1];
|
|
6981
|
+
if (part === "**" && prev === "**") {
|
|
6982
|
+
return set;
|
|
6983
|
+
}
|
|
6984
|
+
if (part === "..") {
|
|
6985
|
+
if (prev && prev !== ".." && prev !== "." && prev !== "**") {
|
|
6986
|
+
set.pop();
|
|
6987
|
+
return set;
|
|
6988
|
+
}
|
|
6989
|
+
}
|
|
6990
|
+
set.push(part);
|
|
6991
|
+
return set;
|
|
6992
|
+
}, []);
|
|
6993
|
+
return parts.length === 0 ? [""] : parts;
|
|
6994
|
+
});
|
|
6995
|
+
}
|
|
6996
|
+
levelTwoFileOptimize(parts) {
|
|
6997
|
+
if (!Array.isArray(parts)) {
|
|
6998
|
+
parts = this.slashSplit(parts);
|
|
6999
|
+
}
|
|
7000
|
+
let didSomething = false;
|
|
7001
|
+
do {
|
|
7002
|
+
didSomething = false;
|
|
7003
|
+
if (!this.preserveMultipleSlashes) {
|
|
7004
|
+
for (let i = 1;i < parts.length - 1; i++) {
|
|
7005
|
+
const p = parts[i];
|
|
7006
|
+
if (i === 1 && p === "" && parts[0] === "")
|
|
7007
|
+
continue;
|
|
7008
|
+
if (p === "." || p === "") {
|
|
7009
|
+
didSomething = true;
|
|
7010
|
+
parts.splice(i, 1);
|
|
7011
|
+
i--;
|
|
7012
|
+
}
|
|
7013
|
+
}
|
|
7014
|
+
if (parts[0] === "." && parts.length === 2 && (parts[1] === "." || parts[1] === "")) {
|
|
7015
|
+
didSomething = true;
|
|
7016
|
+
parts.pop();
|
|
7017
|
+
}
|
|
7018
|
+
}
|
|
7019
|
+
let dd = 0;
|
|
7020
|
+
while ((dd = parts.indexOf("..", dd + 1)) !== -1) {
|
|
7021
|
+
const p = parts[dd - 1];
|
|
7022
|
+
if (p && p !== "." && p !== ".." && p !== "**") {
|
|
7023
|
+
didSomething = true;
|
|
7024
|
+
parts.splice(dd - 1, 2);
|
|
7025
|
+
dd -= 2;
|
|
7026
|
+
}
|
|
7027
|
+
}
|
|
7028
|
+
} while (didSomething);
|
|
7029
|
+
return parts.length === 0 ? [""] : parts;
|
|
7030
|
+
}
|
|
7031
|
+
firstPhasePreProcess(globParts) {
|
|
7032
|
+
let didSomething = false;
|
|
7033
|
+
do {
|
|
7034
|
+
didSomething = false;
|
|
7035
|
+
for (let parts of globParts) {
|
|
7036
|
+
let gs = -1;
|
|
7037
|
+
while ((gs = parts.indexOf("**", gs + 1)) !== -1) {
|
|
7038
|
+
let gss = gs;
|
|
7039
|
+
while (parts[gss + 1] === "**") {
|
|
7040
|
+
gss++;
|
|
7041
|
+
}
|
|
7042
|
+
if (gss > gs) {
|
|
7043
|
+
parts.splice(gs + 1, gss - gs);
|
|
7044
|
+
}
|
|
7045
|
+
let next = parts[gs + 1];
|
|
7046
|
+
const p = parts[gs + 2];
|
|
7047
|
+
const p2 = parts[gs + 3];
|
|
7048
|
+
if (next !== "..")
|
|
7049
|
+
continue;
|
|
7050
|
+
if (!p || p === "." || p === ".." || !p2 || p2 === "." || p2 === "..") {
|
|
7051
|
+
continue;
|
|
7052
|
+
}
|
|
7053
|
+
didSomething = true;
|
|
7054
|
+
parts.splice(gs, 1);
|
|
7055
|
+
const other = parts.slice(0);
|
|
7056
|
+
other[gs] = "**";
|
|
7057
|
+
globParts.push(other);
|
|
7058
|
+
gs--;
|
|
7059
|
+
}
|
|
7060
|
+
if (!this.preserveMultipleSlashes) {
|
|
7061
|
+
for (let i = 1;i < parts.length - 1; i++) {
|
|
7062
|
+
const p = parts[i];
|
|
7063
|
+
if (i === 1 && p === "" && parts[0] === "")
|
|
7064
|
+
continue;
|
|
7065
|
+
if (p === "." || p === "") {
|
|
7066
|
+
didSomething = true;
|
|
7067
|
+
parts.splice(i, 1);
|
|
7068
|
+
i--;
|
|
7069
|
+
}
|
|
7070
|
+
}
|
|
7071
|
+
if (parts[0] === "." && parts.length === 2 && (parts[1] === "." || parts[1] === "")) {
|
|
7072
|
+
didSomething = true;
|
|
7073
|
+
parts.pop();
|
|
7074
|
+
}
|
|
7075
|
+
}
|
|
7076
|
+
let dd = 0;
|
|
7077
|
+
while ((dd = parts.indexOf("..", dd + 1)) !== -1) {
|
|
7078
|
+
const p = parts[dd - 1];
|
|
7079
|
+
if (p && p !== "." && p !== ".." && p !== "**") {
|
|
7080
|
+
didSomething = true;
|
|
7081
|
+
const needDot = dd === 1 && parts[dd + 1] === "**";
|
|
7082
|
+
const splin = needDot ? ["."] : [];
|
|
7083
|
+
parts.splice(dd - 1, 2, ...splin);
|
|
7084
|
+
if (parts.length === 0)
|
|
7085
|
+
parts.push("");
|
|
7086
|
+
dd -= 2;
|
|
7087
|
+
}
|
|
7088
|
+
}
|
|
7089
|
+
}
|
|
7090
|
+
} while (didSomething);
|
|
7091
|
+
return globParts;
|
|
7092
|
+
}
|
|
7093
|
+
secondPhasePreProcess(globParts) {
|
|
7094
|
+
for (let i = 0;i < globParts.length - 1; i++) {
|
|
7095
|
+
for (let j = i + 1;j < globParts.length; j++) {
|
|
7096
|
+
const matched = this.partsMatch(globParts[i], globParts[j], !this.preserveMultipleSlashes);
|
|
7097
|
+
if (matched) {
|
|
7098
|
+
globParts[i] = [];
|
|
7099
|
+
globParts[j] = matched;
|
|
7100
|
+
break;
|
|
7101
|
+
}
|
|
7102
|
+
}
|
|
7103
|
+
}
|
|
7104
|
+
return globParts.filter((gs) => gs.length);
|
|
7105
|
+
}
|
|
7106
|
+
partsMatch(a, b, emptyGSMatch = false) {
|
|
7107
|
+
let ai = 0;
|
|
7108
|
+
let bi = 0;
|
|
7109
|
+
let result = [];
|
|
7110
|
+
let which = "";
|
|
7111
|
+
while (ai < a.length && bi < b.length) {
|
|
7112
|
+
if (a[ai] === b[bi]) {
|
|
7113
|
+
result.push(which === "b" ? b[bi] : a[ai]);
|
|
7114
|
+
ai++;
|
|
7115
|
+
bi++;
|
|
7116
|
+
} else if (emptyGSMatch && a[ai] === "**" && b[bi] === a[ai + 1]) {
|
|
7117
|
+
result.push(a[ai]);
|
|
7118
|
+
ai++;
|
|
7119
|
+
} else if (emptyGSMatch && b[bi] === "**" && a[ai] === b[bi + 1]) {
|
|
7120
|
+
result.push(b[bi]);
|
|
7121
|
+
bi++;
|
|
7122
|
+
} else if (a[ai] === "*" && b[bi] && (this.options.dot || !b[bi].startsWith(".")) && b[bi] !== "**") {
|
|
7123
|
+
if (which === "b")
|
|
7124
|
+
return false;
|
|
7125
|
+
which = "a";
|
|
7126
|
+
result.push(a[ai]);
|
|
7127
|
+
ai++;
|
|
7128
|
+
bi++;
|
|
7129
|
+
} else if (b[bi] === "*" && a[ai] && (this.options.dot || !a[ai].startsWith(".")) && a[ai] !== "**") {
|
|
7130
|
+
if (which === "a")
|
|
7131
|
+
return false;
|
|
7132
|
+
which = "b";
|
|
7133
|
+
result.push(b[bi]);
|
|
7134
|
+
ai++;
|
|
7135
|
+
bi++;
|
|
7136
|
+
} else {
|
|
7137
|
+
return false;
|
|
7138
|
+
}
|
|
7139
|
+
}
|
|
7140
|
+
return a.length === b.length && result;
|
|
7141
|
+
}
|
|
7142
|
+
parseNegate() {
|
|
7143
|
+
if (this.nonegate)
|
|
7144
|
+
return;
|
|
7145
|
+
const pattern = this.pattern;
|
|
7146
|
+
let negate = false;
|
|
7147
|
+
let negateOffset = 0;
|
|
7148
|
+
for (let i = 0;i < pattern.length && pattern.charAt(i) === "!"; i++) {
|
|
7149
|
+
negate = !negate;
|
|
7150
|
+
negateOffset++;
|
|
7151
|
+
}
|
|
7152
|
+
if (negateOffset)
|
|
7153
|
+
this.pattern = pattern.slice(negateOffset);
|
|
7154
|
+
this.negate = negate;
|
|
7155
|
+
}
|
|
7156
|
+
matchOne(file, pattern, partial = false) {
|
|
7157
|
+
const options = this.options;
|
|
7158
|
+
if (this.isWindows) {
|
|
7159
|
+
const fileDrive = typeof file[0] === "string" && /^[a-z]:$/i.test(file[0]);
|
|
7160
|
+
const fileUNC = !fileDrive && file[0] === "" && file[1] === "" && file[2] === "?" && /^[a-z]:$/i.test(file[3]);
|
|
7161
|
+
const patternDrive = typeof pattern[0] === "string" && /^[a-z]:$/i.test(pattern[0]);
|
|
7162
|
+
const patternUNC = !patternDrive && pattern[0] === "" && pattern[1] === "" && pattern[2] === "?" && typeof pattern[3] === "string" && /^[a-z]:$/i.test(pattern[3]);
|
|
7163
|
+
const fdi = fileUNC ? 3 : fileDrive ? 0 : undefined;
|
|
7164
|
+
const pdi = patternUNC ? 3 : patternDrive ? 0 : undefined;
|
|
7165
|
+
if (typeof fdi === "number" && typeof pdi === "number") {
|
|
7166
|
+
const [fd, pd] = [file[fdi], pattern[pdi]];
|
|
7167
|
+
if (fd.toLowerCase() === pd.toLowerCase()) {
|
|
7168
|
+
pattern[pdi] = fd;
|
|
7169
|
+
if (pdi > fdi) {
|
|
7170
|
+
pattern = pattern.slice(pdi);
|
|
7171
|
+
} else if (fdi > pdi) {
|
|
7172
|
+
file = file.slice(fdi);
|
|
7173
|
+
}
|
|
7174
|
+
}
|
|
7175
|
+
}
|
|
7176
|
+
}
|
|
7177
|
+
const { optimizationLevel = 1 } = this.options;
|
|
7178
|
+
if (optimizationLevel >= 2) {
|
|
7179
|
+
file = this.levelTwoFileOptimize(file);
|
|
7180
|
+
}
|
|
7181
|
+
this.debug("matchOne", this, { file, pattern });
|
|
7182
|
+
this.debug("matchOne", file.length, pattern.length);
|
|
7183
|
+
for (var fi = 0, pi = 0, fl = file.length, pl = pattern.length;fi < fl && pi < pl; fi++, pi++) {
|
|
7184
|
+
this.debug("matchOne loop");
|
|
7185
|
+
var p = pattern[pi];
|
|
7186
|
+
var f = file[fi];
|
|
7187
|
+
this.debug(pattern, p, f);
|
|
7188
|
+
if (p === false) {
|
|
7189
|
+
return false;
|
|
7190
|
+
}
|
|
7191
|
+
if (p === GLOBSTAR) {
|
|
7192
|
+
this.debug("GLOBSTAR", [pattern, p, f]);
|
|
7193
|
+
var fr = fi;
|
|
7194
|
+
var pr = pi + 1;
|
|
7195
|
+
if (pr === pl) {
|
|
7196
|
+
this.debug("** at the end");
|
|
7197
|
+
for (;fi < fl; fi++) {
|
|
7198
|
+
if (file[fi] === "." || file[fi] === ".." || !options.dot && file[fi].charAt(0) === ".")
|
|
7199
|
+
return false;
|
|
7200
|
+
}
|
|
7201
|
+
return true;
|
|
7202
|
+
}
|
|
7203
|
+
while (fr < fl) {
|
|
7204
|
+
var swallowee = file[fr];
|
|
7205
|
+
this.debug(`
|
|
7206
|
+
globstar while`, file, fr, pattern, pr, swallowee);
|
|
7207
|
+
if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
|
|
7208
|
+
this.debug("globstar found match!", fr, fl, swallowee);
|
|
7209
|
+
return true;
|
|
7210
|
+
} else {
|
|
7211
|
+
if (swallowee === "." || swallowee === ".." || !options.dot && swallowee.charAt(0) === ".") {
|
|
7212
|
+
this.debug("dot detected!", file, fr, pattern, pr);
|
|
7213
|
+
break;
|
|
7214
|
+
}
|
|
7215
|
+
this.debug("globstar swallow a segment, and continue");
|
|
7216
|
+
fr++;
|
|
7217
|
+
}
|
|
7218
|
+
}
|
|
7219
|
+
if (partial) {
|
|
7220
|
+
this.debug(`
|
|
7221
|
+
>>> no match, partial?`, file, fr, pattern, pr);
|
|
7222
|
+
if (fr === fl) {
|
|
7223
|
+
return true;
|
|
7224
|
+
}
|
|
7225
|
+
}
|
|
7226
|
+
return false;
|
|
7227
|
+
}
|
|
7228
|
+
let hit;
|
|
7229
|
+
if (typeof p === "string") {
|
|
7230
|
+
hit = f === p;
|
|
7231
|
+
this.debug("string match", p, f, hit);
|
|
7232
|
+
} else {
|
|
7233
|
+
hit = p.test(f);
|
|
7234
|
+
this.debug("pattern match", p, f, hit);
|
|
7235
|
+
}
|
|
7236
|
+
if (!hit)
|
|
7237
|
+
return false;
|
|
7238
|
+
}
|
|
7239
|
+
if (fi === fl && pi === pl) {
|
|
7240
|
+
return true;
|
|
7241
|
+
} else if (fi === fl) {
|
|
7242
|
+
return partial;
|
|
7243
|
+
} else if (pi === pl) {
|
|
7244
|
+
return fi === fl - 1 && file[fi] === "";
|
|
7245
|
+
} else {
|
|
7246
|
+
throw new Error("wtf?");
|
|
7247
|
+
}
|
|
7248
|
+
}
|
|
7249
|
+
braceExpand() {
|
|
7250
|
+
return braceExpand(this.pattern, this.options);
|
|
7251
|
+
}
|
|
7252
|
+
parse(pattern) {
|
|
7253
|
+
assertValidPattern(pattern);
|
|
7254
|
+
const options = this.options;
|
|
7255
|
+
if (pattern === "**")
|
|
7256
|
+
return GLOBSTAR;
|
|
7257
|
+
if (pattern === "")
|
|
7258
|
+
return "";
|
|
7259
|
+
let m;
|
|
7260
|
+
let fastTest = null;
|
|
7261
|
+
if (m = pattern.match(starRE)) {
|
|
7262
|
+
fastTest = options.dot ? starTestDot : starTest;
|
|
7263
|
+
} else if (m = pattern.match(starDotExtRE)) {
|
|
7264
|
+
fastTest = (options.nocase ? options.dot ? starDotExtTestNocaseDot : starDotExtTestNocase : options.dot ? starDotExtTestDot : starDotExtTest)(m[1]);
|
|
7265
|
+
} else if (m = pattern.match(qmarksRE)) {
|
|
7266
|
+
fastTest = (options.nocase ? options.dot ? qmarksTestNocaseDot : qmarksTestNocase : options.dot ? qmarksTestDot : qmarksTest)(m);
|
|
7267
|
+
} else if (m = pattern.match(starDotStarRE)) {
|
|
7268
|
+
fastTest = options.dot ? starDotStarTestDot : starDotStarTest;
|
|
7269
|
+
} else if (m = pattern.match(dotStarRE)) {
|
|
7270
|
+
fastTest = dotStarTest;
|
|
7271
|
+
}
|
|
7272
|
+
const re = AST.fromGlob(pattern, this.options).toMMPattern();
|
|
7273
|
+
if (fastTest && typeof re === "object") {
|
|
7274
|
+
Reflect.defineProperty(re, "test", { value: fastTest });
|
|
7275
|
+
}
|
|
7276
|
+
return re;
|
|
7277
|
+
}
|
|
7278
|
+
makeRe() {
|
|
7279
|
+
if (this.regexp || this.regexp === false)
|
|
7280
|
+
return this.regexp;
|
|
7281
|
+
const set = this.set;
|
|
7282
|
+
if (!set.length) {
|
|
7283
|
+
this.regexp = false;
|
|
7284
|
+
return this.regexp;
|
|
7285
|
+
}
|
|
7286
|
+
const options = this.options;
|
|
7287
|
+
const twoStar = options.noglobstar ? star2 : options.dot ? twoStarDot : twoStarNoDot;
|
|
7288
|
+
const flags = new Set(options.nocase ? ["i"] : []);
|
|
7289
|
+
let re = set.map((pattern) => {
|
|
7290
|
+
const pp = pattern.map((p) => {
|
|
7291
|
+
if (p instanceof RegExp) {
|
|
7292
|
+
for (const f of p.flags.split(""))
|
|
7293
|
+
flags.add(f);
|
|
7294
|
+
}
|
|
7295
|
+
return typeof p === "string" ? regExpEscape2(p) : p === GLOBSTAR ? GLOBSTAR : p._src;
|
|
7296
|
+
});
|
|
7297
|
+
pp.forEach((p, i) => {
|
|
7298
|
+
const next = pp[i + 1];
|
|
7299
|
+
const prev = pp[i - 1];
|
|
7300
|
+
if (p !== GLOBSTAR || prev === GLOBSTAR) {
|
|
7301
|
+
return;
|
|
7302
|
+
}
|
|
7303
|
+
if (prev === undefined) {
|
|
7304
|
+
if (next !== undefined && next !== GLOBSTAR) {
|
|
7305
|
+
pp[i + 1] = "(?:\\/|" + twoStar + "\\/)?" + next;
|
|
7306
|
+
} else {
|
|
7307
|
+
pp[i] = twoStar;
|
|
7308
|
+
}
|
|
7309
|
+
} else if (next === undefined) {
|
|
7310
|
+
pp[i - 1] = prev + "(?:\\/|" + twoStar + ")?";
|
|
7311
|
+
} else if (next !== GLOBSTAR) {
|
|
7312
|
+
pp[i - 1] = prev + "(?:\\/|\\/" + twoStar + "\\/)" + next;
|
|
7313
|
+
pp[i + 1] = GLOBSTAR;
|
|
7314
|
+
}
|
|
7315
|
+
});
|
|
7316
|
+
return pp.filter((p) => p !== GLOBSTAR).join("/");
|
|
7317
|
+
}).join("|");
|
|
7318
|
+
const [open, close] = set.length > 1 ? ["(?:", ")"] : ["", ""];
|
|
7319
|
+
re = "^" + open + re + close + "$";
|
|
7320
|
+
if (this.negate)
|
|
7321
|
+
re = "^(?!" + re + ").+$";
|
|
7322
|
+
try {
|
|
7323
|
+
this.regexp = new RegExp(re, [...flags].join(""));
|
|
7324
|
+
} catch (ex) {
|
|
7325
|
+
this.regexp = false;
|
|
7326
|
+
}
|
|
7327
|
+
return this.regexp;
|
|
7328
|
+
}
|
|
7329
|
+
slashSplit(p) {
|
|
7330
|
+
if (this.preserveMultipleSlashes) {
|
|
7331
|
+
return p.split("/");
|
|
7332
|
+
} else if (this.isWindows && /^\/\/[^\/]+/.test(p)) {
|
|
7333
|
+
return ["", ...p.split(/\/+/)];
|
|
7334
|
+
} else {
|
|
7335
|
+
return p.split(/\/+/);
|
|
7336
|
+
}
|
|
7337
|
+
}
|
|
7338
|
+
match(f, partial = this.partial) {
|
|
7339
|
+
this.debug("match", f, this.pattern);
|
|
7340
|
+
if (this.comment) {
|
|
7341
|
+
return false;
|
|
7342
|
+
}
|
|
7343
|
+
if (this.empty) {
|
|
7344
|
+
return f === "";
|
|
7345
|
+
}
|
|
7346
|
+
if (f === "/" && partial) {
|
|
7347
|
+
return true;
|
|
7348
|
+
}
|
|
7349
|
+
const options = this.options;
|
|
7350
|
+
if (this.isWindows) {
|
|
7351
|
+
f = f.split("\\").join("/");
|
|
7352
|
+
}
|
|
7353
|
+
const ff = this.slashSplit(f);
|
|
7354
|
+
this.debug(this.pattern, "split", ff);
|
|
7355
|
+
const set = this.set;
|
|
7356
|
+
this.debug(this.pattern, "set", set);
|
|
7357
|
+
let filename = ff[ff.length - 1];
|
|
7358
|
+
if (!filename) {
|
|
7359
|
+
for (let i = ff.length - 2;!filename && i >= 0; i--) {
|
|
7360
|
+
filename = ff[i];
|
|
7361
|
+
}
|
|
7362
|
+
}
|
|
7363
|
+
for (let i = 0;i < set.length; i++) {
|
|
7364
|
+
const pattern = set[i];
|
|
7365
|
+
let file = ff;
|
|
7366
|
+
if (options.matchBase && pattern.length === 1) {
|
|
7367
|
+
file = [filename];
|
|
7368
|
+
}
|
|
7369
|
+
const hit = this.matchOne(file, pattern, partial);
|
|
7370
|
+
if (hit) {
|
|
7371
|
+
if (options.flipNegate) {
|
|
7372
|
+
return true;
|
|
7373
|
+
}
|
|
7374
|
+
return !this.negate;
|
|
7375
|
+
}
|
|
7376
|
+
}
|
|
7377
|
+
if (options.flipNegate) {
|
|
7378
|
+
return false;
|
|
7379
|
+
}
|
|
7380
|
+
return this.negate;
|
|
7381
|
+
}
|
|
7382
|
+
static defaults(def) {
|
|
7383
|
+
return minimatch.defaults(def).Minimatch;
|
|
7384
|
+
}
|
|
7385
|
+
}
|
|
7386
|
+
var import_brace_expansion, minimatch = (p, pattern, options = {}) => {
|
|
7387
|
+
assertValidPattern(pattern);
|
|
7388
|
+
if (!options.nocomment && pattern.charAt(0) === "#") {
|
|
7389
|
+
return false;
|
|
7390
|
+
}
|
|
7391
|
+
return new Minimatch(pattern, options).match(p);
|
|
7392
|
+
}, starDotExtRE, starDotExtTest = (ext) => (f) => !f.startsWith(".") && f.endsWith(ext), starDotExtTestDot = (ext) => (f) => f.endsWith(ext), starDotExtTestNocase = (ext) => {
|
|
7393
|
+
ext = ext.toLowerCase();
|
|
7394
|
+
return (f) => !f.startsWith(".") && f.toLowerCase().endsWith(ext);
|
|
7395
|
+
}, starDotExtTestNocaseDot = (ext) => {
|
|
7396
|
+
ext = ext.toLowerCase();
|
|
7397
|
+
return (f) => f.toLowerCase().endsWith(ext);
|
|
7398
|
+
}, starDotStarRE, starDotStarTest = (f) => !f.startsWith(".") && f.includes("."), starDotStarTestDot = (f) => f !== "." && f !== ".." && f.includes("."), dotStarRE, dotStarTest = (f) => f !== "." && f !== ".." && f.startsWith("."), starRE, starTest = (f) => f.length !== 0 && !f.startsWith("."), starTestDot = (f) => f.length !== 0 && f !== "." && f !== "..", qmarksRE, qmarksTestNocase = ([$0, ext = ""]) => {
|
|
7399
|
+
const noext = qmarksTestNoExt([$0]);
|
|
7400
|
+
if (!ext)
|
|
7401
|
+
return noext;
|
|
7402
|
+
ext = ext.toLowerCase();
|
|
7403
|
+
return (f) => noext(f) && f.toLowerCase().endsWith(ext);
|
|
7404
|
+
}, qmarksTestNocaseDot = ([$0, ext = ""]) => {
|
|
7405
|
+
const noext = qmarksTestNoExtDot([$0]);
|
|
7406
|
+
if (!ext)
|
|
7407
|
+
return noext;
|
|
7408
|
+
ext = ext.toLowerCase();
|
|
7409
|
+
return (f) => noext(f) && f.toLowerCase().endsWith(ext);
|
|
7410
|
+
}, qmarksTestDot = ([$0, ext = ""]) => {
|
|
7411
|
+
const noext = qmarksTestNoExtDot([$0]);
|
|
7412
|
+
return !ext ? noext : (f) => noext(f) && f.endsWith(ext);
|
|
7413
|
+
}, qmarksTest = ([$0, ext = ""]) => {
|
|
7414
|
+
const noext = qmarksTestNoExt([$0]);
|
|
7415
|
+
return !ext ? noext : (f) => noext(f) && f.endsWith(ext);
|
|
7416
|
+
}, qmarksTestNoExt = ([$0]) => {
|
|
7417
|
+
const len = $0.length;
|
|
7418
|
+
return (f) => f.length === len && !f.startsWith(".");
|
|
7419
|
+
}, qmarksTestNoExtDot = ([$0]) => {
|
|
7420
|
+
const len = $0.length;
|
|
7421
|
+
return (f) => f.length === len && f !== "." && f !== "..";
|
|
7422
|
+
}, defaultPlatform, path17, sep, GLOBSTAR, qmark2 = "[^/]", star2, twoStarDot = "(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?", twoStarNoDot = "(?:(?!(?:\\/|^)\\.).)*?", filter = (pattern, options = {}) => (p) => minimatch(p, pattern, options), ext = (a, b = {}) => Object.assign({}, a, b), defaults = (def) => {
|
|
7423
|
+
if (!def || typeof def !== "object" || !Object.keys(def).length) {
|
|
7424
|
+
return minimatch;
|
|
7425
|
+
}
|
|
7426
|
+
const orig = minimatch;
|
|
7427
|
+
const m = (p, pattern, options = {}) => orig(p, pattern, ext(def, options));
|
|
7428
|
+
return Object.assign(m, {
|
|
7429
|
+
Minimatch: class Minimatch extends orig.Minimatch {
|
|
7430
|
+
constructor(pattern, options = {}) {
|
|
7431
|
+
super(pattern, ext(def, options));
|
|
7432
|
+
}
|
|
7433
|
+
static defaults(options) {
|
|
7434
|
+
return orig.defaults(ext(def, options)).Minimatch;
|
|
7435
|
+
}
|
|
7436
|
+
},
|
|
7437
|
+
AST: class AST2 extends orig.AST {
|
|
7438
|
+
constructor(type, parent, options = {}) {
|
|
7439
|
+
super(type, parent, ext(def, options));
|
|
7440
|
+
}
|
|
7441
|
+
static fromGlob(pattern, options = {}) {
|
|
7442
|
+
return orig.AST.fromGlob(pattern, ext(def, options));
|
|
7443
|
+
}
|
|
7444
|
+
},
|
|
7445
|
+
unescape: (s, options = {}) => orig.unescape(s, ext(def, options)),
|
|
7446
|
+
escape: (s, options = {}) => orig.escape(s, ext(def, options)),
|
|
7447
|
+
filter: (pattern, options = {}) => orig.filter(pattern, ext(def, options)),
|
|
7448
|
+
defaults: (options) => orig.defaults(ext(def, options)),
|
|
7449
|
+
makeRe: (pattern, options = {}) => orig.makeRe(pattern, ext(def, options)),
|
|
7450
|
+
braceExpand: (pattern, options = {}) => orig.braceExpand(pattern, ext(def, options)),
|
|
7451
|
+
match: (list, pattern, options = {}) => orig.match(list, pattern, ext(def, options)),
|
|
7452
|
+
sep: orig.sep,
|
|
7453
|
+
GLOBSTAR
|
|
7454
|
+
});
|
|
7455
|
+
}, braceExpand = (pattern, options = {}) => {
|
|
7456
|
+
assertValidPattern(pattern);
|
|
7457
|
+
if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) {
|
|
7458
|
+
return [pattern];
|
|
7459
|
+
}
|
|
7460
|
+
return import_brace_expansion.default(pattern);
|
|
7461
|
+
}, makeRe = (pattern, options = {}) => new Minimatch(pattern, options).makeRe(), match = (list, pattern, options = {}) => {
|
|
7462
|
+
const mm = new Minimatch(pattern, options);
|
|
7463
|
+
list = list.filter((f) => mm.match(f));
|
|
7464
|
+
if (mm.options.nonull && !list.length) {
|
|
7465
|
+
list.push(pattern);
|
|
7466
|
+
}
|
|
7467
|
+
return list;
|
|
7468
|
+
}, globMagic, regExpEscape2 = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
7469
|
+
var init_esm = __esm(() => {
|
|
7470
|
+
init_assert_valid_pattern();
|
|
7471
|
+
init_ast();
|
|
7472
|
+
init_ast();
|
|
7473
|
+
import_brace_expansion = __toESM(require_brace_expansion(), 1);
|
|
7474
|
+
starDotExtRE = /^\*+([^+@!?\*\[\(]*)$/;
|
|
7475
|
+
starDotStarRE = /^\*+\.\*+$/;
|
|
7476
|
+
dotStarRE = /^\.\*+$/;
|
|
7477
|
+
starRE = /^\*+$/;
|
|
7478
|
+
qmarksRE = /^\?+([^+@!?\*\[\(]*)?$/;
|
|
7479
|
+
defaultPlatform = typeof process === "object" && process ? typeof process.env === "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix";
|
|
7480
|
+
path17 = {
|
|
7481
|
+
win32: { sep: "\\" },
|
|
7482
|
+
posix: { sep: "/" }
|
|
7483
|
+
};
|
|
7484
|
+
sep = defaultPlatform === "win32" ? path17.win32.sep : path17.posix.sep;
|
|
7485
|
+
minimatch.sep = sep;
|
|
7486
|
+
GLOBSTAR = Symbol("globstar **");
|
|
7487
|
+
minimatch.GLOBSTAR = GLOBSTAR;
|
|
7488
|
+
star2 = qmark2 + "*?";
|
|
7489
|
+
minimatch.filter = filter;
|
|
7490
|
+
minimatch.defaults = defaults;
|
|
7491
|
+
minimatch.braceExpand = braceExpand;
|
|
7492
|
+
minimatch.makeRe = makeRe;
|
|
7493
|
+
minimatch.match = match;
|
|
7494
|
+
globMagic = /[?*]|[+@!]\(.*?\)|\[|\]/;
|
|
7495
|
+
minimatch.AST = AST;
|
|
7496
|
+
minimatch.Minimatch = Minimatch;
|
|
7497
|
+
minimatch.escape = escape;
|
|
7498
|
+
minimatch.unescape = unescape;
|
|
7499
|
+
});
|
|
7500
|
+
|
|
6076
7501
|
// src/types.ts
|
|
6077
7502
|
var init_types = __esm(() => {
|
|
6078
7503
|
init_entities();
|
|
@@ -6085,9 +7510,9 @@ __export(exports_search, {
|
|
|
6085
7510
|
formatSearchResults: () => formatSearchResults
|
|
6086
7511
|
});
|
|
6087
7512
|
import * as fs8 from "fs/promises";
|
|
6088
|
-
import * as
|
|
7513
|
+
import * as path18 from "path";
|
|
6089
7514
|
async function search(rootDir, query, options = {}) {
|
|
6090
|
-
rootDir =
|
|
7515
|
+
rootDir = path18.resolve(rootDir);
|
|
6091
7516
|
const ensureFresh = options.ensureFresh ?? DEFAULT_SEARCH_OPTIONS.ensureFresh;
|
|
6092
7517
|
if (ensureFresh) {
|
|
6093
7518
|
await ensureIndexFresh(rootDir, { quiet: true });
|
|
@@ -6126,7 +7551,15 @@ async function search(rootDir, query, options = {}) {
|
|
|
6126
7551
|
const normalizedFilters = options.pathFilter.map((p) => p.replace(/\\/g, "/").replace(/^\//, "").replace(/\/$/, ""));
|
|
6127
7552
|
filteredResults = allResults.filter((result) => {
|
|
6128
7553
|
const normalizedPath = result.filepath.replace(/\\/g, "/");
|
|
6129
|
-
return normalizedFilters.some((
|
|
7554
|
+
return normalizedFilters.some((filter2) => {
|
|
7555
|
+
const isGlobPattern = /[*?[\]{}!]/.test(filter2);
|
|
7556
|
+
if (isGlobPattern) {
|
|
7557
|
+
const pattern = filter2.startsWith("**/") ? filter2 : `**/${filter2}`;
|
|
7558
|
+
return minimatch(normalizedPath, pattern, { matchBase: true });
|
|
7559
|
+
} else {
|
|
7560
|
+
return normalizedPath.startsWith(filter2 + "/") || normalizedPath === filter2 || normalizedPath.startsWith("./" + filter2 + "/") || normalizedPath === "./" + filter2;
|
|
7561
|
+
}
|
|
7562
|
+
});
|
|
6130
7563
|
});
|
|
6131
7564
|
}
|
|
6132
7565
|
filteredResults.sort((a, b) => b.score - a.score);
|
|
@@ -6140,7 +7573,7 @@ function createSearchContext(rootDir, moduleId, config) {
|
|
|
6140
7573
|
config,
|
|
6141
7574
|
loadFileIndex: async (filepath) => {
|
|
6142
7575
|
const hasExtension = /\.[^./]+$/.test(filepath);
|
|
6143
|
-
const indexFilePath = hasExtension ?
|
|
7576
|
+
const indexFilePath = hasExtension ? path18.join(indexPath, filepath.replace(/\.[^.]+$/, ".json")) : path18.join(indexPath, filepath + ".json");
|
|
6144
7577
|
try {
|
|
6145
7578
|
const content = await fs8.readFile(indexFilePath, "utf-8");
|
|
6146
7579
|
return JSON.parse(content);
|
|
@@ -6152,7 +7585,7 @@ function createSearchContext(rootDir, moduleId, config) {
|
|
|
6152
7585
|
const files = [];
|
|
6153
7586
|
await traverseDirectory(indexPath, files, indexPath);
|
|
6154
7587
|
return files.filter((f) => f.endsWith(".json") && !f.endsWith("manifest.json")).map((f) => {
|
|
6155
|
-
const relative4 =
|
|
7588
|
+
const relative4 = path18.relative(indexPath, f);
|
|
6156
7589
|
return relative4.replace(/\.json$/, "");
|
|
6157
7590
|
});
|
|
6158
7591
|
}
|
|
@@ -6162,7 +7595,7 @@ async function traverseDirectory(dir, files, basePath) {
|
|
|
6162
7595
|
try {
|
|
6163
7596
|
const entries = await fs8.readdir(dir, { withFileTypes: true });
|
|
6164
7597
|
for (const entry of entries) {
|
|
6165
|
-
const fullPath =
|
|
7598
|
+
const fullPath = path18.join(dir, entry.name);
|
|
6166
7599
|
if (entry.isDirectory()) {
|
|
6167
7600
|
await traverseDirectory(fullPath, files, basePath);
|
|
6168
7601
|
} else if (entry.isFile()) {
|
|
@@ -6228,6 +7661,7 @@ function formatSearchResults(results) {
|
|
|
6228
7661
|
return output;
|
|
6229
7662
|
}
|
|
6230
7663
|
var init_search = __esm(() => {
|
|
7664
|
+
init_esm();
|
|
6231
7665
|
init_types();
|
|
6232
7666
|
init_config2();
|
|
6233
7667
|
init_registry();
|
|
@@ -6240,7 +7674,7 @@ init_logger();
|
|
|
6240
7674
|
// package.json
|
|
6241
7675
|
var package_default = {
|
|
6242
7676
|
name: "raggrep",
|
|
6243
|
-
version: "0.8.
|
|
7677
|
+
version: "0.8.2",
|
|
6244
7678
|
description: "Local filesystem-based RAG system for codebases - semantic search using local embeddings",
|
|
6245
7679
|
type: "module",
|
|
6246
7680
|
main: "./dist/index.js",
|
|
@@ -6392,7 +7826,7 @@ function parseFlags(args2) {
|
|
|
6392
7826
|
}
|
|
6393
7827
|
flags.pathFilter.push(filterPath);
|
|
6394
7828
|
} else {
|
|
6395
|
-
console.error(
|
|
7829
|
+
console.error('--filter requires a path or glob pattern (e.g., src/auth, "*.ts")');
|
|
6396
7830
|
process.exit(1);
|
|
6397
7831
|
}
|
|
6398
7832
|
} else if (!arg.startsWith("-")) {
|
|
@@ -6503,7 +7937,7 @@ Options:
|
|
|
6503
7937
|
-k, --top <n> Number of results to return (default: 10)
|
|
6504
7938
|
-s, --min-score <n> Minimum similarity score 0-1 (default: 0.15)
|
|
6505
7939
|
-t, --type <ext> Filter by file extension (e.g., ts, tsx, js)
|
|
6506
|
-
-f, --filter <path> Filter by path
|
|
7940
|
+
-f, --filter <path> Filter by path or glob pattern (can be used multiple times)
|
|
6507
7941
|
-h, --help Show this help message
|
|
6508
7942
|
|
|
6509
7943
|
Note:
|
|
@@ -6513,6 +7947,12 @@ Note:
|
|
|
6513
7947
|
- Deleted files are cleaned up automatically
|
|
6514
7948
|
- Unchanged files use the cached index (instant)
|
|
6515
7949
|
|
|
7950
|
+
Filter Patterns:
|
|
7951
|
+
Path prefix: --filter src/auth (matches src/auth/*)
|
|
7952
|
+
Glob pattern: --filter "*.ts" (matches all .ts files)
|
|
7953
|
+
Glob pattern: --filter "*.md" (matches all .md files)
|
|
7954
|
+
Glob pattern: --filter "src/**/*.test.ts" (matches test files in src/)
|
|
7955
|
+
|
|
6516
7956
|
Examples:
|
|
6517
7957
|
raggrep query "user authentication"
|
|
6518
7958
|
raggrep query "handle errors" --top 5
|
|
@@ -6520,6 +7960,16 @@ Examples:
|
|
|
6520
7960
|
raggrep query "interface" --type ts
|
|
6521
7961
|
raggrep query "login" --filter src/auth
|
|
6522
7962
|
raggrep query "api" --filter src/api --filter src/routes
|
|
7963
|
+
|
|
7964
|
+
# Search only source code files
|
|
7965
|
+
raggrep query "service controller" --filter "*.ts"
|
|
7966
|
+
raggrep query "component state" --filter "*.tsx"
|
|
7967
|
+
|
|
7968
|
+
# Search only documentation
|
|
7969
|
+
raggrep query "deployment workflow" --filter "*.md"
|
|
7970
|
+
|
|
7971
|
+
# Search specific patterns
|
|
7972
|
+
raggrep query "test helpers" --filter "*.test.ts"
|
|
6523
7973
|
`);
|
|
6524
7974
|
process.exit(0);
|
|
6525
7975
|
}
|
|
@@ -6701,4 +8151,4 @@ Run 'raggrep <command> --help' for more information.
|
|
|
6701
8151
|
}
|
|
6702
8152
|
main();
|
|
6703
8153
|
|
|
6704
|
-
//# debugId=
|
|
8154
|
+
//# debugId=A1D76ED5E6F86EB564756E2164756E21
|