Commit fd17c942 authored by Josh Haberman's avatar Josh Haberman Committed by Feng Xiao

Bugfix: base the require logic on the file being required.

parent a0f49037
...@@ -159,8 +159,8 @@ string GetJSFilename(const string& filename) { ...@@ -159,8 +159,8 @@ string GetJSFilename(const string& filename) {
// Given a filename like foo/bar/baz.proto, returns the root directory // Given a filename like foo/bar/baz.proto, returns the root directory
// path ../../ // path ../../
string GetRootPath(const string& filename) { string GetRootPath(const string& from_filename, const string& to_filename) {
if (filename.find("google/protobuf") == 0) { if (to_filename.find("google/protobuf") == 0) {
// Well-known types (.proto files in the google/protobuf directory) are // Well-known types (.proto files in the google/protobuf directory) are
// assumed to come from the 'google-protobuf' npm package. We may want to // assumed to come from the 'google-protobuf' npm package. We may want to
// generalize this exception later by letting others put generated code in // generalize this exception later by letting others put generated code in
...@@ -168,7 +168,7 @@ string GetRootPath(const string& filename) { ...@@ -168,7 +168,7 @@ string GetRootPath(const string& filename) {
return "google-protobuf/"; 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) { if (slashes == 0) {
return "./"; return "./";
} }
...@@ -2845,7 +2845,7 @@ void Generator::GenerateFile(const GeneratorOptions& options, ...@@ -2845,7 +2845,7 @@ void Generator::GenerateFile(const GeneratorOptions& options,
printer->Print( printer->Print(
"var $alias$ = require('$file$');\n", "var $alias$ = require('$file$');\n",
"alias", ModuleAlias(name), "alias", ModuleAlias(name),
"file", GetRootPath(file->name()) + GetJSFilename(name)); "file", GetRootPath(file->name(), name) + GetJSFilename(name));
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment