Skip to content

Port mint CLI from Deno to Go - #2

Open
pglevy wants to merge 2 commits into
mainfrom
claude/nifty-fermi-f7f3bi
Open

pglevy wants to merge 2 commits into
mainfrom
claude/nifty-fermi-f7f3bi

Conversation

@pglevy

@pglevy pglevy commented Oct 23, 2026

Copy link
Copy Markdown
Owner

Summary

Reimplements the list, tokens and export commands in Go with no behaviour change for existing invocations, then removes the Deno implementation.

Two commits, so the removal is easy to drop or revert on its own:

  1. Port mint CLI from Deno to Go adds the Go code alongside the Deno code.
  2. Remove the Deno implementation and update docs for Go deletes main.ts, src/, tests/, deno.json, deno.lock and .vscode/, and rewrites the README and .gitignore.

How it is built

The layout under internal/ mirrors the TypeScript modules: cli, args, tokens, jsonv, jsnum, output, prompt, help, errs.

  • jsonv: Go maps and encoding/json would reorder token scales ("50", "100", ...), so this package keeps JavaScript key order (integer-like keys first, then insertion order) and reproduces JSON.stringify layout, escaping and number formatting.
  • args: a port of the @std/cli parseArgs code the CLI used, because its lenient rules (global flags anywhere, unknown flags accepted) are part of the current behaviour.
  • Sorting: family sorting uses golang.org/x/text/collate to match localeCompare (about 1.5 MB of binary size).
  • Prompt: golang.org/x/term for raw mode.
  • Testability: the environment (streams, TTY state, fetch, prompt) is injected, so the commands can be tested without a network or a terminal. The original had no tests for list, tokens or export.

Verification

I ran the original Deno CLI side by side with the Go binary:

  • Live data: 31 invocations, byte-identical stdout, stderr and exit codes.
  • Randomized token documents: about 6,300 comparisons, 0 differences.
  • Real terminal (pty): 24 scenarios, byte-identical. These cover arrow-key prompts, Escape and Ctrl+C, color, and NO_COLOR.
  • Arg parsing: 40,000 random argument lists compared against parseArgs.
  • Sorting and numbers: 30,000 string pairs compared against localeCompare, and 60,000 floats against String(n).
  • Tests: go test -race ./... passes, including 95 golden cases captured from the Deno CLI (internal/cli/testdata/golden, so they pin the port to the behaviour it replaced).
  • Build: cross-compiles for linux/darwin (amd64, arm64) and windows/amd64.

Intentional differences

  • --debug prints the error kind and cause chain instead of a JS stack trace.
  • Network and malformed-JSON errors are worded differently. A token file whose root is not a JSON object is now an error; Deno printed nothing for [] and crashed on null.
  • The fetch has a 30 second timeout.
  • Unusual shapes no longer crash or print NaN% undefined / [object Object]. Examples are a group-level $description string and malformed gradient stops.
  • -q0 and -q=0 now count as set. Deno turned them into the number 0, so the flag stayed off.

Existing quirks preserved (candidates for follow-up)

  • mint list --quiet with no category exits 1 with no message.
  • Cancelling a prompt prints a confirmation line showing the highlighted option.
  • mint tokens -c color in a terminal still prompts for a family.
  • mint --typo list shows the short help, because the unknown flag swallows list.

Not covered

The Windows build compiles, but I could not run the interactive prompt there. go install github.com/pglevy/mint@latest (as documented in the README) only works once this is merged.


Generated by Claude Code

Reimplements the list, tokens and export commands in Go with no behaviour
change for existing invocations. The Deno sources are left in place by this
commit and removed in the next one.

Layout mirrors the TypeScript modules under internal/:

  cli       routing, global flags, top-level error reporting, the commands
  args      port of @std/cli parseArgs (the CLI relies on its lenient rules)
  tokens    token store, DTCG flattening, fetcher
  jsonv     JSON model with JavaScript semantics (see below)
  jsnum     JS number formatting / parseFloat / Number() / Math.round
  output    colour, writer, FormatValue
  prompt    raw-mode arrow-key select (golang.org/x/term)
  help, errs

Go maps and encoding/json would reorder token scales ("50", "100", ...), so
jsonv keeps insertion order with JavaScript's integer-keys-first rule and
reproduces JSON.stringify layout, escaping and number formatting. Family
sorting uses golang.org/x/text/collate to match localeCompare.

The environment (streams, TTY state, fetch, prompt) is injected, so the
commands can be tested without a network or a terminal; the original had no
tests for list/tokens/export.

Verified against the original implementation:
 - 95 golden cases captured from the Deno CLI (testdata/golden)
 - byte-identical stdout/stderr/exit status on live data and on randomized
   token documents, including under a real pty for prompts and colour
 - arg parsing fuzzed against @std/cli parseArgs (40,000 vectors)

Known, intentional differences: JS stack traces under --debug, wording of
network/JSON-parse errors, non-object token documents are rejected, and the
fetch has a 30s timeout.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SYRWL23gQSxfUQzjQ1ysWf
Deletes main.ts, src/, tests/, deno.json, deno.lock and the Deno VS Code
settings, now that the Go port replaces them. The Deno fixture lives on as
internal/tokens/testdata/tokens.json.

README now documents installing with `go install`, running with `go run .`,
and the Go development commands. .gitignore drops the Node entries in favour
of the built binary.

This commit only deletes the old implementation; reverting it restores the
Deno sources alongside the Go port.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SYRWL23gQSxfUQzjQ1ysWf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants