project

package
v0.0.0-...-bd06792 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package project owns the on-disk contract generated for a TinyGo Zed project. It merges managed values into user files, preserves unrelated HuJSON content, and rejects symlinks or concurrent edits before replacement.

Index

Constants

View Source
const (
	// ConfigPath is the project-relative source of truth for the selected target
	// and optional flash port.
	ConfigPath = ".zed/tinygo.json"
)

Variables

This section is empty.

Functions

func Initialized

func Initialized(root string) (bool, error)

Initialized reports whether the project source-of-truth configuration exists. It applies the same root and file safety checks used by write operations.

func MergeSettings

func MergeSettings(input []byte, info TargetInfo) ([]byte, error)

MergeSettings returns Zed settings with TinyGo's target environment and build tags under the configuration section requested by gopls. It preserves HuJSON comments, unrelated settings, user environment entries, and non-tag build flags, and migrates the flat shape emitted by early CLI versions. It does not mutate input.

func MergeTasks

func MergeTasks(input []byte, target, port string, canFlash bool) ([]byte, error)

MergeTasks replaces only tasks marked as managed by tinygo-zed. User tasks and their HuJSON comments retain their relative order; the flash task is omitted when canFlash is false. It does not mutate input.

func ResolveRoot

func ResolveRoot(root string) (string, error)

ResolveRoot returns an absolute project directory after rejecting missing, non-directory, or symlinked roots and unsafe existing .zed paths.

Types

type Config

type Config struct {
	// Target is one exact name reported by `tinygo targets`.
	Target string `json:"target"`
	// Port is empty when TinyGo should discover the flash port automatically.
	Port string `json:"port,omitempty"`
}

Config contains the user-selected state from which Zed settings and tasks are derived. An empty Port delegates port discovery to TinyGo.

func LoadConfig

func LoadConfig(root string) (Config, error)

LoadConfig reads ConfigPath using strict JSON decoding. Unknown fields, trailing values, and an empty target are rejected rather than ignored.

type Plan

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

Plan is a prepared set of file replacements. Preparation captures the prior contents so Apply can refuse to overwrite intervening edits.

func PrepareInit

func PrepareInit(root string, config Config, info TargetInfo) (Plan, error)

PrepareInit builds a plan for a previously unconfigured project. It creates managed Zed files and adds a minimal go.mod or main.go only when absent (or, for main.go, empty); it does not write until Plan.Apply is called.

func PrepareSync

func PrepareSync(root string, config Config, info TargetInfo) (Plan, error)

PrepareSync builds a plan that reconciles managed Zed files with config and info. The project must already contain ConfigPath; unrelated settings and tasks are retained.

func (Plan) Apply

func (plan Plan) Apply() error

Apply stages every changed file before replacing any of them and refuses to proceed if a captured file changed after preparation. A non-empty Plan is single-use. Individual replacements are atomic, but the plan is not a filesystem transaction: ConfigPath is replaced first so rerunning PrepareSync repairs an interrupted application.

func (Plan) Changes

func (plan Plan) Changes() []string

Changes returns human-readable create or update descriptions in application order. An empty result means the project is already synchronized.

type TargetInfo

type TargetInfo struct {
	// GOROOT is TinyGo's generated Go root for the selected target and version.
	GOROOT string
	// GOOS and GOARCH select the target platform presented to gopls.
	GOOS   string
	GOARCH string
	// GOARM and GOMIPS are optional architecture tuning values.
	GOARM  string
	GOMIPS string
	// BuildTags is the complete tag set required for target package discovery.
	BuildTags []string
	// CanFlash controls whether the managed task set includes a flash task.
	CanFlash bool
}

TargetInfo contains the validated TinyGo metadata needed to derive Zed configuration. BuildTags must contain at least one safe tag.

Jump to

Keyboard shortcuts

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