Documentation
¶
Index ¶
- type Config
- type ParameterMetadata
- type Store
- type TinyWasm
- func (w *TinyWasm) Change(newValue string, progress chan<- string)
- func (h *TinyWasm) ClearJavaScriptCache()
- func (t *TinyWasm) CreateDefaultWasmFileClientIfNotExist() *TinyWasm
- func (w *TinyWasm) GetLastOperationID() string
- func (w *TinyWasm) GetMCPToolsMetadata() []ToolMetadata
- func (t *TinyWasm) GetTinyGoVersion() (string, error)
- func (w *TinyWasm) GetWasmExecJsPathGo() (string, error)
- func (w *TinyWasm) GetWasmExecJsPathTinyGo() (string, error)
- func (h *TinyWasm) JavascriptForInitializing(customizations ...string) (js string, err error)
- func (w *TinyWasm) Label() string
- func (w *TinyWasm) MainInputFileRelativePath() string
- func (w *TinyWasm) MainOutputFileAbsolutePath() string
- func (w *TinyWasm) Name() string
- func (w *TinyWasm) NewFileEvent(fileName, extension, filePath, event string) error
- func (w *TinyWasm) OutputRelativePath() string
- func (w *TinyWasm) RecompileMainWasm() error
- func (w *TinyWasm) SetLastOperationID(id string)
- func (w *TinyWasm) Shortcuts() []map[string]string
- func (w *TinyWasm) ShouldCompileToWasm(fileName, filePath string) bool
- func (w *TinyWasm) SupportedExtensions() []string
- func (w *TinyWasm) TinyGoCompiler() bool
- func (w *TinyWasm) UnobservedFiles() []string
- func (w *TinyWasm) Value() string
- func (t *TinyWasm) VerifyTinyGoInstallation() error
- func (w *TinyWasm) VerifyTinyGoProjectCompatibility()
- func (w *TinyWasm) VisualStudioCodeWasmEnvConfig()
- func (w *TinyWasm) WasmExecJsOutputPath() string
- func (w *TinyWasm) WasmProjectTinyGoJsUse(mode ...string) (isWasmProject bool, useTinyGo bool)
- type ToolExecutor
- type ToolMetadata
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// AppRootDir specifies the application root directory (absolute).
// e.g., "/home/user/project". If empty, defaults to "." to preserve existing behavior.
AppRootDir string
// SourceDir specifies the directory containing the Go source for the webclient (relative to AppRootDir).
// e.g., "src/cmd/webclient"
SourceDir string
// OutputDir specifies the directory for WASM and related assets (relative to AppRootDir).
// e.g., "src/web/public"
OutputDir string
WasmExecJsOutputDir string // output dir for wasm_exec.js file (relative) eg: "src/web/ui/js", "theme/js"
MainInputFile string // main input file for WASM compilation (default: "main.wasm.go")
OutputName string // output name for WASM file (default: "main")
Logger func(message ...any)
BuildLargeSizeShortcut string // "L" (Large) compile with go
BuildMediumSizeShortcut string // "M" (Medium) compile with tinygo debug
BuildSmallSizeShortcut string // "S" (Small) compile with tinygo minimal binary size
// gobuild integration fields
Callback func(error) // Optional callback for async compilation
CompilingArguments func() []string // Build arguments for compilation (e.g., ldflags)
// DisableWasmExecJsOutput prevents automatic creation of wasm_exec.js file
// Useful when embedding wasm_exec.js content inline (e.g., Cloudflare Pages Advanced Mode)
DisableWasmExecJsOutput bool
Store Store // Key-Value store for state persistence
OnWasmExecChange func() // Callback for wasm_exec.js changes
// contains filtered or unexported fields
}
Config holds configuration for WASM compilation
type ParameterMetadata ¶
type ParameterMetadata struct {
Name string
Description string
Required bool
Type string
EnumValues []string
Default any
}
ParameterMetadata describes a tool parameter
type Store ¶ added in v0.3.7
Store defines the interface for a key-value storage system used to persist the compiler state (e.g. current mode).
type TinyWasm ¶ added in v0.3.7
type TinyWasm struct {
*Config
// contains filtered or unexported fields
}
TinyWasm provides WebAssembly compilation capabilities with 3-mode compiler selection
func New ¶
New creates a new TinyWasm instance with the provided configuration Timeout is set to 40 seconds maximum as TinyGo compilation can be slow Default values: MainInputFile in Config defaults to "main.wasm.go"
func (*TinyWasm) Change ¶ added in v0.3.7
Change updates the compiler mode for TinyWasm and reports progress via the provided channel. Implements the HandlerEdit interface: Change(newValue string, progress chan<- string) NOTE: The caller (devtui) is responsible for closing the progress channel, NOT the handler.
func (*TinyWasm) ClearJavaScriptCache ¶ added in v0.3.7
func (h *TinyWasm) ClearJavaScriptCache()
ClearJavaScriptCache clears both cached JavaScript strings to force regeneration
func (*TinyWasm) CreateDefaultWasmFileClientIfNotExist ¶ added in v0.3.7
CreateDefaultWasmFileClientIfNotExist creates a default WASM main.go file from the embedded markdown template It never overwrites an existing file and returns the TinyWasm instance for method chaining.
func (*TinyWasm) GetLastOperationID ¶ added in v0.3.7
func (*TinyWasm) GetMCPToolsMetadata ¶ added in v0.3.7
func (w *TinyWasm) GetMCPToolsMetadata() []ToolMetadata
GetMCPToolsMetadata returns metadata for all TinyWasm MCP tools
func (*TinyWasm) GetTinyGoVersion ¶ added in v0.3.7
GetTinyGoVersion returns the installed TinyGo version
func (*TinyWasm) GetWasmExecJsPathGo ¶ added in v0.3.7
GetWasmExecJsPathGo returns the path to Go's wasm_exec.js file
func (*TinyWasm) GetWasmExecJsPathTinyGo ¶ added in v0.3.7
GetWasmExecJsPathTinyGo returns the path to TinyGo's wasm_exec.js file
func (*TinyWasm) JavascriptForInitializing ¶ added in v0.3.7
JavascriptForInitializing returns the JavaScript code needed to initialize WASM.
Parameters (variadic):
- customizations[0]: Custom header string to prepend to wasm_exec.js content. If not provided, defaults to "// TinyWasm: mode=<current_mode>\n"
- customizations[1]: Custom footer string to append after wasm_exec.js content. If not provided, defaults to WebAssembly initialization code with fetch and instantiate.
Examples:
- JavascriptForInitializing() - Uses default header and footer
- JavascriptForInitializing("// Custom Header\n") - Custom header, default footer
- JavascriptForInitializing("// Custom Header\n", "console.log('loaded');") - Both custom
func (*TinyWasm) MainInputFileRelativePath ¶ added in v0.3.7
MainInputFileRelativePath returns the relative path to the main WASM input file (e.g. "main.wasm.go").
func (*TinyWasm) MainOutputFileAbsolutePath ¶ added in v0.3.7
MainOutputFileAbsolutePath returns the absolute path to the main WASM output file (e.g. "main.wasm").
func (*TinyWasm) NewFileEvent ¶ added in v0.3.7
NewFileEvent handles file events for WASM compilation with automatic project detection fileName: name of the file (e.g., main.wasm.go) extension: file extension (e.g., .go) filePath: full path to the file (e.g., ./home/userName/ProjectName/web/public/main.wasm.go) event: type of file event (e.g., create, remove, write, rename)
func (*TinyWasm) OutputRelativePath ¶ added in v0.3.7
OutputRelativePath returns the RELATIVE path to the final output file eg: "deploy/edgeworker/app.wasm" (relative to AppRootDir) This is used by file watchers to identify output files that should be ignored. The returned path always uses forward slashes (/) for consistency across platforms.
func (*TinyWasm) RecompileMainWasm ¶ added in v0.3.7
RecompileMainWasm recompiles the main WASM file if it exists
func (*TinyWasm) SetLastOperationID ¶ added in v0.3.7
func (*TinyWasm) ShouldCompileToWasm ¶ added in v0.3.7
ShouldCompileToWasm determines if a file should trigger WASM compilation
func (*TinyWasm) SupportedExtensions ¶ added in v0.3.7
func (*TinyWasm) TinyGoCompiler ¶ added in v0.3.7
TinyGoCompiler returns if TinyGo compiler should be used (dynamic based on configuration)
func (*TinyWasm) UnobservedFiles ¶ added in v0.3.7
UnobservedFiles returns files that should not be watched for changes e.g: main.wasm
func (*TinyWasm) Value ¶ added in v0.3.7
Value returns the current compiler mode shortcut (c, d, or p)
func (*TinyWasm) VerifyTinyGoInstallation ¶ added in v0.3.7
VerifyTinyGoInstallation checks if TinyGo is properly installed
func (*TinyWasm) VerifyTinyGoProjectCompatibility ¶ added in v0.3.7
func (w *TinyWasm) VerifyTinyGoProjectCompatibility()
VerifyTinyGoProjectCompatibility checks if the project is compatible with TinyGo compilation
func (*TinyWasm) VisualStudioCodeWasmEnvConfig ¶ added in v0.3.7
func (w *TinyWasm) VisualStudioCodeWasmEnvConfig()
VisualStudioCodeWasmEnvConfig automatically creates and configures VS Code settings for WASM development. This method resolves the "could not import syscall/js" error by setting proper environment variables in .vscode/settings.json file. On Windows, the .vscode directory is made hidden for a cleaner project view. This configuration enables VS Code's Go extension to properly recognize WASM imports and provide accurate IntelliSense, error detection, and code completion for syscall/js and other WASM-specific packages.
func (*TinyWasm) WasmExecJsOutputPath ¶ added in v0.3.7
WasmExecJsOutputPath returns the output path for wasm_exec.js
type ToolExecutor ¶
ToolExecutor defines how a tool should be executed Channel accepts string messages (no binary data in tinywasm)
type ToolMetadata ¶
type ToolMetadata struct {
Name string
Description string
Parameters []ParameterMetadata
Execute ToolExecutor // Execution function
}
ToolMetadata provides MCP tool configuration metadata