Skip to main content

resolve_program

Function resolve_program 

Source
pub fn resolve_program(program: &str, path: &OsStr) -> Option<PathBuf>
Expand description

Find program on path, mirroring how the shell would resolve it.

This is a correctness requirement, not an optimization: on Unix Command::new("tsc") resolves through execvp, which searches the parent’s environ and ignores the PATH we hand the child — so without resolving here ourselves, a node_modules/.bin program would not be found at all.

Costs a stat and a 4-byte read per candidate until a hit (typically one for a project-local bin, three for node), which is noise next to the fork and shell startup it replaces. Deliberately uncached: a cache would have to be invalidated on every install, and there is nothing to win.