Documentation
¶
Index ¶
- Constants
- Variables
- func GetForgeV1Proto() ([]byte, error)
- func GetValidateProto() ([]byte, error)
- func IsVendoredProtoRelPath(relPath string) bool
- func NormalizeVendoredProto(s string) string
- func WriteForgeV1Proto(destDir string) error
- func WriteTemplate(templateName, destPath string) error
- func WriteTemplateWithData(templateName, destPath string, data any) error
- func WriteValidateProto(destDir string) error
Constants ¶
const ForgeProtoImportPath = "forge/v1/forge.proto"
ForgeProtoImportPath is the import path a project's protos use to pull in forge's annotations: `import "forge/v1/forge.proto";`.
const ForgeProtoVendorRelPath = "proto/forge/v1/forge.proto"
ForgeProtoVendorRelPath is where the vendored forge.proto lives inside a scaffolded project, relative to the project root.
const ValidateProtoImportPath = "buf/validate/validate.proto"
ValidateProtoImportPath is the import path a project's protos use to pull in protovalidate's field rules: `import "buf/validate/validate.proto";`.
const ValidateProtoVendorRelPath = "proto/buf/validate/validate.proto"
ValidateProtoVendorRelPath is where the vendored validate.proto lives inside a scaffolded project, relative to the project root. buf resolves the import from here because it sits under the `proto` module path.
Variables ¶
var EmbeddedFiles embed.FS
EmbeddedFiles bundles the proto annotation definitions shipped with the forge binary so they can be vendored into scaffolded projects without a network fetch.
buf/validate/validate.proto is protovalidate's option-definition file (buf.build/bufbuild/protovalidate). Vendoring it locally — exactly as forge/v1/forge.proto is vendored — keeps the no-BSR-dep property: a project can use `[(buf.validate.field)...]` field rules and still `forge generate` offline, with no `buf registry login`. It is a buf COMPILE input only; buf.gen excludes it from Go/TS output and the runtime library (buf.build/go/protovalidate, pulled in by forge/pkg) provides the extension types + the validation interceptor.
var VendoredProtoRelPaths = []string{ ForgeProtoVendorRelPath, ValidateProtoVendorRelPath, }
VendoredProtoRelPaths is the complete set of files forge COPIES into a project verbatim, rather than rendering from a template — the two embedded protos above, at the project-relative paths scaffold writes them to.
It is a declared list because these copies are otherwise UNTRACKED: they are not templates, not Tier-1 (a forge:hash marker is a comment, and a comment here would be vendored into every project along with the file), and absent from .forge/hashes/ — so forge's upgrade path is blind to them and a stale copy diverges silently. Two features depend on knowing exactly which files those are, and MUST agree:
- `forge lint --vendored-protos` reports drift against the embedded copy (internal/cli/lint/lint_vendored_protos.go).
- `forge project disown` accepts these paths despite the missing marker, so the lint's escape hatch actually opens.
Adding a go:embed'd proto above without adding it here reintroduces the blind spot; a test in internal/cli/lint pins the list against the embedded FS so that cannot happen quietly.
Functions ¶
func GetForgeV1Proto ¶
GetForgeV1Proto returns the unified forge/v1/forge.proto file.
func GetValidateProto ¶ added in v0.1.45
GetValidateProto returns the vendored buf/validate/validate.proto.
func IsVendoredProtoRelPath ¶ added in v0.1.45
IsVendoredProtoRelPath reports whether relPath (slash-separated, project-relative) is one of forge's vendored copies.
func NormalizeVendoredProto ¶ added in v0.1.46
NormalizeVendoredProto canonicalizes a vendored proto for comparison with the copy embedded in this binary — the one comparison `forge generate` (which refreshes a stale copy) and `forge lint --vendored-protos` (which reports one) both make, so the two cannot disagree about what "stale" is.
The go_package line is dropped from both sides: WriteForgeV1Proto rewrites it on purpose, so it differs in every project, and the value forge writes has itself changed across versions. CRLF and trailing whitespace are normalized too, and trailing blank lines dropped: a checkout artifact is not a divergence in what the file declares.
func WriteForgeV1Proto ¶
WriteForgeV1Proto writes the unified forge.proto into destDir/forge.proto, rewriting the go_package option to point at forge's shared forgepb package.
Rationale: scaffolded projects vendor forge.proto into proto/forge/v1/ as a buf COMPILE input (other protos import its annotations), but they do NOT generate a local Go copy — buf.gen.yaml excludes forge/v1 from output and the project links forge/pkg/forgepb instead. The fixed go_package below is what makes the cross-file blank-imports in the generated *.pb.go resolve to that shared package.
func WriteTemplate ¶
WriteTemplate writes a project template to the specified path.
func WriteTemplateWithData ¶
WriteTemplateWithData writes a project template with data substitution.
func WriteValidateProto ¶ added in v0.1.45
WriteValidateProto writes the vendored buf/validate/validate.proto into destDir/validate.proto (destDir being <project>/proto/buf/validate). Unlike forge.proto, the go_package is left untouched: buf.gen excludes this path from every language's output, so no Go/TS is ever emitted from it — the protovalidate runtime library supplies the types.
Types ¶
This section is empty.