wave

package
v0.85.0-pre.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Overview

Package wave provides runtime services for Wave applications. Build-time and dev-time functionality is in the wave/tooling subpackage.

Index

Constants

View Source
const (
	PrehashedDirname = "prehashed"
	NohashDirname    = "__nohash"

	HashedOutputPrefix           = "vorma_out_"
	HashedOutputPrefixNoTrailing = "vorma_out"

	NormalCSSBaseName    = "vorma_internal_normal.css"
	NormalCSSGlobPattern = HashedOutputPrefix + "vorma_internal_normal_*.css"

	GeneratedTSFileName   = "index.ts"
	PublicFileMapTSName   = "filemap.ts"
	PublicFileMapJSONName = "filemap.json"
	FileMapJSGlobPattern  = HashedOutputPrefix + "vorma_internal_public_filemap_*.js"
)

Public constants

View Source
const (
	CriticalCSSElementID = "wave-critical-css"
	StyleSheetElementID  = "wave-normal-css"
)

Variables

View Source
var MustGetAppPort = MustGetPort

MustGetAppPort is an alias for MustGetPort for backward compatibility.

View Source
var RelPaths = relPaths{}

RelPaths provides fs.FS-relative paths (no leading slash, forward slashes).

Functions

func GetIsDev

func GetIsDev() bool

func GetPort

func GetPort() int

func GetRefreshServerPort

func GetRefreshServerPort() int

func MustGetPort

func MustGetPort() int

MustGetPort returns the application port. In dev mode, finds a free port if needed.

func RefreshScriptInner

func RefreshScriptInner(port int) string

RefreshScriptInner returns the raw JavaScript for the refresh script. Exported so devserver can serve it via HTTP endpoint.

func SetModeToDev

func SetModeToDev()

func SetPort

func SetPort(port int)

func SetRefreshServerPort

func SetRefreshServerPort(port int)

Types

type CSSEntryFiles

type CSSEntryFiles struct {
	Critical    string `json:"Critical,omitempty"`
	NonCritical string `json:"NonCritical,omitempty"`
}

type Config

type Config struct {
	// Required -- the bytes of your wave.config.json file.
	// You can use go:embed or just read the file in yourself.
	// Using go:embed is recommended for simpler deployments and improved performance.
	WaveConfigJSON []byte

	// Required -- be sure to pass in a file system that has your
	// <distDir>/static directory as its ROOT.
	// If you are using an embedded filesystem, you may need to use fs.Sub to get the
	// correct subdirectory.
	// Using go:embed is recommended for simpler deployments and improved performance.
	DistStaticFS fs.FS

	// Optional -- a logger instance.
	// If not provided, a default logger will be created that writes to standard out.
	Logger *slog.Logger
}

Config configures Wave initialization.

type CoreConfig

type CoreConfig struct {
	ConfigLocation    string          `json:"ConfigLocation,omitempty"`
	DevBuildHook      string          `json:"DevBuildHook,omitempty"`
	ProdBuildHook     string          `json:"ProdBuildHook,omitempty"`
	MainAppEntry      string          `json:"MainAppEntry"`
	DistDir           string          `json:"DistDir"`
	StaticAssetDirs   StaticAssetDirs `json:"StaticAssetDirs"`
	CSSEntryFiles     CSSEntryFiles   `json:"CSSEntryFiles,omitempty"`
	PublicPathPrefix  string          `json:"PublicPathPrefix,omitempty"`
	ServerOnlyMode    bool            `json:"ServerOnlyMode,omitempty"`
	SequentialGoBuild bool            `json:"SequentialGoBuild,omitempty"`
}

type DistLayout

type DistLayout struct {
	Root string
}

DistLayout provides computed paths for the dist directory structure.

func (DistLayout) Binary

func (d DistLayout) Binary() string

func (DistLayout) CriticalCSS

func (d DistLayout) CriticalCSS() string

func (DistLayout) Internal

func (d DistLayout) Internal() string

func (DistLayout) KeepFile

func (d DistLayout) KeepFile() string

func (DistLayout) NormalCSSRef

func (d DistLayout) NormalCSSRef() string

func (DistLayout) PrivateFileMapGob

func (d DistLayout) PrivateFileMapGob() string

func (DistLayout) PublicFileMapGob

func (d DistLayout) PublicFileMapGob() string

func (DistLayout) PublicFileMapRef

func (d DistLayout) PublicFileMapRef() string

