pkgmap

package
v1.169.2 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pkgmap turns a JavaScript project's package.json and lockfile into the imports map a site's _build.json declares (#2785): each package the entries import at its locked version on esm.sh, each imported path inside a package as its own entry, and every package's locked peers pinned through ?deps= so that one copy of React loads. It also refuses a map that would load two copies of a package only one copy of which may load.

Index

Constants

View Source
const CDN = "https://esm.sh/"

CDN is where a generated map loads packages from.

Variables

View Source
var DefaultSingletons = []string{"react", "react-dom"}

DefaultSingletons are the packages only one copy of which may load.

Functions

func CheckSingletons

func CheckSingletons(ctx context.Context, imports map[string]string, singletons []string, lock *Lock, extra Peers) ([]string, error)

CheckSingletons refuses an imports map that would load two copies of a package only one copy of which may load (#2785): two URLs naming it at different versions, a ?deps= pin of another version, or an esm.sh URL for a package that peers on it without pinning it, which esm.sh then builds against a copy of its own. Peers are read from the lockfile, else from extra; a package whose peers neither knows is not judged on that last rule.

func PackageOf

func PackageOf(spec string) (pkg, sub string)

PackageOf splits a bare specifier into its package and the path inside it.

Types

type Generated

type Generated struct {
	Imports map[string]string `json:"imports"`
	// Lockfile is the file versions were read from.
	Lockfile string `json:"lockfile"`
	// Missing are the specifiers whose package the lockfile does not lock.
	Missing []string `json:"missing"`
}

Generated is a proposed imports map and what could not go in it.

func Generate

func Generate(ctx context.Context, specifiers []string, lock *Lock, extra Peers) (*Generated, error)

Generate maps every bare specifier to its locked version on the CDN, each path inside a package its own entry, and every package's locked peers pinned through ?deps= (#2785).

type Lock

type Lock struct {
	// File is the lockfile it was read from, "" for none.
	File     string
	Packages map[string]Package
}

Lock is what a project's lockfile says about its packages, by name.

func ReadLock

func ReadLock(src fs.FS) (*Lock, error)

ReadLock reads the project's lockfile from the root of a tree.

type Package

type Package struct {
	Version string
	// Peers are its peer dependencies; nil when the lockfile does not say.
	Peers []string
}

Package is one locked package.

type Peers

type Peers interface {
	PeersOf(ctx context.Context, pkg, version string) ([]string, error)
}

Peers reads what a package version peers on when its lockfile does not say: the registry's record of it.

type Registry

type Registry struct {
	Fetch func(ctx context.Context, url string) ([]byte, string, error)
}

Registry reads peer dependencies from the npm registry through a fetcher.

func (Registry) PeersOf

func (r Registry) PeersOf(ctx context.Context, pkg, version string) ([]string, error)

PeersOf reads one version's peerDependencies.

Jump to

Keyboard shortcuts

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