@@ -235,6 +235,15 @@ string GetRootPath(const string& from_filename, const string& to_filename) {
235
235
return result;
236
236
}
237
237
238
+ // Returns the basename of a file.
239
+ string GetBasename (string filename) {
240
+ size_t last_slash = filename.find_last_of (' /' );
241
+ if (last_slash != string::npos) {
242
+ return filename.substr (last_slash + 1 );
243
+ }
244
+ return filename;
245
+ }
246
+
238
247
// Returns the alias we assign to the module of the given .proto filename
239
248
// when importing.
240
249
string ModuleAlias (const string& filename) {
@@ -319,12 +328,7 @@ void PrintCommonJsMessagesDeps(Printer* printer, const FileDescriptor* file) {
319
328
}
320
329
321
330
// need to import the messages from our own file
322
- string filename = StripProto (file->name ());
323
- size_t last_slash = filename.find_last_of (' /' );
324
- if (last_slash != string::npos) {
325
- filename = filename.substr (last_slash + 1 );
326
- }
327
- vars[" filename" ] = filename;
331
+ vars[" filename" ] = GetBasename (StripProto (file->name ()));
328
332
329
333
if (!package.empty ()) {
330
334
printer->Print (
@@ -340,7 +344,7 @@ void PrintCommonJsMessagesDeps(Printer* printer, const FileDescriptor* file) {
340
344
void PrintES6Imports (Printer* printer, const FileDescriptor* file) {
341
345
std::map<string, string> vars;
342
346
std::map<string, const Descriptor*> messages = GetAllMessages (file);
343
- vars[" base_name" ] = StripProto (file->name ());
347
+ vars[" base_name" ] = GetBasename ( StripProto (file->name () ));
344
348
printer->Print (" import * as grpcWeb from 'grpc-web';\n " );
345
349
printer->Print (" import {\n " );
346
350
printer->Indent ();
0 commit comments