Documentation
¶
Overview ¶
Package oxfmt checks and formats JavaScript/TypeScript workspaces with Oxfmt using the shared @gv-tech/oxc-config style, without requiring a local install.
Bare invocations verify formatting (check mode); pass Options.Write to format files in place. Set Options.Diff to also render a colored unified-style diff of the pending changes.
Index ¶
Constants ¶
const ( RunnerAuto = "auto" RunnerNpx = "npx" RunnerBun = "bun" RunnerOxfmt = "oxfmt" )
Runner selection values for Options.Runner.
const ConfigPackage = "@gv-tech/oxc-config@latest"
ConfigPackage is the shareable style package forwarded to the npx/bun wrapper.
const MaxDiffBytes = 1 << 20
MaxDiffBytes skips stdin formatting for files larger than this during --diff.
const MaxDiffFiles = 20
MaxDiffFiles caps how many per-file diffs check mode renders with Options.Diff.
Variables ¶
var ErrUnformatted = errors.New("formatting check failed: files would be reformatted")
ErrUnformatted is returned when check mode finds files needing formatting. Callers use errors.Is to distinguish "dirty workspace" from hard failures.
Functions ¶
func RenderDiff ¶
RenderDiff returns a colored unified-style diff between oldText and newText for path. It returns an empty string when the inputs are identical.
Types ¶
type LaunchSpec ¶
LaunchSpec describes the binary plus leading args used to invoke oxfmt. Direct specs call a local oxfmt; wrapper specs go through the gv-oxfmt runner (npx --package ... / bun x --package ...) which bundles the @gv-tech/oxc-config style.
func ResolveLauncher ¶
func ResolveLauncher(opts Options, lookPath func(string) (string, error), bunLockExists bool) (LaunchSpec, error)
ResolveLauncher picks the oxfmt entrypoint for opts.Runner.
Auto mode prefers the gv-oxfmt wrapper (bun, then npx) so the shared @gv-tech/oxc-config style applies even without a local install. A local oxfmt binary is only the last resort: it honors project config discovery (or ships defaults) rather than the shared style. With an explicit --config, a local oxfmt is preferred since no style package is needed.
Callers may inject lookPath and bunLockExists for testing; pass nil/false for production behavior (execx.LookPath plus a bun.lock ancestor search).