clippy-test 1.0.8 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,126 @@
1
+ import { RipGrep } from "ripgrep-node";
2
+ import { logd } from "./cli-helpers.js";
3
+ export async function ripgrepSearch(query, options = {}) {
4
+ const defaultExcludePatterns = [
5
+ "node_modules",
6
+ ".git",
7
+ "dist",
8
+ "build",
9
+ ".next",
10
+ ".cache",
11
+ "coverage",
12
+ ".nyc_output",
13
+ ".vscode",
14
+ ".idea",
15
+ "*.log",
16
+ "*.lock",
17
+ "package-lock.json",
18
+ "yarn.lock",
19
+ "pnpm-lock.yaml",
20
+ ".env",
21
+ ".env.*",
22
+ "*.min.js",
23
+ "*.min.css",
24
+ ".DS_Store",
25
+ "Thumbs.db",
26
+ ];
27
+ const { maxResults = 20, caseSensitive = false, fileTypes = [], excludePatterns = defaultExcludePatterns, workingDirectory, } = options;
28
+ if (!query || query.trim().length === 0) {
29
+ return [];
30
+ }
31
+ const searchDir = workingDirectory || (typeof process !== "undefined" ? process.cwd() : undefined);
32
+ if (!searchDir) {
33
+ logd("[ripgrep] ERROR: workingDirectory is required for client-side usage");
34
+ return [];
35
+ }
36
+ logd(`[ripgrep] Starting search: query=${query}, searchDir=${searchDir}, maxResults=${maxResults}, caseSensitive=${caseSensitive}, fileTypes=${JSON.stringify(fileTypes)}, excludePatterns=${JSON.stringify(excludePatterns.slice(0, 5))}`);
37
+ try {
38
+ let rg = new RipGrep(query, searchDir);
39
+ rg.withFilename().lineNumber();
40
+ rg.fixedStrings();
41
+ if (!caseSensitive) {
42
+ rg.ignoreCase();
43
+ }
44
+ if (fileTypes.length > 0) {
45
+ for (const ext of fileTypes) {
46
+ rg.glob(`*.${ext}`);
47
+ }
48
+ }
49
+ for (const pattern of excludePatterns) {
50
+ const hasFileExtension = /\.(json|lock|yaml|js|css|log)$/.test(pattern) ||
51
+ pattern.startsWith("*.") ||
52
+ pattern === ".env" ||
53
+ pattern.startsWith(".env.") ||
54
+ pattern === ".DS_Store" ||
55
+ pattern === "Thumbs.db";
56
+ const isFilePattern = pattern.includes("*") || hasFileExtension;
57
+ const excludePattern = isFilePattern ? `!${pattern}` : `!${pattern}/**`;
58
+ rg.glob(excludePattern);
59
+ }
60
+ const output = await rg.run().asString();
61
+ logd(`[ripgrep] Raw output: outputLength=${output?.length || 0}, hasOutput=${!!(output && output.trim().length > 0)}, outputPreview=${output?.substring(0, 200) || "N/A"}`);
62
+ if (!output || output.trim().length === 0) {
63
+ logd("[ripgrep] ⚠️ No output from ripgrep - returning empty results");
64
+ return [];
65
+ }
66
+ const lines = output.trim().split("\n");
67
+ logd(`[ripgrep] Parsing output: totalLines=${lines.length}, firstLine=${lines[0]?.substring(0, 100) || "N/A"}`);
68
+ const results = [];
69
+ for (const line of lines.slice(0, maxResults)) {
70
+ const match = line.match(/^(.+?):(\d+):(.+)$/);
71
+ if (match) {
72
+ const [, filePath, lineNum, content] = match;
73
+ const lineNumber = lineNum ? parseInt(lineNum, 10) : null;
74
+ const preview = content ? content.trim().slice(0, 200) : undefined;
75
+ results.push({
76
+ filePath: filePath.trim(),
77
+ line: lineNumber ?? null,
78
+ preview: preview || undefined,
79
+ score: 1.0,
80
+ });
81
+ }
82
+ else {
83
+ logd(`[ripgrep] ⚠️ Line didn't match expected format: line=${line.substring(0, 100)}, lineLength=${line.length}`);
84
+ }
85
+ }
86
+ logd(`[ripgrep] ✅ Parsed results: totalResults=${results.length}, results=${JSON.stringify(results.map(r => ({
87
+ filePath: r.filePath,
88
+ line: r.line,
89
+ previewLength: r.preview?.length || 0,
90
+ })))}`);
91
+ return results;
92
+ }
93
+ catch (error) {
94
+ logd(`[ripgrep] ❌ Exception caught: error=${error.message}, code=${error.code}, stack=${error.stack?.substring(0, 200) || 'N/A'}`);
95
+ if (error.message?.includes("No matches") ||
96
+ error.message?.includes("not found") ||
97
+ error.code === 1) {
98
+ logd("[ripgrep] ℹ️ No matches found (this is normal if search term doesn't exist)");
99
+ return [];
100
+ }
101
+ logd(`[ripgrep] Error executing ripgrep: ${error.message}`);
102
+ return [];
103
+ }
104
+ }
105
+ export async function ripgrepSearchMultiple(queries, options = {}) {
106
+ const allResults = [];
107
+ for (const query of queries) {
108
+ const results = await ripgrepSearch(query, {
109
+ ...options,
110
+ maxResults: Math.ceil((options.maxResults || 20) / queries.length),
111
+ });
112
+ allResults.push(...results);
113
+ }
114
+ // Deduplicate by filePath:line
115
+ const seen = new Set();
116
+ const unique = [];
117
+ for (const result of allResults) {
118
+ const key = `${result.filePath}:${result.line}`;
119
+ if (!seen.has(key)) {
120
+ seen.add(key);
121
+ unique.push(result);
122
+ }
123
+ }
124
+ return unique.slice(0, options.maxResults || 20);
125
+ }
126
+ //# sourceMappingURL=ripgrep-tool.js.map