func (DistLayout) Static

func (d DistLayout) Static() string

func (DistLayout) StaticAssets

func (d DistLayout) StaticAssets() string

func (DistLayout) StaticPrivate

func (d DistLayout) StaticPrivate() string

func (DistLayout) StaticPublic

func (d DistLayout) StaticPublic() string

type FileMap

type FileMap map[string]FileVal

func (FileMap) Lookup

func (fm FileMap) Lookup(original, prefix string) (url string, found bool)

type FileVal

type FileVal struct {
	DistName    string
	ContentHash string
	IsPrehashed bool
}

type HookContext

type HookContext struct {
	// FilePath is the absolute path of the changed file.
	FilePath string
	// AppStoppedForBatch is true when the app has been stopped as part of batch
	// processing (e.g., a Go file changed in the same batch). When true, HTTP
	// endpoints on the running app cannot be called.
	AppStoppedForBatch bool
}

HookContext provides context to callbacks during file change handling.

type OnChangeHook

type OnChangeHook struct {
	// Cmd is a shell command to run. Can be any shell command or "DevBuildHook"
	// to run the configured dev build hook.
	Cmd string `json:"Cmd,omitempty"`
	// Timing controls when the hook runs relative to Wave's rebuild process.
	Timing Timing `json:"Timing,omitempty"`
	// Exclude contains glob patterns for files to exclude from triggering this hook.
	Exclude []string `json:"Exclude,omitempty"`
	// Callback is a Go function to run. Framework use only (not JSON-configurable).
	// If the callback returns a non-nil RefreshAction, it controls what Wave does
	// after all hooks complete. Multiple RefreshActions are merged with OR semantics.
	Callback func(*HookContext) (*RefreshAction, error) `json:"-"`
}

OnChangeHook defines an action to run when a watched file changes.

type ParsedConfig

type ParsedConfig struct {
	Core  *CoreConfig  `json:"Core"`
	Vite  *ViteConfig  `json:"Vite,omitempty"`
	Watch *WatchConfig `json:"Watch,omitempty"`

	Dist DistLayout `json:"-"`

	FrameworkWatchPatterns       []WatchedFile               `json:"-"`
	FrameworkIgnoredPatterns     []string                    `json:"-"`
	FrameworkPublicFileMapOutDir string                      `json:"-"`
	FrameworkSchemaExtensions    map[string]jsonschema.Entry `json:"-"`
	FrameworkDevBuildHook        string                      `json:"-"`
	FrameworkProdBuildHook       string                      `json:"-"`
}

ParsedConfig is the parsed and validated wave.config.json

func ParseConfig

func ParseConfig(data []byte) (*ParsedConfig, error)

ParseConfig parses wave.config.json bytes into a ParsedConfig. This performs minimal validation to prevent nil pointer panics during parsing. Full validation of required fields should be done at build time via tooling.ValidateConfig.

func ParseConfigFile

func ParseConfigFile(path string) (*ParsedConfig, error)

ParseConfigFile reads and parses a config file

func (*ParsedConfig) CriticalCSSEntry

func (c *ParsedConfig) CriticalCSSEntry() string

func (*ParsedConfig) HealthcheckEndpoint

func (c *ParsedConfig) HealthcheckEndpoint() string

func (*ParsedConfig) NonCriticalCSSEntry

func (c *ParsedConfig) NonCriticalCSSEntry() string

func (*ParsedConfig) PublicPathPrefix

func (c *ParsedConfig) PublicPathPrefix() string

func (*ParsedConfig) UsingBrowser

func (c *ParsedConfig) UsingBrowser() bool

func (*ParsedConfig) UsingVite

func (c *ParsedConfig) UsingVite() bool

func (*ParsedConfig) ViteManifestPath

func (c *ParsedConfig) ViteManifestPath() string

func (*ParsedConfig) WatchRoot

func (c *ParsedConfig) WatchRoot() string

type RefreshAction

type RefreshAction struct {
	// ReloadBrowser triggers a browser reload via WebSocket.
	// Ignored if TriggerRestart is true.
	ReloadBrowser bool
	// WaitForApp polls the app's healthcheck before reloading the browser.
	// Ignored if TriggerRestart is true.
	WaitForApp bool
	// WaitForVite waits for Vite dev server to be ready before reloading.
	// Ignored if TriggerRestart is true.
	WaitForVite bool
	// TriggerRestart causes Wave to restart the app process.
	// When true, ReloadBrowser/WaitForApp/WaitForVite are ignored.
	TriggerRestart bool
	// RecompileGo recompiles the Go binary before restart.
	// Only relevant when TriggerRestart is true.
	RecompileGo bool
}

