@hubblecommerce/overmind-core 0.1.6 → 0.1.7
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repomix-search.d.ts","sourceRoot":"","sources":["../../../src/utils/repomix-search.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,UAAU,WAAW;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"repomix-search.d.ts","sourceRoot":"","sources":["../../../src/utils/repomix-search.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,UAAU,WAAW;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,UAAU,YAAY;IAClB,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,eAAe,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,UAAU,aAAa;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB;AAmGD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,YAAY,CASjG;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQ3E"}
|
|
@@ -13,8 +13,26 @@ function createRegexPattern(pattern, ignoreCase) {
|
|
|
13
13
|
throw new Error(`Invalid regular expression pattern: ${pattern}. ${error instanceof Error ? error.message : String(error)}`);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
+
const FILE_TAG_REGEX = /^<file\s+path="([^"]+)"/;
|
|
17
|
+
/**
|
|
18
|
+
* Build a lookup: for each line index, find the file path it belongs to
|
|
19
|
+
* by scanning for `<file path="...">` tags.
|
|
20
|
+
*/
|
|
21
|
+
function buildFilePathIndex(lines) {
|
|
22
|
+
const index = new Array(lines.length).fill('');
|
|
23
|
+
let currentPath = '';
|
|
24
|
+
for (let i = 0; i < lines.length; i++) {
|
|
25
|
+
const tagMatch = lines[i].match(FILE_TAG_REGEX);
|
|
26
|
+
if (tagMatch) {
|
|
27
|
+
currentPath = tagMatch[1];
|
|
28
|
+
}
|
|
29
|
+
index[i] = currentPath;
|
|
30
|
+
}
|
|
31
|
+
return index;
|
|
32
|
+
}
|
|
16
33
|
function searchInLines(lines, pattern, ignoreCase) {
|
|
17
34
|
const regex = createRegexPattern(pattern, ignoreCase);
|
|
35
|
+
const filePathIndex = buildFilePathIndex(lines);
|
|
18
36
|
const matches = [];
|
|
19
37
|
for (let i = 0; i < lines.length; i++) {
|
|
20
38
|
const line = lines[i];
|
|
@@ -24,6 +42,7 @@ function searchInLines(lines, pattern, ignoreCase) {
|
|
|
24
42
|
lineNumber: i + 1,
|
|
25
43
|
line,
|
|
26
44
|
matchedText: match[0],
|
|
45
|
+
filePath: filePathIndex[i] || null,
|
|
27
46
|
});
|
|
28
47
|
}
|
|
29
48
|
}
|
|
@@ -35,10 +54,18 @@ function formatSearchResults(lines, matches, beforeLines, afterLines) {
|
|
|
35
54
|
}
|
|
36
55
|
const resultLines = [];
|
|
37
56
|
const addedLines = new Set();
|
|
57
|
+
let lastFilePath = null;
|
|
38
58
|
for (const match of matches) {
|
|
39
59
|
const start = Math.max(0, match.lineNumber - 1 - beforeLines);
|
|
40
60
|
const end = Math.min(lines.length - 1, match.lineNumber - 1 + afterLines);
|
|
41
|
-
|
|
61
|
+
// Add file path header when entering a different file
|
|
62
|
+
if (match.filePath && match.filePath !== lastFilePath) {
|
|
63
|
+
if (resultLines.length > 0)
|
|
64
|
+
resultLines.push('');
|
|
65
|
+
resultLines.push(`=== ${match.filePath} ===`);
|
|
66
|
+
lastFilePath = match.filePath;
|
|
67
|
+
}
|
|
68
|
+
else if (resultLines.length > 0 && start > Math.min(...addedLines) + 1) {
|
|
42
69
|
resultLines.push('--');
|
|
43
70
|
}
|
|
44
71
|
for (let i = start; i <= end; i++) {
|
|
@@ -31,6 +31,19 @@ describe('searchRepomix', () => {
|
|
|
31
31
|
expect(results.matches.length).toBeGreaterThan(0);
|
|
32
32
|
expect(results.matches.some(m => m.line.includes('auth'))).toBe(true);
|
|
33
33
|
});
|
|
34
|
+
it('enriches each match with its file path', () => {
|
|
35
|
+
const results = searchRepomix(SAMPLE_XML, 'auth');
|
|
36
|
+
const readmeMatch = results.matches.find(m => m.line.includes('authentication'));
|
|
37
|
+
expect(readmeMatch?.filePath).toBe('README.md');
|
|
38
|
+
const loginMatch = results.matches.find(m => m.line.includes('/api/auth/login'));
|
|
39
|
+
expect(loginMatch?.filePath).toBe('src/auth/login.ts');
|
|
40
|
+
});
|
|
41
|
+
it('includes file path headers in formatted output when file changes', () => {
|
|
42
|
+
const results = searchRepomix(SAMPLE_XML, 'auth');
|
|
43
|
+
const output = results.formattedOutput.join('\n');
|
|
44
|
+
expect(output).toContain('=== README.md ===');
|
|
45
|
+
expect(output).toContain('=== src/auth/login.ts ===');
|
|
46
|
+
});
|
|
34
47
|
it('returns empty matches for non-existent pattern', () => {
|
|
35
48
|
const results = searchRepomix(SAMPLE_XML, 'nonexistent_xyz_pattern');
|
|
36
49
|
expect(results.matches).toHaveLength(0);
|