resolver

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

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 Exists

func Exists(path string) bool

Exists reports whether a file or directory exists at path.

func NodeModule

func NodeModule(startDir, spec string) string

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

func NodeModuleDir(startDir, spec string) string

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

func PackageDir(pkgDir string) string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL