require

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: MIT, MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	InvalidModuleError     = errors.New("Invalid module")
	IllegalModuleNameError = errors.New("Illegal module name")

	ModuleFileDoesNotExistError = errors.New("module file does not exist")
)

Functions

func DefaultSourceLoader

func DefaultSourceLoader(filename string) ([]byte, error)

DefaultSourceLoader reads module files from the host filesystem.

func RegisterNativeModule

func RegisterNativeModule(name string, loader ModuleLoader)

func Require

func Require(runtime *js.Runtime, name string) js.Value

Types

type ModuleLoader

type ModuleLoader func(*js.Runtime, *js.Object)

type Option

type Option func(*Registry)

func WithGlobalFolders

func WithGlobalFolders(globalFolders ...string) Option

WithGlobalFolders appends paths searched for modules not found elsewhere.

func WithLoader

func WithLoader(srcLoader SourceLoader) Option

WithLoader configures the source and external source-map loader used by require.

type Registry

type Registry struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Registry contains a cache of compiled modules which can be shared by runtimes.

func NewRegistry

func NewRegistry(opts ...Option) *Registry

func NewRegistryWithLoader

func NewRegistryWithLoader(srcLoader SourceLoader) *Registry

func (*Registry) Enable

func (r *Registry) Enable(runtime *js.Runtime) *RequireModule

Enable adds require() to runtime.

func (*Registry) RegisterNativeModule

func (r *Registry) RegisterNativeModule(name string, loader ModuleLoader)

type RequireModule

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

func (*RequireModule) Require

func (r *RequireModule) Require(p string) (js.Value, error)

Require imports a module from Go code.

type SourceLoader

type SourceLoader func(path string) ([]byte, error)

SourceLoader returns file data for a path. It must return ModuleFileDoesNotExistError when the path does not exist or is a directory.

Jump to

Keyboard shortcuts

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