Skip to content

Fix the import path for generated typescript files #360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions javascript/net/grpc/web/grpc_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,15 @@ string GetRootPath(const string& from_filename, const string& to_filename) {
return result;
}

// Returns the basename of a file.
string GetBasename(string filename) {
size_t last_slash = filename.find_last_of('/');
if (last_slash != string::npos) {
return filename.substr(last_slash + 1);
}
return filename;
}

// Returns the alias we assign to the module of the given .proto filename
// when importing.
string ModuleAlias(const string& filename) {
Expand Down Expand Up @@ -319,12 +328,7 @@ void PrintCommonJsMessagesDeps(Printer* printer, const FileDescriptor* file) {
}

// need to import the messages from our own file
string filename = StripProto(file->name());
size_t last_slash = filename.find_last_of('/');
if (last_slash != string::npos) {
filename = filename.substr(last_slash + 1);
}
vars["filename"] = filename;
vars["filename"] = GetBasename(StripProto(file->name()));

if (!package.empty()) {
printer->Print(
Expand All @@ -340,7 +344,7 @@ void PrintCommonJsMessagesDeps(Printer* printer, const FileDescriptor* file) {
void PrintES6Imports(Printer* printer, const FileDescriptor* file) {
std::map<string, string> vars;
std::map<string, const Descriptor*> messages = GetAllMessages(file);
vars["base_name"] = StripProto(file->name());
vars["base_name"] = GetBasename(StripProto(file->name()));
printer->Print("import * as grpcWeb from 'grpc-web';\n");
printer->Print("import {\n");
printer->Indent();
Expand Down