@polka-codes/cli-shared 0.10.23 → 0.10.24

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.
Files changed (47) hide show
  1. package/dist/index.js +1913 -7
  2. package/package.json +2 -2
  3. package/dist/config.js +0 -202
  4. package/dist/config.js.map +0 -1
  5. package/dist/config.parameters.test.js +0 -240
  6. package/dist/config.parameters.test.js.map +0 -1
  7. package/dist/config.rules.test.js +0 -92
  8. package/dist/config.rules.test.js.map +0 -1
  9. package/dist/config.test.js +0 -311
  10. package/dist/config.test.js.map +0 -1
  11. package/dist/index.js.map +0 -1
  12. package/dist/memory-manager.js +0 -76
  13. package/dist/memory-manager.js.map +0 -1
  14. package/dist/project-scope.js +0 -67
  15. package/dist/project-scope.js.map +0 -1
  16. package/dist/provider.js +0 -366
  17. package/dist/provider.js.map +0 -1
  18. package/dist/provider.test.js +0 -21
  19. package/dist/provider.test.js.map +0 -1
  20. package/dist/sqlite-memory-store.js +0 -911
  21. package/dist/sqlite-memory-store.js.map +0 -1
  22. package/dist/sqlite-memory-store.test.js +0 -661
  23. package/dist/sqlite-memory-store.test.js.map +0 -1
  24. package/dist/utils/__tests__/parameterSimplifier.test.js +0 -137
  25. package/dist/utils/__tests__/parameterSimplifier.test.js.map +0 -1
  26. package/dist/utils/checkRipgrep.js +0 -22
  27. package/dist/utils/checkRipgrep.js.map +0 -1
  28. package/dist/utils/eventHandler.js +0 -199
  29. package/dist/utils/eventHandler.js.map +0 -1
  30. package/dist/utils/eventHandler.test.js +0 -50
  31. package/dist/utils/eventHandler.test.js.map +0 -1
  32. package/dist/utils/index.js +0 -7
  33. package/dist/utils/index.js.map +0 -1
  34. package/dist/utils/listFiles.js +0 -136
  35. package/dist/utils/listFiles.js.map +0 -1
  36. package/dist/utils/listFiles.test.js +0 -64
  37. package/dist/utils/listFiles.test.js.map +0 -1
  38. package/dist/utils/parameterSimplifier.js +0 -65
  39. package/dist/utils/parameterSimplifier.js.map +0 -1
  40. package/dist/utils/readMultiline.js +0 -19
  41. package/dist/utils/readMultiline.js.map +0 -1
  42. package/dist/utils/search.constants.js +0 -8
  43. package/dist/utils/search.constants.js.map +0 -1
  44. package/dist/utils/searchFiles.js +0 -72
  45. package/dist/utils/searchFiles.js.map +0 -1
  46. package/dist/utils/searchFiles.test.js +0 -140
  47. package/dist/utils/searchFiles.test.js.map +0 -1