RefreshAction specifies what Wave should do after a callback completes. Multiple RefreshActions from different hooks are merged with OR semantics.

func (RefreshAction) IsZero

func (r RefreshAction) IsZero() bool

IsZero returns true if this RefreshAction specifies no action.

func (RefreshAction) Merge

func (r RefreshAction) Merge(other RefreshAction) RefreshAction

Merge combines two RefreshActions with OR semantics. TriggerRestart takes precedence over browser reload.

type SortedHooks

type SortedHooks struct {
	Pre              []OnChangeHook
	Concurrent       []OnChangeHook
	ConcurrentNoWait []OnChangeHook
	Post             []OnChangeHook
}

type StaticAssetDirs

type StaticAssetDirs struct {
	Private string `json:"Private"`
	Public  string `json:"Public"`
}

type Timing

type Timing string

Timing represents when an OnChangeHook runs relative to Wave's rebuild process

const (
	// Blocks build, use when build depends on hook output (e.g., code generation)
	OnChangeStrategyPre Timing = "pre"
	// Blocks reload, use when hook depends on build output (e.g., something that reads compiled artifacts)
	OnChangeStrategyPost Timing = "post"
	// Runs during build, blocks reload, saves time when hook and build are independent
	OnChangeStrategyConcurrent Timing = "concurrent"
	// Fire-and-forget, blocks nothing
	OnChangeStrategyConcurrentNoWait Timing = "concurrent-no-wait"
)

type ViteConfig

type ViteConfig struct {
	JSPackageManagerBaseCmd string `json:"JSPackageManagerBaseCmd"`
	JSPackageManagerCmdDir  string `json:"JSPackageManagerCmdDir,omitempty"`
	DefaultPort             int    `json:"DefaultPort,omitempty"`
	ViteConfigFile          string `json:"ViteConfigFile,omitempty"`
}

type WatchConfig

type WatchConfig struct {
	WatchRoot           string        `json:"WatchRoot,omitempty"`
	HealthcheckEndpoint string        `json:"HealthcheckEndpoint,omitempty"`
	Include             []WatchedFile `json:"Include,omitempty"`
	Exclude             struct {
		Dirs  []string `json:"Dirs,omitempty"`
		Files []string `json:"Files,omitempty"`
	} `json:"Exclude,omitempty"`
}

type WatchedFile

type WatchedFile struct {
	Pattern                            string         `json:"Pattern"`
	OnChangeHooks                      []OnChangeHook `json:"OnChangeHooks,omitempty"`
	RecompileGoBinary                  bool           `json:"RecompileGoBinary,omitempty"`
	RestartApp                         bool           `json:"RestartApp,omitempty"`
	OnlyRunClientDefinedRevalidateFunc bool           `json:"OnlyRunClientDefinedRevalidateFunc,omitempty"`
	RunOnChangeOnly                    bool           `json:"RunOnChangeOnly,omitempty"`
	SkipRebuildingNotification         bool           `json:"SkipRebuildingNotification,omitempty"`
	TreatAsNonGo                       bool           `json:"TreatAsNonGo,omitempty"`
	SortedHooks                        *SortedHooks   `json:"-"`
}

func (*WatchedFile) Sort

func (wf *WatchedFile) Sort()

type Wave

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

Wave provides runtime services for Wave applications.

func New

func New(c Config) *Wave

func (*Wave) AddFrameworkWatchPatterns

func (w *Wave) AddFrameworkWatchPatterns(patterns []WatchedFile)

AddFrameworkWatchPatterns adds watch patterns for use during development.

func (*Wave) AddIgnoredPatterns

func (w *Wave) AddIgnoredPatterns(patterns []string)

AddIgnoredPatterns adds glob patterns for files/directories to ignore during watching.

func (*Wave) FaviconRedirect

func (w *Wave) FaviconRedirect() middleware.Middleware

func (*Wave) GetBaseFS

func (w *Wave) GetBaseFS() (fs.FS, error)

func (*Wave) GetConfigFile

func (w *Wave) GetConfigFile() string

func (*Wave) GetCriticalCSS

func (w *Wave) GetCriticalCSS() template.CSS

