From c137e11918d95e2a20bef5c148f764507869b8a7 Mon Sep 17 00:00:00 2001 From: Red Daly Date: Mon, 9 Jan 2023 04:11:24 +0000 Subject: [PATCH] Update ES6 imports with comment about corresponding proto import path. I was experiencing a long import path in the generated code that doesn't work. Outputting the proto file that corresponds to a JS import is helpful for both diagnosing the issue and writing a wrapper for altering the import path to my satisfaction. Before: ```js import * as github_com_gonzojive_rules_ts_proto_example_prefix_greeting_pb from '../../../../../github.com/gonzojive/rules_ts_proto/example/prefix/greeting_pb'; ``` After: ```js import * as github_com_gonzojive_rules_ts_proto_example_prefix_greeting_pb from '../../../../../github.com/gonzojive/rules_ts_proto/example/prefix/greeting_pb'; // proto import: "github.com/gonzojive/rules_ts_proto/example/prefix/greeting.proto" ``` --- javascript/net/grpc/web/generator/grpc_generator.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/javascript/net/grpc/web/generator/grpc_generator.cc b/javascript/net/grpc/web/generator/grpc_generator.cc index 54efa8e5d..4e0e9332b 100644 --- a/javascript/net/grpc/web/generator/grpc_generator.cc +++ b/javascript/net/grpc/web/generator/grpc_generator.cc @@ -555,15 +555,18 @@ void PrintES6Imports(Printer* printer, const FileDescriptor* file) { std::set imports; for (const auto& entry : GetAllMessages(file)) { - const string& name = entry.second->file()->name(); + const string& proto_filename = entry.second->file()->name(); string dep_filename = GetRootPath(file->name(), name) + StripProto(name); if (imports.find(dep_filename) != imports.end()) { continue; } imports.insert(dep_filename); // We need to give each cross-file import an alias. - printer->Print("import * as $alias$ from '$dep_filename$_pb';\n", "alias", - ModuleAlias(name), "dep_filename", dep_filename); + printer->Print("import * as $alias$ from '$dep_filename$_pb'; // proto import: \"$proto_filename$\"\n", + "alias", ModuleAlias(name), + "dep_filename", dep_filename, + "proto_filename", proto_filename); + } } printer->Print("\n\n"); }