@@ -1,136 +0,0 @@
1
- import { promises as fs } from 'node:fs';
2
- import { join, relative, resolve } from 'node:path';
3
- import ignore from 'ignore';
4
- /** Default patterns commonly ignored in projects of various languages. */
5
- const DEFAULT_IGNORES = [
6
- '__pycache__',
7
- '.DS_Store',
8
- '.env',
9
- '.git',
10
- '.idea',
11
- '.svn',
12
- '.temp',
13
- '.vscode',
14
- 'coverage',
15
- 'dist',
16
- 'node_modules',
17
- 'out',
18
- 'Thumbs.db',
19
- ];
20
- /**
21
- * Reads a `.gitignore` file in `dirPath` (if it exists) and appends its lines
22
- * to the `basePatterns`. Returns a new array without mutating the original.
23
- */
24
- async function extendPatterns(basePatterns, dirPath) {
25
- try {
26
- const gitignorePath = join(dirPath, '.gitignore');
27
- const content = await fs.readFile(gitignorePath, 'utf8');
28
- const lines = content.split(/\r?\n/).filter(Boolean);
29
- return [...basePatterns, ...lines];
30
- }
31
- catch {
32
- // No .gitignore or unreadable
33
- return basePatterns;
34
- }
35
- }
36
- /** Creates an `ignore` instance from the given patterns. */
37
- function createIgnore(patterns) {
38
- return ignore().add(patterns);
39
- }
40
- /**
41
- * Lists files under `dirPath` in BFS order, respecting:
42
- * - A default set of ignores
43
- * - A root .gitignore under `cwd`
44
- * - Any .gitignore files in child directories (merged as we go)
45
- *
46
- * Returns `[files, limitReached]`:
47
- * - `files` is the array of file paths (relative to `cwd`)
48
- * - `limitReached` is `true` if `maxCount` was hit, otherwise `false`
49
- * - When truncated, adds markers like `path/to/dir/(files omitted)` for truncated directories
50
- */
51
- export async function listFiles(dirPath, recursive, maxCount, cwd, excludeFiles, includeIgnored) {
52
- // Merge default ignores with root .gitignore and excludeFiles (if found)
53
- let rootPatterns = [...(excludeFiles || [])];
54
- if (!includeIgnored) {
55
- rootPatterns.push(...DEFAULT_IGNORES);
56
- try {
57
- const rootGitignore = await fs.readFile(join(cwd, '.gitignore'), 'utf8');
58
- const lines = rootGitignore.split(/\r?\n/).filter(Boolean);
59
- rootPatterns = [...rootPatterns, ...lines];
60
- }
61
- catch {
62
- // No .gitignore at root or unreadable; ignore silently
63
- }
64
- }
65
- // Final results (relative to `cwd`) and indicator if we reached the limit
66
- const results = [];
67
- // Track directories we've seen to avoid duplicate "(files omitted)" markers
68
- const processedDirs = new Set();
69
- // BFS queue
70
- // Each entry holds the directory path, patterns, and relative path
71
- const queue = [
72
- {
73
- path: resolve(dirPath),
74
- patterns: rootPatterns,
75
- relPath: relative(cwd, resolve(dirPath)).replace(/\\/g, '/') || '.',
76
- },
77
- ];
78
- // Perform BFS until queue is empty or maxCount is reached
79
- while (queue.length > 0) {
80
- // biome-ignore lint/style/noNonNullAssertion: checked above
81
- const { path: currentPath, patterns: parentPatterns, relPath: currentRelPath } = queue.shift();
82
- // Mark this directory as processed
83
- processedDirs.add(currentRelPath);
84
- // Merge parent's patterns with local .gitignore
85
- const mergedPatterns = includeIgnored ? parentPatterns : await extendPatterns(parentPatterns, currentPath);
86
- const folderIg = createIgnore(mergedPatterns);
87
- const entries = await fs.readdir(currentPath, { withFileTypes: true });
88
- entries.sort((a, b) => a.name.localeCompare(b.name)); // Sort entries for consistent order
89
- for (const entry of entries) {
90
- const fullPath = join(currentPath, entry.name);
91
- // Convert full path to something relative to `cwd`
92
- const relPath = relative(cwd, fullPath).replace(/\\/g, '/');
93
- if (folderIg.ignores(relPath)) {
94
- continue; // Skip ignored entries
95
- }
96
- if (entry.isDirectory()) {
97
- if (recursive) {
98
- queue.push({
99
- path: fullPath,
100
- patterns: mergedPatterns,
101
- relPath,
102
- });
103
- }
104
- }
105
- else {
106
- results.push(relPath);
107
- if (results.length >= maxCount) {
108
- // We've hit the limit, add "(files omitted)" markers for directories
109
- // still in the queue and the current directory if we haven't processed all its files
110
- // First, check if there are remaining files in the current directory
111
- const remainingEntries = entries.slice(entries.indexOf(entry) + 1);
112
- const hasRemainingFiles = remainingEntries.some((e) => !e.isDirectory() && !folderIg.ignores(relative(cwd, join(currentPath, e.name)).replace(/\\/g, '/')));
113
- if (hasRemainingFiles) {
114
- const marker = `${currentRelPath}/(files omitted)`;
115
- results.push(marker);
116
- }
117
- // Then add markers for all directories still in the queue
118
- for (const queueItem of queue) {
119
- // Only add markers for directories we haven't processed yet
120
- if (!processedDirs.has(queueItem.relPath)) {
121
- const marker = `${queueItem.relPath}/(files omitted)`;
122
- results.push(marker);
123
- processedDirs.add(queueItem.relPath); // Mark as processed to avoid duplicates
124
- }
125
- }
126
- results.sort();
127
- return [results, true];
128
- }
129
- }
130
- }
131
- }
132
- results.sort();
133
- // If we exhaust the BFS queue, we did not reach maxCount
134
- return [results, false];
135
- }
136
- //# sourceMappingURL=listFiles.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"listFiles.js","sourceRoot":"","sources":["../../src/utils/listFiles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAA;AACxC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnD,OAAO,MAAuB,MAAM,QAAQ,CAAA;AAE5C,0EAA0E;AAC1E,MAAM,eAAe,GAAG;IACtB,aAAa;IACb,WAAW;IACX,MAAM;IACN,MAAM;IACN,OAAO;IACP,MAAM;IACN,OAAO;IACP,SAAS;IACT,UAAU;IACV,MAAM;IACN,cAAc;IACd,KAAK;IACL,WAAW;CACZ,CAAA;AAED;;;GAGG;AACH,KAAK,UAAU,cAAc,CAAC,YAAsB,EAAE,OAAe;IACnE,IAAI,CAAC;QACH,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,EAAE,YAAY,CA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,OAAO,CAAC,EAAE,CAAC;4BAC1C,MAAM,MAAM,GAAG,GAAG,SAAS,CAAC,OAAO,kBAAkB,CAAA;4BACrD,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;4BACpB,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA,CAAC,wCAAwC;wBAC/E,CAAC;oBACH,CAAC;oBAED,OAAO,CAAC,IAAI,EAAE,CAAA;oBACd,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;gBACxB,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,CAAC,IAAI,EAAE,CAAA;IACd,yDAAyD;IACzD,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;AACzB,CAAC"}
@@ -1,64 +0,0 @@
1
- import { afterAll, beforeAll, describe, expect, it } from 'bun:test';
2
- import { promises as fs } from 'node:fs';
3
- import { join } from 'node:path';
4
- import { listFiles } from './listFiles';
5
- describe('listFiles', () => {
6
- const testDir = join(__dirname, 'test-fixtures');
7
- beforeAll(async () => {
8
- // Create test directory structure
9
- await fs.mkdir(testDir, { recursive: true });
10
- await fs.writeFile(join(testDir, '.gitignore'), 'ignored.txt\nsubdir/ignored-too.txt');
11
- await fs.writeFile(join(testDir, 'file1.txt'), '');
12
- await fs.writeFile(join(testDir, 'file2.txt'), '');
13
- await fs.writeFile(join(testDir, 'ignored.txt'), '');
14
- // Create subdirectory
15
- const subDir = join(testDir, 'asubdir');
16
- await fs.mkdir(subDir);
17
- await fs.writeFile(join(subDir, 'file3.txt'), '');
18
- await fs.writeFile(join(subDir, 'ignored-too.txt'), '');
19
- });
20
- afterAll(async () => {
21
- // Clean up test directory
22
- await fs.rm(testDir, { recursive: true, force: true });
23
- });
24
- it('should list files in directory', async () => {
25
- const [files] = await listFiles(testDir, false, 10, testDir, []);
26
- expect(files).toEqual(['.gitignore', 'file1.txt', 'file2.txt']);
27
- });
28
- it('should list files recursively', async () => {
29
- const [files] = await listFiles(testDir, true, 10, testDir);
30
- expect(files).toMatchSnapshot();
31
- });
32
- it('should respect maxCount and show truncation markers', async () => {
33
- const [files, limitReached] = await listFiles(testDir, true, 3, testDir);
34
- expect(limitReached).toBe(true);
35
- expect(files).toMatchSnapshot();
36
- });
37
- it('should show truncation markers for root directories', async () => {
38
- // Set a low maxCount to force truncation
39
- const [files, limitReached] = await listFiles(testDir, true, 2, testDir);
40
- expect(limitReached).toBe(true);
41
- expect(files).toMatchSnapshot();
42
- });
43
- it('should not show truncation markers when limit not reached', async () => {
44
- // Set a high maxCount to avoid truncation
45
- const [files, limitReached] = await listFiles(testDir, true, 100, testDir);
46
- expect(limitReached).toBe(false);
47
- expect(files).toMatchSnapshot();
48
- });
49
- it('should handle empty directory', async () => {
50
- const emptyDir = join(testDir, 'empty');
51
- await fs.mkdir(emptyDir);
52
- const [files] = await listFiles(emptyDir, true, 10, emptyDir);
53
- expect(files).toEqual([]);
54
- await fs.rm(emptyDir, { recursive: true });
55
- });
56
- it('should handle non-existent directory', async () => {
57
- expect(listFiles(join(testDir, 'nonexistent'), false, 10, testDir)).rejects.toThrow();
58
- });
59
- it('should exclude files matching excludeFiles patterns', async () => {
60
- const [files] = await listFiles(testDir, true, 10, testDir, ['file2.txt', 'asubdir/*']);
61
- expect(files).toEqual(['.gitignore', 'file1.txt']);
62
- });
63
- });
64
- //# sourceMappingURL=listFiles.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"listFiles.test.js","sourceRoot":"","sources":["../../src/utils/listFiles.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,UAAU,CAAA;AACpE,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAA;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEvC,Q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AAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1,65 +0,0 @@
1
- /**
2
- * Factory that creates a parameter simplifier which only keeps specified fields
3
- *
4
- * @param keepFields - Array of field names to preserve in the simplified params
5
- * @returns A simplifier function that filters to only the specified fields
6
- *
7
- * @example
8
- * ```typescript
9
- * const readFileSimplifier = createSimplifier(['path', 'includeIgnored'])
10
- * readFileSimplifier({ path: '/test', includeIgnored: true, extra: 'data' })
11
- * // Returns: { path: '/test', includeIgnored: true }
12
- * ```
13
- */
14
- function createSimplifier(keepFields) {
15
- return (params) => {
16
- const result = {};
17
- for (const field of keepFields) {
18
- if (params[field] !== undefined) {
19
- result[field] = params[field];
20
- }
21
- }
22
- return result;
23
- };
24
- }
25
- /**
26
- * Factory that creates a simplifier with custom logic
27
- *
28
- * For cases where simple field filtering isn't enough, this allows
29
- * custom transformation logic while maintaining a consistent API.
30
- */
31
- function createCustomSimplifier(transform) {
32
- return transform;
33
- }
34
- // Simplifier registry using the factory pattern
35
- const SIMPLIFIERS = {
36
- // Simple field-based simplifiers
37
- replaceInFile: createSimplifier(['path']),
38
- writeToFile: createSimplifier(['path']),
39
- readFile: createSimplifier(['path', 'includeIgnored']),
40
- executeCommand: createSimplifier(['command', 'requiresApproval']),
41
- updateMemory: createSimplifier(['operation', 'topic']),
42
- // searchFiles passes through all params
43
- searchFiles: createCustomSimplifier((params) => ({ ...params })),
44
- // listFiles has custom logic for maxCount default value
45
- listFiles: createCustomSimplifier((params) => {
46
- const DEFAULT_MAX_COUNT = 2000;
47
- const maxCount = params.maxCount;
48
- return {
49
- path: params.path,
50
- recursive: params.recursive,
51
- ...(maxCount !== DEFAULT_MAX_COUNT && { maxCount }),
52
- };
53
- }),
54
- };
55
- export function simplifyToolParameters(toolName, params) {
56
- if (params === undefined || params === null) {
57
- return {};
58
- }
59
- const simplifier = SIMPLIFIERS[toolName];
60
- if (simplifier) {
61
- return simplifier(params);
62
- }
63
- return { ...params };
64
- }
65
- //# sourceMappingURL=parameterSim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Q,CAAA;QAChC,OAAO;YACL,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,GAAG,CAAC,QAAQ,KAAK,iBAAiB,IAAI,EAAE,QAAQ,EAAE,CAAC;SACpD,CAAA;IACH,CAAC,CAAC;CACH,CAAA;AAED,MAAM,UAAU,sBAAsB,CAAC,QAAgB,EAAE,MAA2C;IAClG,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QAC5C,OAAO,EAAE,CAAA;IACX,CAAC;IAED,MAAM,UAAU,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAA;IACxC,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,UAAU,CAAC,MAAM,CAAC,CAAA;IAC3B,CAAC;IAED,OAAO,EAAE,GAAG,MAAM,EAAE,CAAA;AACtB,CAAC"}
@@ -1,19 +0,0 @@
1
- import readline from 'node:readline';
2
- export function readMultiline(prompt = 'Enter text (Ctrl+D to finish):') {
3
- return new Promise((resolve) => {
4
- console.log(prompt);
5
- const rl = readline.createInterface({
6
- input: process.stdin,
7
- output: process.stdout,
8
- prompt: '',
9
- });
10
- const lines = [];
11
- rl.on('line', (line) => {
12
- lines.push(line);
13
- });
14
- rl.on('close', () => {
15
- resolve(lines.join('\n'));
16
- });
17
- });
18
- }
19
- //# sourceMappingURL=readMultiline.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"readMultiline.js","sourceRoot":"","sources":["../../src/utils/readMultiline.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,eAAe,CAAA;AAEpC,MAAM,UAAU,aAAa,CAAC,MAAM,GAAG,gCAAgC;IACrE,OAAO,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,EAAE;QACrC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QACnB,MAAM,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC;YAClC,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,MAAM,EAAE,EAAE;SACX,CAAC,CAAA;QAEF,MAAM,KAAK,GAAa,EAAE,CAAA;QAC1B,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YACrB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAClB,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;YAClB,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;QAC3B,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC"}
@@ -1,8 +0,0 @@
1
- /**
2
- * Constants for file search operations
3
- */
4
- export const SEARCH_CONSTANTS = {
5
- /** Default number of context lines to show around search matches */
6
- DEFAULT_CONTEXT_LINES: 5,
7
- };
8
- //# sourceMappingURL=search.constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"search.constants.js","sourceRoot":"","sources":["../../src/utils/search.constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,oEAAoE;IACpE,qBAAqB,EAAE,CAAC;CAChB,CAAA"}
@@ -1,72 +0,0 @@
1
- /**
2
- * File search utility using ripgrep for performant code search
3
- * Generated by polka.codes
4
- */
5
- import { spawn } from 'node:child_process';
6
- import { SEARCH_CONSTANTS } from './search.constants.js';
7
- /**
8
- * Performs a regex search across files using ripgrep.
9
- * Respects .gitignore and provides context-rich results.
10
- *
11
- * @param path - Directory to search in
12
- * @param regex - Regular expression pattern to search for
13
- * @param filePattern - Optional glob pattern to filter files. Can be a comma-separated string (e.g., "*.ts,*.js")
14
- * @param cwd - Working directory for relative paths
15
- * @param excludeFiles - Additional patterns to exclude
16
- * @returns Array of search results with context
17
- */
18
- export async function searchFiles(path, regex, filePattern, cwd, excludeFiles) {
19
- // Build ripgrep arguments
20
- const args = [
21
- '--line-number', // Show line numbers
22
- `--context=${SEARCH_CONSTANTS.DEFAULT_CONTEXT_LINES}`, // Show lines before and after matches
23
- '--color=never', // No color codes in output
24
- '--with-filename', // Show filenames
25
- '--smart-case', // Smart case sensitivity
26
- ];
27
- // Add file pattern filter if specified
28
- if (filePattern && filePattern !== '*') {
29
- // Handle comma-separated patterns
30
- const patterns = filePattern
31
- .split(',')
32
- .map((p) => p.trim())
33
- .filter(Boolean);
34
- // Add each pattern as a separate --glob argument
35
- for (const pattern of patterns) {
36
- if (pattern) {
37
- args.push('--glob', pattern);
38
- }
39
- }
40
- }
41
- // Add custom ignore patterns
42
- if (excludeFiles) {
43
- for (const pattern of excludeFiles) {
44
- args.push('--glob', `!${pattern}`);
45
- }
46
- }
47
- // Add the search pattern and path
48
- args.push(regex, path);
49
- return new Promise((resolve, reject) => {
50
- const results = [];
51
- const rg = spawn('rg', args, {
52
- cwd,
53
- stdio: ['ignore', 'pipe', 'pipe'],
54
- });
55
- rg.stdout.on('data', (data) => {
56
- const lines = data.toString().split('\n').filter(Boolean);
57
- results.push(...lines);
58
- });
59
- rg.on('error', (error) => {
60
- reject(new Error(`Failed to execute ripgrep: ${error.message}`));
61
- });
62
- rg.on('close', (code) => {
63
- if (code !== 0 && code !== 1) {
64
- // code 1 means no matches found, which is not an error
65
- reject(new Error(`Ripgrep process exited with code ${code}`));
66
- return;
67
- }
68
- resolve(results);
69
- });
70
- });
71
- }
72
- //# sourceMappingURL=searchFiles.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"searchFiles.js","sourceRoot":"","sources":["../../src/utils/searchFiles.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAExD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,IAAY,EACZ,KAAa,EACb,W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C,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YAC5B,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;YACzD,OAAO,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAA;QACxB,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YACvB,MAAM,CAAC,IAAI,KAAK,CAAC,8BAA8B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;QAClE,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YACtB,IAAI,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;gBAC7B,uDAAuD;gBACvD,MAAM,CAAC,IAAI,KAAK,CAAC,oCAAoC,IAAI,EAAE,CAAC,CAAC,CAAA;gBAC7D,OAAM;YACR,CAAC;YACD,OAAO,CAAC,OAAO,CAAC,CAAA;QAClB,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC"}
@@ -1,140 +0,0 @@
1
- /**
2
- * Tests for searchFiles utility
3
- * Generated by polka.codes
4
- */
5
- import { afterAll, beforeAll, describe, expect, it, mock, spyOn } from 'bun:test';
6
- import * as child_process from 'node:child_process';
7
- import { EventEmitter } from 'node:events';
8
- import { promises as fs } from 'node:fs';
9
- import { join } from 'node:path';
10
- import { afterEach } from 'node:test';
11
- import { searchFiles } from './searchFiles';
12
- describe('searchFiles with mocks', () => {
13
- afterEach(() => mock.restore());
14
- it('should execute ripgrep with correct arguments for a single pattern', async () => {
15
- const mockSpawn = spyOn(child_process, 'spawn');
16
- // Create mock process
17
- const mockProcess = new EventEmitter();
18
- mockProcess.stdout = new EventEmitter();
19
- mockProcess.stderr = new EventEmitter();
20
- mockSpawn.mockImplementation(() => mockProcess);
21
- // Start search
22
- const searchPromise = searchFiles('src', 'test', '*.ts', '/test/path');
23
- // Verify arguments
24
- expect(mockSpawn).toHaveBeenCalled();
25
- const args = mockSpawn.mock.calls[0][1];
26
- expect(args).toContain('--line-number');
27
- expect(args).toContain('--context=5');
28
- expect(args).toContain('--glob');
29
- expect(args).toContain('*.ts');
30
- expect(args).toContain('test');
31
- expect(args).toContain('src');
32
- // Simulate successful search
33
- mockProcess.stdout.emit('data', 'file1.ts:10:test match\n');
34
- mockProcess.emit('close', 0);
35
- const results = await searchPromise;
36
- expect(results).toEqual(['file1.ts:10:test match']);
37
- });
38
- // TODO: investigate why this test is failing on CI but passes locally
39
- describe.skipIf(!!process.env.CI)('searchFiles with real files', () => {
40
- const testDir = join(__dirname, 'search-test-fixtures');
41
- // Create files with searchable content
42
- beforeAll(async () => {
43
- // Create test directory structure
44
- await fs.mkdir(testDir, { recursive: true });
45
- // Create files with searchable content
46
- await fs.writeFile(join(testDir, 'file1.txt'), 'This file contains SEARCHABLE text');
47
- await fs.writeFile(join(testDir, 'file2.txt'), 'Another file with SEARCHABLE content');
48
- await fs.writeFile(join(testDir, 'excluded.txt'), 'This file has SEARCHABLE content but should be excluded');
49
- // Create subdirectory
50
- const subDir = join(testDir, 'subdir');
51
- await fs.mkdir(subDir, { recursive: true });
52
- await fs.writeFile(join(subDir, 'file3.txt'), 'Subdirectory file with SEARCHABLE content');
53
- await fs.writeFile(join(subDir, 'excluded-too.txt'), 'Another SEARCHABLE file to exclude');
54
- });
55
- afterAll(async () => {
56
- // Clean up test directory
57
- await fs.rm(testDir, { recursive: true, force: true });
58
- });
59
- it('should search with comma-separated glob patterns in real files', async () => {
60
- const results = await searchFiles(testDir, 'SEARCHABLE', 'file1.txt,file2.txt', testDir);
61
- const fileMatches = results.join('\n');
62
- expect(fileMatches).toContain('file1.txt');
63
- expect(fileMatches).toContain('file2.txt');
64
- expect(fileMatches).not.toContain('excluded.txt');
65
- });
66
- it('should find all files with searchable content when no exclusions specified', async () => {
67
- const results = await searchFiles(testDir, 'SEARCHABLE', '*.txt', testDir);
68
- // Should find all 5 files
69
- expect(results.length).toBeGreaterThan(0);
70
- // Check if all files are found
71
- const fileMatches = results.join('\n');
72
- expect(fileMatches).toContain('file1.txt');
73
- expect(fileMatches).toContain('file2.txt');
74
- expect(fileMatches).toContain('excluded.txt');
75
- expect(fileMatches).toContain('subdir/file3.txt');
76
- expect(fileMatches).toContain('subdir/excluded-too.txt');
77
- });
78
- it('should exclude files specified in excludeFiles parameter', async () => {
79
- const results = await searchFiles(testDir, 'SEARCHABLE', '*.txt', testDir, ['excluded.txt', 'subdir/excluded-too.txt']);
80
- // Should still find matches
81
- expect(results.length).toBeGreaterThan(0);
82
- // Check if excluded files are not in results
83
- const fileMatches = results.join('\n');
84
- expect(fileMatches).toContain('file1.txt');
85
- expect(fileMatches).toContain('file2.txt');
86
- expect(fileMatches).toContain('subdir/file3.txt');
87
- // Excluded files should not be found
88
- expect(fileMatches).not.toContain('excluded.txt:');
89
- expect(fileMatches).not.toContain('subdir/excluded-too.txt:');
90
- });
91
- it('should exclude files using glob patterns', async () => {
92
- const results = await searchFiles(testDir, 'SEARCHABLE', '*.txt', testDir, ['**/excluded*.txt']);
93
- // Should still find matches
94
- expect(results.length).toBeGreaterThan(0);
95
- // Check if excluded files are not in results
96
- const fileMatches = results.join('\n');
97
- expect(fileMatches).toContain('file1.txt');
98
- expect(fileMatches).toContain('file2.txt');
99
- expect(fileMatches).toContain('subdir/file3.txt');
100
- // Excluded files should not be found
101
- expect(fileMatches).not.toContain('excluded.txt:');
102
- expect(fileMatches).not.toContain('subdir/excluded-too.txt:');
103
- });
104
- it('should exclude entire directories', async () => {
105
- const results = await searchFiles(testDir, 'SEARCHABLE', '*.txt', testDir, ['subdir']);
106
- // Should still find matches
107
- expect(results.length).toBeGreaterThan(0);
108
- // Check if excluded directory files are not in results
109
- const fileMatches = results.join('\n');
110
- expect(fileMatches).toContain('file1.txt');
111
- expect(fileMatches).toContain('file2.txt');
112
- expect(fileMatches).toContain('excluded.txt');
113
- // Files in excluded directory should not be found
114
- expect(fileMatches).not.toContain('subdir/file3.txt');
115
- expect(fileMatches).not.toContain('subdir/excluded-too.txt');
116
- });
117
- });
118
- it('should handle no matches gracefully', async () => {
119
- const mockSpawn = spyOn(child_process, 'spawn');
120
- const mockProcess = new EventEmitter();
121
- mockProcess.stdout = new EventEmitter();
122
- mockProcess.stderr = new EventEmitter();
123
- mockSpawn.mockImplementation(() => mockProcess);
124
- const searchPromise = searchFiles('src', 'nonexistent', '*.ts', '/test/path');
125
- mockProcess.emit('close', 1); // Exit code 1 means no matches
126
- const results = await searchPromise;
127
- expect(results).toEqual([]);
128
- });
129
- it('should handle errors', async () => {
130
- const mockSpawn = spyOn(child_process, 'spawn');
131
- const mockProcess = new EventEmitter();
132
- mockProcess.stdout = new EventEmitter();
133
- mockProcess.stderr = new EventEmitter();
134
- mockSpawn.mockImplementation(() => mockProcess);
135
- const searchPromise = searchFiles('src', 'test', '*.ts', '/test/path');
136
- mockProcess.emit('error', new Error('Test error'));
137
- await expect(searchPromise).rejects.toThrow('Failed to execute ripgrep');
138
- });
139
- });
140
- //# sourceMappingURL=searchFiles.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"searchFiles.test.js","sourceRoot":"","sources":["../../src/utils/searchFiles.test.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AACjF,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAA;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE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