build

package
v0.0.1-beta.5 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: BSD-3-Clause Imports: 25 Imported by: 0

Documentation

Overview

Package build connects the pipeline: Go frontend (loader) -> semantic lowering (lower) -> TypeScript files -> esbuild (Go API) -> ES modules.

esbuild owns TypeScript syntax stripping, JS printing, target lowering, bundling, tree shaking, minification, code splitting and final source map emission. It never sees Go and makes no Go-semantic decisions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadOverlay

func ReadOverlay(file string) (map[string][]byte, error)

ReadOverlay reads an overlay file in the go command's -overlay format, {"Replace": {"/abs/file.go": "/path/with/contents.go"}}, into file contents keyed by absolute path. Deleting files (an empty replacement) is not supported.

func ToolexecOverlay

func ToolexecOverlay(dir, prog string, overlay map[string][]byte, patterns []string) (map[string][]byte, error)

ToolexecOverlay runs the build of patterns through the -toolexec program prog and returns overlay extended with the source its compiles saw. An empty prog returns overlay as is.

func WriteTS

func WriteTS(dir string, mods []*lower.Module) error

WriteTS writes generated modules and the embedded runtime to dir: the module of Go package p at p.ts and the runtime at @goesm/runtime/*.ts (see lower.ModuleFile). The tree is ready for any ESM bundler; Build bundles it with esbuild.

Types

type DiagError

type DiagError struct {
	Layer string
	Lines []string
}

DiagError carries diagnostics from one pipeline layer.

func (*DiagError) Error

func (e *DiagError) Error() string

type Lowered

type Lowered struct {
	Mods    []*lower.Module
	Entries []string // import paths of the root packages, in the order of the patterns
	// Warnings name standard library and dependency functions that goesm
	// cannot lower yet; they were replaced by stubs that panic when called.
	Warnings []string
	// Cached is the number of modules taken from the module cache (see
	// modCache) instead of being lowered.
	Cached int
}

Lowered is the result of the frontend and the semantic lowering.

func Lower

func Lower(dir string, patterns []string) (*Lowered, error)

Lower runs the Go frontend and the semantic lowering.

func LowerOverlay

func LowerOverlay(dir string, overlay map[string][]byte, patterns []string) (*Lowered, error)

LowerOverlay is Lower with an overlay (see Options.Overlay).

type Options

type Options struct {
	Dir      string   // working directory (module root or below)
	Patterns []string // Go package patterns, e.g. ./main
	OutDir   string   // output directory (default "dist")
	TSDir    string   // where generated TypeScript is written ("" = temp dir)
	Split    bool     // one ES module per Go package instead of one bundle
	Minify   bool
	// Overlay replaces or adds files by absolute path, as go build -overlay
	// does. Nil means the files on disk.
	Overlay map[string][]byte
	// Toolexec is a program run on the build's compile commands, as with
	// go build -toolexec (see internal/toolexec).
	Toolexec string
}

Options for a build.

type Result

type Result struct {
	Outputs  []string // written JS files
	TSDir    string
	Warnings []string // see Lowered.Warnings
}

Result describes the outputs.

func Build

func Build(opts Options) (*Result, error)

Build runs the whole pipeline.

Jump to

Keyboard shortcuts

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