rt

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package rt provides a JavaScript runtime for hydris plugins using goja.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindDataDir

func FindDataDir(path string) string

FindDataDir walks up from path to find the directory containing package.json. Returns empty string if not found.

func RunPlugin

func RunPlugin(ctx context.Context, bundlePath string, dataDir string) error

RunPlugin runs a JS bundle in goja with automatic restart on crash. Blocks until ctx is cancelled. Suitable for both CLI and in-process (android) use. dataDir is the plugin source directory (containing package.json) used to sandbox file access; pass "" to disable.

func RunPluginEnv

func RunPluginEnv(ctx context.Context, bundlePath, dataDir, serverURL string) error

RunPluginEnv is like RunPlugin but sets HYDRIS_SERVER first.

Types

type Runtime

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

Runtime wraps a goja event loop with the globals needed by hydris plugins.

func New

func New(dataDir string) *Runtime

New creates a Runtime. dataDir is the plugin's source directory (containing package.json) used to sandbox file access. The event loop provides setTimeout/setInterval, console, and CommonJS require out of the box via goja_nodejs. Node.js-compatible http2, events, stream modules are registered so that connect-rpc bundles work without modification.

func (*Runtime) RunFile

func (r *Runtime) RunFile(ctx context.Context, path string) error

RunFile reads path and executes it. Blocks until ctx is cancelled.

func (*Runtime) RunScript

func (r *Runtime) RunScript(ctx context.Context, name, src string) error

RunScript executes src inside the event loop. Uses Start() so the loop stays alive for async operations (fetch, promises). Blocks until ctx is cancelled.

func (*Runtime) Stop

func (r *Runtime) Stop()

Stop terminates the event loop.

Jump to

Keyboard shortcuts

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