Releases: kevinconway/wrapgen
Update x/tools to support Go 1.22
Installing and running the tool with Go 1.22 resulted in a panic from the x/tools library. The library is updated in go.mod to a recent version which resolves the panic.
Add ImportsWithSource template value
Add a template value called ImportsWithSource
. This is equivalent to the Imports
value injected into templates but is guaranteed to contain the Source
value. This is useful in cases when generating code with a --package
set to a different value than Source
because Imports
is only generated from the import statements in Source
which never contains itself. The documented suggestion of using goimports
should continue to resolve this condition for users of the Imports
template value which makes this change backwards compatible. You are encouraged to use ImportsWithSource
if you want to use the --package
flag without needing to also run goimports
.
Additionally, the Imports
and ImportsWithSource
values are now deduped which removes another reliance on goimports
.
Fix source package name detection
The previous version assumed that the package path ended with the
package name. In cases where the package path contained invalid package
characters, like "-", the tools would generate invalid output.
The naive solution to this would be to use the --package flag to set
the name to something valid. However, this flag indicates that the
source and destination packages are different. This results in the
source package receiving an import alias to prevent conflicts. This
means that any package generated using --package that is rendered
within the file tree of --source also results in an invalid file.
This patch preserves all existing behaviors except that it now correctly
extracts the true package name rather than relying on the package path.
Delay output file creation until the end
This resolves an issue that appears when generating an output file into
the same package from which the interfaces are being loaded. The empty
file causes the Go package to become invalid which prevents the tool
from parsing the code.
Add optional destination file
Defaulting to STDOUT is useful for creating script pipelines but it is
difficult to use with go:generate. There is no way to pipe and redirect
STDOUT in the go:generate comment syntax without breaking the
abstraction and adding something like sh -c "<command>"
.
This new option preserves backwards compatibility by keeping STDOUT the
default output but offers a new option of specifying --destination
which switches the output to a specified file.
Fix go modules compatibility for v2+ releases
Merge pull request #10 from kevinconway/fix-v2-modules Add /v2 path to module
Fix issues related to conflicting package names
Merge pull request #9 from orian/fix-pkg-name-conflicts Added proper handling of package name conflict.
Go modules support
Add support for go modules.
Switch to go modules for dependency management.
Add ability to render select interfaces.
More heavily annotate the AST related code and add new cases.
Add support for rendering in and out of the source package.
Drop code API.
Legacy release
I never made a release of the stable version of this package. Creating one before major changes are introduced.