devtool

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package devtool runs the development servers so that several worktrees can run them at once without colliding on ports.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	Stdout    io.Writer
	Resolve   func(context.Context) (Environment, error)
	Ports     PortAllocator
	Processes ProcessManager
}

App implements the commands behind the mise start and docs tasks.

func NewApp

func NewApp() *App

NewApp returns an App that runs real processes from the current worktree.

func (*App) Run

func (a *App) Run(ctx context.Context, args []string) error

Run dispatches a command: "start [all|air|api|web]" or "docs".

type Environment

type Environment struct {
	MainRoot    string
	CurrentRoot string
}

Environment locates the worktree a command runs in and the main worktree that every worktree of the repository shares.

func ResolveEnvironment

func ResolveEnvironment(ctx context.Context) (Environment, error)

ResolveEnvironment describes the worktree containing the working directory.

func (Environment) CookieNamespace

func (e Environment) CookieNamespace() string

CookieNamespace names this worktree's session cookie. The main worktree keeps the default cookie name. A linked worktree gets its directory name plus a hash of its path, so two worktrees with the same directory name in different places still differ.

func (Environment) PortLockRoot

func (e Environment) PortLockRoot() string

PortLockRoot is where worktrees record the ports they hold. It lives in the main worktree so that every linked worktree sees the same locks.

type FilePortAllocator

type FilePortAllocator struct {
	LockRoot string
}

FilePortAllocator coordinates ports between worktrees with advisory locks. A port is only free if no other worktree holds its lock and nothing is listening on it. The lock closes the gap between choosing a port and the server binding it, and the kernel drops it if the process dies.

func (*FilePortAllocator) Acquire

func (a *FilePortAllocator) Acquire(preferred int) (PortLease, error)

Acquire locks the first available port at or above preferred.

type OSProcesses

type OSProcesses struct{}

OSProcesses runs development commands as child process groups.

func (*OSProcesses) Docs

func (p *OSProcesses) Docs(ctx context.Context, env Environment, port int) error

Docs runs the documentation dev server.

func (*OSProcesses) Start

func (p *OSProcesses) Start(ctx context.Context, env Environment, mode string, apiPort, webPort int) error

Start runs the servers for a start mode on the reserved ports. A zero port means the mode does not run that server.

type PortAllocator

type PortAllocator interface {
	Acquire(preferred int) (PortLease, error)
}

PortAllocator reserves the first available port at or above a preferred port.

type PortLease

type PortLease interface {
	Port() int
	Close() error
}

PortLease reserves a port until Close is called.

type ProcessManager

type ProcessManager interface {
	Start(ctx context.Context, env Environment, mode string, apiPort, webPort int) error
	Docs(ctx context.Context, env Environment, port int) error
}

ProcessManager runs the development servers.

Jump to

Keyboard shortcuts

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