This `ripgrep` npm package provides the powerful command-line utility `ripgrep` in a fully cross-platform, dependency-free manner by compiling it to WebAssembly (WASM). As of version 0.3.1, it offers programmatic access to `ripgrep`'s core functionality, suitable for Node.js, Bun, Deno, and even bundler-friendly browser environments without requiring native binaries or post-install scripts. The package embeds the WASM module as a z85+brotli encoded string and leverages WASI for execution, defaulting to Node.js's built-in `node:wasi` for optimal performance when available. Its key differentiator is providing `ripgrep`'s capabilities entirely within the JavaScript ecosystem, making it a drop-in programmatic replacement for native `ripgrep` spawns, with the WASM module dynamically cached to the OS temp directory for subsequent fast access.
npm install ripgrepVerified import paths — ran on the pinned version, not inferred.
Demonstrates programmatic usage of `ripgrep` to search a temporary file, capturing its output, and an alternative method using `rgPath` with `node:child_process.spawn`.
Benchmark against native `ripgrep` for critical performance paths. Optimize search patterns or file sets as needed.
Explicitly pass `--color=always` or `--color=ansi` in the `args` array to force colored output when using custom streams.
Ensure custom `stdout`/`stderr` streams passed in options have a valid `fd` property, or use `buffer: true` if streams are not strictly required.
Ensure the runtime environment allows writing to the standard temporary directory. No direct configuration option is available to change the cache path.
Always explicitly provide the directory to search (e.g., `['pattern', './']`) or pass `stdio: ['ignore', 'pipe', 'pipe']` to `spawn` options to prevent `ripgrep` from waiting on stdin.
Ensure you are running on a modern Node.js (16+ is recommended for `node:wasi`), Bun, Deno, or a browser with full WebAssembly/WASI support. Update your runtime or bundler configuration if targeting older environments.
Use ESM `import { ripgrep } from 'ripgrep';` in your module. If you must use CommonJS, convert your file to an ES Module (e.g., by adding `"type": "module"` to `package.json` or changing file extension to `.mjs`), or use dynamic import: `const { ripgrep } = await import('ripgrep');`.When calling `ripgrep(args, options)`, set `buffer: true` in options to capture `stdout` and `stderr` as strings in the returned object `{ code, stdout, stderr }`. This will allow you to inspect `stderr` for `ripgrep`'s specific error messages. Also, check `preopens` options if dealing with files outside the current working directory.No dependency data recorded yet.