importmap

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 19 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	CDN    string `json:"cdn,omitempty"`
	Target string `json:"target,omitempty"`
}

Config represents the configuration of an import map.

type Import

type Import struct {
	Name     string `json:"name"`
	Version  string `json:"version"`
	SubPath  string `json:"-"`
	Github   bool   `json:"-"`
	Jsr      bool   `json:"-"`
	External bool   `json:"-"`
	Dev      bool   `json:"-"`
}

Import represents an import from esm.sh CDN.

func ParseEsmPath

func ParseEsmPath(pathnameOrUrl string) (imp Import, err error)

ParseEsmPath parses an import from a pathname or URL.

func ParseSpecifier added in v0.2.0

func ParseSpecifier(specifier string) (imp Import, err error)

func (Import) RegistryPrefix

func (im Import) RegistryPrefix() string

func (Import) Specifier

func (im Import) Specifier(withVersion bool) string

type ImportMap

type ImportMap struct {
	Imports *Imports
	// contains filtered or unexported fields
}

ImportMap represents an import maps that follows the import maps specification: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script/type/importmap

func Blank

func Blank() *ImportMap

Blank creates a new import map with empty imports and scopes.

func Parse

func Parse(baseUrl *url.URL, data []byte) (im *ImportMap, err error)

Parse parses an importmap from a JSON string.

func (*ImportMap) AddImport

func (im *ImportMap) AddImport(imp ImportMeta, noSRI bool) (warnings []string, errors []error)

AddImport adds an import to the import map.

func (*ImportMap) AddImportFromSpecifier

func (im *ImportMap) AddImportFromSpecifier(specifier string, noSRI bool) (warnings []string, errors []error)

AddImportFromSpecifier adds an import from a specifier to the import map.

func (*ImportMap) Config

func (im *ImportMap) Config() Config

Config returns the config of the import map.

func (*ImportMap) FetchImportMeta

func (im *ImportMap) FetchImportMeta(imp Import) (meta ImportMeta, err error)

func (*ImportMap) FormatJSON

func (im *ImportMap) FormatJSON(indent int) string

FormatJSON formats the import map as a JSON string.

func (*ImportMap) GetScopeImports

func (im *ImportMap) GetScopeImports(scope string) (*Imports, bool)

GetScopeImports returns the imports of the given scope.

func (*ImportMap) Integrity

func (im *ImportMap) Integrity() *Imports

Integrity returns the integrity of the import map.

func (*ImportMap) MarshalJSON

func (im *ImportMap) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*ImportMap) ParseImport

func (im *ImportMap) ParseImport(specifier string) (meta ImportMeta, err error)

ParseImport gets the import metadata from a specifier. Currently, it supports the following specifiers: - npm:package[@semver][/subpath] - jsr:scope/package[@semver][/subpath] - github:owner/repo[@<branch|tag|commit>][/subpath]

func (*ImportMap) RangeScopes

func (im *ImportMap) RangeScopes(fn func(scope string, imports *Imports) bool)

RangeScopes ranges over the scopes of the import map.

func (*ImportMap) Resolve

func (im *ImportMap) Resolve(specifier string, referrer *url.URL) (string, bool)

Resolve resolves a specifier to a URL. It returns the URL and a boolean indicating if the specifier was found. This function follows the import maps specification: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script/type/importmap

func (*ImportMap) SetConfig

func (im *ImportMap) SetConfig(config Config)

SetConfig sets the config of the import map.

func (*ImportMap) SetIntegrity

func (im *ImportMap) SetIntegrity(integrity *Imports)

SetIntegrity sets the integrity of the import map.

func (*ImportMap) SetScopeImports

func (im *ImportMap) SetScopeImports(scope string, imports *Imports)

SetScopeImports sets the imports of the given scope.

type ImportMapJson

type ImportMapJson struct {
	Config    Config                       `json:"config"`
	Imports   map[string]string            `json:"imports,omitempty"`
	Scopes    map[string]map[string]string `json:"scopes,omitempty"`
	Integrity map[string]string            `json:"integrity,omitempty"`
}

ImportMapJson represents the JSON structure of an import map.

type ImportMeta

type ImportMeta struct {
	Import
	Module      string   `json:"module"`
	Integrity   string   `json:"integrity"` // "sha384-..."
	Exports     []string `json:"exports"`
	Imports     []string `json:"imports"`
	PeerImports []string `json:"peerImports"`
}

ImportMeta represents the import metadata of a import.

func (*ImportMeta) EsmSpecifier

func (imp *ImportMeta) EsmSpecifier() string

EsmSpecifier returns the esm specifier of the import meta.

func (*ImportMeta) HasExternalImports

func (imp *ImportMeta) HasExternalImports() bool

HasExternalImports returns true if the import has external imports.

type Imports

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

Imports represents a map of imports.

func (*Imports) Delete

func (i *Imports) Delete(specifier string)

Delete deletes the value of the key in the imports map.

func (*Imports) Get

func (i *Imports) Get(specifier string) (string, bool)

Get returns the value of the key in the imports map.

func (*Imports) Has

func (i *Imports) Has(specifier string) bool

Has returns true if the key is in the imports map.

func (*Imports) Keys

func (i *Imports) Keys() []string

Keys returns the keys of the imports map.

func (*Imports) Len

func (i *Imports) Len() int

Len returns the length of the imports map.

func (*Imports) Range

func (i *Imports) Range(fn func(specifier string, url string) bool)

Range ranges over the imports map.

func (*Imports) Set

func (i *Imports) Set(specifier string, url string)

Set sets the value of the key in the imports map.

type ScopeKeys

type ScopeKeys []string

func (ScopeKeys) Len

func (s ScopeKeys) Len() int

Len implements the sort.Interface interface.

func (ScopeKeys) Less

func (s ScopeKeys) Less(i, j int) bool

Less implements the sort.Interface interface. sort by the number of slashes in the key

func (ScopeKeys) Swap

func (s ScopeKeys) Swap(i, j int)

Swap implements the sort.Interface interface.

Jump to

Keyboard shortcuts

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