From 75ebf28506bdacf7f021adadfd1805b1301f5068 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 25 Jul 2025 16:45:18 +0200 Subject: [PATCH 1/4] fix(cosmosgen): fallback to local generation when possible --- docs/docs/04-clients/02-typescript.md | 13 +++- ignite/cmd/generate_typescript_client.go | 22 ++----- ignite/pkg/cosmosgen/generate_typescript.go | 68 +++++++++++++++++++-- 3 files changed, 80 insertions(+), 23 deletions(-) diff --git a/docs/docs/04-clients/02-typescript.md b/docs/docs/04-clients/02-typescript.md index 13771fbfde..525cd6b764 100644 --- a/docs/docs/04-clients/02-typescript.md +++ b/docs/docs/04-clients/02-typescript.md @@ -2,7 +2,7 @@ description: Information about the generated TypeScript client code. --- -# TypeScript frontend +# TypeScript library Ignite offers powerful functionality for generating client-side code for your blockchain. Think of this as a one-click client SDK generation tailored @@ -35,6 +35,17 @@ SDK modules: ignite generate ts-client --clear-cache ``` +:::tip +In order to not rely on the remote `buf.build` service, you can install the +`protoc-gen-ts_proto` binary locally and Ignite will use it instead of the remote plugin. + +```sh +npm install -g ts-proto +``` + +Learn more at +::: + Run a command to start your blockchain node: ``` diff --git a/ignite/cmd/generate_typescript_client.go b/ignite/cmd/generate_typescript_client.go index e4efd79502..50c9fcf6fd 100644 --- a/ignite/cmd/generate_typescript_client.go +++ b/ignite/cmd/generate_typescript_client.go @@ -5,14 +5,10 @@ import ( "github.com/ignite/cli/v29/ignite/pkg/cliui" "github.com/ignite/cli/v29/ignite/pkg/cliui/icons" - "github.com/ignite/cli/v29/ignite/pkg/errors" "github.com/ignite/cli/v29/ignite/services/chain" ) -const ( - flagUseCache = "use-cache" - msgBufAuth = "Generate ts-client uses a 'buf.build' remote plugin. Buf is begin limiting remote plugin requests from unauthenticated users on 'buf.build'. Intensively using this function will get you rate limited. Authenticate with 'buf registry login' to avoid this (https://buf.build/docs/generate/auth-required)." -) +const flagDisableCache = "disable-cache" func NewGenerateTSClient() *cobra.Command { c := &cobra.Command{ @@ -41,7 +37,7 @@ changes when the blockchain is started with a flag: c.Flags().AddFlagSet(flagSetYes()) c.Flags().StringP(flagOutput, "o", "", "TypeScript client output path") - c.Flags().Bool(flagUseCache, false, "use build cache to speed-up generation") + c.Flags().Bool(flagDisableCache, false, "disable build cache") return c } @@ -53,16 +49,6 @@ func generateTSClientHandler(cmd *cobra.Command, _ []string) error { ) defer session.End() - if !getYes(cmd) { - if err := session.AskConfirm(msgBufAuth); err != nil { - if errors.Is(err, cliui.ErrAbort) { - return errors.New("buf not auth") - } - - return err - } - } - c, err := chain.NewWithHomeFlags( cmd, chain.WithOutputer(session), @@ -79,14 +65,14 @@ func generateTSClientHandler(cmd *cobra.Command, _ []string) error { } output, _ := cmd.Flags().GetString(flagOutput) - useCache, _ := cmd.Flags().GetBool(flagUseCache) + disableCache, _ := cmd.Flags().GetBool(flagDisableCache) var opts []chain.GenerateTarget if flagGetEnableProtoVendor(cmd) { opts = append(opts, chain.GenerateProtoVendor()) } - err = c.Generate(cmd.Context(), cacheStorage, chain.GenerateTSClient(output, useCache), opts...) + err = c.Generate(cmd.Context(), cacheStorage, chain.GenerateTSClient(output, !disableCache), opts...) if err != nil { return err } diff --git a/ignite/pkg/cosmosgen/generate_typescript.go b/ignite/pkg/cosmosgen/generate_typescript.go index 952bb083e0..fc8d338099 100644 --- a/ignite/pkg/cosmosgen/generate_typescript.go +++ b/ignite/pkg/cosmosgen/generate_typescript.go @@ -2,7 +2,9 @@ package cosmosgen import ( "context" + "log" "os" + "os/exec" "path/filepath" "sort" "strings" @@ -16,10 +18,28 @@ import ( "github.com/ignite/cli/v29/ignite/pkg/gomodulepath" ) -var dirchangeCacheNamespace = "generate.typescript.dirchange" +var ( + dirchangeCacheNamespace = "generate.typescript.dirchange" + + protocGenTSProtoBin = "protoc-gen-ts_proto" + + msgBufAuth = "Note: Buf is limits remote plugin requests from unauthenticated users on 'buf.build'. Intensively using this function will get you rate limited. Authenticate with 'buf registry login' to avoid this (https://buf.build/docs/generate/auth-required)." +) + +const localTSProtoTmpl = `version: v1 +plugins: + - plugin: ts_proto + out: . + opt: + - "esModuleInterop=true" + - "forceLong=long" + - "useOptionals=true" +` type tsGenerator struct { - g *generator + g *generator + tsTemplateFile string + isLocalProto bool } type generatePayload struct { @@ -28,7 +48,41 @@ type generatePayload struct { } func newTSGenerator(g *generator) *tsGenerator { - return &tsGenerator{g} + tsg := &tsGenerator{g: g} + if _, err := exec.LookPath(protocGenTSProtoBin); err == nil { + tsg.isLocalProto = true + } + + if !tsg.isLocalProto { + log.Printf("No '%s' binary found in PATH, using remote buf plugin for Typescript generation. %s", protocGenTSProtoBin, msgBufAuth) + } + + return tsg +} + +func (g *tsGenerator) tsTemplate() (string, error) { + if !g.isLocalProto { + return g.g.tsTemplate(), nil + } + if g.tsTemplateFile != "" { + return g.tsTemplateFile, nil + } + f, err := os.CreateTemp("", "buf-gen-ts-*.yaml") + if err != nil { + return "", err + } + defer f.Close() + if _, err := f.WriteString(localTSProtoTmpl); err != nil { + return "", err + } + g.tsTemplateFile = f.Name() + return g.tsTemplateFile, nil +} + +func (g *tsGenerator) cleanup() { + if g.tsTemplateFile != "" { + os.Remove(g.tsTemplateFile) + } } func (g *generator) tsTemplate() string { @@ -55,6 +109,7 @@ func (g *generator) generateTS(ctx context.Context) error { }) tsg := newTSGenerator(g) + defer tsg.cleanup() if err := tsg.generateModuleTemplates(ctx); err != nil { return err } @@ -142,12 +197,17 @@ func (g *tsGenerator) generateModuleTemplate( protoPath = filepath.Join(g.g.sdkDir, "proto") } + tsTemplate, err := g.tsTemplate() + if err != nil { + return err + } + // code generate for each module. if err := g.g.buf.Generate( ctx, protoPath, typesOut, - g.g.tsTemplate(), + tsTemplate, cosmosbuf.IncludeWKT(), cosmosbuf.WithModuleName(m.Pkg.Name), ); err != nil { From 42b2a228c5e102f95e86ce378f594786311784f9 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 25 Jul 2025 16:46:04 +0200 Subject: [PATCH 2/4] cl --- changelog.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/changelog.md b/changelog.md index e2cc656038..2c7ebf2b10 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,12 @@ ## Unreleased +## [`v29.2.1`](https://github.com/ignite/cli/releases/tag/v29.2.1) + +### Changes + +- [#4780](https://github.com/ignite/cli/pull/4780) Fallback to local generation when possible in `generate ts-client` command. + ## [`v29.2.0`](https://github.com/ignite/cli/releases/tag/v29.2.0) ### Features From 2a468df355edd999619874aa3e62c0093daf049b Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Sat, 9 Aug 2025 16:20:27 +0200 Subject: [PATCH 3/4] feedback --- changelog.md | 5 ++--- ignite/pkg/cosmosgen/generate_typescript.go | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/changelog.md b/changelog.md index a3481fede4..1fc3045644 100644 --- a/changelog.md +++ b/changelog.md @@ -2,12 +2,12 @@ ## Unreleased +## [`v29.3.0`](https://github.com/ignite/cli/releases/tag/v29.3.0) + ### Features - [#4786](https://github.com/ignite/cli/pull/4786) Add all types to the documentation and disclaimer for multiple coin types. -## [`v29.2.1`](https://github.com/ignite/cli/releases/tag/v29.2.1) - ### Changes - [#4780](https://github.com/ignite/cli/pull/4780) Fallback to local generation when possible in `generate ts-client` command. @@ -912,7 +912,6 @@ Our new name is **Ignite CLI**! in [PR 1971](https://github.com/ignite/cli/pull/1971/files) Updates are required if your chain uses these packages: - - `spm/ibckeeper` is now `pkg/cosmosibckeeper` - `spm/cosmoscmd` is now `pkg/cosmoscmd` - `spm/openapiconsole` is now `pkg/openapiconsole` diff --git a/ignite/pkg/cosmosgen/generate_typescript.go b/ignite/pkg/cosmosgen/generate_typescript.go index cf2fda0b3a..70e7f0467e 100644 --- a/ignite/pkg/cosmosgen/generate_typescript.go +++ b/ignite/pkg/cosmosgen/generate_typescript.go @@ -54,7 +54,7 @@ func newTSGenerator(g *generator) *tsGenerator { } if !tsg.isLocalProto { - log.Printf("No '%s' binary found in PATH, using remote buf plugin for Typescript generation. %s", protocGenTSProtoBin, msgBufAuth) + log.Print("No '%s' binary found in PATH, using remote buf plugin for Typescript generation. %s\n", protocGenTSProtoBin, msgBufAuth) } return tsg From 6e34abddcec439de6dc13df122a653655077a76f Mon Sep 17 00:00:00 2001 From: julienrbrt Date: Sun, 10 Aug 2025 23:54:30 +0200 Subject: [PATCH 4/4] Update generate_typescript.go --- ignite/pkg/cosmosgen/generate_typescript.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ignite/pkg/cosmosgen/generate_typescript.go b/ignite/pkg/cosmosgen/generate_typescript.go index 70e7f0467e..c6919d805a 100644 --- a/ignite/pkg/cosmosgen/generate_typescript.go +++ b/ignite/pkg/cosmosgen/generate_typescript.go @@ -54,7 +54,7 @@ func newTSGenerator(g *generator) *tsGenerator { } if !tsg.isLocalProto { - log.Print("No '%s' binary found in PATH, using remote buf plugin for Typescript generation. %s\n", protocGenTSProtoBin, msgBufAuth) + log.Printf("No '%s' binary found in PATH, using remote buf plugin for Typescript generation. %s\n", protocGenTSProtoBin, msgBufAuth) } return tsg