Documentation
¶
Overview ¶
Package resolver provides the shared node_modules package resolution used by the bundler (bare import specifiers) and the docs plugin (npm docs themes). Resolution mirrors Node's `exports`/`module`/`main` fallback: a package's entry file is picked from package.json `exports` (the `import`/`default` condition) when present, then `module`, then `main`, then a top-level index.* file, by walking up the directory tree from a start dir looking for node_modules/<pkg>. Modern ESM packages (e.g. Radix UI) ship `.mjs` with an `exports` map, both of which are handled here.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NodeModule ¶
NodeModule resolves a bare npm package specifier ("formslib", "@scope/formslib", "@scope/formslib/subpath") by walking up from startDir looking for node_modules/pkg. It returns the absolute path to the package entry file, or "" if the package (or an entry file) cannot be found.
func NodeModuleDir ¶
NodeModuleDir resolves a bare npm specifier that may include a subpath, e.g. "formslib", "@scope/formslib", or "formslib/styles/x.css". Kept as the public entry point used by the plugin API.
func PackageDir ¶
PackageDir resolves a package directory's entry file: package.json `exports` (import/default), then `module`, then `main`, then a top-level index.* - or "" if none exist. Kept for callers that already have a package directory.
Types ¶
type PkgJSON ¶
type PkgJSON struct {
Main string `json:"main"`
Module string `json:"module"`
Exports json.RawMessage `json:"exports"`
}
PkgJSON is the subset of package.json the resolver reads to find a package entry file. Exports is kept raw because it may be a string, a conditions object, or a subpath map.