From fd17c94259d9c1b611080e1fdd0525c3eee0d5bb Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Thu, 16 Jun 2016 14:45:42 -0700 Subject: Bugfix: base the require logic on the file being required. --- src/google/protobuf/compiler/js/js_generator.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc index 5d1ba598..17d50987 100755 --- a/src/google/protobuf/compiler/js/js_generator.cc +++ b/src/google/protobuf/compiler/js/js_generator.cc @@ -159,8 +159,8 @@ string GetJSFilename(const string& filename) { // Given a filename like foo/bar/baz.proto, returns the root directory // path ../../ -string GetRootPath(const string& filename) { - if (filename.find("google/protobuf") == 0) { +string GetRootPath(const string& from_filename, const string& to_filename) { + if (to_filename.find("google/protobuf") == 0) { // Well-known types (.proto files in the google/protobuf directory) are // assumed to come from the 'google-protobuf' npm package. We may want to // generalize this exception later by letting others put generated code in @@ -168,7 +168,7 @@ string GetRootPath(const string& filename) { return "google-protobuf/"; } - size_t slashes = std::count(filename.begin(), filename.end(), '/'); + size_t slashes = std::count(from_filename.begin(), from_filename.end(), '/'); if (slashes == 0) { return "./"; } @@ -2845,7 +2845,7 @@ void Generator::GenerateFile(const GeneratorOptions& options, printer->Print( "var $alias$ = require('$file$');\n", "alias", ModuleAlias(name), - "file", GetRootPath(file->name()) + GetJSFilename(name)); + "file", GetRootPath(file->name(), name) + GetJSFilename(name)); } } -- cgit v1.2.3