Expand description
Locate files inside an installed dependency under node_modules/.
package_dir finds node_modules/<name> by walking up from a starting
directory, the way Node resolves a bare specifier; package_file then maps a
<name>/<subpath> reference to the real file on disk, honoring the package’s
exports (and its encapsulation) when declared and addressing the file directly
when not. Every result is confined to the resolved package directory via
crate::path_safety — nothing here writes, fetches over the network, or
resolves a reference outside the package it located.
Functions§
- package_
dir - Find an installed package by walking
node_modules/<name>upward fromfrom_dir(Node’s module-resolution order), returning the first directory that exists.namemay be scoped (@scope/pkg). Errors when the package is installed nowhere on the way up — runnpm install/web-modules cifirst. - package_
dir_ within package_dir, but the ascent stops atboundary(inclusive): a package installed only above it is not found. The boundary is canonicalized once; each candidate level is compared canonically, so a symlinked start directory cannot slip past it.- package_
file - Resolve
<name>/<subpath>to a real file inside the installed package. - package_
file_ within package_file, with the package lookup bounded atboundary(package_dir_within).