resolve

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Copyright © 2026 Benny Powers <web@bennypowers.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Copyright © 2026 Benny Powers <web@bennypowers.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Copyright © 2026 Benny Powers <web@bennypowers.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Package resolve provides interfaces and utilities for import map resolution.

Copyright © 2026 Benny Powers <web@bennypowers.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Copyright © 2026 Benny Powers <web@bennypowers.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

View Source
const DefaultLocalTemplate = "/node_modules/{package}/{path}"

DefaultLocalTemplate is the default template for local resolution.

Variables

This section is empty.

Functions

func FindWorkspaceRoot

func FindWorkspaceRoot(fs fs.FileSystem, startDir string) string

FindWorkspaceRoot walks up the directory tree to find the workspace root. Returns the directory containing node_modules, workspace configuration, or .git.

func SplitPackageName

func SplitPackageName(pkg string) (name, scope string)

SplitPackageName splits a package name into name and scope. For "@scope/name" returns ("name", "scope"). For "name" returns ("name", "").

func ToWebPath

func ToWebPath(rootDir, fullPath string) string

ToWebPath converts a filesystem path relative to rootDir into a web path. e.g., "node_modules/lit" -> "/node_modules/lit"

Types

type DependencyGraph added in v0.0.2

type DependencyGraph struct {
	// contains filtered or unexported fields
}

DependencyGraph tracks package dependencies for incremental updates. Built during resolution and cached for efficient dependent discovery.

func NewDependencyGraph added in v0.0.2

func NewDependencyGraph() *DependencyGraph

NewDependencyGraph creates a new empty dependency graph.

func (*DependencyGraph) AddDependency added in v0.0.2

func (g *DependencyGraph) AddDependency(pkg, dep string)

AddDependency records that pkg depends on dep. Updates both dependsOn and dependents maps.

func (*DependencyGraph) AddWorkspacePackage added in v0.0.2

func (g *DependencyGraph) AddWorkspacePackage(name string)

AddWorkspacePackage marks a package as a workspace package.

func (*DependencyGraph) Clone added in v0.0.2

func (g *DependencyGraph) Clone() *DependencyGraph

Clone creates a deep copy of the dependency graph.

func (*DependencyGraph) Dependents added in v0.0.2

func (g *DependencyGraph) Dependents(pkg string) []string

Dependents returns all packages that directly depend on pkg.

func (*DependencyGraph) IsWorkspacePackage added in v0.0.2

func (g *DependencyGraph) IsWorkspacePackage(name string) bool

IsWorkspacePackage returns true if the package is a workspace package.

func (*DependencyGraph) PackagePath added in v0.0.2

func (g *DependencyGraph) PackagePath(pkg string) string

PackagePath returns the filesystem path for a package, or empty string if not found.

func (*DependencyGraph) RemovePackage added in v0.0.2

func (g *DependencyGraph) RemovePackage(pkg string) []string

RemovePackage removes a package and all its edges from the graph. Returns the packages that were dependents of the removed package.

func (*DependencyGraph) ScopeKey added in v0.0.2

func (g *DependencyGraph) ScopeKey(pkg string) string

ScopeKey returns the scope key for a package, or empty string if not found.

func (*DependencyGraph) SetPackagePath added in v0.0.2

func (g *DependencyGraph) SetPackagePath(pkg, path string)

SetPackagePath records the filesystem path for a package.

func (*DependencyGraph) SetScopeKey added in v0.0.2

func (g *DependencyGraph) SetScopeKey(pkg, scopeKey string)

SetScopeKey records the import map scope key for a package.

func (*DependencyGraph) TransitiveDependents added in v0.0.2

func (g *DependencyGraph) TransitiveDependents(pkg string) []string

TransitiveDependents returns all packages that directly or indirectly depend on pkg. Uses breadth-first traversal to find all dependents.

type IncrementalResult added in v0.0.2

type IncrementalResult struct {
	// ImportMap is the resolved import map.
	ImportMap *importmap.ImportMap

	// DependencyGraph tracks package dependencies for future incremental updates.
	DependencyGraph *DependencyGraph
}

IncrementalResult contains both the new import map and dependency graph.

type IncrementalUpdate added in v0.0.2

type IncrementalUpdate struct {
	// ChangedPackages lists packages whose package.json files changed.
	// Can include both workspace packages and node_modules packages.
	// Use the package name (e.g., "@myorg/core" or "lit").
	ChangedPackages []string

	// PreviousMap is the import map to update incrementally.
	// If nil, a full resolution is performed.
	PreviousMap *importmap.ImportMap

	// PreviousGraph is the dependency graph from the previous resolution.
	// If nil, dependents cannot be computed and a full resolution is used.
	PreviousGraph *DependencyGraph
}

IncrementalUpdate describes which packages changed for incremental resolution.

type Logger

type Logger interface {
	Warning(format string, args ...any)
	Debug(format string, args ...any)
}

Logger is an interface for logging messages during resolution.

type Resolver

type Resolver interface {
	// Resolve generates an ImportMap for a project rooted at the given directory.
	Resolve(rootDir string) (*importmap.ImportMap, error)
}

Resolver generates import map entries for packages.

type Template

type Template struct {
	// contains filtered or unexported fields
}

Template represents a URL template with variable placeholders. Supported variables:

  • {package} - Full package name (e.g., "@scope/name" or "name")
  • {name} - Package name without scope
  • {scope} - Scope without @ prefix (empty for unscoped)
  • {version} - Resolved version (for CDN resolution)
  • {path} - Relative path within the package

func ParseTemplate

func ParseTemplate(pattern string) (*Template, error)

ParseTemplate parses a URL template pattern.

func (*Template) Expand

func (t *Template) Expand(pkg, version, path string) string

Expand substitutes variables in the template with actual values.

func (*Template) HasVersion

func (t *Template) HasVersion() bool

HasVersion returns true if the template contains a {version} variable. Templates with version variables require lockfile resolution (CDN mode).

func (*Template) Pattern

func (t *Template) Pattern() string

Pattern returns the original template pattern.

func (*Template) Variables

func (t *Template) Variables() []string

Variables returns the list of variables used in the template.

type WorkspacePackage

type WorkspacePackage struct {
	Name string // Package name from package.json
	Path string // Absolute path to package directory
}

WorkspacePackage represents a package in a monorepo workspace.

func DiscoverWorkspacePackages added in v0.0.2

func DiscoverWorkspacePackages(fsys fs.FileSystem, rootDir string) ([]WorkspacePackage, error)

DiscoverWorkspacePackages finds all workspace packages based on the workspaces field in the root package.json. Returns nil if no workspaces are defined.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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