gobundle

package module
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: GPL-3.0 Imports: 14 Imported by: 0

README

gobundle

installation

go install github.com/haruyama480/gobundle/cmd/gobundle

example

mkdir tmp
cd tmp

cat <<EOF >go.mod
module example.com/astutil
require golang.org/x/tools v0.40.0
EOF
go mod download golang.org/x/tools
gobundle golang.org/x/tools/go/ast/astutil > astutil.go

gobundle doesn't support

  • //go:embed
  • initialization order
  • and following TODOs

TODO

  • dot import
    • If an explicit period (.) appears instead of a name, all the package's exported identifiers declared in that package's package block will be declared in the importing source file's file block and must be accessed without a qualifier.

    • https://go.dev/ref/spec#Import_declarations
    • ネストしたdot importの可視性は伝播しないことに注意
  • underscore import
  • オプション化
    • dstPkgName
    • retainFn
    • コメント狩り
    • deadcode狩り
  • コメントサポートの範囲
    • posを保持してないのもあるのでいくつか消える可能性がありそう
  • testtesttest
  • GetPackageNameFromPathの代替

Documentation

Index

Constants

View Source
const Delim = "__"

Variables

This section is empty.

Functions

func Bundle

func Bundle(patterns ...string) (string, error)

func GetPackageIdentifier

func GetPackageIdentifier(spec *ast.ImportSpec) string

GetPackageIdentifier は golang/go の慣習に則り ImportSpec から利用可能なパッケージ名を導出します。

Types

type Packages

type Packages struct {
	Roots []*packages.Package

	// All following fields are calculated
	Unfold        map[PkgPath]*packages.Package
	ImportsUnfold []PkgPath // in topological order
	ImportsRetain []PkgPath // in topological order
}

func NewPackage

func NewPackage(patterns ...string) (*Packages, error)

type PkgPath

type PkgPath string

type PkgWriter

type PkgWriter struct {
	Writer *strings.Builder
	Buf    bytes.Buffer
	// contains filtered or unexported fields
}

func NewPkgWriter

func NewPkgWriter() *PkgWriter

func (*PkgWriter) String

func (p *PkgWriter) String() string

func (*PkgWriter) WriteImportDecl

func (p *PkgWriter) WriteImportDecl(imports []PkgPath, pkgStrFn func(PkgPath) string)

func (*PkgWriter) WritePackage

func (p *PkgWriter) WritePackage(fset *token.FileSet, files []*ast.File, pkgPath string) error

func (*PkgWriter) WritePackageClause

func (p *PkgWriter) WritePackageClause(pkgName string)

func (*PkgWriter) WriteSubPackage

func (p *PkgWriter) WriteSubPackage(fset *token.FileSet, file *ast.File) error

not goroutine safe

Directories

Path Synopsis
cmd
gobundle command

Jump to

Keyboard shortcuts

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