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 ¶
const CDN = "https://esm.sh/"
CDN is where a generated map loads packages from.
Variables ¶
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.
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.
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.
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 ¶
Peers reads what a package version peers on when its lockfile does not say: the registry's record of it.