Skip to main content

package_dir

Function package_dir 

Source
pub fn package_dir(from_dir: &Path, name: &str) -> Result<PathBuf>
Expand description

Find an installed package by walking node_modules/<name> upward from from_dir (Node’s module-resolution order), returning the first directory that exists. name may be scoped (@scope/pkg). Errors when the package is installed nowhere on the way up — run npm install / web-modules ci first.

The ascent runs to the filesystem root: a same-named package in a node_modules above the project (a parent workspace, ~/node_modules) is found and used. When the starting directory is untrusted, prefer package_dir_within to stop the ascent at the project boundary.