ripgrep 0.0.0 → 0.0.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/LICENSE.md ADDED
@@ -0,0 +1,52 @@
1
+ # License
2
+
3
+ ## zigrep
4
+
5
+ The MIT License (MIT)
6
+
7
+ Copyright (c) 2026 Pooya Parsa <pooya@pi0.io>
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in
17
+ all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
+ THE SOFTWARE.
26
+
27
+ ---
28
+
29
+ ## Third-party notices
30
+
31
+ This project builds and redistributes binaries of [ripgrep](https://github.com/BurntSushi/ripgrep),
32
+ Copyright (c) 2015 Andrew Gallant.
33
+
34
+ ripgrep is dual-licensed under **The MIT License** and **The Unlicense**; you
35
+ may use it under the terms of either. For zigrep's redistribution, we rely on
36
+ the MIT license terms. The upstream license texts are preserved in this
37
+ repository at:
38
+
39
+ - [vendor/ripgrep/LICENSE-MIT](vendor/ripgrep/LICENSE-MIT)
40
+ - [vendor/ripgrep/UNLICENSE](vendor/ripgrep/UNLICENSE)
41
+ - [vendor/ripgrep/COPYING](vendor/ripgrep/COPYING)
42
+
43
+ Any distribution of the `rg` binary produced by this project must include a
44
+ copy of one of the above ripgrep license texts, per the MIT license's notice
45
+ requirement. The Unlicense imposes no such requirement, so recipients who
46
+ prefer it may instead rely on the Unlicense terms.
47
+
48
+ ripgrep transitively depends on a number of Rust crates, each under their own
49
+ permissive license (typically MIT or Apache-2.0). When shipping a compiled
50
+ `rg` binary, you should also reproduce those notices; they can be generated
51
+ from the upstream source tree with tools such as `cargo about` or
52
+ `cargo-license`.
package/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # ripgrep-node
2
+
3
+ [ripgrep](https://github.com/BurntSushi/ripgrep) in a compact and cross-platform npm package. Works with Node.js, Bun, and Deno without native binaries. Bundler-friendly, with the WASM embedded as z85+brotli.
4
+
5
+ ## CLI
6
+
7
+ ```sh
8
+ npx ripgrep TODO src/
9
+ ```
10
+
11
+ Or install globally:
12
+
13
+ ```sh
14
+ npm i -g ripgrep
15
+ rg TODO src/
16
+ ```
17
+
18
+ ## Programmatic API
19
+
20
+ ```js
21
+ import { ripgrep } from "ripgrep";
22
+
23
+ const { code } = await ripgrep(["--json", "TODO", "src"]);
24
+ // 0 = matches found, 1 = no matches, 2 = error
25
+ ```
26
+
27
+ ### `ripgrep(args, options)`
28
+
29
+ Runs ripgrep with the given CLI arguments and returns a `{ code }` result object. Output is written to the host's `process.stdout` / `process.stderr`.
30
+
31
+ Options:
32
+
33
+ - `env` — environment variables passed to the WASI instance (default: `process.env`).
34
+ - `preopens` — WASI preopened directories mapping guest paths to host paths (default: `{ ".": process.cwd() }`). Required for ripgrep to see any files on disk.
35
+ - `returnOnExit` — when `true`, `proc_exit` returns the exit code instead of terminating the process (default: `true`).
36
+ - `nodeWasi` — use Node's built-in `node:wasi` instead of the bundled WASI shim (default: `false`, also enabled via `ZIGREP_NODE_WASI=1`).
37
+
38
+ ### `rgPath`
39
+
40
+ Absolute filesystem path to a JS shim that runs ripgrep via `ripgrep`. Drop-in replacement for `rgPath` from `vscode-ripgrep` / `@vscode/ripgrep`-style consumers that spawn the binary directly:
41
+
42
+ ```js
43
+ import { spawn } from "node:child_process";
44
+ import { rgPath } from "ripgrep";
45
+
46
+ spawn(rgPath, ["TODO", "src"], { stdio: "inherit" });
47
+ ```
48
+
49
+ ## How it works
50
+
51
+ - ripgrep is cross-compiled to `wasm32-wasip1` via [`cargo zigbuild`](https://github.com/rust-cross/cargo-zigbuild), using Zig as the C compiler/linker.
52
+ - The resulting `.wasm` is brotli-compressed and z85-encoded into `lib/_rg.wasm.mjs`, so it ships as a plain ESM module — no `.wasm` asset resolution or postinstall needed.
53
+ - On first use, the z85 blob is decoded and decompressed, then cached to the OS temp directory (`$TMPDIR/ripgrep-wasm-<hash>.wasm`). Subsequent calls (even across processes) skip decoding entirely. The z85 string itself is wrapped in a function so V8 lazy-parses it only when needed.
54
+ - The compiled `WebAssembly.Module` is memoized in-process — repeated `ripgrep()` calls only pay the compilation cost once. Fresh instances are still created per-call since WASI state (memory, file descriptors) is per-instance.
55
+ - A minimal WASI preview1 shim (`lib/_wasi.mjs`, ~20 syscalls, backed by `node:fs`) instantiates the module. Works uniformly on Node, Bun, and Deno.
56
+ - ripgrep's TTY color detection doesn't survive the WASI boundary, so `ripgrep()` auto-injects `--color=ansi` when the host stdout is a TTY and the caller hasn't picked a color mode.
57
+
58
+ ## Building from source
59
+
60
+ Requirements:
61
+
62
+ - `zig` (tested with 0.15.2)
63
+ - `rustc` + `cargo` (tested with 1.90.0)
64
+ - [`cargo-zigbuild`](https://github.com/rust-cross/cargo-zigbuild): `cargo install cargo-zigbuild`
65
+ - `rustup target add wasm32-wasip1`
66
+
67
+ Then:
68
+
69
+ ```sh
70
+ git submodule update --init --recursive
71
+ zig build # → dist/rg-wasm32-wasip1.wasm
72
+ node build.ts # inline wasm into lib/_rg.wasm.mjs
73
+ ```
74
+
75
+ Native cross-compiled binaries (macOS / Linux / Windows) are also available via `zig build native`, but they are not part of the published npm package — WASI is the only shipped flavor.
76
+
77
+ ## License
78
+
79
+ MIT. ripgrep itself is licensed under MIT / Unlicense by its authors — see [vendor/ripgrep](vendor/ripgrep).