xgrep 0.1.5 → 0.2.1
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 +119 -0
- package/package.json +2 -1
- package/xgrep.darwin-arm64.node +0 -0
- package/xgrep.darwin-x64.node +0 -0
- package/xgrep.linux-arm64-gnu.node +0 -0
- package/xgrep.linux-x64-gnu.node +0 -0
- package/xgrep.win32-x64-msvc.node +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# xgrep
|
|
2
|
+
|
|
3
|
+
Ultra-fast indexed code search engine for Node.js. Powered by [trigram inverted index](https://swtch.com/~rsc/regexp/regexp4.html) in Rust via [napi-rs](https://napi.rs/).
|
|
4
|
+
|
|
5
|
+
27-59x faster than ripgrep on repeated searches.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install xgrep
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Pre-built binaries are available for:
|
|
14
|
+
- Linux (x86_64, ARM64)
|
|
15
|
+
- macOS (x86_64, ARM64)
|
|
16
|
+
- Windows (x86_64)
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { Xgrep } from 'xgrep';
|
|
22
|
+
|
|
23
|
+
// Open a directory and build the index
|
|
24
|
+
const xg = Xgrep.open('/path/to/your/repo');
|
|
25
|
+
xg.buildIndex();
|
|
26
|
+
|
|
27
|
+
// Search for a pattern
|
|
28
|
+
const results = xg.search('fn main');
|
|
29
|
+
for (const r of results) {
|
|
30
|
+
console.log(`${r.file}:${r.lineNumber}: ${r.line}`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Search with options
|
|
34
|
+
const filtered = xg.search('TODO', {
|
|
35
|
+
fileType: 'ts', // Filter by file type
|
|
36
|
+
caseInsensitive: true, // Case-insensitive search
|
|
37
|
+
maxCount: 10, // Limit results
|
|
38
|
+
pathPattern: 'src/', // Filter by path
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Regex search
|
|
42
|
+
const regexResults = xg.search('fn\\s+\\w+', { regex: true });
|
|
43
|
+
|
|
44
|
+
// Index status
|
|
45
|
+
console.log(xg.indexStatus());
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## API
|
|
49
|
+
|
|
50
|
+
### `Xgrep.open(root: string): Xgrep`
|
|
51
|
+
|
|
52
|
+
Open a directory for searching. Index location is auto-resolved to `~/.cache/xgrep/`.
|
|
53
|
+
|
|
54
|
+
### `Xgrep.openLocal(root: string): Xgrep`
|
|
55
|
+
|
|
56
|
+
Open with local index storage (`.xgrep/` in the project root).
|
|
57
|
+
|
|
58
|
+
### `xg.buildIndex(): void`
|
|
59
|
+
|
|
60
|
+
Build or rebuild the search index.
|
|
61
|
+
|
|
62
|
+
### `xg.search(pattern: string, opts?: SearchOptions): SearchResult[]`
|
|
63
|
+
|
|
64
|
+
Search for a pattern in the indexed codebase.
|
|
65
|
+
|
|
66
|
+
**SearchOptions:**
|
|
67
|
+
|
|
68
|
+
| Option | Type | Default | Description |
|
|
69
|
+
|--------|------|---------|-------------|
|
|
70
|
+
| `caseInsensitive` | `boolean` | `false` | Case-insensitive search (ASCII-only) |
|
|
71
|
+
| `regex` | `boolean` | `false` | Treat pattern as regex |
|
|
72
|
+
| `fileType` | `string` | - | Filter by file type (e.g., `"rs"`, `"py"`, `"js"`) |
|
|
73
|
+
| `maxCount` | `number` | - | Maximum number of results |
|
|
74
|
+
| `changedOnly` | `boolean` | `false` | Only search git-changed files |
|
|
75
|
+
| `since` | `string` | - | Files changed within duration (`"1h"`, `"2d"`, `"3.commits"`) |
|
|
76
|
+
| `pathPattern` | `string` | - | Filter by path substring |
|
|
77
|
+
| `fresh` | `boolean` | `false` | Check index freshness before searching |
|
|
78
|
+
|
|
79
|
+
**SearchResult:**
|
|
80
|
+
|
|
81
|
+
| Field | Type | Description |
|
|
82
|
+
|-------|------|-------------|
|
|
83
|
+
| `file` | `string` | File path relative to root |
|
|
84
|
+
| `lineNumber` | `number` | Line number (1-based) |
|
|
85
|
+
| `line` | `string` | The matching line content |
|
|
86
|
+
|
|
87
|
+
### `xg.indexStatus(): string`
|
|
88
|
+
|
|
89
|
+
Get the current index status.
|
|
90
|
+
|
|
91
|
+
### `xg.root: string` (getter)
|
|
92
|
+
|
|
93
|
+
Get the root directory path.
|
|
94
|
+
|
|
95
|
+
### `xg.indexPath: string` (getter)
|
|
96
|
+
|
|
97
|
+
Get the index file path.
|
|
98
|
+
|
|
99
|
+
## How It Works
|
|
100
|
+
|
|
101
|
+
xgrep builds a trigram inverted index of your codebase. On the first search, the index is built automatically. Subsequent searches use the index to narrow down candidate files before scanning, making repeated searches extremely fast.
|
|
102
|
+
|
|
103
|
+
| Benchmark | xgrep | ripgrep | Speedup |
|
|
104
|
+
|-----------|-------|---------|---------|
|
|
105
|
+
| Linux kernel (92K files) | 38ms | 2,236ms | **59x** |
|
|
106
|
+
| ripgrep source (248 files) | 2.5ms | 7.9ms | **3.1x** |
|
|
107
|
+
|
|
108
|
+
## CLI
|
|
109
|
+
|
|
110
|
+
xgrep also provides a CLI tool. Install via Rust:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
cargo install xgrep-search
|
|
114
|
+
xg "pattern" --type rs
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xgrep",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Ultra-fast indexed code search engine powered by trigram index. Native Rust bindings for Node.js.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"files": [
|
|
47
47
|
"index.js",
|
|
48
48
|
"index.d.ts",
|
|
49
|
+
"README.md",
|
|
49
50
|
"xgrep.*.node"
|
|
50
51
|
]
|
|
51
52
|
}
|
package/xgrep.darwin-arm64.node
CHANGED
|
Binary file
|
package/xgrep.darwin-x64.node
CHANGED
|
Binary file
|
|
Binary file
|
package/xgrep.linux-x64-gnu.node
CHANGED
|
Binary file
|
|
Binary file
|