Skip to content

v1.0.19

Choose a tag to compare

@shanjunmei shanjunmei released this 18 Aug 02:48
· 27 commits to main since this release

[v1.0.19] - 2026-08-18

digen CLI subcommands + generation-time contract pre-check

✨ New Features

  • Five new digen subcommands (reuse the generation pipeline, accept all existing flags):
    • digen init — scaffold a di.go with the dig.Build entry point
    • digen check — validate DI contracts without writing any file (lightweight static check)
    • digen graph — print the provider dependency graph as Mermaid
    • digen explain <type> — explain how a type / provider is resolved
    • digen completion <shell> — emit bash / zsh / fish completion scripts
    • digen -h and the completion scripts now list every flag and subcommand.

🔧 Improved Diagnostics

  • Generation-time contract pre-check: ensures di.go holds wiring only. If any wiring references a package-level symbol defined inside a //go:build digen file, generation aborts (no file written) with a clear error and a 💡 Fix: that names the file and tells you to move the definition to a non-digen file or an imported package. Covers constructor signatures, dig.Supply value types, closure signatures & free-variable types, merged parameter types, recursing through pointers / slices / maps / channels and generic type arguments.
  • Post-generation safety net upgraded: now classifies contract violations vs internal generator bugs. Contract violations get the same 💡 Fix: as the pre-check; genuine bugs emit a pre-filled issue link. Also fixes a previously misleading error message.

⬆️ Upgrade Notes

  • This is a largely additive, non-breaking release. The only behavior change: the generation-time contract pre-check now catches a class of wiring that was already invalid before any file is written — a package-level symbol (type / func / var / const) defined inside a //go:build digen file and referenced by dig.Provide / Invoke / Supply or a closure body. Previously this only surfaced during the post-generation type check; now generation aborts immediately with a 💡 Fix:.
  • If you do reference a symbol defined in a digen file from your wiring, follow the 💡 Fix: to move the definition to a file without the //go:build digen tag, or reference it from an imported package.
  • Run digen check for a pure static contract check before triggering a full generation.

🛠 Internals & Quality (for contributors)

  • Build-constraint checks consolidated into a single source of truth, internal/buildconstraint (FileHasDigenConstraint / RequiresDigen), removing duplicated logic.
  • New golden-file byte-diff regression test (example/golden/golden_test.go) covering 11 complex examples, catching silent "compiles but semantically drifted" changes.