Commit 0e27112c authored by Josh Haberman's avatar Josh Haberman

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

parent 13374867
......@@ -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 "./";
}
......@@ -2846,7 +2846,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));
}
}
......
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