sitebuild

package
v1.167.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sitebuild compiles the TypeScript, TSX and JSX of a site's source tree into the JavaScript it serves (#2774). A release opts in with a _build.json at its root; each entry it names is bundled with the local modules it imports into one ES module beside it, and its imports of libraries go to the exact version URLs the file maps them to. The compile reads only the tree, and the network only when the release asks for its URL modules to be bundled.

Index

Constants

View Source
const (
	// RemoteExternal leaves a URL import a URL, for the browser to load.
	RemoteExternal = "external"
	// RemoteBundle fetches it at publish and bundles it into the output.
	RemoteBundle = "bundle"
)

The two answers to what a URL import becomes.

View Source
const ControlFile = "_build.json"

ControlFile is the file whose presence turns the compile on. It is source: read at publish and never served.

View Source
const Version = reviewedCompiler + "/1"

Version names what an output is a function of beyond its inputs: the compiler and these options. An output compiled under another version is compiled again.

Variables

This section is empty.

Functions

func IsSource

func IsSource(name string) bool

IsSource reports whether a release path is compiled source, which a release with a control file never serves.

func OutputOf

func OutputOf(entry string) string

OutputOf is the file an entry compiles to: the same path ending in .js.

func Pinned

func Pinned(u string) bool

Pinned reports whether a URL may be imported: https, at an exact version, so that what it loads cannot change under a release.

Types

type Config

type Config struct {
	// Entries are the files compiled, each to its own output.
	Entries []string `json:"entries"`
	// Imports maps a bare specifier, or a prefix of one ending in /, to the
	// exact-version URL it is loaded from.
	Imports map[string]string `json:"imports"`
	// Remote is RemoteExternal (the default) or RemoteBundle.
	Remote string `json:"remote"`
	// Sourcemap writes <output>.map beside each output, holding the source.
	Sourcemap bool `json:"sourcemap"`
	// Minify shortens the output.
	Minify bool `json:"minify"`
}

Config is what a control file declares.

func Parse

func Parse(data []byte) (*Config, error)

Parse reads a control file, refusing anything it cannot honor.

type Error

type Error struct {
	Messages []Message
}

Error is every message of a failed compile.

func (*Error) Error

func (e *Error) Error() string

type Fetcher

type Fetcher interface {
	Fetch(ctx context.Context, url string) (body []byte, contentType string, err error)
}

Fetcher reads a module by URL, for a release that bundles its URL modules.

type LimitError

type LimitError struct {
	Entry    string
	Resource string
	Limit    int64
}

LimitError is a compile stopped for reading or writing more than it may.

func (*LimitError) Error

func (e *LimitError) Error() string

type Limits

type Limits struct {
	// Modules is how many modules, local and fetched, one entry may read.
	Modules int
	// FileBytes is the largest one module may be.
	FileBytes int64
	// InputBytes is what all of one entry's modules may hold together.
	InputBytes int64
	// OutputBytes is what one entry's outputs may hold together.
	OutputBytes int64
}

Limits bound one entry's compile.

type Message

type Message struct {
	File   string
	Line   int
	Column int
	Text   string
}

Message is one place a compile could not get past.

type Options

type Options struct {
	Config *Config
	Limits Limits
	// Fetch reads URL modules in bundle mode; nil refuses them.
	Fetch Fetcher
}

Options are what a compile is given besides its tree and entry.

type Output

type Output struct {
	Path string
	Body []byte
}

Output is one file a compile produced.

type Result

type Result struct {
	Outputs []Output
	Inputs  []string
}

Result is one entry compiled: its outputs, and every path of the tree it read or looked for, so it is compiled again when any of them changes.

func Compile

func Compile(ctx context.Context, src fs.FS, entry string, opts Options) (res *Result, err error)

Compile builds one entry of the tree. Every module it reads comes from src or, in bundle mode, from Fetch: nothing resolves against the disk of the process running it.

Directories

Path Synopsis
Package modfetch reads the modules a site release bundles at publish (#2774): by URL, through the egress guard, kept in the replica's memory by URL.
Package modfetch reads the modules a site release bundles at publish (#2774): by URL, through the egress guard, kept in the replica's memory by URL.

Jump to

Keyboard shortcuts

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