Skip to main content

Module resolve

Module resolve 

Source
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 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.
package_file
Resolve <name>/<subpath> to a real file inside the installed package.