func (*Wave) GetCriticalCSSElementID

func (w *Wave) GetCriticalCSSElementID() string

func (*Wave) GetCriticalCSSStyleElement

func (w *Wave) GetCriticalCSSStyleElement() template.HTML

func (*Wave) GetCriticalCSSStyleElementSha256Hash

func (w *Wave) GetCriticalCSSStyleElementSha256Hash() string

func (*Wave) GetDistDir

func (w *Wave) GetDistDir() string

func (*Wave) GetIsDev

func (w *Wave) GetIsDev() bool

GetIsDev returns true if running in development mode.

func (*Wave) GetParsedConfig

func (w *Wave) GetParsedConfig() *ParsedConfig

GetParsedConfig returns the parsed configuration for use by tooling. This should only be used by build-time tooling, not at runtime.

func (*Wave) GetPrivateFS

func (w *Wave) GetPrivateFS() (fs.FS, error)

func (*Wave) GetPrivateStaticDir

func (w *Wave) GetPrivateStaticDir() string

func (*Wave) GetPublicFS

func (w *Wave) GetPublicFS() (fs.FS, error)

func (*Wave) GetPublicFileMap

func (w *Wave) GetPublicFileMap() (FileMap, error)

func (*Wave) GetPublicFileMapElements

func (w *Wave) GetPublicFileMapElements() template.HTML

func (*Wave) GetPublicFileMapScriptSha256Hash

func (w *Wave) GetPublicFileMapScriptSha256Hash() string

func (*Wave) GetPublicFileMapURL

func (w *Wave) GetPublicFileMapURL() string

func (*Wave) GetPublicPathPrefix

func (w *Wave) GetPublicPathPrefix() string

func (*Wave) GetPublicStaticDir

func (w *Wave) GetPublicStaticDir() string

func (*Wave) GetPublicURL

func (w *Wave) GetPublicURL(original string) string

func (*Wave) GetRefreshScript

func (w *Wave) GetRefreshScript() template.HTML

func (*Wave) GetRefreshScriptSha256Hash

func (w *Wave) GetRefreshScriptSha256Hash() string

func (*Wave) GetServeStaticHandler

func (w *Wave) GetServeStaticHandler(immutable bool) (http.Handler, error)

func (*Wave) GetStaticPrivateOutDir

func (w *Wave) GetStaticPrivateOutDir() string

func (*Wave) GetStaticPublicOutDir

func (w *Wave) GetStaticPublicOutDir() string

func (*Wave) GetStyleSheetElementID

func (w *Wave) GetStyleSheetElementID() string

func (*Wave) GetStyleSheetLinkElement

func (w *Wave) GetStyleSheetLinkElement() template.HTML

func (*Wave) GetStyleSheetURL

func (w *Wave) GetStyleSheetURL() string

func (*Wave) GetViteManifestLocation

func (w *Wave) GetViteManifestLocation() string

func (*Wave) GetViteOutDir

func (w *Wave) GetViteOutDir() string

func (*Wave) IsPublicAsset

func (w *Wave) IsPublicAsset(urlPath string) bool

func (*Wave) Logger

func (w *Wave) Logger() *slog.Logger

func (*Wave) MustGetPort

func (w *Wave) MustGetPort() int

MustGetPort returns the application port.

func (*Wave) MustGetPrivateFS

func (w *Wave) MustGetPrivateFS() fs.FS

func (*Wave) MustGetPublicFS

func (w *Wave) MustGetPublicFS() fs.FS

func (*Wave) MustGetServeStaticHandler

func (w *Wave) MustGetServeStaticHandler(immutable bool) http.Handler

func (*Wave) RawConfigJSON

func (w *Wave) RawConfigJSON() []byte

RawConfigJSON returns the raw bytes of the configuration file.

func (*Wave) ServeStatic

func (w *Wave) ServeStatic(immutable bool) func(http.Handler) http.Handler

func (*Wave) SetModeToDev

func (w *Wave) SetModeToDev()

SetModeToDev sets the environment to development mode.

func (*Wave) SetPublicFileMapOutDir

func (w *Wave) SetPublicFileMapOutDir(dir string)

SetPublicFileMapOutDir sets the directory where Wave should write the public filemap TypeScript file.

Directories

Path Synopsis
Package tooling provides build-time and dev-time functionality for Wave.
Package tooling provides build-time and dev-time functionality for Wave.

Jump to

Keyboard shortcuts

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