resolver

package
v0.4.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 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 `module`/`main`/index fallback: a package's entry file is picked from package.json `module` (preferred) or `main`, then from a top-level index.* file, by walking up the directory tree from a start dir looking for node_modules/<pkg>.

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, pkg string) string

NodeModule resolves a bare npm package specifier ("formslib", "@scope/formslib") 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. startDir may be an absolute or root-relative path.

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". For a bare package name it returns the package entry file (via PackageDir); when a subpath is present it returns the joined subpath. It walks up from startDir looking for node_modules/<pkg>, returning "" when nothing resolves.

func PackageDir

func PackageDir(pkgDir string) string

PackageDir resolves a package directory's entry file: package.json `module` (preferred), then `main`, then a top-level index.* — or "" if none exist.

Types

type PkgJSON

type PkgJSON struct {
	Main   string `json:"main"`
	Module string `json:"module"`
}

PkgJSON is the subset of package.json the resolver reads to find a package entry file.

Jump to

Keyboard shortcuts

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