Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsStdModule ¶
IsStdModule returns `true` if the module name given is part of the standard library, false otherwise. Useful for checking the referrer (importing module), to restrict access to internals.
func ScriptBase ¶
ScriptBase returns a base location representing the filesystem under the path given. It is so called because it's used to create the initial base for resolving modules relative to the script being run.
Types ¶
type Candidate ¶
Candidate is a path that was considered when resolving an import, and the explanation (resolution rule) for why it was considered.
type FileImporter ¶
type FileImporter struct {
// contains filtered or unexported fields
}
FileImporter is an importer sourcing from a filesystem. Modules are expected to be arranged at the root of the filesystem, in the directory structure implied by the import path. A specifier `foo/bar` will be resolved to (in the order attempted):
- `/foo/bar`
- `/foo/bar.{js,mjs}`
- `/foo/bar/index.{js,mjs}
func NewFileImporter ¶
func NewFileImporter(vfs vfs.FileSystem) *FileImporter
NewFileImporter constructs a FileImport given a filesystem
func (*FileImporter) Import ¶
func (fi *FileImporter) Import(base vfs.Location, specifier, referrer string) ([]byte, vfs.Location, []Candidate)
Import implements importer. Note that the file import only ever cares to look in the root of the given filesystem. It doesn't care where the importing module is located.
type Importer ¶
type Importer interface { // Resolve a specifier (e.g., `my-module/foo') to a specific path // and file contents. Also returns a list of the interpretations // of the specifier attempted, including that returned. Import(base vfs.Location, specifier, referrer string) (data []byte, resolved vfs.Location, candidates []Candidate) }
Importer is a object resolving a import to actual JS code.
type Loader ¶
type Loader interface {
LoadModule(scriptName string, code string, resolve v8.ModuleResolverCallback) error
}
Loader is an object able to load a ES 2015 module.
type MagicImporter ¶
type MagicImporter struct { Specifier string Generate func(vfs.Location) ([]byte, string) Public bool // can this be imported from any module? }
MagicImporter handles importing "magic" modules, that is modules that are calculated wherever they are imported.
type NodeImporter ¶
type NodeImporter struct {
// contains filtered or unexported fields
}
NodeImporter is an implementation of Importer that uses a resolution algorithm adapted from Node.JS's, in order to support modules installed with npm.
func NewNodeImporter ¶
func NewNodeImporter(vfs vfs.FileSystem) *NodeImporter
NewNodeImporter constructs a NodeImporter using the given filesystem
type Relative ¶
type Relative struct { }
Relative resolves specifiers that start with './' or '../', by looking for a file relative to the importing module (as given by the base argument).
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver implements module resolution by deferring to the set of importers that it's given.
func NewResolver ¶
NewResolver creates a new Resolver.
func (Resolver) ResolveModule ¶
ResolveModule imports the specifier from an import statement located in the referrer module.
func (*Resolver) SetRecorder ¶
SetRecorder instructs Resolver to record actions in the specified recoder. Call with nil to disable.
type StaticImporter ¶
StaticImporter is an importer mapping an import specifier to a static string.
type StdImporter ¶
type StdImporter struct { // PublicModules are modules users are allowed to import. PublicModules []string }
StdImporter is the standard library importer.