fix: add rg to path (#146)

This commit is contained in:
Charles Packer
2025-12-01 22:29:05 -08:00
committed by GitHub
parent f1f507a45d
commit bc558e5c5b
3 changed files with 47 additions and 3 deletions

View File

@@ -0,0 +1,42 @@
/**
* Shell environment utilities
* Provides enhanced environment variables for shell execution,
* including bundled tools like ripgrep in PATH.
*/
import { createRequire } from "node:module";
import * as path from "node:path";
import { fileURLToPath } from "node:url";
/**
* Get the directory containing the bundled ripgrep binary.
* Returns undefined if @vscode/ripgrep is not installed.
*/
function getRipgrepBinDir(): string | undefined {
try {
const __filename = fileURLToPath(import.meta.url);
const require = createRequire(__filename);
const rgPackage = require("@vscode/ripgrep");
// rgPath is the full path to the binary, we want the directory
return path.dirname(rgPackage.rgPath);
} catch (_error) {
return undefined;
}
}
/**
* Get enhanced environment variables for shell execution.
* Includes bundled tools (like ripgrep) in PATH.
*/
export function getShellEnv(): NodeJS.ProcessEnv {
const env = { ...process.env };
// Add ripgrep bin directory to PATH if available
const rgBinDir = getRipgrepBinDir();
if (rgBinDir) {
const currentPath = env.PATH || "";
env.PATH = `${rgBinDir}${path.delimiter}${currentPath}`;
}
return env;
}