build

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package build generates the dist/ directory of the framework from src/: the unminified and minified bundles (script and ES module), the extensions, the ypy.max bundle, the editor files, the skills, the type declarations and the brotli copies.

Generate returns the whole output in memory so the same code serves the build (write it), the drift gate (compare it with the disk) and the size gate (measure it).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Command

func Command() cli.Command

Command is the "build" subcommand.

func Write

func Write(dir string, out Output, only Part) error

Write writes the output under dir, through an os.Root: no path can leave dir, and a symlink where an output file goes is replaced by the file (never written through). A full build (PartAll) first removes the stale files (see Compare), so the result does not keep files of a previous layout; it only does so in a directory that is empty, holds a ypy build or only entries the build writes, and refuses any other (a mistaken --out ~ would delete the user's files).

func WriteSizes

func WriteSizes(w io.Writer, rows []SizeRow) bool

WriteSizes prints the table and the budgets, and reports whether every file is within its budget.

Types

type Drift

type Drift struct {
	Missing []string // generated but not on disk
	Changed []string // on disk with other bytes
	Stale   []string // on disk, owned by the build, not generated
}

Drift describes how the disk differs from the generated output.

func Compare

func Compare(dir string, out Output, only Part) Drift

Compare checks the output against what is on disk under dir. Stale files are reported only for a full build. A symlink where an output file goes counts as changed, whatever it points at.

func (Drift) Empty

func (d Drift) Empty() bool

Empty reports whether the disk matches the output.

func (Drift) String

func (d Drift) String() string

String lists the differences, one per line.

type Options

type Options struct {
	// Root is the repository root: it holds src/.
	Root string
	// Only limits the output to one part; PartAll builds everything.
	Only Part
}

Options configure Generate.

type Output

type Output map[string][]byte

Output is the generated tree: slash separated paths relative to the output directory, mapped to their bytes.

func Generate

func Generate(opts Options) (Output, error)

Generate builds the output in memory.

func (Output) Names

func (o Output) Names() []string

Names returns the generated paths, sorted.

type Part

type Part string

Part selects a slice of the output.

const (
	PartAll  Part = ""
	PartCore Part = "core" // ypy, ypy.esm, their minified forms, types, editors, skills
	PartExt  Part = "ext"  // dist/ext
	PartMax  Part = "max"  // ypy.max bundle
)

The parts a build can be limited to.

func ParsePart

func ParsePart(s string) (Part, error)

ParsePart validates a --only value.

type SizeRow

type SizeRow struct {
	File   string
	Min    int
	Gzip   int
	Budget int
	OK     bool
}

SizeRow is one measured file against its budget.

func Sizes

func Sizes(out Output) []SizeRow

Sizes measures the min+gzip size (level 9) of the budgeted files of out: the core (ypy.min.js, at most 18 kB) and every extension (ext/*.min.js, at most 6 kB each; 1 kB = 1024 B). The max bundle and the module build have no budget. Only files that are in out are measured.

Jump to

Keyboard shortcuts

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